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