diff options
Diffstat (limited to 'drivers/scsi/libfc')
-rw-r--r-- | drivers/scsi/libfc/Makefile | 4 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_disc.c | 85 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_elsct.c | 79 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_exch.c | 932 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_fcp.c | 1044 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_frame.c | 13 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_libfc.c | 134 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_libfc.h | 112 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_lport.c | 853 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_npiv.c | 161 | ||||
-rw-r--r-- | drivers/scsi/libfc/fc_rport.c | 409 |
11 files changed, 2538 insertions, 1288 deletions
diff --git a/drivers/scsi/libfc/Makefile b/drivers/scsi/libfc/Makefile index 55f982de3a9a..4bb23ac86a5c 100644 --- a/drivers/scsi/libfc/Makefile +++ b/drivers/scsi/libfc/Makefile | |||
@@ -3,10 +3,12 @@ | |||
3 | obj-$(CONFIG_LIBFC) += libfc.o | 3 | obj-$(CONFIG_LIBFC) += libfc.o |
4 | 4 | ||
5 | libfc-objs := \ | 5 | libfc-objs := \ |
6 | fc_libfc.o \ | ||
6 | fc_disc.o \ | 7 | fc_disc.o \ |
7 | fc_exch.o \ | 8 | fc_exch.o \ |
8 | fc_elsct.o \ | 9 | fc_elsct.o \ |
9 | fc_frame.o \ | 10 | fc_frame.o \ |
10 | fc_lport.o \ | 11 | fc_lport.o \ |
11 | fc_rport.o \ | 12 | fc_rport.o \ |
12 | fc_fcp.o | 13 | fc_fcp.o \ |
14 | fc_npiv.o | ||
diff --git a/drivers/scsi/libfc/fc_disc.c b/drivers/scsi/libfc/fc_disc.c index c48799e9dd8e..9b0a5192a965 100644 --- a/drivers/scsi/libfc/fc_disc.c +++ b/drivers/scsi/libfc/fc_disc.c | |||
@@ -40,6 +40,8 @@ | |||
40 | 40 | ||
41 | #include <scsi/libfc.h> | 41 | #include <scsi/libfc.h> |
42 | 42 | ||
43 | #include "fc_libfc.h" | ||
44 | |||
43 | #define FC_DISC_RETRY_LIMIT 3 /* max retries */ | 45 | #define FC_DISC_RETRY_LIMIT 3 /* max retries */ |
44 | #define FC_DISC_RETRY_DELAY 500UL /* (msecs) delay */ | 46 | #define FC_DISC_RETRY_DELAY 500UL /* (msecs) delay */ |
45 | 47 | ||
@@ -51,8 +53,8 @@ static int fc_disc_single(struct fc_lport *, struct fc_disc_port *); | |||
51 | static void fc_disc_restart(struct fc_disc *); | 53 | static void fc_disc_restart(struct fc_disc *); |
52 | 54 | ||
53 | /** | 55 | /** |
54 | * fc_disc_stop_rports() - delete all the remote ports associated with the lport | 56 | * fc_disc_stop_rports() - Delete all the remote ports associated with the lport |
55 | * @disc: The discovery job to stop rports on | 57 | * @disc: The discovery job to stop remote ports on |
56 | * | 58 | * |
57 | * Locking Note: This function expects that the lport mutex is locked before | 59 | * Locking Note: This function expects that the lport mutex is locked before |
58 | * calling it. | 60 | * calling it. |
@@ -72,9 +74,9 @@ void fc_disc_stop_rports(struct fc_disc *disc) | |||
72 | 74 | ||
73 | /** | 75 | /** |
74 | * fc_disc_recv_rscn_req() - Handle Registered State Change Notification (RSCN) | 76 | * fc_disc_recv_rscn_req() - Handle Registered State Change Notification (RSCN) |
75 | * @sp: Current sequence of the RSCN exchange | 77 | * @sp: The sequence of the RSCN exchange |
76 | * @fp: RSCN Frame | 78 | * @fp: The RSCN frame |
77 | * @lport: Fibre Channel host port instance | 79 | * @lport: The local port that the request will be sent on |
78 | * | 80 | * |
79 | * Locking Note: This function expects that the disc_mutex is locked | 81 | * Locking Note: This function expects that the disc_mutex is locked |
80 | * before it is called. | 82 | * before it is called. |
@@ -183,9 +185,9 @@ reject: | |||
183 | 185 | ||
184 | /** | 186 | /** |
185 | * fc_disc_recv_req() - Handle incoming requests | 187 | * fc_disc_recv_req() - Handle incoming requests |
186 | * @sp: Current sequence of the request exchange | 188 | * @sp: The sequence of the request exchange |
187 | * @fp: The frame | 189 | * @fp: The request frame |
188 | * @lport: The FC local port | 190 | * @lport: The local port receiving the request |
189 | * | 191 | * |
190 | * Locking Note: This function is called from the EM and will lock | 192 | * Locking Note: This function is called from the EM and will lock |
191 | * the disc_mutex before calling the handler for the | 193 | * the disc_mutex before calling the handler for the |
@@ -213,7 +215,7 @@ static void fc_disc_recv_req(struct fc_seq *sp, struct fc_frame *fp, | |||
213 | 215 | ||
214 | /** | 216 | /** |
215 | * fc_disc_restart() - Restart discovery | 217 | * fc_disc_restart() - Restart discovery |
216 | * @lport: FC discovery context | 218 | * @disc: The discovery object to be restarted |
217 | * | 219 | * |
218 | * Locking Note: This function expects that the disc mutex | 220 | * Locking Note: This function expects that the disc mutex |
219 | * is already locked. | 221 | * is already locked. |
@@ -240,9 +242,9 @@ static void fc_disc_restart(struct fc_disc *disc) | |||
240 | } | 242 | } |
241 | 243 | ||
242 | /** | 244 | /** |
243 | * fc_disc_start() - Fibre Channel Target discovery | 245 | * fc_disc_start() - Start discovery on a local port |
244 | * @lport: FC local port | 246 | * @lport: The local port to have discovery started on |
245 | * @disc_callback: function to be called when discovery is complete | 247 | * @disc_callback: Callback function to be called when discovery is complete |
246 | */ | 248 | */ |
247 | static void fc_disc_start(void (*disc_callback)(struct fc_lport *, | 249 | static void fc_disc_start(void (*disc_callback)(struct fc_lport *, |
248 | enum fc_disc_event), | 250 | enum fc_disc_event), |
@@ -263,8 +265,8 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *, | |||
263 | 265 | ||
264 | /** | 266 | /** |
265 | * fc_disc_done() - Discovery has been completed | 267 | * fc_disc_done() - Discovery has been completed |
266 | * @disc: FC discovery context | 268 | * @disc: The discovery context |
267 | * @event: discovery completion status | 269 | * @event: The discovery completion status |
268 | * | 270 | * |
269 | * Locking Note: This function expects that the disc mutex is locked before | 271 | * Locking Note: This function expects that the disc mutex is locked before |
270 | * it is called. The discovery callback is then made with the lock released, | 272 | * it is called. The discovery callback is then made with the lock released, |
@@ -284,8 +286,8 @@ static void fc_disc_done(struct fc_disc *disc, enum fc_disc_event event) | |||
284 | } | 286 | } |
285 | 287 | ||
286 | /* | 288 | /* |
287 | * Go through all remote ports. If they were found in the latest | 289 | * Go through all remote ports. If they were found in the latest |
288 | * discovery, reverify or log them in. Otherwise, log them out. | 290 | * discovery, reverify or log them in. Otherwise, log them out. |
289 | * Skip ports which were never discovered. These are the dNS port | 291 | * Skip ports which were never discovered. These are the dNS port |
290 | * and ports which were created by PLOGI. | 292 | * and ports which were created by PLOGI. |
291 | */ | 293 | */ |
@@ -305,8 +307,8 @@ static void fc_disc_done(struct fc_disc *disc, enum fc_disc_event event) | |||
305 | 307 | ||
306 | /** | 308 | /** |
307 | * fc_disc_error() - Handle error on dNS request | 309 | * fc_disc_error() - Handle error on dNS request |
308 | * @disc: FC discovery context | 310 | * @disc: The discovery context |
309 | * @fp: The frame pointer | 311 | * @fp: The error code encoded as a frame pointer |
310 | */ | 312 | */ |
311 | static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp) | 313 | static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp) |
312 | { | 314 | { |
@@ -342,7 +344,7 @@ static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp) | |||
342 | 344 | ||
343 | /** | 345 | /** |
344 | * fc_disc_gpn_ft_req() - Send Get Port Names by FC-4 type (GPN_FT) request | 346 | * fc_disc_gpn_ft_req() - Send Get Port Names by FC-4 type (GPN_FT) request |
345 | * @lport: FC discovery context | 347 | * @lport: The discovery context |
346 | * | 348 | * |
347 | * Locking Note: This function expects that the disc_mutex is locked | 349 | * Locking Note: This function expects that the disc_mutex is locked |
348 | * before it is called. | 350 | * before it is called. |
@@ -368,17 +370,17 @@ static void fc_disc_gpn_ft_req(struct fc_disc *disc) | |||
368 | if (lport->tt.elsct_send(lport, 0, fp, | 370 | if (lport->tt.elsct_send(lport, 0, fp, |
369 | FC_NS_GPN_FT, | 371 | FC_NS_GPN_FT, |
370 | fc_disc_gpn_ft_resp, | 372 | fc_disc_gpn_ft_resp, |
371 | disc, lport->e_d_tov)) | 373 | disc, 3 * lport->r_a_tov)) |
372 | return; | 374 | return; |
373 | err: | 375 | err: |
374 | fc_disc_error(disc, fp); | 376 | fc_disc_error(disc, NULL); |
375 | } | 377 | } |
376 | 378 | ||
377 | /** | 379 | /** |
378 | * fc_disc_gpn_ft_parse() - Parse the body of the dNS GPN_FT response. | 380 | * fc_disc_gpn_ft_parse() - Parse the body of the dNS GPN_FT response. |
379 | * @lport: Fibre Channel host port instance | 381 | * @lport: The local port the GPN_FT was received on |
380 | * @buf: GPN_FT response buffer | 382 | * @buf: The GPN_FT response buffer |
381 | * @len: size of response buffer | 383 | * @len: The size of response buffer |
382 | * | 384 | * |
383 | * Goes through the list of IDs and names resulting from a request. | 385 | * Goes through the list of IDs and names resulting from a request. |
384 | */ | 386 | */ |
@@ -477,10 +479,8 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len) | |||
477 | } | 479 | } |
478 | 480 | ||
479 | /** | 481 | /** |
480 | * fc_disc_timeout() - Retry handler for the disc component | 482 | * fc_disc_timeout() - Handler for discovery timeouts |
481 | * @work: Structure holding disc obj that needs retry discovery | 483 | * @work: Structure holding discovery context that needs to retry discovery |
482 | * | ||
483 | * Handle retry of memory allocation for remote ports. | ||
484 | */ | 484 | */ |
485 | static void fc_disc_timeout(struct work_struct *work) | 485 | static void fc_disc_timeout(struct work_struct *work) |
486 | { | 486 | { |
@@ -494,9 +494,9 @@ static void fc_disc_timeout(struct work_struct *work) | |||
494 | 494 | ||
495 | /** | 495 | /** |
496 | * fc_disc_gpn_ft_resp() - Handle a response frame from Get Port Names (GPN_FT) | 496 | * fc_disc_gpn_ft_resp() - Handle a response frame from Get Port Names (GPN_FT) |
497 | * @sp: Current sequence of GPN_FT exchange | 497 | * @sp: The sequence that the GPN_FT response was received on |
498 | * @fp: response frame | 498 | * @fp: The GPN_FT response frame |
499 | * @lp_arg: Fibre Channel host port instance | 499 | * @lp_arg: The discovery context |
500 | * | 500 | * |
501 | * Locking Note: This function is called without disc mutex held, and | 501 | * Locking Note: This function is called without disc mutex held, and |
502 | * should do all its processing with the mutex held | 502 | * should do all its processing with the mutex held |
@@ -567,9 +567,9 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp, | |||
567 | 567 | ||
568 | /** | 568 | /** |
569 | * fc_disc_gpn_id_resp() - Handle a response frame from Get Port Names (GPN_ID) | 569 | * fc_disc_gpn_id_resp() - Handle a response frame from Get Port Names (GPN_ID) |
570 | * @sp: exchange sequence | 570 | * @sp: The sequence the GPN_ID is on |
571 | * @fp: response frame | 571 | * @fp: The response frame |
572 | * @rdata_arg: remote port private data | 572 | * @rdata_arg: The remote port that sent the GPN_ID response |
573 | * | 573 | * |
574 | * Locking Note: This function is called without disc mutex held. | 574 | * Locking Note: This function is called without disc mutex held. |
575 | */ | 575 | */ |
@@ -637,7 +637,7 @@ out: | |||
637 | 637 | ||
638 | /** | 638 | /** |
639 | * fc_disc_gpn_id_req() - Send Get Port Names by ID (GPN_ID) request | 639 | * fc_disc_gpn_id_req() - Send Get Port Names by ID (GPN_ID) request |
640 | * @lport: local port | 640 | * @lport: The local port to initiate discovery on |
641 | * @rdata: remote port private data | 641 | * @rdata: remote port private data |
642 | * | 642 | * |
643 | * Locking Note: This function expects that the disc_mutex is locked | 643 | * Locking Note: This function expects that the disc_mutex is locked |
@@ -654,7 +654,8 @@ static int fc_disc_gpn_id_req(struct fc_lport *lport, | |||
654 | if (!fp) | 654 | if (!fp) |
655 | return -ENOMEM; | 655 | return -ENOMEM; |
656 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, FC_NS_GPN_ID, | 656 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, FC_NS_GPN_ID, |
657 | fc_disc_gpn_id_resp, rdata, lport->e_d_tov)) | 657 | fc_disc_gpn_id_resp, rdata, |
658 | 3 * lport->r_a_tov)) | ||
658 | return -ENOMEM; | 659 | return -ENOMEM; |
659 | kref_get(&rdata->kref); | 660 | kref_get(&rdata->kref); |
660 | return 0; | 661 | return 0; |
@@ -662,8 +663,8 @@ static int fc_disc_gpn_id_req(struct fc_lport *lport, | |||
662 | 663 | ||
663 | /** | 664 | /** |
664 | * fc_disc_single() - Discover the directory information for a single target | 665 | * fc_disc_single() - Discover the directory information for a single target |
665 | * @lport: local port | 666 | * @lport: The local port the remote port is associated with |
666 | * @dp: The port to rediscover | 667 | * @dp: The port to rediscover |
667 | * | 668 | * |
668 | * Locking Note: This function expects that the disc_mutex is locked | 669 | * Locking Note: This function expects that the disc_mutex is locked |
669 | * before it is called. | 670 | * before it is called. |
@@ -681,7 +682,7 @@ static int fc_disc_single(struct fc_lport *lport, struct fc_disc_port *dp) | |||
681 | 682 | ||
682 | /** | 683 | /** |
683 | * fc_disc_stop() - Stop discovery for a given lport | 684 | * fc_disc_stop() - Stop discovery for a given lport |
684 | * @lport: The lport that discovery should stop for | 685 | * @lport: The local port that discovery should stop on |
685 | */ | 686 | */ |
686 | void fc_disc_stop(struct fc_lport *lport) | 687 | void fc_disc_stop(struct fc_lport *lport) |
687 | { | 688 | { |
@@ -695,7 +696,7 @@ void fc_disc_stop(struct fc_lport *lport) | |||
695 | 696 | ||
696 | /** | 697 | /** |
697 | * fc_disc_stop_final() - Stop discovery for a given lport | 698 | * fc_disc_stop_final() - Stop discovery for a given lport |
698 | * @lport: The lport that discovery should stop for | 699 | * @lport: The lport that discovery should stop on |
699 | * | 700 | * |
700 | * This function will block until discovery has been | 701 | * This function will block until discovery has been |
701 | * completely stopped and all rports have been deleted. | 702 | * completely stopped and all rports have been deleted. |
@@ -707,8 +708,8 @@ void fc_disc_stop_final(struct fc_lport *lport) | |||
707 | } | 708 | } |
708 | 709 | ||
709 | /** | 710 | /** |
710 | * fc_disc_init() - Initialize the discovery block | 711 | * fc_disc_init() - Initialize the discovery layer for a local port |
711 | * @lport: FC local port | 712 | * @lport: The local port that needs the discovery layer to be initialized |
712 | */ | 713 | */ |
713 | int fc_disc_init(struct fc_lport *lport) | 714 | int fc_disc_init(struct fc_lport *lport) |
714 | { | 715 | { |
diff --git a/drivers/scsi/libfc/fc_elsct.c b/drivers/scsi/libfc/fc_elsct.c index 5cfa68732e9d..53748724f2c5 100644 --- a/drivers/scsi/libfc/fc_elsct.c +++ b/drivers/scsi/libfc/fc_elsct.c | |||
@@ -28,17 +28,22 @@ | |||
28 | #include <scsi/libfc.h> | 28 | #include <scsi/libfc.h> |
29 | #include <scsi/fc_encode.h> | 29 | #include <scsi/fc_encode.h> |
30 | 30 | ||
31 | /* | 31 | /** |
32 | * fc_elsct_send - sends ELS/CT frame | 32 | * fc_elsct_send() - Send an ELS or CT frame |
33 | * @lport: The local port to send the frame on | ||
34 | * @did: The destination ID for the frame | ||
35 | * @fp: The frame to be sent | ||
36 | * @op: The operational code | ||
37 | * @resp: The callback routine when the response is received | ||
38 | * @arg: The argument to pass to the response callback routine | ||
39 | * @timer_msec: The timeout period for the frame (in msecs) | ||
33 | */ | 40 | */ |
34 | static struct fc_seq *fc_elsct_send(struct fc_lport *lport, | 41 | struct fc_seq *fc_elsct_send(struct fc_lport *lport, u32 did, |
35 | u32 did, | 42 | struct fc_frame *fp, unsigned int op, |
36 | struct fc_frame *fp, | 43 | void (*resp)(struct fc_seq *, |
37 | unsigned int op, | 44 | struct fc_frame *, |
38 | void (*resp)(struct fc_seq *, | 45 | void *), |
39 | struct fc_frame *fp, | 46 | void *arg, u32 timer_msec) |
40 | void *arg), | ||
41 | void *arg, u32 timer_msec) | ||
42 | { | 47 | { |
43 | enum fc_rctl r_ctl; | 48 | enum fc_rctl r_ctl; |
44 | enum fc_fh_type fh_type; | 49 | enum fc_fh_type fh_type; |
@@ -53,15 +58,22 @@ static struct fc_seq *fc_elsct_send(struct fc_lport *lport, | |||
53 | did = FC_FID_DIR_SERV; | 58 | did = FC_FID_DIR_SERV; |
54 | } | 59 | } |
55 | 60 | ||
56 | if (rc) | 61 | if (rc) { |
62 | fc_frame_free(fp); | ||
57 | return NULL; | 63 | return NULL; |
64 | } | ||
58 | 65 | ||
59 | fc_fill_fc_hdr(fp, r_ctl, did, fc_host_port_id(lport->host), fh_type, | 66 | fc_fill_fc_hdr(fp, r_ctl, did, fc_host_port_id(lport->host), fh_type, |
60 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); | 67 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
61 | 68 | ||
62 | return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec); | 69 | return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec); |
63 | } | 70 | } |
71 | EXPORT_SYMBOL(fc_elsct_send); | ||
64 | 72 | ||
73 | /** | ||
74 | * fc_elsct_init() - Initialize the ELS/CT layer | ||
75 | * @lport: The local port to initialize the ELS/CT layer for | ||
76 | */ | ||
65 | int fc_elsct_init(struct fc_lport *lport) | 77 | int fc_elsct_init(struct fc_lport *lport) |
66 | { | 78 | { |
67 | if (!lport->tt.elsct_send) | 79 | if (!lport->tt.elsct_send) |
@@ -72,12 +84,15 @@ int fc_elsct_init(struct fc_lport *lport) | |||
72 | EXPORT_SYMBOL(fc_elsct_init); | 84 | EXPORT_SYMBOL(fc_elsct_init); |
73 | 85 | ||
74 | /** | 86 | /** |
75 | * fc_els_resp_type() - return string describing ELS response for debug. | 87 | * fc_els_resp_type() - Return a string describing the ELS response |
76 | * @fp: frame pointer with possible error code. | 88 | * @fp: The frame pointer or possible error code |
77 | */ | 89 | */ |
78 | const char *fc_els_resp_type(struct fc_frame *fp) | 90 | const char *fc_els_resp_type(struct fc_frame *fp) |
79 | { | 91 | { |
80 | const char *msg; | 92 | const char *msg; |
93 | struct fc_frame_header *fh; | ||
94 | struct fc_ct_hdr *ct; | ||
95 | |||
81 | if (IS_ERR(fp)) { | 96 | if (IS_ERR(fp)) { |
82 | switch (-PTR_ERR(fp)) { | 97 | switch (-PTR_ERR(fp)) { |
83 | case FC_NO_ERR: | 98 | case FC_NO_ERR: |
@@ -94,15 +109,41 @@ const char *fc_els_resp_type(struct fc_frame *fp) | |||
94 | break; | 109 | break; |
95 | } | 110 | } |
96 | } else { | 111 | } else { |
97 | switch (fc_frame_payload_op(fp)) { | 112 | fh = fc_frame_header_get(fp); |
98 | case ELS_LS_ACC: | 113 | switch (fh->fh_type) { |
99 | msg = "accept"; | 114 | case FC_TYPE_ELS: |
115 | switch (fc_frame_payload_op(fp)) { | ||
116 | case ELS_LS_ACC: | ||
117 | msg = "accept"; | ||
118 | break; | ||
119 | case ELS_LS_RJT: | ||
120 | msg = "reject"; | ||
121 | break; | ||
122 | default: | ||
123 | msg = "response unknown ELS"; | ||
124 | break; | ||
125 | } | ||
100 | break; | 126 | break; |
101 | case ELS_LS_RJT: | 127 | case FC_TYPE_CT: |
102 | msg = "reject"; | 128 | ct = fc_frame_payload_get(fp, sizeof(*ct)); |
129 | if (ct) { | ||
130 | switch (ntohs(ct->ct_cmd)) { | ||
131 | case FC_FS_ACC: | ||
132 | msg = "CT accept"; | ||
133 | break; | ||
134 | case FC_FS_RJT: | ||
135 | msg = "CT reject"; | ||
136 | break; | ||
137 | default: | ||
138 | msg = "response unknown CT"; | ||
139 | break; | ||
140 | } | ||
141 | } else { | ||
142 | msg = "short CT response"; | ||
143 | } | ||
103 | break; | 144 | break; |
104 | default: | 145 | default: |
105 | msg = "response unknown ELS"; | 146 | msg = "response not ELS or CT"; |
106 | break; | 147 | break; |
107 | } | 148 | } |
108 | } | 149 | } |
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c index c1c15748220c..19d711cb938c 100644 --- a/drivers/scsi/libfc/fc_exch.c +++ b/drivers/scsi/libfc/fc_exch.c | |||
@@ -32,10 +32,13 @@ | |||
32 | #include <scsi/libfc.h> | 32 | #include <scsi/libfc.h> |
33 | #include <scsi/fc_encode.h> | 33 | #include <scsi/fc_encode.h> |
34 | 34 | ||
35 | #include "fc_libfc.h" | ||
36 | |||
35 | u16 fc_cpu_mask; /* cpu mask for possible cpus */ | 37 | u16 fc_cpu_mask; /* cpu mask for possible cpus */ |
36 | EXPORT_SYMBOL(fc_cpu_mask); | 38 | EXPORT_SYMBOL(fc_cpu_mask); |
37 | static u16 fc_cpu_order; /* 2's power to represent total possible cpus */ | 39 | static u16 fc_cpu_order; /* 2's power to represent total possible cpus */ |
38 | static struct kmem_cache *fc_em_cachep; /* cache for exchanges */ | 40 | static struct kmem_cache *fc_em_cachep; /* cache for exchanges */ |
41 | struct workqueue_struct *fc_exch_workqueue; | ||
39 | 42 | ||
40 | /* | 43 | /* |
41 | * Structure and function definitions for managing Fibre Channel Exchanges | 44 | * Structure and function definitions for managing Fibre Channel Exchanges |
@@ -50,35 +53,46 @@ static struct kmem_cache *fc_em_cachep; /* cache for exchanges */ | |||
50 | * fc_seq holds the state for an individual sequence. | 53 | * fc_seq holds the state for an individual sequence. |
51 | */ | 54 | */ |
52 | 55 | ||
53 | /* | 56 | /** |
54 | * Per cpu exchange pool | 57 | * struct fc_exch_pool - Per cpu exchange pool |
58 | * @next_index: Next possible free exchange index | ||
59 | * @total_exches: Total allocated exchanges | ||
60 | * @lock: Exch pool lock | ||
61 | * @ex_list: List of exchanges | ||
55 | * | 62 | * |
56 | * This structure manages per cpu exchanges in array of exchange pointers. | 63 | * This structure manages per cpu exchanges in array of exchange pointers. |
57 | * This array is allocated followed by struct fc_exch_pool memory for | 64 | * This array is allocated followed by struct fc_exch_pool memory for |
58 | * assigned range of exchanges to per cpu pool. | 65 | * assigned range of exchanges to per cpu pool. |
59 | */ | 66 | */ |
60 | struct fc_exch_pool { | 67 | struct fc_exch_pool { |
61 | u16 next_index; /* next possible free exchange index */ | 68 | u16 next_index; |
62 | u16 total_exches; /* total allocated exchanges */ | 69 | u16 total_exches; |
63 | spinlock_t lock; /* exch pool lock */ | 70 | spinlock_t lock; |
64 | struct list_head ex_list; /* allocated exchanges list */ | 71 | struct list_head ex_list; |
65 | }; | 72 | }; |
66 | 73 | ||
67 | /* | 74 | /** |
68 | * Exchange manager. | 75 | * struct fc_exch_mgr - The Exchange Manager (EM). |
76 | * @class: Default class for new sequences | ||
77 | * @kref: Reference counter | ||
78 | * @min_xid: Minimum exchange ID | ||
79 | * @max_xid: Maximum exchange ID | ||
80 | * @ep_pool: Reserved exchange pointers | ||
81 | * @pool_max_index: Max exch array index in exch pool | ||
82 | * @pool: Per cpu exch pool | ||
83 | * @stats: Statistics structure | ||
69 | * | 84 | * |
70 | * This structure is the center for creating exchanges and sequences. | 85 | * This structure is the center for creating exchanges and sequences. |
71 | * It manages the allocation of exchange IDs. | 86 | * It manages the allocation of exchange IDs. |
72 | */ | 87 | */ |
73 | struct fc_exch_mgr { | 88 | struct fc_exch_mgr { |
74 | enum fc_class class; /* default class for sequences */ | 89 | enum fc_class class; |
75 | struct kref kref; /* exchange mgr reference count */ | 90 | struct kref kref; |
76 | u16 min_xid; /* min exchange ID */ | 91 | u16 min_xid; |
77 | u16 max_xid; /* max exchange ID */ | 92 | u16 max_xid; |
78 | struct list_head ex_list; /* allocated exchanges list */ | 93 | mempool_t *ep_pool; |
79 | mempool_t *ep_pool; /* reserve ep's */ | 94 | u16 pool_max_index; |
80 | u16 pool_max_index; /* max exch array index in exch pool */ | 95 | struct fc_exch_pool *pool; |
81 | struct fc_exch_pool *pool; /* per cpu exch pool */ | ||
82 | 96 | ||
83 | /* | 97 | /* |
84 | * currently exchange mgr stats are updated but not used. | 98 | * currently exchange mgr stats are updated but not used. |
@@ -96,6 +110,18 @@ struct fc_exch_mgr { | |||
96 | }; | 110 | }; |
97 | #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq) | 111 | #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq) |
98 | 112 | ||
113 | /** | ||
114 | * struct fc_exch_mgr_anchor - primary structure for list of EMs | ||
115 | * @ema_list: Exchange Manager Anchor list | ||
116 | * @mp: Exchange Manager associated with this anchor | ||
117 | * @match: Routine to determine if this anchor's EM should be used | ||
118 | * | ||
119 | * When walking the list of anchors the match routine will be called | ||
120 | * for each anchor to determine if that EM should be used. The last | ||
121 | * anchor in the list will always match to handle any exchanges not | ||
122 | * handled by other EMs. The non-default EMs would be added to the | ||
123 | * anchor list by HW that provides FCoE offloads. | ||
124 | */ | ||
99 | struct fc_exch_mgr_anchor { | 125 | struct fc_exch_mgr_anchor { |
100 | struct list_head ema_list; | 126 | struct list_head ema_list; |
101 | struct fc_exch_mgr *mp; | 127 | struct fc_exch_mgr *mp; |
@@ -108,7 +134,6 @@ static void fc_seq_ls_rjt(struct fc_seq *, enum fc_els_rjt_reason, | |||
108 | enum fc_els_rjt_explan); | 134 | enum fc_els_rjt_explan); |
109 | static void fc_exch_els_rec(struct fc_seq *, struct fc_frame *); | 135 | static void fc_exch_els_rec(struct fc_seq *, struct fc_frame *); |
110 | static void fc_exch_els_rrq(struct fc_seq *, struct fc_frame *); | 136 | static void fc_exch_els_rrq(struct fc_seq *, struct fc_frame *); |
111 | static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp); | ||
112 | 137 | ||
113 | /* | 138 | /* |
114 | * Internal implementation notes. | 139 | * Internal implementation notes. |
@@ -196,6 +221,15 @@ static char *fc_exch_rctl_names[] = FC_RCTL_NAMES_INIT; | |||
196 | 221 | ||
197 | #define FC_TABLE_SIZE(x) (sizeof(x) / sizeof(x[0])) | 222 | #define FC_TABLE_SIZE(x) (sizeof(x) / sizeof(x[0])) |
198 | 223 | ||
224 | /** | ||
225 | * fc_exch_name_lookup() - Lookup name by opcode | ||
226 | * @op: Opcode to be looked up | ||
227 | * @table: Opcode/name table | ||
228 | * @max_index: Index not to be exceeded | ||
229 | * | ||
230 | * This routine is used to determine a human-readable string identifying | ||
231 | * a R_CTL opcode. | ||
232 | */ | ||
199 | static inline const char *fc_exch_name_lookup(unsigned int op, char **table, | 233 | static inline const char *fc_exch_name_lookup(unsigned int op, char **table, |
200 | unsigned int max_index) | 234 | unsigned int max_index) |
201 | { | 235 | { |
@@ -208,25 +242,34 @@ static inline const char *fc_exch_name_lookup(unsigned int op, char **table, | |||
208 | return name; | 242 | return name; |
209 | } | 243 | } |
210 | 244 | ||
245 | /** | ||
246 | * fc_exch_rctl_name() - Wrapper routine for fc_exch_name_lookup() | ||
247 | * @op: The opcode to be looked up | ||
248 | */ | ||
211 | static const char *fc_exch_rctl_name(unsigned int op) | 249 | static const char *fc_exch_rctl_name(unsigned int op) |
212 | { | 250 | { |
213 | return fc_exch_name_lookup(op, fc_exch_rctl_names, | 251 | return fc_exch_name_lookup(op, fc_exch_rctl_names, |
214 | FC_TABLE_SIZE(fc_exch_rctl_names)); | 252 | FC_TABLE_SIZE(fc_exch_rctl_names)); |
215 | } | 253 | } |
216 | 254 | ||
217 | /* | 255 | /** |
218 | * Hold an exchange - keep it from being freed. | 256 | * fc_exch_hold() - Increment an exchange's reference count |
257 | * @ep: Echange to be held | ||
219 | */ | 258 | */ |
220 | static void fc_exch_hold(struct fc_exch *ep) | 259 | static inline void fc_exch_hold(struct fc_exch *ep) |
221 | { | 260 | { |
222 | atomic_inc(&ep->ex_refcnt); | 261 | atomic_inc(&ep->ex_refcnt); |
223 | } | 262 | } |
224 | 263 | ||
225 | /* | 264 | /** |
226 | * setup fc hdr by initializing few more FC header fields and sof/eof. | 265 | * fc_exch_setup_hdr() - Initialize a FC header by initializing some fields |
227 | * Initialized fields by this func: | 266 | * and determine SOF and EOF. |
228 | * - fh_ox_id, fh_rx_id, fh_seq_id, fh_seq_cnt | 267 | * @ep: The exchange to that will use the header |
229 | * - sof and eof | 268 | * @fp: The frame whose header is to be modified |
269 | * @f_ctl: F_CTL bits that will be used for the frame header | ||
270 | * | ||
271 | * The fields initialized by this routine are: fh_ox_id, fh_rx_id, | ||
272 | * fh_seq_id, fh_seq_cnt and the SOF and EOF. | ||
230 | */ | 273 | */ |
231 | static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp, | 274 | static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp, |
232 | u32 f_ctl) | 275 | u32 f_ctl) |
@@ -243,7 +286,7 @@ static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp, | |||
243 | if (fc_sof_needs_ack(ep->class)) | 286 | if (fc_sof_needs_ack(ep->class)) |
244 | fr_eof(fp) = FC_EOF_N; | 287 | fr_eof(fp) = FC_EOF_N; |
245 | /* | 288 | /* |
246 | * Form f_ctl. | 289 | * From F_CTL. |
247 | * The number of fill bytes to make the length a 4-byte | 290 | * The number of fill bytes to make the length a 4-byte |
248 | * multiple is the low order 2-bits of the f_ctl. | 291 | * multiple is the low order 2-bits of the f_ctl. |
249 | * The fill itself will have been cleared by the frame | 292 | * The fill itself will have been cleared by the frame |
@@ -273,10 +316,12 @@ static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp, | |||
273 | fh->fh_seq_cnt = htons(ep->seq.cnt); | 316 | fh->fh_seq_cnt = htons(ep->seq.cnt); |
274 | } | 317 | } |
275 | 318 | ||
276 | 319 | /** | |
277 | /* | 320 | * fc_exch_release() - Decrement an exchange's reference count |
278 | * Release a reference to an exchange. | 321 | * @ep: Exchange to be released |
279 | * If the refcnt goes to zero and the exchange is complete, it is freed. | 322 | * |
323 | * If the reference count reaches zero and the exchange is complete, | ||
324 | * it is freed. | ||
280 | */ | 325 | */ |
281 | static void fc_exch_release(struct fc_exch *ep) | 326 | static void fc_exch_release(struct fc_exch *ep) |
282 | { | 327 | { |
@@ -291,6 +336,10 @@ static void fc_exch_release(struct fc_exch *ep) | |||
291 | } | 336 | } |
292 | } | 337 | } |
293 | 338 | ||
339 | /** | ||
340 | * fc_exch_done_locked() - Complete an exchange with the exchange lock held | ||
341 | * @ep: The exchange that is complete | ||
342 | */ | ||
294 | static int fc_exch_done_locked(struct fc_exch *ep) | 343 | static int fc_exch_done_locked(struct fc_exch *ep) |
295 | { | 344 | { |
296 | int rc = 1; | 345 | int rc = 1; |
@@ -315,6 +364,15 @@ static int fc_exch_done_locked(struct fc_exch *ep) | |||
315 | return rc; | 364 | return rc; |
316 | } | 365 | } |
317 | 366 | ||
367 | /** | ||
368 | * fc_exch_ptr_get() - Return an exchange from an exchange pool | ||
369 | * @pool: Exchange Pool to get an exchange from | ||
370 | * @index: Index of the exchange within the pool | ||
371 | * | ||
372 | * Use the index to get an exchange from within an exchange pool. exches | ||
373 | * will point to an array of exchange pointers. The index will select | ||
374 | * the exchange within the array. | ||
375 | */ | ||
318 | static inline struct fc_exch *fc_exch_ptr_get(struct fc_exch_pool *pool, | 376 | static inline struct fc_exch *fc_exch_ptr_get(struct fc_exch_pool *pool, |
319 | u16 index) | 377 | u16 index) |
320 | { | 378 | { |
@@ -322,12 +380,22 @@ static inline struct fc_exch *fc_exch_ptr_get(struct fc_exch_pool *pool, | |||
322 | return exches[index]; | 380 | return exches[index]; |
323 | } | 381 | } |
324 | 382 | ||
383 | /** | ||
384 | * fc_exch_ptr_set() - Assign an exchange to a slot in an exchange pool | ||
385 | * @pool: The pool to assign the exchange to | ||
386 | * @index: The index in the pool where the exchange will be assigned | ||
387 | * @ep: The exchange to assign to the pool | ||
388 | */ | ||
325 | static inline void fc_exch_ptr_set(struct fc_exch_pool *pool, u16 index, | 389 | static inline void fc_exch_ptr_set(struct fc_exch_pool *pool, u16 index, |
326 | struct fc_exch *ep) | 390 | struct fc_exch *ep) |
327 | { | 391 | { |
328 | ((struct fc_exch **)(pool + 1))[index] = ep; | 392 | ((struct fc_exch **)(pool + 1))[index] = ep; |
329 | } | 393 | } |
330 | 394 | ||
395 | /** | ||
396 | * fc_exch_delete() - Delete an exchange | ||
397 | * @ep: The exchange to be deleted | ||
398 | */ | ||
331 | static void fc_exch_delete(struct fc_exch *ep) | 399 | static void fc_exch_delete(struct fc_exch *ep) |
332 | { | 400 | { |
333 | struct fc_exch_pool *pool; | 401 | struct fc_exch_pool *pool; |
@@ -343,8 +411,14 @@ static void fc_exch_delete(struct fc_exch *ep) | |||
343 | fc_exch_release(ep); /* drop hold for exch in mp */ | 411 | fc_exch_release(ep); /* drop hold for exch in mp */ |
344 | } | 412 | } |
345 | 413 | ||
346 | /* | 414 | /** |
347 | * Internal version of fc_exch_timer_set - used with lock held. | 415 | * fc_exch_timer_set_locked() - Start a timer for an exchange w/ the |
416 | * the exchange lock held | ||
417 | * @ep: The exchange whose timer will start | ||
418 | * @timer_msec: The timeout period | ||
419 | * | ||
420 | * Used for upper level protocols to time out the exchange. | ||
421 | * The timer is cancelled when it fires or when the exchange completes. | ||
348 | */ | 422 | */ |
349 | static inline void fc_exch_timer_set_locked(struct fc_exch *ep, | 423 | static inline void fc_exch_timer_set_locked(struct fc_exch *ep, |
350 | unsigned int timer_msec) | 424 | unsigned int timer_msec) |
@@ -354,17 +428,15 @@ static inline void fc_exch_timer_set_locked(struct fc_exch *ep, | |||
354 | 428 | ||
355 | FC_EXCH_DBG(ep, "Exchange timer armed\n"); | 429 | FC_EXCH_DBG(ep, "Exchange timer armed\n"); |
356 | 430 | ||
357 | if (schedule_delayed_work(&ep->timeout_work, | 431 | if (queue_delayed_work(fc_exch_workqueue, &ep->timeout_work, |
358 | msecs_to_jiffies(timer_msec))) | 432 | msecs_to_jiffies(timer_msec))) |
359 | fc_exch_hold(ep); /* hold for timer */ | 433 | fc_exch_hold(ep); /* hold for timer */ |
360 | } | 434 | } |
361 | 435 | ||
362 | /* | 436 | /** |
363 | * Set timer for an exchange. | 437 | * fc_exch_timer_set() - Lock the exchange and set the timer |
364 | * The time is a minimum delay in milliseconds until the timer fires. | 438 | * @ep: The exchange whose timer will start |
365 | * Used for upper level protocols to time out the exchange. | 439 | * @timer_msec: The timeout period |
366 | * The timer is cancelled when it fires or when the exchange completes. | ||
367 | * Returns non-zero if a timer couldn't be allocated. | ||
368 | */ | 440 | */ |
369 | static void fc_exch_timer_set(struct fc_exch *ep, unsigned int timer_msec) | 441 | static void fc_exch_timer_set(struct fc_exch *ep, unsigned int timer_msec) |
370 | { | 442 | { |
@@ -373,7 +445,115 @@ static void fc_exch_timer_set(struct fc_exch *ep, unsigned int timer_msec) | |||
373 | spin_unlock_bh(&ep->ex_lock); | 445 | spin_unlock_bh(&ep->ex_lock); |
374 | } | 446 | } |
375 | 447 | ||
376 | int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec) | 448 | /** |
449 | * fc_seq_send() - Send a frame using existing sequence/exchange pair | ||
450 | * @lport: The local port that the exchange will be sent on | ||
451 | * @sp: The sequence to be sent | ||
452 | * @fp: The frame to be sent on the exchange | ||
453 | */ | ||
454 | static int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, | ||
455 | struct fc_frame *fp) | ||
456 | { | ||
457 | struct fc_exch *ep; | ||
458 | struct fc_frame_header *fh = fc_frame_header_get(fp); | ||
459 | int error; | ||
460 | u32 f_ctl; | ||
461 | |||
462 | ep = fc_seq_exch(sp); | ||
463 | WARN_ON((ep->esb_stat & ESB_ST_SEQ_INIT) != ESB_ST_SEQ_INIT); | ||
464 | |||
465 | f_ctl = ntoh24(fh->fh_f_ctl); | ||
466 | fc_exch_setup_hdr(ep, fp, f_ctl); | ||
467 | |||
468 | /* | ||
469 | * update sequence count if this frame is carrying | ||
470 | * multiple FC frames when sequence offload is enabled | ||
471 | * by LLD. | ||
472 | */ | ||
473 | if (fr_max_payload(fp)) | ||
474 | sp->cnt += DIV_ROUND_UP((fr_len(fp) - sizeof(*fh)), | ||
475 | fr_max_payload(fp)); | ||
476 | else | ||
477 | sp->cnt++; | ||
478 | |||
479 | /* | ||
480 | * Send the frame. | ||
481 | */ | ||
482 | error = lport->tt.frame_send(lport, fp); | ||
483 | |||
484 | /* | ||
485 | * Update the exchange and sequence flags, | ||
486 | * assuming all frames for the sequence have been sent. | ||
487 | * We can only be called to send once for each sequence. | ||
488 | */ | ||
489 | spin_lock_bh(&ep->ex_lock); | ||
490 | ep->f_ctl = f_ctl & ~FC_FC_FIRST_SEQ; /* not first seq */ | ||
491 | if (f_ctl & (FC_FC_END_SEQ | FC_FC_SEQ_INIT)) | ||
492 | ep->esb_stat &= ~ESB_ST_SEQ_INIT; | ||
493 | spin_unlock_bh(&ep->ex_lock); | ||
494 | return error; | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * fc_seq_alloc() - Allocate a sequence for a given exchange | ||
499 | * @ep: The exchange to allocate a new sequence for | ||
500 | * @seq_id: The sequence ID to be used | ||
501 | * | ||
502 | * We don't support multiple originated sequences on the same exchange. | ||
503 | * By implication, any previously originated sequence on this exchange | ||
504 | * is complete, and we reallocate the same sequence. | ||
505 | */ | ||
506 | static struct fc_seq *fc_seq_alloc(struct fc_exch *ep, u8 seq_id) | ||
507 | { | ||
508 | struct fc_seq *sp; | ||
509 | |||
510 | sp = &ep->seq; | ||
511 | sp->ssb_stat = 0; | ||
512 | sp->cnt = 0; | ||
513 | sp->id = seq_id; | ||
514 | return sp; | ||
515 | } | ||
516 | |||
517 | /** | ||
518 | * fc_seq_start_next_locked() - Allocate a new sequence on the same | ||
519 | * exchange as the supplied sequence | ||
520 | * @sp: The sequence/exchange to get a new sequence for | ||
521 | */ | ||
522 | static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp) | ||
523 | { | ||
524 | struct fc_exch *ep = fc_seq_exch(sp); | ||
525 | |||
526 | sp = fc_seq_alloc(ep, ep->seq_id++); | ||
527 | FC_EXCH_DBG(ep, "f_ctl %6x seq %2x\n", | ||
528 | ep->f_ctl, sp->id); | ||
529 | return sp; | ||
530 | } | ||
531 | |||
532 | /** | ||
533 | * fc_seq_start_next() - Lock the exchange and get a new sequence | ||
534 | * for a given sequence/exchange pair | ||
535 | * @sp: The sequence/exchange to get a new exchange for | ||
536 | */ | ||
537 | static struct fc_seq *fc_seq_start_next(struct fc_seq *sp) | ||
538 | { | ||
539 | struct fc_exch *ep = fc_seq_exch(sp); | ||
540 | |||
541 | spin_lock_bh(&ep->ex_lock); | ||
542 | sp = fc_seq_start_next_locked(sp); | ||
543 | spin_unlock_bh(&ep->ex_lock); | ||
544 | |||
545 | return sp; | ||
546 | } | ||
547 | |||
548 | /** | ||
549 | * fc_seq_exch_abort() - Abort an exchange and sequence | ||
550 | * @req_sp: The sequence to be aborted | ||
551 | * @timer_msec: The period of time to wait before aborting | ||
552 | * | ||
553 | * Generally called because of a timeout or an abort from the upper layer. | ||
554 | */ | ||
555 | static int fc_seq_exch_abort(const struct fc_seq *req_sp, | ||
556 | unsigned int timer_msec) | ||
377 | { | 557 | { |
378 | struct fc_seq *sp; | 558 | struct fc_seq *sp; |
379 | struct fc_exch *ep; | 559 | struct fc_exch *ep; |
@@ -422,11 +602,10 @@ int fc_seq_exch_abort(const struct fc_seq *req_sp, unsigned int timer_msec) | |||
422 | error = -ENOBUFS; | 602 | error = -ENOBUFS; |
423 | return error; | 603 | return error; |
424 | } | 604 | } |
425 | EXPORT_SYMBOL(fc_seq_exch_abort); | ||
426 | 605 | ||
427 | /* | 606 | /** |
428 | * Exchange timeout - handle exchange timer expiration. | 607 | * fc_exch_timeout() - Handle exchange timer expiration |
429 | * The timer will have been cancelled before this is called. | 608 | * @work: The work_struct identifying the exchange that timed out |
430 | */ | 609 | */ |
431 | static void fc_exch_timeout(struct work_struct *work) | 610 | static void fc_exch_timeout(struct work_struct *work) |
432 | { | 611 | { |
@@ -474,28 +653,10 @@ done: | |||
474 | fc_exch_release(ep); | 653 | fc_exch_release(ep); |
475 | } | 654 | } |
476 | 655 | ||
477 | /* | ||
478 | * Allocate a sequence. | ||
479 | * | ||
480 | * We don't support multiple originated sequences on the same exchange. | ||
481 | * By implication, any previously originated sequence on this exchange | ||
482 | * is complete, and we reallocate the same sequence. | ||
483 | */ | ||
484 | static struct fc_seq *fc_seq_alloc(struct fc_exch *ep, u8 seq_id) | ||
485 | { | ||
486 | struct fc_seq *sp; | ||
487 | |||
488 | sp = &ep->seq; | ||
489 | sp->ssb_stat = 0; | ||
490 | sp->cnt = 0; | ||
491 | sp->id = seq_id; | ||
492 | return sp; | ||
493 | } | ||
494 | |||
495 | /** | 656 | /** |
496 | * fc_exch_em_alloc() - allocate an exchange from a specified EM. | 657 | * fc_exch_em_alloc() - Allocate an exchange from a specified EM. |
497 | * @lport: ptr to the local port | 658 | * @lport: The local port that the exchange is for |
498 | * @mp: ptr to the exchange manager | 659 | * @mp: The exchange manager that will allocate the exchange |
499 | * | 660 | * |
500 | * Returns pointer to allocated fc_exch with exch lock held. | 661 | * Returns pointer to allocated fc_exch with exch lock held. |
501 | */ | 662 | */ |
@@ -563,16 +724,18 @@ err: | |||
563 | } | 724 | } |
564 | 725 | ||
565 | /** | 726 | /** |
566 | * fc_exch_alloc() - allocate an exchange. | 727 | * fc_exch_alloc() - Allocate an exchange from an EM on a |
567 | * @lport: ptr to the local port | 728 | * local port's list of EMs. |
568 | * @fp: ptr to the FC frame | 729 | * @lport: The local port that will own the exchange |
730 | * @fp: The FC frame that the exchange will be for | ||
569 | * | 731 | * |
570 | * This function walks the list of the exchange manager(EM) | 732 | * This function walks the list of exchange manager(EM) |
571 | * anchors to select a EM for new exchange allocation. The | 733 | * anchors to select an EM for a new exchange allocation. The |
572 | * EM is selected having either a NULL match function pointer | 734 | * EM is selected when a NULL match function pointer is encountered |
573 | * or call to match function returning true. | 735 | * or when a call to a match function returns true. |
574 | */ | 736 | */ |
575 | struct fc_exch *fc_exch_alloc(struct fc_lport *lport, struct fc_frame *fp) | 737 | static struct fc_exch *fc_exch_alloc(struct fc_lport *lport, |
738 | struct fc_frame *fp) | ||
576 | { | 739 | { |
577 | struct fc_exch_mgr_anchor *ema; | 740 | struct fc_exch_mgr_anchor *ema; |
578 | struct fc_exch *ep; | 741 | struct fc_exch *ep; |
@@ -586,10 +749,11 @@ struct fc_exch *fc_exch_alloc(struct fc_lport *lport, struct fc_frame *fp) | |||
586 | } | 749 | } |
587 | return NULL; | 750 | return NULL; |
588 | } | 751 | } |
589 | EXPORT_SYMBOL(fc_exch_alloc); | ||
590 | 752 | ||
591 | /* | 753 | /** |
592 | * Lookup and hold an exchange. | 754 | * fc_exch_find() - Lookup and hold an exchange |
755 | * @mp: The exchange manager to lookup the exchange from | ||
756 | * @xid: The XID of the exchange to look up | ||
593 | */ | 757 | */ |
594 | static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid) | 758 | static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid) |
595 | { | 759 | { |
@@ -609,7 +773,13 @@ static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid) | |||
609 | return ep; | 773 | return ep; |
610 | } | 774 | } |
611 | 775 | ||
612 | void fc_exch_done(struct fc_seq *sp) | 776 | |
777 | /** | ||
778 | * fc_exch_done() - Indicate that an exchange/sequence tuple is complete and | ||
779 | * the memory allocated for the related objects may be freed. | ||
780 | * @sp: The sequence that has completed | ||
781 | */ | ||
782 | static void fc_exch_done(struct fc_seq *sp) | ||
613 | { | 783 | { |
614 | struct fc_exch *ep = fc_seq_exch(sp); | 784 | struct fc_exch *ep = fc_seq_exch(sp); |
615 | int rc; | 785 | int rc; |
@@ -620,10 +790,13 @@ void fc_exch_done(struct fc_seq *sp) | |||
620 | if (!rc) | 790 | if (!rc) |
621 | fc_exch_delete(ep); | 791 | fc_exch_delete(ep); |
622 | } | 792 | } |
623 | EXPORT_SYMBOL(fc_exch_done); | ||
624 | 793 | ||
625 | /* | 794 | /** |
626 | * Allocate a new exchange as responder. | 795 | * fc_exch_resp() - Allocate a new exchange for a response frame |
796 | * @lport: The local port that the exchange was for | ||
797 | * @mp: The exchange manager to allocate the exchange from | ||
798 | * @fp: The response frame | ||
799 | * | ||
627 | * Sets the responder ID in the frame header. | 800 | * Sets the responder ID in the frame header. |
628 | */ | 801 | */ |
629 | static struct fc_exch *fc_exch_resp(struct fc_lport *lport, | 802 | static struct fc_exch *fc_exch_resp(struct fc_lport *lport, |
@@ -664,8 +837,13 @@ static struct fc_exch *fc_exch_resp(struct fc_lport *lport, | |||
664 | return ep; | 837 | return ep; |
665 | } | 838 | } |
666 | 839 | ||
667 | /* | 840 | /** |
668 | * Find a sequence for receive where the other end is originating the sequence. | 841 | * fc_seq_lookup_recip() - Find a sequence where the other end |
842 | * originated the sequence | ||
843 | * @lport: The local port that the frame was sent to | ||
844 | * @mp: The Exchange Manager to lookup the exchange from | ||
845 | * @fp: The frame associated with the sequence we're looking for | ||
846 | * | ||
669 | * If fc_pf_rjt_reason is FC_RJT_NONE then this function will have a hold | 847 | * If fc_pf_rjt_reason is FC_RJT_NONE then this function will have a hold |
670 | * on the ep that should be released by the caller. | 848 | * on the ep that should be released by the caller. |
671 | */ | 849 | */ |
@@ -771,10 +949,12 @@ rel: | |||
771 | return reject; | 949 | return reject; |
772 | } | 950 | } |
773 | 951 | ||
774 | /* | 952 | /** |
775 | * Find the sequence for a frame being received. | 953 | * fc_seq_lookup_orig() - Find a sequence where this end |
776 | * We originated the sequence, so it should be found. | 954 | * originated the sequence |
777 | * We may or may not have originated the exchange. | 955 | * @mp: The Exchange Manager to lookup the exchange from |
956 | * @fp: The frame associated with the sequence we're looking for | ||
957 | * | ||
778 | * Does not hold the sequence for the caller. | 958 | * Does not hold the sequence for the caller. |
779 | */ | 959 | */ |
780 | static struct fc_seq *fc_seq_lookup_orig(struct fc_exch_mgr *mp, | 960 | static struct fc_seq *fc_seq_lookup_orig(struct fc_exch_mgr *mp, |
@@ -806,8 +986,12 @@ static struct fc_seq *fc_seq_lookup_orig(struct fc_exch_mgr *mp, | |||
806 | return sp; | 986 | return sp; |
807 | } | 987 | } |
808 | 988 | ||
809 | /* | 989 | /** |
810 | * Set addresses for an exchange. | 990 | * fc_exch_set_addr() - Set the source and destination IDs for an exchange |
991 | * @ep: The exchange to set the addresses for | ||
992 | * @orig_id: The originator's ID | ||
993 | * @resp_id: The responder's ID | ||
994 | * | ||
811 | * Note this must be done before the first sequence of the exchange is sent. | 995 | * Note this must be done before the first sequence of the exchange is sent. |
812 | */ | 996 | */ |
813 | static void fc_exch_set_addr(struct fc_exch *ep, | 997 | static void fc_exch_set_addr(struct fc_exch *ep, |
@@ -823,76 +1007,15 @@ static void fc_exch_set_addr(struct fc_exch *ep, | |||
823 | } | 1007 | } |
824 | } | 1008 | } |
825 | 1009 | ||
826 | static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp) | 1010 | /** |
827 | { | 1011 | * fc_seq_els_rsp_send() - Send an ELS response using infomation from |
828 | struct fc_exch *ep = fc_seq_exch(sp); | 1012 | * the existing sequence/exchange. |
829 | 1013 | * @sp: The sequence/exchange to get information from | |
830 | sp = fc_seq_alloc(ep, ep->seq_id++); | 1014 | * @els_cmd: The ELS command to be sent |
831 | FC_EXCH_DBG(ep, "f_ctl %6x seq %2x\n", | 1015 | * @els_data: The ELS data to be sent |
832 | ep->f_ctl, sp->id); | ||
833 | return sp; | ||
834 | } | ||
835 | /* | ||
836 | * Allocate a new sequence on the same exchange as the supplied sequence. | ||
837 | * This will never return NULL. | ||
838 | */ | 1016 | */ |
839 | struct fc_seq *fc_seq_start_next(struct fc_seq *sp) | 1017 | static void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd, |
840 | { | 1018 | struct fc_seq_els_data *els_data) |
841 | struct fc_exch *ep = fc_seq_exch(sp); | ||
842 | |||
843 | spin_lock_bh(&ep->ex_lock); | ||
844 | sp = fc_seq_start_next_locked(sp); | ||
845 | spin_unlock_bh(&ep->ex_lock); | ||
846 | |||
847 | return sp; | ||
848 | } | ||
849 | EXPORT_SYMBOL(fc_seq_start_next); | ||
850 | |||
851 | int fc_seq_send(struct fc_lport *lp, struct fc_seq *sp, struct fc_frame *fp) | ||
852 | { | ||
853 | struct fc_exch *ep; | ||
854 | struct fc_frame_header *fh = fc_frame_header_get(fp); | ||
855 | int error; | ||
856 | u32 f_ctl; | ||
857 | |||
858 | ep = fc_seq_exch(sp); | ||
859 | WARN_ON((ep->esb_stat & ESB_ST_SEQ_INIT) != ESB_ST_SEQ_INIT); | ||
860 | |||
861 | f_ctl = ntoh24(fh->fh_f_ctl); | ||
862 | fc_exch_setup_hdr(ep, fp, f_ctl); | ||
863 | |||
864 | /* | ||
865 | * update sequence count if this frame is carrying | ||
866 | * multiple FC frames when sequence offload is enabled | ||
867 | * by LLD. | ||
868 | */ | ||
869 | if (fr_max_payload(fp)) | ||
870 | sp->cnt += DIV_ROUND_UP((fr_len(fp) - sizeof(*fh)), | ||
871 | fr_max_payload(fp)); | ||
872 | else | ||
873 | sp->cnt++; | ||
874 | |||
875 | /* | ||
876 | * Send the frame. | ||
877 | */ | ||
878 | error = lp->tt.frame_send(lp, fp); | ||
879 | |||
880 | /* | ||
881 | * Update the exchange and sequence flags, | ||
882 | * assuming all frames for the sequence have been sent. | ||
883 | * We can only be called to send once for each sequence. | ||
884 | */ | ||
885 | spin_lock_bh(&ep->ex_lock); | ||
886 | ep->f_ctl = f_ctl & ~FC_FC_FIRST_SEQ; /* not first seq */ | ||
887 | if (f_ctl & (FC_FC_END_SEQ | FC_FC_SEQ_INIT)) | ||
888 | ep->esb_stat &= ~ESB_ST_SEQ_INIT; | ||
889 | spin_unlock_bh(&ep->ex_lock); | ||
890 | return error; | ||
891 | } | ||
892 | EXPORT_SYMBOL(fc_seq_send); | ||
893 | |||
894 | void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd, | ||
895 | struct fc_seq_els_data *els_data) | ||
896 | { | 1019 | { |
897 | switch (els_cmd) { | 1020 | switch (els_cmd) { |
898 | case ELS_LS_RJT: | 1021 | case ELS_LS_RJT: |
@@ -911,10 +1034,13 @@ void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd, | |||
911 | FC_EXCH_DBG(fc_seq_exch(sp), "Invalid ELS CMD:%x\n", els_cmd); | 1034 | FC_EXCH_DBG(fc_seq_exch(sp), "Invalid ELS CMD:%x\n", els_cmd); |
912 | } | 1035 | } |
913 | } | 1036 | } |
914 | EXPORT_SYMBOL(fc_seq_els_rsp_send); | ||
915 | 1037 | ||
916 | /* | 1038 | /** |
917 | * Send a sequence, which is also the last sequence in the exchange. | 1039 | * fc_seq_send_last() - Send a sequence that is the last in the exchange |
1040 | * @sp: The sequence that is to be sent | ||
1041 | * @fp: The frame that will be sent on the sequence | ||
1042 | * @rctl: The R_CTL information to be sent | ||
1043 | * @fh_type: The frame header type | ||
918 | */ | 1044 | */ |
919 | static void fc_seq_send_last(struct fc_seq *sp, struct fc_frame *fp, | 1045 | static void fc_seq_send_last(struct fc_seq *sp, struct fc_frame *fp, |
920 | enum fc_rctl rctl, enum fc_fh_type fh_type) | 1046 | enum fc_rctl rctl, enum fc_fh_type fh_type) |
@@ -928,9 +1054,12 @@ static void fc_seq_send_last(struct fc_seq *sp, struct fc_frame *fp, | |||
928 | fc_seq_send(ep->lp, sp, fp); | 1054 | fc_seq_send(ep->lp, sp, fp); |
929 | } | 1055 | } |
930 | 1056 | ||
931 | /* | 1057 | /** |
1058 | * fc_seq_send_ack() - Send an acknowledgement that we've received a frame | ||
1059 | * @sp: The sequence to send the ACK on | ||
1060 | * @rx_fp: The received frame that is being acknoledged | ||
1061 | * | ||
932 | * Send ACK_1 (or equiv.) indicating we received something. | 1062 | * Send ACK_1 (or equiv.) indicating we received something. |
933 | * The frame we're acking is supplied. | ||
934 | */ | 1063 | */ |
935 | static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp) | 1064 | static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp) |
936 | { | 1065 | { |
@@ -938,14 +1067,14 @@ static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp) | |||
938 | struct fc_frame_header *rx_fh; | 1067 | struct fc_frame_header *rx_fh; |
939 | struct fc_frame_header *fh; | 1068 | struct fc_frame_header *fh; |
940 | struct fc_exch *ep = fc_seq_exch(sp); | 1069 | struct fc_exch *ep = fc_seq_exch(sp); |
941 | struct fc_lport *lp = ep->lp; | 1070 | struct fc_lport *lport = ep->lp; |
942 | unsigned int f_ctl; | 1071 | unsigned int f_ctl; |
943 | 1072 | ||
944 | /* | 1073 | /* |
945 | * Don't send ACKs for class 3. | 1074 | * Don't send ACKs for class 3. |
946 | */ | 1075 | */ |
947 | if (fc_sof_needs_ack(fr_sof(rx_fp))) { | 1076 | if (fc_sof_needs_ack(fr_sof(rx_fp))) { |
948 | fp = fc_frame_alloc(lp, 0); | 1077 | fp = fc_frame_alloc(lport, 0); |
949 | if (!fp) | 1078 | if (!fp) |
950 | return; | 1079 | return; |
951 | 1080 | ||
@@ -980,12 +1109,16 @@ static void fc_seq_send_ack(struct fc_seq *sp, const struct fc_frame *rx_fp) | |||
980 | else | 1109 | else |
981 | fr_eof(fp) = FC_EOF_N; | 1110 | fr_eof(fp) = FC_EOF_N; |
982 | 1111 | ||
983 | (void) lp->tt.frame_send(lp, fp); | 1112 | lport->tt.frame_send(lport, fp); |
984 | } | 1113 | } |
985 | } | 1114 | } |
986 | 1115 | ||
987 | /* | 1116 | /** |
988 | * Send BLS Reject. | 1117 | * fc_exch_send_ba_rjt() - Send BLS Reject |
1118 | * @rx_fp: The frame being rejected | ||
1119 | * @reason: The reason the frame is being rejected | ||
1120 | * @explan: The explaination for the rejection | ||
1121 | * | ||
989 | * This is for rejecting BA_ABTS only. | 1122 | * This is for rejecting BA_ABTS only. |
990 | */ | 1123 | */ |
991 | static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp, | 1124 | static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp, |
@@ -996,11 +1129,11 @@ static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp, | |||
996 | struct fc_frame_header *rx_fh; | 1129 | struct fc_frame_header *rx_fh; |
997 | struct fc_frame_header *fh; | 1130 | struct fc_frame_header *fh; |
998 | struct fc_ba_rjt *rp; | 1131 | struct fc_ba_rjt *rp; |
999 | struct fc_lport *lp; | 1132 | struct fc_lport *lport; |
1000 | unsigned int f_ctl; | 1133 | unsigned int f_ctl; |
1001 | 1134 | ||
1002 | lp = fr_dev(rx_fp); | 1135 | lport = fr_dev(rx_fp); |
1003 | fp = fc_frame_alloc(lp, sizeof(*rp)); | 1136 | fp = fc_frame_alloc(lport, sizeof(*rp)); |
1004 | if (!fp) | 1137 | if (!fp) |
1005 | return; | 1138 | return; |
1006 | fh = fc_frame_header_get(fp); | 1139 | fh = fc_frame_header_get(fp); |
@@ -1045,13 +1178,17 @@ static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp, | |||
1045 | if (fc_sof_needs_ack(fr_sof(fp))) | 1178 | if (fc_sof_needs_ack(fr_sof(fp))) |
1046 | fr_eof(fp) = FC_EOF_N; | 1179 | fr_eof(fp) = FC_EOF_N; |
1047 | 1180 | ||
1048 | (void) lp->tt.frame_send(lp, fp); | 1181 | lport->tt.frame_send(lport, fp); |
1049 | } | 1182 | } |
1050 | 1183 | ||
1051 | /* | 1184 | /** |
1052 | * Handle an incoming ABTS. This would be for target mode usually, | 1185 | * fc_exch_recv_abts() - Handle an incoming ABTS |
1053 | * but could be due to lost FCP transfer ready, confirm or RRQ. | 1186 | * @ep: The exchange the abort was on |
1054 | * We always handle this as an exchange abort, ignoring the parameter. | 1187 | * @rx_fp: The ABTS frame |
1188 | * | ||
1189 | * This would be for target mode usually, but could be due to lost | ||
1190 | * FCP transfer ready, confirm or RRQ. We always handle this as an | ||
1191 | * exchange abort, ignoring the parameter. | ||
1055 | */ | 1192 | */ |
1056 | static void fc_exch_recv_abts(struct fc_exch *ep, struct fc_frame *rx_fp) | 1193 | static void fc_exch_recv_abts(struct fc_exch *ep, struct fc_frame *rx_fp) |
1057 | { | 1194 | { |
@@ -1100,10 +1237,14 @@ free: | |||
1100 | fc_frame_free(rx_fp); | 1237 | fc_frame_free(rx_fp); |
1101 | } | 1238 | } |
1102 | 1239 | ||
1103 | /* | 1240 | /** |
1104 | * Handle receive where the other end is originating the sequence. | 1241 | * fc_exch_recv_req() - Handler for an incoming request where is other |
1242 | * end is originating the sequence | ||
1243 | * @lport: The local port that received the request | ||
1244 | * @mp: The EM that the exchange is on | ||
1245 | * @fp: The request frame | ||
1105 | */ | 1246 | */ |
1106 | static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp, | 1247 | static void fc_exch_recv_req(struct fc_lport *lport, struct fc_exch_mgr *mp, |
1107 | struct fc_frame *fp) | 1248 | struct fc_frame *fp) |
1108 | { | 1249 | { |
1109 | struct fc_frame_header *fh = fc_frame_header_get(fp); | 1250 | struct fc_frame_header *fh = fc_frame_header_get(fp); |
@@ -1114,8 +1255,17 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp, | |||
1114 | u32 f_ctl; | 1255 | u32 f_ctl; |
1115 | enum fc_pf_rjt_reason reject; | 1256 | enum fc_pf_rjt_reason reject; |
1116 | 1257 | ||
1258 | /* We can have the wrong fc_lport at this point with NPIV, which is a | ||
1259 | * problem now that we know a new exchange needs to be allocated | ||
1260 | */ | ||
1261 | lport = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id)); | ||
1262 | if (!lport) { | ||
1263 | fc_frame_free(fp); | ||
1264 | return; | ||
1265 | } | ||
1266 | |||
1117 | fr_seq(fp) = NULL; | 1267 | fr_seq(fp) = NULL; |
1118 | reject = fc_seq_lookup_recip(lp, mp, fp); | 1268 | reject = fc_seq_lookup_recip(lport, mp, fp); |
1119 | if (reject == FC_RJT_NONE) { | 1269 | if (reject == FC_RJT_NONE) { |
1120 | sp = fr_seq(fp); /* sequence will be held */ | 1270 | sp = fr_seq(fp); /* sequence will be held */ |
1121 | ep = fc_seq_exch(sp); | 1271 | ep = fc_seq_exch(sp); |
@@ -1138,17 +1288,21 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp, | |||
1138 | if (ep->resp) | 1288 | if (ep->resp) |
1139 | ep->resp(sp, fp, ep->arg); | 1289 | ep->resp(sp, fp, ep->arg); |
1140 | else | 1290 | else |
1141 | lp->tt.lport_recv(lp, sp, fp); | 1291 | lport->tt.lport_recv(lport, sp, fp); |
1142 | fc_exch_release(ep); /* release from lookup */ | 1292 | fc_exch_release(ep); /* release from lookup */ |
1143 | } else { | 1293 | } else { |
1144 | FC_LPORT_DBG(lp, "exch/seq lookup failed: reject %x\n", reject); | 1294 | FC_LPORT_DBG(lport, "exch/seq lookup failed: reject %x\n", |
1295 | reject); | ||
1145 | fc_frame_free(fp); | 1296 | fc_frame_free(fp); |
1146 | } | 1297 | } |
1147 | } | 1298 | } |
1148 | 1299 | ||
1149 | /* | 1300 | /** |
1150 | * Handle receive where the other end is originating the sequence in | 1301 | * fc_exch_recv_seq_resp() - Handler for an incoming response where the other |
1151 | * response to our exchange. | 1302 | * end is the originator of the sequence that is a |
1303 | * response to our initial exchange | ||
1304 | * @mp: The EM that the exchange is on | ||
1305 | * @fp: The response frame | ||
1152 | */ | 1306 | */ |
1153 | static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) | 1307 | static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) |
1154 | { | 1308 | { |
@@ -1239,8 +1393,11 @@ out: | |||
1239 | fc_frame_free(fp); | 1393 | fc_frame_free(fp); |
1240 | } | 1394 | } |
1241 | 1395 | ||
1242 | /* | 1396 | /** |
1243 | * Handle receive for a sequence where other end is responding to our sequence. | 1397 | * fc_exch_recv_resp() - Handler for a sequence where other end is |
1398 | * responding to our sequence | ||
1399 | * @mp: The EM that the exchange is on | ||
1400 | * @fp: The response frame | ||
1244 | */ | 1401 | */ |
1245 | static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) | 1402 | static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) |
1246 | { | 1403 | { |
@@ -1256,9 +1413,13 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp) | |||
1256 | fc_frame_free(fp); | 1413 | fc_frame_free(fp); |
1257 | } | 1414 | } |
1258 | 1415 | ||
1259 | /* | 1416 | /** |
1260 | * Handle the response to an ABTS for exchange or sequence. | 1417 | * fc_exch_abts_resp() - Handler for a response to an ABT |
1261 | * This can be BA_ACC or BA_RJT. | 1418 | * @ep: The exchange that the frame is on |
1419 | * @fp: The response frame | ||
1420 | * | ||
1421 | * This response would be to an ABTS cancelling an exchange or sequence. | ||
1422 | * The response can be either BA_ACC or BA_RJT | ||
1262 | */ | 1423 | */ |
1263 | static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp) | 1424 | static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp) |
1264 | { | 1425 | { |
@@ -1333,9 +1494,12 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp) | |||
1333 | 1494 | ||
1334 | } | 1495 | } |
1335 | 1496 | ||
1336 | /* | 1497 | /** |
1337 | * Receive BLS sequence. | 1498 | * fc_exch_recv_bls() - Handler for a BLS sequence |
1338 | * This is always a sequence initiated by the remote side. | 1499 | * @mp: The EM that the exchange is on |
1500 | * @fp: The request frame | ||
1501 | * | ||
1502 | * The BLS frame is always a sequence initiated by the remote side. | ||
1339 | * We may be either the originator or recipient of the exchange. | 1503 | * We may be either the originator or recipient of the exchange. |
1340 | */ | 1504 | */ |
1341 | static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp) | 1505 | static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp) |
@@ -1392,8 +1556,10 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp) | |||
1392 | fc_exch_release(ep); /* release hold taken by fc_exch_find */ | 1556 | fc_exch_release(ep); /* release hold taken by fc_exch_find */ |
1393 | } | 1557 | } |
1394 | 1558 | ||
1395 | /* | 1559 | /** |
1396 | * Accept sequence with LS_ACC. | 1560 | * fc_seq_ls_acc() - Accept sequence with LS_ACC |
1561 | * @req_sp: The request sequence | ||
1562 | * | ||
1397 | * If this fails due to allocation or transmit congestion, assume the | 1563 | * If this fails due to allocation or transmit congestion, assume the |
1398 | * originator will repeat the sequence. | 1564 | * originator will repeat the sequence. |
1399 | */ | 1565 | */ |
@@ -1413,8 +1579,12 @@ static void fc_seq_ls_acc(struct fc_seq *req_sp) | |||
1413 | } | 1579 | } |
1414 | } | 1580 | } |
1415 | 1581 | ||
1416 | /* | 1582 | /** |
1417 | * Reject sequence with ELS LS_RJT. | 1583 | * fc_seq_ls_rjt() - Reject a sequence with ELS LS_RJT |
1584 | * @req_sp: The request sequence | ||
1585 | * @reason: The reason the sequence is being rejected | ||
1586 | * @explan: The explaination for the rejection | ||
1587 | * | ||
1418 | * If this fails due to allocation or transmit congestion, assume the | 1588 | * If this fails due to allocation or transmit congestion, assume the |
1419 | * originator will repeat the sequence. | 1589 | * originator will repeat the sequence. |
1420 | */ | 1590 | */ |
@@ -1437,6 +1607,10 @@ static void fc_seq_ls_rjt(struct fc_seq *req_sp, enum fc_els_rjt_reason reason, | |||
1437 | } | 1607 | } |
1438 | } | 1608 | } |
1439 | 1609 | ||
1610 | /** | ||
1611 | * fc_exch_reset() - Reset an exchange | ||
1612 | * @ep: The exchange to be reset | ||
1613 | */ | ||
1440 | static void fc_exch_reset(struct fc_exch *ep) | 1614 | static void fc_exch_reset(struct fc_exch *ep) |
1441 | { | 1615 | { |
1442 | struct fc_seq *sp; | 1616 | struct fc_seq *sp; |
@@ -1446,12 +1620,6 @@ static void fc_exch_reset(struct fc_exch *ep) | |||
1446 | 1620 | ||
1447 | spin_lock_bh(&ep->ex_lock); | 1621 | spin_lock_bh(&ep->ex_lock); |
1448 | ep->state |= FC_EX_RST_CLEANUP; | 1622 | ep->state |= FC_EX_RST_CLEANUP; |
1449 | /* | ||
1450 | * we really want to call del_timer_sync, but cannot due | ||
1451 | * to the lport calling with the lport lock held (some resp | ||
1452 | * functions can also grab the lport lock which could cause | ||
1453 | * a deadlock). | ||
1454 | */ | ||
1455 | if (cancel_delayed_work(&ep->timeout_work)) | 1623 | if (cancel_delayed_work(&ep->timeout_work)) |
1456 | atomic_dec(&ep->ex_refcnt); /* drop hold for timer */ | 1624 | atomic_dec(&ep->ex_refcnt); /* drop hold for timer */ |
1457 | resp = ep->resp; | 1625 | resp = ep->resp; |
@@ -1471,16 +1639,16 @@ static void fc_exch_reset(struct fc_exch *ep) | |||
1471 | } | 1639 | } |
1472 | 1640 | ||
1473 | /** | 1641 | /** |
1474 | * fc_exch_pool_reset() - Resets an per cpu exches pool. | 1642 | * fc_exch_pool_reset() - Reset a per cpu exchange pool |
1475 | * @lport: ptr to the local port | 1643 | * @lport: The local port that the exchange pool is on |
1476 | * @pool: ptr to the per cpu exches pool | 1644 | * @pool: The exchange pool to be reset |
1477 | * @sid: source FC ID | 1645 | * @sid: The source ID |
1478 | * @did: destination FC ID | 1646 | * @did: The destination ID |
1479 | * | 1647 | * |
1480 | * Resets an per cpu exches pool, releasing its all sequences | 1648 | * Resets a per cpu exches pool, releasing all of its sequences |
1481 | * and exchanges. If sid is non-zero, then reset only exchanges | 1649 | * and exchanges. If sid is non-zero then reset only exchanges |
1482 | * we sourced from that FID. If did is non-zero, reset only | 1650 | * we sourced from the local port's FID. If did is non-zero then |
1483 | * exchanges destined to that FID. | 1651 | * only reset exchanges destined for the local port's FID. |
1484 | */ | 1652 | */ |
1485 | static void fc_exch_pool_reset(struct fc_lport *lport, | 1653 | static void fc_exch_pool_reset(struct fc_lport *lport, |
1486 | struct fc_exch_pool *pool, | 1654 | struct fc_exch_pool *pool, |
@@ -1514,15 +1682,15 @@ restart: | |||
1514 | } | 1682 | } |
1515 | 1683 | ||
1516 | /** | 1684 | /** |
1517 | * fc_exch_mgr_reset() - Resets all EMs of a lport | 1685 | * fc_exch_mgr_reset() - Reset all EMs of a local port |
1518 | * @lport: ptr to the local port | 1686 | * @lport: The local port whose EMs are to be reset |
1519 | * @sid: source FC ID | 1687 | * @sid: The source ID |
1520 | * @did: destination FC ID | 1688 | * @did: The destination ID |
1521 | * | 1689 | * |
1522 | * Reset all EMs of a lport, releasing its all sequences and | 1690 | * Reset all EMs associated with a given local port. Release all |
1523 | * exchanges. If sid is non-zero, then reset only exchanges | 1691 | * sequences and exchanges. If sid is non-zero then reset only the |
1524 | * we sourced from that FID. If did is non-zero, reset only | 1692 | * exchanges sent from the local port's FID. If did is non-zero then |
1525 | * exchanges destined to that FID. | 1693 | * reset only exchanges destined for the local port's FID. |
1526 | */ | 1694 | */ |
1527 | void fc_exch_mgr_reset(struct fc_lport *lport, u32 sid, u32 did) | 1695 | void fc_exch_mgr_reset(struct fc_lport *lport, u32 sid, u32 did) |
1528 | { | 1696 | { |
@@ -1538,8 +1706,11 @@ void fc_exch_mgr_reset(struct fc_lport *lport, u32 sid, u32 did) | |||
1538 | } | 1706 | } |
1539 | EXPORT_SYMBOL(fc_exch_mgr_reset); | 1707 | EXPORT_SYMBOL(fc_exch_mgr_reset); |
1540 | 1708 | ||
1541 | /* | 1709 | /** |
1542 | * Handle incoming ELS REC - Read Exchange Concise. | 1710 | * fc_exch_els_rec() - Handler for ELS REC (Read Exchange Concise) requests |
1711 | * @sp: The sequence the REC is on | ||
1712 | * @rfp: The REC frame | ||
1713 | * | ||
1543 | * Note that the requesting port may be different than the S_ID in the request. | 1714 | * Note that the requesting port may be different than the S_ID in the request. |
1544 | */ | 1715 | */ |
1545 | static void fc_exch_els_rec(struct fc_seq *sp, struct fc_frame *rfp) | 1716 | static void fc_exch_els_rec(struct fc_seq *sp, struct fc_frame *rfp) |
@@ -1621,10 +1792,11 @@ reject: | |||
1621 | fc_frame_free(rfp); | 1792 | fc_frame_free(rfp); |
1622 | } | 1793 | } |
1623 | 1794 | ||
1624 | /* | 1795 | /** |
1625 | * Handle response from RRQ. | 1796 | * fc_exch_rrq_resp() - Handler for RRQ responses |
1626 | * Not much to do here, really. | 1797 | * @sp: The sequence that the RRQ is on |
1627 | * Should report errors. | 1798 | * @fp: The RRQ frame |
1799 | * @arg: The exchange that the RRQ is on | ||
1628 | * | 1800 | * |
1629 | * TODO: fix error handler. | 1801 | * TODO: fix error handler. |
1630 | */ | 1802 | */ |
@@ -1664,21 +1836,99 @@ cleanup: | |||
1664 | fc_exch_release(aborted_ep); | 1836 | fc_exch_release(aborted_ep); |
1665 | } | 1837 | } |
1666 | 1838 | ||
1667 | /* | 1839 | |
1668 | * Send ELS RRQ - Reinstate Recovery Qualifier. | 1840 | /** |
1841 | * fc_exch_seq_send() - Send a frame using a new exchange and sequence | ||
1842 | * @lport: The local port to send the frame on | ||
1843 | * @fp: The frame to be sent | ||
1844 | * @resp: The response handler for this request | ||
1845 | * @destructor: The destructor for the exchange | ||
1846 | * @arg: The argument to be passed to the response handler | ||
1847 | * @timer_msec: The timeout period for the exchange | ||
1848 | * | ||
1849 | * The frame pointer with some of the header's fields must be | ||
1850 | * filled before calling this routine, those fields are: | ||
1851 | * | ||
1852 | * - routing control | ||
1853 | * - FC port did | ||
1854 | * - FC port sid | ||
1855 | * - FC header type | ||
1856 | * - frame control | ||
1857 | * - parameter or relative offset | ||
1858 | */ | ||
1859 | static struct fc_seq *fc_exch_seq_send(struct fc_lport *lport, | ||
1860 | struct fc_frame *fp, | ||
1861 | void (*resp)(struct fc_seq *, | ||
1862 | struct fc_frame *fp, | ||
1863 | void *arg), | ||
1864 | void (*destructor)(struct fc_seq *, | ||
1865 | void *), | ||
1866 | void *arg, u32 timer_msec) | ||
1867 | { | ||
1868 | struct fc_exch *ep; | ||
1869 | struct fc_seq *sp = NULL; | ||
1870 | struct fc_frame_header *fh; | ||
1871 | int rc = 1; | ||
1872 | |||
1873 | ep = fc_exch_alloc(lport, fp); | ||
1874 | if (!ep) { | ||
1875 | fc_frame_free(fp); | ||
1876 | return NULL; | ||
1877 | } | ||
1878 | ep->esb_stat |= ESB_ST_SEQ_INIT; | ||
1879 | fh = fc_frame_header_get(fp); | ||
1880 | fc_exch_set_addr(ep, ntoh24(fh->fh_s_id), ntoh24(fh->fh_d_id)); | ||
1881 | ep->resp = resp; | ||
1882 | ep->destructor = destructor; | ||
1883 | ep->arg = arg; | ||
1884 | ep->r_a_tov = FC_DEF_R_A_TOV; | ||
1885 | ep->lp = lport; | ||
1886 | sp = &ep->seq; | ||
1887 | |||
1888 | ep->fh_type = fh->fh_type; /* save for possbile timeout handling */ | ||
1889 | ep->f_ctl = ntoh24(fh->fh_f_ctl); | ||
1890 | fc_exch_setup_hdr(ep, fp, ep->f_ctl); | ||
1891 | sp->cnt++; | ||
1892 | |||
1893 | if (ep->xid <= lport->lro_xid) | ||
1894 | fc_fcp_ddp_setup(fr_fsp(fp), ep->xid); | ||
1895 | |||
1896 | if (unlikely(lport->tt.frame_send(lport, fp))) | ||
1897 | goto err; | ||
1898 | |||
1899 | if (timer_msec) | ||
1900 | fc_exch_timer_set_locked(ep, timer_msec); | ||
1901 | ep->f_ctl &= ~FC_FC_FIRST_SEQ; /* not first seq */ | ||
1902 | |||
1903 | if (ep->f_ctl & FC_FC_SEQ_INIT) | ||
1904 | ep->esb_stat &= ~ESB_ST_SEQ_INIT; | ||
1905 | spin_unlock_bh(&ep->ex_lock); | ||
1906 | return sp; | ||
1907 | err: | ||
1908 | rc = fc_exch_done_locked(ep); | ||
1909 | spin_unlock_bh(&ep->ex_lock); | ||
1910 | if (!rc) | ||
1911 | fc_exch_delete(ep); | ||
1912 | return NULL; | ||
1913 | } | ||
1914 | |||
1915 | /** | ||
1916 | * fc_exch_rrq() - Send an ELS RRQ (Reinstate Recovery Qualifier) command | ||
1917 | * @ep: The exchange to send the RRQ on | ||
1918 | * | ||
1669 | * This tells the remote port to stop blocking the use of | 1919 | * This tells the remote port to stop blocking the use of |
1670 | * the exchange and the seq_cnt range. | 1920 | * the exchange and the seq_cnt range. |
1671 | */ | 1921 | */ |
1672 | static void fc_exch_rrq(struct fc_exch *ep) | 1922 | static void fc_exch_rrq(struct fc_exch *ep) |
1673 | { | 1923 | { |
1674 | struct fc_lport *lp; | 1924 | struct fc_lport *lport; |
1675 | struct fc_els_rrq *rrq; | 1925 | struct fc_els_rrq *rrq; |
1676 | struct fc_frame *fp; | 1926 | struct fc_frame *fp; |
1677 | u32 did; | 1927 | u32 did; |
1678 | 1928 | ||
1679 | lp = ep->lp; | 1929 | lport = ep->lp; |
1680 | 1930 | ||
1681 | fp = fc_frame_alloc(lp, sizeof(*rrq)); | 1931 | fp = fc_frame_alloc(lport, sizeof(*rrq)); |
1682 | if (!fp) | 1932 | if (!fp) |
1683 | goto retry; | 1933 | goto retry; |
1684 | 1934 | ||
@@ -1694,10 +1944,11 @@ static void fc_exch_rrq(struct fc_exch *ep) | |||
1694 | did = ep->sid; | 1944 | did = ep->sid; |
1695 | 1945 | ||
1696 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, did, | 1946 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, did, |
1697 | fc_host_port_id(lp->host), FC_TYPE_ELS, | 1947 | fc_host_port_id(lport->host), FC_TYPE_ELS, |
1698 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); | 1948 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
1699 | 1949 | ||
1700 | if (fc_exch_seq_send(lp, fp, fc_exch_rrq_resp, NULL, ep, lp->e_d_tov)) | 1950 | if (fc_exch_seq_send(lport, fp, fc_exch_rrq_resp, NULL, ep, |
1951 | lport->e_d_tov)) | ||
1701 | return; | 1952 | return; |
1702 | 1953 | ||
1703 | retry: | 1954 | retry: |
@@ -1714,12 +1965,14 @@ retry: | |||
1714 | } | 1965 | } |
1715 | 1966 | ||
1716 | 1967 | ||
1717 | /* | 1968 | /** |
1718 | * Handle incoming ELS RRQ - Reset Recovery Qualifier. | 1969 | * fc_exch_els_rrq() - Handler for ELS RRQ (Reset Recovery Qualifier) requests |
1970 | * @sp: The sequence that the RRQ is on | ||
1971 | * @fp: The RRQ frame | ||
1719 | */ | 1972 | */ |
1720 | static void fc_exch_els_rrq(struct fc_seq *sp, struct fc_frame *fp) | 1973 | static void fc_exch_els_rrq(struct fc_seq *sp, struct fc_frame *fp) |
1721 | { | 1974 | { |
1722 | struct fc_exch *ep; /* request or subject exchange */ | 1975 | struct fc_exch *ep = NULL; /* request or subject exchange */ |
1723 | struct fc_els_rrq *rp; | 1976 | struct fc_els_rrq *rp; |
1724 | u32 sid; | 1977 | u32 sid; |
1725 | u16 xid; | 1978 | u16 xid; |
@@ -1769,17 +2022,24 @@ static void fc_exch_els_rrq(struct fc_seq *sp, struct fc_frame *fp) | |||
1769 | * Send LS_ACC. | 2022 | * Send LS_ACC. |
1770 | */ | 2023 | */ |
1771 | fc_seq_ls_acc(sp); | 2024 | fc_seq_ls_acc(sp); |
1772 | fc_frame_free(fp); | 2025 | goto out; |
1773 | return; | ||
1774 | 2026 | ||
1775 | unlock_reject: | 2027 | unlock_reject: |
1776 | spin_unlock_bh(&ep->ex_lock); | 2028 | spin_unlock_bh(&ep->ex_lock); |
1777 | fc_exch_release(ep); /* drop hold from fc_exch_find */ | ||
1778 | reject: | 2029 | reject: |
1779 | fc_seq_ls_rjt(sp, ELS_RJT_LOGIC, explan); | 2030 | fc_seq_ls_rjt(sp, ELS_RJT_LOGIC, explan); |
2031 | out: | ||
1780 | fc_frame_free(fp); | 2032 | fc_frame_free(fp); |
2033 | if (ep) | ||
2034 | fc_exch_release(ep); /* drop hold from fc_exch_find */ | ||
1781 | } | 2035 | } |
1782 | 2036 | ||
2037 | /** | ||
2038 | * fc_exch_mgr_add() - Add an exchange manager to a local port's list of EMs | ||
2039 | * @lport: The local port to add the exchange manager to | ||
2040 | * @mp: The exchange manager to be added to the local port | ||
2041 | * @match: The match routine that indicates when this EM should be used | ||
2042 | */ | ||
1783 | struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport, | 2043 | struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport, |
1784 | struct fc_exch_mgr *mp, | 2044 | struct fc_exch_mgr *mp, |
1785 | bool (*match)(struct fc_frame *)) | 2045 | bool (*match)(struct fc_frame *)) |
@@ -1799,6 +2059,10 @@ struct fc_exch_mgr_anchor *fc_exch_mgr_add(struct fc_lport *lport, | |||
1799 | } | 2059 | } |
1800 | EXPORT_SYMBOL(fc_exch_mgr_add); | 2060 | EXPORT_SYMBOL(fc_exch_mgr_add); |
1801 | 2061 | ||
2062 | /** | ||
2063 | * fc_exch_mgr_destroy() - Destroy an exchange manager | ||
2064 | * @kref: The reference to the EM to be destroyed | ||
2065 | */ | ||
1802 | static void fc_exch_mgr_destroy(struct kref *kref) | 2066 | static void fc_exch_mgr_destroy(struct kref *kref) |
1803 | { | 2067 | { |
1804 | struct fc_exch_mgr *mp = container_of(kref, struct fc_exch_mgr, kref); | 2068 | struct fc_exch_mgr *mp = container_of(kref, struct fc_exch_mgr, kref); |
@@ -1808,6 +2072,10 @@ static void fc_exch_mgr_destroy(struct kref *kref) | |||
1808 | kfree(mp); | 2072 | kfree(mp); |
1809 | } | 2073 | } |
1810 | 2074 | ||
2075 | /** | ||
2076 | * fc_exch_mgr_del() - Delete an EM from a local port's list | ||
2077 | * @ema: The exchange manager anchor identifying the EM to be deleted | ||
2078 | */ | ||
1811 | void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema) | 2079 | void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema) |
1812 | { | 2080 | { |
1813 | /* remove EM anchor from EM anchors list */ | 2081 | /* remove EM anchor from EM anchors list */ |
@@ -1817,7 +2085,35 @@ void fc_exch_mgr_del(struct fc_exch_mgr_anchor *ema) | |||
1817 | } | 2085 | } |
1818 | EXPORT_SYMBOL(fc_exch_mgr_del); | 2086 | EXPORT_SYMBOL(fc_exch_mgr_del); |
1819 | 2087 | ||
1820 | struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp, | 2088 | /** |
2089 | * fc_exch_mgr_list_clone() - Share all exchange manager objects | ||
2090 | * @src: Source lport to clone exchange managers from | ||
2091 | * @dst: New lport that takes references to all the exchange managers | ||
2092 | */ | ||
2093 | int fc_exch_mgr_list_clone(struct fc_lport *src, struct fc_lport *dst) | ||
2094 | { | ||
2095 | struct fc_exch_mgr_anchor *ema, *tmp; | ||
2096 | |||
2097 | list_for_each_entry(ema, &src->ema_list, ema_list) { | ||
2098 | if (!fc_exch_mgr_add(dst, ema->mp, ema->match)) | ||
2099 | goto err; | ||
2100 | } | ||
2101 | return 0; | ||
2102 | err: | ||
2103 | list_for_each_entry_safe(ema, tmp, &dst->ema_list, ema_list) | ||
2104 | fc_exch_mgr_del(ema); | ||
2105 | return -ENOMEM; | ||
2106 | } | ||
2107 | |||
2108 | /** | ||
2109 | * fc_exch_mgr_alloc() - Allocate an exchange manager | ||
2110 | * @lport: The local port that the new EM will be associated with | ||
2111 | * @class: The default FC class for new exchanges | ||
2112 | * @min_xid: The minimum XID for exchanges from the new EM | ||
2113 | * @max_xid: The maximum XID for exchanges from the new EM | ||
2114 | * @match: The match routine for the new EM | ||
2115 | */ | ||
2116 | struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lport, | ||
1821 | enum fc_class class, | 2117 | enum fc_class class, |
1822 | u16 min_xid, u16 max_xid, | 2118 | u16 min_xid, u16 max_xid, |
1823 | bool (*match)(struct fc_frame *)) | 2119 | bool (*match)(struct fc_frame *)) |
@@ -1830,7 +2126,7 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp, | |||
1830 | 2126 | ||
1831 | if (max_xid <= min_xid || max_xid == FC_XID_UNKNOWN || | 2127 | if (max_xid <= min_xid || max_xid == FC_XID_UNKNOWN || |
1832 | (min_xid & fc_cpu_mask) != 0) { | 2128 | (min_xid & fc_cpu_mask) != 0) { |
1833 | FC_LPORT_DBG(lp, "Invalid min_xid 0x:%x and max_xid 0x:%x\n", | 2129 | FC_LPORT_DBG(lport, "Invalid min_xid 0x:%x and max_xid 0x:%x\n", |
1834 | min_xid, max_xid); | 2130 | min_xid, max_xid); |
1835 | return NULL; | 2131 | return NULL; |
1836 | } | 2132 | } |
@@ -1873,7 +2169,7 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp, | |||
1873 | } | 2169 | } |
1874 | 2170 | ||
1875 | kref_init(&mp->kref); | 2171 | kref_init(&mp->kref); |
1876 | if (!fc_exch_mgr_add(lp, mp, match)) { | 2172 | if (!fc_exch_mgr_add(lport, mp, match)) { |
1877 | free_percpu(mp->pool); | 2173 | free_percpu(mp->pool); |
1878 | goto free_mempool; | 2174 | goto free_mempool; |
1879 | } | 2175 | } |
@@ -1894,76 +2190,26 @@ free_mp: | |||
1894 | } | 2190 | } |
1895 | EXPORT_SYMBOL(fc_exch_mgr_alloc); | 2191 | EXPORT_SYMBOL(fc_exch_mgr_alloc); |
1896 | 2192 | ||
2193 | /** | ||
2194 | * fc_exch_mgr_free() - Free all exchange managers on a local port | ||
2195 | * @lport: The local port whose EMs are to be freed | ||
2196 | */ | ||
1897 | void fc_exch_mgr_free(struct fc_lport *lport) | 2197 | void fc_exch_mgr_free(struct fc_lport *lport) |
1898 | { | 2198 | { |
1899 | struct fc_exch_mgr_anchor *ema, *next; | 2199 | struct fc_exch_mgr_anchor *ema, *next; |
1900 | 2200 | ||
2201 | flush_workqueue(fc_exch_workqueue); | ||
1901 | list_for_each_entry_safe(ema, next, &lport->ema_list, ema_list) | 2202 | list_for_each_entry_safe(ema, next, &lport->ema_list, ema_list) |
1902 | fc_exch_mgr_del(ema); | 2203 | fc_exch_mgr_del(ema); |
1903 | } | 2204 | } |
1904 | EXPORT_SYMBOL(fc_exch_mgr_free); | 2205 | EXPORT_SYMBOL(fc_exch_mgr_free); |
1905 | 2206 | ||
1906 | 2207 | /** | |
1907 | struct fc_seq *fc_exch_seq_send(struct fc_lport *lp, | 2208 | * fc_exch_recv() - Handler for received frames |
1908 | struct fc_frame *fp, | 2209 | * @lport: The local port the frame was received on |
1909 | void (*resp)(struct fc_seq *, | 2210 | * @fp: The received frame |
1910 | struct fc_frame *fp, | ||
1911 | void *arg), | ||
1912 | void (*destructor)(struct fc_seq *, void *), | ||
1913 | void *arg, u32 timer_msec) | ||
1914 | { | ||
1915 | struct fc_exch *ep; | ||
1916 | struct fc_seq *sp = NULL; | ||
1917 | struct fc_frame_header *fh; | ||
1918 | int rc = 1; | ||
1919 | |||
1920 | ep = fc_exch_alloc(lp, fp); | ||
1921 | if (!ep) { | ||
1922 | fc_frame_free(fp); | ||
1923 | return NULL; | ||
1924 | } | ||
1925 | ep->esb_stat |= ESB_ST_SEQ_INIT; | ||
1926 | fh = fc_frame_header_get(fp); | ||
1927 | fc_exch_set_addr(ep, ntoh24(fh->fh_s_id), ntoh24(fh->fh_d_id)); | ||
1928 | ep->resp = resp; | ||
1929 | ep->destructor = destructor; | ||
1930 | ep->arg = arg; | ||
1931 | ep->r_a_tov = FC_DEF_R_A_TOV; | ||
1932 | ep->lp = lp; | ||
1933 | sp = &ep->seq; | ||
1934 | |||
1935 | ep->fh_type = fh->fh_type; /* save for possbile timeout handling */ | ||
1936 | ep->f_ctl = ntoh24(fh->fh_f_ctl); | ||
1937 | fc_exch_setup_hdr(ep, fp, ep->f_ctl); | ||
1938 | sp->cnt++; | ||
1939 | |||
1940 | if (ep->xid <= lp->lro_xid) | ||
1941 | fc_fcp_ddp_setup(fr_fsp(fp), ep->xid); | ||
1942 | |||
1943 | if (unlikely(lp->tt.frame_send(lp, fp))) | ||
1944 | goto err; | ||
1945 | |||
1946 | if (timer_msec) | ||
1947 | fc_exch_timer_set_locked(ep, timer_msec); | ||
1948 | ep->f_ctl &= ~FC_FC_FIRST_SEQ; /* not first seq */ | ||
1949 | |||
1950 | if (ep->f_ctl & FC_FC_SEQ_INIT) | ||
1951 | ep->esb_stat &= ~ESB_ST_SEQ_INIT; | ||
1952 | spin_unlock_bh(&ep->ex_lock); | ||
1953 | return sp; | ||
1954 | err: | ||
1955 | rc = fc_exch_done_locked(ep); | ||
1956 | spin_unlock_bh(&ep->ex_lock); | ||
1957 | if (!rc) | ||
1958 | fc_exch_delete(ep); | ||
1959 | return NULL; | ||
1960 | } | ||
1961 | EXPORT_SYMBOL(fc_exch_seq_send); | ||
1962 | |||
1963 | /* | ||
1964 | * Receive a frame | ||
1965 | */ | 2211 | */ |
1966 | void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp) | 2212 | void fc_exch_recv(struct fc_lport *lport, struct fc_frame *fp) |
1967 | { | 2213 | { |
1968 | struct fc_frame_header *fh = fc_frame_header_get(fp); | 2214 | struct fc_frame_header *fh = fc_frame_header_get(fp); |
1969 | struct fc_exch_mgr_anchor *ema; | 2215 | struct fc_exch_mgr_anchor *ema; |
@@ -1971,8 +2217,8 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp) | |||
1971 | u16 oxid; | 2217 | u16 oxid; |
1972 | 2218 | ||
1973 | /* lport lock ? */ | 2219 | /* lport lock ? */ |
1974 | if (!lp || lp->state == LPORT_ST_DISABLED) { | 2220 | if (!lport || lport->state == LPORT_ST_DISABLED) { |
1975 | FC_LPORT_DBG(lp, "Receiving frames for an lport that " | 2221 | FC_LPORT_DBG(lport, "Receiving frames for an lport that " |
1976 | "has not been initialized correctly\n"); | 2222 | "has not been initialized correctly\n"); |
1977 | fc_frame_free(fp); | 2223 | fc_frame_free(fp); |
1978 | return; | 2224 | return; |
@@ -1981,7 +2227,7 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp) | |||
1981 | f_ctl = ntoh24(fh->fh_f_ctl); | 2227 | f_ctl = ntoh24(fh->fh_f_ctl); |
1982 | oxid = ntohs(fh->fh_ox_id); | 2228 | oxid = ntohs(fh->fh_ox_id); |
1983 | if (f_ctl & FC_FC_EX_CTX) { | 2229 | if (f_ctl & FC_FC_EX_CTX) { |
1984 | list_for_each_entry(ema, &lp->ema_list, ema_list) { | 2230 | list_for_each_entry(ema, &lport->ema_list, ema_list) { |
1985 | if ((oxid >= ema->mp->min_xid) && | 2231 | if ((oxid >= ema->mp->min_xid) && |
1986 | (oxid <= ema->mp->max_xid)) { | 2232 | (oxid <= ema->mp->max_xid)) { |
1987 | found = 1; | 2233 | found = 1; |
@@ -1990,13 +2236,13 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp) | |||
1990 | } | 2236 | } |
1991 | 2237 | ||
1992 | if (!found) { | 2238 | if (!found) { |
1993 | FC_LPORT_DBG(lp, "Received response for out " | 2239 | FC_LPORT_DBG(lport, "Received response for out " |
1994 | "of range oxid:%hx\n", oxid); | 2240 | "of range oxid:%hx\n", oxid); |
1995 | fc_frame_free(fp); | 2241 | fc_frame_free(fp); |
1996 | return; | 2242 | return; |
1997 | } | 2243 | } |
1998 | } else | 2244 | } else |
1999 | ema = list_entry(lp->ema_list.prev, typeof(*ema), ema_list); | 2245 | ema = list_entry(lport->ema_list.prev, typeof(*ema), ema_list); |
2000 | 2246 | ||
2001 | /* | 2247 | /* |
2002 | * If frame is marked invalid, just drop it. | 2248 | * If frame is marked invalid, just drop it. |
@@ -2015,37 +2261,56 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_frame *fp) | |||
2015 | else if (f_ctl & FC_FC_SEQ_CTX) | 2261 | else if (f_ctl & FC_FC_SEQ_CTX) |
2016 | fc_exch_recv_resp(ema->mp, fp); | 2262 | fc_exch_recv_resp(ema->mp, fp); |
2017 | else | 2263 | else |
2018 | fc_exch_recv_req(lp, ema->mp, fp); | 2264 | fc_exch_recv_req(lport, ema->mp, fp); |
2019 | break; | 2265 | break; |
2020 | default: | 2266 | default: |
2021 | FC_LPORT_DBG(lp, "dropping invalid frame (eof %x)", fr_eof(fp)); | 2267 | FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)", |
2268 | fr_eof(fp)); | ||
2022 | fc_frame_free(fp); | 2269 | fc_frame_free(fp); |
2023 | } | 2270 | } |
2024 | } | 2271 | } |
2025 | EXPORT_SYMBOL(fc_exch_recv); | 2272 | EXPORT_SYMBOL(fc_exch_recv); |
2026 | 2273 | ||
2027 | int fc_exch_init(struct fc_lport *lp) | 2274 | /** |
2275 | * fc_exch_init() - Initialize the exchange layer for a local port | ||
2276 | * @lport: The local port to initialize the exchange layer for | ||
2277 | */ | ||
2278 | int fc_exch_init(struct fc_lport *lport) | ||
2028 | { | 2279 | { |
2029 | if (!lp->tt.seq_start_next) | 2280 | if (!lport->tt.seq_start_next) |
2030 | lp->tt.seq_start_next = fc_seq_start_next; | 2281 | lport->tt.seq_start_next = fc_seq_start_next; |
2031 | 2282 | ||
2032 | if (!lp->tt.exch_seq_send) | 2283 | if (!lport->tt.exch_seq_send) |
2033 | lp->tt.exch_seq_send = fc_exch_seq_send; | 2284 | lport->tt.exch_seq_send = fc_exch_seq_send; |
2034 | 2285 | ||
2035 | if (!lp->tt.seq_send) | 2286 | if (!lport->tt.seq_send) |
2036 | lp->tt.seq_send = fc_seq_send; | 2287 | lport->tt.seq_send = fc_seq_send; |
2037 | 2288 | ||
2038 | if (!lp->tt.seq_els_rsp_send) | 2289 | if (!lport->tt.seq_els_rsp_send) |
2039 | lp->tt.seq_els_rsp_send = fc_seq_els_rsp_send; | 2290 | lport->tt.seq_els_rsp_send = fc_seq_els_rsp_send; |
2040 | 2291 | ||
2041 | if (!lp->tt.exch_done) | 2292 | if (!lport->tt.exch_done) |
2042 | lp->tt.exch_done = fc_exch_done; | 2293 | lport->tt.exch_done = fc_exch_done; |
2043 | 2294 | ||
2044 | if (!lp->tt.exch_mgr_reset) | 2295 | if (!lport->tt.exch_mgr_reset) |
2045 | lp->tt.exch_mgr_reset = fc_exch_mgr_reset; | 2296 | lport->tt.exch_mgr_reset = fc_exch_mgr_reset; |
2046 | 2297 | ||
2047 | if (!lp->tt.seq_exch_abort) | 2298 | if (!lport->tt.seq_exch_abort) |
2048 | lp->tt.seq_exch_abort = fc_seq_exch_abort; | 2299 | lport->tt.seq_exch_abort = fc_seq_exch_abort; |
2300 | |||
2301 | return 0; | ||
2302 | } | ||
2303 | EXPORT_SYMBOL(fc_exch_init); | ||
2304 | |||
2305 | /** | ||
2306 | * fc_setup_exch_mgr() - Setup an exchange manager | ||
2307 | */ | ||
2308 | int fc_setup_exch_mgr() | ||
2309 | { | ||
2310 | fc_em_cachep = kmem_cache_create("libfc_em", sizeof(struct fc_exch), | ||
2311 | 0, SLAB_HWCACHE_ALIGN, NULL); | ||
2312 | if (!fc_em_cachep) | ||
2313 | return -ENOMEM; | ||
2049 | 2314 | ||
2050 | /* | 2315 | /* |
2051 | * Initialize fc_cpu_mask and fc_cpu_order. The | 2316 | * Initialize fc_cpu_mask and fc_cpu_order. The |
@@ -2069,20 +2334,17 @@ int fc_exch_init(struct fc_lport *lp) | |||
2069 | } | 2334 | } |
2070 | fc_cpu_mask--; | 2335 | fc_cpu_mask--; |
2071 | 2336 | ||
2072 | return 0; | 2337 | fc_exch_workqueue = create_singlethread_workqueue("fc_exch_workqueue"); |
2073 | } | 2338 | if (!fc_exch_workqueue) |
2074 | EXPORT_SYMBOL(fc_exch_init); | ||
2075 | |||
2076 | int fc_setup_exch_mgr(void) | ||
2077 | { | ||
2078 | fc_em_cachep = kmem_cache_create("libfc_em", sizeof(struct fc_exch), | ||
2079 | 0, SLAB_HWCACHE_ALIGN, NULL); | ||
2080 | if (!fc_em_cachep) | ||
2081 | return -ENOMEM; | 2339 | return -ENOMEM; |
2082 | return 0; | 2340 | return 0; |
2083 | } | 2341 | } |
2084 | 2342 | ||
2085 | void fc_destroy_exch_mgr(void) | 2343 | /** |
2344 | * fc_destroy_exch_mgr() - Destroy an exchange manager | ||
2345 | */ | ||
2346 | void fc_destroy_exch_mgr() | ||
2086 | { | 2347 | { |
2348 | destroy_workqueue(fc_exch_workqueue); | ||
2087 | kmem_cache_destroy(fc_em_cachep); | 2349 | kmem_cache_destroy(fc_em_cachep); |
2088 | } | 2350 | } |
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c index 59a4408b27b5..c4b58d042f6f 100644 --- a/drivers/scsi/libfc/fc_fcp.c +++ b/drivers/scsi/libfc/fc_fcp.c | |||
@@ -39,15 +39,9 @@ | |||
39 | #include <scsi/libfc.h> | 39 | #include <scsi/libfc.h> |
40 | #include <scsi/fc_encode.h> | 40 | #include <scsi/fc_encode.h> |
41 | 41 | ||
42 | MODULE_AUTHOR("Open-FCoE.org"); | 42 | #include "fc_libfc.h" |
43 | MODULE_DESCRIPTION("libfc"); | ||
44 | MODULE_LICENSE("GPL v2"); | ||
45 | 43 | ||
46 | unsigned int fc_debug_logging; | 44 | struct kmem_cache *scsi_pkt_cachep; |
47 | module_param_named(debug_logging, fc_debug_logging, int, S_IRUGO|S_IWUSR); | ||
48 | MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels"); | ||
49 | |||
50 | static struct kmem_cache *scsi_pkt_cachep; | ||
51 | 45 | ||
52 | /* SRB state definitions */ | 46 | /* SRB state definitions */ |
53 | #define FC_SRB_FREE 0 /* cmd is free */ | 47 | #define FC_SRB_FREE 0 /* cmd is free */ |
@@ -58,7 +52,6 @@ static struct kmem_cache *scsi_pkt_cachep; | |||
58 | #define FC_SRB_DISCONTIG (1 << 4) /* non-sequential data recvd */ | 52 | #define FC_SRB_DISCONTIG (1 << 4) /* non-sequential data recvd */ |
59 | #define FC_SRB_COMPL (1 << 5) /* fc_io_compl has been run */ | 53 | #define FC_SRB_COMPL (1 << 5) /* fc_io_compl has been run */ |
60 | #define FC_SRB_FCP_PROCESSING_TMO (1 << 6) /* timer function processing */ | 54 | #define FC_SRB_FCP_PROCESSING_TMO (1 << 6) /* timer function processing */ |
61 | #define FC_SRB_NOMEM (1 << 7) /* dropped to out of mem */ | ||
62 | 55 | ||
63 | #define FC_SRB_READ (1 << 1) | 56 | #define FC_SRB_READ (1 << 1) |
64 | #define FC_SRB_WRITE (1 << 0) | 57 | #define FC_SRB_WRITE (1 << 0) |
@@ -73,10 +66,20 @@ static struct kmem_cache *scsi_pkt_cachep; | |||
73 | #define CMD_SCSI_STATUS(Cmnd) ((Cmnd)->SCp.Status) | 66 | #define CMD_SCSI_STATUS(Cmnd) ((Cmnd)->SCp.Status) |
74 | #define CMD_RESID_LEN(Cmnd) ((Cmnd)->SCp.buffers_residual) | 67 | #define CMD_RESID_LEN(Cmnd) ((Cmnd)->SCp.buffers_residual) |
75 | 68 | ||
69 | /** | ||
70 | * struct fc_fcp_internal - FCP layer internal data | ||
71 | * @scsi_pkt_pool: Memory pool to draw FCP packets from | ||
72 | * @scsi_pkt_queue: Current FCP packets | ||
73 | * @last_can_queue_ramp_down_time: ramp down time | ||
74 | * @last_can_queue_ramp_up_time: ramp up time | ||
75 | * @max_can_queue: max can_queue size | ||
76 | */ | ||
76 | struct fc_fcp_internal { | 77 | struct fc_fcp_internal { |
77 | mempool_t *scsi_pkt_pool; | 78 | mempool_t *scsi_pkt_pool; |
78 | struct list_head scsi_pkt_queue; | 79 | struct list_head scsi_pkt_queue; |
79 | u8 throttled; | 80 | unsigned long last_can_queue_ramp_down_time; |
81 | unsigned long last_can_queue_ramp_up_time; | ||
82 | int max_can_queue; | ||
80 | }; | 83 | }; |
81 | 84 | ||
82 | #define fc_get_scsi_internal(x) ((struct fc_fcp_internal *)(x)->scsi_priv) | 85 | #define fc_get_scsi_internal(x) ((struct fc_fcp_internal *)(x)->scsi_priv) |
@@ -90,9 +93,9 @@ static void fc_fcp_recv(struct fc_seq *, struct fc_frame *, void *); | |||
90 | static void fc_fcp_resp(struct fc_fcp_pkt *, struct fc_frame *); | 93 | static void fc_fcp_resp(struct fc_fcp_pkt *, struct fc_frame *); |
91 | static void fc_fcp_complete_locked(struct fc_fcp_pkt *); | 94 | static void fc_fcp_complete_locked(struct fc_fcp_pkt *); |
92 | static void fc_tm_done(struct fc_seq *, struct fc_frame *, void *); | 95 | static void fc_tm_done(struct fc_seq *, struct fc_frame *, void *); |
93 | static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp); | 96 | static void fc_fcp_error(struct fc_fcp_pkt *, struct fc_frame *); |
94 | static void fc_timeout_error(struct fc_fcp_pkt *); | 97 | static void fc_timeout_error(struct fc_fcp_pkt *); |
95 | static void fc_fcp_timeout(unsigned long data); | 98 | static void fc_fcp_timeout(unsigned long); |
96 | static void fc_fcp_rec(struct fc_fcp_pkt *); | 99 | static void fc_fcp_rec(struct fc_fcp_pkt *); |
97 | static void fc_fcp_rec_error(struct fc_fcp_pkt *, struct fc_frame *); | 100 | static void fc_fcp_rec_error(struct fc_fcp_pkt *, struct fc_frame *); |
98 | static void fc_fcp_rec_resp(struct fc_seq *, struct fc_frame *, void *); | 101 | static void fc_fcp_rec_resp(struct fc_seq *, struct fc_frame *, void *); |
@@ -124,6 +127,7 @@ static void fc_fcp_srr_error(struct fc_fcp_pkt *, struct fc_frame *); | |||
124 | #define FC_SCSI_TM_TOV (10 * HZ) | 127 | #define FC_SCSI_TM_TOV (10 * HZ) |
125 | #define FC_SCSI_REC_TOV (2 * HZ) | 128 | #define FC_SCSI_REC_TOV (2 * HZ) |
126 | #define FC_HOST_RESET_TIMEOUT (30 * HZ) | 129 | #define FC_HOST_RESET_TIMEOUT (30 * HZ) |
130 | #define FC_CAN_QUEUE_PERIOD (60 * HZ) | ||
127 | 131 | ||
128 | #define FC_MAX_ERROR_CNT 5 | 132 | #define FC_MAX_ERROR_CNT 5 |
129 | #define FC_MAX_RECOV_RETRY 3 | 133 | #define FC_MAX_RECOV_RETRY 3 |
@@ -131,23 +135,22 @@ static void fc_fcp_srr_error(struct fc_fcp_pkt *, struct fc_frame *); | |||
131 | #define FC_FCP_DFLT_QUEUE_DEPTH 32 | 135 | #define FC_FCP_DFLT_QUEUE_DEPTH 32 |
132 | 136 | ||
133 | /** | 137 | /** |
134 | * fc_fcp_pkt_alloc - allocation routine for scsi_pkt packet | 138 | * fc_fcp_pkt_alloc() - Allocate a fcp_pkt |
135 | * @lp: fc lport struct | 139 | * @lport: The local port that the FCP packet is for |
136 | * @gfp: gfp flags for allocation | 140 | * @gfp: GFP flags for allocation |
137 | * | 141 | * |
138 | * This is used by upper layer scsi driver. | 142 | * Return value: fcp_pkt structure or null on allocation failure. |
139 | * Return Value : scsi_pkt structure or null on allocation failure. | 143 | * Context: Can be called from process context, no lock is required. |
140 | * Context : call from process context. no locking required. | ||
141 | */ | 144 | */ |
142 | static struct fc_fcp_pkt *fc_fcp_pkt_alloc(struct fc_lport *lp, gfp_t gfp) | 145 | static struct fc_fcp_pkt *fc_fcp_pkt_alloc(struct fc_lport *lport, gfp_t gfp) |
143 | { | 146 | { |
144 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | 147 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); |
145 | struct fc_fcp_pkt *fsp; | 148 | struct fc_fcp_pkt *fsp; |
146 | 149 | ||
147 | fsp = mempool_alloc(si->scsi_pkt_pool, gfp); | 150 | fsp = mempool_alloc(si->scsi_pkt_pool, gfp); |
148 | if (fsp) { | 151 | if (fsp) { |
149 | memset(fsp, 0, sizeof(*fsp)); | 152 | memset(fsp, 0, sizeof(*fsp)); |
150 | fsp->lp = lp; | 153 | fsp->lp = lport; |
151 | atomic_set(&fsp->ref_cnt, 1); | 154 | atomic_set(&fsp->ref_cnt, 1); |
152 | init_timer(&fsp->timer); | 155 | init_timer(&fsp->timer); |
153 | INIT_LIST_HEAD(&fsp->list); | 156 | INIT_LIST_HEAD(&fsp->list); |
@@ -157,12 +160,11 @@ static struct fc_fcp_pkt *fc_fcp_pkt_alloc(struct fc_lport *lp, gfp_t gfp) | |||
157 | } | 160 | } |
158 | 161 | ||
159 | /** | 162 | /** |
160 | * fc_fcp_pkt_release() - release hold on scsi_pkt packet | 163 | * fc_fcp_pkt_release() - Release hold on a fcp_pkt |
161 | * @fsp: fcp packet struct | 164 | * @fsp: The FCP packet to be released |
162 | * | 165 | * |
163 | * This is used by upper layer scsi driver. | 166 | * Context: Can be called from process or interrupt context, |
164 | * Context : call from process and interrupt context. | 167 | * no lock is required. |
165 | * no locking required | ||
166 | */ | 168 | */ |
167 | static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp) | 169 | static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp) |
168 | { | 170 | { |
@@ -173,20 +175,25 @@ static void fc_fcp_pkt_release(struct fc_fcp_pkt *fsp) | |||
173 | } | 175 | } |
174 | } | 176 | } |
175 | 177 | ||
178 | /** | ||
179 | * fc_fcp_pkt_hold() - Hold a fcp_pkt | ||
180 | * @fsp: The FCP packet to be held | ||
181 | */ | ||
176 | static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp) | 182 | static void fc_fcp_pkt_hold(struct fc_fcp_pkt *fsp) |
177 | { | 183 | { |
178 | atomic_inc(&fsp->ref_cnt); | 184 | atomic_inc(&fsp->ref_cnt); |
179 | } | 185 | } |
180 | 186 | ||
181 | /** | 187 | /** |
182 | * fc_fcp_pkt_destory() - release hold on scsi_pkt packet | 188 | * fc_fcp_pkt_destory() - Release hold on a fcp_pkt |
183 | * @seq: exchange sequence | 189 | * @seq: The sequence that the FCP packet is on (required by destructor API) |
184 | * @fsp: fcp packet struct | 190 | * @fsp: The FCP packet to be released |
191 | * | ||
192 | * This routine is called by a destructor callback in the exch_seq_send() | ||
193 | * routine of the libfc Transport Template. The 'struct fc_seq' is a required | ||
194 | * argument even though it is not used by this routine. | ||
185 | * | 195 | * |
186 | * Release hold on scsi_pkt packet set to keep scsi_pkt | 196 | * Context: No locking required. |
187 | * till EM layer exch resource is not freed. | ||
188 | * Context : called from from EM layer. | ||
189 | * no locking required | ||
190 | */ | 197 | */ |
191 | static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp) | 198 | static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp) |
192 | { | 199 | { |
@@ -194,10 +201,10 @@ static void fc_fcp_pkt_destroy(struct fc_seq *seq, void *fsp) | |||
194 | } | 201 | } |
195 | 202 | ||
196 | /** | 203 | /** |
197 | * fc_fcp_lock_pkt() - lock a packet and get a ref to it. | 204 | * fc_fcp_lock_pkt() - Lock a fcp_pkt and increase its reference count |
198 | * @fsp: fcp packet | 205 | * @fsp: The FCP packet to be locked and incremented |
199 | * | 206 | * |
200 | * We should only return error if we return a command to scsi-ml before | 207 | * We should only return error if we return a command to SCSI-ml before |
201 | * getting a response. This can happen in cases where we send a abort, but | 208 | * getting a response. This can happen in cases where we send a abort, but |
202 | * do not wait for the response and the abort and command can be passing | 209 | * do not wait for the response and the abort and command can be passing |
203 | * each other on the wire/network-layer. | 210 | * each other on the wire/network-layer. |
@@ -222,18 +229,33 @@ static inline int fc_fcp_lock_pkt(struct fc_fcp_pkt *fsp) | |||
222 | return 0; | 229 | return 0; |
223 | } | 230 | } |
224 | 231 | ||
232 | /** | ||
233 | * fc_fcp_unlock_pkt() - Release a fcp_pkt's lock and decrement its | ||
234 | * reference count | ||
235 | * @fsp: The FCP packet to be unlocked and decremented | ||
236 | */ | ||
225 | static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp) | 237 | static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt *fsp) |
226 | { | 238 | { |
227 | spin_unlock_bh(&fsp->scsi_pkt_lock); | 239 | spin_unlock_bh(&fsp->scsi_pkt_lock); |
228 | fc_fcp_pkt_release(fsp); | 240 | fc_fcp_pkt_release(fsp); |
229 | } | 241 | } |
230 | 242 | ||
243 | /** | ||
244 | * fc_fcp_timer_set() - Start a timer for a fcp_pkt | ||
245 | * @fsp: The FCP packet to start a timer for | ||
246 | * @delay: The timeout period for the timer | ||
247 | */ | ||
231 | static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay) | 248 | static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay) |
232 | { | 249 | { |
233 | if (!(fsp->state & FC_SRB_COMPL)) | 250 | if (!(fsp->state & FC_SRB_COMPL)) |
234 | mod_timer(&fsp->timer, jiffies + delay); | 251 | mod_timer(&fsp->timer, jiffies + delay); |
235 | } | 252 | } |
236 | 253 | ||
254 | /** | ||
255 | * fc_fcp_send_abort() - Send an abort for exchanges associated with a | ||
256 | * fcp_pkt | ||
257 | * @fsp: The FCP packet to abort exchanges on | ||
258 | */ | ||
237 | static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp) | 259 | static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp) |
238 | { | 260 | { |
239 | if (!fsp->seq_ptr) | 261 | if (!fsp->seq_ptr) |
@@ -243,9 +265,14 @@ static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp) | |||
243 | return fsp->lp->tt.seq_exch_abort(fsp->seq_ptr, 0); | 265 | return fsp->lp->tt.seq_exch_abort(fsp->seq_ptr, 0); |
244 | } | 266 | } |
245 | 267 | ||
246 | /* | 268 | /** |
247 | * Retry command. | 269 | * fc_fcp_retry_cmd() - Retry a fcp_pkt |
248 | * An abort isn't needed. | 270 | * @fsp: The FCP packet to be retried |
271 | * | ||
272 | * Sets the status code to be FC_ERROR and then calls | ||
273 | * fc_fcp_complete_locked() which in turn calls fc_io_compl(). | ||
274 | * fc_io_compl() will notify the SCSI-ml that the I/O is done. | ||
275 | * The SCSI-ml will retry the command. | ||
249 | */ | 276 | */ |
250 | static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp) | 277 | static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp) |
251 | { | 278 | { |
@@ -260,64 +287,146 @@ static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp) | |||
260 | fc_fcp_complete_locked(fsp); | 287 | fc_fcp_complete_locked(fsp); |
261 | } | 288 | } |
262 | 289 | ||
263 | /* | 290 | /** |
264 | * fc_fcp_ddp_setup - calls to LLD's ddp_setup to set up DDP | 291 | * fc_fcp_ddp_setup() - Calls a LLD's ddp_setup routine to set up DDP context |
265 | * transfer for a read I/O indicated by the fc_fcp_pkt. | 292 | * @fsp: The FCP packet that will manage the DDP frames |
266 | * @fsp: ptr to the fc_fcp_pkt | 293 | * @xid: The XID that will be used for the DDP exchange |
267 | * | ||
268 | * This is called in exch_seq_send() when we have a newly allocated | ||
269 | * exchange with a valid exchange id to setup ddp. | ||
270 | * | ||
271 | * returns: none | ||
272 | */ | 294 | */ |
273 | void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid) | 295 | void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid) |
274 | { | 296 | { |
275 | struct fc_lport *lp; | 297 | struct fc_lport *lport; |
276 | 298 | ||
277 | if (!fsp) | 299 | if (!fsp) |
278 | return; | 300 | return; |
279 | 301 | ||
280 | lp = fsp->lp; | 302 | lport = fsp->lp; |
281 | if ((fsp->req_flags & FC_SRB_READ) && | 303 | if ((fsp->req_flags & FC_SRB_READ) && |
282 | (lp->lro_enabled) && (lp->tt.ddp_setup)) { | 304 | (lport->lro_enabled) && (lport->tt.ddp_setup)) { |
283 | if (lp->tt.ddp_setup(lp, xid, scsi_sglist(fsp->cmd), | 305 | if (lport->tt.ddp_setup(lport, xid, scsi_sglist(fsp->cmd), |
284 | scsi_sg_count(fsp->cmd))) | 306 | scsi_sg_count(fsp->cmd))) |
285 | fsp->xfer_ddp = xid; | 307 | fsp->xfer_ddp = xid; |
286 | } | 308 | } |
287 | } | 309 | } |
288 | EXPORT_SYMBOL(fc_fcp_ddp_setup); | ||
289 | 310 | ||
290 | /* | 311 | /** |
291 | * fc_fcp_ddp_done - calls to LLD's ddp_done to release any | 312 | * fc_fcp_ddp_done() - Calls a LLD's ddp_done routine to release any |
292 | * DDP related resources for this I/O if it is initialized | 313 | * DDP related resources for a fcp_pkt |
293 | * as a ddp transfer | 314 | * @fsp: The FCP packet that DDP had been used on |
294 | * @fsp: ptr to the fc_fcp_pkt | ||
295 | * | ||
296 | * returns: none | ||
297 | */ | 315 | */ |
298 | static void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp) | 316 | static void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp) |
299 | { | 317 | { |
300 | struct fc_lport *lp; | 318 | struct fc_lport *lport; |
301 | 319 | ||
302 | if (!fsp) | 320 | if (!fsp) |
303 | return; | 321 | return; |
304 | 322 | ||
305 | lp = fsp->lp; | 323 | if (fsp->xfer_ddp == FC_XID_UNKNOWN) |
306 | if (fsp->xfer_ddp && lp->tt.ddp_done) { | 324 | return; |
307 | fsp->xfer_len = lp->tt.ddp_done(lp, fsp->xfer_ddp); | 325 | |
308 | fsp->xfer_ddp = 0; | 326 | lport = fsp->lp; |
327 | if (lport->tt.ddp_done) { | ||
328 | fsp->xfer_len = lport->tt.ddp_done(lport, fsp->xfer_ddp); | ||
329 | fsp->xfer_ddp = FC_XID_UNKNOWN; | ||
309 | } | 330 | } |
310 | } | 331 | } |
311 | 332 | ||
333 | /** | ||
334 | * fc_fcp_can_queue_ramp_up() - increases can_queue | ||
335 | * @lport: lport to ramp up can_queue | ||
336 | * | ||
337 | * Locking notes: Called with Scsi_Host lock held | ||
338 | */ | ||
339 | static void fc_fcp_can_queue_ramp_up(struct fc_lport *lport) | ||
340 | { | ||
341 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); | ||
342 | int can_queue; | ||
343 | |||
344 | if (si->last_can_queue_ramp_up_time && | ||
345 | (time_before(jiffies, si->last_can_queue_ramp_up_time + | ||
346 | FC_CAN_QUEUE_PERIOD))) | ||
347 | return; | ||
348 | |||
349 | if (time_before(jiffies, si->last_can_queue_ramp_down_time + | ||
350 | FC_CAN_QUEUE_PERIOD)) | ||
351 | return; | ||
352 | |||
353 | si->last_can_queue_ramp_up_time = jiffies; | ||
354 | |||
355 | can_queue = lport->host->can_queue << 1; | ||
356 | if (can_queue >= si->max_can_queue) { | ||
357 | can_queue = si->max_can_queue; | ||
358 | si->last_can_queue_ramp_down_time = 0; | ||
359 | } | ||
360 | lport->host->can_queue = can_queue; | ||
361 | shost_printk(KERN_ERR, lport->host, "libfc: increased " | ||
362 | "can_queue to %d.\n", can_queue); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * fc_fcp_can_queue_ramp_down() - reduces can_queue | ||
367 | * @lport: lport to reduce can_queue | ||
368 | * | ||
369 | * If we are getting memory allocation failures, then we may | ||
370 | * be trying to execute too many commands. We let the running | ||
371 | * commands complete or timeout, then try again with a reduced | ||
372 | * can_queue. Eventually we will hit the point where we run | ||
373 | * on all reserved structs. | ||
374 | * | ||
375 | * Locking notes: Called with Scsi_Host lock held | ||
376 | */ | ||
377 | static void fc_fcp_can_queue_ramp_down(struct fc_lport *lport) | ||
378 | { | ||
379 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); | ||
380 | int can_queue; | ||
381 | |||
382 | if (si->last_can_queue_ramp_down_time && | ||
383 | (time_before(jiffies, si->last_can_queue_ramp_down_time + | ||
384 | FC_CAN_QUEUE_PERIOD))) | ||
385 | return; | ||
386 | |||
387 | si->last_can_queue_ramp_down_time = jiffies; | ||
388 | |||
389 | can_queue = lport->host->can_queue; | ||
390 | can_queue >>= 1; | ||
391 | if (!can_queue) | ||
392 | can_queue = 1; | ||
393 | lport->host->can_queue = can_queue; | ||
394 | shost_printk(KERN_ERR, lport->host, "libfc: Could not allocate frame.\n" | ||
395 | "Reducing can_queue to %d.\n", can_queue); | ||
396 | } | ||
312 | 397 | ||
313 | /* | 398 | /* |
314 | * Receive SCSI data from target. | 399 | * fc_fcp_frame_alloc() - Allocates fc_frame structure and buffer. |
315 | * Called after receiving solicited data. | 400 | * @lport: fc lport struct |
401 | * @len: payload length | ||
402 | * | ||
403 | * Allocates fc_frame structure and buffer but if fails to allocate | ||
404 | * then reduce can_queue. | ||
405 | */ | ||
406 | static inline struct fc_frame *fc_fcp_frame_alloc(struct fc_lport *lport, | ||
407 | size_t len) | ||
408 | { | ||
409 | struct fc_frame *fp; | ||
410 | unsigned long flags; | ||
411 | |||
412 | fp = fc_frame_alloc(lport, len); | ||
413 | if (!fp) { | ||
414 | spin_lock_irqsave(lport->host->host_lock, flags); | ||
415 | fc_fcp_can_queue_ramp_down(lport); | ||
416 | spin_unlock_irqrestore(lport->host->host_lock, flags); | ||
417 | } | ||
418 | return fp; | ||
419 | } | ||
420 | |||
421 | /** | ||
422 | * fc_fcp_recv_data() - Handler for receiving SCSI-FCP data from a target | ||
423 | * @fsp: The FCP packet the data is on | ||
424 | * @fp: The data frame | ||
316 | */ | 425 | */ |
317 | static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 426 | static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
318 | { | 427 | { |
319 | struct scsi_cmnd *sc = fsp->cmd; | 428 | struct scsi_cmnd *sc = fsp->cmd; |
320 | struct fc_lport *lp = fsp->lp; | 429 | struct fc_lport *lport = fsp->lp; |
321 | struct fcoe_dev_stats *stats; | 430 | struct fcoe_dev_stats *stats; |
322 | struct fc_frame_header *fh; | 431 | struct fc_frame_header *fh; |
323 | size_t start_offset; | 432 | size_t start_offset; |
@@ -327,7 +436,7 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | |||
327 | size_t len; | 436 | size_t len; |
328 | void *buf; | 437 | void *buf; |
329 | struct scatterlist *sg; | 438 | struct scatterlist *sg; |
330 | size_t remaining; | 439 | u32 nents; |
331 | 440 | ||
332 | fh = fc_frame_header_get(fp); | 441 | fh = fc_frame_header_get(fp); |
333 | offset = ntohl(fh->fh_parm_offset); | 442 | offset = ntohl(fh->fh_parm_offset); |
@@ -351,65 +460,29 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | |||
351 | if (offset != fsp->xfer_len) | 460 | if (offset != fsp->xfer_len) |
352 | fsp->state |= FC_SRB_DISCONTIG; | 461 | fsp->state |= FC_SRB_DISCONTIG; |
353 | 462 | ||
354 | crc = 0; | ||
355 | if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) | ||
356 | crc = crc32(~0, (u8 *) fh, sizeof(*fh)); | ||
357 | |||
358 | sg = scsi_sglist(sc); | 463 | sg = scsi_sglist(sc); |
359 | remaining = len; | 464 | nents = scsi_sg_count(sc); |
360 | |||
361 | while (remaining > 0 && sg) { | ||
362 | size_t off; | ||
363 | void *page_addr; | ||
364 | size_t sg_bytes; | ||
365 | 465 | ||
366 | if (offset >= sg->length) { | 466 | if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED)) { |
367 | offset -= sg->length; | 467 | copy_len = fc_copy_buffer_to_sglist(buf, len, sg, &nents, |
368 | sg = sg_next(sg); | 468 | &offset, KM_SOFTIRQ0, NULL); |
369 | continue; | 469 | } else { |
370 | } | 470 | crc = crc32(~0, (u8 *) fh, sizeof(*fh)); |
371 | sg_bytes = min(remaining, sg->length - offset); | 471 | copy_len = fc_copy_buffer_to_sglist(buf, len, sg, &nents, |
372 | 472 | &offset, KM_SOFTIRQ0, &crc); | |
373 | /* | ||
374 | * The scatterlist item may be bigger than PAGE_SIZE, | ||
375 | * but we are limited to mapping PAGE_SIZE at a time. | ||
376 | */ | ||
377 | off = offset + sg->offset; | ||
378 | sg_bytes = min(sg_bytes, (size_t) | ||
379 | (PAGE_SIZE - (off & ~PAGE_MASK))); | ||
380 | page_addr = kmap_atomic(sg_page(sg) + (off >> PAGE_SHIFT), | ||
381 | KM_SOFTIRQ0); | ||
382 | if (!page_addr) | ||
383 | break; /* XXX panic? */ | ||
384 | |||
385 | if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) | ||
386 | crc = crc32(crc, buf, sg_bytes); | ||
387 | memcpy((char *)page_addr + (off & ~PAGE_MASK), buf, | ||
388 | sg_bytes); | ||
389 | |||
390 | kunmap_atomic(page_addr, KM_SOFTIRQ0); | ||
391 | buf += sg_bytes; | ||
392 | offset += sg_bytes; | ||
393 | remaining -= sg_bytes; | ||
394 | copy_len += sg_bytes; | ||
395 | } | ||
396 | |||
397 | if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) { | ||
398 | buf = fc_frame_payload_get(fp, 0); | 473 | buf = fc_frame_payload_get(fp, 0); |
399 | if (len % 4) { | 474 | if (len % 4) |
400 | crc = crc32(crc, buf + len, 4 - (len % 4)); | 475 | crc = crc32(crc, buf + len, 4 - (len % 4)); |
401 | len += 4 - (len % 4); | ||
402 | } | ||
403 | 476 | ||
404 | if (~crc != le32_to_cpu(fr_crc(fp))) { | 477 | if (~crc != le32_to_cpu(fr_crc(fp))) { |
405 | crc_err: | 478 | crc_err: |
406 | stats = fc_lport_get_stats(lp); | 479 | stats = fc_lport_get_stats(lport); |
407 | stats->ErrorFrames++; | 480 | stats->ErrorFrames++; |
408 | /* FIXME - per cpu count, not total count! */ | 481 | /* FIXME - per cpu count, not total count! */ |
409 | if (stats->InvalidCRCCount++ < 5) | 482 | if (stats->InvalidCRCCount++ < 5) |
410 | printk(KERN_WARNING "libfc: CRC error on data " | 483 | printk(KERN_WARNING "libfc: CRC error on data " |
411 | "frame for port (%6x)\n", | 484 | "frame for port (%6x)\n", |
412 | fc_host_port_id(lp->host)); | 485 | fc_host_port_id(lport->host)); |
413 | /* | 486 | /* |
414 | * Assume the frame is total garbage. | 487 | * Assume the frame is total garbage. |
415 | * We may have copied it over the good part | 488 | * We may have copied it over the good part |
@@ -437,18 +510,17 @@ crc_err: | |||
437 | } | 510 | } |
438 | 511 | ||
439 | /** | 512 | /** |
440 | * fc_fcp_send_data() - Send SCSI data to target. | 513 | * fc_fcp_send_data() - Send SCSI data to a target |
441 | * @fsp: ptr to fc_fcp_pkt | 514 | * @fsp: The FCP packet the data is on |
442 | * @sp: ptr to this sequence | 515 | * @sp: The sequence the data is to be sent on |
443 | * @offset: starting offset for this data request | 516 | * @offset: The starting offset for this data request |
444 | * @seq_blen: the burst length for this data request | 517 | * @seq_blen: The burst length for this data request |
445 | * | 518 | * |
446 | * Called after receiving a Transfer Ready data descriptor. | 519 | * Called after receiving a Transfer Ready data descriptor. |
447 | * if LLD is capable of seq offload then send down seq_blen | 520 | * If the LLD is capable of sequence offload then send down the |
448 | * size of data in single frame, otherwise send multiple FC | 521 | * seq_blen ammount of data in single frame, otherwise send |
449 | * frames of max FC frame payload supported by target port. | 522 | * multiple frames of the maximum frame payload supported by |
450 | * | 523 | * the target port. |
451 | * Returns : 0 for success. | ||
452 | */ | 524 | */ |
453 | static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | 525 | static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, |
454 | size_t offset, size_t seq_blen) | 526 | size_t offset, size_t seq_blen) |
@@ -457,16 +529,18 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
457 | struct scsi_cmnd *sc; | 529 | struct scsi_cmnd *sc; |
458 | struct scatterlist *sg; | 530 | struct scatterlist *sg; |
459 | struct fc_frame *fp = NULL; | 531 | struct fc_frame *fp = NULL; |
460 | struct fc_lport *lp = fsp->lp; | 532 | struct fc_lport *lport = fsp->lp; |
533 | struct page *page; | ||
461 | size_t remaining; | 534 | size_t remaining; |
462 | size_t t_blen; | 535 | size_t t_blen; |
463 | size_t tlen; | 536 | size_t tlen; |
464 | size_t sg_bytes; | 537 | size_t sg_bytes; |
465 | size_t frame_offset, fh_parm_offset; | 538 | size_t frame_offset, fh_parm_offset; |
539 | size_t off; | ||
466 | int error; | 540 | int error; |
467 | void *data = NULL; | 541 | void *data = NULL; |
468 | void *page_addr; | 542 | void *page_addr; |
469 | int using_sg = lp->sg_supp; | 543 | int using_sg = lport->sg_supp; |
470 | u32 f_ctl; | 544 | u32 f_ctl; |
471 | 545 | ||
472 | WARN_ON(seq_blen <= 0); | 546 | WARN_ON(seq_blen <= 0); |
@@ -488,10 +562,10 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
488 | * to max FC frame payload previously set in fsp->max_payload. | 562 | * to max FC frame payload previously set in fsp->max_payload. |
489 | */ | 563 | */ |
490 | t_blen = fsp->max_payload; | 564 | t_blen = fsp->max_payload; |
491 | if (lp->seq_offload) { | 565 | if (lport->seq_offload) { |
492 | t_blen = min(seq_blen, (size_t)lp->lso_max); | 566 | t_blen = min(seq_blen, (size_t)lport->lso_max); |
493 | FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n", | 567 | FC_FCP_DBG(fsp, "fsp=%p:lso:blen=%zx lso_max=0x%x t_blen=%zx\n", |
494 | fsp, seq_blen, lp->lso_max, t_blen); | 568 | fsp, seq_blen, lport->lso_max, t_blen); |
495 | } | 569 | } |
496 | 570 | ||
497 | WARN_ON(t_blen < FC_MIN_MAX_PAYLOAD); | 571 | WARN_ON(t_blen < FC_MIN_MAX_PAYLOAD); |
@@ -503,7 +577,7 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
503 | remaining = seq_blen; | 577 | remaining = seq_blen; |
504 | fh_parm_offset = frame_offset = offset; | 578 | fh_parm_offset = frame_offset = offset; |
505 | tlen = 0; | 579 | tlen = 0; |
506 | seq = lp->tt.seq_start_next(seq); | 580 | seq = lport->tt.seq_start_next(seq); |
507 | f_ctl = FC_FC_REL_OFF; | 581 | f_ctl = FC_FC_REL_OFF; |
508 | WARN_ON(!seq); | 582 | WARN_ON(!seq); |
509 | 583 | ||
@@ -525,43 +599,34 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
525 | */ | 599 | */ |
526 | if (tlen % 4) | 600 | if (tlen % 4) |
527 | using_sg = 0; | 601 | using_sg = 0; |
528 | if (using_sg) { | 602 | fp = fc_frame_alloc(lport, using_sg ? 0 : tlen); |
529 | fp = _fc_frame_alloc(lp, 0); | 603 | if (!fp) |
530 | if (!fp) | 604 | return -ENOMEM; |
531 | return -ENOMEM; | ||
532 | } else { | ||
533 | fp = fc_frame_alloc(lp, tlen); | ||
534 | if (!fp) | ||
535 | return -ENOMEM; | ||
536 | 605 | ||
537 | data = (void *)(fr_hdr(fp)) + | 606 | data = fc_frame_header_get(fp) + 1; |
538 | sizeof(struct fc_frame_header); | ||
539 | } | ||
540 | fh_parm_offset = frame_offset; | 607 | fh_parm_offset = frame_offset; |
541 | fr_max_payload(fp) = fsp->max_payload; | 608 | fr_max_payload(fp) = fsp->max_payload; |
542 | } | 609 | } |
610 | |||
611 | off = offset + sg->offset; | ||
543 | sg_bytes = min(tlen, sg->length - offset); | 612 | sg_bytes = min(tlen, sg->length - offset); |
613 | sg_bytes = min(sg_bytes, | ||
614 | (size_t) (PAGE_SIZE - (off & ~PAGE_MASK))); | ||
615 | page = sg_page(sg) + (off >> PAGE_SHIFT); | ||
544 | if (using_sg) { | 616 | if (using_sg) { |
545 | get_page(sg_page(sg)); | 617 | get_page(page); |
546 | skb_fill_page_desc(fp_skb(fp), | 618 | skb_fill_page_desc(fp_skb(fp), |
547 | skb_shinfo(fp_skb(fp))->nr_frags, | 619 | skb_shinfo(fp_skb(fp))->nr_frags, |
548 | sg_page(sg), sg->offset + offset, | 620 | page, off & ~PAGE_MASK, sg_bytes); |
549 | sg_bytes); | ||
550 | fp_skb(fp)->data_len += sg_bytes; | 621 | fp_skb(fp)->data_len += sg_bytes; |
551 | fr_len(fp) += sg_bytes; | 622 | fr_len(fp) += sg_bytes; |
552 | fp_skb(fp)->truesize += PAGE_SIZE; | 623 | fp_skb(fp)->truesize += PAGE_SIZE; |
553 | } else { | 624 | } else { |
554 | size_t off = offset + sg->offset; | ||
555 | |||
556 | /* | 625 | /* |
557 | * The scatterlist item may be bigger than PAGE_SIZE, | 626 | * The scatterlist item may be bigger than PAGE_SIZE, |
558 | * but we must not cross pages inside the kmap. | 627 | * but we must not cross pages inside the kmap. |
559 | */ | 628 | */ |
560 | sg_bytes = min(sg_bytes, (size_t) (PAGE_SIZE - | 629 | page_addr = kmap_atomic(page, KM_SOFTIRQ0); |
561 | (off & ~PAGE_MASK))); | ||
562 | page_addr = kmap_atomic(sg_page(sg) + | ||
563 | (off >> PAGE_SHIFT), | ||
564 | KM_SOFTIRQ0); | ||
565 | memcpy(data, (char *)page_addr + (off & ~PAGE_MASK), | 630 | memcpy(data, (char *)page_addr + (off & ~PAGE_MASK), |
566 | sg_bytes); | 631 | sg_bytes); |
567 | kunmap_atomic(page_addr, KM_SOFTIRQ0); | 632 | kunmap_atomic(page_addr, KM_SOFTIRQ0); |
@@ -572,7 +637,8 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
572 | tlen -= sg_bytes; | 637 | tlen -= sg_bytes; |
573 | remaining -= sg_bytes; | 638 | remaining -= sg_bytes; |
574 | 639 | ||
575 | if (tlen) | 640 | if ((skb_shinfo(fp_skb(fp))->nr_frags < FC_FRAME_SG_LEN) && |
641 | (tlen)) | ||
576 | continue; | 642 | continue; |
577 | 643 | ||
578 | /* | 644 | /* |
@@ -589,7 +655,7 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
589 | /* | 655 | /* |
590 | * send fragment using for a sequence. | 656 | * send fragment using for a sequence. |
591 | */ | 657 | */ |
592 | error = lp->tt.seq_send(lp, seq, fp); | 658 | error = lport->tt.seq_send(lport, seq, fp); |
593 | if (error) { | 659 | if (error) { |
594 | WARN_ON(1); /* send error should be rare */ | 660 | WARN_ON(1); /* send error should be rare */ |
595 | fc_fcp_retry_cmd(fsp); | 661 | fc_fcp_retry_cmd(fsp); |
@@ -601,6 +667,11 @@ static int fc_fcp_send_data(struct fc_fcp_pkt *fsp, struct fc_seq *seq, | |||
601 | return 0; | 667 | return 0; |
602 | } | 668 | } |
603 | 669 | ||
670 | /** | ||
671 | * fc_fcp_abts_resp() - Send an ABTS response | ||
672 | * @fsp: The FCP packet that is being aborted | ||
673 | * @fp: The response frame | ||
674 | */ | ||
604 | static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 675 | static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
605 | { | 676 | { |
606 | int ba_done = 1; | 677 | int ba_done = 1; |
@@ -637,46 +708,13 @@ static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | |||
637 | } | 708 | } |
638 | 709 | ||
639 | /** | 710 | /** |
640 | * fc_fcp_reduce_can_queue() - drop can_queue | 711 | * fc_fcp_recv() - Reveive an FCP frame |
641 | * @lp: lport to drop queueing for | ||
642 | * | ||
643 | * If we are getting memory allocation failures, then we may | ||
644 | * be trying to execute too many commands. We let the running | ||
645 | * commands complete or timeout, then try again with a reduced | ||
646 | * can_queue. Eventually we will hit the point where we run | ||
647 | * on all reserved structs. | ||
648 | */ | ||
649 | static void fc_fcp_reduce_can_queue(struct fc_lport *lp) | ||
650 | { | ||
651 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | ||
652 | unsigned long flags; | ||
653 | int can_queue; | ||
654 | |||
655 | spin_lock_irqsave(lp->host->host_lock, flags); | ||
656 | if (si->throttled) | ||
657 | goto done; | ||
658 | si->throttled = 1; | ||
659 | |||
660 | can_queue = lp->host->can_queue; | ||
661 | can_queue >>= 1; | ||
662 | if (!can_queue) | ||
663 | can_queue = 1; | ||
664 | lp->host->can_queue = can_queue; | ||
665 | shost_printk(KERN_ERR, lp->host, "libfc: Could not allocate frame.\n" | ||
666 | "Reducing can_queue to %d.\n", can_queue); | ||
667 | done: | ||
668 | spin_unlock_irqrestore(lp->host->host_lock, flags); | ||
669 | } | ||
670 | |||
671 | /** | ||
672 | * fc_fcp_recv() - Reveive FCP frames | ||
673 | * @seq: The sequence the frame is on | 712 | * @seq: The sequence the frame is on |
674 | * @fp: The FC frame | 713 | * @fp: The received frame |
675 | * @arg: The related FCP packet | 714 | * @arg: The related FCP packet |
676 | * | 715 | * |
677 | * Return : None | 716 | * Context: Called from Soft IRQ context. Can not be called |
678 | * Context : called from Soft IRQ context | 717 | * holding the FCP packet list lock. |
679 | * can not called holding list lock | ||
680 | */ | 718 | */ |
681 | static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) | 719 | static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) |
682 | { | 720 | { |
@@ -687,8 +725,10 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
687 | u8 r_ctl; | 725 | u8 r_ctl; |
688 | int rc = 0; | 726 | int rc = 0; |
689 | 727 | ||
690 | if (IS_ERR(fp)) | 728 | if (IS_ERR(fp)) { |
691 | goto errout; | 729 | fc_fcp_error(fsp, fp); |
730 | return; | ||
731 | } | ||
692 | 732 | ||
693 | fh = fc_frame_header_get(fp); | 733 | fh = fc_frame_header_get(fp); |
694 | r_ctl = fh->fh_r_ctl; | 734 | r_ctl = fh->fh_r_ctl; |
@@ -721,8 +761,6 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
721 | (size_t) ntohl(dd->ft_burst_len)); | 761 | (size_t) ntohl(dd->ft_burst_len)); |
722 | if (!rc) | 762 | if (!rc) |
723 | seq->rec_data = fsp->xfer_len; | 763 | seq->rec_data = fsp->xfer_len; |
724 | else if (rc == -ENOMEM) | ||
725 | fsp->state |= FC_SRB_NOMEM; | ||
726 | } else if (r_ctl == FC_RCTL_DD_SOL_DATA) { | 764 | } else if (r_ctl == FC_RCTL_DD_SOL_DATA) { |
727 | /* | 765 | /* |
728 | * received a DATA frame | 766 | * received a DATA frame |
@@ -742,13 +780,13 @@ unlock: | |||
742 | fc_fcp_unlock_pkt(fsp); | 780 | fc_fcp_unlock_pkt(fsp); |
743 | out: | 781 | out: |
744 | fc_frame_free(fp); | 782 | fc_frame_free(fp); |
745 | errout: | ||
746 | if (IS_ERR(fp)) | ||
747 | fc_fcp_error(fsp, fp); | ||
748 | else if (rc == -ENOMEM) | ||
749 | fc_fcp_reduce_can_queue(lport); | ||
750 | } | 783 | } |
751 | 784 | ||
785 | /** | ||
786 | * fc_fcp_resp() - Handler for FCP responses | ||
787 | * @fsp: The FCP packet the response is for | ||
788 | * @fp: The response frame | ||
789 | */ | ||
752 | static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 790 | static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
753 | { | 791 | { |
754 | struct fc_frame_header *fh; | 792 | struct fc_frame_header *fh; |
@@ -862,15 +900,16 @@ err: | |||
862 | } | 900 | } |
863 | 901 | ||
864 | /** | 902 | /** |
865 | * fc_fcp_complete_locked() - complete processing of a fcp packet | 903 | * fc_fcp_complete_locked() - Complete processing of a fcp_pkt with the |
866 | * @fsp: fcp packet | 904 | * fcp_pkt lock held |
905 | * @fsp: The FCP packet to be completed | ||
867 | * | 906 | * |
868 | * This function may sleep if a timer is pending. The packet lock must be | 907 | * This function may sleep if a timer is pending. The packet lock must be |
869 | * held, and the host lock must not be held. | 908 | * held, and the host lock must not be held. |
870 | */ | 909 | */ |
871 | static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) | 910 | static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) |
872 | { | 911 | { |
873 | struct fc_lport *lp = fsp->lp; | 912 | struct fc_lport *lport = fsp->lp; |
874 | struct fc_seq *seq; | 913 | struct fc_seq *seq; |
875 | struct fc_exch *ep; | 914 | struct fc_exch *ep; |
876 | u32 f_ctl; | 915 | u32 f_ctl; |
@@ -901,8 +940,8 @@ static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) | |||
901 | struct fc_frame *conf_frame; | 940 | struct fc_frame *conf_frame; |
902 | struct fc_seq *csp; | 941 | struct fc_seq *csp; |
903 | 942 | ||
904 | csp = lp->tt.seq_start_next(seq); | 943 | csp = lport->tt.seq_start_next(seq); |
905 | conf_frame = fc_frame_alloc(fsp->lp, 0); | 944 | conf_frame = fc_fcp_frame_alloc(fsp->lp, 0); |
906 | if (conf_frame) { | 945 | if (conf_frame) { |
907 | f_ctl = FC_FC_SEQ_INIT; | 946 | f_ctl = FC_FC_SEQ_INIT; |
908 | f_ctl |= FC_FC_LAST_SEQ | FC_FC_END_SEQ; | 947 | f_ctl |= FC_FC_LAST_SEQ | FC_FC_END_SEQ; |
@@ -910,43 +949,48 @@ static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp) | |||
910 | fc_fill_fc_hdr(conf_frame, FC_RCTL_DD_SOL_CTL, | 949 | fc_fill_fc_hdr(conf_frame, FC_RCTL_DD_SOL_CTL, |
911 | ep->did, ep->sid, | 950 | ep->did, ep->sid, |
912 | FC_TYPE_FCP, f_ctl, 0); | 951 | FC_TYPE_FCP, f_ctl, 0); |
913 | lp->tt.seq_send(lp, csp, conf_frame); | 952 | lport->tt.seq_send(lport, csp, conf_frame); |
914 | } | 953 | } |
915 | } | 954 | } |
916 | lp->tt.exch_done(seq); | 955 | lport->tt.exch_done(seq); |
917 | } | 956 | } |
918 | fc_io_compl(fsp); | 957 | fc_io_compl(fsp); |
919 | } | 958 | } |
920 | 959 | ||
960 | /** | ||
961 | * fc_fcp_cleanup_cmd() - Cancel the active exchange on a fcp_pkt | ||
962 | * @fsp: The FCP packet whose exchanges should be canceled | ||
963 | * @error: The reason for the cancellation | ||
964 | */ | ||
921 | static void fc_fcp_cleanup_cmd(struct fc_fcp_pkt *fsp, int error) | 965 | static void fc_fcp_cleanup_cmd(struct fc_fcp_pkt *fsp, int error) |
922 | { | 966 | { |
923 | struct fc_lport *lp = fsp->lp; | 967 | struct fc_lport *lport = fsp->lp; |
924 | 968 | ||
925 | if (fsp->seq_ptr) { | 969 | if (fsp->seq_ptr) { |
926 | lp->tt.exch_done(fsp->seq_ptr); | 970 | lport->tt.exch_done(fsp->seq_ptr); |
927 | fsp->seq_ptr = NULL; | 971 | fsp->seq_ptr = NULL; |
928 | } | 972 | } |
929 | fsp->status_code = error; | 973 | fsp->status_code = error; |
930 | } | 974 | } |
931 | 975 | ||
932 | /** | 976 | /** |
933 | * fc_fcp_cleanup_each_cmd() - Cleanup active commads | 977 | * fc_fcp_cleanup_each_cmd() - Cancel all exchanges on a local port |
934 | * @lp: logical port | 978 | * @lport: The local port whose exchanges should be canceled |
935 | * @id: target id | 979 | * @id: The target's ID |
936 | * @lun: lun | 980 | * @lun: The LUN |
937 | * @error: fsp status code | 981 | * @error: The reason for cancellation |
938 | * | 982 | * |
939 | * If lun or id is -1, they are ignored. | 983 | * If lun or id is -1, they are ignored. |
940 | */ | 984 | */ |
941 | static void fc_fcp_cleanup_each_cmd(struct fc_lport *lp, unsigned int id, | 985 | static void fc_fcp_cleanup_each_cmd(struct fc_lport *lport, unsigned int id, |
942 | unsigned int lun, int error) | 986 | unsigned int lun, int error) |
943 | { | 987 | { |
944 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | 988 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); |
945 | struct fc_fcp_pkt *fsp; | 989 | struct fc_fcp_pkt *fsp; |
946 | struct scsi_cmnd *sc_cmd; | 990 | struct scsi_cmnd *sc_cmd; |
947 | unsigned long flags; | 991 | unsigned long flags; |
948 | 992 | ||
949 | spin_lock_irqsave(lp->host->host_lock, flags); | 993 | spin_lock_irqsave(lport->host->host_lock, flags); |
950 | restart: | 994 | restart: |
951 | list_for_each_entry(fsp, &si->scsi_pkt_queue, list) { | 995 | list_for_each_entry(fsp, &si->scsi_pkt_queue, list) { |
952 | sc_cmd = fsp->cmd; | 996 | sc_cmd = fsp->cmd; |
@@ -957,7 +1001,7 @@ restart: | |||
957 | continue; | 1001 | continue; |
958 | 1002 | ||
959 | fc_fcp_pkt_hold(fsp); | 1003 | fc_fcp_pkt_hold(fsp); |
960 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1004 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
961 | 1005 | ||
962 | if (!fc_fcp_lock_pkt(fsp)) { | 1006 | if (!fc_fcp_lock_pkt(fsp)) { |
963 | fc_fcp_cleanup_cmd(fsp, error); | 1007 | fc_fcp_cleanup_cmd(fsp, error); |
@@ -966,35 +1010,36 @@ restart: | |||
966 | } | 1010 | } |
967 | 1011 | ||
968 | fc_fcp_pkt_release(fsp); | 1012 | fc_fcp_pkt_release(fsp); |
969 | spin_lock_irqsave(lp->host->host_lock, flags); | 1013 | spin_lock_irqsave(lport->host->host_lock, flags); |
970 | /* | 1014 | /* |
971 | * while we dropped the lock multiple pkts could | 1015 | * while we dropped the lock multiple pkts could |
972 | * have been released, so we have to start over. | 1016 | * have been released, so we have to start over. |
973 | */ | 1017 | */ |
974 | goto restart; | 1018 | goto restart; |
975 | } | 1019 | } |
976 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1020 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
977 | } | 1021 | } |
978 | 1022 | ||
979 | static void fc_fcp_abort_io(struct fc_lport *lp) | 1023 | /** |
1024 | * fc_fcp_abort_io() - Abort all FCP-SCSI exchanges on a local port | ||
1025 | * @lport: The local port whose exchanges are to be aborted | ||
1026 | */ | ||
1027 | static void fc_fcp_abort_io(struct fc_lport *lport) | ||
980 | { | 1028 | { |
981 | fc_fcp_cleanup_each_cmd(lp, -1, -1, FC_HRD_ERROR); | 1029 | fc_fcp_cleanup_each_cmd(lport, -1, -1, FC_HRD_ERROR); |
982 | } | 1030 | } |
983 | 1031 | ||
984 | /** | 1032 | /** |
985 | * fc_fcp_pkt_send() - send a fcp packet to the lower level. | 1033 | * fc_fcp_pkt_send() - Send a fcp_pkt |
986 | * @lp: fc lport | 1034 | * @lport: The local port to send the FCP packet on |
987 | * @fsp: fc packet. | 1035 | * @fsp: The FCP packet to send |
988 | * | 1036 | * |
989 | * This is called by upper layer protocol. | 1037 | * Return: Zero for success and -1 for failure |
990 | * Return : zero for success and -1 for failure | 1038 | * Locks: Called with the host lock and irqs disabled. |
991 | * Context : called from queuecommand which can be called from process | ||
992 | * or scsi soft irq. | ||
993 | * Locks : called with the host lock and irqs disabled. | ||
994 | */ | 1039 | */ |
995 | static int fc_fcp_pkt_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp) | 1040 | static int fc_fcp_pkt_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp) |
996 | { | 1041 | { |
997 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | 1042 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); |
998 | int rc; | 1043 | int rc; |
999 | 1044 | ||
1000 | fsp->cmd->SCp.ptr = (char *)fsp; | 1045 | fsp->cmd->SCp.ptr = (char *)fsp; |
@@ -1006,16 +1051,22 @@ static int fc_fcp_pkt_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp) | |||
1006 | memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len); | 1051 | memcpy(fsp->cdb_cmd.fc_cdb, fsp->cmd->cmnd, fsp->cmd->cmd_len); |
1007 | list_add_tail(&fsp->list, &si->scsi_pkt_queue); | 1052 | list_add_tail(&fsp->list, &si->scsi_pkt_queue); |
1008 | 1053 | ||
1009 | spin_unlock_irq(lp->host->host_lock); | 1054 | spin_unlock_irq(lport->host->host_lock); |
1010 | rc = lp->tt.fcp_cmd_send(lp, fsp, fc_fcp_recv); | 1055 | rc = lport->tt.fcp_cmd_send(lport, fsp, fc_fcp_recv); |
1011 | spin_lock_irq(lp->host->host_lock); | 1056 | spin_lock_irq(lport->host->host_lock); |
1012 | if (rc) | 1057 | if (rc) |
1013 | list_del(&fsp->list); | 1058 | list_del(&fsp->list); |
1014 | 1059 | ||
1015 | return rc; | 1060 | return rc; |
1016 | } | 1061 | } |
1017 | 1062 | ||
1018 | static int fc_fcp_cmd_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | 1063 | /** |
1064 | * fc_fcp_cmd_send() - Send a FCP command | ||
1065 | * @lport: The local port to send the command on | ||
1066 | * @fsp: The FCP packet the command is on | ||
1067 | * @resp: The handler for the response | ||
1068 | */ | ||
1069 | static int fc_fcp_cmd_send(struct fc_lport *lport, struct fc_fcp_pkt *fsp, | ||
1019 | void (*resp)(struct fc_seq *, | 1070 | void (*resp)(struct fc_seq *, |
1020 | struct fc_frame *fp, | 1071 | struct fc_frame *fp, |
1021 | void *arg)) | 1072 | void *arg)) |
@@ -1023,14 +1074,14 @@ static int fc_fcp_cmd_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | |||
1023 | struct fc_frame *fp; | 1074 | struct fc_frame *fp; |
1024 | struct fc_seq *seq; | 1075 | struct fc_seq *seq; |
1025 | struct fc_rport *rport; | 1076 | struct fc_rport *rport; |
1026 | struct fc_rport_libfc_priv *rp; | 1077 | struct fc_rport_libfc_priv *rpriv; |
1027 | const size_t len = sizeof(fsp->cdb_cmd); | 1078 | const size_t len = sizeof(fsp->cdb_cmd); |
1028 | int rc = 0; | 1079 | int rc = 0; |
1029 | 1080 | ||
1030 | if (fc_fcp_lock_pkt(fsp)) | 1081 | if (fc_fcp_lock_pkt(fsp)) |
1031 | return 0; | 1082 | return 0; |
1032 | 1083 | ||
1033 | fp = fc_frame_alloc(lp, sizeof(fsp->cdb_cmd)); | 1084 | fp = fc_fcp_frame_alloc(lport, sizeof(fsp->cdb_cmd)); |
1034 | if (!fp) { | 1085 | if (!fp) { |
1035 | rc = -1; | 1086 | rc = -1; |
1036 | goto unlock; | 1087 | goto unlock; |
@@ -1040,15 +1091,15 @@ static int fc_fcp_cmd_send(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | |||
1040 | fr_fsp(fp) = fsp; | 1091 | fr_fsp(fp) = fsp; |
1041 | rport = fsp->rport; | 1092 | rport = fsp->rport; |
1042 | fsp->max_payload = rport->maxframe_size; | 1093 | fsp->max_payload = rport->maxframe_size; |
1043 | rp = rport->dd_data; | 1094 | rpriv = rport->dd_data; |
1044 | 1095 | ||
1045 | fc_fill_fc_hdr(fp, FC_RCTL_DD_UNSOL_CMD, rport->port_id, | 1096 | fc_fill_fc_hdr(fp, FC_RCTL_DD_UNSOL_CMD, rport->port_id, |
1046 | fc_host_port_id(rp->local_port->host), FC_TYPE_FCP, | 1097 | fc_host_port_id(rpriv->local_port->host), FC_TYPE_FCP, |
1047 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); | 1098 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
1048 | 1099 | ||
1049 | seq = lp->tt.exch_seq_send(lp, fp, resp, fc_fcp_pkt_destroy, fsp, 0); | 1100 | seq = lport->tt.exch_seq_send(lport, fp, resp, fc_fcp_pkt_destroy, |
1101 | fsp, 0); | ||
1050 | if (!seq) { | 1102 | if (!seq) { |
1051 | fc_frame_free(fp); | ||
1052 | rc = -1; | 1103 | rc = -1; |
1053 | goto unlock; | 1104 | goto unlock; |
1054 | } | 1105 | } |
@@ -1065,8 +1116,10 @@ unlock: | |||
1065 | return rc; | 1116 | return rc; |
1066 | } | 1117 | } |
1067 | 1118 | ||
1068 | /* | 1119 | /** |
1069 | * transport error handler | 1120 | * fc_fcp_error() - Handler for FCP layer errors |
1121 | * @fsp: The FCP packet the error is on | ||
1122 | * @fp: The frame that has errored | ||
1070 | */ | 1123 | */ |
1071 | static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 1124 | static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
1072 | { | 1125 | { |
@@ -1091,11 +1144,13 @@ unlock: | |||
1091 | fc_fcp_unlock_pkt(fsp); | 1144 | fc_fcp_unlock_pkt(fsp); |
1092 | } | 1145 | } |
1093 | 1146 | ||
1094 | /* | 1147 | /** |
1095 | * Scsi abort handler- calls to send an abort | 1148 | * fc_fcp_pkt_abort() - Abort a fcp_pkt |
1096 | * and then wait for abort completion | 1149 | * @fsp: The FCP packet to abort on |
1150 | * | ||
1151 | * Called to send an abort and then wait for abort completion | ||
1097 | */ | 1152 | */ |
1098 | static int fc_fcp_pkt_abort(struct fc_lport *lp, struct fc_fcp_pkt *fsp) | 1153 | static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp) |
1099 | { | 1154 | { |
1100 | int rc = FAILED; | 1155 | int rc = FAILED; |
1101 | 1156 | ||
@@ -1122,14 +1177,15 @@ static int fc_fcp_pkt_abort(struct fc_lport *lp, struct fc_fcp_pkt *fsp) | |||
1122 | return rc; | 1177 | return rc; |
1123 | } | 1178 | } |
1124 | 1179 | ||
1125 | /* | 1180 | /** |
1126 | * Retry LUN reset after resource allocation failed. | 1181 | * fc_lun_reset_send() - Send LUN reset command |
1182 | * @data: The FCP packet that identifies the LUN to be reset | ||
1127 | */ | 1183 | */ |
1128 | static void fc_lun_reset_send(unsigned long data) | 1184 | static void fc_lun_reset_send(unsigned long data) |
1129 | { | 1185 | { |
1130 | struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; | 1186 | struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; |
1131 | struct fc_lport *lp = fsp->lp; | 1187 | struct fc_lport *lport = fsp->lp; |
1132 | if (lp->tt.fcp_cmd_send(lp, fsp, fc_tm_done)) { | 1188 | if (lport->tt.fcp_cmd_send(lport, fsp, fc_tm_done)) { |
1133 | if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY) | 1189 | if (fsp->recov_retry++ >= FC_MAX_RECOV_RETRY) |
1134 | return; | 1190 | return; |
1135 | if (fc_fcp_lock_pkt(fsp)) | 1191 | if (fc_fcp_lock_pkt(fsp)) |
@@ -1140,11 +1196,15 @@ static void fc_lun_reset_send(unsigned long data) | |||
1140 | } | 1196 | } |
1141 | } | 1197 | } |
1142 | 1198 | ||
1143 | /* | 1199 | /** |
1144 | * Scsi device reset handler- send a LUN RESET to the device | 1200 | * fc_lun_reset() - Send a LUN RESET command to a device |
1145 | * and wait for reset reply | 1201 | * and wait for the reply |
1202 | * @lport: The local port to sent the comand on | ||
1203 | * @fsp: The FCP packet that identifies the LUN to be reset | ||
1204 | * @id: The SCSI command ID | ||
1205 | * @lun: The LUN ID to be reset | ||
1146 | */ | 1206 | */ |
1147 | static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | 1207 | static int fc_lun_reset(struct fc_lport *lport, struct fc_fcp_pkt *fsp, |
1148 | unsigned int id, unsigned int lun) | 1208 | unsigned int id, unsigned int lun) |
1149 | { | 1209 | { |
1150 | int rc; | 1210 | int rc; |
@@ -1172,14 +1232,14 @@ static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | |||
1172 | 1232 | ||
1173 | spin_lock_bh(&fsp->scsi_pkt_lock); | 1233 | spin_lock_bh(&fsp->scsi_pkt_lock); |
1174 | if (fsp->seq_ptr) { | 1234 | if (fsp->seq_ptr) { |
1175 | lp->tt.exch_done(fsp->seq_ptr); | 1235 | lport->tt.exch_done(fsp->seq_ptr); |
1176 | fsp->seq_ptr = NULL; | 1236 | fsp->seq_ptr = NULL; |
1177 | } | 1237 | } |
1178 | fsp->wait_for_comp = 0; | 1238 | fsp->wait_for_comp = 0; |
1179 | spin_unlock_bh(&fsp->scsi_pkt_lock); | 1239 | spin_unlock_bh(&fsp->scsi_pkt_lock); |
1180 | 1240 | ||
1181 | if (!rc) { | 1241 | if (!rc) { |
1182 | FC_SCSI_DBG(lp, "lun reset failed\n"); | 1242 | FC_SCSI_DBG(lport, "lun reset failed\n"); |
1183 | return FAILED; | 1243 | return FAILED; |
1184 | } | 1244 | } |
1185 | 1245 | ||
@@ -1187,13 +1247,16 @@ static int fc_lun_reset(struct fc_lport *lp, struct fc_fcp_pkt *fsp, | |||
1187 | if (fsp->cdb_status != FCP_TMF_CMPL) | 1247 | if (fsp->cdb_status != FCP_TMF_CMPL) |
1188 | return FAILED; | 1248 | return FAILED; |
1189 | 1249 | ||
1190 | FC_SCSI_DBG(lp, "lun reset to lun %u completed\n", lun); | 1250 | FC_SCSI_DBG(lport, "lun reset to lun %u completed\n", lun); |
1191 | fc_fcp_cleanup_each_cmd(lp, id, lun, FC_CMD_ABORTED); | 1251 | fc_fcp_cleanup_each_cmd(lport, id, lun, FC_CMD_ABORTED); |
1192 | return SUCCESS; | 1252 | return SUCCESS; |
1193 | } | 1253 | } |
1194 | 1254 | ||
1195 | /* | 1255 | /** |
1196 | * Task Managment response handler | 1256 | * fc_tm_done() - Task Managment response handler |
1257 | * @seq: The sequence that the response is on | ||
1258 | * @fp: The response frame | ||
1259 | * @arg: The FCP packet the response is for | ||
1197 | */ | 1260 | */ |
1198 | static void fc_tm_done(struct fc_seq *seq, struct fc_frame *fp, void *arg) | 1261 | static void fc_tm_done(struct fc_seq *seq, struct fc_frame *fp, void *arg) |
1199 | { | 1262 | { |
@@ -1230,34 +1293,31 @@ static void fc_tm_done(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
1230 | fc_fcp_unlock_pkt(fsp); | 1293 | fc_fcp_unlock_pkt(fsp); |
1231 | } | 1294 | } |
1232 | 1295 | ||
1233 | static void fc_fcp_cleanup(struct fc_lport *lp) | 1296 | /** |
1297 | * fc_fcp_cleanup() - Cleanup all FCP exchanges on a local port | ||
1298 | * @lport: The local port to be cleaned up | ||
1299 | */ | ||
1300 | static void fc_fcp_cleanup(struct fc_lport *lport) | ||
1234 | { | 1301 | { |
1235 | fc_fcp_cleanup_each_cmd(lp, -1, -1, FC_ERROR); | 1302 | fc_fcp_cleanup_each_cmd(lport, -1, -1, FC_ERROR); |
1236 | } | 1303 | } |
1237 | 1304 | ||
1238 | /* | 1305 | /** |
1239 | * fc_fcp_timeout: called by OS timer function. | 1306 | * fc_fcp_timeout() - Handler for fcp_pkt timeouts |
1240 | * | 1307 | * @data: The FCP packet that has timed out |
1241 | * The timer has been inactivated and must be reactivated if desired | ||
1242 | * using fc_fcp_timer_set(). | ||
1243 | * | ||
1244 | * Algorithm: | ||
1245 | * | ||
1246 | * If REC is supported, just issue it, and return. The REC exchange will | ||
1247 | * complete or time out, and recovery can continue at that point. | ||
1248 | * | ||
1249 | * Otherwise, if the response has been received without all the data, | ||
1250 | * it has been ER_TIMEOUT since the response was received. | ||
1251 | * | 1308 | * |
1252 | * If the response has not been received, | 1309 | * If REC is supported then just issue it and return. The REC exchange will |
1253 | * we see if data was received recently. If it has been, we continue waiting, | 1310 | * complete or time out and recovery can continue at that point. Otherwise, |
1254 | * otherwise, we abort the command. | 1311 | * if the response has been received without all the data it has been |
1312 | * ER_TIMEOUT since the response was received. If the response has not been | ||
1313 | * received we see if data was received recently. If it has been then we | ||
1314 | * continue waiting, otherwise, we abort the command. | ||
1255 | */ | 1315 | */ |
1256 | static void fc_fcp_timeout(unsigned long data) | 1316 | static void fc_fcp_timeout(unsigned long data) |
1257 | { | 1317 | { |
1258 | struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; | 1318 | struct fc_fcp_pkt *fsp = (struct fc_fcp_pkt *)data; |
1259 | struct fc_rport *rport = fsp->rport; | 1319 | struct fc_rport *rport = fsp->rport; |
1260 | struct fc_rport_libfc_priv *rp = rport->dd_data; | 1320 | struct fc_rport_libfc_priv *rpriv = rport->dd_data; |
1261 | 1321 | ||
1262 | if (fc_fcp_lock_pkt(fsp)) | 1322 | if (fc_fcp_lock_pkt(fsp)) |
1263 | return; | 1323 | return; |
@@ -1267,7 +1327,7 @@ static void fc_fcp_timeout(unsigned long data) | |||
1267 | 1327 | ||
1268 | fsp->state |= FC_SRB_FCP_PROCESSING_TMO; | 1328 | fsp->state |= FC_SRB_FCP_PROCESSING_TMO; |
1269 | 1329 | ||
1270 | if (rp->flags & FC_RP_FLAGS_REC_SUPPORTED) | 1330 | if (rpriv->flags & FC_RP_FLAGS_REC_SUPPORTED) |
1271 | fc_fcp_rec(fsp); | 1331 | fc_fcp_rec(fsp); |
1272 | else if (time_after_eq(fsp->last_pkt_time + (FC_SCSI_ER_TIMEOUT / 2), | 1332 | else if (time_after_eq(fsp->last_pkt_time + (FC_SCSI_ER_TIMEOUT / 2), |
1273 | jiffies)) | 1333 | jiffies)) |
@@ -1281,39 +1341,40 @@ unlock: | |||
1281 | fc_fcp_unlock_pkt(fsp); | 1341 | fc_fcp_unlock_pkt(fsp); |
1282 | } | 1342 | } |
1283 | 1343 | ||
1284 | /* | 1344 | /** |
1285 | * Send a REC ELS request | 1345 | * fc_fcp_rec() - Send a REC ELS request |
1346 | * @fsp: The FCP packet to send the REC request on | ||
1286 | */ | 1347 | */ |
1287 | static void fc_fcp_rec(struct fc_fcp_pkt *fsp) | 1348 | static void fc_fcp_rec(struct fc_fcp_pkt *fsp) |
1288 | { | 1349 | { |
1289 | struct fc_lport *lp; | 1350 | struct fc_lport *lport; |
1290 | struct fc_frame *fp; | 1351 | struct fc_frame *fp; |
1291 | struct fc_rport *rport; | 1352 | struct fc_rport *rport; |
1292 | struct fc_rport_libfc_priv *rp; | 1353 | struct fc_rport_libfc_priv *rpriv; |
1293 | 1354 | ||
1294 | lp = fsp->lp; | 1355 | lport = fsp->lp; |
1295 | rport = fsp->rport; | 1356 | rport = fsp->rport; |
1296 | rp = rport->dd_data; | 1357 | rpriv = rport->dd_data; |
1297 | if (!fsp->seq_ptr || rp->rp_state != RPORT_ST_READY) { | 1358 | if (!fsp->seq_ptr || rpriv->rp_state != RPORT_ST_READY) { |
1298 | fsp->status_code = FC_HRD_ERROR; | 1359 | fsp->status_code = FC_HRD_ERROR; |
1299 | fsp->io_status = 0; | 1360 | fsp->io_status = 0; |
1300 | fc_fcp_complete_locked(fsp); | 1361 | fc_fcp_complete_locked(fsp); |
1301 | return; | 1362 | return; |
1302 | } | 1363 | } |
1303 | fp = fc_frame_alloc(lp, sizeof(struct fc_els_rec)); | 1364 | fp = fc_fcp_frame_alloc(lport, sizeof(struct fc_els_rec)); |
1304 | if (!fp) | 1365 | if (!fp) |
1305 | goto retry; | 1366 | goto retry; |
1306 | 1367 | ||
1307 | fr_seq(fp) = fsp->seq_ptr; | 1368 | fr_seq(fp) = fsp->seq_ptr; |
1308 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rport->port_id, | 1369 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rport->port_id, |
1309 | fc_host_port_id(rp->local_port->host), FC_TYPE_ELS, | 1370 | fc_host_port_id(rpriv->local_port->host), FC_TYPE_ELS, |
1310 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); | 1371 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
1311 | if (lp->tt.elsct_send(lp, rport->port_id, fp, ELS_REC, fc_fcp_rec_resp, | 1372 | if (lport->tt.elsct_send(lport, rport->port_id, fp, ELS_REC, |
1312 | fsp, jiffies_to_msecs(FC_SCSI_REC_TOV))) { | 1373 | fc_fcp_rec_resp, fsp, |
1374 | jiffies_to_msecs(FC_SCSI_REC_TOV))) { | ||
1313 | fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */ | 1375 | fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */ |
1314 | return; | 1376 | return; |
1315 | } | 1377 | } |
1316 | fc_frame_free(fp); | ||
1317 | retry: | 1378 | retry: |
1318 | if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) | 1379 | if (fsp->recov_retry++ < FC_MAX_RECOV_RETRY) |
1319 | fc_fcp_timer_set(fsp, FC_SCSI_REC_TOV); | 1380 | fc_fcp_timer_set(fsp, FC_SCSI_REC_TOV); |
@@ -1321,12 +1382,16 @@ retry: | |||
1321 | fc_timeout_error(fsp); | 1382 | fc_timeout_error(fsp); |
1322 | } | 1383 | } |
1323 | 1384 | ||
1324 | /* | 1385 | /** |
1325 | * Receive handler for REC ELS frame | 1386 | * fc_fcp_rec_resp() - Handler for REC ELS responses |
1326 | * if it is a reject then let the scsi layer to handle | 1387 | * @seq: The sequence the response is on |
1327 | * the timeout. if it is a LS_ACC then if the io was not completed | 1388 | * @fp: The response frame |
1328 | * then set the timeout and return otherwise complete the exchange | 1389 | * @arg: The FCP packet the response is on |
1329 | * and tell the scsi layer to restart the I/O. | 1390 | * |
1391 | * If the response is a reject then the scsi layer will handle | ||
1392 | * the timeout. If the response is a LS_ACC then if the I/O was not completed | ||
1393 | * set the timeout and return. If the I/O was completed then complete the | ||
1394 | * exchange and tell the SCSI layer. | ||
1330 | */ | 1395 | */ |
1331 | static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | 1396 | static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) |
1332 | { | 1397 | { |
@@ -1338,7 +1403,7 @@ static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
1338 | u32 offset; | 1403 | u32 offset; |
1339 | enum dma_data_direction data_dir; | 1404 | enum dma_data_direction data_dir; |
1340 | enum fc_rctl r_ctl; | 1405 | enum fc_rctl r_ctl; |
1341 | struct fc_rport_libfc_priv *rp; | 1406 | struct fc_rport_libfc_priv *rpriv; |
1342 | 1407 | ||
1343 | if (IS_ERR(fp)) { | 1408 | if (IS_ERR(fp)) { |
1344 | fc_fcp_rec_error(fsp, fp); | 1409 | fc_fcp_rec_error(fsp, fp); |
@@ -1361,13 +1426,13 @@ static void fc_fcp_rec_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | |||
1361 | /* fall through */ | 1426 | /* fall through */ |
1362 | case ELS_RJT_UNSUP: | 1427 | case ELS_RJT_UNSUP: |
1363 | FC_FCP_DBG(fsp, "device does not support REC\n"); | 1428 | FC_FCP_DBG(fsp, "device does not support REC\n"); |
1364 | rp = fsp->rport->dd_data; | 1429 | rpriv = fsp->rport->dd_data; |
1365 | /* | 1430 | /* |
1366 | * if we do not spport RECs or got some bogus | 1431 | * if we do not spport RECs or got some bogus |
1367 | * reason then resetup timer so we check for | 1432 | * reason then resetup timer so we check for |
1368 | * making progress. | 1433 | * making progress. |
1369 | */ | 1434 | */ |
1370 | rp->flags &= ~FC_RP_FLAGS_REC_SUPPORTED; | 1435 | rpriv->flags &= ~FC_RP_FLAGS_REC_SUPPORTED; |
1371 | fc_fcp_timer_set(fsp, FC_SCSI_ER_TIMEOUT); | 1436 | fc_fcp_timer_set(fsp, FC_SCSI_ER_TIMEOUT); |
1372 | break; | 1437 | break; |
1373 | case ELS_RJT_LOGIC: | 1438 | case ELS_RJT_LOGIC: |
@@ -1464,8 +1529,10 @@ out: | |||
1464 | fc_frame_free(fp); | 1529 | fc_frame_free(fp); |
1465 | } | 1530 | } |
1466 | 1531 | ||
1467 | /* | 1532 | /** |
1468 | * Handle error response or timeout for REC exchange. | 1533 | * fc_fcp_rec_error() - Handler for REC errors |
1534 | * @fsp: The FCP packet the error is on | ||
1535 | * @fp: The REC frame | ||
1469 | */ | 1536 | */ |
1470 | static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 1537 | static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
1471 | { | 1538 | { |
@@ -1504,10 +1571,9 @@ out: | |||
1504 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */ | 1571 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding REC */ |
1505 | } | 1572 | } |
1506 | 1573 | ||
1507 | /* | 1574 | /** |
1508 | * Time out error routine: | 1575 | * fc_timeout_error() - Handler for fcp_pkt timeouts |
1509 | * abort's the I/O close the exchange and | 1576 | * @fsp: The FCP packt that has timed out |
1510 | * send completion notification to scsi layer | ||
1511 | */ | 1577 | */ |
1512 | static void fc_timeout_error(struct fc_fcp_pkt *fsp) | 1578 | static void fc_timeout_error(struct fc_fcp_pkt *fsp) |
1513 | { | 1579 | { |
@@ -1521,16 +1587,18 @@ static void fc_timeout_error(struct fc_fcp_pkt *fsp) | |||
1521 | fc_fcp_send_abort(fsp); | 1587 | fc_fcp_send_abort(fsp); |
1522 | } | 1588 | } |
1523 | 1589 | ||
1524 | /* | 1590 | /** |
1525 | * Sequence retransmission request. | 1591 | * fc_fcp_srr() - Send a SRR request (Sequence Retransmission Request) |
1592 | * @fsp: The FCP packet the SRR is to be sent on | ||
1593 | * @r_ctl: The R_CTL field for the SRR request | ||
1526 | * This is called after receiving status but insufficient data, or | 1594 | * This is called after receiving status but insufficient data, or |
1527 | * when expecting status but the request has timed out. | 1595 | * when expecting status but the request has timed out. |
1528 | */ | 1596 | */ |
1529 | static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) | 1597 | static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) |
1530 | { | 1598 | { |
1531 | struct fc_lport *lp = fsp->lp; | 1599 | struct fc_lport *lport = fsp->lp; |
1532 | struct fc_rport *rport; | 1600 | struct fc_rport *rport; |
1533 | struct fc_rport_libfc_priv *rp; | 1601 | struct fc_rport_libfc_priv *rpriv; |
1534 | struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); | 1602 | struct fc_exch *ep = fc_seq_exch(fsp->seq_ptr); |
1535 | struct fc_seq *seq; | 1603 | struct fc_seq *seq; |
1536 | struct fcp_srr *srr; | 1604 | struct fcp_srr *srr; |
@@ -1538,12 +1606,13 @@ static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) | |||
1538 | u8 cdb_op; | 1606 | u8 cdb_op; |
1539 | 1607 | ||
1540 | rport = fsp->rport; | 1608 | rport = fsp->rport; |
1541 | rp = rport->dd_data; | 1609 | rpriv = rport->dd_data; |
1542 | cdb_op = fsp->cdb_cmd.fc_cdb[0]; | 1610 | cdb_op = fsp->cdb_cmd.fc_cdb[0]; |
1543 | 1611 | ||
1544 | if (!(rp->flags & FC_RP_FLAGS_RETRY) || rp->rp_state != RPORT_ST_READY) | 1612 | if (!(rpriv->flags & FC_RP_FLAGS_RETRY) || |
1613 | rpriv->rp_state != RPORT_ST_READY) | ||
1545 | goto retry; /* shouldn't happen */ | 1614 | goto retry; /* shouldn't happen */ |
1546 | fp = fc_frame_alloc(lp, sizeof(*srr)); | 1615 | fp = fc_fcp_frame_alloc(lport, sizeof(*srr)); |
1547 | if (!fp) | 1616 | if (!fp) |
1548 | goto retry; | 1617 | goto retry; |
1549 | 1618 | ||
@@ -1556,15 +1625,14 @@ static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum fc_rctl r_ctl, u32 offset) | |||
1556 | srr->srr_rel_off = htonl(offset); | 1625 | srr->srr_rel_off = htonl(offset); |
1557 | 1626 | ||
1558 | fc_fill_fc_hdr(fp, FC_RCTL_ELS4_REQ, rport->port_id, | 1627 | fc_fill_fc_hdr(fp, FC_RCTL_ELS4_REQ, rport->port_id, |
1559 | fc_host_port_id(rp->local_port->host), FC_TYPE_FCP, | 1628 | fc_host_port_id(rpriv->local_port->host), FC_TYPE_FCP, |
1560 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); | 1629 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
1561 | 1630 | ||
1562 | seq = lp->tt.exch_seq_send(lp, fp, fc_fcp_srr_resp, NULL, | 1631 | seq = lport->tt.exch_seq_send(lport, fp, fc_fcp_srr_resp, NULL, |
1563 | fsp, jiffies_to_msecs(FC_SCSI_REC_TOV)); | 1632 | fsp, jiffies_to_msecs(FC_SCSI_REC_TOV)); |
1564 | if (!seq) { | 1633 | if (!seq) |
1565 | fc_frame_free(fp); | ||
1566 | goto retry; | 1634 | goto retry; |
1567 | } | 1635 | |
1568 | fsp->recov_seq = seq; | 1636 | fsp->recov_seq = seq; |
1569 | fsp->xfer_len = offset; | 1637 | fsp->xfer_len = offset; |
1570 | fsp->xfer_contig_end = offset; | 1638 | fsp->xfer_contig_end = offset; |
@@ -1575,8 +1643,11 @@ retry: | |||
1575 | fc_fcp_retry_cmd(fsp); | 1643 | fc_fcp_retry_cmd(fsp); |
1576 | } | 1644 | } |
1577 | 1645 | ||
1578 | /* | 1646 | /** |
1579 | * Handle response from SRR. | 1647 | * fc_fcp_srr_resp() - Handler for SRR response |
1648 | * @seq: The sequence the SRR is on | ||
1649 | * @fp: The SRR frame | ||
1650 | * @arg: The FCP packet the SRR is on | ||
1580 | */ | 1651 | */ |
1581 | static void fc_fcp_srr_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) | 1652 | static void fc_fcp_srr_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) |
1582 | { | 1653 | { |
@@ -1622,6 +1693,11 @@ out: | |||
1622 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding SRR */ | 1693 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding SRR */ |
1623 | } | 1694 | } |
1624 | 1695 | ||
1696 | /** | ||
1697 | * fc_fcp_srr_error() - Handler for SRR errors | ||
1698 | * @fsp: The FCP packet that the SRR error is on | ||
1699 | * @fp: The SRR frame | ||
1700 | */ | ||
1625 | static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) | 1701 | static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, struct fc_frame *fp) |
1626 | { | 1702 | { |
1627 | if (fc_fcp_lock_pkt(fsp)) | 1703 | if (fc_fcp_lock_pkt(fsp)) |
@@ -1646,31 +1722,36 @@ out: | |||
1646 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding SRR */ | 1722 | fc_fcp_pkt_release(fsp); /* drop hold for outstanding SRR */ |
1647 | } | 1723 | } |
1648 | 1724 | ||
1649 | static inline int fc_fcp_lport_queue_ready(struct fc_lport *lp) | 1725 | /** |
1726 | * fc_fcp_lport_queue_ready() - Determine if the lport and it's queue is ready | ||
1727 | * @lport: The local port to be checked | ||
1728 | */ | ||
1729 | static inline int fc_fcp_lport_queue_ready(struct fc_lport *lport) | ||
1650 | { | 1730 | { |
1651 | /* lock ? */ | 1731 | /* lock ? */ |
1652 | return (lp->state == LPORT_ST_READY) && lp->link_up && !lp->qfull; | 1732 | return (lport->state == LPORT_ST_READY) && |
1733 | lport->link_up && !lport->qfull; | ||
1653 | } | 1734 | } |
1654 | 1735 | ||
1655 | /** | 1736 | /** |
1656 | * fc_queuecommand - The queuecommand function of the scsi template | 1737 | * fc_queuecommand() - The queuecommand function of the SCSI template |
1657 | * @cmd: struct scsi_cmnd to be executed | 1738 | * @cmd: The scsi_cmnd to be executed |
1658 | * @done: Callback function to be called when cmd is completed | 1739 | * @done: The callback function to be called when the scsi_cmnd is complete |
1659 | * | 1740 | * |
1660 | * this is the i/o strategy routine, called by the scsi layer | 1741 | * This is the i/o strategy routine, called by the SCSI layer. This routine |
1661 | * this routine is called with holding the host_lock. | 1742 | * is called with the host_lock held. |
1662 | */ | 1743 | */ |
1663 | int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | 1744 | int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) |
1664 | { | 1745 | { |
1665 | struct fc_lport *lp; | 1746 | struct fc_lport *lport; |
1666 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); | 1747 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); |
1667 | struct fc_fcp_pkt *fsp; | 1748 | struct fc_fcp_pkt *fsp; |
1668 | struct fc_rport_libfc_priv *rp; | 1749 | struct fc_rport_libfc_priv *rpriv; |
1669 | int rval; | 1750 | int rval; |
1670 | int rc = 0; | 1751 | int rc = 0; |
1671 | struct fcoe_dev_stats *stats; | 1752 | struct fcoe_dev_stats *stats; |
1672 | 1753 | ||
1673 | lp = shost_priv(sc_cmd->device->host); | 1754 | lport = shost_priv(sc_cmd->device->host); |
1674 | 1755 | ||
1675 | rval = fc_remote_port_chkready(rport); | 1756 | rval = fc_remote_port_chkready(rport); |
1676 | if (rval) { | 1757 | if (rval) { |
@@ -1689,14 +1770,16 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1689 | goto out; | 1770 | goto out; |
1690 | } | 1771 | } |
1691 | 1772 | ||
1692 | rp = rport->dd_data; | 1773 | rpriv = rport->dd_data; |
1693 | 1774 | ||
1694 | if (!fc_fcp_lport_queue_ready(lp)) { | 1775 | if (!fc_fcp_lport_queue_ready(lport)) { |
1776 | if (lport->qfull) | ||
1777 | fc_fcp_can_queue_ramp_down(lport); | ||
1695 | rc = SCSI_MLQUEUE_HOST_BUSY; | 1778 | rc = SCSI_MLQUEUE_HOST_BUSY; |
1696 | goto out; | 1779 | goto out; |
1697 | } | 1780 | } |
1698 | 1781 | ||
1699 | fsp = fc_fcp_pkt_alloc(lp, GFP_ATOMIC); | 1782 | fsp = fc_fcp_pkt_alloc(lport, GFP_ATOMIC); |
1700 | if (fsp == NULL) { | 1783 | if (fsp == NULL) { |
1701 | rc = SCSI_MLQUEUE_HOST_BUSY; | 1784 | rc = SCSI_MLQUEUE_HOST_BUSY; |
1702 | goto out; | 1785 | goto out; |
@@ -1706,8 +1789,9 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1706 | * build the libfc request pkt | 1789 | * build the libfc request pkt |
1707 | */ | 1790 | */ |
1708 | fsp->cmd = sc_cmd; /* save the cmd */ | 1791 | fsp->cmd = sc_cmd; /* save the cmd */ |
1709 | fsp->lp = lp; /* save the softc ptr */ | 1792 | fsp->lp = lport; /* save the softc ptr */ |
1710 | fsp->rport = rport; /* set the remote port ptr */ | 1793 | fsp->rport = rport; /* set the remote port ptr */ |
1794 | fsp->xfer_ddp = FC_XID_UNKNOWN; | ||
1711 | sc_cmd->scsi_done = done; | 1795 | sc_cmd->scsi_done = done; |
1712 | 1796 | ||
1713 | /* | 1797 | /* |
@@ -1719,7 +1803,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1719 | /* | 1803 | /* |
1720 | * setup the data direction | 1804 | * setup the data direction |
1721 | */ | 1805 | */ |
1722 | stats = fc_lport_get_stats(lp); | 1806 | stats = fc_lport_get_stats(lport); |
1723 | if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) { | 1807 | if (sc_cmd->sc_data_direction == DMA_FROM_DEVICE) { |
1724 | fsp->req_flags = FC_SRB_READ; | 1808 | fsp->req_flags = FC_SRB_READ; |
1725 | stats->InputRequests++; | 1809 | stats->InputRequests++; |
@@ -1733,7 +1817,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1733 | stats->ControlRequests++; | 1817 | stats->ControlRequests++; |
1734 | } | 1818 | } |
1735 | 1819 | ||
1736 | fsp->tgt_flags = rp->flags; | 1820 | fsp->tgt_flags = rpriv->flags; |
1737 | 1821 | ||
1738 | init_timer(&fsp->timer); | 1822 | init_timer(&fsp->timer); |
1739 | fsp->timer.data = (unsigned long)fsp; | 1823 | fsp->timer.data = (unsigned long)fsp; |
@@ -1743,7 +1827,7 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *)) | |||
1743 | * if we get -1 return then put the request in the pending | 1827 | * if we get -1 return then put the request in the pending |
1744 | * queue. | 1828 | * queue. |
1745 | */ | 1829 | */ |
1746 | rval = fc_fcp_pkt_send(lp, fsp); | 1830 | rval = fc_fcp_pkt_send(lport, fsp); |
1747 | if (rval != 0) { | 1831 | if (rval != 0) { |
1748 | fsp->state = FC_SRB_FREE; | 1832 | fsp->state = FC_SRB_FREE; |
1749 | fc_fcp_pkt_release(fsp); | 1833 | fc_fcp_pkt_release(fsp); |
@@ -1755,18 +1839,17 @@ out: | |||
1755 | EXPORT_SYMBOL(fc_queuecommand); | 1839 | EXPORT_SYMBOL(fc_queuecommand); |
1756 | 1840 | ||
1757 | /** | 1841 | /** |
1758 | * fc_io_compl() - Handle responses for completed commands | 1842 | * fc_io_compl() - Handle responses for completed commands |
1759 | * @fsp: scsi packet | 1843 | * @fsp: The FCP packet that is complete |
1760 | * | ||
1761 | * Translates a error to a Linux SCSI error. | ||
1762 | * | 1844 | * |
1845 | * Translates fcp_pkt errors to a Linux SCSI errors. | ||
1763 | * The fcp packet lock must be held when calling. | 1846 | * The fcp packet lock must be held when calling. |
1764 | */ | 1847 | */ |
1765 | static void fc_io_compl(struct fc_fcp_pkt *fsp) | 1848 | static void fc_io_compl(struct fc_fcp_pkt *fsp) |
1766 | { | 1849 | { |
1767 | struct fc_fcp_internal *si; | 1850 | struct fc_fcp_internal *si; |
1768 | struct scsi_cmnd *sc_cmd; | 1851 | struct scsi_cmnd *sc_cmd; |
1769 | struct fc_lport *lp; | 1852 | struct fc_lport *lport; |
1770 | unsigned long flags; | 1853 | unsigned long flags; |
1771 | 1854 | ||
1772 | /* release outstanding ddp context */ | 1855 | /* release outstanding ddp context */ |
@@ -1779,28 +1862,26 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp) | |||
1779 | spin_lock_bh(&fsp->scsi_pkt_lock); | 1862 | spin_lock_bh(&fsp->scsi_pkt_lock); |
1780 | } | 1863 | } |
1781 | 1864 | ||
1782 | lp = fsp->lp; | 1865 | lport = fsp->lp; |
1783 | si = fc_get_scsi_internal(lp); | 1866 | si = fc_get_scsi_internal(lport); |
1784 | spin_lock_irqsave(lp->host->host_lock, flags); | 1867 | spin_lock_irqsave(lport->host->host_lock, flags); |
1785 | if (!fsp->cmd) { | 1868 | if (!fsp->cmd) { |
1786 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1869 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1787 | return; | 1870 | return; |
1788 | } | 1871 | } |
1789 | 1872 | ||
1790 | /* | 1873 | /* |
1791 | * if a command timed out while we had to try and throttle IO | 1874 | * if can_queue ramp down is done then try can_queue ramp up |
1792 | * and it is now getting cleaned up, then we are about to | 1875 | * since commands are completing now. |
1793 | * try again so clear the throttled flag incase we get more | ||
1794 | * time outs. | ||
1795 | */ | 1876 | */ |
1796 | if (si->throttled && fsp->state & FC_SRB_NOMEM) | 1877 | if (si->last_can_queue_ramp_down_time) |
1797 | si->throttled = 0; | 1878 | fc_fcp_can_queue_ramp_up(lport); |
1798 | 1879 | ||
1799 | sc_cmd = fsp->cmd; | 1880 | sc_cmd = fsp->cmd; |
1800 | fsp->cmd = NULL; | 1881 | fsp->cmd = NULL; |
1801 | 1882 | ||
1802 | if (!sc_cmd->SCp.ptr) { | 1883 | if (!sc_cmd->SCp.ptr) { |
1803 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1884 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1804 | return; | 1885 | return; |
1805 | } | 1886 | } |
1806 | 1887 | ||
@@ -1814,21 +1895,6 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp) | |||
1814 | sc_cmd->result = DID_OK << 16; | 1895 | sc_cmd->result = DID_OK << 16; |
1815 | if (fsp->scsi_resid) | 1896 | if (fsp->scsi_resid) |
1816 | CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid; | 1897 | CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid; |
1817 | } else if (fsp->cdb_status == QUEUE_FULL) { | ||
1818 | struct scsi_device *tmp_sdev; | ||
1819 | struct scsi_device *sdev = sc_cmd->device; | ||
1820 | |||
1821 | shost_for_each_device(tmp_sdev, sdev->host) { | ||
1822 | if (tmp_sdev->id != sdev->id) | ||
1823 | continue; | ||
1824 | |||
1825 | if (tmp_sdev->queue_depth > 1) { | ||
1826 | scsi_track_queue_full(tmp_sdev, | ||
1827 | tmp_sdev-> | ||
1828 | queue_depth - 1); | ||
1829 | } | ||
1830 | } | ||
1831 | sc_cmd->result = (DID_OK << 16) | fsp->cdb_status; | ||
1832 | } else { | 1898 | } else { |
1833 | /* | 1899 | /* |
1834 | * transport level I/O was ok but scsi | 1900 | * transport level I/O was ok but scsi |
@@ -1846,7 +1912,8 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp) | |||
1846 | * scsi status is good but transport level | 1912 | * scsi status is good but transport level |
1847 | * underrun. | 1913 | * underrun. |
1848 | */ | 1914 | */ |
1849 | sc_cmd->result = DID_OK << 16; | 1915 | sc_cmd->result = (fsp->state & FC_SRB_RCV_STATUS ? |
1916 | DID_OK : DID_ERROR) << 16; | ||
1850 | } else { | 1917 | } else { |
1851 | /* | 1918 | /* |
1852 | * scsi got underrun, this is an error | 1919 | * scsi got underrun, this is an error |
@@ -1881,60 +1948,42 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp) | |||
1881 | list_del(&fsp->list); | 1948 | list_del(&fsp->list); |
1882 | sc_cmd->SCp.ptr = NULL; | 1949 | sc_cmd->SCp.ptr = NULL; |
1883 | sc_cmd->scsi_done(sc_cmd); | 1950 | sc_cmd->scsi_done(sc_cmd); |
1884 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1951 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1885 | 1952 | ||
1886 | /* release ref from initial allocation in queue command */ | 1953 | /* release ref from initial allocation in queue command */ |
1887 | fc_fcp_pkt_release(fsp); | 1954 | fc_fcp_pkt_release(fsp); |
1888 | } | 1955 | } |
1889 | 1956 | ||
1890 | /** | 1957 | /** |
1891 | * fc_fcp_complete() - complete processing of a fcp packet | ||
1892 | * @fsp: fcp packet | ||
1893 | * | ||
1894 | * This function may sleep if a fsp timer is pending. | ||
1895 | * The host lock must not be held by caller. | ||
1896 | */ | ||
1897 | void fc_fcp_complete(struct fc_fcp_pkt *fsp) | ||
1898 | { | ||
1899 | if (fc_fcp_lock_pkt(fsp)) | ||
1900 | return; | ||
1901 | |||
1902 | fc_fcp_complete_locked(fsp); | ||
1903 | fc_fcp_unlock_pkt(fsp); | ||
1904 | } | ||
1905 | EXPORT_SYMBOL(fc_fcp_complete); | ||
1906 | |||
1907 | /** | ||
1908 | * fc_eh_abort() - Abort a command | 1958 | * fc_eh_abort() - Abort a command |
1909 | * @sc_cmd: scsi command to abort | 1959 | * @sc_cmd: The SCSI command to abort |
1910 | * | 1960 | * |
1911 | * From scsi host template. | 1961 | * From SCSI host template. |
1912 | * send ABTS to the target device and wait for the response | 1962 | * Send an ABTS to the target device and wait for the response. |
1913 | * sc_cmd is the pointer to the command to be aborted. | ||
1914 | */ | 1963 | */ |
1915 | int fc_eh_abort(struct scsi_cmnd *sc_cmd) | 1964 | int fc_eh_abort(struct scsi_cmnd *sc_cmd) |
1916 | { | 1965 | { |
1917 | struct fc_fcp_pkt *fsp; | 1966 | struct fc_fcp_pkt *fsp; |
1918 | struct fc_lport *lp; | 1967 | struct fc_lport *lport; |
1919 | int rc = FAILED; | 1968 | int rc = FAILED; |
1920 | unsigned long flags; | 1969 | unsigned long flags; |
1921 | 1970 | ||
1922 | lp = shost_priv(sc_cmd->device->host); | 1971 | lport = shost_priv(sc_cmd->device->host); |
1923 | if (lp->state != LPORT_ST_READY) | 1972 | if (lport->state != LPORT_ST_READY) |
1924 | return rc; | 1973 | return rc; |
1925 | else if (!lp->link_up) | 1974 | else if (!lport->link_up) |
1926 | return rc; | 1975 | return rc; |
1927 | 1976 | ||
1928 | spin_lock_irqsave(lp->host->host_lock, flags); | 1977 | spin_lock_irqsave(lport->host->host_lock, flags); |
1929 | fsp = CMD_SP(sc_cmd); | 1978 | fsp = CMD_SP(sc_cmd); |
1930 | if (!fsp) { | 1979 | if (!fsp) { |
1931 | /* command completed while scsi eh was setting up */ | 1980 | /* command completed while scsi eh was setting up */ |
1932 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1981 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1933 | return SUCCESS; | 1982 | return SUCCESS; |
1934 | } | 1983 | } |
1935 | /* grab a ref so the fsp and sc_cmd cannot be relased from under us */ | 1984 | /* grab a ref so the fsp and sc_cmd cannot be relased from under us */ |
1936 | fc_fcp_pkt_hold(fsp); | 1985 | fc_fcp_pkt_hold(fsp); |
1937 | spin_unlock_irqrestore(lp->host->host_lock, flags); | 1986 | spin_unlock_irqrestore(lport->host->host_lock, flags); |
1938 | 1987 | ||
1939 | if (fc_fcp_lock_pkt(fsp)) { | 1988 | if (fc_fcp_lock_pkt(fsp)) { |
1940 | /* completed while we were waiting for timer to be deleted */ | 1989 | /* completed while we were waiting for timer to be deleted */ |
@@ -1942,7 +1991,7 @@ int fc_eh_abort(struct scsi_cmnd *sc_cmd) | |||
1942 | goto release_pkt; | 1991 | goto release_pkt; |
1943 | } | 1992 | } |
1944 | 1993 | ||
1945 | rc = fc_fcp_pkt_abort(lp, fsp); | 1994 | rc = fc_fcp_pkt_abort(fsp); |
1946 | fc_fcp_unlock_pkt(fsp); | 1995 | fc_fcp_unlock_pkt(fsp); |
1947 | 1996 | ||
1948 | release_pkt: | 1997 | release_pkt: |
@@ -1952,37 +2001,34 @@ release_pkt: | |||
1952 | EXPORT_SYMBOL(fc_eh_abort); | 2001 | EXPORT_SYMBOL(fc_eh_abort); |
1953 | 2002 | ||
1954 | /** | 2003 | /** |
1955 | * fc_eh_device_reset() Reset a single LUN | 2004 | * fc_eh_device_reset() - Reset a single LUN |
1956 | * @sc_cmd: scsi command | 2005 | * @sc_cmd: The SCSI command which identifies the device whose |
2006 | * LUN is to be reset | ||
1957 | * | 2007 | * |
1958 | * Set from scsi host template to send tm cmd to the target and wait for the | 2008 | * Set from SCSI host template. |
1959 | * response. | ||
1960 | */ | 2009 | */ |
1961 | int fc_eh_device_reset(struct scsi_cmnd *sc_cmd) | 2010 | int fc_eh_device_reset(struct scsi_cmnd *sc_cmd) |
1962 | { | 2011 | { |
1963 | struct fc_lport *lp; | 2012 | struct fc_lport *lport; |
1964 | struct fc_fcp_pkt *fsp; | 2013 | struct fc_fcp_pkt *fsp; |
1965 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); | 2014 | struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); |
1966 | int rc = FAILED; | 2015 | int rc = FAILED; |
1967 | struct fc_rport_libfc_priv *rp; | ||
1968 | int rval; | 2016 | int rval; |
1969 | 2017 | ||
1970 | rval = fc_remote_port_chkready(rport); | 2018 | rval = fc_remote_port_chkready(rport); |
1971 | if (rval) | 2019 | if (rval) |
1972 | goto out; | 2020 | goto out; |
1973 | 2021 | ||
1974 | rp = rport->dd_data; | 2022 | lport = shost_priv(sc_cmd->device->host); |
1975 | lp = shost_priv(sc_cmd->device->host); | ||
1976 | 2023 | ||
1977 | if (lp->state != LPORT_ST_READY) | 2024 | if (lport->state != LPORT_ST_READY) |
1978 | return rc; | 2025 | return rc; |
1979 | 2026 | ||
1980 | FC_SCSI_DBG(lp, "Resetting rport (%6x)\n", rport->port_id); | 2027 | FC_SCSI_DBG(lport, "Resetting rport (%6x)\n", rport->port_id); |
1981 | 2028 | ||
1982 | fsp = fc_fcp_pkt_alloc(lp, GFP_NOIO); | 2029 | fsp = fc_fcp_pkt_alloc(lport, GFP_NOIO); |
1983 | if (fsp == NULL) { | 2030 | if (fsp == NULL) { |
1984 | printk(KERN_WARNING "libfc: could not allocate scsi_pkt\n"); | 2031 | printk(KERN_WARNING "libfc: could not allocate scsi_pkt\n"); |
1985 | sc_cmd->result = DID_NO_CONNECT << 16; | ||
1986 | goto out; | 2032 | goto out; |
1987 | } | 2033 | } |
1988 | 2034 | ||
@@ -1991,13 +2037,13 @@ int fc_eh_device_reset(struct scsi_cmnd *sc_cmd) | |||
1991 | * the sc passed in is not setup for execution like when sent | 2037 | * the sc passed in is not setup for execution like when sent |
1992 | * through the queuecommand callout. | 2038 | * through the queuecommand callout. |
1993 | */ | 2039 | */ |
1994 | fsp->lp = lp; /* save the softc ptr */ | 2040 | fsp->lp = lport; /* save the softc ptr */ |
1995 | fsp->rport = rport; /* set the remote port ptr */ | 2041 | fsp->rport = rport; /* set the remote port ptr */ |
1996 | 2042 | ||
1997 | /* | 2043 | /* |
1998 | * flush outstanding commands | 2044 | * flush outstanding commands |
1999 | */ | 2045 | */ |
2000 | rc = fc_lun_reset(lp, fsp, scmd_id(sc_cmd), sc_cmd->device->lun); | 2046 | rc = fc_lun_reset(lport, fsp, scmd_id(sc_cmd), sc_cmd->device->lun); |
2001 | fsp->state = FC_SRB_FREE; | 2047 | fsp->state = FC_SRB_FREE; |
2002 | fc_fcp_pkt_release(fsp); | 2048 | fc_fcp_pkt_release(fsp); |
2003 | 2049 | ||
@@ -2007,38 +2053,39 @@ out: | |||
2007 | EXPORT_SYMBOL(fc_eh_device_reset); | 2053 | EXPORT_SYMBOL(fc_eh_device_reset); |
2008 | 2054 | ||
2009 | /** | 2055 | /** |
2010 | * fc_eh_host_reset() - The reset function will reset the ports on the host. | 2056 | * fc_eh_host_reset() - Reset a Scsi_Host. |
2011 | * @sc_cmd: scsi command | 2057 | * @sc_cmd: The SCSI command that identifies the SCSI host to be reset |
2012 | */ | 2058 | */ |
2013 | int fc_eh_host_reset(struct scsi_cmnd *sc_cmd) | 2059 | int fc_eh_host_reset(struct scsi_cmnd *sc_cmd) |
2014 | { | 2060 | { |
2015 | struct Scsi_Host *shost = sc_cmd->device->host; | 2061 | struct Scsi_Host *shost = sc_cmd->device->host; |
2016 | struct fc_lport *lp = shost_priv(shost); | 2062 | struct fc_lport *lport = shost_priv(shost); |
2017 | unsigned long wait_tmo; | 2063 | unsigned long wait_tmo; |
2018 | 2064 | ||
2019 | FC_SCSI_DBG(lp, "Resetting host\n"); | 2065 | FC_SCSI_DBG(lport, "Resetting host\n"); |
2020 | 2066 | ||
2021 | lp->tt.lport_reset(lp); | 2067 | lport->tt.lport_reset(lport); |
2022 | wait_tmo = jiffies + FC_HOST_RESET_TIMEOUT; | 2068 | wait_tmo = jiffies + FC_HOST_RESET_TIMEOUT; |
2023 | while (!fc_fcp_lport_queue_ready(lp) && time_before(jiffies, wait_tmo)) | 2069 | while (!fc_fcp_lport_queue_ready(lport) && time_before(jiffies, |
2070 | wait_tmo)) | ||
2024 | msleep(1000); | 2071 | msleep(1000); |
2025 | 2072 | ||
2026 | if (fc_fcp_lport_queue_ready(lp)) { | 2073 | if (fc_fcp_lport_queue_ready(lport)) { |
2027 | shost_printk(KERN_INFO, shost, "libfc: Host reset succeeded " | 2074 | shost_printk(KERN_INFO, shost, "libfc: Host reset succeeded " |
2028 | "on port (%6x)\n", fc_host_port_id(lp->host)); | 2075 | "on port (%6x)\n", fc_host_port_id(lport->host)); |
2029 | return SUCCESS; | 2076 | return SUCCESS; |
2030 | } else { | 2077 | } else { |
2031 | shost_printk(KERN_INFO, shost, "libfc: Host reset failed, " | 2078 | shost_printk(KERN_INFO, shost, "libfc: Host reset failed, " |
2032 | "port (%6x) is not ready.\n", | 2079 | "port (%6x) is not ready.\n", |
2033 | fc_host_port_id(lp->host)); | 2080 | fc_host_port_id(lport->host)); |
2034 | return FAILED; | 2081 | return FAILED; |
2035 | } | 2082 | } |
2036 | } | 2083 | } |
2037 | EXPORT_SYMBOL(fc_eh_host_reset); | 2084 | EXPORT_SYMBOL(fc_eh_host_reset); |
2038 | 2085 | ||
2039 | /** | 2086 | /** |
2040 | * fc_slave_alloc() - configure queue depth | 2087 | * fc_slave_alloc() - Configure the queue depth of a Scsi_Host |
2041 | * @sdev: scsi device | 2088 | * @sdev: The SCSI device that identifies the SCSI host |
2042 | * | 2089 | * |
2043 | * Configures queue depth based on host's cmd_per_len. If not set | 2090 | * Configures queue depth based on host's cmd_per_len. If not set |
2044 | * then we use the libfc default. | 2091 | * then we use the libfc default. |
@@ -2046,29 +2093,50 @@ EXPORT_SYMBOL(fc_eh_host_reset); | |||
2046 | int fc_slave_alloc(struct scsi_device *sdev) | 2093 | int fc_slave_alloc(struct scsi_device *sdev) |
2047 | { | 2094 | { |
2048 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | 2095 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
2049 | int queue_depth; | ||
2050 | 2096 | ||
2051 | if (!rport || fc_remote_port_chkready(rport)) | 2097 | if (!rport || fc_remote_port_chkready(rport)) |
2052 | return -ENXIO; | 2098 | return -ENXIO; |
2053 | 2099 | ||
2054 | if (sdev->tagged_supported) { | 2100 | if (sdev->tagged_supported) |
2055 | if (sdev->host->hostt->cmd_per_lun) | 2101 | scsi_activate_tcq(sdev, FC_FCP_DFLT_QUEUE_DEPTH); |
2056 | queue_depth = sdev->host->hostt->cmd_per_lun; | 2102 | else |
2057 | else | 2103 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), |
2058 | queue_depth = FC_FCP_DFLT_QUEUE_DEPTH; | 2104 | FC_FCP_DFLT_QUEUE_DEPTH); |
2059 | scsi_activate_tcq(sdev, queue_depth); | 2105 | |
2060 | } | ||
2061 | return 0; | 2106 | return 0; |
2062 | } | 2107 | } |
2063 | EXPORT_SYMBOL(fc_slave_alloc); | 2108 | EXPORT_SYMBOL(fc_slave_alloc); |
2064 | 2109 | ||
2065 | int fc_change_queue_depth(struct scsi_device *sdev, int qdepth) | 2110 | /** |
2111 | * fc_change_queue_depth() - Change a device's queue depth | ||
2112 | * @sdev: The SCSI device whose queue depth is to change | ||
2113 | * @qdepth: The new queue depth | ||
2114 | * @reason: The resason for the change | ||
2115 | */ | ||
2116 | int fc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) | ||
2066 | { | 2117 | { |
2067 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | 2118 | switch (reason) { |
2119 | case SCSI_QDEPTH_DEFAULT: | ||
2120 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | ||
2121 | break; | ||
2122 | case SCSI_QDEPTH_QFULL: | ||
2123 | scsi_track_queue_full(sdev, qdepth); | ||
2124 | break; | ||
2125 | case SCSI_QDEPTH_RAMP_UP: | ||
2126 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | ||
2127 | break; | ||
2128 | default: | ||
2129 | return -EOPNOTSUPP; | ||
2130 | } | ||
2068 | return sdev->queue_depth; | 2131 | return sdev->queue_depth; |
2069 | } | 2132 | } |
2070 | EXPORT_SYMBOL(fc_change_queue_depth); | 2133 | EXPORT_SYMBOL(fc_change_queue_depth); |
2071 | 2134 | ||
2135 | /** | ||
2136 | * fc_change_queue_type() - Change a device's queue type | ||
2137 | * @sdev: The SCSI device whose queue depth is to change | ||
2138 | * @tag_type: Identifier for queue type | ||
2139 | */ | ||
2072 | int fc_change_queue_type(struct scsi_device *sdev, int tag_type) | 2140 | int fc_change_queue_type(struct scsi_device *sdev, int tag_type) |
2073 | { | 2141 | { |
2074 | if (sdev->tagged_supported) { | 2142 | if (sdev->tagged_supported) { |
@@ -2084,38 +2152,69 @@ int fc_change_queue_type(struct scsi_device *sdev, int tag_type) | |||
2084 | } | 2152 | } |
2085 | EXPORT_SYMBOL(fc_change_queue_type); | 2153 | EXPORT_SYMBOL(fc_change_queue_type); |
2086 | 2154 | ||
2087 | void fc_fcp_destroy(struct fc_lport *lp) | 2155 | /** |
2156 | * fc_fcp_destory() - Tear down the FCP layer for a given local port | ||
2157 | * @lport: The local port that no longer needs the FCP layer | ||
2158 | */ | ||
2159 | void fc_fcp_destroy(struct fc_lport *lport) | ||
2088 | { | 2160 | { |
2089 | struct fc_fcp_internal *si = fc_get_scsi_internal(lp); | 2161 | struct fc_fcp_internal *si = fc_get_scsi_internal(lport); |
2090 | 2162 | ||
2091 | if (!list_empty(&si->scsi_pkt_queue)) | 2163 | if (!list_empty(&si->scsi_pkt_queue)) |
2092 | printk(KERN_ERR "libfc: Leaked SCSI packets when destroying " | 2164 | printk(KERN_ERR "libfc: Leaked SCSI packets when destroying " |
2093 | "port (%6x)\n", fc_host_port_id(lp->host)); | 2165 | "port (%6x)\n", fc_host_port_id(lport->host)); |
2094 | 2166 | ||
2095 | mempool_destroy(si->scsi_pkt_pool); | 2167 | mempool_destroy(si->scsi_pkt_pool); |
2096 | kfree(si); | 2168 | kfree(si); |
2097 | lp->scsi_priv = NULL; | 2169 | lport->scsi_priv = NULL; |
2098 | } | 2170 | } |
2099 | EXPORT_SYMBOL(fc_fcp_destroy); | 2171 | EXPORT_SYMBOL(fc_fcp_destroy); |
2100 | 2172 | ||
2101 | int fc_fcp_init(struct fc_lport *lp) | 2173 | int fc_setup_fcp() |
2174 | { | ||
2175 | int rc = 0; | ||
2176 | |||
2177 | scsi_pkt_cachep = kmem_cache_create("libfc_fcp_pkt", | ||
2178 | sizeof(struct fc_fcp_pkt), | ||
2179 | 0, SLAB_HWCACHE_ALIGN, NULL); | ||
2180 | if (!scsi_pkt_cachep) { | ||
2181 | printk(KERN_ERR "libfc: Unable to allocate SRB cache, " | ||
2182 | "module load failed!"); | ||
2183 | rc = -ENOMEM; | ||
2184 | } | ||
2185 | |||
2186 | return rc; | ||
2187 | } | ||
2188 | |||
2189 | void fc_destroy_fcp() | ||
2190 | { | ||
2191 | if (scsi_pkt_cachep) | ||
2192 | kmem_cache_destroy(scsi_pkt_cachep); | ||
2193 | } | ||
2194 | |||
2195 | /** | ||
2196 | * fc_fcp_init() - Initialize the FCP layer for a local port | ||
2197 | * @lport: The local port to initialize the exchange layer for | ||
2198 | */ | ||
2199 | int fc_fcp_init(struct fc_lport *lport) | ||
2102 | { | 2200 | { |
2103 | int rc; | 2201 | int rc; |
2104 | struct fc_fcp_internal *si; | 2202 | struct fc_fcp_internal *si; |
2105 | 2203 | ||
2106 | if (!lp->tt.fcp_cmd_send) | 2204 | if (!lport->tt.fcp_cmd_send) |
2107 | lp->tt.fcp_cmd_send = fc_fcp_cmd_send; | 2205 | lport->tt.fcp_cmd_send = fc_fcp_cmd_send; |
2108 | 2206 | ||
2109 | if (!lp->tt.fcp_cleanup) | 2207 | if (!lport->tt.fcp_cleanup) |
2110 | lp->tt.fcp_cleanup = fc_fcp_cleanup; | 2208 | lport->tt.fcp_cleanup = fc_fcp_cleanup; |
2111 | 2209 | ||
2112 | if (!lp->tt.fcp_abort_io) | 2210 | if (!lport->tt.fcp_abort_io) |
2113 | lp->tt.fcp_abort_io = fc_fcp_abort_io; | 2211 | lport->tt.fcp_abort_io = fc_fcp_abort_io; |
2114 | 2212 | ||
2115 | si = kzalloc(sizeof(struct fc_fcp_internal), GFP_KERNEL); | 2213 | si = kzalloc(sizeof(struct fc_fcp_internal), GFP_KERNEL); |
2116 | if (!si) | 2214 | if (!si) |
2117 | return -ENOMEM; | 2215 | return -ENOMEM; |
2118 | lp->scsi_priv = si; | 2216 | lport->scsi_priv = si; |
2217 | si->max_can_queue = lport->host->can_queue; | ||
2119 | INIT_LIST_HEAD(&si->scsi_pkt_queue); | 2218 | INIT_LIST_HEAD(&si->scsi_pkt_queue); |
2120 | 2219 | ||
2121 | si->scsi_pkt_pool = mempool_create_slab_pool(2, scsi_pkt_cachep); | 2220 | si->scsi_pkt_pool = mempool_create_slab_pool(2, scsi_pkt_cachep); |
@@ -2130,42 +2229,3 @@ free_internal: | |||
2130 | return rc; | 2229 | return rc; |
2131 | } | 2230 | } |
2132 | EXPORT_SYMBOL(fc_fcp_init); | 2231 | EXPORT_SYMBOL(fc_fcp_init); |
2133 | |||
2134 | static int __init libfc_init(void) | ||
2135 | { | ||
2136 | int rc; | ||
2137 | |||
2138 | scsi_pkt_cachep = kmem_cache_create("libfc_fcp_pkt", | ||
2139 | sizeof(struct fc_fcp_pkt), | ||
2140 | 0, SLAB_HWCACHE_ALIGN, NULL); | ||
2141 | if (scsi_pkt_cachep == NULL) { | ||
2142 | printk(KERN_ERR "libfc: Unable to allocate SRB cache, " | ||
2143 | "module load failed!"); | ||
2144 | return -ENOMEM; | ||
2145 | } | ||
2146 | |||
2147 | rc = fc_setup_exch_mgr(); | ||
2148 | if (rc) | ||
2149 | goto destroy_pkt_cache; | ||
2150 | |||
2151 | rc = fc_setup_rport(); | ||
2152 | if (rc) | ||
2153 | goto destroy_em; | ||
2154 | |||
2155 | return rc; | ||
2156 | destroy_em: | ||
2157 | fc_destroy_exch_mgr(); | ||
2158 | destroy_pkt_cache: | ||
2159 | kmem_cache_destroy(scsi_pkt_cachep); | ||
2160 | return rc; | ||
2161 | } | ||
2162 | |||
2163 | static void __exit libfc_exit(void) | ||
2164 | { | ||
2165 | kmem_cache_destroy(scsi_pkt_cachep); | ||
2166 | fc_destroy_exch_mgr(); | ||
2167 | fc_destroy_rport(); | ||
2168 | } | ||
2169 | |||
2170 | module_init(libfc_init); | ||
2171 | module_exit(libfc_exit); | ||
diff --git a/drivers/scsi/libfc/fc_frame.c b/drivers/scsi/libfc/fc_frame.c index 63fe00cfe667..6da01c616964 100644 --- a/drivers/scsi/libfc/fc_frame.c +++ b/drivers/scsi/libfc/fc_frame.c | |||
@@ -51,24 +51,24 @@ EXPORT_SYMBOL(fc_frame_crc_check); | |||
51 | * Allocate a frame intended to be sent via fcoe_xmit. | 51 | * Allocate a frame intended to be sent via fcoe_xmit. |
52 | * Get an sk_buff for the frame and set the length. | 52 | * Get an sk_buff for the frame and set the length. |
53 | */ | 53 | */ |
54 | struct fc_frame *__fc_frame_alloc(size_t len) | 54 | struct fc_frame *_fc_frame_alloc(size_t len) |
55 | { | 55 | { |
56 | struct fc_frame *fp; | 56 | struct fc_frame *fp; |
57 | struct sk_buff *skb; | 57 | struct sk_buff *skb; |
58 | 58 | ||
59 | WARN_ON((len % sizeof(u32)) != 0); | 59 | WARN_ON((len % sizeof(u32)) != 0); |
60 | len += sizeof(struct fc_frame_header); | 60 | len += sizeof(struct fc_frame_header); |
61 | skb = dev_alloc_skb(len + FC_FRAME_HEADROOM + FC_FRAME_TAILROOM); | 61 | skb = alloc_skb_fclone(len + FC_FRAME_HEADROOM + FC_FRAME_TAILROOM + |
62 | NET_SKB_PAD, GFP_ATOMIC); | ||
62 | if (!skb) | 63 | if (!skb) |
63 | return NULL; | 64 | return NULL; |
65 | skb_reserve(skb, NET_SKB_PAD + FC_FRAME_HEADROOM); | ||
64 | fp = (struct fc_frame *) skb; | 66 | fp = (struct fc_frame *) skb; |
65 | fc_frame_init(fp); | 67 | fc_frame_init(fp); |
66 | skb_reserve(skb, FC_FRAME_HEADROOM); | ||
67 | skb_put(skb, len); | 68 | skb_put(skb, len); |
68 | return fp; | 69 | return fp; |
69 | } | 70 | } |
70 | EXPORT_SYMBOL(__fc_frame_alloc); | 71 | EXPORT_SYMBOL(_fc_frame_alloc); |
71 | |||
72 | 72 | ||
73 | struct fc_frame *fc_frame_alloc_fill(struct fc_lport *lp, size_t payload_len) | 73 | struct fc_frame *fc_frame_alloc_fill(struct fc_lport *lp, size_t payload_len) |
74 | { | 74 | { |
@@ -78,7 +78,7 @@ struct fc_frame *fc_frame_alloc_fill(struct fc_lport *lp, size_t payload_len) | |||
78 | fill = payload_len % 4; | 78 | fill = payload_len % 4; |
79 | if (fill != 0) | 79 | if (fill != 0) |
80 | fill = 4 - fill; | 80 | fill = 4 - fill; |
81 | fp = __fc_frame_alloc(payload_len + fill); | 81 | fp = _fc_frame_alloc(payload_len + fill); |
82 | if (fp) { | 82 | if (fp) { |
83 | memset((char *) fr_hdr(fp) + payload_len, 0, fill); | 83 | memset((char *) fr_hdr(fp) + payload_len, 0, fill); |
84 | /* trim is OK, we just allocated it so there are no fragments */ | 84 | /* trim is OK, we just allocated it so there are no fragments */ |
@@ -87,3 +87,4 @@ struct fc_frame *fc_frame_alloc_fill(struct fc_lport *lp, size_t payload_len) | |||
87 | } | 87 | } |
88 | return fp; | 88 | return fp; |
89 | } | 89 | } |
90 | EXPORT_SYMBOL(fc_frame_alloc_fill); | ||
diff --git a/drivers/scsi/libfc/fc_libfc.c b/drivers/scsi/libfc/fc_libfc.c new file mode 100644 index 000000000000..39f4b6ab04b4 --- /dev/null +++ b/drivers/scsi/libfc/fc_libfc.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | * Copyright(c) 2009 Intel Corporation. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License along with | ||
14 | * this program; if not, write to the Free Software Foundation, Inc., | ||
15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
16 | * | ||
17 | * Maintained at www.Open-FCoE.org | ||
18 | */ | ||
19 | |||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/scatterlist.h> | ||
23 | #include <linux/crc32.h> | ||
24 | |||
25 | #include <scsi/libfc.h> | ||
26 | |||
27 | #include "fc_libfc.h" | ||
28 | |||
29 | MODULE_AUTHOR("Open-FCoE.org"); | ||
30 | MODULE_DESCRIPTION("libfc"); | ||
31 | MODULE_LICENSE("GPL v2"); | ||
32 | |||
33 | unsigned int fc_debug_logging; | ||
34 | module_param_named(debug_logging, fc_debug_logging, int, S_IRUGO|S_IWUSR); | ||
35 | MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels"); | ||
36 | |||
37 | /** | ||
38 | * libfc_init() - Initialize libfc.ko | ||
39 | */ | ||
40 | static int __init libfc_init(void) | ||
41 | { | ||
42 | int rc = 0; | ||
43 | |||
44 | rc = fc_setup_fcp(); | ||
45 | if (rc) | ||
46 | return rc; | ||
47 | |||
48 | rc = fc_setup_exch_mgr(); | ||
49 | if (rc) | ||
50 | goto destroy_pkt_cache; | ||
51 | |||
52 | rc = fc_setup_rport(); | ||
53 | if (rc) | ||
54 | goto destroy_em; | ||
55 | |||
56 | return rc; | ||
57 | destroy_em: | ||
58 | fc_destroy_exch_mgr(); | ||
59 | destroy_pkt_cache: | ||
60 | fc_destroy_fcp(); | ||
61 | return rc; | ||
62 | } | ||
63 | module_init(libfc_init); | ||
64 | |||
65 | /** | ||
66 | * libfc_exit() - Tear down libfc.ko | ||
67 | */ | ||
68 | static void __exit libfc_exit(void) | ||
69 | { | ||
70 | fc_destroy_fcp(); | ||
71 | fc_destroy_exch_mgr(); | ||
72 | fc_destroy_rport(); | ||
73 | } | ||
74 | module_exit(libfc_exit); | ||
75 | |||
76 | /** | ||
77 | * fc_copy_buffer_to_sglist() - This routine copies the data of a buffer | ||
78 | * into a scatter-gather list (SG list). | ||
79 | * | ||
80 | * @buf: pointer to the data buffer. | ||
81 | * @len: the byte-length of the data buffer. | ||
82 | * @sg: pointer to the pointer of the SG list. | ||
83 | * @nents: pointer to the remaining number of entries in the SG list. | ||
84 | * @offset: pointer to the current offset in the SG list. | ||
85 | * @km_type: dedicated page table slot type for kmap_atomic. | ||
86 | * @crc: pointer to the 32-bit crc value. | ||
87 | * If crc is NULL, CRC is not calculated. | ||
88 | */ | ||
89 | u32 fc_copy_buffer_to_sglist(void *buf, size_t len, | ||
90 | struct scatterlist *sg, | ||
91 | u32 *nents, size_t *offset, | ||
92 | enum km_type km_type, u32 *crc) | ||
93 | { | ||
94 | size_t remaining = len; | ||
95 | u32 copy_len = 0; | ||
96 | |||
97 | while (remaining > 0 && sg) { | ||
98 | size_t off, sg_bytes; | ||
99 | void *page_addr; | ||
100 | |||
101 | if (*offset >= sg->length) { | ||
102 | /* | ||
103 | * Check for end and drop resources | ||
104 | * from the last iteration. | ||
105 | */ | ||
106 | if (!(*nents)) | ||
107 | break; | ||
108 | --(*nents); | ||
109 | *offset -= sg->length; | ||
110 | sg = sg_next(sg); | ||
111 | continue; | ||
112 | } | ||
113 | sg_bytes = min(remaining, sg->length - *offset); | ||
114 | |||
115 | /* | ||
116 | * The scatterlist item may be bigger than PAGE_SIZE, | ||
117 | * but we are limited to mapping PAGE_SIZE at a time. | ||
118 | */ | ||
119 | off = *offset + sg->offset; | ||
120 | sg_bytes = min(sg_bytes, | ||
121 | (size_t)(PAGE_SIZE - (off & ~PAGE_MASK))); | ||
122 | page_addr = kmap_atomic(sg_page(sg) + (off >> PAGE_SHIFT), | ||
123 | km_type); | ||
124 | if (crc) | ||
125 | *crc = crc32(*crc, buf, sg_bytes); | ||
126 | memcpy((char *)page_addr + (off & ~PAGE_MASK), buf, sg_bytes); | ||
127 | kunmap_atomic(page_addr, km_type); | ||
128 | buf += sg_bytes; | ||
129 | *offset += sg_bytes; | ||
130 | remaining -= sg_bytes; | ||
131 | copy_len += sg_bytes; | ||
132 | } | ||
133 | return copy_len; | ||
134 | } | ||
diff --git a/drivers/scsi/libfc/fc_libfc.h b/drivers/scsi/libfc/fc_libfc.h new file mode 100644 index 000000000000..741fd5c72e13 --- /dev/null +++ b/drivers/scsi/libfc/fc_libfc.h | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | * Copyright(c) 2009 Intel Corporation. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License along with | ||
14 | * this program; if not, write to the Free Software Foundation, Inc., | ||
15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
16 | * | ||
17 | * Maintained at www.Open-FCoE.org | ||
18 | */ | ||
19 | |||
20 | #ifndef _FC_LIBFC_H_ | ||
21 | #define _FC_LIBFC_H_ | ||
22 | |||
23 | #define FC_LIBFC_LOGGING 0x01 /* General logging, not categorized */ | ||
24 | #define FC_LPORT_LOGGING 0x02 /* lport layer logging */ | ||
25 | #define FC_DISC_LOGGING 0x04 /* discovery layer logging */ | ||
26 | #define FC_RPORT_LOGGING 0x08 /* rport layer logging */ | ||
27 | #define FC_FCP_LOGGING 0x10 /* I/O path logging */ | ||
28 | #define FC_EM_LOGGING 0x20 /* Exchange Manager logging */ | ||
29 | #define FC_EXCH_LOGGING 0x40 /* Exchange/Sequence logging */ | ||
30 | #define FC_SCSI_LOGGING 0x80 /* SCSI logging (mostly error handling) */ | ||
31 | |||
32 | extern unsigned int fc_debug_logging; | ||
33 | |||
34 | #define FC_CHECK_LOGGING(LEVEL, CMD) \ | ||
35 | do { \ | ||
36 | if (unlikely(fc_debug_logging & LEVEL)) \ | ||
37 | do { \ | ||
38 | CMD; \ | ||
39 | } while (0); \ | ||
40 | } while (0) | ||
41 | |||
42 | #define FC_LIBFC_DBG(fmt, args...) \ | ||
43 | FC_CHECK_LOGGING(FC_LIBFC_LOGGING, \ | ||
44 | printk(KERN_INFO "libfc: " fmt, ##args)) | ||
45 | |||
46 | #define FC_LPORT_DBG(lport, fmt, args...) \ | ||
47 | FC_CHECK_LOGGING(FC_LPORT_LOGGING, \ | ||
48 | printk(KERN_INFO "host%u: lport %6x: " fmt, \ | ||
49 | (lport)->host->host_no, \ | ||
50 | fc_host_port_id((lport)->host), ##args)) | ||
51 | |||
52 | #define FC_DISC_DBG(disc, fmt, args...) \ | ||
53 | FC_CHECK_LOGGING(FC_DISC_LOGGING, \ | ||
54 | printk(KERN_INFO "host%u: disc: " fmt, \ | ||
55 | (disc)->lport->host->host_no, \ | ||
56 | ##args)) | ||
57 | |||
58 | #define FC_RPORT_ID_DBG(lport, port_id, fmt, args...) \ | ||
59 | FC_CHECK_LOGGING(FC_RPORT_LOGGING, \ | ||
60 | printk(KERN_INFO "host%u: rport %6x: " fmt, \ | ||
61 | (lport)->host->host_no, \ | ||
62 | (port_id), ##args)) | ||
63 | |||
64 | #define FC_RPORT_DBG(rdata, fmt, args...) \ | ||
65 | FC_RPORT_ID_DBG((rdata)->local_port, (rdata)->ids.port_id, fmt, ##args) | ||
66 | |||
67 | #define FC_FCP_DBG(pkt, fmt, args...) \ | ||
68 | FC_CHECK_LOGGING(FC_FCP_LOGGING, \ | ||
69 | printk(KERN_INFO "host%u: fcp: %6x: " fmt, \ | ||
70 | (pkt)->lp->host->host_no, \ | ||
71 | pkt->rport->port_id, ##args)) | ||
72 | |||
73 | #define FC_EXCH_DBG(exch, fmt, args...) \ | ||
74 | FC_CHECK_LOGGING(FC_EXCH_LOGGING, \ | ||
75 | printk(KERN_INFO "host%u: xid %4x: " fmt, \ | ||
76 | (exch)->lp->host->host_no, \ | ||
77 | exch->xid, ##args)) | ||
78 | |||
79 | #define FC_SCSI_DBG(lport, fmt, args...) \ | ||
80 | FC_CHECK_LOGGING(FC_SCSI_LOGGING, \ | ||
81 | printk(KERN_INFO "host%u: scsi: " fmt, \ | ||
82 | (lport)->host->host_no, ##args)) | ||
83 | |||
84 | /* | ||
85 | * Set up direct-data placement for this I/O request | ||
86 | */ | ||
87 | void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid); | ||
88 | |||
89 | /* | ||
90 | * Module setup functions | ||
91 | */ | ||
92 | int fc_setup_exch_mgr(void); | ||
93 | void fc_destroy_exch_mgr(void); | ||
94 | int fc_setup_rport(void); | ||
95 | void fc_destroy_rport(void); | ||
96 | int fc_setup_fcp(void); | ||
97 | void fc_destroy_fcp(void); | ||
98 | |||
99 | /* | ||
100 | * Internal libfc functions | ||
101 | */ | ||
102 | const char *fc_els_resp_type(struct fc_frame *); | ||
103 | |||
104 | /* | ||
105 | * Copies a buffer into an sg list | ||
106 | */ | ||
107 | u32 fc_copy_buffer_to_sglist(void *buf, size_t len, | ||
108 | struct scatterlist *sg, | ||
109 | u32 *nents, size_t *offset, | ||
110 | enum km_type km_type, u32 *crc); | ||
111 | |||
112 | #endif /* _FC_LIBFC_H_ */ | ||
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c index bd2f77197447..bbf4152c9c69 100644 --- a/drivers/scsi/libfc/fc_lport.c +++ b/drivers/scsi/libfc/fc_lport.c | |||
@@ -94,6 +94,9 @@ | |||
94 | 94 | ||
95 | #include <scsi/libfc.h> | 95 | #include <scsi/libfc.h> |
96 | #include <scsi/fc_encode.h> | 96 | #include <scsi/fc_encode.h> |
97 | #include <linux/scatterlist.h> | ||
98 | |||
99 | #include "fc_libfc.h" | ||
97 | 100 | ||
98 | /* Fabric IDs to use for point-to-point mode, chosen on whims. */ | 101 | /* Fabric IDs to use for point-to-point mode, chosen on whims. */ |
99 | #define FC_LOCAL_PTP_FID_LO 0x010101 | 102 | #define FC_LOCAL_PTP_FID_LO 0x010101 |
@@ -106,8 +109,7 @@ static void fc_lport_error(struct fc_lport *, struct fc_frame *); | |||
106 | static void fc_lport_enter_reset(struct fc_lport *); | 109 | static void fc_lport_enter_reset(struct fc_lport *); |
107 | static void fc_lport_enter_flogi(struct fc_lport *); | 110 | static void fc_lport_enter_flogi(struct fc_lport *); |
108 | static void fc_lport_enter_dns(struct fc_lport *); | 111 | static void fc_lport_enter_dns(struct fc_lport *); |
109 | static void fc_lport_enter_rpn_id(struct fc_lport *); | 112 | static void fc_lport_enter_ns(struct fc_lport *, enum fc_lport_state); |
110 | static void fc_lport_enter_rft_id(struct fc_lport *); | ||
111 | static void fc_lport_enter_scr(struct fc_lport *); | 113 | static void fc_lport_enter_scr(struct fc_lport *); |
112 | static void fc_lport_enter_ready(struct fc_lport *); | 114 | static void fc_lport_enter_ready(struct fc_lport *); |
113 | static void fc_lport_enter_logo(struct fc_lport *); | 115 | static void fc_lport_enter_logo(struct fc_lport *); |
@@ -116,14 +118,40 @@ static const char *fc_lport_state_names[] = { | |||
116 | [LPORT_ST_DISABLED] = "disabled", | 118 | [LPORT_ST_DISABLED] = "disabled", |
117 | [LPORT_ST_FLOGI] = "FLOGI", | 119 | [LPORT_ST_FLOGI] = "FLOGI", |
118 | [LPORT_ST_DNS] = "dNS", | 120 | [LPORT_ST_DNS] = "dNS", |
119 | [LPORT_ST_RPN_ID] = "RPN_ID", | 121 | [LPORT_ST_RNN_ID] = "RNN_ID", |
122 | [LPORT_ST_RSNN_NN] = "RSNN_NN", | ||
123 | [LPORT_ST_RSPN_ID] = "RSPN_ID", | ||
120 | [LPORT_ST_RFT_ID] = "RFT_ID", | 124 | [LPORT_ST_RFT_ID] = "RFT_ID", |
125 | [LPORT_ST_RFF_ID] = "RFF_ID", | ||
121 | [LPORT_ST_SCR] = "SCR", | 126 | [LPORT_ST_SCR] = "SCR", |
122 | [LPORT_ST_READY] = "Ready", | 127 | [LPORT_ST_READY] = "Ready", |
123 | [LPORT_ST_LOGO] = "LOGO", | 128 | [LPORT_ST_LOGO] = "LOGO", |
124 | [LPORT_ST_RESET] = "reset", | 129 | [LPORT_ST_RESET] = "reset", |
125 | }; | 130 | }; |
126 | 131 | ||
132 | /** | ||
133 | * struct fc_bsg_info - FC Passthrough managemet structure | ||
134 | * @job: The passthrough job | ||
135 | * @lport: The local port to pass through a command | ||
136 | * @rsp_code: The expected response code | ||
137 | * @sg: job->reply_payload.sg_list | ||
138 | * @nents: job->reply_payload.sg_cnt | ||
139 | * @offset: The offset into the response data | ||
140 | */ | ||
141 | struct fc_bsg_info { | ||
142 | struct fc_bsg_job *job; | ||
143 | struct fc_lport *lport; | ||
144 | u16 rsp_code; | ||
145 | struct scatterlist *sg; | ||
146 | u32 nents; | ||
147 | size_t offset; | ||
148 | }; | ||
149 | |||
150 | /** | ||
151 | * fc_frame_drop() - Dummy frame handler | ||
152 | * @lport: The local port the frame was received on | ||
153 | * @fp: The received frame | ||
154 | */ | ||
127 | static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp) | 155 | static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp) |
128 | { | 156 | { |
129 | fc_frame_free(fp); | 157 | fc_frame_free(fp); |
@@ -150,8 +178,8 @@ static void fc_lport_rport_callback(struct fc_lport *lport, | |||
150 | switch (event) { | 178 | switch (event) { |
151 | case RPORT_EV_READY: | 179 | case RPORT_EV_READY: |
152 | if (lport->state == LPORT_ST_DNS) { | 180 | if (lport->state == LPORT_ST_DNS) { |
153 | lport->dns_rp = rdata; | 181 | lport->dns_rdata = rdata; |
154 | fc_lport_enter_rpn_id(lport); | 182 | fc_lport_enter_ns(lport, LPORT_ST_RNN_ID); |
155 | } else { | 183 | } else { |
156 | FC_LPORT_DBG(lport, "Received an READY event " | 184 | FC_LPORT_DBG(lport, "Received an READY event " |
157 | "on port (%6x) for the directory " | 185 | "on port (%6x) for the directory " |
@@ -165,7 +193,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport, | |||
165 | case RPORT_EV_LOGO: | 193 | case RPORT_EV_LOGO: |
166 | case RPORT_EV_FAILED: | 194 | case RPORT_EV_FAILED: |
167 | case RPORT_EV_STOP: | 195 | case RPORT_EV_STOP: |
168 | lport->dns_rp = NULL; | 196 | lport->dns_rdata = NULL; |
169 | break; | 197 | break; |
170 | case RPORT_EV_NONE: | 198 | case RPORT_EV_NONE: |
171 | break; | 199 | break; |
@@ -189,8 +217,8 @@ static const char *fc_lport_state(struct fc_lport *lport) | |||
189 | 217 | ||
190 | /** | 218 | /** |
191 | * fc_lport_ptp_setup() - Create an rport for point-to-point mode | 219 | * fc_lport_ptp_setup() - Create an rport for point-to-point mode |
192 | * @lport: The lport to attach the ptp rport to | 220 | * @lport: The lport to attach the ptp rport to |
193 | * @fid: The FID of the ptp rport | 221 | * @remote_fid: The FID of the ptp rport |
194 | * @remote_wwpn: The WWPN of the ptp rport | 222 | * @remote_wwpn: The WWPN of the ptp rport |
195 | * @remote_wwnn: The WWNN of the ptp rport | 223 | * @remote_wwnn: The WWNN of the ptp rport |
196 | */ | 224 | */ |
@@ -199,18 +227,22 @@ static void fc_lport_ptp_setup(struct fc_lport *lport, | |||
199 | u64 remote_wwnn) | 227 | u64 remote_wwnn) |
200 | { | 228 | { |
201 | mutex_lock(&lport->disc.disc_mutex); | 229 | mutex_lock(&lport->disc.disc_mutex); |
202 | if (lport->ptp_rp) | 230 | if (lport->ptp_rdata) |
203 | lport->tt.rport_logoff(lport->ptp_rp); | 231 | lport->tt.rport_logoff(lport->ptp_rdata); |
204 | lport->ptp_rp = lport->tt.rport_create(lport, remote_fid); | 232 | lport->ptp_rdata = lport->tt.rport_create(lport, remote_fid); |
205 | lport->ptp_rp->ids.port_name = remote_wwpn; | 233 | lport->ptp_rdata->ids.port_name = remote_wwpn; |
206 | lport->ptp_rp->ids.node_name = remote_wwnn; | 234 | lport->ptp_rdata->ids.node_name = remote_wwnn; |
207 | mutex_unlock(&lport->disc.disc_mutex); | 235 | mutex_unlock(&lport->disc.disc_mutex); |
208 | 236 | ||
209 | lport->tt.rport_login(lport->ptp_rp); | 237 | lport->tt.rport_login(lport->ptp_rdata); |
210 | 238 | ||
211 | fc_lport_enter_ready(lport); | 239 | fc_lport_enter_ready(lport); |
212 | } | 240 | } |
213 | 241 | ||
242 | /** | ||
243 | * fc_get_host_port_type() - Return the port type of the given Scsi_Host | ||
244 | * @shost: The SCSI host whose port type is to be determined | ||
245 | */ | ||
214 | void fc_get_host_port_type(struct Scsi_Host *shost) | 246 | void fc_get_host_port_type(struct Scsi_Host *shost) |
215 | { | 247 | { |
216 | /* TODO - currently just NPORT */ | 248 | /* TODO - currently just NPORT */ |
@@ -218,17 +250,33 @@ void fc_get_host_port_type(struct Scsi_Host *shost) | |||
218 | } | 250 | } |
219 | EXPORT_SYMBOL(fc_get_host_port_type); | 251 | EXPORT_SYMBOL(fc_get_host_port_type); |
220 | 252 | ||
253 | /** | ||
254 | * fc_get_host_port_state() - Return the port state of the given Scsi_Host | ||
255 | * @shost: The SCSI host whose port state is to be determined | ||
256 | */ | ||
221 | void fc_get_host_port_state(struct Scsi_Host *shost) | 257 | void fc_get_host_port_state(struct Scsi_Host *shost) |
222 | { | 258 | { |
223 | struct fc_lport *lp = shost_priv(shost); | 259 | struct fc_lport *lport = shost_priv(shost); |
224 | 260 | ||
225 | if (lp->link_up) | 261 | mutex_lock(&lport->lp_mutex); |
226 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | 262 | if (!lport->link_up) |
263 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | ||
227 | else | 264 | else |
228 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | 265 | switch (lport->state) { |
266 | case LPORT_ST_READY: | ||
267 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | ||
268 | break; | ||
269 | default: | ||
270 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | ||
271 | } | ||
272 | mutex_unlock(&lport->lp_mutex); | ||
229 | } | 273 | } |
230 | EXPORT_SYMBOL(fc_get_host_port_state); | 274 | EXPORT_SYMBOL(fc_get_host_port_state); |
231 | 275 | ||
276 | /** | ||
277 | * fc_get_host_speed() - Return the speed of the given Scsi_Host | ||
278 | * @shost: The SCSI host whose port speed is to be determined | ||
279 | */ | ||
232 | void fc_get_host_speed(struct Scsi_Host *shost) | 280 | void fc_get_host_speed(struct Scsi_Host *shost) |
233 | { | 281 | { |
234 | struct fc_lport *lport = shost_priv(shost); | 282 | struct fc_lport *lport = shost_priv(shost); |
@@ -237,24 +285,28 @@ void fc_get_host_speed(struct Scsi_Host *shost) | |||
237 | } | 285 | } |
238 | EXPORT_SYMBOL(fc_get_host_speed); | 286 | EXPORT_SYMBOL(fc_get_host_speed); |
239 | 287 | ||
288 | /** | ||
289 | * fc_get_host_stats() - Return the Scsi_Host's statistics | ||
290 | * @shost: The SCSI host whose statistics are to be returned | ||
291 | */ | ||
240 | struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) | 292 | struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) |
241 | { | 293 | { |
242 | struct fc_host_statistics *fcoe_stats; | 294 | struct fc_host_statistics *fcoe_stats; |
243 | struct fc_lport *lp = shost_priv(shost); | 295 | struct fc_lport *lport = shost_priv(shost); |
244 | struct timespec v0, v1; | 296 | struct timespec v0, v1; |
245 | unsigned int cpu; | 297 | unsigned int cpu; |
246 | 298 | ||
247 | fcoe_stats = &lp->host_stats; | 299 | fcoe_stats = &lport->host_stats; |
248 | memset(fcoe_stats, 0, sizeof(struct fc_host_statistics)); | 300 | memset(fcoe_stats, 0, sizeof(struct fc_host_statistics)); |
249 | 301 | ||
250 | jiffies_to_timespec(jiffies, &v0); | 302 | jiffies_to_timespec(jiffies, &v0); |
251 | jiffies_to_timespec(lp->boot_time, &v1); | 303 | jiffies_to_timespec(lport->boot_time, &v1); |
252 | fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); | 304 | fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); |
253 | 305 | ||
254 | for_each_possible_cpu(cpu) { | 306 | for_each_possible_cpu(cpu) { |
255 | struct fcoe_dev_stats *stats; | 307 | struct fcoe_dev_stats *stats; |
256 | 308 | ||
257 | stats = per_cpu_ptr(lp->dev_stats, cpu); | 309 | stats = per_cpu_ptr(lport->dev_stats, cpu); |
258 | 310 | ||
259 | fcoe_stats->tx_frames += stats->TxFrames; | 311 | fcoe_stats->tx_frames += stats->TxFrames; |
260 | fcoe_stats->tx_words += stats->TxWords; | 312 | fcoe_stats->tx_words += stats->TxWords; |
@@ -279,12 +331,15 @@ struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) | |||
279 | } | 331 | } |
280 | EXPORT_SYMBOL(fc_get_host_stats); | 332 | EXPORT_SYMBOL(fc_get_host_stats); |
281 | 333 | ||
282 | /* | 334 | /** |
283 | * Fill in FLOGI command for request. | 335 | * fc_lport_flogi_fill() - Fill in FLOGI command for request |
336 | * @lport: The local port the FLOGI is for | ||
337 | * @flogi: The FLOGI command | ||
338 | * @op: The opcode | ||
284 | */ | 339 | */ |
285 | static void | 340 | static void fc_lport_flogi_fill(struct fc_lport *lport, |
286 | fc_lport_flogi_fill(struct fc_lport *lport, struct fc_els_flogi *flogi, | 341 | struct fc_els_flogi *flogi, |
287 | unsigned int op) | 342 | unsigned int op) |
288 | { | 343 | { |
289 | struct fc_els_csp *sp; | 344 | struct fc_els_csp *sp; |
290 | struct fc_els_cssp *cp; | 345 | struct fc_els_cssp *cp; |
@@ -312,8 +367,10 @@ fc_lport_flogi_fill(struct fc_lport *lport, struct fc_els_flogi *flogi, | |||
312 | } | 367 | } |
313 | } | 368 | } |
314 | 369 | ||
315 | /* | 370 | /** |
316 | * Add a supported FC-4 type. | 371 | * fc_lport_add_fc4_type() - Add a supported FC-4 type to a local port |
372 | * @lport: The local port to add a new FC-4 type to | ||
373 | * @type: The new FC-4 type | ||
317 | */ | 374 | */ |
318 | static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type) | 375 | static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type) |
319 | { | 376 | { |
@@ -325,11 +382,11 @@ static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type) | |||
325 | 382 | ||
326 | /** | 383 | /** |
327 | * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report. | 384 | * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report. |
385 | * @sp: The sequence in the RLIR exchange | ||
386 | * @fp: The RLIR request frame | ||
328 | * @lport: Fibre Channel local port recieving the RLIR | 387 | * @lport: Fibre Channel local port recieving the RLIR |
329 | * @sp: current sequence in the RLIR exchange | ||
330 | * @fp: RLIR request frame | ||
331 | * | 388 | * |
332 | * Locking Note: The lport lock is exected to be held before calling | 389 | * Locking Note: The lport lock is expected to be held before calling |
333 | * this function. | 390 | * this function. |
334 | */ | 391 | */ |
335 | static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp, | 392 | static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp, |
@@ -344,11 +401,11 @@ static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp, | |||
344 | 401 | ||
345 | /** | 402 | /** |
346 | * fc_lport_recv_echo_req() - Handle received ECHO request | 403 | * fc_lport_recv_echo_req() - Handle received ECHO request |
347 | * @lport: Fibre Channel local port recieving the ECHO | 404 | * @sp: The sequence in the ECHO exchange |
348 | * @sp: current sequence in the ECHO exchange | 405 | * @fp: ECHO request frame |
349 | * @fp: ECHO request frame | 406 | * @lport: The local port recieving the ECHO |
350 | * | 407 | * |
351 | * Locking Note: The lport lock is exected to be held before calling | 408 | * Locking Note: The lport lock is expected to be held before calling |
352 | * this function. | 409 | * this function. |
353 | */ | 410 | */ |
354 | static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, | 411 | static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, |
@@ -361,7 +418,7 @@ static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, | |||
361 | void *dp; | 418 | void *dp; |
362 | u32 f_ctl; | 419 | u32 f_ctl; |
363 | 420 | ||
364 | FC_LPORT_DBG(lport, "Received RLIR request while in state %s\n", | 421 | FC_LPORT_DBG(lport, "Received ECHO request while in state %s\n", |
365 | fc_lport_state(lport)); | 422 | fc_lport_state(lport)); |
366 | 423 | ||
367 | len = fr_len(in_fp) - sizeof(struct fc_frame_header); | 424 | len = fr_len(in_fp) - sizeof(struct fc_frame_header); |
@@ -374,7 +431,7 @@ static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, | |||
374 | if (fp) { | 431 | if (fp) { |
375 | dp = fc_frame_payload_get(fp, len); | 432 | dp = fc_frame_payload_get(fp, len); |
376 | memcpy(dp, pp, len); | 433 | memcpy(dp, pp, len); |
377 | *((u32 *)dp) = htonl(ELS_LS_ACC << 24); | 434 | *((__be32 *)dp) = htonl(ELS_LS_ACC << 24); |
378 | sp = lport->tt.seq_start_next(sp); | 435 | sp = lport->tt.seq_start_next(sp); |
379 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; | 436 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; |
380 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, | 437 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
@@ -385,12 +442,12 @@ static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, | |||
385 | } | 442 | } |
386 | 443 | ||
387 | /** | 444 | /** |
388 | * fc_lport_recv_echo_req() - Handle received Request Node ID data request | 445 | * fc_lport_recv_rnid_req() - Handle received Request Node ID data request |
389 | * @lport: Fibre Channel local port recieving the RNID | 446 | * @sp: The sequence in the RNID exchange |
390 | * @sp: current sequence in the RNID exchange | 447 | * @fp: The RNID request frame |
391 | * @fp: RNID request frame | 448 | * @lport: The local port recieving the RNID |
392 | * | 449 | * |
393 | * Locking Note: The lport lock is exected to be held before calling | 450 | * Locking Note: The lport lock is expected to be held before calling |
394 | * this function. | 451 | * this function. |
395 | */ | 452 | */ |
396 | static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp, | 453 | static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp, |
@@ -453,9 +510,9 @@ static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp, | |||
453 | 510 | ||
454 | /** | 511 | /** |
455 | * fc_lport_recv_logo_req() - Handle received fabric LOGO request | 512 | * fc_lport_recv_logo_req() - Handle received fabric LOGO request |
456 | * @lport: Fibre Channel local port recieving the LOGO | 513 | * @sp: The sequence in the LOGO exchange |
457 | * @sp: current sequence in the LOGO exchange | 514 | * @fp: The LOGO request frame |
458 | * @fp: LOGO request frame | 515 | * @lport: The local port recieving the LOGO |
459 | * | 516 | * |
460 | * Locking Note: The lport lock is exected to be held before calling | 517 | * Locking Note: The lport lock is exected to be held before calling |
461 | * this function. | 518 | * this function. |
@@ -470,7 +527,7 @@ static void fc_lport_recv_logo_req(struct fc_seq *sp, struct fc_frame *fp, | |||
470 | 527 | ||
471 | /** | 528 | /** |
472 | * fc_fabric_login() - Start the lport state machine | 529 | * fc_fabric_login() - Start the lport state machine |
473 | * @lport: The lport that should log into the fabric | 530 | * @lport: The local port that should log into the fabric |
474 | * | 531 | * |
475 | * Locking Note: This function should not be called | 532 | * Locking Note: This function should not be called |
476 | * with the lport lock held. | 533 | * with the lport lock held. |
@@ -491,47 +548,69 @@ int fc_fabric_login(struct fc_lport *lport) | |||
491 | EXPORT_SYMBOL(fc_fabric_login); | 548 | EXPORT_SYMBOL(fc_fabric_login); |
492 | 549 | ||
493 | /** | 550 | /** |
494 | * fc_linkup() - Handler for transport linkup events | 551 | * __fc_linkup() - Handler for transport linkup events |
495 | * @lport: The lport whose link is up | 552 | * @lport: The lport whose link is up |
553 | * | ||
554 | * Locking: must be called with the lp_mutex held | ||
496 | */ | 555 | */ |
497 | void fc_linkup(struct fc_lport *lport) | 556 | void __fc_linkup(struct fc_lport *lport) |
498 | { | 557 | { |
499 | printk(KERN_INFO "libfc: Link up on port (%6x)\n", | ||
500 | fc_host_port_id(lport->host)); | ||
501 | |||
502 | mutex_lock(&lport->lp_mutex); | ||
503 | if (!lport->link_up) { | 558 | if (!lport->link_up) { |
504 | lport->link_up = 1; | 559 | lport->link_up = 1; |
505 | 560 | ||
506 | if (lport->state == LPORT_ST_RESET) | 561 | if (lport->state == LPORT_ST_RESET) |
507 | fc_lport_enter_flogi(lport); | 562 | fc_lport_enter_flogi(lport); |
508 | } | 563 | } |
564 | } | ||
565 | |||
566 | /** | ||
567 | * fc_linkup() - Handler for transport linkup events | ||
568 | * @lport: The local port whose link is up | ||
569 | */ | ||
570 | void fc_linkup(struct fc_lport *lport) | ||
571 | { | ||
572 | printk(KERN_INFO "host%d: libfc: Link up on port (%6x)\n", | ||
573 | lport->host->host_no, fc_host_port_id(lport->host)); | ||
574 | |||
575 | mutex_lock(&lport->lp_mutex); | ||
576 | __fc_linkup(lport); | ||
509 | mutex_unlock(&lport->lp_mutex); | 577 | mutex_unlock(&lport->lp_mutex); |
510 | } | 578 | } |
511 | EXPORT_SYMBOL(fc_linkup); | 579 | EXPORT_SYMBOL(fc_linkup); |
512 | 580 | ||
513 | /** | 581 | /** |
514 | * fc_linkdown() - Handler for transport linkdown events | 582 | * __fc_linkdown() - Handler for transport linkdown events |
515 | * @lport: The lport whose link is down | 583 | * @lport: The lport whose link is down |
584 | * | ||
585 | * Locking: must be called with the lp_mutex held | ||
516 | */ | 586 | */ |
517 | void fc_linkdown(struct fc_lport *lport) | 587 | void __fc_linkdown(struct fc_lport *lport) |
518 | { | 588 | { |
519 | mutex_lock(&lport->lp_mutex); | ||
520 | printk(KERN_INFO "libfc: Link down on port (%6x)\n", | ||
521 | fc_host_port_id(lport->host)); | ||
522 | |||
523 | if (lport->link_up) { | 589 | if (lport->link_up) { |
524 | lport->link_up = 0; | 590 | lport->link_up = 0; |
525 | fc_lport_enter_reset(lport); | 591 | fc_lport_enter_reset(lport); |
526 | lport->tt.fcp_cleanup(lport); | 592 | lport->tt.fcp_cleanup(lport); |
527 | } | 593 | } |
594 | } | ||
595 | |||
596 | /** | ||
597 | * fc_linkdown() - Handler for transport linkdown events | ||
598 | * @lport: The local port whose link is down | ||
599 | */ | ||
600 | void fc_linkdown(struct fc_lport *lport) | ||
601 | { | ||
602 | printk(KERN_INFO "host%d: libfc: Link down on port (%6x)\n", | ||
603 | lport->host->host_no, fc_host_port_id(lport->host)); | ||
604 | |||
605 | mutex_lock(&lport->lp_mutex); | ||
606 | __fc_linkdown(lport); | ||
528 | mutex_unlock(&lport->lp_mutex); | 607 | mutex_unlock(&lport->lp_mutex); |
529 | } | 608 | } |
530 | EXPORT_SYMBOL(fc_linkdown); | 609 | EXPORT_SYMBOL(fc_linkdown); |
531 | 610 | ||
532 | /** | 611 | /** |
533 | * fc_fabric_logoff() - Logout of the fabric | 612 | * fc_fabric_logoff() - Logout of the fabric |
534 | * @lport: fc_lport pointer to logoff the fabric | 613 | * @lport: The local port to logoff the fabric |
535 | * | 614 | * |
536 | * Return value: | 615 | * Return value: |
537 | * 0 for success, -1 for failure | 616 | * 0 for success, -1 for failure |
@@ -540,8 +619,8 @@ int fc_fabric_logoff(struct fc_lport *lport) | |||
540 | { | 619 | { |
541 | lport->tt.disc_stop_final(lport); | 620 | lport->tt.disc_stop_final(lport); |
542 | mutex_lock(&lport->lp_mutex); | 621 | mutex_lock(&lport->lp_mutex); |
543 | if (lport->dns_rp) | 622 | if (lport->dns_rdata) |
544 | lport->tt.rport_logoff(lport->dns_rp); | 623 | lport->tt.rport_logoff(lport->dns_rdata); |
545 | mutex_unlock(&lport->lp_mutex); | 624 | mutex_unlock(&lport->lp_mutex); |
546 | lport->tt.rport_flush_queue(); | 625 | lport->tt.rport_flush_queue(); |
547 | mutex_lock(&lport->lp_mutex); | 626 | mutex_lock(&lport->lp_mutex); |
@@ -553,11 +632,9 @@ int fc_fabric_logoff(struct fc_lport *lport) | |||
553 | EXPORT_SYMBOL(fc_fabric_logoff); | 632 | EXPORT_SYMBOL(fc_fabric_logoff); |
554 | 633 | ||
555 | /** | 634 | /** |
556 | * fc_lport_destroy() - unregister a fc_lport | 635 | * fc_lport_destroy() - Unregister a fc_lport |
557 | * @lport: fc_lport pointer to unregister | 636 | * @lport: The local port to unregister |
558 | * | 637 | * |
559 | * Return value: | ||
560 | * None | ||
561 | * Note: | 638 | * Note: |
562 | * exit routine for fc_lport instance | 639 | * exit routine for fc_lport instance |
563 | * clean-up all the allocated memory | 640 | * clean-up all the allocated memory |
@@ -580,13 +657,9 @@ int fc_lport_destroy(struct fc_lport *lport) | |||
580 | EXPORT_SYMBOL(fc_lport_destroy); | 657 | EXPORT_SYMBOL(fc_lport_destroy); |
581 | 658 | ||
582 | /** | 659 | /** |
583 | * fc_set_mfs() - sets up the mfs for the corresponding fc_lport | 660 | * fc_set_mfs() - Set the maximum frame size for a local port |
584 | * @lport: fc_lport pointer to unregister | 661 | * @lport: The local port to set the MFS for |
585 | * @mfs: the new mfs for fc_lport | 662 | * @mfs: The new MFS |
586 | * | ||
587 | * Set mfs for the given fc_lport to the new mfs. | ||
588 | * | ||
589 | * Return: 0 for success | ||
590 | */ | 663 | */ |
591 | int fc_set_mfs(struct fc_lport *lport, u32 mfs) | 664 | int fc_set_mfs(struct fc_lport *lport, u32 mfs) |
592 | { | 665 | { |
@@ -617,7 +690,7 @@ EXPORT_SYMBOL(fc_set_mfs); | |||
617 | 690 | ||
618 | /** | 691 | /** |
619 | * fc_lport_disc_callback() - Callback for discovery events | 692 | * fc_lport_disc_callback() - Callback for discovery events |
620 | * @lport: FC local port | 693 | * @lport: The local port receiving the event |
621 | * @event: The discovery event | 694 | * @event: The discovery event |
622 | */ | 695 | */ |
623 | void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event) | 696 | void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event) |
@@ -627,8 +700,9 @@ void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event) | |||
627 | FC_LPORT_DBG(lport, "Discovery succeeded\n"); | 700 | FC_LPORT_DBG(lport, "Discovery succeeded\n"); |
628 | break; | 701 | break; |
629 | case DISC_EV_FAILED: | 702 | case DISC_EV_FAILED: |
630 | printk(KERN_ERR "libfc: Discovery failed for port (%6x)\n", | 703 | printk(KERN_ERR "host%d: libfc: " |
631 | fc_host_port_id(lport->host)); | 704 | "Discovery failed for port (%6x)\n", |
705 | lport->host->host_no, fc_host_port_id(lport->host)); | ||
632 | mutex_lock(&lport->lp_mutex); | 706 | mutex_lock(&lport->lp_mutex); |
633 | fc_lport_enter_reset(lport); | 707 | fc_lport_enter_reset(lport); |
634 | mutex_unlock(&lport->lp_mutex); | 708 | mutex_unlock(&lport->lp_mutex); |
@@ -641,7 +715,7 @@ void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event) | |||
641 | 715 | ||
642 | /** | 716 | /** |
643 | * fc_rport_enter_ready() - Enter the ready state and start discovery | 717 | * fc_rport_enter_ready() - Enter the ready state and start discovery |
644 | * @lport: Fibre Channel local port that is ready | 718 | * @lport: The local port that is ready |
645 | * | 719 | * |
646 | * Locking Note: The lport lock is expected to be held before calling | 720 | * Locking Note: The lport lock is expected to be held before calling |
647 | * this routine. | 721 | * this routine. |
@@ -652,22 +726,46 @@ static void fc_lport_enter_ready(struct fc_lport *lport) | |||
652 | fc_lport_state(lport)); | 726 | fc_lport_state(lport)); |
653 | 727 | ||
654 | fc_lport_state_enter(lport, LPORT_ST_READY); | 728 | fc_lport_state_enter(lport, LPORT_ST_READY); |
729 | if (lport->vport) | ||
730 | fc_vport_set_state(lport->vport, FC_VPORT_ACTIVE); | ||
731 | fc_vports_linkchange(lport); | ||
655 | 732 | ||
656 | if (!lport->ptp_rp) | 733 | if (!lport->ptp_rdata) |
657 | lport->tt.disc_start(fc_lport_disc_callback, lport); | 734 | lport->tt.disc_start(fc_lport_disc_callback, lport); |
658 | } | 735 | } |
659 | 736 | ||
660 | /** | 737 | /** |
738 | * fc_lport_set_port_id() - set the local port Port ID | ||
739 | * @lport: The local port which will have its Port ID set. | ||
740 | * @port_id: The new port ID. | ||
741 | * @fp: The frame containing the incoming request, or NULL. | ||
742 | * | ||
743 | * Locking Note: The lport lock is expected to be held before calling | ||
744 | * this function. | ||
745 | */ | ||
746 | static void fc_lport_set_port_id(struct fc_lport *lport, u32 port_id, | ||
747 | struct fc_frame *fp) | ||
748 | { | ||
749 | if (port_id) | ||
750 | printk(KERN_INFO "host%d: Assigned Port ID %6x\n", | ||
751 | lport->host->host_no, port_id); | ||
752 | |||
753 | fc_host_port_id(lport->host) = port_id; | ||
754 | if (lport->tt.lport_set_port_id) | ||
755 | lport->tt.lport_set_port_id(lport, port_id, fp); | ||
756 | } | ||
757 | |||
758 | /** | ||
661 | * fc_lport_recv_flogi_req() - Receive a FLOGI request | 759 | * fc_lport_recv_flogi_req() - Receive a FLOGI request |
662 | * @sp_in: The sequence the FLOGI is on | 760 | * @sp_in: The sequence the FLOGI is on |
663 | * @rx_fp: The frame the FLOGI is in | 761 | * @rx_fp: The FLOGI frame |
664 | * @lport: The lport that recieved the request | 762 | * @lport: The local port that recieved the request |
665 | * | 763 | * |
666 | * A received FLOGI request indicates a point-to-point connection. | 764 | * A received FLOGI request indicates a point-to-point connection. |
667 | * Accept it with the common service parameters indicating our N port. | 765 | * Accept it with the common service parameters indicating our N port. |
668 | * Set up to do a PLOGI if we have the higher-number WWPN. | 766 | * Set up to do a PLOGI if we have the higher-number WWPN. |
669 | * | 767 | * |
670 | * Locking Note: The lport lock is exected to be held before calling | 768 | * Locking Note: The lport lock is expected to be held before calling |
671 | * this function. | 769 | * this function. |
672 | */ | 770 | */ |
673 | static void fc_lport_recv_flogi_req(struct fc_seq *sp_in, | 771 | static void fc_lport_recv_flogi_req(struct fc_seq *sp_in, |
@@ -695,8 +793,9 @@ static void fc_lport_recv_flogi_req(struct fc_seq *sp_in, | |||
695 | goto out; | 793 | goto out; |
696 | remote_wwpn = get_unaligned_be64(&flp->fl_wwpn); | 794 | remote_wwpn = get_unaligned_be64(&flp->fl_wwpn); |
697 | if (remote_wwpn == lport->wwpn) { | 795 | if (remote_wwpn == lport->wwpn) { |
698 | printk(KERN_WARNING "libfc: Received FLOGI from port " | 796 | printk(KERN_WARNING "host%d: libfc: Received FLOGI from port " |
699 | "with same WWPN %llx\n", remote_wwpn); | 797 | "with same WWPN %llx\n", |
798 | lport->host->host_no, remote_wwpn); | ||
700 | goto out; | 799 | goto out; |
701 | } | 800 | } |
702 | FC_LPORT_DBG(lport, "FLOGI from port WWPN %llx\n", remote_wwpn); | 801 | FC_LPORT_DBG(lport, "FLOGI from port WWPN %llx\n", remote_wwpn); |
@@ -715,7 +814,7 @@ static void fc_lport_recv_flogi_req(struct fc_seq *sp_in, | |||
715 | remote_fid = FC_LOCAL_PTP_FID_HI; | 814 | remote_fid = FC_LOCAL_PTP_FID_HI; |
716 | } | 815 | } |
717 | 816 | ||
718 | fc_host_port_id(lport->host) = local_fid; | 817 | fc_lport_set_port_id(lport, local_fid, rx_fp); |
719 | 818 | ||
720 | fp = fc_frame_alloc(lport, sizeof(*flp)); | 819 | fp = fc_frame_alloc(lport, sizeof(*flp)); |
721 | if (fp) { | 820 | if (fp) { |
@@ -747,9 +846,9 @@ out: | |||
747 | 846 | ||
748 | /** | 847 | /** |
749 | * fc_lport_recv_req() - The generic lport request handler | 848 | * fc_lport_recv_req() - The generic lport request handler |
750 | * @lport: The lport that received the request | 849 | * @lport: The local port that received the request |
751 | * @sp: The sequence the request is on | 850 | * @sp: The sequence the request is on |
752 | * @fp: The frame the request is in | 851 | * @fp: The request frame |
753 | * | 852 | * |
754 | * This function will see if the lport handles the request or | 853 | * This function will see if the lport handles the request or |
755 | * if an rport should handle the request. | 854 | * if an rport should handle the request. |
@@ -817,8 +916,8 @@ static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp, | |||
817 | } | 916 | } |
818 | 917 | ||
819 | /** | 918 | /** |
820 | * fc_lport_reset() - Reset an lport | 919 | * fc_lport_reset() - Reset a local port |
821 | * @lport: The lport which should be reset | 920 | * @lport: The local port which should be reset |
822 | * | 921 | * |
823 | * Locking Note: This functions should not be called with the | 922 | * Locking Note: This functions should not be called with the |
824 | * lport lock held. | 923 | * lport lock held. |
@@ -834,29 +933,31 @@ int fc_lport_reset(struct fc_lport *lport) | |||
834 | EXPORT_SYMBOL(fc_lport_reset); | 933 | EXPORT_SYMBOL(fc_lport_reset); |
835 | 934 | ||
836 | /** | 935 | /** |
837 | * fc_lport_reset_locked() - Reset the local port | 936 | * fc_lport_reset_locked() - Reset the local port w/ the lport lock held |
838 | * @lport: Fibre Channel local port to be reset | 937 | * @lport: The local port to be reset |
839 | * | 938 | * |
840 | * Locking Note: The lport lock is expected to be held before calling | 939 | * Locking Note: The lport lock is expected to be held before calling |
841 | * this routine. | 940 | * this routine. |
842 | */ | 941 | */ |
843 | static void fc_lport_reset_locked(struct fc_lport *lport) | 942 | static void fc_lport_reset_locked(struct fc_lport *lport) |
844 | { | 943 | { |
845 | if (lport->dns_rp) | 944 | if (lport->dns_rdata) |
846 | lport->tt.rport_logoff(lport->dns_rp); | 945 | lport->tt.rport_logoff(lport->dns_rdata); |
847 | 946 | ||
848 | lport->ptp_rp = NULL; | 947 | lport->ptp_rdata = NULL; |
849 | 948 | ||
850 | lport->tt.disc_stop(lport); | 949 | lport->tt.disc_stop(lport); |
851 | 950 | ||
852 | lport->tt.exch_mgr_reset(lport, 0, 0); | 951 | lport->tt.exch_mgr_reset(lport, 0, 0); |
853 | fc_host_fabric_name(lport->host) = 0; | 952 | fc_host_fabric_name(lport->host) = 0; |
854 | fc_host_port_id(lport->host) = 0; | 953 | |
954 | if (fc_host_port_id(lport->host)) | ||
955 | fc_lport_set_port_id(lport, 0, NULL); | ||
855 | } | 956 | } |
856 | 957 | ||
857 | /** | 958 | /** |
858 | * fc_lport_enter_reset() - Reset the local port | 959 | * fc_lport_enter_reset() - Reset the local port |
859 | * @lport: Fibre Channel local port to be reset | 960 | * @lport: The local port to be reset |
860 | * | 961 | * |
861 | * Locking Note: The lport lock is expected to be held before calling | 962 | * Locking Note: The lport lock is expected to be held before calling |
862 | * this routine. | 963 | * this routine. |
@@ -866,15 +967,22 @@ static void fc_lport_enter_reset(struct fc_lport *lport) | |||
866 | FC_LPORT_DBG(lport, "Entered RESET state from %s state\n", | 967 | FC_LPORT_DBG(lport, "Entered RESET state from %s state\n", |
867 | fc_lport_state(lport)); | 968 | fc_lport_state(lport)); |
868 | 969 | ||
970 | if (lport->vport) { | ||
971 | if (lport->link_up) | ||
972 | fc_vport_set_state(lport->vport, FC_VPORT_INITIALIZING); | ||
973 | else | ||
974 | fc_vport_set_state(lport->vport, FC_VPORT_LINKDOWN); | ||
975 | } | ||
869 | fc_lport_state_enter(lport, LPORT_ST_RESET); | 976 | fc_lport_state_enter(lport, LPORT_ST_RESET); |
977 | fc_vports_linkchange(lport); | ||
870 | fc_lport_reset_locked(lport); | 978 | fc_lport_reset_locked(lport); |
871 | if (lport->link_up) | 979 | if (lport->link_up) |
872 | fc_lport_enter_flogi(lport); | 980 | fc_lport_enter_flogi(lport); |
873 | } | 981 | } |
874 | 982 | ||
875 | /** | 983 | /** |
876 | * fc_lport_enter_disabled() - disable the local port | 984 | * fc_lport_enter_disabled() - Disable the local port |
877 | * @lport: Fibre Channel local port to be reset | 985 | * @lport: The local port to be reset |
878 | * | 986 | * |
879 | * Locking Note: The lport lock is expected to be held before calling | 987 | * Locking Note: The lport lock is expected to be held before calling |
880 | * this routine. | 988 | * this routine. |
@@ -885,13 +993,14 @@ static void fc_lport_enter_disabled(struct fc_lport *lport) | |||
885 | fc_lport_state(lport)); | 993 | fc_lport_state(lport)); |
886 | 994 | ||
887 | fc_lport_state_enter(lport, LPORT_ST_DISABLED); | 995 | fc_lport_state_enter(lport, LPORT_ST_DISABLED); |
996 | fc_vports_linkchange(lport); | ||
888 | fc_lport_reset_locked(lport); | 997 | fc_lport_reset_locked(lport); |
889 | } | 998 | } |
890 | 999 | ||
891 | /** | 1000 | /** |
892 | * fc_lport_error() - Handler for any errors | 1001 | * fc_lport_error() - Handler for any errors |
893 | * @lport: The fc_lport object | 1002 | * @lport: The local port that the error was on |
894 | * @fp: The frame pointer | 1003 | * @fp: The error code encoded in a frame pointer |
895 | * | 1004 | * |
896 | * If the error was caused by a resource allocation failure | 1005 | * If the error was caused by a resource allocation failure |
897 | * then wait for half a second and retry, otherwise retry | 1006 | * then wait for half a second and retry, otherwise retry |
@@ -922,8 +1031,11 @@ static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp) | |||
922 | case LPORT_ST_DISABLED: | 1031 | case LPORT_ST_DISABLED: |
923 | case LPORT_ST_READY: | 1032 | case LPORT_ST_READY: |
924 | case LPORT_ST_RESET: | 1033 | case LPORT_ST_RESET: |
925 | case LPORT_ST_RPN_ID: | 1034 | case LPORT_ST_RNN_ID: |
1035 | case LPORT_ST_RSNN_NN: | ||
1036 | case LPORT_ST_RSPN_ID: | ||
926 | case LPORT_ST_RFT_ID: | 1037 | case LPORT_ST_RFT_ID: |
1038 | case LPORT_ST_RFF_ID: | ||
927 | case LPORT_ST_SCR: | 1039 | case LPORT_ST_SCR: |
928 | case LPORT_ST_DNS: | 1040 | case LPORT_ST_DNS: |
929 | case LPORT_ST_FLOGI: | 1041 | case LPORT_ST_FLOGI: |
@@ -936,33 +1048,33 @@ static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp) | |||
936 | } | 1048 | } |
937 | 1049 | ||
938 | /** | 1050 | /** |
939 | * fc_lport_rft_id_resp() - Handle response to Register Fibre | 1051 | * fc_lport_ns_resp() - Handle response to a name server |
940 | * Channel Types by ID (RPN_ID) request | 1052 | * registration exchange |
941 | * @sp: current sequence in RPN_ID exchange | 1053 | * @sp: current sequence in exchange |
942 | * @fp: response frame | 1054 | * @fp: response frame |
943 | * @lp_arg: Fibre Channel host port instance | 1055 | * @lp_arg: Fibre Channel host port instance |
944 | * | 1056 | * |
945 | * Locking Note: This function will be called without the lport lock | 1057 | * Locking Note: This function will be called without the lport lock |
946 | * held, but it will lock, call an _enter_* function or fc_lport_error | 1058 | * held, but it will lock, call an _enter_* function or fc_lport_error() |
947 | * and then unlock the lport. | 1059 | * and then unlock the lport. |
948 | */ | 1060 | */ |
949 | static void fc_lport_rft_id_resp(struct fc_seq *sp, struct fc_frame *fp, | 1061 | static void fc_lport_ns_resp(struct fc_seq *sp, struct fc_frame *fp, |
950 | void *lp_arg) | 1062 | void *lp_arg) |
951 | { | 1063 | { |
952 | struct fc_lport *lport = lp_arg; | 1064 | struct fc_lport *lport = lp_arg; |
953 | struct fc_frame_header *fh; | 1065 | struct fc_frame_header *fh; |
954 | struct fc_ct_hdr *ct; | 1066 | struct fc_ct_hdr *ct; |
955 | 1067 | ||
956 | FC_LPORT_DBG(lport, "Received a RFT_ID %s\n", fc_els_resp_type(fp)); | 1068 | FC_LPORT_DBG(lport, "Received a ns %s\n", fc_els_resp_type(fp)); |
957 | 1069 | ||
958 | if (fp == ERR_PTR(-FC_EX_CLOSED)) | 1070 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
959 | return; | 1071 | return; |
960 | 1072 | ||
961 | mutex_lock(&lport->lp_mutex); | 1073 | mutex_lock(&lport->lp_mutex); |
962 | 1074 | ||
963 | if (lport->state != LPORT_ST_RFT_ID) { | 1075 | if (lport->state < LPORT_ST_RNN_ID || lport->state > LPORT_ST_RFF_ID) { |
964 | FC_LPORT_DBG(lport, "Received a RFT_ID response, but in state " | 1076 | FC_LPORT_DBG(lport, "Received a name server response, " |
965 | "%s\n", fc_lport_state(lport)); | 1077 | "but in state %s\n", fc_lport_state(lport)); |
966 | if (IS_ERR(fp)) | 1078 | if (IS_ERR(fp)) |
967 | goto err; | 1079 | goto err; |
968 | goto out; | 1080 | goto out; |
@@ -980,63 +1092,28 @@ static void fc_lport_rft_id_resp(struct fc_seq *sp, struct fc_frame *fp, | |||
980 | ct->ct_fs_type == FC_FST_DIR && | 1092 | ct->ct_fs_type == FC_FST_DIR && |
981 | ct->ct_fs_subtype == FC_NS_SUBTYPE && | 1093 | ct->ct_fs_subtype == FC_NS_SUBTYPE && |
982 | ntohs(ct->ct_cmd) == FC_FS_ACC) | 1094 | ntohs(ct->ct_cmd) == FC_FS_ACC) |
983 | fc_lport_enter_scr(lport); | 1095 | switch (lport->state) { |
984 | else | 1096 | case LPORT_ST_RNN_ID: |
985 | fc_lport_error(lport, fp); | 1097 | fc_lport_enter_ns(lport, LPORT_ST_RSNN_NN); |
986 | out: | 1098 | break; |
987 | fc_frame_free(fp); | 1099 | case LPORT_ST_RSNN_NN: |
988 | err: | 1100 | fc_lport_enter_ns(lport, LPORT_ST_RSPN_ID); |
989 | mutex_unlock(&lport->lp_mutex); | 1101 | break; |
990 | } | 1102 | case LPORT_ST_RSPN_ID: |
991 | 1103 | fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); | |
992 | /** | 1104 | break; |
993 | * fc_lport_rpn_id_resp() - Handle response to Register Port | 1105 | case LPORT_ST_RFT_ID: |
994 | * Name by ID (RPN_ID) request | 1106 | fc_lport_enter_ns(lport, LPORT_ST_RFF_ID); |
995 | * @sp: current sequence in RPN_ID exchange | 1107 | break; |
996 | * @fp: response frame | 1108 | case LPORT_ST_RFF_ID: |
997 | * @lp_arg: Fibre Channel host port instance | 1109 | fc_lport_enter_scr(lport); |
998 | * | 1110 | break; |
999 | * Locking Note: This function will be called without the lport lock | 1111 | default: |
1000 | * held, but it will lock, call an _enter_* function or fc_lport_error | 1112 | /* should have already been caught by state checks */ |
1001 | * and then unlock the lport. | 1113 | break; |
1002 | */ | 1114 | } |
1003 | static void fc_lport_rpn_id_resp(struct fc_seq *sp, struct fc_frame *fp, | ||
1004 | void *lp_arg) | ||
1005 | { | ||
1006 | struct fc_lport *lport = lp_arg; | ||
1007 | struct fc_frame_header *fh; | ||
1008 | struct fc_ct_hdr *ct; | ||
1009 | |||
1010 | FC_LPORT_DBG(lport, "Received a RPN_ID %s\n", fc_els_resp_type(fp)); | ||
1011 | |||
1012 | if (fp == ERR_PTR(-FC_EX_CLOSED)) | ||
1013 | return; | ||
1014 | |||
1015 | mutex_lock(&lport->lp_mutex); | ||
1016 | |||
1017 | if (lport->state != LPORT_ST_RPN_ID) { | ||
1018 | FC_LPORT_DBG(lport, "Received a RPN_ID response, but in state " | ||
1019 | "%s\n", fc_lport_state(lport)); | ||
1020 | if (IS_ERR(fp)) | ||
1021 | goto err; | ||
1022 | goto out; | ||
1023 | } | ||
1024 | |||
1025 | if (IS_ERR(fp)) { | ||
1026 | fc_lport_error(lport, fp); | ||
1027 | goto err; | ||
1028 | } | ||
1029 | |||
1030 | fh = fc_frame_header_get(fp); | ||
1031 | ct = fc_frame_payload_get(fp, sizeof(*ct)); | ||
1032 | if (fh && ct && fh->fh_type == FC_TYPE_CT && | ||
1033 | ct->ct_fs_type == FC_FST_DIR && | ||
1034 | ct->ct_fs_subtype == FC_NS_SUBTYPE && | ||
1035 | ntohs(ct->ct_cmd) == FC_FS_ACC) | ||
1036 | fc_lport_enter_rft_id(lport); | ||
1037 | else | 1115 | else |
1038 | fc_lport_error(lport, fp); | 1116 | fc_lport_error(lport, fp); |
1039 | |||
1040 | out: | 1117 | out: |
1041 | fc_frame_free(fp); | 1118 | fc_frame_free(fp); |
1042 | err: | 1119 | err: |
@@ -1045,8 +1122,8 @@ err: | |||
1045 | 1122 | ||
1046 | /** | 1123 | /** |
1047 | * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request | 1124 | * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request |
1048 | * @sp: current sequence in SCR exchange | 1125 | * @sp: current sequence in SCR exchange |
1049 | * @fp: response frame | 1126 | * @fp: response frame |
1050 | * @lp_arg: Fibre Channel lport port instance that sent the registration request | 1127 | * @lp_arg: Fibre Channel lport port instance that sent the registration request |
1051 | * | 1128 | * |
1052 | * Locking Note: This function will be called without the lport lock | 1129 | * Locking Note: This function will be called without the lport lock |
@@ -1092,8 +1169,8 @@ err: | |||
1092 | } | 1169 | } |
1093 | 1170 | ||
1094 | /** | 1171 | /** |
1095 | * fc_lport_enter_scr() - Send a State Change Register (SCR) request | 1172 | * fc_lport_enter_scr() - Send a SCR (State Change Register) request |
1096 | * @lport: Fibre Channel local port to register for state changes | 1173 | * @lport: The local port to register for state changes |
1097 | * | 1174 | * |
1098 | * Locking Note: The lport lock is expected to be held before calling | 1175 | * Locking Note: The lport lock is expected to be held before calling |
1099 | * this routine. | 1176 | * this routine. |
@@ -1114,78 +1191,74 @@ static void fc_lport_enter_scr(struct fc_lport *lport) | |||
1114 | } | 1191 | } |
1115 | 1192 | ||
1116 | if (!lport->tt.elsct_send(lport, FC_FID_FCTRL, fp, ELS_SCR, | 1193 | if (!lport->tt.elsct_send(lport, FC_FID_FCTRL, fp, ELS_SCR, |
1117 | fc_lport_scr_resp, lport, lport->e_d_tov)) | 1194 | fc_lport_scr_resp, lport, |
1118 | fc_lport_error(lport, fp); | 1195 | 2 * lport->r_a_tov)) |
1196 | fc_lport_error(lport, NULL); | ||
1119 | } | 1197 | } |
1120 | 1198 | ||
1121 | /** | 1199 | /** |
1122 | * fc_lport_enter_rft_id() - Register FC4-types with the name server | 1200 | * fc_lport_enter_ns() - register some object with the name server |
1123 | * @lport: Fibre Channel local port to register | 1201 | * @lport: Fibre Channel local port to register |
1124 | * | 1202 | * |
1125 | * Locking Note: The lport lock is expected to be held before calling | 1203 | * Locking Note: The lport lock is expected to be held before calling |
1126 | * this routine. | 1204 | * this routine. |
1127 | */ | 1205 | */ |
1128 | static void fc_lport_enter_rft_id(struct fc_lport *lport) | 1206 | static void fc_lport_enter_ns(struct fc_lport *lport, enum fc_lport_state state) |
1129 | { | 1207 | { |
1130 | struct fc_frame *fp; | 1208 | struct fc_frame *fp; |
1131 | struct fc_ns_fts *lps; | 1209 | enum fc_ns_req cmd; |
1132 | int i; | 1210 | int size = sizeof(struct fc_ct_hdr); |
1211 | size_t len; | ||
1133 | 1212 | ||
1134 | FC_LPORT_DBG(lport, "Entered RFT_ID state from %s state\n", | 1213 | FC_LPORT_DBG(lport, "Entered %s state from %s state\n", |
1214 | fc_lport_state_names[state], | ||
1135 | fc_lport_state(lport)); | 1215 | fc_lport_state(lport)); |
1136 | 1216 | ||
1137 | fc_lport_state_enter(lport, LPORT_ST_RFT_ID); | 1217 | fc_lport_state_enter(lport, state); |
1138 | |||
1139 | lps = &lport->fcts; | ||
1140 | i = sizeof(lps->ff_type_map) / sizeof(lps->ff_type_map[0]); | ||
1141 | while (--i >= 0) | ||
1142 | if (ntohl(lps->ff_type_map[i]) != 0) | ||
1143 | break; | ||
1144 | if (i < 0) { | ||
1145 | /* nothing to register, move on to SCR */ | ||
1146 | fc_lport_enter_scr(lport); | ||
1147 | return; | ||
1148 | } | ||
1149 | 1218 | ||
1150 | fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + | 1219 | switch (state) { |
1151 | sizeof(struct fc_ns_rft)); | 1220 | case LPORT_ST_RNN_ID: |
1152 | if (!fp) { | 1221 | cmd = FC_NS_RNN_ID; |
1153 | fc_lport_error(lport, fp); | 1222 | size += sizeof(struct fc_ns_rn_id); |
1223 | break; | ||
1224 | case LPORT_ST_RSNN_NN: | ||
1225 | len = strnlen(fc_host_symbolic_name(lport->host), 255); | ||
1226 | /* if there is no symbolic name, skip to RFT_ID */ | ||
1227 | if (!len) | ||
1228 | return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); | ||
1229 | cmd = FC_NS_RSNN_NN; | ||
1230 | size += sizeof(struct fc_ns_rsnn) + len; | ||
1231 | break; | ||
1232 | case LPORT_ST_RSPN_ID: | ||
1233 | len = strnlen(fc_host_symbolic_name(lport->host), 255); | ||
1234 | /* if there is no symbolic name, skip to RFT_ID */ | ||
1235 | if (!len) | ||
1236 | return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); | ||
1237 | cmd = FC_NS_RSPN_ID; | ||
1238 | size += sizeof(struct fc_ns_rspn) + len; | ||
1239 | break; | ||
1240 | case LPORT_ST_RFT_ID: | ||
1241 | cmd = FC_NS_RFT_ID; | ||
1242 | size += sizeof(struct fc_ns_rft); | ||
1243 | break; | ||
1244 | case LPORT_ST_RFF_ID: | ||
1245 | cmd = FC_NS_RFF_ID; | ||
1246 | size += sizeof(struct fc_ns_rff_id); | ||
1247 | break; | ||
1248 | default: | ||
1249 | fc_lport_error(lport, NULL); | ||
1154 | return; | 1250 | return; |
1155 | } | 1251 | } |
1156 | 1252 | ||
1157 | if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RFT_ID, | 1253 | fp = fc_frame_alloc(lport, size); |
1158 | fc_lport_rft_id_resp, | ||
1159 | lport, lport->e_d_tov)) | ||
1160 | fc_lport_error(lport, fp); | ||
1161 | } | ||
1162 | |||
1163 | /** | ||
1164 | * fc_rport_enter_rft_id() - Register port name with the name server | ||
1165 | * @lport: Fibre Channel local port to register | ||
1166 | * | ||
1167 | * Locking Note: The lport lock is expected to be held before calling | ||
1168 | * this routine. | ||
1169 | */ | ||
1170 | static void fc_lport_enter_rpn_id(struct fc_lport *lport) | ||
1171 | { | ||
1172 | struct fc_frame *fp; | ||
1173 | |||
1174 | FC_LPORT_DBG(lport, "Entered RPN_ID state from %s state\n", | ||
1175 | fc_lport_state(lport)); | ||
1176 | |||
1177 | fc_lport_state_enter(lport, LPORT_ST_RPN_ID); | ||
1178 | |||
1179 | fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + | ||
1180 | sizeof(struct fc_ns_rn_id)); | ||
1181 | if (!fp) { | 1254 | if (!fp) { |
1182 | fc_lport_error(lport, fp); | 1255 | fc_lport_error(lport, fp); |
1183 | return; | 1256 | return; |
1184 | } | 1257 | } |
1185 | 1258 | ||
1186 | if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RPN_ID, | 1259 | if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, cmd, |
1187 | fc_lport_rpn_id_resp, | 1260 | fc_lport_ns_resp, |
1188 | lport, lport->e_d_tov)) | 1261 | lport, 3 * lport->r_a_tov)) |
1189 | fc_lport_error(lport, fp); | 1262 | fc_lport_error(lport, fp); |
1190 | } | 1263 | } |
1191 | 1264 | ||
@@ -1194,8 +1267,8 @@ static struct fc_rport_operations fc_lport_rport_ops = { | |||
1194 | }; | 1267 | }; |
1195 | 1268 | ||
1196 | /** | 1269 | /** |
1197 | * fc_rport_enter_dns() - Create a rport to the name server | 1270 | * fc_rport_enter_dns() - Create a fc_rport for the name server |
1198 | * @lport: Fibre Channel local port requesting a rport for the name server | 1271 | * @lport: The local port requesting a remote port for the name server |
1199 | * | 1272 | * |
1200 | * Locking Note: The lport lock is expected to be held before calling | 1273 | * Locking Note: The lport lock is expected to be held before calling |
1201 | * this routine. | 1274 | * this routine. |
@@ -1224,8 +1297,8 @@ err: | |||
1224 | } | 1297 | } |
1225 | 1298 | ||
1226 | /** | 1299 | /** |
1227 | * fc_lport_timeout() - Handler for the retry_work timer. | 1300 | * fc_lport_timeout() - Handler for the retry_work timer |
1228 | * @work: The work struct of the fc_lport | 1301 | * @work: The work struct of the local port |
1229 | */ | 1302 | */ |
1230 | static void fc_lport_timeout(struct work_struct *work) | 1303 | static void fc_lport_timeout(struct work_struct *work) |
1231 | { | 1304 | { |
@@ -1237,21 +1310,25 @@ static void fc_lport_timeout(struct work_struct *work) | |||
1237 | 1310 | ||
1238 | switch (lport->state) { | 1311 | switch (lport->state) { |
1239 | case LPORT_ST_DISABLED: | 1312 | case LPORT_ST_DISABLED: |
1313 | WARN_ON(1); | ||
1314 | break; | ||
1240 | case LPORT_ST_READY: | 1315 | case LPORT_ST_READY: |
1241 | case LPORT_ST_RESET: | ||
1242 | WARN_ON(1); | 1316 | WARN_ON(1); |
1243 | break; | 1317 | break; |
1318 | case LPORT_ST_RESET: | ||
1319 | break; | ||
1244 | case LPORT_ST_FLOGI: | 1320 | case LPORT_ST_FLOGI: |
1245 | fc_lport_enter_flogi(lport); | 1321 | fc_lport_enter_flogi(lport); |
1246 | break; | 1322 | break; |
1247 | case LPORT_ST_DNS: | 1323 | case LPORT_ST_DNS: |
1248 | fc_lport_enter_dns(lport); | 1324 | fc_lport_enter_dns(lport); |
1249 | break; | 1325 | break; |
1250 | case LPORT_ST_RPN_ID: | 1326 | case LPORT_ST_RNN_ID: |
1251 | fc_lport_enter_rpn_id(lport); | 1327 | case LPORT_ST_RSNN_NN: |
1252 | break; | 1328 | case LPORT_ST_RSPN_ID: |
1253 | case LPORT_ST_RFT_ID: | 1329 | case LPORT_ST_RFT_ID: |
1254 | fc_lport_enter_rft_id(lport); | 1330 | case LPORT_ST_RFF_ID: |
1331 | fc_lport_enter_ns(lport, lport->state); | ||
1255 | break; | 1332 | break; |
1256 | case LPORT_ST_SCR: | 1333 | case LPORT_ST_SCR: |
1257 | fc_lport_enter_scr(lport); | 1334 | fc_lport_enter_scr(lport); |
@@ -1266,16 +1343,16 @@ static void fc_lport_timeout(struct work_struct *work) | |||
1266 | 1343 | ||
1267 | /** | 1344 | /** |
1268 | * fc_lport_logo_resp() - Handle response to LOGO request | 1345 | * fc_lport_logo_resp() - Handle response to LOGO request |
1269 | * @sp: current sequence in LOGO exchange | 1346 | * @sp: The sequence that the LOGO was on |
1270 | * @fp: response frame | 1347 | * @fp: The LOGO frame |
1271 | * @lp_arg: Fibre Channel lport port instance that sent the LOGO request | 1348 | * @lp_arg: The lport port that received the LOGO request |
1272 | * | 1349 | * |
1273 | * Locking Note: This function will be called without the lport lock | 1350 | * Locking Note: This function will be called without the lport lock |
1274 | * held, but it will lock, call an _enter_* function or fc_lport_error | 1351 | * held, but it will lock, call an _enter_* function or fc_lport_error() |
1275 | * and then unlock the lport. | 1352 | * and then unlock the lport. |
1276 | */ | 1353 | */ |
1277 | static void fc_lport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, | 1354 | void fc_lport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, |
1278 | void *lp_arg) | 1355 | void *lp_arg) |
1279 | { | 1356 | { |
1280 | struct fc_lport *lport = lp_arg; | 1357 | struct fc_lport *lport = lp_arg; |
1281 | u8 op; | 1358 | u8 op; |
@@ -1311,10 +1388,11 @@ out: | |||
1311 | err: | 1388 | err: |
1312 | mutex_unlock(&lport->lp_mutex); | 1389 | mutex_unlock(&lport->lp_mutex); |
1313 | } | 1390 | } |
1391 | EXPORT_SYMBOL(fc_lport_logo_resp); | ||
1314 | 1392 | ||
1315 | /** | 1393 | /** |
1316 | * fc_rport_enter_logo() - Logout of the fabric | 1394 | * fc_rport_enter_logo() - Logout of the fabric |
1317 | * @lport: Fibre Channel local port to be logged out | 1395 | * @lport: The local port to be logged out |
1318 | * | 1396 | * |
1319 | * Locking Note: The lport lock is expected to be held before calling | 1397 | * Locking Note: The lport lock is expected to be held before calling |
1320 | * this routine. | 1398 | * this routine. |
@@ -1328,6 +1406,7 @@ static void fc_lport_enter_logo(struct fc_lport *lport) | |||
1328 | fc_lport_state(lport)); | 1406 | fc_lport_state(lport)); |
1329 | 1407 | ||
1330 | fc_lport_state_enter(lport, LPORT_ST_LOGO); | 1408 | fc_lport_state_enter(lport, LPORT_ST_LOGO); |
1409 | fc_vports_linkchange(lport); | ||
1331 | 1410 | ||
1332 | fp = fc_frame_alloc(lport, sizeof(*logo)); | 1411 | fp = fc_frame_alloc(lport, sizeof(*logo)); |
1333 | if (!fp) { | 1412 | if (!fp) { |
@@ -1336,22 +1415,23 @@ static void fc_lport_enter_logo(struct fc_lport *lport) | |||
1336 | } | 1415 | } |
1337 | 1416 | ||
1338 | if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_LOGO, | 1417 | if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_LOGO, |
1339 | fc_lport_logo_resp, lport, lport->e_d_tov)) | 1418 | fc_lport_logo_resp, lport, |
1340 | fc_lport_error(lport, fp); | 1419 | 2 * lport->r_a_tov)) |
1420 | fc_lport_error(lport, NULL); | ||
1341 | } | 1421 | } |
1342 | 1422 | ||
1343 | /** | 1423 | /** |
1344 | * fc_lport_flogi_resp() - Handle response to FLOGI request | 1424 | * fc_lport_flogi_resp() - Handle response to FLOGI request |
1345 | * @sp: current sequence in FLOGI exchange | 1425 | * @sp: The sequence that the FLOGI was on |
1346 | * @fp: response frame | 1426 | * @fp: The FLOGI response frame |
1347 | * @lp_arg: Fibre Channel lport port instance that sent the FLOGI request | 1427 | * @lp_arg: The lport port that received the FLOGI response |
1348 | * | 1428 | * |
1349 | * Locking Note: This function will be called without the lport lock | 1429 | * Locking Note: This function will be called without the lport lock |
1350 | * held, but it will lock, call an _enter_* function or fc_lport_error | 1430 | * held, but it will lock, call an _enter_* function or fc_lport_error() |
1351 | * and then unlock the lport. | 1431 | * and then unlock the lport. |
1352 | */ | 1432 | */ |
1353 | static void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, | 1433 | void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, |
1354 | void *lp_arg) | 1434 | void *lp_arg) |
1355 | { | 1435 | { |
1356 | struct fc_lport *lport = lp_arg; | 1436 | struct fc_lport *lport = lp_arg; |
1357 | struct fc_frame_header *fh; | 1437 | struct fc_frame_header *fh; |
@@ -1385,11 +1465,6 @@ static void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, | |||
1385 | fh = fc_frame_header_get(fp); | 1465 | fh = fc_frame_header_get(fp); |
1386 | did = ntoh24(fh->fh_d_id); | 1466 | did = ntoh24(fh->fh_d_id); |
1387 | if (fc_frame_payload_op(fp) == ELS_LS_ACC && did != 0) { | 1467 | if (fc_frame_payload_op(fp) == ELS_LS_ACC && did != 0) { |
1388 | |||
1389 | printk(KERN_INFO "libfc: Assigned FID (%6x) in FLOGI response\n", | ||
1390 | did); | ||
1391 | fc_host_port_id(lport->host) = did; | ||
1392 | |||
1393 | flp = fc_frame_payload_get(fp, sizeof(*flp)); | 1468 | flp = fc_frame_payload_get(fp, sizeof(*flp)); |
1394 | if (flp) { | 1469 | if (flp) { |
1395 | mfs = ntohs(flp->fl_csp.sp_bb_data) & | 1470 | mfs = ntohs(flp->fl_csp.sp_bb_data) & |
@@ -1402,12 +1477,18 @@ static void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, | |||
1402 | e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov); | 1477 | e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov); |
1403 | if (csp_flags & FC_SP_FT_EDTR) | 1478 | if (csp_flags & FC_SP_FT_EDTR) |
1404 | e_d_tov /= 1000000; | 1479 | e_d_tov /= 1000000; |
1480 | |||
1481 | lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC); | ||
1482 | |||
1405 | if ((csp_flags & FC_SP_FT_FPORT) == 0) { | 1483 | if ((csp_flags & FC_SP_FT_FPORT) == 0) { |
1406 | if (e_d_tov > lport->e_d_tov) | 1484 | if (e_d_tov > lport->e_d_tov) |
1407 | lport->e_d_tov = e_d_tov; | 1485 | lport->e_d_tov = e_d_tov; |
1408 | lport->r_a_tov = 2 * e_d_tov; | 1486 | lport->r_a_tov = 2 * e_d_tov; |
1409 | printk(KERN_INFO "libfc: Port (%6x) entered " | 1487 | fc_lport_set_port_id(lport, did, fp); |
1410 | "point to point mode\n", did); | 1488 | printk(KERN_INFO "host%d: libfc: " |
1489 | "Port (%6x) entered " | ||
1490 | "point-to-point mode\n", | ||
1491 | lport->host->host_no, did); | ||
1411 | fc_lport_ptp_setup(lport, ntoh24(fh->fh_s_id), | 1492 | fc_lport_ptp_setup(lport, ntoh24(fh->fh_s_id), |
1412 | get_unaligned_be64( | 1493 | get_unaligned_be64( |
1413 | &flp->fl_wwpn), | 1494 | &flp->fl_wwpn), |
@@ -1418,6 +1499,7 @@ static void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, | |||
1418 | lport->r_a_tov = r_a_tov; | 1499 | lport->r_a_tov = r_a_tov; |
1419 | fc_host_fabric_name(lport->host) = | 1500 | fc_host_fabric_name(lport->host) = |
1420 | get_unaligned_be64(&flp->fl_wwnn); | 1501 | get_unaligned_be64(&flp->fl_wwnn); |
1502 | fc_lport_set_port_id(lport, did, fp); | ||
1421 | fc_lport_enter_dns(lport); | 1503 | fc_lport_enter_dns(lport); |
1422 | } | 1504 | } |
1423 | } | 1505 | } |
@@ -1430,6 +1512,7 @@ out: | |||
1430 | err: | 1512 | err: |
1431 | mutex_unlock(&lport->lp_mutex); | 1513 | mutex_unlock(&lport->lp_mutex); |
1432 | } | 1514 | } |
1515 | EXPORT_SYMBOL(fc_lport_flogi_resp); | ||
1433 | 1516 | ||
1434 | /** | 1517 | /** |
1435 | * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager | 1518 | * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager |
@@ -1451,12 +1534,18 @@ void fc_lport_enter_flogi(struct fc_lport *lport) | |||
1451 | if (!fp) | 1534 | if (!fp) |
1452 | return fc_lport_error(lport, fp); | 1535 | return fc_lport_error(lport, fp); |
1453 | 1536 | ||
1454 | if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_FLOGI, | 1537 | if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, |
1455 | fc_lport_flogi_resp, lport, lport->e_d_tov)) | 1538 | lport->vport ? ELS_FDISC : ELS_FLOGI, |
1456 | fc_lport_error(lport, fp); | 1539 | fc_lport_flogi_resp, lport, |
1540 | lport->vport ? 2 * lport->r_a_tov : | ||
1541 | lport->e_d_tov)) | ||
1542 | fc_lport_error(lport, NULL); | ||
1457 | } | 1543 | } |
1458 | 1544 | ||
1459 | /* Configure a fc_lport */ | 1545 | /** |
1546 | * fc_lport_config() - Configure a fc_lport | ||
1547 | * @lport: The local port to be configured | ||
1548 | */ | ||
1460 | int fc_lport_config(struct fc_lport *lport) | 1549 | int fc_lport_config(struct fc_lport *lport) |
1461 | { | 1550 | { |
1462 | INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout); | 1551 | INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout); |
@@ -1471,6 +1560,10 @@ int fc_lport_config(struct fc_lport *lport) | |||
1471 | } | 1560 | } |
1472 | EXPORT_SYMBOL(fc_lport_config); | 1561 | EXPORT_SYMBOL(fc_lport_config); |
1473 | 1562 | ||
1563 | /** | ||
1564 | * fc_lport_init() - Initialize the lport layer for a local port | ||
1565 | * @lport: The local port to initialize the exchange layer for | ||
1566 | */ | ||
1474 | int fc_lport_init(struct fc_lport *lport) | 1567 | int fc_lport_init(struct fc_lport *lport) |
1475 | { | 1568 | { |
1476 | if (!lport->tt.lport_recv) | 1569 | if (!lport->tt.lport_recv) |
@@ -1500,7 +1593,253 @@ int fc_lport_init(struct fc_lport *lport) | |||
1500 | if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT) | 1593 | if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT) |
1501 | fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT; | 1594 | fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT; |
1502 | 1595 | ||
1503 | INIT_LIST_HEAD(&lport->ema_list); | ||
1504 | return 0; | 1596 | return 0; |
1505 | } | 1597 | } |
1506 | EXPORT_SYMBOL(fc_lport_init); | 1598 | EXPORT_SYMBOL(fc_lport_init); |
1599 | |||
1600 | /** | ||
1601 | * fc_lport_bsg_resp() - The common response handler for FC Passthrough requests | ||
1602 | * @sp: The sequence for the FC Passthrough response | ||
1603 | * @fp: The response frame | ||
1604 | * @info_arg: The BSG info that the response is for | ||
1605 | */ | ||
1606 | static void fc_lport_bsg_resp(struct fc_seq *sp, struct fc_frame *fp, | ||
1607 | void *info_arg) | ||
1608 | { | ||
1609 | struct fc_bsg_info *info = info_arg; | ||
1610 | struct fc_bsg_job *job = info->job; | ||
1611 | struct fc_lport *lport = info->lport; | ||
1612 | struct fc_frame_header *fh; | ||
1613 | size_t len; | ||
1614 | void *buf; | ||
1615 | |||
1616 | if (IS_ERR(fp)) { | ||
1617 | job->reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ? | ||
1618 | -ECONNABORTED : -ETIMEDOUT; | ||
1619 | job->reply_len = sizeof(uint32_t); | ||
1620 | job->state_flags |= FC_RQST_STATE_DONE; | ||
1621 | job->job_done(job); | ||
1622 | kfree(info); | ||
1623 | return; | ||
1624 | } | ||
1625 | |||
1626 | mutex_lock(&lport->lp_mutex); | ||
1627 | fh = fc_frame_header_get(fp); | ||
1628 | len = fr_len(fp) - sizeof(*fh); | ||
1629 | buf = fc_frame_payload_get(fp, 0); | ||
1630 | |||
1631 | if (fr_sof(fp) == FC_SOF_I3 && !ntohs(fh->fh_seq_cnt)) { | ||
1632 | /* Get the response code from the first frame payload */ | ||
1633 | unsigned short cmd = (info->rsp_code == FC_FS_ACC) ? | ||
1634 | ntohs(((struct fc_ct_hdr *)buf)->ct_cmd) : | ||
1635 | (unsigned short)fc_frame_payload_op(fp); | ||
1636 | |||
1637 | /* Save the reply status of the job */ | ||
1638 | job->reply->reply_data.ctels_reply.status = | ||
1639 | (cmd == info->rsp_code) ? | ||
1640 | FC_CTELS_STATUS_OK : FC_CTELS_STATUS_REJECT; | ||
1641 | } | ||
1642 | |||
1643 | job->reply->reply_payload_rcv_len += | ||
1644 | fc_copy_buffer_to_sglist(buf, len, info->sg, &info->nents, | ||
1645 | &info->offset, KM_BIO_SRC_IRQ, NULL); | ||
1646 | |||
1647 | if (fr_eof(fp) == FC_EOF_T && | ||
1648 | (ntoh24(fh->fh_f_ctl) & (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) == | ||
1649 | (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) { | ||
1650 | if (job->reply->reply_payload_rcv_len > | ||
1651 | job->reply_payload.payload_len) | ||
1652 | job->reply->reply_payload_rcv_len = | ||
1653 | job->reply_payload.payload_len; | ||
1654 | job->reply->result = 0; | ||
1655 | job->state_flags |= FC_RQST_STATE_DONE; | ||
1656 | job->job_done(job); | ||
1657 | kfree(info); | ||
1658 | } | ||
1659 | fc_frame_free(fp); | ||
1660 | mutex_unlock(&lport->lp_mutex); | ||
1661 | } | ||
1662 | |||
1663 | /** | ||
1664 | * fc_lport_els_request() - Send ELS passthrough request | ||
1665 | * @job: The BSG Passthrough job | ||
1666 | * @lport: The local port sending the request | ||
1667 | * @did: The destination port id | ||
1668 | * | ||
1669 | * Locking Note: The lport lock is expected to be held before calling | ||
1670 | * this routine. | ||
1671 | */ | ||
1672 | static int fc_lport_els_request(struct fc_bsg_job *job, | ||
1673 | struct fc_lport *lport, | ||
1674 | u32 did, u32 tov) | ||
1675 | { | ||
1676 | struct fc_bsg_info *info; | ||
1677 | struct fc_frame *fp; | ||
1678 | struct fc_frame_header *fh; | ||
1679 | char *pp; | ||
1680 | int len; | ||
1681 | |||
1682 | fp = fc_frame_alloc(lport, job->request_payload.payload_len); | ||
1683 | if (!fp) | ||
1684 | return -ENOMEM; | ||
1685 | |||
1686 | len = job->request_payload.payload_len; | ||
1687 | pp = fc_frame_payload_get(fp, len); | ||
1688 | |||
1689 | sg_copy_to_buffer(job->request_payload.sg_list, | ||
1690 | job->request_payload.sg_cnt, | ||
1691 | pp, len); | ||
1692 | |||
1693 | fh = fc_frame_header_get(fp); | ||
1694 | fh->fh_r_ctl = FC_RCTL_ELS_REQ; | ||
1695 | hton24(fh->fh_d_id, did); | ||
1696 | hton24(fh->fh_s_id, fc_host_port_id(lport->host)); | ||
1697 | fh->fh_type = FC_TYPE_ELS; | ||
1698 | hton24(fh->fh_f_ctl, FC_FC_FIRST_SEQ | | ||
1699 | FC_FC_END_SEQ | FC_FC_SEQ_INIT); | ||
1700 | fh->fh_cs_ctl = 0; | ||
1701 | fh->fh_df_ctl = 0; | ||
1702 | fh->fh_parm_offset = 0; | ||
1703 | |||
1704 | info = kzalloc(sizeof(struct fc_bsg_info), GFP_KERNEL); | ||
1705 | if (!info) { | ||
1706 | fc_frame_free(fp); | ||
1707 | return -ENOMEM; | ||
1708 | } | ||
1709 | |||
1710 | info->job = job; | ||
1711 | info->lport = lport; | ||
1712 | info->rsp_code = ELS_LS_ACC; | ||
1713 | info->nents = job->reply_payload.sg_cnt; | ||
1714 | info->sg = job->reply_payload.sg_list; | ||
1715 | |||
1716 | if (!lport->tt.exch_seq_send(lport, fp, fc_lport_bsg_resp, | ||
1717 | NULL, info, tov)) | ||
1718 | return -ECOMM; | ||
1719 | return 0; | ||
1720 | } | ||
1721 | |||
1722 | /** | ||
1723 | * fc_lport_ct_request() - Send CT Passthrough request | ||
1724 | * @job: The BSG Passthrough job | ||
1725 | * @lport: The local port sending the request | ||
1726 | * @did: The destination FC-ID | ||
1727 | * @tov: The timeout period to wait for the response | ||
1728 | * | ||
1729 | * Locking Note: The lport lock is expected to be held before calling | ||
1730 | * this routine. | ||
1731 | */ | ||
1732 | static int fc_lport_ct_request(struct fc_bsg_job *job, | ||
1733 | struct fc_lport *lport, u32 did, u32 tov) | ||
1734 | { | ||
1735 | struct fc_bsg_info *info; | ||
1736 | struct fc_frame *fp; | ||
1737 | struct fc_frame_header *fh; | ||
1738 | struct fc_ct_req *ct; | ||
1739 | size_t len; | ||
1740 | |||
1741 | fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + | ||
1742 | job->request_payload.payload_len); | ||
1743 | if (!fp) | ||
1744 | return -ENOMEM; | ||
1745 | |||
1746 | len = job->request_payload.payload_len; | ||
1747 | ct = fc_frame_payload_get(fp, len); | ||
1748 | |||
1749 | sg_copy_to_buffer(job->request_payload.sg_list, | ||
1750 | job->request_payload.sg_cnt, | ||
1751 | ct, len); | ||
1752 | |||
1753 | fh = fc_frame_header_get(fp); | ||
1754 | fh->fh_r_ctl = FC_RCTL_DD_UNSOL_CTL; | ||
1755 | hton24(fh->fh_d_id, did); | ||
1756 | hton24(fh->fh_s_id, fc_host_port_id(lport->host)); | ||
1757 | fh->fh_type = FC_TYPE_CT; | ||
1758 | hton24(fh->fh_f_ctl, FC_FC_FIRST_SEQ | | ||
1759 | FC_FC_END_SEQ | FC_FC_SEQ_INIT); | ||
1760 | fh->fh_cs_ctl = 0; | ||
1761 | fh->fh_df_ctl = 0; | ||
1762 | fh->fh_parm_offset = 0; | ||
1763 | |||
1764 | info = kzalloc(sizeof(struct fc_bsg_info), GFP_KERNEL); | ||
1765 | if (!info) { | ||
1766 | fc_frame_free(fp); | ||
1767 | return -ENOMEM; | ||
1768 | } | ||
1769 | |||
1770 | info->job = job; | ||
1771 | info->lport = lport; | ||
1772 | info->rsp_code = FC_FS_ACC; | ||
1773 | info->nents = job->reply_payload.sg_cnt; | ||
1774 | info->sg = job->reply_payload.sg_list; | ||
1775 | |||
1776 | if (!lport->tt.exch_seq_send(lport, fp, fc_lport_bsg_resp, | ||
1777 | NULL, info, tov)) | ||
1778 | return -ECOMM; | ||
1779 | return 0; | ||
1780 | } | ||
1781 | |||
1782 | /** | ||
1783 | * fc_lport_bsg_request() - The common entry point for sending | ||
1784 | * FC Passthrough requests | ||
1785 | * @job: The BSG passthrough job | ||
1786 | */ | ||
1787 | int fc_lport_bsg_request(struct fc_bsg_job *job) | ||
1788 | { | ||
1789 | struct request *rsp = job->req->next_rq; | ||
1790 | struct Scsi_Host *shost = job->shost; | ||
1791 | struct fc_lport *lport = shost_priv(shost); | ||
1792 | struct fc_rport *rport; | ||
1793 | struct fc_rport_priv *rdata; | ||
1794 | int rc = -EINVAL; | ||
1795 | u32 did; | ||
1796 | |||
1797 | job->reply->reply_payload_rcv_len = 0; | ||
1798 | rsp->resid_len = job->reply_payload.payload_len; | ||
1799 | |||
1800 | mutex_lock(&lport->lp_mutex); | ||
1801 | |||
1802 | switch (job->request->msgcode) { | ||
1803 | case FC_BSG_RPT_ELS: | ||
1804 | rport = job->rport; | ||
1805 | if (!rport) | ||
1806 | break; | ||
1807 | |||
1808 | rdata = rport->dd_data; | ||
1809 | rc = fc_lport_els_request(job, lport, rport->port_id, | ||
1810 | rdata->e_d_tov); | ||
1811 | break; | ||
1812 | |||
1813 | case FC_BSG_RPT_CT: | ||
1814 | rport = job->rport; | ||
1815 | if (!rport) | ||
1816 | break; | ||
1817 | |||
1818 | rdata = rport->dd_data; | ||
1819 | rc = fc_lport_ct_request(job, lport, rport->port_id, | ||
1820 | rdata->e_d_tov); | ||
1821 | break; | ||
1822 | |||
1823 | case FC_BSG_HST_CT: | ||
1824 | did = ntoh24(job->request->rqst_data.h_ct.port_id); | ||
1825 | if (did == FC_FID_DIR_SERV) | ||
1826 | rdata = lport->dns_rdata; | ||
1827 | else | ||
1828 | rdata = lport->tt.rport_lookup(lport, did); | ||
1829 | |||
1830 | if (!rdata) | ||
1831 | break; | ||
1832 | |||
1833 | rc = fc_lport_ct_request(job, lport, did, rdata->e_d_tov); | ||
1834 | break; | ||
1835 | |||
1836 | case FC_BSG_HST_ELS_NOLOGIN: | ||
1837 | did = ntoh24(job->request->rqst_data.h_els.port_id); | ||
1838 | rc = fc_lport_els_request(job, lport, did, lport->e_d_tov); | ||
1839 | break; | ||
1840 | } | ||
1841 | |||
1842 | mutex_unlock(&lport->lp_mutex); | ||
1843 | return rc; | ||
1844 | } | ||
1845 | EXPORT_SYMBOL(fc_lport_bsg_request); | ||
diff --git a/drivers/scsi/libfc/fc_npiv.c b/drivers/scsi/libfc/fc_npiv.c new file mode 100644 index 000000000000..c68f6c7341c2 --- /dev/null +++ b/drivers/scsi/libfc/fc_npiv.c | |||
@@ -0,0 +1,161 @@ | |||
1 | /* | ||
2 | * Copyright(c) 2009 Intel Corporation. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License along with | ||
14 | * this program; if not, write to the Free Software Foundation, Inc., | ||
15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
16 | * | ||
17 | * Maintained at www.Open-FCoE.org | ||
18 | */ | ||
19 | |||
20 | /* | ||
21 | * NPIV VN_Port helper functions for libfc | ||
22 | */ | ||
23 | |||
24 | #include <scsi/libfc.h> | ||
25 | |||
26 | /** | ||
27 | * fc_vport_create() - Create a new NPIV vport instance | ||
28 | * @vport: fc_vport structure from scsi_transport_fc | ||
29 | * @privsize: driver private data size to allocate along with the Scsi_Host | ||
30 | */ | ||
31 | |||
32 | struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize) | ||
33 | { | ||
34 | struct Scsi_Host *shost = vport_to_shost(vport); | ||
35 | struct fc_lport *n_port = shost_priv(shost); | ||
36 | struct fc_lport *vn_port; | ||
37 | |||
38 | vn_port = libfc_host_alloc(shost->hostt, privsize); | ||
39 | if (!vn_port) | ||
40 | goto err_out; | ||
41 | if (fc_exch_mgr_list_clone(n_port, vn_port)) | ||
42 | goto err_put; | ||
43 | |||
44 | vn_port->vport = vport; | ||
45 | vport->dd_data = vn_port; | ||
46 | |||
47 | mutex_lock(&n_port->lp_mutex); | ||
48 | list_add_tail(&vn_port->list, &n_port->vports); | ||
49 | mutex_unlock(&n_port->lp_mutex); | ||
50 | |||
51 | return vn_port; | ||
52 | |||
53 | err_put: | ||
54 | scsi_host_put(vn_port->host); | ||
55 | err_out: | ||
56 | return NULL; | ||
57 | } | ||
58 | EXPORT_SYMBOL(libfc_vport_create); | ||
59 | |||
60 | /** | ||
61 | * fc_vport_id_lookup() - find NPIV lport that matches a given fabric ID | ||
62 | * @n_port: Top level N_Port which may have multiple NPIV VN_Ports | ||
63 | * @port_id: Fabric ID to find a match for | ||
64 | * | ||
65 | * Returns: matching lport pointer or NULL if there is no match | ||
66 | */ | ||
67 | struct fc_lport *fc_vport_id_lookup(struct fc_lport *n_port, u32 port_id) | ||
68 | { | ||
69 | struct fc_lport *lport = NULL; | ||
70 | struct fc_lport *vn_port; | ||
71 | |||
72 | if (fc_host_port_id(n_port->host) == port_id) | ||
73 | return n_port; | ||
74 | |||
75 | mutex_lock(&n_port->lp_mutex); | ||
76 | list_for_each_entry(vn_port, &n_port->vports, list) { | ||
77 | if (fc_host_port_id(vn_port->host) == port_id) { | ||
78 | lport = vn_port; | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | mutex_unlock(&n_port->lp_mutex); | ||
83 | |||
84 | return lport; | ||
85 | } | ||
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/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c index 03ea6748e7ee..35ca0e72df46 100644 --- a/drivers/scsi/libfc/fc_rport.c +++ b/drivers/scsi/libfc/fc_rport.c | |||
@@ -55,6 +55,8 @@ | |||
55 | #include <scsi/libfc.h> | 55 | #include <scsi/libfc.h> |
56 | #include <scsi/fc_encode.h> | 56 | #include <scsi/fc_encode.h> |
57 | 57 | ||
58 | #include "fc_libfc.h" | ||
59 | |||
58 | struct workqueue_struct *rport_event_queue; | 60 | struct workqueue_struct *rport_event_queue; |
59 | 61 | ||
60 | static void fc_rport_enter_plogi(struct fc_rport_priv *); | 62 | static void fc_rport_enter_plogi(struct fc_rport_priv *); |
@@ -86,12 +88,13 @@ static const char *fc_rport_state_names[] = { | |||
86 | [RPORT_ST_LOGO] = "LOGO", | 88 | [RPORT_ST_LOGO] = "LOGO", |
87 | [RPORT_ST_ADISC] = "ADISC", | 89 | [RPORT_ST_ADISC] = "ADISC", |
88 | [RPORT_ST_DELETE] = "Delete", | 90 | [RPORT_ST_DELETE] = "Delete", |
91 | [RPORT_ST_RESTART] = "Restart", | ||
89 | }; | 92 | }; |
90 | 93 | ||
91 | /** | 94 | /** |
92 | * fc_rport_lookup() - lookup a remote port by port_id | 95 | * fc_rport_lookup() - Lookup a remote port by port_id |
93 | * @lport: Fibre Channel host port instance | 96 | * @lport: The local port to lookup the remote port on |
94 | * @port_id: remote port port_id to match | 97 | * @port_id: The remote port ID to look up |
95 | */ | 98 | */ |
96 | static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport, | 99 | static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport, |
97 | u32 port_id) | 100 | u32 port_id) |
@@ -99,16 +102,17 @@ static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport, | |||
99 | struct fc_rport_priv *rdata; | 102 | struct fc_rport_priv *rdata; |
100 | 103 | ||
101 | list_for_each_entry(rdata, &lport->disc.rports, peers) | 104 | list_for_each_entry(rdata, &lport->disc.rports, peers) |
102 | if (rdata->ids.port_id == port_id && | 105 | if (rdata->ids.port_id == port_id) |
103 | rdata->rp_state != RPORT_ST_DELETE) | ||
104 | return rdata; | 106 | return rdata; |
105 | return NULL; | 107 | return NULL; |
106 | } | 108 | } |
107 | 109 | ||
108 | /** | 110 | /** |
109 | * fc_rport_create() - Create a new remote port | 111 | * fc_rport_create() - Create a new remote port |
110 | * @lport: The local port that the new remote port is for | 112 | * @lport: The local port this remote port will be associated with |
111 | * @port_id: The port ID for the new remote port | 113 | * @ids: The identifiers for the new remote port |
114 | * | ||
115 | * The remote port will start in the INIT state. | ||
112 | * | 116 | * |
113 | * Locking note: must be called with the disc_mutex held. | 117 | * Locking note: must be called with the disc_mutex held. |
114 | */ | 118 | */ |
@@ -147,8 +151,8 @@ static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, | |||
147 | } | 151 | } |
148 | 152 | ||
149 | /** | 153 | /** |
150 | * fc_rport_destroy() - free a remote port after last reference is released. | 154 | * fc_rport_destroy() - Free a remote port after last reference is released |
151 | * @kref: pointer to kref inside struct fc_rport_priv | 155 | * @kref: The remote port's kref |
152 | */ | 156 | */ |
153 | static void fc_rport_destroy(struct kref *kref) | 157 | static void fc_rport_destroy(struct kref *kref) |
154 | { | 158 | { |
@@ -159,8 +163,8 @@ static void fc_rport_destroy(struct kref *kref) | |||
159 | } | 163 | } |
160 | 164 | ||
161 | /** | 165 | /** |
162 | * fc_rport_state() - return a string for the state the rport is in | 166 | * fc_rport_state() - Return a string identifying the remote port's state |
163 | * @rdata: remote port private data | 167 | * @rdata: The remote port |
164 | */ | 168 | */ |
165 | static const char *fc_rport_state(struct fc_rport_priv *rdata) | 169 | static const char *fc_rport_state(struct fc_rport_priv *rdata) |
166 | { | 170 | { |
@@ -173,9 +177,9 @@ static const char *fc_rport_state(struct fc_rport_priv *rdata) | |||
173 | } | 177 | } |
174 | 178 | ||
175 | /** | 179 | /** |
176 | * fc_set_rport_loss_tmo() - Set the remote port loss timeout in seconds. | 180 | * fc_set_rport_loss_tmo() - Set the remote port loss timeout |
177 | * @rport: Pointer to Fibre Channel remote port structure | 181 | * @rport: The remote port that gets a new timeout value |
178 | * @timeout: timeout in seconds | 182 | * @timeout: The new timeout value (in seconds) |
179 | */ | 183 | */ |
180 | void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) | 184 | void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) |
181 | { | 185 | { |
@@ -187,9 +191,11 @@ void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) | |||
187 | EXPORT_SYMBOL(fc_set_rport_loss_tmo); | 191 | EXPORT_SYMBOL(fc_set_rport_loss_tmo); |
188 | 192 | ||
189 | /** | 193 | /** |
190 | * fc_plogi_get_maxframe() - Get max payload from the common service parameters | 194 | * fc_plogi_get_maxframe() - Get the maximum payload from the common service |
191 | * @flp: FLOGI payload structure | 195 | * parameters in a FLOGI frame |
192 | * @maxval: upper limit, may be less than what is in the service parameters | 196 | * @flp: The FLOGI payload |
197 | * @maxval: The maximum frame size upper limit; this may be less than what | ||
198 | * is in the service parameters | ||
193 | */ | 199 | */ |
194 | static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp, | 200 | static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp, |
195 | unsigned int maxval) | 201 | unsigned int maxval) |
@@ -210,9 +216,9 @@ static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp, | |||
210 | } | 216 | } |
211 | 217 | ||
212 | /** | 218 | /** |
213 | * fc_rport_state_enter() - Change the rport's state | 219 | * fc_rport_state_enter() - Change the state of a remote port |
214 | * @rdata: The rport whose state should change | 220 | * @rdata: The remote port whose state should change |
215 | * @new: The new state of the rport | 221 | * @new: The new state |
216 | * | 222 | * |
217 | * Locking Note: Called with the rport lock held | 223 | * Locking Note: Called with the rport lock held |
218 | */ | 224 | */ |
@@ -224,17 +230,22 @@ static void fc_rport_state_enter(struct fc_rport_priv *rdata, | |||
224 | rdata->rp_state = new; | 230 | rdata->rp_state = new; |
225 | } | 231 | } |
226 | 232 | ||
233 | /** | ||
234 | * fc_rport_work() - Handler for remote port events in the rport_event_queue | ||
235 | * @work: Handle to the remote port being dequeued | ||
236 | */ | ||
227 | static void fc_rport_work(struct work_struct *work) | 237 | static void fc_rport_work(struct work_struct *work) |
228 | { | 238 | { |
229 | u32 port_id; | 239 | u32 port_id; |
230 | struct fc_rport_priv *rdata = | 240 | struct fc_rport_priv *rdata = |
231 | container_of(work, struct fc_rport_priv, event_work); | 241 | container_of(work, struct fc_rport_priv, event_work); |
232 | struct fc_rport_libfc_priv *rp; | 242 | struct fc_rport_libfc_priv *rpriv; |
233 | enum fc_rport_event event; | 243 | enum fc_rport_event event; |
234 | struct fc_lport *lport = rdata->local_port; | 244 | struct fc_lport *lport = rdata->local_port; |
235 | struct fc_rport_operations *rport_ops; | 245 | struct fc_rport_operations *rport_ops; |
236 | struct fc_rport_identifiers ids; | 246 | struct fc_rport_identifiers ids; |
237 | struct fc_rport *rport; | 247 | struct fc_rport *rport; |
248 | int restart = 0; | ||
238 | 249 | ||
239 | mutex_lock(&rdata->rp_mutex); | 250 | mutex_lock(&rdata->rp_mutex); |
240 | event = rdata->event; | 251 | event = rdata->event; |
@@ -265,12 +276,12 @@ static void fc_rport_work(struct work_struct *work) | |||
265 | rport->maxframe_size = rdata->maxframe_size; | 276 | rport->maxframe_size = rdata->maxframe_size; |
266 | rport->supported_classes = rdata->supported_classes; | 277 | rport->supported_classes = rdata->supported_classes; |
267 | 278 | ||
268 | rp = rport->dd_data; | 279 | rpriv = rport->dd_data; |
269 | rp->local_port = lport; | 280 | rpriv->local_port = lport; |
270 | rp->rp_state = rdata->rp_state; | 281 | rpriv->rp_state = rdata->rp_state; |
271 | rp->flags = rdata->flags; | 282 | rpriv->flags = rdata->flags; |
272 | rp->e_d_tov = rdata->e_d_tov; | 283 | rpriv->e_d_tov = rdata->e_d_tov; |
273 | rp->r_a_tov = rdata->r_a_tov; | 284 | rpriv->r_a_tov = rdata->r_a_tov; |
274 | mutex_unlock(&rdata->rp_mutex); | 285 | mutex_unlock(&rdata->rp_mutex); |
275 | 286 | ||
276 | if (rport_ops && rport_ops->event_callback) { | 287 | if (rport_ops && rport_ops->event_callback) { |
@@ -287,8 +298,19 @@ static void fc_rport_work(struct work_struct *work) | |||
287 | mutex_unlock(&rdata->rp_mutex); | 298 | mutex_unlock(&rdata->rp_mutex); |
288 | 299 | ||
289 | if (port_id != FC_FID_DIR_SERV) { | 300 | if (port_id != FC_FID_DIR_SERV) { |
301 | /* | ||
302 | * We must drop rp_mutex before taking disc_mutex. | ||
303 | * Re-evaluate state to allow for restart. | ||
304 | * A transition to RESTART state must only happen | ||
305 | * while disc_mutex is held and rdata is on the list. | ||
306 | */ | ||
290 | mutex_lock(&lport->disc.disc_mutex); | 307 | mutex_lock(&lport->disc.disc_mutex); |
291 | list_del(&rdata->peers); | 308 | mutex_lock(&rdata->rp_mutex); |
309 | if (rdata->rp_state == RPORT_ST_RESTART) | ||
310 | restart = 1; | ||
311 | else | ||
312 | list_del(&rdata->peers); | ||
313 | mutex_unlock(&rdata->rp_mutex); | ||
292 | mutex_unlock(&lport->disc.disc_mutex); | 314 | mutex_unlock(&lport->disc.disc_mutex); |
293 | } | 315 | } |
294 | 316 | ||
@@ -305,14 +327,20 @@ static void fc_rport_work(struct work_struct *work) | |||
305 | lport->tt.exch_mgr_reset(lport, port_id, 0); | 327 | lport->tt.exch_mgr_reset(lport, port_id, 0); |
306 | 328 | ||
307 | if (rport) { | 329 | if (rport) { |
308 | rp = rport->dd_data; | 330 | rpriv = rport->dd_data; |
309 | rp->rp_state = RPORT_ST_DELETE; | 331 | rpriv->rp_state = RPORT_ST_DELETE; |
310 | mutex_lock(&rdata->rp_mutex); | 332 | mutex_lock(&rdata->rp_mutex); |
311 | rdata->rport = NULL; | 333 | rdata->rport = NULL; |
312 | mutex_unlock(&rdata->rp_mutex); | 334 | mutex_unlock(&rdata->rp_mutex); |
313 | fc_remote_port_delete(rport); | 335 | fc_remote_port_delete(rport); |
314 | } | 336 | } |
315 | kref_put(&rdata->kref, lport->tt.rport_destroy); | 337 | if (restart) { |
338 | mutex_lock(&rdata->rp_mutex); | ||
339 | FC_RPORT_DBG(rdata, "work restart\n"); | ||
340 | fc_rport_enter_plogi(rdata); | ||
341 | mutex_unlock(&rdata->rp_mutex); | ||
342 | } else | ||
343 | kref_put(&rdata->kref, lport->tt.rport_destroy); | ||
316 | break; | 344 | break; |
317 | 345 | ||
318 | default: | 346 | default: |
@@ -323,7 +351,7 @@ static void fc_rport_work(struct work_struct *work) | |||
323 | 351 | ||
324 | /** | 352 | /** |
325 | * fc_rport_login() - Start the remote port login state machine | 353 | * fc_rport_login() - Start the remote port login state machine |
326 | * @rdata: private remote port | 354 | * @rdata: The remote port to be logged in to |
327 | * | 355 | * |
328 | * Locking Note: Called without the rport lock held. This | 356 | * Locking Note: Called without the rport lock held. This |
329 | * function will hold the rport lock, call an _enter_* | 357 | * function will hold the rport lock, call an _enter_* |
@@ -342,6 +370,12 @@ int fc_rport_login(struct fc_rport_priv *rdata) | |||
342 | FC_RPORT_DBG(rdata, "ADISC port\n"); | 370 | FC_RPORT_DBG(rdata, "ADISC port\n"); |
343 | fc_rport_enter_adisc(rdata); | 371 | fc_rport_enter_adisc(rdata); |
344 | break; | 372 | break; |
373 | case RPORT_ST_RESTART: | ||
374 | break; | ||
375 | case RPORT_ST_DELETE: | ||
376 | FC_RPORT_DBG(rdata, "Restart deleted port\n"); | ||
377 | fc_rport_state_enter(rdata, RPORT_ST_RESTART); | ||
378 | break; | ||
345 | default: | 379 | default: |
346 | FC_RPORT_DBG(rdata, "Login to port\n"); | 380 | FC_RPORT_DBG(rdata, "Login to port\n"); |
347 | fc_rport_enter_plogi(rdata); | 381 | fc_rport_enter_plogi(rdata); |
@@ -353,9 +387,9 @@ int fc_rport_login(struct fc_rport_priv *rdata) | |||
353 | } | 387 | } |
354 | 388 | ||
355 | /** | 389 | /** |
356 | * fc_rport_enter_delete() - schedule a remote port to be deleted. | 390 | * fc_rport_enter_delete() - Schedule a remote port to be deleted |
357 | * @rdata: private remote port | 391 | * @rdata: The remote port to be deleted |
358 | * @event: event to report as the reason for deletion | 392 | * @event: The event to report as the reason for deletion |
359 | * | 393 | * |
360 | * Locking Note: Called with the rport lock held. | 394 | * Locking Note: Called with the rport lock held. |
361 | * | 395 | * |
@@ -382,8 +416,8 @@ static void fc_rport_enter_delete(struct fc_rport_priv *rdata, | |||
382 | } | 416 | } |
383 | 417 | ||
384 | /** | 418 | /** |
385 | * fc_rport_logoff() - Logoff and remove an rport | 419 | * fc_rport_logoff() - Logoff and remove a remote port |
386 | * @rdata: private remote port | 420 | * @rdata: The remote port to be logged off of |
387 | * | 421 | * |
388 | * Locking Note: Called without the rport lock held. This | 422 | * Locking Note: Called without the rport lock held. This |
389 | * function will hold the rport lock, call an _enter_* | 423 | * function will hold the rport lock, call an _enter_* |
@@ -397,26 +431,27 @@ int fc_rport_logoff(struct fc_rport_priv *rdata) | |||
397 | 431 | ||
398 | if (rdata->rp_state == RPORT_ST_DELETE) { | 432 | if (rdata->rp_state == RPORT_ST_DELETE) { |
399 | FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n"); | 433 | FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n"); |
400 | mutex_unlock(&rdata->rp_mutex); | ||
401 | goto out; | 434 | goto out; |
402 | } | 435 | } |
403 | 436 | ||
404 | fc_rport_enter_logo(rdata); | 437 | if (rdata->rp_state == RPORT_ST_RESTART) |
438 | FC_RPORT_DBG(rdata, "Port in Restart state, deleting\n"); | ||
439 | else | ||
440 | fc_rport_enter_logo(rdata); | ||
405 | 441 | ||
406 | /* | 442 | /* |
407 | * Change the state to Delete so that we discard | 443 | * Change the state to Delete so that we discard |
408 | * the response. | 444 | * the response. |
409 | */ | 445 | */ |
410 | fc_rport_enter_delete(rdata, RPORT_EV_STOP); | 446 | fc_rport_enter_delete(rdata, RPORT_EV_STOP); |
411 | mutex_unlock(&rdata->rp_mutex); | ||
412 | |||
413 | out: | 447 | out: |
448 | mutex_unlock(&rdata->rp_mutex); | ||
414 | return 0; | 449 | return 0; |
415 | } | 450 | } |
416 | 451 | ||
417 | /** | 452 | /** |
418 | * fc_rport_enter_ready() - The rport is ready | 453 | * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state |
419 | * @rdata: private remote port | 454 | * @rdata: The remote port that is ready |
420 | * | 455 | * |
421 | * Locking Note: The rport lock is expected to be held before calling | 456 | * Locking Note: The rport lock is expected to be held before calling |
422 | * this routine. | 457 | * this routine. |
@@ -433,8 +468,8 @@ static void fc_rport_enter_ready(struct fc_rport_priv *rdata) | |||
433 | } | 468 | } |
434 | 469 | ||
435 | /** | 470 | /** |
436 | * fc_rport_timeout() - Handler for the retry_work timer. | 471 | * fc_rport_timeout() - Handler for the retry_work timer |
437 | * @work: The work struct of the fc_rport_priv | 472 | * @work: Handle to the remote port that has timed out |
438 | * | 473 | * |
439 | * Locking Note: Called without the rport lock held. This | 474 | * Locking Note: Called without the rport lock held. This |
440 | * function will hold the rport lock, call an _enter_* | 475 | * function will hold the rport lock, call an _enter_* |
@@ -466,6 +501,7 @@ static void fc_rport_timeout(struct work_struct *work) | |||
466 | case RPORT_ST_READY: | 501 | case RPORT_ST_READY: |
467 | case RPORT_ST_INIT: | 502 | case RPORT_ST_INIT: |
468 | case RPORT_ST_DELETE: | 503 | case RPORT_ST_DELETE: |
504 | case RPORT_ST_RESTART: | ||
469 | break; | 505 | break; |
470 | } | 506 | } |
471 | 507 | ||
@@ -474,8 +510,8 @@ static void fc_rport_timeout(struct work_struct *work) | |||
474 | 510 | ||
475 | /** | 511 | /** |
476 | * fc_rport_error() - Error handler, called once retries have been exhausted | 512 | * fc_rport_error() - Error handler, called once retries have been exhausted |
477 | * @rdata: private remote port | 513 | * @rdata: The remote port the error is happened on |
478 | * @fp: The frame pointer | 514 | * @fp: The error code encapsulated in a frame pointer |
479 | * | 515 | * |
480 | * Locking Note: The rport lock is expected to be held before | 516 | * Locking Note: The rport lock is expected to be held before |
481 | * calling this routine | 517 | * calling this routine |
@@ -499,6 +535,7 @@ static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp) | |||
499 | fc_rport_enter_logo(rdata); | 535 | fc_rport_enter_logo(rdata); |
500 | break; | 536 | break; |
501 | case RPORT_ST_DELETE: | 537 | case RPORT_ST_DELETE: |
538 | case RPORT_ST_RESTART: | ||
502 | case RPORT_ST_READY: | 539 | case RPORT_ST_READY: |
503 | case RPORT_ST_INIT: | 540 | case RPORT_ST_INIT: |
504 | break; | 541 | break; |
@@ -506,9 +543,9 @@ static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp) | |||
506 | } | 543 | } |
507 | 544 | ||
508 | /** | 545 | /** |
509 | * fc_rport_error_retry() - Error handler when retries are desired | 546 | * fc_rport_error_retry() - Handler for remote port state retries |
510 | * @rdata: private remote port data | 547 | * @rdata: The remote port whose state is to be retried |
511 | * @fp: The frame pointer | 548 | * @fp: The error code encapsulated in a frame pointer |
512 | * | 549 | * |
513 | * If the error was an exchange timeout retry immediately, | 550 | * If the error was an exchange timeout retry immediately, |
514 | * otherwise wait for E_D_TOV. | 551 | * otherwise wait for E_D_TOV. |
@@ -540,10 +577,10 @@ static void fc_rport_error_retry(struct fc_rport_priv *rdata, | |||
540 | } | 577 | } |
541 | 578 | ||
542 | /** | 579 | /** |
543 | * fc_rport_plogi_recv_resp() - Handle incoming ELS PLOGI response | 580 | * fc_rport_plogi_recv_resp() - Handler for ELS PLOGI responses |
544 | * @sp: current sequence in the PLOGI exchange | 581 | * @sp: The sequence the PLOGI is on |
545 | * @fp: response frame | 582 | * @fp: The PLOGI response frame |
546 | * @rdata_arg: private remote port data | 583 | * @rdata_arg: The remote port that sent the PLOGI response |
547 | * | 584 | * |
548 | * Locking Note: This function will be called without the rport lock | 585 | * Locking Note: This function will be called without the rport lock |
549 | * held, but it will lock, call an _enter_* function or fc_rport_error | 586 | * held, but it will lock, call an _enter_* function or fc_rport_error |
@@ -606,8 +643,8 @@ err: | |||
606 | } | 643 | } |
607 | 644 | ||
608 | /** | 645 | /** |
609 | * fc_rport_enter_plogi() - Send Port Login (PLOGI) request to peer | 646 | * fc_rport_enter_plogi() - Send Port Login (PLOGI) request |
610 | * @rdata: private remote port data | 647 | * @rdata: The remote port to send a PLOGI to |
611 | * | 648 | * |
612 | * Locking Note: The rport lock is expected to be held before calling | 649 | * Locking Note: The rport lock is expected to be held before calling |
613 | * this routine. | 650 | * this routine. |
@@ -631,17 +668,18 @@ static void fc_rport_enter_plogi(struct fc_rport_priv *rdata) | |||
631 | rdata->e_d_tov = lport->e_d_tov; | 668 | rdata->e_d_tov = lport->e_d_tov; |
632 | 669 | ||
633 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI, | 670 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI, |
634 | fc_rport_plogi_resp, rdata, lport->e_d_tov)) | 671 | fc_rport_plogi_resp, rdata, |
635 | fc_rport_error_retry(rdata, fp); | 672 | 2 * lport->r_a_tov)) |
673 | fc_rport_error_retry(rdata, NULL); | ||
636 | else | 674 | else |
637 | kref_get(&rdata->kref); | 675 | kref_get(&rdata->kref); |
638 | } | 676 | } |
639 | 677 | ||
640 | /** | 678 | /** |
641 | * fc_rport_prli_resp() - Process Login (PRLI) response handler | 679 | * fc_rport_prli_resp() - Process Login (PRLI) response handler |
642 | * @sp: current sequence in the PRLI exchange | 680 | * @sp: The sequence the PRLI response was on |
643 | * @fp: response frame | 681 | * @fp: The PRLI response frame |
644 | * @rdata_arg: private remote port data | 682 | * @rdata_arg: The remote port that sent the PRLI response |
645 | * | 683 | * |
646 | * Locking Note: This function will be called without the rport lock | 684 | * Locking Note: This function will be called without the rport lock |
647 | * held, but it will lock, call an _enter_* function or fc_rport_error | 685 | * held, but it will lock, call an _enter_* function or fc_rport_error |
@@ -710,10 +748,10 @@ err: | |||
710 | } | 748 | } |
711 | 749 | ||
712 | /** | 750 | /** |
713 | * fc_rport_logo_resp() - Logout (LOGO) response handler | 751 | * fc_rport_logo_resp() - Handler for logout (LOGO) responses |
714 | * @sp: current sequence in the LOGO exchange | 752 | * @sp: The sequence the LOGO was on |
715 | * @fp: response frame | 753 | * @fp: The LOGO response frame |
716 | * @rdata_arg: private remote port data | 754 | * @rdata_arg: The remote port that sent the LOGO response |
717 | * | 755 | * |
718 | * Locking Note: This function will be called without the rport lock | 756 | * Locking Note: This function will be called without the rport lock |
719 | * held, but it will lock, call an _enter_* function or fc_rport_error | 757 | * held, but it will lock, call an _enter_* function or fc_rport_error |
@@ -756,8 +794,8 @@ err: | |||
756 | } | 794 | } |
757 | 795 | ||
758 | /** | 796 | /** |
759 | * fc_rport_enter_prli() - Send Process Login (PRLI) request to peer | 797 | * fc_rport_enter_prli() - Send Process Login (PRLI) request |
760 | * @rdata: private remote port data | 798 | * @rdata: The remote port to send the PRLI request to |
761 | * | 799 | * |
762 | * Locking Note: The rport lock is expected to be held before calling | 800 | * Locking Note: The rport lock is expected to be held before calling |
763 | * this routine. | 801 | * this routine. |
@@ -792,17 +830,18 @@ static void fc_rport_enter_prli(struct fc_rport_priv *rdata) | |||
792 | } | 830 | } |
793 | 831 | ||
794 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PRLI, | 832 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PRLI, |
795 | fc_rport_prli_resp, rdata, lport->e_d_tov)) | 833 | fc_rport_prli_resp, rdata, |
796 | fc_rport_error_retry(rdata, fp); | 834 | 2 * lport->r_a_tov)) |
835 | fc_rport_error_retry(rdata, NULL); | ||
797 | else | 836 | else |
798 | kref_get(&rdata->kref); | 837 | kref_get(&rdata->kref); |
799 | } | 838 | } |
800 | 839 | ||
801 | /** | 840 | /** |
802 | * fc_rport_els_rtv_resp() - Request Timeout Value response handler | 841 | * fc_rport_els_rtv_resp() - Handler for Request Timeout Value (RTV) responses |
803 | * @sp: current sequence in the RTV exchange | 842 | * @sp: The sequence the RTV was on |
804 | * @fp: response frame | 843 | * @fp: The RTV response frame |
805 | * @rdata_arg: private remote port data | 844 | * @rdata_arg: The remote port that sent the RTV response |
806 | * | 845 | * |
807 | * Many targets don't seem to support this. | 846 | * Many targets don't seem to support this. |
808 | * | 847 | * |
@@ -865,8 +904,8 @@ err: | |||
865 | } | 904 | } |
866 | 905 | ||
867 | /** | 906 | /** |
868 | * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request to peer | 907 | * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request |
869 | * @rdata: private remote port data | 908 | * @rdata: The remote port to send the RTV request to |
870 | * | 909 | * |
871 | * Locking Note: The rport lock is expected to be held before calling | 910 | * Locking Note: The rport lock is expected to be held before calling |
872 | * this routine. | 911 | * this routine. |
@@ -888,15 +927,16 @@ static void fc_rport_enter_rtv(struct fc_rport_priv *rdata) | |||
888 | } | 927 | } |
889 | 928 | ||
890 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV, | 929 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV, |
891 | fc_rport_rtv_resp, rdata, lport->e_d_tov)) | 930 | fc_rport_rtv_resp, rdata, |
892 | fc_rport_error_retry(rdata, fp); | 931 | 2 * lport->r_a_tov)) |
932 | fc_rport_error_retry(rdata, NULL); | ||
893 | else | 933 | else |
894 | kref_get(&rdata->kref); | 934 | kref_get(&rdata->kref); |
895 | } | 935 | } |
896 | 936 | ||
897 | /** | 937 | /** |
898 | * fc_rport_enter_logo() - Send Logout (LOGO) request to peer | 938 | * fc_rport_enter_logo() - Send a logout (LOGO) request |
899 | * @rdata: private remote port data | 939 | * @rdata: The remote port to send the LOGO request to |
900 | * | 940 | * |
901 | * Locking Note: The rport lock is expected to be held before calling | 941 | * Locking Note: The rport lock is expected to be held before calling |
902 | * this routine. | 942 | * this routine. |
@@ -918,24 +958,25 @@ static void fc_rport_enter_logo(struct fc_rport_priv *rdata) | |||
918 | } | 958 | } |
919 | 959 | ||
920 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO, | 960 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO, |
921 | fc_rport_logo_resp, rdata, lport->e_d_tov)) | 961 | fc_rport_logo_resp, rdata, |
922 | fc_rport_error_retry(rdata, fp); | 962 | 2 * lport->r_a_tov)) |
963 | fc_rport_error_retry(rdata, NULL); | ||
923 | else | 964 | else |
924 | kref_get(&rdata->kref); | 965 | kref_get(&rdata->kref); |
925 | } | 966 | } |
926 | 967 | ||
927 | /** | 968 | /** |
928 | * fc_rport_els_adisc_resp() - Address Discovery response handler | 969 | * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses |
929 | * @sp: current sequence in the ADISC exchange | 970 | * @sp: The sequence the ADISC response was on |
930 | * @fp: response frame | 971 | * @fp: The ADISC response frame |
931 | * @rdata_arg: remote port private. | 972 | * @rdata_arg: The remote port that sent the ADISC response |
932 | * | 973 | * |
933 | * Locking Note: This function will be called without the rport lock | 974 | * Locking Note: This function will be called without the rport lock |
934 | * held, but it will lock, call an _enter_* function or fc_rport_error | 975 | * held, but it will lock, call an _enter_* function or fc_rport_error |
935 | * and then unlock the rport. | 976 | * and then unlock the rport. |
936 | */ | 977 | */ |
937 | static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp, | 978 | static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp, |
938 | void *rdata_arg) | 979 | void *rdata_arg) |
939 | { | 980 | { |
940 | struct fc_rport_priv *rdata = rdata_arg; | 981 | struct fc_rport_priv *rdata = rdata_arg; |
941 | struct fc_els_adisc *adisc; | 982 | struct fc_els_adisc *adisc; |
@@ -983,8 +1024,8 @@ err: | |||
983 | } | 1024 | } |
984 | 1025 | ||
985 | /** | 1026 | /** |
986 | * fc_rport_enter_adisc() - Send Address Discover (ADISC) request to peer | 1027 | * fc_rport_enter_adisc() - Send Address Discover (ADISC) request |
987 | * @rdata: remote port private data | 1028 | * @rdata: The remote port to send the ADISC request to |
988 | * | 1029 | * |
989 | * Locking Note: The rport lock is expected to be held before calling | 1030 | * Locking Note: The rport lock is expected to be held before calling |
990 | * this routine. | 1031 | * this routine. |
@@ -1005,17 +1046,18 @@ static void fc_rport_enter_adisc(struct fc_rport_priv *rdata) | |||
1005 | return; | 1046 | return; |
1006 | } | 1047 | } |
1007 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC, | 1048 | if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC, |
1008 | fc_rport_adisc_resp, rdata, lport->e_d_tov)) | 1049 | fc_rport_adisc_resp, rdata, |
1009 | fc_rport_error_retry(rdata, fp); | 1050 | 2 * lport->r_a_tov)) |
1051 | fc_rport_error_retry(rdata, NULL); | ||
1010 | else | 1052 | else |
1011 | kref_get(&rdata->kref); | 1053 | kref_get(&rdata->kref); |
1012 | } | 1054 | } |
1013 | 1055 | ||
1014 | /** | 1056 | /** |
1015 | * fc_rport_recv_adisc_req() - Handle incoming Address Discovery (ADISC) Request | 1057 | * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests |
1016 | * @rdata: remote port private | 1058 | * @rdata: The remote port that sent the ADISC request |
1017 | * @sp: current sequence in the ADISC exchange | 1059 | * @sp: The sequence the ADISC request was on |
1018 | * @in_fp: ADISC request frame | 1060 | * @in_fp: The ADISC request frame |
1019 | * | 1061 | * |
1020 | * Locking Note: Called with the lport and rport locks held. | 1062 | * Locking Note: Called with the lport and rport locks held. |
1021 | */ | 1063 | */ |
@@ -1056,10 +1098,82 @@ drop: | |||
1056 | } | 1098 | } |
1057 | 1099 | ||
1058 | /** | 1100 | /** |
1059 | * fc_rport_recv_els_req() - handle a validated ELS request. | 1101 | * fc_rport_recv_rls_req() - Handle received Read Link Status request |
1060 | * @lport: Fibre Channel local port | 1102 | * @rdata: The remote port that sent the RLS request |
1061 | * @sp: current sequence in the PLOGI exchange | 1103 | * @sp: The sequence that the RLS was on |
1062 | * @fp: response frame | 1104 | * @rx_fp: The PRLI request frame |
1105 | * | ||
1106 | * Locking Note: The rport lock is expected to be held before calling | ||
1107 | * this function. | ||
1108 | */ | ||
1109 | static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata, | ||
1110 | struct fc_seq *sp, struct fc_frame *rx_fp) | ||
1111 | |||
1112 | { | ||
1113 | struct fc_lport *lport = rdata->local_port; | ||
1114 | struct fc_frame *fp; | ||
1115 | struct fc_exch *ep = fc_seq_exch(sp); | ||
1116 | struct fc_els_rls *rls; | ||
1117 | struct fc_els_rls_resp *rsp; | ||
1118 | struct fc_els_lesb *lesb; | ||
1119 | struct fc_seq_els_data rjt_data; | ||
1120 | struct fc_host_statistics *hst; | ||
1121 | u32 f_ctl; | ||
1122 | |||
1123 | FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n", | ||
1124 | fc_rport_state(rdata)); | ||
1125 | |||
1126 | rls = fc_frame_payload_get(rx_fp, sizeof(*rls)); | ||
1127 | if (!rls) { | ||
1128 | rjt_data.reason = ELS_RJT_PROT; | ||
1129 | rjt_data.explan = ELS_EXPL_INV_LEN; | ||
1130 | goto out_rjt; | ||
1131 | } | ||
1132 | |||
1133 | fp = fc_frame_alloc(lport, sizeof(*rsp)); | ||
1134 | if (!fp) { | ||
1135 | rjt_data.reason = ELS_RJT_UNAB; | ||
1136 | rjt_data.explan = ELS_EXPL_INSUF_RES; | ||
1137 | goto out_rjt; | ||
1138 | } | ||
1139 | |||
1140 | rsp = fc_frame_payload_get(fp, sizeof(*rsp)); | ||
1141 | memset(rsp, 0, sizeof(*rsp)); | ||
1142 | rsp->rls_cmd = ELS_LS_ACC; | ||
1143 | lesb = &rsp->rls_lesb; | ||
1144 | if (lport->tt.get_lesb) { | ||
1145 | /* get LESB from LLD if it supports it */ | ||
1146 | lport->tt.get_lesb(lport, lesb); | ||
1147 | } else { | ||
1148 | fc_get_host_stats(lport->host); | ||
1149 | hst = &lport->host_stats; | ||
1150 | lesb->lesb_link_fail = htonl(hst->link_failure_count); | ||
1151 | lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count); | ||
1152 | lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count); | ||
1153 | lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count); | ||
1154 | lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count); | ||
1155 | lesb->lesb_inv_crc = htonl(hst->invalid_crc_count); | ||
1156 | } | ||
1157 | |||
1158 | sp = lport->tt.seq_start_next(sp); | ||
1159 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; | ||
1160 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, | ||
1161 | FC_TYPE_ELS, f_ctl, 0); | ||
1162 | lport->tt.seq_send(lport, sp, fp); | ||
1163 | goto out; | ||
1164 | |||
1165 | out_rjt: | ||
1166 | rjt_data.fp = NULL; | ||
1167 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); | ||
1168 | out: | ||
1169 | fc_frame_free(rx_fp); | ||
1170 | } | ||
1171 | |||
1172 | /** | ||
1173 | * fc_rport_recv_els_req() - Handler for validated ELS requests | ||
1174 | * @lport: The local port that received the ELS request | ||
1175 | * @sp: The sequence that the ELS request was on | ||
1176 | * @fp: The ELS request frame | ||
1063 | * | 1177 | * |
1064 | * Handle incoming ELS requests that require port login. | 1178 | * Handle incoming ELS requests that require port login. |
1065 | * The ELS opcode has already been validated by the caller. | 1179 | * The ELS opcode has already been validated by the caller. |
@@ -1117,6 +1231,9 @@ static void fc_rport_recv_els_req(struct fc_lport *lport, | |||
1117 | els_data.fp = fp; | 1231 | els_data.fp = fp; |
1118 | lport->tt.seq_els_rsp_send(sp, ELS_REC, &els_data); | 1232 | lport->tt.seq_els_rsp_send(sp, ELS_REC, &els_data); |
1119 | break; | 1233 | break; |
1234 | case ELS_RLS: | ||
1235 | fc_rport_recv_rls_req(rdata, sp, fp); | ||
1236 | break; | ||
1120 | default: | 1237 | default: |
1121 | fc_frame_free(fp); /* can't happen */ | 1238 | fc_frame_free(fp); /* can't happen */ |
1122 | break; | 1239 | break; |
@@ -1131,10 +1248,10 @@ reject: | |||
1131 | } | 1248 | } |
1132 | 1249 | ||
1133 | /** | 1250 | /** |
1134 | * fc_rport_recv_req() - Handle a received ELS request from a rport | 1251 | * fc_rport_recv_req() - Handler for requests |
1135 | * @sp: current sequence in the PLOGI exchange | 1252 | * @sp: The sequence the request was on |
1136 | * @fp: response frame | 1253 | * @fp: The request frame |
1137 | * @lport: Fibre Channel local port | 1254 | * @lport: The local port that received the request |
1138 | * | 1255 | * |
1139 | * Locking Note: Called with the lport lock held. | 1256 | * Locking Note: Called with the lport lock held. |
1140 | */ | 1257 | */ |
@@ -1161,6 +1278,7 @@ void fc_rport_recv_req(struct fc_seq *sp, struct fc_frame *fp, | |||
1161 | case ELS_ADISC: | 1278 | case ELS_ADISC: |
1162 | case ELS_RRQ: | 1279 | case ELS_RRQ: |
1163 | case ELS_REC: | 1280 | case ELS_REC: |
1281 | case ELS_RLS: | ||
1164 | fc_rport_recv_els_req(lport, sp, fp); | 1282 | fc_rport_recv_els_req(lport, sp, fp); |
1165 | break; | 1283 | break; |
1166 | default: | 1284 | default: |
@@ -1174,10 +1292,10 @@ void fc_rport_recv_req(struct fc_seq *sp, struct fc_frame *fp, | |||
1174 | } | 1292 | } |
1175 | 1293 | ||
1176 | /** | 1294 | /** |
1177 | * fc_rport_recv_plogi_req() - Handle incoming Port Login (PLOGI) request | 1295 | * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests |
1178 | * @lport: local port | 1296 | * @lport: The local port that received the PLOGI request |
1179 | * @sp: current sequence in the PLOGI exchange | 1297 | * @sp: The sequence that the PLOGI request was on |
1180 | * @fp: PLOGI request frame | 1298 | * @rx_fp: The PLOGI request frame |
1181 | * | 1299 | * |
1182 | * Locking Note: The rport lock is held before calling this function. | 1300 | * Locking Note: The rport lock is held before calling this function. |
1183 | */ | 1301 | */ |
@@ -1248,6 +1366,7 @@ static void fc_rport_recv_plogi_req(struct fc_lport *lport, | |||
1248 | } | 1366 | } |
1249 | break; | 1367 | break; |
1250 | case RPORT_ST_PRLI: | 1368 | case RPORT_ST_PRLI: |
1369 | case RPORT_ST_RTV: | ||
1251 | case RPORT_ST_READY: | 1370 | case RPORT_ST_READY: |
1252 | case RPORT_ST_ADISC: | 1371 | case RPORT_ST_ADISC: |
1253 | FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d " | 1372 | FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d " |
@@ -1255,11 +1374,14 @@ static void fc_rport_recv_plogi_req(struct fc_lport *lport, | |||
1255 | /* XXX TBD - should reset */ | 1374 | /* XXX TBD - should reset */ |
1256 | break; | 1375 | break; |
1257 | case RPORT_ST_DELETE: | 1376 | case RPORT_ST_DELETE: |
1258 | default: | 1377 | case RPORT_ST_LOGO: |
1259 | FC_RPORT_DBG(rdata, "Received PLOGI in unexpected state %d\n", | 1378 | case RPORT_ST_RESTART: |
1260 | rdata->rp_state); | 1379 | FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n", |
1261 | fc_frame_free(rx_fp); | 1380 | fc_rport_state(rdata)); |
1262 | goto out; | 1381 | mutex_unlock(&rdata->rp_mutex); |
1382 | rjt_data.reason = ELS_RJT_BUSY; | ||
1383 | rjt_data.explan = ELS_EXPL_NONE; | ||
1384 | goto reject; | ||
1263 | } | 1385 | } |
1264 | 1386 | ||
1265 | /* | 1387 | /* |
@@ -1295,10 +1417,10 @@ reject: | |||
1295 | } | 1417 | } |
1296 | 1418 | ||
1297 | /** | 1419 | /** |
1298 | * fc_rport_recv_prli_req() - Handle incoming Process Login (PRLI) request | 1420 | * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests |
1299 | * @rdata: private remote port data | 1421 | * @rdata: The remote port that sent the PRLI request |
1300 | * @sp: current sequence in the PRLI exchange | 1422 | * @sp: The sequence that the PRLI was on |
1301 | * @fp: PRLI request frame | 1423 | * @rx_fp: The PRLI request frame |
1302 | * | 1424 | * |
1303 | * Locking Note: The rport lock is exected to be held before calling | 1425 | * Locking Note: The rport lock is exected to be held before calling |
1304 | * this function. | 1426 | * this function. |
@@ -1402,7 +1524,7 @@ static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata, | |||
1402 | break; | 1524 | break; |
1403 | case FC_TYPE_FCP: | 1525 | case FC_TYPE_FCP: |
1404 | fcp_parm = ntohl(rspp->spp_params); | 1526 | fcp_parm = ntohl(rspp->spp_params); |
1405 | if (fcp_parm * FCP_SPPF_RETRY) | 1527 | if (fcp_parm & FCP_SPPF_RETRY) |
1406 | rdata->flags |= FC_RP_FLAGS_RETRY; | 1528 | rdata->flags |= FC_RP_FLAGS_RETRY; |
1407 | rdata->supported_classes = FC_COS_CLASS3; | 1529 | rdata->supported_classes = FC_COS_CLASS3; |
1408 | if (fcp_parm & FCP_SPPF_INIT_FCN) | 1530 | if (fcp_parm & FCP_SPPF_INIT_FCN) |
@@ -1452,10 +1574,10 @@ static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata, | |||
1452 | } | 1574 | } |
1453 | 1575 | ||
1454 | /** | 1576 | /** |
1455 | * fc_rport_recv_prlo_req() - Handle incoming Process Logout (PRLO) request | 1577 | * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests |
1456 | * @rdata: private remote port data | 1578 | * @rdata: The remote port that sent the PRLO request |
1457 | * @sp: current sequence in the PRLO exchange | 1579 | * @sp: The sequence that the PRLO was on |
1458 | * @fp: PRLO request frame | 1580 | * @fp: The PRLO request frame |
1459 | * | 1581 | * |
1460 | * Locking Note: The rport lock is exected to be held before calling | 1582 | * Locking Note: The rport lock is exected to be held before calling |
1461 | * this function. | 1583 | * this function. |
@@ -1482,10 +1604,10 @@ static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata, | |||
1482 | } | 1604 | } |
1483 | 1605 | ||
1484 | /** | 1606 | /** |
1485 | * fc_rport_recv_logo_req() - Handle incoming Logout (LOGO) request | 1607 | * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests |
1486 | * @lport: local port. | 1608 | * @lport: The local port that received the LOGO request |
1487 | * @sp: current sequence in the LOGO exchange | 1609 | * @sp: The sequence that the LOGO request was on |
1488 | * @fp: LOGO request frame | 1610 | * @fp: The LOGO request frame |
1489 | * | 1611 | * |
1490 | * Locking Note: The rport lock is exected to be held before calling | 1612 | * Locking Note: The rport lock is exected to be held before calling |
1491 | * this function. | 1613 | * this function. |
@@ -1510,14 +1632,14 @@ static void fc_rport_recv_logo_req(struct fc_lport *lport, | |||
1510 | FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n", | 1632 | FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n", |
1511 | fc_rport_state(rdata)); | 1633 | fc_rport_state(rdata)); |
1512 | 1634 | ||
1635 | fc_rport_enter_delete(rdata, RPORT_EV_LOGO); | ||
1636 | |||
1513 | /* | 1637 | /* |
1514 | * If the remote port was created due to discovery, | 1638 | * If the remote port was created due to discovery, set state |
1515 | * log back in. It may have seen a stale RSCN about us. | 1639 | * to log back in. It may have seen a stale RSCN about us. |
1516 | */ | 1640 | */ |
1517 | if (rdata->rp_state != RPORT_ST_DELETE && rdata->disc_id) | 1641 | if (rdata->disc_id) |
1518 | fc_rport_enter_plogi(rdata); | 1642 | fc_rport_state_enter(rdata, RPORT_ST_RESTART); |
1519 | else | ||
1520 | fc_rport_enter_delete(rdata, RPORT_EV_LOGO); | ||
1521 | mutex_unlock(&rdata->rp_mutex); | 1643 | mutex_unlock(&rdata->rp_mutex); |
1522 | } else | 1644 | } else |
1523 | FC_RPORT_ID_DBG(lport, sid, | 1645 | FC_RPORT_ID_DBG(lport, sid, |
@@ -1526,11 +1648,18 @@ static void fc_rport_recv_logo_req(struct fc_lport *lport, | |||
1526 | fc_frame_free(fp); | 1648 | fc_frame_free(fp); |
1527 | } | 1649 | } |
1528 | 1650 | ||
1651 | /** | ||
1652 | * fc_rport_flush_queue() - Flush the rport_event_queue | ||
1653 | */ | ||
1529 | static void fc_rport_flush_queue(void) | 1654 | static void fc_rport_flush_queue(void) |
1530 | { | 1655 | { |
1531 | flush_workqueue(rport_event_queue); | 1656 | flush_workqueue(rport_event_queue); |
1532 | } | 1657 | } |
1533 | 1658 | ||
1659 | /** | ||
1660 | * fc_rport_init() - Initialize the remote port layer for a local port | ||
1661 | * @lport: The local port to initialize the remote port layer for | ||
1662 | */ | ||
1534 | int fc_rport_init(struct fc_lport *lport) | 1663 | int fc_rport_init(struct fc_lport *lport) |
1535 | { | 1664 | { |
1536 | if (!lport->tt.rport_lookup) | 1665 | if (!lport->tt.rport_lookup) |
@@ -1558,25 +1687,33 @@ int fc_rport_init(struct fc_lport *lport) | |||
1558 | } | 1687 | } |
1559 | EXPORT_SYMBOL(fc_rport_init); | 1688 | EXPORT_SYMBOL(fc_rport_init); |
1560 | 1689 | ||
1561 | int fc_setup_rport(void) | 1690 | /** |
1691 | * fc_setup_rport() - Initialize the rport_event_queue | ||
1692 | */ | ||
1693 | int fc_setup_rport() | ||
1562 | { | 1694 | { |
1563 | rport_event_queue = create_singlethread_workqueue("fc_rport_eq"); | 1695 | rport_event_queue = create_singlethread_workqueue("fc_rport_eq"); |
1564 | if (!rport_event_queue) | 1696 | if (!rport_event_queue) |
1565 | return -ENOMEM; | 1697 | return -ENOMEM; |
1566 | return 0; | 1698 | return 0; |
1567 | } | 1699 | } |
1568 | EXPORT_SYMBOL(fc_setup_rport); | ||
1569 | 1700 | ||
1570 | void fc_destroy_rport(void) | 1701 | /** |
1702 | * fc_destroy_rport() - Destroy the rport_event_queue | ||
1703 | */ | ||
1704 | void fc_destroy_rport() | ||
1571 | { | 1705 | { |
1572 | destroy_workqueue(rport_event_queue); | 1706 | destroy_workqueue(rport_event_queue); |
1573 | } | 1707 | } |
1574 | EXPORT_SYMBOL(fc_destroy_rport); | ||
1575 | 1708 | ||
1709 | /** | ||
1710 | * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port | ||
1711 | * @rport: The remote port whose I/O should be terminated | ||
1712 | */ | ||
1576 | void fc_rport_terminate_io(struct fc_rport *rport) | 1713 | void fc_rport_terminate_io(struct fc_rport *rport) |
1577 | { | 1714 | { |
1578 | struct fc_rport_libfc_priv *rp = rport->dd_data; | 1715 | struct fc_rport_libfc_priv *rpriv = rport->dd_data; |
1579 | struct fc_lport *lport = rp->local_port; | 1716 | struct fc_lport *lport = rpriv->local_port; |
1580 | 1717 | ||
1581 | lport->tt.exch_mgr_reset(lport, 0, rport->port_id); | 1718 | lport->tt.exch_mgr_reset(lport, 0, rport->port_id); |
1582 | lport->tt.exch_mgr_reset(lport, rport->port_id, 0); | 1719 | lport->tt.exch_mgr_reset(lport, rport->port_id, 0); |