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