libfcoe.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved.
  3. * Copyright (c) 2007-2008 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. * Maintained at www.Open-FCoE.org
  19. */
  20. #ifndef _LIBFCOE_H
  21. #define _LIBFCOE_H
  22. #include <linux/etherdevice.h>
  23. #include <linux/if_ether.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/workqueue.h>
  27. #include <scsi/fc/fc_fcoe.h>
  28. #include <scsi/libfc.h>
  29. /*
  30. * FIP tunable parameters.
  31. */
  32. #define FCOE_CTLR_START_DELAY 2000 /* mS after first adv. to choose FCF */
  33. #define FCOE_CTRL_SOL_TOV 2000 /* min. solicitation interval (mS) */
  34. #define FCOE_CTLR_FCF_LIMIT 20 /* max. number of FCF entries */
  35. /**
  36. * enum fip_state - internal state of FCoE controller.
  37. * @FIP_ST_DISABLED: controller has been disabled or not yet enabled.
  38. * @FIP_ST_LINK_WAIT: the physical link is down or unusable.
  39. * @FIP_ST_AUTO: determining whether to use FIP or non-FIP mode.
  40. * @FIP_ST_NON_FIP: non-FIP mode selected.
  41. * @FIP_ST_ENABLED: FIP mode selected.
  42. */
  43. enum fip_state {
  44. FIP_ST_DISABLED,
  45. FIP_ST_LINK_WAIT,
  46. FIP_ST_AUTO,
  47. FIP_ST_NON_FIP,
  48. FIP_ST_ENABLED,
  49. };
  50. /**
  51. * struct fcoe_ctlr - FCoE Controller and FIP state.
  52. * @state: internal FIP state for network link and FIP or non-FIP mode.
  53. * @lp: &fc_lport: libfc local port.
  54. * @sel_fcf: currently selected FCF, or NULL.
  55. * @fcfs: list of discovered FCFs.
  56. * @fcf_count: number of discovered FCF entries.
  57. * @sol_time: time when a multicast solicitation was last sent.
  58. * @sel_time: time after which to select an FCF.
  59. * @port_ka_time: time of next port keep-alive.
  60. * @ctlr_ka_time: time of next controller keep-alive.
  61. * @timer: timer struct used for all delayed events.
  62. * @link_work: &work_struct for doing FCF selection.
  63. * @recv_work: &work_struct for receiving FIP frames.
  64. * @fip_recv_list: list of received FIP frames.
  65. * @user_mfs: configured maximum FC frame size, including FC header.
  66. * @flogi_oxid: exchange ID of most recent fabric login.
  67. * @flogi_count: number of FLOGI attempts in AUTO mode.
  68. * @link: current link status for libfc.
  69. * @last_link: last link state reported to libfc.
  70. * @map_dest: use the FC_MAP mode for destination MAC addresses.
  71. * @spma: supports SPMA server-provided MACs mode
  72. * @dest_addr: MAC address of the selected FC forwarder.
  73. * @ctl_src_addr: the native MAC address of our local port.
  74. * @data_src_addr: the assigned MAC address for the local port after FLOGI.
  75. * @send: LLD-supplied function to handle sending of FIP Ethernet frames.
  76. * @update_mac: LLD-supplied function to handle changes to MAC addresses.
  77. * @lock: lock protecting this structure.
  78. *
  79. * This structure is used by all FCoE drivers. It contains information
  80. * needed by all FCoE low-level drivers (LLDs) as well as internal state
  81. * for FIP, and fields shared with the LLDS.
  82. */
  83. struct fcoe_ctlr {
  84. enum fip_state state;
  85. struct fc_lport *lp;
  86. struct fcoe_fcf *sel_fcf;
  87. struct list_head fcfs;
  88. u16 fcf_count;
  89. unsigned long sol_time;
  90. unsigned long sel_time;
  91. unsigned long port_ka_time;
  92. unsigned long ctlr_ka_time;
  93. struct timer_list timer;
  94. struct work_struct link_work;
  95. struct work_struct recv_work;
  96. struct sk_buff_head fip_recv_list;
  97. u16 user_mfs;
  98. u16 flogi_oxid;
  99. u8 flogi_count;
  100. u8 link;
  101. u8 last_link;
  102. u8 map_dest;
  103. u8 spma;
  104. u8 dest_addr[ETH_ALEN];
  105. u8 ctl_src_addr[ETH_ALEN];
  106. u8 data_src_addr[ETH_ALEN];
  107. void (*send)(struct fcoe_ctlr *, struct sk_buff *);
  108. void (*update_mac)(struct fcoe_ctlr *, u8 *old, u8 *new);
  109. spinlock_t lock;
  110. };
  111. /*
  112. * struct fcoe_fcf - Fibre-Channel Forwarder.
  113. * @list: list linkage.
  114. * @time: system time (jiffies) when an advertisement was last received.
  115. * @switch_name: WWN of switch from advertisement.
  116. * @fabric_name: WWN of fabric from advertisement.
  117. * @fc_map: FC_MAP value from advertisement.
  118. * @fcf_mac: Ethernet address of the FCF.
  119. * @vfid: virtual fabric ID.
  120. * @pri: seletion priority, smaller values are better.
  121. * @flags: flags received from advertisement.
  122. * @fka_period: keep-alive period, in jiffies.
  123. *
  124. * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that
  125. * passes FCoE frames on to an FC fabric. This structure represents
  126. * one FCF from which advertisements have been received.
  127. *
  128. * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and
  129. * @fcf_mac together form the lookup key.
  130. */
  131. struct fcoe_fcf {
  132. struct list_head list;
  133. unsigned long time;
  134. u64 switch_name;
  135. u64 fabric_name;
  136. u32 fc_map;
  137. u16 vfid;
  138. u8 fcf_mac[ETH_ALEN];
  139. u8 pri;
  140. u16 flags;
  141. u32 fka_period;
  142. };
  143. /* FIP API functions */
  144. void fcoe_ctlr_init(struct fcoe_ctlr *);
  145. void fcoe_ctlr_destroy(struct fcoe_ctlr *);
  146. void fcoe_ctlr_link_up(struct fcoe_ctlr *);
  147. int fcoe_ctlr_link_down(struct fcoe_ctlr *);
  148. int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct sk_buff *);
  149. void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *);
  150. int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_frame *fp, u8 *sa);
  151. /* libfcoe funcs */
  152. u64 fcoe_wwn_from_mac(unsigned char mac[], unsigned int, unsigned int);
  153. int fcoe_libfc_config(struct fc_lport *, struct libfc_function_template *);
  154. #endif /* _LIBFCOE_H */