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