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