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