xref: /freebsd/sys/dev/bnxt/bnxt_en/bnxt_mgmt.h (revision d53d7b466016408229491cfd2f8bdc742ff642e3)
1 /*
2  * Broadcom NetXtreme-C/E network driver.
3  *
4  * Copyright (c) 2022 Broadcom, All Rights Reserved.
5  * The term Broadcom refers to Broadcom Limited and/or its subsidiaries
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "bnxt.h"
30 #include <sys/types.h>
31 #include <sys/systm.h>
32 #include <sys/param.h>
33 #include <sys/module.h>
34 #include <sys/kernel.h>
35 #include <sys/conf.h>
36 #include <sys/uio.h>
37 #include <sys/malloc.h>
38 
39 
40 #define	DRIVER_NAME				"if_bnxt"
41 
42 
43 #define	IOW_BNXT_MGMT_OPCODE_GET_DEV_INFO	_IOW(0, 0, 0)
44 #define	IOW_BNXT_MGMT_OPCODE_PASSTHROUGH_HWRM	_IOW(0, 1, 0)
45 #define	IOW_BNXT_MGMT_OPCODE_DCB_OPS		_IOW(0, 2, 0)
46 
47 #define	IO_BNXT_MGMT_OPCODE_GET_DEV_INFO	_IO(0, 0)
48 #define	IO_BNXT_MGMT_OPCODE_PASSTHROUGH_HWRM	_IO(0, 1)
49 #define	IO_BNXT_MGMT_OPCODE_DCB_OPS		_IO(0, 2)
50 
51 #define BNXT_MGMT_MAX_HWRM_REQ_LENGTH		HWRM_MAX_REQ_LEN
52 #define BNXT_MGMT_MAX_HWRM_RESP_LENGTH		(512)
53 
54 struct bnxt_nic_info {
55 #define BNXT_MAX_STR 64
56 	char dev_name[BNXT_MAX_STR];
57 	char driver_version[BNXT_MAX_STR];
58 	char driver_name[BNXT_MAX_STR];
59 	char device_serial_number[64];
60 	uint32_t mtu;
61 	uint8_t mac[ETHER_ADDR_LEN];
62 	uint32_t pci_link_speed;
63 	uint32_t pci_link_width;
64 	uint32_t rsvd[4];
65 } __packed;
66 
67 struct bnxt_pci_info {
68         uint16_t domain_no;
69         uint16_t bus_no;
70         uint16_t device_no;
71         uint16_t function_no;
72         uint16_t vendor_id;
73         uint16_t device_id;
74         uint16_t sub_system_vendor_id;
75         uint16_t sub_system_device_id;
76         uint16_t revision;
77         uint32_t chip_rev_id;
78 	uint32_t rsvd[2];
79 } __packed;
80 
81 struct bnxt_dev_info {
82         struct bnxt_nic_info nic_info;
83         struct bnxt_pci_info pci_info;
84 } __packed;
85 
86 struct dma_info {
87         uint64_t data;
88         uint32_t length;
89         uint16_t offset;
90         uint8_t read_or_write;
91         uint8_t unused;
92 };
93 
94 struct bnxt_mgmt_fw_msg {
95         uint64_t usr_req;
96         uint64_t usr_resp;
97         uint32_t len_req;
98         uint32_t len_resp;
99         uint32_t timeout;
100         uint32_t num_dma_indications;
101         struct dma_info dma[0];
102 };
103 
104 struct bnxt_mgmt_generic_msg {
105         uint8_t key;
106 #define BNXT_LFC_KEY_DOMAIN_NO  1
107         uint8_t reserved[3];
108         uint32_t value;
109 };
110 
111 enum bnxt_mgmt_req_type {
112         BNXT_MGMT_NVM_GET_VAR_REQ = 1,
113         BNXT_MGMT_NVM_SET_VAR_REQ,
114         BNXT_MGMT_NVM_FLUSH_REQ,
115         BNXT_MGMT_GENERIC_HWRM_REQ,
116 };
117 
118 struct bnxt_mgmt_req_hdr {
119         uint32_t ver;
120 	uint32_t domain;
121         uint32_t bus;
122         uint32_t devfn;
123         enum bnxt_mgmt_req_type req_type;
124 };
125 
126 struct bnxt_mgmt_req {
127 	struct bnxt_mgmt_req_hdr hdr;
128 	union {
129 		uint64_t hreq;
130 	} req;
131 };
132 
133 struct bnxt_mgmt_app_tlv {
134 	uint32_t num_app;
135 	struct bnxt_dcb_app app[128];
136 } __attribute__ ((__packed__));
137 
138 struct bnxt_mgmt_dcb {
139 	struct bnxt_mgmt_req_hdr hdr;
140 #define BNXT_MGMT_DCB_GET_ETS	0x1
141 #define BNXT_MGMT_DCB_SET_ETS	0x2
142 #define BNXT_MGMT_DCB_GET_PFC	0x3
143 #define BNXT_MGMT_DCB_SET_PFC	0x4
144 #define BNXT_MGMT_DCB_SET_APP	0x5
145 #define BNXT_MGMT_DCB_DEL_APP	0x6
146 #define BNXT_MGMT_DCB_LIST_APP	0x7
147 #define BNXT_MGMT_DCB_MAX	BNXT_MGMT_DCB_LIST_APP
148 	uint32_t op;
149 	union {
150 		struct bnxt_ieee_ets ets;
151 		struct bnxt_ieee_pfc pfc;
152 		struct bnxt_mgmt_app_tlv app_tlv;
153 	} req;
154 } __attribute__ ((__packed__));
155