3  * linux/drivers/s390/scsi/zfcp_erp.c 
 
   5  * FCP adapter driver for IBM eServer zSeries 
 
   7  * (C) Copyright IBM Corp. 2002, 2004
 
   9  * Author(s): Martin Peschke <mpeschke@de.ibm.com> 
 
  10  *            Raimund Schroeder <raimund.schroeder@de.ibm.com> 
 
  13  *            Stefan Bader <stefan.bader@de.ibm.com> 
 
  14  *            Heiko Carstens <heiko.carstens@de.ibm.com> 
 
  15  *            Andreas Herrmann <aherrman@de.ibm.com>
 
  17  * This program is free software; you can redistribute it and/or modify 
 
  18  * it under the terms of the GNU General Public License as published by 
 
  19  * the Free Software Foundation; either version 2, or (at your option) 
 
  22  * This program is distributed in the hope that it will be useful, 
 
  23  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
  24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 
  25  * GNU General Public License for more details. 
 
  27  * You should have received a copy of the GNU General Public License 
 
  28  * along with this program; if not, write to the Free Software 
 
  29  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 
  32 #define ZFCP_LOG_AREA                   ZFCP_LOG_AREA_ERP
 
  36 static int zfcp_erp_adisc(struct zfcp_port *);
 
  37 static void zfcp_erp_adisc_handler(unsigned long);
 
  39 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
 
  40 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
 
  41 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
 
  42 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
 
  44 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
 
  45 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
 
  47 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
 
  48 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
 
  49 static void zfcp_erp_port_block(struct zfcp_port *, int);
 
  50 static void zfcp_erp_port_unblock(struct zfcp_port *);
 
  51 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
 
  52 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
 
  54 static int zfcp_erp_thread(void *);
 
  56 static int zfcp_erp_strategy(struct zfcp_erp_action *);
 
  58 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
 
  59 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
 
  60 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
 
  61 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
 
  62 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
 
  63 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
 
  64 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
 
  66                                          struct zfcp_unit *, int);
 
  67 static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
 
  68 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
 
  70                                               struct zfcp_unit *, int);
 
  71 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
 
  72 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
 
  74 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
 
  75 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
 
  76 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
 
  77 static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
 
  78 static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
 
  79 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
 
  80 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
 
  81 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
 
  82 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
 
  83 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
 
  84 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
 
  85         struct zfcp_erp_action *);
 
  87 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
 
  88 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
 
  90 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
 
  91 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
 
  92 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
 
  93 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
 
  94 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
 
  95 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
 
  96         struct zfcp_erp_action *);
 
  97 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
 
  98 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
 
  99 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
 
 101 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
 
 102 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
 
 103 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
 
 104 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
 
 106 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
 
 107 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
 
 108 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
 
 109 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
 
 111 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
 
 112                                    struct zfcp_port *, struct zfcp_unit *);
 
 113 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
 
 114 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
 
 115                                     struct zfcp_port *, struct zfcp_unit *,
 
 118 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
 
 119 static int  zfcp_erp_action_exists(struct zfcp_erp_action *);
 
 121 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
 
 122 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
 
 124 static void zfcp_erp_memwait_handler(unsigned long);
 
 125 static void zfcp_erp_timeout_handler(unsigned long);
 
 126 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
 
 129  * zfcp_fsf_request_timeout_handler - called if a request timed out
 
 130  * @data: pointer to adapter for handler function
 
 132  * This function needs to be called if requests (ELS, Generic Service,
 
 133  * or SCSI commands) exceed a certain time limit. The assumption is
 
 134  * that after the time limit the adapter get stuck. So we trigger a reopen of
 
 135  * the adapter. This should not be used for error recovery, SCSI abort
 
 136  * commands and SCSI requests from SCSI mid-layer.
 
 139 zfcp_fsf_request_timeout_handler(unsigned long data)
 
 141         struct zfcp_adapter *adapter;
 
 143         adapter = (struct zfcp_adapter *) data;
 
 145         zfcp_erp_adapter_reopen(adapter, 0);
 
 149  * function:    zfcp_fsf_scsi_er_timeout_handler
 
 151  * purpose:     This function needs to be called whenever a SCSI error recovery
 
 152  *              action (abort/reset) does not return.
 
 153  *              Re-opening the adapter means that the command can be returned
 
 154  *              by zfcp (it is guarranteed that it does not return via the
 
 155  *              adapter anymore). The buffer can then be used again.
 
 160 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
 
 162         struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
 
 164         ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
 
 165                         "Restarting all operations on the adapter %s\n",
 
 166                         zfcp_get_busid_by_adapter(adapter));
 
 167         debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
 
 168         zfcp_erp_adapter_reopen(adapter, 0);
 
 176  * purpose:     called if an adapter failed,
 
 177  *              initiates adapter recovery which is done
 
 180  * returns:     0       - initiated action succesfully
 
 181  *              <0      - failed to initiate action
 
 184 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
 
 188         debug_text_event(adapter->erp_dbf, 5, "a_ro");
 
 189         ZFCP_LOG_DEBUG("reopen adapter %s\n",
 
 190                        zfcp_get_busid_by_adapter(adapter));
 
 192         zfcp_erp_adapter_block(adapter, clear_mask);
 
 194         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
 
 195                 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
 
 196                                zfcp_get_busid_by_adapter(adapter));
 
 197                 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
 
 198                 /* ensure propagation of failed status to new devices */
 
 199                 zfcp_erp_adapter_failed(adapter);
 
 203         retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
 
 204                                          adapter, NULL, NULL);
 
 213  * purpose:     Wrappper for zfcp_erp_adapter_reopen_internal
 
 214  *              used to ensure the correct locking
 
 216  * returns:     0       - initiated action succesfully
 
 217  *              <0      - failed to initiate action
 
 220 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
 
 225         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
 226         write_lock(&adapter->erp_lock);
 
 227         retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
 
 228         write_unlock(&adapter->erp_lock);
 
 229         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
 242 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
 
 246         retval = zfcp_erp_adapter_reopen(adapter,
 
 247                                          ZFCP_STATUS_COMMON_RUNNING |
 
 248                                          ZFCP_STATUS_COMMON_ERP_FAILED |
 
 262 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
 
 266         retval = zfcp_erp_port_reopen(port,
 
 267                                       ZFCP_STATUS_COMMON_RUNNING |
 
 268                                       ZFCP_STATUS_COMMON_ERP_FAILED |
 
 282 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
 
 286         retval = zfcp_erp_unit_reopen(unit,
 
 287                                       ZFCP_STATUS_COMMON_RUNNING |
 
 288                                       ZFCP_STATUS_COMMON_ERP_FAILED |
 
 296  * zfcp_erp_adisc - send ADISC ELS command
 
 297  * @port: port structure
 
 300 zfcp_erp_adisc(struct zfcp_port *port)
 
 302         struct zfcp_adapter *adapter = port->adapter;
 
 303         struct zfcp_send_els *send_els;
 
 304         struct zfcp_ls_adisc *adisc;
 
 305         void *address = NULL;
 
 307         struct timer_list *timer;
 
 309         send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
 
 310         if (send_els == NULL)
 
 312         memset(send_els, 0, sizeof(*send_els));
 
 314         send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
 
 315         if (send_els->req == NULL)
 
 317         memset(send_els->req, 0, sizeof(*send_els->req));
 
 319         send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
 
 320         if (send_els->resp == NULL)
 
 322         memset(send_els->resp, 0, sizeof(*send_els->resp));
 
 324         address = (void *) get_zeroed_page(GFP_ATOMIC);
 
 328         zfcp_address_to_sg(address, send_els->req);
 
 329         address += PAGE_SIZE >> 1;
 
 330         zfcp_address_to_sg(address, send_els->resp);
 
 331         send_els->req_count = send_els->resp_count = 1;
 
 333         send_els->adapter = adapter;
 
 334         send_els->port = port;
 
 335         send_els->d_id = port->d_id;
 
 336         send_els->handler = zfcp_erp_adisc_handler;
 
 337         send_els->handler_data = (unsigned long) send_els;
 
 339         adisc = zfcp_sg_to_address(send_els->req);
 
 340         send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
 
 342         send_els->req->length = sizeof(struct zfcp_ls_adisc);
 
 343         send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
 
 345         /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
 
 346            without FC-AL-2 capability, so we don't set it */
 
 347         adisc->wwpn = fc_host_port_name(adapter->scsi_host);
 
 348         adisc->wwnn = fc_host_node_name(adapter->scsi_host);
 
 349         adisc->nport_id = fc_host_port_id(adapter->scsi_host);
 
 350         ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
 
 351                       "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
 
 352                       "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
 
 353                       adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
 
 354                       (wwn_t) adisc->wwnn, adisc->hard_nport_id,
 
 357         timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
 
 362         timer->function = zfcp_fsf_request_timeout_handler;
 
 363         timer->data = (unsigned long) adapter;
 
 364         timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
 
 365         send_els->timer = timer;
 
 367         retval = zfcp_fsf_send_els(send_els);
 
 369                 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
 
 370                                 "0x%08x on adapter %s\n", send_els->d_id,
 
 371                                 zfcp_get_busid_by_adapter(adapter));
 
 372                 del_timer(send_els->timer);
 
 382                 __free_pages(send_els->req->page, 0);
 
 383         if (send_els != NULL) {
 
 384                 kfree(send_els->timer);
 
 385                 kfree(send_els->req);
 
 386                 kfree(send_els->resp);
 
 395  * zfcp_erp_adisc_handler - handler for ADISC ELS command
 
 396  * @data: pointer to struct zfcp_send_els
 
 398  * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
 
 401 zfcp_erp_adisc_handler(unsigned long data)
 
 403         struct zfcp_send_els *send_els;
 
 404         struct zfcp_port *port;
 
 405         struct zfcp_adapter *adapter;
 
 407         struct zfcp_ls_adisc_acc *adisc;
 
 409         send_els = (struct zfcp_send_els *) data;
 
 411         del_timer(send_els->timer);
 
 413         adapter = send_els->adapter;
 
 414         port = send_els->port;
 
 415         d_id = send_els->d_id;
 
 417         /* request rejected or timed out */
 
 418         if (send_els->status != 0) {
 
 419                 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
 
 420                                 "force physical port reopen "
 
 421                                 "(adapter %s, port d_id=0x%08x)\n",
 
 422                                 zfcp_get_busid_by_adapter(adapter), d_id);
 
 423                 debug_text_event(adapter->erp_dbf, 3, "forcreop");
 
 424                 if (zfcp_erp_port_forced_reopen(port, 0))
 
 425                         ZFCP_LOG_NORMAL("failed reopen of port "
 
 426                                         "(adapter %s, wwpn=0x%016Lx)\n",
 
 427                                         zfcp_get_busid_by_port(port),
 
 432         adisc = zfcp_sg_to_address(send_els->resp);
 
 434         ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
 
 435                       "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
 
 436                       "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
 
 437                       d_id, fc_host_port_id(adapter->scsi_host),
 
 438                       (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
 
 439                       adisc->hard_nport_id, adisc->nport_id);
 
 441         /* set wwnn for port */
 
 443                 port->wwnn = adisc->wwnn;
 
 445         if (port->wwpn != adisc->wwpn) {
 
 446                 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
 
 447                                 "port (adapter %s, wwpn=0x%016Lx, "
 
 448                                 "adisc_resp_wwpn=0x%016Lx)\n",
 
 449                                 zfcp_get_busid_by_port(port),
 
 450                                 port->wwpn, (wwn_t) adisc->wwpn);
 
 451                 if (zfcp_erp_port_reopen(port, 0))
 
 452                         ZFCP_LOG_NORMAL("failed reopen of port "
 
 453                                         "(adapter %s, wwpn=0x%016Lx)\n",
 
 454                                         zfcp_get_busid_by_port(port),
 
 460         __free_pages(send_els->req->page, 0);
 
 461         kfree(send_els->timer);
 
 462         kfree(send_els->req);
 
 463         kfree(send_els->resp);
 
 469  * zfcp_test_link - lightweight link test procedure
 
 470  * @port: port to be tested
 
 472  * Test status of a link to a remote port using the ELS command ADISC.
 
 475 zfcp_test_link(struct zfcp_port *port)
 
 480         retval = zfcp_erp_adisc(port);
 
 483                 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
 
 484                                 "on adapter %s\n ", port->wwpn,
 
 485                                 zfcp_get_busid_by_port(port));
 
 486                 retval = zfcp_erp_port_forced_reopen(port, 0);
 
 488                         ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
 
 489                                         "on adapter %s failed\n", port->wwpn,
 
 490                                         zfcp_get_busid_by_port(port));
 
 502  * purpose:     called if a port failed to be opened normally
 
 503  *              initiates Forced Reopen recovery which is done
 
 506  * returns:     0       - initiated action succesfully
 
 507  *              <0      - failed to initiate action
 
 510 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
 
 513         struct zfcp_adapter *adapter = port->adapter;
 
 515         debug_text_event(adapter->erp_dbf, 5, "pf_ro");
 
 516         debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
 518         ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
 
 519                        port->wwpn, zfcp_get_busid_by_port(port));
 
 521         zfcp_erp_port_block(port, clear_mask);
 
 523         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
 
 524                 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
 
 525                                "on adapter %s\n", port->wwpn,
 
 526                                zfcp_get_busid_by_port(port));
 
 527                 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
 
 528                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
 533         retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
 
 534                                          port->adapter, port, NULL);
 
 543  * purpose:     Wrappper for zfcp_erp_port_forced_reopen_internal
 
 544  *              used to ensure the correct locking
 
 546  * returns:     0       - initiated action succesfully
 
 547  *              <0      - failed to initiate action
 
 550 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
 
 554         struct zfcp_adapter *adapter;
 
 556         adapter = port->adapter;
 
 557         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
 558         write_lock(&adapter->erp_lock);
 
 559         retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
 
 560         write_unlock(&adapter->erp_lock);
 
 561         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
 569  * purpose:     called if a port is to be opened
 
 570  *              initiates Reopen recovery which is done
 
 573  * returns:     0       - initiated action succesfully
 
 574  *              <0      - failed to initiate action
 
 577 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
 
 580         struct zfcp_adapter *adapter = port->adapter;
 
 582         debug_text_event(adapter->erp_dbf, 5, "p_ro");
 
 583         debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
 585         ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
 
 586                        port->wwpn, zfcp_get_busid_by_port(port));
 
 588         zfcp_erp_port_block(port, clear_mask);
 
 590         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
 
 591                 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
 
 592                                "on adapter %s\n", port->wwpn,
 
 593                                zfcp_get_busid_by_port(port));
 
 594                 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
 
 595                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
 596                 /* ensure propagation of failed status to new devices */
 
 597                 zfcp_erp_port_failed(port);
 
 602         retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
 
 603                                          port->adapter, port, NULL);
 
 610  * zfcp_erp_port_reopen - initiate reopen of a remote port
 
 611  * @port: port to be reopened
 
 612  * @clear_mask: specifies flags in port status to be cleared
 
 613  * Return: 0 on success, < 0 on error
 
 615  * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
 
 616  * correct locking. An error recovery task is initiated to do the reopen.
 
 617  * To wait for the completion of the reopen zfcp_erp_wait should be used.
 
 620 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
 
 624         struct zfcp_adapter *adapter = port->adapter;
 
 626         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
 627         write_lock(&adapter->erp_lock);
 
 628         retval = zfcp_erp_port_reopen_internal(port, clear_mask);
 
 629         write_unlock(&adapter->erp_lock);
 
 630         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
 638  * purpose:     called if a unit is to be opened
 
 639  *              initiates Reopen recovery which is done
 
 642  * returns:     0       - initiated action succesfully
 
 643  *              <0      - failed to initiate action
 
 646 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
 
 649         struct zfcp_adapter *adapter = unit->port->adapter;
 
 651         debug_text_event(adapter->erp_dbf, 5, "u_ro");
 
 652         debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
 
 653         ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
 
 654                        "on adapter %s\n", unit->fcp_lun,
 
 655                        unit->port->wwpn, zfcp_get_busid_by_unit(unit));
 
 657         zfcp_erp_unit_block(unit, clear_mask);
 
 659         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
 
 660                 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
 
 661                                "on port 0x%016Lx on adapter %s\n",
 
 662                                unit->fcp_lun, unit->port->wwpn,
 
 663                                zfcp_get_busid_by_unit(unit));
 
 664                 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
 
 665                 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
 
 671         retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
 
 672                                          unit->port->adapter, unit->port, unit);
 
 678  * zfcp_erp_unit_reopen - initiate reopen of a unit
 
 679  * @unit: unit to be reopened
 
 680  * @clear_mask: specifies flags in unit status to be cleared
 
 681  * Return: 0 on success, < 0 on error
 
 683  * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
 
 684  * locking. An error recovery task is initiated to do the reopen.
 
 685  * To wait for the completion of the reopen zfcp_erp_wait should be used.
 
 688 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
 
 692         struct zfcp_adapter *adapter;
 
 693         struct zfcp_port *port;
 
 696         adapter = port->adapter;
 
 698         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
 699         write_lock(&adapter->erp_lock);
 
 700         retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
 
 701         write_unlock(&adapter->erp_lock);
 
 702         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
 710  * purpose:     disable I/O,
 
 711  *              return any open requests and clean them up,
 
 712  *              aim: no pending and incoming I/O
 
 717 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
 
 719         debug_text_event(adapter->erp_dbf, 6, "a_bl");
 
 720         zfcp_erp_modify_adapter_status(adapter,
 
 721                                        ZFCP_STATUS_COMMON_UNBLOCKED |
 
 722                                        clear_mask, ZFCP_CLEAR);
 
 728  * purpose:     enable I/O
 
 733 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
 
 735         debug_text_event(adapter->erp_dbf, 6, "a_ubl");
 
 736         atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
 
 742  * purpose:     disable I/O,
 
 743  *              return any open requests and clean them up,
 
 744  *              aim: no pending and incoming I/O
 
 749 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
 
 751         struct zfcp_adapter *adapter = port->adapter;
 
 753         debug_text_event(adapter->erp_dbf, 6, "p_bl");
 
 754         debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
 
 755         zfcp_erp_modify_port_status(port,
 
 756                                     ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
 
 763  * purpose:     enable I/O
 
 768 zfcp_erp_port_unblock(struct zfcp_port *port)
 
 770         struct zfcp_adapter *adapter = port->adapter;
 
 772         debug_text_event(adapter->erp_dbf, 6, "p_ubl");
 
 773         debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
 
 774         atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
 
 780  * purpose:     disable I/O,
 
 781  *              return any open requests and clean them up,
 
 782  *              aim: no pending and incoming I/O
 
 787 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
 
 789         struct zfcp_adapter *adapter = unit->port->adapter;
 
 791         debug_text_event(adapter->erp_dbf, 6, "u_bl");
 
 792         debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
 
 793         zfcp_erp_modify_unit_status(unit,
 
 794                                     ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
 
 801  * purpose:     enable I/O
 
 806 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
 
 808         struct zfcp_adapter *adapter = unit->port->adapter;
 
 810         debug_text_event(adapter->erp_dbf, 6, "u_ubl");
 
 811         debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
 
 812         atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
 
 823 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
 
 825         struct zfcp_adapter *adapter = erp_action->adapter;
 
 827         debug_text_event(adapter->erp_dbf, 4, "a_ar");
 
 828         debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
 
 830         zfcp_erp_action_to_ready(erp_action);
 
 831         up(&adapter->erp_ready_sem);
 
 839  * returns:     <0                      erp_action not found in any list
 
 840  *              ZFCP_ERP_ACTION_READY   erp_action is in ready list
 
 841  *              ZFCP_ERP_ACTION_RUNNING erp_action is in running list
 
 843  * locks:       erp_lock must be held
 
 846 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
 
 848         int retval = -EINVAL;
 
 849         struct list_head *entry;
 
 850         struct zfcp_erp_action *entry_erp_action;
 
 851         struct zfcp_adapter *adapter = erp_action->adapter;
 
 853         /* search in running list */
 
 854         list_for_each(entry, &adapter->erp_running_head) {
 
 856                     list_entry(entry, struct zfcp_erp_action, list);
 
 857                 if (entry_erp_action == erp_action) {
 
 858                         retval = ZFCP_ERP_ACTION_RUNNING;
 
 862         /* search in ready list */
 
 863         list_for_each(entry, &adapter->erp_ready_head) {
 
 865                     list_entry(entry, struct zfcp_erp_action, list);
 
 866                 if (entry_erp_action == erp_action) {
 
 867                         retval = ZFCP_ERP_ACTION_READY;
 
 877  * purpose:     checks current status of action (timed out, dismissed, ...)
 
 878  *              and does appropriate preparations (dismiss fsf request, ...)
 
 880  * locks:       called under erp_lock (disabled interrupts)
 
 885 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
 
 888         struct zfcp_fsf_req *fsf_req = NULL;
 
 889         struct zfcp_adapter *adapter = erp_action->adapter;
 
 891         if (erp_action->fsf_req) {
 
 892                 /* take lock to ensure that request is not being deleted meanwhile */
 
 893                 spin_lock(&adapter->fsf_req_list_lock);
 
 894                 /* check whether fsf req does still exist */
 
 895                 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
 
 896                     if (fsf_req == erp_action->fsf_req)
 
 898                 if (fsf_req && (fsf_req->erp_action == erp_action)) {
 
 899                         /* fsf_req still exists */
 
 900                         debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
 
 901                         debug_event(adapter->erp_dbf, 3, &fsf_req,
 
 902                                     sizeof (unsigned long));
 
 903                         /* dismiss fsf_req of timed out or dismissed erp_action */
 
 904                         if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
 
 905                                                   ZFCP_STATUS_ERP_TIMEDOUT)) {
 
 906                                 debug_text_event(adapter->erp_dbf, 3,
 
 908                                 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
 
 910                         if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
 
 911                                 ZFCP_LOG_NORMAL("error: erp step timed out "
 
 912                                                 "(action=%d, fsf_req=%p)\n ",
 
 914                                                 erp_action->fsf_req);
 
 917                          * If fsf_req is neither dismissed nor completed
 
 918                          * then keep it running asynchronously and don't mess
 
 919                          * with the association of erp_action and fsf_req.
 
 921                         if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
 
 922                                                ZFCP_STATUS_FSFREQ_DISMISSED)) {
 
 923                                 /* forget about association between fsf_req
 
 925                                 fsf_req->erp_action = NULL;
 
 926                                 erp_action->fsf_req = NULL;
 
 929                         debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
 
 931                          * even if this fsf_req has gone, forget about
 
 932                          * association between erp_action and fsf_req
 
 934                         erp_action->fsf_req = NULL;
 
 936                 spin_unlock(&adapter->fsf_req_list_lock);
 
 938                 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
 
 944  * purpose:     generic handler for asynchronous events related to erp_action events
 
 945  *              (normal completion, time-out, dismissing, retry after
 
 946  *              low memory condition)
 
 948  * note:        deletion of timer is not required (e.g. in case of a time-out),
 
 949  *              but a second try does no harm,
 
 950  *              we leave it in here to allow for greater simplification
 
 952  * returns:     0 - there was an action to handle
 
 956 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
 
 957                               unsigned long set_mask)
 
 960         struct zfcp_adapter *adapter = erp_action->adapter;
 
 962         if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
 
 963                 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
 
 964                 debug_event(adapter->erp_dbf, 2, &erp_action->action,
 
 966                 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
 
 967                         del_timer(&erp_action->timer);
 
 968                 erp_action->status |= set_mask;
 
 969                 zfcp_erp_action_ready(erp_action);
 
 972                 /* action is ready or gone - nothing to do */
 
 973                 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
 
 974                 debug_event(adapter->erp_dbf, 3, &erp_action->action,
 
 983  * purpose:     generic handler for asynchronous events related to erp_action
 
 984  *               events (normal completion, time-out, dismissing, retry after
 
 985  *              low memory condition)
 
 987  * note:        deletion of timer is not required (e.g. in case of a time-out),
 
 988  *              but a second try does no harm,
 
 989  *              we leave it in here to allow for greater simplification
 
 991  * returns:     0 - there was an action to handle
 
 995 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
 
 996                        unsigned long set_mask)
 
 998         struct zfcp_adapter *adapter = erp_action->adapter;
 
1002         write_lock_irqsave(&adapter->erp_lock, flags);
 
1003         retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
 
1004         write_unlock_irqrestore(&adapter->erp_lock, flags);
 
1010  * purpose:     is called for erp_action which was slept waiting for
 
1011  *              memory becoming avaliable,
 
1012  *              will trigger that this action will be continued
 
1015 zfcp_erp_memwait_handler(unsigned long data)
 
1017         struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
 
1018         struct zfcp_adapter *adapter = erp_action->adapter;
 
1020         debug_text_event(adapter->erp_dbf, 2, "a_mwh");
 
1021         debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
 
1023         zfcp_erp_async_handler(erp_action, 0);
 
1027  * purpose:     is called if an asynchronous erp step timed out,
 
1028  *              action gets an appropriate flag and will be processed
 
1032 zfcp_erp_timeout_handler(unsigned long data)
 
1034         struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
 
1035         struct zfcp_adapter *adapter = erp_action->adapter;
 
1037         debug_text_event(adapter->erp_dbf, 2, "a_th");
 
1038         debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
 
1040         zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
 
1044  * purpose:     is called for an erp_action which needs to be ended
 
1045  *              though not being done,
 
1046  *              this is usually required if an higher is generated,
 
1047  *              action gets an appropriate flag and will be processed
 
1050  * locks:       erp_lock held (thus we need to call another handler variant)
 
1053 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
 
1055         struct zfcp_adapter *adapter = erp_action->adapter;
 
1057         debug_text_event(adapter->erp_dbf, 2, "a_adis");
 
1058         debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
 
1060         zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
 
1066 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
 
1070         atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
 
1072         retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
 
1074                 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
 
1076                                 zfcp_get_busid_by_adapter(adapter));
 
1077                 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
 
1079                 wait_event(adapter->erp_thread_wqh,
 
1080                            atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
 
1082                 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
 
1085         return (retval < 0);
 
1095  * context:     process (i.e. proc-fs or rmmod/insmod)
 
1097  * note:        The caller of this routine ensures that the specified
 
1098  *              adapter has been shut down and that this operation
 
1099  *              has been completed. Thus, there are no pending erp_actions
 
1100  *              which would need to be handled here.
 
1103 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
 
1107         atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
 
1108         up(&adapter->erp_ready_sem);
 
1110         wait_event(adapter->erp_thread_wqh,
 
1111                    !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
 
1114         atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
 
1117         debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
 
1123  * purpose:     is run as a kernel thread,
 
1124  *              goes through list of error recovery actions of associated adapter
 
1125  *              and delegates single action to execution
 
1130 zfcp_erp_thread(void *data)
 
1132         struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
 
1133         struct list_head *next;
 
1134         struct zfcp_erp_action *erp_action;
 
1135         unsigned long flags;
 
1137         daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
 
1138         /* Block all signals */
 
1139         siginitsetinv(¤t->blocked, 0);
 
1140         atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
 
1141         debug_text_event(adapter->erp_dbf, 5, "a_th_run");
 
1142         wake_up(&adapter->erp_thread_wqh);
 
1144         while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
 
1145                                  &adapter->status)) {
 
1147                 write_lock_irqsave(&adapter->erp_lock, flags);
 
1148                 next = adapter->erp_ready_head.prev;
 
1149                 write_unlock_irqrestore(&adapter->erp_lock, flags);
 
1151                 if (next != &adapter->erp_ready_head) {
 
1153                             list_entry(next, struct zfcp_erp_action, list);
 
1155                          * process action (incl. [re]moving it
 
1156                          * from 'ready' queue)
 
1158                         zfcp_erp_strategy(erp_action);
 
1162                  * sleep as long as there is nothing to do, i.e.
 
1163                  * no action in 'ready' queue to be processed and
 
1164                  * thread is not to be killed
 
1166                 down_interruptible(&adapter->erp_ready_sem);
 
1167                 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
 
1170         atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
 
1171         debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
 
1172         wake_up(&adapter->erp_thread_wqh);
 
1180  * purpose:     drives single error recovery action and schedules higher and
 
1181  *              subordinate actions, if necessary
 
1183  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
1184  *              ZFCP_ERP_SUCCEEDED      - action finished successfully (deqd)
 
1185  *              ZFCP_ERP_FAILED         - action finished unsuccessfully (deqd)
 
1186  *              ZFCP_ERP_EXIT           - action finished (dequeued), offline
 
1187  *              ZFCP_ERP_DISMISSED      - action canceled (dequeued)
 
1190 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
 
1193         struct zfcp_adapter *adapter = erp_action->adapter;
 
1194         struct zfcp_port *port = erp_action->port;
 
1195         struct zfcp_unit *unit = erp_action->unit;
 
1196         int action = erp_action->action;
 
1197         u32 status = erp_action->status;
 
1198         unsigned long flags;
 
1200         /* serialise dismissing, timing out, moving, enqueueing */
 
1201         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
1202         write_lock(&adapter->erp_lock);
 
1204         /* dequeue dismissed action and leave, if required */
 
1205         retval = zfcp_erp_strategy_check_action(erp_action, retval);
 
1206         if (retval == ZFCP_ERP_DISMISSED) {
 
1207                 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
 
1212          * move action to 'running' queue before processing it
 
1213          * (to avoid a race condition regarding moving the
 
1214          * action to the 'running' queue and back)
 
1216         zfcp_erp_action_to_running(erp_action);
 
1219          * try to process action as far as possible,
 
1220          * no lock to allow for blocking operations (kmalloc, qdio, ...),
 
1221          * afterwards the lock is required again for the following reasons:
 
1222          * - dequeueing of finished action and enqueueing of
 
1223          *   follow-up actions must be atomic so that any other
 
1224          *   reopen-routine does not believe there is nothing to do
 
1225          *   and that it is safe to enqueue something else,
 
1226          * - we want to force any control thread which is dismissing
 
1227          *   actions to finish this before we decide about
 
1228          *   necessary steps to be taken here further
 
1230         write_unlock(&adapter->erp_lock);
 
1231         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
1232         retval = zfcp_erp_strategy_do_action(erp_action);
 
1233         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
1234         write_lock(&adapter->erp_lock);
 
1237          * check for dismissed status again to avoid follow-up actions,
 
1238          * failing of targets and so on for dismissed actions
 
1240         retval = zfcp_erp_strategy_check_action(erp_action, retval);
 
1243         case ZFCP_ERP_DISMISSED:
 
1244                 /* leave since this action has ridden to its ancestors */
 
1245                 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
 
1247         case ZFCP_ERP_NOMEM:
 
1248                 /* no memory to continue immediately, let it sleep */
 
1249                 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
 
1250                         ++adapter->erp_low_mem_count;
 
1251                         erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
 
1253                 /* This condition is true if there is no memory available
 
1254                    for any erp_action on this adapter. This implies that there
 
1255                    are no elements in the memory pool(s) left for erp_actions.
 
1256                    This might happen if an erp_action that used a memory pool
 
1257                    element was timed out.
 
1259                 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
 
1260                         debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
 
1261                         ZFCP_LOG_NORMAL("error: no mempool elements available, "
 
1262                                         "restarting I/O on adapter %s "
 
1263                                         "to free mempool\n",
 
1264                                         zfcp_get_busid_by_adapter(adapter));
 
1265                         zfcp_erp_adapter_reopen_internal(adapter, 0);
 
1267                 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
 
1268                 retval = zfcp_erp_strategy_memwait(erp_action);
 
1271         case ZFCP_ERP_CONTINUES:
 
1272                 /* leave since this action runs asynchronously */
 
1273                 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
 
1274                 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
 
1275                         --adapter->erp_low_mem_count;
 
1276                         erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
 
1280         /* ok, finished action (whatever its result is) */
 
1282         /* check for unrecoverable targets */
 
1283         retval = zfcp_erp_strategy_check_target(erp_action, retval);
 
1285         /* action must be dequeued (here to allow for further ones) */
 
1286         zfcp_erp_action_dequeue(erp_action);
 
1289          * put this target through the erp mill again if someone has
 
1290          * requested to change the status of a target being online 
 
1291          * to offline or the other way around
 
1292          * (old retval is preserved if nothing has to be done here)
 
1294         retval = zfcp_erp_strategy_statechange(action, status, adapter,
 
1295                                                port, unit, retval);
 
1298          * leave if target is in permanent error state or if
 
1299          * action is repeated in order to process state change
 
1301         if (retval == ZFCP_ERP_EXIT) {
 
1302                 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
 
1306         /* trigger follow up actions */
 
1307         zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
 
1310         write_unlock(&adapter->erp_lock);
 
1311         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
1313         if (retval != ZFCP_ERP_CONTINUES)
 
1314                 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
 
1317          * a few tasks remain when the erp queues are empty
 
1318          * (don't do that if the last action evaluated was dismissed
 
1319          * since this clearly indicates that there is more to come) :
 
1320          * - close the name server port if it is open yet
 
1321          *   (enqueues another [probably] final action)
 
1322          * - otherwise, wake up whoever wants to be woken when we are
 
1325         if (retval != ZFCP_ERP_DISMISSED)
 
1326                 zfcp_erp_strategy_check_queues(adapter);
 
1328         debug_text_event(adapter->erp_dbf, 6, "a_st_done");
 
1338  * returns:     ZFCP_ERP_DISMISSED      - if action has been dismissed
 
1339  *              retval                  - otherwise
 
1342 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
 
1344         struct zfcp_adapter *adapter = erp_action->adapter;
 
1346         zfcp_erp_strategy_check_fsfreq(erp_action);
 
1348         debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
 
1349         if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
 
1350                 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
 
1351                 zfcp_erp_action_dequeue(erp_action);
 
1352                 retval = ZFCP_ERP_DISMISSED;
 
1354                 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
 
1367 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
 
1369         int retval = ZFCP_ERP_FAILED;
 
1370         struct zfcp_adapter *adapter = erp_action->adapter;
 
1373          * try to execute/continue action as far as possible,
 
1374          * note: no lock in subsequent strategy routines
 
1375          * (this allows these routine to call schedule, e.g.
 
1376          * kmalloc with such flags or qdio_initialize & friends)
 
1377          * Note: in case of timeout, the seperate strategies will fail
 
1378          * anyhow. No need for a special action. Even worse, a nameserver
 
1379          * failure would not wake up waiting ports without the call.
 
1381         switch (erp_action->action) {
 
1383         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
 
1384                 retval = zfcp_erp_adapter_strategy(erp_action);
 
1387         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
 
1388                 retval = zfcp_erp_port_forced_strategy(erp_action);
 
1391         case ZFCP_ERP_ACTION_REOPEN_PORT:
 
1392                 retval = zfcp_erp_port_strategy(erp_action);
 
1395         case ZFCP_ERP_ACTION_REOPEN_UNIT:
 
1396                 retval = zfcp_erp_unit_strategy(erp_action);
 
1400                 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
 
1401                 debug_event(adapter->erp_dbf, 1, &erp_action->action,
 
1403                 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
 
1404                                 "adapter %s (action=%d)\n",
 
1405                                 zfcp_get_busid_by_adapter(erp_action->adapter),
 
1406                                 erp_action->action);
 
1415  * purpose:     triggers retry of this action after a certain amount of time
 
1416  *              by means of timer provided by erp_action
 
1418  * returns:     ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
 
1421 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
 
1423         int retval = ZFCP_ERP_CONTINUES;
 
1424         struct zfcp_adapter *adapter = erp_action->adapter;
 
1426         debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
 
1427         debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
 
1428         init_timer(&erp_action->timer);
 
1429         erp_action->timer.function = zfcp_erp_memwait_handler;
 
1430         erp_action->timer.data = (unsigned long) erp_action;
 
1431         erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
 
1432         add_timer(&erp_action->timer);
 
1438  * function:    zfcp_erp_adapter_failed
 
1440  * purpose:     sets the adapter and all underlying devices to ERP_FAILED
 
1444 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
 
1446         zfcp_erp_modify_adapter_status(adapter,
 
1447                                        ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
 
1448         ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
 
1449                         zfcp_get_busid_by_adapter(adapter));
 
1450         debug_text_event(adapter->erp_dbf, 2, "a_afail");
 
1454  * function:    zfcp_erp_port_failed
 
1456  * purpose:     sets the port and all underlying devices to ERP_FAILED
 
1460 zfcp_erp_port_failed(struct zfcp_port *port)
 
1462         zfcp_erp_modify_port_status(port,
 
1463                                     ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
 
1465         if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
 
1466                 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
 
1467                                 "port d_id=0x%08x)\n",
 
1468                                 zfcp_get_busid_by_port(port), port->d_id);
 
1470                 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
 
1471                                 zfcp_get_busid_by_port(port), port->wwpn);
 
1473         debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
 
1474         debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
 
1478  * function:    zfcp_erp_unit_failed
 
1480  * purpose:     sets the unit to ERP_FAILED
 
1484 zfcp_erp_unit_failed(struct zfcp_unit *unit)
 
1486         zfcp_erp_modify_unit_status(unit,
 
1487                                     ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
 
1489         ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
 
1490                         " on adapter %s\n", unit->fcp_lun,
 
1491                         unit->port->wwpn, zfcp_get_busid_by_unit(unit));
 
1492         debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
 
1493         debug_event(unit->port->adapter->erp_dbf, 2,
 
1494                     &unit->fcp_lun, sizeof (fcp_lun_t));
 
1498  * function:    zfcp_erp_strategy_check_target
 
1500  * purpose:     increments the erp action count on the device currently in
 
1501  *              recovery if the action failed or resets the count in case of
 
1502  *              success. If a maximum count is exceeded the device is marked
 
1504  *              The 'blocked' state of a target which has been recovered
 
1505  *              successfully is reset.
 
1507  * returns:     ZFCP_ERP_CONTINUES      - action continues (not considered)
 
1508  *              ZFCP_ERP_SUCCEEDED      - action finished successfully 
 
1509  *              ZFCP_ERP_EXIT           - action failed and will not continue
 
1512 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
 
1514         struct zfcp_adapter *adapter = erp_action->adapter;
 
1515         struct zfcp_port *port = erp_action->port;
 
1516         struct zfcp_unit *unit = erp_action->unit;
 
1518         debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
 
1519         debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
 
1520         debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
 
1522         switch (erp_action->action) {
 
1524         case ZFCP_ERP_ACTION_REOPEN_UNIT:
 
1525                 result = zfcp_erp_strategy_check_unit(unit, result);
 
1528         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
 
1529         case ZFCP_ERP_ACTION_REOPEN_PORT:
 
1530                 result = zfcp_erp_strategy_check_port(port, result);
 
1533         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
 
1534                 result = zfcp_erp_strategy_check_adapter(adapter, result);
 
1549 zfcp_erp_strategy_statechange(int action,
 
1551                               struct zfcp_adapter *adapter,
 
1552                               struct zfcp_port *port,
 
1553                               struct zfcp_unit *unit, int retval)
 
1555         debug_text_event(adapter->erp_dbf, 3, "a_stsc");
 
1556         debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
 
1560         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
 
1561                 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
 
1563                         zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
 
1564                         retval = ZFCP_ERP_EXIT;
 
1568         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
 
1569         case ZFCP_ERP_ACTION_REOPEN_PORT:
 
1570                 if (zfcp_erp_strategy_statechange_detected(&port->status,
 
1572                         zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
 
1573                         retval = ZFCP_ERP_EXIT;
 
1577         case ZFCP_ERP_ACTION_REOPEN_UNIT:
 
1578                 if (zfcp_erp_strategy_statechange_detected(&unit->status,
 
1580                         zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
 
1581                         retval = ZFCP_ERP_EXIT;
 
1597 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
 
1600             /* take it online */
 
1601             (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
 
1602              (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
 
1603             /* take it offline */
 
1604             (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
 
1605              !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
 
1616 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
 
1618         debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
 
1619         debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
 
1620                     sizeof (fcp_lun_t));
 
1623         case ZFCP_ERP_SUCCEEDED :
 
1624                 atomic_set(&unit->erp_counter, 0);
 
1625                 zfcp_erp_unit_unblock(unit);
 
1627         case ZFCP_ERP_FAILED :
 
1628                 atomic_inc(&unit->erp_counter);
 
1629                 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
 
1630                         zfcp_erp_unit_failed(unit);
 
1632         case ZFCP_ERP_EXIT :
 
1637         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
 
1638                 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
 
1639                 result = ZFCP_ERP_EXIT;
 
1653 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
 
1655         debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
 
1656         debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
1659         case ZFCP_ERP_SUCCEEDED :
 
1660                 atomic_set(&port->erp_counter, 0);
 
1661                 zfcp_erp_port_unblock(port);
 
1663         case ZFCP_ERP_FAILED :
 
1664                 atomic_inc(&port->erp_counter);
 
1665                 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
 
1666                         zfcp_erp_port_failed(port);
 
1668         case ZFCP_ERP_EXIT :
 
1673         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
 
1674                 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
 
1675                 result = ZFCP_ERP_EXIT;
 
1689 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
 
1691         debug_text_event(adapter->erp_dbf, 5, "a_stct");
 
1694         case ZFCP_ERP_SUCCEEDED :
 
1695                 atomic_set(&adapter->erp_counter, 0);
 
1696                 zfcp_erp_adapter_unblock(adapter);
 
1698         case ZFCP_ERP_FAILED :
 
1699                 atomic_inc(&adapter->erp_counter);
 
1700                 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
 
1701                         zfcp_erp_adapter_failed(adapter);
 
1703         case ZFCP_ERP_EXIT :
 
1708         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
 
1709                 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
 
1710                 result = ZFCP_ERP_EXIT;
 
1719  * purpose:     remaining things in good cases,
 
1720  *              escalation in bad cases
 
1725 zfcp_erp_strategy_followup_actions(int action,
 
1726                                    struct zfcp_adapter *adapter,
 
1727                                    struct zfcp_port *port,
 
1728                                    struct zfcp_unit *unit, int status)
 
1730         debug_text_event(adapter->erp_dbf, 5, "a_stfol");
 
1731         debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
 
1733         /* initiate follow-up actions depending on success of finished action */
 
1736         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
 
1737                 if (status == ZFCP_ERP_SUCCEEDED)
 
1738                         zfcp_erp_port_reopen_all_internal(adapter, 0);
 
1740                         zfcp_erp_adapter_reopen_internal(adapter, 0);
 
1743         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
 
1744                 if (status == ZFCP_ERP_SUCCEEDED)
 
1745                         zfcp_erp_port_reopen_internal(port, 0);
 
1747                         zfcp_erp_adapter_reopen_internal(adapter, 0);
 
1750         case ZFCP_ERP_ACTION_REOPEN_PORT:
 
1751                 if (status == ZFCP_ERP_SUCCEEDED)
 
1752                         zfcp_erp_unit_reopen_all_internal(port, 0);
 
1754                         zfcp_erp_port_forced_reopen_internal(port, 0);
 
1757         case ZFCP_ERP_ACTION_REOPEN_UNIT:
 
1758                 if (status == ZFCP_ERP_SUCCEEDED) ;     /* no further action */
 
1760                         zfcp_erp_port_reopen_internal(unit->port, 0);
 
1775 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
 
1777         unsigned long flags;
 
1779         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
1780         read_lock(&adapter->erp_lock);
 
1781         if (list_empty(&adapter->erp_ready_head) &&
 
1782             list_empty(&adapter->erp_running_head)) {
 
1783                         debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
 
1784                         atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
 
1786                         wake_up(&adapter->erp_done_wqh);
 
1788                 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
 
1789         read_unlock(&adapter->erp_lock);
 
1790         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
1796  * zfcp_erp_wait - wait for completion of error recovery on an adapter
 
1797  * @adapter: adapter for which to wait for completion of its error recovery
 
1801 zfcp_erp_wait(struct zfcp_adapter *adapter)
 
1805         wait_event(adapter->erp_done_wqh,
 
1806                    !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
 
1813  * function:    zfcp_erp_modify_adapter_status
 
1819 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
 
1820                                u32 mask, int set_or_clear)
 
1822         struct zfcp_port *port;
 
1823         u32 common_mask = mask & ZFCP_COMMON_FLAGS;
 
1825         if (set_or_clear == ZFCP_SET) {
 
1826                 atomic_set_mask(mask, &adapter->status);
 
1827                 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
 
1829                 atomic_clear_mask(mask, &adapter->status);
 
1830                 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
 
1831                         atomic_set(&adapter->erp_counter, 0);
 
1832                 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
 
1834         debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
 
1836         /* Deal with all underlying devices, only pass common_mask */
 
1838                 list_for_each_entry(port, &adapter->port_list_head, list)
 
1839                     zfcp_erp_modify_port_status(port, common_mask,
 
1844  * function:    zfcp_erp_modify_port_status
 
1846  * purpose:     sets the port and all underlying devices to ERP_FAILED
 
1850 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
 
1852         struct zfcp_unit *unit;
 
1853         u32 common_mask = mask & ZFCP_COMMON_FLAGS;
 
1855         if (set_or_clear == ZFCP_SET) {
 
1856                 atomic_set_mask(mask, &port->status);
 
1857                 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
 
1859                 atomic_clear_mask(mask, &port->status);
 
1860                 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
 
1861                         atomic_set(&port->erp_counter, 0);
 
1862                 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
 
1864         debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
 
1865         debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
 
1867         /* Modify status of all underlying devices, only pass common mask */
 
1869                 list_for_each_entry(unit, &port->unit_list_head, list)
 
1870                     zfcp_erp_modify_unit_status(unit, common_mask,
 
1875  * function:    zfcp_erp_modify_unit_status
 
1877  * purpose:     sets the unit to ERP_FAILED
 
1881 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
 
1883         if (set_or_clear == ZFCP_SET) {
 
1884                 atomic_set_mask(mask, &unit->status);
 
1885                 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
 
1887                 atomic_clear_mask(mask, &unit->status);
 
1888                 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
 
1889                         atomic_set(&unit->erp_counter, 0);
 
1891                 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
 
1893         debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
 
1894                     sizeof (fcp_lun_t));
 
1895         debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
 
1901  * purpose:     Wrappper for zfcp_erp_port_reopen_all_internal
 
1902  *              used to ensure the correct locking
 
1904  * returns:     0       - initiated action succesfully
 
1905  *              <0      - failed to initiate action
 
1908 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
 
1911         unsigned long flags;
 
1913         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
1914         write_lock(&adapter->erp_lock);
 
1915         retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
 
1916         write_unlock(&adapter->erp_lock);
 
1917         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
1930 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
 
1933         struct zfcp_port *port;
 
1935         list_for_each_entry(port, &adapter->port_list_head, list)
 
1936                 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
 
1937                         zfcp_erp_port_reopen_internal(port, clear_mask);
 
1950 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
 
1953         struct zfcp_unit *unit;
 
1955         list_for_each_entry(unit, &port->unit_list_head, list)
 
1956             zfcp_erp_unit_reopen_internal(unit, clear_mask);
 
1964  * purpose:     this routine executes the 'Reopen Adapter' action
 
1965  *              (the entire action is processed synchronously, since
 
1966  *              there are no actions which might be run concurrently
 
1969  * returns:     ZFCP_ERP_SUCCEEDED      - action finished successfully
 
1970  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
1973 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
 
1976         struct zfcp_adapter *adapter = erp_action->adapter;
 
1978         retval = zfcp_erp_adapter_strategy_close(erp_action);
 
1979         if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
 
1980                 retval = ZFCP_ERP_EXIT;
 
1982                 retval = zfcp_erp_adapter_strategy_open(erp_action);
 
1984         debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
 
1985         debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
 
1986         debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
 
1988         if (retval == ZFCP_ERP_FAILED) {
 
1989                 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
 
1990                               "to recover itself\n",
 
1991                               zfcp_get_busid_by_adapter(adapter));
 
1992                 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
 
2003  * returns:     ZFCP_ERP_SUCCEEDED      - action finished successfully
 
2004  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2007 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
 
2011         atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
 
2012                         &erp_action->adapter->status);
 
2013         retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
 
2014         atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
 
2015                           &erp_action->adapter->status);
 
2025  * returns:     ZFCP_ERP_SUCCEEDED      - action finished successfully
 
2026  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2029 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
 
2033         atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
 
2034                         &erp_action->adapter->status);
 
2035         retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
 
2036         atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
 
2037                           &erp_action->adapter->status);
 
2043  * function:    zfcp_register_adapter
 
2045  * purpose:     allocate the irq associated with this devno and register
 
2046  *              the FSF adapter with the SCSI stack
 
2051 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
 
2053         int retval = ZFCP_ERP_SUCCEEDED;
 
2058         retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
 
2059         if (retval != ZFCP_ERP_SUCCEEDED)
 
2062         retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
 
2063         if (retval != ZFCP_ERP_SUCCEEDED)
 
2064                 goto failed_openfcp;
 
2066         atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
 
2070         atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
 
2071                           &erp_action->adapter->status);
 
2074         zfcp_erp_adapter_strategy_close_qdio(erp_action);
 
2075         zfcp_erp_adapter_strategy_close_fsf(erp_action);
 
2082  * function:    zfcp_qdio_init
 
2084  * purpose:     setup QDIO operation for specified adapter
 
2086  * returns:     0 - successful setup
 
2090 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
 
2094         volatile struct qdio_buffer_element *sbale;
 
2095         struct zfcp_adapter *adapter = erp_action->adapter;
 
2097         if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
 
2098                 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
 
2100                                 zfcp_get_busid_by_adapter(adapter));
 
2104         if (qdio_establish(&adapter->qdio_init_data) != 0) {
 
2105                 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
 
2107                               zfcp_get_busid_by_adapter(adapter));
 
2108                 goto failed_qdio_establish;
 
2110         debug_text_event(adapter->erp_dbf, 3, "qdio_est");
 
2112         if (qdio_activate(adapter->ccw_device, 0) != 0) {
 
2113                 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
 
2115                               zfcp_get_busid_by_adapter(adapter));
 
2116                 goto failed_qdio_activate;
 
2118         debug_text_event(adapter->erp_dbf, 3, "qdio_act");
 
2121          * put buffers into response queue,
 
2123         for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
 
2124                 sbale = &(adapter->response_queue.buffer[i]->element[0]);
 
2126                 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
 
2130         ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
 
2131                        "queue_no=%i, index_in_queue=%i, count=%i)\n",
 
2132                        zfcp_get_busid_by_adapter(adapter),
 
2133                        QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
 
2135         retval = do_QDIO(adapter->ccw_device,
 
2136                          QDIO_FLAG_SYNC_INPUT,
 
2137                          0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
 
2140                 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
 
2142                 goto failed_do_qdio;
 
2144                 adapter->response_queue.free_index = 0;
 
2145                 atomic_set(&adapter->response_queue.free_count, 0);
 
2146                 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
 
2147                                "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
 
2149         /* set index of first avalable SBALS / number of available SBALS */
 
2150         adapter->request_queue.free_index = 0;
 
2151         atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
 
2152         adapter->request_queue.distance_from_int = 0;
 
2154         /* initialize waitqueue used to wait for free SBALs in requests queue */
 
2155         init_waitqueue_head(&adapter->request_wq);
 
2157         /* ok, we did it - skip all cleanups for different failures */
 
2158         atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
 
2159         retval = ZFCP_ERP_SUCCEEDED;
 
2165  failed_qdio_activate:
 
2166         debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
 
2167         while (qdio_shutdown(adapter->ccw_device,
 
2168                              QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
 
2170         debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
 
2172  failed_qdio_establish:
 
2174         retval = ZFCP_ERP_FAILED;
 
2181  * function:    zfcp_qdio_cleanup
 
2183  * purpose:     cleans up QDIO operation for the specified adapter
 
2185  * returns:     0 - successful cleanup
 
2186  *              !0 - failed cleanup
 
2189 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
 
2191         int retval = ZFCP_ERP_SUCCEEDED;
 
2194         struct zfcp_adapter *adapter = erp_action->adapter;
 
2196         if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
 
2197                 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
 
2198                                "queues on adapter %s\n",
 
2199                                zfcp_get_busid_by_adapter(adapter));
 
2200                 retval = ZFCP_ERP_FAILED;
 
2205          * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
 
2206          * do_QDIO won't be called while qdio_shutdown is in progress.
 
2209         write_lock_irq(&adapter->request_queue.queue_lock);
 
2210         atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
 
2211         write_unlock_irq(&adapter->request_queue.queue_lock);
 
2213         debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
 
2214         while (qdio_shutdown(adapter->ccw_device,
 
2215                              QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
 
2217         debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
 
2220          * First we had to stop QDIO operation.
 
2221          * Now it is safe to take the following actions.
 
2224         /* Cleanup only necessary when there are unacknowledged buffers */
 
2225         if (atomic_read(&adapter->request_queue.free_count)
 
2226             < QDIO_MAX_BUFFERS_PER_Q) {
 
2227                 first_used = (adapter->request_queue.free_index +
 
2228                               atomic_read(&adapter->request_queue.free_count))
 
2229                         % QDIO_MAX_BUFFERS_PER_Q;
 
2230                 used_count = QDIO_MAX_BUFFERS_PER_Q -
 
2231                         atomic_read(&adapter->request_queue.free_count);
 
2232                 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
 
2233                                      first_used, used_count);
 
2235         adapter->response_queue.free_index = 0;
 
2236         atomic_set(&adapter->response_queue.free_count, 0);
 
2237         adapter->request_queue.free_index = 0;
 
2238         atomic_set(&adapter->request_queue.free_count, 0);
 
2239         adapter->request_queue.distance_from_int = 0;
 
2245 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
 
2249         retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
 
2250         if (retval == ZFCP_ERP_FAILED)
 
2251                 return ZFCP_ERP_FAILED;
 
2253         retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
 
2254         if (retval == ZFCP_ERP_FAILED)
 
2255                 return ZFCP_ERP_FAILED;
 
2257         return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
 
2261 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
 
2263         int retval = ZFCP_ERP_SUCCEEDED;
 
2265         int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
 
2266         struct zfcp_adapter *adapter = erp_action->adapter;
 
2268         atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
 
2270         for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
 
2271                 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
 
2273                 ZFCP_LOG_DEBUG("Doing exchange config data\n");
 
2274                 write_lock(&adapter->erp_lock);
 
2275                 zfcp_erp_action_to_running(erp_action);
 
2276                 write_unlock(&adapter->erp_lock);
 
2277                 zfcp_erp_timeout_init(erp_action);
 
2278                 if (zfcp_fsf_exchange_config_data(erp_action)) {
 
2279                         retval = ZFCP_ERP_FAILED;
 
2280                         debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
 
2281                         ZFCP_LOG_INFO("error:  initiation of exchange of "
 
2282                                       "configuration data failed for "
 
2284                                       zfcp_get_busid_by_adapter(adapter));
 
2287                 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
 
2288                 ZFCP_LOG_DEBUG("Xchange underway\n");
 
2292                  * Both the normal completion handler as well as the timeout
 
2293                  * handler will do an 'up' when the 'exchange config data'
 
2294                  * request completes or times out. Thus, the signal to go on
 
2295                  * won't be lost utilizing this semaphore.
 
2296                  * Furthermore, this 'adapter_reopen' action is
 
2297                  * guaranteed to be the only action being there (highest action
 
2298                  * which prevents other actions from being created).
 
2299                  * Resulting from that, the wake signal recognized here
 
2300                  * _must_ be the one belonging to the 'exchange config
 
2303                 down(&adapter->erp_ready_sem);
 
2304                 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
 
2305                         ZFCP_LOG_INFO("error: exchange of configuration data "
 
2306                                       "for adapter %s timed out\n",
 
2307                                       zfcp_get_busid_by_adapter(adapter));
 
2311                 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
 
2315                 ZFCP_LOG_DEBUG("host connection still initialising... "
 
2316                                "waiting and retrying...\n");
 
2317                 /* sleep a little bit before retry */
 
2318                 msleep(jiffies_to_msecs(sleep));
 
2322         if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
 
2323                               &adapter->status)) {
 
2324                 ZFCP_LOG_INFO("error: exchange of configuration data for "
 
2325                               "adapter %s failed\n",
 
2326                               zfcp_get_busid_by_adapter(adapter));
 
2327                 retval = ZFCP_ERP_FAILED;
 
2334 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
 
2337         struct zfcp_adapter *adapter;
 
2339         adapter = erp_action->adapter;
 
2340         atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
 
2342         write_lock(&adapter->erp_lock);
 
2343         zfcp_erp_action_to_running(erp_action);
 
2344         write_unlock(&adapter->erp_lock);
 
2346         zfcp_erp_timeout_init(erp_action);
 
2347         ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL);
 
2348         if (ret == -EOPNOTSUPP) {
 
2349                 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
 
2350                 return ZFCP_ERP_SUCCEEDED;
 
2352                 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
 
2353                 return ZFCP_ERP_FAILED;
 
2355         debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
 
2357         ret = ZFCP_ERP_SUCCEEDED;
 
2358         down(&adapter->erp_ready_sem);
 
2359         if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
 
2360                 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
 
2361                               "%s)\n", zfcp_get_busid_by_adapter(adapter));
 
2362                 ret = ZFCP_ERP_FAILED;
 
2364         if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status)) {
 
2365                 ZFCP_LOG_INFO("error: exchange port data failed (adapter "
 
2366                               "%s\n", zfcp_get_busid_by_adapter(adapter));
 
2367                 ret = ZFCP_ERP_FAILED;
 
2381 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
 
2384         int retval = ZFCP_ERP_SUCCEEDED;
 
2386         struct zfcp_adapter *adapter = erp_action->adapter;
 
2389         adapter->status_read_failed = 0;
 
2390         for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
 
2391                 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
 
2393                         ZFCP_LOG_INFO("error: set-up of unsolicited status "
 
2394                                       "notification failed on adapter %s\n",
 
2395                                       zfcp_get_busid_by_adapter(adapter));
 
2396                         retval = ZFCP_ERP_FAILED;
 
2406  * function:    zfcp_fsf_cleanup
 
2408  * purpose:     cleanup FSF operation for specified adapter
 
2410  * returns:     0 - FSF operation successfully cleaned up
 
2411  *              !0 - failed to cleanup FSF operation for this adapter
 
2414 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
 
2416         int retval = ZFCP_ERP_SUCCEEDED;
 
2417         struct zfcp_adapter *adapter = erp_action->adapter;
 
2420          * wake waiting initiators of requests,
 
2421          * return SCSI commands (with error status),
 
2422          * clean up all requests (synchronously)
 
2424         zfcp_fsf_req_dismiss_all(adapter);
 
2425         /* reset FSF request sequence number */
 
2426         adapter->fsf_req_seq_no = 0;
 
2427         /* all ports and units are closed */
 
2428         zfcp_erp_modify_adapter_status(adapter,
 
2429                                        ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
 
2437  * purpose:     this routine executes the 'Reopen Physical Port' action
 
2439  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
2440  *              ZFCP_ERP_SUCCEEDED      - action finished successfully
 
2441  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2444 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
 
2446         int retval = ZFCP_ERP_FAILED;
 
2447         struct zfcp_port *port = erp_action->port;
 
2448         struct zfcp_adapter *adapter = erp_action->adapter;
 
2450         switch (erp_action->step) {
 
2454                  * the ULP spec. begs for waiting for oustanding commands
 
2456         case ZFCP_ERP_STEP_UNINITIALIZED:
 
2457                 zfcp_erp_port_strategy_clearstati(port);
 
2459                  * it would be sufficient to test only the normal open flag
 
2460                  * since the phys. open flag cannot be set if the normal
 
2461                  * open flag is unset - however, this is for readabilty ...
 
2463                 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
 
2464                                       ZFCP_STATUS_COMMON_OPEN),
 
2466                         ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
 
2467                                        "close physical\n", port->wwpn);
 
2469                             zfcp_erp_port_forced_strategy_close(erp_action);
 
2471                         retval = ZFCP_ERP_FAILED;
 
2474         case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
 
2475                 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
 
2477                         ZFCP_LOG_DEBUG("close physical failed for port "
 
2478                                        "0x%016Lx\n", port->wwpn);
 
2479                         retval = ZFCP_ERP_FAILED;
 
2481                         retval = ZFCP_ERP_SUCCEEDED;
 
2485         debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
 
2486         debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
 
2487         debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
 
2488         debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
 
2496  * purpose:     this routine executes the 'Reopen Port' action
 
2498  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
2499  *              ZFCP_ERP_SUCCEEDED      - action finished successfully
 
2500  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2503 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
 
2505         int retval = ZFCP_ERP_FAILED;
 
2506         struct zfcp_port *port = erp_action->port;
 
2507         struct zfcp_adapter *adapter = erp_action->adapter;
 
2509         switch (erp_action->step) {
 
2513                  * the ULP spec. begs for waiting for oustanding commands
 
2515         case ZFCP_ERP_STEP_UNINITIALIZED:
 
2516                 zfcp_erp_port_strategy_clearstati(port);
 
2517                 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
 
2518                         ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
 
2519                                        "close\n", port->wwpn);
 
2520                         retval = zfcp_erp_port_strategy_close(erp_action);
 
2522                 }               /* else it's already closed, open it */
 
2525         case ZFCP_ERP_STEP_PORT_CLOSING:
 
2526                 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
 
2527                         ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
 
2529                         retval = ZFCP_ERP_FAILED;
 
2531                 }               /* else it's closed now, open it */
 
2534         if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
 
2535                 retval = ZFCP_ERP_EXIT;
 
2537                 retval = zfcp_erp_port_strategy_open(erp_action);
 
2540         debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
 
2541         debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
 
2542         debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
 
2543         debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
 
2556 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
 
2560         if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
 
2561                              &erp_action->port->status))
 
2562                 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
 
2564                 retval = zfcp_erp_port_strategy_open_common(erp_action);
 
2576  * FIXME(design):       currently only prepared for fabric (nameserver!)
 
2579 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
 
2582         struct zfcp_adapter *adapter = erp_action->adapter;
 
2583         struct zfcp_port *port = erp_action->port;
 
2585         switch (erp_action->step) {
 
2587         case ZFCP_ERP_STEP_UNINITIALIZED:
 
2588         case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
 
2589         case ZFCP_ERP_STEP_PORT_CLOSING:
 
2590                 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
 
2591                         if (port->wwpn != adapter->peer_wwpn) {
 
2592                                 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
 
2593                                                 "on adapter %s.\nPeer WWPN "
 
2594                                                 "0x%016Lx does not match\n",
 
2596                                                 zfcp_get_busid_by_adapter(adapter),
 
2597                                                 adapter->peer_wwpn);
 
2598                                 zfcp_erp_port_failed(port);
 
2599                                 retval = ZFCP_ERP_FAILED;
 
2602                         port->d_id = adapter->peer_d_id;
 
2603                         atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
 
2604                         retval = zfcp_erp_port_strategy_open_port(erp_action);
 
2607                 if (!(adapter->nameserver_port)) {
 
2608                         retval = zfcp_nameserver_enqueue(adapter);
 
2610                                 ZFCP_LOG_NORMAL("error: nameserver port "
 
2611                                                 "unavailable for adapter %s\n",
 
2612                                                 zfcp_get_busid_by_adapter(adapter));
 
2613                                 retval = ZFCP_ERP_FAILED;
 
2617                 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
 
2618                                       &adapter->nameserver_port->status)) {
 
2619                         ZFCP_LOG_DEBUG("nameserver port is not open -> open "
 
2620                                        "nameserver port\n");
 
2621                         /* nameserver port may live again */
 
2622                         atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
 
2623                                         &adapter->nameserver_port->status);
 
2624                         if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
 
2627                                         ZFCP_ERP_STEP_NAMESERVER_OPEN;
 
2628                                 retval = ZFCP_ERP_CONTINUES;
 
2630                                 retval = ZFCP_ERP_FAILED;
 
2633                 /* else nameserver port is already open, fall through */
 
2634         case ZFCP_ERP_STEP_NAMESERVER_OPEN:
 
2635                 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
 
2636                                       &adapter->nameserver_port->status)) {
 
2637                         ZFCP_LOG_DEBUG("open failed for nameserver port\n");
 
2638                         retval = ZFCP_ERP_FAILED;
 
2640                         ZFCP_LOG_DEBUG("nameserver port is open -> "
 
2641                                        "nameserver look-up for port 0x%016Lx\n",
 
2643                         retval = zfcp_erp_port_strategy_open_common_lookup
 
2648         case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
 
2649                 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
 
2650                         if (atomic_test_mask
 
2651                             (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
 
2652                                 ZFCP_LOG_DEBUG("nameserver look-up failed "
 
2653                                                "for port 0x%016Lx "
 
2654                                                "(misconfigured WWPN?)\n",
 
2656                                 zfcp_erp_port_failed(port);
 
2657                                 retval = ZFCP_ERP_EXIT;
 
2659                                 ZFCP_LOG_DEBUG("nameserver look-up failed for "
 
2660                                                "port 0x%016Lx\n", port->wwpn);
 
2661                                 retval = ZFCP_ERP_FAILED;
 
2664                         ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
 
2665                                        "trying open\n", port->wwpn, port->d_id);
 
2666                         retval = zfcp_erp_port_strategy_open_port(erp_action);
 
2670         case ZFCP_ERP_STEP_PORT_OPENING:
 
2671                 /* D_ID might have changed during open */
 
2672                 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
 
2673                                       ZFCP_STATUS_PORT_DID_DID),
 
2675                         ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
 
2676                         retval = ZFCP_ERP_SUCCEEDED;
 
2678                         ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
 
2680                         retval = ZFCP_ERP_FAILED;
 
2685                 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
 
2687                 retval = ZFCP_ERP_FAILED;
 
2701 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
 
2704         struct zfcp_port *port = erp_action->port;
 
2706         switch (erp_action->step) {
 
2708         case ZFCP_ERP_STEP_UNINITIALIZED:
 
2709         case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
 
2710         case ZFCP_ERP_STEP_PORT_CLOSING:
 
2711                 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
 
2712                                port->wwpn, port->d_id);
 
2713                 retval = zfcp_erp_port_strategy_open_port(erp_action);
 
2716         case ZFCP_ERP_STEP_PORT_OPENING:
 
2717                 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
 
2718                         ZFCP_LOG_DEBUG("WKA port is open\n");
 
2719                         retval = ZFCP_ERP_SUCCEEDED;
 
2721                         ZFCP_LOG_DEBUG("open failed for WKA port\n");
 
2722                         retval = ZFCP_ERP_FAILED;
 
2724                 /* this is needed anyway (dont care for retval of wakeup) */
 
2725                 ZFCP_LOG_DEBUG("continue other open port operations\n");
 
2726                 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
 
2730                 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
 
2732                 retval = ZFCP_ERP_FAILED;
 
2741  * purpose:     makes the erp thread continue with reopen (physical) port
 
2742  *              actions which have been paused until the name server port
 
2743  *              is opened (or failed)
 
2745  * returns:     0       (a kind of void retval, its not used)
 
2748 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
 
2752         unsigned long flags;
 
2753         struct zfcp_adapter *adapter = ns_erp_action->adapter;
 
2754         struct zfcp_erp_action *erp_action, *tmp;
 
2756         read_lock_irqsave(&adapter->erp_lock, flags);
 
2757         list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
 
2759                 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
 
2760                 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
 
2762                 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
 
2763                         debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
 
2764                         debug_event(adapter->erp_dbf, 3,
 
2765                                     &erp_action->port->wwpn, sizeof (wwn_t));
 
2766                         if (atomic_test_mask(
 
2767                                     ZFCP_STATUS_COMMON_ERP_FAILED,
 
2768                                     &adapter->nameserver_port->status))
 
2769                                 zfcp_erp_port_failed(erp_action->port);
 
2770                         zfcp_erp_action_ready(erp_action);
 
2773         read_unlock_irqrestore(&adapter->erp_lock, flags);
 
2783  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
2784  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2787 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
 
2790         struct zfcp_adapter *adapter = erp_action->adapter;
 
2791         struct zfcp_port *port = erp_action->port;
 
2793         zfcp_erp_timeout_init(erp_action);
 
2794         retval = zfcp_fsf_close_physical_port(erp_action);
 
2795         if (retval == -ENOMEM) {
 
2796                 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
 
2797                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2798                 retval = ZFCP_ERP_NOMEM;
 
2801         erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
 
2803                 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
 
2804                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2805                 /* could not send 'open', fail */
 
2806                 retval = ZFCP_ERP_FAILED;
 
2809         debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
 
2810         debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
 
2811         retval = ZFCP_ERP_CONTINUES;
 
2824 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
 
2827         struct zfcp_adapter *adapter = port->adapter;
 
2829         debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
 
2830         debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2832         atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
 
2833                           ZFCP_STATUS_COMMON_CLOSING |
 
2834                           ZFCP_STATUS_COMMON_ACCESS_DENIED |
 
2835                           ZFCP_STATUS_PORT_DID_DID |
 
2836                           ZFCP_STATUS_PORT_PHYS_CLOSING |
 
2837                           ZFCP_STATUS_PORT_INVALID_WWPN,
 
2847  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
2848  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2851 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
 
2854         struct zfcp_adapter *adapter = erp_action->adapter;
 
2855         struct zfcp_port *port = erp_action->port;
 
2857         zfcp_erp_timeout_init(erp_action);
 
2858         retval = zfcp_fsf_close_port(erp_action);
 
2859         if (retval == -ENOMEM) {
 
2860                 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
 
2861                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2862                 retval = ZFCP_ERP_NOMEM;
 
2865         erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
 
2867                 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
 
2868                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2869                 /* could not send 'close', fail */
 
2870                 retval = ZFCP_ERP_FAILED;
 
2873         debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
 
2874         debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
 
2875         retval = ZFCP_ERP_CONTINUES;
 
2885  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
2886  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2889 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
 
2892         struct zfcp_adapter *adapter = erp_action->adapter;
 
2893         struct zfcp_port *port = erp_action->port;
 
2895         zfcp_erp_timeout_init(erp_action);
 
2896         retval = zfcp_fsf_open_port(erp_action);
 
2897         if (retval == -ENOMEM) {
 
2898                 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
 
2899                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2900                 retval = ZFCP_ERP_NOMEM;
 
2903         erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
 
2905                 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
 
2906                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2907                 /* could not send 'open', fail */
 
2908                 retval = ZFCP_ERP_FAILED;
 
2911         debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
 
2912         debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
 
2913         retval = ZFCP_ERP_CONTINUES;
 
2923  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
2924  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2927 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
 
2930         struct zfcp_adapter *adapter = erp_action->adapter;
 
2931         struct zfcp_port *port = erp_action->port;
 
2933         zfcp_erp_timeout_init(erp_action);
 
2934         retval = zfcp_ns_gid_pn_request(erp_action);
 
2935         if (retval == -ENOMEM) {
 
2936                 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
 
2937                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2938                 retval = ZFCP_ERP_NOMEM;
 
2941         erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
 
2943                 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
 
2944                 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
2945                 /* could not send nameserver request, fail */
 
2946                 retval = ZFCP_ERP_FAILED;
 
2949         debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
 
2950         debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
 
2951         retval = ZFCP_ERP_CONTINUES;
 
2959  * purpose:     this routine executes the 'Reopen Unit' action
 
2960  *              currently no retries
 
2962  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
2963  *              ZFCP_ERP_SUCCEEDED      - action finished successfully
 
2964  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
2967 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
 
2969         int retval = ZFCP_ERP_FAILED;
 
2970         struct zfcp_unit *unit = erp_action->unit;
 
2971         struct zfcp_adapter *adapter = erp_action->adapter;
 
2973         switch (erp_action->step) {
 
2977                  * the ULP spec. begs for waiting for oustanding commands
 
2979         case ZFCP_ERP_STEP_UNINITIALIZED:
 
2980                 zfcp_erp_unit_strategy_clearstati(unit);
 
2981                 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
 
2982                         ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
 
2983                                        "trying close\n", unit->fcp_lun);
 
2984                         retval = zfcp_erp_unit_strategy_close(erp_action);
 
2987                 /* else it's already closed, fall through */
 
2988         case ZFCP_ERP_STEP_UNIT_CLOSING:
 
2989                 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
 
2990                         ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
 
2992                         retval = ZFCP_ERP_FAILED;
 
2994                         if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
 
2995                                 retval = ZFCP_ERP_EXIT;
 
2997                                 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
 
2998                                                "trying open\n", unit->fcp_lun);
 
3000                                     zfcp_erp_unit_strategy_open(erp_action);
 
3005         case ZFCP_ERP_STEP_UNIT_OPENING:
 
3006                 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
 
3007                         ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
 
3009                         retval = ZFCP_ERP_SUCCEEDED;
 
3011                         ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
 
3013                         retval = ZFCP_ERP_FAILED;
 
3018         debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
 
3019         debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
 
3020         debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
 
3021         debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
 
3033 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
 
3036         struct zfcp_adapter *adapter = unit->port->adapter;
 
3038         debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
 
3039         debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
 
3041         atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
 
3042                           ZFCP_STATUS_COMMON_CLOSING |
 
3043                           ZFCP_STATUS_COMMON_ACCESS_DENIED |
 
3044                           ZFCP_STATUS_UNIT_SHARED |
 
3045                           ZFCP_STATUS_UNIT_READONLY,
 
3056  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
3057  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
3060 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
 
3063         struct zfcp_adapter *adapter = erp_action->adapter;
 
3064         struct zfcp_unit *unit = erp_action->unit;
 
3066         zfcp_erp_timeout_init(erp_action);
 
3067         retval = zfcp_fsf_close_unit(erp_action);
 
3068         if (retval == -ENOMEM) {
 
3069                 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
 
3070                 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
 
3071                             sizeof (fcp_lun_t));
 
3072                 retval = ZFCP_ERP_NOMEM;
 
3075         erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
 
3077                 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
 
3078                 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
 
3079                             sizeof (fcp_lun_t));
 
3080                 /* could not send 'close', fail */
 
3081                 retval = ZFCP_ERP_FAILED;
 
3084         debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
 
3085         debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
 
3086         retval = ZFCP_ERP_CONTINUES;
 
3097  * returns:     ZFCP_ERP_CONTINUES      - action continues (asynchronously)
 
3098  *              ZFCP_ERP_FAILED         - action finished unsuccessfully
 
3101 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
 
3104         struct zfcp_adapter *adapter = erp_action->adapter;
 
3105         struct zfcp_unit *unit = erp_action->unit;
 
3107         zfcp_erp_timeout_init(erp_action);
 
3108         retval = zfcp_fsf_open_unit(erp_action);
 
3109         if (retval == -ENOMEM) {
 
3110                 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
 
3111                 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
 
3112                             sizeof (fcp_lun_t));
 
3113                 retval = ZFCP_ERP_NOMEM;
 
3116         erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
 
3118                 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
 
3119                 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
 
3120                             sizeof (fcp_lun_t));
 
3121                 /* could not send 'open', fail */
 
3122                 retval = ZFCP_ERP_FAILED;
 
3125         debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
 
3126         debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
 
3127         retval = ZFCP_ERP_CONTINUES;
 
3140 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
 
3142         init_timer(&erp_action->timer);
 
3143         erp_action->timer.function = zfcp_erp_timeout_handler;
 
3144         erp_action->timer.data = (unsigned long) erp_action;
 
3145         /* jiffies will be added in zfcp_fsf_req_send */
 
3146         erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
 
3152  * purpose:     enqueue the specified error recovery action, if needed
 
3157 zfcp_erp_action_enqueue(int action,
 
3158                         struct zfcp_adapter *adapter,
 
3159                         struct zfcp_port *port, struct zfcp_unit *unit)
 
3162         struct zfcp_erp_action *erp_action = NULL;
 
3163         int stronger_action = 0;
 
3167          * We need some rules here which check whether we really need
 
3168          * this action or whether we should just drop it.
 
3169          * E.g. if there is a unfinished 'Reopen Port' request then we drop a
 
3170          * 'Reopen Unit' request for an associated unit since we can't
 
3171          * satisfy this request now. A 'Reopen Port' action will trigger
 
3172          * 'Reopen Unit' actions when it completes.
 
3173          * Thus, there are only actions in the queue which can immediately be
 
3174          * executed. This makes the processing of the action queue more
 
3178         if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
 
3182         debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
 
3183         /* check whether we really need this */
 
3185         case ZFCP_ERP_ACTION_REOPEN_UNIT:
 
3186                 if (atomic_test_mask
 
3187                     (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
 
3188                         debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
 
3189                         debug_event(adapter->erp_dbf, 4, &port->wwpn,
 
3191                         debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
 
3192                                     sizeof (fcp_lun_t));
 
3195                 if (!atomic_test_mask
 
3196                     (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
 
3198                     (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
 
3201                 if (!atomic_test_mask
 
3202                     (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
 
3203                         stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
 
3206                 /* fall through !!! */
 
3208         case ZFCP_ERP_ACTION_REOPEN_PORT:
 
3209                 if (atomic_test_mask
 
3210                     (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
 
3211                         debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
 
3212                         debug_event(adapter->erp_dbf, 4, &port->wwpn,
 
3216                 /* fall through !!! */
 
3218         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
 
3219                 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
 
3221                         if (port->erp_action.action !=
 
3222                             ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
 
3223                                 ZFCP_LOG_INFO("dropped erp action %i (port "
 
3224                                               "0x%016Lx, action in use: %i)\n",
 
3226                                               port->erp_action.action);
 
3227                                 debug_text_event(adapter->erp_dbf, 4,
 
3230                                 debug_text_event(adapter->erp_dbf, 4,
 
3232                         debug_event(adapter->erp_dbf, 4, &port->wwpn,
 
3236                 if (!atomic_test_mask
 
3237                     (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
 
3239                     (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
 
3242                 if (!atomic_test_mask
 
3243                     (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
 
3244                         stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
 
3247                 /* fall through !!! */
 
3249         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
 
3250                 if (atomic_test_mask
 
3251                     (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
 
3252                         debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
 
3258                 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
 
3259                 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
 
3260                 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
 
3261                                 "on adapter %s (action=%d)\n",
 
3262                                 zfcp_get_busid_by_adapter(adapter), action);
 
3266         /* check whether we need something stronger first */
 
3267         if (stronger_action) {
 
3268                 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
 
3269                 debug_event(adapter->erp_dbf, 4, &stronger_action,
 
3271                 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
 
3272                                "erp action %d on adapter %s\n",
 
3273                                stronger_action, action,
 
3274                                zfcp_get_busid_by_adapter(adapter));
 
3275                 action = stronger_action;
 
3278         /* mark adapter to have some error recovery pending */
 
3279         atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
 
3281         /* setup error recovery action */
 
3284         case ZFCP_ERP_ACTION_REOPEN_UNIT:
 
3285                 zfcp_unit_get(unit);
 
3286                 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
 
3287                 erp_action = &unit->erp_action;
 
3288                 if (!atomic_test_mask
 
3289                     (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
 
3290                         status = ZFCP_STATUS_ERP_CLOSE_ONLY;
 
3293         case ZFCP_ERP_ACTION_REOPEN_PORT:
 
3294         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
 
3295                 zfcp_port_get(port);
 
3296                 zfcp_erp_action_dismiss_port(port);
 
3297                 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
 
3298                 erp_action = &port->erp_action;
 
3299                 if (!atomic_test_mask
 
3300                     (ZFCP_STATUS_COMMON_RUNNING, &port->status))
 
3301                         status = ZFCP_STATUS_ERP_CLOSE_ONLY;
 
3304         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
 
3305                 zfcp_adapter_get(adapter);
 
3306                 zfcp_erp_action_dismiss_adapter(adapter);
 
3307                 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
 
3308                 erp_action = &adapter->erp_action;
 
3309                 if (!atomic_test_mask
 
3310                     (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
 
3311                         status = ZFCP_STATUS_ERP_CLOSE_ONLY;
 
3315         debug_text_event(adapter->erp_dbf, 4, "a_actenq");
 
3317         memset(erp_action, 0, sizeof (struct zfcp_erp_action));
 
3318         erp_action->adapter = adapter;
 
3319         erp_action->port = port;
 
3320         erp_action->unit = unit;
 
3321         erp_action->action = action;
 
3322         erp_action->status = status;
 
3324         ++adapter->erp_total_count;
 
3326         /* finally put it into 'ready' queue and kick erp thread */
 
3327         list_add(&erp_action->list, &adapter->erp_ready_head);
 
3328         up(&adapter->erp_ready_sem);
 
3342 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
 
3345         struct zfcp_adapter *adapter = erp_action->adapter;
 
3347         --adapter->erp_total_count;
 
3348         if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
 
3349                 --adapter->erp_low_mem_count;
 
3350                 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
 
3353         debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
 
3354         debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
 
3355         list_del(&erp_action->list);
 
3356         switch (erp_action->action) {
 
3357         case ZFCP_ERP_ACTION_REOPEN_UNIT:
 
3358                 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
 
3359                                   &erp_action->unit->status);
 
3361         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
 
3362         case ZFCP_ERP_ACTION_REOPEN_PORT:
 
3363                 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
 
3364                                   &erp_action->port->status);
 
3366         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
 
3367                 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
 
3368                                   &erp_action->adapter->status);
 
3378  * zfcp_erp_action_cleanup
 
3380  * Register unit with scsi stack if appropriate and fix reference counts.
 
3381  * Note: Temporary units are not registered with scsi stack.
 
3384 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
 
3385                         struct zfcp_port *port, struct zfcp_unit *unit,
 
3389         case ZFCP_ERP_ACTION_REOPEN_UNIT:
 
3390                 if ((result == ZFCP_ERP_SUCCEEDED)
 
3391                     && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
 
3395                         atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
 
3397                         scsi_scan_target(&port->rport->dev, 0,
 
3398                                          port->rport->scsi_target_id,
 
3401                 zfcp_unit_put(unit);
 
3403         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
 
3404         case ZFCP_ERP_ACTION_REOPEN_PORT:
 
3405                 if ((result == ZFCP_ERP_SUCCEEDED)
 
3406                     && !atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
 
3409                         struct fc_rport_identifiers ids;
 
3410                         ids.node_name = port->wwnn;
 
3411                         ids.port_name = port->wwpn;
 
3412                         ids.port_id = port->d_id;
 
3413                         ids.roles = FC_RPORT_ROLE_FCP_TARGET;
 
3415                                 fc_remote_port_add(adapter->scsi_host, 0, &ids);
 
3417                                 ZFCP_LOG_NORMAL("failed registration of rport"
 
3418                                                 "(adapter %s, wwpn=0x%016Lx)\n",
 
3419                                                 zfcp_get_busid_by_port(port),
 
3422                                 scsi_flush_work(adapter->scsi_host);
 
3424                 zfcp_port_put(port);
 
3426         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
 
3427                 zfcp_adapter_put(adapter);
 
3443 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
 
3446         struct zfcp_port *port;
 
3448         debug_text_event(adapter->erp_dbf, 5, "a_actab");
 
3449         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
 
3450                 zfcp_erp_action_dismiss(&adapter->erp_action);
 
3452                 list_for_each_entry(port, &adapter->port_list_head, list)
 
3453                     zfcp_erp_action_dismiss_port(port);
 
3466 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
 
3469         struct zfcp_unit *unit;
 
3470         struct zfcp_adapter *adapter = port->adapter;
 
3472         debug_text_event(adapter->erp_dbf, 5, "p_actab");
 
3473         debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
 
3474         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
 
3475                 zfcp_erp_action_dismiss(&port->erp_action);
 
3477                 list_for_each_entry(unit, &port->unit_list_head, list)
 
3478                     zfcp_erp_action_dismiss_unit(unit);
 
3491 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
 
3494         struct zfcp_adapter *adapter = unit->port->adapter;
 
3496         debug_text_event(adapter->erp_dbf, 5, "u_actab");
 
3497         debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
 
3498         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
 
3499                 zfcp_erp_action_dismiss(&unit->erp_action);
 
3507  * purpose:     moves erp_action to 'erp running list'
 
3512 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
 
3514         struct zfcp_adapter *adapter = erp_action->adapter;
 
3516         debug_text_event(adapter->erp_dbf, 6, "a_toru");
 
3517         debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
 
3518         list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
 
3524  * purpose:     moves erp_action to 'erp ready list'
 
3529 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
 
3531         struct zfcp_adapter *adapter = erp_action->adapter;
 
3533         debug_text_event(adapter->erp_dbf, 6, "a_tore");
 
3534         debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
 
3535         list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
 
3539  * function:    zfcp_erp_port_boxed
 
3544 zfcp_erp_port_boxed(struct zfcp_port *port)
 
3546         struct zfcp_adapter *adapter = port->adapter;
 
3547         unsigned long flags;
 
3549         debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
 
3550         debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
 
3551         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
3552         zfcp_erp_modify_port_status(port,
 
3553                         ZFCP_STATUS_COMMON_ACCESS_BOXED,
 
3555         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
3556         zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
 
3560  * function:    zfcp_erp_unit_boxed
 
3565 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
 
3567         struct zfcp_adapter *adapter = unit->port->adapter;
 
3569         debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
 
3570         debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
 
3571         zfcp_erp_modify_unit_status(unit,
 
3572                         ZFCP_STATUS_COMMON_ACCESS_BOXED,
 
3574         zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
 
3578  * function:    zfcp_erp_port_access_denied
 
3583 zfcp_erp_port_access_denied(struct zfcp_port *port)
 
3585         struct zfcp_adapter *adapter = port->adapter;
 
3586         unsigned long flags;
 
3588         debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
 
3589         debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
 
3590         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
3591         zfcp_erp_modify_port_status(port,
 
3592                         ZFCP_STATUS_COMMON_ERP_FAILED |
 
3593                         ZFCP_STATUS_COMMON_ACCESS_DENIED,
 
3595         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
3599  * function:    zfcp_erp_unit_access_denied
 
3604 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
 
3606         struct zfcp_adapter *adapter = unit->port->adapter;
 
3608         debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
 
3609         debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
 
3610         zfcp_erp_modify_unit_status(unit,
 
3611                         ZFCP_STATUS_COMMON_ERP_FAILED |
 
3612                         ZFCP_STATUS_COMMON_ACCESS_DENIED,
 
3617  * function:    zfcp_erp_adapter_access_changed
 
3622 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
 
3624         struct zfcp_port *port;
 
3625         unsigned long flags;
 
3627         if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
 
3630         debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
 
3631         debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
 
3633         read_lock_irqsave(&zfcp_data.config_lock, flags);
 
3634         if (adapter->nameserver_port)
 
3635                 zfcp_erp_port_access_changed(adapter->nameserver_port);
 
3636         list_for_each_entry(port, &adapter->port_list_head, list)
 
3637                 if (port != adapter->nameserver_port)
 
3638                         zfcp_erp_port_access_changed(port);
 
3639         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
 
3643  * function:    zfcp_erp_port_access_changed
 
3648 zfcp_erp_port_access_changed(struct zfcp_port *port)
 
3650         struct zfcp_adapter *adapter = port->adapter;
 
3651         struct zfcp_unit *unit;
 
3653         debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
 
3654         debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
 
3656         if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
 
3658             !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
 
3660                 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
 
3661                         list_for_each_entry(unit, &port->unit_list_head, list)
 
3662                                 zfcp_erp_unit_access_changed(unit);
 
3666         ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
 
3667                         "(due to ACT update)\n",
 
3668                         port->wwpn, zfcp_get_busid_by_adapter(adapter));
 
3669         if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
 
3670                 ZFCP_LOG_NORMAL("failed reopen of port"
 
3671                                 "(adapter %s, wwpn=0x%016Lx)\n",
 
3672                                 zfcp_get_busid_by_adapter(adapter), port->wwpn);
 
3676  * function:    zfcp_erp_unit_access_changed
 
3681 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
 
3683         struct zfcp_adapter *adapter = unit->port->adapter;
 
3685         debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
 
3686         debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
 
3688         if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
 
3690             !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
 
3694         ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
 
3695                         " on adapter %s (due to ACT update)\n",
 
3696                         unit->fcp_lun, unit->port->wwpn,
 
3697                         zfcp_get_busid_by_adapter(adapter));
 
3698         if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
 
3699                 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
 
3700                                 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
 
3701                                 zfcp_get_busid_by_adapter(adapter),
 
3702                                 unit->port->wwpn, unit->fcp_lun);
 
3705 #undef ZFCP_LOG_AREA