Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | * Maintained at www.Open-FCoE.org |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * RPORT GENERAL INFO |
| 22 | * |
| 23 | * This file contains all processing regarding fc_rports. It contains the |
| 24 | * rport state machine and does all rport interaction with the transport class. |
| 25 | * There should be no other places in libfc that interact directly with the |
| 26 | * transport class in regards to adding and deleting rports. |
| 27 | * |
| 28 | * fc_rport's represent N_Port's within the fabric. |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | * RPORT LOCKING |
| 33 | * |
| 34 | * The rport should never hold the rport mutex and then attempt to acquire |
| 35 | * either the lport or disc mutexes. The rport's mutex is considered lesser |
| 36 | * than both the lport's mutex and the disc mutex. Refer to fc_lport.c for |
| 37 | * more comments on the heirarchy. |
| 38 | * |
| 39 | * The locking strategy is similar to the lport's strategy. The lock protects |
| 40 | * the rport's states and is held and released by the entry points to the rport |
| 41 | * block. All _enter_* functions correspond to rport states and expect the rport |
| 42 | * mutex to be locked before calling them. This means that rports only handle |
| 43 | * one request or response at a time, since they're not critical for the I/O |
| 44 | * path this potential over-use of the mutex is acceptable. |
| 45 | */ |
| 46 | |
| 47 | #include <linux/kernel.h> |
| 48 | #include <linux/spinlock.h> |
| 49 | #include <linux/interrupt.h> |
| 50 | #include <linux/rcupdate.h> |
| 51 | #include <linux/timer.h> |
| 52 | #include <linux/workqueue.h> |
| 53 | #include <asm/unaligned.h> |
| 54 | |
| 55 | #include <scsi/libfc.h> |
| 56 | #include <scsi/fc_encode.h> |
| 57 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 58 | struct workqueue_struct *rport_event_queue; |
| 59 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 60 | static void fc_rport_enter_plogi(struct fc_rport_priv *); |
| 61 | static void fc_rport_enter_prli(struct fc_rport_priv *); |
| 62 | static void fc_rport_enter_rtv(struct fc_rport_priv *); |
| 63 | static void fc_rport_enter_ready(struct fc_rport_priv *); |
| 64 | static void fc_rport_enter_logo(struct fc_rport_priv *); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 65 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 66 | static void fc_rport_recv_plogi_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 67 | struct fc_seq *, struct fc_frame *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 68 | static void fc_rport_recv_prli_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 69 | struct fc_seq *, struct fc_frame *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 70 | static void fc_rport_recv_prlo_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 71 | struct fc_seq *, struct fc_frame *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 72 | static void fc_rport_recv_logo_req(struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 73 | struct fc_seq *, struct fc_frame *); |
| 74 | static void fc_rport_timeout(struct work_struct *); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 75 | static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *); |
| 76 | 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] | 77 | static void fc_rport_work(struct work_struct *); |
| 78 | |
| 79 | static const char *fc_rport_state_names[] = { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 80 | [RPORT_ST_INIT] = "Init", |
| 81 | [RPORT_ST_PLOGI] = "PLOGI", |
| 82 | [RPORT_ST_PRLI] = "PRLI", |
| 83 | [RPORT_ST_RTV] = "RTV", |
| 84 | [RPORT_ST_READY] = "Ready", |
| 85 | [RPORT_ST_LOGO] = "LOGO", |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 86 | [RPORT_ST_DELETE] = "Delete", |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static void fc_rport_rogue_destroy(struct device *dev) |
| 90 | { |
| 91 | struct fc_rport *rport = dev_to_rport(dev); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 92 | struct fc_rport_priv *rdata = RPORT_TO_PRIV(rport); |
| 93 | |
| 94 | FC_RPORT_DBG(rdata, "Destroying rogue rport\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 95 | kfree(rport); |
| 96 | } |
| 97 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 98 | struct fc_rport_priv *fc_rport_rogue_create(struct fc_lport *lport, |
| 99 | struct fc_rport_identifiers *ids) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 100 | { |
| 101 | struct fc_rport *rport; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 102 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 103 | rport = kzalloc(sizeof(*rport) + sizeof(*rdata), GFP_KERNEL); |
| 104 | |
| 105 | if (!rport) |
| 106 | return NULL; |
| 107 | |
| 108 | rdata = RPORT_TO_PRIV(rport); |
| 109 | |
| 110 | rport->dd_data = rdata; |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 111 | rport->port_id = ids->port_id; |
| 112 | rport->port_name = ids->port_name; |
| 113 | rport->node_name = ids->node_name; |
| 114 | rport->roles = ids->roles; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 115 | rport->maxframe_size = FC_MIN_MAX_PAYLOAD; |
| 116 | /* |
| 117 | * Note: all this libfc rogue rport code will be removed for |
| 118 | * upstream so it fine that this is really ugly and hacky right now. |
| 119 | */ |
| 120 | device_initialize(&rport->dev); |
| 121 | rport->dev.release = fc_rport_rogue_destroy; |
| 122 | |
| 123 | mutex_init(&rdata->rp_mutex); |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 124 | rdata->local_port = lport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 125 | rdata->trans_state = FC_PORTSTATE_ROGUE; |
| 126 | rdata->rp_state = RPORT_ST_INIT; |
| 127 | rdata->event = RPORT_EV_NONE; |
| 128 | rdata->flags = FC_RP_FLAGS_REC_SUPPORTED; |
| 129 | rdata->ops = NULL; |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 130 | rdata->e_d_tov = lport->e_d_tov; |
| 131 | rdata->r_a_tov = lport->r_a_tov; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 132 | INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout); |
| 133 | INIT_WORK(&rdata->event_work, fc_rport_work); |
| 134 | /* |
| 135 | * For good measure, but not necessary as we should only |
| 136 | * add REAL rport to the lport list. |
| 137 | */ |
| 138 | INIT_LIST_HEAD(&rdata->peers); |
| 139 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 140 | return rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 144 | * fc_rport_state() - return a string for the state the rport is in |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 145 | * @rdata: remote port private data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 146 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 147 | static const char *fc_rport_state(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 148 | { |
| 149 | const char *cp; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 150 | |
| 151 | cp = fc_rport_state_names[rdata->rp_state]; |
| 152 | if (!cp) |
| 153 | cp = "Unknown"; |
| 154 | return cp; |
| 155 | } |
| 156 | |
| 157 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 158 | * fc_set_rport_loss_tmo() - Set the remote port loss timeout in seconds. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 159 | * @rport: Pointer to Fibre Channel remote port structure |
| 160 | * @timeout: timeout in seconds |
| 161 | */ |
| 162 | void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) |
| 163 | { |
| 164 | if (timeout) |
| 165 | rport->dev_loss_tmo = timeout + 5; |
| 166 | else |
| 167 | rport->dev_loss_tmo = 30; |
| 168 | } |
| 169 | EXPORT_SYMBOL(fc_set_rport_loss_tmo); |
| 170 | |
| 171 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 172 | * fc_plogi_get_maxframe() - Get max payload from the common service parameters |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 173 | * @flp: FLOGI payload structure |
| 174 | * @maxval: upper limit, may be less than what is in the service parameters |
| 175 | */ |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 176 | static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp, |
| 177 | unsigned int maxval) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 178 | { |
| 179 | unsigned int mfs; |
| 180 | |
| 181 | /* |
| 182 | * Get max payload from the common service parameters and the |
| 183 | * class 3 receive data field size. |
| 184 | */ |
| 185 | mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK; |
| 186 | if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval) |
| 187 | maxval = mfs; |
| 188 | mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs); |
| 189 | if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval) |
| 190 | maxval = mfs; |
| 191 | return maxval; |
| 192 | } |
| 193 | |
| 194 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 195 | * fc_rport_state_enter() - Change the rport's state |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 196 | * @rdata: The rport whose state should change |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 197 | * @new: The new state of the rport |
| 198 | * |
| 199 | * Locking Note: Called with the rport lock held |
| 200 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 201 | static void fc_rport_state_enter(struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 202 | enum fc_rport_state new) |
| 203 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 204 | if (rdata->rp_state != new) |
| 205 | rdata->retries = 0; |
| 206 | rdata->rp_state = new; |
| 207 | } |
| 208 | |
| 209 | static void fc_rport_work(struct work_struct *work) |
| 210 | { |
Abhijeet Joglekar | 571f824 | 2009-02-27 10:54:41 -0800 | [diff] [blame] | 211 | u32 port_id; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 212 | struct fc_rport_priv *rdata = |
| 213 | container_of(work, struct fc_rport_priv, event_work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 214 | enum fc_rport_event event; |
| 215 | enum fc_rport_trans_state trans_state; |
| 216 | struct fc_lport *lport = rdata->local_port; |
| 217 | struct fc_rport_operations *rport_ops; |
| 218 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
| 219 | |
| 220 | mutex_lock(&rdata->rp_mutex); |
| 221 | event = rdata->event; |
| 222 | rport_ops = rdata->ops; |
| 223 | |
| 224 | if (event == RPORT_EV_CREATED) { |
| 225 | struct fc_rport *new_rport; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 226 | struct fc_rport_priv *new_rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 227 | struct fc_rport_identifiers ids; |
| 228 | |
| 229 | ids.port_id = rport->port_id; |
| 230 | ids.roles = rport->roles; |
| 231 | ids.port_name = rport->port_name; |
| 232 | ids.node_name = rport->node_name; |
| 233 | |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 234 | rdata->event = RPORT_EV_NONE; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 235 | mutex_unlock(&rdata->rp_mutex); |
| 236 | |
| 237 | new_rport = fc_remote_port_add(lport->host, 0, &ids); |
| 238 | if (new_rport) { |
| 239 | /* |
| 240 | * Switch from the rogue rport to the rport |
| 241 | * returned by the FC class. |
| 242 | */ |
| 243 | new_rport->maxframe_size = rport->maxframe_size; |
| 244 | |
| 245 | new_rdata = new_rport->dd_data; |
| 246 | new_rdata->e_d_tov = rdata->e_d_tov; |
| 247 | new_rdata->r_a_tov = rdata->r_a_tov; |
| 248 | new_rdata->ops = rdata->ops; |
| 249 | new_rdata->local_port = rdata->local_port; |
| 250 | new_rdata->flags = FC_RP_FLAGS_REC_SUPPORTED; |
| 251 | new_rdata->trans_state = FC_PORTSTATE_REAL; |
| 252 | mutex_init(&new_rdata->rp_mutex); |
| 253 | INIT_DELAYED_WORK(&new_rdata->retry_work, |
| 254 | fc_rport_timeout); |
| 255 | INIT_LIST_HEAD(&new_rdata->peers); |
| 256 | INIT_WORK(&new_rdata->event_work, fc_rport_work); |
| 257 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 258 | fc_rport_state_enter(new_rdata, RPORT_ST_READY); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 259 | } else { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 260 | printk(KERN_WARNING "libfc: Failed to allocate " |
| 261 | " memory for rport (%6x)\n", ids.port_id); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 262 | event = RPORT_EV_FAILED; |
| 263 | } |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 264 | if (rport->port_id != FC_FID_DIR_SERV) |
| 265 | if (rport_ops->event_callback) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 266 | rport_ops->event_callback(lport, rdata, |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 267 | RPORT_EV_FAILED); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 268 | put_device(&rport->dev); |
| 269 | rport = new_rport; |
| 270 | rdata = new_rport->dd_data; |
| 271 | if (rport_ops->event_callback) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 272 | rport_ops->event_callback(lport, rdata, event); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 273 | } else if ((event == RPORT_EV_FAILED) || |
| 274 | (event == RPORT_EV_LOGO) || |
| 275 | (event == RPORT_EV_STOP)) { |
| 276 | trans_state = rdata->trans_state; |
| 277 | mutex_unlock(&rdata->rp_mutex); |
| 278 | if (rport_ops->event_callback) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 279 | rport_ops->event_callback(lport, rdata, event); |
Joe Eykholt | 201e579 | 2009-07-29 17:04:54 -0700 | [diff] [blame] | 280 | cancel_delayed_work_sync(&rdata->retry_work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 281 | if (trans_state == FC_PORTSTATE_ROGUE) |
| 282 | put_device(&rport->dev); |
Abhijeet Joglekar | 571f824 | 2009-02-27 10:54:41 -0800 | [diff] [blame] | 283 | else { |
| 284 | port_id = rport->port_id; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 285 | fc_remote_port_delete(rport); |
Abhijeet Joglekar | 571f824 | 2009-02-27 10:54:41 -0800 | [diff] [blame] | 286 | lport->tt.exch_mgr_reset(lport, 0, port_id); |
| 287 | lport->tt.exch_mgr_reset(lport, port_id, 0); |
| 288 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 289 | } else |
| 290 | mutex_unlock(&rdata->rp_mutex); |
| 291 | } |
| 292 | |
| 293 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 294 | * fc_rport_login() - Start the remote port login state machine |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 295 | * @rdata: private remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 296 | * |
| 297 | * Locking Note: Called without the rport lock held. This |
| 298 | * function will hold the rport lock, call an _enter_* |
| 299 | * function and then unlock the rport. |
| 300 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 301 | int fc_rport_login(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 302 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 303 | mutex_lock(&rdata->rp_mutex); |
| 304 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 305 | FC_RPORT_DBG(rdata, "Login to port\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 306 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 307 | fc_rport_enter_plogi(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 308 | |
| 309 | mutex_unlock(&rdata->rp_mutex); |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | /** |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 315 | * fc_rport_enter_delete() - schedule a remote port to be deleted. |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 316 | * @rdata: private remote port |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 317 | * @event: event to report as the reason for deletion |
| 318 | * |
| 319 | * Locking Note: Called with the rport lock held. |
| 320 | * |
| 321 | * Allow state change into DELETE only once. |
| 322 | * |
| 323 | * Call queue_work only if there's no event already pending. |
| 324 | * Set the new event so that the old pending event will not occur. |
| 325 | * Since we have the mutex, even if fc_rport_work() is already started, |
| 326 | * it'll see the new event. |
| 327 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 328 | static void fc_rport_enter_delete(struct fc_rport_priv *rdata, |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 329 | enum fc_rport_event event) |
| 330 | { |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 331 | if (rdata->rp_state == RPORT_ST_DELETE) |
| 332 | return; |
| 333 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 334 | FC_RPORT_DBG(rdata, "Delete port\n"); |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 335 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 336 | fc_rport_state_enter(rdata, RPORT_ST_DELETE); |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 337 | |
| 338 | if (rdata->event == RPORT_EV_NONE) |
| 339 | queue_work(rport_event_queue, &rdata->event_work); |
| 340 | rdata->event = event; |
| 341 | } |
| 342 | |
| 343 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 344 | * fc_rport_logoff() - Logoff and remove an rport |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 345 | * @rdata: private remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 346 | * |
| 347 | * Locking Note: Called without the rport lock held. This |
| 348 | * function will hold the rport lock, call an _enter_* |
| 349 | * function and then unlock the rport. |
| 350 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 351 | int fc_rport_logoff(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 352 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 353 | mutex_lock(&rdata->rp_mutex); |
| 354 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 355 | FC_RPORT_DBG(rdata, "Remove port\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 356 | |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 357 | if (rdata->rp_state == RPORT_ST_DELETE) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 358 | FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n"); |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 359 | mutex_unlock(&rdata->rp_mutex); |
| 360 | goto out; |
| 361 | } |
| 362 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 363 | fc_rport_enter_logo(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 364 | |
| 365 | /* |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 366 | * Change the state to Delete so that we discard |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 367 | * the response. |
| 368 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 369 | fc_rport_enter_delete(rdata, RPORT_EV_STOP); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 370 | mutex_unlock(&rdata->rp_mutex); |
| 371 | |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 372 | out: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 377 | * fc_rport_enter_ready() - The rport is ready |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 378 | * @rdata: private remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 379 | * |
| 380 | * Locking Note: The rport lock is expected to be held before calling |
| 381 | * this routine. |
| 382 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 383 | static void fc_rport_enter_ready(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 384 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 385 | fc_rport_state_enter(rdata, RPORT_ST_READY); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 386 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 387 | FC_RPORT_DBG(rdata, "Port is Ready\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 388 | |
Joe Eykholt | 5f7ea3b | 2009-07-29 17:04:49 -0700 | [diff] [blame] | 389 | if (rdata->event == RPORT_EV_NONE) |
| 390 | queue_work(rport_event_queue, &rdata->event_work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 391 | rdata->event = RPORT_EV_CREATED; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 395 | * fc_rport_timeout() - Handler for the retry_work timer. |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 396 | * @work: The work struct of the fc_rport_priv |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 397 | * |
| 398 | * Locking Note: Called without the rport lock held. This |
| 399 | * function will hold the rport lock, call an _enter_* |
| 400 | * function and then unlock the rport. |
| 401 | */ |
| 402 | static void fc_rport_timeout(struct work_struct *work) |
| 403 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 404 | struct fc_rport_priv *rdata = |
| 405 | container_of(work, struct fc_rport_priv, retry_work.work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 406 | |
| 407 | mutex_lock(&rdata->rp_mutex); |
| 408 | |
| 409 | switch (rdata->rp_state) { |
| 410 | case RPORT_ST_PLOGI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 411 | fc_rport_enter_plogi(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 412 | break; |
| 413 | case RPORT_ST_PRLI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 414 | fc_rport_enter_prli(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 415 | break; |
| 416 | case RPORT_ST_RTV: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 417 | fc_rport_enter_rtv(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 418 | break; |
| 419 | case RPORT_ST_LOGO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 420 | fc_rport_enter_logo(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 421 | break; |
| 422 | case RPORT_ST_READY: |
| 423 | case RPORT_ST_INIT: |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 424 | case RPORT_ST_DELETE: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 425 | break; |
| 426 | } |
| 427 | |
| 428 | mutex_unlock(&rdata->rp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 432 | * fc_rport_error() - Error handler, called once retries have been exhausted |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 433 | * @rdata: private remote port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 434 | * @fp: The frame pointer |
| 435 | * |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 436 | * Locking Note: The rport lock is expected to be held before |
| 437 | * calling this routine |
| 438 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 439 | 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] | 440 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 441 | FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n", |
| 442 | PTR_ERR(fp), fc_rport_state(rdata), rdata->retries); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 443 | |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 444 | switch (rdata->rp_state) { |
| 445 | case RPORT_ST_PLOGI: |
| 446 | case RPORT_ST_PRLI: |
| 447 | case RPORT_ST_LOGO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 448 | fc_rport_enter_delete(rdata, RPORT_EV_FAILED); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 449 | break; |
| 450 | case RPORT_ST_RTV: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 451 | fc_rport_enter_ready(rdata); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 452 | break; |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 453 | case RPORT_ST_DELETE: |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 454 | case RPORT_ST_READY: |
| 455 | case RPORT_ST_INIT: |
| 456 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 461 | * fc_rport_error_retry() - Error handler when retries are desired |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 462 | * @rdata: private remote port data |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 463 | * @fp: The frame pointer |
| 464 | * |
| 465 | * If the error was an exchange timeout retry immediately, |
| 466 | * otherwise wait for E_D_TOV. |
| 467 | * |
| 468 | * Locking Note: The rport lock is expected to be held before |
| 469 | * calling this routine |
| 470 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 471 | static void fc_rport_error_retry(struct fc_rport_priv *rdata, |
| 472 | struct fc_frame *fp) |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 473 | { |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 474 | unsigned long delay = FC_DEF_E_D_TOV; |
| 475 | |
| 476 | /* make sure this isn't an FC_EX_CLOSED error, never retry those */ |
| 477 | if (PTR_ERR(fp) == -FC_EX_CLOSED) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 478 | return fc_rport_error(rdata, fp); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 479 | |
Abhijeet Joglekar | a366695 | 2009-05-01 10:01:26 -0700 | [diff] [blame] | 480 | if (rdata->retries < rdata->local_port->max_rport_retry_count) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 481 | FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n", |
| 482 | PTR_ERR(fp), fc_rport_state(rdata)); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 483 | rdata->retries++; |
| 484 | /* no additional delay on exchange timeouts */ |
| 485 | if (PTR_ERR(fp) == -FC_EX_TIMEOUT) |
| 486 | delay = 0; |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 487 | schedule_delayed_work(&rdata->retry_work, delay); |
| 488 | return; |
| 489 | } |
| 490 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 491 | return fc_rport_error(rdata, fp); |
Chris Leech | 6755db1 | 2009-02-27 10:55:02 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 495 | * fc_rport_plogi_recv_resp() - Handle incoming ELS PLOGI response |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 496 | * @sp: current sequence in the PLOGI exchange |
| 497 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 498 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 499 | * |
| 500 | * Locking Note: This function will be called without the rport lock |
| 501 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 502 | * and then unlock the rport. |
| 503 | */ |
| 504 | 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^] | 505 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 506 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 507 | struct fc_rport_priv *rdata = rdata_arg; |
| 508 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 509 | struct fc_lport *lport = rdata->local_port; |
Robert Love | a29e764 | 2009-04-21 16:27:41 -0700 | [diff] [blame] | 510 | struct fc_els_flogi *plp = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 511 | unsigned int tov; |
| 512 | u16 csp_seq; |
| 513 | u16 cssp_seq; |
| 514 | u8 op; |
| 515 | |
| 516 | mutex_lock(&rdata->rp_mutex); |
| 517 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 518 | FC_RPORT_DBG(rdata, "Received a PLOGI response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 519 | |
| 520 | if (rdata->rp_state != RPORT_ST_PLOGI) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 521 | FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state " |
| 522 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 523 | if (IS_ERR(fp)) |
| 524 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 525 | goto out; |
| 526 | } |
| 527 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 528 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 529 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 530 | goto err; |
| 531 | } |
| 532 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 533 | op = fc_frame_payload_op(fp); |
| 534 | if (op == ELS_LS_ACC && |
| 535 | (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) { |
| 536 | rport->port_name = get_unaligned_be64(&plp->fl_wwpn); |
| 537 | rport->node_name = get_unaligned_be64(&plp->fl_wwnn); |
| 538 | |
| 539 | tov = ntohl(plp->fl_csp.sp_e_d_tov); |
| 540 | if (ntohs(plp->fl_csp.sp_features) & FC_SP_FT_EDTR) |
| 541 | tov /= 1000; |
| 542 | if (tov > rdata->e_d_tov) |
| 543 | rdata->e_d_tov = tov; |
| 544 | csp_seq = ntohs(plp->fl_csp.sp_tot_seq); |
| 545 | cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq); |
| 546 | if (cssp_seq < csp_seq) |
| 547 | csp_seq = cssp_seq; |
| 548 | rdata->max_seq = csp_seq; |
| 549 | rport->maxframe_size = |
| 550 | fc_plogi_get_maxframe(plp, lport->mfs); |
| 551 | |
| 552 | /* |
| 553 | * If the rport is one of the well known addresses |
| 554 | * we skip PRLI and RTV and go straight to READY. |
| 555 | */ |
| 556 | if (rport->port_id >= FC_FID_DOM_MGR) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 557 | fc_rport_enter_ready(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 558 | else |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 559 | fc_rport_enter_prli(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 560 | } else |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 561 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 562 | |
| 563 | out: |
| 564 | fc_frame_free(fp); |
| 565 | err: |
| 566 | mutex_unlock(&rdata->rp_mutex); |
| 567 | put_device(&rport->dev); |
| 568 | } |
| 569 | |
| 570 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 571 | * fc_rport_enter_plogi() - Send Port Login (PLOGI) request to peer |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 572 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 573 | * |
| 574 | * Locking Note: The rport lock is expected to be held before calling |
| 575 | * this routine. |
| 576 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 577 | static void fc_rport_enter_plogi(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 578 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 579 | struct fc_lport *lport = rdata->local_port; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 580 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 581 | struct fc_frame *fp; |
| 582 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 583 | FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n", |
| 584 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 585 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 586 | fc_rport_state_enter(rdata, RPORT_ST_PLOGI); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 587 | |
| 588 | rport->maxframe_size = FC_MIN_MAX_PAYLOAD; |
| 589 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); |
| 590 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 591 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 592 | return; |
| 593 | } |
| 594 | rdata->e_d_tov = lport->e_d_tov; |
| 595 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 596 | if (!lport->tt.elsct_send(lport, rdata, fp, ELS_PLOGI, |
| 597 | fc_rport_plogi_resp, rdata, lport->e_d_tov)) |
| 598 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 599 | else |
| 600 | get_device(&rport->dev); |
| 601 | } |
| 602 | |
| 603 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 604 | * fc_rport_prli_resp() - Process Login (PRLI) response handler |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 605 | * @sp: current sequence in the PRLI exchange |
| 606 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 607 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 608 | * |
| 609 | * Locking Note: This function will be called without the rport lock |
| 610 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 611 | * and then unlock the rport. |
| 612 | */ |
| 613 | 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^] | 614 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 615 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 616 | struct fc_rport_priv *rdata = rdata_arg; |
| 617 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 618 | struct { |
| 619 | struct fc_els_prli prli; |
| 620 | struct fc_els_spp spp; |
| 621 | } *pp; |
| 622 | u32 roles = FC_RPORT_ROLE_UNKNOWN; |
| 623 | u32 fcp_parm = 0; |
| 624 | u8 op; |
| 625 | |
| 626 | mutex_lock(&rdata->rp_mutex); |
| 627 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 628 | FC_RPORT_DBG(rdata, "Received a PRLI response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 629 | |
| 630 | if (rdata->rp_state != RPORT_ST_PRLI) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 631 | FC_RPORT_DBG(rdata, "Received a PRLI response, but in state " |
| 632 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 633 | if (IS_ERR(fp)) |
| 634 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 635 | goto out; |
| 636 | } |
| 637 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 638 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 639 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 640 | goto err; |
| 641 | } |
| 642 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 643 | op = fc_frame_payload_op(fp); |
| 644 | if (op == ELS_LS_ACC) { |
| 645 | pp = fc_frame_payload_get(fp, sizeof(*pp)); |
| 646 | if (pp && pp->prli.prli_spp_len >= sizeof(pp->spp)) { |
| 647 | fcp_parm = ntohl(pp->spp.spp_params); |
| 648 | if (fcp_parm & FCP_SPPF_RETRY) |
| 649 | rdata->flags |= FC_RP_FLAGS_RETRY; |
| 650 | } |
| 651 | |
| 652 | rport->supported_classes = FC_COS_CLASS3; |
| 653 | if (fcp_parm & FCP_SPPF_INIT_FCN) |
| 654 | roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 655 | if (fcp_parm & FCP_SPPF_TARG_FCN) |
| 656 | roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 657 | |
| 658 | rport->roles = roles; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 659 | fc_rport_enter_rtv(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 660 | |
| 661 | } else { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 662 | FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n"); |
| 663 | fc_rport_enter_delete(rdata, RPORT_EV_FAILED); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | out: |
| 667 | fc_frame_free(fp); |
| 668 | err: |
| 669 | mutex_unlock(&rdata->rp_mutex); |
| 670 | put_device(&rport->dev); |
| 671 | } |
| 672 | |
| 673 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 674 | * fc_rport_logo_resp() - Logout (LOGO) response handler |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 675 | * @sp: current sequence in the LOGO exchange |
| 676 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 677 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 678 | * |
| 679 | * Locking Note: This function will be called without the rport lock |
| 680 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 681 | * and then unlock the rport. |
| 682 | */ |
| 683 | static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 684 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 685 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 686 | struct fc_rport_priv *rdata = rdata_arg; |
| 687 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 688 | u8 op; |
| 689 | |
| 690 | mutex_lock(&rdata->rp_mutex); |
| 691 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 692 | FC_RPORT_DBG(rdata, "Received a LOGO response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 693 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 694 | if (rdata->rp_state != RPORT_ST_LOGO) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 695 | FC_RPORT_DBG(rdata, "Received a LOGO response, but in state " |
| 696 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 697 | if (IS_ERR(fp)) |
| 698 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 699 | goto out; |
| 700 | } |
| 701 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 702 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 703 | fc_rport_error_retry(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 704 | goto err; |
| 705 | } |
| 706 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 707 | op = fc_frame_payload_op(fp); |
| 708 | if (op == ELS_LS_ACC) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 709 | fc_rport_enter_rtv(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 710 | } else { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 711 | FC_RPORT_DBG(rdata, "Bad ELS response for LOGO command\n"); |
| 712 | fc_rport_enter_delete(rdata, RPORT_EV_LOGO); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | out: |
| 716 | fc_frame_free(fp); |
| 717 | err: |
| 718 | mutex_unlock(&rdata->rp_mutex); |
| 719 | put_device(&rport->dev); |
| 720 | } |
| 721 | |
| 722 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 723 | * fc_rport_enter_prli() - Send Process Login (PRLI) request to peer |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 724 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 725 | * |
| 726 | * Locking Note: The rport lock is expected to be held before calling |
| 727 | * this routine. |
| 728 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 729 | static void fc_rport_enter_prli(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 730 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 731 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 732 | struct fc_lport *lport = rdata->local_port; |
| 733 | struct { |
| 734 | struct fc_els_prli prli; |
| 735 | struct fc_els_spp spp; |
| 736 | } *pp; |
| 737 | struct fc_frame *fp; |
| 738 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 739 | FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n", |
| 740 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 741 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 742 | fc_rport_state_enter(rdata, RPORT_ST_PRLI); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 743 | |
| 744 | fp = fc_frame_alloc(lport, sizeof(*pp)); |
| 745 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 746 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 747 | return; |
| 748 | } |
| 749 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 750 | if (!lport->tt.elsct_send(lport, rdata, fp, ELS_PRLI, |
| 751 | fc_rport_prli_resp, rdata, lport->e_d_tov)) |
| 752 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 753 | else |
| 754 | get_device(&rport->dev); |
| 755 | } |
| 756 | |
| 757 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 758 | * fc_rport_els_rtv_resp() - Request Timeout Value response handler |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 759 | * @sp: current sequence in the RTV exchange |
| 760 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 761 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 762 | * |
| 763 | * Many targets don't seem to support this. |
| 764 | * |
| 765 | * Locking Note: This function will be called without the rport lock |
| 766 | * held, but it will lock, call an _enter_* function or fc_rport_error |
| 767 | * and then unlock the rport. |
| 768 | */ |
| 769 | 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^] | 770 | void *rdata_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 771 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 772 | struct fc_rport_priv *rdata = rdata_arg; |
| 773 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 774 | u8 op; |
| 775 | |
| 776 | mutex_lock(&rdata->rp_mutex); |
| 777 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 778 | FC_RPORT_DBG(rdata, "Received a RTV response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 779 | |
| 780 | if (rdata->rp_state != RPORT_ST_RTV) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 781 | FC_RPORT_DBG(rdata, "Received a RTV response, but in state " |
| 782 | "%s\n", fc_rport_state(rdata)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 783 | if (IS_ERR(fp)) |
| 784 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 785 | goto out; |
| 786 | } |
| 787 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 788 | if (IS_ERR(fp)) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 789 | fc_rport_error(rdata, fp); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 790 | goto err; |
| 791 | } |
| 792 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 793 | op = fc_frame_payload_op(fp); |
| 794 | if (op == ELS_LS_ACC) { |
| 795 | struct fc_els_rtv_acc *rtv; |
| 796 | u32 toq; |
| 797 | u32 tov; |
| 798 | |
| 799 | rtv = fc_frame_payload_get(fp, sizeof(*rtv)); |
| 800 | if (rtv) { |
| 801 | toq = ntohl(rtv->rtv_toq); |
| 802 | tov = ntohl(rtv->rtv_r_a_tov); |
| 803 | if (tov == 0) |
| 804 | tov = 1; |
| 805 | rdata->r_a_tov = tov; |
| 806 | tov = ntohl(rtv->rtv_e_d_tov); |
| 807 | if (toq & FC_ELS_RTV_EDRES) |
| 808 | tov /= 1000000; |
| 809 | if (tov == 0) |
| 810 | tov = 1; |
| 811 | rdata->e_d_tov = tov; |
| 812 | } |
| 813 | } |
| 814 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 815 | fc_rport_enter_ready(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 816 | |
| 817 | out: |
| 818 | fc_frame_free(fp); |
| 819 | err: |
| 820 | mutex_unlock(&rdata->rp_mutex); |
| 821 | put_device(&rport->dev); |
| 822 | } |
| 823 | |
| 824 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 825 | * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request to peer |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 826 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 827 | * |
| 828 | * Locking Note: The rport lock is expected to be held before calling |
| 829 | * this routine. |
| 830 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 831 | static void fc_rport_enter_rtv(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 832 | { |
| 833 | struct fc_frame *fp; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 834 | struct fc_lport *lport = rdata->local_port; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 835 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 836 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 837 | FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n", |
| 838 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 839 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 840 | fc_rport_state_enter(rdata, RPORT_ST_RTV); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 841 | |
| 842 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv)); |
| 843 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 844 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 845 | return; |
| 846 | } |
| 847 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 848 | if (!lport->tt.elsct_send(lport, rdata, fp, ELS_RTV, |
| 849 | fc_rport_rtv_resp, rdata, lport->e_d_tov)) |
| 850 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 851 | else |
| 852 | get_device(&rport->dev); |
| 853 | } |
| 854 | |
| 855 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 856 | * fc_rport_enter_logo() - Send Logout (LOGO) request to peer |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 857 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 858 | * |
| 859 | * Locking Note: The rport lock is expected to be held before calling |
| 860 | * this routine. |
| 861 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 862 | static void fc_rport_enter_logo(struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 863 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 864 | struct fc_lport *lport = rdata->local_port; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 865 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 866 | struct fc_frame *fp; |
| 867 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 868 | FC_RPORT_DBG(rdata, "Port entered LOGO state from %s state\n", |
| 869 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 870 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 871 | fc_rport_state_enter(rdata, RPORT_ST_LOGO); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 872 | |
| 873 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo)); |
| 874 | if (!fp) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 875 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 876 | return; |
| 877 | } |
| 878 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 879 | if (!lport->tt.elsct_send(lport, rdata, fp, ELS_LOGO, |
| 880 | fc_rport_logo_resp, rdata, lport->e_d_tov)) |
| 881 | fc_rport_error_retry(rdata, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 882 | else |
| 883 | get_device(&rport->dev); |
| 884 | } |
| 885 | |
| 886 | |
| 887 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 888 | * fc_rport_recv_req() - Receive a request from a rport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 889 | * @sp: current sequence in the PLOGI exchange |
| 890 | * @fp: response frame |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 891 | * @rdata_arg: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 892 | * |
| 893 | * Locking Note: Called without the rport lock held. This |
| 894 | * function will hold the rport lock, call an _enter_* |
| 895 | * function and then unlock the rport. |
| 896 | */ |
| 897 | void fc_rport_recv_req(struct fc_seq *sp, struct fc_frame *fp, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 898 | struct fc_rport_priv *rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 899 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 900 | struct fc_lport *lport = rdata->local_port; |
| 901 | |
| 902 | struct fc_frame_header *fh; |
| 903 | struct fc_seq_els_data els_data; |
| 904 | u8 op; |
| 905 | |
| 906 | mutex_lock(&rdata->rp_mutex); |
| 907 | |
| 908 | els_data.fp = NULL; |
| 909 | els_data.explan = ELS_EXPL_NONE; |
| 910 | els_data.reason = ELS_RJT_NONE; |
| 911 | |
| 912 | fh = fc_frame_header_get(fp); |
| 913 | |
| 914 | if (fh->fh_r_ctl == FC_RCTL_ELS_REQ && fh->fh_type == FC_TYPE_ELS) { |
| 915 | op = fc_frame_payload_op(fp); |
| 916 | switch (op) { |
| 917 | case ELS_PLOGI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 918 | fc_rport_recv_plogi_req(rdata, sp, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 919 | break; |
| 920 | case ELS_PRLI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 921 | fc_rport_recv_prli_req(rdata, sp, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 922 | break; |
| 923 | case ELS_PRLO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 924 | fc_rport_recv_prlo_req(rdata, sp, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 925 | break; |
| 926 | case ELS_LOGO: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 927 | fc_rport_recv_logo_req(rdata, sp, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 928 | break; |
| 929 | case ELS_RRQ: |
| 930 | els_data.fp = fp; |
| 931 | lport->tt.seq_els_rsp_send(sp, ELS_RRQ, &els_data); |
| 932 | break; |
| 933 | case ELS_REC: |
| 934 | els_data.fp = fp; |
| 935 | lport->tt.seq_els_rsp_send(sp, ELS_REC, &els_data); |
| 936 | break; |
| 937 | default: |
| 938 | els_data.reason = ELS_RJT_UNSUP; |
| 939 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &els_data); |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | mutex_unlock(&rdata->rp_mutex); |
| 945 | } |
| 946 | |
| 947 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 948 | * fc_rport_recv_plogi_req() - Handle incoming Port Login (PLOGI) request |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 949 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 950 | * @sp: current sequence in the PLOGI exchange |
| 951 | * @fp: PLOGI request frame |
| 952 | * |
| 953 | * Locking Note: The rport lock is exected to be held before calling |
| 954 | * this function. |
| 955 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 956 | static void fc_rport_recv_plogi_req(struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 957 | struct fc_seq *sp, struct fc_frame *rx_fp) |
| 958 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 959 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 960 | struct fc_lport *lport = rdata->local_port; |
| 961 | struct fc_frame *fp = rx_fp; |
| 962 | struct fc_exch *ep; |
| 963 | struct fc_frame_header *fh; |
| 964 | struct fc_els_flogi *pl; |
| 965 | struct fc_seq_els_data rjt_data; |
| 966 | u32 sid; |
| 967 | u64 wwpn; |
| 968 | u64 wwnn; |
| 969 | enum fc_els_rjt_reason reject = 0; |
| 970 | u32 f_ctl; |
| 971 | rjt_data.fp = NULL; |
| 972 | |
| 973 | fh = fc_frame_header_get(fp); |
| 974 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 975 | FC_RPORT_DBG(rdata, "Received PLOGI request while in state %s\n", |
| 976 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 977 | |
| 978 | sid = ntoh24(fh->fh_s_id); |
| 979 | pl = fc_frame_payload_get(fp, sizeof(*pl)); |
| 980 | if (!pl) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 981 | FC_RPORT_DBG(rdata, "Received PLOGI too short\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 982 | WARN_ON(1); |
| 983 | /* XXX TBD: send reject? */ |
| 984 | fc_frame_free(fp); |
| 985 | return; |
| 986 | } |
| 987 | wwpn = get_unaligned_be64(&pl->fl_wwpn); |
| 988 | wwnn = get_unaligned_be64(&pl->fl_wwnn); |
| 989 | |
| 990 | /* |
| 991 | * If the session was just created, possibly due to the incoming PLOGI, |
| 992 | * set the state appropriately and accept the PLOGI. |
| 993 | * |
| 994 | * If we had also sent a PLOGI, and if the received PLOGI is from a |
| 995 | * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason |
| 996 | * "command already in progress". |
| 997 | * |
| 998 | * XXX TBD: If the session was ready before, the PLOGI should result in |
| 999 | * all outstanding exchanges being reset. |
| 1000 | */ |
| 1001 | switch (rdata->rp_state) { |
| 1002 | case RPORT_ST_INIT: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1003 | FC_RPORT_DBG(rdata, "Received PLOGI, wwpn %llx state INIT " |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1004 | "- reject\n", (unsigned long long)wwpn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1005 | reject = ELS_RJT_UNSUP; |
| 1006 | break; |
| 1007 | case RPORT_ST_PLOGI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1008 | FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state %d\n", |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1009 | rdata->rp_state); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1010 | if (wwpn < lport->wwpn) |
| 1011 | reject = ELS_RJT_INPROG; |
| 1012 | break; |
| 1013 | case RPORT_ST_PRLI: |
| 1014 | case RPORT_ST_READY: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1015 | FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d " |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1016 | "- ignored for now\n", rdata->rp_state); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1017 | /* XXX TBD - should reset */ |
| 1018 | break; |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 1019 | case RPORT_ST_DELETE: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1020 | default: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1021 | FC_RPORT_DBG(rdata, "Received PLOGI in unexpected " |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1022 | "state %d\n", rdata->rp_state); |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 1023 | fc_frame_free(fp); |
| 1024 | return; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1025 | break; |
| 1026 | } |
| 1027 | |
| 1028 | if (reject) { |
| 1029 | rjt_data.reason = reject; |
| 1030 | rjt_data.explan = ELS_EXPL_NONE; |
| 1031 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1032 | fc_frame_free(fp); |
| 1033 | } else { |
| 1034 | fp = fc_frame_alloc(lport, sizeof(*pl)); |
| 1035 | if (fp == NULL) { |
| 1036 | fp = rx_fp; |
| 1037 | rjt_data.reason = ELS_RJT_UNAB; |
| 1038 | rjt_data.explan = ELS_EXPL_NONE; |
| 1039 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1040 | fc_frame_free(fp); |
| 1041 | } else { |
| 1042 | sp = lport->tt.seq_start_next(sp); |
| 1043 | WARN_ON(!sp); |
| 1044 | fc_rport_set_name(rport, wwpn, wwnn); |
| 1045 | |
| 1046 | /* |
| 1047 | * Get session payload size from incoming PLOGI. |
| 1048 | */ |
| 1049 | rport->maxframe_size = |
| 1050 | fc_plogi_get_maxframe(pl, lport->mfs); |
| 1051 | fc_frame_free(rx_fp); |
| 1052 | fc_plogi_fill(lport, fp, ELS_LS_ACC); |
| 1053 | |
| 1054 | /* |
| 1055 | * Send LS_ACC. If this fails, |
| 1056 | * the originator should retry. |
| 1057 | */ |
| 1058 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; |
| 1059 | f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 1060 | ep = fc_seq_exch(sp); |
| 1061 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1062 | FC_TYPE_ELS, f_ctl, 0); |
| 1063 | lport->tt.seq_send(lport, sp, fp); |
| 1064 | if (rdata->rp_state == RPORT_ST_PLOGI) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1065 | fc_rport_enter_prli(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1071 | * fc_rport_recv_prli_req() - Handle incoming Process Login (PRLI) request |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1072 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1073 | * @sp: current sequence in the PRLI exchange |
| 1074 | * @fp: PRLI request frame |
| 1075 | * |
| 1076 | * Locking Note: The rport lock is exected to be held before calling |
| 1077 | * this function. |
| 1078 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1079 | static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1080 | struct fc_seq *sp, struct fc_frame *rx_fp) |
| 1081 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1082 | struct fc_rport *rport = PRIV_TO_RPORT(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1083 | struct fc_lport *lport = rdata->local_port; |
| 1084 | struct fc_exch *ep; |
| 1085 | struct fc_frame *fp; |
| 1086 | struct fc_frame_header *fh; |
| 1087 | struct { |
| 1088 | struct fc_els_prli prli; |
| 1089 | struct fc_els_spp spp; |
| 1090 | } *pp; |
| 1091 | struct fc_els_spp *rspp; /* request service param page */ |
| 1092 | struct fc_els_spp *spp; /* response spp */ |
| 1093 | unsigned int len; |
| 1094 | unsigned int plen; |
| 1095 | enum fc_els_rjt_reason reason = ELS_RJT_UNAB; |
| 1096 | enum fc_els_rjt_explan explan = ELS_EXPL_NONE; |
| 1097 | enum fc_els_spp_resp resp; |
| 1098 | struct fc_seq_els_data rjt_data; |
| 1099 | u32 f_ctl; |
| 1100 | u32 fcp_parm; |
| 1101 | u32 roles = FC_RPORT_ROLE_UNKNOWN; |
| 1102 | rjt_data.fp = NULL; |
| 1103 | |
| 1104 | fh = fc_frame_header_get(rx_fp); |
| 1105 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1106 | FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n", |
| 1107 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1108 | |
| 1109 | switch (rdata->rp_state) { |
| 1110 | case RPORT_ST_PRLI: |
| 1111 | case RPORT_ST_READY: |
| 1112 | reason = ELS_RJT_NONE; |
| 1113 | break; |
| 1114 | default: |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 1115 | fc_frame_free(rx_fp); |
| 1116 | return; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1117 | break; |
| 1118 | } |
| 1119 | len = fr_len(rx_fp) - sizeof(*fh); |
| 1120 | pp = fc_frame_payload_get(rx_fp, sizeof(*pp)); |
| 1121 | if (pp == NULL) { |
| 1122 | reason = ELS_RJT_PROT; |
| 1123 | explan = ELS_EXPL_INV_LEN; |
| 1124 | } else { |
| 1125 | plen = ntohs(pp->prli.prli_len); |
| 1126 | if ((plen % 4) != 0 || plen > len) { |
| 1127 | reason = ELS_RJT_PROT; |
| 1128 | explan = ELS_EXPL_INV_LEN; |
| 1129 | } else if (plen < len) { |
| 1130 | len = plen; |
| 1131 | } |
| 1132 | plen = pp->prli.prli_spp_len; |
| 1133 | if ((plen % 4) != 0 || plen < sizeof(*spp) || |
| 1134 | plen > len || len < sizeof(*pp)) { |
| 1135 | reason = ELS_RJT_PROT; |
| 1136 | explan = ELS_EXPL_INV_LEN; |
| 1137 | } |
| 1138 | rspp = &pp->spp; |
| 1139 | } |
| 1140 | if (reason != ELS_RJT_NONE || |
| 1141 | (fp = fc_frame_alloc(lport, len)) == NULL) { |
| 1142 | rjt_data.reason = reason; |
| 1143 | rjt_data.explan = explan; |
| 1144 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1145 | } else { |
| 1146 | sp = lport->tt.seq_start_next(sp); |
| 1147 | WARN_ON(!sp); |
| 1148 | pp = fc_frame_payload_get(fp, len); |
| 1149 | WARN_ON(!pp); |
| 1150 | memset(pp, 0, len); |
| 1151 | pp->prli.prli_cmd = ELS_LS_ACC; |
| 1152 | pp->prli.prli_spp_len = plen; |
| 1153 | pp->prli.prli_len = htons(len); |
| 1154 | len -= sizeof(struct fc_els_prli); |
| 1155 | |
| 1156 | /* |
| 1157 | * Go through all the service parameter pages and build |
| 1158 | * response. If plen indicates longer SPP than standard, |
| 1159 | * use that. The entire response has been pre-cleared above. |
| 1160 | */ |
| 1161 | spp = &pp->spp; |
| 1162 | while (len >= plen) { |
| 1163 | spp->spp_type = rspp->spp_type; |
| 1164 | spp->spp_type_ext = rspp->spp_type_ext; |
| 1165 | spp->spp_flags = rspp->spp_flags & FC_SPP_EST_IMG_PAIR; |
| 1166 | resp = FC_SPP_RESP_ACK; |
| 1167 | if (rspp->spp_flags & FC_SPP_RPA_VAL) |
| 1168 | resp = FC_SPP_RESP_NO_PA; |
| 1169 | switch (rspp->spp_type) { |
| 1170 | case 0: /* common to all FC-4 types */ |
| 1171 | break; |
| 1172 | case FC_TYPE_FCP: |
| 1173 | fcp_parm = ntohl(rspp->spp_params); |
| 1174 | if (fcp_parm * FCP_SPPF_RETRY) |
| 1175 | rdata->flags |= FC_RP_FLAGS_RETRY; |
| 1176 | rport->supported_classes = FC_COS_CLASS3; |
| 1177 | if (fcp_parm & FCP_SPPF_INIT_FCN) |
| 1178 | roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 1179 | if (fcp_parm & FCP_SPPF_TARG_FCN) |
| 1180 | roles |= FC_RPORT_ROLE_FCP_TARGET; |
| 1181 | rport->roles = roles; |
| 1182 | |
| 1183 | spp->spp_params = |
| 1184 | htonl(lport->service_params); |
| 1185 | break; |
| 1186 | default: |
| 1187 | resp = FC_SPP_RESP_INVL; |
| 1188 | break; |
| 1189 | } |
| 1190 | spp->spp_flags |= resp; |
| 1191 | len -= plen; |
| 1192 | rspp = (struct fc_els_spp *)((char *)rspp + plen); |
| 1193 | spp = (struct fc_els_spp *)((char *)spp + plen); |
| 1194 | } |
| 1195 | |
| 1196 | /* |
| 1197 | * Send LS_ACC. If this fails, the originator should retry. |
| 1198 | */ |
| 1199 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; |
| 1200 | f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 1201 | ep = fc_seq_exch(sp); |
| 1202 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 1203 | FC_TYPE_ELS, f_ctl, 0); |
| 1204 | lport->tt.seq_send(lport, sp, fp); |
| 1205 | |
| 1206 | /* |
| 1207 | * Get lock and re-check state. |
| 1208 | */ |
| 1209 | switch (rdata->rp_state) { |
| 1210 | case RPORT_ST_PRLI: |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1211 | fc_rport_enter_ready(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1212 | break; |
| 1213 | case RPORT_ST_READY: |
| 1214 | break; |
| 1215 | default: |
| 1216 | break; |
| 1217 | } |
| 1218 | } |
| 1219 | fc_frame_free(rx_fp); |
| 1220 | } |
| 1221 | |
| 1222 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1223 | * fc_rport_recv_prlo_req() - Handle incoming Process Logout (PRLO) request |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1224 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1225 | * @sp: current sequence in the PRLO exchange |
| 1226 | * @fp: PRLO request frame |
| 1227 | * |
| 1228 | * Locking Note: The rport lock is exected to be held before calling |
| 1229 | * this function. |
| 1230 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1231 | static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata, |
| 1232 | struct fc_seq *sp, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1233 | struct fc_frame *fp) |
| 1234 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1235 | struct fc_lport *lport = rdata->local_port; |
| 1236 | |
| 1237 | struct fc_frame_header *fh; |
| 1238 | struct fc_seq_els_data rjt_data; |
| 1239 | |
| 1240 | fh = fc_frame_header_get(fp); |
| 1241 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1242 | FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n", |
| 1243 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1244 | |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 1245 | if (rdata->rp_state == RPORT_ST_DELETE) { |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 1246 | fc_frame_free(fp); |
| 1247 | return; |
| 1248 | } |
| 1249 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1250 | rjt_data.fp = NULL; |
| 1251 | rjt_data.reason = ELS_RJT_UNAB; |
| 1252 | rjt_data.explan = ELS_EXPL_NONE; |
| 1253 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 1254 | fc_frame_free(fp); |
| 1255 | } |
| 1256 | |
| 1257 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1258 | * fc_rport_recv_logo_req() - Handle incoming Logout (LOGO) request |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1259 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1260 | * @sp: current sequence in the LOGO exchange |
| 1261 | * @fp: LOGO request frame |
| 1262 | * |
| 1263 | * Locking Note: The rport lock is exected to be held before calling |
| 1264 | * this function. |
| 1265 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1266 | static void fc_rport_recv_logo_req(struct fc_rport_priv *rdata, |
| 1267 | struct fc_seq *sp, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1268 | struct fc_frame *fp) |
| 1269 | { |
| 1270 | struct fc_frame_header *fh; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1271 | struct fc_lport *lport = rdata->local_port; |
| 1272 | |
| 1273 | fh = fc_frame_header_get(fp); |
| 1274 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1275 | FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n", |
| 1276 | fc_rport_state(rdata)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1277 | |
Joe Eykholt | 1419405 | 2009-07-29 17:04:43 -0700 | [diff] [blame] | 1278 | if (rdata->rp_state == RPORT_ST_DELETE) { |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 1279 | fc_frame_free(fp); |
| 1280 | return; |
| 1281 | } |
| 1282 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1283 | rdata->event = RPORT_EV_LOGO; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame^] | 1284 | fc_rport_state_enter(rdata, RPORT_ST_DELETE); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1285 | queue_work(rport_event_queue, &rdata->event_work); |
| 1286 | |
| 1287 | lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); |
| 1288 | fc_frame_free(fp); |
| 1289 | } |
| 1290 | |
| 1291 | static void fc_rport_flush_queue(void) |
| 1292 | { |
| 1293 | flush_workqueue(rport_event_queue); |
| 1294 | } |
| 1295 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1296 | int fc_rport_init(struct fc_lport *lport) |
| 1297 | { |
Robert Love | 5101ff9 | 2009-02-27 10:55:18 -0800 | [diff] [blame] | 1298 | if (!lport->tt.rport_create) |
| 1299 | lport->tt.rport_create = fc_rport_rogue_create; |
| 1300 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1301 | if (!lport->tt.rport_login) |
| 1302 | lport->tt.rport_login = fc_rport_login; |
| 1303 | |
| 1304 | if (!lport->tt.rport_logoff) |
| 1305 | lport->tt.rport_logoff = fc_rport_logoff; |
| 1306 | |
| 1307 | if (!lport->tt.rport_recv_req) |
| 1308 | lport->tt.rport_recv_req = fc_rport_recv_req; |
| 1309 | |
| 1310 | if (!lport->tt.rport_flush_queue) |
| 1311 | lport->tt.rport_flush_queue = fc_rport_flush_queue; |
| 1312 | |
| 1313 | return 0; |
| 1314 | } |
| 1315 | EXPORT_SYMBOL(fc_rport_init); |
| 1316 | |
Randy Dunlap | b0d428a | 2009-04-27 21:49:31 -0700 | [diff] [blame] | 1317 | int fc_setup_rport(void) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1318 | { |
| 1319 | rport_event_queue = create_singlethread_workqueue("fc_rport_eq"); |
| 1320 | if (!rport_event_queue) |
| 1321 | return -ENOMEM; |
| 1322 | return 0; |
| 1323 | } |
| 1324 | EXPORT_SYMBOL(fc_setup_rport); |
| 1325 | |
Randy Dunlap | b0d428a | 2009-04-27 21:49:31 -0700 | [diff] [blame] | 1326 | void fc_destroy_rport(void) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1327 | { |
| 1328 | destroy_workqueue(rport_event_queue); |
| 1329 | } |
| 1330 | EXPORT_SYMBOL(fc_destroy_rport); |
| 1331 | |
| 1332 | void fc_rport_terminate_io(struct fc_rport *rport) |
| 1333 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 1334 | struct fc_rport_libfc_priv *rp = rport->dd_data; |
| 1335 | struct fc_lport *lport = rp->local_port; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1336 | |
Abhijeet Joglekar | 1f6ff36 | 2009-02-27 10:54:35 -0800 | [diff] [blame] | 1337 | lport->tt.exch_mgr_reset(lport, 0, rport->port_id); |
| 1338 | lport->tt.exch_mgr_reset(lport, rport->port_id, 0); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1339 | } |
| 1340 | EXPORT_SYMBOL(fc_rport_terminate_io); |