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