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