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