^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * zfcp device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Error Recovery Procedures (ERP).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright IBM Corp. 2002, 2020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define KMSG_COMPONENT "zfcp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "zfcp_ext.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "zfcp_reqlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "zfcp_diag.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ZFCP_MAX_ERPS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) enum zfcp_erp_act_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) ZFCP_STATUS_ERP_NO_REF = 0x00800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Eyecatcher pseudo flag to bitwise or-combine with enum zfcp_erp_act_type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Used to indicate that an ERP action could not be set up despite a detected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * need for some recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define ZFCP_ERP_ACTION_NONE 0xc0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Eyecatcher pseudo flag to bitwise or-combine with enum zfcp_erp_act_type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Used to indicate that ERP not needed because the object has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * ZFCP_STATUS_COMMON_ERP_FAILED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define ZFCP_ERP_ACTION_FAILED 0xe0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) enum zfcp_erp_act_result {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ZFCP_ERP_SUCCEEDED = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ZFCP_ERP_FAILED = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ZFCP_ERP_CONTINUES = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ZFCP_ERP_EXIT = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ZFCP_ERP_DISMISSED = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ZFCP_ERP_NOMEM = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) zfcp_erp_clear_adapter_status(adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ZFCP_STATUS_COMMON_UNBLOCKED | mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static bool zfcp_erp_action_is_running(struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct zfcp_erp_action *curr_act;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (act == curr_act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) list_move(&act->list, &adapter->erp_ready_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) zfcp_dbf_rec_run("erardy1", act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) wake_up(&adapter->erp_ready_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) zfcp_dbf_rec_run("erardy2", act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) act->status |= ZFCP_STATUS_ERP_DISMISSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (zfcp_erp_action_is_running(act))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) zfcp_erp_action_ready(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static void zfcp_erp_action_dismiss_lun(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) zfcp_erp_action_dismiss(&zfcp_sdev->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) zfcp_erp_action_dismiss(&port->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) spin_lock(port->adapter->scsi_host->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) __shost_for_each_device(sdev, port->adapter->scsi_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (sdev_to_zfcp(sdev)->port == port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) zfcp_erp_action_dismiss_lun(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) spin_unlock(port->adapter->scsi_host->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) zfcp_erp_action_dismiss(&adapter->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) read_lock(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) list_for_each_entry(port, &adapter->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) zfcp_erp_action_dismiss_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) read_unlock(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static enum zfcp_erp_act_type zfcp_erp_handle_failed(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) enum zfcp_erp_act_type want, struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct zfcp_port *port, struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) enum zfcp_erp_act_type need = want;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct zfcp_scsi_dev *zsdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) switch (want) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) zsdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (atomic_read(&zsdev->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) need = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) need = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (atomic_read(&port->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ZFCP_STATUS_COMMON_ERP_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) need = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /* ensure propagation of failed status to new devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) zfcp_erp_set_port_status(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) port, ZFCP_STATUS_COMMON_ERP_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ZFCP_STATUS_COMMON_ERP_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) need = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* ensure propagation of failed status to new devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) zfcp_erp_set_adapter_status(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return need;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static enum zfcp_erp_act_type zfcp_erp_required_act(enum zfcp_erp_act_type want,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct zfcp_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) enum zfcp_erp_act_type need = want;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int l_status, p_status, a_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct zfcp_scsi_dev *zfcp_sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) switch (want) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) l_status = atomic_read(&zfcp_sdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (l_status & ZFCP_STATUS_COMMON_ERP_INUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) p_status = atomic_read(&port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) need = ZFCP_ERP_ACTION_REOPEN_PORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) p_status = atomic_read(&port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (!(p_status & ZFCP_STATUS_COMMON_OPEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) need = ZFCP_ERP_ACTION_REOPEN_PORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) p_status = atomic_read(&port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) a_status = atomic_read(&adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (p_status & ZFCP_STATUS_COMMON_NOESC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return need;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) a_status = atomic_read(&adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) !(a_status & ZFCP_STATUS_COMMON_OPEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return 0; /* shutdown requested for closed adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return need;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static struct zfcp_erp_action *zfcp_erp_setup_act(enum zfcp_erp_act_type need,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) u32 act_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct zfcp_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct zfcp_erp_action *erp_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct zfcp_scsi_dev *zfcp_sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (WARN_ON_ONCE(need != ZFCP_ERP_ACTION_REOPEN_LUN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) need != ZFCP_ERP_ACTION_REOPEN_PORT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) need != ZFCP_ERP_ACTION_REOPEN_PORT_FORCED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) need != ZFCP_ERP_ACTION_REOPEN_ADAPTER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) switch (need) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (!(act_status & ZFCP_STATUS_ERP_NO_REF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (scsi_device_get(sdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) &zfcp_sdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) erp_action = &zfcp_sdev->erp_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) WARN_ON_ONCE(erp_action->port != port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) WARN_ON_ONCE(erp_action->sdev != sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (!(atomic_read(&zfcp_sdev->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ZFCP_STATUS_COMMON_RUNNING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (!get_device(&port->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) zfcp_erp_action_dismiss_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) erp_action = &port->erp_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) WARN_ON_ONCE(erp_action->port != port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) WARN_ON_ONCE(erp_action->sdev != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) kref_get(&adapter->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) zfcp_erp_action_dismiss_adapter(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) erp_action = &adapter->erp_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) WARN_ON_ONCE(erp_action->port != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) WARN_ON_ONCE(erp_action->sdev != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (!(atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ZFCP_STATUS_COMMON_RUNNING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) act_status |= ZFCP_STATUS_ERP_CLOSE_ONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) WARN_ON_ONCE(erp_action->adapter != adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) memset(&erp_action->list, 0, sizeof(erp_action->list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) memset(&erp_action->timer, 0, sizeof(erp_action->timer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) erp_action->step = ZFCP_ERP_STEP_UNINITIALIZED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) erp_action->fsf_req_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) erp_action->type = need;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) erp_action->status = act_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return erp_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static void zfcp_erp_action_enqueue(enum zfcp_erp_act_type want,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct zfcp_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct scsi_device *sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) char *dbftag, u32 act_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) enum zfcp_erp_act_type need;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct zfcp_erp_action *act;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) need = zfcp_erp_handle_failed(want, adapter, port, sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (!need) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) need = ZFCP_ERP_ACTION_FAILED; /* marker for trace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (!adapter->erp_thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) need = ZFCP_ERP_ACTION_NONE; /* marker for trace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) need = zfcp_erp_required_act(want, adapter, port, sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (!need)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) act = zfcp_erp_setup_act(need, act_status, adapter, port, sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (!act) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) need |= ZFCP_ERP_ACTION_NONE; /* marker for trace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) atomic_or(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) ++adapter->erp_total_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) list_add_tail(&act->list, &adapter->erp_ready_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) wake_up(&adapter->erp_ready_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) zfcp_dbf_rec_trig(dbftag, adapter, port, sdev, want, need);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) void zfcp_erp_port_forced_no_port_dbf(char *dbftag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) u64 port_name, u32 port_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static /* don't waste stack */ struct zfcp_port tmpport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* Stand-in zfcp port with fields just good enough for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * zfcp_dbf_rec_trig() and zfcp_dbf_set_common().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * Under lock because tmpport is static.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) atomic_set(&tmpport.status, -1); /* unknown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) tmpport.wwpn = port_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) tmpport.d_id = port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) zfcp_dbf_rec_trig(dbftag, adapter, &tmpport, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ZFCP_ERP_ACTION_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static void _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) int clear_mask, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) zfcp_erp_adapter_block(adapter, clear_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) zfcp_scsi_schedule_rports_block(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) adapter, NULL, NULL, dbftag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * zfcp_erp_adapter_reopen - Reopen adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * @adapter: Adapter to reopen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * @clear: Status flags to clear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * @dbftag: Tag for debug trace event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) zfcp_erp_adapter_block(adapter, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) zfcp_scsi_schedule_rports_block(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER, adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) NULL, NULL, dbftag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * zfcp_erp_adapter_shutdown - Shutdown adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * @adapter: Adapter to shut down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * @clear: Status flags to clear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * @dbftag: Tag for debug trace event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) zfcp_erp_adapter_reopen(adapter, clear | flags, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * zfcp_erp_port_shutdown - Shutdown port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * @port: Port to shut down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * @clear: Status flags to clear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * @dbftag: Tag for debug trace event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) zfcp_erp_port_reopen(port, clear | flags, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) zfcp_erp_clear_port_status(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ZFCP_STATUS_COMMON_UNBLOCKED | clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) zfcp_erp_port_block(port, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) zfcp_scsi_schedule_rport_block(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) port->adapter, port, NULL, dbftag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * zfcp_erp_port_forced_reopen - Forced close of port and open again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * @port: Port to force close and to reopen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * @clear: Status flags to clear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * @dbftag: Tag for debug trace event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct zfcp_adapter *adapter = port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) _zfcp_erp_port_forced_reopen(port, clear, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static void _zfcp_erp_port_reopen(struct zfcp_port *port, int clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) zfcp_erp_port_block(port, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) zfcp_scsi_schedule_rport_block(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) port->adapter, port, NULL, dbftag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * zfcp_erp_port_reopen - trigger remote port recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * @port: port to recover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * @clear: flags in port status to be cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * @dbftag: Tag for debug trace event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) void zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct zfcp_adapter *adapter = port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) _zfcp_erp_port_reopen(port, clear, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static void zfcp_erp_lun_block(struct scsi_device *sdev, int clear_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) zfcp_erp_clear_lun_status(sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static void _zfcp_erp_lun_reopen(struct scsi_device *sdev, int clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) char *dbftag, u32 act_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) zfcp_erp_lun_block(sdev, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_LUN, adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) zfcp_sdev->port, sdev, dbftag, act_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * zfcp_erp_lun_reopen - initiate reopen of a LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * @sdev: SCSI device / LUN to be reopened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * @clear: specifies flags in LUN status to be cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * @dbftag: Tag for debug trace event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * Return: 0 on success, < 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) void zfcp_erp_lun_reopen(struct scsi_device *sdev, int clear, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct zfcp_port *port = zfcp_sdev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct zfcp_adapter *adapter = port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) _zfcp_erp_lun_reopen(sdev, clear, dbftag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * zfcp_erp_lun_shutdown - Shutdown LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * @sdev: SCSI device / LUN to shut down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * @clear: Status flags to clear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * @dbftag: Tag for debug trace event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) void zfcp_erp_lun_shutdown(struct scsi_device *sdev, int clear, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) zfcp_erp_lun_reopen(sdev, clear | flags, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * zfcp_erp_lun_shutdown_wait - Shutdown LUN and wait for erp completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * @sdev: SCSI device / LUN to shut down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * @dbftag: Tag for debug trace event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * Do not acquire a reference for the LUN when creating the ERP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * action. It is safe, because this function waits for the ERP to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * complete first. This allows to shutdown the LUN, even when the SCSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * device is in the state SDEV_DEL when scsi_device_get will fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) void zfcp_erp_lun_shutdown_wait(struct scsi_device *sdev, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct zfcp_port *port = zfcp_sdev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct zfcp_adapter *adapter = port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) int clear = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) _zfcp_erp_lun_reopen(sdev, clear, dbftag, ZFCP_STATUS_ERP_NO_REF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static int zfcp_erp_status_change_set(unsigned long mask, atomic_t *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return (atomic_read(status) ^ mask) & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) &adapter->status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) zfcp_dbf_rec_run("eraubl1", &adapter->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static void zfcp_erp_port_unblock(struct zfcp_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) &port->status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) zfcp_dbf_rec_run("erpubl1", &port->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static void zfcp_erp_lun_unblock(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) &zfcp_sdev->status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) zfcp_dbf_rec_run("erlubl1", &sdev_to_zfcp(sdev)->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED, &zfcp_sdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) zfcp_dbf_rec_run("erator1", erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct zfcp_fsf_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (!act->fsf_req_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) spin_lock(&adapter->req_list->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) req = _zfcp_reqlist_find(adapter->req_list, act->fsf_req_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (req && req->erp_action == act) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) ZFCP_STATUS_ERP_TIMEDOUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) zfcp_dbf_rec_run("erscf_1", act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* lock-free concurrent access with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * zfcp_erp_timeout_handler()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) WRITE_ONCE(req->erp_action, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) zfcp_dbf_rec_run("erscf_2", act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) act->fsf_req_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) act->fsf_req_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) spin_unlock(&adapter->req_list->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * zfcp_erp_notify - Trigger ERP action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * @erp_action: ERP action to continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * @set_mask: ERP action status flags to set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) struct zfcp_adapter *adapter = erp_action->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (zfcp_erp_action_is_running(erp_action)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) erp_action->status |= set_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) zfcp_erp_action_ready(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * @t: timer list entry embedded in zfcp FSF request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) void zfcp_erp_timeout_handler(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct zfcp_fsf_req *fsf_req = from_timer(fsf_req, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) struct zfcp_erp_action *act;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /* lock-free concurrent access with zfcp_erp_strategy_check_fsfreq() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) act = READ_ONCE(fsf_req->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (!act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static void zfcp_erp_memwait_handler(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct zfcp_erp_action *act = from_timer(act, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) zfcp_erp_notify(act, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) timer_setup(&erp_action->timer, zfcp_erp_memwait_handler, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) erp_action->timer.expires = jiffies + HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) add_timer(&erp_action->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) void zfcp_erp_port_forced_reopen_all(struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) int clear, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) read_lock(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) list_for_each_entry(port, &adapter->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) _zfcp_erp_port_forced_reopen(port, clear, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) read_unlock(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) int clear, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) read_lock(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) list_for_each_entry(port, &adapter->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) _zfcp_erp_port_reopen(port, clear, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) read_unlock(&adapter->port_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static void _zfcp_erp_lun_reopen_all(struct zfcp_port *port, int clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) spin_lock(port->adapter->scsi_host->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) __shost_for_each_device(sdev, port->adapter->scsi_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (sdev_to_zfcp(sdev)->port == port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) _zfcp_erp_lun_reopen(sdev, clear, dbftag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) spin_unlock(port->adapter->scsi_host->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) switch (act->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) _zfcp_erp_port_reopen(act->port, 0, "ersff_3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) _zfcp_erp_lun_reopen(act->sdev, 0, "ersff_4", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) switch (act->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) _zfcp_erp_port_reopen(act->port, 0, "ersfs_2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) _zfcp_erp_lun_reopen_all(act->port, 0, "ersfs_3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) read_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (list_empty(&adapter->erp_ready_head) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) list_empty(&adapter->erp_running_head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) atomic_andnot(ZFCP_STATUS_ADAPTER_ERP_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) wake_up(&adapter->erp_done_wqh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) read_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) adapter->peer_d_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (IS_ERR(port)) /* error or port already attached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) zfcp_erp_port_reopen(port, 0, "ereptp1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) static enum zfcp_erp_act_result zfcp_erp_adapter_strat_fsf_xconf(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) int retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) int sleep = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) struct zfcp_adapter *adapter = erp_action->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) for (retries = 7; retries; retries--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) write_lock_irq(&adapter->erp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) zfcp_erp_action_to_running(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) write_unlock_irq(&adapter->erp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (zfcp_fsf_exchange_config_data(erp_action)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) wait_event(adapter->erp_ready_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) !list_empty(&adapter->erp_ready_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (!(atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) ssleep(sleep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) sleep *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) zfcp_erp_adapter_strategy_open_ptp_port(struct zfcp_adapter *const adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) zfcp_erp_enqueue_ptp_port(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) static enum zfcp_erp_act_result zfcp_erp_adapter_strategy_open_fsf_xport(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) write_lock_irq(&adapter->erp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) zfcp_erp_action_to_running(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) write_unlock_irq(&adapter->erp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) ret = zfcp_fsf_exchange_port_data(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (ret == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) zfcp_dbf_rec_run("erasox1", act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) wait_event(adapter->erp_ready_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) !list_empty(&adapter->erp_ready_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) zfcp_dbf_rec_run("erasox2", act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) static enum zfcp_erp_act_result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) zfcp_erp_adapter_strategy_alloc_shost(struct zfcp_adapter *const adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct zfcp_diag_adapter_config_data *const config_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) &adapter->diagnostics->config_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct zfcp_diag_adapter_port_data *const port_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) &adapter->diagnostics->port_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) rc = zfcp_scsi_adapter_register(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (rc == -EEXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) else if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * We allocated the shost for the first time. Before it was NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) * and so we deferred all updates in the xconf- and xport-data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) * handlers. We need to make up for that now, and make all the updates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) * that would have been done before.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * We can be sure that xconf- and xport-data succeeded, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) * otherwise this function is not called. But they might have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * incomplete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) spin_lock_irqsave(&config_data->header.access_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) zfcp_scsi_shost_update_config_data(adapter, &config_data->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) !!config_data->header.incomplete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) spin_unlock_irqrestore(&config_data->header.access_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) spin_lock_irqsave(&port_data->header.access_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) zfcp_scsi_shost_update_port_data(adapter, &port_data->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) spin_unlock_irqrestore(&port_data->header.access_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * There is a remote possibility that the 'Exchange Port Data' request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) * reports a different connectivity status than 'Exchange Config Data'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) * But any change to the connectivity status of the local optic that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) * happens after the initial xconf request is expected to be reported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) * to us, as soon as we post Status Read Buffers to the FCP channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) * firmware after this function. So any resulting inconsistency will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) * only be momentary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (config_data->header.incomplete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) zfcp_fsf_fc_host_link_down(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) static enum zfcp_erp_act_result zfcp_erp_adapter_strategy_open_fsf(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (zfcp_erp_adapter_strategy_alloc_shost(act->adapter) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) ZFCP_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) zfcp_erp_adapter_strategy_open_ptp_port(act->adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (mempool_resize(act->adapter->pool.sr_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) act->adapter->stat_read_buf_num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) if (mempool_resize(act->adapter->pool.status_read_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) act->adapter->stat_read_buf_num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) atomic_set(&act->adapter->stat_miss, act->adapter->stat_read_buf_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (zfcp_status_read_refill(act->adapter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) /* close queues to ensure that buffers are not accessed by adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) zfcp_qdio_close(adapter->qdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) zfcp_fsf_req_dismiss_all(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) adapter->fsf_req_seq_no = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) zfcp_fc_wka_ports_force_offline(adapter->gs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) /* all ports and LUNs are closed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) zfcp_erp_clear_adapter_status(adapter, ZFCP_STATUS_COMMON_OPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) static enum zfcp_erp_act_result zfcp_erp_adapter_strategy_open(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (zfcp_qdio_open(adapter->qdio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) if (zfcp_erp_adapter_strategy_open_fsf(act)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) zfcp_erp_adapter_strategy_close(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) atomic_or(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) static enum zfcp_erp_act_result zfcp_erp_adapter_strategy(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) zfcp_erp_adapter_strategy_close(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) return ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (zfcp_erp_adapter_strategy_open(act)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) ssleep(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static enum zfcp_erp_act_result zfcp_erp_port_forced_strategy_close(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) retval = zfcp_fsf_close_physical_port(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) if (retval == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) return ZFCP_ERP_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) return ZFCP_ERP_CONTINUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) static enum zfcp_erp_act_result zfcp_erp_port_forced_strategy(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) struct zfcp_port *port = erp_action->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) int status = atomic_read(&port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) switch (erp_action->step) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) case ZFCP_ERP_STEP_UNINITIALIZED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) (status & ZFCP_STATUS_COMMON_OPEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) return zfcp_erp_port_forced_strategy_close(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) case ZFCP_ERP_STEP_PORT_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) case ZFCP_ERP_STEP_PORT_OPENING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) case ZFCP_ERP_STEP_LUN_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) case ZFCP_ERP_STEP_LUN_OPENING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) static enum zfcp_erp_act_result zfcp_erp_port_strategy_close(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) retval = zfcp_fsf_close_port(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (retval == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) return ZFCP_ERP_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) return ZFCP_ERP_CONTINUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static enum zfcp_erp_act_result zfcp_erp_port_strategy_open_port(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) retval = zfcp_fsf_open_port(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) if (retval == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) return ZFCP_ERP_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) return ZFCP_ERP_CONTINUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) struct zfcp_port *port = act->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) if (port->wwpn != adapter->peer_wwpn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ERP_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) port->d_id = adapter->peer_d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) return zfcp_erp_port_strategy_open_port(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) static enum zfcp_erp_act_result zfcp_erp_port_strategy_open_common(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) struct zfcp_erp_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) struct zfcp_port *port = act->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) int p_status = atomic_read(&port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) switch (act->step) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) case ZFCP_ERP_STEP_UNINITIALIZED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) case ZFCP_ERP_STEP_PORT_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) return zfcp_erp_open_ptp_port(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (!port->d_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) zfcp_fc_trigger_did_lookup(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) return zfcp_erp_port_strategy_open_port(act);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) case ZFCP_ERP_STEP_PORT_OPENING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) /* D_ID might have changed during open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) if (p_status & ZFCP_STATUS_COMMON_OPEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if (!port->d_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) zfcp_fc_trigger_did_lookup(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) return ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) port->d_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) /* no early return otherwise, continue after switch case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) case ZFCP_ERP_STEP_LUN_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) case ZFCP_ERP_STEP_LUN_OPENING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) static enum zfcp_erp_act_result zfcp_erp_port_strategy(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) struct zfcp_port *port = erp_action->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) int p_status = atomic_read(&port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) if ((p_status & ZFCP_STATUS_COMMON_NOESC) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) !(p_status & ZFCP_STATUS_COMMON_OPEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) goto close_init_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) switch (erp_action->step) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) case ZFCP_ERP_STEP_UNINITIALIZED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (p_status & ZFCP_STATUS_COMMON_OPEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) return zfcp_erp_port_strategy_close(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) case ZFCP_ERP_STEP_PORT_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (p_status & ZFCP_STATUS_COMMON_OPEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) case ZFCP_ERP_STEP_PORT_OPENING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) case ZFCP_ERP_STEP_LUN_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) case ZFCP_ERP_STEP_LUN_OPENING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) close_init_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) return ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) return zfcp_erp_port_strategy_open_common(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) static void zfcp_erp_lun_strategy_clearstati(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) &zfcp_sdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static enum zfcp_erp_act_result zfcp_erp_lun_strategy_close(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) int retval = zfcp_fsf_close_lun(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) if (retval == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) return ZFCP_ERP_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) erp_action->step = ZFCP_ERP_STEP_LUN_CLOSING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) return ZFCP_ERP_CONTINUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) static enum zfcp_erp_act_result zfcp_erp_lun_strategy_open(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) int retval = zfcp_fsf_open_lun(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) if (retval == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) return ZFCP_ERP_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) erp_action->step = ZFCP_ERP_STEP_LUN_OPENING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) return ZFCP_ERP_CONTINUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static enum zfcp_erp_act_result zfcp_erp_lun_strategy(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) struct scsi_device *sdev = erp_action->sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) switch (erp_action->step) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) case ZFCP_ERP_STEP_UNINITIALIZED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) zfcp_erp_lun_strategy_clearstati(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_OPEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) return zfcp_erp_lun_strategy_close(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) /* already closed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) case ZFCP_ERP_STEP_LUN_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_OPEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) return ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) return zfcp_erp_lun_strategy_open(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) case ZFCP_ERP_STEP_LUN_OPENING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_OPEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) return ZFCP_ERP_SUCCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) case ZFCP_ERP_STEP_PORT_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) case ZFCP_ERP_STEP_PORT_OPENING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) static enum zfcp_erp_act_result zfcp_erp_strategy_check_lun(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) struct scsi_device *sdev, enum zfcp_erp_act_result result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) switch (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) case ZFCP_ERP_SUCCEEDED :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) atomic_set(&zfcp_sdev->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) zfcp_erp_lun_unblock(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) case ZFCP_ERP_FAILED :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) atomic_inc(&zfcp_sdev->erp_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (atomic_read(&zfcp_sdev->erp_counter) > ZFCP_MAX_ERPS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) dev_err(&zfcp_sdev->port->adapter->ccw_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) "ERP failed for LUN 0x%016Lx on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) "port 0x%016Lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) (unsigned long long)zfcp_scsi_dev_lun(sdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) (unsigned long long)zfcp_sdev->port->wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) zfcp_erp_set_lun_status(sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) ZFCP_STATUS_COMMON_ERP_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) case ZFCP_ERP_CONTINUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) case ZFCP_ERP_EXIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) case ZFCP_ERP_DISMISSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) case ZFCP_ERP_NOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) zfcp_erp_lun_block(sdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) result = ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) static enum zfcp_erp_act_result zfcp_erp_strategy_check_port(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) struct zfcp_port *port, enum zfcp_erp_act_result result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) switch (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) case ZFCP_ERP_SUCCEEDED :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) atomic_set(&port->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) zfcp_erp_port_unblock(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) case ZFCP_ERP_FAILED :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) zfcp_erp_port_block(port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) result = ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) atomic_inc(&port->erp_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) dev_err(&port->adapter->ccw_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) "ERP failed for remote port 0x%016Lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) (unsigned long long)port->wwpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) zfcp_erp_set_port_status(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) ZFCP_STATUS_COMMON_ERP_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) case ZFCP_ERP_CONTINUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) case ZFCP_ERP_EXIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) case ZFCP_ERP_DISMISSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) case ZFCP_ERP_NOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) zfcp_erp_port_block(port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) result = ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) static enum zfcp_erp_act_result zfcp_erp_strategy_check_adapter(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) struct zfcp_adapter *adapter, enum zfcp_erp_act_result result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) switch (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) case ZFCP_ERP_SUCCEEDED :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) atomic_set(&adapter->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) zfcp_erp_adapter_unblock(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) case ZFCP_ERP_FAILED :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) atomic_inc(&adapter->erp_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) dev_err(&adapter->ccw_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) "ERP cannot recover an error "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) "on the FCP device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) zfcp_erp_set_adapter_status(adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) ZFCP_STATUS_COMMON_ERP_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) case ZFCP_ERP_CONTINUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) case ZFCP_ERP_EXIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) case ZFCP_ERP_DISMISSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) case ZFCP_ERP_NOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) zfcp_erp_adapter_block(adapter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) result = ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) static enum zfcp_erp_act_result zfcp_erp_strategy_check_target(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) struct zfcp_erp_action *erp_action, enum zfcp_erp_act_result result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) struct zfcp_adapter *adapter = erp_action->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) struct zfcp_port *port = erp_action->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) struct scsi_device *sdev = erp_action->sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) switch (erp_action->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) result = zfcp_erp_strategy_check_lun(sdev, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) result = zfcp_erp_strategy_check_port(port, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) result = zfcp_erp_strategy_check_adapter(adapter, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) int status = atomic_read(target_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) return 1; /* take it online */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) return 1; /* take it offline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) static enum zfcp_erp_act_result zfcp_erp_strategy_statechange(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) struct zfcp_erp_action *act, enum zfcp_erp_act_result result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) enum zfcp_erp_act_type type = act->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) struct zfcp_port *port = act->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) struct scsi_device *sdev = act->sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) struct zfcp_scsi_dev *zfcp_sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) u32 erp_status = act->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) _zfcp_erp_adapter_reopen(adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) ZFCP_STATUS_COMMON_ERP_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) "ersscg1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) return ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) _zfcp_erp_port_reopen(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) ZFCP_STATUS_COMMON_ERP_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) "ersscg2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) return ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (zfcp_erp_strat_change_det(&zfcp_sdev->status, erp_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) _zfcp_erp_lun_reopen(sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) ZFCP_STATUS_COMMON_ERP_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) "ersscg3", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) return ZFCP_ERP_EXIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) struct zfcp_adapter *adapter = erp_action->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) struct zfcp_scsi_dev *zfcp_sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) adapter->erp_total_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) adapter->erp_low_mem_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) list_del(&erp_action->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) zfcp_dbf_rec_run("eractd1", erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) switch (erp_action->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) &zfcp_sdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) &erp_action->port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) &erp_action->adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) * zfcp_erp_try_rport_unblock - unblock rport if no more/new recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) * @port: zfcp_port whose fc_rport we should try to unblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) static void zfcp_erp_try_rport_unblock(struct zfcp_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) struct zfcp_adapter *adapter = port->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) int port_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) struct Scsi_Host *shost = adapter->scsi_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) port_status = atomic_read(&port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) if ((port_status & ZFCP_STATUS_COMMON_UNBLOCKED) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) (port_status & (ZFCP_STATUS_COMMON_ERP_INUSE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) ZFCP_STATUS_COMMON_ERP_FAILED)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) /* new ERP of severity >= port triggered elsewhere meanwhile or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) * local link down (adapter erp_failed but not clear unblock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) zfcp_dbf_rec_run_lvl(4, "ertru_p", &port->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) spin_lock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) __shost_for_each_device(sdev, shost) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) struct zfcp_scsi_dev *zsdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) int lun_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) if (sdev->sdev_state == SDEV_DEL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) sdev->sdev_state == SDEV_CANCEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) if (zsdev->port != port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) /* LUN under port of interest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) lun_status = atomic_read(&zsdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) if ((lun_status & ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) continue; /* unblock rport despite failed LUNs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) /* LUN recovery not given up yet [maybe follow-up pending] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if ((lun_status & ZFCP_STATUS_COMMON_UNBLOCKED) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) (lun_status & ZFCP_STATUS_COMMON_ERP_INUSE) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) /* LUN blocked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) * not yet unblocked [LUN recovery pending]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) * or meanwhile blocked [new LUN recovery triggered]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) zfcp_dbf_rec_run_lvl(4, "ertru_l", &zsdev->erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) spin_unlock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) /* now port has no child or all children have completed recovery,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) * and no ERP of severity >= port was meanwhile triggered elsewhere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) zfcp_scsi_schedule_rport_register(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) spin_unlock(shost->host_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) enum zfcp_erp_act_result result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) struct zfcp_adapter *adapter = act->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) struct zfcp_port *port = act->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) struct scsi_device *sdev = act->sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) switch (act->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) if (!(act->status & ZFCP_STATUS_ERP_NO_REF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) scsi_device_put(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) zfcp_erp_try_rport_unblock(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) /* This switch case might also happen after a forced reopen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) * was successfully done and thus overwritten with a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) * non-forced reopen at `ersfs_2'. In this case, we must not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) * do the clean-up of the non-forced version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) if (act->step != ZFCP_ERP_STEP_UNINITIALIZED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) if (result == ZFCP_ERP_SUCCEEDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) zfcp_erp_try_rport_unblock(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) put_device(&port->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) if (result == ZFCP_ERP_SUCCEEDED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) register_service_level(&adapter->service_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) zfcp_fc_conditional_port_scan(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) queue_work(adapter->work_queue, &adapter->ns_up_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) unregister_service_level(&adapter->service_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) kref_put(&adapter->ref, zfcp_adapter_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) static enum zfcp_erp_act_result zfcp_erp_strategy_do_action(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) switch (erp_action->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) return zfcp_erp_adapter_strategy(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) return zfcp_erp_port_forced_strategy(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) case ZFCP_ERP_ACTION_REOPEN_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) return zfcp_erp_port_strategy(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) case ZFCP_ERP_ACTION_REOPEN_LUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) return zfcp_erp_lun_strategy(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) return ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) static enum zfcp_erp_act_result zfcp_erp_strategy(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) struct zfcp_erp_action *erp_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) enum zfcp_erp_act_result result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) struct zfcp_adapter *adapter = erp_action->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) kref_get(&adapter->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) zfcp_erp_strategy_check_fsfreq(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) zfcp_erp_action_dequeue(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) result = ZFCP_ERP_DISMISSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) result = ZFCP_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) goto check_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) zfcp_erp_action_to_running(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) /* no lock to allow for blocking operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) result = zfcp_erp_strategy_do_action(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) result = ZFCP_ERP_CONTINUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) switch (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) case ZFCP_ERP_NOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) ++adapter->erp_low_mem_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) if (adapter->erp_total_count == adapter->erp_low_mem_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) zfcp_erp_strategy_memwait(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) result = ZFCP_ERP_CONTINUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) case ZFCP_ERP_CONTINUES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) --adapter->erp_low_mem_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) case ZFCP_ERP_SUCCEEDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) case ZFCP_ERP_FAILED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) case ZFCP_ERP_EXIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) case ZFCP_ERP_DISMISSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) check_target:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) result = zfcp_erp_strategy_check_target(erp_action, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) zfcp_erp_action_dequeue(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) result = zfcp_erp_strategy_statechange(erp_action, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) if (result == ZFCP_ERP_EXIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) if (result == ZFCP_ERP_SUCCEEDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) zfcp_erp_strategy_followup_success(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) if (result == ZFCP_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) zfcp_erp_strategy_followup_failed(erp_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) if (result != ZFCP_ERP_CONTINUES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) zfcp_erp_action_cleanup(erp_action, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) kref_put(&adapter->ref, zfcp_adapter_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) static int zfcp_erp_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) struct zfcp_erp_action *act;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) wait_event_interruptible(adapter->erp_ready_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) !list_empty(&adapter->erp_ready_head) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) kthread_should_stop());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) if (kthread_should_stop())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) write_lock_irqsave(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) act = list_first_entry_or_null(&adapter->erp_ready_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) struct zfcp_erp_action, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) write_unlock_irqrestore(&adapter->erp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) if (act) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) /* there is more to come after dismission, no notify */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) zfcp_erp_wakeup(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) * zfcp_erp_thread_setup - Start ERP thread for adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) * @adapter: Adapter to start the ERP thread for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) * Return: 0 on success, or error code from kthread_run().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) struct task_struct *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) dev_name(&adapter->ccw_device->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) if (IS_ERR(thread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) dev_err(&adapter->ccw_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) "Creating an ERP thread for the FCP device failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) return PTR_ERR(thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) adapter->erp_thread = thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) * zfcp_erp_thread_kill - Stop ERP thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) * @adapter: Adapter where the ERP thread should be stopped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) * The caller of this routine ensures that the specified adapter has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) * been shut down and that this operation has been completed. Thus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) * there are no pending erp_actions which would need to be handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) * here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) kthread_stop(adapter->erp_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) adapter->erp_thread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) WARN_ON(!list_empty(&adapter->erp_ready_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) WARN_ON(!list_empty(&adapter->erp_running_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) * zfcp_erp_wait - wait for completion of error recovery on an adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) * @adapter: adapter for which to wait for completion of its error recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) void zfcp_erp_wait(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) wait_event(adapter->erp_done_wqh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) !(atomic_read(&adapter->status) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) ZFCP_STATUS_ADAPTER_ERP_PENDING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) * zfcp_erp_set_adapter_status - set adapter status bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) * @adapter: adapter to change the status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) * @mask: status bits to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) * Changes in common status bits are propagated to attached ports and LUNs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) void zfcp_erp_set_adapter_status(struct zfcp_adapter *adapter, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) u32 common_mask = mask & ZFCP_COMMON_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) atomic_or(mask, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) if (!common_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) read_lock_irqsave(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) list_for_each_entry(port, &adapter->port_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) atomic_or(common_mask, &port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) read_unlock_irqrestore(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) * if `scsi_host` is missing, xconfig/xport data has never completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) * yet, so we can't access it, but there are also no SDEVs yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) if (adapter->scsi_host == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) spin_lock_irqsave(adapter->scsi_host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) __shost_for_each_device(sdev, adapter->scsi_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) atomic_or(common_mask, &sdev_to_zfcp(sdev)->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) spin_unlock_irqrestore(adapter->scsi_host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) * zfcp_erp_clear_adapter_status - clear adapter status bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) * @adapter: adapter to change the status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) * @mask: status bits to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) * Changes in common status bits are propagated to attached ports and LUNs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) void zfcp_erp_clear_adapter_status(struct zfcp_adapter *adapter, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) struct zfcp_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) u32 common_mask = mask & ZFCP_COMMON_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) u32 clear_counter = mask & ZFCP_STATUS_COMMON_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) atomic_andnot(mask, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) if (!common_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) if (clear_counter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) atomic_set(&adapter->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) read_lock_irqsave(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) list_for_each_entry(port, &adapter->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) atomic_andnot(common_mask, &port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) if (clear_counter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) atomic_set(&port->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) read_unlock_irqrestore(&adapter->port_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) * if `scsi_host` is missing, xconfig/xport data has never completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) * yet, so we can't access it, but there are also no SDEVs yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) if (adapter->scsi_host == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) spin_lock_irqsave(adapter->scsi_host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) __shost_for_each_device(sdev, adapter->scsi_host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) atomic_andnot(common_mask, &sdev_to_zfcp(sdev)->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) if (clear_counter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) atomic_set(&sdev_to_zfcp(sdev)->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) spin_unlock_irqrestore(adapter->scsi_host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) * zfcp_erp_set_port_status - set port status bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) * @port: port to change the status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) * @mask: status bits to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) * Changes in common status bits are propagated to attached LUNs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) void zfcp_erp_set_port_status(struct zfcp_port *port, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) u32 common_mask = mask & ZFCP_COMMON_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) atomic_or(mask, &port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) if (!common_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) spin_lock_irqsave(port->adapter->scsi_host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) __shost_for_each_device(sdev, port->adapter->scsi_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) if (sdev_to_zfcp(sdev)->port == port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) atomic_or(common_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) &sdev_to_zfcp(sdev)->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) spin_unlock_irqrestore(port->adapter->scsi_host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) * zfcp_erp_clear_port_status - clear port status bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) * @port: adapter to change the status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) * @mask: status bits to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) * Changes in common status bits are propagated to attached LUNs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) void zfcp_erp_clear_port_status(struct zfcp_port *port, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) u32 common_mask = mask & ZFCP_COMMON_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) u32 clear_counter = mask & ZFCP_STATUS_COMMON_ERP_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) atomic_andnot(mask, &port->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) if (!common_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) if (clear_counter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) atomic_set(&port->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) spin_lock_irqsave(port->adapter->scsi_host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) __shost_for_each_device(sdev, port->adapter->scsi_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) if (sdev_to_zfcp(sdev)->port == port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) atomic_andnot(common_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) &sdev_to_zfcp(sdev)->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) if (clear_counter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) atomic_set(&sdev_to_zfcp(sdev)->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) spin_unlock_irqrestore(port->adapter->scsi_host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) * zfcp_erp_set_lun_status - set lun status bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) * @sdev: SCSI device / lun to set the status bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) * @mask: status bits to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) void zfcp_erp_set_lun_status(struct scsi_device *sdev, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) atomic_or(mask, &zfcp_sdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) * zfcp_erp_clear_lun_status - clear lun status bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) * @sdev: SCSi device / lun to clear the status bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) * @mask: status bits to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) void zfcp_erp_clear_lun_status(struct scsi_device *sdev, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) atomic_andnot(mask, &zfcp_sdev->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) atomic_set(&zfcp_sdev->erp_counter, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) * zfcp_erp_adapter_reset_sync() - Really reopen adapter and wait.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) * @adapter: Pointer to zfcp_adapter to reopen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) * @dbftag: Trace tag string of length %ZFCP_DBF_TAG_LEN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) void zfcp_erp_adapter_reset_sync(struct zfcp_adapter *adapter, char *dbftag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) zfcp_erp_wait(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) }