fnic.h 10.0 KB

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