2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
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.
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
21 #include <linux/interrupt.h>
22 #include <linux/netdevice.h>
23 #include <linux/workqueue.h>
24 #include <scsi/libfc.h>
31 #include "vnic_wq_copy.h"
32 #include "vnic_intr.h"
33 #include "vnic_stats.h"
34 #include "vnic_scsi.h"
36 #define DRV_NAME "fnic"
37 #define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
38 #define DRV_VERSION "1.0.0.1121"
39 #define PFX DRV_NAME ": "
40 #define DFX DRV_NAME "%d: "
42 #define DESC_CLEAN_LOW_WATERMARK 8
43 #define FNIC_MAX_IO_REQ 2048 /* scsi_cmnd tag map entries */
44 #define FNIC_IO_LOCKS 64 /* IO locks: power of 2 */
45 #define FNIC_DFLT_QUEUE_DEPTH 32
46 #define FNIC_STATS_RATE_LIMIT 4 /* limit rate at which stats are pulled up */
49 * Tag bits used for special requests.
51 #define BIT(nr) (1UL << (nr))
52 #define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */
53 #define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */
54 #define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */
55 #define FNIC_NO_TAG -1
58 * Usage of the scsi_cmnd scratchpad.
59 * These fields are locked by the hashed io_req_lock.
61 #define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
62 #define CMD_STATE(Cmnd) ((Cmnd)->SCp.phase)
63 #define CMD_ABTS_STATUS(Cmnd) ((Cmnd)->SCp.Message)
64 #define CMD_LR_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in)
65 #define CMD_TAG(Cmnd) ((Cmnd)->SCp.sent_command)
67 #define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */
69 #define FNIC_LUN_RESET_TIMEOUT 10000 /* mSec */
70 #define FNIC_HOST_RESET_TIMEOUT 10000 /* mSec */
71 #define FNIC_RMDEVICE_TIMEOUT 1000 /* mSec */
72 #define FNIC_HOST_RESET_SETTLE_TIME 30 /* Sec */
74 #define FNIC_MAX_FCP_TARGET 256
76 extern unsigned int fnic_log_level
;
78 #define FNIC_MAIN_LOGGING 0x01
79 #define FNIC_FCS_LOGGING 0x02
80 #define FNIC_SCSI_LOGGING 0x04
81 #define FNIC_ISR_LOGGING 0x08
83 #define FNIC_CHECK_LOGGING(LEVEL, CMD) \
85 if (unlikely(fnic_log_level & LEVEL)) \
91 #define FNIC_MAIN_DBG(kern_level, host, fmt, args...) \
92 FNIC_CHECK_LOGGING(FNIC_MAIN_LOGGING, \
93 shost_printk(kern_level, host, fmt, ##args);)
95 #define FNIC_FCS_DBG(kern_level, host, fmt, args...) \
96 FNIC_CHECK_LOGGING(FNIC_FCS_LOGGING, \
97 shost_printk(kern_level, host, fmt, ##args);)
99 #define FNIC_SCSI_DBG(kern_level, host, fmt, args...) \
100 FNIC_CHECK_LOGGING(FNIC_SCSI_LOGGING, \
101 shost_printk(kern_level, host, fmt, ##args);)
103 #define FNIC_ISR_DBG(kern_level, host, fmt, args...) \
104 FNIC_CHECK_LOGGING(FNIC_ISR_LOGGING, \
105 shost_printk(kern_level, host, fmt, ##args);)
107 extern const char *fnic_state_str
[];
109 enum fnic_intx_intr_index
{
110 FNIC_INTX_WQ_RQ_COPYWQ
,
116 enum fnic_msix_intr_index
{
120 FNIC_MSIX_ERR_NOTIFY
,
124 struct fnic_msix_entry
{
126 char devname
[IFNAMSIZ
];
127 irqreturn_t (*isr
)(int, void *);
133 FNIC_IN_FC_TRANS_ETH_MODE
,
135 FNIC_IN_ETH_TRANS_FC_MODE
,
138 #define FNIC_WQ_COPY_MAX 1
139 #define FNIC_WQ_MAX 1
140 #define FNIC_RQ_MAX 1
141 #define FNIC_CQ_MAX (FNIC_WQ_COPY_MAX + FNIC_WQ_MAX + FNIC_RQ_MAX)
145 /* Per-instance private data structure */
147 struct fc_lport
*lport
;
148 struct vnic_dev_bar bar0
;
150 struct msix_entry msix_entry
[FNIC_MSIX_INTR_MAX
];
151 struct fnic_msix_entry msix
[FNIC_MSIX_INTR_MAX
];
153 struct vnic_stats
*stats
;
154 unsigned long stats_time
; /* time of stats update */
155 struct vnic_nic_cfg
*nic_cfg
;
157 struct timer_list notify_timer
; /* used for MSI interrupts */
159 unsigned int err_intr_offset
;
160 unsigned int link_intr_offset
;
162 unsigned int wq_count
;
163 unsigned int cq_count
;
165 u32 fcoui_mode
:1; /* use fcoui address*/
166 u32 vlan_hw_insert
:1; /* let hw insert the tag */
167 u32 in_remove
:1; /* fnic device in removal */
168 u32 stop_rx_link_events
:1; /* stop proc. rx frames, link events */
170 struct completion
*remove_wait
; /* device remove thread blocks */
172 struct fc_frame
*flogi
;
173 struct fc_frame
*flogi_resp
;
176 enum fnic_state state
;
177 spinlock_t fnic_lock
;
179 u16 vlan_id
; /* VLAN tag including priority */
180 u8 mac_addr
[ETH_ALEN
];
181 u8 dest_addr
[ETH_ALEN
];
182 u8 data_src_addr
[ETH_ALEN
];
183 u64 fcp_input_bytes
; /* internal statistic */
184 u64 fcp_output_bytes
; /* internal statistic */
188 struct list_head list
;
189 struct pci_dev
*pdev
;
190 struct vnic_fc_config config
;
191 struct vnic_dev
*vdev
;
192 unsigned int raw_wq_count
;
193 unsigned int wq_copy_count
;
194 unsigned int rq_count
;
195 int fw_ack_index
[FNIC_WQ_COPY_MAX
];
196 unsigned short fw_ack_recd
[FNIC_WQ_COPY_MAX
];
197 unsigned short wq_copy_desc_low
[FNIC_WQ_COPY_MAX
];
198 unsigned int intr_count
;
199 u32 __iomem
*legacy_pba
;
200 struct fnic_host_tag
*tags
;
201 mempool_t
*io_req_pool
;
202 mempool_t
*io_sgl_pool
[FNIC_SGL_NUM_CACHES
];
203 spinlock_t io_req_lock
[FNIC_IO_LOCKS
]; /* locks for scsi cmnds */
205 struct work_struct link_work
;
206 struct work_struct frame_work
;
207 struct sk_buff_head frame_queue
;
209 /* copy work queue cache line section */
210 ____cacheline_aligned
struct vnic_wq_copy wq_copy
[FNIC_WQ_COPY_MAX
];
211 /* completion queue cache line section */
212 ____cacheline_aligned
struct vnic_cq cq
[FNIC_CQ_MAX
];
214 spinlock_t wq_copy_lock
[FNIC_WQ_COPY_MAX
];
216 /* work queue cache line section */
217 ____cacheline_aligned
struct vnic_wq wq
[FNIC_WQ_MAX
];
218 spinlock_t wq_lock
[FNIC_WQ_MAX
];
220 /* receive queue cache line section */
221 ____cacheline_aligned
struct vnic_rq rq
[FNIC_RQ_MAX
];
223 /* interrupt resource cache line section */
224 ____cacheline_aligned
struct vnic_intr intr
[FNIC_MSIX_INTR_MAX
];
227 extern struct workqueue_struct
*fnic_event_queue
;
228 extern struct device_attribute
*fnic_attrs
[];
230 void fnic_clear_intr_mode(struct fnic
*fnic
);
231 int fnic_set_intr_mode(struct fnic
*fnic
);
232 void fnic_free_intr(struct fnic
*fnic
);
233 int fnic_request_intr(struct fnic
*fnic
);
235 int fnic_send(struct fc_lport
*, struct fc_frame
*);
236 void fnic_free_wq_buf(struct vnic_wq
*wq
, struct vnic_wq_buf
*buf
);
237 void fnic_handle_frame(struct work_struct
*work
);
238 void fnic_handle_link(struct work_struct
*work
);
239 int fnic_rq_cmpl_handler(struct fnic
*fnic
, int);
240 int fnic_alloc_rq_frame(struct vnic_rq
*rq
);
241 void fnic_free_rq_buf(struct vnic_rq
*rq
, struct vnic_rq_buf
*buf
);
242 int fnic_send_frame(struct fnic
*fnic
, struct fc_frame
*fp
);
244 int fnic_queuecommand(struct scsi_cmnd
*, void (*done
)(struct scsi_cmnd
*));
245 int fnic_abort_cmd(struct scsi_cmnd
*);
246 int fnic_device_reset(struct scsi_cmnd
*);
247 int fnic_host_reset(struct scsi_cmnd
*);
248 int fnic_reset(struct Scsi_Host
*);
249 void fnic_scsi_cleanup(struct fc_lport
*);
250 void fnic_scsi_abort_io(struct fc_lport
*);
251 void fnic_empty_scsi_cleanup(struct fc_lport
*);
252 void fnic_exch_mgr_reset(struct fc_lport
*, u32
, u32
);
253 int fnic_wq_copy_cmpl_handler(struct fnic
*fnic
, int);
254 int fnic_wq_cmpl_handler(struct fnic
*fnic
, int);
255 int fnic_flogi_reg_handler(struct fnic
*fnic
);
256 void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy
*wq
,
257 struct fcpio_host_req
*desc
);
258 int fnic_fw_reset_handler(struct fnic
*fnic
);
259 void fnic_terminate_rport_io(struct fc_rport
*);
260 const char *fnic_state_to_str(unsigned int state
);
262 void fnic_log_q_error(struct fnic
*fnic
);
263 void fnic_handle_link_event(struct fnic
*fnic
);
265 #endif /* _FNIC_H_ */