1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48#include <linux/kernel.h>
49#include <linux/spinlock.h>
50#include <linux/interrupt.h>
51#include <linux/slab.h>
52#include <linux/rcupdate.h>
53#include <linux/timer.h>
54#include <linux/workqueue.h>
55#include <linux/export.h>
56#include <linux/rculist.h>
57
58#include <asm/unaligned.h>
59
60#include <scsi/libfc.h>
61#include <scsi/fc_encode.h>
62
63#include "fc_libfc.h"
64
65static struct workqueue_struct *rport_event_queue;
66
67static void fc_rport_enter_flogi(struct fc_rport_priv *);
68static void fc_rport_enter_plogi(struct fc_rport_priv *);
69static void fc_rport_enter_prli(struct fc_rport_priv *);
70static void fc_rport_enter_rtv(struct fc_rport_priv *);
71static void fc_rport_enter_ready(struct fc_rport_priv *);
72static void fc_rport_enter_logo(struct fc_rport_priv *);
73static void fc_rport_enter_adisc(struct fc_rport_priv *);
74
75static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
76static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
77static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
78static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
79static void fc_rport_timeout(struct work_struct *);
80static void fc_rport_error(struct fc_rport_priv *, int);
81static void fc_rport_error_retry(struct fc_rport_priv *, int);
82static void fc_rport_work(struct work_struct *);
83
84static const char *fc_rport_state_names[] = {
85 [RPORT_ST_INIT] = "Init",
86 [RPORT_ST_FLOGI] = "FLOGI",
87 [RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
88 [RPORT_ST_PLOGI] = "PLOGI",
89 [RPORT_ST_PRLI] = "PRLI",
90 [RPORT_ST_RTV] = "RTV",
91 [RPORT_ST_READY] = "Ready",
92 [RPORT_ST_ADISC] = "ADISC",
93 [RPORT_ST_DELETE] = "Delete",
94};
95
96
97
98
99
100
101
102
103
104struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
105 u32 port_id)
106{
107 struct fc_rport_priv *rdata = NULL, *tmp_rdata;
108
109 rcu_read_lock();
110 list_for_each_entry_rcu(tmp_rdata, &lport->disc.rports, peers)
111 if (tmp_rdata->ids.port_id == port_id &&
112 kref_get_unless_zero(&tmp_rdata->kref)) {
113 rdata = tmp_rdata;
114 break;
115 }
116 rcu_read_unlock();
117 return rdata;
118}
119EXPORT_SYMBOL(fc_rport_lookup);
120
121
122
123
124
125
126
127
128struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id)
129{
130 struct fc_rport_priv *rdata;
131 size_t rport_priv_size = sizeof(*rdata);
132
133 lockdep_assert_held(&lport->disc.disc_mutex);
134
135 rdata = fc_rport_lookup(lport, port_id);
136 if (rdata) {
137 kref_put(&rdata->kref, fc_rport_destroy);
138 return rdata;
139 }
140
141 if (lport->rport_priv_size > 0)
142 rport_priv_size = lport->rport_priv_size;
143 rdata = kzalloc(rport_priv_size, GFP_KERNEL);
144 if (!rdata)
145 return NULL;
146
147 rdata->ids.node_name = -1;
148 rdata->ids.port_name = -1;
149 rdata->ids.port_id = port_id;
150 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
151
152 kref_init(&rdata->kref);
153 mutex_init(&rdata->rp_mutex);
154 rdata->local_port = lport;
155 rdata->rp_state = RPORT_ST_INIT;
156 rdata->event = RPORT_EV_NONE;
157 rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
158 rdata->e_d_tov = lport->e_d_tov;
159 rdata->r_a_tov = lport->r_a_tov;
160 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
161 INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
162 INIT_WORK(&rdata->event_work, fc_rport_work);
163 if (port_id != FC_FID_DIR_SERV) {
164 rdata->lld_event_callback = lport->tt.rport_event_callback;
165 list_add_rcu(&rdata->peers, &lport->disc.rports);
166 }
167 return rdata;
168}
169EXPORT_SYMBOL(fc_rport_create);
170
171
172
173
174
175void fc_rport_destroy(struct kref *kref)
176{
177 struct fc_rport_priv *rdata;
178
179 rdata = container_of(kref, struct fc_rport_priv, kref);
180 kfree_rcu(rdata, rcu);
181}
182EXPORT_SYMBOL(fc_rport_destroy);
183
184
185
186
187
188static const char *fc_rport_state(struct fc_rport_priv *rdata)
189{
190 const char *cp;
191
192 cp = fc_rport_state_names[rdata->rp_state];
193 if (!cp)
194 cp = "Unknown";
195 return cp;
196}
197
198
199
200
201
202
203void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
204{
205 if (timeout)
206 rport->dev_loss_tmo = timeout;
207 else
208 rport->dev_loss_tmo = 1;
209}
210EXPORT_SYMBOL(fc_set_rport_loss_tmo);
211
212
213
214
215
216
217
218
219static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
220 unsigned int maxval)
221{
222 unsigned int mfs;
223
224
225
226
227
228 mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
229 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
230 maxval = mfs;
231 mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
232 if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
233 maxval = mfs;
234 return maxval;
235}
236
237
238
239
240
241
242static void fc_rport_state_enter(struct fc_rport_priv *rdata,
243 enum fc_rport_state new)
244{
245 lockdep_assert_held(&rdata->rp_mutex);
246
247 if (rdata->rp_state != new)
248 rdata->retries = 0;
249 rdata->rp_state = new;
250}
251
252
253
254
255
256
257
258static void fc_rport_work(struct work_struct *work)
259{
260 u32 port_id;
261 struct fc_rport_priv *rdata =
262 container_of(work, struct fc_rport_priv, event_work);
263 struct fc_rport_libfc_priv *rpriv;
264 enum fc_rport_event event;
265 struct fc_lport *lport = rdata->local_port;
266 struct fc_rport_operations *rport_ops;
267 struct fc_rport_identifiers ids;
268 struct fc_rport *rport;
269 struct fc4_prov *prov;
270 u8 type;
271
272 mutex_lock(&rdata->rp_mutex);
273 event = rdata->event;
274 rport_ops = rdata->ops;
275 rport = rdata->rport;
276
277 FC_RPORT_DBG(rdata, "work event %u\n", event);
278
279 switch (event) {
280 case RPORT_EV_READY:
281 ids = rdata->ids;
282 rdata->event = RPORT_EV_NONE;
283 rdata->major_retries = 0;
284 kref_get(&rdata->kref);
285 mutex_unlock(&rdata->rp_mutex);
286
287 if (!rport) {
288 FC_RPORT_DBG(rdata, "No rport!\n");
289 rport = fc_remote_port_add(lport->host, 0, &ids);
290 }
291 if (!rport) {
292 FC_RPORT_DBG(rdata, "Failed to add the rport\n");
293 fc_rport_logoff(rdata);
294 kref_put(&rdata->kref, fc_rport_destroy);
295 return;
296 }
297 mutex_lock(&rdata->rp_mutex);
298 if (rdata->rport)
299 FC_RPORT_DBG(rdata, "rport already allocated\n");
300 rdata->rport = rport;
301 rport->maxframe_size = rdata->maxframe_size;
302 rport->supported_classes = rdata->supported_classes;
303
304 rpriv = rport->dd_data;
305 rpriv->local_port = lport;
306 rpriv->rp_state = rdata->rp_state;
307 rpriv->flags = rdata->flags;
308 rpriv->e_d_tov = rdata->e_d_tov;
309 rpriv->r_a_tov = rdata->r_a_tov;
310 mutex_unlock(&rdata->rp_mutex);
311
312 if (rport_ops && rport_ops->event_callback) {
313 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
314 rport_ops->event_callback(lport, rdata, event);
315 }
316 if (rdata->lld_event_callback) {
317 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
318 rdata->lld_event_callback(lport, rdata, event);
319 }
320 kref_put(&rdata->kref, fc_rport_destroy);
321 break;
322
323 case RPORT_EV_FAILED:
324 case RPORT_EV_LOGO:
325 case RPORT_EV_STOP:
326 if (rdata->prli_count) {
327 mutex_lock(&fc_prov_mutex);
328 for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
329 prov = fc_passive_prov[type];
330 if (prov && prov->prlo)
331 prov->prlo(rdata);
332 }
333 mutex_unlock(&fc_prov_mutex);
334 }
335 port_id = rdata->ids.port_id;
336 mutex_unlock(&rdata->rp_mutex);
337
338 if (rport_ops && rport_ops->event_callback) {
339 FC_RPORT_DBG(rdata, "callback ev %d\n", event);
340 rport_ops->event_callback(lport, rdata, event);
341 }
342 if (rdata->lld_event_callback) {
343 FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
344 rdata->lld_event_callback(lport, rdata, event);
345 }
346 if (cancel_delayed_work_sync(&rdata->retry_work))
347 kref_put(&rdata->kref, fc_rport_destroy);
348
349
350
351
352 lport->tt.exch_mgr_reset(lport, 0, port_id);
353 lport->tt.exch_mgr_reset(lport, port_id, 0);
354
355 if (rport) {
356 rpriv = rport->dd_data;
357 rpriv->rp_state = RPORT_ST_DELETE;
358 mutex_lock(&rdata->rp_mutex);
359 rdata->rport = NULL;
360 mutex_unlock(&rdata->rp_mutex);
361 fc_remote_port_delete(rport);
362 }
363
364 mutex_lock(&rdata->rp_mutex);
365 if (rdata->rp_state == RPORT_ST_DELETE) {
366 if (port_id == FC_FID_DIR_SERV) {
367 rdata->event = RPORT_EV_NONE;
368 mutex_unlock(&rdata->rp_mutex);
369 kref_put(&rdata->kref, fc_rport_destroy);
370 } else if ((rdata->flags & FC_RP_STARTED) &&
371 rdata->major_retries <
372 lport->max_rport_retry_count) {
373 rdata->major_retries++;
374 rdata->event = RPORT_EV_NONE;
375 FC_RPORT_DBG(rdata, "work restart\n");
376 fc_rport_enter_flogi(rdata);
377 mutex_unlock(&rdata->rp_mutex);
378 } else {
379 mutex_unlock(&rdata->rp_mutex);
380 FC_RPORT_DBG(rdata, "work delete\n");
381 mutex_lock(&lport->disc.disc_mutex);
382 list_del_rcu(&rdata->peers);
383 mutex_unlock(&lport->disc.disc_mutex);
384 kref_put(&rdata->kref, fc_rport_destroy);
385 }
386 } else {
387
388
389
390 rdata->event = RPORT_EV_NONE;
391 if (rdata->rp_state == RPORT_ST_READY) {
392 FC_RPORT_DBG(rdata, "work reopen\n");
393 fc_rport_enter_ready(rdata);
394 }
395 mutex_unlock(&rdata->rp_mutex);
396 }
397 break;
398
399 default:
400 mutex_unlock(&rdata->rp_mutex);
401 break;
402 }
403 kref_put(&rdata->kref, fc_rport_destroy);
404}
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426int fc_rport_login(struct fc_rport_priv *rdata)
427{
428 mutex_lock(&rdata->rp_mutex);
429
430 if (rdata->flags & FC_RP_STARTED) {
431 FC_RPORT_DBG(rdata, "port already started\n");
432 mutex_unlock(&rdata->rp_mutex);
433 return 0;
434 }
435
436 rdata->flags |= FC_RP_STARTED;
437 switch (rdata->rp_state) {
438 case RPORT_ST_READY:
439 FC_RPORT_DBG(rdata, "ADISC port\n");
440 fc_rport_enter_adisc(rdata);
441 break;
442 case RPORT_ST_DELETE:
443 FC_RPORT_DBG(rdata, "Restart deleted port\n");
444 break;
445 case RPORT_ST_INIT:
446 FC_RPORT_DBG(rdata, "Login to port\n");
447 fc_rport_enter_flogi(rdata);
448 break;
449 default:
450 FC_RPORT_DBG(rdata, "Login in progress, state %s\n",
451 fc_rport_state(rdata));
452 break;
453 }
454 mutex_unlock(&rdata->rp_mutex);
455
456 return 0;
457}
458EXPORT_SYMBOL(fc_rport_login);
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
475 enum fc_rport_event event)
476{
477 lockdep_assert_held(&rdata->rp_mutex);
478
479 if (rdata->rp_state == RPORT_ST_DELETE)
480 return;
481
482 FC_RPORT_DBG(rdata, "Delete port\n");
483
484 fc_rport_state_enter(rdata, RPORT_ST_DELETE);
485
486 if (rdata->event == RPORT_EV_NONE) {
487 kref_get(&rdata->kref);
488 if (!queue_work(rport_event_queue, &rdata->event_work))
489 kref_put(&rdata->kref, fc_rport_destroy);
490 }
491
492 rdata->event = event;
493}
494
495
496
497
498
499
500
501
502
503int fc_rport_logoff(struct fc_rport_priv *rdata)
504{
505 struct fc_lport *lport = rdata->local_port;
506 u32 port_id = rdata->ids.port_id;
507
508 mutex_lock(&rdata->rp_mutex);
509
510 FC_RPORT_DBG(rdata, "Remove port\n");
511
512 rdata->flags &= ~FC_RP_STARTED;
513 if (rdata->rp_state == RPORT_ST_DELETE) {
514 FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
515 goto out;
516 }
517
518
519
520
521
522
523 lport->tt.exch_mgr_reset(lport, 0, port_id);
524 lport->tt.exch_mgr_reset(lport, port_id, 0);
525
526 fc_rport_enter_logo(rdata);
527
528
529
530
531
532 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
533out:
534 mutex_unlock(&rdata->rp_mutex);
535 return 0;
536}
537EXPORT_SYMBOL(fc_rport_logoff);
538
539
540
541
542
543
544
545static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
546{
547 lockdep_assert_held(&rdata->rp_mutex);
548
549 fc_rport_state_enter(rdata, RPORT_ST_READY);
550
551 FC_RPORT_DBG(rdata, "Port is Ready\n");
552
553 kref_get(&rdata->kref);
554 if (rdata->event == RPORT_EV_NONE &&
555 !queue_work(rport_event_queue, &rdata->event_work))
556 kref_put(&rdata->kref, fc_rport_destroy);
557
558 rdata->event = RPORT_EV_READY;
559}
560
561
562
563
564
565
566
567
568
569
570
571static void fc_rport_timeout(struct work_struct *work)
572{
573 struct fc_rport_priv *rdata =
574 container_of(work, struct fc_rport_priv, retry_work.work);
575
576 mutex_lock(&rdata->rp_mutex);
577 FC_RPORT_DBG(rdata, "Port timeout, state %s\n", fc_rport_state(rdata));
578
579 switch (rdata->rp_state) {
580 case RPORT_ST_FLOGI:
581 fc_rport_enter_flogi(rdata);
582 break;
583 case RPORT_ST_PLOGI:
584 fc_rport_enter_plogi(rdata);
585 break;
586 case RPORT_ST_PRLI:
587 fc_rport_enter_prli(rdata);
588 break;
589 case RPORT_ST_RTV:
590 fc_rport_enter_rtv(rdata);
591 break;
592 case RPORT_ST_ADISC:
593 fc_rport_enter_adisc(rdata);
594 break;
595 case RPORT_ST_PLOGI_WAIT:
596 case RPORT_ST_READY:
597 case RPORT_ST_INIT:
598 case RPORT_ST_DELETE:
599 break;
600 }
601
602 mutex_unlock(&rdata->rp_mutex);
603 kref_put(&rdata->kref, fc_rport_destroy);
604}
605
606
607
608
609
610
611
612
613static void fc_rport_error(struct fc_rport_priv *rdata, int err)
614{
615 struct fc_lport *lport = rdata->local_port;
616
617 lockdep_assert_held(&rdata->rp_mutex);
618
619 FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
620 -err, fc_rport_state(rdata), rdata->retries);
621
622 switch (rdata->rp_state) {
623 case RPORT_ST_FLOGI:
624 rdata->flags &= ~FC_RP_STARTED;
625 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
626 break;
627 case RPORT_ST_PLOGI:
628 if (lport->point_to_multipoint) {
629 rdata->flags &= ~FC_RP_STARTED;
630 fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
631 } else
632 fc_rport_enter_logo(rdata);
633 break;
634 case RPORT_ST_RTV:
635 fc_rport_enter_ready(rdata);
636 break;
637 case RPORT_ST_PRLI:
638 fc_rport_enter_plogi(rdata);
639 break;
640 case RPORT_ST_ADISC:
641 fc_rport_enter_logo(rdata);
642 break;
643 case RPORT_ST_PLOGI_WAIT:
644 case RPORT_ST_DELETE:
645 case RPORT_ST_READY:
646 case RPORT_ST_INIT:
647 break;
648 }
649}
650
651
652
653
654
655
656
657
658
659
660
661static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
662{
663 unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
664
665 lockdep_assert_held(&rdata->rp_mutex);
666
667
668 if (err == -FC_EX_CLOSED)
669 goto out;
670
671 if (rdata->retries < rdata->local_port->max_rport_retry_count) {
672 FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
673 err, fc_rport_state(rdata));
674 rdata->retries++;
675
676 if (err == -FC_EX_TIMEOUT)
677 delay = 0;
678 kref_get(&rdata->kref);
679 if (!schedule_delayed_work(&rdata->retry_work, delay))
680 kref_put(&rdata->kref, fc_rport_destroy);
681 return;
682 }
683
684out:
685 fc_rport_error(rdata, err);
686}
687
688
689
690
691
692
693
694
695
696
697
698static int fc_rport_login_complete(struct fc_rport_priv *rdata,
699 struct fc_frame *fp)
700{
701 struct fc_lport *lport = rdata->local_port;
702 struct fc_els_flogi *flogi;
703 unsigned int e_d_tov;
704 u16 csp_flags;
705
706 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
707 if (!flogi)
708 return -EINVAL;
709
710 csp_flags = ntohs(flogi->fl_csp.sp_features);
711
712 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
713 if (csp_flags & FC_SP_FT_FPORT) {
714 FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
715 return -EINVAL;
716 }
717 } else {
718
719
720
721
722 e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
723 if (csp_flags & FC_SP_FT_EDTR)
724 e_d_tov /= 1000000;
725 if (e_d_tov > rdata->e_d_tov)
726 rdata->e_d_tov = e_d_tov;
727 }
728 rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
729 return 0;
730}
731
732
733
734
735
736
737
738static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
739 void *rp_arg)
740{
741 struct fc_rport_priv *rdata = rp_arg;
742 struct fc_lport *lport = rdata->local_port;
743 struct fc_els_flogi *flogi;
744 unsigned int r_a_tov;
745 u8 opcode;
746 int err = 0;
747
748 FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
749 IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
750
751 if (fp == ERR_PTR(-FC_EX_CLOSED))
752 goto put;
753
754 mutex_lock(&rdata->rp_mutex);
755
756 if (rdata->rp_state != RPORT_ST_FLOGI) {
757 FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
758 "%s\n", fc_rport_state(rdata));
759 if (IS_ERR(fp))
760 goto err;
761 goto out;
762 }
763
764 if (IS_ERR(fp)) {
765 fc_rport_error(rdata, PTR_ERR(fp));
766 goto err;
767 }
768 opcode = fc_frame_payload_op(fp);
769 if (opcode == ELS_LS_RJT) {
770 struct fc_els_ls_rjt *rjt;
771
772 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
773 FC_RPORT_DBG(rdata, "FLOGI ELS rejected, reason %x expl %x\n",
774 rjt->er_reason, rjt->er_explan);
775 err = -FC_EX_ELS_RJT;
776 goto bad;
777 } else if (opcode != ELS_LS_ACC) {
778 FC_RPORT_DBG(rdata, "FLOGI ELS invalid opcode %x\n", opcode);
779 err = -FC_EX_ELS_RJT;
780 goto bad;
781 }
782 if (fc_rport_login_complete(rdata, fp)) {
783 FC_RPORT_DBG(rdata, "FLOGI failed, no login\n");
784 err = -FC_EX_INV_LOGIN;
785 goto bad;
786 }
787
788 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
789 if (!flogi) {
790 err = -FC_EX_ALLOC_ERR;
791 goto bad;
792 }
793 r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
794 if (r_a_tov > rdata->r_a_tov)
795 rdata->r_a_tov = r_a_tov;
796
797 if (rdata->ids.port_name < lport->wwpn)
798 fc_rport_enter_plogi(rdata);
799 else
800 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
801out:
802 fc_frame_free(fp);
803err:
804 mutex_unlock(&rdata->rp_mutex);
805put:
806 kref_put(&rdata->kref, fc_rport_destroy);
807 return;
808bad:
809 FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
810 fc_rport_error_retry(rdata, err);
811 goto out;
812}
813
814
815
816
817
818
819
820static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
821{
822 struct fc_lport *lport = rdata->local_port;
823 struct fc_frame *fp;
824
825 lockdep_assert_held(&rdata->rp_mutex);
826
827 if (!lport->point_to_multipoint)
828 return fc_rport_enter_plogi(rdata);
829
830 FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
831 fc_rport_state(rdata));
832
833 fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
834
835 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
836 if (!fp)
837 return fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
838
839 kref_get(&rdata->kref);
840 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
841 fc_rport_flogi_resp, rdata,
842 2 * lport->r_a_tov)) {
843 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
844 kref_put(&rdata->kref, fc_rport_destroy);
845 }
846}
847
848
849
850
851
852
853
854
855static void fc_rport_recv_flogi_req(struct fc_lport *lport,
856 struct fc_frame *rx_fp)
857{
858 struct fc_els_flogi *flp;
859 struct fc_rport_priv *rdata;
860 struct fc_frame *fp = rx_fp;
861 struct fc_seq_els_data rjt_data;
862 u32 sid;
863
864 sid = fc_frame_sid(fp);
865
866 FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
867
868 if (!lport->point_to_multipoint) {
869 rjt_data.reason = ELS_RJT_UNSUP;
870 rjt_data.explan = ELS_EXPL_NONE;
871 goto reject;
872 }
873
874 flp = fc_frame_payload_get(fp, sizeof(*flp));
875 if (!flp) {
876 rjt_data.reason = ELS_RJT_LOGIC;
877 rjt_data.explan = ELS_EXPL_INV_LEN;
878 goto reject;
879 }
880
881 rdata = fc_rport_lookup(lport, sid);
882 if (!rdata) {
883 rjt_data.reason = ELS_RJT_FIP;
884 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
885 goto reject;
886 }
887 mutex_lock(&rdata->rp_mutex);
888
889 FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
890 fc_rport_state(rdata));
891
892 switch (rdata->rp_state) {
893 case RPORT_ST_INIT:
894
895
896
897
898
899
900
901
902
903
904
905
906 break;
907 case RPORT_ST_DELETE:
908 mutex_unlock(&rdata->rp_mutex);
909 rjt_data.reason = ELS_RJT_FIP;
910 rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
911 goto reject_put;
912 case RPORT_ST_FLOGI:
913 case RPORT_ST_PLOGI_WAIT:
914 case RPORT_ST_PLOGI:
915 break;
916 case RPORT_ST_PRLI:
917 case RPORT_ST_RTV:
918 case RPORT_ST_READY:
919 case RPORT_ST_ADISC:
920
921
922
923
924 fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
925 mutex_unlock(&rdata->rp_mutex);
926 rjt_data.reason = ELS_RJT_BUSY;
927 rjt_data.explan = ELS_EXPL_NONE;
928 goto reject_put;
929 }
930 if (fc_rport_login_complete(rdata, fp)) {
931 mutex_unlock(&rdata->rp_mutex);
932 rjt_data.reason = ELS_RJT_LOGIC;
933 rjt_data.explan = ELS_EXPL_NONE;
934 goto reject_put;
935 }
936
937 fp = fc_frame_alloc(lport, sizeof(*flp));
938 if (!fp)
939 goto out;
940
941 fc_flogi_fill(lport, fp);
942 flp = fc_frame_payload_get(fp, sizeof(*flp));
943 flp->fl_cmd = ELS_LS_ACC;
944
945 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
946 lport->tt.frame_send(lport, fp);
947
948
949
950
951
952
953 if (rdata->rp_state != RPORT_ST_FLOGI) {
954 if (rdata->ids.port_name < lport->wwpn)
955 fc_rport_enter_plogi(rdata);
956 else
957 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
958 }
959out:
960 mutex_unlock(&rdata->rp_mutex);
961 kref_put(&rdata->kref, fc_rport_destroy);
962 fc_frame_free(rx_fp);
963 return;
964
965reject_put:
966 kref_put(&rdata->kref, fc_rport_destroy);
967reject:
968 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
969 fc_frame_free(rx_fp);
970}
971
972
973
974
975
976
977
978
979
980
981
982static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
983 void *rdata_arg)
984{
985 struct fc_rport_priv *rdata = rdata_arg;
986 struct fc_lport *lport = rdata->local_port;
987 struct fc_els_flogi *plp = NULL;
988 u16 csp_seq;
989 u16 cssp_seq;
990 u8 op;
991
992 FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
993
994 if (fp == ERR_PTR(-FC_EX_CLOSED))
995 goto put;
996
997 mutex_lock(&rdata->rp_mutex);
998
999 if (rdata->rp_state != RPORT_ST_PLOGI) {
1000 FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
1001 "%s\n", fc_rport_state(rdata));
1002 if (IS_ERR(fp))
1003 goto err;
1004 goto out;
1005 }
1006
1007 if (IS_ERR(fp)) {
1008 fc_rport_error_retry(rdata, PTR_ERR(fp));
1009 goto err;
1010 }
1011
1012 op = fc_frame_payload_op(fp);
1013 if (op == ELS_LS_ACC &&
1014 (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
1015 rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
1016 rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
1017
1018
1019 rdata->sp_features = ntohs(plp->fl_csp.sp_features);
1020
1021 if (lport->point_to_multipoint)
1022 fc_rport_login_complete(rdata, fp);
1023 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
1024 cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
1025 if (cssp_seq < csp_seq)
1026 csp_seq = cssp_seq;
1027 rdata->max_seq = csp_seq;
1028 rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
1029 fc_rport_enter_prli(rdata);
1030 } else {
1031 struct fc_els_ls_rjt *rjt;
1032
1033 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1034 if (!rjt)
1035 FC_RPORT_DBG(rdata, "PLOGI bad response\n");
1036 else
1037 FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
1038 rjt->er_reason, rjt->er_explan);
1039 fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
1040 }
1041out:
1042 fc_frame_free(fp);
1043err:
1044 mutex_unlock(&rdata->rp_mutex);
1045put:
1046 kref_put(&rdata->kref, fc_rport_destroy);
1047}
1048
1049static bool
1050fc_rport_compatible_roles(struct fc_lport *lport, struct fc_rport_priv *rdata)
1051{
1052 if (rdata->ids.roles == FC_PORT_ROLE_UNKNOWN)
1053 return true;
1054 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_TARGET) &&
1055 (lport->service_params & FCP_SPPF_INIT_FCN))
1056 return true;
1057 if ((rdata->ids.roles & FC_PORT_ROLE_FCP_INITIATOR) &&
1058 (lport->service_params & FCP_SPPF_TARG_FCN))
1059 return true;
1060 return false;
1061}
1062
1063
1064
1065
1066
1067
1068
1069static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
1070{
1071 struct fc_lport *lport = rdata->local_port;
1072 struct fc_frame *fp;
1073
1074 lockdep_assert_held(&rdata->rp_mutex);
1075
1076 if (!fc_rport_compatible_roles(lport, rdata)) {
1077 FC_RPORT_DBG(rdata, "PLOGI suppressed for incompatible role\n");
1078 fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
1079 return;
1080 }
1081
1082 FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
1083 fc_rport_state(rdata));
1084
1085 fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
1086
1087 rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
1088 fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
1089 if (!fp) {
1090 FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
1091 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1092 return;
1093 }
1094 rdata->e_d_tov = lport->e_d_tov;
1095
1096 kref_get(&rdata->kref);
1097 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
1098 fc_rport_plogi_resp, rdata,
1099 2 * lport->r_a_tov)) {
1100 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1101 kref_put(&rdata->kref, fc_rport_destroy);
1102 }
1103}
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
1116 void *rdata_arg)
1117{
1118 struct fc_rport_priv *rdata = rdata_arg;
1119 struct {
1120 struct fc_els_prli prli;
1121 struct fc_els_spp spp;
1122 } *pp;
1123 struct fc_els_spp temp_spp;
1124 struct fc_els_ls_rjt *rjt;
1125 struct fc4_prov *prov;
1126 u32 roles = FC_RPORT_ROLE_UNKNOWN;
1127 u32 fcp_parm = 0;
1128 u8 op;
1129 enum fc_els_spp_resp resp_code;
1130
1131 FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
1132
1133 if (fp == ERR_PTR(-FC_EX_CLOSED))
1134 goto put;
1135
1136 mutex_lock(&rdata->rp_mutex);
1137
1138 if (rdata->rp_state != RPORT_ST_PRLI) {
1139 FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
1140 "%s\n", fc_rport_state(rdata));
1141 if (IS_ERR(fp))
1142 goto err;
1143 goto out;
1144 }
1145
1146 if (IS_ERR(fp)) {
1147 fc_rport_error_retry(rdata, PTR_ERR(fp));
1148 goto err;
1149 }
1150
1151
1152 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
1153
1154 op = fc_frame_payload_op(fp);
1155 if (op == ELS_LS_ACC) {
1156 pp = fc_frame_payload_get(fp, sizeof(*pp));
1157 if (!pp) {
1158 fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
1159 goto out;
1160 }
1161
1162 resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
1163 FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
1164 pp->spp.spp_flags, pp->spp.spp_type);
1165 rdata->spp_type = pp->spp.spp_type;
1166 if (resp_code != FC_SPP_RESP_ACK) {
1167 if (resp_code == FC_SPP_RESP_CONF)
1168 fc_rport_error(rdata, -FC_EX_SEQ_ERR);
1169 else
1170 fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
1171 goto out;
1172 }
1173 if (pp->prli.prli_spp_len < sizeof(pp->spp)) {
1174 fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
1175 goto out;
1176 }
1177
1178 fcp_parm = ntohl(pp->spp.spp_params);
1179 if (fcp_parm & FCP_SPPF_RETRY)
1180 rdata->flags |= FC_RP_FLAGS_RETRY;
1181 if (fcp_parm & FCP_SPPF_CONF_COMPL)
1182 rdata->flags |= FC_RP_FLAGS_CONF_REQ;
1183
1184
1185
1186
1187 prov = fc_passive_prov[rdata->spp_type];
1188 if (prov) {
1189 memset(&temp_spp, 0, sizeof(temp_spp));
1190 prov->prli(rdata, pp->prli.prli_spp_len,
1191 &pp->spp, &temp_spp);
1192 }
1193
1194
1195
1196 if (rdata->spp_type != FC_TYPE_FCP ||
1197 !(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) {
1198
1199
1200
1201 fcp_parm &= ~FCP_SPPF_TARG_FCN;
1202 }
1203 rdata->supported_classes = FC_COS_CLASS3;
1204 if (fcp_parm & FCP_SPPF_INIT_FCN)
1205 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1206 if (fcp_parm & FCP_SPPF_TARG_FCN)
1207 roles |= FC_RPORT_ROLE_FCP_TARGET;
1208
1209 rdata->ids.roles = roles;
1210 fc_rport_enter_rtv(rdata);
1211
1212 } else {
1213 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
1214 if (!rjt)
1215 FC_RPORT_DBG(rdata, "PRLI bad response\n");
1216 else {
1217 FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
1218 rjt->er_reason, rjt->er_explan);
1219 if (rjt->er_reason == ELS_RJT_UNAB &&
1220 rjt->er_explan == ELS_EXPL_PLOGI_REQD) {
1221 fc_rport_enter_plogi(rdata);
1222 goto out;
1223 }
1224 }
1225 fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
1226 }
1227
1228out:
1229 fc_frame_free(fp);
1230err:
1231 mutex_unlock(&rdata->rp_mutex);
1232put:
1233 kref_put(&rdata->kref, fc_rport_destroy);
1234}
1235
1236
1237
1238
1239
1240
1241
1242static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
1243{
1244 struct fc_lport *lport = rdata->local_port;
1245 struct {
1246 struct fc_els_prli prli;
1247 struct fc_els_spp spp;
1248 } *pp;
1249 struct fc_frame *fp;
1250 struct fc4_prov *prov;
1251
1252 lockdep_assert_held(&rdata->rp_mutex);
1253
1254
1255
1256
1257
1258 if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
1259 fc_rport_enter_ready(rdata);
1260 return;
1261 }
1262
1263
1264
1265
1266
1267 if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
1268 fc_rport_enter_ready(rdata);
1269 return;
1270 }
1271
1272 FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
1273 fc_rport_state(rdata));
1274
1275 fc_rport_state_enter(rdata, RPORT_ST_PRLI);
1276
1277 fp = fc_frame_alloc(lport, sizeof(*pp));
1278 if (!fp) {
1279 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1280 return;
1281 }
1282
1283 fc_prli_fill(lport, fp);
1284
1285 prov = fc_passive_prov[FC_TYPE_FCP];
1286 if (prov) {
1287 pp = fc_frame_payload_get(fp, sizeof(*pp));
1288 prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
1289 }
1290
1291 fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
1292 fc_host_port_id(lport->host), FC_TYPE_ELS,
1293 FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1294
1295 kref_get(&rdata->kref);
1296 if (!fc_exch_seq_send(lport, fp, fc_rport_prli_resp,
1297 NULL, rdata, 2 * lport->r_a_tov)) {
1298 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1299 kref_put(&rdata->kref, fc_rport_destroy);
1300 }
1301}
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
1316 void *rdata_arg)
1317{
1318 struct fc_rport_priv *rdata = rdata_arg;
1319 u8 op;
1320
1321 FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
1322
1323 if (fp == ERR_PTR(-FC_EX_CLOSED))
1324 goto put;
1325
1326 mutex_lock(&rdata->rp_mutex);
1327
1328 if (rdata->rp_state != RPORT_ST_RTV) {
1329 FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
1330 "%s\n", fc_rport_state(rdata));
1331 if (IS_ERR(fp))
1332 goto err;
1333 goto out;
1334 }
1335
1336 if (IS_ERR(fp)) {
1337 fc_rport_error(rdata, PTR_ERR(fp));
1338 goto err;
1339 }
1340
1341 op = fc_frame_payload_op(fp);
1342 if (op == ELS_LS_ACC) {
1343 struct fc_els_rtv_acc *rtv;
1344 u32 toq;
1345 u32 tov;
1346
1347 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1348 if (rtv) {
1349 toq = ntohl(rtv->rtv_toq);
1350 tov = ntohl(rtv->rtv_r_a_tov);
1351 if (tov == 0)
1352 tov = 1;
1353 if (tov > rdata->r_a_tov)
1354 rdata->r_a_tov = tov;
1355 tov = ntohl(rtv->rtv_e_d_tov);
1356 if (toq & FC_ELS_RTV_EDRES)
1357 tov /= 1000000;
1358 if (tov == 0)
1359 tov = 1;
1360 if (tov > rdata->e_d_tov)
1361 rdata->e_d_tov = tov;
1362 }
1363 }
1364
1365 fc_rport_enter_ready(rdata);
1366
1367out:
1368 fc_frame_free(fp);
1369err:
1370 mutex_unlock(&rdata->rp_mutex);
1371put:
1372 kref_put(&rdata->kref, fc_rport_destroy);
1373}
1374
1375
1376
1377
1378
1379
1380
1381static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
1382{
1383 struct fc_frame *fp;
1384 struct fc_lport *lport = rdata->local_port;
1385
1386 lockdep_assert_held(&rdata->rp_mutex);
1387
1388 FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
1389 fc_rport_state(rdata));
1390
1391 fc_rport_state_enter(rdata, RPORT_ST_RTV);
1392
1393 fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
1394 if (!fp) {
1395 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1396 return;
1397 }
1398
1399 kref_get(&rdata->kref);
1400 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
1401 fc_rport_rtv_resp, rdata,
1402 2 * lport->r_a_tov)) {
1403 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1404 kref_put(&rdata->kref, fc_rport_destroy);
1405 }
1406}
1407
1408
1409
1410
1411
1412
1413static void fc_rport_recv_rtv_req(struct fc_rport_priv *rdata,
1414 struct fc_frame *in_fp)
1415{
1416 struct fc_lport *lport = rdata->local_port;
1417 struct fc_frame *fp;
1418 struct fc_els_rtv_acc *rtv;
1419 struct fc_seq_els_data rjt_data;
1420
1421 lockdep_assert_held(&rdata->rp_mutex);
1422 lockdep_assert_held(&lport->lp_mutex);
1423
1424 FC_RPORT_DBG(rdata, "Received RTV request\n");
1425
1426 fp = fc_frame_alloc(lport, sizeof(*rtv));
1427 if (!fp) {
1428 rjt_data.reason = ELS_RJT_UNAB;
1429 rjt_data.explan = ELS_EXPL_INSUF_RES;
1430 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1431 goto drop;
1432 }
1433 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
1434 rtv->rtv_cmd = ELS_LS_ACC;
1435 rtv->rtv_r_a_tov = htonl(lport->r_a_tov);
1436 rtv->rtv_e_d_tov = htonl(lport->e_d_tov);
1437 rtv->rtv_toq = 0;
1438 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1439 lport->tt.frame_send(lport, fp);
1440drop:
1441 fc_frame_free(in_fp);
1442}
1443
1444
1445
1446
1447
1448
1449
1450static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
1451 void *rdata_arg)
1452{
1453 struct fc_rport_priv *rdata = rdata_arg;
1454 struct fc_lport *lport = rdata->local_port;
1455
1456 FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
1457 "Received a LOGO %s\n", fc_els_resp_type(fp));
1458 if (!IS_ERR(fp))
1459 fc_frame_free(fp);
1460 kref_put(&rdata->kref, fc_rport_destroy);
1461}
1462
1463
1464
1465
1466
1467
1468
1469static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
1470{
1471 struct fc_lport *lport = rdata->local_port;
1472 struct fc_frame *fp;
1473
1474 lockdep_assert_held(&rdata->rp_mutex);
1475
1476 FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
1477 fc_rport_state(rdata));
1478
1479 fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
1480 if (!fp)
1481 return;
1482 kref_get(&rdata->kref);
1483 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
1484 fc_rport_logo_resp, rdata, 0))
1485 kref_put(&rdata->kref, fc_rport_destroy);
1486}
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
1499 void *rdata_arg)
1500{
1501 struct fc_rport_priv *rdata = rdata_arg;
1502 struct fc_els_adisc *adisc;
1503 u8 op;
1504
1505 FC_RPORT_DBG(rdata, "Received a ADISC response\n");
1506
1507 if (fp == ERR_PTR(-FC_EX_CLOSED))
1508 goto put;
1509
1510 mutex_lock(&rdata->rp_mutex);
1511
1512 if (rdata->rp_state != RPORT_ST_ADISC) {
1513 FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
1514 fc_rport_state(rdata));
1515 if (IS_ERR(fp))
1516 goto err;
1517 goto out;
1518 }
1519
1520 if (IS_ERR(fp)) {
1521 fc_rport_error(rdata, PTR_ERR(fp));
1522 goto err;
1523 }
1524
1525
1526
1527
1528
1529
1530 op = fc_frame_payload_op(fp);
1531 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1532 if (op != ELS_LS_ACC || !adisc ||
1533 ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
1534 get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
1535 get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
1536 FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
1537 fc_rport_enter_flogi(rdata);
1538 } else {
1539 FC_RPORT_DBG(rdata, "ADISC OK\n");
1540 fc_rport_enter_ready(rdata);
1541 }
1542out:
1543 fc_frame_free(fp);
1544err:
1545 mutex_unlock(&rdata->rp_mutex);
1546put:
1547 kref_put(&rdata->kref, fc_rport_destroy);
1548}
1549
1550
1551
1552
1553
1554
1555
1556static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
1557{
1558 struct fc_lport *lport = rdata->local_port;
1559 struct fc_frame *fp;
1560
1561 lockdep_assert_held(&rdata->rp_mutex);
1562
1563 FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
1564 fc_rport_state(rdata));
1565
1566 fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1567
1568 fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1569 if (!fp) {
1570 fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
1571 return;
1572 }
1573 kref_get(&rdata->kref);
1574 if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
1575 fc_rport_adisc_resp, rdata,
1576 2 * lport->r_a_tov)) {
1577 fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
1578 kref_put(&rdata->kref, fc_rport_destroy);
1579 }
1580}
1581
1582
1583
1584
1585
1586
1587static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
1588 struct fc_frame *in_fp)
1589{
1590 struct fc_lport *lport = rdata->local_port;
1591 struct fc_frame *fp;
1592 struct fc_els_adisc *adisc;
1593 struct fc_seq_els_data rjt_data;
1594
1595 lockdep_assert_held(&rdata->rp_mutex);
1596 lockdep_assert_held(&lport->lp_mutex);
1597
1598 FC_RPORT_DBG(rdata, "Received ADISC request\n");
1599
1600 adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
1601 if (!adisc) {
1602 rjt_data.reason = ELS_RJT_PROT;
1603 rjt_data.explan = ELS_EXPL_INV_LEN;
1604 fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
1605 goto drop;
1606 }
1607
1608 fp = fc_frame_alloc(lport, sizeof(*adisc));
1609 if (!fp)
1610 goto drop;
1611 fc_adisc_fill(lport, fp);
1612 adisc = fc_frame_payload_get(fp, sizeof(*adisc));
1613 adisc->adisc_cmd = ELS_LS_ACC;
1614 fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
1615 lport->tt.frame_send(lport, fp);
1616drop:
1617 fc_frame_free(in_fp);
1618}
1619
1620
1621
1622
1623
1624
1625static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
1626 struct fc_frame *rx_fp)
1627
1628{
1629 struct fc_lport *lport = rdata->local_port;
1630 struct fc_frame *fp;
1631 struct fc_els_rls *rls;
1632 struct fc_els_rls_resp *rsp;
1633 struct fc_els_lesb *lesb;
1634 struct fc_seq_els_data rjt_data;
1635 struct fc_host_statistics *hst;
1636
1637 lockdep_assert_held(&rdata->rp_mutex);
1638
1639 FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
1640 fc_rport_state(rdata));
1641
1642 rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
1643 if (!rls) {
1644 rjt_data.reason = ELS_RJT_PROT;
1645 rjt_data.explan = ELS_EXPL_INV_LEN;
1646 goto out_rjt;
1647 }
1648
1649 fp = fc_frame_alloc(lport, sizeof(*rsp));
1650 if (!fp) {
1651 rjt_data.reason = ELS_RJT_UNAB;
1652 rjt_data.explan = ELS_EXPL_INSUF_RES;
1653 goto out_rjt;
1654 }
1655
1656 rsp = fc_frame_payload_get(fp, sizeof(*rsp));
1657 memset(rsp, 0, sizeof(*rsp));
1658 rsp->rls_cmd = ELS_LS_ACC;
1659 lesb = &rsp->rls_lesb;
1660 if (lport->tt.get_lesb) {
1661
1662 lport->tt.get_lesb(lport, lesb);
1663 } else {
1664 fc_get_host_stats(lport->host);
1665 hst = &lport->host_stats;
1666 lesb->lesb_link_fail = htonl(hst->link_failure_count);
1667 lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
1668 lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
1669 lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
1670 lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
1671 lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
1672 }
1673
1674 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1675 lport->tt.frame_send(lport, fp);
1676 goto out;
1677
1678out_rjt:
1679 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
1680out:
1681 fc_frame_free(rx_fp);
1682}
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
1695{
1696 struct fc_rport_priv *rdata;
1697 struct fc_seq_els_data els_data;
1698
1699 lockdep_assert_held(&lport->lp_mutex);
1700
1701 rdata = fc_rport_lookup(lport, fc_frame_sid(fp));
1702 if (!rdata) {
1703 FC_RPORT_ID_DBG(lport, fc_frame_sid(fp),
1704 "Received ELS 0x%02x from non-logged-in port\n",
1705 fc_frame_payload_op(fp));
1706 goto reject;
1707 }
1708
1709 mutex_lock(&rdata->rp_mutex);
1710
1711 switch (rdata->rp_state) {
1712 case RPORT_ST_PRLI:
1713 case RPORT_ST_RTV:
1714 case RPORT_ST_READY:
1715 case RPORT_ST_ADISC:
1716 break;
1717 case RPORT_ST_PLOGI:
1718 if (fc_frame_payload_op(fp) == ELS_PRLI) {
1719 FC_RPORT_DBG(rdata, "Reject ELS PRLI "
1720 "while in state %s\n",
1721 fc_rport_state(rdata));
1722 mutex_unlock(&rdata->rp_mutex);
1723 kref_put(&rdata->kref, fc_rport_destroy);
1724 goto busy;
1725 }
1726 fallthrough;
1727 default:
1728 FC_RPORT_DBG(rdata,
1729 "Reject ELS 0x%02x while in state %s\n",
1730 fc_frame_payload_op(fp), fc_rport_state(rdata));
1731 mutex_unlock(&rdata->rp_mutex);
1732 kref_put(&rdata->kref, fc_rport_destroy);
1733 goto reject;
1734 }
1735
1736 switch (fc_frame_payload_op(fp)) {
1737 case ELS_PRLI:
1738 fc_rport_recv_prli_req(rdata, fp);
1739 break;
1740 case ELS_PRLO:
1741 fc_rport_recv_prlo_req(rdata, fp);
1742 break;
1743 case ELS_ADISC:
1744 fc_rport_recv_adisc_req(rdata, fp);
1745 break;
1746 case ELS_RRQ:
1747 fc_seq_els_rsp_send(fp, ELS_RRQ, NULL);
1748 fc_frame_free(fp);
1749 break;
1750 case ELS_REC:
1751 fc_seq_els_rsp_send(fp, ELS_REC, NULL);
1752 fc_frame_free(fp);
1753 break;
1754 case ELS_RLS:
1755 fc_rport_recv_rls_req(rdata, fp);
1756 break;
1757 case ELS_RTV:
1758 fc_rport_recv_rtv_req(rdata, fp);
1759 break;
1760 default:
1761 fc_frame_free(fp);
1762 break;
1763 }
1764
1765 mutex_unlock(&rdata->rp_mutex);
1766 kref_put(&rdata->kref, fc_rport_destroy);
1767 return;
1768
1769reject:
1770 els_data.reason = ELS_RJT_UNAB;
1771 els_data.explan = ELS_EXPL_PLOGI_REQD;
1772 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1773 fc_frame_free(fp);
1774 return;
1775
1776busy:
1777 els_data.reason = ELS_RJT_BUSY;
1778 els_data.explan = ELS_EXPL_NONE;
1779 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1780 fc_frame_free(fp);
1781 return;
1782}
1783
1784
1785
1786
1787
1788
1789
1790
1791void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
1792{
1793 struct fc_seq_els_data els_data;
1794
1795 lockdep_assert_held(&lport->lp_mutex);
1796
1797
1798
1799
1800
1801
1802
1803 switch (fc_frame_payload_op(fp)) {
1804 case ELS_FLOGI:
1805 fc_rport_recv_flogi_req(lport, fp);
1806 break;
1807 case ELS_PLOGI:
1808 fc_rport_recv_plogi_req(lport, fp);
1809 break;
1810 case ELS_LOGO:
1811 fc_rport_recv_logo_req(lport, fp);
1812 break;
1813 case ELS_PRLI:
1814 case ELS_PRLO:
1815 case ELS_ADISC:
1816 case ELS_RRQ:
1817 case ELS_REC:
1818 case ELS_RLS:
1819 case ELS_RTV:
1820 fc_rport_recv_els_req(lport, fp);
1821 break;
1822 default:
1823 els_data.reason = ELS_RJT_UNSUP;
1824 els_data.explan = ELS_EXPL_NONE;
1825 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
1826 fc_frame_free(fp);
1827 break;
1828 }
1829}
1830EXPORT_SYMBOL(fc_rport_recv_req);
1831
1832
1833
1834
1835
1836
1837
1838
1839static void fc_rport_recv_plogi_req(struct fc_lport *lport,
1840 struct fc_frame *rx_fp)
1841{
1842 struct fc_disc *disc;
1843 struct fc_rport_priv *rdata;
1844 struct fc_frame *fp = rx_fp;
1845 struct fc_els_flogi *pl;
1846 struct fc_seq_els_data rjt_data;
1847 u32 sid;
1848
1849 lockdep_assert_held(&lport->lp_mutex);
1850
1851 sid = fc_frame_sid(fp);
1852
1853 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
1854
1855 pl = fc_frame_payload_get(fp, sizeof(*pl));
1856 if (!pl) {
1857 FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
1858 rjt_data.reason = ELS_RJT_PROT;
1859 rjt_data.explan = ELS_EXPL_INV_LEN;
1860 goto reject;
1861 }
1862
1863 disc = &lport->disc;
1864 mutex_lock(&disc->disc_mutex);
1865 rdata = fc_rport_create(lport, sid);
1866 if (!rdata) {
1867 mutex_unlock(&disc->disc_mutex);
1868 rjt_data.reason = ELS_RJT_UNAB;
1869 rjt_data.explan = ELS_EXPL_INSUF_RES;
1870 goto reject;
1871 }
1872
1873 mutex_lock(&rdata->rp_mutex);
1874 mutex_unlock(&disc->disc_mutex);
1875
1876 rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
1877 rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890 switch (rdata->rp_state) {
1891 case RPORT_ST_INIT:
1892 FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
1893 break;
1894 case RPORT_ST_PLOGI_WAIT:
1895 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
1896 break;
1897 case RPORT_ST_PLOGI:
1898 FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
1899 if (rdata->ids.port_name < lport->wwpn) {
1900 mutex_unlock(&rdata->rp_mutex);
1901 rjt_data.reason = ELS_RJT_INPROG;
1902 rjt_data.explan = ELS_EXPL_NONE;
1903 goto reject;
1904 }
1905 break;
1906 case RPORT_ST_PRLI:
1907 case RPORT_ST_RTV:
1908 case RPORT_ST_READY:
1909 case RPORT_ST_ADISC:
1910 FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1911 "- ignored for now\n", rdata->rp_state);
1912
1913 break;
1914 case RPORT_ST_FLOGI:
1915 case RPORT_ST_DELETE:
1916 FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
1917 fc_rport_state(rdata));
1918 mutex_unlock(&rdata->rp_mutex);
1919 rjt_data.reason = ELS_RJT_BUSY;
1920 rjt_data.explan = ELS_EXPL_NONE;
1921 goto reject;
1922 }
1923 if (!fc_rport_compatible_roles(lport, rdata)) {
1924 FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
1925 mutex_unlock(&rdata->rp_mutex);
1926 rjt_data.reason = ELS_RJT_LOGIC;
1927 rjt_data.explan = ELS_EXPL_NONE;
1928 goto reject;
1929 }
1930
1931
1932
1933
1934 rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
1935
1936
1937
1938
1939 fp = fc_frame_alloc(lport, sizeof(*pl));
1940 if (!fp)
1941 goto out;
1942
1943 fc_plogi_fill(lport, fp, ELS_LS_ACC);
1944 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
1945 lport->tt.frame_send(lport, fp);
1946 fc_rport_enter_prli(rdata);
1947out:
1948 mutex_unlock(&rdata->rp_mutex);
1949 fc_frame_free(rx_fp);
1950 return;
1951
1952reject:
1953 fc_seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
1954 fc_frame_free(fp);
1955}
1956
1957
1958
1959
1960
1961
1962static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
1963 struct fc_frame *rx_fp)
1964{
1965 struct fc_lport *lport = rdata->local_port;
1966 struct fc_frame *fp;
1967 struct {
1968 struct fc_els_prli prli;
1969 struct fc_els_spp spp;
1970 } *pp;
1971 struct fc_els_spp *rspp;
1972 struct fc_els_spp *spp;
1973 unsigned int len;
1974 unsigned int plen;
1975 enum fc_els_spp_resp resp;
1976 struct fc_seq_els_data rjt_data;
1977 struct fc4_prov *prov;
1978
1979 lockdep_assert_held(&rdata->rp_mutex);
1980
1981 FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
1982 fc_rport_state(rdata));
1983
1984 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
1985 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
1986 if (!pp)
1987 goto reject_len;
1988 plen = ntohs(pp->prli.prli_len);
1989 if ((plen % 4) != 0 || plen > len || plen < 16)
1990 goto reject_len;
1991 if (plen < len)
1992 len = plen;
1993 plen = pp->prli.prli_spp_len;
1994 if ((plen % 4) != 0 || plen < sizeof(*spp) ||
1995 plen > len || len < sizeof(*pp) || plen < 12)
1996 goto reject_len;
1997 rspp = &pp->spp;
1998
1999 fp = fc_frame_alloc(lport, len);
2000 if (!fp) {
2001 rjt_data.reason = ELS_RJT_UNAB;
2002 rjt_data.explan = ELS_EXPL_INSUF_RES;
2003 goto reject;
2004 }
2005 pp = fc_frame_payload_get(fp, len);
2006 WARN_ON(!pp);
2007 memset(pp, 0, len);
2008 pp->prli.prli_cmd = ELS_LS_ACC;
2009 pp->prli.prli_spp_len = plen;
2010 pp->prli.prli_len = htons(len);
2011 len -= sizeof(struct fc_els_prli);
2012
2013
2014
2015
2016
2017
2018 spp = &pp->spp;
2019 mutex_lock(&fc_prov_mutex);
2020 while (len >= plen) {
2021 rdata->spp_type = rspp->spp_type;
2022 spp->spp_type = rspp->spp_type;
2023 spp->spp_type_ext = rspp->spp_type_ext;
2024 resp = 0;
2025
2026 if (rspp->spp_type < FC_FC4_PROV_SIZE) {
2027 enum fc_els_spp_resp active = 0, passive = 0;
2028
2029 prov = fc_active_prov[rspp->spp_type];
2030 if (prov)
2031 active = prov->prli(rdata, plen, rspp, spp);
2032 prov = fc_passive_prov[rspp->spp_type];
2033 if (prov)
2034 passive = prov->prli(rdata, plen, rspp, spp);
2035 if (!active || passive == FC_SPP_RESP_ACK)
2036 resp = passive;
2037 else
2038 resp = active;
2039 FC_RPORT_DBG(rdata, "PRLI rspp type %x "
2040 "active %x passive %x\n",
2041 rspp->spp_type, active, passive);
2042 }
2043 if (!resp) {
2044 if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
2045 resp |= FC_SPP_RESP_CONF;
2046 else
2047 resp |= FC_SPP_RESP_INVL;
2048 }
2049 spp->spp_flags |= resp;
2050 len -= plen;
2051 rspp = (struct fc_els_spp *)((char *)rspp + plen);
2052 spp = (struct fc_els_spp *)((char *)spp + plen);
2053 }
2054 mutex_unlock(&fc_prov_mutex);
2055
2056
2057
2058
2059 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2060 lport->tt.frame_send(lport, fp);
2061
2062 goto drop;
2063
2064reject_len:
2065 rjt_data.reason = ELS_RJT_PROT;
2066 rjt_data.explan = ELS_EXPL_INV_LEN;
2067reject:
2068 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2069drop:
2070 fc_frame_free(rx_fp);
2071}
2072
2073
2074
2075
2076
2077
2078static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
2079 struct fc_frame *rx_fp)
2080{
2081 struct fc_lport *lport = rdata->local_port;
2082 struct fc_frame *fp;
2083 struct {
2084 struct fc_els_prlo prlo;
2085 struct fc_els_spp spp;
2086 } *pp;
2087 struct fc_els_spp *rspp;
2088 struct fc_els_spp *spp;
2089 unsigned int len;
2090 unsigned int plen;
2091 struct fc_seq_els_data rjt_data;
2092
2093 lockdep_assert_held(&rdata->rp_mutex);
2094
2095 FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
2096 fc_rport_state(rdata));
2097
2098 len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
2099 pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
2100 if (!pp)
2101 goto reject_len;
2102 plen = ntohs(pp->prlo.prlo_len);
2103 if (plen != 20)
2104 goto reject_len;
2105 if (plen < len)
2106 len = plen;
2107
2108 rspp = &pp->spp;
2109
2110 fp = fc_frame_alloc(lport, len);
2111 if (!fp) {
2112 rjt_data.reason = ELS_RJT_UNAB;
2113 rjt_data.explan = ELS_EXPL_INSUF_RES;
2114 goto reject;
2115 }
2116
2117 pp = fc_frame_payload_get(fp, len);
2118 WARN_ON(!pp);
2119 memset(pp, 0, len);
2120 pp->prlo.prlo_cmd = ELS_LS_ACC;
2121 pp->prlo.prlo_obs = 0x10;
2122 pp->prlo.prlo_len = htons(len);
2123 spp = &pp->spp;
2124 spp->spp_type = rspp->spp_type;
2125 spp->spp_type_ext = rspp->spp_type_ext;
2126 spp->spp_flags = FC_SPP_RESP_ACK;
2127
2128 fc_rport_enter_prli(rdata);
2129
2130 fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
2131 lport->tt.frame_send(lport, fp);
2132 goto drop;
2133
2134reject_len:
2135 rjt_data.reason = ELS_RJT_PROT;
2136 rjt_data.explan = ELS_EXPL_INV_LEN;
2137reject:
2138 fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
2139drop:
2140 fc_frame_free(rx_fp);
2141}
2142
2143
2144
2145
2146
2147
2148
2149
2150static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
2151{
2152 struct fc_rport_priv *rdata;
2153 u32 sid;
2154
2155 lockdep_assert_held(&lport->lp_mutex);
2156
2157 fc_seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
2158
2159 sid = fc_frame_sid(fp);
2160
2161 rdata = fc_rport_lookup(lport, sid);
2162 if (rdata) {
2163 mutex_lock(&rdata->rp_mutex);
2164 FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
2165 fc_rport_state(rdata));
2166
2167 fc_rport_enter_delete(rdata, RPORT_EV_STOP);
2168 mutex_unlock(&rdata->rp_mutex);
2169 kref_put(&rdata->kref, fc_rport_destroy);
2170 } else
2171 FC_RPORT_ID_DBG(lport, sid,
2172 "Received LOGO from non-logged-in port\n");
2173 fc_frame_free(fp);
2174}
2175
2176
2177
2178
2179void fc_rport_flush_queue(void)
2180{
2181 flush_workqueue(rport_event_queue);
2182}
2183EXPORT_SYMBOL(fc_rport_flush_queue);
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
2196 const struct fc_els_spp *rspp,
2197 struct fc_els_spp *spp)
2198{
2199 struct fc_lport *lport = rdata->local_port;
2200 u32 fcp_parm;
2201
2202 fcp_parm = ntohl(rspp->spp_params);
2203 rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
2204 if (fcp_parm & FCP_SPPF_INIT_FCN)
2205 rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2206 if (fcp_parm & FCP_SPPF_TARG_FCN)
2207 rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2208 if (fcp_parm & FCP_SPPF_RETRY)
2209 rdata->flags |= FC_RP_FLAGS_RETRY;
2210 rdata->supported_classes = FC_COS_CLASS3;
2211
2212 if (!(lport->service_params & FCP_SPPF_INIT_FCN))
2213 return 0;
2214
2215 spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
2216
2217
2218
2219
2220 fcp_parm = ntohl(spp->spp_params);
2221 spp->spp_params = htonl(fcp_parm | lport->service_params);
2222 return FC_SPP_RESP_ACK;
2223}
2224
2225
2226
2227
2228struct fc4_prov fc_rport_fcp_init = {
2229 .prli = fc_rport_fcp_prli,
2230};
2231
2232
2233
2234
2235
2236
2237
2238
2239static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
2240 const struct fc_els_spp *rspp,
2241 struct fc_els_spp *spp)
2242{
2243 if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
2244 return FC_SPP_RESP_INVL;
2245 return FC_SPP_RESP_ACK;
2246}
2247
2248
2249
2250
2251
2252
2253
2254struct fc4_prov fc_rport_t0_prov = {
2255 .prli = fc_rport_t0_prli,
2256};
2257
2258
2259
2260
2261int fc_setup_rport(void)
2262{
2263 rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
2264 if (!rport_event_queue)
2265 return -ENOMEM;
2266 return 0;
2267}
2268
2269
2270
2271
2272void fc_destroy_rport(void)
2273{
2274 destroy_workqueue(rport_event_queue);
2275}
2276
2277
2278
2279
2280
2281void fc_rport_terminate_io(struct fc_rport *rport)
2282{
2283 struct fc_rport_libfc_priv *rpriv = rport->dd_data;
2284 struct fc_lport *lport = rpriv->local_port;
2285
2286 lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
2287 lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
2288}
2289EXPORT_SYMBOL(fc_rport_terminate_io);
2290