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
46 struct bfad_itnim_data_s
{
47 struct bfad_itnim_s
*itnim
;
50 struct bfad_im_port_s
{
52 struct bfad_port_s
*port
;
53 struct work_struct port_delete_work
;
57 struct list_head binding_list
;
58 struct Scsi_Host
*shost
;
59 struct list_head itnim_mapped_list
;
60 struct fc_vport
*fc_vport
;
63 struct bfad_im_port_pointer
{
64 struct bfad_im_port_s
*p
;
67 static inline struct bfad_im_port_s
*bfad_get_im_port(struct Scsi_Host
*host
)
69 struct bfad_im_port_pointer
*im_portp
= shost_priv(host
);
73 enum bfad_itnim_state
{
76 ITNIM_STATE_OFFLINE_PENDING
,
83 * Per itnim data structure
86 struct list_head list_entry
;
87 struct bfa_fcs_itnim_s fcs_itnim
;
88 struct work_struct itnim_work
;
90 enum bfad_itnim_state state
;
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
;
99 unsigned long last_ramp_up_time
;
100 unsigned long last_queue_full_time
;
103 enum bfad_binding_type
{
104 FCP_PWWN_BINDING
= 0x1,
105 FCP_NWWN_BINDING
= 0x2,
106 FCP_FCID_BINDING
= 0x3,
109 struct bfad_fcp_binding
{
110 struct list_head list_entry
;
111 enum bfad_binding_type binding_type
;
120 struct workqueue_struct
*drv_workq
;
121 char drv_workq_name
[KOBJ_NAME_LEN
];
122 struct work_struct aen_im_notify_work
;
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)); \
130 list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \
131 spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \
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
,
140 struct timespec64 ts
;
142 ktime_get_real_ts64(&ts
);
144 * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
145 * architectures, or in 2038 if user space interprets it
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
);
158 struct Scsi_Host
*bfad_scsi_host_alloc(struct bfad_im_port_s
*im_port
,
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
);
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
;
177 extern struct device_attribute
*bfad_im_host_attrs
[];
178 extern struct device_attribute
*bfad_im_vport_attrs
[];
180 irqreturn_t
bfad_intx(int irq
, void *dev_id
);
182 int bfad_im_bsg_request(struct bsg_job
*job
);
183 int bfad_im_bsg_timeout(struct bsg_job
*job
);
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
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.
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), \
198 __sdev = scsi_device_lookup((__im_port)->shost, \
200 __itnim->scsi_tgt_id, 0); \
202 if ((__lunmask_cfg) == BFA_TRUE) \
203 __sdev->sdev_bflags |= scan_flags; \
205 __sdev->sdev_bflags &= ~scan_flags; \
206 scsi_device_put(__sdev); \