fnic.h 8.5 KB

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