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 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * zfcp device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Fibre Channel related definitions and inline functions for the zfcp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright IBM Corp. 2009, 2017
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #ifndef ZFCP_FC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define ZFCP_FC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <scsi/fc/fc_els.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <scsi/fc/fc_fcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <scsi/fc/fc_ns.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "zfcp_fsf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define ZFCP_FC_CT_SIZE_PAGE	  (PAGE_SIZE - sizeof(struct fc_ct_hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define ZFCP_FC_GPN_FT_ENT_PAGE	  (ZFCP_FC_CT_SIZE_PAGE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 					/ sizeof(struct fc_gpn_ft_resp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define ZFCP_FC_GPN_FT_NUM_BUFS	  4 /* memory pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define ZFCP_FC_GPN_FT_MAX_SIZE	  (ZFCP_FC_GPN_FT_NUM_BUFS * PAGE_SIZE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 					- sizeof(struct fc_ct_hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define ZFCP_FC_GPN_FT_MAX_ENT	  (ZFCP_FC_GPN_FT_NUM_BUFS * \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 					(ZFCP_FC_GPN_FT_ENT_PAGE + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define ZFCP_FC_CTELS_TMO	(2 * FC_DEF_R_A_TOV / 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * struct zfcp_fc_event - FC HBAAPI event for internal queueing from irq context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * @code: Event code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * @data: Event data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * @list: list_head for zfcp_fc_events list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) struct zfcp_fc_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	enum fc_host_event_code code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	u32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * struct zfcp_fc_events - Infrastructure for posting FC events from irq context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @list: List for queueing of events from irq context to workqueue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @list_lock: Lock for event list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @work: work_struct for forwarding events in workqueue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) struct zfcp_fc_events {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	spinlock_t list_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * struct zfcp_fc_gid_pn_req - container for ct header plus gid_pn request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @ct_hdr: FC GS common transport header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @gid_pn: GID_PN request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) struct zfcp_fc_gid_pn_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct fc_ct_hdr	ct_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct fc_ns_gid_pn	gid_pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * struct zfcp_fc_gid_pn_rsp - container for ct header plus gid_pn response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * @ct_hdr: FC GS common transport header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * @gid_pn: GID_PN response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) struct zfcp_fc_gid_pn_rsp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct fc_ct_hdr	ct_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct fc_gid_pn_resp	gid_pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * @ct_hdr: FC GS common transport header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * @gpn_ft: GPN_FT request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) struct zfcp_fc_gpn_ft_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct fc_ct_hdr	ct_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct fc_ns_gid_ft	gpn_ft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * struct zfcp_fc_gspn_req - container for ct header plus GSPN_ID request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * @ct_hdr: FC GS common transport header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * @gspn: GSPN_ID request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) struct zfcp_fc_gspn_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct fc_ct_hdr	ct_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct fc_gid_pn_resp	gspn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * struct zfcp_fc_gspn_rsp - container for ct header plus GSPN_ID response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * @ct_hdr: FC GS common transport header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * @gspn: GSPN_ID response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * @name: The name string of the GSPN_ID response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct zfcp_fc_gspn_rsp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct fc_ct_hdr	ct_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct fc_gspn_resp	gspn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	char			name[FC_SYMBOLIC_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * struct zfcp_fc_rspn_req - container for ct header plus RSPN_ID request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * @ct_hdr: FC GS common transport header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * @rspn: RSPN_ID request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * @name: The name string of the RSPN_ID request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct zfcp_fc_rspn_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct fc_ct_hdr	ct_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct fc_ns_rspn	rspn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	char			name[FC_SYMBOLIC_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * struct zfcp_fc_req - Container for FC ELS and CT requests sent from zfcp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * @ct_els: data required for issuing fsf command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * @sg_req: scatterlist entry for request data, refers to embedded @u submember
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * @sg_rsp: scatterlist entry for response data, refers to embedded @u submember
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * @u: request and response specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * @u.adisc: ADISC specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * @u.adisc.req: ADISC request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * @u.adisc.rsp: ADISC response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * @u.gid_pn: GID_PN specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * @u.gid_pn.req: GID_PN request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * @u.gid_pn.rsp: GID_PN response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * @u.gpn_ft: GPN_FT specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * @u.gpn_ft.sg_rsp2: GPN_FT response, not embedded here, allocated elsewhere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * @u.gpn_ft.req: GPN_FT request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * @u.gspn: GSPN specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * @u.gspn.req: GSPN request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * @u.gspn.rsp: GSPN response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * @u.rspn: RSPN specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * @u.rspn.req: RSPN request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * @u.rspn.rsp: RSPN response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct zfcp_fc_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct zfcp_fsf_ct_els				ct_els;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct scatterlist				sg_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct scatterlist				sg_rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			struct fc_els_adisc		req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			struct fc_els_adisc		rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		} adisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			struct zfcp_fc_gid_pn_req	req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			struct zfcp_fc_gid_pn_rsp	rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		} gid_pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			struct scatterlist sg_rsp2[ZFCP_FC_GPN_FT_NUM_BUFS - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			struct zfcp_fc_gpn_ft_req	req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		} gpn_ft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			struct zfcp_fc_gspn_req		req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			struct zfcp_fc_gspn_rsp		rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		} gspn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			struct zfcp_fc_rspn_req		req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			struct fc_ct_hdr		rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		} rspn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	} u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * enum zfcp_fc_wka_status - FC WKA port status in zfcp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * @ZFCP_FC_WKA_PORT_OFFLINE: Port is closed and not in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * @ZFCP_FC_WKA_PORT_CLOSING: The FSF "close port" request is pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * @ZFCP_FC_WKA_PORT_OPENING: The FSF "open port" request is pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * @ZFCP_FC_WKA_PORT_ONLINE: The port is open and the port handle is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) enum zfcp_fc_wka_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	ZFCP_FC_WKA_PORT_OFFLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	ZFCP_FC_WKA_PORT_CLOSING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	ZFCP_FC_WKA_PORT_OPENING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	ZFCP_FC_WKA_PORT_ONLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * @adapter: Pointer to adapter structure this WKA port belongs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * @completion_wq: Wait for completion of open/close command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * @status: Current status of WKA port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * @refcount: Reference count to keep port open as long as it is in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * @d_id: FC destination id or well-known-address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * @handle: FSF handle for the open WKA port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * @mutex: Mutex used during opening/closing state changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * @work: For delaying the closing of the WKA port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct zfcp_fc_wka_port {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct zfcp_adapter	*adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	wait_queue_head_t	completion_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	enum zfcp_fc_wka_status	status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	atomic_t		refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	u32			d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	u32			handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct mutex		mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct delayed_work	work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * struct zfcp_fc_wka_ports - Data structures for FC generic services
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * @ms: FC Management service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * @ts: FC time service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * @ds: FC directory service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * @as: FC alias service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct zfcp_fc_wka_ports {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct zfcp_fc_wka_port ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct zfcp_fc_wka_port ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct zfcp_fc_wka_port ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct zfcp_fc_wka_port as;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * @fcp: fcp_cmnd to setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	u32 datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	fcp->fc_pri_ta = FCP_PTA_SIMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (scsi->sc_data_direction == DMA_FROM_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		fcp->fc_flags |= FCP_CFL_RDDATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (scsi->sc_data_direction == DMA_TO_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		fcp->fc_flags |= FCP_CFL_WRDATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	datalen = scsi_bufflen(scsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	fcp->fc_dl = cpu_to_be32(datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (scsi_get_prot_type(scsi) == SCSI_PROT_DIF_TYPE1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		datalen += datalen / scsi->device->sector_size * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		fcp->fc_dl = cpu_to_be32(datalen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * zfcp_fc_fcp_tm() - Setup FCP command as task management command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * @fcp: Pointer to FCP_CMND IU to set up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * @dev: Pointer to SCSI_device where to send the task management command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * @tm_flags: Task management flags to setup tm command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	fcp->fc_tm_flags = tm_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * @fcp_rsp: FCP RSP IU to evaluate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * @scsi: SCSI command where to update status and sense buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			  struct scsi_cmnd *scsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct fcp_resp_rsp_info *rsp_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	char *sense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	u32 sense_len, resid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	u8 rsp_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	set_msg_byte(scsi, COMMAND_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	scsi->result |= fcp_rsp->resp.fr_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	rsp_flags = fcp_rsp->resp.fr_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		if (rsp_info->rsp_code == FCP_TMF_CMPL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			set_host_byte(scsi, DID_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			set_host_byte(scsi, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		sense = (char *) &fcp_rsp[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if (rsp_flags & FCP_RSP_LEN_VAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			sense += be32_to_cpu(fcp_rsp->ext.fr_rsp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		sense_len = min_t(u32, be32_to_cpu(fcp_rsp->ext.fr_sns_len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				  SCSI_SENSE_BUFFERSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		memcpy(scsi->sense_buffer, sense, sense_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		resid = be32_to_cpu(fcp_rsp->ext.fr_resid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		scsi_set_resid(scsi, resid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		if (scsi_bufflen(scsi) - resid < scsi->underflow &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		     !(rsp_flags & FCP_SNS_LEN_VAL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		     fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			set_host_byte(scsi, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	} else if (unlikely(rsp_flags & FCP_RESID_OVER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		/* FCP_DL was not sufficient for SCSI data length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		if (fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			set_host_byte(scsi, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) #endif