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