0001
0002
0003
0004
0005
0006 #ifndef _FNIC_H_
0007 #define _FNIC_H_
0008
0009 #include <linux/interrupt.h>
0010 #include <linux/netdevice.h>
0011 #include <linux/workqueue.h>
0012 #include <linux/bitops.h>
0013 #include <scsi/libfc.h>
0014 #include <scsi/libfcoe.h>
0015 #include "fnic_io.h"
0016 #include "fnic_res.h"
0017 #include "fnic_trace.h"
0018 #include "fnic_stats.h"
0019 #include "vnic_dev.h"
0020 #include "vnic_wq.h"
0021 #include "vnic_rq.h"
0022 #include "vnic_cq.h"
0023 #include "vnic_wq_copy.h"
0024 #include "vnic_intr.h"
0025 #include "vnic_stats.h"
0026 #include "vnic_scsi.h"
0027
0028 #define DRV_NAME "fnic"
0029 #define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
0030 #define DRV_VERSION "1.6.0.54"
0031 #define PFX DRV_NAME ": "
0032 #define DFX DRV_NAME "%d: "
0033
0034 #define DESC_CLEAN_LOW_WATERMARK 8
0035 #define FNIC_UCSM_DFLT_THROTTLE_CNT_BLD 16
0036 #define FNIC_MIN_IO_REQ 256
0037 #define FNIC_MAX_IO_REQ 1024
0038 #define FNIC_DFLT_IO_REQ 256
0039 #define FNIC_IO_LOCKS 64
0040 #define FNIC_DFLT_QUEUE_DEPTH 256
0041 #define FNIC_STATS_RATE_LIMIT 4
0042
0043
0044
0045
0046 #define FNIC_TAG_ABORT BIT(30)
0047 #define FNIC_TAG_DEV_RST BIT(29)
0048 #define FNIC_TAG_MASK (BIT(24) - 1)
0049 #define FNIC_NO_TAG -1
0050
0051
0052
0053
0054
0055 #define FNIC_NO_FLAGS 0
0056 #define FNIC_IO_INITIALIZED BIT(0)
0057 #define FNIC_IO_ISSUED BIT(1)
0058 #define FNIC_IO_DONE BIT(2)
0059 #define FNIC_IO_REQ_NULL BIT(3)
0060 #define FNIC_IO_ABTS_PENDING BIT(4)
0061 #define FNIC_IO_ABORTED BIT(5)
0062 #define FNIC_IO_ABTS_ISSUED BIT(6)
0063 #define FNIC_IO_TERM_ISSUED BIT(7)
0064 #define FNIC_IO_INTERNAL_TERM_ISSUED BIT(8)
0065 #define FNIC_IO_ABT_TERM_DONE BIT(9)
0066 #define FNIC_IO_ABT_TERM_REQ_NULL BIT(10)
0067 #define FNIC_IO_ABT_TERM_TIMED_OUT BIT(11)
0068 #define FNIC_DEVICE_RESET BIT(12)
0069 #define FNIC_DEV_RST_ISSUED BIT(13)
0070 #define FNIC_DEV_RST_TIMED_OUT BIT(14)
0071 #define FNIC_DEV_RST_ABTS_ISSUED BIT(15)
0072 #define FNIC_DEV_RST_TERM_ISSUED BIT(16)
0073 #define FNIC_DEV_RST_DONE BIT(17)
0074 #define FNIC_DEV_RST_REQ_NULL BIT(18)
0075 #define FNIC_DEV_RST_ABTS_DONE BIT(19)
0076 #define FNIC_DEV_RST_TERM_DONE BIT(20)
0077 #define FNIC_DEV_RST_ABTS_PENDING BIT(21)
0078
0079
0080
0081
0082
0083 struct fnic_cmd_priv {
0084 struct fnic_io_req *io_req;
0085 enum fnic_ioreq_state state;
0086 u32 flags;
0087 u16 abts_status;
0088 u16 lr_status;
0089 };
0090
0091 static inline struct fnic_cmd_priv *fnic_priv(struct scsi_cmnd *cmd)
0092 {
0093 return scsi_cmd_priv(cmd);
0094 }
0095
0096 static inline u64 fnic_flags_and_state(struct scsi_cmnd *cmd)
0097 {
0098 struct fnic_cmd_priv *fcmd = fnic_priv(cmd);
0099
0100 return ((u64)fcmd->flags << 32) | fcmd->state;
0101 }
0102
0103 #define FCPIO_INVALID_CODE 0x100
0104
0105 #define FNIC_LUN_RESET_TIMEOUT 10000
0106 #define FNIC_HOST_RESET_TIMEOUT 10000
0107 #define FNIC_RMDEVICE_TIMEOUT 1000
0108 #define FNIC_HOST_RESET_SETTLE_TIME 30
0109 #define FNIC_ABT_TERM_DELAY_TIMEOUT 500
0110
0111 #define FNIC_MAX_FCP_TARGET 256
0112
0113
0114
0115
0116 #define __FNIC_FLAGS_FWRESET BIT(0)
0117 #define __FNIC_FLAGS_BLOCK_IO BIT(1)
0118
0119 #define FNIC_FLAGS_NONE (0)
0120 #define FNIC_FLAGS_FWRESET (__FNIC_FLAGS_FWRESET | \
0121 __FNIC_FLAGS_BLOCK_IO)
0122
0123 #define FNIC_FLAGS_IO_BLOCKED (__FNIC_FLAGS_BLOCK_IO)
0124
0125 #define fnic_set_state_flags(fnicp, st_flags) \
0126 __fnic_set_state_flags(fnicp, st_flags, 0)
0127
0128 #define fnic_clear_state_flags(fnicp, st_flags) \
0129 __fnic_set_state_flags(fnicp, st_flags, 1)
0130
0131 extern unsigned int fnic_log_level;
0132 extern unsigned int io_completions;
0133
0134 #define FNIC_MAIN_LOGGING 0x01
0135 #define FNIC_FCS_LOGGING 0x02
0136 #define FNIC_SCSI_LOGGING 0x04
0137 #define FNIC_ISR_LOGGING 0x08
0138
0139 #define FNIC_CHECK_LOGGING(LEVEL, CMD) \
0140 do { \
0141 if (unlikely(fnic_log_level & LEVEL)) \
0142 do { \
0143 CMD; \
0144 } while (0); \
0145 } while (0)
0146
0147 #define FNIC_MAIN_DBG(kern_level, host, fmt, args...) \
0148 FNIC_CHECK_LOGGING(FNIC_MAIN_LOGGING, \
0149 shost_printk(kern_level, host, fmt, ##args);)
0150
0151 #define FNIC_FCS_DBG(kern_level, host, fmt, args...) \
0152 FNIC_CHECK_LOGGING(FNIC_FCS_LOGGING, \
0153 shost_printk(kern_level, host, fmt, ##args);)
0154
0155 #define FNIC_SCSI_DBG(kern_level, host, fmt, args...) \
0156 FNIC_CHECK_LOGGING(FNIC_SCSI_LOGGING, \
0157 shost_printk(kern_level, host, fmt, ##args);)
0158
0159 #define FNIC_ISR_DBG(kern_level, host, fmt, args...) \
0160 FNIC_CHECK_LOGGING(FNIC_ISR_LOGGING, \
0161 shost_printk(kern_level, host, fmt, ##args);)
0162
0163 #define FNIC_MAIN_NOTE(kern_level, host, fmt, args...) \
0164 shost_printk(kern_level, host, fmt, ##args)
0165
0166 extern const char *fnic_state_str[];
0167
0168 enum fnic_intx_intr_index {
0169 FNIC_INTX_WQ_RQ_COPYWQ,
0170 FNIC_INTX_ERR,
0171 FNIC_INTX_NOTIFY,
0172 FNIC_INTX_INTR_MAX,
0173 };
0174
0175 enum fnic_msix_intr_index {
0176 FNIC_MSIX_RQ,
0177 FNIC_MSIX_WQ,
0178 FNIC_MSIX_WQ_COPY,
0179 FNIC_MSIX_ERR_NOTIFY,
0180 FNIC_MSIX_INTR_MAX,
0181 };
0182
0183 struct fnic_msix_entry {
0184 int requested;
0185 char devname[IFNAMSIZ + 11];
0186 irqreturn_t (*isr)(int, void *);
0187 void *devid;
0188 };
0189
0190 enum fnic_state {
0191 FNIC_IN_FC_MODE = 0,
0192 FNIC_IN_FC_TRANS_ETH_MODE,
0193 FNIC_IN_ETH_MODE,
0194 FNIC_IN_ETH_TRANS_FC_MODE,
0195 };
0196
0197 #define FNIC_WQ_COPY_MAX 1
0198 #define FNIC_WQ_MAX 1
0199 #define FNIC_RQ_MAX 1
0200 #define FNIC_CQ_MAX (FNIC_WQ_COPY_MAX + FNIC_WQ_MAX + FNIC_RQ_MAX)
0201 #define FNIC_DFLT_IO_COMPLETIONS 256
0202
0203 struct mempool;
0204
0205 enum fnic_evt {
0206 FNIC_EVT_START_VLAN_DISC = 1,
0207 FNIC_EVT_START_FCF_DISC = 2,
0208 FNIC_EVT_MAX,
0209 };
0210
0211 struct fnic_event {
0212 struct list_head list;
0213 struct fnic *fnic;
0214 enum fnic_evt event;
0215 };
0216
0217
0218 struct fnic {
0219 struct fc_lport *lport;
0220 struct fcoe_ctlr ctlr;
0221 struct vnic_dev_bar bar0;
0222
0223 struct fnic_msix_entry msix[FNIC_MSIX_INTR_MAX];
0224
0225 struct vnic_stats *stats;
0226 unsigned long stats_time;
0227 unsigned long stats_reset_time;
0228 struct vnic_nic_cfg *nic_cfg;
0229 char name[IFNAMSIZ];
0230 struct timer_list notify_timer;
0231
0232 unsigned int fnic_max_tag_id;
0233 unsigned int err_intr_offset;
0234 unsigned int link_intr_offset;
0235
0236 unsigned int wq_count;
0237 unsigned int cq_count;
0238
0239 struct dentry *fnic_stats_debugfs_host;
0240 struct dentry *fnic_stats_debugfs_file;
0241 struct dentry *fnic_reset_debugfs_file;
0242 unsigned int reset_stats;
0243 atomic64_t io_cmpl_skip;
0244 struct fnic_stats fnic_stats;
0245
0246 u32 vlan_hw_insert:1;
0247 u32 in_remove:1;
0248 u32 stop_rx_link_events:1;
0249 u32 link_events:1;
0250
0251 struct completion *remove_wait;
0252
0253 atomic_t in_flight;
0254 bool internal_reset_inprogress;
0255 u32 _reserved;
0256 unsigned long state_flags;
0257 enum fnic_state state;
0258 spinlock_t fnic_lock;
0259
0260 u16 vlan_id;
0261 u8 data_src_addr[ETH_ALEN];
0262 u64 fcp_input_bytes;
0263 u64 fcp_output_bytes;
0264 u32 link_down_cnt;
0265 int link_status;
0266
0267 struct list_head list;
0268 struct pci_dev *pdev;
0269 struct vnic_fc_config config;
0270 struct vnic_dev *vdev;
0271 unsigned int raw_wq_count;
0272 unsigned int wq_copy_count;
0273 unsigned int rq_count;
0274 int fw_ack_index[FNIC_WQ_COPY_MAX];
0275 unsigned short fw_ack_recd[FNIC_WQ_COPY_MAX];
0276 unsigned short wq_copy_desc_low[FNIC_WQ_COPY_MAX];
0277 unsigned int intr_count;
0278 u32 __iomem *legacy_pba;
0279 struct fnic_host_tag *tags;
0280 mempool_t *io_req_pool;
0281 mempool_t *io_sgl_pool[FNIC_SGL_NUM_CACHES];
0282 spinlock_t io_req_lock[FNIC_IO_LOCKS];
0283
0284 struct work_struct link_work;
0285 struct work_struct frame_work;
0286 struct sk_buff_head frame_queue;
0287 struct sk_buff_head tx_queue;
0288
0289
0290 void (*set_vlan)(struct fnic *, u16 vlan);
0291 struct work_struct fip_frame_work;
0292 struct sk_buff_head fip_frame_queue;
0293 struct timer_list fip_timer;
0294 struct list_head vlans;
0295 spinlock_t vlans_lock;
0296
0297 struct work_struct event_work;
0298 struct list_head evlist;
0299
0300
0301
0302 ____cacheline_aligned struct vnic_wq_copy wq_copy[FNIC_WQ_COPY_MAX];
0303
0304 ____cacheline_aligned struct vnic_cq cq[FNIC_CQ_MAX];
0305
0306 spinlock_t wq_copy_lock[FNIC_WQ_COPY_MAX];
0307
0308
0309 ____cacheline_aligned struct vnic_wq wq[FNIC_WQ_MAX];
0310 spinlock_t wq_lock[FNIC_WQ_MAX];
0311
0312
0313 ____cacheline_aligned struct vnic_rq rq[FNIC_RQ_MAX];
0314
0315
0316 ____cacheline_aligned struct vnic_intr intr[FNIC_MSIX_INTR_MAX];
0317 };
0318
0319 static inline struct fnic *fnic_from_ctlr(struct fcoe_ctlr *fip)
0320 {
0321 return container_of(fip, struct fnic, ctlr);
0322 }
0323
0324 extern struct workqueue_struct *fnic_event_queue;
0325 extern struct workqueue_struct *fnic_fip_queue;
0326 extern const struct attribute_group *fnic_host_groups[];
0327
0328 void fnic_clear_intr_mode(struct fnic *fnic);
0329 int fnic_set_intr_mode(struct fnic *fnic);
0330 void fnic_free_intr(struct fnic *fnic);
0331 int fnic_request_intr(struct fnic *fnic);
0332
0333 int fnic_send(struct fc_lport *, struct fc_frame *);
0334 void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf);
0335 void fnic_handle_frame(struct work_struct *work);
0336 void fnic_handle_link(struct work_struct *work);
0337 void fnic_handle_event(struct work_struct *work);
0338 int fnic_rq_cmpl_handler(struct fnic *fnic, int);
0339 int fnic_alloc_rq_frame(struct vnic_rq *rq);
0340 void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf);
0341 void fnic_flush_tx(struct fnic *);
0342 void fnic_eth_send(struct fcoe_ctlr *, struct sk_buff *skb);
0343 void fnic_set_port_id(struct fc_lport *, u32, struct fc_frame *);
0344 void fnic_update_mac(struct fc_lport *, u8 *new);
0345 void fnic_update_mac_locked(struct fnic *, u8 *new);
0346
0347 int fnic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
0348 int fnic_abort_cmd(struct scsi_cmnd *);
0349 int fnic_device_reset(struct scsi_cmnd *);
0350 int fnic_host_reset(struct scsi_cmnd *);
0351 int fnic_reset(struct Scsi_Host *);
0352 void fnic_scsi_cleanup(struct fc_lport *);
0353 void fnic_scsi_abort_io(struct fc_lport *);
0354 void fnic_empty_scsi_cleanup(struct fc_lport *);
0355 void fnic_exch_mgr_reset(struct fc_lport *, u32, u32);
0356 int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int);
0357 int fnic_wq_cmpl_handler(struct fnic *fnic, int);
0358 int fnic_flogi_reg_handler(struct fnic *fnic, u32);
0359 void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
0360 struct fcpio_host_req *desc);
0361 int fnic_fw_reset_handler(struct fnic *fnic);
0362 void fnic_terminate_rport_io(struct fc_rport *);
0363 const char *fnic_state_to_str(unsigned int state);
0364
0365 void fnic_log_q_error(struct fnic *fnic);
0366 void fnic_handle_link_event(struct fnic *fnic);
0367
0368 int fnic_is_abts_pending(struct fnic *, struct scsi_cmnd *);
0369
0370 void fnic_handle_fip_frame(struct work_struct *work);
0371 void fnic_handle_fip_event(struct fnic *fnic);
0372 void fnic_fcoe_reset_vlans(struct fnic *fnic);
0373 void fnic_fcoe_evlist_free(struct fnic *fnic);
0374 extern void fnic_handle_fip_timer(struct fnic *fnic);
0375
0376 static inline int
0377 fnic_chk_state_flags_locked(struct fnic *fnic, unsigned long st_flags)
0378 {
0379 return ((fnic->state_flags & st_flags) == st_flags);
0380 }
0381 void __fnic_set_state_flags(struct fnic *, unsigned long, unsigned long);
0382 void fnic_dump_fchost_stats(struct Scsi_Host *, struct fc_host_statistics *);
0383 #endif