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