diff options
-rw-r--r-- | drivers/scsi/libfc/fc_lport.c | 72 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_npiv.c | 75 | ||||
-rw-r--r-- | include/scsi/libfc.h | 8 |
3 files changed, 140 insertions, 15 deletions
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c index 41650d336289..46897cf23ea6 100644 --- a/drivers/scsi/libfc/fc_lport.c +++ b/drivers/scsi/libfc/fc_lport.c | |||
@@ -224,10 +224,18 @@ void fc_get_host_port_state(struct Scsi_Host *shost) | |||
224 | { | 224 | { |
225 | struct fc_lport *lp = shost_priv(shost); | 225 | struct fc_lport *lp = shost_priv(shost); |
226 | 226 | ||
227 | if (lp->link_up) | 227 | mutex_lock(&lp->lp_mutex); |
228 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | 228 | if (!lp->link_up) |
229 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | ||
229 | else | 230 | else |
230 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | 231 | switch (lp->state) { |
232 | case LPORT_ST_READY: | ||
233 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | ||
234 | break; | ||
235 | default: | ||
236 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | ||
237 | } | ||
238 | mutex_unlock(&lp->lp_mutex); | ||
231 | } | 239 | } |
232 | EXPORT_SYMBOL(fc_get_host_port_state); | 240 | EXPORT_SYMBOL(fc_get_host_port_state); |
233 | 241 | ||
@@ -493,40 +501,62 @@ int fc_fabric_login(struct fc_lport *lport) | |||
493 | EXPORT_SYMBOL(fc_fabric_login); | 501 | EXPORT_SYMBOL(fc_fabric_login); |
494 | 502 | ||
495 | /** | 503 | /** |
496 | * fc_linkup() - Handler for transport linkup events | 504 | * __fc_linkup() - Handler for transport linkup events |
497 | * @lport: The lport whose link is up | 505 | * @lport: The lport whose link is up |
506 | * | ||
507 | * Locking: must be called with the lp_mutex held | ||
498 | */ | 508 | */ |
499 | void fc_linkup(struct fc_lport *lport) | 509 | void __fc_linkup(struct fc_lport *lport) |
500 | { | 510 | { |
501 | printk(KERN_INFO "libfc: Link up on port (%6x)\n", | ||
502 | fc_host_port_id(lport->host)); | ||
503 | |||
504 | mutex_lock(&lport->lp_mutex); | ||
505 | if (!lport->link_up) { | 511 | if (!lport->link_up) { |
506 | lport->link_up = 1; | 512 | lport->link_up = 1; |
507 | 513 | ||
508 | if (lport->state == LPORT_ST_RESET) | 514 | if (lport->state == LPORT_ST_RESET) |
509 | fc_lport_enter_flogi(lport); | 515 | fc_lport_enter_flogi(lport); |
510 | } | 516 | } |
517 | } | ||
518 | |||
519 | /** | ||
520 | * fc_linkup() - Handler for transport linkup events | ||
521 | * @lport: The lport whose link is up | ||
522 | */ | ||
523 | void fc_linkup(struct fc_lport *lport) | ||
524 | { | ||
525 | printk(KERN_INFO "libfc: Link up on port (%6x)\n", | ||
526 | fc_host_port_id(lport->host)); | ||
527 | |||
528 | mutex_lock(&lport->lp_mutex); | ||
529 | __fc_linkup(lport); | ||
511 | mutex_unlock(&lport->lp_mutex); | 530 | mutex_unlock(&lport->lp_mutex); |
512 | } | 531 | } |
513 | EXPORT_SYMBOL(fc_linkup); | 532 | EXPORT_SYMBOL(fc_linkup); |
514 | 533 | ||
515 | /** | 534 | /** |
516 | * fc_linkdown() - Handler for transport linkdown events | 535 | * __fc_linkdown() - Handler for transport linkdown events |
517 | * @lport: The lport whose link is down | 536 | * @lport: The lport whose link is down |
537 | * | ||
538 | * Locking: must be called with the lp_mutex held | ||
518 | */ | 539 | */ |
519 | void fc_linkdown(struct fc_lport *lport) | 540 | void __fc_linkdown(struct fc_lport *lport) |
520 | { | 541 | { |
521 | mutex_lock(&lport->lp_mutex); | ||
522 | printk(KERN_INFO "libfc: Link down on port (%6x)\n", | ||
523 | fc_host_port_id(lport->host)); | ||
524 | |||
525 | if (lport->link_up) { | 542 | if (lport->link_up) { |
526 | lport->link_up = 0; | 543 | lport->link_up = 0; |
527 | fc_lport_enter_reset(lport); | 544 | fc_lport_enter_reset(lport); |
528 | lport->tt.fcp_cleanup(lport); | 545 | lport->tt.fcp_cleanup(lport); |
529 | } | 546 | } |
547 | } | ||
548 | |||
549 | /** | ||
550 | * fc_linkdown() - Handler for transport linkdown events | ||
551 | * @lport: The lport whose link is down | ||
552 | */ | ||
553 | void fc_linkdown(struct fc_lport *lport) | ||
554 | { | ||
555 | printk(KERN_INFO "libfc: Link down on port (%6x)\n", | ||
556 | fc_host_port_id(lport->host)); | ||
557 | |||
558 | mutex_lock(&lport->lp_mutex); | ||
559 | __fc_linkdown(lport); | ||
530 | mutex_unlock(&lport->lp_mutex); | 560 | mutex_unlock(&lport->lp_mutex); |
531 | } | 561 | } |
532 | EXPORT_SYMBOL(fc_linkdown); | 562 | EXPORT_SYMBOL(fc_linkdown); |
@@ -654,6 +684,9 @@ static void fc_lport_enter_ready(struct fc_lport *lport) | |||
654 | fc_lport_state(lport)); | 684 | fc_lport_state(lport)); |
655 | 685 | ||
656 | fc_lport_state_enter(lport, LPORT_ST_READY); | 686 | fc_lport_state_enter(lport, LPORT_ST_READY); |
687 | if (lport->vport) | ||
688 | fc_vport_set_state(lport->vport, FC_VPORT_ACTIVE); | ||
689 | fc_vports_linkchange(lport); | ||
657 | 690 | ||
658 | if (!lport->ptp_rp) | 691 | if (!lport->ptp_rp) |
659 | lport->tt.disc_start(fc_lport_disc_callback, lport); | 692 | lport->tt.disc_start(fc_lport_disc_callback, lport); |
@@ -868,7 +901,14 @@ static void fc_lport_enter_reset(struct fc_lport *lport) | |||
868 | FC_LPORT_DBG(lport, "Entered RESET state from %s state\n", | 901 | FC_LPORT_DBG(lport, "Entered RESET state from %s state\n", |
869 | fc_lport_state(lport)); | 902 | fc_lport_state(lport)); |
870 | 903 | ||
904 | if (lport->vport) { | ||
905 | if (lport->link_up) | ||
906 | fc_vport_set_state(lport->vport, FC_VPORT_INITIALIZING); | ||
907 | else | ||
908 | fc_vport_set_state(lport->vport, FC_VPORT_LINKDOWN); | ||
909 | } | ||
871 | fc_lport_state_enter(lport, LPORT_ST_RESET); | 910 | fc_lport_state_enter(lport, LPORT_ST_RESET); |
911 | fc_vports_linkchange(lport); | ||
872 | fc_lport_reset_locked(lport); | 912 | fc_lport_reset_locked(lport); |
873 | if (lport->link_up) | 913 | if (lport->link_up) |
874 | fc_lport_enter_flogi(lport); | 914 | fc_lport_enter_flogi(lport); |
@@ -887,6 +927,7 @@ static void fc_lport_enter_disabled(struct fc_lport *lport) | |||
887 | fc_lport_state(lport)); | 927 | fc_lport_state(lport)); |
888 | 928 | ||
889 | fc_lport_state_enter(lport, LPORT_ST_DISABLED); | 929 | fc_lport_state_enter(lport, LPORT_ST_DISABLED); |
930 | fc_vports_linkchange(lport); | ||
890 | fc_lport_reset_locked(lport); | 931 | fc_lport_reset_locked(lport); |
891 | } | 932 | } |
892 | 933 | ||
@@ -1333,6 +1374,7 @@ static void fc_lport_enter_logo(struct fc_lport *lport) | |||
1333 | fc_lport_state(lport)); | 1374 | fc_lport_state(lport)); |
1334 | 1375 | ||
1335 | fc_lport_state_enter(lport, LPORT_ST_LOGO); | 1376 | fc_lport_state_enter(lport, LPORT_ST_LOGO); |
1377 | fc_vports_linkchange(lport); | ||
1336 | 1378 | ||
1337 | fp = fc_frame_alloc(lport, sizeof(*logo)); | 1379 | fp = fc_frame_alloc(lport, sizeof(*logo)); |
1338 | if (!fp) { | 1380 | if (!fp) { |
diff --git a/drivers/scsi/libfc/fc_npiv.c b/drivers/scsi/libfc/fc_npiv.c index 39f02c09a8d9..c68f6c7341c2 100644 --- a/drivers/scsi/libfc/fc_npiv.c +++ b/drivers/scsi/libfc/fc_npiv.c | |||
@@ -84,3 +84,78 @@ struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id) | |||
84 | return lport; | 84 | return lport; |
85 | } | 85 | } |
86 | 86 | ||
87 | /* | ||
88 | * When setting the link state of vports during an lport state change, it's | ||
89 | * necessary to hold the lp_mutex of both the N_Port and the VN_Port. | ||
90 | * This tells the lockdep engine to treat the nested locking of the VN_Port | ||
91 | * as a different lock class. | ||
92 | */ | ||
93 | enum libfc_lport_mutex_class { | ||
94 | LPORT_MUTEX_NORMAL = 0, | ||
95 | LPORT_MUTEX_VN_PORT = 1, | ||
96 | }; | ||
97 | |||
98 | /** | ||
99 | * __fc_vport_setlink() - update link and status on a VN_Port | ||
100 | * @n_port: parent N_Port | ||
101 | * @vn_port: VN_Port to update | ||
102 | * | ||
103 | * Locking: must be called with both the N_Port and VN_Port lp_mutex held | ||
104 | */ | ||
105 | static void __fc_vport_setlink(struct fc_lport *n_port, | ||
106 | struct fc_lport *vn_port) | ||
107 | { | ||
108 | struct fc_vport *vport = vn_port->vport; | ||
109 | |||
110 | if (vn_port->state == LPORT_ST_DISABLED) | ||
111 | return; | ||
112 | |||
113 | if (n_port->state == LPORT_ST_READY) { | ||
114 | if (n_port->npiv_enabled) { | ||
115 | fc_vport_set_state(vport, FC_VPORT_INITIALIZING); | ||
116 | __fc_linkup(vn_port); | ||
117 | } else { | ||
118 | fc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); | ||
119 | __fc_linkdown(vn_port); | ||
120 | } | ||
121 | } else { | ||
122 | fc_vport_set_state(vport, FC_VPORT_LINKDOWN); | ||
123 | __fc_linkdown(vn_port); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | * fc_vport_setlink() - update link and status on a VN_Port | ||
129 | * @vn_port: virtual port to update | ||
130 | */ | ||
131 | void fc_vport_setlink(struct fc_lport *vn_port) | ||
132 | { | ||
133 | struct fc_vport *vport = vn_port->vport; | ||
134 | struct Scsi_Host *shost = vport_to_shost(vport); | ||
135 | struct fc_lport *n_port = shost_priv(shost); | ||
136 | |||
137 | mutex_lock(&n_port->lp_mutex); | ||
138 | mutex_lock_nested(&vn_port->lp_mutex, LPORT_MUTEX_VN_PORT); | ||
139 | __fc_vport_setlink(n_port, vn_port); | ||
140 | mutex_unlock(&vn_port->lp_mutex); | ||
141 | mutex_unlock(&n_port->lp_mutex); | ||
142 | } | ||
143 | EXPORT_SYMBOL(fc_vport_setlink); | ||
144 | |||
145 | /** | ||
146 | * fc_vports_linkchange() - change the link state of all vports | ||
147 | * @n_port: Parent N_Port that has changed state | ||
148 | * | ||
149 | * Locking: called with the n_port lp_mutex held | ||
150 | */ | ||
151 | void fc_vports_linkchange(struct fc_lport *n_port) | ||
152 | { | ||
153 | struct fc_lport *vn_port; | ||
154 | |||
155 | list_for_each_entry(vn_port, &n_port->vports, list) { | ||
156 | mutex_lock_nested(&vn_port->lp_mutex, LPORT_MUTEX_VN_PORT); | ||
157 | __fc_vport_setlink(n_port, vn_port); | ||
158 | mutex_unlock(&vn_port->lp_mutex); | ||
159 | } | ||
160 | } | ||
161 | |||
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h index 2c6d55de8ccd..dfeb1ee4f03f 100644 --- a/include/scsi/libfc.h +++ b/include/scsi/libfc.h | |||
@@ -788,11 +788,13 @@ int fc_fabric_login(struct fc_lport *lp); | |||
788 | /* | 788 | /* |
789 | * The link is up for the given local port. | 789 | * The link is up for the given local port. |
790 | */ | 790 | */ |
791 | void __fc_linkup(struct fc_lport *); | ||
791 | void fc_linkup(struct fc_lport *); | 792 | void fc_linkup(struct fc_lport *); |
792 | 793 | ||
793 | /* | 794 | /* |
794 | * Link is down for the given local port. | 795 | * Link is down for the given local port. |
795 | */ | 796 | */ |
797 | void __fc_linkdown(struct fc_lport *); | ||
796 | void fc_linkdown(struct fc_lport *); | 798 | void fc_linkdown(struct fc_lport *); |
797 | 799 | ||
798 | /* | 800 | /* |
@@ -821,6 +823,12 @@ struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize); | |||
821 | struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id); | 823 | struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id); |
822 | 824 | ||
823 | /* | 825 | /* |
826 | * NPIV VN_Port link state management | ||
827 | */ | ||
828 | void fc_vport_setlink(struct fc_lport *vn_port); | ||
829 | void fc_vports_linkchange(struct fc_lport *n_port); | ||
830 | |||
831 | /* | ||
824 | * REMOTE PORT LAYER | 832 | * REMOTE PORT LAYER |
825 | *****************************/ | 833 | *****************************/ |
826 | int fc_rport_init(struct fc_lport *lp); | 834 | int fc_rport_init(struct fc_lport *lp); |