fc_elsct.c 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * Copyright(c) 2008 Intel Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Maintained at www.Open-FCoE.org
 */

/*
 * Provide interface to send ELS/CT FC frames
 */

#include <asm/unaligned.h>
#include <scsi/fc/fc_gs.h>
#include <scsi/fc/fc_ns.h>
#include <scsi/fc/fc_els.h>
#include <scsi/libfc.h>
#include <scsi/fc_encode.h>

31 32 33 34 35 36 37 38 39
/**
 * fc_elsct_send() - Send an ELS or CT frame
 * @lport:	The local port to send the frame on
 * @did:	The destination ID for the frame
 * @fp:		The frame to be sent
 * @op:		The operational code
 * @resp:	The callback routine when the response is received
 * @arg:	The argument to pass to the response callback routine
 * @timer_msec: The timeout period for the frame (in msecs)
40
 */
41 42 43 44 45 46
struct fc_seq *fc_elsct_send(struct fc_lport *lport, u32 did,
			     struct fc_frame *fp, unsigned int op,
			     void (*resp)(struct fc_seq *,
					  struct fc_frame *,
					  void *),
			     void *arg, u32 timer_msec)
47 48 49 50 51 52 53
{
	enum fc_rctl r_ctl;
	enum fc_fh_type fh_type;
	int rc;

	/* ELS requests */
	if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
54 55
		rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type);
	else {
56
		/* CT requests */
57
		rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type);
58 59
		did = FC_FID_DIR_SERV;
	}
60

61 62
	if (rc) {
		fc_frame_free(fp);
63
		return NULL;
64
	}
65

66
	fc_fill_fc_hdr(fp, r_ctl, did, lport->port_id, fh_type,
67
		       FC_FCTL_REQ, 0);
68 69 70

	return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec);
}
71
EXPORT_SYMBOL(fc_elsct_send);
72

73 74 75 76
/**
 * fc_elsct_init() - Initialize the ELS/CT layer
 * @lport: The local port to initialize the ELS/CT layer for
 */
77 78 79 80 81 82 83 84
int fc_elsct_init(struct fc_lport *lport)
{
	if (!lport->tt.elsct_send)
		lport->tt.elsct_send = fc_elsct_send;

	return 0;
}
EXPORT_SYMBOL(fc_elsct_init);
85 86

/**
87 88
 * fc_els_resp_type() - Return a string describing the ELS response
 * @fp: The frame pointer or possible error code
89 90 91 92
 */
const char *fc_els_resp_type(struct fc_frame *fp)
{
	const char *msg;
93 94 95
	struct fc_frame_header *fh;
	struct fc_ct_hdr *ct;

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	if (IS_ERR(fp)) {
		switch (-PTR_ERR(fp)) {
		case FC_NO_ERR:
			msg = "response no error";
			break;
		case FC_EX_TIMEOUT:
			msg = "response timeout";
			break;
		case FC_EX_CLOSED:
			msg = "response closed";
			break;
		default:
			msg = "response unknown error";
			break;
		}
	} else {
112 113 114 115 116 117 118 119 120 121 122 123 124 125
		fh = fc_frame_header_get(fp);
		switch (fh->fh_type) {
		case FC_TYPE_ELS:
			switch (fc_frame_payload_op(fp)) {
			case ELS_LS_ACC:
				msg = "accept";
				break;
			case ELS_LS_RJT:
				msg = "reject";
				break;
			default:
				msg = "response unknown ELS";
				break;
			}
126
			break;
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
		case FC_TYPE_CT:
			ct = fc_frame_payload_get(fp, sizeof(*ct));
			if (ct) {
				switch (ntohs(ct->ct_cmd)) {
				case FC_FS_ACC:
					msg = "CT accept";
					break;
				case FC_FS_RJT:
					msg = "CT reject";
					break;
				default:
					msg = "response unknown CT";
					break;
				}
			} else {
				msg = "short CT response";
			}
144 145
			break;
		default:
146
			msg = "response not ELS or CT";
147 148 149 150 151
			break;
		}
	}
	return msg;
}