blob: 13d3d758fb0e0f1d691ba4a3ef6ed4f55f4c3887 [file] [log] [blame]
Robert Love42e9a922008-12-09 15:10:17 -08001/*
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 Love42e9a922008-12-09 15:10:17 -080058struct workqueue_struct *rport_event_queue;
59
Joe Eykholt9fb9d322009-08-25 14:00:50 -070060static void fc_rport_enter_plogi(struct fc_rport_priv *);
61static void fc_rport_enter_prli(struct fc_rport_priv *);
62static void fc_rport_enter_rtv(struct fc_rport_priv *);
63static void fc_rport_enter_ready(struct fc_rport_priv *);
64static void fc_rport_enter_logo(struct fc_rport_priv *);
Robert Love42e9a922008-12-09 15:10:17 -080065
Joe Eykholt9fb9d322009-08-25 14:00:50 -070066static void fc_rport_recv_plogi_req(struct fc_rport_priv *,
Robert Love42e9a922008-12-09 15:10:17 -080067 struct fc_seq *, struct fc_frame *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070068static void fc_rport_recv_prli_req(struct fc_rport_priv *,
Robert Love42e9a922008-12-09 15:10:17 -080069 struct fc_seq *, struct fc_frame *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070070static void fc_rport_recv_prlo_req(struct fc_rport_priv *,
Robert Love42e9a922008-12-09 15:10:17 -080071 struct fc_seq *, struct fc_frame *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070072static void fc_rport_recv_logo_req(struct fc_rport_priv *,
Robert Love42e9a922008-12-09 15:10:17 -080073 struct fc_seq *, struct fc_frame *);
74static void fc_rport_timeout(struct work_struct *);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070075static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *);
76static void fc_rport_error_retry(struct fc_rport_priv *, struct fc_frame *);
Robert Love42e9a922008-12-09 15:10:17 -080077static void fc_rport_work(struct work_struct *);
78
79static const char *fc_rport_state_names[] = {
Robert Love42e9a922008-12-09 15:10:17 -080080 [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 Eykholt14194052009-07-29 17:04:43 -070086 [RPORT_ST_DELETE] = "Delete",
Robert Love42e9a922008-12-09 15:10:17 -080087};
88
89static void fc_rport_rogue_destroy(struct device *dev)
90{
91 struct fc_rport *rport = dev_to_rport(dev);
Joe Eykholt9fb9d322009-08-25 14:00:50 -070092 struct fc_rport_priv *rdata = RPORT_TO_PRIV(rport);
93
94 FC_RPORT_DBG(rdata, "Destroying rogue rport\n");
Robert Love42e9a922008-12-09 15:10:17 -080095 kfree(rport);
96}
97
Joe Eykholt9fb9d322009-08-25 14:00:50 -070098struct fc_rport_priv *fc_rport_rogue_create(struct fc_lport *lport,
99 struct fc_rport_identifiers *ids)
Robert Love42e9a922008-12-09 15:10:17 -0800100{
101 struct fc_rport *rport;
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700102 struct fc_rport_priv *rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800103 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 Eykholt795d86f2009-08-25 14:00:39 -0700111 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 Love42e9a922008-12-09 15:10:17 -0800115 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 Eykholt795d86f2009-08-25 14:00:39 -0700124 rdata->local_port = lport;
Robert Love42e9a922008-12-09 15:10:17 -0800125 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 Eykholt795d86f2009-08-25 14:00:39 -0700130 rdata->e_d_tov = lport->e_d_tov;
131 rdata->r_a_tov = lport->r_a_tov;
Robert Love42e9a922008-12-09 15:10:17 -0800132 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 Eykholt9fb9d322009-08-25 14:00:50 -0700140 return rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800141}
142
143/**
Robert Love34f42a02009-02-27 10:55:45 -0800144 * fc_rport_state() - return a string for the state the rport is in
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700145 * @rdata: remote port private data
Robert Love42e9a922008-12-09 15:10:17 -0800146 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700147static const char *fc_rport_state(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800148{
149 const char *cp;
Robert Love42e9a922008-12-09 15:10:17 -0800150
151 cp = fc_rport_state_names[rdata->rp_state];
152 if (!cp)
153 cp = "Unknown";
154 return cp;
155}
156
157/**
Robert Love34f42a02009-02-27 10:55:45 -0800158 * fc_set_rport_loss_tmo() - Set the remote port loss timeout in seconds.
Robert Love42e9a922008-12-09 15:10:17 -0800159 * @rport: Pointer to Fibre Channel remote port structure
160 * @timeout: timeout in seconds
161 */
162void 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}
169EXPORT_SYMBOL(fc_set_rport_loss_tmo);
170
171/**
Robert Love34f42a02009-02-27 10:55:45 -0800172 * fc_plogi_get_maxframe() - Get max payload from the common service parameters
Robert Love42e9a922008-12-09 15:10:17 -0800173 * @flp: FLOGI payload structure
174 * @maxval: upper limit, may be less than what is in the service parameters
175 */
Robert Loveb2ab99c2009-02-27 10:55:50 -0800176static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
177 unsigned int maxval)
Robert Love42e9a922008-12-09 15:10:17 -0800178{
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 Love34f42a02009-02-27 10:55:45 -0800195 * fc_rport_state_enter() - Change the rport's state
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700196 * @rdata: The rport whose state should change
Robert Love42e9a922008-12-09 15:10:17 -0800197 * @new: The new state of the rport
198 *
199 * Locking Note: Called with the rport lock held
200 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700201static void fc_rport_state_enter(struct fc_rport_priv *rdata,
Robert Love42e9a922008-12-09 15:10:17 -0800202 enum fc_rport_state new)
203{
Robert Love42e9a922008-12-09 15:10:17 -0800204 if (rdata->rp_state != new)
205 rdata->retries = 0;
206 rdata->rp_state = new;
207}
208
209static void fc_rport_work(struct work_struct *work)
210{
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800211 u32 port_id;
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700212 struct fc_rport_priv *rdata =
213 container_of(work, struct fc_rport_priv, event_work);
Robert Love42e9a922008-12-09 15:10:17 -0800214 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 Eykholtab28f1f2009-08-25 14:00:34 -0700226 struct fc_rport_priv *new_rdata;
Robert Love42e9a922008-12-09 15:10:17 -0800227 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 Eykholt5f7ea3b2009-07-29 17:04:49 -0700234 rdata->event = RPORT_EV_NONE;
Robert Love42e9a922008-12-09 15:10:17 -0800235 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 Eykholt9fb9d322009-08-25 14:00:50 -0700258 fc_rport_state_enter(new_rdata, RPORT_ST_READY);
Robert Love42e9a922008-12-09 15:10:17 -0800259 } else {
Robert Love74147052009-06-10 15:31:10 -0700260 printk(KERN_WARNING "libfc: Failed to allocate "
261 " memory for rport (%6x)\n", ids.port_id);
Robert Love42e9a922008-12-09 15:10:17 -0800262 event = RPORT_EV_FAILED;
263 }
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700264 if (rport->port_id != FC_FID_DIR_SERV)
265 if (rport_ops->event_callback)
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700266 rport_ops->event_callback(lport, rdata,
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700267 RPORT_EV_FAILED);
Robert Love42e9a922008-12-09 15:10:17 -0800268 put_device(&rport->dev);
269 rport = new_rport;
270 rdata = new_rport->dd_data;
271 if (rport_ops->event_callback)
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700272 rport_ops->event_callback(lport, rdata, event);
Robert Love42e9a922008-12-09 15:10:17 -0800273 } 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 Eykholt9fb9d322009-08-25 14:00:50 -0700279 rport_ops->event_callback(lport, rdata, event);
Joe Eykholt201e5792009-07-29 17:04:54 -0700280 cancel_delayed_work_sync(&rdata->retry_work);
Robert Love42e9a922008-12-09 15:10:17 -0800281 if (trans_state == FC_PORTSTATE_ROGUE)
282 put_device(&rport->dev);
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800283 else {
284 port_id = rport->port_id;
Robert Love42e9a922008-12-09 15:10:17 -0800285 fc_remote_port_delete(rport);
Abhijeet Joglekar571f8242009-02-27 10:54:41 -0800286 lport->tt.exch_mgr_reset(lport, 0, port_id);
287 lport->tt.exch_mgr_reset(lport, port_id, 0);
288 }
Robert Love42e9a922008-12-09 15:10:17 -0800289 } else
290 mutex_unlock(&rdata->rp_mutex);
291}
292
293/**
Robert Love34f42a02009-02-27 10:55:45 -0800294 * fc_rport_login() - Start the remote port login state machine
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700295 * @rdata: private remote port
Robert Love42e9a922008-12-09 15:10:17 -0800296 *
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 Eykholt9fb9d322009-08-25 14:00:50 -0700301int fc_rport_login(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800302{
Robert Love42e9a922008-12-09 15:10:17 -0800303 mutex_lock(&rdata->rp_mutex);
304
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700305 FC_RPORT_DBG(rdata, "Login to port\n");
Robert Love42e9a922008-12-09 15:10:17 -0800306
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700307 fc_rport_enter_plogi(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800308
309 mutex_unlock(&rdata->rp_mutex);
310
311 return 0;
312}
313
314/**
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700315 * fc_rport_enter_delete() - schedule a remote port to be deleted.
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700316 * @rdata: private remote port
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700317 * @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 Eykholt9fb9d322009-08-25 14:00:50 -0700328static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700329 enum fc_rport_event event)
330{
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700331 if (rdata->rp_state == RPORT_ST_DELETE)
332 return;
333
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700334 FC_RPORT_DBG(rdata, "Delete port\n");
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700335
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700336 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700337
338 if (rdata->event == RPORT_EV_NONE)
339 queue_work(rport_event_queue, &rdata->event_work);
340 rdata->event = event;
341}
342
343/**
Robert Love34f42a02009-02-27 10:55:45 -0800344 * fc_rport_logoff() - Logoff and remove an rport
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700345 * @rdata: private remote port
Robert Love42e9a922008-12-09 15:10:17 -0800346 *
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 Eykholt9fb9d322009-08-25 14:00:50 -0700351int fc_rport_logoff(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800352{
Robert Love42e9a922008-12-09 15:10:17 -0800353 mutex_lock(&rdata->rp_mutex);
354
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700355 FC_RPORT_DBG(rdata, "Remove port\n");
Robert Love42e9a922008-12-09 15:10:17 -0800356
Joe Eykholt14194052009-07-29 17:04:43 -0700357 if (rdata->rp_state == RPORT_ST_DELETE) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700358 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700359 mutex_unlock(&rdata->rp_mutex);
360 goto out;
361 }
362
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700363 fc_rport_enter_logo(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800364
365 /*
Joe Eykholt14194052009-07-29 17:04:43 -0700366 * Change the state to Delete so that we discard
Robert Love42e9a922008-12-09 15:10:17 -0800367 * the response.
368 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700369 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
Robert Love42e9a922008-12-09 15:10:17 -0800370 mutex_unlock(&rdata->rp_mutex);
371
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -0700372out:
Robert Love42e9a922008-12-09 15:10:17 -0800373 return 0;
374}
375
376/**
Robert Love34f42a02009-02-27 10:55:45 -0800377 * fc_rport_enter_ready() - The rport is ready
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700378 * @rdata: private remote port
Robert Love42e9a922008-12-09 15:10:17 -0800379 *
380 * Locking Note: The rport lock is expected to be held before calling
381 * this routine.
382 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700383static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800384{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700385 fc_rport_state_enter(rdata, RPORT_ST_READY);
Robert Love42e9a922008-12-09 15:10:17 -0800386
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700387 FC_RPORT_DBG(rdata, "Port is Ready\n");
Robert Love42e9a922008-12-09 15:10:17 -0800388
Joe Eykholt5f7ea3b2009-07-29 17:04:49 -0700389 if (rdata->event == RPORT_EV_NONE)
390 queue_work(rport_event_queue, &rdata->event_work);
Robert Love42e9a922008-12-09 15:10:17 -0800391 rdata->event = RPORT_EV_CREATED;
Robert Love42e9a922008-12-09 15:10:17 -0800392}
393
394/**
Robert Love34f42a02009-02-27 10:55:45 -0800395 * fc_rport_timeout() - Handler for the retry_work timer.
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700396 * @work: The work struct of the fc_rport_priv
Robert Love42e9a922008-12-09 15:10:17 -0800397 *
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 */
402static void fc_rport_timeout(struct work_struct *work)
403{
Joe Eykholtab28f1f2009-08-25 14:00:34 -0700404 struct fc_rport_priv *rdata =
405 container_of(work, struct fc_rport_priv, retry_work.work);
Robert Love42e9a922008-12-09 15:10:17 -0800406
407 mutex_lock(&rdata->rp_mutex);
408
409 switch (rdata->rp_state) {
410 case RPORT_ST_PLOGI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700411 fc_rport_enter_plogi(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800412 break;
413 case RPORT_ST_PRLI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700414 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800415 break;
416 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700417 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800418 break;
419 case RPORT_ST_LOGO:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700420 fc_rport_enter_logo(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800421 break;
422 case RPORT_ST_READY:
423 case RPORT_ST_INIT:
Joe Eykholt14194052009-07-29 17:04:43 -0700424 case RPORT_ST_DELETE:
Robert Love42e9a922008-12-09 15:10:17 -0800425 break;
426 }
427
428 mutex_unlock(&rdata->rp_mutex);
Robert Love42e9a922008-12-09 15:10:17 -0800429}
430
431/**
Robert Love34f42a02009-02-27 10:55:45 -0800432 * fc_rport_error() - Error handler, called once retries have been exhausted
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700433 * @rdata: private remote port
Robert Love42e9a922008-12-09 15:10:17 -0800434 * @fp: The frame pointer
435 *
Robert Love42e9a922008-12-09 15:10:17 -0800436 * Locking Note: The rport lock is expected to be held before
437 * calling this routine
438 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700439static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp)
Robert Love42e9a922008-12-09 15:10:17 -0800440{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700441 FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n",
442 PTR_ERR(fp), fc_rport_state(rdata), rdata->retries);
Robert Love42e9a922008-12-09 15:10:17 -0800443
Chris Leech6755db12009-02-27 10:55:02 -0800444 switch (rdata->rp_state) {
445 case RPORT_ST_PLOGI:
446 case RPORT_ST_PRLI:
447 case RPORT_ST_LOGO:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700448 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
Chris Leech6755db12009-02-27 10:55:02 -0800449 break;
450 case RPORT_ST_RTV:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700451 fc_rport_enter_ready(rdata);
Chris Leech6755db12009-02-27 10:55:02 -0800452 break;
Joe Eykholt14194052009-07-29 17:04:43 -0700453 case RPORT_ST_DELETE:
Chris Leech6755db12009-02-27 10:55:02 -0800454 case RPORT_ST_READY:
455 case RPORT_ST_INIT:
456 break;
Robert Love42e9a922008-12-09 15:10:17 -0800457 }
458}
459
460/**
Robert Love34f42a02009-02-27 10:55:45 -0800461 * fc_rport_error_retry() - Error handler when retries are desired
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700462 * @rdata: private remote port data
Chris Leech6755db12009-02-27 10:55:02 -0800463 * @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 Eykholt9fb9d322009-08-25 14:00:50 -0700471static void fc_rport_error_retry(struct fc_rport_priv *rdata,
472 struct fc_frame *fp)
Chris Leech6755db12009-02-27 10:55:02 -0800473{
Chris Leech6755db12009-02-27 10:55:02 -0800474 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 Eykholt9fb9d322009-08-25 14:00:50 -0700478 return fc_rport_error(rdata, fp);
Chris Leech6755db12009-02-27 10:55:02 -0800479
Abhijeet Joglekara3666952009-05-01 10:01:26 -0700480 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700481 FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n",
482 PTR_ERR(fp), fc_rport_state(rdata));
Chris Leech6755db12009-02-27 10:55:02 -0800483 rdata->retries++;
484 /* no additional delay on exchange timeouts */
485 if (PTR_ERR(fp) == -FC_EX_TIMEOUT)
486 delay = 0;
Chris Leech6755db12009-02-27 10:55:02 -0800487 schedule_delayed_work(&rdata->retry_work, delay);
488 return;
489 }
490
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700491 return fc_rport_error(rdata, fp);
Chris Leech6755db12009-02-27 10:55:02 -0800492}
493
494/**
Robert Love34f42a02009-02-27 10:55:45 -0800495 * fc_rport_plogi_recv_resp() - Handle incoming ELS PLOGI response
Robert Love42e9a922008-12-09 15:10:17 -0800496 * @sp: current sequence in the PLOGI exchange
497 * @fp: response frame
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700498 * @rdata_arg: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800499 *
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 */
504static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700505 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800506{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700507 struct fc_rport_priv *rdata = rdata_arg;
508 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800509 struct fc_lport *lport = rdata->local_port;
Robert Lovea29e7642009-04-21 16:27:41 -0700510 struct fc_els_flogi *plp = NULL;
Robert Love42e9a922008-12-09 15:10:17 -0800511 unsigned int tov;
512 u16 csp_seq;
513 u16 cssp_seq;
514 u8 op;
515
516 mutex_lock(&rdata->rp_mutex);
517
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700518 FC_RPORT_DBG(rdata, "Received a PLOGI response\n");
Robert Love42e9a922008-12-09 15:10:17 -0800519
520 if (rdata->rp_state != RPORT_ST_PLOGI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700521 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
522 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700523 if (IS_ERR(fp))
524 goto err;
Robert Love42e9a922008-12-09 15:10:17 -0800525 goto out;
526 }
527
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700528 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700529 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700530 goto err;
531 }
532
Robert Love42e9a922008-12-09 15:10:17 -0800533 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 Eykholt9fb9d322009-08-25 14:00:50 -0700557 fc_rport_enter_ready(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800558 else
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700559 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800560 } else
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700561 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800562
563out:
564 fc_frame_free(fp);
565err:
566 mutex_unlock(&rdata->rp_mutex);
567 put_device(&rport->dev);
568}
569
570/**
Robert Love34f42a02009-02-27 10:55:45 -0800571 * fc_rport_enter_plogi() - Send Port Login (PLOGI) request to peer
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700572 * @rdata: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800573 *
574 * Locking Note: The rport lock is expected to be held before calling
575 * this routine.
576 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700577static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800578{
Robert Love42e9a922008-12-09 15:10:17 -0800579 struct fc_lport *lport = rdata->local_port;
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700580 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800581 struct fc_frame *fp;
582
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700583 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
584 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800585
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700586 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
Robert Love42e9a922008-12-09 15:10:17 -0800587
588 rport->maxframe_size = FC_MIN_MAX_PAYLOAD;
589 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
590 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700591 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800592 return;
593 }
594 rdata->e_d_tov = lport->e_d_tov;
595
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700596 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 Love42e9a922008-12-09 15:10:17 -0800599 else
600 get_device(&rport->dev);
601}
602
603/**
Robert Love34f42a02009-02-27 10:55:45 -0800604 * fc_rport_prli_resp() - Process Login (PRLI) response handler
Robert Love42e9a922008-12-09 15:10:17 -0800605 * @sp: current sequence in the PRLI exchange
606 * @fp: response frame
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700607 * @rdata_arg: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800608 *
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 */
613static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700614 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800615{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700616 struct fc_rport_priv *rdata = rdata_arg;
617 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800618 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 Eykholt9fb9d322009-08-25 14:00:50 -0700628 FC_RPORT_DBG(rdata, "Received a PRLI response\n");
Robert Love42e9a922008-12-09 15:10:17 -0800629
630 if (rdata->rp_state != RPORT_ST_PRLI) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700631 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
632 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700633 if (IS_ERR(fp))
634 goto err;
Robert Love42e9a922008-12-09 15:10:17 -0800635 goto out;
636 }
637
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700638 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700639 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700640 goto err;
641 }
642
Robert Love42e9a922008-12-09 15:10:17 -0800643 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 Eykholt9fb9d322009-08-25 14:00:50 -0700659 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800660
661 } else {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700662 FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n");
663 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
Robert Love42e9a922008-12-09 15:10:17 -0800664 }
665
666out:
667 fc_frame_free(fp);
668err:
669 mutex_unlock(&rdata->rp_mutex);
670 put_device(&rport->dev);
671}
672
673/**
Robert Love34f42a02009-02-27 10:55:45 -0800674 * fc_rport_logo_resp() - Logout (LOGO) response handler
Robert Love42e9a922008-12-09 15:10:17 -0800675 * @sp: current sequence in the LOGO exchange
676 * @fp: response frame
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700677 * @rdata_arg: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800678 *
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 */
683static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700684 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800685{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700686 struct fc_rport_priv *rdata = rdata_arg;
687 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800688 u8 op;
689
690 mutex_lock(&rdata->rp_mutex);
691
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700692 FC_RPORT_DBG(rdata, "Received a LOGO response\n");
Robert Love42e9a922008-12-09 15:10:17 -0800693
Robert Love42e9a922008-12-09 15:10:17 -0800694 if (rdata->rp_state != RPORT_ST_LOGO) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700695 FC_RPORT_DBG(rdata, "Received a LOGO response, but in state "
696 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700697 if (IS_ERR(fp))
698 goto err;
Robert Love42e9a922008-12-09 15:10:17 -0800699 goto out;
700 }
701
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700702 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700703 fc_rport_error_retry(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700704 goto err;
705 }
706
Robert Love42e9a922008-12-09 15:10:17 -0800707 op = fc_frame_payload_op(fp);
708 if (op == ELS_LS_ACC) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700709 fc_rport_enter_rtv(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800710 } else {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700711 FC_RPORT_DBG(rdata, "Bad ELS response for LOGO command\n");
712 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
Robert Love42e9a922008-12-09 15:10:17 -0800713 }
714
715out:
716 fc_frame_free(fp);
717err:
718 mutex_unlock(&rdata->rp_mutex);
719 put_device(&rport->dev);
720}
721
722/**
Robert Love34f42a02009-02-27 10:55:45 -0800723 * fc_rport_enter_prli() - Send Process Login (PRLI) request to peer
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700724 * @rdata: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800725 *
726 * Locking Note: The rport lock is expected to be held before calling
727 * this routine.
728 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700729static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800730{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700731 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800732 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 Eykholt9fb9d322009-08-25 14:00:50 -0700739 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
740 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800741
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700742 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
Robert Love42e9a922008-12-09 15:10:17 -0800743
744 fp = fc_frame_alloc(lport, sizeof(*pp));
745 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700746 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800747 return;
748 }
749
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700750 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 Love42e9a922008-12-09 15:10:17 -0800753 else
754 get_device(&rport->dev);
755}
756
757/**
Robert Love34f42a02009-02-27 10:55:45 -0800758 * fc_rport_els_rtv_resp() - Request Timeout Value response handler
Robert Love42e9a922008-12-09 15:10:17 -0800759 * @sp: current sequence in the RTV exchange
760 * @fp: response frame
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700761 * @rdata_arg: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800762 *
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 */
769static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700770 void *rdata_arg)
Robert Love42e9a922008-12-09 15:10:17 -0800771{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700772 struct fc_rport_priv *rdata = rdata_arg;
773 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800774 u8 op;
775
776 mutex_lock(&rdata->rp_mutex);
777
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700778 FC_RPORT_DBG(rdata, "Received a RTV response\n");
Robert Love42e9a922008-12-09 15:10:17 -0800779
780 if (rdata->rp_state != RPORT_ST_RTV) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700781 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
782 "%s\n", fc_rport_state(rdata));
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700783 if (IS_ERR(fp))
784 goto err;
Robert Love42e9a922008-12-09 15:10:17 -0800785 goto out;
786 }
787
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700788 if (IS_ERR(fp)) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700789 fc_rport_error(rdata, fp);
Abhijeet Joglekar76f68042009-04-21 16:26:58 -0700790 goto err;
791 }
792
Robert Love42e9a922008-12-09 15:10:17 -0800793 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 Eykholt9fb9d322009-08-25 14:00:50 -0700815 fc_rport_enter_ready(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800816
817out:
818 fc_frame_free(fp);
819err:
820 mutex_unlock(&rdata->rp_mutex);
821 put_device(&rport->dev);
822}
823
824/**
Robert Love34f42a02009-02-27 10:55:45 -0800825 * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request to peer
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700826 * @rdata: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800827 *
828 * Locking Note: The rport lock is expected to be held before calling
829 * this routine.
830 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700831static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800832{
833 struct fc_frame *fp;
Robert Love42e9a922008-12-09 15:10:17 -0800834 struct fc_lport *lport = rdata->local_port;
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700835 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800836
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700837 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
838 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800839
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700840 fc_rport_state_enter(rdata, RPORT_ST_RTV);
Robert Love42e9a922008-12-09 15:10:17 -0800841
842 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
843 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700844 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800845 return;
846 }
847
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700848 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 Love42e9a922008-12-09 15:10:17 -0800851 else
852 get_device(&rport->dev);
853}
854
855/**
Robert Love34f42a02009-02-27 10:55:45 -0800856 * fc_rport_enter_logo() - Send Logout (LOGO) request to peer
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700857 * @rdata: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800858 *
859 * Locking Note: The rport lock is expected to be held before calling
860 * this routine.
861 */
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700862static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800863{
Robert Love42e9a922008-12-09 15:10:17 -0800864 struct fc_lport *lport = rdata->local_port;
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700865 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800866 struct fc_frame *fp;
867
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700868 FC_RPORT_DBG(rdata, "Port entered LOGO state from %s state\n",
869 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800870
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700871 fc_rport_state_enter(rdata, RPORT_ST_LOGO);
Robert Love42e9a922008-12-09 15:10:17 -0800872
873 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
874 if (!fp) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700875 fc_rport_error_retry(rdata, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800876 return;
877 }
878
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700879 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 Love42e9a922008-12-09 15:10:17 -0800882 else
883 get_device(&rport->dev);
884}
885
886
887/**
Robert Love34f42a02009-02-27 10:55:45 -0800888 * fc_rport_recv_req() - Receive a request from a rport
Robert Love42e9a922008-12-09 15:10:17 -0800889 * @sp: current sequence in the PLOGI exchange
890 * @fp: response frame
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700891 * @rdata_arg: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800892 *
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 */
897void fc_rport_recv_req(struct fc_seq *sp, struct fc_frame *fp,
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700898 struct fc_rport_priv *rdata)
Robert Love42e9a922008-12-09 15:10:17 -0800899{
Robert Love42e9a922008-12-09 15:10:17 -0800900 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 Eykholt9fb9d322009-08-25 14:00:50 -0700918 fc_rport_recv_plogi_req(rdata, sp, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800919 break;
920 case ELS_PRLI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700921 fc_rport_recv_prli_req(rdata, sp, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800922 break;
923 case ELS_PRLO:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700924 fc_rport_recv_prlo_req(rdata, sp, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800925 break;
926 case ELS_LOGO:
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700927 fc_rport_recv_logo_req(rdata, sp, fp);
Robert Love42e9a922008-12-09 15:10:17 -0800928 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 Love34f42a02009-02-27 10:55:45 -0800948 * fc_rport_recv_plogi_req() - Handle incoming Port Login (PLOGI) request
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700949 * @rdata: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -0800950 * @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 Eykholt9fb9d322009-08-25 14:00:50 -0700956static void fc_rport_recv_plogi_req(struct fc_rport_priv *rdata,
Robert Love42e9a922008-12-09 15:10:17 -0800957 struct fc_seq *sp, struct fc_frame *rx_fp)
958{
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700959 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -0800960 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 Eykholt9fb9d322009-08-25 14:00:50 -0700975 FC_RPORT_DBG(rdata, "Received PLOGI request while in state %s\n",
976 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -0800977
978 sid = ntoh24(fh->fh_s_id);
979 pl = fc_frame_payload_get(fp, sizeof(*pl));
980 if (!pl) {
Joe Eykholt9fb9d322009-08-25 14:00:50 -0700981 FC_RPORT_DBG(rdata, "Received PLOGI too short\n");
Robert Love42e9a922008-12-09 15:10:17 -0800982 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 Eykholt9fb9d322009-08-25 14:00:50 -07001003 FC_RPORT_DBG(rdata, "Received PLOGI, wwpn %llx state INIT "
Robert Love74147052009-06-10 15:31:10 -07001004 "- reject\n", (unsigned long long)wwpn);
Robert Love42e9a922008-12-09 15:10:17 -08001005 reject = ELS_RJT_UNSUP;
1006 break;
1007 case RPORT_ST_PLOGI:
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001008 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state %d\n",
Robert Love74147052009-06-10 15:31:10 -07001009 rdata->rp_state);
Robert Love42e9a922008-12-09 15:10:17 -08001010 if (wwpn < lport->wwpn)
1011 reject = ELS_RJT_INPROG;
1012 break;
1013 case RPORT_ST_PRLI:
1014 case RPORT_ST_READY:
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001015 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
Robert Love74147052009-06-10 15:31:10 -07001016 "- ignored for now\n", rdata->rp_state);
Robert Love42e9a922008-12-09 15:10:17 -08001017 /* XXX TBD - should reset */
1018 break;
Joe Eykholt14194052009-07-29 17:04:43 -07001019 case RPORT_ST_DELETE:
Robert Love42e9a922008-12-09 15:10:17 -08001020 default:
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001021 FC_RPORT_DBG(rdata, "Received PLOGI in unexpected "
Robert Love74147052009-06-10 15:31:10 -07001022 "state %d\n", rdata->rp_state);
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -07001023 fc_frame_free(fp);
1024 return;
Robert Love42e9a922008-12-09 15:10:17 -08001025 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 Eykholt9fb9d322009-08-25 14:00:50 -07001065 fc_rport_enter_prli(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001066 }
1067 }
1068}
1069
1070/**
Robert Love34f42a02009-02-27 10:55:45 -08001071 * fc_rport_recv_prli_req() - Handle incoming Process Login (PRLI) request
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001072 * @rdata: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -08001073 * @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 Eykholt9fb9d322009-08-25 14:00:50 -07001079static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
Robert Love42e9a922008-12-09 15:10:17 -08001080 struct fc_seq *sp, struct fc_frame *rx_fp)
1081{
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001082 struct fc_rport *rport = PRIV_TO_RPORT(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001083 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 Eykholt9fb9d322009-08-25 14:00:50 -07001106 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1107 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001108
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 Joglekarb4c6f542009-04-21 16:27:04 -07001115 fc_frame_free(rx_fp);
1116 return;
Robert Love42e9a922008-12-09 15:10:17 -08001117 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 Eykholt9fb9d322009-08-25 14:00:50 -07001211 fc_rport_enter_ready(rdata);
Robert Love42e9a922008-12-09 15:10:17 -08001212 break;
1213 case RPORT_ST_READY:
1214 break;
1215 default:
1216 break;
1217 }
1218 }
1219 fc_frame_free(rx_fp);
1220}
1221
1222/**
Robert Love34f42a02009-02-27 10:55:45 -08001223 * fc_rport_recv_prlo_req() - Handle incoming Process Logout (PRLO) request
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001224 * @rdata: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -08001225 * @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 Eykholt9fb9d322009-08-25 14:00:50 -07001231static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
1232 struct fc_seq *sp,
Robert Love42e9a922008-12-09 15:10:17 -08001233 struct fc_frame *fp)
1234{
Robert Love42e9a922008-12-09 15:10:17 -08001235 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 Eykholt9fb9d322009-08-25 14:00:50 -07001242 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
1243 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001244
Joe Eykholt14194052009-07-29 17:04:43 -07001245 if (rdata->rp_state == RPORT_ST_DELETE) {
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -07001246 fc_frame_free(fp);
1247 return;
1248 }
1249
Robert Love42e9a922008-12-09 15:10:17 -08001250 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 Love34f42a02009-02-27 10:55:45 -08001258 * fc_rport_recv_logo_req() - Handle incoming Logout (LOGO) request
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001259 * @rdata: private remote port data
Robert Love42e9a922008-12-09 15:10:17 -08001260 * @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 Eykholt9fb9d322009-08-25 14:00:50 -07001266static void fc_rport_recv_logo_req(struct fc_rport_priv *rdata,
1267 struct fc_seq *sp,
Robert Love42e9a922008-12-09 15:10:17 -08001268 struct fc_frame *fp)
1269{
1270 struct fc_frame_header *fh;
Robert Love42e9a922008-12-09 15:10:17 -08001271 struct fc_lport *lport = rdata->local_port;
1272
1273 fh = fc_frame_header_get(fp);
1274
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001275 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
1276 fc_rport_state(rdata));
Robert Love42e9a922008-12-09 15:10:17 -08001277
Joe Eykholt14194052009-07-29 17:04:43 -07001278 if (rdata->rp_state == RPORT_ST_DELETE) {
Abhijeet Joglekarb4c6f542009-04-21 16:27:04 -07001279 fc_frame_free(fp);
1280 return;
1281 }
1282
Robert Love42e9a922008-12-09 15:10:17 -08001283 rdata->event = RPORT_EV_LOGO;
Joe Eykholt9fb9d322009-08-25 14:00:50 -07001284 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
Robert Love42e9a922008-12-09 15:10:17 -08001285 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
1291static void fc_rport_flush_queue(void)
1292{
1293 flush_workqueue(rport_event_queue);
1294}
1295
Robert Love42e9a922008-12-09 15:10:17 -08001296int fc_rport_init(struct fc_lport *lport)
1297{
Robert Love5101ff92009-02-27 10:55:18 -08001298 if (!lport->tt.rport_create)
1299 lport->tt.rport_create = fc_rport_rogue_create;
1300
Robert Love42e9a922008-12-09 15:10:17 -08001301 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}
1315EXPORT_SYMBOL(fc_rport_init);
1316
Randy Dunlapb0d428a2009-04-27 21:49:31 -07001317int fc_setup_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08001318{
1319 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
1320 if (!rport_event_queue)
1321 return -ENOMEM;
1322 return 0;
1323}
1324EXPORT_SYMBOL(fc_setup_rport);
1325
Randy Dunlapb0d428a2009-04-27 21:49:31 -07001326void fc_destroy_rport(void)
Robert Love42e9a922008-12-09 15:10:17 -08001327{
1328 destroy_workqueue(rport_event_queue);
1329}
1330EXPORT_SYMBOL(fc_destroy_rport);
1331
1332void fc_rport_terminate_io(struct fc_rport *rport)
1333{
Joe Eykholtab28f1f2009-08-25 14:00:34 -07001334 struct fc_rport_libfc_priv *rp = rport->dd_data;
1335 struct fc_lport *lport = rp->local_port;
Robert Love42e9a922008-12-09 15:10:17 -08001336
Abhijeet Joglekar1f6ff362009-02-27 10:54:35 -08001337 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
1338 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
Robert Love42e9a922008-12-09 15:10:17 -08001339}
1340EXPORT_SYMBOL(fc_rport_terminate_io);