Bharat Gooty | b48ee74 | 2021-11-08 14:46:10 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019-2021 Broadcom. |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | |
| 8 | #include <asm/io.h> |
| 9 | #include <dm.h> |
| 10 | #include <linux/delay.h> |
| 11 | #include <memalign.h> |
| 12 | #include <net.h> |
| 13 | |
| 14 | #include "bnxt.h" |
| 15 | #include "bnxt_dbg.h" |
| 16 | |
| 17 | #define bnxt_down_chip(bp) bnxt_hwrm_run(down_chip, bp, 0) |
| 18 | #define bnxt_bring_chip(bp) bnxt_hwrm_run(bring_chip, bp, 1) |
| 19 | |
| 20 | /* Broadcom ethernet driver PCI APIs. */ |
| 21 | static void bnxt_bring_pci(struct bnxt *bp) |
| 22 | { |
| 23 | u16 cmd_reg = 0; |
| 24 | |
| 25 | dm_pci_read_config16(bp->pdev, PCI_VENDOR_ID, &bp->vendor_id); |
| 26 | dm_pci_read_config16(bp->pdev, PCI_DEVICE_ID, &bp->device_id); |
| 27 | dm_pci_read_config16(bp->pdev, PCI_SUBSYSTEM_VENDOR_ID, &bp->subsystem_vendor); |
| 28 | dm_pci_read_config16(bp->pdev, PCI_SUBSYSTEM_ID, &bp->subsystem_device); |
| 29 | dm_pci_read_config16(bp->pdev, PCI_COMMAND, &bp->cmd_reg); |
| 30 | dm_pci_read_config8(bp->pdev, PCI_INTERRUPT_LINE, &bp->irq); |
| 31 | bp->bar0 = dm_pci_map_bar(bp->pdev, PCI_BASE_ADDRESS_0, PCI_REGION_MEM); |
| 32 | bp->bar1 = dm_pci_map_bar(bp->pdev, PCI_BASE_ADDRESS_2, PCI_REGION_MEM); |
| 33 | bp->bar2 = dm_pci_map_bar(bp->pdev, PCI_BASE_ADDRESS_4, PCI_REGION_MEM); |
| 34 | cmd_reg = bp->cmd_reg | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
| 35 | cmd_reg |= PCI_COMMAND_INTX_DISABLE; /* disable intr */ |
| 36 | dm_pci_write_config16(bp->pdev, PCI_COMMAND, cmd_reg); |
| 37 | dm_pci_read_config16(bp->pdev, PCI_COMMAND, &cmd_reg); |
| 38 | dbg_pci(bp, __func__, cmd_reg); |
| 39 | } |
| 40 | |
| 41 | int bnxt_free_rx_iob(struct bnxt *bp) |
| 42 | { |
| 43 | unsigned int i; |
| 44 | |
| 45 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_RX_IOB))) |
| 46 | return STATUS_SUCCESS; |
| 47 | |
| 48 | for (i = 0; i < bp->rx.buf_cnt; i++) { |
| 49 | if (bp->rx.iob[i]) { |
| 50 | free(bp->rx.iob[i]); |
| 51 | bp->rx.iob[i] = NULL; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | FLAG_RESET(bp->flag_hwrm, VALID_RX_IOB); |
| 56 | |
| 57 | return STATUS_SUCCESS; |
| 58 | } |
| 59 | |
| 60 | static void set_rx_desc(u8 *buf, void *iob, u16 cons_id, u32 iob_idx) |
| 61 | { |
| 62 | struct rx_prod_pkt_bd *desc; |
| 63 | u16 off = cons_id * sizeof(struct rx_prod_pkt_bd); |
| 64 | |
| 65 | desc = (struct rx_prod_pkt_bd *)&buf[off]; |
| 66 | desc->flags_type = RX_PROD_PKT_BD_TYPE_RX_PROD_PKT; |
| 67 | desc->len = MAX_ETHERNET_PACKET_BUFFER_SIZE; |
| 68 | desc->opaque = iob_idx; |
| 69 | desc->dma.addr = virt_to_bus(iob); |
| 70 | } |
| 71 | |
| 72 | static int bnxt_alloc_rx_iob(struct bnxt *bp, u16 cons_id, u16 iob_idx) |
| 73 | { |
| 74 | void *iob; |
| 75 | |
| 76 | iob = memalign(BNXT_DMA_ALIGNMENT, RX_STD_DMA_ALIGNED); |
| 77 | if (!iob) |
| 78 | return -ENOMEM; |
| 79 | |
| 80 | dbg_rx_iob(iob, iob_idx, cons_id); |
| 81 | set_rx_desc((u8 *)bp->rx.bd_virt, iob, cons_id, (u32)iob_idx); |
| 82 | bp->rx.iob[iob_idx] = iob; |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | void bnxt_mm_init(struct bnxt *bp, const char *func) |
| 88 | { |
| 89 | memset(bp->hwrm_addr_req, 0, REQ_BUFFER_SIZE); |
| 90 | memset(bp->hwrm_addr_resp, 0, RESP_BUFFER_SIZE); |
| 91 | memset(bp->cq.bd_virt, 0, CQ_RING_DMA_BUFFER_SIZE); |
| 92 | memset(bp->tx.bd_virt, 0, TX_RING_DMA_BUFFER_SIZE); |
| 93 | memset(bp->rx.bd_virt, 0, RX_RING_DMA_BUFFER_SIZE); |
| 94 | |
| 95 | bp->data_addr_mapping = virt_to_bus(bp->hwrm_addr_data); |
| 96 | bp->req_addr_mapping = virt_to_bus(bp->hwrm_addr_req); |
| 97 | bp->resp_addr_mapping = virt_to_bus(bp->hwrm_addr_resp); |
| 98 | bp->wait_link_timeout = LINK_DEFAULT_TIMEOUT; |
| 99 | bp->link_status = STATUS_LINK_DOWN; |
| 100 | bp->media_change = 1; |
| 101 | bp->mtu = MAX_ETHERNET_PACKET_BUFFER_SIZE; |
| 102 | bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN; |
| 103 | bp->rx.buf_cnt = NUM_RX_BUFFERS; |
| 104 | bp->rx.ring_cnt = MAX_RX_DESC_CNT; |
| 105 | bp->tx.ring_cnt = MAX_TX_DESC_CNT; |
| 106 | bp->cq.ring_cnt = MAX_CQ_DESC_CNT; |
| 107 | bp->cq.completion_bit = 0x1; |
| 108 | bp->link_set = LINK_SPEED_DRV_100G; |
| 109 | dbg_mem(bp, func); |
| 110 | } |
| 111 | |
| 112 | void bnxt_free_mem(struct bnxt *bp) |
| 113 | { |
| 114 | if (bp->cq.bd_virt) { |
| 115 | free(bp->cq.bd_virt); |
| 116 | bp->cq.bd_virt = NULL; |
| 117 | } |
| 118 | |
| 119 | if (bp->rx.bd_virt) { |
| 120 | free(bp->rx.bd_virt); |
| 121 | bp->rx.bd_virt = NULL; |
| 122 | } |
| 123 | |
| 124 | if (bp->tx.bd_virt) { |
| 125 | free(bp->tx.bd_virt); |
| 126 | bp->tx.bd_virt = NULL; |
| 127 | } |
| 128 | |
| 129 | if (bp->hwrm_addr_resp) { |
| 130 | free(bp->hwrm_addr_resp); |
| 131 | bp->resp_addr_mapping = 0; |
| 132 | bp->hwrm_addr_resp = NULL; |
| 133 | } |
| 134 | |
| 135 | if (bp->hwrm_addr_req) { |
| 136 | free(bp->hwrm_addr_req); |
| 137 | bp->req_addr_mapping = 0; |
| 138 | bp->hwrm_addr_req = NULL; |
| 139 | } |
| 140 | |
| 141 | if (bp->hwrm_addr_data) { |
| 142 | free(bp->hwrm_addr_data); |
| 143 | bp->data_addr_mapping = 0; |
| 144 | bp->hwrm_addr_data = NULL; |
| 145 | } |
| 146 | |
| 147 | dbg_mem_free_done(__func__); |
| 148 | } |
| 149 | |
| 150 | int bnxt_alloc_mem(struct bnxt *bp) |
| 151 | { |
| 152 | bp->hwrm_addr_data = memalign(BNXT_DMA_ALIGNMENT, DMA_BUF_SIZE_ALIGNED); |
| 153 | bp->hwrm_addr_req = memalign(BNXT_DMA_ALIGNMENT, REQ_BUF_SIZE_ALIGNED); |
| 154 | bp->hwrm_addr_resp = MEM_HWRM_RESP; |
| 155 | |
| 156 | memset(&bp->tx, 0, sizeof(struct lm_tx_info_t)); |
| 157 | memset(&bp->rx, 0, sizeof(struct lm_rx_info_t)); |
| 158 | memset(&bp->cq, 0, sizeof(struct lm_cmp_info_t)); |
| 159 | |
| 160 | bp->tx.bd_virt = memalign(BNXT_DMA_ALIGNMENT, TX_RING_DMA_BUFFER_SIZE); |
| 161 | bp->rx.bd_virt = memalign(BNXT_DMA_ALIGNMENT, RX_RING_DMA_BUFFER_SIZE); |
| 162 | bp->cq.bd_virt = memalign(BNXT_DMA_ALIGNMENT, CQ_RING_DMA_BUFFER_SIZE); |
| 163 | |
| 164 | if (bp->hwrm_addr_req && |
| 165 | bp->hwrm_addr_resp && |
| 166 | bp->hwrm_addr_data && |
| 167 | bp->tx.bd_virt && |
| 168 | bp->rx.bd_virt && |
| 169 | bp->cq.bd_virt) { |
| 170 | bnxt_mm_init(bp, __func__); |
| 171 | return STATUS_SUCCESS; |
| 172 | } |
| 173 | |
| 174 | dbg_mem_alloc_fail(__func__); |
| 175 | bnxt_free_mem(bp); |
| 176 | |
| 177 | return -ENOMEM; |
| 178 | } |
| 179 | |
| 180 | static void hwrm_init(struct bnxt *bp, struct input *req, u16 cmd, u16 len) |
| 181 | { |
| 182 | memset(req, 0, len); |
| 183 | req->req_type = cmd; |
| 184 | req->cmpl_ring = (u16)HWRM_NA_SIGNATURE; |
| 185 | req->target_id = (u16)HWRM_NA_SIGNATURE; |
| 186 | req->resp_addr = bp->resp_addr_mapping; |
| 187 | req->seq_id = bp->seq_id++; |
| 188 | } |
| 189 | |
| 190 | static void hwrm_write_req(struct bnxt *bp, void *req, u32 cnt) |
| 191 | { |
| 192 | u32 i = 0; |
| 193 | |
| 194 | for (i = 0; i < cnt; i++) |
| 195 | writel(((u32 *)req)[i], bp->bar0 + GRC_COM_CHAN_BASE + (i * 4)); |
| 196 | |
| 197 | writel(0x1, (bp->bar0 + GRC_COM_CHAN_BASE + GRC_COM_CHAN_TRIG)); |
| 198 | } |
| 199 | |
| 200 | static void short_hwrm_cmd_req(struct bnxt *bp, u16 len) |
| 201 | { |
| 202 | struct hwrm_short_input sreq; |
| 203 | |
| 204 | memset(&sreq, 0, sizeof(struct hwrm_short_input)); |
| 205 | sreq.req_type = (u16)((struct input *)bp->hwrm_addr_req)->req_type; |
| 206 | sreq.signature = SHORT_REQ_SIGNATURE_SHORT_CMD; |
| 207 | sreq.size = len; |
| 208 | sreq.req_addr = bp->req_addr_mapping; |
| 209 | dbg_short_cmd((u8 *)&sreq, __func__, sizeof(struct hwrm_short_input)); |
| 210 | hwrm_write_req(bp, &sreq, sizeof(struct hwrm_short_input) / 4); |
| 211 | } |
| 212 | |
| 213 | static int wait_resp(struct bnxt *bp, u32 tmo, u16 len, const char *func) |
| 214 | { |
| 215 | struct input *req = (struct input *)bp->hwrm_addr_req; |
| 216 | struct output *resp = (struct output *)bp->hwrm_addr_resp; |
| 217 | u8 *ptr = (u8 *)resp; |
| 218 | u32 idx; |
| 219 | u32 wait_cnt = HWRM_CMD_DEFAULT_MULTIPLAYER((u32)tmo); |
| 220 | u16 resp_len = 0; |
| 221 | u16 ret = STATUS_TIMEOUT; |
| 222 | |
| 223 | if (len > bp->hwrm_max_req_len) |
| 224 | short_hwrm_cmd_req(bp, len); |
| 225 | else |
| 226 | hwrm_write_req(bp, req, (u32)(len / 4)); |
| 227 | |
| 228 | for (idx = 0; idx < wait_cnt; idx++) { |
| 229 | resp_len = resp->resp_len; |
| 230 | if (resp->seq_id == req->seq_id && resp->req_type == req->req_type && |
| 231 | ptr[resp_len - 1] == 1) { |
| 232 | bp->last_resp_code = resp->error_code; |
| 233 | ret = resp->error_code; |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | udelay(HWRM_CMD_POLL_WAIT_TIME); |
| 238 | } |
| 239 | |
| 240 | dbg_hw_cmd(bp, func, len, resp_len, tmo, ret); |
| 241 | |
| 242 | return (int)ret; |
| 243 | } |
| 244 | |
| 245 | static void bnxt_db_cq(struct bnxt *bp) |
| 246 | { |
| 247 | writel(CQ_DOORBELL_KEY_IDX(bp->cq.cons_idx), bp->bar1); |
| 248 | } |
| 249 | |
| 250 | static void bnxt_db_rx(struct bnxt *bp, u32 idx) |
| 251 | { |
| 252 | writel(RX_DOORBELL_KEY_RX | idx, bp->bar1); |
| 253 | } |
| 254 | |
| 255 | static void bnxt_db_tx(struct bnxt *bp, u32 idx) |
| 256 | { |
| 257 | writel((u32)(TX_DOORBELL_KEY_TX | idx), bp->bar1); |
| 258 | } |
| 259 | |
| 260 | int iob_pad(void *packet, int length) |
| 261 | { |
| 262 | if (length >= ETH_ZLEN) |
| 263 | return length; |
| 264 | |
| 265 | memset(((u8 *)packet + length), 0x00, (ETH_ZLEN - length)); |
| 266 | |
| 267 | return ETH_ZLEN; |
| 268 | } |
| 269 | |
| 270 | static inline u32 bnxt_tx_avail(struct bnxt *bp) |
| 271 | { |
| 272 | barrier(); |
| 273 | |
| 274 | return TX_AVAIL(bp->tx.ring_cnt) - |
| 275 | ((bp->tx.prod_id - bp->tx.cons_id) & |
| 276 | (bp->tx.ring_cnt - 1)); |
| 277 | } |
| 278 | |
| 279 | void set_txq(struct bnxt *bp, int entry, dma_addr_t mapping, int len) |
| 280 | { |
| 281 | struct tx_bd_short *prod_bd; |
| 282 | |
| 283 | prod_bd = (struct tx_bd_short *)BD_NOW(bp->tx.bd_virt, |
| 284 | entry, |
| 285 | sizeof(struct tx_bd_short)); |
| 286 | if (len < 512) |
| 287 | prod_bd->flags_type = TX_BD_SHORT_FLAGS_LHINT_LT512; |
| 288 | else if (len < 1024) |
| 289 | prod_bd->flags_type = TX_BD_SHORT_FLAGS_LHINT_LT1K; |
| 290 | else if (len < 2048) |
| 291 | prod_bd->flags_type = TX_BD_SHORT_FLAGS_LHINT_LT2K; |
| 292 | else |
| 293 | prod_bd->flags_type = TX_BD_SHORT_FLAGS_LHINT_GTE2K; |
| 294 | |
| 295 | prod_bd->flags_type |= TX_BD_FLAGS; |
| 296 | prod_bd->dma.addr = mapping; |
| 297 | prod_bd->len = len; |
| 298 | prod_bd->opaque = (u32)entry; |
| 299 | dump_tx_bd(prod_bd, (u16)(sizeof(struct tx_bd_short))); |
| 300 | } |
| 301 | |
| 302 | static void bnxt_tx_complete(struct bnxt *bp) |
| 303 | { |
| 304 | bp->tx.cons_id = NEXT_IDX(bp->tx.cons_id, bp->tx.ring_cnt); |
| 305 | bp->tx.cnt++; |
| 306 | dump_tx_stat(bp); |
| 307 | } |
| 308 | |
| 309 | int post_rx_buffers(struct bnxt *bp) |
| 310 | { |
| 311 | u16 cons_id = (bp->rx.cons_idx % bp->rx.ring_cnt); |
| 312 | u16 iob_idx; |
| 313 | |
| 314 | while (bp->rx.iob_cnt < bp->rx.buf_cnt) { |
| 315 | iob_idx = (cons_id % bp->rx.buf_cnt); |
| 316 | if (!bp->rx.iob[iob_idx]) { |
| 317 | if (bnxt_alloc_rx_iob(bp, cons_id, iob_idx) < 0) { |
| 318 | dbg_rx_alloc_iob_fail(iob_idx, cons_id); |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | cons_id = NEXT_IDX(cons_id, bp->rx.ring_cnt); |
| 324 | bp->rx.iob_cnt++; |
| 325 | } |
| 326 | |
| 327 | if (cons_id != bp->rx.cons_idx) { |
| 328 | dbg_rx_cid(bp->rx.cons_idx, cons_id); |
| 329 | bp->rx.cons_idx = cons_id; |
| 330 | bnxt_db_rx(bp, (u32)cons_id); |
| 331 | } |
| 332 | |
| 333 | FLAG_SET(bp->flag_hwrm, VALID_RX_IOB); |
| 334 | |
| 335 | return STATUS_SUCCESS; |
| 336 | } |
| 337 | |
| 338 | u8 bnxt_rx_drop(struct bnxt *bp, u8 *rx_buf, struct rx_pkt_cmpl_hi *rx_cmp_hi) |
| 339 | { |
| 340 | u8 chksum_err = 0; |
| 341 | u8 i; |
| 342 | u16 error_flags; |
| 343 | |
| 344 | error_flags = (rx_cmp_hi->errors_v2 >> |
| 345 | RX_PKT_CMPL_ERRORS_BUFFER_ERROR_SFT); |
| 346 | if (rx_cmp_hi->errors_v2 == 0x20 || rx_cmp_hi->errors_v2 == 0x21) |
| 347 | chksum_err = 1; |
| 348 | |
| 349 | if (error_flags && !chksum_err) { |
| 350 | bp->rx.err++; |
| 351 | return 1; |
| 352 | } |
| 353 | |
| 354 | for (i = 0; i < 6; i++) { |
| 355 | if (rx_buf[6 + i] != bp->mac_set[i]) |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | if (i == 6) { |
| 360 | bp->rx.dropped++; |
| 361 | return 2; /* Drop the loopback packets */ |
| 362 | } |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static void bnxt_adv_cq_index(struct bnxt *bp, u16 count) |
| 368 | { |
| 369 | u16 cons_idx = bp->cq.cons_idx + count; |
| 370 | |
| 371 | if (cons_idx >= MAX_CQ_DESC_CNT) { |
| 372 | /* Toggle completion bit when the ring wraps. */ |
| 373 | bp->cq.completion_bit ^= 1; |
| 374 | cons_idx = cons_idx - MAX_CQ_DESC_CNT; |
| 375 | } |
| 376 | |
| 377 | bp->cq.cons_idx = cons_idx; |
| 378 | } |
| 379 | |
| 380 | void bnxt_adv_rx_index(struct bnxt *bp, u8 *iob, u32 iob_idx) |
| 381 | { |
| 382 | u16 cons_id = (bp->rx.cons_idx % bp->rx.ring_cnt); |
| 383 | |
| 384 | set_rx_desc((u8 *)bp->rx.bd_virt, (void *)iob, cons_id, iob_idx); |
| 385 | cons_id = NEXT_IDX(cons_id, bp->rx.ring_cnt); |
| 386 | if (cons_id != bp->rx.cons_idx) { |
| 387 | dbg_rx_cid(bp->rx.cons_idx, cons_id); |
| 388 | bp->rx.cons_idx = cons_id; |
| 389 | bnxt_db_rx(bp, (u32)cons_id); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | void rx_process(struct bnxt *bp, struct rx_pkt_cmpl *rx_cmp, |
| 394 | struct rx_pkt_cmpl_hi *rx_cmp_hi) |
| 395 | { |
| 396 | u32 desc_idx = rx_cmp->opaque; |
| 397 | u8 *iob = bp->rx.iob[desc_idx]; |
| 398 | |
| 399 | dump_rx_bd(rx_cmp, rx_cmp_hi, desc_idx); |
| 400 | bp->rx.iob_len = rx_cmp->len; |
| 401 | bp->rx.iob_rx = iob; |
| 402 | if (bnxt_rx_drop(bp, iob, rx_cmp_hi)) |
| 403 | bp->rx.iob_recv = PKT_DROPPED; |
| 404 | else |
| 405 | bp->rx.iob_recv = PKT_RECEIVED; |
| 406 | |
| 407 | bp->rx.rx_cnt++; |
| 408 | |
| 409 | dbg_rxp(bp->rx.iob_rx, bp->rx.iob_len, bp->rx.iob_recv); |
| 410 | bnxt_adv_rx_index(bp, iob, desc_idx); |
| 411 | bnxt_adv_cq_index(bp, 2); /* Rx completion is 2 entries. */ |
| 412 | } |
| 413 | |
| 414 | static int bnxt_rx_complete(struct bnxt *bp, struct rx_pkt_cmpl *rx_cmp) |
| 415 | { |
| 416 | struct rx_pkt_cmpl_hi *rx_cmp_hi; |
| 417 | u8 completion_bit = bp->cq.completion_bit; |
| 418 | |
| 419 | if (bp->cq.cons_idx == (bp->cq.ring_cnt - 1)) { |
| 420 | rx_cmp_hi = (struct rx_pkt_cmpl_hi *)bp->cq.bd_virt; |
| 421 | completion_bit ^= 0x1; /* Ring has wrapped. */ |
| 422 | } else { |
| 423 | rx_cmp_hi = (struct rx_pkt_cmpl_hi *)(rx_cmp + 1); |
| 424 | } |
| 425 | |
| 426 | if (!((rx_cmp_hi->errors_v2 & RX_PKT_CMPL_V2) ^ completion_bit)) |
| 427 | rx_process(bp, rx_cmp, rx_cmp_hi); |
| 428 | |
| 429 | return NO_MORE_CQ_BD_TO_SERVICE; |
| 430 | } |
| 431 | |
| 432 | static int bnxt_hwrm_ver_get(struct bnxt *bp) |
| 433 | { |
| 434 | u16 cmd_len = (u16)sizeof(struct hwrm_ver_get_input); |
| 435 | struct hwrm_ver_get_input *req; |
| 436 | struct hwrm_ver_get_output *resp; |
| 437 | int rc; |
| 438 | |
| 439 | req = (struct hwrm_ver_get_input *)bp->hwrm_addr_req; |
| 440 | resp = (struct hwrm_ver_get_output *)bp->hwrm_addr_resp; |
| 441 | hwrm_init(bp, (void *)req, (u16)HWRM_VER_GET, cmd_len); |
| 442 | req->hwrm_intf_maj = HWRM_VERSION_MAJOR; |
| 443 | req->hwrm_intf_min = HWRM_VERSION_MINOR; |
| 444 | req->hwrm_intf_upd = HWRM_VERSION_UPDATE; |
| 445 | rc = wait_resp(bp, HWRM_CMD_DEFAULT_TIMEOUT, cmd_len, __func__); |
| 446 | if (rc) |
| 447 | return STATUS_FAILURE; |
| 448 | |
| 449 | bp->hwrm_spec_code = |
| 450 | resp->hwrm_intf_maj_8b << 16 | |
| 451 | resp->hwrm_intf_min_8b << 8 | |
| 452 | resp->hwrm_intf_upd_8b; |
| 453 | bp->hwrm_cmd_timeout = (u32)resp->def_req_timeout; |
| 454 | if (!bp->hwrm_cmd_timeout) |
| 455 | bp->hwrm_cmd_timeout = (u32)HWRM_CMD_DEFAULT_TIMEOUT; |
| 456 | |
| 457 | if (resp->hwrm_intf_maj_8b >= 1) |
| 458 | bp->hwrm_max_req_len = resp->max_req_win_len; |
| 459 | |
| 460 | bp->chip_id = |
| 461 | resp->chip_rev << 24 | |
| 462 | resp->chip_metal << 16 | |
| 463 | resp->chip_bond_id << 8 | |
| 464 | resp->chip_platform_type; |
| 465 | bp->chip_num = resp->chip_num; |
| 466 | if ((resp->dev_caps_cfg & SHORT_CMD_SUPPORTED) && |
| 467 | (resp->dev_caps_cfg & SHORT_CMD_REQUIRED)) |
| 468 | FLAG_SET(bp->flags, BNXT_FLAG_HWRM_SHORT_CMD_SUPP); |
| 469 | |
| 470 | bp->hwrm_max_ext_req_len = resp->max_ext_req_len; |
| 471 | bp->fw_maj = resp->hwrm_fw_maj_8b; |
| 472 | bp->fw_min = resp->hwrm_fw_min_8b; |
| 473 | bp->fw_bld = resp->hwrm_fw_bld_8b; |
| 474 | bp->fw_rsvd = resp->hwrm_fw_rsvd_8b; |
| 475 | print_fw_ver(resp, bp->hwrm_cmd_timeout); |
| 476 | |
| 477 | return STATUS_SUCCESS; |
| 478 | } |
| 479 | |
| 480 | /* Broadcom ethernet driver Function HW cmds APIs. */ |
| 481 | static int bnxt_hwrm_func_resource_qcaps(struct bnxt *bp) |
| 482 | { |
| 483 | u16 cmd_len = (u16)sizeof(struct hwrm_func_resource_qcaps_input); |
| 484 | struct hwrm_func_resource_qcaps_input *req; |
| 485 | struct hwrm_func_resource_qcaps_output *resp; |
| 486 | int rc; |
| 487 | |
| 488 | req = (struct hwrm_func_resource_qcaps_input *)bp->hwrm_addr_req; |
| 489 | resp = (struct hwrm_func_resource_qcaps_output *)bp->hwrm_addr_resp; |
| 490 | hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_RESOURCE_QCAPS, cmd_len); |
| 491 | req->fid = (u16)HWRM_NA_SIGNATURE; |
| 492 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 493 | if (rc != STATUS_SUCCESS) |
| 494 | return STATUS_SUCCESS; |
| 495 | |
| 496 | FLAG_SET(bp->flags, BNXT_FLAG_RESOURCE_QCAPS_SUPPORT); |
| 497 | /* VFs */ |
| 498 | bp->max_vfs = resp->max_vfs; |
| 499 | bp->vf_res_strategy = resp->vf_reservation_strategy; |
| 500 | /* vNICs */ |
| 501 | bp->min_vnics = resp->min_vnics; |
| 502 | bp->max_vnics = resp->max_vnics; |
| 503 | /* MSI-X */ |
| 504 | bp->max_msix = resp->max_msix; |
| 505 | /* Ring Groups */ |
| 506 | bp->min_hw_ring_grps = resp->min_hw_ring_grps; |
| 507 | bp->max_hw_ring_grps = resp->max_hw_ring_grps; |
| 508 | /* TX Rings */ |
| 509 | bp->min_tx_rings = resp->min_tx_rings; |
| 510 | bp->max_tx_rings = resp->max_tx_rings; |
| 511 | /* RX Rings */ |
| 512 | bp->min_rx_rings = resp->min_rx_rings; |
| 513 | bp->max_rx_rings = resp->max_rx_rings; |
| 514 | /* Completion Rings */ |
| 515 | bp->min_cp_rings = resp->min_cmpl_rings; |
| 516 | bp->max_cp_rings = resp->max_cmpl_rings; |
| 517 | /* RSS Contexts */ |
| 518 | bp->min_rsscos_ctxs = resp->min_rsscos_ctx; |
| 519 | bp->max_rsscos_ctxs = resp->max_rsscos_ctx; |
| 520 | /* L2 Contexts */ |
| 521 | bp->min_l2_ctxs = resp->min_l2_ctxs; |
| 522 | bp->max_l2_ctxs = resp->max_l2_ctxs; |
| 523 | /* Statistic Contexts */ |
| 524 | bp->min_stat_ctxs = resp->min_stat_ctx; |
| 525 | bp->max_stat_ctxs = resp->max_stat_ctx; |
| 526 | dbg_func_resource_qcaps(bp); |
| 527 | |
| 528 | return STATUS_SUCCESS; |
| 529 | } |
| 530 | |
| 531 | static u32 set_ring_info(struct bnxt *bp) |
| 532 | { |
| 533 | u32 enables = 0; |
| 534 | |
| 535 | bp->num_cmpl_rings = DEFAULT_NUMBER_OF_CMPL_RINGS; |
| 536 | bp->num_tx_rings = DEFAULT_NUMBER_OF_TX_RINGS; |
| 537 | bp->num_rx_rings = DEFAULT_NUMBER_OF_RX_RINGS; |
| 538 | bp->num_hw_ring_grps = DEFAULT_NUMBER_OF_RING_GRPS; |
| 539 | bp->num_stat_ctxs = DEFAULT_NUMBER_OF_STAT_CTXS; |
| 540 | if (bp->min_cp_rings <= DEFAULT_NUMBER_OF_CMPL_RINGS) |
| 541 | bp->num_cmpl_rings = bp->min_cp_rings; |
| 542 | |
| 543 | if (bp->min_tx_rings <= DEFAULT_NUMBER_OF_TX_RINGS) |
| 544 | bp->num_tx_rings = bp->min_tx_rings; |
| 545 | |
| 546 | if (bp->min_rx_rings <= DEFAULT_NUMBER_OF_RX_RINGS) |
| 547 | bp->num_rx_rings = bp->min_rx_rings; |
| 548 | |
| 549 | if (bp->min_hw_ring_grps <= DEFAULT_NUMBER_OF_RING_GRPS) |
| 550 | bp->num_hw_ring_grps = bp->min_hw_ring_grps; |
| 551 | |
| 552 | if (bp->min_stat_ctxs <= DEFAULT_NUMBER_OF_STAT_CTXS) |
| 553 | bp->num_stat_ctxs = bp->min_stat_ctxs; |
| 554 | |
| 555 | print_num_rings(bp); |
| 556 | enables = (FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS | |
| 557 | FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS | |
| 558 | FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS | |
| 559 | FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS | |
| 560 | FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS); |
| 561 | |
| 562 | return enables; |
| 563 | } |
| 564 | |
| 565 | static void bnxt_hwrm_assign_resources(struct bnxt *bp) |
| 566 | { |
| 567 | struct hwrm_func_cfg_input *req; |
| 568 | u32 enables = 0; |
| 569 | |
| 570 | if (FLAG_TEST(bp->flags, BNXT_FLAG_RESOURCE_QCAPS_SUPPORT)) |
| 571 | enables = set_ring_info(bp); |
| 572 | |
| 573 | req = (struct hwrm_func_cfg_input *)bp->hwrm_addr_req; |
| 574 | req->num_cmpl_rings = bp->num_cmpl_rings; |
| 575 | req->num_tx_rings = bp->num_tx_rings; |
| 576 | req->num_rx_rings = bp->num_rx_rings; |
| 577 | req->num_stat_ctxs = bp->num_stat_ctxs; |
| 578 | req->num_hw_ring_grps = bp->num_hw_ring_grps; |
| 579 | req->enables = enables; |
| 580 | } |
| 581 | |
| 582 | int bnxt_hwrm_nvm_flush(struct bnxt *bp) |
| 583 | { |
| 584 | u16 cmd_len = (u16)sizeof(struct hwrm_nvm_flush_input); |
| 585 | struct hwrm_nvm_flush_input *req; |
| 586 | int rc; |
| 587 | |
| 588 | req = (struct hwrm_nvm_flush_input *)bp->hwrm_addr_req; |
| 589 | |
| 590 | hwrm_init(bp, (void *)req, (u16)HWRM_NVM_FLUSH, cmd_len); |
| 591 | |
| 592 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 593 | if (rc) |
| 594 | return STATUS_FAILURE; |
| 595 | |
| 596 | return STATUS_SUCCESS; |
| 597 | } |
| 598 | |
| 599 | static int bnxt_hwrm_func_qcaps_req(struct bnxt *bp) |
| 600 | { |
| 601 | u16 cmd_len = (u16)sizeof(struct hwrm_func_qcaps_input); |
| 602 | struct hwrm_func_qcaps_input *req; |
| 603 | struct hwrm_func_qcaps_output *resp; |
| 604 | int rc; |
| 605 | |
| 606 | req = (struct hwrm_func_qcaps_input *)bp->hwrm_addr_req; |
| 607 | resp = (struct hwrm_func_qcaps_output *)bp->hwrm_addr_resp; |
| 608 | hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_QCAPS, cmd_len); |
| 609 | req->fid = (u16)HWRM_NA_SIGNATURE; |
| 610 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 611 | if (rc) |
| 612 | return STATUS_FAILURE; |
| 613 | |
| 614 | bp->fid = resp->fid; |
| 615 | bp->port_idx = (u8)resp->port_id; |
| 616 | |
| 617 | /* Get MAC address for this PF */ |
| 618 | memcpy(&bp->mac_addr[0], &resp->mac_address[0], ETH_ALEN); |
| 619 | |
| 620 | memcpy(&bp->mac_set[0], &bp->mac_addr[0], ETH_ALEN); |
| 621 | |
| 622 | print_func_qcaps(bp); |
| 623 | |
| 624 | return STATUS_SUCCESS; |
| 625 | } |
| 626 | |
| 627 | static int bnxt_hwrm_func_qcfg_req(struct bnxt *bp) |
| 628 | { |
| 629 | u16 cmd_len = (u16)sizeof(struct hwrm_func_qcfg_input); |
| 630 | struct hwrm_func_qcfg_input *req; |
| 631 | struct hwrm_func_qcfg_output *resp; |
| 632 | int rc; |
| 633 | |
| 634 | req = (struct hwrm_func_qcfg_input *)bp->hwrm_addr_req; |
| 635 | resp = (struct hwrm_func_qcfg_output *)bp->hwrm_addr_resp; |
| 636 | hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_QCFG, cmd_len); |
| 637 | req->fid = (u16)HWRM_NA_SIGNATURE; |
| 638 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 639 | if (rc) |
| 640 | return STATUS_FAILURE; |
| 641 | |
| 642 | if (resp->flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST) |
| 643 | FLAG_SET(bp->flags, BNXT_FLAG_MULTI_HOST); |
| 644 | |
| 645 | if (resp->port_partition_type & |
| 646 | FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0) |
| 647 | FLAG_SET(bp->flags, BNXT_FLAG_NPAR_MODE); |
| 648 | |
| 649 | bp->ordinal_value = (u8)resp->pci_id & 0x0F; |
| 650 | bp->stat_ctx_id = resp->stat_ctx_id; |
| 651 | memcpy(&bp->mac_addr[0], &resp->mac_address[0], ETH_ALEN); |
| 652 | print_func_qcfg(bp); |
| 653 | dbg_flags(__func__, bp->flags); |
| 654 | |
| 655 | return STATUS_SUCCESS; |
| 656 | } |
| 657 | |
| 658 | static int bnxt_hwrm_func_reset_req(struct bnxt *bp) |
| 659 | { |
| 660 | u16 cmd_len = (u16)sizeof(struct hwrm_func_reset_input); |
| 661 | struct hwrm_func_reset_input *req; |
| 662 | |
| 663 | req = (struct hwrm_func_reset_input *)bp->hwrm_addr_req; |
| 664 | hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_RESET, cmd_len); |
| 665 | req->func_reset_level = FUNC_RESET_REQ_FUNC_RESET_LEVEL_RESETME; |
| 666 | |
| 667 | return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 668 | } |
| 669 | |
| 670 | static int bnxt_hwrm_func_cfg_req(struct bnxt *bp) |
| 671 | { |
| 672 | u16 cmd_len = (u16)sizeof(struct hwrm_func_cfg_input); |
| 673 | struct hwrm_func_cfg_input *req; |
| 674 | |
| 675 | req = (struct hwrm_func_cfg_input *)bp->hwrm_addr_req; |
| 676 | hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_CFG, cmd_len); |
| 677 | req->fid = (u16)HWRM_NA_SIGNATURE; |
| 678 | bnxt_hwrm_assign_resources(bp); |
| 679 | |
| 680 | return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 681 | } |
| 682 | |
| 683 | static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp) |
| 684 | { |
| 685 | u16 cmd_len = (u16)sizeof(struct hwrm_func_drv_rgtr_input); |
| 686 | struct hwrm_func_drv_rgtr_input *req; |
| 687 | int rc; |
| 688 | |
| 689 | req = (struct hwrm_func_drv_rgtr_input *)bp->hwrm_addr_req; |
| 690 | hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_DRV_RGTR, cmd_len); |
| 691 | /* Register with HWRM */ |
| 692 | req->enables = FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE | |
| 693 | FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD | |
| 694 | FUNC_DRV_RGTR_REQ_ENABLES_VER; |
| 695 | req->async_event_fwd[0] |= 0x01; |
| 696 | req->os_type = FUNC_DRV_RGTR_REQ_OS_TYPE_OTHER; |
| 697 | req->ver_maj = DRIVER_VERSION_MAJOR; |
| 698 | req->ver_min = DRIVER_VERSION_MINOR; |
| 699 | req->ver_upd = DRIVER_VERSION_UPDATE; |
| 700 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 701 | if (rc) |
| 702 | return STATUS_FAILURE; |
| 703 | |
| 704 | FLAG_SET(bp->flag_hwrm, VALID_DRIVER_REG); |
| 705 | |
| 706 | return STATUS_SUCCESS; |
| 707 | } |
| 708 | |
| 709 | static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp) |
| 710 | { |
| 711 | u16 cmd_len = (u16)sizeof(struct hwrm_func_drv_unrgtr_input); |
| 712 | struct hwrm_func_drv_unrgtr_input *req; |
| 713 | int rc; |
| 714 | |
| 715 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_DRIVER_REG))) |
| 716 | return STATUS_SUCCESS; |
| 717 | |
| 718 | req = (struct hwrm_func_drv_unrgtr_input *)bp->hwrm_addr_req; |
| 719 | hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_DRV_UNRGTR, cmd_len); |
| 720 | req->flags = FUNC_DRV_UNRGTR_REQ_FLAGS_PREPARE_FOR_SHUTDOWN; |
| 721 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 722 | if (rc) |
| 723 | return STATUS_FAILURE; |
| 724 | |
| 725 | FLAG_RESET(bp->flag_hwrm, VALID_DRIVER_REG); |
| 726 | |
| 727 | return STATUS_SUCCESS; |
| 728 | } |
| 729 | |
| 730 | static int bnxt_hwrm_cfa_l2_filter_alloc(struct bnxt *bp) |
| 731 | { |
| 732 | u16 cmd_len = (u16)sizeof(struct hwrm_cfa_l2_filter_alloc_input); |
| 733 | struct hwrm_cfa_l2_filter_alloc_input *req; |
| 734 | struct hwrm_cfa_l2_filter_alloc_output *resp; |
| 735 | int rc; |
| 736 | u32 flags = CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX; |
| 737 | u32 enables; |
| 738 | |
| 739 | req = (struct hwrm_cfa_l2_filter_alloc_input *)bp->hwrm_addr_req; |
| 740 | resp = (struct hwrm_cfa_l2_filter_alloc_output *)bp->hwrm_addr_resp; |
| 741 | enables = CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID | |
| 742 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR | |
| 743 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK; |
| 744 | |
| 745 | hwrm_init(bp, (void *)req, (u16)HWRM_CFA_L2_FILTER_ALLOC, cmd_len); |
| 746 | req->flags = flags; |
| 747 | req->enables = enables; |
| 748 | memcpy((char *)&req->l2_addr[0], (char *)&bp->mac_set[0], ETH_ALEN); |
| 749 | memset((char *)&req->l2_addr_mask[0], 0xff, ETH_ALEN); |
| 750 | memcpy((char *)&req->t_l2_addr[0], (char *)&bp->mac_set[0], ETH_ALEN); |
| 751 | memset((char *)&req->t_l2_addr_mask[0], 0xff, ETH_ALEN); |
| 752 | req->src_type = CFA_L2_FILTER_ALLOC_REQ_SRC_TYPE_NPORT; |
| 753 | req->src_id = (u32)bp->port_idx; |
| 754 | req->dst_id = bp->vnic_id; |
| 755 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 756 | if (rc) |
| 757 | return STATUS_FAILURE; |
| 758 | |
| 759 | FLAG_SET(bp->flag_hwrm, VALID_L2_FILTER); |
| 760 | bp->l2_filter_id = resp->l2_filter_id; |
| 761 | |
| 762 | return STATUS_SUCCESS; |
| 763 | } |
| 764 | |
| 765 | static int bnxt_hwrm_cfa_l2_filter_free(struct bnxt *bp) |
| 766 | { |
| 767 | u16 cmd_len = (u16)sizeof(struct hwrm_cfa_l2_filter_free_input); |
| 768 | struct hwrm_cfa_l2_filter_free_input *req; |
| 769 | int rc; |
| 770 | |
| 771 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_L2_FILTER))) |
| 772 | return STATUS_SUCCESS; |
| 773 | |
| 774 | req = (struct hwrm_cfa_l2_filter_free_input *)bp->hwrm_addr_req; |
| 775 | hwrm_init(bp, (void *)req, (u16)HWRM_CFA_L2_FILTER_FREE, cmd_len); |
| 776 | req->l2_filter_id = bp->l2_filter_id; |
| 777 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 778 | if (rc) |
| 779 | return STATUS_FAILURE; |
| 780 | |
| 781 | FLAG_RESET(bp->flag_hwrm, VALID_L2_FILTER); |
| 782 | |
| 783 | return STATUS_SUCCESS; |
| 784 | } |
| 785 | |
| 786 | u32 bnxt_set_rx_mask(u32 rx_mask) |
| 787 | { |
| 788 | u32 mask = 0; |
| 789 | |
| 790 | if (!rx_mask) |
| 791 | return mask; |
| 792 | mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST; |
| 793 | if (rx_mask != RX_MASK_ACCEPT_NONE) { |
| 794 | if (rx_mask & RX_MASK_ACCEPT_MULTICAST) |
| 795 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST; |
| 796 | |
| 797 | if (rx_mask & RX_MASK_ACCEPT_ALL_MULTICAST) |
| 798 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 799 | |
| 800 | if (rx_mask & RX_MASK_PROMISCUOUS_MODE) |
| 801 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 802 | } |
| 803 | |
| 804 | return mask; |
| 805 | } |
| 806 | |
| 807 | static int bnxt_hwrm_set_rx_mask(struct bnxt *bp, u32 rx_mask) |
| 808 | { |
| 809 | u16 cmd_len = (u16)sizeof(struct hwrm_cfa_l2_set_rx_mask_input); |
| 810 | struct hwrm_cfa_l2_set_rx_mask_input *req; |
| 811 | u32 mask = bnxt_set_rx_mask(rx_mask); |
| 812 | |
| 813 | req = (struct hwrm_cfa_l2_set_rx_mask_input *)bp->hwrm_addr_req; |
| 814 | hwrm_init(bp, (void *)req, (u16)HWRM_CFA_L2_SET_RX_MASK, cmd_len); |
| 815 | req->vnic_id = bp->vnic_id; |
| 816 | req->mask = mask; |
| 817 | |
| 818 | return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 819 | } |
| 820 | |
| 821 | static int bnxt_hwrm_port_mac_cfg(struct bnxt *bp) |
| 822 | { |
| 823 | u16 cmd_len = (u16)sizeof(struct hwrm_port_mac_cfg_input); |
| 824 | struct hwrm_port_mac_cfg_input *req; |
| 825 | |
| 826 | req = (struct hwrm_port_mac_cfg_input *)bp->hwrm_addr_req; |
| 827 | hwrm_init(bp, (void *)req, (u16)HWRM_PORT_MAC_CFG, cmd_len); |
| 828 | req->lpbk = PORT_MAC_CFG_REQ_LPBK_NONE; |
| 829 | |
| 830 | return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 831 | } |
| 832 | |
| 833 | static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp, u16 idx) |
| 834 | { |
| 835 | u16 cmd_len = (u16)sizeof(struct hwrm_port_phy_qcfg_input); |
| 836 | struct hwrm_port_phy_qcfg_input *req; |
| 837 | struct hwrm_port_phy_qcfg_output *resp; |
| 838 | int rc; |
| 839 | |
| 840 | req = (struct hwrm_port_phy_qcfg_input *)bp->hwrm_addr_req; |
| 841 | resp = (struct hwrm_port_phy_qcfg_output *)bp->hwrm_addr_resp; |
| 842 | hwrm_init(bp, (void *)req, (u16)HWRM_PORT_PHY_QCFG, cmd_len); |
| 843 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 844 | if (rc) |
| 845 | return STATUS_FAILURE; |
| 846 | |
| 847 | if (idx & SUPPORT_SPEEDS) |
| 848 | bp->support_speeds = resp->support_speeds; |
| 849 | |
| 850 | if (idx & DETECT_MEDIA) |
| 851 | bp->media_detect = resp->module_status; |
| 852 | |
| 853 | if (idx & PHY_SPEED) |
| 854 | bp->current_link_speed = resp->link_speed; |
| 855 | |
| 856 | if (idx & PHY_STATUS) { |
| 857 | if (resp->link == PORT_PHY_QCFG_RESP_LINK_LINK) |
| 858 | bp->link_status = STATUS_LINK_ACTIVE; |
| 859 | else |
| 860 | bp->link_status = STATUS_LINK_DOWN; |
| 861 | } |
| 862 | |
| 863 | return STATUS_SUCCESS; |
| 864 | } |
| 865 | |
| 866 | u16 set_link_speed_mask(u16 link_cap) |
| 867 | { |
| 868 | u16 speed_mask = 0; |
| 869 | |
| 870 | if (link_cap & SPEED_CAPABILITY_DRV_100M) |
| 871 | speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_100MB; |
| 872 | |
| 873 | if (link_cap & SPEED_CAPABILITY_DRV_1G) |
| 874 | speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_1GB; |
| 875 | |
| 876 | if (link_cap & SPEED_CAPABILITY_DRV_10G) |
| 877 | speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_10GB; |
| 878 | |
| 879 | if (link_cap & SPEED_CAPABILITY_DRV_25G) |
| 880 | speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_25GB; |
| 881 | |
| 882 | if (link_cap & SPEED_CAPABILITY_DRV_40G) |
| 883 | speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_40GB; |
| 884 | |
| 885 | if (link_cap & SPEED_CAPABILITY_DRV_50G) |
| 886 | speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_50GB; |
| 887 | |
| 888 | if (link_cap & SPEED_CAPABILITY_DRV_100G) |
| 889 | speed_mask |= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_MASK_100GB; |
| 890 | |
| 891 | return speed_mask; |
| 892 | } |
| 893 | |
| 894 | static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp) |
| 895 | { |
| 896 | u16 cmd_len = (u16)sizeof(struct hwrm_port_phy_cfg_input); |
| 897 | struct hwrm_port_phy_cfg_input *req; |
| 898 | u32 flags; |
| 899 | u32 enables = 0; |
| 900 | u16 force_link_speed = 0; |
| 901 | u16 auto_link_speed_mask = 0; |
| 902 | u8 auto_mode = 0; |
| 903 | u8 auto_pause = 0; |
| 904 | u8 auto_duplex = 0; |
| 905 | |
| 906 | /* |
| 907 | * If multi_host or NPAR is set to TRUE, |
| 908 | * do not issue hwrm_port_phy_cfg |
| 909 | */ |
| 910 | if (FLAG_TEST(bp->flags, PORT_PHY_FLAGS)) { |
| 911 | dbg_flags(__func__, bp->flags); |
| 912 | return STATUS_SUCCESS; |
| 913 | } |
| 914 | |
| 915 | req = (struct hwrm_port_phy_cfg_input *)bp->hwrm_addr_req; |
| 916 | flags = PORT_PHY_CFG_REQ_FLAGS_FORCE | |
| 917 | PORT_PHY_CFG_REQ_FLAGS_RESET_PHY; |
| 918 | |
| 919 | switch (GET_MEDIUM_SPEED(bp->medium)) { |
| 920 | case MEDIUM_SPEED_1000MBPS: |
| 921 | force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB; |
| 922 | break; |
| 923 | case MEDIUM_SPEED_10GBPS: |
| 924 | force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB; |
| 925 | break; |
| 926 | case MEDIUM_SPEED_25GBPS: |
| 927 | force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB; |
| 928 | break; |
| 929 | case MEDIUM_SPEED_40GBPS: |
| 930 | force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB; |
| 931 | break; |
| 932 | case MEDIUM_SPEED_50GBPS: |
| 933 | force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB; |
| 934 | break; |
| 935 | case MEDIUM_SPEED_100GBPS: |
| 936 | force_link_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_100GB; |
| 937 | break; |
| 938 | default: |
| 939 | /* Enable AUTONEG by default */ |
| 940 | auto_mode = PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK; |
| 941 | flags &= ~PORT_PHY_CFG_REQ_FLAGS_FORCE; |
| 942 | enables |= PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE | |
| 943 | PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK | |
| 944 | PORT_PHY_CFG_REQ_ENABLES_AUTO_DUPLEX | |
| 945 | PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE; |
| 946 | auto_pause = PORT_PHY_CFG_REQ_AUTO_PAUSE_TX | |
| 947 | PORT_PHY_CFG_REQ_AUTO_PAUSE_RX; |
| 948 | auto_duplex = PORT_PHY_CFG_REQ_AUTO_DUPLEX_BOTH; |
| 949 | auto_link_speed_mask = bp->support_speeds; |
| 950 | break; |
| 951 | } |
| 952 | |
| 953 | hwrm_init(bp, (void *)req, (u16)HWRM_PORT_PHY_CFG, cmd_len); |
| 954 | req->flags = flags; |
| 955 | req->enables = enables; |
| 956 | req->port_id = bp->port_idx; |
| 957 | req->force_link_speed = force_link_speed; |
| 958 | req->auto_mode = auto_mode; |
| 959 | req->auto_duplex = auto_duplex; |
| 960 | req->auto_pause = auto_pause; |
| 961 | req->auto_link_speed_mask = auto_link_speed_mask; |
| 962 | |
| 963 | return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 964 | } |
| 965 | |
| 966 | static int bnxt_qphy_link(struct bnxt *bp) |
| 967 | { |
| 968 | u16 flag = QCFG_PHY_ALL; |
| 969 | |
| 970 | /* Query Link Status */ |
| 971 | if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS) |
| 972 | return STATUS_FAILURE; |
| 973 | |
| 974 | if (bp->link_status != STATUS_LINK_ACTIVE) { |
| 975 | /* |
| 976 | * Configure link if it is not up. |
| 977 | * try to bring link up, but don't return |
| 978 | * failure if port_phy_cfg() fails |
| 979 | */ |
| 980 | bnxt_hwrm_port_phy_cfg(bp); |
| 981 | /* refresh link speed values after bringing link up */ |
| 982 | if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS) |
| 983 | return STATUS_FAILURE; |
| 984 | } |
| 985 | |
| 986 | return STATUS_SUCCESS; |
| 987 | } |
| 988 | |
| 989 | static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp) |
| 990 | { |
| 991 | u16 cmd_len = (u16)sizeof(struct hwrm_stat_ctx_alloc_input); |
| 992 | struct hwrm_stat_ctx_alloc_input *req; |
| 993 | struct hwrm_stat_ctx_alloc_output *resp; |
| 994 | int rc; |
| 995 | |
| 996 | req = (struct hwrm_stat_ctx_alloc_input *)bp->hwrm_addr_req; |
| 997 | resp = (struct hwrm_stat_ctx_alloc_output *)bp->hwrm_addr_resp; |
| 998 | hwrm_init(bp, (void *)req, (u16)HWRM_STAT_CTX_ALLOC, cmd_len); |
| 999 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1000 | if (rc) |
| 1001 | return STATUS_FAILURE; |
| 1002 | |
| 1003 | FLAG_SET(bp->flag_hwrm, VALID_STAT_CTX); |
| 1004 | bp->stat_ctx_id = (u16)resp->stat_ctx_id; |
| 1005 | |
| 1006 | return STATUS_SUCCESS; |
| 1007 | } |
| 1008 | |
| 1009 | static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp) |
| 1010 | { |
| 1011 | u16 cmd_len = (u16)sizeof(struct hwrm_stat_ctx_free_input); |
| 1012 | struct hwrm_stat_ctx_free_input *req; |
| 1013 | int rc; |
| 1014 | |
| 1015 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_STAT_CTX))) |
| 1016 | return STATUS_SUCCESS; |
| 1017 | |
| 1018 | req = (struct hwrm_stat_ctx_free_input *)bp->hwrm_addr_req; |
| 1019 | hwrm_init(bp, (void *)req, (u16)HWRM_STAT_CTX_FREE, cmd_len); |
| 1020 | req->stat_ctx_id = (u32)bp->stat_ctx_id; |
| 1021 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1022 | if (rc) |
| 1023 | return STATUS_FAILURE; |
| 1024 | |
| 1025 | FLAG_RESET(bp->flag_hwrm, VALID_STAT_CTX); |
| 1026 | |
| 1027 | return STATUS_SUCCESS; |
| 1028 | } |
| 1029 | |
| 1030 | static int bnxt_hwrm_ring_free_grp(struct bnxt *bp) |
| 1031 | { |
| 1032 | u16 cmd_len = (u16)sizeof(struct hwrm_ring_grp_free_input); |
| 1033 | struct hwrm_ring_grp_free_input *req; |
| 1034 | int rc; |
| 1035 | |
| 1036 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_RING_GRP))) |
| 1037 | return STATUS_SUCCESS; |
| 1038 | |
| 1039 | req = (struct hwrm_ring_grp_free_input *)bp->hwrm_addr_req; |
| 1040 | hwrm_init(bp, (void *)req, (u16)HWRM_RING_GRP_FREE, cmd_len); |
| 1041 | req->ring_group_id = (u32)bp->ring_grp_id; |
| 1042 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1043 | if (rc) |
| 1044 | return STATUS_FAILURE; |
| 1045 | |
| 1046 | FLAG_RESET(bp->flag_hwrm, VALID_RING_GRP); |
| 1047 | |
| 1048 | return STATUS_SUCCESS; |
| 1049 | } |
| 1050 | |
| 1051 | static int bnxt_hwrm_ring_alloc_grp(struct bnxt *bp) |
| 1052 | { |
| 1053 | u16 cmd_len = (u16)sizeof(struct hwrm_ring_grp_alloc_input); |
| 1054 | struct hwrm_ring_grp_alloc_input *req; |
| 1055 | struct hwrm_ring_grp_alloc_output *resp; |
| 1056 | int rc; |
| 1057 | |
| 1058 | req = (struct hwrm_ring_grp_alloc_input *)bp->hwrm_addr_req; |
| 1059 | resp = (struct hwrm_ring_grp_alloc_output *)bp->hwrm_addr_resp; |
| 1060 | hwrm_init(bp, (void *)req, (u16)HWRM_RING_GRP_ALLOC, cmd_len); |
| 1061 | req->cr = bp->cq_ring_id; |
| 1062 | req->rr = bp->rx_ring_id; |
| 1063 | req->ar = (u16)HWRM_NA_SIGNATURE; |
| 1064 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1065 | if (rc) |
| 1066 | return STATUS_FAILURE; |
| 1067 | |
| 1068 | FLAG_SET(bp->flag_hwrm, VALID_RING_GRP); |
| 1069 | bp->ring_grp_id = (u16)resp->ring_group_id; |
| 1070 | |
| 1071 | return STATUS_SUCCESS; |
| 1072 | } |
| 1073 | |
| 1074 | int bnxt_hwrm_ring_free(struct bnxt *bp, u16 ring_id, u8 ring_type) |
| 1075 | { |
| 1076 | u16 cmd_len = (u16)sizeof(struct hwrm_ring_free_input); |
| 1077 | struct hwrm_ring_free_input *req; |
| 1078 | |
| 1079 | req = (struct hwrm_ring_free_input *)bp->hwrm_addr_req; |
| 1080 | hwrm_init(bp, (void *)req, (u16)HWRM_RING_FREE, cmd_len); |
| 1081 | req->ring_type = ring_type; |
| 1082 | req->ring_id = ring_id; |
| 1083 | |
| 1084 | return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1085 | } |
| 1086 | |
| 1087 | static int bnxt_hwrm_ring_alloc(struct bnxt *bp, |
| 1088 | dma_addr_t ring_map, |
| 1089 | u16 length, |
| 1090 | u16 ring_id, |
| 1091 | u8 ring_type, |
| 1092 | u8 int_mode) |
| 1093 | { |
| 1094 | u16 cmd_len = (u16)sizeof(struct hwrm_ring_alloc_input); |
| 1095 | struct hwrm_ring_alloc_input *req; |
| 1096 | struct hwrm_ring_alloc_output *resp; |
| 1097 | int rc; |
| 1098 | |
| 1099 | req = (struct hwrm_ring_alloc_input *)bp->hwrm_addr_req; |
| 1100 | resp = (struct hwrm_ring_alloc_output *)bp->hwrm_addr_resp; |
| 1101 | hwrm_init(bp, (void *)req, (u16)HWRM_RING_ALLOC, cmd_len); |
| 1102 | req->ring_type = ring_type; |
| 1103 | req->page_tbl_addr = ring_map; |
| 1104 | req->page_size = LM_PAGE_SIZE; |
| 1105 | req->length = (u32)length; |
| 1106 | req->cmpl_ring_id = ring_id; |
| 1107 | req->int_mode = int_mode; |
| 1108 | if (ring_type == RING_ALLOC_REQ_RING_TYPE_TX) { |
| 1109 | req->queue_id = TX_RING_QID; |
| 1110 | } else if (ring_type == RING_ALLOC_REQ_RING_TYPE_RX) { |
| 1111 | req->queue_id = RX_RING_QID; |
| 1112 | req->enables = RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID; |
| 1113 | req->rx_buf_size = MAX_ETHERNET_PACKET_BUFFER_SIZE; |
| 1114 | } |
| 1115 | |
| 1116 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1117 | if (rc) |
| 1118 | return STATUS_FAILURE; |
| 1119 | |
| 1120 | if (ring_type == RING_ALLOC_REQ_RING_TYPE_L2_CMPL) { |
| 1121 | FLAG_SET(bp->flag_hwrm, VALID_RING_CQ); |
| 1122 | bp->cq_ring_id = resp->ring_id; |
| 1123 | } else if (ring_type == RING_ALLOC_REQ_RING_TYPE_TX) { |
| 1124 | FLAG_SET(bp->flag_hwrm, VALID_RING_TX); |
| 1125 | bp->tx_ring_id = resp->ring_id; |
| 1126 | } else if (ring_type == RING_ALLOC_REQ_RING_TYPE_RX) { |
| 1127 | FLAG_SET(bp->flag_hwrm, VALID_RING_RX); |
| 1128 | bp->rx_ring_id = resp->ring_id; |
| 1129 | } |
| 1130 | |
| 1131 | return STATUS_SUCCESS; |
| 1132 | } |
| 1133 | |
| 1134 | static int bnxt_hwrm_ring_alloc_cq(struct bnxt *bp) |
| 1135 | { |
| 1136 | return bnxt_hwrm_ring_alloc(bp, |
| 1137 | virt_to_bus(bp->cq.bd_virt), |
| 1138 | bp->cq.ring_cnt, |
| 1139 | 0, |
| 1140 | RING_ALLOC_REQ_RING_TYPE_L2_CMPL, |
| 1141 | BNXT_CQ_INTR_MODE()); |
| 1142 | } |
| 1143 | |
| 1144 | static int bnxt_hwrm_ring_alloc_tx(struct bnxt *bp) |
| 1145 | { |
| 1146 | return bnxt_hwrm_ring_alloc(bp, |
| 1147 | virt_to_bus(bp->tx.bd_virt), |
| 1148 | bp->tx.ring_cnt, bp->cq_ring_id, |
| 1149 | RING_ALLOC_REQ_RING_TYPE_TX, |
| 1150 | BNXT_INTR_MODE()); |
| 1151 | } |
| 1152 | |
| 1153 | static int bnxt_hwrm_ring_alloc_rx(struct bnxt *bp) |
| 1154 | { |
| 1155 | return bnxt_hwrm_ring_alloc(bp, |
| 1156 | virt_to_bus(bp->rx.bd_virt), |
| 1157 | bp->rx.ring_cnt, |
| 1158 | bp->cq_ring_id, |
| 1159 | RING_ALLOC_REQ_RING_TYPE_RX, |
| 1160 | BNXT_INTR_MODE()); |
| 1161 | } |
| 1162 | |
| 1163 | static int bnxt_hwrm_ring_free_cq(struct bnxt *bp) |
| 1164 | { |
| 1165 | int ret = STATUS_SUCCESS; |
| 1166 | |
| 1167 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_RING_CQ))) |
| 1168 | return ret; |
| 1169 | |
| 1170 | ret = RING_FREE(bp, bp->cq_ring_id, RING_FREE_REQ_RING_TYPE_L2_CMPL); |
| 1171 | if (ret == STATUS_SUCCESS) |
| 1172 | FLAG_RESET(bp->flag_hwrm, VALID_RING_CQ); |
| 1173 | |
| 1174 | return ret; |
| 1175 | } |
| 1176 | |
| 1177 | static int bnxt_hwrm_ring_free_tx(struct bnxt *bp) |
| 1178 | { |
| 1179 | int ret = STATUS_SUCCESS; |
| 1180 | |
| 1181 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_RING_TX))) |
| 1182 | return ret; |
| 1183 | |
| 1184 | ret = RING_FREE(bp, bp->tx_ring_id, RING_FREE_REQ_RING_TYPE_TX); |
| 1185 | if (ret == STATUS_SUCCESS) |
| 1186 | FLAG_RESET(bp->flag_hwrm, VALID_RING_TX); |
| 1187 | |
| 1188 | return ret; |
| 1189 | } |
| 1190 | |
| 1191 | static int bnxt_hwrm_ring_free_rx(struct bnxt *bp) |
| 1192 | { |
| 1193 | int ret = STATUS_SUCCESS; |
| 1194 | |
| 1195 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_RING_RX))) |
| 1196 | return ret; |
| 1197 | |
| 1198 | ret = RING_FREE(bp, bp->rx_ring_id, RING_FREE_REQ_RING_TYPE_RX); |
| 1199 | if (ret == STATUS_SUCCESS) |
| 1200 | FLAG_RESET(bp->flag_hwrm, VALID_RING_RX); |
| 1201 | |
| 1202 | return ret; |
| 1203 | } |
| 1204 | |
| 1205 | static int bnxt_hwrm_vnic_alloc(struct bnxt *bp) |
| 1206 | { |
| 1207 | u16 cmd_len = (u16)sizeof(struct hwrm_vnic_alloc_input); |
| 1208 | struct hwrm_vnic_alloc_input *req; |
| 1209 | struct hwrm_vnic_alloc_output *resp; |
| 1210 | int rc; |
| 1211 | |
| 1212 | req = (struct hwrm_vnic_alloc_input *)bp->hwrm_addr_req; |
| 1213 | resp = (struct hwrm_vnic_alloc_output *)bp->hwrm_addr_resp; |
| 1214 | hwrm_init(bp, (void *)req, (u16)HWRM_VNIC_ALLOC, cmd_len); |
| 1215 | req->flags = VNIC_ALLOC_REQ_FLAGS_DEFAULT; |
| 1216 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1217 | if (rc) |
| 1218 | return STATUS_FAILURE; |
| 1219 | |
| 1220 | FLAG_SET(bp->flag_hwrm, VALID_VNIC_ID); |
| 1221 | bp->vnic_id = resp->vnic_id; |
| 1222 | |
| 1223 | return STATUS_SUCCESS; |
| 1224 | } |
| 1225 | |
| 1226 | static int bnxt_hwrm_vnic_free(struct bnxt *bp) |
| 1227 | { |
| 1228 | u16 cmd_len = (u16)sizeof(struct hwrm_vnic_free_input); |
| 1229 | struct hwrm_vnic_free_input *req; |
| 1230 | int rc; |
| 1231 | |
| 1232 | if (!(FLAG_TEST(bp->flag_hwrm, VALID_VNIC_ID))) |
| 1233 | return STATUS_SUCCESS; |
| 1234 | |
| 1235 | req = (struct hwrm_vnic_free_input *)bp->hwrm_addr_req; |
| 1236 | hwrm_init(bp, (void *)req, (u16)HWRM_VNIC_FREE, cmd_len); |
| 1237 | req->vnic_id = bp->vnic_id; |
| 1238 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1239 | if (rc) |
| 1240 | return STATUS_FAILURE; |
| 1241 | |
| 1242 | FLAG_RESET(bp->flag_hwrm, VALID_VNIC_ID); |
| 1243 | |
| 1244 | return STATUS_SUCCESS; |
| 1245 | } |
| 1246 | |
| 1247 | static int bnxt_hwrm_vnic_cfg(struct bnxt *bp) |
| 1248 | { |
| 1249 | u16 cmd_len = (u16)sizeof(struct hwrm_vnic_cfg_input); |
| 1250 | struct hwrm_vnic_cfg_input *req; |
| 1251 | |
| 1252 | req = (struct hwrm_vnic_cfg_input *)bp->hwrm_addr_req; |
| 1253 | hwrm_init(bp, (void *)req, (u16)HWRM_VNIC_CFG, cmd_len); |
| 1254 | req->enables = VNIC_CFG_REQ_ENABLES_MRU; |
| 1255 | req->mru = bp->mtu; |
| 1256 | req->enables |= VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP; |
| 1257 | req->dflt_ring_grp = bp->ring_grp_id; |
| 1258 | req->vnic_id = bp->vnic_id; |
| 1259 | |
| 1260 | return wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1261 | } |
| 1262 | |
| 1263 | static int set_phy_speed(struct bnxt *bp) |
| 1264 | { |
| 1265 | char name[20]; |
| 1266 | u16 flag = PHY_STATUS | PHY_SPEED | DETECT_MEDIA; |
| 1267 | |
| 1268 | /* Query Link Status */ |
| 1269 | if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS) |
| 1270 | return STATUS_FAILURE; |
| 1271 | |
| 1272 | switch (bp->current_link_speed) { |
| 1273 | case PORT_PHY_QCFG_RESP_LINK_SPEED_100GB: |
| 1274 | sprintf(name, "%s %s", str_100, str_gbps); |
| 1275 | break; |
| 1276 | case PORT_PHY_QCFG_RESP_LINK_SPEED_50GB: |
| 1277 | sprintf(name, "%s %s", str_50, str_gbps); |
| 1278 | break; |
| 1279 | case PORT_PHY_QCFG_RESP_LINK_SPEED_40GB: |
| 1280 | sprintf(name, "%s %s", str_40, str_gbps); |
| 1281 | break; |
| 1282 | case PORT_PHY_QCFG_RESP_LINK_SPEED_25GB: |
| 1283 | sprintf(name, "%s %s", str_25, str_gbps); |
| 1284 | break; |
| 1285 | case PORT_PHY_QCFG_RESP_LINK_SPEED_20GB: |
| 1286 | sprintf(name, "%s %s", str_20, str_gbps); |
| 1287 | break; |
| 1288 | case PORT_PHY_QCFG_RESP_LINK_SPEED_10GB: |
| 1289 | sprintf(name, "%s %s", str_10, str_gbps); |
| 1290 | break; |
| 1291 | case PORT_PHY_QCFG_RESP_LINK_SPEED_2_5GB: |
| 1292 | sprintf(name, "%s %s", str_2_5, str_gbps); |
| 1293 | break; |
| 1294 | case PORT_PHY_QCFG_RESP_LINK_SPEED_2GB: |
| 1295 | sprintf(name, "%s %s", str_2, str_gbps); |
| 1296 | break; |
| 1297 | case PORT_PHY_QCFG_RESP_LINK_SPEED_1GB: |
| 1298 | sprintf(name, "%s %s", str_1, str_gbps); |
| 1299 | break; |
| 1300 | case PORT_PHY_QCFG_RESP_LINK_SPEED_100MB: |
| 1301 | sprintf(name, "%s %s", str_100, str_mbps); |
| 1302 | break; |
| 1303 | case PORT_PHY_QCFG_RESP_LINK_SPEED_10MB: |
| 1304 | sprintf(name, "%s %s", str_10, str_mbps); |
| 1305 | break; |
| 1306 | default: |
| 1307 | sprintf(name, "%s %x", str_unknown, bp->current_link_speed); |
| 1308 | } |
| 1309 | |
| 1310 | dbg_phy_speed(bp, name); |
| 1311 | |
| 1312 | return STATUS_SUCCESS; |
| 1313 | } |
| 1314 | |
| 1315 | static int set_phy_link(struct bnxt *bp, u32 tmo) |
| 1316 | { |
| 1317 | int ret; |
| 1318 | |
| 1319 | set_phy_speed(bp); |
| 1320 | dbg_link_status(bp); |
| 1321 | ret = STATUS_FAILURE; |
| 1322 | if (bp->link_status == STATUS_LINK_ACTIVE) { |
| 1323 | dbg_link_state(bp, tmo); |
| 1324 | ret = STATUS_SUCCESS; |
| 1325 | } |
| 1326 | |
| 1327 | return ret; |
| 1328 | } |
| 1329 | |
| 1330 | static int get_phy_link(struct bnxt *bp) |
| 1331 | { |
| 1332 | u16 flag = PHY_STATUS | PHY_SPEED | DETECT_MEDIA; |
| 1333 | |
| 1334 | dbg_chip_info(bp); |
| 1335 | /* Query Link Status */ |
| 1336 | if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS) |
| 1337 | return STATUS_FAILURE; |
| 1338 | |
| 1339 | set_phy_link(bp, 100); |
| 1340 | |
| 1341 | return STATUS_SUCCESS; |
| 1342 | } |
| 1343 | |
| 1344 | static int bnxt_hwrm_set_async_event(struct bnxt *bp) |
| 1345 | { |
| 1346 | int rc; |
| 1347 | u16 cmd_len = (u16)sizeof(struct hwrm_func_cfg_input); |
| 1348 | struct hwrm_func_cfg_input *req; |
| 1349 | |
| 1350 | req = (struct hwrm_func_cfg_input *)bp->hwrm_addr_req; |
| 1351 | hwrm_init(bp, (void *)req, (u16)HWRM_FUNC_CFG, cmd_len); |
| 1352 | req->fid = (u16)HWRM_NA_SIGNATURE; |
| 1353 | req->enables = FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR; |
| 1354 | req->async_event_cr = bp->cq_ring_id; |
| 1355 | rc = wait_resp(bp, bp->hwrm_cmd_timeout, cmd_len, __func__); |
| 1356 | |
| 1357 | return rc; |
| 1358 | } |
| 1359 | |
| 1360 | int bnxt_hwrm_get_nvmem(struct bnxt *bp, |
| 1361 | u16 data_len, |
| 1362 | u16 option_num, |
| 1363 | u16 dimensions, |
| 1364 | u16 index_0) |
| 1365 | { |
| 1366 | u16 cmd_len = (u16)sizeof(struct hwrm_nvm_get_variable_input); |
| 1367 | struct hwrm_nvm_get_variable_input *req; |
| 1368 | |
| 1369 | req = (struct hwrm_nvm_get_variable_input *)bp->hwrm_addr_req; |
| 1370 | hwrm_init(bp, (void *)req, (u16)HWRM_NVM_GET_VARIABLE, cmd_len); |
| 1371 | req->dest_data_addr = bp->data_addr_mapping; |
| 1372 | req->data_len = data_len; |
| 1373 | req->option_num = option_num; |
| 1374 | req->dimensions = dimensions; |
| 1375 | req->index_0 = index_0; |
| 1376 | |
| 1377 | return wait_resp(bp, |
| 1378 | HWRM_CMD_FLASH_MULTIPLAYER(bp->hwrm_cmd_timeout), |
| 1379 | cmd_len, |
| 1380 | __func__); |
| 1381 | } |
| 1382 | |
| 1383 | static void set_medium(struct bnxt *bp) |
| 1384 | { |
| 1385 | switch (bp->link_set & LINK_SPEED_DRV_MASK) { |
| 1386 | case LINK_SPEED_DRV_1G: |
| 1387 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_1000MBPS); |
| 1388 | break; |
| 1389 | case LINK_SPEED_DRV_2_5G: |
| 1390 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_2500MBPS); |
| 1391 | break; |
| 1392 | case LINK_SPEED_DRV_10G: |
| 1393 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_10GBPS); |
| 1394 | break; |
| 1395 | case LINK_SPEED_DRV_25G: |
| 1396 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_25GBPS); |
| 1397 | break; |
| 1398 | case LINK_SPEED_DRV_40G: |
| 1399 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_40GBPS); |
| 1400 | break; |
| 1401 | case LINK_SPEED_DRV_50G: |
| 1402 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_50GBPS); |
| 1403 | break; |
| 1404 | case LINK_SPEED_DRV_100G: |
| 1405 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_100GBPS); |
| 1406 | break; |
| 1407 | case LINK_SPEED_DRV_200G: |
| 1408 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_200GBPS); |
| 1409 | break; |
| 1410 | case LINK_SPEED_DRV_AUTONEG: |
| 1411 | bp->medium = SET_MEDIUM_SPEED(bp, MEDIUM_SPEED_AUTONEG); |
| 1412 | break; |
| 1413 | default: |
| 1414 | bp->medium = SET_MEDIUM_DUPLEX(bp, MEDIUM_FULL_DUPLEX); |
| 1415 | break; |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | static int bnxt_hwrm_get_link_speed(struct bnxt *bp) |
| 1420 | { |
| 1421 | u32 *ptr32 = (u32 *)bp->hwrm_addr_data; |
| 1422 | |
| 1423 | if (bnxt_hwrm_get_nvmem(bp, |
| 1424 | 4, |
| 1425 | (u16)LINK_SPEED_DRV_NUM, |
| 1426 | 1, |
| 1427 | (u16)bp->port_idx) != STATUS_SUCCESS) |
| 1428 | return STATUS_FAILURE; |
| 1429 | |
| 1430 | bp->link_set = *ptr32; |
| 1431 | bp->link_set &= SPEED_DRV_MASK; |
| 1432 | set_medium(bp); |
| 1433 | |
| 1434 | return STATUS_SUCCESS; |
| 1435 | } |
| 1436 | |
| 1437 | typedef int (*hwrm_func_t)(struct bnxt *bp); |
| 1438 | |
| 1439 | hwrm_func_t down_chip[] = { |
| 1440 | bnxt_hwrm_cfa_l2_filter_free, /* Free l2 filter */ |
| 1441 | bnxt_free_rx_iob, /* Free rx iob */ |
| 1442 | bnxt_hwrm_vnic_free, /* Free vnic */ |
| 1443 | bnxt_hwrm_ring_free_grp, /* Free ring group */ |
| 1444 | bnxt_hwrm_ring_free_rx, /* Free rx ring */ |
| 1445 | bnxt_hwrm_ring_free_tx, /* Free tx ring */ |
| 1446 | bnxt_hwrm_ring_free_cq, /* Free CQ ring */ |
| 1447 | bnxt_hwrm_stat_ctx_free, /* Free Stat ctx */ |
| 1448 | bnxt_hwrm_func_drv_unrgtr, /* unreg driver */ |
| 1449 | NULL, |
| 1450 | }; |
| 1451 | |
| 1452 | hwrm_func_t bring_chip[] = { |
| 1453 | bnxt_hwrm_ver_get, /* HWRM_VER_GET */ |
| 1454 | bnxt_hwrm_func_reset_req, /* HWRM_FUNC_RESET */ |
| 1455 | bnxt_hwrm_func_drv_rgtr, /* HWRM_FUNC_DRV_RGTR */ |
| 1456 | bnxt_hwrm_func_resource_qcaps, /* HWRM_FUNC_RESOURCE_QCAPS */ |
| 1457 | bnxt_hwrm_func_qcfg_req, /* HWRM_FUNC_QCFG */ |
| 1458 | bnxt_hwrm_func_qcaps_req, /* HWRM_FUNC_QCAPS */ |
| 1459 | bnxt_hwrm_get_link_speed, /* HWRM_NVM_GET_VARIABLE - 203 */ |
| 1460 | bnxt_hwrm_port_mac_cfg, /* HWRM_PORT_MAC_CFG */ |
| 1461 | bnxt_qphy_link, /* HWRM_PORT_PHY_QCFG */ |
| 1462 | bnxt_hwrm_func_cfg_req, /* HWRM_FUNC_CFG - ring resource*/ |
| 1463 | bnxt_hwrm_stat_ctx_alloc, /* Allocate Stat Ctx ID */ |
| 1464 | bnxt_hwrm_ring_alloc_cq, /* Allocate CQ Ring */ |
| 1465 | bnxt_hwrm_ring_alloc_tx, /* Allocate Tx ring */ |
| 1466 | bnxt_hwrm_ring_alloc_rx, /* Allocate Rx Ring */ |
| 1467 | bnxt_hwrm_ring_alloc_grp, /* Create Ring Group */ |
| 1468 | post_rx_buffers, /* Post RX buffers */ |
| 1469 | bnxt_hwrm_set_async_event, /* ENABLES_ASYNC_EVENT_CR */ |
| 1470 | bnxt_hwrm_vnic_alloc, /* Alloc VNIC */ |
| 1471 | bnxt_hwrm_vnic_cfg, /* Config VNIC */ |
| 1472 | bnxt_hwrm_cfa_l2_filter_alloc, /* Alloc L2 Filter */ |
| 1473 | get_phy_link, /* Get Physical Link */ |
| 1474 | NULL, |
| 1475 | }; |
| 1476 | |
| 1477 | int bnxt_hwrm_run(hwrm_func_t cmds[], struct bnxt *bp, int flag) |
| 1478 | { |
| 1479 | hwrm_func_t *ptr; |
| 1480 | int ret; |
| 1481 | int status = STATUS_SUCCESS; |
| 1482 | |
| 1483 | for (ptr = cmds; *ptr; ++ptr) { |
| 1484 | ret = (*ptr)(bp); |
| 1485 | if (ret) { |
| 1486 | status = STATUS_FAILURE; |
| 1487 | /* Continue till all cleanup routines are called */ |
| 1488 | if (flag) |
| 1489 | return STATUS_FAILURE; |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | return status; |
| 1494 | } |
| 1495 | |
| 1496 | /* Broadcom ethernet driver Network interface APIs. */ |
| 1497 | static int bnxt_start(struct udevice *dev) |
| 1498 | { |
| 1499 | struct bnxt *bp = dev_get_priv(dev); |
| 1500 | |
| 1501 | if (bnxt_hwrm_set_rx_mask(bp, RX_MASK) != STATUS_SUCCESS) |
| 1502 | return STATUS_FAILURE; |
| 1503 | |
| 1504 | bp->card_en = true; |
| 1505 | return STATUS_SUCCESS; |
| 1506 | } |
| 1507 | |
| 1508 | static int bnxt_send(struct udevice *dev, void *packet, int length) |
| 1509 | { |
| 1510 | struct bnxt *bp = dev_get_priv(dev); |
| 1511 | int len; |
| 1512 | u16 entry; |
| 1513 | dma_addr_t mapping; |
| 1514 | |
| 1515 | if (bnxt_tx_avail(bp) < 1) { |
| 1516 | dbg_no_tx_bd(); |
| 1517 | return -ENOBUFS; |
| 1518 | } |
| 1519 | |
| 1520 | entry = bp->tx.prod_id; |
| 1521 | len = iob_pad(packet, length); |
| 1522 | mapping = virt_to_bus(packet); |
| 1523 | set_txq(bp, entry, mapping, len); |
| 1524 | entry = NEXT_IDX(entry, bp->tx.ring_cnt); |
| 1525 | dump_tx_pkt(packet, mapping, len); |
| 1526 | bnxt_db_tx(bp, (u32)entry); |
| 1527 | bp->tx.prod_id = entry; |
| 1528 | bp->tx.cnt_req++; |
| 1529 | bnxt_tx_complete(bp); |
| 1530 | |
| 1531 | return 0; |
| 1532 | } |
| 1533 | |
| 1534 | static void bnxt_link_evt(struct bnxt *bp, struct cmpl_base *cmp) |
| 1535 | { |
| 1536 | struct hwrm_async_event_cmpl *evt; |
| 1537 | |
| 1538 | evt = (struct hwrm_async_event_cmpl *)cmp; |
| 1539 | switch (evt->event_id) { |
| 1540 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE: |
| 1541 | if (evt->event_data1 & 0x01) |
| 1542 | bp->link_status = STATUS_LINK_ACTIVE; |
| 1543 | else |
| 1544 | bp->link_status = STATUS_LINK_DOWN; |
| 1545 | |
| 1546 | set_phy_link(bp, 0); |
| 1547 | break; |
| 1548 | default: |
| 1549 | break; |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | static int bnxt_recv(struct udevice *dev, int flags, uchar **packetp) |
| 1554 | { |
| 1555 | struct bnxt *bp = dev_get_priv(dev); |
| 1556 | struct cmpl_base *cmp; |
| 1557 | u16 old_cons_idx = bp->cq.cons_idx; |
| 1558 | int done = SERVICE_NEXT_CQ_BD; |
| 1559 | u32 cq_type; |
| 1560 | |
| 1561 | while (done == SERVICE_NEXT_CQ_BD) { |
| 1562 | cmp = (struct cmpl_base *)BD_NOW(bp->cq.bd_virt, |
| 1563 | bp->cq.cons_idx, |
| 1564 | sizeof(struct cmpl_base)); |
| 1565 | if ((cmp->info3_v & CMPL_BASE_V) ^ bp->cq.completion_bit) |
| 1566 | break; |
| 1567 | |
| 1568 | cq_type = cmp->type & CMPL_BASE_TYPE_MASK; |
| 1569 | dump_evt((u8 *)cmp, cq_type, bp->cq.cons_idx); |
| 1570 | dump_CQ(cmp, bp->cq.cons_idx); |
| 1571 | switch (cq_type) { |
| 1572 | case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT: |
| 1573 | bnxt_link_evt(bp, cmp); |
| 1574 | fallthrough; |
| 1575 | case CMPL_BASE_TYPE_TX_L2: |
| 1576 | case CMPL_BASE_TYPE_STAT_EJECT: |
| 1577 | bnxt_adv_cq_index(bp, 1); |
| 1578 | break; |
| 1579 | case CMPL_BASE_TYPE_RX_L2: |
| 1580 | done = bnxt_rx_complete(bp, (struct rx_pkt_cmpl *)cmp); |
| 1581 | break; |
| 1582 | default: |
| 1583 | done = NO_MORE_CQ_BD_TO_SERVICE; |
| 1584 | break; |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | if (bp->cq.cons_idx != old_cons_idx) |
| 1589 | bnxt_db_cq(bp); |
| 1590 | |
| 1591 | if (bp->rx.iob_recv == PKT_RECEIVED) { |
| 1592 | *packetp = bp->rx.iob_rx; |
| 1593 | return bp->rx.iob_len; |
| 1594 | } |
| 1595 | |
| 1596 | return -EAGAIN; |
| 1597 | } |
| 1598 | |
| 1599 | static void bnxt_stop(struct udevice *dev) |
| 1600 | { |
| 1601 | struct bnxt *bp = dev_get_priv(dev); |
| 1602 | |
| 1603 | if (bp->card_en) { |
| 1604 | bnxt_hwrm_set_rx_mask(bp, 0); |
| 1605 | bp->card_en = false; |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | static int bnxt_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 1610 | { |
| 1611 | struct bnxt *bp = dev_get_priv(dev); |
| 1612 | |
| 1613 | dbg_rx_pkt(bp, __func__, packet, length); |
| 1614 | bp->rx.iob_recv = PKT_DONE; |
| 1615 | bp->rx.iob_len = 0; |
| 1616 | bp->rx.iob_rx = NULL; |
| 1617 | |
| 1618 | return 0; |
| 1619 | } |
| 1620 | |
| 1621 | static int bnxt_read_rom_hwaddr(struct udevice *dev) |
| 1622 | { |
| 1623 | struct eth_pdata *plat = dev_get_plat(dev); |
| 1624 | struct bnxt *bp = dev_get_priv(dev); |
| 1625 | |
| 1626 | memcpy(plat->enetaddr, bp->mac_set, ETH_ALEN); |
| 1627 | |
| 1628 | return 0; |
| 1629 | } |
| 1630 | |
| 1631 | static const struct eth_ops bnxt_eth_ops = { |
| 1632 | .start = bnxt_start, |
| 1633 | .send = bnxt_send, |
| 1634 | .recv = bnxt_recv, |
| 1635 | .stop = bnxt_stop, |
| 1636 | .free_pkt = bnxt_free_pkt, |
| 1637 | .read_rom_hwaddr = bnxt_read_rom_hwaddr, |
| 1638 | }; |
| 1639 | |
| 1640 | static const struct udevice_id bnxt_eth_ids[] = { |
| 1641 | { .compatible = "broadcom,nxe" }, |
| 1642 | { } |
| 1643 | }; |
| 1644 | |
| 1645 | static int bnxt_eth_bind(struct udevice *dev) |
| 1646 | { |
| 1647 | char name[20]; |
| 1648 | |
| 1649 | sprintf(name, "bnxt_eth%u", dev_seq(dev)); |
| 1650 | |
| 1651 | return device_set_name(dev, name); |
| 1652 | } |
| 1653 | |
| 1654 | static int bnxt_eth_probe(struct udevice *dev) |
| 1655 | { |
| 1656 | struct bnxt *bp = dev_get_priv(dev); |
| 1657 | int ret; |
| 1658 | |
| 1659 | ret = bnxt_alloc_mem(bp); |
| 1660 | if (ret) { |
| 1661 | printf("*** error: bnxt_alloc_mem failed! ***\n"); |
| 1662 | return ret; |
| 1663 | } |
| 1664 | |
| 1665 | bp->cardnum = dev_seq(dev); |
| 1666 | bp->name = dev->name; |
| 1667 | bp->pdev = (struct udevice *)dev; |
| 1668 | |
| 1669 | bnxt_bring_pci(bp); |
| 1670 | |
| 1671 | ret = bnxt_bring_chip(bp); |
| 1672 | if (ret) { |
| 1673 | printf("*** error: bnxt_bring_chip failed! ***\n"); |
| 1674 | return -ENODATA; |
| 1675 | } |
| 1676 | |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
| 1680 | static int bnxt_eth_remove(struct udevice *dev) |
| 1681 | { |
| 1682 | struct bnxt *bp = dev_get_priv(dev); |
| 1683 | |
| 1684 | bnxt_down_chip(bp); |
| 1685 | bnxt_free_mem(bp); |
| 1686 | |
| 1687 | return 0; |
| 1688 | } |
| 1689 | |
| 1690 | static struct pci_device_id bnxt_nics[] = { |
| 1691 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NXT_57320)}, |
| 1692 | {} |
| 1693 | }; |
| 1694 | |
| 1695 | U_BOOT_DRIVER(eth_bnxt) = { |
| 1696 | .name = "eth_bnxt", |
| 1697 | .id = UCLASS_ETH, |
| 1698 | .of_match = bnxt_eth_ids, |
| 1699 | .bind = bnxt_eth_bind, |
| 1700 | .probe = bnxt_eth_probe, |
| 1701 | .remove = bnxt_eth_remove, |
| 1702 | .ops = &bnxt_eth_ops, |
| 1703 | .priv_auto = sizeof(struct bnxt), |
| 1704 | .plat_auto = sizeof(struct eth_pdata), |
| 1705 | .flags = DM_FLAG_ACTIVE_DMA, |
| 1706 | }; |
| 1707 | |
| 1708 | U_BOOT_PCI_DEVICE(eth_bnxt, bnxt_nics); |