blob: bd4ac187fd8e7830bcee23d1ee1e975582830aad [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07006 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05007 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Jing Huang7725ccf2009-09-23 17:46:15 -07008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
19#ifndef __BFAD_IM_H__
20#define __BFAD_IM_H__
21
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070022#include "bfa_fcs.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070023
24#define FCPI_NAME " fcpim"
25
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070026#ifndef KOBJ_NAME_LEN
27#define KOBJ_NAME_LEN 20
28#endif
29
Jing Huang7725ccf2009-09-23 17:46:15 -070030bfa_status_t bfad_im_module_init(void);
31void bfad_im_module_exit(void);
32bfa_status_t bfad_im_probe(struct bfad_s *bfad);
33void bfad_im_probe_undo(struct bfad_s *bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -070034bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port);
35void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port);
Jing Huang7725ccf2009-09-23 17:46:15 -070036void bfad_im_port_clean(struct bfad_im_port_s *im_port);
37int bfad_im_scsi_host_alloc(struct bfad_s *bfad,
Jing Huangb5042932010-03-19 11:05:39 -070038 struct bfad_im_port_s *im_port, struct device *dev);
Jing Huang7725ccf2009-09-23 17:46:15 -070039void bfad_im_scsi_host_free(struct bfad_s *bfad,
40 struct bfad_im_port_s *im_port);
Krishna Gudipati6192bd72012-05-11 17:49:59 -070041u32 bfad_im_supported_speeds(struct bfa_s *bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -070042
43#define MAX_FCP_TARGET 1024
44#define MAX_FCP_LUN 16384
45#define BFAD_TARGET_RESET_TMO 60
46#define BFAD_LUN_RESET_TMO 60
Jing Huang7725ccf2009-09-23 17:46:15 -070047#define BFA_QUEUE_FULL_RAMP_UP_TIME 120
Jing Huang7725ccf2009-09-23 17:46:15 -070048
49/*
50 * itnim flags
51 */
Jing Huang7725ccf2009-09-23 17:46:15 -070052#define IO_DONE_BIT 0
53
54struct bfad_itnim_data_s {
55 struct bfad_itnim_s *itnim;
56};
57
58struct bfad_im_port_s {
59 struct bfad_s *bfad;
60 struct bfad_port_s *port;
61 struct work_struct port_delete_work;
62 int idr_id;
63 u16 cur_scsi_id;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070064 u16 flags;
Jing Huang7725ccf2009-09-23 17:46:15 -070065 struct list_head binding_list;
66 struct Scsi_Host *shost;
67 struct list_head itnim_mapped_list;
Jing Huangb5042932010-03-19 11:05:39 -070068 struct fc_vport *fc_vport;
Jing Huang7725ccf2009-09-23 17:46:15 -070069};
70
Arnd Bergmann48d83282017-12-06 15:14:18 +010071struct bfad_im_port_pointer {
72 struct bfad_im_port_s *p;
73};
74
75static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host)
76{
77 struct bfad_im_port_pointer *im_portp = shost_priv(host);
78 return im_portp->p;
79}
80
Jing Huang7725ccf2009-09-23 17:46:15 -070081enum bfad_itnim_state {
82 ITNIM_STATE_NONE,
83 ITNIM_STATE_ONLINE,
84 ITNIM_STATE_OFFLINE_PENDING,
85 ITNIM_STATE_OFFLINE,
86 ITNIM_STATE_TIMEOUT,
87 ITNIM_STATE_FREE,
88};
89
90/*
91 * Per itnim data structure
92 */
93struct bfad_itnim_s {
94 struct list_head list_entry;
95 struct bfa_fcs_itnim_s fcs_itnim;
96 struct work_struct itnim_work;
97 u32 flags;
98 enum bfad_itnim_state state;
99 struct bfad_im_s *im;
100 struct bfad_im_port_s *im_port;
101 struct bfad_rport_s *drv_rport;
102 struct fc_rport *fc_rport;
103 struct bfa_itnim_s *bfa_itnim;
104 u16 scsi_tgt_id;
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -0800105 u16 channel;
Jing Huang7725ccf2009-09-23 17:46:15 -0700106 u16 queue_work;
107 unsigned long last_ramp_up_time;
108 unsigned long last_queue_full_time;
109};
110
111enum bfad_binding_type {
112 FCP_PWWN_BINDING = 0x1,
113 FCP_NWWN_BINDING = 0x2,
114 FCP_FCID_BINDING = 0x3,
115};
116
117struct bfad_fcp_binding {
118 struct list_head list_entry;
119 enum bfad_binding_type binding_type;
120 u16 scsi_target_id;
121 u32 fc_id;
122 wwn_t nwwn;
123 wwn_t pwwn;
124};
125
126struct bfad_im_s {
127 struct bfad_s *bfad;
128 struct workqueue_struct *drv_workq;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700129 char drv_workq_name[KOBJ_NAME_LEN];
Krishna Gudipati7826f302011-07-20 16:59:13 -0700130 struct work_struct aen_im_notify_work;
Jing Huang7725ccf2009-09-23 17:46:15 -0700131};
132
Krishna Gudipati7826f302011-07-20 16:59:13 -0700133#define bfad_get_aen_entry(_drv, _entry) do { \
134 unsigned long _flags; \
135 spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags); \
136 bfa_q_deq(&(_drv)->free_aen_q, &(_entry)); \
137 if (_entry) \
138 list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \
139 spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \
140} while (0)
141
142/* post fc_host vendor event */
Arnd Bergmann6d4bc342017-11-10 16:37:14 +0100143static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry,
144 struct bfad_s *drv, int cnt,
145 enum bfa_aen_category cat,
Nathan Chancellor06815ae2018-09-27 16:56:52 -0700146 int evt)
Arnd Bergmann6d4bc342017-11-10 16:37:14 +0100147{
148 struct timespec64 ts;
149
150 ktime_get_real_ts64(&ts);
151 /*
152 * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
153 * architectures, or in 2038 if user space interprets it
154 * as 'signed'.
155 */
156 entry->aen_tv_sec = ts.tv_sec;
157 entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC;
158 entry->bfad_num = drv->inst_no;
159 entry->seq_num = cnt;
160 entry->aen_category = cat;
161 entry->aen_type = evt;
162 if (drv->bfad_flags & BFAD_FC4_PROBE_DONE)
163 queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work);
164}
Krishna Gudipati7826f302011-07-20 16:59:13 -0700165
Maggie Zhangf16a1752010-12-09 19:12:32 -0800166struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
Jing Huang7725ccf2009-09-23 17:46:15 -0700167 struct bfad_s *);
Maggie Zhangf16a1752010-12-09 19:12:32 -0800168bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
169void bfad_destroy_workq(struct bfad_im_s *im);
170void bfad_fc_host_init(struct bfad_im_port_s *im_port);
171void bfad_scsi_host_free(struct bfad_s *bfad,
Jing Huang7725ccf2009-09-23 17:46:15 -0700172 struct bfad_im_port_s *im_port);
Maggie Zhangf16a1752010-12-09 19:12:32 -0800173void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -0700174 struct scsi_device *sdev);
Maggie Zhangf16a1752010-12-09 19:12:32 -0800175void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
176struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700177
178extern struct scsi_host_template bfad_im_scsi_host_template;
179extern struct scsi_host_template bfad_im_vport_template;
180extern struct fc_function_template bfad_im_fc_function_template;
Jing Huangb5042932010-03-19 11:05:39 -0700181extern struct fc_function_template bfad_im_vport_fc_function_template;
Jing Huang7725ccf2009-09-23 17:46:15 -0700182extern struct scsi_transport_template *bfad_im_scsi_transport_template;
Jing Huangb5042932010-03-19 11:05:39 -0700183extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
Jing Huang7725ccf2009-09-23 17:46:15 -0700184
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700185extern struct device_attribute *bfad_im_host_attrs[];
186extern struct device_attribute *bfad_im_vport_attrs[];
187
188irqreturn_t bfad_intx(int irq, void *dev_id);
189
Johannes Thumshirn75cc8cf2016-11-17 10:31:19 +0100190int bfad_im_bsg_request(struct bsg_job *job);
191int bfad_im_bsg_timeout(struct bsg_job *job);
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700192
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -0800193/*
194 * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
195 * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
196 *
197 * Internally iterate's over all the ITNIM's part of the im_port & set's the
198 * sdev_bflags for the scsi_device associated with LUN #0.
199 */
200#define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \
201 struct scsi_device *__sdev = NULL; \
202 struct bfad_itnim_s *__itnim = NULL; \
203 u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \
204 list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \
205 list_entry) { \
206 __sdev = scsi_device_lookup((__im_port)->shost, \
207 __itnim->channel, \
208 __itnim->scsi_tgt_id, 0); \
209 if (__sdev) { \
210 if ((__lunmask_cfg) == BFA_TRUE) \
211 __sdev->sdev_bflags |= scan_flags; \
212 else \
213 __sdev->sdev_bflags &= ~scan_flags; \
214 scsi_device_put(__sdev); \
215 } \
216 } \
217} while (0)
218
Jing Huang7725ccf2009-09-23 17:46:15 -0700219#endif