blob: e17a28d324d04ccdf903043ae4549e04c94ccb85 [file] [log] [blame]
Robert Love42e9a922008-12-09 15:10:17 -08001/*
2 * Copyright(c) 2008 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Maintained at www.Open-FCoE.org
18 */
19
20/*
21 * Provide interface to send ELS/CT FC frames
22 */
23
Paul Gortmaker09703662011-05-27 09:37:25 -040024#include <linux/export.h>
Robert Love42e9a922008-12-09 15:10:17 -080025#include <asm/unaligned.h>
26#include <scsi/fc/fc_gs.h>
27#include <scsi/fc/fc_ns.h>
28#include <scsi/fc/fc_els.h>
29#include <scsi/libfc.h>
30#include <scsi/fc_encode.h>
Bart Van Asschec6b21c92012-01-13 17:26:20 -080031#include "fc_libfc.h"
Robert Love42e9a922008-12-09 15:10:17 -080032
Robert Love3a3b42b2009-11-03 11:47:39 -080033/**
34 * fc_elsct_send() - Send an ELS or CT frame
35 * @lport: The local port to send the frame on
36 * @did: The destination ID for the frame
37 * @fp: The frame to be sent
38 * @op: The operational code
39 * @resp: The callback routine when the response is received
40 * @arg: The argument to pass to the response callback routine
41 * @timer_msec: The timeout period for the frame (in msecs)
Robert Love42e9a922008-12-09 15:10:17 -080042 */
Robert Love3a3b42b2009-11-03 11:47:39 -080043struct fc_seq *fc_elsct_send(struct fc_lport *lport, u32 did,
44 struct fc_frame *fp, unsigned int op,
45 void (*resp)(struct fc_seq *,
46 struct fc_frame *,
47 void *),
48 void *arg, u32 timer_msec)
Robert Love42e9a922008-12-09 15:10:17 -080049{
50 enum fc_rctl r_ctl;
Robert Love42e9a922008-12-09 15:10:17 -080051 enum fc_fh_type fh_type;
52 int rc;
53
54 /* ELS requests */
55 if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
Joe Eykholta46f3272009-08-25 14:00:55 -070056 rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type);
57 else {
Robert Love42e9a922008-12-09 15:10:17 -080058 /* CT requests */
Joe Eykholt2ab7e1e2009-08-25 14:03:58 -070059 rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type);
Joe Eykholta46f3272009-08-25 14:00:55 -070060 did = FC_FID_DIR_SERV;
61 }
Robert Love42e9a922008-12-09 15:10:17 -080062
Chris Leech8f550f92009-10-21 16:28:09 -070063 if (rc) {
64 fc_frame_free(fp);
Robert Love42e9a922008-12-09 15:10:17 -080065 return NULL;
Chris Leech8f550f92009-10-21 16:28:09 -070066 }
Robert Love42e9a922008-12-09 15:10:17 -080067
Robert Love7b2787e2010-05-07 15:18:41 -070068 fc_fill_fc_hdr(fp, r_ctl, did, lport->port_id, fh_type,
Joe Eykholt24f089e2010-07-20 15:21:01 -070069 FC_FCTL_REQ, 0);
Robert Love42e9a922008-12-09 15:10:17 -080070
71 return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec);
72}
Chris Leech11b56182009-11-03 11:46:29 -080073EXPORT_SYMBOL(fc_elsct_send);
Robert Love42e9a922008-12-09 15:10:17 -080074
Robert Love3a3b42b2009-11-03 11:47:39 -080075/**
76 * fc_elsct_init() - Initialize the ELS/CT layer
77 * @lport: The local port to initialize the ELS/CT layer for
78 */
Robert Love42e9a922008-12-09 15:10:17 -080079int fc_elsct_init(struct fc_lport *lport)
80{
81 if (!lport->tt.elsct_send)
82 lport->tt.elsct_send = fc_elsct_send;
83
84 return 0;
85}
86EXPORT_SYMBOL(fc_elsct_init);
Joe Eykholtf657d292009-08-25 14:03:21 -070087
88/**
Robert Love3a3b42b2009-11-03 11:47:39 -080089 * fc_els_resp_type() - Return a string describing the ELS response
90 * @fp: The frame pointer or possible error code
Joe Eykholtf657d292009-08-25 14:03:21 -070091 */
92const char *fc_els_resp_type(struct fc_frame *fp)
93{
94 const char *msg;
Joe Eykholt52a66902009-11-03 11:49:00 -080095 struct fc_frame_header *fh;
96 struct fc_ct_hdr *ct;
97
Joe Eykholtf657d292009-08-25 14:03:21 -070098 if (IS_ERR(fp)) {
99 switch (-PTR_ERR(fp)) {
100 case FC_NO_ERR:
101 msg = "response no error";
102 break;
103 case FC_EX_TIMEOUT:
104 msg = "response timeout";
105 break;
106 case FC_EX_CLOSED:
107 msg = "response closed";
108 break;
109 default:
110 msg = "response unknown error";
111 break;
112 }
113 } else {
Joe Eykholt52a66902009-11-03 11:49:00 -0800114 fh = fc_frame_header_get(fp);
115 switch (fh->fh_type) {
116 case FC_TYPE_ELS:
117 switch (fc_frame_payload_op(fp)) {
118 case ELS_LS_ACC:
119 msg = "accept";
120 break;
121 case ELS_LS_RJT:
122 msg = "reject";
123 break;
124 default:
125 msg = "response unknown ELS";
126 break;
127 }
Joe Eykholtf657d292009-08-25 14:03:21 -0700128 break;
Joe Eykholt52a66902009-11-03 11:49:00 -0800129 case FC_TYPE_CT:
130 ct = fc_frame_payload_get(fp, sizeof(*ct));
131 if (ct) {
132 switch (ntohs(ct->ct_cmd)) {
133 case FC_FS_ACC:
134 msg = "CT accept";
135 break;
136 case FC_FS_RJT:
137 msg = "CT reject";
138 break;
139 default:
140 msg = "response unknown CT";
141 break;
142 }
143 } else {
144 msg = "short CT response";
145 }
Joe Eykholtf657d292009-08-25 14:03:21 -0700146 break;
147 default:
Joe Eykholt52a66902009-11-03 11:49:00 -0800148 msg = "response not ELS or CT";
Joe Eykholtf657d292009-08-25 14:03:21 -0700149 break;
150 }
151 }
152 return msg;
153}