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