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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 50 | #include <linux/slab.h> |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 51 | #include <linux/rcupdate.h> |
| 52 | #include <linux/timer.h> |
| 53 | #include <linux/workqueue.h> |
| 54 | #include <asm/unaligned.h> |
| 55 | |
| 56 | #include <scsi/libfc.h> |
| 57 | #include <scsi/fc_encode.h> |
| 58 | |
Robert Love | 8866a5d | 2009-11-03 11:45:58 -0800 | [diff] [blame] | 59 | #include "fc_libfc.h" |
| 60 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 61 | struct workqueue_struct *rport_event_queue; |
| 62 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 63 | static void fc_rport_enter_plogi(struct fc_rport_priv *); |
| 64 | static void fc_rport_enter_prli(struct fc_rport_priv *); |
| 65 | static void fc_rport_enter_rtv(struct fc_rport_priv *); |
| 66 | static void fc_rport_enter_ready(struct fc_rport_priv *); |
| 67 | static void fc_rport_enter_logo(struct fc_rport_priv *); |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 68 | static void fc_rport_enter_adisc(struct fc_rport_priv *); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 69 | |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 70 | static void fc_rport_recv_plogi_req(struct fc_lport *, |
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_prli_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 73 | struct fc_seq *, struct fc_frame *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 74 | static void fc_rport_recv_prlo_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 75 | struct fc_seq *, struct fc_frame *); |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 76 | static void fc_rport_recv_logo_req(struct fc_lport *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 77 | struct fc_seq *, struct fc_frame *); |
| 78 | static void fc_rport_timeout(struct work_struct *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 79 | static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *); |
| 80 | 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] | 81 | static void fc_rport_work(struct work_struct *); |
| 82 | |
| 83 | static const char *fc_rport_state_names[] = { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 84 | [RPORT_ST_INIT] = "Init", |
| 85 | [RPORT_ST_PLOGI] = "PLOGI", |
| 86 | [RPORT_ST_PRLI] = "PRLI", |
| 87 | [RPORT_ST_RTV] = "RTV", |
| 88 | [RPORT_ST_READY] = "Ready", |
| 89 | [RPORT_ST_LOGO] = "LOGO", |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 90 | [RPORT_ST_ADISC] = "ADISC", |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 91 | [RPORT_ST_DELETE] = "Delete", |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 94 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 95 | * fc_rport_lookup() - Lookup a remote port by port_id |
| 96 | * @lport: The local port to lookup the remote port on |
| 97 | * @port_id: The remote port ID to look up |
Joe Eykholt | 8025b5d | 2009-08-25 14:02:06 -0700 | [diff] [blame] | 98 | */ |
| 99 | static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport, |
| 100 | u32 port_id) |
| 101 | { |
| 102 | struct fc_rport_priv *rdata; |
| 103 | |
| 104 | list_for_each_entry(rdata, &lport->disc.rports, peers) |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 105 | if (rdata->ids.port_id == port_id) |
Joe Eykholt | 8025b5d | 2009-08-25 14:02:06 -0700 | [diff] [blame] | 106 | return rdata; |
| 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | /** |
Robert Love | 9737e6a | 2009-08-25 14:02:59 -0700 | [diff] [blame] | 111 | * fc_rport_create() - Create a new remote port |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 112 | * @lport: The local port this remote port will be associated with |
| 113 | * @ids: The identifiers for the new remote port |
| 114 | * |
| 115 | * The remote port will start in the INIT state. |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 116 | * |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 117 | * Locking note: must be called with the disc_mutex held. |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 118 | */ |
| 119 | static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, |
Robert Love | 9737e6a | 2009-08-25 14:02:59 -0700 | [diff] [blame] | 120 | u32 port_id) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 121 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 122 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 123 | |
Robert Love | 9737e6a | 2009-08-25 14:02:59 -0700 | [diff] [blame] | 124 | rdata = lport->tt.rport_lookup(lport, port_id); |
Joe Eykholt | 19f97e3 | 2009-08-25 14:01:55 -0700 | [diff] [blame] | 125 | if (rdata) |
| 126 | return rdata; |
| 127 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 128 | rdata = kzalloc(sizeof(*rdata), GFP_KERNEL); |
| 129 | if (!rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 130 | return NULL; |
| 131 | |
Robert Love | 9737e6a | 2009-08-25 14:02:59 -0700 | [diff] [blame] | 132 | rdata->ids.node_name = -1; |
| 133 | rdata->ids.port_name = -1; |
| 134 | rdata->ids.port_id = port_id; |
| 135 | rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 136 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 137 | kref_init(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 138 | mutex_init(&rdata->rp_mutex); |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 139 | rdata->local_port = lport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 140 | rdata->rp_state = RPORT_ST_INIT; |
| 141 | rdata->event = RPORT_EV_NONE; |
| 142 | rdata->flags = FC_RP_FLAGS_REC_SUPPORTED; |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 143 | rdata->e_d_tov = lport->e_d_tov; |
| 144 | rdata->r_a_tov = lport->r_a_tov; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 145 | rdata->maxframe_size = FC_MIN_MAX_PAYLOAD; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 146 | INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout); |
| 147 | INIT_WORK(&rdata->event_work, fc_rport_work); |
Robert Love | 9737e6a | 2009-08-25 14:02:59 -0700 | [diff] [blame] | 148 | if (port_id != FC_FID_DIR_SERV) |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 149 | list_add(&rdata->peers, &lport->disc.rports); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 150 | return rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 154 | * fc_rport_destroy() - Free a remote port after last reference is released |
| 155 | * @kref: The remote port's kref |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 156 | */ |
| 157 | static void fc_rport_destroy(struct kref *kref) |
| 158 | { |
| 159 | struct fc_rport_priv *rdata; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 160 | |
| 161 | rdata = container_of(kref, struct fc_rport_priv, kref); |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 162 | kfree(rdata); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 166 | * fc_rport_state() - Return a string identifying the remote port's state |
| 167 | * @rdata: The remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 168 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 169 | static const char *fc_rport_state(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 170 | { |
| 171 | const char *cp; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 172 | |
| 173 | cp = fc_rport_state_names[rdata->rp_state]; |
| 174 | if (!cp) |
| 175 | cp = "Unknown"; |
| 176 | return cp; |
| 177 | } |
| 178 | |
| 179 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 180 | * fc_set_rport_loss_tmo() - Set the remote port loss timeout |
| 181 | * @rport: The remote port that gets a new timeout value |
| 182 | * @timeout: The new timeout value (in seconds) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 183 | */ |
| 184 | void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) |
| 185 | { |
| 186 | if (timeout) |
| 187 | rport->dev_loss_tmo = timeout + 5; |
| 188 | else |
| 189 | rport->dev_loss_tmo = 30; |
| 190 | } |
| 191 | EXPORT_SYMBOL(fc_set_rport_loss_tmo); |
| 192 | |
| 193 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 194 | * fc_plogi_get_maxframe() - Get the maximum payload from the common service |
| 195 | * parameters in a FLOGI frame |
| 196 | * @flp: The FLOGI payload |
| 197 | * @maxval: The maximum frame size upper limit; this may be less than what |
| 198 | * is in the service parameters |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 199 | */ |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 200 | static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp, |
| 201 | unsigned int maxval) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 202 | { |
| 203 | unsigned int mfs; |
| 204 | |
| 205 | /* |
| 206 | * Get max payload from the common service parameters and the |
| 207 | * class 3 receive data field size. |
| 208 | */ |
| 209 | mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK; |
| 210 | if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval) |
| 211 | maxval = mfs; |
| 212 | mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs); |
| 213 | if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval) |
| 214 | maxval = mfs; |
| 215 | return maxval; |
| 216 | } |
| 217 | |
| 218 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 219 | * fc_rport_state_enter() - Change the state of a remote port |
| 220 | * @rdata: The remote port whose state should change |
| 221 | * @new: The new state |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 222 | * |
| 223 | * Locking Note: Called with the rport lock held |
| 224 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 225 | static void fc_rport_state_enter(struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 226 | enum fc_rport_state new) |
| 227 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 228 | if (rdata->rp_state != new) |
| 229 | rdata->retries = 0; |
| 230 | rdata->rp_state = new; |
| 231 | } |
| 232 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 233 | /** |
| 234 | * fc_rport_work() - Handler for remote port events in the rport_event_queue |
| 235 | * @work: Handle to the remote port being dequeued |
| 236 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 237 | static void fc_rport_work(struct work_struct *work) |
| 238 | { |
Abhijeet Joglekar | 571f824 | 2009-02-27 10:54:41 -0800 | [diff] [blame] | 239 | u32 port_id; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 240 | struct fc_rport_priv *rdata = |
| 241 | container_of(work, struct fc_rport_priv, event_work); |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 242 | struct fc_rport_libfc_priv *rpriv; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 243 | enum fc_rport_event event; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 244 | struct fc_lport *lport = rdata->local_port; |
| 245 | struct fc_rport_operations *rport_ops; |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 246 | struct fc_rport_identifiers ids; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 247 | struct fc_rport *rport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 248 | |
| 249 | mutex_lock(&rdata->rp_mutex); |
| 250 | event = rdata->event; |
| 251 | rport_ops = rdata->ops; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 252 | rport = rdata->rport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 253 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 254 | FC_RPORT_DBG(rdata, "work event %u\n", event); |
| 255 | |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 256 | switch (event) { |
Joe Eykholt | 4c0f62b | 2009-08-25 14:01:12 -0700 | [diff] [blame] | 257 | case RPORT_EV_READY: |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 258 | ids = rdata->ids; |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 259 | rdata->event = RPORT_EV_NONE; |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 260 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 261 | mutex_unlock(&rdata->rp_mutex); |
| 262 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 263 | if (!rport) |
| 264 | rport = fc_remote_port_add(lport->host, 0, &ids); |
| 265 | if (!rport) { |
| 266 | FC_RPORT_DBG(rdata, "Failed to add the rport\n"); |
| 267 | lport->tt.rport_logoff(rdata); |
| 268 | kref_put(&rdata->kref, lport->tt.rport_destroy); |
| 269 | return; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 270 | } |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 271 | mutex_lock(&rdata->rp_mutex); |
| 272 | if (rdata->rport) |
| 273 | FC_RPORT_DBG(rdata, "rport already allocated\n"); |
| 274 | rdata->rport = rport; |
| 275 | rport->maxframe_size = rdata->maxframe_size; |
| 276 | rport->supported_classes = rdata->supported_classes; |
| 277 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 278 | rpriv = rport->dd_data; |
| 279 | rpriv->local_port = lport; |
| 280 | rpriv->rp_state = rdata->rp_state; |
| 281 | rpriv->flags = rdata->flags; |
| 282 | rpriv->e_d_tov = rdata->e_d_tov; |
| 283 | rpriv->r_a_tov = rdata->r_a_tov; |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 284 | mutex_unlock(&rdata->rp_mutex); |
| 285 | |
Joe Eykholt | 8345592 | 2009-08-25 14:02:01 -0700 | [diff] [blame] | 286 | if (rport_ops && rport_ops->event_callback) { |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 287 | FC_RPORT_DBG(rdata, "callback ev %d\n", event); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 288 | rport_ops->event_callback(lport, rdata, event); |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 289 | } |
| 290 | kref_put(&rdata->kref, lport->tt.rport_destroy); |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 291 | break; |
| 292 | |
| 293 | case RPORT_EV_FAILED: |
| 294 | case RPORT_EV_LOGO: |
| 295 | case RPORT_EV_STOP: |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 296 | port_id = rdata->ids.port_id; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 297 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 298 | |
Joe Eykholt | 8345592 | 2009-08-25 14:02:01 -0700 | [diff] [blame] | 299 | if (rport_ops && rport_ops->event_callback) { |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 300 | FC_RPORT_DBG(rdata, "callback ev %d\n", event); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 301 | rport_ops->event_callback(lport, rdata, event); |
Abhijeet Joglekar | 571f824 | 2009-02-27 10:54:41 -0800 | [diff] [blame] | 302 | } |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 303 | cancel_delayed_work_sync(&rdata->retry_work); |
| 304 | |
| 305 | /* |
| 306 | * Reset any outstanding exchanges before freeing rport. |
| 307 | */ |
| 308 | lport->tt.exch_mgr_reset(lport, 0, port_id); |
| 309 | lport->tt.exch_mgr_reset(lport, port_id, 0); |
| 310 | |
| 311 | if (rport) { |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 312 | rpriv = rport->dd_data; |
| 313 | rpriv->rp_state = RPORT_ST_DELETE; |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 314 | mutex_lock(&rdata->rp_mutex); |
| 315 | rdata->rport = NULL; |
| 316 | mutex_unlock(&rdata->rp_mutex); |
| 317 | fc_remote_port_delete(rport); |
| 318 | } |
Joe Eykholt | 4b2164d | 2010-06-11 16:44:51 -0700 | [diff] [blame^] | 319 | |
| 320 | mutex_lock(&lport->disc.disc_mutex); |
| 321 | mutex_lock(&rdata->rp_mutex); |
| 322 | if (rdata->rp_state == RPORT_ST_DELETE) { |
| 323 | if (port_id == FC_FID_DIR_SERV) { |
| 324 | rdata->event = RPORT_EV_NONE; |
| 325 | mutex_unlock(&rdata->rp_mutex); |
| 326 | } else if (rdata->flags & FC_RP_STARTED) { |
| 327 | rdata->event = RPORT_EV_NONE; |
| 328 | FC_RPORT_DBG(rdata, "work restart\n"); |
| 329 | fc_rport_enter_plogi(rdata); |
| 330 | mutex_unlock(&rdata->rp_mutex); |
| 331 | } else { |
| 332 | FC_RPORT_DBG(rdata, "work delete\n"); |
| 333 | list_del(&rdata->peers); |
| 334 | mutex_unlock(&rdata->rp_mutex); |
| 335 | kref_put(&rdata->kref, lport->tt.rport_destroy); |
| 336 | } |
| 337 | } else { |
| 338 | /* |
| 339 | * Re-open for events. Reissue READY event if ready. |
| 340 | */ |
| 341 | rdata->event = RPORT_EV_NONE; |
| 342 | if (rdata->rp_state == RPORT_ST_READY) |
| 343 | fc_rport_enter_ready(rdata); |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 344 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | 4b2164d | 2010-06-11 16:44:51 -0700 | [diff] [blame^] | 345 | } |
| 346 | mutex_unlock(&lport->disc.disc_mutex); |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 347 | break; |
| 348 | |
| 349 | default: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 350 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | 629f442 | 2009-08-25 14:01:06 -0700 | [diff] [blame] | 351 | break; |
| 352 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 356 | * fc_rport_login() - Start the remote port login state machine |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 357 | * @rdata: The remote port to be logged in to |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 358 | * |
| 359 | * Locking Note: Called without the rport lock held. This |
| 360 | * function will hold the rport lock, call an _enter_* |
| 361 | * function and then unlock the rport. |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 362 | * |
| 363 | * This indicates the intent to be logged into the remote port. |
| 364 | * If it appears we are already logged in, ADISC is used to verify |
| 365 | * the setup. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 366 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 367 | int fc_rport_login(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 368 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 369 | mutex_lock(&rdata->rp_mutex); |
| 370 | |
Joe Eykholt | 4b2164d | 2010-06-11 16:44:51 -0700 | [diff] [blame^] | 371 | rdata->flags |= FC_RP_STARTED; |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 372 | switch (rdata->rp_state) { |
| 373 | case RPORT_ST_READY: |
| 374 | FC_RPORT_DBG(rdata, "ADISC port\n"); |
| 375 | fc_rport_enter_adisc(rdata); |
| 376 | break; |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 377 | case RPORT_ST_DELETE: |
| 378 | FC_RPORT_DBG(rdata, "Restart deleted port\n"); |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 379 | break; |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 380 | default: |
| 381 | FC_RPORT_DBG(rdata, "Login to port\n"); |
| 382 | fc_rport_enter_plogi(rdata); |
| 383 | break; |
| 384 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 385 | mutex_unlock(&rdata->rp_mutex); |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 391 | * fc_rport_enter_delete() - Schedule a remote port to be deleted |
| 392 | * @rdata: The remote port to be deleted |
| 393 | * @event: The event to report as the reason for deletion |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 394 | * |
| 395 | * Locking Note: Called with the rport lock held. |
| 396 | * |
| 397 | * Allow state change into DELETE only once. |
| 398 | * |
| 399 | * Call queue_work only if there's no event already pending. |
| 400 | * Set the new event so that the old pending event will not occur. |
| 401 | * Since we have the mutex, even if fc_rport_work() is already started, |
| 402 | * it'll see the new event. |
| 403 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 404 | static void fc_rport_enter_delete(struct fc_rport_priv *rdata, |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 405 | enum fc_rport_event event) |
| 406 | { |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 407 | if (rdata->rp_state == RPORT_ST_DELETE) |
| 408 | return; |
| 409 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 410 | FC_RPORT_DBG(rdata, "Delete port\n"); |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 411 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 412 | fc_rport_state_enter(rdata, RPORT_ST_DELETE); |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 413 | |
| 414 | if (rdata->event == RPORT_EV_NONE) |
| 415 | queue_work(rport_event_queue, &rdata->event_work); |
| 416 | rdata->event = event; |
| 417 | } |
| 418 | |
| 419 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 420 | * fc_rport_logoff() - Logoff and remove a remote port |
| 421 | * @rdata: The remote port to be logged off of |
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 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 427 | int fc_rport_logoff(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 428 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 429 | mutex_lock(&rdata->rp_mutex); |
| 430 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 431 | FC_RPORT_DBG(rdata, "Remove port\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 432 | |
Joe Eykholt | 4b2164d | 2010-06-11 16:44:51 -0700 | [diff] [blame^] | 433 | rdata->flags &= ~FC_RP_STARTED; |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 434 | if (rdata->rp_state == RPORT_ST_DELETE) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 435 | FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n"); |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 436 | goto out; |
| 437 | } |
Joe Eykholt | 4b2164d | 2010-06-11 16:44:51 -0700 | [diff] [blame^] | 438 | fc_rport_enter_logo(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 439 | |
| 440 | /* |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 441 | * Change the state to Delete so that we discard |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 442 | * the response. |
| 443 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 444 | fc_rport_enter_delete(rdata, RPORT_EV_STOP); |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 445 | out: |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 446 | mutex_unlock(&rdata->rp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 451 | * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state |
| 452 | * @rdata: The remote port that is ready |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 453 | * |
| 454 | * Locking Note: The rport lock is expected to be held before calling |
| 455 | * this routine. |
| 456 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 457 | static void fc_rport_enter_ready(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 458 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 459 | fc_rport_state_enter(rdata, RPORT_ST_READY); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 460 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 461 | FC_RPORT_DBG(rdata, "Port is Ready\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 462 | |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 463 | if (rdata->event == RPORT_EV_NONE) |
| 464 | queue_work(rport_event_queue, &rdata->event_work); |
Joe Eykholt | 4c0f62b | 2009-08-25 14:01:12 -0700 | [diff] [blame] | 465 | rdata->event = RPORT_EV_READY; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 469 | * fc_rport_timeout() - Handler for the retry_work timer |
| 470 | * @work: Handle to the remote port that has timed out |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 471 | * |
| 472 | * Locking Note: Called without the rport lock held. This |
| 473 | * function will hold the rport lock, call an _enter_* |
| 474 | * function and then unlock the rport. |
| 475 | */ |
| 476 | static void fc_rport_timeout(struct work_struct *work) |
| 477 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 478 | struct fc_rport_priv *rdata = |
| 479 | container_of(work, struct fc_rport_priv, retry_work.work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 480 | |
| 481 | mutex_lock(&rdata->rp_mutex); |
| 482 | |
| 483 | switch (rdata->rp_state) { |
| 484 | case RPORT_ST_PLOGI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 485 | fc_rport_enter_plogi(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 486 | break; |
| 487 | case RPORT_ST_PRLI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 488 | fc_rport_enter_prli(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 489 | break; |
| 490 | case RPORT_ST_RTV: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 491 | fc_rport_enter_rtv(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 492 | break; |
| 493 | case RPORT_ST_LOGO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 494 | fc_rport_enter_logo(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 495 | break; |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 496 | case RPORT_ST_ADISC: |
| 497 | fc_rport_enter_adisc(rdata); |
| 498 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 499 | case RPORT_ST_READY: |
| 500 | case RPORT_ST_INIT: |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 501 | case RPORT_ST_DELETE: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 502 | break; |
| 503 | } |
| 504 | |
| 505 | mutex_unlock(&rdata->rp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 509 | * fc_rport_error() - Error handler, called once retries have been exhausted |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 510 | * @rdata: The remote port the error is happened on |
| 511 | * @fp: The error code encapsulated in a frame pointer |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 512 | * |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 513 | * Locking Note: The rport lock is expected to be held before |
| 514 | * calling this routine |
| 515 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 516 | 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] | 517 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 518 | FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n", |
Joe Eykholt | cdbe6df | 2009-08-25 14:01:39 -0700 | [diff] [blame] | 519 | IS_ERR(fp) ? -PTR_ERR(fp) : 0, |
| 520 | fc_rport_state(rdata), rdata->retries); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 521 | |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 522 | switch (rdata->rp_state) { |
| 523 | case RPORT_ST_PLOGI: |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 524 | case RPORT_ST_LOGO: |
Joe Eykholt | 4b2164d | 2010-06-11 16:44:51 -0700 | [diff] [blame^] | 525 | rdata->flags &= ~FC_RP_STARTED; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 526 | fc_rport_enter_delete(rdata, RPORT_EV_FAILED); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 527 | break; |
| 528 | case RPORT_ST_RTV: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 529 | fc_rport_enter_ready(rdata); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 530 | break; |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 531 | case RPORT_ST_PRLI: |
| 532 | case RPORT_ST_ADISC: |
| 533 | fc_rport_enter_logo(rdata); |
| 534 | break; |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 535 | case RPORT_ST_DELETE: |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 536 | case RPORT_ST_READY: |
| 537 | case RPORT_ST_INIT: |
| 538 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
| 542 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 543 | * fc_rport_error_retry() - Handler for remote port state retries |
| 544 | * @rdata: The remote port whose state is to be retried |
| 545 | * @fp: The error code encapsulated in a frame pointer |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 546 | * |
| 547 | * If the error was an exchange timeout retry immediately, |
| 548 | * otherwise wait for E_D_TOV. |
| 549 | * |
| 550 | * Locking Note: The rport lock is expected to be held before |
| 551 | * calling this routine |
| 552 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 553 | static void fc_rport_error_retry(struct fc_rport_priv *rdata, |
| 554 | struct fc_frame *fp) |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 555 | { |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 556 | unsigned long delay = FC_DEF_E_D_TOV; |
| 557 | |
| 558 | /* make sure this isn't an FC_EX_CLOSED error, never retry those */ |
| 559 | if (PTR_ERR(fp) == -FC_EX_CLOSED) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 560 | return fc_rport_error(rdata, fp); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 561 | |
Abhijeet Joglekar | a366695 | 2009-05-01 10:01:26 -0700 | [diff] [blame] | 562 | if (rdata->retries < rdata->local_port->max_rport_retry_count) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 563 | FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n", |
| 564 | PTR_ERR(fp), fc_rport_state(rdata)); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 565 | rdata->retries++; |
| 566 | /* no additional delay on exchange timeouts */ |
| 567 | if (PTR_ERR(fp) == -FC_EX_TIMEOUT) |
| 568 | delay = 0; |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 569 | schedule_delayed_work(&rdata->retry_work, delay); |
| 570 | return; |
| 571 | } |
| 572 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 573 | return fc_rport_error(rdata, fp); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 577 | * fc_rport_plogi_recv_resp() - Handler for ELS PLOGI responses |
| 578 | * @sp: The sequence the PLOGI is on |
| 579 | * @fp: The PLOGI response frame |
| 580 | * @rdata_arg: The remote port that sent the PLOGI response |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 581 | * |
| 582 | * Locking Note: This function will be called without the rport lock |
| 583 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 584 | * and then unlock the rport. |
| 585 | */ |
| 586 | 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] | 587 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 588 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 589 | struct fc_rport_priv *rdata = rdata_arg; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 590 | struct fc_lport *lport = rdata->local_port; |
Robert Love | a29e764 | 2009-04-21 16:27:41 -0700 | [diff] [blame] | 591 | struct fc_els_flogi *plp = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 592 | unsigned int tov; |
| 593 | u16 csp_seq; |
| 594 | u16 cssp_seq; |
| 595 | u8 op; |
| 596 | |
| 597 | mutex_lock(&rdata->rp_mutex); |
| 598 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 599 | 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] | 600 | |
| 601 | if (rdata->rp_state != RPORT_ST_PLOGI) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 602 | FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state " |
| 603 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 604 | if (IS_ERR(fp)) |
| 605 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 606 | goto out; |
| 607 | } |
| 608 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 609 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 610 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 611 | goto err; |
| 612 | } |
| 613 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 614 | op = fc_frame_payload_op(fp); |
| 615 | if (op == ELS_LS_ACC && |
| 616 | (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) { |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 617 | rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn); |
| 618 | rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 619 | |
| 620 | tov = ntohl(plp->fl_csp.sp_e_d_tov); |
| 621 | if (ntohs(plp->fl_csp.sp_features) & FC_SP_FT_EDTR) |
Hugh Daschbach | 3b70915 | 2010-01-21 10:15:49 -0800 | [diff] [blame] | 622 | tov /= 1000000; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 623 | if (tov > rdata->e_d_tov) |
| 624 | rdata->e_d_tov = tov; |
| 625 | csp_seq = ntohs(plp->fl_csp.sp_tot_seq); |
| 626 | cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq); |
| 627 | if (cssp_seq < csp_seq) |
| 628 | csp_seq = cssp_seq; |
| 629 | rdata->max_seq = csp_seq; |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 630 | rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs); |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 631 | fc_rport_enter_prli(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 632 | } else |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 633 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 634 | |
| 635 | out: |
| 636 | fc_frame_free(fp); |
| 637 | err: |
| 638 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 639 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 643 | * fc_rport_enter_plogi() - Send Port Login (PLOGI) request |
| 644 | * @rdata: The remote port to send a PLOGI to |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 645 | * |
| 646 | * Locking Note: The rport lock is expected to be held before calling |
| 647 | * this routine. |
| 648 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 649 | static void fc_rport_enter_plogi(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 650 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 651 | struct fc_lport *lport = rdata->local_port; |
| 652 | struct fc_frame *fp; |
| 653 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 654 | FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n", |
| 655 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 656 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 657 | fc_rport_state_enter(rdata, RPORT_ST_PLOGI); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 658 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 659 | rdata->maxframe_size = FC_MIN_MAX_PAYLOAD; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 660 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); |
| 661 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 662 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 663 | return; |
| 664 | } |
| 665 | rdata->e_d_tov = lport->e_d_tov; |
| 666 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 667 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI, |
Joe Eykholt | b94f895 | 2009-11-03 11:50:21 -0800 | [diff] [blame] | 668 | fc_rport_plogi_resp, rdata, |
| 669 | 2 * lport->r_a_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 670 | fc_rport_error_retry(rdata, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 671 | else |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 672 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 676 | * fc_rport_prli_resp() - Process Login (PRLI) response handler |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 677 | * @sp: The sequence the PRLI response was on |
| 678 | * @fp: The PRLI response frame |
| 679 | * @rdata_arg: The remote port that sent the PRLI response |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 680 | * |
| 681 | * Locking Note: This function will be called without the rport lock |
| 682 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 683 | * and then unlock the rport. |
| 684 | */ |
| 685 | 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] | 686 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 687 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 688 | struct fc_rport_priv *rdata = rdata_arg; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 689 | struct { |
| 690 | struct fc_els_prli prli; |
| 691 | struct fc_els_spp spp; |
| 692 | } *pp; |
| 693 | u32 roles = FC_RPORT_ROLE_UNKNOWN; |
| 694 | u32 fcp_parm = 0; |
| 695 | u8 op; |
Bhanu Prakash Gollapudi | 618461c | 2010-06-11 16:43:54 -0700 | [diff] [blame] | 696 | u8 resp_code = 0; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 697 | |
| 698 | mutex_lock(&rdata->rp_mutex); |
| 699 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 700 | 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] | 701 | |
| 702 | if (rdata->rp_state != RPORT_ST_PRLI) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 703 | FC_RPORT_DBG(rdata, "Received a PRLI response, but in state " |
| 704 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 705 | if (IS_ERR(fp)) |
| 706 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 707 | goto out; |
| 708 | } |
| 709 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 710 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 711 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 712 | goto err; |
| 713 | } |
| 714 | |
Robert Love | 6bd054c | 2009-08-25 14:03:04 -0700 | [diff] [blame] | 715 | /* reinitialize remote port roles */ |
| 716 | rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 717 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 718 | op = fc_frame_payload_op(fp); |
| 719 | if (op == ELS_LS_ACC) { |
| 720 | pp = fc_frame_payload_get(fp, sizeof(*pp)); |
Bhanu Prakash Gollapudi | 618461c | 2010-06-11 16:43:54 -0700 | [diff] [blame] | 721 | if (!pp) |
| 722 | goto out; |
| 723 | |
| 724 | resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK); |
| 725 | FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n", |
| 726 | pp->spp.spp_flags); |
| 727 | if (resp_code != FC_SPP_RESP_ACK) { |
| 728 | if (resp_code == FC_SPP_RESP_CONF) |
| 729 | fc_rport_error(rdata, fp); |
| 730 | else |
| 731 | fc_rport_error_retry(rdata, fp); |
| 732 | goto out; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 733 | } |
Bhanu Prakash Gollapudi | 618461c | 2010-06-11 16:43:54 -0700 | [diff] [blame] | 734 | if (pp->prli.prli_spp_len < sizeof(pp->spp)) |
| 735 | goto out; |
| 736 | |
| 737 | fcp_parm = ntohl(pp->spp.spp_params); |
| 738 | if (fcp_parm & FCP_SPPF_RETRY) |
| 739 | rdata->flags |= FC_RP_FLAGS_RETRY; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 740 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 741 | rdata->supported_classes = FC_COS_CLASS3; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 742 | if (fcp_parm & FCP_SPPF_INIT_FCN) |
| 743 | roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 744 | if (fcp_parm & FCP_SPPF_TARG_FCN) |
| 745 | roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 746 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 747 | rdata->ids.roles = roles; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 748 | fc_rport_enter_rtv(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 749 | |
| 750 | } else { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 751 | FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n"); |
Bhanu Prakash Gollapudi | 292e40b | 2010-06-11 16:43:49 -0700 | [diff] [blame] | 752 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | out: |
| 756 | fc_frame_free(fp); |
| 757 | err: |
| 758 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 759 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 763 | * fc_rport_logo_resp() - Handler for logout (LOGO) responses |
| 764 | * @sp: The sequence the LOGO was on |
| 765 | * @fp: The LOGO response frame |
| 766 | * @rdata_arg: The remote port that sent the LOGO response |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 767 | * |
| 768 | * Locking Note: This function will be called without the rport lock |
| 769 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 770 | * and then unlock the rport. |
| 771 | */ |
| 772 | static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 773 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 774 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 775 | struct fc_rport_priv *rdata = rdata_arg; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 776 | u8 op; |
| 777 | |
| 778 | mutex_lock(&rdata->rp_mutex); |
| 779 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 780 | 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] | 781 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 782 | if (rdata->rp_state != RPORT_ST_LOGO) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 783 | FC_RPORT_DBG(rdata, "Received a LOGO response, but in state " |
| 784 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 785 | if (IS_ERR(fp)) |
| 786 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 787 | goto out; |
| 788 | } |
| 789 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 790 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 791 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 792 | goto err; |
| 793 | } |
| 794 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 795 | op = fc_frame_payload_op(fp); |
Joe Eykholt | 68a1750 | 2009-08-25 14:03:42 -0700 | [diff] [blame] | 796 | if (op != ELS_LS_ACC) |
| 797 | FC_RPORT_DBG(rdata, "Bad ELS response op %x for LOGO command\n", |
| 798 | op); |
| 799 | fc_rport_enter_delete(rdata, RPORT_EV_LOGO); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 800 | |
| 801 | out: |
| 802 | fc_frame_free(fp); |
| 803 | err: |
| 804 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 805 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 809 | * fc_rport_enter_prli() - Send Process Login (PRLI) request |
| 810 | * @rdata: The remote port to send the PRLI request to |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 811 | * |
| 812 | * Locking Note: The rport lock is expected to be held before calling |
| 813 | * this routine. |
| 814 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 815 | static void fc_rport_enter_prli(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 816 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 817 | struct fc_lport *lport = rdata->local_port; |
| 818 | struct { |
| 819 | struct fc_els_prli prli; |
| 820 | struct fc_els_spp spp; |
| 821 | } *pp; |
| 822 | struct fc_frame *fp; |
| 823 | |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 824 | /* |
| 825 | * If the rport is one of the well known addresses |
| 826 | * we skip PRLI and RTV and go straight to READY. |
| 827 | */ |
| 828 | if (rdata->ids.port_id >= FC_FID_DOM_MGR) { |
| 829 | fc_rport_enter_ready(rdata); |
| 830 | return; |
| 831 | } |
| 832 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 833 | FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n", |
| 834 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 835 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 836 | fc_rport_state_enter(rdata, RPORT_ST_PRLI); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 837 | |
| 838 | fp = fc_frame_alloc(lport, sizeof(*pp)); |
| 839 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 840 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 841 | return; |
| 842 | } |
| 843 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 844 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PRLI, |
Joe Eykholt | b94f895 | 2009-11-03 11:50:21 -0800 | [diff] [blame] | 845 | fc_rport_prli_resp, rdata, |
| 846 | 2 * lport->r_a_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 847 | fc_rport_error_retry(rdata, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 848 | else |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 849 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 853 | * fc_rport_els_rtv_resp() - Handler for Request Timeout Value (RTV) responses |
| 854 | * @sp: The sequence the RTV was on |
| 855 | * @fp: The RTV response frame |
| 856 | * @rdata_arg: The remote port that sent the RTV response |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 857 | * |
| 858 | * Many targets don't seem to support this. |
| 859 | * |
| 860 | * Locking Note: This function will be called without the rport lock |
| 861 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 862 | * and then unlock the rport. |
| 863 | */ |
| 864 | 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] | 865 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 866 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 867 | struct fc_rport_priv *rdata = rdata_arg; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 868 | u8 op; |
| 869 | |
| 870 | mutex_lock(&rdata->rp_mutex); |
| 871 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 872 | 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] | 873 | |
| 874 | if (rdata->rp_state != RPORT_ST_RTV) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 875 | FC_RPORT_DBG(rdata, "Received a RTV response, but in state " |
| 876 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 877 | if (IS_ERR(fp)) |
| 878 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 879 | goto out; |
| 880 | } |
| 881 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 882 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 883 | fc_rport_error(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 884 | goto err; |
| 885 | } |
| 886 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 887 | op = fc_frame_payload_op(fp); |
| 888 | if (op == ELS_LS_ACC) { |
| 889 | struct fc_els_rtv_acc *rtv; |
| 890 | u32 toq; |
| 891 | u32 tov; |
| 892 | |
| 893 | rtv = fc_frame_payload_get(fp, sizeof(*rtv)); |
| 894 | if (rtv) { |
| 895 | toq = ntohl(rtv->rtv_toq); |
| 896 | tov = ntohl(rtv->rtv_r_a_tov); |
| 897 | if (tov == 0) |
| 898 | tov = 1; |
| 899 | rdata->r_a_tov = tov; |
| 900 | tov = ntohl(rtv->rtv_e_d_tov); |
| 901 | if (toq & FC_ELS_RTV_EDRES) |
| 902 | tov /= 1000000; |
| 903 | if (tov == 0) |
| 904 | tov = 1; |
| 905 | rdata->e_d_tov = tov; |
| 906 | } |
| 907 | } |
| 908 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 909 | fc_rport_enter_ready(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 910 | |
| 911 | out: |
| 912 | fc_frame_free(fp); |
| 913 | err: |
| 914 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 915 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 919 | * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request |
| 920 | * @rdata: The remote port to send the RTV request to |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 921 | * |
| 922 | * Locking Note: The rport lock is expected to be held before calling |
| 923 | * this routine. |
| 924 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 925 | static void fc_rport_enter_rtv(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 926 | { |
| 927 | struct fc_frame *fp; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 928 | struct fc_lport *lport = rdata->local_port; |
| 929 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 930 | FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n", |
| 931 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 932 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 933 | fc_rport_state_enter(rdata, RPORT_ST_RTV); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 934 | |
| 935 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv)); |
| 936 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 937 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 938 | return; |
| 939 | } |
| 940 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 941 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV, |
Joe Eykholt | b94f895 | 2009-11-03 11:50:21 -0800 | [diff] [blame] | 942 | fc_rport_rtv_resp, rdata, |
| 943 | 2 * lport->r_a_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 944 | fc_rport_error_retry(rdata, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 945 | else |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 946 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 950 | * fc_rport_enter_logo() - Send a logout (LOGO) request |
| 951 | * @rdata: The remote port to send the LOGO request to |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 952 | * |
| 953 | * Locking Note: The rport lock is expected to be held before calling |
| 954 | * this routine. |
| 955 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 956 | static void fc_rport_enter_logo(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 957 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 958 | struct fc_lport *lport = rdata->local_port; |
| 959 | struct fc_frame *fp; |
| 960 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 961 | FC_RPORT_DBG(rdata, "Port entered LOGO state from %s state\n", |
| 962 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 963 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 964 | fc_rport_state_enter(rdata, RPORT_ST_LOGO); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 965 | |
| 966 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo)); |
| 967 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 968 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 969 | return; |
| 970 | } |
| 971 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 972 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO, |
Joe Eykholt | b94f895 | 2009-11-03 11:50:21 -0800 | [diff] [blame] | 973 | fc_rport_logo_resp, rdata, |
| 974 | 2 * lport->r_a_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 975 | fc_rport_error_retry(rdata, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 976 | else |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 977 | kref_get(&rdata->kref); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 978 | } |
| 979 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 980 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 981 | * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses |
| 982 | * @sp: The sequence the ADISC response was on |
| 983 | * @fp: The ADISC response frame |
| 984 | * @rdata_arg: The remote port that sent the ADISC response |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 985 | * |
| 986 | * Locking Note: This function will be called without the rport lock |
| 987 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 988 | * and then unlock the rport. |
| 989 | */ |
| 990 | static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp, |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 991 | void *rdata_arg) |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 992 | { |
| 993 | struct fc_rport_priv *rdata = rdata_arg; |
| 994 | struct fc_els_adisc *adisc; |
| 995 | u8 op; |
| 996 | |
| 997 | mutex_lock(&rdata->rp_mutex); |
| 998 | |
| 999 | FC_RPORT_DBG(rdata, "Received a ADISC response\n"); |
| 1000 | |
| 1001 | if (rdata->rp_state != RPORT_ST_ADISC) { |
| 1002 | FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n", |
| 1003 | fc_rport_state(rdata)); |
| 1004 | if (IS_ERR(fp)) |
| 1005 | goto err; |
| 1006 | goto out; |
| 1007 | } |
| 1008 | |
| 1009 | if (IS_ERR(fp)) { |
| 1010 | fc_rport_error(rdata, fp); |
| 1011 | goto err; |
| 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * If address verification failed. Consider us logged out of the rport. |
| 1016 | * Since the rport is still in discovery, we want to be |
| 1017 | * logged in, so go to PLOGI state. Otherwise, go back to READY. |
| 1018 | */ |
| 1019 | op = fc_frame_payload_op(fp); |
| 1020 | adisc = fc_frame_payload_get(fp, sizeof(*adisc)); |
| 1021 | if (op != ELS_LS_ACC || !adisc || |
| 1022 | ntoh24(adisc->adisc_port_id) != rdata->ids.port_id || |
| 1023 | get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name || |
| 1024 | get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) { |
| 1025 | FC_RPORT_DBG(rdata, "ADISC error or mismatch\n"); |
| 1026 | fc_rport_enter_plogi(rdata); |
| 1027 | } else { |
| 1028 | FC_RPORT_DBG(rdata, "ADISC OK\n"); |
| 1029 | fc_rport_enter_ready(rdata); |
| 1030 | } |
| 1031 | out: |
| 1032 | fc_frame_free(fp); |
| 1033 | err: |
| 1034 | mutex_unlock(&rdata->rp_mutex); |
| 1035 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
| 1036 | } |
| 1037 | |
| 1038 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1039 | * fc_rport_enter_adisc() - Send Address Discover (ADISC) request |
| 1040 | * @rdata: The remote port to send the ADISC request to |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 1041 | * |
| 1042 | * Locking Note: The rport lock is expected to be held before calling |
| 1043 | * this routine. |
| 1044 | */ |
| 1045 | static void fc_rport_enter_adisc(struct fc_rport_priv *rdata) |
| 1046 | { |
| 1047 | struct fc_lport *lport = rdata->local_port; |
| 1048 | struct fc_frame *fp; |
| 1049 | |
| 1050 | FC_RPORT_DBG(rdata, "sending ADISC from %s state\n", |
| 1051 | fc_rport_state(rdata)); |
| 1052 | |
| 1053 | fc_rport_state_enter(rdata, RPORT_ST_ADISC); |
| 1054 | |
| 1055 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc)); |
| 1056 | if (!fp) { |
| 1057 | fc_rport_error_retry(rdata, fp); |
| 1058 | return; |
| 1059 | } |
| 1060 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC, |
Joe Eykholt | b94f895 | 2009-11-03 11:50:21 -0800 | [diff] [blame] | 1061 | fc_rport_adisc_resp, rdata, |
| 1062 | 2 * lport->r_a_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 1063 | fc_rport_error_retry(rdata, NULL); |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 1064 | else |
| 1065 | kref_get(&rdata->kref); |
| 1066 | } |
| 1067 | |
| 1068 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1069 | * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests |
| 1070 | * @rdata: The remote port that sent the ADISC request |
| 1071 | * @sp: The sequence the ADISC request was on |
| 1072 | * @in_fp: The ADISC request frame |
Joe Eykholt | 8abbe3a | 2009-08-25 14:03:52 -0700 | [diff] [blame] | 1073 | * |
| 1074 | * Locking Note: Called with the lport and rport locks held. |
| 1075 | */ |
| 1076 | static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata, |
| 1077 | struct fc_seq *sp, struct fc_frame *in_fp) |
| 1078 | { |
| 1079 | struct fc_lport *lport = rdata->local_port; |
| 1080 | struct fc_frame *fp; |
| 1081 | struct fc_exch *ep = fc_seq_exch(sp); |
| 1082 | struct fc_els_adisc *adisc; |
| 1083 | struct fc_seq_els_data rjt_data; |
| 1084 | u32 f_ctl; |
| 1085 | |
| 1086 | FC_RPORT_DBG(rdata, "Received ADISC request\n"); |
| 1087 | |
| 1088 | adisc = fc_frame_payload_get(in_fp, sizeof(*adisc)); |
| 1089 | if (!adisc) { |
| 1090 | rjt_data.fp = NULL; |
| 1091 | rjt_data.reason = ELS_RJT_PROT; |
| 1092 | rjt_data.explan = ELS_EXPL_INV_LEN; |
| 1093 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1094 | goto drop; |
| 1095 | } |
| 1096 | |
| 1097 | fp = fc_frame_alloc(lport, sizeof(*adisc)); |
| 1098 | if (!fp) |
| 1099 | goto drop; |
| 1100 | fc_adisc_fill(lport, fp); |
| 1101 | adisc = fc_frame_payload_get(fp, sizeof(*adisc)); |
| 1102 | adisc->adisc_cmd = ELS_LS_ACC; |
| 1103 | sp = lport->tt.seq_start_next(sp); |
| 1104 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 1105 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1106 | FC_TYPE_ELS, f_ctl, 0); |
| 1107 | lport->tt.seq_send(lport, sp, fp); |
| 1108 | drop: |
| 1109 | fc_frame_free(in_fp); |
| 1110 | } |
| 1111 | |
| 1112 | /** |
Yi Zou | 63e27fb | 2009-11-20 14:55:24 -0800 | [diff] [blame] | 1113 | * fc_rport_recv_rls_req() - Handle received Read Link Status request |
| 1114 | * @rdata: The remote port that sent the RLS request |
| 1115 | * @sp: The sequence that the RLS was on |
| 1116 | * @rx_fp: The PRLI request frame |
| 1117 | * |
| 1118 | * Locking Note: The rport lock is expected to be held before calling |
| 1119 | * this function. |
| 1120 | */ |
| 1121 | static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata, |
| 1122 | struct fc_seq *sp, struct fc_frame *rx_fp) |
| 1123 | |
| 1124 | { |
| 1125 | struct fc_lport *lport = rdata->local_port; |
| 1126 | struct fc_frame *fp; |
| 1127 | struct fc_exch *ep = fc_seq_exch(sp); |
| 1128 | struct fc_els_rls *rls; |
| 1129 | struct fc_els_rls_resp *rsp; |
| 1130 | struct fc_els_lesb *lesb; |
| 1131 | struct fc_seq_els_data rjt_data; |
| 1132 | struct fc_host_statistics *hst; |
| 1133 | u32 f_ctl; |
| 1134 | |
| 1135 | FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n", |
| 1136 | fc_rport_state(rdata)); |
| 1137 | |
| 1138 | rls = fc_frame_payload_get(rx_fp, sizeof(*rls)); |
| 1139 | if (!rls) { |
| 1140 | rjt_data.reason = ELS_RJT_PROT; |
| 1141 | rjt_data.explan = ELS_EXPL_INV_LEN; |
| 1142 | goto out_rjt; |
| 1143 | } |
| 1144 | |
| 1145 | fp = fc_frame_alloc(lport, sizeof(*rsp)); |
| 1146 | if (!fp) { |
| 1147 | rjt_data.reason = ELS_RJT_UNAB; |
| 1148 | rjt_data.explan = ELS_EXPL_INSUF_RES; |
| 1149 | goto out_rjt; |
| 1150 | } |
| 1151 | |
| 1152 | rsp = fc_frame_payload_get(fp, sizeof(*rsp)); |
| 1153 | memset(rsp, 0, sizeof(*rsp)); |
| 1154 | rsp->rls_cmd = ELS_LS_ACC; |
| 1155 | lesb = &rsp->rls_lesb; |
| 1156 | if (lport->tt.get_lesb) { |
| 1157 | /* get LESB from LLD if it supports it */ |
| 1158 | lport->tt.get_lesb(lport, lesb); |
| 1159 | } else { |
| 1160 | fc_get_host_stats(lport->host); |
| 1161 | hst = &lport->host_stats; |
| 1162 | lesb->lesb_link_fail = htonl(hst->link_failure_count); |
| 1163 | lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count); |
| 1164 | lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count); |
| 1165 | lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count); |
| 1166 | lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count); |
| 1167 | lesb->lesb_inv_crc = htonl(hst->invalid_crc_count); |
| 1168 | } |
| 1169 | |
| 1170 | sp = lport->tt.seq_start_next(sp); |
| 1171 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; |
| 1172 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1173 | FC_TYPE_ELS, f_ctl, 0); |
| 1174 | lport->tt.seq_send(lport, sp, fp); |
| 1175 | goto out; |
| 1176 | |
| 1177 | out_rjt: |
| 1178 | rjt_data.fp = NULL; |
| 1179 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1180 | out: |
| 1181 | fc_frame_free(rx_fp); |
| 1182 | } |
| 1183 | |
| 1184 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1185 | * fc_rport_recv_els_req() - Handler for validated ELS requests |
| 1186 | * @lport: The local port that received the ELS request |
| 1187 | * @sp: The sequence that the ELS request was on |
| 1188 | * @fp: The ELS request frame |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1189 | * |
| 1190 | * Handle incoming ELS requests that require port login. |
| 1191 | * The ELS opcode has already been validated by the caller. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1192 | * |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1193 | * Locking Note: Called with the lport lock held. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1194 | */ |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1195 | static void fc_rport_recv_els_req(struct fc_lport *lport, |
| 1196 | struct fc_seq *sp, struct fc_frame *fp) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1197 | { |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1198 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1199 | struct fc_frame_header *fh; |
| 1200 | struct fc_seq_els_data els_data; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1201 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1202 | els_data.fp = NULL; |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1203 | els_data.reason = ELS_RJT_UNAB; |
| 1204 | els_data.explan = ELS_EXPL_PLOGI_REQD; |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1205 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1206 | fh = fc_frame_header_get(fp); |
| 1207 | |
Joe Eykholt | 25b37b9 | 2009-08-25 14:03:15 -0700 | [diff] [blame] | 1208 | mutex_lock(&lport->disc.disc_mutex); |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1209 | rdata = lport->tt.rport_lookup(lport, ntoh24(fh->fh_s_id)); |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1210 | if (!rdata) { |
Joe Eykholt | 25b37b9 | 2009-08-25 14:03:15 -0700 | [diff] [blame] | 1211 | mutex_unlock(&lport->disc.disc_mutex); |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1212 | goto reject; |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1213 | } |
| 1214 | mutex_lock(&rdata->rp_mutex); |
Joe Eykholt | 25b37b9 | 2009-08-25 14:03:15 -0700 | [diff] [blame] | 1215 | mutex_unlock(&lport->disc.disc_mutex); |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1216 | |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1217 | switch (rdata->rp_state) { |
| 1218 | case RPORT_ST_PRLI: |
| 1219 | case RPORT_ST_RTV: |
| 1220 | case RPORT_ST_READY: |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 1221 | case RPORT_ST_ADISC: |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1222 | break; |
| 1223 | default: |
| 1224 | mutex_unlock(&rdata->rp_mutex); |
| 1225 | goto reject; |
| 1226 | } |
| 1227 | |
| 1228 | switch (fc_frame_payload_op(fp)) { |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1229 | case ELS_PRLI: |
| 1230 | fc_rport_recv_prli_req(rdata, sp, fp); |
| 1231 | break; |
| 1232 | case ELS_PRLO: |
| 1233 | fc_rport_recv_prlo_req(rdata, sp, fp); |
| 1234 | break; |
Joe Eykholt | 8abbe3a | 2009-08-25 14:03:52 -0700 | [diff] [blame] | 1235 | case ELS_ADISC: |
| 1236 | fc_rport_recv_adisc_req(rdata, sp, fp); |
| 1237 | break; |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1238 | case ELS_RRQ: |
| 1239 | els_data.fp = fp; |
| 1240 | lport->tt.seq_els_rsp_send(sp, ELS_RRQ, &els_data); |
| 1241 | break; |
| 1242 | case ELS_REC: |
| 1243 | els_data.fp = fp; |
| 1244 | lport->tt.seq_els_rsp_send(sp, ELS_REC, &els_data); |
| 1245 | break; |
Yi Zou | 63e27fb | 2009-11-20 14:55:24 -0800 | [diff] [blame] | 1246 | case ELS_RLS: |
| 1247 | fc_rport_recv_rls_req(rdata, sp, fp); |
| 1248 | break; |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1249 | default: |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1250 | fc_frame_free(fp); /* can't happen */ |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 1251 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1255 | return; |
| 1256 | |
| 1257 | reject: |
| 1258 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &els_data); |
| 1259 | fc_frame_free(fp); |
| 1260 | } |
| 1261 | |
| 1262 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1263 | * fc_rport_recv_req() - Handler for requests |
| 1264 | * @sp: The sequence the request was on |
| 1265 | * @fp: The request frame |
| 1266 | * @lport: The local port that received the request |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1267 | * |
| 1268 | * Locking Note: Called with the lport lock held. |
| 1269 | */ |
| 1270 | void fc_rport_recv_req(struct fc_seq *sp, struct fc_frame *fp, |
| 1271 | struct fc_lport *lport) |
| 1272 | { |
| 1273 | struct fc_seq_els_data els_data; |
| 1274 | |
| 1275 | /* |
| 1276 | * Handle PLOGI and LOGO requests separately, since they |
| 1277 | * don't require prior login. |
| 1278 | * Check for unsupported opcodes first and reject them. |
| 1279 | * For some ops, it would be incorrect to reject with "PLOGI required". |
| 1280 | */ |
| 1281 | switch (fc_frame_payload_op(fp)) { |
| 1282 | case ELS_PLOGI: |
| 1283 | fc_rport_recv_plogi_req(lport, sp, fp); |
| 1284 | break; |
| 1285 | case ELS_LOGO: |
| 1286 | fc_rport_recv_logo_req(lport, sp, fp); |
| 1287 | break; |
| 1288 | case ELS_PRLI: |
| 1289 | case ELS_PRLO: |
Joe Eykholt | 8abbe3a | 2009-08-25 14:03:52 -0700 | [diff] [blame] | 1290 | case ELS_ADISC: |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1291 | case ELS_RRQ: |
| 1292 | case ELS_REC: |
Yi Zou | 63e27fb | 2009-11-20 14:55:24 -0800 | [diff] [blame] | 1293 | case ELS_RLS: |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1294 | fc_rport_recv_els_req(lport, sp, fp); |
| 1295 | break; |
| 1296 | default: |
| 1297 | fc_frame_free(fp); |
| 1298 | els_data.fp = NULL; |
| 1299 | els_data.reason = ELS_RJT_UNSUP; |
| 1300 | els_data.explan = ELS_EXPL_NONE; |
| 1301 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &els_data); |
| 1302 | break; |
| 1303 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1307 | * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests |
| 1308 | * @lport: The local port that received the PLOGI request |
| 1309 | * @sp: The sequence that the PLOGI request was on |
| 1310 | * @rx_fp: The PLOGI request frame |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1311 | * |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1312 | * Locking Note: The rport lock is held before calling this function. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1313 | */ |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1314 | static void fc_rport_recv_plogi_req(struct fc_lport *lport, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1315 | struct fc_seq *sp, struct fc_frame *rx_fp) |
| 1316 | { |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1317 | struct fc_disc *disc; |
| 1318 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1319 | struct fc_frame *fp = rx_fp; |
| 1320 | struct fc_exch *ep; |
| 1321 | struct fc_frame_header *fh; |
| 1322 | struct fc_els_flogi *pl; |
| 1323 | struct fc_seq_els_data rjt_data; |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1324 | u32 sid, f_ctl; |
| 1325 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1326 | rjt_data.fp = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1327 | fh = fc_frame_header_get(fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1328 | sid = ntoh24(fh->fh_s_id); |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1329 | |
| 1330 | FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n"); |
| 1331 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1332 | pl = fc_frame_payload_get(fp, sizeof(*pl)); |
| 1333 | if (!pl) { |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1334 | FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n"); |
| 1335 | rjt_data.reason = ELS_RJT_PROT; |
| 1336 | rjt_data.explan = ELS_EXPL_INV_LEN; |
| 1337 | goto reject; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1338 | } |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1339 | |
| 1340 | disc = &lport->disc; |
| 1341 | mutex_lock(&disc->disc_mutex); |
| 1342 | rdata = lport->tt.rport_create(lport, sid); |
| 1343 | if (!rdata) { |
| 1344 | mutex_unlock(&disc->disc_mutex); |
| 1345 | rjt_data.reason = ELS_RJT_UNAB; |
| 1346 | rjt_data.explan = ELS_EXPL_INSUF_RES; |
| 1347 | goto reject; |
| 1348 | } |
| 1349 | |
| 1350 | mutex_lock(&rdata->rp_mutex); |
| 1351 | mutex_unlock(&disc->disc_mutex); |
| 1352 | |
| 1353 | rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn); |
| 1354 | rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1355 | |
| 1356 | /* |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1357 | * If the rport was just created, possibly due to the incoming PLOGI, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1358 | * set the state appropriately and accept the PLOGI. |
| 1359 | * |
| 1360 | * If we had also sent a PLOGI, and if the received PLOGI is from a |
| 1361 | * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason |
| 1362 | * "command already in progress". |
| 1363 | * |
| 1364 | * XXX TBD: If the session was ready before, the PLOGI should result in |
| 1365 | * all outstanding exchanges being reset. |
| 1366 | */ |
| 1367 | switch (rdata->rp_state) { |
| 1368 | case RPORT_ST_INIT: |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1369 | FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1370 | break; |
| 1371 | case RPORT_ST_PLOGI: |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1372 | FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n"); |
| 1373 | if (rdata->ids.port_name < lport->wwpn) { |
| 1374 | mutex_unlock(&rdata->rp_mutex); |
| 1375 | rjt_data.reason = ELS_RJT_INPROG; |
| 1376 | rjt_data.explan = ELS_EXPL_NONE; |
| 1377 | goto reject; |
| 1378 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1379 | break; |
| 1380 | case RPORT_ST_PRLI: |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 1381 | case RPORT_ST_RTV: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1382 | case RPORT_ST_READY: |
Joe Eykholt | 370c3bd | 2009-08-25 14:03:47 -0700 | [diff] [blame] | 1383 | case RPORT_ST_ADISC: |
| 1384 | FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d " |
| 1385 | "- ignored for now\n", rdata->rp_state); |
| 1386 | /* XXX TBD - should reset */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1387 | break; |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 1388 | case RPORT_ST_DELETE: |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 1389 | case RPORT_ST_LOGO: |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 1390 | FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n", |
| 1391 | fc_rport_state(rdata)); |
| 1392 | mutex_unlock(&rdata->rp_mutex); |
| 1393 | rjt_data.reason = ELS_RJT_BUSY; |
| 1394 | rjt_data.explan = ELS_EXPL_NONE; |
| 1395 | goto reject; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1396 | } |
| 1397 | |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1398 | /* |
| 1399 | * Get session payload size from incoming PLOGI. |
| 1400 | */ |
| 1401 | rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs); |
| 1402 | fc_frame_free(rx_fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1403 | |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1404 | /* |
| 1405 | * Send LS_ACC. If this fails, the originator should retry. |
| 1406 | */ |
| 1407 | sp = lport->tt.seq_start_next(sp); |
| 1408 | if (!sp) |
| 1409 | goto out; |
| 1410 | fp = fc_frame_alloc(lport, sizeof(*pl)); |
| 1411 | if (!fp) |
| 1412 | goto out; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1413 | |
Joe Eykholt | 3ac6f98 | 2009-08-25 14:03:26 -0700 | [diff] [blame] | 1414 | fc_plogi_fill(lport, fp, ELS_LS_ACC); |
| 1415 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 1416 | ep = fc_seq_exch(sp); |
| 1417 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1418 | FC_TYPE_ELS, f_ctl, 0); |
| 1419 | lport->tt.seq_send(lport, sp, fp); |
| 1420 | fc_rport_enter_prli(rdata); |
| 1421 | out: |
| 1422 | mutex_unlock(&rdata->rp_mutex); |
| 1423 | return; |
| 1424 | |
| 1425 | reject: |
| 1426 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1427 | fc_frame_free(fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1431 | * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests |
| 1432 | * @rdata: The remote port that sent the PRLI request |
| 1433 | * @sp: The sequence that the PRLI was on |
| 1434 | * @rx_fp: The PRLI request frame |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1435 | * |
| 1436 | * Locking Note: The rport lock is exected to be held before calling |
| 1437 | * this function. |
| 1438 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1439 | static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1440 | struct fc_seq *sp, struct fc_frame *rx_fp) |
| 1441 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1442 | struct fc_lport *lport = rdata->local_port; |
| 1443 | struct fc_exch *ep; |
| 1444 | struct fc_frame *fp; |
| 1445 | struct fc_frame_header *fh; |
| 1446 | struct { |
| 1447 | struct fc_els_prli prli; |
| 1448 | struct fc_els_spp spp; |
| 1449 | } *pp; |
| 1450 | struct fc_els_spp *rspp; /* request service param page */ |
| 1451 | struct fc_els_spp *spp; /* response spp */ |
| 1452 | unsigned int len; |
| 1453 | unsigned int plen; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1454 | enum fc_els_spp_resp resp; |
| 1455 | struct fc_seq_els_data rjt_data; |
| 1456 | u32 f_ctl; |
| 1457 | u32 fcp_parm; |
| 1458 | u32 roles = FC_RPORT_ROLE_UNKNOWN; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1459 | |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1460 | rjt_data.fp = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1461 | fh = fc_frame_header_get(rx_fp); |
| 1462 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1463 | FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n", |
| 1464 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1465 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1466 | len = fr_len(rx_fp) - sizeof(*fh); |
| 1467 | pp = fc_frame_payload_get(rx_fp, sizeof(*pp)); |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1468 | if (!pp) |
| 1469 | goto reject_len; |
| 1470 | plen = ntohs(pp->prli.prli_len); |
| 1471 | if ((plen % 4) != 0 || plen > len || plen < 16) |
| 1472 | goto reject_len; |
| 1473 | if (plen < len) |
| 1474 | len = plen; |
| 1475 | plen = pp->prli.prli_spp_len; |
| 1476 | if ((plen % 4) != 0 || plen < sizeof(*spp) || |
| 1477 | plen > len || len < sizeof(*pp) || plen < 12) |
| 1478 | goto reject_len; |
| 1479 | rspp = &pp->spp; |
| 1480 | |
| 1481 | fp = fc_frame_alloc(lport, len); |
| 1482 | if (!fp) { |
| 1483 | rjt_data.reason = ELS_RJT_UNAB; |
| 1484 | rjt_data.explan = ELS_EXPL_INSUF_RES; |
| 1485 | goto reject; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1486 | } |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1487 | sp = lport->tt.seq_start_next(sp); |
| 1488 | WARN_ON(!sp); |
| 1489 | pp = fc_frame_payload_get(fp, len); |
| 1490 | WARN_ON(!pp); |
| 1491 | memset(pp, 0, len); |
| 1492 | pp->prli.prli_cmd = ELS_LS_ACC; |
| 1493 | pp->prli.prli_spp_len = plen; |
| 1494 | pp->prli.prli_len = htons(len); |
| 1495 | len -= sizeof(struct fc_els_prli); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1496 | |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1497 | /* reinitialize remote port roles */ |
| 1498 | rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Robert Love | 6bd054c | 2009-08-25 14:03:04 -0700 | [diff] [blame] | 1499 | |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1500 | /* |
| 1501 | * Go through all the service parameter pages and build |
| 1502 | * response. If plen indicates longer SPP than standard, |
| 1503 | * use that. The entire response has been pre-cleared above. |
| 1504 | */ |
| 1505 | spp = &pp->spp; |
| 1506 | while (len >= plen) { |
| 1507 | spp->spp_type = rspp->spp_type; |
| 1508 | spp->spp_type_ext = rspp->spp_type_ext; |
| 1509 | spp->spp_flags = rspp->spp_flags & FC_SPP_EST_IMG_PAIR; |
| 1510 | resp = FC_SPP_RESP_ACK; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1511 | |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1512 | switch (rspp->spp_type) { |
| 1513 | case 0: /* common to all FC-4 types */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1514 | break; |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1515 | case FC_TYPE_FCP: |
| 1516 | fcp_parm = ntohl(rspp->spp_params); |
| 1517 | if (fcp_parm & FCP_SPPF_RETRY) |
| 1518 | rdata->flags |= FC_RP_FLAGS_RETRY; |
| 1519 | rdata->supported_classes = FC_COS_CLASS3; |
| 1520 | if (fcp_parm & FCP_SPPF_INIT_FCN) |
| 1521 | roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 1522 | if (fcp_parm & FCP_SPPF_TARG_FCN) |
| 1523 | roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 1524 | rdata->ids.roles = roles; |
| 1525 | |
| 1526 | spp->spp_params = htonl(lport->service_params); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1527 | break; |
| 1528 | default: |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1529 | resp = FC_SPP_RESP_INVL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1530 | break; |
| 1531 | } |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1532 | spp->spp_flags |= resp; |
| 1533 | len -= plen; |
| 1534 | rspp = (struct fc_els_spp *)((char *)rspp + plen); |
| 1535 | spp = (struct fc_els_spp *)((char *)spp + plen); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1536 | } |
Joe Eykholt | a2f6a02 | 2010-03-12 16:07:36 -0800 | [diff] [blame] | 1537 | |
| 1538 | /* |
| 1539 | * Send LS_ACC. If this fails, the originator should retry. |
| 1540 | */ |
| 1541 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; |
| 1542 | f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 1543 | ep = fc_seq_exch(sp); |
| 1544 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1545 | FC_TYPE_ELS, f_ctl, 0); |
| 1546 | lport->tt.seq_send(lport, sp, fp); |
| 1547 | |
| 1548 | switch (rdata->rp_state) { |
| 1549 | case RPORT_ST_PRLI: |
| 1550 | fc_rport_enter_ready(rdata); |
| 1551 | break; |
| 1552 | default: |
| 1553 | break; |
| 1554 | } |
| 1555 | goto drop; |
| 1556 | |
| 1557 | reject_len: |
| 1558 | rjt_data.reason = ELS_RJT_PROT; |
| 1559 | rjt_data.explan = ELS_EXPL_INV_LEN; |
| 1560 | reject: |
| 1561 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1562 | drop: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1563 | fc_frame_free(rx_fp); |
| 1564 | } |
| 1565 | |
| 1566 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1567 | * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests |
| 1568 | * @rdata: The remote port that sent the PRLO request |
| 1569 | * @sp: The sequence that the PRLO was on |
Bhanu Prakash Gollapudi | f8fc6c2 | 2010-06-11 16:44:04 -0700 | [diff] [blame] | 1570 | * @rx_fp: The PRLO request frame |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1571 | * |
| 1572 | * Locking Note: The rport lock is exected to be held before calling |
| 1573 | * this function. |
| 1574 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1575 | static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata, |
| 1576 | struct fc_seq *sp, |
Bhanu Prakash Gollapudi | f8fc6c2 | 2010-06-11 16:44:04 -0700 | [diff] [blame] | 1577 | struct fc_frame *rx_fp) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1578 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1579 | struct fc_lport *lport = rdata->local_port; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1580 | struct fc_frame_header *fh; |
Bhanu Prakash Gollapudi | f8fc6c2 | 2010-06-11 16:44:04 -0700 | [diff] [blame] | 1581 | struct fc_exch *ep; |
| 1582 | struct fc_frame *fp; |
| 1583 | struct { |
| 1584 | struct fc_els_prlo prlo; |
| 1585 | struct fc_els_spp spp; |
| 1586 | } *pp; |
| 1587 | struct fc_els_spp *rspp; /* request service param page */ |
| 1588 | struct fc_els_spp *spp; /* response spp */ |
| 1589 | unsigned int len; |
| 1590 | unsigned int plen; |
| 1591 | u32 f_ctl; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1592 | struct fc_seq_els_data rjt_data; |
| 1593 | |
Bhanu Prakash Gollapudi | f8fc6c2 | 2010-06-11 16:44:04 -0700 | [diff] [blame] | 1594 | rjt_data.fp = NULL; |
| 1595 | fh = fc_frame_header_get(rx_fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1596 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1597 | FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n", |
| 1598 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1599 | |
Bhanu Prakash Gollapudi | f8fc6c2 | 2010-06-11 16:44:04 -0700 | [diff] [blame] | 1600 | len = fr_len(rx_fp) - sizeof(*fh); |
| 1601 | pp = fc_frame_payload_get(rx_fp, sizeof(*pp)); |
| 1602 | if (!pp) |
| 1603 | goto reject_len; |
| 1604 | plen = ntohs(pp->prlo.prlo_len); |
| 1605 | if (plen != 20) |
| 1606 | goto reject_len; |
| 1607 | if (plen < len) |
| 1608 | len = plen; |
| 1609 | |
| 1610 | rspp = &pp->spp; |
| 1611 | |
| 1612 | fp = fc_frame_alloc(lport, len); |
| 1613 | if (!fp) { |
| 1614 | rjt_data.reason = ELS_RJT_UNAB; |
| 1615 | rjt_data.explan = ELS_EXPL_INSUF_RES; |
| 1616 | goto reject; |
| 1617 | } |
| 1618 | |
| 1619 | sp = lport->tt.seq_start_next(sp); |
| 1620 | WARN_ON(!sp); |
| 1621 | pp = fc_frame_payload_get(fp, len); |
| 1622 | WARN_ON(!pp); |
| 1623 | memset(pp, 0, len); |
| 1624 | pp->prlo.prlo_cmd = ELS_LS_ACC; |
| 1625 | pp->prlo.prlo_obs = 0x10; |
| 1626 | pp->prlo.prlo_len = htons(len); |
| 1627 | spp = &pp->spp; |
| 1628 | spp->spp_type = rspp->spp_type; |
| 1629 | spp->spp_type_ext = rspp->spp_type_ext; |
| 1630 | spp->spp_flags = FC_SPP_RESP_ACK; |
| 1631 | |
| 1632 | fc_rport_enter_delete(rdata, RPORT_EV_LOGO); |
| 1633 | |
| 1634 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; |
| 1635 | f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 1636 | ep = fc_seq_exch(sp); |
| 1637 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1638 | FC_TYPE_ELS, f_ctl, 0); |
| 1639 | lport->tt.seq_send(lport, sp, fp); |
| 1640 | goto drop; |
| 1641 | |
| 1642 | reject_len: |
| 1643 | rjt_data.reason = ELS_RJT_PROT; |
| 1644 | rjt_data.explan = ELS_EXPL_INV_LEN; |
| 1645 | reject: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1646 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
Bhanu Prakash Gollapudi | f8fc6c2 | 2010-06-11 16:44:04 -0700 | [diff] [blame] | 1647 | drop: |
| 1648 | fc_frame_free(rx_fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1652 | * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests |
| 1653 | * @lport: The local port that received the LOGO request |
| 1654 | * @sp: The sequence that the LOGO request was on |
| 1655 | * @fp: The LOGO request frame |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1656 | * |
| 1657 | * Locking Note: The rport lock is exected to be held before calling |
| 1658 | * this function. |
| 1659 | */ |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1660 | static void fc_rport_recv_logo_req(struct fc_lport *lport, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1661 | struct fc_seq *sp, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1662 | struct fc_frame *fp) |
| 1663 | { |
| 1664 | struct fc_frame_header *fh; |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1665 | struct fc_rport_priv *rdata; |
| 1666 | u32 sid; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1667 | |
Joe Eykholt | feab4ae | 2009-08-25 14:03:36 -0700 | [diff] [blame] | 1668 | lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); |
| 1669 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1670 | fh = fc_frame_header_get(fp); |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1671 | sid = ntoh24(fh->fh_s_id); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1672 | |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1673 | mutex_lock(&lport->disc.disc_mutex); |
| 1674 | rdata = lport->tt.rport_lookup(lport, sid); |
| 1675 | if (rdata) { |
| 1676 | mutex_lock(&rdata->rp_mutex); |
| 1677 | FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n", |
| 1678 | fc_rport_state(rdata)); |
Joe Eykholt | feab4ae | 2009-08-25 14:03:36 -0700 | [diff] [blame] | 1679 | |
Joe Eykholt | b4a9c7e | 2009-10-21 16:28:30 -0700 | [diff] [blame] | 1680 | fc_rport_enter_delete(rdata, RPORT_EV_LOGO); |
Joe Eykholt | 83fe6a9 | 2009-08-25 14:03:31 -0700 | [diff] [blame] | 1681 | mutex_unlock(&rdata->rp_mutex); |
| 1682 | } else |
| 1683 | FC_RPORT_ID_DBG(lport, sid, |
| 1684 | "Received LOGO from non-logged-in port\n"); |
| 1685 | mutex_unlock(&lport->disc.disc_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1686 | fc_frame_free(fp); |
| 1687 | } |
| 1688 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1689 | /** |
| 1690 | * fc_rport_flush_queue() - Flush the rport_event_queue |
| 1691 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1692 | static void fc_rport_flush_queue(void) |
| 1693 | { |
| 1694 | flush_workqueue(rport_event_queue); |
| 1695 | } |
| 1696 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1697 | /** |
| 1698 | * fc_rport_init() - Initialize the remote port layer for a local port |
| 1699 | * @lport: The local port to initialize the remote port layer for |
| 1700 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1701 | int fc_rport_init(struct fc_lport *lport) |
| 1702 | { |
Joe Eykholt | 8025b5d | 2009-08-25 14:02:06 -0700 | [diff] [blame] | 1703 | if (!lport->tt.rport_lookup) |
| 1704 | lport->tt.rport_lookup = fc_rport_lookup; |
| 1705 | |
Robert Love | 5101ff9 | 2009-02-27 10:55:18 -0800 | [diff] [blame] | 1706 | if (!lport->tt.rport_create) |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 1707 | lport->tt.rport_create = fc_rport_create; |
Robert Love | 5101ff9 | 2009-02-27 10:55:18 -0800 | [diff] [blame] | 1708 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1709 | if (!lport->tt.rport_login) |
| 1710 | lport->tt.rport_login = fc_rport_login; |
| 1711 | |
| 1712 | if (!lport->tt.rport_logoff) |
| 1713 | lport->tt.rport_logoff = fc_rport_logoff; |
| 1714 | |
| 1715 | if (!lport->tt.rport_recv_req) |
| 1716 | lport->tt.rport_recv_req = fc_rport_recv_req; |
| 1717 | |
| 1718 | if (!lport->tt.rport_flush_queue) |
| 1719 | lport->tt.rport_flush_queue = fc_rport_flush_queue; |
| 1720 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 1721 | if (!lport->tt.rport_destroy) |
| 1722 | lport->tt.rport_destroy = fc_rport_destroy; |
| 1723 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1724 | return 0; |
| 1725 | } |
| 1726 | EXPORT_SYMBOL(fc_rport_init); |
| 1727 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1728 | /** |
| 1729 | * fc_setup_rport() - Initialize the rport_event_queue |
| 1730 | */ |
| 1731 | int fc_setup_rport() |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1732 | { |
| 1733 | rport_event_queue = create_singlethread_workqueue("fc_rport_eq"); |
| 1734 | if (!rport_event_queue) |
| 1735 | return -ENOMEM; |
| 1736 | return 0; |
| 1737 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1738 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1739 | /** |
| 1740 | * fc_destroy_rport() - Destroy the rport_event_queue |
| 1741 | */ |
| 1742 | void fc_destroy_rport() |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1743 | { |
| 1744 | destroy_workqueue(rport_event_queue); |
| 1745 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1746 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1747 | /** |
| 1748 | * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port |
| 1749 | * @rport: The remote port whose I/O should be terminated |
| 1750 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1751 | void fc_rport_terminate_io(struct fc_rport *rport) |
| 1752 | { |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1753 | struct fc_rport_libfc_priv *rpriv = rport->dd_data; |
| 1754 | struct fc_lport *lport = rpriv->local_port; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1755 | |
Abhijeet Joglekar | 1f6ff36 | 2009-02-27 10:54:35 -0800 | [diff] [blame] | 1756 | lport->tt.exch_mgr_reset(lport, 0, rport->port_id); |
| 1757 | lport->tt.exch_mgr_reset(lport, rport->port_id, 0); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1758 | } |
| 1759 | EXPORT_SYMBOL(fc_rport_terminate_io); |