1 #ifndef _INTELVF_H
2 #define _INTELVF_H
3 
4 /** @file
5  *
6  * Intel 10/100/1000 virtual function network card driver
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include "intel.h"
13 
14 /** Intel VF BAR size */
15 #define INTELVF_BAR_SIZE ( 16 * 1024 )
16 
17 /** Mailbox Control Register */
18 #define INTELVF_MBCTRL 0x0c40UL
19 #define INTELVF_MBCTRL_REQ	0x00000001UL	/**< Request for PF ready */
20 #define INTELVF_MBCTRL_ACK	0x00000002UL	/**< PF message received */
21 #define INTELVF_MBCTRL_VFU	0x00000004UL	/**< Buffer taken by VF */
22 #define INTELVF_MBCTRL_PFU	0x00000008UL	/**< Buffer taken to PF */
23 #define INTELVF_MBCTRL_PFSTS	0x00000010UL	/**< PF wrote a message */
24 #define INTELVF_MBCTRL_PFACK	0x00000020UL	/**< PF acknowledged message */
25 #define INTELVF_MBCTRL_RSTI	0x00000040UL	/**< PF reset in progress */
26 #define INTELVF_MBCTRL_RSTD	0x00000080UL	/**< PF reset complete */
27 
28 /** Mailbox Memory Register Base */
29 #define INTELVF_MBMEM 0x0800UL
30 
31 /** Reset mailbox message */
32 #define INTELVF_MSG_TYPE_RESET 0x00000001UL
33 
34 /** Set MAC address mailbox message */
35 #define INTELVF_MSG_TYPE_SET_MAC 0x00000002UL
36 
37 /** Set MTU mailbox message */
38 #define INTELVF_MSG_TYPE_SET_MTU 0x00000005UL
39 
40 /** Get queue configuration message */
41 #define INTELVF_MSG_TYPE_GET_QUEUES 0x00000009UL
42 
43 /** Control ("ping") mailbox message */
44 #define INTELVF_MSG_TYPE_CONTROL 0x00000100UL
45 
46 /** Message type mask */
47 #define INTELVF_MSG_TYPE_MASK 0x0000ffffUL
48 
49 /** Message NACK flag */
50 #define INTELVF_MSG_NACK 0x40000000UL
51 
52 /** Message ACK flag */
53 #define INTELVF_MSG_ACK 0x80000000UL
54 
55 /** Message is a response */
56 #define INTELVF_MSG_RESPONSE ( INTELVF_MSG_ACK | INTELVF_MSG_NACK )
57 
58 /** MAC address mailbox message */
59 struct intelvf_msg_mac {
60 	/** Message header */
61 	uint32_t hdr;
62 	/** MAC address */
63 	uint8_t mac[ETH_ALEN];
64 	/** Alignment padding */
65 	uint8_t reserved[ (-ETH_ALEN) & 0x3 ];
66 } __attribute__ (( packed ));
67 
68 /** Version number mailbox message */
69 struct intelvf_msg_version {
70 	/** Message header */
71 	uint32_t hdr;
72 	/** API version */
73 	uint32_t version;
74 } __attribute__ (( packed ));
75 
76 /** MTU mailbox message */
77 struct intelvf_msg_mtu {
78 	/** Message header */
79 	uint32_t hdr;
80 	/** Maximum packet size */
81 	uint32_t mtu;
82 } __attribute__ (( packed ));
83 
84 /** Queue configuration mailbox message (API v1.1+ only) */
85 struct intelvf_msg_queues {
86 	/** Message header */
87 	uint32_t hdr;
88 	/** Maximum number of transmit queues */
89 	uint32_t tx;
90 	/** Maximum number of receive queues */
91 	uint32_t rx;
92 	/** VLAN hand-waving thing
93 	 *
94 	 * This is labelled IXGBE_VF_TRANS_VLAN in the Linux driver.
95 	 *
96 	 * A comment in the Linux PF driver describes it as "notify VF
97 	 * of need for VLAN tag stripping, and correct queue".  It
98 	 * will be filled with a non-zero value if the PF is enforcing
99 	 * the use of a single VLAN tag.  It will also be filled with
100 	 * a non-zero value if the PF is using multiple traffic
101 	 * classes.
102 	 *
103 	 * The Linux VF driver seems to treat this field as being
104 	 * simply the number of traffic classes, and gives it no
105 	 * VLAN-related interpretation.
106 	 *
107 	 * If the PF is enforcing the use of a single VLAN tag for the
108 	 * VF, then the VLAN tag will be transparently inserted in
109 	 * transmitted packets (via the PFVMVIR register) but will
110 	 * still be visible in received packets.  The Linux VF driver
111 	 * handles this unexpected VLAN tag by simply ignoring any
112 	 * unrecognised VLAN tags.
113 	 *
114 	 * We choose to strip and ignore the VLAN tag if this field
115 	 * has a non-zero value.
116 	 */
117 	uint32_t vlan_thing;
118 	/** Default queue */
119 	uint32_t dflt;
120 } __attribute__ (( packed ));
121 
122 /** Raw mailbox message */
123 struct intelvf_msg_raw {
124 	/** Raw dwords */
125 	uint32_t dword[0];
126 } __attribute__ (( packed ));
127 
128 /** Mailbox message */
129 union intelvf_msg {
130 	/** Message header */
131 	uint32_t hdr;
132 	/** MAC address message */
133 	struct intelvf_msg_mac mac;
134 	/** Version number message */
135 	struct intelvf_msg_version version;
136 	/** MTU message */
137 	struct intelvf_msg_mtu mtu;
138 	/** Queue configuration message */
139 	struct intelvf_msg_queues queues;
140 	/** Raw dwords */
141 	struct intelvf_msg_raw raw;
142 };
143 
144 /** Maximum time to wait for mailbox message
145  *
146  * This is a policy decision.
147  */
148 #define INTELVF_MBOX_MAX_WAIT_MS 500
149 
150 extern int intelvf_mbox_msg ( struct intel_nic *intel, union intelvf_msg *msg );
151 extern int intelvf_mbox_poll ( struct intel_nic *intel );
152 extern int intelvf_mbox_wait ( struct intel_nic *intel );
153 extern int intelvf_mbox_reset ( struct intel_nic *intel, uint8_t *hw_addr );
154 extern int intelvf_mbox_set_mac ( struct intel_nic *intel,
155 				  const uint8_t *ll_addr );
156 extern int intelvf_mbox_set_mtu ( struct intel_nic *intel, size_t mtu );
157 
158 #endif /* _INTELVF_H */
159