Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1 | /* |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved. |
| 3 | * Copyright (c) 2007-2008 Intel Corporation. All rights reserved. |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 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 | |
| 21 | #ifndef _LIBFCOE_H |
| 22 | #define _LIBFCOE_H |
| 23 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 24 | #include <linux/etherdevice.h> |
| 25 | #include <linux/if_ether.h> |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/skbuff.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 28 | #include <linux/workqueue.h> |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 29 | #include <scsi/fc/fc_fcoe.h> |
| 30 | #include <scsi/libfc.h> |
| 31 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 32 | /* |
| 33 | * FIP tunable parameters. |
| 34 | */ |
| 35 | #define FCOE_CTLR_START_DELAY 2000 /* mS after first adv. to choose FCF */ |
| 36 | #define FCOE_CTRL_SOL_TOV 2000 /* min. solicitation interval (mS) */ |
| 37 | #define FCOE_CTLR_FCF_LIMIT 20 /* max. number of FCF entries */ |
| 38 | |
| 39 | /** |
| 40 | * enum fip_state - internal state of FCoE controller. |
| 41 | * @FIP_ST_DISABLED: controller has been disabled or not yet enabled. |
| 42 | * @FIP_ST_LINK_WAIT: the physical link is down or unusable. |
| 43 | * @FIP_ST_AUTO: determining whether to use FIP or non-FIP mode. |
| 44 | * @FIP_ST_NON_FIP: non-FIP mode selected. |
| 45 | * @FIP_ST_ENABLED: FIP mode selected. |
| 46 | */ |
| 47 | enum fip_state { |
| 48 | FIP_ST_DISABLED, |
| 49 | FIP_ST_LINK_WAIT, |
| 50 | FIP_ST_AUTO, |
| 51 | FIP_ST_NON_FIP, |
| 52 | FIP_ST_ENABLED, |
| 53 | }; |
| 54 | |
| 55 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 56 | * struct fcoe_ctlr - FCoE Controller and FIP state |
| 57 | * @state: internal FIP state for network link and FIP or non-FIP mode. |
Joe Eykholt | 22bcd22 | 2009-11-03 11:48:11 -0800 | [diff] [blame] | 58 | * @mode: LLD-selected mode. |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 59 | * @lp: &fc_lport: libfc local port. |
| 60 | * @sel_fcf: currently selected FCF, or NULL. |
| 61 | * @fcfs: list of discovered FCFs. |
| 62 | * @fcf_count: number of discovered FCF entries. |
| 63 | * @sol_time: time when a multicast solicitation was last sent. |
| 64 | * @sel_time: time after which to select an FCF. |
| 65 | * @port_ka_time: time of next port keep-alive. |
| 66 | * @ctlr_ka_time: time of next controller keep-alive. |
| 67 | * @timer: timer struct used for all delayed events. |
| 68 | * @link_work: &work_struct for doing FCF selection. |
| 69 | * @recv_work: &work_struct for receiving FIP frames. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 70 | * @fip_recv_list: list of received FIP frames. |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 71 | * @user_mfs: configured maximum FC frame size, including FC header. |
| 72 | * @flogi_oxid: exchange ID of most recent fabric login. |
| 73 | * @flogi_count: number of FLOGI attempts in AUTO mode. |
| 74 | * @link: current link status for libfc. |
| 75 | * @last_link: last link state reported to libfc. |
| 76 | * @map_dest: use the FC_MAP mode for destination MAC addresses. |
| 77 | * @spma: supports SPMA server-provided MACs mode |
| 78 | * @send_ctlr_ka: need to send controller keep alive |
| 79 | * @send_port_ka: need to send port keep alives |
| 80 | * @dest_addr: MAC address of the selected FC forwarder. |
| 81 | * @ctl_src_addr: the native MAC address of our local port. |
| 82 | * @send: LLD-supplied function to handle sending FIP Ethernet frames |
| 83 | * @update_mac: LLD-supplied function to handle changes to MAC addresses. |
| 84 | * @get_src_addr: LLD-supplied function to supply a source MAC address. |
| 85 | * @lock: lock protecting this structure. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 86 | * |
| 87 | * This structure is used by all FCoE drivers. It contains information |
| 88 | * needed by all FCoE low-level drivers (LLDs) as well as internal state |
| 89 | * for FIP, and fields shared with the LLDS. |
| 90 | */ |
| 91 | struct fcoe_ctlr { |
| 92 | enum fip_state state; |
Joe Eykholt | 22bcd22 | 2009-11-03 11:48:11 -0800 | [diff] [blame] | 93 | enum fip_state mode; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 94 | struct fc_lport *lp; |
| 95 | struct fcoe_fcf *sel_fcf; |
| 96 | struct list_head fcfs; |
| 97 | u16 fcf_count; |
| 98 | unsigned long sol_time; |
| 99 | unsigned long sel_time; |
| 100 | unsigned long port_ka_time; |
| 101 | unsigned long ctlr_ka_time; |
| 102 | struct timer_list timer; |
| 103 | struct work_struct link_work; |
| 104 | struct work_struct recv_work; |
| 105 | struct sk_buff_head fip_recv_list; |
| 106 | u16 user_mfs; |
| 107 | u16 flogi_oxid; |
| 108 | u8 flogi_count; |
| 109 | u8 link; |
| 110 | u8 last_link; |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 111 | u8 reset_req; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 112 | u8 map_dest; |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 113 | u8 spma; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 114 | u8 send_ctlr_ka; |
| 115 | u8 send_port_ka; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 116 | u8 dest_addr[ETH_ALEN]; |
| 117 | u8 ctl_src_addr[ETH_ALEN]; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 118 | |
| 119 | void (*send)(struct fcoe_ctlr *, struct sk_buff *); |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 120 | void (*update_mac)(struct fc_lport *, u8 *addr); |
| 121 | u8 * (*get_src_addr)(struct fc_lport *); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 122 | spinlock_t lock; |
| 123 | }; |
| 124 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 125 | /** |
| 126 | * struct fcoe_fcf - Fibre-Channel Forwarder |
| 127 | * @list: list linkage |
| 128 | * @time: system time (jiffies) when an advertisement was last received |
| 129 | * @switch_name: WWN of switch from advertisement |
| 130 | * @fabric_name: WWN of fabric from advertisement |
| 131 | * @fc_map: FC_MAP value from advertisement |
| 132 | * @fcf_mac: Ethernet address of the FCF |
| 133 | * @vfid: virtual fabric ID |
| 134 | * @pri: selection priority, smaller values are better |
| 135 | * @flags: flags received from advertisement |
| 136 | * @fka_period: keep-alive period, in jiffies |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 137 | * |
| 138 | * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that |
| 139 | * passes FCoE frames on to an FC fabric. This structure represents |
| 140 | * one FCF from which advertisements have been received. |
| 141 | * |
| 142 | * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and |
| 143 | * @fcf_mac together form the lookup key. |
| 144 | */ |
| 145 | struct fcoe_fcf { |
| 146 | struct list_head list; |
| 147 | unsigned long time; |
| 148 | |
| 149 | u64 switch_name; |
| 150 | u64 fabric_name; |
| 151 | u32 fc_map; |
| 152 | u16 vfid; |
| 153 | u8 fcf_mac[ETH_ALEN]; |
| 154 | |
| 155 | u8 pri; |
| 156 | u16 flags; |
| 157 | u32 fka_period; |
Yi Zou | 8cdffdc | 2009-11-20 14:54:57 -0800 | [diff] [blame] | 158 | u8 fd_flags:1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | /* FIP API functions */ |
| 162 | void fcoe_ctlr_init(struct fcoe_ctlr *); |
| 163 | void fcoe_ctlr_destroy(struct fcoe_ctlr *); |
| 164 | void fcoe_ctlr_link_up(struct fcoe_ctlr *); |
| 165 | int fcoe_ctlr_link_down(struct fcoe_ctlr *); |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 166 | int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 167 | void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *); |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 168 | int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *, |
Joe Eykholt | 386309ce | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 169 | struct fc_frame *); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 170 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 171 | /* libfcoe funcs */ |
Vasu Dev | fdd7802 | 2009-03-17 11:42:24 -0700 | [diff] [blame] | 172 | u64 fcoe_wwn_from_mac(unsigned char mac[], unsigned int, unsigned int); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 173 | int fcoe_libfc_config(struct fc_lport *, struct libfc_function_template *); |
Vasu Dev | fdd7802 | 2009-03-17 11:42:24 -0700 | [diff] [blame] | 174 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 175 | #endif /* _LIBFCOE_H */ |