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