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