xref: /linux/drivers/scsi/bfa/bfad_im.h (revision 811f35ff59b6f99ae272d6f5b96bc9e974f88196)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4  * Copyright (c) 2014- QLogic Corporation.
5  * All rights reserved
6  * www.qlogic.com
7  *
8  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9  */
10 
11 #ifndef __BFAD_IM_H__
12 #define __BFAD_IM_H__
13 
14 #include "bfa_fcs.h"
15 
16 #define FCPI_NAME " fcpim"
17 
18 #ifndef KOBJ_NAME_LEN
19 #define KOBJ_NAME_LEN           20
20 #endif
21 
22 bfa_status_t bfad_im_module_init(void);
23 void bfad_im_module_exit(void);
24 bfa_status_t bfad_im_probe(struct bfad_s *bfad);
25 void bfad_im_probe_undo(struct bfad_s *bfad);
26 bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port);
27 void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port);
28 void bfad_im_port_clean(struct bfad_im_port_s *im_port);
29 int  bfad_im_scsi_host_alloc(struct bfad_s *bfad,
30 		struct bfad_im_port_s *im_port, struct device *dev);
31 void bfad_im_scsi_host_free(struct bfad_s *bfad,
32 				struct bfad_im_port_s *im_port);
33 u32 bfad_im_supported_speeds(struct bfa_s *bfa);
34 
35 #define MAX_FCP_TARGET 1024
36 #define MAX_FCP_LUN 16384
37 #define BFAD_TARGET_RESET_TMO 60
38 #define BFAD_LUN_RESET_TMO 60
39 #define BFA_QUEUE_FULL_RAMP_UP_TIME 120
40 
41 /*
42  * itnim flags
43  */
44 #define IO_DONE_BIT			0
45 
46 /**
47  * struct bfad_cmd_priv - private data per SCSI command.
48  * @status: Lowest bit represents IO_DONE. The next seven bits hold a value of
49  * type enum bfi_tskim_status.
50  * @wq: Wait queue used to wait for completion of an operation.
51  */
52 struct bfad_cmd_priv {
53 	unsigned long status;
54 	wait_queue_head_t *wq;
55 };
56 
57 static inline struct bfad_cmd_priv *bfad_priv(struct scsi_cmnd *cmd)
58 {
59 	return scsi_cmd_priv(cmd);
60 }
61 
62 struct bfad_itnim_data_s {
63 	struct bfad_itnim_s *itnim;
64 };
65 
66 struct bfad_im_port_s {
67 	struct bfad_s         *bfad;
68 	struct bfad_port_s    *port;
69 	struct work_struct port_delete_work;
70 	int             idr_id;
71 	u16        cur_scsi_id;
72 	u16	flags;
73 	struct list_head binding_list;
74 	struct Scsi_Host *shost;
75 	struct list_head itnim_mapped_list;
76 	struct fc_vport *fc_vport;
77 };
78 
79 struct bfad_im_port_pointer {
80 	struct bfad_im_port_s *p;
81 };
82 
83 static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host)
84 {
85 	struct bfad_im_port_pointer *im_portp = shost_priv(host);
86 	return im_portp->p;
87 }
88 
89 enum bfad_itnim_state {
90 	ITNIM_STATE_NONE,
91 	ITNIM_STATE_ONLINE,
92 	ITNIM_STATE_OFFLINE_PENDING,
93 	ITNIM_STATE_OFFLINE,
94 	ITNIM_STATE_TIMEOUT,
95 	ITNIM_STATE_FREE,
96 };
97 
98 /*
99  * Per itnim data structure
100  */
101 struct bfad_itnim_s {
102 	struct list_head list_entry;
103 	struct bfa_fcs_itnim_s fcs_itnim;
104 	struct work_struct itnim_work;
105 	u32        flags;
106 	enum bfad_itnim_state state;
107 	struct bfad_im_s *im;
108 	struct bfad_im_port_s *im_port;
109 	struct bfad_rport_s *drv_rport;
110 	struct fc_rport *fc_rport;
111 	struct bfa_itnim_s *bfa_itnim;
112 	u16        scsi_tgt_id;
113 	u16	   channel;
114 	u16        queue_work;
115 	unsigned long	last_ramp_up_time;
116 	unsigned long	last_queue_full_time;
117 };
118 
119 enum bfad_binding_type {
120 	FCP_PWWN_BINDING = 0x1,
121 	FCP_NWWN_BINDING = 0x2,
122 	FCP_FCID_BINDING = 0x3,
123 };
124 
125 struct bfad_fcp_binding {
126 	struct list_head list_entry;
127 	enum bfad_binding_type binding_type;
128 	u16        scsi_target_id;
129 	u32        fc_id;
130 	wwn_t           nwwn;
131 	wwn_t           pwwn;
132 };
133 
134 struct bfad_im_s {
135 	struct bfad_s         *bfad;
136 	struct workqueue_struct *drv_workq;
137 	char            drv_workq_name[KOBJ_NAME_LEN];
138 	struct work_struct	aen_im_notify_work;
139 };
140 
141 #define bfad_get_aen_entry(_drv, _entry) do {				\
142 	unsigned long	_flags;						\
143 	spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags);		\
144 	bfa_q_deq(&(_drv)->free_aen_q, &(_entry));			\
145 	if (_entry)							\
146 		list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q);	\
147 	spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags);	\
148 } while (0)
149 
150 /* post fc_host vendor event */
151 static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry,
152 					     struct bfad_s *drv, int cnt,
153 					     enum bfa_aen_category cat,
154 					     int evt)
155 {
156 	struct timespec64 ts;
157 
158 	ktime_get_real_ts64(&ts);
159 	/*
160 	 * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
161 	 * architectures, or in 2038 if user space interprets it
162 	 * as 'signed'.
163 	 */
164 	entry->aen_tv_sec = ts.tv_sec;
165 	entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC;
166 	entry->bfad_num = drv->inst_no;
167 	entry->seq_num = cnt;
168 	entry->aen_category = cat;
169 	entry->aen_type = evt;
170 	if (drv->bfad_flags & BFAD_FC4_PROBE_DONE)
171 		queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work);
172 }
173 
174 struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
175 				struct bfad_s *);
176 bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
177 void bfad_destroy_workq(struct bfad_im_s *im);
178 void bfad_fc_host_init(struct bfad_im_port_s *im_port);
179 void bfad_scsi_host_free(struct bfad_s *bfad,
180 				 struct bfad_im_port_s *im_port);
181 void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
182 				 struct scsi_device *sdev);
183 void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
184 struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
185 
186 extern struct scsi_host_template bfad_im_scsi_host_template;
187 extern struct scsi_host_template bfad_im_vport_template;
188 extern struct fc_function_template bfad_im_fc_function_template;
189 extern struct fc_function_template bfad_im_vport_fc_function_template;
190 extern struct scsi_transport_template *bfad_im_scsi_transport_template;
191 extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
192 
193 extern const struct attribute_group *bfad_im_host_groups[];
194 extern const struct attribute_group *bfad_im_vport_groups[];
195 
196 irqreturn_t bfad_intx(int irq, void *dev_id);
197 
198 int bfad_im_bsg_request(struct bsg_job *job);
199 int bfad_im_bsg_timeout(struct bsg_job *job);
200 
201 #endif
202