blob: 7d18b500f2c1fc093f7f85cf9ae8731ee3f4a3de [file] [log] [blame]
Robert Love85b4aa42008-12-09 15:10:24 -08001/*
Joe Eykholt97c83892009-03-17 11:42:40 -07002 * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2007-2008 Intel Corporation. All rights reserved.
Robert Love85b4aa42008-12-09 15:10:24 -08004 *
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
21#ifndef _LIBFCOE_H
22#define _LIBFCOE_H
23
Joe Eykholt97c83892009-03-17 11:42:40 -070024#include <linux/etherdevice.h>
25#include <linux/if_ether.h>
Robert Love85b4aa42008-12-09 15:10:24 -080026#include <linux/netdevice.h>
27#include <linux/skbuff.h>
Joe Eykholt97c83892009-03-17 11:42:40 -070028#include <linux/workqueue.h>
Robert Love85b4aa42008-12-09 15:10:24 -080029#include <scsi/fc/fc_fcoe.h>
30#include <scsi/libfc.h>
31
Vasu Devda87bfa2010-04-09 14:22:59 -070032#define FCOE_MAX_CMD_LEN 16 /* Supported CDB length */
33
Joe Eykholt97c83892009-03-17 11:42:40 -070034/*
35 * FIP tunable parameters.
36 */
37#define FCOE_CTLR_START_DELAY 2000 /* mS after first adv. to choose FCF */
38#define FCOE_CTRL_SOL_TOV 2000 /* min. solicitation interval (mS) */
39#define FCOE_CTLR_FCF_LIMIT 20 /* max. number of FCF entries */
40
41/**
42 * enum fip_state - internal state of FCoE controller.
43 * @FIP_ST_DISABLED: controller has been disabled or not yet enabled.
44 * @FIP_ST_LINK_WAIT: the physical link is down or unusable.
45 * @FIP_ST_AUTO: determining whether to use FIP or non-FIP mode.
46 * @FIP_ST_NON_FIP: non-FIP mode selected.
47 * @FIP_ST_ENABLED: FIP mode selected.
48 */
49enum fip_state {
50 FIP_ST_DISABLED,
51 FIP_ST_LINK_WAIT,
52 FIP_ST_AUTO,
53 FIP_ST_NON_FIP,
54 FIP_ST_ENABLED,
55};
56
57/**
Robert Love70b51aa2009-11-03 11:47:45 -080058 * struct fcoe_ctlr - FCoE Controller and FIP state
59 * @state: internal FIP state for network link and FIP or non-FIP mode.
Joe Eykholt22bcd222009-11-03 11:48:11 -080060 * @mode: LLD-selected mode.
Robert Love70b51aa2009-11-03 11:47:45 -080061 * @lp: &fc_lport: libfc local port.
62 * @sel_fcf: currently selected FCF, or NULL.
63 * @fcfs: list of discovered FCFs.
64 * @fcf_count: number of discovered FCF entries.
65 * @sol_time: time when a multicast solicitation was last sent.
66 * @sel_time: time after which to select an FCF.
67 * @port_ka_time: time of next port keep-alive.
68 * @ctlr_ka_time: time of next controller keep-alive.
69 * @timer: timer struct used for all delayed events.
Joe Eykholt42913652010-03-12 16:08:23 -080070 * @timer_work: &work_struct for doing keep-alives and resets.
Robert Love70b51aa2009-11-03 11:47:45 -080071 * @recv_work: &work_struct for receiving FIP frames.
Joe Eykholt97c83892009-03-17 11:42:40 -070072 * @fip_recv_list: list of received FIP frames.
Robert Love70b51aa2009-11-03 11:47:45 -080073 * @user_mfs: configured maximum FC frame size, including FC header.
74 * @flogi_oxid: exchange ID of most recent fabric login.
75 * @flogi_count: number of FLOGI attempts in AUTO mode.
Robert Love70b51aa2009-11-03 11:47:45 -080076 * @map_dest: use the FC_MAP mode for destination MAC addresses.
77 * @spma: supports SPMA server-provided MACs mode
Robert Love70b51aa2009-11-03 11:47:45 -080078 * @dest_addr: MAC address of the selected FC forwarder.
79 * @ctl_src_addr: the native MAC address of our local port.
80 * @send: LLD-supplied function to handle sending FIP Ethernet frames
81 * @update_mac: LLD-supplied function to handle changes to MAC addresses.
82 * @get_src_addr: LLD-supplied function to supply a source MAC address.
Joe Eykholtfdb068c2010-07-20 15:19:47 -070083 * @ctlr_mutex: lock protecting this structure.
Joe Eykholt97c83892009-03-17 11:42:40 -070084 *
85 * This structure is used by all FCoE drivers. It contains information
86 * needed by all FCoE low-level drivers (LLDs) as well as internal state
87 * for FIP, and fields shared with the LLDS.
88 */
89struct fcoe_ctlr {
90 enum fip_state state;
Joe Eykholt22bcd222009-11-03 11:48:11 -080091 enum fip_state mode;
Joe Eykholt97c83892009-03-17 11:42:40 -070092 struct fc_lport *lp;
93 struct fcoe_fcf *sel_fcf;
94 struct list_head fcfs;
95 u16 fcf_count;
96 unsigned long sol_time;
97 unsigned long sel_time;
98 unsigned long port_ka_time;
99 unsigned long ctlr_ka_time;
100 struct timer_list timer;
Joe Eykholt42913652010-03-12 16:08:23 -0800101 struct work_struct timer_work;
Joe Eykholt97c83892009-03-17 11:42:40 -0700102 struct work_struct recv_work;
103 struct sk_buff_head fip_recv_list;
104 u16 user_mfs;
105 u16 flogi_oxid;
106 u8 flogi_count;
Joe Eykholt97c83892009-03-17 11:42:40 -0700107 u8 map_dest;
Vasu Dev184dd342009-05-17 12:33:28 +0000108 u8 spma;
Joe Eykholt97c83892009-03-17 11:42:40 -0700109 u8 dest_addr[ETH_ALEN];
110 u8 ctl_src_addr[ETH_ALEN];
Joe Eykholt97c83892009-03-17 11:42:40 -0700111
112 void (*send)(struct fcoe_ctlr *, struct sk_buff *);
Chris Leech11b56182009-11-03 11:46:29 -0800113 void (*update_mac)(struct fc_lport *, u8 *addr);
114 u8 * (*get_src_addr)(struct fc_lport *);
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700115 struct mutex ctlr_mutex;
Joe Eykholt97c83892009-03-17 11:42:40 -0700116};
117
Robert Love70b51aa2009-11-03 11:47:45 -0800118/**
119 * struct fcoe_fcf - Fibre-Channel Forwarder
120 * @list: list linkage
121 * @time: system time (jiffies) when an advertisement was last received
122 * @switch_name: WWN of switch from advertisement
123 * @fabric_name: WWN of fabric from advertisement
124 * @fc_map: FC_MAP value from advertisement
125 * @fcf_mac: Ethernet address of the FCF
126 * @vfid: virtual fabric ID
127 * @pri: selection priority, smaller values are better
128 * @flags: flags received from advertisement
129 * @fka_period: keep-alive period, in jiffies
Joe Eykholt97c83892009-03-17 11:42:40 -0700130 *
131 * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that
132 * passes FCoE frames on to an FC fabric. This structure represents
133 * one FCF from which advertisements have been received.
134 *
135 * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and
136 * @fcf_mac together form the lookup key.
137 */
138struct fcoe_fcf {
139 struct list_head list;
140 unsigned long time;
141
142 u64 switch_name;
143 u64 fabric_name;
144 u32 fc_map;
145 u16 vfid;
146 u8 fcf_mac[ETH_ALEN];
147
148 u8 pri;
149 u16 flags;
150 u32 fka_period;
Yi Zou8cdffdc2009-11-20 14:54:57 -0800151 u8 fd_flags:1;
Joe Eykholt97c83892009-03-17 11:42:40 -0700152};
153
154/* FIP API functions */
155void fcoe_ctlr_init(struct fcoe_ctlr *);
156void fcoe_ctlr_destroy(struct fcoe_ctlr *);
157void fcoe_ctlr_link_up(struct fcoe_ctlr *);
158int fcoe_ctlr_link_down(struct fcoe_ctlr *);
Chris Leech11b56182009-11-03 11:46:29 -0800159int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *);
Joe Eykholt97c83892009-03-17 11:42:40 -0700160void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *);
Robert Love70b51aa2009-11-03 11:47:45 -0800161int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *,
Joe Eykholt386309ce2009-11-03 11:49:16 -0800162 struct fc_frame *);
Joe Eykholt97c83892009-03-17 11:42:40 -0700163
Robert Love85b4aa42008-12-09 15:10:24 -0800164/* libfcoe funcs */
Vasu Devfdd78022009-03-17 11:42:24 -0700165u64 fcoe_wwn_from_mac(unsigned char mac[], unsigned int, unsigned int);
Robert Love85b4aa42008-12-09 15:10:24 -0800166int fcoe_libfc_config(struct fc_lport *, struct libfc_function_template *);
Vasu Devfdd78022009-03-17 11:42:24 -0700167
Vasu Dev519e5132010-07-20 15:19:32 -0700168/**
169 * is_fip_mode() - returns true if FIP mode selected.
170 * @fip: FCoE controller.
171 */
172static inline bool is_fip_mode(struct fcoe_ctlr *fip)
173{
174 return fip->state == FIP_ST_ENABLED;
175}
176
177
Robert Love85b4aa42008-12-09 15:10:24 -0800178#endif /* _LIBFCOE_H */