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