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