![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-only */ 0002 /* 0003 * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved. 0004 * Copyright (c) 2007-2008 Intel Corporation. All rights reserved. 0005 * 0006 * Maintained at www.Open-FCoE.org 0007 */ 0008 0009 #ifndef _LIBFCOE_H 0010 #define _LIBFCOE_H 0011 0012 #include <linux/etherdevice.h> 0013 #include <linux/if_ether.h> 0014 #include <linux/netdevice.h> 0015 #include <linux/skbuff.h> 0016 #include <linux/workqueue.h> 0017 #include <linux/local_lock.h> 0018 #include <linux/random.h> 0019 #include <scsi/fc/fc_fcoe.h> 0020 #include <scsi/libfc.h> 0021 #include <scsi/fcoe_sysfs.h> 0022 0023 #define FCOE_MAX_CMD_LEN 16 /* Supported CDB length */ 0024 0025 /* 0026 * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload) 0027 * + 4 (FC CRC) + 4 (FCoE trailer) = 2158 bytes 0028 */ 0029 #define FCOE_MTU 2158 0030 0031 /* 0032 * FIP tunable parameters. 0033 */ 0034 #define FCOE_CTLR_START_DELAY 2000 /* mS after first adv. to choose FCF */ 0035 #define FCOE_CTLR_SOL_TOV 2000 /* min. solicitation interval (mS) */ 0036 #define FCOE_CTLR_FCF_LIMIT 20 /* max. number of FCF entries */ 0037 #define FCOE_CTLR_VN2VN_LOGIN_LIMIT 3 /* max. VN2VN rport login retries */ 0038 0039 /** 0040 * enum fip_state - internal state of FCoE controller. 0041 * @FIP_ST_DISABLED: controller has been disabled or not yet enabled. 0042 * @FIP_ST_LINK_WAIT: the physical link is down or unusable. 0043 * @FIP_ST_AUTO: determining whether to use FIP or non-FIP mode. 0044 * @FIP_ST_NON_FIP: non-FIP mode selected. 0045 * @FIP_ST_ENABLED: FIP mode selected. 0046 * @FIP_ST_VNMP_START: VN2VN multipath mode start, wait 0047 * @FIP_ST_VNMP_PROBE1: VN2VN sent first probe, listening 0048 * @FIP_ST_VNMP_PROBE2: VN2VN sent second probe, listening 0049 * @FIP_ST_VNMP_CLAIM: VN2VN sent claim, waiting for responses 0050 * @FIP_ST_VNMP_UP: VN2VN multipath mode operation 0051 */ 0052 enum fip_state { 0053 FIP_ST_DISABLED, 0054 FIP_ST_LINK_WAIT, 0055 FIP_ST_AUTO, 0056 FIP_ST_NON_FIP, 0057 FIP_ST_ENABLED, 0058 FIP_ST_VNMP_START, 0059 FIP_ST_VNMP_PROBE1, 0060 FIP_ST_VNMP_PROBE2, 0061 FIP_ST_VNMP_CLAIM, 0062 FIP_ST_VNMP_UP, 0063 }; 0064 0065 /* 0066 * Modes: 0067 * The mode is the state that is to be entered after link up. 0068 * It must not change after fcoe_ctlr_init() sets it. 0069 */ 0070 enum fip_mode { 0071 FIP_MODE_AUTO, 0072 FIP_MODE_NON_FIP, 0073 FIP_MODE_FABRIC, 0074 FIP_MODE_VN2VN, 0075 }; 0076 0077 /** 0078 * struct fcoe_ctlr - FCoE Controller and FIP state 0079 * @state: internal FIP state for network link and FIP or non-FIP mode. 0080 * @mode: LLD-selected mode. 0081 * @lp: &fc_lport: libfc local port. 0082 * @sel_fcf: currently selected FCF, or NULL. 0083 * @fcfs: list of discovered FCFs. 0084 * @cdev: (Optional) pointer to sysfs fcoe_ctlr_device. 0085 * @fcf_count: number of discovered FCF entries. 0086 * @sol_time: time when a multicast solicitation was last sent. 0087 * @sel_time: time after which to select an FCF. 0088 * @port_ka_time: time of next port keep-alive. 0089 * @ctlr_ka_time: time of next controller keep-alive. 0090 * @timer: timer struct used for all delayed events. 0091 * @timer_work: &work_struct for doing keep-alives and resets. 0092 * @recv_work: &work_struct for receiving FIP frames. 0093 * @fip_recv_list: list of received FIP frames. 0094 * @flogi_req: clone of FLOGI request sent 0095 * @rnd_state: state for pseudo-random number generator. 0096 * @port_id: proposed or selected local-port ID. 0097 * @user_mfs: configured maximum FC frame size, including FC header. 0098 * @flogi_oxid: exchange ID of most recent fabric login. 0099 * @flogi_req_send: send of FLOGI requested 0100 * @flogi_count: number of FLOGI attempts in AUTO mode. 0101 * @map_dest: use the FC_MAP mode for destination MAC addresses. 0102 * @fip_resp: start FIP VLAN discovery responder 0103 * @spma: supports SPMA server-provided MACs mode 0104 * @probe_tries: number of FC_IDs probed 0105 * @priority: DCBx FCoE APP priority 0106 * @dest_addr: MAC address of the selected FC forwarder. 0107 * @ctl_src_addr: the native MAC address of our local port. 0108 * @send: LLD-supplied function to handle sending FIP Ethernet frames 0109 * @update_mac: LLD-supplied function to handle changes to MAC addresses. 0110 * @get_src_addr: LLD-supplied function to supply a source MAC address. 0111 * @ctlr_mutex: lock protecting this structure. 0112 * @ctlr_lock: spinlock covering flogi_req 0113 * 0114 * This structure is used by all FCoE drivers. It contains information 0115 * needed by all FCoE low-level drivers (LLDs) as well as internal state 0116 * for FIP, and fields shared with the LLDS. 0117 */ 0118 struct fcoe_ctlr { 0119 enum fip_state state; 0120 enum fip_mode mode; 0121 struct fc_lport *lp; 0122 struct fcoe_fcf *sel_fcf; 0123 struct list_head fcfs; 0124 struct fcoe_ctlr_device *cdev; 0125 u16 fcf_count; 0126 unsigned long sol_time; 0127 unsigned long sel_time; 0128 unsigned long port_ka_time; 0129 unsigned long ctlr_ka_time; 0130 struct timer_list timer; 0131 struct work_struct timer_work; 0132 struct work_struct recv_work; 0133 struct sk_buff_head fip_recv_list; 0134 struct sk_buff *flogi_req; 0135 0136 struct rnd_state rnd_state; 0137 u32 port_id; 0138 0139 u16 user_mfs; 0140 u16 flogi_oxid; 0141 u8 flogi_req_send; 0142 u8 flogi_count; 0143 bool map_dest; 0144 bool fip_resp; 0145 u8 spma; 0146 u8 probe_tries; 0147 u8 priority; 0148 u8 dest_addr[ETH_ALEN]; 0149 u8 ctl_src_addr[ETH_ALEN]; 0150 0151 void (*send)(struct fcoe_ctlr *, struct sk_buff *); 0152 void (*update_mac)(struct fc_lport *, u8 *addr); 0153 u8 * (*get_src_addr)(struct fc_lport *); 0154 struct mutex ctlr_mutex; 0155 spinlock_t ctlr_lock; 0156 }; 0157 0158 /** 0159 * fcoe_ctlr_priv() - Return the private data from a fcoe_ctlr 0160 * @cltr: The fcoe_ctlr whose private data will be returned 0161 */ 0162 static inline void *fcoe_ctlr_priv(const struct fcoe_ctlr *ctlr) 0163 { 0164 return (void *)(ctlr + 1); 0165 } 0166 0167 /* 0168 * This assumes that the fcoe_ctlr (x) is allocated with the fcoe_ctlr_device. 0169 */ 0170 #define fcoe_ctlr_to_ctlr_dev(x) \ 0171 (x)->cdev 0172 0173 /** 0174 * struct fcoe_fcf - Fibre-Channel Forwarder 0175 * @list: list linkage 0176 * @event_work: Work for FC Transport actions queue 0177 * @event: The event to be processed 0178 * @fip: The controller that the FCF was discovered on 0179 * @fcf_dev: The associated fcoe_fcf_device instance 0180 * @time: system time (jiffies) when an advertisement was last received 0181 * @switch_name: WWN of switch from advertisement 0182 * @fabric_name: WWN of fabric from advertisement 0183 * @fc_map: FC_MAP value from advertisement 0184 * @fcf_mac: Ethernet address of the FCF for FIP traffic 0185 * @fcoe_mac: Ethernet address of the FCF for FCoE traffic 0186 * @vfid: virtual fabric ID 0187 * @pri: selection priority, smaller values are better 0188 * @flogi_sent: current FLOGI sent to this FCF 0189 * @flags: flags received from advertisement 0190 * @fka_period: keep-alive period, in jiffies 0191 * 0192 * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that 0193 * passes FCoE frames on to an FC fabric. This structure represents 0194 * one FCF from which advertisements have been received. 0195 * 0196 * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and 0197 * @fcf_mac together form the lookup key. 0198 */ 0199 struct fcoe_fcf { 0200 struct list_head list; 0201 struct work_struct event_work; 0202 struct fcoe_ctlr *fip; 0203 struct fcoe_fcf_device *fcf_dev; 0204 unsigned long time; 0205 0206 u64 switch_name; 0207 u64 fabric_name; 0208 u32 fc_map; 0209 u16 vfid; 0210 u8 fcf_mac[ETH_ALEN]; 0211 u8 fcoe_mac[ETH_ALEN]; 0212 0213 u8 pri; 0214 u8 flogi_sent; 0215 u16 flags; 0216 u32 fka_period; 0217 u8 fd_flags:1; 0218 }; 0219 0220 #define fcoe_fcf_to_fcf_dev(x) \ 0221 ((x)->fcf_dev) 0222 0223 /** 0224 * struct fcoe_rport - VN2VN remote port 0225 * @time: time of create or last beacon packet received from node 0226 * @fcoe_len: max FCoE frame size, not including VLAN or Ethernet headers 0227 * @flags: flags from probe or claim 0228 * @login_count: number of unsuccessful rport logins to this port 0229 * @enode_mac: E_Node control MAC address 0230 * @vn_mac: VN_Node assigned MAC address for data 0231 */ 0232 struct fcoe_rport { 0233 struct fc_rport_priv rdata; 0234 unsigned long time; 0235 u16 fcoe_len; 0236 u16 flags; 0237 u8 login_count; 0238 u8 enode_mac[ETH_ALEN]; 0239 u8 vn_mac[ETH_ALEN]; 0240 }; 0241 0242 /* FIP API functions */ 0243 void fcoe_ctlr_init(struct fcoe_ctlr *, enum fip_mode); 0244 void fcoe_ctlr_destroy(struct fcoe_ctlr *); 0245 void fcoe_ctlr_link_up(struct fcoe_ctlr *); 0246 int fcoe_ctlr_link_down(struct fcoe_ctlr *); 0247 int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *); 0248 void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *); 0249 int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *, 0250 struct fc_frame *); 0251 0252 /* libfcoe funcs */ 0253 u64 fcoe_wwn_from_mac(unsigned char mac[ETH_ALEN], unsigned int scheme, 0254 unsigned int port); 0255 int fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *, 0256 const struct libfc_function_template *, int init_fcp); 0257 u32 fcoe_fc_crc(struct fc_frame *fp); 0258 int fcoe_start_io(struct sk_buff *skb); 0259 int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type); 0260 void __fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb, 0261 struct net_device *netdev); 0262 void fcoe_wwn_to_str(u64 wwn, char *buf, int len); 0263 int fcoe_validate_vport_create(struct fc_vport *vport); 0264 int fcoe_link_speed_update(struct fc_lport *); 0265 void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *); 0266 void fcoe_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev); 0267 0268 /** 0269 * is_fip_mode() - returns true if FIP mode selected. 0270 * @fip: FCoE controller. 0271 */ 0272 static inline bool is_fip_mode(struct fcoe_ctlr *fip) 0273 { 0274 return fip->state == FIP_ST_ENABLED; 0275 } 0276 0277 /* helper for FCoE SW HBA drivers, can include subven and subdev if needed. The 0278 * modpost would use pci_device_id table to auto-generate formatted module alias 0279 * into the corresponding .mod.c file, but there may or may not be a pci device 0280 * id table for FCoE drivers so we use the following helper for build the fcoe 0281 * driver module alias. 0282 */ 0283 #define MODULE_ALIAS_FCOE_PCI(ven, dev) \ 0284 MODULE_ALIAS("fcoe-pci:" \ 0285 "v" __stringify(ven) \ 0286 "d" __stringify(dev) "sv*sd*bc*sc*i*") 0287 0288 /* the name of the default FCoE transport driver fcoe.ko */ 0289 #define FCOE_TRANSPORT_DEFAULT "fcoe" 0290 0291 /* struct fcoe_transport - The FCoE transport interface 0292 * @name: a vendor specific name for their FCoE transport driver 0293 * @attached: whether this transport is already attached 0294 * @list: list linkage to all attached transports 0295 * @match: handler to allow the transport driver to match up a given netdev 0296 * @alloc: handler to allocate per-instance FCoE structures 0297 * (no discovery or login) 0298 * @create: handler to sysfs entry of create for FCoE instances 0299 * @destroy: handler to delete per-instance FCoE structures 0300 * (frees all memory) 0301 * @enable: handler to sysfs entry of enable for FCoE instances 0302 * @disable: handler to sysfs entry of disable for FCoE instances 0303 */ 0304 struct fcoe_transport { 0305 char name[IFNAMSIZ]; 0306 bool attached; 0307 struct list_head list; 0308 bool (*match) (struct net_device *device); 0309 int (*alloc) (struct net_device *device); 0310 int (*create) (struct net_device *device, enum fip_mode fip_mode); 0311 int (*destroy) (struct net_device *device); 0312 int (*enable) (struct net_device *device); 0313 int (*disable) (struct net_device *device); 0314 }; 0315 0316 /** 0317 * struct fcoe_percpu_s - The context for FCoE receive thread(s) 0318 * @kthread: The thread context (used by bnx2fc) 0319 * @work: The work item (used by fcoe) 0320 * @fcoe_rx_list: The queue of pending packets to process 0321 * @page: The memory page for calculating frame trailer CRCs 0322 * @crc_eof_offset: The offset into the CRC page pointing to available 0323 * memory for a new trailer 0324 */ 0325 struct fcoe_percpu_s { 0326 struct task_struct *kthread; 0327 struct work_struct work; 0328 struct sk_buff_head fcoe_rx_list; 0329 struct page *crc_eof_page; 0330 int crc_eof_offset; 0331 local_lock_t lock; 0332 }; 0333 0334 /** 0335 * struct fcoe_port - The FCoE private structure 0336 * @priv: The associated fcoe interface. The structure is 0337 * defined by the low level driver 0338 * @lport: The associated local port 0339 * @fcoe_pending_queue: The pending Rx queue of skbs 0340 * @fcoe_pending_queue_active: Indicates if the pending queue is active 0341 * @max_queue_depth: Max queue depth of pending queue 0342 * @min_queue_depth: Min queue depth of pending queue 0343 * @timer: The queue timer 0344 * @destroy_work: Handle for work context 0345 * (to prevent RTNL deadlocks) 0346 * @data_srt_addr: Source address for data 0347 * 0348 * An instance of this structure is to be allocated along with the 0349 * Scsi_Host and libfc fc_lport structures. 0350 */ 0351 struct fcoe_port { 0352 void *priv; 0353 struct fc_lport *lport; 0354 struct sk_buff_head fcoe_pending_queue; 0355 u8 fcoe_pending_queue_active; 0356 u32 max_queue_depth; 0357 u32 min_queue_depth; 0358 struct timer_list timer; 0359 struct work_struct destroy_work; 0360 u8 data_src_addr[ETH_ALEN]; 0361 struct net_device * (*get_netdev)(const struct fc_lport *lport); 0362 }; 0363 0364 /** 0365 * fcoe_get_netdev() - Return the net device associated with a local port 0366 * @lport: The local port to get the net device from 0367 */ 0368 static inline struct net_device *fcoe_get_netdev(const struct fc_lport *lport) 0369 { 0370 struct fcoe_port *port = ((struct fcoe_port *)lport_priv(lport)); 0371 0372 return (port->get_netdev) ? port->get_netdev(lport) : NULL; 0373 } 0374 0375 void fcoe_clean_pending_queue(struct fc_lport *); 0376 void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb); 0377 void fcoe_queue_timer(struct timer_list *t); 0378 int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen, 0379 struct fcoe_percpu_s *fps); 0380 0381 /* FCoE Sysfs helpers */ 0382 void fcoe_fcf_get_selected(struct fcoe_fcf_device *); 0383 void fcoe_ctlr_set_fip_mode(struct fcoe_ctlr_device *); 0384 0385 /** 0386 * struct netdev_list 0387 * A mapping from netdevice to fcoe_transport 0388 */ 0389 struct fcoe_netdev_mapping { 0390 struct list_head list; 0391 struct net_device *netdev; 0392 struct fcoe_transport *ft; 0393 }; 0394 0395 /* fcoe transports registration and deregistration */ 0396 int fcoe_transport_attach(struct fcoe_transport *ft); 0397 int fcoe_transport_detach(struct fcoe_transport *ft); 0398 0399 /* sysfs store handler for ctrl_control interface */ 0400 ssize_t fcoe_ctlr_create_store(struct bus_type *bus, 0401 const char *buf, size_t count); 0402 ssize_t fcoe_ctlr_destroy_store(struct bus_type *bus, 0403 const char *buf, size_t count); 0404 0405 #endif /* _LIBFCOE_H */ 0406 0407
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |