xref: /openbmc/linux/drivers/scsi/snic/snic_disc.h (revision 26b32974)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */
3 
4 #ifndef __SNIC_DISC_H
5 #define __SNIC_DISC_H
6 
7 #include "snic_fwint.h"
8 
9 enum snic_disc_state {
10 	SNIC_DISC_NONE,
11 	SNIC_DISC_INIT,
12 	SNIC_DISC_PENDING,
13 	SNIC_DISC_DONE
14 };
15 
16 struct snic;
17 struct snic_disc {
18 	struct list_head tgt_list;
19 	enum snic_disc_state state;
20 	struct mutex mutex;
21 	u16	disc_id;
22 	u8	req_cnt;
23 	u32	nxt_tgt_id;
24 	u32	rtgt_cnt;
25 	u8	*rtgt_info;
26 	struct delayed_work disc_timeout;
27 	void (*cb)(struct snic *);
28 };
29 
30 #define SNIC_TGT_NAM_LEN	16
31 
32 enum snic_tgt_state {
33 	SNIC_TGT_STAT_NONE,
34 	SNIC_TGT_STAT_INIT,
35 	SNIC_TGT_STAT_ONLINE,	/* Target is Online */
36 	SNIC_TGT_STAT_OFFLINE,	/* Target is Offline */
37 	SNIC_TGT_STAT_DEL,
38 };
39 
40 struct snic_tgt_priv {
41 	struct list_head list;
42 	enum snic_tgt_type typ;
43 	u16 disc_id;
44 	char *name[SNIC_TGT_NAM_LEN];
45 
46 	union {
47 		/*DAS Target specific info */
48 		/*SAN Target specific info */
49 		u8 dummmy;
50 	} u;
51 };
52 
53 /* snic tgt flags */
54 #define SNIC_TGT_SCAN_PENDING	0x01
55 
56 struct snic_tgt {
57 	struct list_head list;
58 	u16	id;
59 	u16	channel;
60 	u32	flags;
61 	u32	scsi_tgt_id;
62 	enum snic_tgt_state state;
63 	struct device dev;
64 	struct work_struct scan_work;
65 	struct work_struct del_work;
66 	struct snic_tgt_priv tdata;
67 };
68 
69 
70 struct snic_fw_req;
71 
72 void snic_disc_init(struct snic_disc *);
73 int snic_disc_start(struct snic *);
74 void snic_disc_term(struct snic *);
75 int snic_report_tgt_cmpl_handler(struct snic *, struct snic_fw_req *);
76 int snic_tgtinfo_cmpl_handler(struct snic *snic, struct snic_fw_req *fwreq);
77 void snic_process_report_tgts_rsp(struct work_struct *);
78 void snic_handle_tgt_disc(struct work_struct *);
79 void snic_handle_disc(struct work_struct *);
80 void snic_tgt_dev_release(struct device *);
81 void snic_tgt_del_all(struct snic *);
82 
83 #define dev_to_tgt(d) \
84 	container_of(d, struct snic_tgt, dev)
85 
86 static inline int
87 is_snic_target(struct device *dev)
88 {
89 	return dev->release == snic_tgt_dev_release;
90 }
91 
92 #define starget_to_tgt(st)	\
93 	(is_snic_target(((struct scsi_target *) st)->dev.parent) ? \
94 		dev_to_tgt(st->dev.parent) : NULL)
95 
96 #define snic_tgt_to_shost(t)	\
97 	dev_to_shost(t->dev.parent)
98 
99 static inline int
100 snic_tgt_chkready(struct snic_tgt *tgt)
101 {
102 	if (tgt->state == SNIC_TGT_STAT_ONLINE)
103 		return 0;
104 	else
105 		return DID_NO_CONNECT << 16;
106 }
107 
108 const char *snic_tgt_state_to_str(int);
109 int snic_tgt_scsi_abort_io(struct snic_tgt *);
110 #endif /* end of  __SNIC_DISC_H */
111