Merge branch 'fixes' of git://ftp.arm.linux.org.uk/~rmk/linux-arm
[linux-2.6-block.git] / drivers / scsi / fnic / fnic.h
CommitLineData
5df6d737
AJ
1/*
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>
a737b88d 24#include <linux/bitops.h>
5df6d737 25#include <scsi/libfc.h>
78112e55 26#include <scsi/libfcoe.h>
5df6d737
AJ
27#include "fnic_io.h"
28#include "fnic_res.h"
4d7007b4 29#include "fnic_trace.h"
67125b02 30#include "fnic_stats.h"
5df6d737
AJ
31#include "vnic_dev.h"
32#include "vnic_wq.h"
33#include "vnic_rq.h"
34#include "vnic_cq.h"
35#include "vnic_wq_copy.h"
36#include "vnic_intr.h"
37#include "vnic_stats.h"
38#include "vnic_scsi.h"
39
40#define DRV_NAME "fnic"
41#define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
efc7a288 42#define DRV_VERSION "1.6.0.17"
5df6d737
AJ
43#define PFX DRV_NAME ": "
44#define DFX DRV_NAME "%d: "
45
46#define DESC_CLEAN_LOW_WATERMARK 8
fc85799e
HP
47#define FNIC_UCSM_DFLT_THROTTLE_CNT_BLD 16 /* UCSM default throttle count */
48#define FNIC_MIN_IO_REQ 256 /* Min IO throttle count */
c8ff03c6
HS
49#define FNIC_MAX_IO_REQ 1024 /* scsi_cmnd tag map entries */
50#define FNIC_DFLT_IO_REQ 256 /* Default scsi_cmnd tag map entries */
5df6d737
AJ
51#define FNIC_IO_LOCKS 64 /* IO locks: power of 2 */
52#define FNIC_DFLT_QUEUE_DEPTH 32
53#define FNIC_STATS_RATE_LIMIT 4 /* limit rate at which stats are pulled up */
da87bfab 54
5df6d737
AJ
55/*
56 * Tag bits used for special requests.
57 */
5df6d737
AJ
58#define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */
59#define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */
60#define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */
61#define FNIC_NO_TAG -1
62
03298552
HP
63/*
64 * Command flags to identify the type of command and for other future
65 * use.
66 */
14eb5d90
HP
67#define FNIC_NO_FLAGS 0
68#define FNIC_IO_INITIALIZED BIT(0)
69#define FNIC_IO_ISSUED BIT(1)
70#define FNIC_IO_DONE BIT(2)
71#define FNIC_IO_REQ_NULL BIT(3)
72#define FNIC_IO_ABTS_PENDING BIT(4)
73#define FNIC_IO_ABORTED BIT(5)
74#define FNIC_IO_ABTS_ISSUED BIT(6)
75#define FNIC_IO_TERM_ISSUED BIT(7)
76#define FNIC_IO_INTERNAL_TERM_ISSUED BIT(8)
77#define FNIC_IO_ABT_TERM_DONE BIT(9)
78#define FNIC_IO_ABT_TERM_REQ_NULL BIT(10)
79#define FNIC_IO_ABT_TERM_TIMED_OUT BIT(11)
80#define FNIC_DEVICE_RESET BIT(12) /* Device reset request */
81#define FNIC_DEV_RST_ISSUED BIT(13)
82#define FNIC_DEV_RST_TIMED_OUT BIT(14)
83#define FNIC_DEV_RST_ABTS_ISSUED BIT(15)
84#define FNIC_DEV_RST_TERM_ISSUED BIT(16)
85#define FNIC_DEV_RST_DONE BIT(17)
86#define FNIC_DEV_RST_REQ_NULL BIT(18)
87#define FNIC_DEV_RST_ABTS_DONE BIT(19)
88#define FNIC_DEV_RST_TERM_DONE BIT(20)
89#define FNIC_DEV_RST_ABTS_PENDING BIT(21)
03298552 90
5df6d737
AJ
91/*
92 * Usage of the scsi_cmnd scratchpad.
93 * These fields are locked by the hashed io_req_lock.
94 */
95#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
96#define CMD_STATE(Cmnd) ((Cmnd)->SCp.phase)
97#define CMD_ABTS_STATUS(Cmnd) ((Cmnd)->SCp.Message)
98#define CMD_LR_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in)
99#define CMD_TAG(Cmnd) ((Cmnd)->SCp.sent_command)
03298552 100#define CMD_FLAGS(Cmnd) ((Cmnd)->SCp.Status)
5df6d737
AJ
101
102#define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */
103
104#define FNIC_LUN_RESET_TIMEOUT 10000 /* mSec */
105#define FNIC_HOST_RESET_TIMEOUT 10000 /* mSec */
106#define FNIC_RMDEVICE_TIMEOUT 1000 /* mSec */
107#define FNIC_HOST_RESET_SETTLE_TIME 30 /* Sec */
03298552 108#define FNIC_ABT_TERM_DELAY_TIMEOUT 500 /* mSec */
5df6d737
AJ
109
110#define FNIC_MAX_FCP_TARGET 256
111
03298552
HP
112/**
113 * state_flags to identify host state along along with fnic's state
114 **/
115#define __FNIC_FLAGS_FWRESET BIT(0) /* fwreset in progress */
116#define __FNIC_FLAGS_BLOCK_IO BIT(1) /* IOs are blocked */
117
118#define FNIC_FLAGS_NONE (0)
119#define FNIC_FLAGS_FWRESET (__FNIC_FLAGS_FWRESET | \
120 __FNIC_FLAGS_BLOCK_IO)
121
122#define FNIC_FLAGS_IO_BLOCKED (__FNIC_FLAGS_BLOCK_IO)
123
124#define fnic_set_state_flags(fnicp, st_flags) \
125 __fnic_set_state_flags(fnicp, st_flags, 0)
126
127#define fnic_clear_state_flags(fnicp, st_flags) \
128 __fnic_set_state_flags(fnicp, st_flags, 1)
129
5df6d737
AJ
130extern unsigned int fnic_log_level;
131
132#define FNIC_MAIN_LOGGING 0x01
133#define FNIC_FCS_LOGGING 0x02
134#define FNIC_SCSI_LOGGING 0x04
135#define FNIC_ISR_LOGGING 0x08
136
137#define FNIC_CHECK_LOGGING(LEVEL, CMD) \
138do { \
139 if (unlikely(fnic_log_level & LEVEL)) \
140 do { \
141 CMD; \
142 } while (0); \
143} while (0)
144
145#define FNIC_MAIN_DBG(kern_level, host, fmt, args...) \
146 FNIC_CHECK_LOGGING(FNIC_MAIN_LOGGING, \
147 shost_printk(kern_level, host, fmt, ##args);)
148
149#define FNIC_FCS_DBG(kern_level, host, fmt, args...) \
150 FNIC_CHECK_LOGGING(FNIC_FCS_LOGGING, \
151 shost_printk(kern_level, host, fmt, ##args);)
152
153#define FNIC_SCSI_DBG(kern_level, host, fmt, args...) \
154 FNIC_CHECK_LOGGING(FNIC_SCSI_LOGGING, \
155 shost_printk(kern_level, host, fmt, ##args);)
156
157#define FNIC_ISR_DBG(kern_level, host, fmt, args...) \
158 FNIC_CHECK_LOGGING(FNIC_ISR_LOGGING, \
159 shost_printk(kern_level, host, fmt, ##args);)
160
1adee040
NM
161#define FNIC_MAIN_NOTE(kern_level, host, fmt, args...) \
162 shost_printk(kern_level, host, fmt, ##args)
163
5df6d737
AJ
164extern const char *fnic_state_str[];
165
166enum fnic_intx_intr_index {
167 FNIC_INTX_WQ_RQ_COPYWQ,
168 FNIC_INTX_ERR,
169 FNIC_INTX_NOTIFY,
170 FNIC_INTX_INTR_MAX,
171};
172
173enum fnic_msix_intr_index {
174 FNIC_MSIX_RQ,
175 FNIC_MSIX_WQ,
176 FNIC_MSIX_WQ_COPY,
177 FNIC_MSIX_ERR_NOTIFY,
178 FNIC_MSIX_INTR_MAX,
179};
180
181struct fnic_msix_entry {
182 int requested;
183 char devname[IFNAMSIZ];
184 irqreturn_t (*isr)(int, void *);
185 void *devid;
186};
187
188enum fnic_state {
189 FNIC_IN_FC_MODE = 0,
190 FNIC_IN_FC_TRANS_ETH_MODE,
191 FNIC_IN_ETH_MODE,
192 FNIC_IN_ETH_TRANS_FC_MODE,
193};
194
195#define FNIC_WQ_COPY_MAX 1
196#define FNIC_WQ_MAX 1
197#define FNIC_RQ_MAX 1
198#define FNIC_CQ_MAX (FNIC_WQ_COPY_MAX + FNIC_WQ_MAX + FNIC_RQ_MAX)
199
200struct mempool;
201
d3c995f1
HP
202enum fnic_evt {
203 FNIC_EVT_START_VLAN_DISC = 1,
204 FNIC_EVT_START_FCF_DISC = 2,
205 FNIC_EVT_MAX,
206};
207
208struct fnic_event {
209 struct list_head list;
210 struct fnic *fnic;
211 enum fnic_evt event;
212};
213
5df6d737
AJ
214/* Per-instance private data structure */
215struct fnic {
216 struct fc_lport *lport;
78112e55 217 struct fcoe_ctlr ctlr; /* FIP FCoE controller structure */
5df6d737
AJ
218 struct vnic_dev_bar bar0;
219
220 struct msix_entry msix_entry[FNIC_MSIX_INTR_MAX];
221 struct fnic_msix_entry msix[FNIC_MSIX_INTR_MAX];
222
223 struct vnic_stats *stats;
224 unsigned long stats_time; /* time of stats update */
1adee040 225 unsigned long stats_reset_time; /* time of stats reset */
5df6d737
AJ
226 struct vnic_nic_cfg *nic_cfg;
227 char name[IFNAMSIZ];
228 struct timer_list notify_timer; /* used for MSI interrupts */
229
fc85799e 230 unsigned int fnic_max_tag_id;
5df6d737
AJ
231 unsigned int err_intr_offset;
232 unsigned int link_intr_offset;
233
234 unsigned int wq_count;
235 unsigned int cq_count;
236
67125b02
HP
237 struct dentry *fnic_stats_debugfs_host;
238 struct dentry *fnic_stats_debugfs_file;
239 struct dentry *fnic_reset_debugfs_file;
240 unsigned int reset_stats;
241 atomic64_t io_cmpl_skip;
242 struct fnic_stats fnic_stats;
243
5df6d737
AJ
244 u32 vlan_hw_insert:1; /* let hw insert the tag */
245 u32 in_remove:1; /* fnic device in removal */
246 u32 stop_rx_link_events:1; /* stop proc. rx frames, link events */
247
248 struct completion *remove_wait; /* device remove thread blocks */
249
03298552
HP
250 atomic_t in_flight; /* io counter */
251 u32 _reserved; /* fill hole */
252 unsigned long state_flags; /* protected by host lock */
5df6d737
AJ
253 enum fnic_state state;
254 spinlock_t fnic_lock;
255
256 u16 vlan_id; /* VLAN tag including priority */
5df6d737
AJ
257 u8 data_src_addr[ETH_ALEN];
258 u64 fcp_input_bytes; /* internal statistic */
259 u64 fcp_output_bytes; /* internal statistic */
260 u32 link_down_cnt;
261 int link_status;
262
263 struct list_head list;
264 struct pci_dev *pdev;
265 struct vnic_fc_config config;
266 struct vnic_dev *vdev;
267 unsigned int raw_wq_count;
268 unsigned int wq_copy_count;
269 unsigned int rq_count;
270 int fw_ack_index[FNIC_WQ_COPY_MAX];
271 unsigned short fw_ack_recd[FNIC_WQ_COPY_MAX];
272 unsigned short wq_copy_desc_low[FNIC_WQ_COPY_MAX];
273 unsigned int intr_count;
274 u32 __iomem *legacy_pba;
275 struct fnic_host_tag *tags;
276 mempool_t *io_req_pool;
277 mempool_t *io_sgl_pool[FNIC_SGL_NUM_CACHES];
278 spinlock_t io_req_lock[FNIC_IO_LOCKS]; /* locks for scsi cmnds */
279
280 struct work_struct link_work;
281 struct work_struct frame_work;
282 struct sk_buff_head frame_queue;
78112e55 283 struct sk_buff_head tx_queue;
5df6d737 284
d3c995f1
HP
285 /*** FIP related data members -- start ***/
286 void (*set_vlan)(struct fnic *, u16 vlan);
287 struct work_struct fip_frame_work;
288 struct sk_buff_head fip_frame_queue;
289 struct timer_list fip_timer;
290 struct list_head vlans;
291 spinlock_t vlans_lock;
292
293 struct work_struct event_work;
294 struct list_head evlist;
295 /*** FIP related data members -- end ***/
296
5df6d737
AJ
297 /* copy work queue cache line section */
298 ____cacheline_aligned struct vnic_wq_copy wq_copy[FNIC_WQ_COPY_MAX];
299 /* completion queue cache line section */
300 ____cacheline_aligned struct vnic_cq cq[FNIC_CQ_MAX];
301
302 spinlock_t wq_copy_lock[FNIC_WQ_COPY_MAX];
303
304 /* work queue cache line section */
305 ____cacheline_aligned struct vnic_wq wq[FNIC_WQ_MAX];
306 spinlock_t wq_lock[FNIC_WQ_MAX];
307
308 /* receive queue cache line section */
309 ____cacheline_aligned struct vnic_rq rq[FNIC_RQ_MAX];
310
311 /* interrupt resource cache line section */
312 ____cacheline_aligned struct vnic_intr intr[FNIC_MSIX_INTR_MAX];
313};
314
78112e55
JE
315static inline struct fnic *fnic_from_ctlr(struct fcoe_ctlr *fip)
316{
317 return container_of(fip, struct fnic, ctlr);
318}
319
5df6d737 320extern struct workqueue_struct *fnic_event_queue;
d3c995f1 321extern struct workqueue_struct *fnic_fip_queue;
5df6d737
AJ
322extern struct device_attribute *fnic_attrs[];
323
324void fnic_clear_intr_mode(struct fnic *fnic);
325int fnic_set_intr_mode(struct fnic *fnic);
326void fnic_free_intr(struct fnic *fnic);
327int fnic_request_intr(struct fnic *fnic);
328
329int fnic_send(struct fc_lport *, struct fc_frame *);
330void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf);
331void fnic_handle_frame(struct work_struct *work);
332void fnic_handle_link(struct work_struct *work);
d3c995f1 333void fnic_handle_event(struct work_struct *work);
5df6d737
AJ
334int fnic_rq_cmpl_handler(struct fnic *fnic, int);
335int fnic_alloc_rq_frame(struct vnic_rq *rq);
336void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf);
78112e55
JE
337void fnic_flush_tx(struct fnic *);
338void fnic_eth_send(struct fcoe_ctlr *, struct sk_buff *skb);
339void fnic_set_port_id(struct fc_lport *, u32, struct fc_frame *);
340void fnic_update_mac(struct fc_lport *, u8 *new);
341void fnic_update_mac_locked(struct fnic *, u8 *new);
5df6d737 342
f281233d 343int fnic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
5df6d737
AJ
344int fnic_abort_cmd(struct scsi_cmnd *);
345int fnic_device_reset(struct scsi_cmnd *);
346int fnic_host_reset(struct scsi_cmnd *);
347int fnic_reset(struct Scsi_Host *);
348void fnic_scsi_cleanup(struct fc_lport *);
349void fnic_scsi_abort_io(struct fc_lport *);
350void fnic_empty_scsi_cleanup(struct fc_lport *);
351void fnic_exch_mgr_reset(struct fc_lport *, u32, u32);
352int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int);
353int fnic_wq_cmpl_handler(struct fnic *fnic, int);
78112e55 354int fnic_flogi_reg_handler(struct fnic *fnic, u32);
5df6d737
AJ
355void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
356 struct fcpio_host_req *desc);
357int fnic_fw_reset_handler(struct fnic *fnic);
358void fnic_terminate_rport_io(struct fc_rport *);
359const char *fnic_state_to_str(unsigned int state);
360
361void fnic_log_q_error(struct fnic *fnic);
362void fnic_handle_link_event(struct fnic *fnic);
363
a0bf1ca2
HP
364int fnic_is_abts_pending(struct fnic *, struct scsi_cmnd *);
365
d3c995f1
HP
366void fnic_handle_fip_frame(struct work_struct *work);
367void fnic_handle_fip_event(struct fnic *fnic);
368void fnic_fcoe_reset_vlans(struct fnic *fnic);
369void fnic_fcoe_evlist_free(struct fnic *fnic);
370extern void fnic_handle_fip_timer(struct fnic *fnic);
371
03298552
HP
372static inline int
373fnic_chk_state_flags_locked(struct fnic *fnic, unsigned long st_flags)
374{
375 return ((fnic->state_flags & st_flags) == st_flags);
376}
377void __fnic_set_state_flags(struct fnic *, unsigned long, unsigned long);
1adee040 378void fnic_dump_fchost_stats(struct Scsi_Host *, struct fc_host_statistics *);
5df6d737 379#endif /* _FNIC_H_ */