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