Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fnic.h
Go to the documentation of this file.
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 "vnic_dev.h"
30 #include "vnic_wq.h"
31 #include "vnic_rq.h"
32 #include "vnic_cq.h"
33 #include "vnic_wq_copy.h"
34 #include "vnic_intr.h"
35 #include "vnic_stats.h"
36 #include "vnic_scsi.h"
37 
38 #define DRV_NAME "fnic"
39 #define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
40 #define DRV_VERSION "1.5.0.2"
41 #define PFX DRV_NAME ": "
42 #define DFX DRV_NAME "%d: "
43 
44 #define DESC_CLEAN_LOW_WATERMARK 8
45 #define FNIC_MAX_IO_REQ 2048 /* scsi_cmnd tag map entries */
46 #define FNIC_IO_LOCKS 64 /* IO locks: power of 2 */
47 #define FNIC_DFLT_QUEUE_DEPTH 32
48 #define FNIC_STATS_RATE_LIMIT 4 /* limit rate at which stats are pulled up */
49 
50 /*
51  * Tag bits used for special requests.
52  */
53 #define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */
54 #define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */
55 #define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */
56 #define FNIC_NO_TAG -1
57 
58 /*
59  * Usage of the scsi_cmnd scratchpad.
60  * These fields are locked by the hashed io_req_lock.
61  */
62 #define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
63 #define CMD_STATE(Cmnd) ((Cmnd)->SCp.phase)
64 #define CMD_ABTS_STATUS(Cmnd) ((Cmnd)->SCp.Message)
65 #define CMD_LR_STATUS(Cmnd) ((Cmnd)->SCp.have_data_in)
66 #define CMD_TAG(Cmnd) ((Cmnd)->SCp.sent_command)
67 
68 #define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */
69 
70 #define FNIC_LUN_RESET_TIMEOUT 10000 /* mSec */
71 #define FNIC_HOST_RESET_TIMEOUT 10000 /* mSec */
72 #define FNIC_RMDEVICE_TIMEOUT 1000 /* mSec */
73 #define FNIC_HOST_RESET_SETTLE_TIME 30 /* Sec */
74 
75 #define FNIC_MAX_FCP_TARGET 256
76 
77 extern unsigned int fnic_log_level;
78 
79 #define FNIC_MAIN_LOGGING 0x01
80 #define FNIC_FCS_LOGGING 0x02
81 #define FNIC_SCSI_LOGGING 0x04
82 #define FNIC_ISR_LOGGING 0x08
83 
84 #define FNIC_CHECK_LOGGING(LEVEL, CMD) \
85 do { \
86  if (unlikely(fnic_log_level & LEVEL)) \
87  do { \
88  CMD; \
89  } while (0); \
90 } while (0)
91 
92 #define FNIC_MAIN_DBG(kern_level, host, fmt, args...) \
93  FNIC_CHECK_LOGGING(FNIC_MAIN_LOGGING, \
94  shost_printk(kern_level, host, fmt, ##args);)
95 
96 #define FNIC_FCS_DBG(kern_level, host, fmt, args...) \
97  FNIC_CHECK_LOGGING(FNIC_FCS_LOGGING, \
98  shost_printk(kern_level, host, fmt, ##args);)
99 
100 #define FNIC_SCSI_DBG(kern_level, host, fmt, args...) \
101  FNIC_CHECK_LOGGING(FNIC_SCSI_LOGGING, \
102  shost_printk(kern_level, host, fmt, ##args);)
103 
104 #define FNIC_ISR_DBG(kern_level, host, fmt, args...) \
105  FNIC_CHECK_LOGGING(FNIC_ISR_LOGGING, \
106  shost_printk(kern_level, host, fmt, ##args);)
107 
108 extern const char *fnic_state_str[];
109 
115 };
116 
123 };
124 
128  irqreturn_t (*isr)(int, void *);
129  void *devid;
130 };
131 
137 };
138 
139 #define FNIC_WQ_COPY_MAX 1
140 #define FNIC_WQ_MAX 1
141 #define FNIC_RQ_MAX 1
142 #define FNIC_CQ_MAX (FNIC_WQ_COPY_MAX + FNIC_WQ_MAX + FNIC_RQ_MAX)
143 
144 struct mempool;
145 
146 /* Per-instance private data structure */
147 struct fnic {
148  struct fc_lport *lport;
149  struct fcoe_ctlr ctlr; /* FIP FCoE controller structure */
151 
154 
155  struct vnic_stats *stats;
156  unsigned long stats_time; /* time of stats update */
157  struct vnic_nic_cfg *nic_cfg;
158  char name[IFNAMSIZ];
159  struct timer_list notify_timer; /* used for MSI interrupts */
160 
161  unsigned int err_intr_offset;
162  unsigned int link_intr_offset;
163 
164  unsigned int wq_count;
165  unsigned int cq_count;
166 
167  u32 vlan_hw_insert:1; /* let hw insert the tag */
168  u32 in_remove:1; /* fnic device in removal */
169  u32 stop_rx_link_events:1; /* stop proc. rx frames, link events */
170 
171  struct completion *remove_wait; /* device remove thread blocks */
172 
175 
176  u16 vlan_id; /* VLAN tag including priority */
178  u64 fcp_input_bytes; /* internal statistic */
179  u64 fcp_output_bytes; /* internal statistic */
182 
183  struct list_head list;
184  struct pci_dev *pdev;
186  struct vnic_dev *vdev;
187  unsigned int raw_wq_count;
188  unsigned int wq_copy_count;
189  unsigned int rq_count;
191  unsigned short fw_ack_recd[FNIC_WQ_COPY_MAX];
193  unsigned int intr_count;
195  struct fnic_host_tag *tags;
198  spinlock_t io_req_lock[FNIC_IO_LOCKS]; /* locks for scsi cmnds */
199 
204 
205  /* copy work queue cache line section */
207  /* completion queue cache line section */
209 
211 
212  /* work queue cache line section */
215 
216  /* receive queue cache line section */
218 
219  /* interrupt resource cache line section */
221 };
222 
223 static inline struct fnic *fnic_from_ctlr(struct fcoe_ctlr *fip)
224 {
225  return container_of(fip, struct fnic, ctlr);
226 }
227 
228 extern struct workqueue_struct *fnic_event_queue;
229 extern struct device_attribute *fnic_attrs[];
230 
231 void fnic_clear_intr_mode(struct fnic *fnic);
232 int fnic_set_intr_mode(struct fnic *fnic);
233 void fnic_free_intr(struct fnic *fnic);
234 int fnic_request_intr(struct fnic *fnic);
235 
236 int fnic_send(struct fc_lport *, struct fc_frame *);
237 void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf);
238 void fnic_handle_frame(struct work_struct *work);
239 void fnic_handle_link(struct work_struct *work);
240 int fnic_rq_cmpl_handler(struct fnic *fnic, int);
241 int fnic_alloc_rq_frame(struct vnic_rq *rq);
242 void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf);
243 void fnic_flush_tx(struct fnic *);
244 void fnic_eth_send(struct fcoe_ctlr *, struct sk_buff *skb);
245 void fnic_set_port_id(struct fc_lport *, u32, struct fc_frame *);
246 void fnic_update_mac(struct fc_lport *, u8 *new);
247 void fnic_update_mac_locked(struct fnic *, u8 *new);
248 
249 int fnic_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
250 int fnic_abort_cmd(struct scsi_cmnd *);
251 int fnic_device_reset(struct scsi_cmnd *);
252 int fnic_host_reset(struct scsi_cmnd *);
253 int fnic_reset(struct Scsi_Host *);
254 void fnic_scsi_cleanup(struct fc_lport *);
255 void fnic_scsi_abort_io(struct fc_lport *);
256 void fnic_empty_scsi_cleanup(struct fc_lport *);
257 void fnic_exch_mgr_reset(struct fc_lport *, u32, u32);
258 int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int);
259 int fnic_wq_cmpl_handler(struct fnic *fnic, int);
260 int fnic_flogi_reg_handler(struct fnic *fnic, u32);
262  struct fcpio_host_req *desc);
263 int fnic_fw_reset_handler(struct fnic *fnic);
264 void fnic_terminate_rport_io(struct fc_rport *);
265 const char *fnic_state_to_str(unsigned int state);
266 
267 void fnic_log_q_error(struct fnic *fnic);
268 void fnic_handle_link_event(struct fnic *fnic);
269 
270 #endif /* _FNIC_H_ */