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