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