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 _IOC(IOC_IN, 0, 0, 0) 44 #define IOW_BNXT_MGMT_OPCODE_PASSTHROUGH_HWRM _IOC(IOC_IN, 0, 1, 0) 45 #define IOW_BNXT_MGMT_OPCODE_DCB_OPS _IOC(IOC_IN, 0, 2, 0) 46 #define IOW_BNXT_MGMT_OPCODE_DRV_DUMP _IOC(IOC_IN, 0, 3, 0) 47 #define IOW_BNXT_MGMT_OPCODE_CRASH_DUMP _IOC(IOC_IN, 0, 4, 0) 48 49 #define IO_BNXT_MGMT_OPCODE_GET_DEV_INFO _IO(0, 0) 50 #define IO_BNXT_MGMT_OPCODE_PASSTHROUGH_HWRM _IO(0, 1) 51 #define IO_BNXT_MGMT_OPCODE_DCB_OPS _IO(0, 2) 52 #define IO_BNXT_MGMT_OPCODE_DRV_DUMP _IO(0, 3) 53 #define IO_BNXT_MGMT_OPCODE_CRASH_DUMP _IO(0, 4) 54 55 #define BNXT_MGMT_MAX_HWRM_REQ_LENGTH HWRM_MAX_REQ_LEN 56 #define BNXT_MGMT_MAX_HWRM_RESP_LENGTH (512) 57 58 struct bnxt_nic_info { 59 #define BNXT_MAX_STR 64 60 char dev_name[BNXT_MAX_STR]; 61 char driver_version[BNXT_MAX_STR]; 62 char driver_name[BNXT_MAX_STR]; 63 char device_serial_number[64]; 64 uint32_t mtu; 65 uint8_t mac[ETHER_ADDR_LEN]; 66 uint32_t pci_link_speed; 67 uint32_t pci_link_width; 68 uint32_t rsvd[4]; 69 } __packed; 70 71 struct bnxt_pci_info { 72 uint16_t domain_no; 73 uint16_t bus_no; 74 uint16_t device_no; 75 uint16_t function_no; 76 uint16_t vendor_id; 77 uint16_t device_id; 78 uint16_t sub_system_vendor_id; 79 uint16_t sub_system_device_id; 80 uint16_t revision; 81 uint32_t chip_rev_id; 82 uint32_t rsvd[2]; 83 } __packed; 84 85 struct bnxt_dev_info { 86 struct bnxt_nic_info nic_info; 87 struct bnxt_pci_info pci_info; 88 } __packed; 89 90 struct dma_info { 91 uint64_t data; 92 uint32_t length; 93 uint16_t offset; 94 uint8_t read_or_write; 95 uint8_t unused; 96 }; 97 98 struct bnxt_mgmt_fw_msg { 99 uint64_t usr_req; 100 uint64_t usr_resp; 101 uint32_t len_req; 102 uint32_t len_resp; 103 uint32_t timeout; 104 uint32_t num_dma_indications; 105 struct dma_info dma[0]; 106 }; 107 108 struct bnxt_mgmt_generic_msg { 109 uint8_t key; 110 #define BNXT_LFC_KEY_DOMAIN_NO 1 111 uint8_t reserved[3]; 112 uint32_t value; 113 }; 114 115 enum bnxt_mgmt_req_type { 116 BNXT_MGMT_NVM_GET_VAR_REQ = 1, 117 BNXT_MGMT_NVM_SET_VAR_REQ, 118 BNXT_MGMT_NVM_FLUSH_REQ, 119 BNXT_MGMT_GENERIC_HWRM_REQ, 120 }; 121 122 struct bnxt_mgmt_req_hdr { 123 uint32_t ver; 124 uint32_t domain; 125 uint32_t bus; 126 uint32_t devfn; 127 enum bnxt_mgmt_req_type req_type; 128 }; 129 130 struct bnxt_mgmt_req { 131 struct bnxt_mgmt_req_hdr hdr; 132 union { 133 uint64_t hreq; 134 } req; 135 }; 136 137 struct bnxt_mgmt_app_tlv { 138 uint32_t num_app; 139 struct bnxt_dcb_app app[128]; 140 } __attribute__ ((__packed__)); 141 142 struct bnxt_mgmt_dcb { 143 struct bnxt_mgmt_req_hdr hdr; 144 #define BNXT_MGMT_DCB_GET_ETS 0x1 145 #define BNXT_MGMT_DCB_SET_ETS 0x2 146 #define BNXT_MGMT_DCB_GET_PFC 0x3 147 #define BNXT_MGMT_DCB_SET_PFC 0x4 148 #define BNXT_MGMT_DCB_SET_APP 0x5 149 #define BNXT_MGMT_DCB_DEL_APP 0x6 150 #define BNXT_MGMT_DCB_LIST_APP 0x7 151 #define BNXT_MGMT_DCB_MAX BNXT_MGMT_DCB_LIST_APP 152 uint32_t op; 153 union { 154 struct bnxt_ieee_ets ets; 155 struct bnxt_ieee_pfc pfc; 156 struct bnxt_mgmt_app_tlv app_tlv; 157 } req; 158 } __attribute__ ((__packed__)); 159 160 struct bnxt_mgmt_drv_dump { 161 struct bnxt_mgmt_req_hdr hdr; 162 #define BNXT_MGMT_GET_DRV_DUMP_SIZE 0x1 163 #define BNXT_MGMT_GET_DRV_DUMP 0x2 164 #define BNXT_MGMT_DRV_DUMP_MAX BNXT_MGMT_GET_DRV_DUMP 165 uint32_t op; 166 void *buf; 167 uint32_t buf_size; 168 } __attribute__ ((__packed__)); 169 170 struct bnxt_mgmt_crash_dump { 171 struct bnxt_mgmt_req_hdr hdr; 172 #define BNXT_MGMT_SET_DUMP_FLAG 0x1 173 #define BNXT_MGMT_GET_DUMP_FLAG 0x2 174 #define BNXT_MGMT_GET_DUMP_DATA 0x3 175 #define BNXT_MGMT_CRASH_DUMP_MAX BNXT_MGMT_GET_DUMP_DATA 176 uint32_t op; 177 union { 178 struct { 179 uint32_t dump_flag; 180 } set_flag; 181 struct { 182 uint32_t dump_flag; 183 uint32_t dump_len; 184 uint32_t version; 185 } get_flag; 186 struct { 187 uint32_t dump_flag; 188 uint32_t dump_len; 189 void *dump_buffer; 190 size_t buffer_size; 191 } get_data; 192 } req; 193 } __attribute__ ((__packed__)); 194 195 struct bnxt_driver_segment_record { 196 uint32_t max_entries; 197 uint32_t entry_size; 198 uint32_t offset; 199 uint8_t wrapped:1; 200 uint8_t reserved[3]; 201 }; 202 203 #define DRV_COREDUMP_COMP_ID 0xD 204 #define DRV_SRT_TRACE_SEG_ID 1 205 #define DRV_SRT2_TRACE_SEG_ID 2 206 #define DRV_CRT_TRACE_SEG_ID 3 207 #define DRV_CRT2_TRACE_SEG_ID 4 208 #define DRV_RIGP0_TRACE_SEG_ID 5 209 #define DRV_LOG_HWRM_L2_TRACE_SEG_ID 6 210 #define DRV_LOG_HWRM_ROCE_TRACE_SEG_ID 7 211 212 void bnxt_get_ctx_coredump(struct bnxt_softc *, void *); 213