blob: e4dd3d7cd236520a35487e5acabb77559ec78f30 [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"
Hiral Patel4d7007b2013-02-12 17:01:02 -080029#include "fnic_trace.h"
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070030#include "vnic_dev.h"
31#include "vnic_wq.h"
32#include "vnic_rq.h"
33#include "vnic_cq.h"
34#include "vnic_wq_copy.h"
35#include "vnic_intr.h"
36#include "vnic_stats.h"
37#include "vnic_scsi.h"
38
39#define DRV_NAME "fnic"
40#define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
Chris Leeche09056b2013-07-23 13:04:58 -070041#define DRV_VERSION "1.5.0.23"
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070042#define PFX DRV_NAME ": "
43#define DFX DRV_NAME "%d: "
44
45#define DESC_CLEAN_LOW_WATERMARK 8
Hiral Patelfc857992013-09-09 13:31:51 -070046#define FNIC_UCSM_DFLT_THROTTLE_CNT_BLD 16 /* UCSM default throttle count */
47#define FNIC_MIN_IO_REQ 256 /* Min IO throttle count */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070048#define FNIC_MAX_IO_REQ 2048 /* scsi_cmnd tag map entries */
49#define FNIC_IO_LOCKS 64 /* IO locks: power of 2 */
50#define FNIC_DFLT_QUEUE_DEPTH 32
51#define FNIC_STATS_RATE_LIMIT 4 /* limit rate at which stats are pulled up */
Vasu Devda87bfa2010-04-09 14:22:59 -070052
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070053/*
54 * Tag bits used for special requests.
55 */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070056#define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */
57#define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */
58#define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */
59#define FNIC_NO_TAG -1
60
61/*
Hiral Patel03298552013-02-12 17:00:58 -080062 * Command flags to identify the type of command and for other future
63 * use.
64 */
Hiral Patel14eb5d92013-02-12 17:01:01 -080065#define FNIC_NO_FLAGS 0
66#define FNIC_IO_INITIALIZED BIT(0)
67#define FNIC_IO_ISSUED BIT(1)
68#define FNIC_IO_DONE BIT(2)
69#define FNIC_IO_REQ_NULL BIT(3)
70#define FNIC_IO_ABTS_PENDING BIT(4)
71#define FNIC_IO_ABORTED BIT(5)
72#define FNIC_IO_ABTS_ISSUED BIT(6)
73#define FNIC_IO_TERM_ISSUED BIT(7)
74#define FNIC_IO_INTERNAL_TERM_ISSUED BIT(8)
75#define FNIC_IO_ABT_TERM_DONE BIT(9)
76#define FNIC_IO_ABT_TERM_REQ_NULL BIT(10)
77#define FNIC_IO_ABT_TERM_TIMED_OUT BIT(11)
78#define FNIC_DEVICE_RESET BIT(12) /* Device reset request */
79#define FNIC_DEV_RST_ISSUED BIT(13)
80#define FNIC_DEV_RST_TIMED_OUT BIT(14)
81#define FNIC_DEV_RST_ABTS_ISSUED BIT(15)
82#define FNIC_DEV_RST_TERM_ISSUED BIT(16)
83#define FNIC_DEV_RST_DONE BIT(17)
84#define FNIC_DEV_RST_REQ_NULL BIT(18)
85#define FNIC_DEV_RST_ABTS_DONE BIT(19)
86#define FNIC_DEV_RST_TERM_DONE BIT(20)
87#define FNIC_DEV_RST_ABTS_PENDING BIT(21)
Hiral Patel03298552013-02-12 17:00:58 -080088
89/*
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070090 * Usage of the scsi_cmnd scratchpad.
91 * These fields are locked by the hashed io_req_lock.
92 */
93#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
94#define CMD_STATE(Cmnd) ((Cmnd)->SCp.phase)
95#define CMD_ABTS_STATUS(Cmnd) ((Cmnd)->SCp.Message)
96#define CMD_LR_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in)
97#define CMD_TAG(Cmnd) ((Cmnd)->SCp.sent_command)
Hiral Patel03298552013-02-12 17:00:58 -080098#define CMD_FLAGS(Cmnd) ((Cmnd)->SCp.Status)
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -070099
100#define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */
101
102#define FNIC_LUN_RESET_TIMEOUT 10000 /* mSec */
103#define FNIC_HOST_RESET_TIMEOUT 10000 /* mSec */
104#define FNIC_RMDEVICE_TIMEOUT 1000 /* mSec */
105#define FNIC_HOST_RESET_SETTLE_TIME 30 /* Sec */
Hiral Patel03298552013-02-12 17:00:58 -0800106#define FNIC_ABT_TERM_DELAY_TIMEOUT 500 /* mSec */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700107
108#define FNIC_MAX_FCP_TARGET 256
109
Hiral Patel03298552013-02-12 17:00:58 -0800110/**
111 * state_flags to identify host state along along with fnic's state
112 **/
113#define __FNIC_FLAGS_FWRESET BIT(0) /* fwreset in progress */
114#define __FNIC_FLAGS_BLOCK_IO BIT(1) /* IOs are blocked */
115
116#define FNIC_FLAGS_NONE (0)
117#define FNIC_FLAGS_FWRESET (__FNIC_FLAGS_FWRESET | \
118 __FNIC_FLAGS_BLOCK_IO)
119
120#define FNIC_FLAGS_IO_BLOCKED (__FNIC_FLAGS_BLOCK_IO)
121
122#define fnic_set_state_flags(fnicp, st_flags) \
123 __fnic_set_state_flags(fnicp, st_flags, 0)
124
125#define fnic_clear_state_flags(fnicp, st_flags) \
126 __fnic_set_state_flags(fnicp, st_flags, 1)
127
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700128extern unsigned int fnic_log_level;
129
130#define FNIC_MAIN_LOGGING 0x01
131#define FNIC_FCS_LOGGING 0x02
132#define FNIC_SCSI_LOGGING 0x04
133#define FNIC_ISR_LOGGING 0x08
134
135#define FNIC_CHECK_LOGGING(LEVEL, CMD) \
136do { \
137 if (unlikely(fnic_log_level & LEVEL)) \
138 do { \
139 CMD; \
140 } while (0); \
141} while (0)
142
143#define FNIC_MAIN_DBG(kern_level, host, fmt, args...) \
144 FNIC_CHECK_LOGGING(FNIC_MAIN_LOGGING, \
145 shost_printk(kern_level, host, fmt, ##args);)
146
147#define FNIC_FCS_DBG(kern_level, host, fmt, args...) \
148 FNIC_CHECK_LOGGING(FNIC_FCS_LOGGING, \
149 shost_printk(kern_level, host, fmt, ##args);)
150
151#define FNIC_SCSI_DBG(kern_level, host, fmt, args...) \
152 FNIC_CHECK_LOGGING(FNIC_SCSI_LOGGING, \
153 shost_printk(kern_level, host, fmt, ##args);)
154
155#define FNIC_ISR_DBG(kern_level, host, fmt, args...) \
156 FNIC_CHECK_LOGGING(FNIC_ISR_LOGGING, \
157 shost_printk(kern_level, host, fmt, ##args);)
158
Narsimhulu Musini1adee042013-09-09 13:31:45 -0700159#define FNIC_MAIN_NOTE(kern_level, host, fmt, args...) \
160 shost_printk(kern_level, host, fmt, ##args)
161
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700162extern const char *fnic_state_str[];
163
164enum fnic_intx_intr_index {
165 FNIC_INTX_WQ_RQ_COPYWQ,
166 FNIC_INTX_ERR,
167 FNIC_INTX_NOTIFY,
168 FNIC_INTX_INTR_MAX,
169};
170
171enum fnic_msix_intr_index {
172 FNIC_MSIX_RQ,
173 FNIC_MSIX_WQ,
174 FNIC_MSIX_WQ_COPY,
175 FNIC_MSIX_ERR_NOTIFY,
176 FNIC_MSIX_INTR_MAX,
177};
178
179struct fnic_msix_entry {
180 int requested;
181 char devname[IFNAMSIZ];
182 irqreturn_t (*isr)(int, void *);
183 void *devid;
184};
185
186enum fnic_state {
187 FNIC_IN_FC_MODE = 0,
188 FNIC_IN_FC_TRANS_ETH_MODE,
189 FNIC_IN_ETH_MODE,
190 FNIC_IN_ETH_TRANS_FC_MODE,
191};
192
193#define FNIC_WQ_COPY_MAX 1
194#define FNIC_WQ_MAX 1
195#define FNIC_RQ_MAX 1
196#define FNIC_CQ_MAX (FNIC_WQ_COPY_MAX + FNIC_WQ_MAX + FNIC_RQ_MAX)
197
198struct mempool;
199
Hiral Pateld3c995f2013-02-25 16:18:36 -0800200enum fnic_evt {
201 FNIC_EVT_START_VLAN_DISC = 1,
202 FNIC_EVT_START_FCF_DISC = 2,
203 FNIC_EVT_MAX,
204};
205
206struct fnic_event {
207 struct list_head list;
208 struct fnic *fnic;
209 enum fnic_evt event;
210};
211
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700212/* Per-instance private data structure */
213struct fnic {
214 struct fc_lport *lport;
Joe Eykholt78112e52009-11-03 11:49:22 -0800215 struct fcoe_ctlr ctlr; /* FIP FCoE controller structure */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700216 struct vnic_dev_bar bar0;
217
218 struct msix_entry msix_entry[FNIC_MSIX_INTR_MAX];
219 struct fnic_msix_entry msix[FNIC_MSIX_INTR_MAX];
220
221 struct vnic_stats *stats;
222 unsigned long stats_time; /* time of stats update */
Narsimhulu Musini1adee042013-09-09 13:31:45 -0700223 unsigned long stats_reset_time; /* time of stats reset */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700224 struct vnic_nic_cfg *nic_cfg;
225 char name[IFNAMSIZ];
226 struct timer_list notify_timer; /* used for MSI interrupts */
227
Hiral Patelfc857992013-09-09 13:31:51 -0700228 unsigned int fnic_max_tag_id;
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700229 unsigned int err_intr_offset;
230 unsigned int link_intr_offset;
231
232 unsigned int wq_count;
233 unsigned int cq_count;
234
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700235 u32 vlan_hw_insert:1; /* let hw insert the tag */
236 u32 in_remove:1; /* fnic device in removal */
237 u32 stop_rx_link_events:1; /* stop proc. rx frames, link events */
238
239 struct completion *remove_wait; /* device remove thread blocks */
240
Hiral Patel03298552013-02-12 17:00:58 -0800241 atomic_t in_flight; /* io counter */
242 u32 _reserved; /* fill hole */
243 unsigned long state_flags; /* protected by host lock */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700244 enum fnic_state state;
245 spinlock_t fnic_lock;
246
247 u16 vlan_id; /* VLAN tag including priority */
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700248 u8 data_src_addr[ETH_ALEN];
249 u64 fcp_input_bytes; /* internal statistic */
250 u64 fcp_output_bytes; /* internal statistic */
251 u32 link_down_cnt;
252 int link_status;
253
254 struct list_head list;
255 struct pci_dev *pdev;
256 struct vnic_fc_config config;
257 struct vnic_dev *vdev;
258 unsigned int raw_wq_count;
259 unsigned int wq_copy_count;
260 unsigned int rq_count;
261 int fw_ack_index[FNIC_WQ_COPY_MAX];
262 unsigned short fw_ack_recd[FNIC_WQ_COPY_MAX];
263 unsigned short wq_copy_desc_low[FNIC_WQ_COPY_MAX];
264 unsigned int intr_count;
265 u32 __iomem *legacy_pba;
266 struct fnic_host_tag *tags;
267 mempool_t *io_req_pool;
268 mempool_t *io_sgl_pool[FNIC_SGL_NUM_CACHES];
269 spinlock_t io_req_lock[FNIC_IO_LOCKS]; /* locks for scsi cmnds */
270
271 struct work_struct link_work;
272 struct work_struct frame_work;
273 struct sk_buff_head frame_queue;
Joe Eykholt78112e52009-11-03 11:49:22 -0800274 struct sk_buff_head tx_queue;
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700275
Hiral Pateld3c995f2013-02-25 16:18:36 -0800276 /*** FIP related data members -- start ***/
277 void (*set_vlan)(struct fnic *, u16 vlan);
278 struct work_struct fip_frame_work;
279 struct sk_buff_head fip_frame_queue;
280 struct timer_list fip_timer;
281 struct list_head vlans;
282 spinlock_t vlans_lock;
283
284 struct work_struct event_work;
285 struct list_head evlist;
286 /*** FIP related data members -- end ***/
287
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700288 /* copy work queue cache line section */
289 ____cacheline_aligned struct vnic_wq_copy wq_copy[FNIC_WQ_COPY_MAX];
290 /* completion queue cache line section */
291 ____cacheline_aligned struct vnic_cq cq[FNIC_CQ_MAX];
292
293 spinlock_t wq_copy_lock[FNIC_WQ_COPY_MAX];
294
295 /* work queue cache line section */
296 ____cacheline_aligned struct vnic_wq wq[FNIC_WQ_MAX];
297 spinlock_t wq_lock[FNIC_WQ_MAX];
298
299 /* receive queue cache line section */
300 ____cacheline_aligned struct vnic_rq rq[FNIC_RQ_MAX];
301
302 /* interrupt resource cache line section */
303 ____cacheline_aligned struct vnic_intr intr[FNIC_MSIX_INTR_MAX];
304};
305
Joe Eykholt78112e52009-11-03 11:49:22 -0800306static inline struct fnic *fnic_from_ctlr(struct fcoe_ctlr *fip)
307{
308 return container_of(fip, struct fnic, ctlr);
309}
310
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700311extern struct workqueue_struct *fnic_event_queue;
Hiral Pateld3c995f2013-02-25 16:18:36 -0800312extern struct workqueue_struct *fnic_fip_queue;
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700313extern struct device_attribute *fnic_attrs[];
314
315void fnic_clear_intr_mode(struct fnic *fnic);
316int fnic_set_intr_mode(struct fnic *fnic);
317void fnic_free_intr(struct fnic *fnic);
318int fnic_request_intr(struct fnic *fnic);
319
320int fnic_send(struct fc_lport *, struct fc_frame *);
321void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf);
322void fnic_handle_frame(struct work_struct *work);
323void fnic_handle_link(struct work_struct *work);
Hiral Pateld3c995f2013-02-25 16:18:36 -0800324void fnic_handle_event(struct work_struct *work);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700325int fnic_rq_cmpl_handler(struct fnic *fnic, int);
326int fnic_alloc_rq_frame(struct vnic_rq *rq);
327void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf);
Joe Eykholt78112e52009-11-03 11:49:22 -0800328void fnic_flush_tx(struct fnic *);
329void fnic_eth_send(struct fcoe_ctlr *, struct sk_buff *skb);
330void fnic_set_port_id(struct fc_lport *, u32, struct fc_frame *);
331void fnic_update_mac(struct fc_lport *, u8 *new);
332void fnic_update_mac_locked(struct fnic *, u8 *new);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700333
Jeff Garzikf2812332010-11-16 02:10:29 -0500334int fnic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700335int fnic_abort_cmd(struct scsi_cmnd *);
336int fnic_device_reset(struct scsi_cmnd *);
337int fnic_host_reset(struct scsi_cmnd *);
338int fnic_reset(struct Scsi_Host *);
339void fnic_scsi_cleanup(struct fc_lport *);
340void fnic_scsi_abort_io(struct fc_lport *);
341void fnic_empty_scsi_cleanup(struct fc_lport *);
342void fnic_exch_mgr_reset(struct fc_lport *, u32, u32);
343int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int);
344int fnic_wq_cmpl_handler(struct fnic *fnic, int);
Joe Eykholt78112e52009-11-03 11:49:22 -0800345int fnic_flogi_reg_handler(struct fnic *fnic, u32);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700346void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
347 struct fcpio_host_req *desc);
348int fnic_fw_reset_handler(struct fnic *fnic);
349void fnic_terminate_rport_io(struct fc_rport *);
350const char *fnic_state_to_str(unsigned int state);
351
352void fnic_log_q_error(struct fnic *fnic);
353void fnic_handle_link_event(struct fnic *fnic);
354
Hiral Patela0bf1ca2013-02-12 17:01:00 -0800355int fnic_is_abts_pending(struct fnic *, struct scsi_cmnd *);
356
Hiral Pateld3c995f2013-02-25 16:18:36 -0800357void fnic_handle_fip_frame(struct work_struct *work);
358void fnic_handle_fip_event(struct fnic *fnic);
359void fnic_fcoe_reset_vlans(struct fnic *fnic);
360void fnic_fcoe_evlist_free(struct fnic *fnic);
361extern void fnic_handle_fip_timer(struct fnic *fnic);
362
Hiral Patel03298552013-02-12 17:00:58 -0800363static inline int
364fnic_chk_state_flags_locked(struct fnic *fnic, unsigned long st_flags)
365{
366 return ((fnic->state_flags & st_flags) == st_flags);
367}
368void __fnic_set_state_flags(struct fnic *, unsigned long, unsigned long);
Narsimhulu Musini1adee042013-09-09 13:31:45 -0700369void fnic_dump_fchost_stats(struct Scsi_Host *, struct fc_host_statistics *);
Abhijeet Joglekar5df6d732009-04-17 18:33:26 -0700370#endif /* _FNIC_H_ */