fnic.h 12 KB

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