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