csio_lnode.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * This file is part of the Chelsio FCoE driver for Linux.
  3. *
  4. * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef __CSIO_LNODE_H__
  35. #define __CSIO_LNODE_H__
  36. #include <linux/kref.h>
  37. #include <linux/timer.h>
  38. #include <linux/workqueue.h>
  39. #include <scsi/fc/fc_els.h>
  40. #include "csio_defs.h"
  41. #include "csio_hw.h"
  42. #define CSIO_FCOE_MAX_NPIV 128
  43. #define CSIO_FCOE_MAX_RNODES 2048
  44. /* FDMI port attribute unknown speed */
  45. #define CSIO_HBA_PORTSPEED_UNKNOWN 0x8000
  46. extern int csio_fcoe_rnodes;
  47. extern int csio_fdmi_enable;
  48. /* State machine evets */
  49. enum csio_ln_ev {
  50. CSIO_LNE_NONE = (uint32_t)0,
  51. CSIO_LNE_LINKUP,
  52. CSIO_LNE_FAB_INIT_DONE,
  53. CSIO_LNE_LINK_DOWN,
  54. CSIO_LNE_DOWN_LINK,
  55. CSIO_LNE_LOGO,
  56. CSIO_LNE_CLOSE,
  57. CSIO_LNE_MAX_EVENT,
  58. };
  59. struct csio_fcf_info {
  60. struct list_head list;
  61. uint8_t priority;
  62. uint8_t mac[6];
  63. uint8_t name_id[8];
  64. uint8_t fabric[8];
  65. uint16_t vf_id;
  66. uint8_t vlan_id;
  67. uint16_t max_fcoe_size;
  68. uint8_t fc_map[3];
  69. uint32_t fka_adv;
  70. uint32_t fcfi;
  71. uint8_t get_next:1;
  72. uint8_t link_aff:1;
  73. uint8_t fpma:1;
  74. uint8_t spma:1;
  75. uint8_t login:1;
  76. uint8_t portid;
  77. uint8_t spma_mac[6];
  78. struct kref kref;
  79. };
  80. /* Defines for flags */
  81. #define CSIO_LNF_FIPSUPP 0x00000001 /* Fip Supported */
  82. #define CSIO_LNF_NPIVSUPP 0x00000002 /* NPIV supported */
  83. #define CSIO_LNF_LINK_ENABLE 0x00000004 /* Link enabled */
  84. #define CSIO_LNF_FDMI_ENABLE 0x00000008 /* FDMI support */
  85. /* Transport events */
  86. enum csio_ln_fc_evt {
  87. CSIO_LN_FC_LINKUP = 1,
  88. CSIO_LN_FC_LINKDOWN,
  89. CSIO_LN_FC_RSCN,
  90. CSIO_LN_FC_ATTRIB_UPDATE,
  91. };
  92. /* Lnode stats */
  93. struct csio_lnode_stats {
  94. uint32_t n_link_up; /* Link down */
  95. uint32_t n_link_down; /* Link up */
  96. uint32_t n_err; /* error */
  97. uint32_t n_err_nomem; /* memory not available */
  98. uint32_t n_inval_parm; /* Invalid parameters */
  99. uint32_t n_evt_unexp; /* unexpected event */
  100. uint32_t n_evt_drop; /* dropped event */
  101. uint32_t n_rnode_match; /* matched rnode */
  102. uint32_t n_dev_loss_tmo; /* Device loss timeout */
  103. uint32_t n_fdmi_err; /* fdmi err */
  104. uint32_t n_evt_fw[PROTO_ERR_IMPL_LOGO + 1]; /* fw events */
  105. enum csio_ln_ev n_evt_sm[CSIO_LNE_MAX_EVENT]; /* State m/c events */
  106. uint32_t n_rnode_alloc; /* rnode allocated */
  107. uint32_t n_rnode_free; /* rnode freed */
  108. uint32_t n_rnode_nomem; /* rnode alloc failure */
  109. uint32_t n_input_requests; /* Input Requests */
  110. uint32_t n_output_requests; /* Output Requests */
  111. uint32_t n_control_requests; /* Control Requests */
  112. uint32_t n_input_bytes; /* Input Bytes */
  113. uint32_t n_output_bytes; /* Output Bytes */
  114. uint32_t rsvd1;
  115. };
  116. /* Common Lnode params */
  117. struct csio_lnode_params {
  118. uint32_t ra_tov;
  119. uint32_t fcfi;
  120. uint32_t log_level; /* Module level for debugging */
  121. };
  122. struct csio_service_parms {
  123. struct fc_els_csp csp; /* Common service parms */
  124. uint8_t wwpn[8]; /* WWPN */
  125. uint8_t wwnn[8]; /* WWNN */
  126. struct fc_els_cssp clsp[4]; /* Class service params */
  127. uint8_t vvl[16]; /* Vendor version level */
  128. };
  129. /* Lnode */
  130. struct csio_lnode {
  131. struct csio_sm sm; /* State machine + sibling
  132. * lnode list.
  133. */
  134. struct csio_hw *hwp; /* Pointer to the HW module */
  135. uint8_t portid; /* Port ID */
  136. uint8_t rsvd1;
  137. uint16_t rsvd2;
  138. uint32_t dev_num; /* Device number */
  139. uint32_t flags; /* Flags */
  140. struct list_head fcf_lsthead; /* FCF entries */
  141. struct csio_fcf_info *fcfinfo; /* FCF in use */
  142. struct csio_ioreq *mgmt_req; /* MGMT request */
  143. /* FCoE identifiers */
  144. uint8_t mac[6];
  145. uint32_t nport_id;
  146. struct csio_service_parms ln_sparm; /* Service parms */
  147. /* Firmware identifiers */
  148. uint32_t fcf_flowid; /*fcf flowid */
  149. uint32_t vnp_flowid;
  150. uint16_t ssn_cnt; /* Registered Session */
  151. uint8_t cur_evt; /* Current event */
  152. uint8_t prev_evt; /* Previous event */
  153. /* Children */
  154. struct list_head cln_head; /* Head of the children lnode
  155. * list.
  156. */
  157. uint32_t num_vports; /* Total NPIV/children LNodes*/
  158. struct csio_lnode *pln; /* Parent lnode of child
  159. * lnodes.
  160. */
  161. struct list_head cmpl_q; /* Pending I/Os on this lnode */
  162. /* Remote node information */
  163. struct list_head rnhead; /* Head of rnode list */
  164. uint32_t num_reg_rnodes; /* Number of rnodes registered
  165. * with the host.
  166. */
  167. uint32_t n_scsi_tgts; /* Number of scsi targets
  168. * found
  169. */
  170. uint32_t last_scan_ntgts;/* Number of scsi targets
  171. * found per last scan.
  172. */
  173. uint32_t tgt_scan_tick; /* timer started after
  174. * new tgt found
  175. */
  176. /* FC transport data */
  177. struct fc_vport *fc_vport;
  178. struct fc_host_statistics fch_stats;
  179. struct csio_lnode_stats stats; /* Common lnode stats */
  180. struct csio_lnode_params params; /* Common lnode params */
  181. };
  182. #define csio_lnode_to_hw(ln) ((ln)->hwp)
  183. #define csio_root_lnode(ln) (csio_lnode_to_hw((ln))->rln)
  184. #define csio_parent_lnode(ln) ((ln)->pln)
  185. #define csio_ln_flowid(ln) ((ln)->vnp_flowid)
  186. #define csio_ln_wwpn(ln) ((ln)->ln_sparm.wwpn)
  187. #define csio_ln_wwnn(ln) ((ln)->ln_sparm.wwnn)
  188. #define csio_is_root_ln(ln) (((ln) == csio_root_lnode((ln))) ? 1 : 0)
  189. #define csio_is_phys_ln(ln) (((ln)->pln == NULL) ? 1 : 0)
  190. #define csio_is_npiv_ln(ln) (((ln)->pln != NULL) ? 1 : 0)
  191. #define csio_ln_dbg(_ln, _fmt, ...) \
  192. csio_dbg(_ln->hwp, "%x:%x "_fmt, CSIO_DEVID_HI(_ln), \
  193. CSIO_DEVID_LO(_ln), ##__VA_ARGS__);
  194. #define csio_ln_err(_ln, _fmt, ...) \
  195. csio_err(_ln->hwp, "%x:%x "_fmt, CSIO_DEVID_HI(_ln), \
  196. CSIO_DEVID_LO(_ln), ##__VA_ARGS__);
  197. #define csio_ln_warn(_ln, _fmt, ...) \
  198. csio_warn(_ln->hwp, "%x:%x "_fmt, CSIO_DEVID_HI(_ln), \
  199. CSIO_DEVID_LO(_ln), ##__VA_ARGS__);
  200. /* HW->Lnode notifications */
  201. enum csio_ln_notify {
  202. CSIO_LN_NOTIFY_HWREADY = 1,
  203. CSIO_LN_NOTIFY_HWSTOP,
  204. CSIO_LN_NOTIFY_HWREMOVE,
  205. CSIO_LN_NOTIFY_HWRESET,
  206. };
  207. void csio_fcoe_fwevt_handler(struct csio_hw *, __u8 cpl_op, __be64 *);
  208. int csio_is_lnode_ready(struct csio_lnode *);
  209. void csio_lnode_state_to_str(struct csio_lnode *ln, int8_t *str);
  210. struct csio_lnode *csio_lnode_lookup_by_wwpn(struct csio_hw *, uint8_t *);
  211. int csio_get_phy_port_stats(struct csio_hw *, uint8_t ,
  212. struct fw_fcoe_port_stats *);
  213. int csio_scan_done(struct csio_lnode *, unsigned long, unsigned long,
  214. unsigned long, unsigned long);
  215. void csio_notify_lnodes(struct csio_hw *, enum csio_ln_notify);
  216. void csio_disable_lnodes(struct csio_hw *, uint8_t, bool);
  217. void csio_lnode_async_event(struct csio_lnode *, enum csio_ln_fc_evt);
  218. int csio_ln_fdmi_start(struct csio_lnode *, void *);
  219. int csio_lnode_start(struct csio_lnode *);
  220. void csio_lnode_stop(struct csio_lnode *);
  221. void csio_lnode_close(struct csio_lnode *);
  222. int csio_lnode_init(struct csio_lnode *, struct csio_hw *,
  223. struct csio_lnode *);
  224. void csio_lnode_exit(struct csio_lnode *);
  225. #endif /* ifndef __CSIO_LNODE_H__ */