blob: f6c1023e502a13cd04f19551d4893ec5f9014129 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
18#ifndef __BFAD_IM_H__
19#define __BFAD_IM_H__
20
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070021#include "bfa_fcs.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070022
23#define FCPI_NAME " fcpim"
24
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070025#ifndef KOBJ_NAME_LEN
26#define KOBJ_NAME_LEN 20
27#endif
28
Jing Huang7725ccf2009-09-23 17:46:15 -070029bfa_status_t bfad_im_module_init(void);
30void bfad_im_module_exit(void);
31bfa_status_t bfad_im_probe(struct bfad_s *bfad);
32void bfad_im_probe_undo(struct bfad_s *bfad);
Jing Huang7725ccf2009-09-23 17:46:15 -070033bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port);
34void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port);
Jing Huang7725ccf2009-09-23 17:46:15 -070035void bfad_im_port_clean(struct bfad_im_port_s *im_port);
36int bfad_im_scsi_host_alloc(struct bfad_s *bfad,
Jing Huangb5042932010-03-19 11:05:39 -070037 struct bfad_im_port_s *im_port, struct device *dev);
Jing Huang7725ccf2009-09-23 17:46:15 -070038void bfad_im_scsi_host_free(struct bfad_s *bfad,
39 struct bfad_im_port_s *im_port);
Krishna Gudipati6192bd72012-05-11 17:49:59 -070040u32 bfad_im_supported_speeds(struct bfa_s *bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -070041
42#define MAX_FCP_TARGET 1024
43#define MAX_FCP_LUN 16384
44#define BFAD_TARGET_RESET_TMO 60
45#define BFAD_LUN_RESET_TMO 60
46#define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
47#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
71enum bfad_itnim_state {
72 ITNIM_STATE_NONE,
73 ITNIM_STATE_ONLINE,
74 ITNIM_STATE_OFFLINE_PENDING,
75 ITNIM_STATE_OFFLINE,
76 ITNIM_STATE_TIMEOUT,
77 ITNIM_STATE_FREE,
78};
79
80/*
81 * Per itnim data structure
82 */
83struct bfad_itnim_s {
84 struct list_head list_entry;
85 struct bfa_fcs_itnim_s fcs_itnim;
86 struct work_struct itnim_work;
87 u32 flags;
88 enum bfad_itnim_state state;
89 struct bfad_im_s *im;
90 struct bfad_im_port_s *im_port;
91 struct bfad_rport_s *drv_rport;
92 struct fc_rport *fc_rport;
93 struct bfa_itnim_s *bfa_itnim;
94 u16 scsi_tgt_id;
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -080095 u16 channel;
Jing Huang7725ccf2009-09-23 17:46:15 -070096 u16 queue_work;
97 unsigned long last_ramp_up_time;
98 unsigned long last_queue_full_time;
99};
100
101enum bfad_binding_type {
102 FCP_PWWN_BINDING = 0x1,
103 FCP_NWWN_BINDING = 0x2,
104 FCP_FCID_BINDING = 0x3,
105};
106
107struct bfad_fcp_binding {
108 struct list_head list_entry;
109 enum bfad_binding_type binding_type;
110 u16 scsi_target_id;
111 u32 fc_id;
112 wwn_t nwwn;
113 wwn_t pwwn;
114};
115
116struct bfad_im_s {
117 struct bfad_s *bfad;
118 struct workqueue_struct *drv_workq;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700119 char drv_workq_name[KOBJ_NAME_LEN];
Krishna Gudipati7826f302011-07-20 16:59:13 -0700120 struct work_struct aen_im_notify_work;
Jing Huang7725ccf2009-09-23 17:46:15 -0700121};
122
Krishna Gudipati7826f302011-07-20 16:59:13 -0700123#define bfad_get_aen_entry(_drv, _entry) do { \
124 unsigned long _flags; \
125 spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags); \
126 bfa_q_deq(&(_drv)->free_aen_q, &(_entry)); \
127 if (_entry) \
128 list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \
129 spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \
130} while (0)
131
132/* post fc_host vendor event */
133#define bfad_im_post_vendor_event(_entry, _drv, _cnt, _cat, _evt) do { \
134 do_gettimeofday(&(_entry)->aen_tv); \
135 (_entry)->bfad_num = (_drv)->inst_no; \
136 (_entry)->seq_num = (_cnt); \
137 (_entry)->aen_category = (_cat); \
138 (_entry)->aen_type = (_evt); \
139 if ((_drv)->bfad_flags & BFAD_FC4_PROBE_DONE) \
140 queue_work((_drv)->im->drv_workq, \
141 &(_drv)->im->aen_im_notify_work); \
142} while (0)
143
Maggie Zhangf16a1752010-12-09 19:12:32 -0800144struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
Jing Huang7725ccf2009-09-23 17:46:15 -0700145 struct bfad_s *);
Maggie Zhangf16a1752010-12-09 19:12:32 -0800146bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
147void bfad_destroy_workq(struct bfad_im_s *im);
148void bfad_fc_host_init(struct bfad_im_port_s *im_port);
149void bfad_scsi_host_free(struct bfad_s *bfad,
Jing Huang7725ccf2009-09-23 17:46:15 -0700150 struct bfad_im_port_s *im_port);
Maggie Zhangf16a1752010-12-09 19:12:32 -0800151void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -0700152 struct scsi_device *sdev);
Maggie Zhangf16a1752010-12-09 19:12:32 -0800153void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
154struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700155
156extern struct scsi_host_template bfad_im_scsi_host_template;
157extern struct scsi_host_template bfad_im_vport_template;
158extern struct fc_function_template bfad_im_fc_function_template;
Jing Huangb5042932010-03-19 11:05:39 -0700159extern struct fc_function_template bfad_im_vport_fc_function_template;
Jing Huang7725ccf2009-09-23 17:46:15 -0700160extern struct scsi_transport_template *bfad_im_scsi_transport_template;
Jing Huangb5042932010-03-19 11:05:39 -0700161extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
Jing Huang7725ccf2009-09-23 17:46:15 -0700162
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700163extern struct device_attribute *bfad_im_host_attrs[];
164extern struct device_attribute *bfad_im_vport_attrs[];
165
166irqreturn_t bfad_intx(int irq, void *dev_id);
167
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700168int bfad_im_bsg_request(struct fc_bsg_job *job);
169int bfad_im_bsg_timeout(struct fc_bsg_job *job);
170
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -0800171/*
172 * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
173 * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
174 *
175 * Internally iterate's over all the ITNIM's part of the im_port & set's the
176 * sdev_bflags for the scsi_device associated with LUN #0.
177 */
178#define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \
179 struct scsi_device *__sdev = NULL; \
180 struct bfad_itnim_s *__itnim = NULL; \
181 u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \
182 list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \
183 list_entry) { \
184 __sdev = scsi_device_lookup((__im_port)->shost, \
185 __itnim->channel, \
186 __itnim->scsi_tgt_id, 0); \
187 if (__sdev) { \
188 if ((__lunmask_cfg) == BFA_TRUE) \
189 __sdev->sdev_bflags |= scan_flags; \
190 else \
191 __sdev->sdev_bflags &= ~scan_flags; \
192 scsi_device_put(__sdev); \
193 } \
194 } \
195} while (0)
196
Jing Huang7725ccf2009-09-23 17:46:15 -0700197#endif