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