Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright(c) 2008 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Maintained at www.Open-FCoE.org
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Provide interface to send ELS/CT FC frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <scsi/fc/fc_gs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <scsi/fc/fc_ns.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <scsi/fc/fc_els.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <scsi/libfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <scsi/fc_encode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "fc_libfc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * fc_elsct_send() - Send an ELS or CT frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * @lport:	The local port to send the frame on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @did:	The destination ID for the frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @fp:		The frame to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @op:		The operational code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * @resp:	The callback routine when the response is received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * @arg:	The argument to pass to the response callback routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * @timer_msec: The timeout period for the frame (in msecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct fc_seq *fc_elsct_send(struct fc_lport *lport, u32 did,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 			     struct fc_frame *fp, unsigned int op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 			     void (*resp)(struct fc_seq *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 					  struct fc_frame *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 					  void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			     void *arg, u32 timer_msec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	enum fc_rctl r_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	enum fc_fh_type fh_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	/* ELS requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		/* CT requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type, &did);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		fc_frame_free(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	fc_fill_fc_hdr(fp, r_ctl, did, lport->port_id, fh_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		       FC_FCTL_REQ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	return fc_exch_seq_send(lport, fp, resp, NULL, arg, timer_msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) EXPORT_SYMBOL(fc_elsct_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * fc_elsct_init() - Initialize the ELS/CT layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * @lport: The local port to initialize the ELS/CT layer for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) int fc_elsct_init(struct fc_lport *lport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (!lport->tt.elsct_send)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		lport->tt.elsct_send = fc_elsct_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) EXPORT_SYMBOL(fc_elsct_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * fc_els_resp_type() - Return a string describing the ELS response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @fp: The frame pointer or possible error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) const char *fc_els_resp_type(struct fc_frame *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	const char *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct fc_frame_header *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct fc_ct_hdr *ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (IS_ERR(fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		switch (-PTR_ERR(fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		case FC_NO_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			msg = "response no error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		case FC_EX_TIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			msg = "response timeout";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		case FC_EX_CLOSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			msg = "response closed";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			msg = "response unknown error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		fh = fc_frame_header_get(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		switch (fh->fh_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		case FC_TYPE_ELS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			switch (fc_frame_payload_op(fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			case ELS_LS_ACC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				msg = "accept";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			case ELS_LS_RJT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				msg = "reject";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				msg = "response unknown ELS";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		case FC_TYPE_CT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			ct = fc_frame_payload_get(fp, sizeof(*ct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			if (ct) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				switch (ntohs(ct->ct_cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				case FC_FS_ACC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					msg = "CT accept";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 				case FC_FS_RJT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					msg = "CT reject";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 					msg = "response unknown CT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				msg = "short CT response";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			msg = "response not ELS or CT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }