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