18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2008-2009 Cisco Systems, Inc.  All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (c) 2007-2008 Intel Corporation.  All rights reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Maintained at www.Open-FCoE.org
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef _LIBFCOE_H
108c2ecf20Sopenharmony_ci#define _LIBFCOE_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
138c2ecf20Sopenharmony_ci#include <linux/if_ether.h>
148c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
158c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
168c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
178c2ecf20Sopenharmony_ci#include <linux/random.h>
188c2ecf20Sopenharmony_ci#include <scsi/fc/fc_fcoe.h>
198c2ecf20Sopenharmony_ci#include <scsi/libfc.h>
208c2ecf20Sopenharmony_ci#include <scsi/fcoe_sysfs.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define FCOE_MAX_CMD_LEN	16	/* Supported CDB length */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload)
268c2ecf20Sopenharmony_ci * + 4 (FC CRC) + 4 (FCoE trailer) =  2158 bytes
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci#define FCOE_MTU	2158
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci * FIP tunable parameters.
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci#define FCOE_CTLR_START_DELAY	2000	/* mS after first adv. to choose FCF */
348c2ecf20Sopenharmony_ci#define FCOE_CTLR_SOL_TOV	2000	/* min. solicitation interval (mS) */
358c2ecf20Sopenharmony_ci#define FCOE_CTLR_FCF_LIMIT	20	/* max. number of FCF entries */
368c2ecf20Sopenharmony_ci#define FCOE_CTLR_VN2VN_LOGIN_LIMIT 3	/* max. VN2VN rport login retries */
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/**
398c2ecf20Sopenharmony_ci * enum fip_state - internal state of FCoE controller.
408c2ecf20Sopenharmony_ci * @FIP_ST_DISABLED: 	controller has been disabled or not yet enabled.
418c2ecf20Sopenharmony_ci * @FIP_ST_LINK_WAIT:	the physical link is down or unusable.
428c2ecf20Sopenharmony_ci * @FIP_ST_AUTO:	determining whether to use FIP or non-FIP mode.
438c2ecf20Sopenharmony_ci * @FIP_ST_NON_FIP:	non-FIP mode selected.
448c2ecf20Sopenharmony_ci * @FIP_ST_ENABLED:	FIP mode selected.
458c2ecf20Sopenharmony_ci * @FIP_ST_VNMP_START:	VN2VN multipath mode start, wait
468c2ecf20Sopenharmony_ci * @FIP_ST_VNMP_PROBE1:	VN2VN sent first probe, listening
478c2ecf20Sopenharmony_ci * @FIP_ST_VNMP_PROBE2:	VN2VN sent second probe, listening
488c2ecf20Sopenharmony_ci * @FIP_ST_VNMP_CLAIM:	VN2VN sent claim, waiting for responses
498c2ecf20Sopenharmony_ci * @FIP_ST_VNMP_UP:	VN2VN multipath mode operation
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_cienum fip_state {
528c2ecf20Sopenharmony_ci	FIP_ST_DISABLED,
538c2ecf20Sopenharmony_ci	FIP_ST_LINK_WAIT,
548c2ecf20Sopenharmony_ci	FIP_ST_AUTO,
558c2ecf20Sopenharmony_ci	FIP_ST_NON_FIP,
568c2ecf20Sopenharmony_ci	FIP_ST_ENABLED,
578c2ecf20Sopenharmony_ci	FIP_ST_VNMP_START,
588c2ecf20Sopenharmony_ci	FIP_ST_VNMP_PROBE1,
598c2ecf20Sopenharmony_ci	FIP_ST_VNMP_PROBE2,
608c2ecf20Sopenharmony_ci	FIP_ST_VNMP_CLAIM,
618c2ecf20Sopenharmony_ci	FIP_ST_VNMP_UP,
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/*
658c2ecf20Sopenharmony_ci * Modes:
668c2ecf20Sopenharmony_ci * The mode is the state that is to be entered after link up.
678c2ecf20Sopenharmony_ci * It must not change after fcoe_ctlr_init() sets it.
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_cienum fip_mode {
708c2ecf20Sopenharmony_ci	FIP_MODE_AUTO,
718c2ecf20Sopenharmony_ci	FIP_MODE_NON_FIP,
728c2ecf20Sopenharmony_ci	FIP_MODE_FABRIC,
738c2ecf20Sopenharmony_ci	FIP_MODE_VN2VN,
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/**
778c2ecf20Sopenharmony_ci * struct fcoe_ctlr - FCoE Controller and FIP state
788c2ecf20Sopenharmony_ci * @state:	   internal FIP state for network link and FIP or non-FIP mode.
798c2ecf20Sopenharmony_ci * @mode:	   LLD-selected mode.
808c2ecf20Sopenharmony_ci * @lp:		   &fc_lport: libfc local port.
818c2ecf20Sopenharmony_ci * @sel_fcf:	   currently selected FCF, or NULL.
828c2ecf20Sopenharmony_ci * @fcfs:	   list of discovered FCFs.
838c2ecf20Sopenharmony_ci * @cdev:          (Optional) pointer to sysfs fcoe_ctlr_device.
848c2ecf20Sopenharmony_ci * @fcf_count:	   number of discovered FCF entries.
858c2ecf20Sopenharmony_ci * @sol_time:	   time when a multicast solicitation was last sent.
868c2ecf20Sopenharmony_ci * @sel_time:	   time after which to select an FCF.
878c2ecf20Sopenharmony_ci * @port_ka_time:  time of next port keep-alive.
888c2ecf20Sopenharmony_ci * @ctlr_ka_time:  time of next controller keep-alive.
898c2ecf20Sopenharmony_ci * @timer:	   timer struct used for all delayed events.
908c2ecf20Sopenharmony_ci * @timer_work:	   &work_struct for doing keep-alives and resets.
918c2ecf20Sopenharmony_ci * @recv_work:	   &work_struct for receiving FIP frames.
928c2ecf20Sopenharmony_ci * @fip_recv_list: list of received FIP frames.
938c2ecf20Sopenharmony_ci * @flogi_req:	   clone of FLOGI request sent
948c2ecf20Sopenharmony_ci * @rnd_state:	   state for pseudo-random number generator.
958c2ecf20Sopenharmony_ci * @port_id:	   proposed or selected local-port ID.
968c2ecf20Sopenharmony_ci * @user_mfs:	   configured maximum FC frame size, including FC header.
978c2ecf20Sopenharmony_ci * @flogi_oxid:    exchange ID of most recent fabric login.
988c2ecf20Sopenharmony_ci * @flogi_req_send: send of FLOGI requested
998c2ecf20Sopenharmony_ci * @flogi_count:   number of FLOGI attempts in AUTO mode.
1008c2ecf20Sopenharmony_ci * @map_dest:	   use the FC_MAP mode for destination MAC addresses.
1018c2ecf20Sopenharmony_ci * @fip_resp:	   start FIP VLAN discovery responder
1028c2ecf20Sopenharmony_ci * @spma:	   supports SPMA server-provided MACs mode
1038c2ecf20Sopenharmony_ci * @probe_tries:   number of FC_IDs probed
1048c2ecf20Sopenharmony_ci * @priority:      DCBx FCoE APP priority
1058c2ecf20Sopenharmony_ci * @dest_addr:	   MAC address of the selected FC forwarder.
1068c2ecf20Sopenharmony_ci * @ctl_src_addr:  the native MAC address of our local port.
1078c2ecf20Sopenharmony_ci * @send:	   LLD-supplied function to handle sending FIP Ethernet frames
1088c2ecf20Sopenharmony_ci * @update_mac:    LLD-supplied function to handle changes to MAC addresses.
1098c2ecf20Sopenharmony_ci * @get_src_addr:  LLD-supplied function to supply a source MAC address.
1108c2ecf20Sopenharmony_ci * @ctlr_mutex:	   lock protecting this structure.
1118c2ecf20Sopenharmony_ci * @ctlr_lock:     spinlock covering flogi_req
1128c2ecf20Sopenharmony_ci *
1138c2ecf20Sopenharmony_ci * This structure is used by all FCoE drivers.  It contains information
1148c2ecf20Sopenharmony_ci * needed by all FCoE low-level drivers (LLDs) as well as internal state
1158c2ecf20Sopenharmony_ci * for FIP, and fields shared with the LLDS.
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_cistruct fcoe_ctlr {
1188c2ecf20Sopenharmony_ci	enum fip_state state;
1198c2ecf20Sopenharmony_ci	enum fip_mode mode;
1208c2ecf20Sopenharmony_ci	struct fc_lport *lp;
1218c2ecf20Sopenharmony_ci	struct fcoe_fcf *sel_fcf;
1228c2ecf20Sopenharmony_ci	struct list_head fcfs;
1238c2ecf20Sopenharmony_ci	struct fcoe_ctlr_device *cdev;
1248c2ecf20Sopenharmony_ci	u16 fcf_count;
1258c2ecf20Sopenharmony_ci	unsigned long sol_time;
1268c2ecf20Sopenharmony_ci	unsigned long sel_time;
1278c2ecf20Sopenharmony_ci	unsigned long port_ka_time;
1288c2ecf20Sopenharmony_ci	unsigned long ctlr_ka_time;
1298c2ecf20Sopenharmony_ci	struct timer_list timer;
1308c2ecf20Sopenharmony_ci	struct work_struct timer_work;
1318c2ecf20Sopenharmony_ci	struct work_struct recv_work;
1328c2ecf20Sopenharmony_ci	struct sk_buff_head fip_recv_list;
1338c2ecf20Sopenharmony_ci	struct sk_buff *flogi_req;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	struct rnd_state rnd_state;
1368c2ecf20Sopenharmony_ci	u32 port_id;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	u16 user_mfs;
1398c2ecf20Sopenharmony_ci	u16 flogi_oxid;
1408c2ecf20Sopenharmony_ci	u8 flogi_req_send;
1418c2ecf20Sopenharmony_ci	u8 flogi_count;
1428c2ecf20Sopenharmony_ci	bool map_dest;
1438c2ecf20Sopenharmony_ci	bool fip_resp;
1448c2ecf20Sopenharmony_ci	u8 spma;
1458c2ecf20Sopenharmony_ci	u8 probe_tries;
1468c2ecf20Sopenharmony_ci	u8 priority;
1478c2ecf20Sopenharmony_ci	u8 dest_addr[ETH_ALEN];
1488c2ecf20Sopenharmony_ci	u8 ctl_src_addr[ETH_ALEN];
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	void (*send)(struct fcoe_ctlr *, struct sk_buff *);
1518c2ecf20Sopenharmony_ci	void (*update_mac)(struct fc_lport *, u8 *addr);
1528c2ecf20Sopenharmony_ci	u8 * (*get_src_addr)(struct fc_lport *);
1538c2ecf20Sopenharmony_ci	struct mutex ctlr_mutex;
1548c2ecf20Sopenharmony_ci	spinlock_t ctlr_lock;
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/**
1588c2ecf20Sopenharmony_ci * fcoe_ctlr_priv() - Return the private data from a fcoe_ctlr
1598c2ecf20Sopenharmony_ci * @cltr: The fcoe_ctlr whose private data will be returned
1608c2ecf20Sopenharmony_ci */
1618c2ecf20Sopenharmony_cistatic inline void *fcoe_ctlr_priv(const struct fcoe_ctlr *ctlr)
1628c2ecf20Sopenharmony_ci{
1638c2ecf20Sopenharmony_ci	return (void *)(ctlr + 1);
1648c2ecf20Sopenharmony_ci}
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/*
1678c2ecf20Sopenharmony_ci * This assumes that the fcoe_ctlr (x) is allocated with the fcoe_ctlr_device.
1688c2ecf20Sopenharmony_ci */
1698c2ecf20Sopenharmony_ci#define fcoe_ctlr_to_ctlr_dev(x)					\
1708c2ecf20Sopenharmony_ci	(x)->cdev
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/**
1738c2ecf20Sopenharmony_ci * struct fcoe_fcf - Fibre-Channel Forwarder
1748c2ecf20Sopenharmony_ci * @list:	 list linkage
1758c2ecf20Sopenharmony_ci * @event_work:  Work for FC Transport actions queue
1768c2ecf20Sopenharmony_ci * @event:       The event to be processed
1778c2ecf20Sopenharmony_ci * @fip:         The controller that the FCF was discovered on
1788c2ecf20Sopenharmony_ci * @fcf_dev:     The associated fcoe_fcf_device instance
1798c2ecf20Sopenharmony_ci * @time:	 system time (jiffies) when an advertisement was last received
1808c2ecf20Sopenharmony_ci * @switch_name: WWN of switch from advertisement
1818c2ecf20Sopenharmony_ci * @fabric_name: WWN of fabric from advertisement
1828c2ecf20Sopenharmony_ci * @fc_map:	 FC_MAP value from advertisement
1838c2ecf20Sopenharmony_ci * @fcf_mac:	 Ethernet address of the FCF for FIP traffic
1848c2ecf20Sopenharmony_ci * @fcoe_mac:	 Ethernet address of the FCF for FCoE traffic
1858c2ecf20Sopenharmony_ci * @vfid:	 virtual fabric ID
1868c2ecf20Sopenharmony_ci * @pri:	 selection priority, smaller values are better
1878c2ecf20Sopenharmony_ci * @flogi_sent:	 current FLOGI sent to this FCF
1888c2ecf20Sopenharmony_ci * @flags:	 flags received from advertisement
1898c2ecf20Sopenharmony_ci * @fka_period:	 keep-alive period, in jiffies
1908c2ecf20Sopenharmony_ci *
1918c2ecf20Sopenharmony_ci * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that
1928c2ecf20Sopenharmony_ci * passes FCoE frames on to an FC fabric.  This structure represents
1938c2ecf20Sopenharmony_ci * one FCF from which advertisements have been received.
1948c2ecf20Sopenharmony_ci *
1958c2ecf20Sopenharmony_ci * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and
1968c2ecf20Sopenharmony_ci * @fcf_mac together form the lookup key.
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_cistruct fcoe_fcf {
1998c2ecf20Sopenharmony_ci	struct list_head list;
2008c2ecf20Sopenharmony_ci	struct work_struct event_work;
2018c2ecf20Sopenharmony_ci	struct fcoe_ctlr *fip;
2028c2ecf20Sopenharmony_ci	struct fcoe_fcf_device *fcf_dev;
2038c2ecf20Sopenharmony_ci	unsigned long time;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	u64 switch_name;
2068c2ecf20Sopenharmony_ci	u64 fabric_name;
2078c2ecf20Sopenharmony_ci	u32 fc_map;
2088c2ecf20Sopenharmony_ci	u16 vfid;
2098c2ecf20Sopenharmony_ci	u8 fcf_mac[ETH_ALEN];
2108c2ecf20Sopenharmony_ci	u8 fcoe_mac[ETH_ALEN];
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	u8 pri;
2138c2ecf20Sopenharmony_ci	u8 flogi_sent;
2148c2ecf20Sopenharmony_ci	u16 flags;
2158c2ecf20Sopenharmony_ci	u32 fka_period;
2168c2ecf20Sopenharmony_ci	u8 fd_flags:1;
2178c2ecf20Sopenharmony_ci};
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci#define fcoe_fcf_to_fcf_dev(x)			\
2208c2ecf20Sopenharmony_ci	((x)->fcf_dev)
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/**
2238c2ecf20Sopenharmony_ci * struct fcoe_rport - VN2VN remote port
2248c2ecf20Sopenharmony_ci * @time:	time of create or last beacon packet received from node
2258c2ecf20Sopenharmony_ci * @fcoe_len:	max FCoE frame size, not including VLAN or Ethernet headers
2268c2ecf20Sopenharmony_ci * @flags:	flags from probe or claim
2278c2ecf20Sopenharmony_ci * @login_count: number of unsuccessful rport logins to this port
2288c2ecf20Sopenharmony_ci * @enode_mac:	E_Node control MAC address
2298c2ecf20Sopenharmony_ci * @vn_mac:	VN_Node assigned MAC address for data
2308c2ecf20Sopenharmony_ci */
2318c2ecf20Sopenharmony_cistruct fcoe_rport {
2328c2ecf20Sopenharmony_ci	struct fc_rport_priv rdata;
2338c2ecf20Sopenharmony_ci	unsigned long time;
2348c2ecf20Sopenharmony_ci	u16 fcoe_len;
2358c2ecf20Sopenharmony_ci	u16 flags;
2368c2ecf20Sopenharmony_ci	u8 login_count;
2378c2ecf20Sopenharmony_ci	u8 enode_mac[ETH_ALEN];
2388c2ecf20Sopenharmony_ci	u8 vn_mac[ETH_ALEN];
2398c2ecf20Sopenharmony_ci};
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci/* FIP API functions */
2428c2ecf20Sopenharmony_civoid fcoe_ctlr_init(struct fcoe_ctlr *, enum fip_mode);
2438c2ecf20Sopenharmony_civoid fcoe_ctlr_destroy(struct fcoe_ctlr *);
2448c2ecf20Sopenharmony_civoid fcoe_ctlr_link_up(struct fcoe_ctlr *);
2458c2ecf20Sopenharmony_ciint fcoe_ctlr_link_down(struct fcoe_ctlr *);
2468c2ecf20Sopenharmony_ciint fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *);
2478c2ecf20Sopenharmony_civoid fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *);
2488c2ecf20Sopenharmony_ciint fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *,
2498c2ecf20Sopenharmony_ci			 struct fc_frame *);
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci/* libfcoe funcs */
2528c2ecf20Sopenharmony_ciu64 fcoe_wwn_from_mac(unsigned char mac[ETH_ALEN], unsigned int scheme,
2538c2ecf20Sopenharmony_ci		      unsigned int port);
2548c2ecf20Sopenharmony_ciint fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *,
2558c2ecf20Sopenharmony_ci		      const struct libfc_function_template *, int init_fcp);
2568c2ecf20Sopenharmony_ciu32 fcoe_fc_crc(struct fc_frame *fp);
2578c2ecf20Sopenharmony_ciint fcoe_start_io(struct sk_buff *skb);
2588c2ecf20Sopenharmony_ciint fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type);
2598c2ecf20Sopenharmony_civoid __fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb,
2608c2ecf20Sopenharmony_ci		     struct net_device *netdev);
2618c2ecf20Sopenharmony_civoid fcoe_wwn_to_str(u64 wwn, char *buf, int len);
2628c2ecf20Sopenharmony_ciint fcoe_validate_vport_create(struct fc_vport *vport);
2638c2ecf20Sopenharmony_ciint fcoe_link_speed_update(struct fc_lport *);
2648c2ecf20Sopenharmony_civoid fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *);
2658c2ecf20Sopenharmony_civoid fcoe_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev);
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci/**
2688c2ecf20Sopenharmony_ci * is_fip_mode() - returns true if FIP mode selected.
2698c2ecf20Sopenharmony_ci * @fip:	FCoE controller.
2708c2ecf20Sopenharmony_ci */
2718c2ecf20Sopenharmony_cistatic inline bool is_fip_mode(struct fcoe_ctlr *fip)
2728c2ecf20Sopenharmony_ci{
2738c2ecf20Sopenharmony_ci	return fip->state == FIP_ST_ENABLED;
2748c2ecf20Sopenharmony_ci}
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci/* helper for FCoE SW HBA drivers, can include subven and subdev if needed. The
2778c2ecf20Sopenharmony_ci * modpost would use pci_device_id table to auto-generate formatted module alias
2788c2ecf20Sopenharmony_ci * into the corresponding .mod.c file, but there may or may not be a pci device
2798c2ecf20Sopenharmony_ci * id table for FCoE drivers so we use the following helper for build the fcoe
2808c2ecf20Sopenharmony_ci * driver module alias.
2818c2ecf20Sopenharmony_ci */
2828c2ecf20Sopenharmony_ci#define MODULE_ALIAS_FCOE_PCI(ven, dev) \
2838c2ecf20Sopenharmony_ci	MODULE_ALIAS("fcoe-pci:"	\
2848c2ecf20Sopenharmony_ci		"v" __stringify(ven)	\
2858c2ecf20Sopenharmony_ci		"d" __stringify(dev) "sv*sd*bc*sc*i*")
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/* the name of the default FCoE transport driver fcoe.ko */
2888c2ecf20Sopenharmony_ci#define FCOE_TRANSPORT_DEFAULT	"fcoe"
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci/* struct fcoe_transport - The FCoE transport interface
2918c2ecf20Sopenharmony_ci * @name:	a vendor specific name for their FCoE transport driver
2928c2ecf20Sopenharmony_ci * @attached:	whether this transport is already attached
2938c2ecf20Sopenharmony_ci * @list:	list linkage to all attached transports
2948c2ecf20Sopenharmony_ci * @match:	handler to allow the transport driver to match up a given netdev
2958c2ecf20Sopenharmony_ci * @alloc:      handler to allocate per-instance FCoE structures
2968c2ecf20Sopenharmony_ci *		(no discovery or login)
2978c2ecf20Sopenharmony_ci * @create:	handler to sysfs entry of create for FCoE instances
2988c2ecf20Sopenharmony_ci * @destroy:    handler to delete per-instance FCoE structures
2998c2ecf20Sopenharmony_ci *		(frees all memory)
3008c2ecf20Sopenharmony_ci * @enable:	handler to sysfs entry of enable for FCoE instances
3018c2ecf20Sopenharmony_ci * @disable:	handler to sysfs entry of disable for FCoE instances
3028c2ecf20Sopenharmony_ci */
3038c2ecf20Sopenharmony_cistruct fcoe_transport {
3048c2ecf20Sopenharmony_ci	char name[IFNAMSIZ];
3058c2ecf20Sopenharmony_ci	bool attached;
3068c2ecf20Sopenharmony_ci	struct list_head list;
3078c2ecf20Sopenharmony_ci	bool (*match) (struct net_device *device);
3088c2ecf20Sopenharmony_ci	int (*alloc) (struct net_device *device);
3098c2ecf20Sopenharmony_ci	int (*create) (struct net_device *device, enum fip_mode fip_mode);
3108c2ecf20Sopenharmony_ci	int (*destroy) (struct net_device *device);
3118c2ecf20Sopenharmony_ci	int (*enable) (struct net_device *device);
3128c2ecf20Sopenharmony_ci	int (*disable) (struct net_device *device);
3138c2ecf20Sopenharmony_ci};
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci/**
3168c2ecf20Sopenharmony_ci * struct fcoe_percpu_s - The context for FCoE receive thread(s)
3178c2ecf20Sopenharmony_ci * @kthread:	    The thread context (used by bnx2fc)
3188c2ecf20Sopenharmony_ci * @work:	    The work item (used by fcoe)
3198c2ecf20Sopenharmony_ci * @fcoe_rx_list:   The queue of pending packets to process
3208c2ecf20Sopenharmony_ci * @page:	    The memory page for calculating frame trailer CRCs
3218c2ecf20Sopenharmony_ci * @crc_eof_offset: The offset into the CRC page pointing to available
3228c2ecf20Sopenharmony_ci *		    memory for a new trailer
3238c2ecf20Sopenharmony_ci */
3248c2ecf20Sopenharmony_cistruct fcoe_percpu_s {
3258c2ecf20Sopenharmony_ci	struct task_struct *kthread;
3268c2ecf20Sopenharmony_ci	struct work_struct work;
3278c2ecf20Sopenharmony_ci	struct sk_buff_head fcoe_rx_list;
3288c2ecf20Sopenharmony_ci	struct page *crc_eof_page;
3298c2ecf20Sopenharmony_ci	int crc_eof_offset;
3308c2ecf20Sopenharmony_ci};
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci/**
3338c2ecf20Sopenharmony_ci * struct fcoe_port - The FCoE private structure
3348c2ecf20Sopenharmony_ci * @priv:		       The associated fcoe interface. The structure is
3358c2ecf20Sopenharmony_ci *			       defined by the low level driver
3368c2ecf20Sopenharmony_ci * @lport:		       The associated local port
3378c2ecf20Sopenharmony_ci * @fcoe_pending_queue:	       The pending Rx queue of skbs
3388c2ecf20Sopenharmony_ci * @fcoe_pending_queue_active: Indicates if the pending queue is active
3398c2ecf20Sopenharmony_ci * @max_queue_depth:	       Max queue depth of pending queue
3408c2ecf20Sopenharmony_ci * @min_queue_depth:	       Min queue depth of pending queue
3418c2ecf20Sopenharmony_ci * @timer:		       The queue timer
3428c2ecf20Sopenharmony_ci * @destroy_work:	       Handle for work context
3438c2ecf20Sopenharmony_ci *			       (to prevent RTNL deadlocks)
3448c2ecf20Sopenharmony_ci * @data_srt_addr:	       Source address for data
3458c2ecf20Sopenharmony_ci *
3468c2ecf20Sopenharmony_ci * An instance of this structure is to be allocated along with the
3478c2ecf20Sopenharmony_ci * Scsi_Host and libfc fc_lport structures.
3488c2ecf20Sopenharmony_ci */
3498c2ecf20Sopenharmony_cistruct fcoe_port {
3508c2ecf20Sopenharmony_ci	void		      *priv;
3518c2ecf20Sopenharmony_ci	struct fc_lport	      *lport;
3528c2ecf20Sopenharmony_ci	struct sk_buff_head   fcoe_pending_queue;
3538c2ecf20Sopenharmony_ci	u8		      fcoe_pending_queue_active;
3548c2ecf20Sopenharmony_ci	u32		      max_queue_depth;
3558c2ecf20Sopenharmony_ci	u32		      min_queue_depth;
3568c2ecf20Sopenharmony_ci	struct timer_list     timer;
3578c2ecf20Sopenharmony_ci	struct work_struct    destroy_work;
3588c2ecf20Sopenharmony_ci	u8		      data_src_addr[ETH_ALEN];
3598c2ecf20Sopenharmony_ci	struct net_device * (*get_netdev)(const struct fc_lport *lport);
3608c2ecf20Sopenharmony_ci};
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci/**
3638c2ecf20Sopenharmony_ci * fcoe_get_netdev() - Return the net device associated with a local port
3648c2ecf20Sopenharmony_ci * @lport: The local port to get the net device from
3658c2ecf20Sopenharmony_ci */
3668c2ecf20Sopenharmony_cistatic inline struct net_device *fcoe_get_netdev(const struct fc_lport *lport)
3678c2ecf20Sopenharmony_ci{
3688c2ecf20Sopenharmony_ci	struct fcoe_port *port = ((struct fcoe_port *)lport_priv(lport));
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci	return (port->get_netdev) ? port->get_netdev(lport) : NULL;
3718c2ecf20Sopenharmony_ci}
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_civoid fcoe_clean_pending_queue(struct fc_lport *);
3748c2ecf20Sopenharmony_civoid fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb);
3758c2ecf20Sopenharmony_civoid fcoe_queue_timer(struct timer_list *t);
3768c2ecf20Sopenharmony_ciint fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
3778c2ecf20Sopenharmony_ci			   struct fcoe_percpu_s *fps);
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci/* FCoE Sysfs helpers */
3808c2ecf20Sopenharmony_civoid fcoe_fcf_get_selected(struct fcoe_fcf_device *);
3818c2ecf20Sopenharmony_civoid fcoe_ctlr_set_fip_mode(struct fcoe_ctlr_device *);
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci/**
3848c2ecf20Sopenharmony_ci * struct netdev_list
3858c2ecf20Sopenharmony_ci * A mapping from netdevice to fcoe_transport
3868c2ecf20Sopenharmony_ci */
3878c2ecf20Sopenharmony_cistruct fcoe_netdev_mapping {
3888c2ecf20Sopenharmony_ci	struct list_head list;
3898c2ecf20Sopenharmony_ci	struct net_device *netdev;
3908c2ecf20Sopenharmony_ci	struct fcoe_transport *ft;
3918c2ecf20Sopenharmony_ci};
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci/* fcoe transports registration and deregistration */
3948c2ecf20Sopenharmony_ciint fcoe_transport_attach(struct fcoe_transport *ft);
3958c2ecf20Sopenharmony_ciint fcoe_transport_detach(struct fcoe_transport *ft);
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci/* sysfs store handler for ctrl_control interface */
3988c2ecf20Sopenharmony_cissize_t fcoe_ctlr_create_store(struct bus_type *bus,
3998c2ecf20Sopenharmony_ci			       const char *buf, size_t count);
4008c2ecf20Sopenharmony_cissize_t fcoe_ctlr_destroy_store(struct bus_type *bus,
4018c2ecf20Sopenharmony_ci				const char *buf, size_t count);
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci#endif /* _LIBFCOE_H */
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci
406