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