xref: /linux/drivers/scsi/bfa/bfad_im.h (revision 6fdcba32711044c35c0e1b094cbd8f3f0b4472c9)
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 struct bfad_itnim_data_s {
47 	struct bfad_itnim_s *itnim;
48 };
49 
50 struct bfad_im_port_s {
51 	struct bfad_s         *bfad;
52 	struct bfad_port_s    *port;
53 	struct work_struct port_delete_work;
54 	int             idr_id;
55 	u16        cur_scsi_id;
56 	u16	flags;
57 	struct list_head binding_list;
58 	struct Scsi_Host *shost;
59 	struct list_head itnim_mapped_list;
60 	struct fc_vport *fc_vport;
61 };
62 
63 struct bfad_im_port_pointer {
64 	struct bfad_im_port_s *p;
65 };
66 
67 static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host)
68 {
69 	struct bfad_im_port_pointer *im_portp = shost_priv(host);
70 	return im_portp->p;
71 }
72 
73 enum bfad_itnim_state {
74 	ITNIM_STATE_NONE,
75 	ITNIM_STATE_ONLINE,
76 	ITNIM_STATE_OFFLINE_PENDING,
77 	ITNIM_STATE_OFFLINE,
78 	ITNIM_STATE_TIMEOUT,
79 	ITNIM_STATE_FREE,
80 };
81 
82 /*
83  * Per itnim data structure
84  */
85 struct bfad_itnim_s {
86 	struct list_head list_entry;
87 	struct bfa_fcs_itnim_s fcs_itnim;
88 	struct work_struct itnim_work;
89 	u32        flags;
90 	enum bfad_itnim_state state;
91 	struct bfad_im_s *im;
92 	struct bfad_im_port_s *im_port;
93 	struct bfad_rport_s *drv_rport;
94 	struct fc_rport *fc_rport;
95 	struct bfa_itnim_s *bfa_itnim;
96 	u16        scsi_tgt_id;
97 	u16	   channel;
98 	u16        queue_work;
99 	unsigned long	last_ramp_up_time;
100 	unsigned long	last_queue_full_time;
101 };
102 
103 enum bfad_binding_type {
104 	FCP_PWWN_BINDING = 0x1,
105 	FCP_NWWN_BINDING = 0x2,
106 	FCP_FCID_BINDING = 0x3,
107 };
108 
109 struct bfad_fcp_binding {
110 	struct list_head list_entry;
111 	enum bfad_binding_type binding_type;
112 	u16        scsi_target_id;
113 	u32        fc_id;
114 	wwn_t           nwwn;
115 	wwn_t           pwwn;
116 };
117 
118 struct bfad_im_s {
119 	struct bfad_s         *bfad;
120 	struct workqueue_struct *drv_workq;
121 	char            drv_workq_name[KOBJ_NAME_LEN];
122 	struct work_struct	aen_im_notify_work;
123 };
124 
125 #define bfad_get_aen_entry(_drv, _entry) do {				\
126 	unsigned long	_flags;						\
127 	spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags);		\
128 	bfa_q_deq(&(_drv)->free_aen_q, &(_entry));			\
129 	if (_entry)							\
130 		list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q);	\
131 	spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags);	\
132 } while (0)
133 
134 /* post fc_host vendor event */
135 static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry,
136 					     struct bfad_s *drv, int cnt,
137 					     enum bfa_aen_category cat,
138 					     int evt)
139 {
140 	struct timespec64 ts;
141 
142 	ktime_get_real_ts64(&ts);
143 	/*
144 	 * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
145 	 * architectures, or in 2038 if user space interprets it
146 	 * as 'signed'.
147 	 */
148 	entry->aen_tv_sec = ts.tv_sec;
149 	entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC;
150 	entry->bfad_num = drv->inst_no;
151 	entry->seq_num = cnt;
152 	entry->aen_category = cat;
153 	entry->aen_type = evt;
154 	if (drv->bfad_flags & BFAD_FC4_PROBE_DONE)
155 		queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work);
156 }
157 
158 struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
159 				struct bfad_s *);
160 bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
161 void bfad_destroy_workq(struct bfad_im_s *im);
162 void bfad_fc_host_init(struct bfad_im_port_s *im_port);
163 void bfad_scsi_host_free(struct bfad_s *bfad,
164 				 struct bfad_im_port_s *im_port);
165 void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
166 				 struct scsi_device *sdev);
167 void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
168 struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
169 
170 extern struct scsi_host_template bfad_im_scsi_host_template;
171 extern struct scsi_host_template bfad_im_vport_template;
172 extern struct fc_function_template bfad_im_fc_function_template;
173 extern struct fc_function_template bfad_im_vport_fc_function_template;
174 extern struct scsi_transport_template *bfad_im_scsi_transport_template;
175 extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
176 
177 extern struct device_attribute *bfad_im_host_attrs[];
178 extern struct device_attribute *bfad_im_vport_attrs[];
179 
180 irqreturn_t bfad_intx(int irq, void *dev_id);
181 
182 int bfad_im_bsg_request(struct bsg_job *job);
183 int bfad_im_bsg_timeout(struct bsg_job *job);
184 
185 /*
186  * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
187  * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
188  *
189  * Internally iterate's over all the ITNIM's part of the im_port & set's the
190  * sdev_bflags for the scsi_device associated with LUN #0.
191  */
192 #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do {		\
193 	struct scsi_device *__sdev = NULL;				\
194 	struct bfad_itnim_s *__itnim = NULL;				\
195 	u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN;		\
196 	list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list),	\
197 			    list_entry) {				\
198 		__sdev = scsi_device_lookup((__im_port)->shost,		\
199 					    __itnim->channel,		\
200 					    __itnim->scsi_tgt_id, 0);	\
201 		if (__sdev) {						\
202 			if ((__lunmask_cfg) == BFA_TRUE)		\
203 				__sdev->sdev_bflags |= scan_flags;	\
204 			else						\
205 				__sdev->sdev_bflags &= ~scan_flags;	\
206 			scsi_device_put(__sdev);			\
207 		}							\
208 	}								\
209 } while (0)
210 
211 #endif
212