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