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