xref: /linux/include/scsi/libfcoe.h (revision d9c91182)
1a61127c2SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
285b4aa49SRobert Love /*
397c8389dSJoe Eykholt  * Copyright (c) 2008-2009 Cisco Systems, Inc.  All rights reserved.
485b4aa49SRobert Love  * Copyright (c) 2007-2008 Intel Corporation.  All rights reserved.
585b4aa49SRobert Love  *
685b4aa49SRobert Love  * Maintained at www.Open-FCoE.org
785b4aa49SRobert Love  */
885b4aa49SRobert Love 
985b4aa49SRobert Love #ifndef _LIBFCOE_H
1085b4aa49SRobert Love #define _LIBFCOE_H
1185b4aa49SRobert Love 
1297c8389dSJoe Eykholt #include <linux/etherdevice.h>
1397c8389dSJoe Eykholt #include <linux/if_ether.h>
1485b4aa49SRobert Love #include <linux/netdevice.h>
1585b4aa49SRobert Love #include <linux/skbuff.h>
1697c8389dSJoe Eykholt #include <linux/workqueue.h>
17848b8977SDavidlohr Bueso #include <linux/local_lock.h>
18e10f8c66SJoe Eykholt #include <linux/random.h>
1985b4aa49SRobert Love #include <scsi/fc/fc_fcoe.h>
2085b4aa49SRobert Love #include <scsi/libfc.h>
219a74e884SRobert Love #include <scsi/fcoe_sysfs.h>
2285b4aa49SRobert Love 
23da87bfabSVasu Dev #define FCOE_MAX_CMD_LEN	16	/* Supported CDB length */
24da87bfabSVasu Dev 
2597c8389dSJoe Eykholt /*
26f4d2b2b6SBhanu Prakash Gollapudi  * Max MTU for FCoE: 14 (FCoE header) + 24 (FC header) + 2112 (max FC payload)
27f4d2b2b6SBhanu Prakash Gollapudi  * + 4 (FC CRC) + 4 (FCoE trailer) =  2158 bytes
28f4d2b2b6SBhanu Prakash Gollapudi  */
29f4d2b2b6SBhanu Prakash Gollapudi #define FCOE_MTU	2158
30f4d2b2b6SBhanu Prakash Gollapudi 
31f4d2b2b6SBhanu Prakash Gollapudi /*
3297c8389dSJoe Eykholt  * FIP tunable parameters.
3397c8389dSJoe Eykholt  */
3497c8389dSJoe Eykholt #define FCOE_CTLR_START_DELAY	2000	/* mS after first adv. to choose FCF */
355523ca8fSChristophe JAILLET #define FCOE_CTLR_SOL_TOV	2000	/* min. solicitation interval (mS) */
3697c8389dSJoe Eykholt #define FCOE_CTLR_FCF_LIMIT	20	/* max. number of FCF entries */
37e10f8c66SJoe Eykholt #define FCOE_CTLR_VN2VN_LOGIN_LIMIT 3	/* max. VN2VN rport login retries */
3897c8389dSJoe Eykholt 
3997c8389dSJoe Eykholt /**
4097c8389dSJoe Eykholt  * enum fip_state - internal state of FCoE controller.
4197c8389dSJoe Eykholt  * @FIP_ST_DISABLED: 	controller has been disabled or not yet enabled.
4297c8389dSJoe Eykholt  * @FIP_ST_LINK_WAIT:	the physical link is down or unusable.
4397c8389dSJoe Eykholt  * @FIP_ST_AUTO:	determining whether to use FIP or non-FIP mode.
4497c8389dSJoe Eykholt  * @FIP_ST_NON_FIP:	non-FIP mode selected.
4597c8389dSJoe Eykholt  * @FIP_ST_ENABLED:	FIP mode selected.
46e10f8c66SJoe Eykholt  * @FIP_ST_VNMP_START:	VN2VN multipath mode start, wait
47e10f8c66SJoe Eykholt  * @FIP_ST_VNMP_PROBE1:	VN2VN sent first probe, listening
48e10f8c66SJoe Eykholt  * @FIP_ST_VNMP_PROBE2:	VN2VN sent second probe, listening
49e10f8c66SJoe Eykholt  * @FIP_ST_VNMP_CLAIM:	VN2VN sent claim, waiting for responses
50e10f8c66SJoe Eykholt  * @FIP_ST_VNMP_UP:	VN2VN multipath mode operation
5197c8389dSJoe Eykholt  */
5297c8389dSJoe Eykholt enum fip_state {
5397c8389dSJoe Eykholt 	FIP_ST_DISABLED,
5497c8389dSJoe Eykholt 	FIP_ST_LINK_WAIT,
5597c8389dSJoe Eykholt 	FIP_ST_AUTO,
5697c8389dSJoe Eykholt 	FIP_ST_NON_FIP,
5797c8389dSJoe Eykholt 	FIP_ST_ENABLED,
58e10f8c66SJoe Eykholt 	FIP_ST_VNMP_START,
59e10f8c66SJoe Eykholt 	FIP_ST_VNMP_PROBE1,
60e10f8c66SJoe Eykholt 	FIP_ST_VNMP_PROBE2,
61e10f8c66SJoe Eykholt 	FIP_ST_VNMP_CLAIM,
62e10f8c66SJoe Eykholt 	FIP_ST_VNMP_UP,
6397c8389dSJoe Eykholt };
6497c8389dSJoe Eykholt 
653d902ac0SJoe Eykholt /*
663d902ac0SJoe Eykholt  * Modes:
673d902ac0SJoe Eykholt  * The mode is the state that is to be entered after link up.
683d902ac0SJoe Eykholt  * It must not change after fcoe_ctlr_init() sets it.
693d902ac0SJoe Eykholt  */
701917d42dSHannes Reinecke enum fip_mode {
718beb90aaSSedat Dilek 	FIP_MODE_AUTO,
721917d42dSHannes Reinecke 	FIP_MODE_NON_FIP,
731917d42dSHannes Reinecke 	FIP_MODE_FABRIC,
741917d42dSHannes Reinecke 	FIP_MODE_VN2VN,
751917d42dSHannes Reinecke };
763d902ac0SJoe Eykholt 
7797c8389dSJoe Eykholt /**
7870b51aabSRobert Love  * struct fcoe_ctlr - FCoE Controller and FIP state
7997c8389dSJoe Eykholt  * @state:	   internal FIP state for network link and FIP or non-FIP mode.
8022bcd225SJoe Eykholt  * @mode:	   LLD-selected mode.
8197c8389dSJoe Eykholt  * @lp:		   &fc_lport: libfc local port.
8297c8389dSJoe Eykholt  * @sel_fcf:	   currently selected FCF, or NULL.
8397c8389dSJoe Eykholt  * @fcfs:	   list of discovered FCFs.
849d34876fSRobert Love  * @cdev:          (Optional) pointer to sysfs fcoe_ctlr_device.
8597c8389dSJoe Eykholt  * @fcf_count:	   number of discovered FCF entries.
8697c8389dSJoe Eykholt  * @sol_time:	   time when a multicast solicitation was last sent.
8797c8389dSJoe Eykholt  * @sel_time:	   time after which to select an FCF.
8897c8389dSJoe Eykholt  * @port_ka_time:  time of next port keep-alive.
8997c8389dSJoe Eykholt  * @ctlr_ka_time:  time of next controller keep-alive.
9097c8389dSJoe Eykholt  * @timer:	   timer struct used for all delayed events.
9142913657SJoe Eykholt  * @timer_work:	   &work_struct for doing keep-alives and resets.
9297c8389dSJoe Eykholt  * @recv_work:	   &work_struct for receiving FIP frames.
9397c8389dSJoe Eykholt  * @fip_recv_list: list of received FIP frames.
94794d98e7SJoe Eykholt  * @flogi_req:	   clone of FLOGI request sent
95e10f8c66SJoe Eykholt  * @rnd_state:	   state for pseudo-random number generator.
96e10f8c66SJoe Eykholt  * @port_id:	   proposed or selected local-port ID.
9797c8389dSJoe Eykholt  * @user_mfs:	   configured maximum FC frame size, including FC header.
9897c8389dSJoe Eykholt  * @flogi_oxid:    exchange ID of most recent fabric login.
99794d98e7SJoe Eykholt  * @flogi_req_send: send of FLOGI requested
10097c8389dSJoe Eykholt  * @flogi_count:   number of FLOGI attempts in AUTO mode.
10197c8389dSJoe Eykholt  * @map_dest:	   use the FC_MAP mode for destination MAC addresses.
1029a6cf881SHannes Reinecke  * @fip_resp:	   start FIP VLAN discovery responder
103184dd345SVasu Dev  * @spma:	   supports SPMA server-provided MACs mode
104e10f8c66SJoe Eykholt  * @probe_tries:   number of FC_IDs probed
1059a6cf881SHannes Reinecke  * @priority:      DCBx FCoE APP priority
10697c8389dSJoe Eykholt  * @dest_addr:	   MAC address of the selected FC forwarder.
10797c8389dSJoe Eykholt  * @ctl_src_addr:  the native MAC address of our local port.
10870b51aabSRobert Love  * @send:	   LLD-supplied function to handle sending FIP Ethernet frames
10997c8389dSJoe Eykholt  * @update_mac:    LLD-supplied function to handle changes to MAC addresses.
11011b56188SChris Leech  * @get_src_addr:  LLD-supplied function to supply a source MAC address.
111fdb068c6SJoe Eykholt  * @ctlr_mutex:	   lock protecting this structure.
112794d98e7SJoe Eykholt  * @ctlr_lock:     spinlock covering flogi_req
11397c8389dSJoe Eykholt  *
11497c8389dSJoe Eykholt  * This structure is used by all FCoE drivers.  It contains information
11597c8389dSJoe Eykholt  * needed by all FCoE low-level drivers (LLDs) as well as internal state
11697c8389dSJoe Eykholt  * for FIP, and fields shared with the LLDS.
11797c8389dSJoe Eykholt  */
11897c8389dSJoe Eykholt struct fcoe_ctlr {
11997c8389dSJoe Eykholt 	enum fip_state state;
1201917d42dSHannes Reinecke 	enum fip_mode mode;
12197c8389dSJoe Eykholt 	struct fc_lport *lp;
12297c8389dSJoe Eykholt 	struct fcoe_fcf *sel_fcf;
12397c8389dSJoe Eykholt 	struct list_head fcfs;
1249d34876fSRobert Love 	struct fcoe_ctlr_device *cdev;
12597c8389dSJoe Eykholt 	u16 fcf_count;
12697c8389dSJoe Eykholt 	unsigned long sol_time;
12797c8389dSJoe Eykholt 	unsigned long sel_time;
12897c8389dSJoe Eykholt 	unsigned long port_ka_time;
12997c8389dSJoe Eykholt 	unsigned long ctlr_ka_time;
13097c8389dSJoe Eykholt 	struct timer_list timer;
13142913657SJoe Eykholt 	struct work_struct timer_work;
13297c8389dSJoe Eykholt 	struct work_struct recv_work;
13397c8389dSJoe Eykholt 	struct sk_buff_head fip_recv_list;
134794d98e7SJoe Eykholt 	struct sk_buff *flogi_req;
135e10f8c66SJoe Eykholt 
136e10f8c66SJoe Eykholt 	struct rnd_state rnd_state;
137e10f8c66SJoe Eykholt 	u32 port_id;
138e10f8c66SJoe Eykholt 
13997c8389dSJoe Eykholt 	u16 user_mfs;
14097c8389dSJoe Eykholt 	u16 flogi_oxid;
141794d98e7SJoe Eykholt 	u8 flogi_req_send;
14297c8389dSJoe Eykholt 	u8 flogi_count;
1439a6cf881SHannes Reinecke 	bool map_dest;
1449a6cf881SHannes Reinecke 	bool fip_resp;
145184dd345SVasu Dev 	u8 spma;
146e10f8c66SJoe Eykholt 	u8 probe_tries;
1476f6c2aa3Sjohn fastabend 	u8 priority;
14897c8389dSJoe Eykholt 	u8 dest_addr[ETH_ALEN];
14997c8389dSJoe Eykholt 	u8 ctl_src_addr[ETH_ALEN];
15097c8389dSJoe Eykholt 
15197c8389dSJoe Eykholt 	void (*send)(struct fcoe_ctlr *, struct sk_buff *);
15211b56188SChris Leech 	void (*update_mac)(struct fc_lport *, u8 *addr);
15311b56188SChris Leech 	u8 * (*get_src_addr)(struct fc_lport *);
154fdb068c6SJoe Eykholt 	struct mutex ctlr_mutex;
155794d98e7SJoe Eykholt 	spinlock_t ctlr_lock;
15697c8389dSJoe Eykholt };
15797c8389dSJoe Eykholt 
15870b51aabSRobert Love /**
159619fe4beSRobert Love  * fcoe_ctlr_priv() - Return the private data from a fcoe_ctlr
160*d9c91182SRandy Dunlap  * @ctlr: The fcoe_ctlr whose private data will be returned
161*d9c91182SRandy Dunlap  *
162*d9c91182SRandy Dunlap  * Returns: pointer to the private data
163619fe4beSRobert Love  */
fcoe_ctlr_priv(const struct fcoe_ctlr * ctlr)164619fe4beSRobert Love static inline void *fcoe_ctlr_priv(const struct fcoe_ctlr *ctlr)
165619fe4beSRobert Love {
166619fe4beSRobert Love 	return (void *)(ctlr + 1);
167619fe4beSRobert Love }
168619fe4beSRobert Love 
1699d34876fSRobert Love /*
1709d34876fSRobert Love  * This assumes that the fcoe_ctlr (x) is allocated with the fcoe_ctlr_device.
1719d34876fSRobert Love  */
1728d55e507SRobert Love #define fcoe_ctlr_to_ctlr_dev(x)					\
1739d34876fSRobert Love 	(x)->cdev
1748d55e507SRobert Love 
175619fe4beSRobert Love /**
17670b51aabSRobert Love  * struct fcoe_fcf - Fibre-Channel Forwarder
17770b51aabSRobert Love  * @list:	 list linkage
1788d55e507SRobert Love  * @event_work:  Work for FC Transport actions queue
1798d55e507SRobert Love  * @fip:         The controller that the FCF was discovered on
1808d55e507SRobert Love  * @fcf_dev:     The associated fcoe_fcf_device instance
18170b51aabSRobert Love  * @time:	 system time (jiffies) when an advertisement was last received
18270b51aabSRobert Love  * @switch_name: WWN of switch from advertisement
18370b51aabSRobert Love  * @fabric_name: WWN of fabric from advertisement
18470b51aabSRobert Love  * @fc_map:	 FC_MAP value from advertisement
18581c11dd2SBhanu Prakash Gollapudi  * @fcf_mac:	 Ethernet address of the FCF for FIP traffic
18681c11dd2SBhanu Prakash Gollapudi  * @fcoe_mac:	 Ethernet address of the FCF for FCoE traffic
18770b51aabSRobert Love  * @vfid:	 virtual fabric ID
18870b51aabSRobert Love  * @pri:	 selection priority, smaller values are better
189794d98e7SJoe Eykholt  * @flogi_sent:	 current FLOGI sent to this FCF
19070b51aabSRobert Love  * @flags:	 flags received from advertisement
19170b51aabSRobert Love  * @fka_period:	 keep-alive period, in jiffies
192*d9c91182SRandy Dunlap  * @fd_flags:	 no need for FKA from ENode
19397c8389dSJoe Eykholt  *
19497c8389dSJoe Eykholt  * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that
19597c8389dSJoe Eykholt  * passes FCoE frames on to an FC fabric.  This structure represents
19697c8389dSJoe Eykholt  * one FCF from which advertisements have been received.
19797c8389dSJoe Eykholt  *
19897c8389dSJoe Eykholt  * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and
19997c8389dSJoe Eykholt  * @fcf_mac together form the lookup key.
20097c8389dSJoe Eykholt  */
20197c8389dSJoe Eykholt struct fcoe_fcf {
20297c8389dSJoe Eykholt 	struct list_head list;
2038d55e507SRobert Love 	struct work_struct event_work;
2048d55e507SRobert Love 	struct fcoe_ctlr *fip;
2058d55e507SRobert Love 	struct fcoe_fcf_device *fcf_dev;
20697c8389dSJoe Eykholt 	unsigned long time;
20797c8389dSJoe Eykholt 
20897c8389dSJoe Eykholt 	u64 switch_name;
20997c8389dSJoe Eykholt 	u64 fabric_name;
21097c8389dSJoe Eykholt 	u32 fc_map;
21197c8389dSJoe Eykholt 	u16 vfid;
21297c8389dSJoe Eykholt 	u8 fcf_mac[ETH_ALEN];
21381c11dd2SBhanu Prakash Gollapudi 	u8 fcoe_mac[ETH_ALEN];
21497c8389dSJoe Eykholt 
21597c8389dSJoe Eykholt 	u8 pri;
216794d98e7SJoe Eykholt 	u8 flogi_sent;
21797c8389dSJoe Eykholt 	u16 flags;
21897c8389dSJoe Eykholt 	u32 fka_period;
2198cdffdccSYi Zou 	u8 fd_flags:1;
22097c8389dSJoe Eykholt };
22197c8389dSJoe Eykholt 
2228d55e507SRobert Love #define fcoe_fcf_to_fcf_dev(x)			\
2238d55e507SRobert Love 	((x)->fcf_dev)
2248d55e507SRobert Love 
225e10f8c66SJoe Eykholt /**
226e10f8c66SJoe Eykholt  * struct fcoe_rport - VN2VN remote port
227*d9c91182SRandy Dunlap  * @rdata:	libfc remote port private data
228e10f8c66SJoe Eykholt  * @time:	time of create or last beacon packet received from node
229e10f8c66SJoe Eykholt  * @fcoe_len:	max FCoE frame size, not including VLAN or Ethernet headers
230e10f8c66SJoe Eykholt  * @flags:	flags from probe or claim
231e10f8c66SJoe Eykholt  * @login_count: number of unsuccessful rport logins to this port
232e10f8c66SJoe Eykholt  * @enode_mac:	E_Node control MAC address
233e10f8c66SJoe Eykholt  * @vn_mac:	VN_Node assigned MAC address for data
234e10f8c66SJoe Eykholt  */
235e10f8c66SJoe Eykholt struct fcoe_rport {
236023358b1SHannes Reinecke 	struct fc_rport_priv rdata;
237e10f8c66SJoe Eykholt 	unsigned long time;
238e10f8c66SJoe Eykholt 	u16 fcoe_len;
239e10f8c66SJoe Eykholt 	u16 flags;
240e10f8c66SJoe Eykholt 	u8 login_count;
241e10f8c66SJoe Eykholt 	u8 enode_mac[ETH_ALEN];
242e10f8c66SJoe Eykholt 	u8 vn_mac[ETH_ALEN];
243e10f8c66SJoe Eykholt };
244e10f8c66SJoe Eykholt 
24597c8389dSJoe Eykholt /* FIP API functions */
2468beb90aaSSedat Dilek void fcoe_ctlr_init(struct fcoe_ctlr *, enum fip_mode);
24797c8389dSJoe Eykholt void fcoe_ctlr_destroy(struct fcoe_ctlr *);
24897c8389dSJoe Eykholt void fcoe_ctlr_link_up(struct fcoe_ctlr *);
24997c8389dSJoe Eykholt int fcoe_ctlr_link_down(struct fcoe_ctlr *);
25011b56188SChris Leech int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *);
25197c8389dSJoe Eykholt void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *);
25270b51aabSRobert Love int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *,
253386309ceSJoe Eykholt 			 struct fc_frame *);
25497c8389dSJoe Eykholt 
25585b4aa49SRobert Love /* libfcoe funcs */
25654db804dSGustavo A. R. Silva u64 fcoe_wwn_from_mac(unsigned char mac[ETH_ALEN], unsigned int scheme,
25754db804dSGustavo A. R. Silva 		      unsigned int port);
258e10f8c66SJoe Eykholt int fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *,
259e10f8c66SJoe Eykholt 		      const struct libfc_function_template *, int init_fcp);
2608597ae8bSBhanu Prakash Gollapudi u32 fcoe_fc_crc(struct fc_frame *fp);
2618597ae8bSBhanu Prakash Gollapudi int fcoe_start_io(struct sk_buff *skb);
262d834895cSBhanu Prakash Gollapudi int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type);
263814740d5SBhanu Prakash Gollapudi void __fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb,
264814740d5SBhanu Prakash Gollapudi 		     struct net_device *netdev);
265d834895cSBhanu Prakash Gollapudi void fcoe_wwn_to_str(u64 wwn, char *buf, int len);
266d834895cSBhanu Prakash Gollapudi int fcoe_validate_vport_create(struct fc_vport *vport);
26703702689SYi Zou int fcoe_link_speed_update(struct fc_lport *);
26857c2728fSYi Zou void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *);
26957c2728fSYi Zou void fcoe_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev);
270fdd78027SVasu Dev 
271519e5135SVasu Dev /**
272*d9c91182SRandy Dunlap  * is_fip_mode() - test if FIP mode selected.
273519e5135SVasu Dev  * @fip:	FCoE controller.
274*d9c91182SRandy Dunlap  *
275*d9c91182SRandy Dunlap  * Returns: %true if FIP mode is selected
276519e5135SVasu Dev  */
is_fip_mode(struct fcoe_ctlr * fip)277519e5135SVasu Dev static inline bool is_fip_mode(struct fcoe_ctlr *fip)
278519e5135SVasu Dev {
279519e5135SVasu Dev 	return fip->state == FIP_ST_ENABLED;
280519e5135SVasu Dev }
281519e5135SVasu Dev 
2820ade7d29SYi Zou /* helper for FCoE SW HBA drivers, can include subven and subdev if needed. The
2830ade7d29SYi Zou  * modpost would use pci_device_id table to auto-generate formatted module alias
2840ade7d29SYi Zou  * into the corresponding .mod.c file, but there may or may not be a pci device
2850ade7d29SYi Zou  * id table for FCoE drivers so we use the following helper for build the fcoe
2860ade7d29SYi Zou  * driver module alias.
2870ade7d29SYi Zou  */
2880ade7d29SYi Zou #define MODULE_ALIAS_FCOE_PCI(ven, dev) \
2890ade7d29SYi Zou 	MODULE_ALIAS("fcoe-pci:"	\
2900ade7d29SYi Zou 		"v" __stringify(ven)	\
2910ade7d29SYi Zou 		"d" __stringify(dev) "sv*sd*bc*sc*i*")
2920ade7d29SYi Zou 
2930ade7d29SYi Zou /* the name of the default FCoE transport driver fcoe.ko */
2940ade7d29SYi Zou #define FCOE_TRANSPORT_DEFAULT	"fcoe"
2950ade7d29SYi Zou 
2960ade7d29SYi Zou /* struct fcoe_transport - The FCoE transport interface
2970ade7d29SYi Zou  * @name:	a vendor specific name for their FCoE transport driver
2980ade7d29SYi Zou  * @attached:	whether this transport is already attached
2990ade7d29SYi Zou  * @list:	list linkage to all attached transports
3000ade7d29SYi Zou  * @match:	handler to allow the transport driver to match up a given netdev
3016a891b07SRobert Love  * @alloc:      handler to allocate per-instance FCoE structures
3026a891b07SRobert Love  *		(no discovery or login)
3030ade7d29SYi Zou  * @create:	handler to sysfs entry of create for FCoE instances
3046a891b07SRobert Love  * @destroy:    handler to delete per-instance FCoE structures
3056a891b07SRobert Love  *		(frees all memory)
3060ade7d29SYi Zou  * @enable:	handler to sysfs entry of enable for FCoE instances
3070ade7d29SYi Zou  * @disable:	handler to sysfs entry of disable for FCoE instances
3080ade7d29SYi Zou  */
3090ade7d29SYi Zou struct fcoe_transport {
3100ade7d29SYi Zou 	char name[IFNAMSIZ];
3110ade7d29SYi Zou 	bool attached;
3120ade7d29SYi Zou 	struct list_head list;
3130ade7d29SYi Zou 	bool (*match) (struct net_device *device);
3146a891b07SRobert Love 	int (*alloc) (struct net_device *device);
3151917d42dSHannes Reinecke 	int (*create) (struct net_device *device, enum fip_mode fip_mode);
3160ade7d29SYi Zou 	int (*destroy) (struct net_device *device);
3170ade7d29SYi Zou 	int (*enable) (struct net_device *device);
3180ade7d29SYi Zou 	int (*disable) (struct net_device *device);
3190ade7d29SYi Zou };
3200ade7d29SYi Zou 
3210ade7d29SYi Zou /**
3228597ae8bSBhanu Prakash Gollapudi  * struct fcoe_percpu_s - The context for FCoE receive thread(s)
3234b9bc86dSSebastian Andrzej Siewior  * @kthread:	    The thread context (used by bnx2fc)
3244b9bc86dSSebastian Andrzej Siewior  * @work:	    The work item (used by fcoe)
3258597ae8bSBhanu Prakash Gollapudi  * @fcoe_rx_list:   The queue of pending packets to process
326*d9c91182SRandy Dunlap  * @crc_eof_page:   The memory page for calculating frame trailer CRCs
3278597ae8bSBhanu Prakash Gollapudi  * @crc_eof_offset: The offset into the CRC page pointing to available
3288597ae8bSBhanu Prakash Gollapudi  *		    memory for a new trailer
329*d9c91182SRandy Dunlap  * @lock:	    local lock for members of this struct
3308597ae8bSBhanu Prakash Gollapudi  */
3318597ae8bSBhanu Prakash Gollapudi struct fcoe_percpu_s {
3324b9bc86dSSebastian Andrzej Siewior 	struct task_struct *kthread;
3334b9bc86dSSebastian Andrzej Siewior 	struct work_struct work;
3348597ae8bSBhanu Prakash Gollapudi 	struct sk_buff_head fcoe_rx_list;
3358597ae8bSBhanu Prakash Gollapudi 	struct page *crc_eof_page;
3368597ae8bSBhanu Prakash Gollapudi 	int crc_eof_offset;
337848b8977SDavidlohr Bueso 	local_lock_t lock;
3388597ae8bSBhanu Prakash Gollapudi };
3398597ae8bSBhanu Prakash Gollapudi 
3408597ae8bSBhanu Prakash Gollapudi /**
3418597ae8bSBhanu Prakash Gollapudi  * struct fcoe_port - The FCoE private structure
3428597ae8bSBhanu Prakash Gollapudi  * @priv:		       The associated fcoe interface. The structure is
3438597ae8bSBhanu Prakash Gollapudi  *			       defined by the low level driver
3448597ae8bSBhanu Prakash Gollapudi  * @lport:		       The associated local port
3458597ae8bSBhanu Prakash Gollapudi  * @fcoe_pending_queue:	       The pending Rx queue of skbs
3468597ae8bSBhanu Prakash Gollapudi  * @fcoe_pending_queue_active: Indicates if the pending queue is active
3478597ae8bSBhanu Prakash Gollapudi  * @max_queue_depth:	       Max queue depth of pending queue
3488597ae8bSBhanu Prakash Gollapudi  * @min_queue_depth:	       Min queue depth of pending queue
3498597ae8bSBhanu Prakash Gollapudi  * @timer:		       The queue timer
3508597ae8bSBhanu Prakash Gollapudi  * @destroy_work:	       Handle for work context
3518597ae8bSBhanu Prakash Gollapudi  *			       (to prevent RTNL deadlocks)
352*d9c91182SRandy Dunlap  * @data_src_addr:	       Source address for data
353*d9c91182SRandy Dunlap  * @get_netdev:                function that returns a &net_device from @lport
3548597ae8bSBhanu Prakash Gollapudi  *
3558597ae8bSBhanu Prakash Gollapudi  * An instance of this structure is to be allocated along with the
3568597ae8bSBhanu Prakash Gollapudi  * Scsi_Host and libfc fc_lport structures.
3578597ae8bSBhanu Prakash Gollapudi  */
3588597ae8bSBhanu Prakash Gollapudi struct fcoe_port {
3598597ae8bSBhanu Prakash Gollapudi 	void		      *priv;
3608597ae8bSBhanu Prakash Gollapudi 	struct fc_lport	      *lport;
3618597ae8bSBhanu Prakash Gollapudi 	struct sk_buff_head   fcoe_pending_queue;
3628597ae8bSBhanu Prakash Gollapudi 	u8		      fcoe_pending_queue_active;
3638597ae8bSBhanu Prakash Gollapudi 	u32		      max_queue_depth;
3648597ae8bSBhanu Prakash Gollapudi 	u32		      min_queue_depth;
3658597ae8bSBhanu Prakash Gollapudi 	struct timer_list     timer;
3668597ae8bSBhanu Prakash Gollapudi 	struct work_struct    destroy_work;
3678597ae8bSBhanu Prakash Gollapudi 	u8		      data_src_addr[ETH_ALEN];
3688106fb47SYi Zou 	struct net_device * (*get_netdev)(const struct fc_lport *lport);
3698597ae8bSBhanu Prakash Gollapudi };
37066524ec9SYi Zou 
37166524ec9SYi Zou /**
37266524ec9SYi Zou  * fcoe_get_netdev() - Return the net device associated with a local port
37366524ec9SYi Zou  * @lport: The local port to get the net device from
374*d9c91182SRandy Dunlap  *
375*d9c91182SRandy Dunlap  * Returns: the &net_device associated with this @lport
37666524ec9SYi Zou  */
fcoe_get_netdev(const struct fc_lport * lport)37766524ec9SYi Zou static inline struct net_device *fcoe_get_netdev(const struct fc_lport *lport)
37866524ec9SYi Zou {
37966524ec9SYi Zou 	struct fcoe_port *port = ((struct fcoe_port *)lport_priv(lport));
38066524ec9SYi Zou 
38166524ec9SYi Zou 	return (port->get_netdev) ? port->get_netdev(lport) : NULL;
38266524ec9SYi Zou }
38366524ec9SYi Zou 
3848597ae8bSBhanu Prakash Gollapudi void fcoe_clean_pending_queue(struct fc_lport *);
3858597ae8bSBhanu Prakash Gollapudi void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb);
38613059106SKees Cook void fcoe_queue_timer(struct timer_list *t);
3878597ae8bSBhanu Prakash Gollapudi int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
3888597ae8bSBhanu Prakash Gollapudi 			   struct fcoe_percpu_s *fps);
3898597ae8bSBhanu Prakash Gollapudi 
3908d55e507SRobert Love /* FCoE Sysfs helpers */
3918d55e507SRobert Love void fcoe_fcf_get_selected(struct fcoe_fcf_device *);
3926a891b07SRobert Love void fcoe_ctlr_set_fip_mode(struct fcoe_ctlr_device *);
3938d55e507SRobert Love 
3948597ae8bSBhanu Prakash Gollapudi /**
395*d9c91182SRandy Dunlap  * struct fcoe_netdev_mapping - A mapping from &net_device to &fcoe_transport
396*d9c91182SRandy Dunlap  * @list: list linkage of the mappings
397*d9c91182SRandy Dunlap  * @netdev: the &net_device
398*d9c91182SRandy Dunlap  * @ft: the fcoe_transport associated with @netdev
3990ade7d29SYi Zou  */
4000ade7d29SYi Zou struct fcoe_netdev_mapping {
4010ade7d29SYi Zou 	struct list_head list;
4020ade7d29SYi Zou 	struct net_device *netdev;
4030ade7d29SYi Zou 	struct fcoe_transport *ft;
4040ade7d29SYi Zou };
4050ade7d29SYi Zou 
4060ade7d29SYi Zou /* fcoe transports registration and deregistration */
4070ade7d29SYi Zou int fcoe_transport_attach(struct fcoe_transport *ft);
4080ade7d29SYi Zou int fcoe_transport_detach(struct fcoe_transport *ft);
409519e5135SVasu Dev 
4106a891b07SRobert Love /* sysfs store handler for ctrl_control interface */
41175cff725SGreg Kroah-Hartman ssize_t fcoe_ctlr_create_store(const char *buf, size_t count);
41275cff725SGreg Kroah-Hartman ssize_t fcoe_ctlr_destroy_store(const char *buf, size_t count);
4136a891b07SRobert Love 
41485b4aa49SRobert Love #endif /* _LIBFCOE_H */
4156a891b07SRobert Love 
4166a891b07SRobert Love 
417