1 /*-
2 * Broadcom NetXtreme-C/E network driver.
3 *
4 * Copyright (c) 2024 Broadcom, All Rights Reserved.
5 * The term Broadcom refers to Broadcom Limited and/or its subsidiaries
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef BNXT_ULP_H
30 #define BNXT_ULP_H
31
32 #include <linux/rcupdate.h>
33 #include "bnxt.h"
34
35 #define BNXT_ROCE_ULP 0
36 #define BNXT_OTHER_ULP 1
37 #define BNXT_MAX_ULP 2
38
39 #define BNXT_MIN_ROCE_CP_RINGS 2
40 #define BNXT_MIN_ROCE_STAT_CTXS 1
41
42 struct hwrm_async_event_cmpl;
43 struct bnxt_softc;
44 struct bnxt_bar_info;
45
46 struct bnxt_msix_entry {
47 uint32_t vector;
48 uint32_t ring_idx;
49 uint32_t db_offset;
50 };
51
52 struct bnxt_ulp_ops {
53 void (*ulp_async_notifier)(void *, struct hwrm_async_event_cmpl *);
54 void (*ulp_stop)(void *);
55 void (*ulp_start)(void *);
56 void (*ulp_sriov_config)(void *, int);
57 void (*ulp_shutdown)(void *);
58 void (*ulp_irq_stop)(void *);
59 void (*ulp_irq_restart)(void *, struct bnxt_msix_entry *);
60 };
61
62 struct bnxt_fw_msg {
63 void *msg;
64 int msg_len;
65 void *resp;
66 int resp_max_len;
67 int timeout;
68 };
69
70 struct bnxt_ulp {
71 void *handle;
72 struct bnxt_ulp_ops __rcu *ulp_ops;
73 unsigned long *async_events_bmap;
74 u16 max_async_event_id;
75 u16 msix_requested;
76 u16 msix_base;
77 atomic_t ref_count;
78 };
79
80 struct bnxt_en_dev {
81 struct ifnet *net;
82 struct pci_dev *pdev;
83 struct bnxt_softc *softc;
84 u32 flags;
85 #define BNXT_EN_FLAG_ROCEV1_CAP 0x1
86 #define BNXT_EN_FLAG_ROCEV2_CAP 0x2
87 #define BNXT_EN_FLAG_ROCE_CAP (BNXT_EN_FLAG_ROCEV1_CAP | \
88 BNXT_EN_FLAG_ROCEV2_CAP)
89 #define BNXT_EN_FLAG_MSIX_REQUESTED 0x4
90 #define BNXT_EN_FLAG_ULP_STOPPED 0x8
91 #define BNXT_EN_FLAG_ASYM_Q 0x10
92 #define BNXT_EN_FLAG_MULTI_HOST 0x20
93 #define BNXT_EN_FLAG_SW_RES_LMT 0x400
94 #define BNXT_EN_ASYM_Q(edev) ((edev)->flags & BNXT_EN_FLAG_ASYM_Q)
95 #define BNXT_EN_MH(edev) ((edev)->flags & BNXT_EN_FLAG_MULTI_HOST)
96 #define BNXT_EN_SW_RES_LMT(edev) ((edev)->flags & BNXT_EN_FLAG_SW_RES_LMT)
97 const struct bnxt_en_ops *en_ops;
98 struct bnxt_ulp ulp_tbl[BNXT_MAX_ULP];
99 int l2_db_offset; /* Doorbell BAR offset
100 * of non-cacheable.
101 */
102 int l2_db_size; /* Doorbell BAR size in
103 * bytes mapped by L2
104 * driver.
105 */
106 int l2_db_size_nc; /* Doorbell BAR size in
107 * bytes mapped as non-
108 * cacheable.
109 */
110 u32 ulp_version; /* bnxt_re checks the
111 * ulp_version is correct
112 * to ensure compatibility
113 * with bnxt_en.
114 */
115 #define BNXT_ULP_VERSION 0x695a0008 /* Change this when any interface
116 * structure or API changes
117 * between bnxt_en and bnxt_re.
118 */
119 unsigned long en_state;
120 void __iomem *bar0;
121 u16 hw_ring_stats_size;
122 u16 pf_port_id;
123 u8 port_partition_type;
124 #define BNXT_EN_NPAR(edev) ((edev)->port_partition_type)
125 u8 port_count;
126 struct bnxt_dbr *en_dbr;
127 struct bnxt_bar_info hwrm_bar;
128 u32 espeed;
129 uint8_t lanes;
130 #define BNXT_VPD_PN_FLD_LEN 32
131 char board_part_number[BNXT_VPD_PN_FLD_LEN];
132 };
133
134 struct bnxt_en_ops {
135 int (*bnxt_register_device)(struct bnxt_en_dev *, int,
136 struct bnxt_ulp_ops *, void *);
137 int (*bnxt_unregister_device)(struct bnxt_en_dev *, int);
138 int (*bnxt_request_msix)(struct bnxt_en_dev *, int,
139 struct bnxt_msix_entry *, int);
140 int (*bnxt_free_msix)(struct bnxt_en_dev *, int);
141 int (*bnxt_send_fw_msg)(struct bnxt_en_dev *, int,
142 struct bnxt_fw_msg *);
143 int (*bnxt_register_fw_async_events)(struct bnxt_en_dev *, int,
144 unsigned long *, u16);
145 int (*bnxt_dbr_complete)(struct bnxt_en_dev *, int, u32);
146 };
147
bnxt_ulp_registered(struct bnxt_en_dev * edev,int ulp_id)148 static inline bool bnxt_ulp_registered(struct bnxt_en_dev *edev, int ulp_id)
149 {
150 if (edev && rcu_access_pointer(edev->ulp_tbl[ulp_id].ulp_ops))
151 return true;
152 return false;
153 }
154
155 int bnxt_get_ulp_msix_num(struct bnxt_softc *bp);
156 int bnxt_get_ulp_msix_base(struct bnxt_softc *bp);
157 int bnxt_get_ulp_stat_ctxs(struct bnxt_softc *bp);
158 void bnxt_ulp_stop(struct bnxt_softc *bp);
159 void bnxt_ulp_start(struct bnxt_softc *bp, int err);
160 void bnxt_ulp_sriov_cfg(struct bnxt_softc *bp, int num_vfs);
161 void bnxt_ulp_shutdown(struct bnxt_softc *bp);
162 void bnxt_ulp_irq_stop(struct bnxt_softc *bp);
163 void bnxt_ulp_irq_restart(struct bnxt_softc *bp, int err);
164 void bnxt_ulp_async_events(struct bnxt_softc *bp, struct hwrm_async_event_cmpl *cmpl);
165 struct bnxt_en_dev *bnxt_ulp_probe(struct net_device *dev);
166 void bnxt_aux_dev_release(struct device *dev);
167 int bnxt_rdma_aux_device_add(struct bnxt_softc *bp);
168 int bnxt_rdma_aux_device_del(struct bnxt_softc *bp);
169 #endif
170