162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * QLogic Fibre Channel HBA Driver
462306a36Sopenharmony_ci * Copyright (c)  2003-2014 QLogic Corporation
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef __QLA_BSG_H
762306a36Sopenharmony_ci#define __QLA_BSG_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/* BSG Vendor specific commands */
1062306a36Sopenharmony_ci#define QL_VND_LOOPBACK		0x01
1162306a36Sopenharmony_ci#define QL_VND_A84_RESET	0x02
1262306a36Sopenharmony_ci#define QL_VND_A84_UPDATE_FW	0x03
1362306a36Sopenharmony_ci#define QL_VND_A84_MGMT_CMD	0x04
1462306a36Sopenharmony_ci#define QL_VND_IIDMA		0x05
1562306a36Sopenharmony_ci#define QL_VND_FCP_PRIO_CFG_CMD	0x06
1662306a36Sopenharmony_ci#define QL_VND_READ_FLASH	0x07
1762306a36Sopenharmony_ci#define QL_VND_UPDATE_FLASH	0x08
1862306a36Sopenharmony_ci#define QL_VND_SET_FRU_VERSION	0x0B
1962306a36Sopenharmony_ci#define QL_VND_READ_FRU_STATUS	0x0C
2062306a36Sopenharmony_ci#define QL_VND_WRITE_FRU_STATUS	0x0D
2162306a36Sopenharmony_ci#define QL_VND_DIAG_IO_CMD	0x0A
2262306a36Sopenharmony_ci#define QL_VND_WRITE_I2C	0x10
2362306a36Sopenharmony_ci#define QL_VND_READ_I2C		0x11
2462306a36Sopenharmony_ci#define QL_VND_FX00_MGMT_CMD	0x12
2562306a36Sopenharmony_ci#define QL_VND_SERDES_OP	0x13
2662306a36Sopenharmony_ci#define	QL_VND_SERDES_OP_EX	0x14
2762306a36Sopenharmony_ci#define QL_VND_GET_FLASH_UPDATE_CAPS    0x15
2862306a36Sopenharmony_ci#define QL_VND_SET_FLASH_UPDATE_CAPS    0x16
2962306a36Sopenharmony_ci#define QL_VND_GET_BBCR_DATA    0x17
3062306a36Sopenharmony_ci#define QL_VND_GET_PRIV_STATS	0x18
3162306a36Sopenharmony_ci#define QL_VND_DPORT_DIAGNOSTICS	0x19
3262306a36Sopenharmony_ci#define QL_VND_GET_PRIV_STATS_EX	0x1A
3362306a36Sopenharmony_ci#define QL_VND_SS_GET_FLASH_IMAGE_STATUS	0x1E
3462306a36Sopenharmony_ci#define QL_VND_EDIF_MGMT                0X1F
3562306a36Sopenharmony_ci#define QL_VND_MANAGE_HOST_STATS	0x23
3662306a36Sopenharmony_ci#define QL_VND_GET_HOST_STATS		0x24
3762306a36Sopenharmony_ci#define QL_VND_GET_TGT_STATS		0x25
3862306a36Sopenharmony_ci#define QL_VND_MANAGE_HOST_PORT		0x26
3962306a36Sopenharmony_ci#define QL_VND_MBX_PASSTHRU		0x2B
4062306a36Sopenharmony_ci#define QL_VND_DPORT_DIAGNOSTICS_V2	0x2C
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* BSG Vendor specific subcode returns */
4362306a36Sopenharmony_ci#define EXT_STATUS_OK			0
4462306a36Sopenharmony_ci#define EXT_STATUS_ERR			1
4562306a36Sopenharmony_ci#define EXT_STATUS_BUSY			2
4662306a36Sopenharmony_ci#define EXT_STATUS_INVALID_PARAM	6
4762306a36Sopenharmony_ci#define EXT_STATUS_DATA_OVERRUN		7
4862306a36Sopenharmony_ci#define EXT_STATUS_DATA_UNDERRUN	8
4962306a36Sopenharmony_ci#define EXT_STATUS_MAILBOX		11
5062306a36Sopenharmony_ci#define EXT_STATUS_BUFFER_TOO_SMALL	16
5162306a36Sopenharmony_ci#define EXT_STATUS_NO_MEMORY		17
5262306a36Sopenharmony_ci#define EXT_STATUS_DEVICE_OFFLINE	22
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/*
5562306a36Sopenharmony_ci * To support bidirectional iocb
5662306a36Sopenharmony_ci * BSG Vendor specific returns
5762306a36Sopenharmony_ci */
5862306a36Sopenharmony_ci#define EXT_STATUS_NOT_SUPPORTED	27
5962306a36Sopenharmony_ci#define EXT_STATUS_INVALID_CFG		28
6062306a36Sopenharmony_ci#define EXT_STATUS_DMA_ERR		29
6162306a36Sopenharmony_ci#define EXT_STATUS_TIMEOUT		30
6262306a36Sopenharmony_ci#define EXT_STATUS_THREAD_FAILED	31
6362306a36Sopenharmony_ci#define EXT_STATUS_DATA_CMP_FAILED	32
6462306a36Sopenharmony_ci#define EXT_STATUS_DPORT_DIAG_ERR	40
6562306a36Sopenharmony_ci#define EXT_STATUS_DPORT_DIAG_IN_PROCESS	41
6662306a36Sopenharmony_ci#define EXT_STATUS_DPORT_DIAG_NOT_RUNNING	42
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* BSG definations for interpreting CommandSent field */
6962306a36Sopenharmony_ci#define INT_DEF_LB_LOOPBACK_CMD         0
7062306a36Sopenharmony_ci#define INT_DEF_LB_ECHO_CMD             1
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* Loopback related definations */
7362306a36Sopenharmony_ci#define INTERNAL_LOOPBACK		0xF1
7462306a36Sopenharmony_ci#define EXTERNAL_LOOPBACK		0xF2
7562306a36Sopenharmony_ci#define ENABLE_INTERNAL_LOOPBACK	0x02
7662306a36Sopenharmony_ci#define ENABLE_EXTERNAL_LOOPBACK	0x04
7762306a36Sopenharmony_ci#define INTERNAL_LOOPBACK_MASK		0x000E
7862306a36Sopenharmony_ci#define MAX_ELS_FRAME_PAYLOAD		252
7962306a36Sopenharmony_ci#define ELS_OPCODE_BYTE			0x10
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci/* BSG Vendor specific definations */
8262306a36Sopenharmony_ci#define A84_ISSUE_WRITE_TYPE_CMD        0
8362306a36Sopenharmony_ci#define A84_ISSUE_READ_TYPE_CMD         1
8462306a36Sopenharmony_ci#define A84_CLEANUP_CMD                 2
8562306a36Sopenharmony_ci#define A84_ISSUE_RESET_OP_FW           3
8662306a36Sopenharmony_ci#define A84_ISSUE_RESET_DIAG_FW         4
8762306a36Sopenharmony_ci#define A84_ISSUE_UPDATE_OPFW_CMD       5
8862306a36Sopenharmony_ci#define A84_ISSUE_UPDATE_DIAGFW_CMD     6
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_cistruct qla84_mgmt_param {
9162306a36Sopenharmony_ci	union {
9262306a36Sopenharmony_ci		struct {
9362306a36Sopenharmony_ci			uint32_t start_addr;
9462306a36Sopenharmony_ci		} mem; /* for QLA84_MGMT_READ/WRITE_MEM */
9562306a36Sopenharmony_ci		struct {
9662306a36Sopenharmony_ci			uint32_t id;
9762306a36Sopenharmony_ci#define QLA84_MGMT_CONFIG_ID_UIF        1
9862306a36Sopenharmony_ci#define QLA84_MGMT_CONFIG_ID_FCOE_COS   2
9962306a36Sopenharmony_ci#define QLA84_MGMT_CONFIG_ID_PAUSE      3
10062306a36Sopenharmony_ci#define QLA84_MGMT_CONFIG_ID_TIMEOUTS   4
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci		uint32_t param0;
10362306a36Sopenharmony_ci		uint32_t param1;
10462306a36Sopenharmony_ci	} config; /* for QLA84_MGMT_CHNG_CONFIG */
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci	struct {
10762306a36Sopenharmony_ci		uint32_t type;
10862306a36Sopenharmony_ci#define QLA84_MGMT_INFO_CONFIG_LOG_DATA         1 /* Get Config Log Data */
10962306a36Sopenharmony_ci#define QLA84_MGMT_INFO_LOG_DATA                2 /* Get Log Data */
11062306a36Sopenharmony_ci#define QLA84_MGMT_INFO_PORT_STAT               3 /* Get Port Statistics */
11162306a36Sopenharmony_ci#define QLA84_MGMT_INFO_LIF_STAT                4 /* Get LIF Statistics  */
11262306a36Sopenharmony_ci#define QLA84_MGMT_INFO_ASIC_STAT               5 /* Get ASIC Statistics */
11362306a36Sopenharmony_ci#define QLA84_MGMT_INFO_CONFIG_PARAMS           6 /* Get Config Parameters */
11462306a36Sopenharmony_ci#define QLA84_MGMT_INFO_PANIC_LOG               7 /* Get Panic Log */
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci		uint32_t context;
11762306a36Sopenharmony_ci/*
11862306a36Sopenharmony_ci* context definitions for QLA84_MGMT_INFO_CONFIG_LOG_DATA
11962306a36Sopenharmony_ci*/
12062306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_DEBUG_LOG                    0
12162306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_LEARN_LOG                    1
12262306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_FC_ACL_INGRESS_LOG           2
12362306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_FC_ACL_EGRESS_LOG            3
12462306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_ETHERNET_ACL_INGRESS_LOG     4
12562306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_ETHERNET_ACL_EGRESS_LOG      5
12662306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_MESSAGE_TRANSMIT_LOG         6
12762306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_MESSAGE_RECEIVE_LOG          7
12862306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_LINK_EVENT_LOG               8
12962306a36Sopenharmony_ci#define IC_LOG_DATA_LOG_ID_DCX_LOG                      9
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci/*
13262306a36Sopenharmony_ci* context definitions for QLA84_MGMT_INFO_PORT_STAT
13362306a36Sopenharmony_ci*/
13462306a36Sopenharmony_ci#define IC_PORT_STATISTICS_PORT_NUMBER_ETHERNET_PORT0   0
13562306a36Sopenharmony_ci#define IC_PORT_STATISTICS_PORT_NUMBER_ETHERNET_PORT1   1
13662306a36Sopenharmony_ci#define IC_PORT_STATISTICS_PORT_NUMBER_NSL_PORT0        2
13762306a36Sopenharmony_ci#define IC_PORT_STATISTICS_PORT_NUMBER_NSL_PORT1        3
13862306a36Sopenharmony_ci#define IC_PORT_STATISTICS_PORT_NUMBER_FC_PORT0         4
13962306a36Sopenharmony_ci#define IC_PORT_STATISTICS_PORT_NUMBER_FC_PORT1         5
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/*
14362306a36Sopenharmony_ci* context definitions for QLA84_MGMT_INFO_LIF_STAT
14462306a36Sopenharmony_ci*/
14562306a36Sopenharmony_ci#define IC_LIF_STATISTICS_LIF_NUMBER_ETHERNET_PORT0     0
14662306a36Sopenharmony_ci#define IC_LIF_STATISTICS_LIF_NUMBER_ETHERNET_PORT1     1
14762306a36Sopenharmony_ci#define IC_LIF_STATISTICS_LIF_NUMBER_FC_PORT0           2
14862306a36Sopenharmony_ci#define IC_LIF_STATISTICS_LIF_NUMBER_FC_PORT1           3
14962306a36Sopenharmony_ci#define IC_LIF_STATISTICS_LIF_NUMBER_CPU                6
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci		} info; /* for QLA84_MGMT_GET_INFO */
15262306a36Sopenharmony_ci	} u;
15362306a36Sopenharmony_ci};
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_cistruct qla84_msg_mgmt {
15662306a36Sopenharmony_ci	uint16_t cmd;
15762306a36Sopenharmony_ci#define QLA84_MGMT_READ_MEM     0x00
15862306a36Sopenharmony_ci#define QLA84_MGMT_WRITE_MEM    0x01
15962306a36Sopenharmony_ci#define QLA84_MGMT_CHNG_CONFIG  0x02
16062306a36Sopenharmony_ci#define QLA84_MGMT_GET_INFO     0x03
16162306a36Sopenharmony_ci	uint16_t rsrvd;
16262306a36Sopenharmony_ci	struct qla84_mgmt_param mgmtp;/* parameters for cmd */
16362306a36Sopenharmony_ci	uint32_t len; /* bytes in payload following this struct */
16462306a36Sopenharmony_ci	uint8_t payload[]; /* payload for cmd */
16562306a36Sopenharmony_ci};
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_cistruct qla_bsg_a84_mgmt {
16862306a36Sopenharmony_ci	struct qla84_msg_mgmt mgmt;
16962306a36Sopenharmony_ci} __attribute__ ((packed));
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_cistruct qla_scsi_addr {
17262306a36Sopenharmony_ci	uint16_t bus;
17362306a36Sopenharmony_ci	uint16_t target;
17462306a36Sopenharmony_ci} __attribute__ ((packed));
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_cistruct qla_ext_dest_addr {
17762306a36Sopenharmony_ci	union {
17862306a36Sopenharmony_ci		uint8_t wwnn[8];
17962306a36Sopenharmony_ci		uint8_t wwpn[8];
18062306a36Sopenharmony_ci		uint8_t id[4];
18162306a36Sopenharmony_ci		struct qla_scsi_addr scsi_addr;
18262306a36Sopenharmony_ci	} dest_addr;
18362306a36Sopenharmony_ci	uint16_t dest_type;
18462306a36Sopenharmony_ci#define	EXT_DEF_TYPE_WWPN	2
18562306a36Sopenharmony_ci	uint16_t lun;
18662306a36Sopenharmony_ci	uint16_t padding[2];
18762306a36Sopenharmony_ci} __attribute__ ((packed));
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_cistruct qla_port_param {
19062306a36Sopenharmony_ci	struct qla_ext_dest_addr fc_scsi_addr;
19162306a36Sopenharmony_ci	uint16_t mode;
19262306a36Sopenharmony_ci	uint16_t speed;
19362306a36Sopenharmony_ci} __attribute__ ((packed));
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_cistruct qla_mbx_passthru {
19662306a36Sopenharmony_ci	uint16_t reserved1[2];
19762306a36Sopenharmony_ci	uint16_t mbx_in[32];
19862306a36Sopenharmony_ci	uint16_t mbx_out[32];
19962306a36Sopenharmony_ci	uint32_t reserved2[16];
20062306a36Sopenharmony_ci} __packed;
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci/* FRU VPD */
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci#define MAX_FRU_SIZE	36
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_cistruct qla_field_address {
20762306a36Sopenharmony_ci	uint16_t offset;
20862306a36Sopenharmony_ci	uint16_t device;
20962306a36Sopenharmony_ci	uint16_t option;
21062306a36Sopenharmony_ci} __packed;
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_cistruct qla_field_info {
21362306a36Sopenharmony_ci	uint8_t version[MAX_FRU_SIZE];
21462306a36Sopenharmony_ci} __packed;
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_cistruct qla_image_version {
21762306a36Sopenharmony_ci	struct qla_field_address field_address;
21862306a36Sopenharmony_ci	struct qla_field_info field_info;
21962306a36Sopenharmony_ci} __packed;
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_cistruct qla_image_version_list {
22262306a36Sopenharmony_ci	uint32_t count;
22362306a36Sopenharmony_ci	struct qla_image_version version[];
22462306a36Sopenharmony_ci} __packed;
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_cistruct qla_status_reg {
22762306a36Sopenharmony_ci	struct qla_field_address field_address;
22862306a36Sopenharmony_ci	uint8_t status_reg;
22962306a36Sopenharmony_ci	uint8_t reserved[7];
23062306a36Sopenharmony_ci} __packed;
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_cistruct qla_i2c_access {
23362306a36Sopenharmony_ci	uint16_t device;
23462306a36Sopenharmony_ci	uint16_t offset;
23562306a36Sopenharmony_ci	uint16_t option;
23662306a36Sopenharmony_ci	uint16_t length;
23762306a36Sopenharmony_ci	uint8_t  buffer[0x40];
23862306a36Sopenharmony_ci} __packed;
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci/* 26xx serdes register interface */
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci/* serdes reg commands */
24362306a36Sopenharmony_ci#define INT_SC_SERDES_READ_REG		1
24462306a36Sopenharmony_ci#define INT_SC_SERDES_WRITE_REG		2
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_cistruct qla_serdes_reg {
24762306a36Sopenharmony_ci	uint16_t cmd;
24862306a36Sopenharmony_ci	uint16_t addr;
24962306a36Sopenharmony_ci	uint16_t val;
25062306a36Sopenharmony_ci} __packed;
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_cistruct qla_serdes_reg_ex {
25362306a36Sopenharmony_ci	uint16_t cmd;
25462306a36Sopenharmony_ci	uint32_t addr;
25562306a36Sopenharmony_ci	uint32_t val;
25662306a36Sopenharmony_ci} __packed;
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_cistruct qla_flash_update_caps {
25962306a36Sopenharmony_ci	uint64_t  capabilities;
26062306a36Sopenharmony_ci	uint32_t  outage_duration;
26162306a36Sopenharmony_ci	uint8_t   reserved[20];
26262306a36Sopenharmony_ci} __packed;
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci/* BB_CR Status */
26562306a36Sopenharmony_ci#define QLA_BBCR_STATUS_DISABLED       0
26662306a36Sopenharmony_ci#define QLA_BBCR_STATUS_ENABLED        1
26762306a36Sopenharmony_ci#define QLA_BBCR_STATUS_UNKNOWN        2
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ci/* BB_CR State */
27062306a36Sopenharmony_ci#define QLA_BBCR_STATE_OFFLINE         0
27162306a36Sopenharmony_ci#define QLA_BBCR_STATE_ONLINE          1
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci/* BB_CR Offline Reason Code */
27462306a36Sopenharmony_ci#define QLA_BBCR_REASON_PORT_SPEED     1
27562306a36Sopenharmony_ci#define QLA_BBCR_REASON_PEER_PORT      2
27662306a36Sopenharmony_ci#define QLA_BBCR_REASON_SWITCH         3
27762306a36Sopenharmony_ci#define QLA_BBCR_REASON_LOGIN_REJECT   4
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_cistruct  qla_bbcr_data {
28062306a36Sopenharmony_ci	uint8_t   status;         /* 1 - enabled, 0 - Disabled */
28162306a36Sopenharmony_ci	uint8_t   state;          /* 1 - online, 0 - offline */
28262306a36Sopenharmony_ci	uint8_t   configured_bbscn;       /* 0-15 */
28362306a36Sopenharmony_ci	uint8_t   negotiated_bbscn;       /* 0-15 */
28462306a36Sopenharmony_ci	uint8_t   offline_reason_code;
28562306a36Sopenharmony_ci	uint16_t  mbx1;			/* Port state */
28662306a36Sopenharmony_ci	uint8_t   reserved[9];
28762306a36Sopenharmony_ci} __packed;
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_cistruct qla_dport_diag {
29062306a36Sopenharmony_ci	uint16_t options;
29162306a36Sopenharmony_ci	uint32_t buf[16];
29262306a36Sopenharmony_ci	uint8_t  unused[62];
29362306a36Sopenharmony_ci} __packed;
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci#define QLA_GET_DPORT_RESULT_V2		0  /* Get Result */
29662306a36Sopenharmony_ci#define QLA_RESTART_DPORT_TEST_V2	1  /* Restart test */
29762306a36Sopenharmony_ci#define QLA_START_DPORT_TEST_V2		2  /* Start test */
29862306a36Sopenharmony_cistruct qla_dport_diag_v2 {
29962306a36Sopenharmony_ci	uint16_t options;
30062306a36Sopenharmony_ci	uint16_t mbx1;
30162306a36Sopenharmony_ci	uint16_t mbx2;
30262306a36Sopenharmony_ci	uint8_t  unused[58];
30362306a36Sopenharmony_ci	uint8_t buf[1024]; /* Test Result */
30462306a36Sopenharmony_ci} __packed;
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_ci/* D_Port options */
30762306a36Sopenharmony_ci#define QLA_DPORT_RESULT	0x0
30862306a36Sopenharmony_ci#define QLA_DPORT_START		0x2
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ci/* active images in flash */
31162306a36Sopenharmony_cistruct qla_active_regions {
31262306a36Sopenharmony_ci	uint8_t global_image;
31362306a36Sopenharmony_ci	uint8_t board_config;
31462306a36Sopenharmony_ci	uint8_t vpd_nvram;
31562306a36Sopenharmony_ci	uint8_t npiv_config_0_1;
31662306a36Sopenharmony_ci	uint8_t npiv_config_2_3;
31762306a36Sopenharmony_ci	uint8_t nvme_params;
31862306a36Sopenharmony_ci	uint8_t reserved[31];
31962306a36Sopenharmony_ci} __packed;
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci#include "qla_edif_bsg.h"
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ci#endif
324