Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | * Maintained at www.Open-FCoE.org |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * RPORT GENERAL INFO |
| 22 | * |
| 23 | * This file contains all processing regarding fc_rports. It contains the |
| 24 | * rport state machine and does all rport interaction with the transport class. |
| 25 | * There should be no other places in libfc that interact directly with the |
| 26 | * transport class in regards to adding and deleting rports. |
| 27 | * |
| 28 | * fc_rport's represent N_Port's within the fabric. |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | * RPORT LOCKING |
| 33 | * |
| 34 | * The rport should never hold the rport mutex and then attempt to acquire |
| 35 | * either the lport or disc mutexes. The rport's mutex is considered lesser |
| 36 | * than both the lport's mutex and the disc mutex. Refer to fc_lport.c for |
| 37 | * more comments on the heirarchy. |
| 38 | * |
| 39 | * The locking strategy is similar to the lport's strategy. The lock protects |
| 40 | * the rport's states and is held and released by the entry points to the rport |
| 41 | * block. All _enter_* functions correspond to rport states and expect the rport |
| 42 | * mutex to be locked before calling them. This means that rports only handle |
| 43 | * one request or response at a time, since they're not critical for the I/O |
| 44 | * path this potential over-use of the mutex is acceptable. |
| 45 | */ |
| 46 | |
| 47 | #include <linux/kernel.h> |
| 48 | #include <linux/spinlock.h> |
| 49 | #include <linux/interrupt.h> |
| 50 | #include <linux/rcupdate.h> |
| 51 | #include <linux/timer.h> |
| 52 | #include <linux/workqueue.h> |
| 53 | #include <asm/unaligned.h> |
| 54 | |
| 55 | #include <scsi/libfc.h> |
| 56 | #include <scsi/fc_encode.h> |
| 57 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 58 | struct workqueue_struct *rport_event_queue; |
| 59 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 60 | static void fc_rport_enter_plogi(struct fc_rport_priv *); |
| 61 | static void fc_rport_enter_prli(struct fc_rport_priv *); |
| 62 | static void fc_rport_enter_rtv(struct fc_rport_priv *); |
| 63 | static void fc_rport_enter_ready(struct fc_rport_priv *); |
| 64 | static void fc_rport_enter_logo(struct fc_rport_priv *); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 65 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 66 | static void fc_rport_recv_plogi_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 67 | struct fc_seq *, struct fc_frame *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 68 | static void fc_rport_recv_prli_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 69 | struct fc_seq *, struct fc_frame *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 70 | static void fc_rport_recv_prlo_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 71 | struct fc_seq *, struct fc_frame *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 72 | static void fc_rport_recv_logo_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 73 | struct fc_seq *, struct fc_frame *); |
| 74 | static void fc_rport_timeout(struct work_struct *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 75 | static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *); |
| 76 | static void fc_rport_error_retry(struct fc_rport_priv *, struct fc_frame *); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 77 | static void fc_rport_work(struct work_struct *); |
| 78 | |
| 79 | static const char *fc_rport_state_names[] = { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 80 | [RPORT_ST_INIT] = "Init", |
| 81 | [RPORT_ST_PLOGI] = "PLOGI", |
| 82 | [RPORT_ST_PRLI] = "PRLI", |
| 83 | [RPORT_ST_RTV] = "RTV", |
| 84 | [RPORT_ST_READY] = "Ready", |
| 85 | [RPORT_ST_LOGO] = "LOGO", |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 86 | [RPORT_ST_DELETE] = "Delete", |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 89 | /** |
| 90 | * fc_rport_create() - create remote port in INIT state. |
| 91 | * @lport: local port. |
| 92 | * @ids: remote port identifiers. |
| 93 | * |
| 94 | * Locking note: this may be called without locks held, but |
| 95 | * is usually called from discovery with the disc_mutex held. |
| 96 | */ |
| 97 | static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, |
| 98 | struct fc_rport_identifiers *ids) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 99 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 100 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 101 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 102 | rdata = kzalloc(sizeof(*rdata), GFP_KERNEL); |
| 103 | if (!rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 104 | return NULL; |
| 105 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 106 | rdata->ids = *ids; |
| 107 | kref_init(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 108 | mutex_init(&rdata->rp_mutex); |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 109 | rdata->local_port = lport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 110 | rdata->rp_state = RPORT_ST_INIT; |
| 111 | rdata->event = RPORT_EV_NONE; |
| 112 | rdata->flags = FC_RP_FLAGS_REC_SUPPORTED; |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 113 | rdata->e_d_tov = lport->e_d_tov; |
| 114 | rdata->r_a_tov = lport->r_a_tov; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 115 | rdata->maxframe_size = FC_MIN_MAX_PAYLOAD; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 116 | INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout); |
| 117 | INIT_WORK(&rdata->event_work, fc_rport_work); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 118 | return rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 122 | * fc_rport_destroy() - free a remote port after last reference is released. |
| 123 | * @kref: pointer to kref inside struct fc_rport_priv |
| 124 | */ |
| 125 | static void fc_rport_destroy(struct kref *kref) |
| 126 | { |
| 127 | struct fc_rport_priv *rdata; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 128 | |
| 129 | rdata = container_of(kref, struct fc_rport_priv, kref); |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 130 | kfree(rdata); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 134 | * fc_rport_state() - return a string for the state the rport is in |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 135 | * @rdata: remote port private data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 136 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 137 | static const char *fc_rport_state(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 138 | { |
| 139 | const char *cp; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 140 | |
| 141 | cp = fc_rport_state_names[rdata->rp_state]; |
| 142 | if (!cp) |
| 143 | cp = "Unknown"; |
| 144 | return cp; |
| 145 | } |
| 146 | |
| 147 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 148 | * fc_set_rport_loss_tmo() - Set the remote port loss timeout in seconds. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 149 | * @rport: Pointer to Fibre Channel remote port structure |
| 150 | * @timeout: timeout in seconds |
| 151 | */ |
| 152 | void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) |
| 153 | { |
| 154 | if (timeout) |
| 155 | rport->dev_loss_tmo = timeout + 5; |
| 156 | else |
| 157 | rport->dev_loss_tmo = 30; |
| 158 | } |
| 159 | EXPORT_SYMBOL(fc_set_rport_loss_tmo); |
| 160 | |
| 161 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 162 | * fc_plogi_get_maxframe() - Get max payload from the common service parameters |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 163 | * @flp: FLOGI payload structure |
| 164 | * @maxval: upper limit, may be less than what is in the service parameters |
| 165 | */ |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 166 | static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp, |
| 167 | unsigned int maxval) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 168 | { |
| 169 | unsigned int mfs; |
| 170 | |
| 171 | /* |
| 172 | * Get max payload from the common service parameters and the |
| 173 | * class 3 receive data field size. |
| 174 | */ |
| 175 | mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK; |
| 176 | if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval) |
| 177 | maxval = mfs; |
| 178 | mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs); |
| 179 | if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval) |
| 180 | maxval = mfs; |
| 181 | return maxval; |
| 182 | } |
| 183 | |
| 184 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 185 | * fc_rport_state_enter() - Change the rport's state |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 186 | * @rdata: The rport whose state should change |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 187 | * @new: The new state of the rport |
| 188 | * |
| 189 | * Locking Note: Called with the rport lock held |
| 190 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 191 | static void fc_rport_state_enter(struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 192 | enum fc_rport_state new) |
| 193 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 194 | if (rdata->rp_state != new) |
| 195 | rdata->retries = 0; |
| 196 | rdata->rp_state = new; |
| 197 | } |
| 198 | |
| 199 | static void fc_rport_work(struct work_struct *work) |
| 200 | { |
Abhijeet Joglekar | 571f824 | 2009-02-27 10:54:41 -0800 | [diff] [blame] | 201 | u32 port_id; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 202 | struct fc_rport_priv *rdata = |
| 203 | container_of(work, struct fc_rport_priv, event_work); |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 204 | struct fc_rport_libfc_priv *rp; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 205 | enum fc_rport_event event; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 206 | struct fc_lport *lport = rdata->local_port; |
| 207 | struct fc_rport_operations *rport_ops; |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 208 | struct fc_rport_identifiers ids; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 209 | struct fc_rport *rport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 210 | |
| 211 | mutex_lock(&rdata->rp_mutex); |
| 212 | event = rdata->event; |
| 213 | rport_ops = rdata->ops; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 214 | rport = rdata->rport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 215 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 216 | FC_RPORT_DBG(rdata, "work event %u\n", event); |
| 217 | |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 218 | switch (event) { |
Joe Eykholt | 4c0f62b | 2009-08-25 14:01:12 -0700 | [diff] [blame] | 219 | case RPORT_EV_READY: |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 220 | ids = rdata->ids; |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 221 | rdata->event = RPORT_EV_NONE; |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 222 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 223 | mutex_unlock(&rdata->rp_mutex); |
| 224 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 225 | if (!rport) |
| 226 | rport = fc_remote_port_add(lport->host, 0, &ids); |
| 227 | if (!rport) { |
| 228 | FC_RPORT_DBG(rdata, "Failed to add the rport\n"); |
| 229 | lport->tt.rport_logoff(rdata); |
| 230 | kref_put(&rdata->kref, lport->tt.rport_destroy); |
| 231 | return; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 232 | } |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 233 | mutex_lock(&rdata->rp_mutex); |
| 234 | if (rdata->rport) |
| 235 | FC_RPORT_DBG(rdata, "rport already allocated\n"); |
| 236 | rdata->rport = rport; |
| 237 | rport->maxframe_size = rdata->maxframe_size; |
| 238 | rport->supported_classes = rdata->supported_classes; |
| 239 | |
| 240 | rp = rport->dd_data; |
| 241 | rp->local_port = lport; |
| 242 | rp->rp_state = rdata->rp_state; |
| 243 | rp->flags = rdata->flags; |
| 244 | rp->e_d_tov = rdata->e_d_tov; |
| 245 | rp->r_a_tov = rdata->r_a_tov; |
| 246 | mutex_unlock(&rdata->rp_mutex); |
| 247 | |
| 248 | if (rport_ops->event_callback) { |
| 249 | FC_RPORT_DBG(rdata, "callback ev %d\n", event); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 250 | rport_ops->event_callback(lport, rdata, event); |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 251 | } |
| 252 | kref_put(&rdata->kref, lport->tt.rport_destroy); |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 253 | break; |
| 254 | |
| 255 | case RPORT_EV_FAILED: |
| 256 | case RPORT_EV_LOGO: |
| 257 | case RPORT_EV_STOP: |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 258 | port_id = rdata->ids.port_id; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 259 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 260 | |
| 261 | if (rport_ops->event_callback) { |
| 262 | FC_RPORT_DBG(rdata, "callback ev %d\n", event); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 263 | rport_ops->event_callback(lport, rdata, event); |
Abhijeet Joglekar | 571f824 | 2009-02-27 10:54:41 -0800 | [diff] [blame] | 264 | } |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 265 | cancel_delayed_work_sync(&rdata->retry_work); |
| 266 | |
| 267 | /* |
| 268 | * Reset any outstanding exchanges before freeing rport. |
| 269 | */ |
| 270 | lport->tt.exch_mgr_reset(lport, 0, port_id); |
| 271 | lport->tt.exch_mgr_reset(lport, port_id, 0); |
| 272 | |
| 273 | if (rport) { |
| 274 | rp = rport->dd_data; |
| 275 | rp->rp_state = RPORT_ST_DELETE; |
| 276 | mutex_lock(&rdata->rp_mutex); |
| 277 | rdata->rport = NULL; |
| 278 | mutex_unlock(&rdata->rp_mutex); |
| 279 | fc_remote_port_delete(rport); |
| 280 | } |
| 281 | kref_put(&rdata->kref, lport->tt.rport_destroy); |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 282 | break; |
| 283 | |
| 284 | default: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 285 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 286 | break; |
| 287 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 291 | * fc_rport_login() - Start the remote port login state machine |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 292 | * @rdata: private remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 293 | * |
| 294 | * Locking Note: Called without the rport lock held. This |
| 295 | * function will hold the rport lock, call an _enter_* |
| 296 | * function and then unlock the rport. |
| 297 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 298 | int fc_rport_login(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 299 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 300 | mutex_lock(&rdata->rp_mutex); |
| 301 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 302 | FC_RPORT_DBG(rdata, "Login to port\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 303 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 304 | fc_rport_enter_plogi(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 305 | |
| 306 | mutex_unlock(&rdata->rp_mutex); |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | /** |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 312 | * fc_rport_enter_delete() - schedule a remote port to be deleted. |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 313 | * @rdata: private remote port |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 314 | * @event: event to report as the reason for deletion |
| 315 | * |
| 316 | * Locking Note: Called with the rport lock held. |
| 317 | * |
| 318 | * Allow state change into DELETE only once. |
| 319 | * |
| 320 | * Call queue_work only if there's no event already pending. |
| 321 | * Set the new event so that the old pending event will not occur. |
| 322 | * Since we have the mutex, even if fc_rport_work() is already started, |
| 323 | * it'll see the new event. |
| 324 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 325 | static void fc_rport_enter_delete(struct fc_rport_priv *rdata, |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 326 | enum fc_rport_event event) |
| 327 | { |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 328 | if (rdata->rp_state == RPORT_ST_DELETE) |
| 329 | return; |
| 330 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 331 | FC_RPORT_DBG(rdata, "Delete port\n"); |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 332 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 333 | fc_rport_state_enter(rdata, RPORT_ST_DELETE); |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 334 | |
| 335 | if (rdata->event == RPORT_EV_NONE) |
| 336 | queue_work(rport_event_queue, &rdata->event_work); |
| 337 | rdata->event = event; |
| 338 | } |
| 339 | |
| 340 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 341 | * fc_rport_logoff() - Logoff and remove an rport |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 342 | * @rdata: private remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 343 | * |
| 344 | * Locking Note: Called without the rport lock held. This |
| 345 | * function will hold the rport lock, call an _enter_* |
| 346 | * function and then unlock the rport. |
| 347 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 348 | int fc_rport_logoff(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 349 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 350 | mutex_lock(&rdata->rp_mutex); |
| 351 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 352 | FC_RPORT_DBG(rdata, "Remove port\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 353 | |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 354 | if (rdata->rp_state == RPORT_ST_DELETE) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 355 | FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n"); |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 356 | mutex_unlock(&rdata->rp_mutex); |
| 357 | goto out; |
| 358 | } |
| 359 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 360 | fc_rport_enter_logo(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 361 | |
| 362 | /* |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 363 | * Change the state to Delete so that we discard |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 364 | * the response. |
| 365 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 366 | fc_rport_enter_delete(rdata, RPORT_EV_STOP); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 367 | mutex_unlock(&rdata->rp_mutex); |
| 368 | |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 369 | out: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 374 | * fc_rport_enter_ready() - The rport is ready |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 375 | * @rdata: private remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 376 | * |
| 377 | * Locking Note: The rport lock is expected to be held before calling |
| 378 | * this routine. |
| 379 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 380 | static void fc_rport_enter_ready(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 381 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 382 | fc_rport_state_enter(rdata, RPORT_ST_READY); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 383 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 384 | FC_RPORT_DBG(rdata, "Port is Ready\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 385 | |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 386 | if (rdata->event == RPORT_EV_NONE) |
| 387 | queue_work(rport_event_queue, &rdata->event_work); |
Joe Eykholt | 4c0f62b | 2009-08-25 14:01:12 -0700 | [diff] [blame] | 388 | rdata->event = RPORT_EV_READY; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 392 | * fc_rport_timeout() - Handler for the retry_work timer. |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 393 | * @work: The work struct of the fc_rport_priv |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 394 | * |
| 395 | * Locking Note: Called without the rport lock held. This |
| 396 | * function will hold the rport lock, call an _enter_* |
| 397 | * function and then unlock the rport. |
| 398 | */ |
| 399 | static void fc_rport_timeout(struct work_struct *work) |
| 400 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 401 | struct fc_rport_priv *rdata = |
| 402 | container_of(work, struct fc_rport_priv, retry_work.work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 403 | |
| 404 | mutex_lock(&rdata->rp_mutex); |
| 405 | |
| 406 | switch (rdata->rp_state) { |
| 407 | case RPORT_ST_PLOGI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 408 | fc_rport_enter_plogi(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 409 | break; |
| 410 | case RPORT_ST_PRLI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 411 | fc_rport_enter_prli(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 412 | break; |
| 413 | case RPORT_ST_RTV: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 414 | fc_rport_enter_rtv(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 415 | break; |
| 416 | case RPORT_ST_LOGO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 417 | fc_rport_enter_logo(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 418 | break; |
| 419 | case RPORT_ST_READY: |
| 420 | case RPORT_ST_INIT: |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 421 | case RPORT_ST_DELETE: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 422 | break; |
| 423 | } |
| 424 | |
| 425 | mutex_unlock(&rdata->rp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 429 | * fc_rport_error() - Error handler, called once retries have been exhausted |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 430 | * @rdata: private remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 431 | * @fp: The frame pointer |
| 432 | * |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 433 | * Locking Note: The rport lock is expected to be held before |
| 434 | * calling this routine |
| 435 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 436 | static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 437 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 438 | FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n", |
Joe Eykholt | cdbe6df | 2009-08-25 14:01:39 -0700 | [diff] [blame^] | 439 | IS_ERR(fp) ? -PTR_ERR(fp) : 0, |
| 440 | fc_rport_state(rdata), rdata->retries); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 441 | |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 442 | switch (rdata->rp_state) { |
| 443 | case RPORT_ST_PLOGI: |
| 444 | case RPORT_ST_PRLI: |
| 445 | case RPORT_ST_LOGO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 446 | fc_rport_enter_delete(rdata, RPORT_EV_FAILED); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 447 | break; |
| 448 | case RPORT_ST_RTV: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 449 | fc_rport_enter_ready(rdata); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 450 | break; |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 451 | case RPORT_ST_DELETE: |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 452 | case RPORT_ST_READY: |
| 453 | case RPORT_ST_INIT: |
| 454 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
| 458 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 459 | * fc_rport_error_retry() - Error handler when retries are desired |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 460 | * @rdata: private remote port data |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 461 | * @fp: The frame pointer |
| 462 | * |
| 463 | * If the error was an exchange timeout retry immediately, |
| 464 | * otherwise wait for E_D_TOV. |
| 465 | * |
| 466 | * Locking Note: The rport lock is expected to be held before |
| 467 | * calling this routine |
| 468 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 469 | static void fc_rport_error_retry(struct fc_rport_priv *rdata, |
| 470 | struct fc_frame *fp) |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 471 | { |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 472 | unsigned long delay = FC_DEF_E_D_TOV; |
| 473 | |
| 474 | /* make sure this isn't an FC_EX_CLOSED error, never retry those */ |
| 475 | if (PTR_ERR(fp) == -FC_EX_CLOSED) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 476 | return fc_rport_error(rdata, fp); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 477 | |
Abhijeet Joglekar | a366695 | 2009-05-01 10:01:26 -0700 | [diff] [blame] | 478 | if (rdata->retries < rdata->local_port->max_rport_retry_count) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 479 | FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n", |
| 480 | PTR_ERR(fp), fc_rport_state(rdata)); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 481 | rdata->retries++; |
| 482 | /* no additional delay on exchange timeouts */ |
| 483 | if (PTR_ERR(fp) == -FC_EX_TIMEOUT) |
| 484 | delay = 0; |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 485 | schedule_delayed_work(&rdata->retry_work, delay); |
| 486 | return; |
| 487 | } |
| 488 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 489 | return fc_rport_error(rdata, fp); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 493 | * fc_rport_plogi_recv_resp() - Handle incoming ELS PLOGI response |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 494 | * @sp: current sequence in the PLOGI exchange |
| 495 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 496 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 497 | * |
| 498 | * Locking Note: This function will be called without the rport lock |
| 499 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 500 | * and then unlock the rport. |
| 501 | */ |
| 502 | static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 503 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 504 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 505 | struct fc_rport_priv *rdata = rdata_arg; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 506 | struct fc_lport *lport = rdata->local_port; |
Robert Love | a29e764 | 2009-04-21 16:27:41 -0700 | [diff] [blame] | 507 | struct fc_els_flogi *plp = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 508 | unsigned int tov; |
| 509 | u16 csp_seq; |
| 510 | u16 cssp_seq; |
| 511 | u8 op; |
| 512 | |
| 513 | mutex_lock(&rdata->rp_mutex); |
| 514 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 515 | FC_RPORT_DBG(rdata, "Received a PLOGI response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 516 | |
| 517 | if (rdata->rp_state != RPORT_ST_PLOGI) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 518 | FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state " |
| 519 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 520 | if (IS_ERR(fp)) |
| 521 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 522 | goto out; |
| 523 | } |
| 524 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 525 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 526 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 527 | goto err; |
| 528 | } |
| 529 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 530 | op = fc_frame_payload_op(fp); |
| 531 | if (op == ELS_LS_ACC && |
| 532 | (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) { |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 533 | rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn); |
| 534 | rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 535 | |
| 536 | tov = ntohl(plp->fl_csp.sp_e_d_tov); |
| 537 | if (ntohs(plp->fl_csp.sp_features) & FC_SP_FT_EDTR) |
| 538 | tov /= 1000; |
| 539 | if (tov > rdata->e_d_tov) |
| 540 | rdata->e_d_tov = tov; |
| 541 | csp_seq = ntohs(plp->fl_csp.sp_tot_seq); |
| 542 | cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq); |
| 543 | if (cssp_seq < csp_seq) |
| 544 | csp_seq = cssp_seq; |
| 545 | rdata->max_seq = csp_seq; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 546 | rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 547 | |
| 548 | /* |
| 549 | * If the rport is one of the well known addresses |
| 550 | * we skip PRLI and RTV and go straight to READY. |
| 551 | */ |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 552 | if (rdata->ids.port_id >= FC_FID_DOM_MGR) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 553 | fc_rport_enter_ready(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 554 | else |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 555 | fc_rport_enter_prli(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 556 | } else |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 557 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 558 | |
| 559 | out: |
| 560 | fc_frame_free(fp); |
| 561 | err: |
| 562 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 563 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 567 | * fc_rport_enter_plogi() - Send Port Login (PLOGI) request to peer |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 568 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 569 | * |
| 570 | * Locking Note: The rport lock is expected to be held before calling |
| 571 | * this routine. |
| 572 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 573 | static void fc_rport_enter_plogi(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 574 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 575 | struct fc_lport *lport = rdata->local_port; |
| 576 | struct fc_frame *fp; |
| 577 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 578 | FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n", |
| 579 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 580 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 581 | fc_rport_state_enter(rdata, RPORT_ST_PLOGI); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 582 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 583 | rdata->maxframe_size = FC_MIN_MAX_PAYLOAD; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 584 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); |
| 585 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 586 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 587 | return; |
| 588 | } |
| 589 | rdata->e_d_tov = lport->e_d_tov; |
| 590 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 591 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 592 | fc_rport_plogi_resp, rdata, lport->e_d_tov)) |
| 593 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 594 | else |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 595 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 599 | * fc_rport_prli_resp() - Process Login (PRLI) response handler |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 600 | * @sp: current sequence in the PRLI exchange |
| 601 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 602 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 603 | * |
| 604 | * Locking Note: This function will be called without the rport lock |
| 605 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 606 | * and then unlock the rport. |
| 607 | */ |
| 608 | static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 609 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 610 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 611 | struct fc_rport_priv *rdata = rdata_arg; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 612 | struct { |
| 613 | struct fc_els_prli prli; |
| 614 | struct fc_els_spp spp; |
| 615 | } *pp; |
| 616 | u32 roles = FC_RPORT_ROLE_UNKNOWN; |
| 617 | u32 fcp_parm = 0; |
| 618 | u8 op; |
| 619 | |
| 620 | mutex_lock(&rdata->rp_mutex); |
| 621 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 622 | FC_RPORT_DBG(rdata, "Received a PRLI response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 623 | |
| 624 | if (rdata->rp_state != RPORT_ST_PRLI) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 625 | FC_RPORT_DBG(rdata, "Received a PRLI response, but in state " |
| 626 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 627 | if (IS_ERR(fp)) |
| 628 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 629 | goto out; |
| 630 | } |
| 631 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 632 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 633 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 634 | goto err; |
| 635 | } |
| 636 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 637 | op = fc_frame_payload_op(fp); |
| 638 | if (op == ELS_LS_ACC) { |
| 639 | pp = fc_frame_payload_get(fp, sizeof(*pp)); |
| 640 | if (pp && pp->prli.prli_spp_len >= sizeof(pp->spp)) { |
| 641 | fcp_parm = ntohl(pp->spp.spp_params); |
| 642 | if (fcp_parm & FCP_SPPF_RETRY) |
| 643 | rdata->flags |= FC_RP_FLAGS_RETRY; |
| 644 | } |
| 645 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 646 | rdata->supported_classes = FC_COS_CLASS3; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 647 | if (fcp_parm & FCP_SPPF_INIT_FCN) |
| 648 | roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 649 | if (fcp_parm & FCP_SPPF_TARG_FCN) |
| 650 | roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 651 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 652 | rdata->ids.roles = roles; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 653 | fc_rport_enter_rtv(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 654 | |
| 655 | } else { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 656 | FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n"); |
| 657 | fc_rport_enter_delete(rdata, RPORT_EV_FAILED); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | out: |
| 661 | fc_frame_free(fp); |
| 662 | err: |
| 663 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 664 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 668 | * fc_rport_logo_resp() - Logout (LOGO) response handler |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 669 | * @sp: current sequence in the LOGO exchange |
| 670 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 671 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 672 | * |
| 673 | * Locking Note: This function will be called without the rport lock |
| 674 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 675 | * and then unlock the rport. |
| 676 | */ |
| 677 | static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 678 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 679 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 680 | struct fc_rport_priv *rdata = rdata_arg; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 681 | u8 op; |
| 682 | |
| 683 | mutex_lock(&rdata->rp_mutex); |
| 684 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 685 | FC_RPORT_DBG(rdata, "Received a LOGO response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 686 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 687 | if (rdata->rp_state != RPORT_ST_LOGO) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 688 | FC_RPORT_DBG(rdata, "Received a LOGO response, but in state " |
| 689 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 690 | if (IS_ERR(fp)) |
| 691 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 692 | goto out; |
| 693 | } |
| 694 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 695 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 696 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 697 | goto err; |
| 698 | } |
| 699 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 700 | op = fc_frame_payload_op(fp); |
| 701 | if (op == ELS_LS_ACC) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 702 | fc_rport_enter_rtv(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 703 | } else { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 704 | FC_RPORT_DBG(rdata, "Bad ELS response for LOGO command\n"); |
| 705 | fc_rport_enter_delete(rdata, RPORT_EV_LOGO); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | out: |
| 709 | fc_frame_free(fp); |
| 710 | err: |
| 711 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 712 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 716 | * fc_rport_enter_prli() - Send Process Login (PRLI) request to peer |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 717 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 718 | * |
| 719 | * Locking Note: The rport lock is expected to be held before calling |
| 720 | * this routine. |
| 721 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 722 | static void fc_rport_enter_prli(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 723 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 724 | struct fc_lport *lport = rdata->local_port; |
| 725 | struct { |
| 726 | struct fc_els_prli prli; |
| 727 | struct fc_els_spp spp; |
| 728 | } *pp; |
| 729 | struct fc_frame *fp; |
| 730 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 731 | FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n", |
| 732 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 733 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 734 | fc_rport_state_enter(rdata, RPORT_ST_PRLI); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 735 | |
| 736 | fp = fc_frame_alloc(lport, sizeof(*pp)); |
| 737 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 738 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 739 | return; |
| 740 | } |
| 741 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 742 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PRLI, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 743 | fc_rport_prli_resp, rdata, lport->e_d_tov)) |
| 744 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 745 | else |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 746 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 750 | * fc_rport_els_rtv_resp() - Request Timeout Value response handler |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 751 | * @sp: current sequence in the RTV exchange |
| 752 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 753 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 754 | * |
| 755 | * Many targets don't seem to support this. |
| 756 | * |
| 757 | * Locking Note: This function will be called without the rport lock |
| 758 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 759 | * and then unlock the rport. |
| 760 | */ |
| 761 | static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 762 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 763 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 764 | struct fc_rport_priv *rdata = rdata_arg; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 765 | u8 op; |
| 766 | |
| 767 | mutex_lock(&rdata->rp_mutex); |
| 768 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 769 | FC_RPORT_DBG(rdata, "Received a RTV response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 770 | |
| 771 | if (rdata->rp_state != RPORT_ST_RTV) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 772 | FC_RPORT_DBG(rdata, "Received a RTV response, but in state " |
| 773 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 774 | if (IS_ERR(fp)) |
| 775 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 776 | goto out; |
| 777 | } |
| 778 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 779 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 780 | fc_rport_error(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 781 | goto err; |
| 782 | } |
| 783 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 784 | op = fc_frame_payload_op(fp); |
| 785 | if (op == ELS_LS_ACC) { |
| 786 | struct fc_els_rtv_acc *rtv; |
| 787 | u32 toq; |
| 788 | u32 tov; |
| 789 | |
| 790 | rtv = fc_frame_payload_get(fp, sizeof(*rtv)); |
| 791 | if (rtv) { |
| 792 | toq = ntohl(rtv->rtv_toq); |
| 793 | tov = ntohl(rtv->rtv_r_a_tov); |
| 794 | if (tov == 0) |
| 795 | tov = 1; |
| 796 | rdata->r_a_tov = tov; |
| 797 | tov = ntohl(rtv->rtv_e_d_tov); |
| 798 | if (toq & FC_ELS_RTV_EDRES) |
| 799 | tov /= 1000000; |
| 800 | if (tov == 0) |
| 801 | tov = 1; |
| 802 | rdata->e_d_tov = tov; |
| 803 | } |
| 804 | } |
| 805 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 806 | fc_rport_enter_ready(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 807 | |
| 808 | out: |
| 809 | fc_frame_free(fp); |
| 810 | err: |
| 811 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 812 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 816 | * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request to peer |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 817 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 818 | * |
| 819 | * Locking Note: The rport lock is expected to be held before calling |
| 820 | * this routine. |
| 821 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 822 | static void fc_rport_enter_rtv(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 823 | { |
| 824 | struct fc_frame *fp; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 825 | struct fc_lport *lport = rdata->local_port; |
| 826 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 827 | FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n", |
| 828 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 829 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 830 | fc_rport_state_enter(rdata, RPORT_ST_RTV); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 831 | |
| 832 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv)); |
| 833 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 834 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 835 | return; |
| 836 | } |
| 837 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 838 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 839 | fc_rport_rtv_resp, rdata, lport->e_d_tov)) |
| 840 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 841 | else |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 842 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 846 | * fc_rport_enter_logo() - Send Logout (LOGO) request to peer |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 847 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 848 | * |
| 849 | * Locking Note: The rport lock is expected to be held before calling |
| 850 | * this routine. |
| 851 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 852 | static void fc_rport_enter_logo(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 853 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 854 | struct fc_lport *lport = rdata->local_port; |
| 855 | struct fc_frame *fp; |
| 856 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 857 | FC_RPORT_DBG(rdata, "Port entered LOGO state from %s state\n", |
| 858 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 859 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 860 | fc_rport_state_enter(rdata, RPORT_ST_LOGO); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 861 | |
| 862 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo)); |
| 863 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 864 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 865 | return; |
| 866 | } |
| 867 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 868 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 869 | fc_rport_logo_resp, rdata, lport->e_d_tov)) |
| 870 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 871 | else |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 872 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | |
| 876 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 877 | * fc_rport_recv_req() - Receive a request from a rport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 878 | * @sp: current sequence in the PLOGI exchange |
| 879 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 880 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 881 | * |
| 882 | * Locking Note: Called without the rport lock held. This |
| 883 | * function will hold the rport lock, call an _enter_* |
| 884 | * function and then unlock the rport. |
| 885 | */ |
| 886 | void fc_rport_recv_req(struct fc_seq *sp, struct fc_frame *fp, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 887 | struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 888 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 889 | struct fc_lport *lport = rdata->local_port; |
| 890 | |
| 891 | struct fc_frame_header *fh; |
| 892 | struct fc_seq_els_data els_data; |
| 893 | u8 op; |
| 894 | |
| 895 | mutex_lock(&rdata->rp_mutex); |
| 896 | |
| 897 | els_data.fp = NULL; |
| 898 | els_data.explan = ELS_EXPL_NONE; |
| 899 | els_data.reason = ELS_RJT_NONE; |
| 900 | |
| 901 | fh = fc_frame_header_get(fp); |
| 902 | |
| 903 | if (fh->fh_r_ctl == FC_RCTL_ELS_REQ && fh->fh_type == FC_TYPE_ELS) { |
| 904 | op = fc_frame_payload_op(fp); |
| 905 | switch (op) { |
| 906 | case ELS_PLOGI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 907 | fc_rport_recv_plogi_req(rdata, sp, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 908 | break; |
| 909 | case ELS_PRLI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 910 | fc_rport_recv_prli_req(rdata, sp, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 911 | break; |
| 912 | case ELS_PRLO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 913 | fc_rport_recv_prlo_req(rdata, sp, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 914 | break; |
| 915 | case ELS_LOGO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 916 | fc_rport_recv_logo_req(rdata, sp, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 917 | break; |
| 918 | case ELS_RRQ: |
| 919 | els_data.fp = fp; |
| 920 | lport->tt.seq_els_rsp_send(sp, ELS_RRQ, &els_data); |
| 921 | break; |
| 922 | case ELS_REC: |
| 923 | els_data.fp = fp; |
| 924 | lport->tt.seq_els_rsp_send(sp, ELS_REC, &els_data); |
| 925 | break; |
| 926 | default: |
| 927 | els_data.reason = ELS_RJT_UNSUP; |
| 928 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &els_data); |
| 929 | break; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | mutex_unlock(&rdata->rp_mutex); |
| 934 | } |
| 935 | |
| 936 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 937 | * fc_rport_recv_plogi_req() - Handle incoming Port Login (PLOGI) request |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 938 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 939 | * @sp: current sequence in the PLOGI exchange |
| 940 | * @fp: PLOGI request frame |
| 941 | * |
| 942 | * Locking Note: The rport lock is exected to be held before calling |
| 943 | * this function. |
| 944 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 945 | static void fc_rport_recv_plogi_req(struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 946 | struct fc_seq *sp, struct fc_frame *rx_fp) |
| 947 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 948 | struct fc_lport *lport = rdata->local_port; |
| 949 | struct fc_frame *fp = rx_fp; |
| 950 | struct fc_exch *ep; |
| 951 | struct fc_frame_header *fh; |
| 952 | struct fc_els_flogi *pl; |
| 953 | struct fc_seq_els_data rjt_data; |
| 954 | u32 sid; |
| 955 | u64 wwpn; |
| 956 | u64 wwnn; |
| 957 | enum fc_els_rjt_reason reject = 0; |
| 958 | u32 f_ctl; |
| 959 | rjt_data.fp = NULL; |
| 960 | |
| 961 | fh = fc_frame_header_get(fp); |
| 962 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 963 | FC_RPORT_DBG(rdata, "Received PLOGI request while in state %s\n", |
| 964 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 965 | |
| 966 | sid = ntoh24(fh->fh_s_id); |
| 967 | pl = fc_frame_payload_get(fp, sizeof(*pl)); |
| 968 | if (!pl) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 969 | FC_RPORT_DBG(rdata, "Received PLOGI too short\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 970 | WARN_ON(1); |
| 971 | /* XXX TBD: send reject? */ |
| 972 | fc_frame_free(fp); |
| 973 | return; |
| 974 | } |
| 975 | wwpn = get_unaligned_be64(&pl->fl_wwpn); |
| 976 | wwnn = get_unaligned_be64(&pl->fl_wwnn); |
| 977 | |
| 978 | /* |
| 979 | * If the session was just created, possibly due to the incoming PLOGI, |
| 980 | * set the state appropriately and accept the PLOGI. |
| 981 | * |
| 982 | * If we had also sent a PLOGI, and if the received PLOGI is from a |
| 983 | * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason |
| 984 | * "command already in progress". |
| 985 | * |
| 986 | * XXX TBD: If the session was ready before, the PLOGI should result in |
| 987 | * all outstanding exchanges being reset. |
| 988 | */ |
| 989 | switch (rdata->rp_state) { |
| 990 | case RPORT_ST_INIT: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 991 | FC_RPORT_DBG(rdata, "Received PLOGI, wwpn %llx state INIT " |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 992 | "- reject\n", (unsigned long long)wwpn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 993 | reject = ELS_RJT_UNSUP; |
| 994 | break; |
| 995 | case RPORT_ST_PLOGI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 996 | FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state %d\n", |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 997 | rdata->rp_state); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 998 | if (wwpn < lport->wwpn) |
| 999 | reject = ELS_RJT_INPROG; |
| 1000 | break; |
| 1001 | case RPORT_ST_PRLI: |
| 1002 | case RPORT_ST_READY: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1003 | FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d " |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1004 | "- ignored for now\n", rdata->rp_state); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1005 | /* XXX TBD - should reset */ |
| 1006 | break; |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 1007 | case RPORT_ST_DELETE: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1008 | default: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1009 | FC_RPORT_DBG(rdata, "Received PLOGI in unexpected " |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1010 | "state %d\n", rdata->rp_state); |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 1011 | fc_frame_free(fp); |
| 1012 | return; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1013 | break; |
| 1014 | } |
| 1015 | |
| 1016 | if (reject) { |
| 1017 | rjt_data.reason = reject; |
| 1018 | rjt_data.explan = ELS_EXPL_NONE; |
| 1019 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1020 | fc_frame_free(fp); |
| 1021 | } else { |
| 1022 | fp = fc_frame_alloc(lport, sizeof(*pl)); |
| 1023 | if (fp == NULL) { |
| 1024 | fp = rx_fp; |
| 1025 | rjt_data.reason = ELS_RJT_UNAB; |
| 1026 | rjt_data.explan = ELS_EXPL_NONE; |
| 1027 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1028 | fc_frame_free(fp); |
| 1029 | } else { |
| 1030 | sp = lport->tt.seq_start_next(sp); |
| 1031 | WARN_ON(!sp); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 1032 | rdata->ids.port_name = wwpn; |
| 1033 | rdata->ids.node_name = wwnn; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1034 | |
| 1035 | /* |
| 1036 | * Get session payload size from incoming PLOGI. |
| 1037 | */ |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 1038 | rdata->maxframe_size = |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1039 | fc_plogi_get_maxframe(pl, lport->mfs); |
| 1040 | fc_frame_free(rx_fp); |
| 1041 | fc_plogi_fill(lport, fp, ELS_LS_ACC); |
| 1042 | |
| 1043 | /* |
| 1044 | * Send LS_ACC. If this fails, |
| 1045 | * the originator should retry. |
| 1046 | */ |
| 1047 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; |
| 1048 | f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 1049 | ep = fc_seq_exch(sp); |
| 1050 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1051 | FC_TYPE_ELS, f_ctl, 0); |
| 1052 | lport->tt.seq_send(lport, sp, fp); |
| 1053 | if (rdata->rp_state == RPORT_ST_PLOGI) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1054 | fc_rport_enter_prli(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1060 | * fc_rport_recv_prli_req() - Handle incoming Process Login (PRLI) request |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1061 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1062 | * @sp: current sequence in the PRLI exchange |
| 1063 | * @fp: PRLI request frame |
| 1064 | * |
| 1065 | * Locking Note: The rport lock is exected to be held before calling |
| 1066 | * this function. |
| 1067 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1068 | static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1069 | struct fc_seq *sp, struct fc_frame *rx_fp) |
| 1070 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1071 | struct fc_lport *lport = rdata->local_port; |
| 1072 | struct fc_exch *ep; |
| 1073 | struct fc_frame *fp; |
| 1074 | struct fc_frame_header *fh; |
| 1075 | struct { |
| 1076 | struct fc_els_prli prli; |
| 1077 | struct fc_els_spp spp; |
| 1078 | } *pp; |
| 1079 | struct fc_els_spp *rspp; /* request service param page */ |
| 1080 | struct fc_els_spp *spp; /* response spp */ |
| 1081 | unsigned int len; |
| 1082 | unsigned int plen; |
| 1083 | enum fc_els_rjt_reason reason = ELS_RJT_UNAB; |
| 1084 | enum fc_els_rjt_explan explan = ELS_EXPL_NONE; |
| 1085 | enum fc_els_spp_resp resp; |
| 1086 | struct fc_seq_els_data rjt_data; |
| 1087 | u32 f_ctl; |
| 1088 | u32 fcp_parm; |
| 1089 | u32 roles = FC_RPORT_ROLE_UNKNOWN; |
| 1090 | rjt_data.fp = NULL; |
| 1091 | |
| 1092 | fh = fc_frame_header_get(rx_fp); |
| 1093 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1094 | FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n", |
| 1095 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1096 | |
| 1097 | switch (rdata->rp_state) { |
| 1098 | case RPORT_ST_PRLI: |
| 1099 | case RPORT_ST_READY: |
| 1100 | reason = ELS_RJT_NONE; |
| 1101 | break; |
| 1102 | default: |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 1103 | fc_frame_free(rx_fp); |
| 1104 | return; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1105 | break; |
| 1106 | } |
| 1107 | len = fr_len(rx_fp) - sizeof(*fh); |
| 1108 | pp = fc_frame_payload_get(rx_fp, sizeof(*pp)); |
| 1109 | if (pp == NULL) { |
| 1110 | reason = ELS_RJT_PROT; |
| 1111 | explan = ELS_EXPL_INV_LEN; |
| 1112 | } else { |
| 1113 | plen = ntohs(pp->prli.prli_len); |
| 1114 | if ((plen % 4) != 0 || plen > len) { |
| 1115 | reason = ELS_RJT_PROT; |
| 1116 | explan = ELS_EXPL_INV_LEN; |
| 1117 | } else if (plen < len) { |
| 1118 | len = plen; |
| 1119 | } |
| 1120 | plen = pp->prli.prli_spp_len; |
| 1121 | if ((plen % 4) != 0 || plen < sizeof(*spp) || |
| 1122 | plen > len || len < sizeof(*pp)) { |
| 1123 | reason = ELS_RJT_PROT; |
| 1124 | explan = ELS_EXPL_INV_LEN; |
| 1125 | } |
| 1126 | rspp = &pp->spp; |
| 1127 | } |
| 1128 | if (reason != ELS_RJT_NONE || |
| 1129 | (fp = fc_frame_alloc(lport, len)) == NULL) { |
| 1130 | rjt_data.reason = reason; |
| 1131 | rjt_data.explan = explan; |
| 1132 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1133 | } else { |
| 1134 | sp = lport->tt.seq_start_next(sp); |
| 1135 | WARN_ON(!sp); |
| 1136 | pp = fc_frame_payload_get(fp, len); |
| 1137 | WARN_ON(!pp); |
| 1138 | memset(pp, 0, len); |
| 1139 | pp->prli.prli_cmd = ELS_LS_ACC; |
| 1140 | pp->prli.prli_spp_len = plen; |
| 1141 | pp->prli.prli_len = htons(len); |
| 1142 | len -= sizeof(struct fc_els_prli); |
| 1143 | |
| 1144 | /* |
| 1145 | * Go through all the service parameter pages and build |
| 1146 | * response. If plen indicates longer SPP than standard, |
| 1147 | * use that. The entire response has been pre-cleared above. |
| 1148 | */ |
| 1149 | spp = &pp->spp; |
| 1150 | while (len >= plen) { |
| 1151 | spp->spp_type = rspp->spp_type; |
| 1152 | spp->spp_type_ext = rspp->spp_type_ext; |
| 1153 | spp->spp_flags = rspp->spp_flags & FC_SPP_EST_IMG_PAIR; |
| 1154 | resp = FC_SPP_RESP_ACK; |
| 1155 | if (rspp->spp_flags & FC_SPP_RPA_VAL) |
| 1156 | resp = FC_SPP_RESP_NO_PA; |
| 1157 | switch (rspp->spp_type) { |
| 1158 | case 0: /* common to all FC-4 types */ |
| 1159 | break; |
| 1160 | case FC_TYPE_FCP: |
| 1161 | fcp_parm = ntohl(rspp->spp_params); |
| 1162 | if (fcp_parm * FCP_SPPF_RETRY) |
| 1163 | rdata->flags |= FC_RP_FLAGS_RETRY; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 1164 | rdata->supported_classes = FC_COS_CLASS3; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1165 | if (fcp_parm & FCP_SPPF_INIT_FCN) |
| 1166 | roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 1167 | if (fcp_parm & FCP_SPPF_TARG_FCN) |
| 1168 | roles |= FC_RPORT_ROLE_FCP_TARGET; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 1169 | rdata->ids.roles = roles; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1170 | |
| 1171 | spp->spp_params = |
| 1172 | htonl(lport->service_params); |
| 1173 | break; |
| 1174 | default: |
| 1175 | resp = FC_SPP_RESP_INVL; |
| 1176 | break; |
| 1177 | } |
| 1178 | spp->spp_flags |= resp; |
| 1179 | len -= plen; |
| 1180 | rspp = (struct fc_els_spp *)((char *)rspp + plen); |
| 1181 | spp = (struct fc_els_spp *)((char *)spp + plen); |
| 1182 | } |
| 1183 | |
| 1184 | /* |
| 1185 | * Send LS_ACC. If this fails, the originator should retry. |
| 1186 | */ |
| 1187 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; |
| 1188 | f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 1189 | ep = fc_seq_exch(sp); |
| 1190 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1191 | FC_TYPE_ELS, f_ctl, 0); |
| 1192 | lport->tt.seq_send(lport, sp, fp); |
| 1193 | |
| 1194 | /* |
| 1195 | * Get lock and re-check state. |
| 1196 | */ |
| 1197 | switch (rdata->rp_state) { |
| 1198 | case RPORT_ST_PRLI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1199 | fc_rport_enter_ready(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1200 | break; |
| 1201 | case RPORT_ST_READY: |
| 1202 | break; |
| 1203 | default: |
| 1204 | break; |
| 1205 | } |
| 1206 | } |
| 1207 | fc_frame_free(rx_fp); |
| 1208 | } |
| 1209 | |
| 1210 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1211 | * fc_rport_recv_prlo_req() - Handle incoming Process Logout (PRLO) request |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1212 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1213 | * @sp: current sequence in the PRLO exchange |
| 1214 | * @fp: PRLO request frame |
| 1215 | * |
| 1216 | * Locking Note: The rport lock is exected to be held before calling |
| 1217 | * this function. |
| 1218 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1219 | static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata, |
| 1220 | struct fc_seq *sp, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1221 | struct fc_frame *fp) |
| 1222 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1223 | struct fc_lport *lport = rdata->local_port; |
| 1224 | |
| 1225 | struct fc_frame_header *fh; |
| 1226 | struct fc_seq_els_data rjt_data; |
| 1227 | |
| 1228 | fh = fc_frame_header_get(fp); |
| 1229 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1230 | FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n", |
| 1231 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1232 | |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 1233 | if (rdata->rp_state == RPORT_ST_DELETE) { |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 1234 | fc_frame_free(fp); |
| 1235 | return; |
| 1236 | } |
| 1237 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1238 | rjt_data.fp = NULL; |
| 1239 | rjt_data.reason = ELS_RJT_UNAB; |
| 1240 | rjt_data.explan = ELS_EXPL_NONE; |
| 1241 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1242 | fc_frame_free(fp); |
| 1243 | } |
| 1244 | |
| 1245 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1246 | * fc_rport_recv_logo_req() - Handle incoming Logout (LOGO) request |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1247 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1248 | * @sp: current sequence in the LOGO exchange |
| 1249 | * @fp: LOGO request frame |
| 1250 | * |
| 1251 | * Locking Note: The rport lock is exected to be held before calling |
| 1252 | * this function. |
| 1253 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1254 | static void fc_rport_recv_logo_req(struct fc_rport_priv *rdata, |
| 1255 | struct fc_seq *sp, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1256 | struct fc_frame *fp) |
| 1257 | { |
| 1258 | struct fc_frame_header *fh; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1259 | struct fc_lport *lport = rdata->local_port; |
| 1260 | |
| 1261 | fh = fc_frame_header_get(fp); |
| 1262 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1263 | FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n", |
| 1264 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1265 | |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 1266 | if (rdata->rp_state == RPORT_ST_DELETE) { |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 1267 | fc_frame_free(fp); |
| 1268 | return; |
| 1269 | } |
| 1270 | |
Joe Eykholt | 00fea93 | 2009-08-25 14:01:23 -0700 | [diff] [blame] | 1271 | fc_rport_enter_delete(rdata, RPORT_EV_LOGO); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1272 | |
| 1273 | lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); |
| 1274 | fc_frame_free(fp); |
| 1275 | } |
| 1276 | |
| 1277 | static void fc_rport_flush_queue(void) |
| 1278 | { |
| 1279 | flush_workqueue(rport_event_queue); |
| 1280 | } |
| 1281 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1282 | int fc_rport_init(struct fc_lport *lport) |
| 1283 | { |
Robert Love | 5101ff9 | 2009-02-27 10:55:18 -0800 | [diff] [blame] | 1284 | if (!lport->tt.rport_create) |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 1285 | lport->tt.rport_create = fc_rport_create; |
Robert Love | 5101ff9 | 2009-02-27 10:55:18 -0800 | [diff] [blame] | 1286 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1287 | if (!lport->tt.rport_login) |
| 1288 | lport->tt.rport_login = fc_rport_login; |
| 1289 | |
| 1290 | if (!lport->tt.rport_logoff) |
| 1291 | lport->tt.rport_logoff = fc_rport_logoff; |
| 1292 | |
| 1293 | if (!lport->tt.rport_recv_req) |
| 1294 | lport->tt.rport_recv_req = fc_rport_recv_req; |
| 1295 | |
| 1296 | if (!lport->tt.rport_flush_queue) |
| 1297 | lport->tt.rport_flush_queue = fc_rport_flush_queue; |
| 1298 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 1299 | if (!lport->tt.rport_destroy) |
| 1300 | lport->tt.rport_destroy = fc_rport_destroy; |
| 1301 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1302 | return 0; |
| 1303 | } |
| 1304 | EXPORT_SYMBOL(fc_rport_init); |
| 1305 | |
Randy Dunlap | b0d428a | 2009-04-27 21:49:31 -0700 | [diff] [blame] | 1306 | int fc_setup_rport(void) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1307 | { |
| 1308 | rport_event_queue = create_singlethread_workqueue("fc_rport_eq"); |
| 1309 | if (!rport_event_queue) |
| 1310 | return -ENOMEM; |
| 1311 | return 0; |
| 1312 | } |
| 1313 | EXPORT_SYMBOL(fc_setup_rport); |
| 1314 | |
Randy Dunlap | b0d428a | 2009-04-27 21:49:31 -0700 | [diff] [blame] | 1315 | void fc_destroy_rport(void) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1316 | { |
| 1317 | destroy_workqueue(rport_event_queue); |
| 1318 | } |
| 1319 | EXPORT_SYMBOL(fc_destroy_rport); |
| 1320 | |
| 1321 | void fc_rport_terminate_io(struct fc_rport *rport) |
| 1322 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 1323 | struct fc_rport_libfc_priv *rp = rport->dd_data; |
| 1324 | struct fc_lport *lport = rp->local_port; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1325 | |
Abhijeet Joglekar | 1f6ff36 | 2009-02-27 10:54:35 -0800 | [diff] [blame] | 1326 | lport->tt.exch_mgr_reset(lport, 0, rport->port_id); |
| 1327 | lport->tt.exch_mgr_reset(lport, rport->port_id, 0); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1328 | } |
| 1329 | EXPORT_SYMBOL(fc_rport_terminate_io); |