libfcoe.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 <linux/random.h>
  28. #include <scsi/fc/fc_fcoe.h>
  29. #include <scsi/libfc.h>
  30. #include <scsi/fcoe_sysfs.h>
  31. #define FCOE_MAX_CMD_LEN 16 /* Supported CDB length */
  32. /*
  33. * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload)
  34. * + 4 (FC CRC) + 4 (FCoE trailer) = 2158 bytes
  35. */
  36. #define FCOE_MTU 2158
  37. /*
  38. * FIP tunable parameters.
  39. */
  40. #define FCOE_CTLR_START_DELAY 2000 /* mS after first adv. to choose FCF */
  41. #define FCOE_CTRL_SOL_TOV 2000 /* min. solicitation interval (mS) */
  42. #define FCOE_CTLR_FCF_LIMIT 20 /* max. number of FCF entries */
  43. #define FCOE_CTLR_VN2VN_LOGIN_LIMIT 3 /* max. VN2VN rport login retries */
  44. /**
  45. * enum fip_state - internal state of FCoE controller.
  46. * @FIP_ST_DISABLED: controller has been disabled or not yet enabled.
  47. * @FIP_ST_LINK_WAIT: the physical link is down or unusable.
  48. * @FIP_ST_AUTO: determining whether to use FIP or non-FIP mode.
  49. * @FIP_ST_NON_FIP: non-FIP mode selected.
  50. * @FIP_ST_ENABLED: FIP mode selected.
  51. * @FIP_ST_VNMP_START: VN2VN multipath mode start, wait
  52. * @FIP_ST_VNMP_PROBE1: VN2VN sent first probe, listening
  53. * @FIP_ST_VNMP_PROBE2: VN2VN sent second probe, listening
  54. * @FIP_ST_VNMP_CLAIM: VN2VN sent claim, waiting for responses
  55. * @FIP_ST_VNMP_UP: VN2VN multipath mode operation
  56. */
  57. enum fip_state {
  58. FIP_ST_DISABLED,
  59. FIP_ST_LINK_WAIT,
  60. FIP_ST_AUTO,
  61. FIP_ST_NON_FIP,
  62. FIP_ST_ENABLED,
  63. FIP_ST_VNMP_START,
  64. FIP_ST_VNMP_PROBE1,
  65. FIP_ST_VNMP_PROBE2,
  66. FIP_ST_VNMP_CLAIM,
  67. FIP_ST_VNMP_UP,
  68. };
  69. /*
  70. * Modes:
  71. * The mode is the state that is to be entered after link up.
  72. * It must not change after fcoe_ctlr_init() sets it.
  73. */
  74. enum fip_mode {
  75. FIP_MODE_AUTO,
  76. FIP_MODE_NON_FIP,
  77. FIP_MODE_FABRIC,
  78. FIP_MODE_VN2VN,
  79. };
  80. /**
  81. * struct fcoe_ctlr - FCoE Controller and FIP state
  82. * @state: internal FIP state for network link and FIP or non-FIP mode.
  83. * @mode: LLD-selected mode.
  84. * @lp: &fc_lport: libfc local port.
  85. * @sel_fcf: currently selected FCF, or NULL.
  86. * @fcfs: list of discovered FCFs.
  87. * @cdev: (Optional) pointer to sysfs fcoe_ctlr_device.
  88. * @fcf_count: number of discovered FCF entries.
  89. * @sol_time: time when a multicast solicitation was last sent.
  90. * @sel_time: time after which to select an FCF.
  91. * @port_ka_time: time of next port keep-alive.
  92. * @ctlr_ka_time: time of next controller keep-alive.
  93. * @timer: timer struct used for all delayed events.
  94. * @timer_work: &work_struct for doing keep-alives and resets.
  95. * @recv_work: &work_struct for receiving FIP frames.
  96. * @fip_recv_list: list of received FIP frames.
  97. * @flogi_req: clone of FLOGI request sent
  98. * @rnd_state: state for pseudo-random number generator.
  99. * @port_id: proposed or selected local-port ID.
  100. * @user_mfs: configured maximum FC frame size, including FC header.
  101. * @flogi_oxid: exchange ID of most recent fabric login.
  102. * @flogi_req_send: send of FLOGI requested
  103. * @flogi_count: number of FLOGI attempts in AUTO mode.
  104. * @map_dest: use the FC_MAP mode for destination MAC addresses.
  105. * @fip_resp: start FIP VLAN discovery responder
  106. * @spma: supports SPMA server-provided MACs mode
  107. * @probe_tries: number of FC_IDs probed
  108. * @priority: DCBx FCoE APP priority
  109. * @dest_addr: MAC address of the selected FC forwarder.
  110. * @ctl_src_addr: the native MAC address of our local port.
  111. * @send: LLD-supplied function to handle sending FIP Ethernet frames
  112. * @update_mac: LLD-supplied function to handle changes to MAC addresses.
  113. * @get_src_addr: LLD-supplied function to supply a source MAC address.
  114. * @ctlr_mutex: lock protecting this structure.
  115. * @ctlr_lock: spinlock covering flogi_req
  116. *
  117. * This structure is used by all FCoE drivers. It contains information
  118. * needed by all FCoE low-level drivers (LLDs) as well as internal state
  119. * for FIP, and fields shared with the LLDS.
  120. */
  121. struct fcoe_ctlr {
  122. enum fip_state state;
  123. enum fip_mode mode;
  124. struct fc_lport *lp;
  125. struct fcoe_fcf *sel_fcf;
  126. struct list_head fcfs;
  127. struct fcoe_ctlr_device *cdev;
  128. u16 fcf_count;
  129. unsigned long sol_time;
  130. unsigned long sel_time;
  131. unsigned long port_ka_time;
  132. unsigned long ctlr_ka_time;
  133. struct timer_list timer;
  134. struct work_struct timer_work;
  135. struct work_struct recv_work;
  136. struct sk_buff_head fip_recv_list;
  137. struct sk_buff *flogi_req;
  138. struct rnd_state rnd_state;
  139. u32 port_id;
  140. u16 user_mfs;
  141. u16 flogi_oxid;
  142. u8 flogi_req_send;
  143. u8 flogi_count;
  144. bool map_dest;
  145. bool fip_resp;
  146. u8 spma;
  147. u8 probe_tries;
  148. u8 priority;
  149. u8 dest_addr[ETH_ALEN];
  150. u8 ctl_src_addr[ETH_ALEN];
  151. void (*send)(struct fcoe_ctlr *, struct sk_buff *);
  152. void (*update_mac)(struct fc_lport *, u8 *addr);
  153. u8 * (*get_src_addr)(struct fc_lport *);
  154. struct mutex ctlr_mutex;
  155. spinlock_t ctlr_lock;
  156. };
  157. /**
  158. * fcoe_ctlr_priv() - Return the private data from a fcoe_ctlr
  159. * @cltr: The fcoe_ctlr whose private data will be returned
  160. */
  161. static inline void *fcoe_ctlr_priv(const struct fcoe_ctlr *ctlr)
  162. {
  163. return (void *)(ctlr + 1);
  164. }
  165. /*
  166. * This assumes that the fcoe_ctlr (x) is allocated with the fcoe_ctlr_device.
  167. */
  168. #define fcoe_ctlr_to_ctlr_dev(x) \
  169. (x)->cdev
  170. /**
  171. * struct fcoe_fcf - Fibre-Channel Forwarder
  172. * @list: list linkage
  173. * @event_work: Work for FC Transport actions queue
  174. * @event: The event to be processed
  175. * @fip: The controller that the FCF was discovered on
  176. * @fcf_dev: The associated fcoe_fcf_device instance
  177. * @time: system time (jiffies) when an advertisement was last received
  178. * @switch_name: WWN of switch from advertisement
  179. * @fabric_name: WWN of fabric from advertisement
  180. * @fc_map: FC_MAP value from advertisement
  181. * @fcf_mac: Ethernet address of the FCF for FIP traffic
  182. * @fcoe_mac: Ethernet address of the FCF for FCoE traffic
  183. * @vfid: virtual fabric ID
  184. * @pri: selection priority, smaller values are better
  185. * @flogi_sent: current FLOGI sent to this FCF
  186. * @flags: flags received from advertisement
  187. * @fka_period: keep-alive period, in jiffies
  188. *
  189. * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that
  190. * passes FCoE frames on to an FC fabric. This structure represents
  191. * one FCF from which advertisements have been received.
  192. *
  193. * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and
  194. * @fcf_mac together form the lookup key.
  195. */
  196. struct fcoe_fcf {
  197. struct list_head list;
  198. struct work_struct event_work;
  199. struct fcoe_ctlr *fip;
  200. struct fcoe_fcf_device *fcf_dev;
  201. unsigned long time;
  202. u64 switch_name;
  203. u64 fabric_name;
  204. u32 fc_map;
  205. u16 vfid;
  206. u8 fcf_mac[ETH_ALEN];
  207. u8 fcoe_mac[ETH_ALEN];
  208. u8 pri;
  209. u8 flogi_sent;
  210. u16 flags;
  211. u32 fka_period;
  212. u8 fd_flags:1;
  213. };
  214. #define fcoe_fcf_to_fcf_dev(x) \
  215. ((x)->fcf_dev)
  216. /**
  217. * struct fcoe_rport - VN2VN remote port
  218. * @time: time of create or last beacon packet received from node
  219. * @fcoe_len: max FCoE frame size, not including VLAN or Ethernet headers
  220. * @flags: flags from probe or claim
  221. * @login_count: number of unsuccessful rport logins to this port
  222. * @enode_mac: E_Node control MAC address
  223. * @vn_mac: VN_Node assigned MAC address for data
  224. */
  225. struct fcoe_rport {
  226. struct fc_rport_priv rdata;
  227. unsigned long time;
  228. u16 fcoe_len;
  229. u16 flags;
  230. u8 login_count;
  231. u8 enode_mac[ETH_ALEN];
  232. u8 vn_mac[ETH_ALEN];
  233. };
  234. /* FIP API functions */
  235. void fcoe_ctlr_init(struct fcoe_ctlr *, enum fip_mode);
  236. void fcoe_ctlr_destroy(struct fcoe_ctlr *);
  237. void fcoe_ctlr_link_up(struct fcoe_ctlr *);
  238. int fcoe_ctlr_link_down(struct fcoe_ctlr *);
  239. int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *);
  240. void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *);
  241. int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *,
  242. struct fc_frame *);
  243. /* libfcoe funcs */
  244. u64 fcoe_wwn_from_mac(unsigned char mac[MAX_ADDR_LEN], unsigned int, unsigned int);
  245. int fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *,
  246. const struct libfc_function_template *, int init_fcp);
  247. u32 fcoe_fc_crc(struct fc_frame *fp);
  248. int fcoe_start_io(struct sk_buff *skb);
  249. int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type);
  250. void __fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb,
  251. struct net_device *netdev);
  252. void fcoe_wwn_to_str(u64 wwn, char *buf, int len);
  253. int fcoe_validate_vport_create(struct fc_vport *vport);
  254. int fcoe_link_speed_update(struct fc_lport *);
  255. void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *);
  256. void fcoe_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev);
  257. /**
  258. * is_fip_mode() - returns true if FIP mode selected.
  259. * @fip: FCoE controller.
  260. */
  261. static inline bool is_fip_mode(struct fcoe_ctlr *fip)
  262. {
  263. return fip->state == FIP_ST_ENABLED;
  264. }
  265. /* helper for FCoE SW HBA drivers, can include subven and subdev if needed. The
  266. * modpost would use pci_device_id table to auto-generate formatted module alias
  267. * into the corresponding .mod.c file, but there may or may not be a pci device
  268. * id table for FCoE drivers so we use the following helper for build the fcoe
  269. * driver module alias.
  270. */
  271. #define MODULE_ALIAS_FCOE_PCI(ven, dev) \
  272. MODULE_ALIAS("fcoe-pci:" \
  273. "v" __stringify(ven) \
  274. "d" __stringify(dev) "sv*sd*bc*sc*i*")
  275. /* the name of the default FCoE transport driver fcoe.ko */
  276. #define FCOE_TRANSPORT_DEFAULT "fcoe"
  277. /* struct fcoe_transport - The FCoE transport interface
  278. * @name: a vendor specific name for their FCoE transport driver
  279. * @attached: whether this transport is already attached
  280. * @list: list linkage to all attached transports
  281. * @match: handler to allow the transport driver to match up a given netdev
  282. * @alloc: handler to allocate per-instance FCoE structures
  283. * (no discovery or login)
  284. * @create: handler to sysfs entry of create for FCoE instances
  285. * @destroy: handler to delete per-instance FCoE structures
  286. * (frees all memory)
  287. * @enable: handler to sysfs entry of enable for FCoE instances
  288. * @disable: handler to sysfs entry of disable for FCoE instances
  289. */
  290. struct fcoe_transport {
  291. char name[IFNAMSIZ];
  292. bool attached;
  293. struct list_head list;
  294. bool (*match) (struct net_device *device);
  295. int (*alloc) (struct net_device *device);
  296. int (*create) (struct net_device *device, enum fip_mode fip_mode);
  297. int (*destroy) (struct net_device *device);
  298. int (*enable) (struct net_device *device);
  299. int (*disable) (struct net_device *device);
  300. };
  301. /**
  302. * struct fcoe_percpu_s - The context for FCoE receive thread(s)
  303. * @kthread: The thread context (used by bnx2fc)
  304. * @work: The work item (used by fcoe)
  305. * @fcoe_rx_list: The queue of pending packets to process
  306. * @page: The memory page for calculating frame trailer CRCs
  307. * @crc_eof_offset: The offset into the CRC page pointing to available
  308. * memory for a new trailer
  309. */
  310. struct fcoe_percpu_s {
  311. struct task_struct *kthread;
  312. struct work_struct work;
  313. struct sk_buff_head fcoe_rx_list;
  314. struct page *crc_eof_page;
  315. int crc_eof_offset;
  316. };
  317. /**
  318. * struct fcoe_port - The FCoE private structure
  319. * @priv: The associated fcoe interface. The structure is
  320. * defined by the low level driver
  321. * @lport: The associated local port
  322. * @fcoe_pending_queue: The pending Rx queue of skbs
  323. * @fcoe_pending_queue_active: Indicates if the pending queue is active
  324. * @max_queue_depth: Max queue depth of pending queue
  325. * @min_queue_depth: Min queue depth of pending queue
  326. * @timer: The queue timer
  327. * @destroy_work: Handle for work context
  328. * (to prevent RTNL deadlocks)
  329. * @data_srt_addr: Source address for data
  330. *
  331. * An instance of this structure is to be allocated along with the
  332. * Scsi_Host and libfc fc_lport structures.
  333. */
  334. struct fcoe_port {
  335. void *priv;
  336. struct fc_lport *lport;
  337. struct sk_buff_head fcoe_pending_queue;
  338. u8 fcoe_pending_queue_active;
  339. u32 max_queue_depth;
  340. u32 min_queue_depth;
  341. struct timer_list timer;
  342. struct work_struct destroy_work;
  343. u8 data_src_addr[ETH_ALEN];
  344. struct net_device * (*get_netdev)(const struct fc_lport *lport);
  345. };
  346. /**
  347. * fcoe_get_netdev() - Return the net device associated with a local port
  348. * @lport: The local port to get the net device from
  349. */
  350. static inline struct net_device *fcoe_get_netdev(const struct fc_lport *lport)
  351. {
  352. struct fcoe_port *port = ((struct fcoe_port *)lport_priv(lport));
  353. return (port->get_netdev) ? port->get_netdev(lport) : NULL;
  354. }
  355. void fcoe_clean_pending_queue(struct fc_lport *);
  356. void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb);
  357. void fcoe_queue_timer(ulong lport);
  358. int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
  359. struct fcoe_percpu_s *fps);
  360. /* FCoE Sysfs helpers */
  361. void fcoe_fcf_get_selected(struct fcoe_fcf_device *);
  362. void fcoe_ctlr_set_fip_mode(struct fcoe_ctlr_device *);
  363. /**
  364. * struct netdev_list
  365. * A mapping from netdevice to fcoe_transport
  366. */
  367. struct fcoe_netdev_mapping {
  368. struct list_head list;
  369. struct net_device *netdev;
  370. struct fcoe_transport *ft;
  371. };
  372. /* fcoe transports registration and deregistration */
  373. int fcoe_transport_attach(struct fcoe_transport *ft);
  374. int fcoe_transport_detach(struct fcoe_transport *ft);
  375. /* sysfs store handler for ctrl_control interface */
  376. ssize_t fcoe_ctlr_create_store(struct bus_type *bus,
  377. const char *buf, size_t count);
  378. ssize_t fcoe_ctlr_destroy_store(struct bus_type *bus,
  379. const char *buf, size_t count);
  380. #endif /* _LIBFCOE_H */