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