162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2008-2009 Cisco Systems, Inc.  All rights reserved.
462306a36Sopenharmony_ci * Copyright (c) 2007-2008 Intel Corporation.  All rights reserved.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Maintained at www.Open-FCoE.org
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _LIBFCOE_H
1062306a36Sopenharmony_ci#define _LIBFCOE_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/etherdevice.h>
1362306a36Sopenharmony_ci#include <linux/if_ether.h>
1462306a36Sopenharmony_ci#include <linux/netdevice.h>
1562306a36Sopenharmony_ci#include <linux/skbuff.h>
1662306a36Sopenharmony_ci#include <linux/workqueue.h>
1762306a36Sopenharmony_ci#include <linux/local_lock.h>
1862306a36Sopenharmony_ci#include <linux/random.h>
1962306a36Sopenharmony_ci#include <scsi/fc/fc_fcoe.h>
2062306a36Sopenharmony_ci#include <scsi/libfc.h>
2162306a36Sopenharmony_ci#include <scsi/fcoe_sysfs.h>
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define FCOE_MAX_CMD_LEN	16	/* Supported CDB length */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/*
2662306a36Sopenharmony_ci * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload)
2762306a36Sopenharmony_ci * + 4 (FC CRC) + 4 (FCoE trailer) =  2158 bytes
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_ci#define FCOE_MTU	2158
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/*
3262306a36Sopenharmony_ci * FIP tunable parameters.
3362306a36Sopenharmony_ci */
3462306a36Sopenharmony_ci#define FCOE_CTLR_START_DELAY	2000	/* mS after first adv. to choose FCF */
3562306a36Sopenharmony_ci#define FCOE_CTLR_SOL_TOV	2000	/* min. solicitation interval (mS) */
3662306a36Sopenharmony_ci#define FCOE_CTLR_FCF_LIMIT	20	/* max. number of FCF entries */
3762306a36Sopenharmony_ci#define FCOE_CTLR_VN2VN_LOGIN_LIMIT 3	/* max. VN2VN rport login retries */
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/**
4062306a36Sopenharmony_ci * enum fip_state - internal state of FCoE controller.
4162306a36Sopenharmony_ci * @FIP_ST_DISABLED: 	controller has been disabled or not yet enabled.
4262306a36Sopenharmony_ci * @FIP_ST_LINK_WAIT:	the physical link is down or unusable.
4362306a36Sopenharmony_ci * @FIP_ST_AUTO:	determining whether to use FIP or non-FIP mode.
4462306a36Sopenharmony_ci * @FIP_ST_NON_FIP:	non-FIP mode selected.
4562306a36Sopenharmony_ci * @FIP_ST_ENABLED:	FIP mode selected.
4662306a36Sopenharmony_ci * @FIP_ST_VNMP_START:	VN2VN multipath mode start, wait
4762306a36Sopenharmony_ci * @FIP_ST_VNMP_PROBE1:	VN2VN sent first probe, listening
4862306a36Sopenharmony_ci * @FIP_ST_VNMP_PROBE2:	VN2VN sent second probe, listening
4962306a36Sopenharmony_ci * @FIP_ST_VNMP_CLAIM:	VN2VN sent claim, waiting for responses
5062306a36Sopenharmony_ci * @FIP_ST_VNMP_UP:	VN2VN multipath mode operation
5162306a36Sopenharmony_ci */
5262306a36Sopenharmony_cienum fip_state {
5362306a36Sopenharmony_ci	FIP_ST_DISABLED,
5462306a36Sopenharmony_ci	FIP_ST_LINK_WAIT,
5562306a36Sopenharmony_ci	FIP_ST_AUTO,
5662306a36Sopenharmony_ci	FIP_ST_NON_FIP,
5762306a36Sopenharmony_ci	FIP_ST_ENABLED,
5862306a36Sopenharmony_ci	FIP_ST_VNMP_START,
5962306a36Sopenharmony_ci	FIP_ST_VNMP_PROBE1,
6062306a36Sopenharmony_ci	FIP_ST_VNMP_PROBE2,
6162306a36Sopenharmony_ci	FIP_ST_VNMP_CLAIM,
6262306a36Sopenharmony_ci	FIP_ST_VNMP_UP,
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/*
6662306a36Sopenharmony_ci * Modes:
6762306a36Sopenharmony_ci * The mode is the state that is to be entered after link up.
6862306a36Sopenharmony_ci * It must not change after fcoe_ctlr_init() sets it.
6962306a36Sopenharmony_ci */
7062306a36Sopenharmony_cienum fip_mode {
7162306a36Sopenharmony_ci	FIP_MODE_AUTO,
7262306a36Sopenharmony_ci	FIP_MODE_NON_FIP,
7362306a36Sopenharmony_ci	FIP_MODE_FABRIC,
7462306a36Sopenharmony_ci	FIP_MODE_VN2VN,
7562306a36Sopenharmony_ci};
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/**
7862306a36Sopenharmony_ci * struct fcoe_ctlr - FCoE Controller and FIP state
7962306a36Sopenharmony_ci * @state:	   internal FIP state for network link and FIP or non-FIP mode.
8062306a36Sopenharmony_ci * @mode:	   LLD-selected mode.
8162306a36Sopenharmony_ci * @lp:		   &fc_lport: libfc local port.
8262306a36Sopenharmony_ci * @sel_fcf:	   currently selected FCF, or NULL.
8362306a36Sopenharmony_ci * @fcfs:	   list of discovered FCFs.
8462306a36Sopenharmony_ci * @cdev:          (Optional) pointer to sysfs fcoe_ctlr_device.
8562306a36Sopenharmony_ci * @fcf_count:	   number of discovered FCF entries.
8662306a36Sopenharmony_ci * @sol_time:	   time when a multicast solicitation was last sent.
8762306a36Sopenharmony_ci * @sel_time:	   time after which to select an FCF.
8862306a36Sopenharmony_ci * @port_ka_time:  time of next port keep-alive.
8962306a36Sopenharmony_ci * @ctlr_ka_time:  time of next controller keep-alive.
9062306a36Sopenharmony_ci * @timer:	   timer struct used for all delayed events.
9162306a36Sopenharmony_ci * @timer_work:	   &work_struct for doing keep-alives and resets.
9262306a36Sopenharmony_ci * @recv_work:	   &work_struct for receiving FIP frames.
9362306a36Sopenharmony_ci * @fip_recv_list: list of received FIP frames.
9462306a36Sopenharmony_ci * @flogi_req:	   clone of FLOGI request sent
9562306a36Sopenharmony_ci * @rnd_state:	   state for pseudo-random number generator.
9662306a36Sopenharmony_ci * @port_id:	   proposed or selected local-port ID.
9762306a36Sopenharmony_ci * @user_mfs:	   configured maximum FC frame size, including FC header.
9862306a36Sopenharmony_ci * @flogi_oxid:    exchange ID of most recent fabric login.
9962306a36Sopenharmony_ci * @flogi_req_send: send of FLOGI requested
10062306a36Sopenharmony_ci * @flogi_count:   number of FLOGI attempts in AUTO mode.
10162306a36Sopenharmony_ci * @map_dest:	   use the FC_MAP mode for destination MAC addresses.
10262306a36Sopenharmony_ci * @fip_resp:	   start FIP VLAN discovery responder
10362306a36Sopenharmony_ci * @spma:	   supports SPMA server-provided MACs mode
10462306a36Sopenharmony_ci * @probe_tries:   number of FC_IDs probed
10562306a36Sopenharmony_ci * @priority:      DCBx FCoE APP priority
10662306a36Sopenharmony_ci * @dest_addr:	   MAC address of the selected FC forwarder.
10762306a36Sopenharmony_ci * @ctl_src_addr:  the native MAC address of our local port.
10862306a36Sopenharmony_ci * @send:	   LLD-supplied function to handle sending FIP Ethernet frames
10962306a36Sopenharmony_ci * @update_mac:    LLD-supplied function to handle changes to MAC addresses.
11062306a36Sopenharmony_ci * @get_src_addr:  LLD-supplied function to supply a source MAC address.
11162306a36Sopenharmony_ci * @ctlr_mutex:	   lock protecting this structure.
11262306a36Sopenharmony_ci * @ctlr_lock:     spinlock covering flogi_req
11362306a36Sopenharmony_ci *
11462306a36Sopenharmony_ci * This structure is used by all FCoE drivers.  It contains information
11562306a36Sopenharmony_ci * needed by all FCoE low-level drivers (LLDs) as well as internal state
11662306a36Sopenharmony_ci * for FIP, and fields shared with the LLDS.
11762306a36Sopenharmony_ci */
11862306a36Sopenharmony_cistruct fcoe_ctlr {
11962306a36Sopenharmony_ci	enum fip_state state;
12062306a36Sopenharmony_ci	enum fip_mode mode;
12162306a36Sopenharmony_ci	struct fc_lport *lp;
12262306a36Sopenharmony_ci	struct fcoe_fcf *sel_fcf;
12362306a36Sopenharmony_ci	struct list_head fcfs;
12462306a36Sopenharmony_ci	struct fcoe_ctlr_device *cdev;
12562306a36Sopenharmony_ci	u16 fcf_count;
12662306a36Sopenharmony_ci	unsigned long sol_time;
12762306a36Sopenharmony_ci	unsigned long sel_time;
12862306a36Sopenharmony_ci	unsigned long port_ka_time;
12962306a36Sopenharmony_ci	unsigned long ctlr_ka_time;
13062306a36Sopenharmony_ci	struct timer_list timer;
13162306a36Sopenharmony_ci	struct work_struct timer_work;
13262306a36Sopenharmony_ci	struct work_struct recv_work;
13362306a36Sopenharmony_ci	struct sk_buff_head fip_recv_list;
13462306a36Sopenharmony_ci	struct sk_buff *flogi_req;
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	struct rnd_state rnd_state;
13762306a36Sopenharmony_ci	u32 port_id;
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci	u16 user_mfs;
14062306a36Sopenharmony_ci	u16 flogi_oxid;
14162306a36Sopenharmony_ci	u8 flogi_req_send;
14262306a36Sopenharmony_ci	u8 flogi_count;
14362306a36Sopenharmony_ci	bool map_dest;
14462306a36Sopenharmony_ci	bool fip_resp;
14562306a36Sopenharmony_ci	u8 spma;
14662306a36Sopenharmony_ci	u8 probe_tries;
14762306a36Sopenharmony_ci	u8 priority;
14862306a36Sopenharmony_ci	u8 dest_addr[ETH_ALEN];
14962306a36Sopenharmony_ci	u8 ctl_src_addr[ETH_ALEN];
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci	void (*send)(struct fcoe_ctlr *, struct sk_buff *);
15262306a36Sopenharmony_ci	void (*update_mac)(struct fc_lport *, u8 *addr);
15362306a36Sopenharmony_ci	u8 * (*get_src_addr)(struct fc_lport *);
15462306a36Sopenharmony_ci	struct mutex ctlr_mutex;
15562306a36Sopenharmony_ci	spinlock_t ctlr_lock;
15662306a36Sopenharmony_ci};
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci/**
15962306a36Sopenharmony_ci * fcoe_ctlr_priv() - Return the private data from a fcoe_ctlr
16062306a36Sopenharmony_ci * @cltr: The fcoe_ctlr whose private data will be returned
16162306a36Sopenharmony_ci */
16262306a36Sopenharmony_cistatic inline void *fcoe_ctlr_priv(const struct fcoe_ctlr *ctlr)
16362306a36Sopenharmony_ci{
16462306a36Sopenharmony_ci	return (void *)(ctlr + 1);
16562306a36Sopenharmony_ci}
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci/*
16862306a36Sopenharmony_ci * This assumes that the fcoe_ctlr (x) is allocated with the fcoe_ctlr_device.
16962306a36Sopenharmony_ci */
17062306a36Sopenharmony_ci#define fcoe_ctlr_to_ctlr_dev(x)					\
17162306a36Sopenharmony_ci	(x)->cdev
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci/**
17462306a36Sopenharmony_ci * struct fcoe_fcf - Fibre-Channel Forwarder
17562306a36Sopenharmony_ci * @list:	 list linkage
17662306a36Sopenharmony_ci * @event_work:  Work for FC Transport actions queue
17762306a36Sopenharmony_ci * @event:       The event to be processed
17862306a36Sopenharmony_ci * @fip:         The controller that the FCF was discovered on
17962306a36Sopenharmony_ci * @fcf_dev:     The associated fcoe_fcf_device instance
18062306a36Sopenharmony_ci * @time:	 system time (jiffies) when an advertisement was last received
18162306a36Sopenharmony_ci * @switch_name: WWN of switch from advertisement
18262306a36Sopenharmony_ci * @fabric_name: WWN of fabric from advertisement
18362306a36Sopenharmony_ci * @fc_map:	 FC_MAP value from advertisement
18462306a36Sopenharmony_ci * @fcf_mac:	 Ethernet address of the FCF for FIP traffic
18562306a36Sopenharmony_ci * @fcoe_mac:	 Ethernet address of the FCF for FCoE traffic
18662306a36Sopenharmony_ci * @vfid:	 virtual fabric ID
18762306a36Sopenharmony_ci * @pri:	 selection priority, smaller values are better
18862306a36Sopenharmony_ci * @flogi_sent:	 current FLOGI sent to this FCF
18962306a36Sopenharmony_ci * @flags:	 flags received from advertisement
19062306a36Sopenharmony_ci * @fka_period:	 keep-alive period, in jiffies
19162306a36Sopenharmony_ci *
19262306a36Sopenharmony_ci * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that
19362306a36Sopenharmony_ci * passes FCoE frames on to an FC fabric.  This structure represents
19462306a36Sopenharmony_ci * one FCF from which advertisements have been received.
19562306a36Sopenharmony_ci *
19662306a36Sopenharmony_ci * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and
19762306a36Sopenharmony_ci * @fcf_mac together form the lookup key.
19862306a36Sopenharmony_ci */
19962306a36Sopenharmony_cistruct fcoe_fcf {
20062306a36Sopenharmony_ci	struct list_head list;
20162306a36Sopenharmony_ci	struct work_struct event_work;
20262306a36Sopenharmony_ci	struct fcoe_ctlr *fip;
20362306a36Sopenharmony_ci	struct fcoe_fcf_device *fcf_dev;
20462306a36Sopenharmony_ci	unsigned long time;
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ci	u64 switch_name;
20762306a36Sopenharmony_ci	u64 fabric_name;
20862306a36Sopenharmony_ci	u32 fc_map;
20962306a36Sopenharmony_ci	u16 vfid;
21062306a36Sopenharmony_ci	u8 fcf_mac[ETH_ALEN];
21162306a36Sopenharmony_ci	u8 fcoe_mac[ETH_ALEN];
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci	u8 pri;
21462306a36Sopenharmony_ci	u8 flogi_sent;
21562306a36Sopenharmony_ci	u16 flags;
21662306a36Sopenharmony_ci	u32 fka_period;
21762306a36Sopenharmony_ci	u8 fd_flags:1;
21862306a36Sopenharmony_ci};
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci#define fcoe_fcf_to_fcf_dev(x)			\
22162306a36Sopenharmony_ci	((x)->fcf_dev)
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci/**
22462306a36Sopenharmony_ci * struct fcoe_rport - VN2VN remote port
22562306a36Sopenharmony_ci * @time:	time of create or last beacon packet received from node
22662306a36Sopenharmony_ci * @fcoe_len:	max FCoE frame size, not including VLAN or Ethernet headers
22762306a36Sopenharmony_ci * @flags:	flags from probe or claim
22862306a36Sopenharmony_ci * @login_count: number of unsuccessful rport logins to this port
22962306a36Sopenharmony_ci * @enode_mac:	E_Node control MAC address
23062306a36Sopenharmony_ci * @vn_mac:	VN_Node assigned MAC address for data
23162306a36Sopenharmony_ci */
23262306a36Sopenharmony_cistruct fcoe_rport {
23362306a36Sopenharmony_ci	struct fc_rport_priv rdata;
23462306a36Sopenharmony_ci	unsigned long time;
23562306a36Sopenharmony_ci	u16 fcoe_len;
23662306a36Sopenharmony_ci	u16 flags;
23762306a36Sopenharmony_ci	u8 login_count;
23862306a36Sopenharmony_ci	u8 enode_mac[ETH_ALEN];
23962306a36Sopenharmony_ci	u8 vn_mac[ETH_ALEN];
24062306a36Sopenharmony_ci};
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci/* FIP API functions */
24362306a36Sopenharmony_civoid fcoe_ctlr_init(struct fcoe_ctlr *, enum fip_mode);
24462306a36Sopenharmony_civoid fcoe_ctlr_destroy(struct fcoe_ctlr *);
24562306a36Sopenharmony_civoid fcoe_ctlr_link_up(struct fcoe_ctlr *);
24662306a36Sopenharmony_ciint fcoe_ctlr_link_down(struct fcoe_ctlr *);
24762306a36Sopenharmony_ciint fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *);
24862306a36Sopenharmony_civoid fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *);
24962306a36Sopenharmony_ciint fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *,
25062306a36Sopenharmony_ci			 struct fc_frame *);
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci/* libfcoe funcs */
25362306a36Sopenharmony_ciu64 fcoe_wwn_from_mac(unsigned char mac[ETH_ALEN], unsigned int scheme,
25462306a36Sopenharmony_ci		      unsigned int port);
25562306a36Sopenharmony_ciint fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *,
25662306a36Sopenharmony_ci		      const struct libfc_function_template *, int init_fcp);
25762306a36Sopenharmony_ciu32 fcoe_fc_crc(struct fc_frame *fp);
25862306a36Sopenharmony_ciint fcoe_start_io(struct sk_buff *skb);
25962306a36Sopenharmony_ciint fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type);
26062306a36Sopenharmony_civoid __fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb,
26162306a36Sopenharmony_ci		     struct net_device *netdev);
26262306a36Sopenharmony_civoid fcoe_wwn_to_str(u64 wwn, char *buf, int len);
26362306a36Sopenharmony_ciint fcoe_validate_vport_create(struct fc_vport *vport);
26462306a36Sopenharmony_ciint fcoe_link_speed_update(struct fc_lport *);
26562306a36Sopenharmony_civoid fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *);
26662306a36Sopenharmony_civoid fcoe_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev);
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci/**
26962306a36Sopenharmony_ci * is_fip_mode() - returns true if FIP mode selected.
27062306a36Sopenharmony_ci * @fip:	FCoE controller.
27162306a36Sopenharmony_ci */
27262306a36Sopenharmony_cistatic inline bool is_fip_mode(struct fcoe_ctlr *fip)
27362306a36Sopenharmony_ci{
27462306a36Sopenharmony_ci	return fip->state == FIP_ST_ENABLED;
27562306a36Sopenharmony_ci}
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci/* helper for FCoE SW HBA drivers, can include subven and subdev if needed. The
27862306a36Sopenharmony_ci * modpost would use pci_device_id table to auto-generate formatted module alias
27962306a36Sopenharmony_ci * into the corresponding .mod.c file, but there may or may not be a pci device
28062306a36Sopenharmony_ci * id table for FCoE drivers so we use the following helper for build the fcoe
28162306a36Sopenharmony_ci * driver module alias.
28262306a36Sopenharmony_ci */
28362306a36Sopenharmony_ci#define MODULE_ALIAS_FCOE_PCI(ven, dev) \
28462306a36Sopenharmony_ci	MODULE_ALIAS("fcoe-pci:"	\
28562306a36Sopenharmony_ci		"v" __stringify(ven)	\
28662306a36Sopenharmony_ci		"d" __stringify(dev) "sv*sd*bc*sc*i*")
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ci/* the name of the default FCoE transport driver fcoe.ko */
28962306a36Sopenharmony_ci#define FCOE_TRANSPORT_DEFAULT	"fcoe"
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci/* struct fcoe_transport - The FCoE transport interface
29262306a36Sopenharmony_ci * @name:	a vendor specific name for their FCoE transport driver
29362306a36Sopenharmony_ci * @attached:	whether this transport is already attached
29462306a36Sopenharmony_ci * @list:	list linkage to all attached transports
29562306a36Sopenharmony_ci * @match:	handler to allow the transport driver to match up a given netdev
29662306a36Sopenharmony_ci * @alloc:      handler to allocate per-instance FCoE structures
29762306a36Sopenharmony_ci *		(no discovery or login)
29862306a36Sopenharmony_ci * @create:	handler to sysfs entry of create for FCoE instances
29962306a36Sopenharmony_ci * @destroy:    handler to delete per-instance FCoE structures
30062306a36Sopenharmony_ci *		(frees all memory)
30162306a36Sopenharmony_ci * @enable:	handler to sysfs entry of enable for FCoE instances
30262306a36Sopenharmony_ci * @disable:	handler to sysfs entry of disable for FCoE instances
30362306a36Sopenharmony_ci */
30462306a36Sopenharmony_cistruct fcoe_transport {
30562306a36Sopenharmony_ci	char name[IFNAMSIZ];
30662306a36Sopenharmony_ci	bool attached;
30762306a36Sopenharmony_ci	struct list_head list;
30862306a36Sopenharmony_ci	bool (*match) (struct net_device *device);
30962306a36Sopenharmony_ci	int (*alloc) (struct net_device *device);
31062306a36Sopenharmony_ci	int (*create) (struct net_device *device, enum fip_mode fip_mode);
31162306a36Sopenharmony_ci	int (*destroy) (struct net_device *device);
31262306a36Sopenharmony_ci	int (*enable) (struct net_device *device);
31362306a36Sopenharmony_ci	int (*disable) (struct net_device *device);
31462306a36Sopenharmony_ci};
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_ci/**
31762306a36Sopenharmony_ci * struct fcoe_percpu_s - The context for FCoE receive thread(s)
31862306a36Sopenharmony_ci * @kthread:	    The thread context (used by bnx2fc)
31962306a36Sopenharmony_ci * @work:	    The work item (used by fcoe)
32062306a36Sopenharmony_ci * @fcoe_rx_list:   The queue of pending packets to process
32162306a36Sopenharmony_ci * @page:	    The memory page for calculating frame trailer CRCs
32262306a36Sopenharmony_ci * @crc_eof_offset: The offset into the CRC page pointing to available
32362306a36Sopenharmony_ci *		    memory for a new trailer
32462306a36Sopenharmony_ci */
32562306a36Sopenharmony_cistruct fcoe_percpu_s {
32662306a36Sopenharmony_ci	struct task_struct *kthread;
32762306a36Sopenharmony_ci	struct work_struct work;
32862306a36Sopenharmony_ci	struct sk_buff_head fcoe_rx_list;
32962306a36Sopenharmony_ci	struct page *crc_eof_page;
33062306a36Sopenharmony_ci	int crc_eof_offset;
33162306a36Sopenharmony_ci	local_lock_t lock;
33262306a36Sopenharmony_ci};
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci/**
33562306a36Sopenharmony_ci * struct fcoe_port - The FCoE private structure
33662306a36Sopenharmony_ci * @priv:		       The associated fcoe interface. The structure is
33762306a36Sopenharmony_ci *			       defined by the low level driver
33862306a36Sopenharmony_ci * @lport:		       The associated local port
33962306a36Sopenharmony_ci * @fcoe_pending_queue:	       The pending Rx queue of skbs
34062306a36Sopenharmony_ci * @fcoe_pending_queue_active: Indicates if the pending queue is active
34162306a36Sopenharmony_ci * @max_queue_depth:	       Max queue depth of pending queue
34262306a36Sopenharmony_ci * @min_queue_depth:	       Min queue depth of pending queue
34362306a36Sopenharmony_ci * @timer:		       The queue timer
34462306a36Sopenharmony_ci * @destroy_work:	       Handle for work context
34562306a36Sopenharmony_ci *			       (to prevent RTNL deadlocks)
34662306a36Sopenharmony_ci * @data_srt_addr:	       Source address for data
34762306a36Sopenharmony_ci *
34862306a36Sopenharmony_ci * An instance of this structure is to be allocated along with the
34962306a36Sopenharmony_ci * Scsi_Host and libfc fc_lport structures.
35062306a36Sopenharmony_ci */
35162306a36Sopenharmony_cistruct fcoe_port {
35262306a36Sopenharmony_ci	void		      *priv;
35362306a36Sopenharmony_ci	struct fc_lport	      *lport;
35462306a36Sopenharmony_ci	struct sk_buff_head   fcoe_pending_queue;
35562306a36Sopenharmony_ci	u8		      fcoe_pending_queue_active;
35662306a36Sopenharmony_ci	u32		      max_queue_depth;
35762306a36Sopenharmony_ci	u32		      min_queue_depth;
35862306a36Sopenharmony_ci	struct timer_list     timer;
35962306a36Sopenharmony_ci	struct work_struct    destroy_work;
36062306a36Sopenharmony_ci	u8		      data_src_addr[ETH_ALEN];
36162306a36Sopenharmony_ci	struct net_device * (*get_netdev)(const struct fc_lport *lport);
36262306a36Sopenharmony_ci};
36362306a36Sopenharmony_ci
36462306a36Sopenharmony_ci/**
36562306a36Sopenharmony_ci * fcoe_get_netdev() - Return the net device associated with a local port
36662306a36Sopenharmony_ci * @lport: The local port to get the net device from
36762306a36Sopenharmony_ci */
36862306a36Sopenharmony_cistatic inline struct net_device *fcoe_get_netdev(const struct fc_lport *lport)
36962306a36Sopenharmony_ci{
37062306a36Sopenharmony_ci	struct fcoe_port *port = ((struct fcoe_port *)lport_priv(lport));
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ci	return (port->get_netdev) ? port->get_netdev(lport) : NULL;
37362306a36Sopenharmony_ci}
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_civoid fcoe_clean_pending_queue(struct fc_lport *);
37662306a36Sopenharmony_civoid fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb);
37762306a36Sopenharmony_civoid fcoe_queue_timer(struct timer_list *t);
37862306a36Sopenharmony_ciint fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
37962306a36Sopenharmony_ci			   struct fcoe_percpu_s *fps);
38062306a36Sopenharmony_ci
38162306a36Sopenharmony_ci/* FCoE Sysfs helpers */
38262306a36Sopenharmony_civoid fcoe_fcf_get_selected(struct fcoe_fcf_device *);
38362306a36Sopenharmony_civoid fcoe_ctlr_set_fip_mode(struct fcoe_ctlr_device *);
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci/**
38662306a36Sopenharmony_ci * struct netdev_list
38762306a36Sopenharmony_ci * A mapping from netdevice to fcoe_transport
38862306a36Sopenharmony_ci */
38962306a36Sopenharmony_cistruct fcoe_netdev_mapping {
39062306a36Sopenharmony_ci	struct list_head list;
39162306a36Sopenharmony_ci	struct net_device *netdev;
39262306a36Sopenharmony_ci	struct fcoe_transport *ft;
39362306a36Sopenharmony_ci};
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci/* fcoe transports registration and deregistration */
39662306a36Sopenharmony_ciint fcoe_transport_attach(struct fcoe_transport *ft);
39762306a36Sopenharmony_ciint fcoe_transport_detach(struct fcoe_transport *ft);
39862306a36Sopenharmony_ci
39962306a36Sopenharmony_ci/* sysfs store handler for ctrl_control interface */
40062306a36Sopenharmony_cissize_t fcoe_ctlr_create_store(const char *buf, size_t count);
40162306a36Sopenharmony_cissize_t fcoe_ctlr_destroy_store(const char *buf, size_t count);
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci#endif /* _LIBFCOE_H */
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_ci
406