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