blob: 9c95a1ad56b9009863fe9b2d64a2391f83abb13b [file] [log] [blame]
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -07001/*
2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 */
18#ifndef _FNIC_H_
19#define _FNIC_H_
20
21#include <linux/interrupt.h>
22#include <linux/netdevice.h>
23#include <linux/workqueue.h>
Andrew Mortona737b882010-08-10 18:01:26 -070024#include <linux/bitops.h>
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070025#include <scsi/libfc.h>
Joe Eykholt78112e52009-11-03 11:49:22 -080026#include <scsi/libfcoe.h>
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070027#include "fnic_io.h"
28#include "fnic_res.h"
29#include "vnic_dev.h"
30#include "vnic_wq.h"
31#include "vnic_rq.h"
32#include "vnic_cq.h"
33#include "vnic_wq_copy.h"
34#include "vnic_intr.h"
35#include "vnic_stats.h"
36#include "vnic_scsi.h"
37
38#define DRV_NAME "fnic"
39#define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
Abhijeet Joglekar0c79c742011-06-13 21:21:01 -070040#define DRV_VERSION "1.5.0.2"
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070041#define PFX DRV_NAME ": "
42#define DFX DRV_NAME "%d: "
43
44#define DESC_CLEAN_LOW_WATERMARK 8
45#define FNIC_MAX_IO_REQ 2048 /* scsi_cmnd tag map entries */
46#define FNIC_IO_LOCKS 64 /* IO locks: power of 2 */
47#define FNIC_DFLT_QUEUE_DEPTH 32
48#define FNIC_STATS_RATE_LIMIT 4 /* limit rate at which stats are pulled up */
Vasu Devda87bfa2010-04-09 14:22:59 -070049
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070050/*
51 * Tag bits used for special requests.
52 */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070053#define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */
54#define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */
55#define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */
56#define FNIC_NO_TAG -1
57
58/*
Hiral Patel03298552013-02-12 17:00:58 -080059 * Command flags to identify the type of command and for other future
60 * use.
61 */
Hiral Patel14eb5d92013-02-12 17:01:01 -080062#define FNIC_NO_FLAGS 0
63#define FNIC_IO_INITIALIZED BIT(0)
64#define FNIC_IO_ISSUED BIT(1)
65#define FNIC_IO_DONE BIT(2)
66#define FNIC_IO_REQ_NULL BIT(3)
67#define FNIC_IO_ABTS_PENDING BIT(4)
68#define FNIC_IO_ABORTED BIT(5)
69#define FNIC_IO_ABTS_ISSUED BIT(6)
70#define FNIC_IO_TERM_ISSUED BIT(7)
71#define FNIC_IO_INTERNAL_TERM_ISSUED BIT(8)
72#define FNIC_IO_ABT_TERM_DONE BIT(9)
73#define FNIC_IO_ABT_TERM_REQ_NULL BIT(10)
74#define FNIC_IO_ABT_TERM_TIMED_OUT BIT(11)
75#define FNIC_DEVICE_RESET BIT(12) /* Device reset request */
76#define FNIC_DEV_RST_ISSUED BIT(13)
77#define FNIC_DEV_RST_TIMED_OUT BIT(14)
78#define FNIC_DEV_RST_ABTS_ISSUED BIT(15)
79#define FNIC_DEV_RST_TERM_ISSUED BIT(16)
80#define FNIC_DEV_RST_DONE BIT(17)
81#define FNIC_DEV_RST_REQ_NULL BIT(18)
82#define FNIC_DEV_RST_ABTS_DONE BIT(19)
83#define FNIC_DEV_RST_TERM_DONE BIT(20)
84#define FNIC_DEV_RST_ABTS_PENDING BIT(21)
Hiral Patel03298552013-02-12 17:00:58 -080085
86/*
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070087 * Usage of the scsi_cmnd scratchpad.
88 * These fields are locked by the hashed io_req_lock.
89 */
90#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
91#define CMD_STATE(Cmnd) ((Cmnd)->SCp.phase)
92#define CMD_ABTS_STATUS(Cmnd) ((Cmnd)->SCp.Message)
93#define CMD_LR_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in)
94#define CMD_TAG(Cmnd) ((Cmnd)->SCp.sent_command)
Hiral Patel03298552013-02-12 17:00:58 -080095#define CMD_FLAGS(Cmnd) ((Cmnd)->SCp.Status)
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070096
97#define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */
98
99#define FNIC_LUN_RESET_TIMEOUT 10000 /* mSec */
100#define FNIC_HOST_RESET_TIMEOUT 10000 /* mSec */
101#define FNIC_RMDEVICE_TIMEOUT 1000 /* mSec */
102#define FNIC_HOST_RESET_SETTLE_TIME 30 /* Sec */
Hiral Patel03298552013-02-12 17:00:58 -0800103#define FNIC_ABT_TERM_DELAY_TIMEOUT 500 /* mSec */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700104
105#define FNIC_MAX_FCP_TARGET 256
106
Hiral Patel03298552013-02-12 17:00:58 -0800107/**
108 * state_flags to identify host state along along with fnic's state
109 **/
110#define __FNIC_FLAGS_FWRESET BIT(0) /* fwreset in progress */
111#define __FNIC_FLAGS_BLOCK_IO BIT(1) /* IOs are blocked */
112
113#define FNIC_FLAGS_NONE (0)
114#define FNIC_FLAGS_FWRESET (__FNIC_FLAGS_FWRESET | \
115 __FNIC_FLAGS_BLOCK_IO)
116
117#define FNIC_FLAGS_IO_BLOCKED (__FNIC_FLAGS_BLOCK_IO)
118
119#define fnic_set_state_flags(fnicp, st_flags) \
120 __fnic_set_state_flags(fnicp, st_flags, 0)
121
122#define fnic_clear_state_flags(fnicp, st_flags) \
123 __fnic_set_state_flags(fnicp, st_flags, 1)
124
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700125extern unsigned int fnic_log_level;
126
127#define FNIC_MAIN_LOGGING 0x01
128#define FNIC_FCS_LOGGING 0x02
129#define FNIC_SCSI_LOGGING 0x04
130#define FNIC_ISR_LOGGING 0x08
131
132#define FNIC_CHECK_LOGGING(LEVEL, CMD) \
133do { \
134 if (unlikely(fnic_log_level & LEVEL)) \
135 do { \
136 CMD; \
137 } while (0); \
138} while (0)
139
140#define FNIC_MAIN_DBG(kern_level, host, fmt, args...) \
141 FNIC_CHECK_LOGGING(FNIC_MAIN_LOGGING, \
142 shost_printk(kern_level, host, fmt, ##args);)
143
144#define FNIC_FCS_DBG(kern_level, host, fmt, args...) \
145 FNIC_CHECK_LOGGING(FNIC_FCS_LOGGING, \
146 shost_printk(kern_level, host, fmt, ##args);)
147
148#define FNIC_SCSI_DBG(kern_level, host, fmt, args...) \
149 FNIC_CHECK_LOGGING(FNIC_SCSI_LOGGING, \
150 shost_printk(kern_level, host, fmt, ##args);)
151
152#define FNIC_ISR_DBG(kern_level, host, fmt, args...) \
153 FNIC_CHECK_LOGGING(FNIC_ISR_LOGGING, \
154 shost_printk(kern_level, host, fmt, ##args);)
155
156extern const char *fnic_state_str[];
157
158enum fnic_intx_intr_index {
159 FNIC_INTX_WQ_RQ_COPYWQ,
160 FNIC_INTX_ERR,
161 FNIC_INTX_NOTIFY,
162 FNIC_INTX_INTR_MAX,
163};
164
165enum fnic_msix_intr_index {
166 FNIC_MSIX_RQ,
167 FNIC_MSIX_WQ,
168 FNIC_MSIX_WQ_COPY,
169 FNIC_MSIX_ERR_NOTIFY,
170 FNIC_MSIX_INTR_MAX,
171};
172
173struct fnic_msix_entry {
174 int requested;
175 char devname[IFNAMSIZ];
176 irqreturn_t (*isr)(int, void *);
177 void *devid;
178};
179
180enum fnic_state {
181 FNIC_IN_FC_MODE = 0,
182 FNIC_IN_FC_TRANS_ETH_MODE,
183 FNIC_IN_ETH_MODE,
184 FNIC_IN_ETH_TRANS_FC_MODE,
185};
186
187#define FNIC_WQ_COPY_MAX 1
188#define FNIC_WQ_MAX 1
189#define FNIC_RQ_MAX 1
190#define FNIC_CQ_MAX (FNIC_WQ_COPY_MAX + FNIC_WQ_MAX + FNIC_RQ_MAX)
191
192struct mempool;
193
194/* Per-instance private data structure */
195struct fnic {
196 struct fc_lport *lport;
Joe Eykholt78112e52009-11-03 11:49:22 -0800197 struct fcoe_ctlr ctlr; /* FIP FCoE controller structure */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700198 struct vnic_dev_bar bar0;
199
200 struct msix_entry msix_entry[FNIC_MSIX_INTR_MAX];
201 struct fnic_msix_entry msix[FNIC_MSIX_INTR_MAX];
202
203 struct vnic_stats *stats;
204 unsigned long stats_time; /* time of stats update */
205 struct vnic_nic_cfg *nic_cfg;
206 char name[IFNAMSIZ];
207 struct timer_list notify_timer; /* used for MSI interrupts */
208
209 unsigned int err_intr_offset;
210 unsigned int link_intr_offset;
211
212 unsigned int wq_count;
213 unsigned int cq_count;
214
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700215 u32 vlan_hw_insert:1; /* let hw insert the tag */
216 u32 in_remove:1; /* fnic device in removal */
217 u32 stop_rx_link_events:1; /* stop proc. rx frames, link events */
218
219 struct completion *remove_wait; /* device remove thread blocks */
220
Hiral Patel03298552013-02-12 17:00:58 -0800221 atomic_t in_flight; /* io counter */
222 u32 _reserved; /* fill hole */
223 unsigned long state_flags; /* protected by host lock */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700224 enum fnic_state state;
225 spinlock_t fnic_lock;
226
227 u16 vlan_id; /* VLAN tag including priority */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700228 u8 data_src_addr[ETH_ALEN];
229 u64 fcp_input_bytes; /* internal statistic */
230 u64 fcp_output_bytes; /* internal statistic */
231 u32 link_down_cnt;
232 int link_status;
233
234 struct list_head list;
235 struct pci_dev *pdev;
236 struct vnic_fc_config config;
237 struct vnic_dev *vdev;
238 unsigned int raw_wq_count;
239 unsigned int wq_copy_count;
240 unsigned int rq_count;
241 int fw_ack_index[FNIC_WQ_COPY_MAX];
242 unsigned short fw_ack_recd[FNIC_WQ_COPY_MAX];
243 unsigned short wq_copy_desc_low[FNIC_WQ_COPY_MAX];
244 unsigned int intr_count;
245 u32 __iomem *legacy_pba;
246 struct fnic_host_tag *tags;
247 mempool_t *io_req_pool;
248 mempool_t *io_sgl_pool[FNIC_SGL_NUM_CACHES];
249 spinlock_t io_req_lock[FNIC_IO_LOCKS]; /* locks for scsi cmnds */
250
251 struct work_struct link_work;
252 struct work_struct frame_work;
253 struct sk_buff_head frame_queue;
Joe Eykholt78112e52009-11-03 11:49:22 -0800254 struct sk_buff_head tx_queue;
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700255
256 /* copy work queue cache line section */
257 ____cacheline_aligned struct vnic_wq_copy wq_copy[FNIC_WQ_COPY_MAX];
258 /* completion queue cache line section */
259 ____cacheline_aligned struct vnic_cq cq[FNIC_CQ_MAX];
260
261 spinlock_t wq_copy_lock[FNIC_WQ_COPY_MAX];
262
263 /* work queue cache line section */
264 ____cacheline_aligned struct vnic_wq wq[FNIC_WQ_MAX];
265 spinlock_t wq_lock[FNIC_WQ_MAX];
266
267 /* receive queue cache line section */
268 ____cacheline_aligned struct vnic_rq rq[FNIC_RQ_MAX];
269
270 /* interrupt resource cache line section */
271 ____cacheline_aligned struct vnic_intr intr[FNIC_MSIX_INTR_MAX];
272};
273
Joe Eykholt78112e52009-11-03 11:49:22 -0800274static inline struct fnic *fnic_from_ctlr(struct fcoe_ctlr *fip)
275{
276 return container_of(fip, struct fnic, ctlr);
277}
278
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700279extern struct workqueue_struct *fnic_event_queue;
280extern struct device_attribute *fnic_attrs[];
281
282void fnic_clear_intr_mode(struct fnic *fnic);
283int fnic_set_intr_mode(struct fnic *fnic);
284void fnic_free_intr(struct fnic *fnic);
285int fnic_request_intr(struct fnic *fnic);
286
287int fnic_send(struct fc_lport *, struct fc_frame *);
288void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf);
289void fnic_handle_frame(struct work_struct *work);
290void fnic_handle_link(struct work_struct *work);
291int fnic_rq_cmpl_handler(struct fnic *fnic, int);
292int fnic_alloc_rq_frame(struct vnic_rq *rq);
293void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf);
Joe Eykholt78112e52009-11-03 11:49:22 -0800294void fnic_flush_tx(struct fnic *);
295void fnic_eth_send(struct fcoe_ctlr *, struct sk_buff *skb);
296void fnic_set_port_id(struct fc_lport *, u32, struct fc_frame *);
297void fnic_update_mac(struct fc_lport *, u8 *new);
298void fnic_update_mac_locked(struct fnic *, u8 *new);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700299
Jeff Garzikf2812332010-11-16 02:10:29 -0500300int fnic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700301int fnic_abort_cmd(struct scsi_cmnd *);
302int fnic_device_reset(struct scsi_cmnd *);
303int fnic_host_reset(struct scsi_cmnd *);
304int fnic_reset(struct Scsi_Host *);
305void fnic_scsi_cleanup(struct fc_lport *);
306void fnic_scsi_abort_io(struct fc_lport *);
307void fnic_empty_scsi_cleanup(struct fc_lport *);
308void fnic_exch_mgr_reset(struct fc_lport *, u32, u32);
309int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int);
310int fnic_wq_cmpl_handler(struct fnic *fnic, int);
Joe Eykholt78112e52009-11-03 11:49:22 -0800311int fnic_flogi_reg_handler(struct fnic *fnic, u32);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700312void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
313 struct fcpio_host_req *desc);
314int fnic_fw_reset_handler(struct fnic *fnic);
315void fnic_terminate_rport_io(struct fc_rport *);
316const char *fnic_state_to_str(unsigned int state);
317
318void fnic_log_q_error(struct fnic *fnic);
319void fnic_handle_link_event(struct fnic *fnic);
320
Hiral Patela0bf1ca2013-02-12 17:01:00 -0800321int fnic_is_abts_pending(struct fnic *, struct scsi_cmnd *);
322
Hiral Patel03298552013-02-12 17:00:58 -0800323static inline int
324fnic_chk_state_flags_locked(struct fnic *fnic, unsigned long st_flags)
325{
326 return ((fnic->state_flags & st_flags) == st_flags);
327}
328void __fnic_set_state_flags(struct fnic *, unsigned long, unsigned long);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700329#endif /* _FNIC_H_ */