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