1 /**********************************************************************
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
7 * Copyright (c) 2003-2016 Cavium, Inc.
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more details.
17 ***********************************************************************/
18 /*! \file liquidio_common.h
19 * \brief Common: Structures and macros used in PCI-NIC package by core and
23 #ifndef __LIQUIDIO_COMMON_H__
24 #define __LIQUIDIO_COMMON_H__
26 #include "octeon_config.h"
28 #define LIQUIDIO_PACKAGE ""
29 #define LIQUIDIO_BASE_MAJOR_VERSION 1
30 #define LIQUIDIO_BASE_MINOR_VERSION 7
31 #define LIQUIDIO_BASE_MICRO_VERSION 2
32 #define LIQUIDIO_BASE_VERSION __stringify(LIQUIDIO_BASE_MAJOR_VERSION) "." \
33 __stringify(LIQUIDIO_BASE_MINOR_VERSION)
34 #define LIQUIDIO_MICRO_VERSION "." __stringify(LIQUIDIO_BASE_MICRO_VERSION)
35 #define LIQUIDIO_VERSION LIQUIDIO_PACKAGE \
36 __stringify(LIQUIDIO_BASE_MAJOR_VERSION) "." \
37 __stringify(LIQUIDIO_BASE_MINOR_VERSION) \
38 "." __stringify(LIQUIDIO_BASE_MICRO_VERSION)
48 /** Tag types used by Octeon cores in its work. */
49 enum octeon_tag_type
{
56 /* pre-defined host->NIC tag values */
57 #define LIO_CONTROL (0x11111110)
58 #define LIO_DATA(i) (0x11111111 + (i))
60 /* Opcodes used by host driver/apps to perform operations on the core.
61 * These are used to identify the major subsystem that the operation
64 #define OPCODE_CORE 0 /* used for generic core operations */
65 #define OPCODE_NIC 1 /* used for NIC operations */
66 /* Subcodes are used by host driver/apps to identify the sub-operation
67 * for the core. They only need to by unique for a given subsystem.
69 #define OPCODE_SUBCODE(op, sub) ((((op) & 0x0f) << 8) | ((sub) & 0x7f))
71 /** OPCODE_CORE subcodes. For future use. */
73 /** OPCODE_NIC subcodes */
75 /* This subcode is sent by core PCI driver to indicate cores are ready. */
76 #define OPCODE_NIC_CORE_DRV_ACTIVE 0x01
77 #define OPCODE_NIC_NW_DATA 0x02 /* network packet data */
78 #define OPCODE_NIC_CMD 0x03
79 #define OPCODE_NIC_INFO 0x04
80 #define OPCODE_NIC_PORT_STATS 0x05
81 #define OPCODE_NIC_MDIO45 0x06
82 #define OPCODE_NIC_TIMESTAMP 0x07
83 #define OPCODE_NIC_INTRMOD_CFG 0x08
84 #define OPCODE_NIC_IF_CFG 0x09
85 #define OPCODE_NIC_VF_DRV_NOTICE 0x0A
86 #define OPCODE_NIC_INTRMOD_PARAMS 0x0B
87 #define OPCODE_NIC_QCOUNT_UPDATE 0x12
88 #define OPCODE_NIC_SET_TRUSTED_VF 0x13
89 #define OPCODE_NIC_SYNC_OCTEON_TIME 0x14
90 #define VF_DRV_LOADED 1
91 #define VF_DRV_REMOVED -1
92 #define VF_DRV_MACADDR_CHANGED 2
94 #define OPCODE_NIC_VF_REP_PKT 0x15
95 #define OPCODE_NIC_VF_REP_CMD 0x16
96 #define OPCODE_NIC_UBOOT_CTL 0x17
98 #define CORE_DRV_TEST_SCATTER_OP 0xFFF5
100 /* Application codes advertised by the core driver initialization packet. */
101 #define CVM_DRV_APP_START 0x0
102 #define CVM_DRV_NO_APP 0
103 #define CVM_DRV_APP_COUNT 0x2
104 #define CVM_DRV_BASE_APP (CVM_DRV_APP_START + 0x0)
105 #define CVM_DRV_NIC_APP (CVM_DRV_APP_START + 0x1)
106 #define CVM_DRV_INVALID_APP (CVM_DRV_APP_START + 0x2)
107 #define CVM_DRV_APP_END (CVM_DRV_INVALID_APP - 1)
109 #define BYTES_PER_DHLEN_UNIT 8
110 #define MAX_REG_CNT 2000000U
111 #define INTRNAMSIZ 32
112 #define IRQ_NAME_OFF(i) ((i) * INTRNAMSIZ)
113 #define MAX_IOQ_INTERRUPTS_PER_PF (64 * 2)
114 #define MAX_IOQ_INTERRUPTS_PER_VF (8 * 2)
116 #define SCR2_BIT_FW_LOADED 63
118 /* App specific capabilities from firmware to pf driver */
119 #define LIQUIDIO_TIME_SYNC_CAP 0x1
120 #define LIQUIDIO_SWITCHDEV_CAP 0x2
122 static inline u32
incr_index(u32 index
, u32 count
, u32 max
)
124 if ((index
+ count
) >= max
)
125 index
= index
+ count
- max
;
132 #define OCT_BOARD_NAME 32
133 #define OCT_SERIAL_LEN 64
135 /* Structure used by core driver to send indication that the Octeon
136 * application is ready.
138 struct octeon_core_setup
{
141 char boardname
[OCT_BOARD_NAME
];
143 char board_serial_number
[OCT_SERIAL_LEN
];
151 /*--------------------------- SCATTER GATHER ENTRY -----------------------*/
153 /* The Scatter-Gather List Entry. The scatter or gather component used with
154 * a Octeon input instruction has this format.
156 struct octeon_sg_entry
{
157 /** The first 64 bit gives the size of data in each dptr.*/
163 /** The 4 dptr pointers for this entry. */
168 #define OCT_SG_ENTRY_SIZE (sizeof(struct octeon_sg_entry))
170 /* \brief Add size to gather list
171 * @param sg_entry scatter/gather entry
172 * @param size size to add
173 * @param pos position to add it.
175 static inline void add_sg_size(struct octeon_sg_entry
*sg_entry
,
179 #ifdef __BIG_ENDIAN_BITFIELD
180 sg_entry
->u
.size
[pos
] = size
;
182 sg_entry
->u
.size
[3 - pos
] = size
;
186 /*------------------------- End Scatter/Gather ---------------------------*/
188 #define OCTNET_FRM_LENGTH_SIZE 8
190 #define OCTNET_FRM_PTP_HEADER_SIZE 8
192 #define OCTNET_FRM_HEADER_SIZE 22 /* VLAN + Ethernet */
194 #define OCTNET_MIN_FRM_SIZE 64
196 #define OCTNET_MAX_FRM_SIZE (16000 + OCTNET_FRM_HEADER_SIZE)
198 #define OCTNET_DEFAULT_MTU (1500)
199 #define OCTNET_DEFAULT_FRM_SIZE (OCTNET_DEFAULT_MTU + OCTNET_FRM_HEADER_SIZE)
201 /** NIC Commands are sent using this Octeon Input Queue */
202 #define OCTNET_CMD_Q 0
204 /* NIC Command types */
205 #define OCTNET_CMD_CHANGE_MTU 0x1
206 #define OCTNET_CMD_CHANGE_MACADDR 0x2
207 #define OCTNET_CMD_CHANGE_DEVFLAGS 0x3
208 #define OCTNET_CMD_RX_CTL 0x4
210 #define OCTNET_CMD_SET_MULTI_LIST 0x5
211 #define OCTNET_CMD_CLEAR_STATS 0x6
213 /* command for setting the speed, duplex & autoneg */
214 #define OCTNET_CMD_SET_SETTINGS 0x7
215 #define OCTNET_CMD_SET_FLOW_CTL 0x8
217 #define OCTNET_CMD_MDIO_READ_WRITE 0x9
218 #define OCTNET_CMD_GPIO_ACCESS 0xA
219 #define OCTNET_CMD_LRO_ENABLE 0xB
220 #define OCTNET_CMD_LRO_DISABLE 0xC
221 #define OCTNET_CMD_SET_RSS 0xD
222 #define OCTNET_CMD_WRITE_SA 0xE
223 #define OCTNET_CMD_DELETE_SA 0xF
224 #define OCTNET_CMD_UPDATE_SA 0x12
226 #define OCTNET_CMD_TNL_RX_CSUM_CTL 0x10
227 #define OCTNET_CMD_TNL_TX_CSUM_CTL 0x11
228 #define OCTNET_CMD_IPSECV2_AH_ESP_CTL 0x13
229 #define OCTNET_CMD_VERBOSE_ENABLE 0x14
230 #define OCTNET_CMD_VERBOSE_DISABLE 0x15
232 #define OCTNET_CMD_VLAN_FILTER_CTL 0x16
233 #define OCTNET_CMD_ADD_VLAN_FILTER 0x17
234 #define OCTNET_CMD_DEL_VLAN_FILTER 0x18
235 #define OCTNET_CMD_VXLAN_PORT_CONFIG 0x19
237 #define OCTNET_CMD_ID_ACTIVE 0x1a
239 #define OCTNET_CMD_SET_UC_LIST 0x1b
240 #define OCTNET_CMD_SET_VF_LINKSTATE 0x1c
242 #define OCTNET_CMD_QUEUE_COUNT_CTL 0x1f
244 #define OCTNET_CMD_VXLAN_PORT_ADD 0x0
245 #define OCTNET_CMD_VXLAN_PORT_DEL 0x1
246 #define OCTNET_CMD_RXCSUM_ENABLE 0x0
247 #define OCTNET_CMD_RXCSUM_DISABLE 0x1
248 #define OCTNET_CMD_TXCSUM_ENABLE 0x0
249 #define OCTNET_CMD_TXCSUM_DISABLE 0x1
250 #define OCTNET_CMD_VLAN_FILTER_ENABLE 0x1
251 #define OCTNET_CMD_VLAN_FILTER_DISABLE 0x0
253 #define SEAPI_CMD_SPEED_SET 0x2
254 #define SEAPI_CMD_SPEED_GET 0x3
256 #define LIO_CMD_WAIT_TM 100
258 /* RX(packets coming from wire) Checksum verification flags */
260 #define CNNIC_L4SUM_VERIFIED 0x1
261 #define CNNIC_IPSUM_VERIFIED 0x2
262 #define CNNIC_TUN_CSUM_VERIFIED 0x4
263 #define CNNIC_CSUM_VERIFIED (CNNIC_IPSUM_VERIFIED | CNNIC_L4SUM_VERIFIED)
265 /*LROIPV4 and LROIPV6 Flags*/
266 #define OCTNIC_LROIPV4 0x1
267 #define OCTNIC_LROIPV6 0x2
269 /* Interface flags communicated between host driver and core app. */
270 enum octnet_ifflags
{
271 OCTNET_IFFLAG_PROMISC
= 0x01,
272 OCTNET_IFFLAG_ALLMULTI
= 0x02,
273 OCTNET_IFFLAG_MULTICAST
= 0x04,
274 OCTNET_IFFLAG_BROADCAST
= 0x08,
275 OCTNET_IFFLAG_UNICAST
= 0x10
299 #ifdef __BIG_ENDIAN_BITFIELD
302 u64 more
:6; /* How many udd words follow the command */
327 #define OCTNET_CMD_SIZE (sizeof(union octnet_cmd))
329 /*pkiih3 + irh + ossp[0] + ossp[1] + rdp + rptr = 40 bytes */
330 #define LIO_SOFTCMDRESP_IH2 40
331 #define LIO_SOFTCMDRESP_IH3 (40 + 8)
333 #define LIO_PCICMD_O2 24
334 #define LIO_PCICMD_O3 (24 + 8)
336 /* Instruction Header(DPI) - for OCTEON-III models */
337 struct octeon_instr_ih3
{
338 #ifdef __BIG_ENDIAN_BITFIELD
343 /** Gather indicator 1=gather*/
346 /** Data length OR no. of entries in gather list */
349 /** Front Data size */
355 /** PKI port kind - PKIND */
365 /** PKI port kind - PKIND */
371 /** Front Data size */
374 /** Data length OR no. of entries in gather list */
377 /** Gather indicator 1=gather*/
386 /* Optional PKI Instruction Header(PKI IH) - for OCTEON-III models */
387 /** BIG ENDIAN format. */
388 struct octeon_instr_pki_ih3
{
389 #ifdef __BIG_ENDIAN_BITFIELD
394 /** Raw mode indicator 1 = RAW */
459 /** Raw mode indicator 1 = RAW */
468 /** Instruction Header */
469 struct octeon_instr_ih2
{
470 #ifdef __BIG_ENDIAN_BITFIELD
471 /** Raw mode indicator 1 = RAW */
474 /** Gather indicator 1=gather*/
477 /** Data length OR no. of entries in gather list */
480 /** Front Data size */
483 /** Packet Order / Work Unit selection (1 of 8)*/
486 /** Core group selection (1 of 16) */
489 /** Short Raw Packet Indicator 1=short raw pkt */
504 /** Short Raw Packet Indicator 1=short raw pkt */
507 /** Core group selection (1 of 16) */
510 /** Packet Order / Work Unit selection (1 of 8)*/
513 /** Front Data size */
516 /** Data length OR no. of entries in gather list */
519 /** Gather indicator 1=gather*/
522 /** Raw mode indicator 1 = RAW */
527 /** Input Request Header */
528 struct octeon_instr_irh
{
529 #ifdef __BIG_ENDIAN_BITFIELD
536 u64 ossp
:32; /* opcode/subcode specific parameters */
538 u64 ossp
:32; /* opcode/subcode specific parameters */
548 /** Return Data Parameters */
549 struct octeon_instr_rdp
{
550 #ifdef __BIG_ENDIAN_BITFIELD
561 /** Receive Header */
563 #ifdef __BIG_ENDIAN_BITFIELD
568 u64 len
:3; /** additional 64-bit words */
570 u64 ossp
:32; /** opcode/subcode specific parameters */
575 u64 len
:3; /** additional 64-bit words */
579 u64 csum_verified
:3; /** checksum verified. */
580 u64 has_hwtstamp
:1; /** Has hardware timestamp. 1 = yes. */
582 u64 has_hash
:1; /** Has hash (rth or rss). 1 = yes. */
587 u64 len
:3; /** additional 64-bit words */
590 u64 max_nic_ports
:10;
598 u64 len
:3; /** additional 64-bit words */
606 u64 ossp
:32; /** opcode/subcode specific parameters */
608 u64 len
:3; /** additional 64-bit words */
613 u64 has_hash
:1; /** Has hash (rth or rss). 1 = yes. */
615 u64 has_hwtstamp
:1; /** 1 = has hwtstamp */
616 u64 csum_verified
:3; /** checksum verified. */
620 u64 len
:3; /** additional 64-bit words */
628 u64 max_nic_ports
:10;
631 u64 len
:3; /** additional 64-bit words */
639 u64 len
:3; /** additional 64-bit words */
646 #define OCT_RH_SIZE (sizeof(union octeon_rh))
648 union octnic_packet_params
{
651 #ifdef __BIG_ENDIAN_BITFIELD
653 u32 ip_csum
:1; /* Perform IP header checksum(s) */
654 /* Perform Outer transport header checksum */
655 u32 transport_csum
:1;
656 /* Find tunnel, and perform transport csum. */
658 u32 tsflag
:1; /* Timestamp this packet */
659 u32 ipsec_ops
:4; /* IPsec operation */
664 u32 transport_csum
:1;
671 /** Status of a RGMII Link on Octeon as seen by core driver. */
672 union oct_link_status
{
676 #ifdef __BIG_ENDIAN_BITFIELD
703 LIO_PHY_PORT_TP
= 0x0,
704 LIO_PHY_PORT_FIBRE
= 0x1,
705 LIO_PHY_PORT_UNKNOWN
,
708 /** The txpciq info passed to host from the firmware */
714 #ifdef __BIG_ENDIAN_BITFIELD
736 /** The rxpciq info passed to host from the firmware */
742 #ifdef __BIG_ENDIAN_BITFIELD
752 /** Information for a OCTEON ethernet interface shared between core & host. */
753 struct oct_link_info
{
754 union oct_link_status link
;
757 #ifdef __BIG_ENDIAN_BITFIELD
759 u64 macaddr_is_admin_asgnd
:1;
767 u64 macaddr_is_admin_asgnd
:1;
771 union oct_txpciq txpciq
[MAX_IOQS_PER_NICIF
];
772 union oct_rxpciq rxpciq
[MAX_IOQS_PER_NICIF
];
775 #define OCT_LINK_INFO_SIZE (sizeof(struct oct_link_info))
777 struct liquidio_if_cfg_info
{
778 u64 iqmask
; /** mask for IQs enabled for the port */
779 u64 oqmask
; /** mask for OQs enabled for the port */
780 struct oct_link_info linfo
; /** initial link information */
781 char liquidio_firmware_version
[32];
784 /** Stats for each NIC port in RX direction. */
785 struct nic_rx_stats
{
786 /* link-level stats */
787 u64 total_rcvd
; /* Received packets */
788 u64 bytes_rcvd
; /* Octets of received packets */
789 u64 total_bcst
; /* Number of non-dropped L2 broadcast packets */
790 u64 total_mcst
; /* Number of non-dropped L2 multicast packets */
791 u64 runts
; /* Packets shorter than allowed */
792 u64 ctl_rcvd
; /* Received PAUSE packets */
793 u64 fifo_err
; /* Packets dropped due to RX FIFO full */
794 u64 dmac_drop
; /* Packets dropped by the DMAC filter */
795 u64 fcs_err
; /* Sum of fragment, overrun, and FCS errors */
796 u64 jabber_err
; /* Packets larger than allowed */
797 u64 l2_err
; /* Sum of DMA, parity, PCAM access, no memory,
798 * buffer overflow, malformed L2 header or
799 * length, oversize errors
801 u64 frame_err
; /* Sum of IPv4 and L4 checksum errors */
802 u64 red_drops
; /* Packets dropped by RED due to buffer
809 u64 fw_total_fwd_bytes
;
820 u64 fw_lro_pkts
; /* Number of packets that are LROed */
821 u64 fw_lro_octs
; /* Number of octets that are LROed */
822 u64 fw_total_lro
; /* Number of LRO packets formed */
823 u64 fw_lro_aborts
; /* Number of times LRO of packet aborted */
824 u64 fw_lro_aborts_port
;
825 u64 fw_lro_aborts_seq
;
826 u64 fw_lro_aborts_tsval
;
827 u64 fw_lro_aborts_timer
; /* Timer setting error */
828 /* intrmod: packet forward rate */
832 /** Stats for each NIC port in RX direction. */
833 struct nic_tx_stats
{
834 /* link-level stats */
835 u64 total_pkts_sent
; /* Total frames sent on the interface */
836 u64 total_bytes_sent
; /* Total octets sent on the interface */
837 u64 mcast_pkts_sent
; /* Packets sent to the multicast DMAC */
838 u64 bcast_pkts_sent
; /* Packets sent to a broadcast DMAC */
839 u64 ctl_sent
; /* Control/PAUSE packets sent */
840 u64 one_collision_sent
; /* Packets sent that experienced a
841 * single collision before successful
844 u64 multi_collision_sent
; /* Packets sent that experienced
845 * multiple collisions before successful
848 u64 max_collision_fail
; /* Packets dropped due to excessive
851 u64 max_deferral_fail
; /* Packets not sent due to max
854 u64 fifo_err
; /* Packets sent that experienced a
855 * transmit underflow and were
858 u64 runts
; /* Packets sent with an octet count
861 u64 total_collisions
; /* Packets dropped due to excessive
868 u64 fw_total_fwd_bytes
;
869 u64 fw_total_mcast_sent
;
870 u64 fw_total_bcast_sent
;
875 u64 fw_tso
; /* number of tso requests */
876 u64 fw_tso_fwd
; /* number of packets segmented in tso */
881 struct oct_link_stats
{
882 struct nic_rx_stats fromwire
;
883 struct nic_tx_stats fromhost
;
887 static inline int opcode_slow_path(union octeon_rh
*rh
)
889 u16 subcode1
, subcode2
;
891 subcode1
= OPCODE_SUBCODE((rh
)->r
.opcode
, (rh
)->r
.subcode
);
892 subcode2
= OPCODE_SUBCODE(OPCODE_NIC
, OPCODE_NIC_NW_DATA
);
894 return (subcode2
!= subcode1
);
897 #define LIO68XX_LED_CTRL_ADDR 0x3501
898 #define LIO68XX_LED_CTRL_CFGON 0x1f
899 #define LIO68XX_LED_CTRL_CFGOFF 0x100
900 #define LIO68XX_LED_BEACON_ADDR 0x3508
901 #define LIO68XX_LED_BEACON_CFGON 0x47fd
902 #define LIO68XX_LED_BEACON_CFGOFF 0x11fc
903 #define VITESSE_PHY_GPIO_DRIVEON 0x1
904 #define VITESSE_PHY_GPIO_CFG 0x8
905 #define VITESSE_PHY_GPIO_DRIVEOFF 0x4
906 #define VITESSE_PHY_GPIO_HIGH 0x2
907 #define VITESSE_PHY_GPIO_LOW 0x3
908 #define LED_IDENTIFICATION_ON 0x1
909 #define LED_IDENTIFICATION_OFF 0x0
910 #define LIO23XX_COPPERHEAD_LED_GPIO 0x2
912 struct oct_mdio_cmd
{
920 #define OCT_LINK_STATS_SIZE (sizeof(struct oct_link_stats))
922 struct oct_intrmod_cfg
{
928 u64 rx_maxcnt_trigger
;
929 u64 rx_mincnt_trigger
;
930 u64 rx_maxtmr_trigger
;
931 u64 rx_mintmr_trigger
;
932 u64 tx_mincnt_trigger
;
933 u64 tx_maxcnt_trigger
;
939 #define BASE_QUEUE_NOT_REQUESTED 65535
941 union oct_nic_if_cfg
{
944 #ifdef __BIG_ENDIAN_BITFIELD
960 struct lio_trusted_vf
{
963 uint64_t reserved
: 55;
967 s64 sec
; /* seconds */
968 s64 nsec
; /* nanoseconds */
971 struct lio_vf_rep_stats
{
981 enum lio_vf_rep_req_type
{
983 LIO_VF_REP_REQ_STATE
,
985 LIO_VF_REP_REQ_STATS
,
986 LIO_VF_REP_REQ_DEVNAME
990 LIO_VF_REP_STATE_DOWN
,
994 #define LIO_IF_NAME_SIZE 16
995 struct lio_vf_rep_req
{
1001 struct lio_vf_rep_name
{
1002 char name
[LIO_IF_NAME_SIZE
];
1005 struct lio_vf_rep_mtu
{
1010 struct lio_vf_rep_state
{
1017 struct lio_vf_rep_resp
{