1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4 * Copyright (c) 2014- QLogic Corporation.
8 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
16 #define FCPI_NAME " fcpim"
19 #define KOBJ_NAME_LEN 20
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);
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
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.
52 struct bfad_cmd_priv {
54 wait_queue_head_t *wq;
57 static inline struct bfad_cmd_priv *bfad_priv(struct scsi_cmnd *cmd)
59 return scsi_cmd_priv(cmd);
62 struct bfad_itnim_data_s {
63 struct bfad_itnim_s *itnim;
66 struct bfad_im_port_s {
68 struct bfad_port_s *port;
69 struct work_struct port_delete_work;
73 struct list_head binding_list;
74 struct Scsi_Host *shost;
75 struct list_head itnim_mapped_list;
76 struct fc_vport *fc_vport;
79 struct bfad_im_port_pointer {
80 struct bfad_im_port_s *p;
83 static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host)
85 struct bfad_im_port_pointer *im_portp = shost_priv(host);
89 enum bfad_itnim_state {
92 ITNIM_STATE_OFFLINE_PENDING,
99 * Per itnim data structure
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;
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;
115 unsigned long last_ramp_up_time;
116 unsigned long last_queue_full_time;
119 enum bfad_binding_type {
120 FCP_PWWN_BINDING = 0x1,
121 FCP_NWWN_BINDING = 0x2,
122 FCP_FCID_BINDING = 0x3,
125 struct bfad_fcp_binding {
126 struct list_head list_entry;
127 enum bfad_binding_type binding_type;
136 struct workqueue_struct *drv_workq;
137 char drv_workq_name[KOBJ_NAME_LEN];
138 struct work_struct aen_im_notify_work;
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)); \
146 list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \
147 spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \
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,
156 struct timespec64 ts;
158 ktime_get_real_ts64(&ts);
160 * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
161 * architectures, or in 2038 if user space interprets it
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);
174 struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
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);
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;
193 extern const struct attribute_group *bfad_im_host_groups[];
194 extern const struct attribute_group *bfad_im_vport_groups[];
196 irqreturn_t bfad_intx(int irq, void *dev_id);
198 int bfad_im_bsg_request(struct bsg_job *job);
199 int bfad_im_bsg_timeout(struct bsg_job *job);
202 * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
203 * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
205 * Internally iterate's over all the ITNIM's part of the im_port & set's the
206 * sdev_bflags for the scsi_device associated with LUN #0.
208 #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \
209 struct scsi_device *__sdev = NULL; \
210 struct bfad_itnim_s *__itnim = NULL; \
211 u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \
212 list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \
214 __sdev = scsi_device_lookup((__im_port)->shost, \
216 __itnim->scsi_tgt_id, 0); \
218 if ((__lunmask_cfg) == BFA_TRUE) \
219 __sdev->sdev_bflags |= scan_flags; \
221 __sdev->sdev_bflags &= ~scan_flags; \
222 scsi_device_put(__sdev); \