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