Deleted Added
full compact
qlnx_os.c (319449) qlnx_os.c (320164)
1/*
2 * Copyright (c) 2017-2018 Cavium, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29/*
30 * File: qlnx_os.c
31 * Author : David C Somayajulu, Cavium, Inc., San Jose, CA 95131.
32 */
33
34#include <sys/cdefs.h>
1/*
2 * Copyright (c) 2017-2018 Cavium, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29/*
30 * File: qlnx_os.c
31 * Author : David C Somayajulu, Cavium, Inc., San Jose, CA 95131.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: stable/11/sys/dev/qlnx/qlnxe/qlnx_os.c 319449 2017-06-01 18:35:04Z davidcs $");
35__FBSDID("$FreeBSD: stable/11/sys/dev/qlnx/qlnxe/qlnx_os.c 320164 2017-06-20 19:16:06Z davidcs $");
36
37#include "qlnx_os.h"
38#include "bcm_osal.h"
39#include "reg_addr.h"
40#include "ecore_gtt_reg_addr.h"
41#include "ecore.h"
42#include "ecore_chain.h"
43#include "ecore_status.h"
44#include "ecore_hw.h"
45#include "ecore_rt_defs.h"
46#include "ecore_init_ops.h"
47#include "ecore_int.h"
48#include "ecore_cxt.h"
49#include "ecore_spq.h"
50#include "ecore_init_fw_funcs.h"
51#include "ecore_sp_commands.h"
52#include "ecore_dev_api.h"
53#include "ecore_l2_api.h"
54#include "ecore_mcp.h"
55#include "ecore_hw_defs.h"
56#include "mcp_public.h"
57#include "ecore_iro.h"
58#include "nvm_cfg.h"
59#include "ecore_dev_api.h"
60#include "ecore_dbg_fw_funcs.h"
61
62#include "qlnx_ioctl.h"
63#include "qlnx_def.h"
64#include "qlnx_ver.h"
65#include <sys/smp.h>
66
67
68/*
69 * static functions
70 */
71/*
72 * ioctl related functions
73 */
74static void qlnx_add_sysctls(qlnx_host_t *ha);
75
76/*
77 * main driver
78 */
79static void qlnx_release(qlnx_host_t *ha);
80static void qlnx_fp_isr(void *arg);
81static void qlnx_init_ifnet(device_t dev, qlnx_host_t *ha);
82static void qlnx_init(void *arg);
83static void qlnx_init_locked(qlnx_host_t *ha);
84static int qlnx_set_multi(qlnx_host_t *ha, uint32_t add_multi);
85static int qlnx_set_promisc(qlnx_host_t *ha);
86static int qlnx_set_allmulti(qlnx_host_t *ha);
87static int qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
88static int qlnx_media_change(struct ifnet *ifp);
89static void qlnx_media_status(struct ifnet *ifp, struct ifmediareq *ifmr);
90static void qlnx_stop(qlnx_host_t *ha);
91static int qlnx_send(qlnx_host_t *ha, struct qlnx_fastpath *fp,
92 struct mbuf **m_headp);
93static int qlnx_get_ifq_snd_maxlen(qlnx_host_t *ha);
94static uint32_t qlnx_get_optics(qlnx_host_t *ha,
95 struct qlnx_link_output *if_link);
96static int qlnx_transmit(struct ifnet *ifp, struct mbuf *mp);
97static void qlnx_qflush(struct ifnet *ifp);
98
99static int qlnx_alloc_parent_dma_tag(qlnx_host_t *ha);
100static void qlnx_free_parent_dma_tag(qlnx_host_t *ha);
101static int qlnx_alloc_tx_dma_tag(qlnx_host_t *ha);
102static void qlnx_free_tx_dma_tag(qlnx_host_t *ha);
103static int qlnx_alloc_rx_dma_tag(qlnx_host_t *ha);
104static void qlnx_free_rx_dma_tag(qlnx_host_t *ha);
105
106static int qlnx_get_mfw_version(qlnx_host_t *ha, uint32_t *mfw_ver);
107static int qlnx_get_flash_size(qlnx_host_t *ha, uint32_t *flash_size);
108
109static int qlnx_nic_setup(struct ecore_dev *cdev,
110 struct ecore_pf_params *func_params);
111static int qlnx_nic_start(struct ecore_dev *cdev);
112static int qlnx_slowpath_start(qlnx_host_t *ha);
113static int qlnx_slowpath_stop(qlnx_host_t *ha);
114static int qlnx_init_hw(qlnx_host_t *ha);
115static void qlnx_set_id(struct ecore_dev *cdev, char name[NAME_SIZE],
116 char ver_str[VER_SIZE]);
117static void qlnx_unload(qlnx_host_t *ha);
118static int qlnx_load(qlnx_host_t *ha);
119static void qlnx_hw_set_multi(qlnx_host_t *ha, uint8_t *mta, uint32_t mcnt,
120 uint32_t add_mac);
121static void qlnx_dump_buf8(qlnx_host_t *ha, const char *msg, void *dbuf,
122 uint32_t len);
123static int qlnx_alloc_rx_buffer(qlnx_host_t *ha, struct qlnx_rx_queue *rxq);
124static void qlnx_reuse_rx_data(struct qlnx_rx_queue *rxq);
125static void qlnx_update_rx_prod(struct ecore_hwfn *p_hwfn,
126 struct qlnx_rx_queue *rxq);
127static int qlnx_set_rx_accept_filter(qlnx_host_t *ha, uint8_t filter);
128static int qlnx_grc_dumpsize(qlnx_host_t *ha, uint32_t *num_dwords,
129 int hwfn_index);
130static int qlnx_idle_chk_size(qlnx_host_t *ha, uint32_t *num_dwords,
131 int hwfn_index);
132static void qlnx_timer(void *arg);
133static int qlnx_alloc_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp);
134static void qlnx_free_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp);
135static void qlnx_trigger_dump(qlnx_host_t *ha);
136static void qlnx_tx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp,
137 struct qlnx_tx_queue *txq);
138static int qlnx_rx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp, int budget,
139 int lro_enable);
140static void qlnx_fp_taskqueue(void *context, int pending);
141static void qlnx_sample_storm_stats(qlnx_host_t *ha);
142static int qlnx_alloc_tpa_mbuf(qlnx_host_t *ha, uint16_t rx_buf_size,
143 struct qlnx_agg_info *tpa);
144static void qlnx_free_tpa_mbuf(qlnx_host_t *ha, struct qlnx_agg_info *tpa);
145
146#if __FreeBSD_version >= 1100000
147static uint64_t qlnx_get_counter(if_t ifp, ift_counter cnt);
148#endif
149
150
151/*
152 * Hooks to the Operating Systems
153 */
154static int qlnx_pci_probe (device_t);
155static int qlnx_pci_attach (device_t);
156static int qlnx_pci_detach (device_t);
157
158static device_method_t qlnx_pci_methods[] = {
159 /* Device interface */
160 DEVMETHOD(device_probe, qlnx_pci_probe),
161 DEVMETHOD(device_attach, qlnx_pci_attach),
162 DEVMETHOD(device_detach, qlnx_pci_detach),
163 { 0, 0 }
164};
165
166static driver_t qlnx_pci_driver = {
167 "ql", qlnx_pci_methods, sizeof (qlnx_host_t),
168};
169
170static devclass_t qlnx_devclass;
171
172MODULE_VERSION(if_qlnxe,1);
173DRIVER_MODULE(if_qlnxe, pci, qlnx_pci_driver, qlnx_devclass, 0, 0);
174
175MODULE_DEPEND(if_qlnxe, pci, 1, 1, 1);
176MODULE_DEPEND(if_qlnxe, ether, 1, 1, 1);
177
178MALLOC_DEFINE(M_QLNXBUF, "qlnxbuf", "Buffers for qlnx driver");
179
180
181char qlnx_dev_str[64];
182char qlnx_ver_str[VER_SIZE];
183char qlnx_name_str[NAME_SIZE];
184
185/*
186 * Some PCI Configuration Space Related Defines
187 */
188
189#ifndef PCI_VENDOR_QLOGIC
190#define PCI_VENDOR_QLOGIC 0x1077
191#endif
192
193/* 40G Adapter QLE45xxx*/
194#ifndef QLOGIC_PCI_DEVICE_ID_1634
195#define QLOGIC_PCI_DEVICE_ID_1634 0x1634
196#endif
197
198/* 100G Adapter QLE45xxx*/
199#ifndef QLOGIC_PCI_DEVICE_ID_1644
200#define QLOGIC_PCI_DEVICE_ID_1644 0x1644
201#endif
202
203/* 25G Adapter QLE45xxx*/
204#ifndef QLOGIC_PCI_DEVICE_ID_1656
205#define QLOGIC_PCI_DEVICE_ID_1656 0x1656
206#endif
207
208/* 50G Adapter QLE45xxx*/
209#ifndef QLOGIC_PCI_DEVICE_ID_1654
210#define QLOGIC_PCI_DEVICE_ID_1654 0x1654
211#endif
212
36
37#include "qlnx_os.h"
38#include "bcm_osal.h"
39#include "reg_addr.h"
40#include "ecore_gtt_reg_addr.h"
41#include "ecore.h"
42#include "ecore_chain.h"
43#include "ecore_status.h"
44#include "ecore_hw.h"
45#include "ecore_rt_defs.h"
46#include "ecore_init_ops.h"
47#include "ecore_int.h"
48#include "ecore_cxt.h"
49#include "ecore_spq.h"
50#include "ecore_init_fw_funcs.h"
51#include "ecore_sp_commands.h"
52#include "ecore_dev_api.h"
53#include "ecore_l2_api.h"
54#include "ecore_mcp.h"
55#include "ecore_hw_defs.h"
56#include "mcp_public.h"
57#include "ecore_iro.h"
58#include "nvm_cfg.h"
59#include "ecore_dev_api.h"
60#include "ecore_dbg_fw_funcs.h"
61
62#include "qlnx_ioctl.h"
63#include "qlnx_def.h"
64#include "qlnx_ver.h"
65#include <sys/smp.h>
66
67
68/*
69 * static functions
70 */
71/*
72 * ioctl related functions
73 */
74static void qlnx_add_sysctls(qlnx_host_t *ha);
75
76/*
77 * main driver
78 */
79static void qlnx_release(qlnx_host_t *ha);
80static void qlnx_fp_isr(void *arg);
81static void qlnx_init_ifnet(device_t dev, qlnx_host_t *ha);
82static void qlnx_init(void *arg);
83static void qlnx_init_locked(qlnx_host_t *ha);
84static int qlnx_set_multi(qlnx_host_t *ha, uint32_t add_multi);
85static int qlnx_set_promisc(qlnx_host_t *ha);
86static int qlnx_set_allmulti(qlnx_host_t *ha);
87static int qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
88static int qlnx_media_change(struct ifnet *ifp);
89static void qlnx_media_status(struct ifnet *ifp, struct ifmediareq *ifmr);
90static void qlnx_stop(qlnx_host_t *ha);
91static int qlnx_send(qlnx_host_t *ha, struct qlnx_fastpath *fp,
92 struct mbuf **m_headp);
93static int qlnx_get_ifq_snd_maxlen(qlnx_host_t *ha);
94static uint32_t qlnx_get_optics(qlnx_host_t *ha,
95 struct qlnx_link_output *if_link);
96static int qlnx_transmit(struct ifnet *ifp, struct mbuf *mp);
97static void qlnx_qflush(struct ifnet *ifp);
98
99static int qlnx_alloc_parent_dma_tag(qlnx_host_t *ha);
100static void qlnx_free_parent_dma_tag(qlnx_host_t *ha);
101static int qlnx_alloc_tx_dma_tag(qlnx_host_t *ha);
102static void qlnx_free_tx_dma_tag(qlnx_host_t *ha);
103static int qlnx_alloc_rx_dma_tag(qlnx_host_t *ha);
104static void qlnx_free_rx_dma_tag(qlnx_host_t *ha);
105
106static int qlnx_get_mfw_version(qlnx_host_t *ha, uint32_t *mfw_ver);
107static int qlnx_get_flash_size(qlnx_host_t *ha, uint32_t *flash_size);
108
109static int qlnx_nic_setup(struct ecore_dev *cdev,
110 struct ecore_pf_params *func_params);
111static int qlnx_nic_start(struct ecore_dev *cdev);
112static int qlnx_slowpath_start(qlnx_host_t *ha);
113static int qlnx_slowpath_stop(qlnx_host_t *ha);
114static int qlnx_init_hw(qlnx_host_t *ha);
115static void qlnx_set_id(struct ecore_dev *cdev, char name[NAME_SIZE],
116 char ver_str[VER_SIZE]);
117static void qlnx_unload(qlnx_host_t *ha);
118static int qlnx_load(qlnx_host_t *ha);
119static void qlnx_hw_set_multi(qlnx_host_t *ha, uint8_t *mta, uint32_t mcnt,
120 uint32_t add_mac);
121static void qlnx_dump_buf8(qlnx_host_t *ha, const char *msg, void *dbuf,
122 uint32_t len);
123static int qlnx_alloc_rx_buffer(qlnx_host_t *ha, struct qlnx_rx_queue *rxq);
124static void qlnx_reuse_rx_data(struct qlnx_rx_queue *rxq);
125static void qlnx_update_rx_prod(struct ecore_hwfn *p_hwfn,
126 struct qlnx_rx_queue *rxq);
127static int qlnx_set_rx_accept_filter(qlnx_host_t *ha, uint8_t filter);
128static int qlnx_grc_dumpsize(qlnx_host_t *ha, uint32_t *num_dwords,
129 int hwfn_index);
130static int qlnx_idle_chk_size(qlnx_host_t *ha, uint32_t *num_dwords,
131 int hwfn_index);
132static void qlnx_timer(void *arg);
133static int qlnx_alloc_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp);
134static void qlnx_free_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp);
135static void qlnx_trigger_dump(qlnx_host_t *ha);
136static void qlnx_tx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp,
137 struct qlnx_tx_queue *txq);
138static int qlnx_rx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp, int budget,
139 int lro_enable);
140static void qlnx_fp_taskqueue(void *context, int pending);
141static void qlnx_sample_storm_stats(qlnx_host_t *ha);
142static int qlnx_alloc_tpa_mbuf(qlnx_host_t *ha, uint16_t rx_buf_size,
143 struct qlnx_agg_info *tpa);
144static void qlnx_free_tpa_mbuf(qlnx_host_t *ha, struct qlnx_agg_info *tpa);
145
146#if __FreeBSD_version >= 1100000
147static uint64_t qlnx_get_counter(if_t ifp, ift_counter cnt);
148#endif
149
150
151/*
152 * Hooks to the Operating Systems
153 */
154static int qlnx_pci_probe (device_t);
155static int qlnx_pci_attach (device_t);
156static int qlnx_pci_detach (device_t);
157
158static device_method_t qlnx_pci_methods[] = {
159 /* Device interface */
160 DEVMETHOD(device_probe, qlnx_pci_probe),
161 DEVMETHOD(device_attach, qlnx_pci_attach),
162 DEVMETHOD(device_detach, qlnx_pci_detach),
163 { 0, 0 }
164};
165
166static driver_t qlnx_pci_driver = {
167 "ql", qlnx_pci_methods, sizeof (qlnx_host_t),
168};
169
170static devclass_t qlnx_devclass;
171
172MODULE_VERSION(if_qlnxe,1);
173DRIVER_MODULE(if_qlnxe, pci, qlnx_pci_driver, qlnx_devclass, 0, 0);
174
175MODULE_DEPEND(if_qlnxe, pci, 1, 1, 1);
176MODULE_DEPEND(if_qlnxe, ether, 1, 1, 1);
177
178MALLOC_DEFINE(M_QLNXBUF, "qlnxbuf", "Buffers for qlnx driver");
179
180
181char qlnx_dev_str[64];
182char qlnx_ver_str[VER_SIZE];
183char qlnx_name_str[NAME_SIZE];
184
185/*
186 * Some PCI Configuration Space Related Defines
187 */
188
189#ifndef PCI_VENDOR_QLOGIC
190#define PCI_VENDOR_QLOGIC 0x1077
191#endif
192
193/* 40G Adapter QLE45xxx*/
194#ifndef QLOGIC_PCI_DEVICE_ID_1634
195#define QLOGIC_PCI_DEVICE_ID_1634 0x1634
196#endif
197
198/* 100G Adapter QLE45xxx*/
199#ifndef QLOGIC_PCI_DEVICE_ID_1644
200#define QLOGIC_PCI_DEVICE_ID_1644 0x1644
201#endif
202
203/* 25G Adapter QLE45xxx*/
204#ifndef QLOGIC_PCI_DEVICE_ID_1656
205#define QLOGIC_PCI_DEVICE_ID_1656 0x1656
206#endif
207
208/* 50G Adapter QLE45xxx*/
209#ifndef QLOGIC_PCI_DEVICE_ID_1654
210#define QLOGIC_PCI_DEVICE_ID_1654 0x1654
211#endif
212
213/* 10G/25G/40G Adapter QLE41xxx*/
214#ifndef QLOGIC_PCI_DEVICE_ID_8070
215#define QLOGIC_PCI_DEVICE_ID_8070 0x8070
216#endif
217
213static int
214qlnx_valid_device(device_t dev)
215{
216 uint16_t device_id;
217
218 device_id = pci_get_device(dev);
219
220 if ((device_id == QLOGIC_PCI_DEVICE_ID_1634) ||
221 (device_id == QLOGIC_PCI_DEVICE_ID_1644) ||
222 (device_id == QLOGIC_PCI_DEVICE_ID_1656) ||
218static int
219qlnx_valid_device(device_t dev)
220{
221 uint16_t device_id;
222
223 device_id = pci_get_device(dev);
224
225 if ((device_id == QLOGIC_PCI_DEVICE_ID_1634) ||
226 (device_id == QLOGIC_PCI_DEVICE_ID_1644) ||
227 (device_id == QLOGIC_PCI_DEVICE_ID_1656) ||
223 (device_id == QLOGIC_PCI_DEVICE_ID_1654))
228 (device_id == QLOGIC_PCI_DEVICE_ID_1654) ||
229 (device_id == QLOGIC_PCI_DEVICE_ID_8070))
224 return 0;
225
226 return -1;
227}
228
229/*
230 * Name: qlnx_pci_probe
231 * Function: Validate the PCI device to be a QLA80XX device
232 */
233static int
234qlnx_pci_probe(device_t dev)
235{
236 snprintf(qlnx_ver_str, sizeof(qlnx_ver_str), "v%d.%d.%d",
237 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR, QLNX_VERSION_BUILD);
238 snprintf(qlnx_name_str, sizeof(qlnx_name_str), "qlnx");
239
240 if (pci_get_vendor(dev) != PCI_VENDOR_QLOGIC) {
241 return (ENXIO);
242 }
243
244 switch (pci_get_device(dev)) {
245
246 case QLOGIC_PCI_DEVICE_ID_1644:
247 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
248 "Qlogic 100GbE PCI CNA Adapter-Ethernet Function",
249 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
250 QLNX_VERSION_BUILD);
251 device_set_desc_copy(dev, qlnx_dev_str);
252
253 break;
254
255 case QLOGIC_PCI_DEVICE_ID_1634:
256 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
257 "Qlogic 40GbE PCI CNA Adapter-Ethernet Function",
258 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
259 QLNX_VERSION_BUILD);
260 device_set_desc_copy(dev, qlnx_dev_str);
261
262 break;
263
264 case QLOGIC_PCI_DEVICE_ID_1656:
265 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
266 "Qlogic 25GbE PCI CNA Adapter-Ethernet Function",
267 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
268 QLNX_VERSION_BUILD);
269 device_set_desc_copy(dev, qlnx_dev_str);
270
271 break;
272
273 case QLOGIC_PCI_DEVICE_ID_1654:
274 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
275 "Qlogic 50GbE PCI CNA Adapter-Ethernet Function",
276 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
277 QLNX_VERSION_BUILD);
278 device_set_desc_copy(dev, qlnx_dev_str);
279
280 break;
281
230 return 0;
231
232 return -1;
233}
234
235/*
236 * Name: qlnx_pci_probe
237 * Function: Validate the PCI device to be a QLA80XX device
238 */
239static int
240qlnx_pci_probe(device_t dev)
241{
242 snprintf(qlnx_ver_str, sizeof(qlnx_ver_str), "v%d.%d.%d",
243 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR, QLNX_VERSION_BUILD);
244 snprintf(qlnx_name_str, sizeof(qlnx_name_str), "qlnx");
245
246 if (pci_get_vendor(dev) != PCI_VENDOR_QLOGIC) {
247 return (ENXIO);
248 }
249
250 switch (pci_get_device(dev)) {
251
252 case QLOGIC_PCI_DEVICE_ID_1644:
253 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
254 "Qlogic 100GbE PCI CNA Adapter-Ethernet Function",
255 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
256 QLNX_VERSION_BUILD);
257 device_set_desc_copy(dev, qlnx_dev_str);
258
259 break;
260
261 case QLOGIC_PCI_DEVICE_ID_1634:
262 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
263 "Qlogic 40GbE PCI CNA Adapter-Ethernet Function",
264 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
265 QLNX_VERSION_BUILD);
266 device_set_desc_copy(dev, qlnx_dev_str);
267
268 break;
269
270 case QLOGIC_PCI_DEVICE_ID_1656:
271 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
272 "Qlogic 25GbE PCI CNA Adapter-Ethernet Function",
273 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
274 QLNX_VERSION_BUILD);
275 device_set_desc_copy(dev, qlnx_dev_str);
276
277 break;
278
279 case QLOGIC_PCI_DEVICE_ID_1654:
280 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
281 "Qlogic 50GbE PCI CNA Adapter-Ethernet Function",
282 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
283 QLNX_VERSION_BUILD);
284 device_set_desc_copy(dev, qlnx_dev_str);
285
286 break;
287
288 case QLOGIC_PCI_DEVICE_ID_8070:
289 snprintf(qlnx_dev_str, sizeof(qlnx_dev_str), "%s v%d.%d.%d",
290 "Qlogic 10GbE/25GbE/40GbE PCI CNA (AH) "
291 "Adapter-Ethernet Function",
292 QLNX_VERSION_MAJOR, QLNX_VERSION_MINOR,
293 QLNX_VERSION_BUILD);
294 device_set_desc_copy(dev, qlnx_dev_str);
295
296 break;
297
282 default:
283 return (ENXIO);
284 }
285
286 return (BUS_PROBE_DEFAULT);
287}
288
289
290static void
291qlnx_sp_intr(void *arg)
292{
293 struct ecore_hwfn *p_hwfn;
294 qlnx_host_t *ha;
295 int i;
296
297 p_hwfn = arg;
298
299 if (p_hwfn == NULL) {
300 printf("%s: spurious slowpath intr\n", __func__);
301 return;
302 }
303
304 ha = (qlnx_host_t *)p_hwfn->p_dev;
305
306 QL_DPRINT2(ha, "enter\n");
307
308 for (i = 0; i < ha->cdev.num_hwfns; i++) {
309 if (&ha->cdev.hwfns[i] == p_hwfn) {
310 taskqueue_enqueue(ha->sp_taskqueue[i], &ha->sp_task[i]);
311 break;
312 }
313 }
314 QL_DPRINT2(ha, "exit\n");
315
316 return;
317}
318
319static void
320qlnx_sp_taskqueue(void *context, int pending)
321{
322 struct ecore_hwfn *p_hwfn;
323
324 p_hwfn = context;
325
326 if (p_hwfn != NULL) {
327 qlnx_sp_isr(p_hwfn);
328 }
329 return;
330}
331
332static int
333qlnx_create_sp_taskqueues(qlnx_host_t *ha)
334{
335 int i;
336 uint8_t tq_name[32];
337
338 for (i = 0; i < ha->cdev.num_hwfns; i++) {
339
340 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[i];
341
342 bzero(tq_name, sizeof (tq_name));
343 snprintf(tq_name, sizeof (tq_name), "ql_sp_tq_%d", i);
344
345 TASK_INIT(&ha->sp_task[i], 0, qlnx_sp_taskqueue, p_hwfn);
346
347 ha->sp_taskqueue[i] = taskqueue_create_fast(tq_name, M_NOWAIT,
348 taskqueue_thread_enqueue, &ha->sp_taskqueue[i]);
349
350 if (ha->sp_taskqueue[i] == NULL)
351 return (-1);
352
353 taskqueue_start_threads(&ha->sp_taskqueue[i], 1, PI_NET, "%s",
354 tq_name);
355
356 QL_DPRINT1(ha, "%p\n", ha->sp_taskqueue[i]);
357 }
358
359 return (0);
360}
361
362static void
363qlnx_destroy_sp_taskqueues(qlnx_host_t *ha)
364{
365 int i;
366
367 for (i = 0; i < ha->cdev.num_hwfns; i++) {
368 if (ha->sp_taskqueue[i] != NULL) {
369 taskqueue_drain(ha->sp_taskqueue[i], &ha->sp_task[i]);
370 taskqueue_free(ha->sp_taskqueue[i]);
371 }
372 }
373 return;
374}
375
376static void
377qlnx_fp_taskqueue(void *context, int pending)
378{
379 struct qlnx_fastpath *fp;
380 qlnx_host_t *ha;
381 struct ifnet *ifp;
382 struct mbuf *mp;
383 int ret;
298 default:
299 return (ENXIO);
300 }
301
302 return (BUS_PROBE_DEFAULT);
303}
304
305
306static void
307qlnx_sp_intr(void *arg)
308{
309 struct ecore_hwfn *p_hwfn;
310 qlnx_host_t *ha;
311 int i;
312
313 p_hwfn = arg;
314
315 if (p_hwfn == NULL) {
316 printf("%s: spurious slowpath intr\n", __func__);
317 return;
318 }
319
320 ha = (qlnx_host_t *)p_hwfn->p_dev;
321
322 QL_DPRINT2(ha, "enter\n");
323
324 for (i = 0; i < ha->cdev.num_hwfns; i++) {
325 if (&ha->cdev.hwfns[i] == p_hwfn) {
326 taskqueue_enqueue(ha->sp_taskqueue[i], &ha->sp_task[i]);
327 break;
328 }
329 }
330 QL_DPRINT2(ha, "exit\n");
331
332 return;
333}
334
335static void
336qlnx_sp_taskqueue(void *context, int pending)
337{
338 struct ecore_hwfn *p_hwfn;
339
340 p_hwfn = context;
341
342 if (p_hwfn != NULL) {
343 qlnx_sp_isr(p_hwfn);
344 }
345 return;
346}
347
348static int
349qlnx_create_sp_taskqueues(qlnx_host_t *ha)
350{
351 int i;
352 uint8_t tq_name[32];
353
354 for (i = 0; i < ha->cdev.num_hwfns; i++) {
355
356 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[i];
357
358 bzero(tq_name, sizeof (tq_name));
359 snprintf(tq_name, sizeof (tq_name), "ql_sp_tq_%d", i);
360
361 TASK_INIT(&ha->sp_task[i], 0, qlnx_sp_taskqueue, p_hwfn);
362
363 ha->sp_taskqueue[i] = taskqueue_create_fast(tq_name, M_NOWAIT,
364 taskqueue_thread_enqueue, &ha->sp_taskqueue[i]);
365
366 if (ha->sp_taskqueue[i] == NULL)
367 return (-1);
368
369 taskqueue_start_threads(&ha->sp_taskqueue[i], 1, PI_NET, "%s",
370 tq_name);
371
372 QL_DPRINT1(ha, "%p\n", ha->sp_taskqueue[i]);
373 }
374
375 return (0);
376}
377
378static void
379qlnx_destroy_sp_taskqueues(qlnx_host_t *ha)
380{
381 int i;
382
383 for (i = 0; i < ha->cdev.num_hwfns; i++) {
384 if (ha->sp_taskqueue[i] != NULL) {
385 taskqueue_drain(ha->sp_taskqueue[i], &ha->sp_task[i]);
386 taskqueue_free(ha->sp_taskqueue[i]);
387 }
388 }
389 return;
390}
391
392static void
393qlnx_fp_taskqueue(void *context, int pending)
394{
395 struct qlnx_fastpath *fp;
396 qlnx_host_t *ha;
397 struct ifnet *ifp;
398 struct mbuf *mp;
399 int ret;
384 int lro_enable, tc;
400 int lro_enable;
385 int rx_int = 0, total_rx_count = 0;
386 struct thread *cthread;
387
388 fp = context;
389
390 if (fp == NULL)
391 return;
392
393 cthread = curthread;
394
395 thread_lock(cthread);
396
397 if (!sched_is_bound(cthread))
398 sched_bind(cthread, fp->rss_id);
399
400 thread_unlock(cthread);
401
402 ha = (qlnx_host_t *)fp->edev;
403
404 ifp = ha->ifp;
405
406 lro_enable = ha->ifp->if_capenable & IFCAP_LRO;
407
408 rx_int = qlnx_rx_int(ha, fp, ha->rx_pkt_threshold, lro_enable);
409
410 if (rx_int) {
411 fp->rx_pkts += rx_int;
412 total_rx_count += rx_int;
413 }
414
415#ifdef QLNX_SOFT_LRO
416 {
417 struct lro_ctrl *lro;
418
419 lro = &fp->rxq->lro;
420
421 if (lro_enable && total_rx_count) {
422
423#if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
424
425 if (ha->dbg_trace_lro_cnt) {
426 if (lro->lro_mbuf_count & ~1023)
427 fp->lro_cnt_1024++;
428 else if (lro->lro_mbuf_count & ~511)
429 fp->lro_cnt_512++;
430 else if (lro->lro_mbuf_count & ~255)
431 fp->lro_cnt_256++;
432 else if (lro->lro_mbuf_count & ~127)
433 fp->lro_cnt_128++;
434 else if (lro->lro_mbuf_count & ~63)
435 fp->lro_cnt_64++;
436 }
437 tcp_lro_flush_all(lro);
438
439#else
440 struct lro_entry *queued;
441
442 while ((!SLIST_EMPTY(&lro->lro_active))) {
443 queued = SLIST_FIRST(&lro->lro_active);
444 SLIST_REMOVE_HEAD(&lro->lro_active, next);
445 tcp_lro_flush(lro, queued);
446 }
447#endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
448 }
449 }
450#endif /* #ifdef QLNX_SOFT_LRO */
451
452 ecore_sb_update_sb_idx(fp->sb_info);
453 rmb();
454
455 mtx_lock(&fp->tx_mtx);
456
457 if (((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
458 IFF_DRV_RUNNING) || (!ha->link_up)) {
459
460 mtx_unlock(&fp->tx_mtx);
461 goto qlnx_fp_taskqueue_exit;
462 }
463
401 int rx_int = 0, total_rx_count = 0;
402 struct thread *cthread;
403
404 fp = context;
405
406 if (fp == NULL)
407 return;
408
409 cthread = curthread;
410
411 thread_lock(cthread);
412
413 if (!sched_is_bound(cthread))
414 sched_bind(cthread, fp->rss_id);
415
416 thread_unlock(cthread);
417
418 ha = (qlnx_host_t *)fp->edev;
419
420 ifp = ha->ifp;
421
422 lro_enable = ha->ifp->if_capenable & IFCAP_LRO;
423
424 rx_int = qlnx_rx_int(ha, fp, ha->rx_pkt_threshold, lro_enable);
425
426 if (rx_int) {
427 fp->rx_pkts += rx_int;
428 total_rx_count += rx_int;
429 }
430
431#ifdef QLNX_SOFT_LRO
432 {
433 struct lro_ctrl *lro;
434
435 lro = &fp->rxq->lro;
436
437 if (lro_enable && total_rx_count) {
438
439#if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
440
441 if (ha->dbg_trace_lro_cnt) {
442 if (lro->lro_mbuf_count & ~1023)
443 fp->lro_cnt_1024++;
444 else if (lro->lro_mbuf_count & ~511)
445 fp->lro_cnt_512++;
446 else if (lro->lro_mbuf_count & ~255)
447 fp->lro_cnt_256++;
448 else if (lro->lro_mbuf_count & ~127)
449 fp->lro_cnt_128++;
450 else if (lro->lro_mbuf_count & ~63)
451 fp->lro_cnt_64++;
452 }
453 tcp_lro_flush_all(lro);
454
455#else
456 struct lro_entry *queued;
457
458 while ((!SLIST_EMPTY(&lro->lro_active))) {
459 queued = SLIST_FIRST(&lro->lro_active);
460 SLIST_REMOVE_HEAD(&lro->lro_active, next);
461 tcp_lro_flush(lro, queued);
462 }
463#endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
464 }
465 }
466#endif /* #ifdef QLNX_SOFT_LRO */
467
468 ecore_sb_update_sb_idx(fp->sb_info);
469 rmb();
470
471 mtx_lock(&fp->tx_mtx);
472
473 if (((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
474 IFF_DRV_RUNNING) || (!ha->link_up)) {
475
476 mtx_unlock(&fp->tx_mtx);
477 goto qlnx_fp_taskqueue_exit;
478 }
479
464 for (tc = 0; tc < ha->num_tc; tc++) {
465 (void)qlnx_tx_int(ha, fp, fp->txq[tc]);
466 }
480// for (tc = 0; tc < ha->num_tc; tc++) {
481// (void)qlnx_tx_int(ha, fp, fp->txq[tc]);
482// }
467
468 mp = drbr_peek(ifp, fp->tx_br);
469
470 while (mp != NULL) {
471
472 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
473 ret = qlnx_send(ha, fp, &mp);
474 } else {
475 ret = -1;
476 }
477
478 if (ret) {
479
480 if (mp != NULL) {
481 drbr_putback(ifp, fp->tx_br, mp);
482 } else {
483 fp->tx_pkts_processed++;
484 drbr_advance(ifp, fp->tx_br);
485 }
486
487 mtx_unlock(&fp->tx_mtx);
488
489 goto qlnx_fp_taskqueue_exit;
490
491 } else {
492 drbr_advance(ifp, fp->tx_br);
493 fp->tx_pkts_transmitted++;
494 fp->tx_pkts_processed++;
495 }
496
497 if (fp->tx_ring_full)
498 break;
499
500 mp = drbr_peek(ifp, fp->tx_br);
501 }
502
483
484 mp = drbr_peek(ifp, fp->tx_br);
485
486 while (mp != NULL) {
487
488 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
489 ret = qlnx_send(ha, fp, &mp);
490 } else {
491 ret = -1;
492 }
493
494 if (ret) {
495
496 if (mp != NULL) {
497 drbr_putback(ifp, fp->tx_br, mp);
498 } else {
499 fp->tx_pkts_processed++;
500 drbr_advance(ifp, fp->tx_br);
501 }
502
503 mtx_unlock(&fp->tx_mtx);
504
505 goto qlnx_fp_taskqueue_exit;
506
507 } else {
508 drbr_advance(ifp, fp->tx_br);
509 fp->tx_pkts_transmitted++;
510 fp->tx_pkts_processed++;
511 }
512
513 if (fp->tx_ring_full)
514 break;
515
516 mp = drbr_peek(ifp, fp->tx_br);
517 }
518
503 for (tc = 0; tc < ha->num_tc; tc++) {
504 (void)qlnx_tx_int(ha, fp, fp->txq[tc]);
505 }
519// for (tc = 0; tc < ha->num_tc; tc++) {
520// (void)qlnx_tx_int(ha, fp, fp->txq[tc]);
521// }
506
507 mtx_unlock(&fp->tx_mtx);
508
509qlnx_fp_taskqueue_exit:
510 if (rx_int) {
511 if (fp->fp_taskqueue != NULL)
512 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
513 } else {
514 if (fp->tx_ring_full) {
515 qlnx_mdelay(__func__, 100);
516 }
517 ecore_sb_ack(fp->sb_info, IGU_INT_ENABLE, 1);
518 }
519
520 QL_DPRINT2(ha, "exit ret = %d\n", ret);
521 return;
522}
523
524static int
525qlnx_create_fp_taskqueues(qlnx_host_t *ha)
526{
527 int i;
528 uint8_t tq_name[32];
529 struct qlnx_fastpath *fp;
530
531 for (i = 0; i < ha->num_rss; i++) {
532
533 fp = &ha->fp_array[i];
534
535 bzero(tq_name, sizeof (tq_name));
536 snprintf(tq_name, sizeof (tq_name), "ql_fp_tq_%d", i);
537
538 TASK_INIT(&fp->fp_task, 0, qlnx_fp_taskqueue, fp);
539
540 fp->fp_taskqueue = taskqueue_create_fast(tq_name, M_NOWAIT,
541 taskqueue_thread_enqueue,
542 &fp->fp_taskqueue);
543
544 if (fp->fp_taskqueue == NULL)
545 return (-1);
546
547 taskqueue_start_threads(&fp->fp_taskqueue, 1, PI_NET, "%s",
548 tq_name);
549
550 QL_DPRINT1(ha, "%p\n",fp->fp_taskqueue);
551 }
552
553 return (0);
554}
555
556static void
557qlnx_destroy_fp_taskqueues(qlnx_host_t *ha)
558{
559 int i;
560 struct qlnx_fastpath *fp;
561
562 for (i = 0; i < ha->num_rss; i++) {
563
564 fp = &ha->fp_array[i];
565
566 if (fp->fp_taskqueue != NULL) {
567
568 taskqueue_drain(fp->fp_taskqueue, &fp->fp_task);
569 taskqueue_free(fp->fp_taskqueue);
570 fp->fp_taskqueue = NULL;
571 }
572 }
573 return;
574}
575
576static void
577qlnx_drain_fp_taskqueues(qlnx_host_t *ha)
578{
579 int i;
580 struct qlnx_fastpath *fp;
581
582 for (i = 0; i < ha->num_rss; i++) {
583 fp = &ha->fp_array[i];
584
585 if (fp->fp_taskqueue != NULL) {
586 QLNX_UNLOCK(ha);
587 taskqueue_drain(fp->fp_taskqueue, &fp->fp_task);
588 QLNX_LOCK(ha);
589 }
590 }
591 return;
592}
593
594/*
595 * Name: qlnx_pci_attach
596 * Function: attaches the device to the operating system
597 */
598static int
599qlnx_pci_attach(device_t dev)
600{
601 qlnx_host_t *ha = NULL;
602 uint32_t rsrc_len_reg = 0;
603 uint32_t rsrc_len_dbells = 0;
604 uint32_t rsrc_len_msix = 0;
605 int i;
606 uint32_t mfw_ver;
607
608 if ((ha = device_get_softc(dev)) == NULL) {
609 device_printf(dev, "cannot get softc\n");
610 return (ENOMEM);
611 }
612
613 memset(ha, 0, sizeof (qlnx_host_t));
614
615 if (qlnx_valid_device(dev) != 0) {
616 device_printf(dev, "device is not valid device\n");
617 return (ENXIO);
618 }
619 ha->pci_func = pci_get_function(dev);
620
621 ha->pci_dev = dev;
622
623 mtx_init(&ha->hw_lock, "qlnx_hw_lock", MTX_NETWORK_LOCK, MTX_DEF);
624
625 ha->flags.lock_init = 1;
626
627 pci_enable_busmaster(dev);
628
629 /*
630 * map the PCI BARs
631 */
632
633 ha->reg_rid = PCIR_BAR(0);
634 ha->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ha->reg_rid,
635 RF_ACTIVE);
636
637 if (ha->pci_reg == NULL) {
638 device_printf(dev, "unable to map BAR0\n");
639 goto qlnx_pci_attach_err;
640 }
641
642 rsrc_len_reg = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
643 ha->reg_rid);
644
645 ha->dbells_rid = PCIR_BAR(2);
646 ha->pci_dbells = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
647 &ha->dbells_rid, RF_ACTIVE);
648
649 if (ha->pci_dbells == NULL) {
650 device_printf(dev, "unable to map BAR1\n");
651 goto qlnx_pci_attach_err;
652 }
653
654 rsrc_len_dbells = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
655 ha->dbells_rid);
656
657 ha->dbells_phys_addr = (uint64_t)
658 bus_get_resource_start(dev, SYS_RES_MEMORY, ha->dbells_rid);;
659 ha->dbells_size = rsrc_len_dbells;
660
661 ha->msix_rid = PCIR_BAR(4);
662 ha->msix_bar = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
663 &ha->msix_rid, RF_ACTIVE);
664
665 if (ha->msix_bar == NULL) {
666 device_printf(dev, "unable to map BAR2\n");
667 goto qlnx_pci_attach_err;
668 }
669
670 rsrc_len_msix = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
671 ha->msix_rid);
672 /*
673 * allocate dma tags
674 */
675
676 if (qlnx_alloc_parent_dma_tag(ha))
677 goto qlnx_pci_attach_err;
678
679 if (qlnx_alloc_tx_dma_tag(ha))
680 goto qlnx_pci_attach_err;
681
682 if (qlnx_alloc_rx_dma_tag(ha))
683 goto qlnx_pci_attach_err;
684
685
686 if (qlnx_init_hw(ha) != 0)
687 goto qlnx_pci_attach_err;
688
689 /*
690 * Allocate MSI-x vectors
691 */
692 ha->num_rss = QLNX_MAX_RSS;
693 ha->num_tc = QLNX_MAX_TC;
694
695 ha->msix_count = pci_msix_count(dev);
696
697 if (ha->msix_count > (mp_ncpus + ha->cdev.num_hwfns))
698 ha->msix_count = mp_ncpus + ha->cdev.num_hwfns;
699
700 if (!ha->msix_count ||
701 (ha->msix_count < (ha->cdev.num_hwfns + 1 ))) {
702 device_printf(dev, "%s: msix_count[%d] not enough\n", __func__,
703 ha->msix_count);
704 goto qlnx_pci_attach_err;
705 }
706
707 if (ha->msix_count > (ha->num_rss + ha->cdev.num_hwfns ))
708 ha->msix_count = ha->num_rss + ha->cdev.num_hwfns;
709 else
710 ha->num_rss = ha->msix_count - ha->cdev.num_hwfns;
711
712 QL_DPRINT1(ha, "\n\t\t\tpci_reg [%p, 0x%08x 0x%08x]"
713 "\n\t\t\tdbells [%p, 0x%08x 0x%08x]"
714 "\n\t\t\tmsix [%p, 0x%08x 0x%08x 0x%x 0x%x]"
715 "\n\t\t\t[ncpus = %d][num_rss = 0x%x] [num_tc = 0x%x]\n",
716 ha->pci_reg, rsrc_len_reg,
717 ha->reg_rid, ha->pci_dbells, rsrc_len_dbells, ha->dbells_rid,
718 ha->msix_bar, rsrc_len_msix, ha->msix_rid, pci_msix_count(dev),
719 ha->msix_count, mp_ncpus, ha->num_rss, ha->num_tc);
720 if (pci_alloc_msix(dev, &ha->msix_count)) {
721 device_printf(dev, "%s: pci_alloc_msix[%d] failed\n", __func__,
722 ha->msix_count);
723 ha->msix_count = 0;
724 goto qlnx_pci_attach_err;
725 }
726
727 /*
728 * Initialize slow path interrupt and task queue
729 */
730 if (qlnx_create_sp_taskqueues(ha) != 0)
731 goto qlnx_pci_attach_err;
732
733 for (i = 0; i < ha->cdev.num_hwfns; i++) {
734
735 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[i];
736
737 ha->sp_irq_rid[i] = i + 1;
738 ha->sp_irq[i] = bus_alloc_resource_any(dev, SYS_RES_IRQ,
739 &ha->sp_irq_rid[i],
740 (RF_ACTIVE | RF_SHAREABLE));
741 if (ha->sp_irq[i] == NULL) {
742 device_printf(dev,
743 "could not allocate mbx interrupt\n");
744 goto qlnx_pci_attach_err;
745 }
746
747 if (bus_setup_intr(dev, ha->sp_irq[i],
748 (INTR_TYPE_NET | INTR_MPSAFE), NULL,
749 qlnx_sp_intr, p_hwfn, &ha->sp_handle[i])) {
750 device_printf(dev,
751 "could not setup slow path interrupt\n");
752 goto qlnx_pci_attach_err;
753 }
754
755 QL_DPRINT1(ha, "p_hwfn [%p] sp_irq_rid %d"
756 " sp_irq %p sp_handle %p\n", p_hwfn,
757 ha->sp_irq_rid[i], ha->sp_irq[i], ha->sp_handle[i]);
758
759 }
760
761 /*
762 * initialize fast path interrupt
763 */
764 if (qlnx_create_fp_taskqueues(ha) != 0)
765 goto qlnx_pci_attach_err;
766
767 for (i = 0; i < ha->num_rss; i++) {
768 ha->irq_vec[i].rss_idx = i;
769 ha->irq_vec[i].ha = ha;
770 ha->irq_vec[i].irq_rid = (1 + ha->cdev.num_hwfns) + i;
771
772 ha->irq_vec[i].irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
773 &ha->irq_vec[i].irq_rid,
774 (RF_ACTIVE | RF_SHAREABLE));
775
776 if (ha->irq_vec[i].irq == NULL) {
777 device_printf(dev,
778 "could not allocate interrupt[%d]\n", i);
779 goto qlnx_pci_attach_err;
780 }
781
782 if (qlnx_alloc_tx_br(ha, &ha->fp_array[i])) {
783 device_printf(dev, "could not allocate tx_br[%d]\n", i);
784 goto qlnx_pci_attach_err;
785
786 }
787 }
788
789 callout_init(&ha->qlnx_callout, 1);
790 ha->flags.callout_init = 1;
791
792 for (i = 0; i < ha->cdev.num_hwfns; i++) {
793
794 if (qlnx_grc_dumpsize(ha, &ha->grcdump_size[i], i) != 0)
795 goto qlnx_pci_attach_err;
796 if (ha->grcdump_size[i] == 0)
797 goto qlnx_pci_attach_err;
798
799 ha->grcdump_size[i] = ha->grcdump_size[i] << 2;
800 QL_DPRINT1(ha, "grcdump_size[%d] = 0x%08x\n",
801 i, ha->grcdump_size[i]);
802
803 ha->grcdump[i] = qlnx_zalloc(ha->grcdump_size[i]);
804 if (ha->grcdump[i] == NULL) {
805 device_printf(dev, "grcdump alloc[%d] failed\n", i);
806 goto qlnx_pci_attach_err;
807 }
808
809 if (qlnx_idle_chk_size(ha, &ha->idle_chk_size[i], i) != 0)
810 goto qlnx_pci_attach_err;
811 if (ha->idle_chk_size[i] == 0)
812 goto qlnx_pci_attach_err;
813
814 ha->idle_chk_size[i] = ha->idle_chk_size[i] << 2;
815 QL_DPRINT1(ha, "idle_chk_size[%d] = 0x%08x\n",
816 i, ha->idle_chk_size[i]);
817
818 ha->idle_chk[i] = qlnx_zalloc(ha->idle_chk_size[i]);
819
820 if (ha->idle_chk[i] == NULL) {
821 device_printf(dev, "idle_chk alloc failed\n");
822 goto qlnx_pci_attach_err;
823 }
824 }
825
826 if (qlnx_slowpath_start(ha) != 0) {
827
828 qlnx_mdelay(__func__, 1000);
829 qlnx_trigger_dump(ha);
830
831 goto qlnx_pci_attach_err0;
832 } else
833 ha->flags.slowpath_start = 1;
834
835 if (qlnx_get_flash_size(ha, &ha->flash_size) != 0) {
836 qlnx_mdelay(__func__, 1000);
837 qlnx_trigger_dump(ha);
838
839 goto qlnx_pci_attach_err0;
840 }
841
842 if (qlnx_get_mfw_version(ha, &mfw_ver) != 0) {
843 qlnx_mdelay(__func__, 1000);
844 qlnx_trigger_dump(ha);
845
846 goto qlnx_pci_attach_err0;
847 }
848 snprintf(ha->mfw_ver, sizeof(ha->mfw_ver), "%d.%d.%d.%d",
849 ((mfw_ver >> 24) & 0xFF), ((mfw_ver >> 16) & 0xFF),
850 ((mfw_ver >> 8) & 0xFF), (mfw_ver & 0xFF));
851 snprintf(ha->stormfw_ver, sizeof(ha->stormfw_ver), "%d.%d.%d.%d",
852 FW_MAJOR_VERSION, FW_MINOR_VERSION, FW_REVISION_VERSION,
853 FW_ENGINEERING_VERSION);
854
855 QL_DPRINT1(ha, "STORM_FW version %s MFW version %s\n",
856 ha->stormfw_ver, ha->mfw_ver);
857
858 qlnx_init_ifnet(dev, ha);
859
860 /*
861 * add sysctls
862 */
863 qlnx_add_sysctls(ha);
864
865qlnx_pci_attach_err0:
866 /*
867 * create ioctl device interface
868 */
869 if (qlnx_make_cdev(ha)) {
870 device_printf(dev, "%s: ql_make_cdev failed\n", __func__);
871 goto qlnx_pci_attach_err;
872 }
873
874 QL_DPRINT2(ha, "success\n");
875
876 return (0);
877
878qlnx_pci_attach_err:
879
880 qlnx_release(ha);
881
882 return (ENXIO);
883}
884
885/*
886 * Name: qlnx_pci_detach
887 * Function: Unhooks the device from the operating system
888 */
889static int
890qlnx_pci_detach(device_t dev)
891{
892 qlnx_host_t *ha = NULL;
893
894 if ((ha = device_get_softc(dev)) == NULL) {
895 device_printf(dev, "cannot get softc\n");
896 return (ENOMEM);
897 }
898
899 QLNX_LOCK(ha);
900 qlnx_stop(ha);
901 QLNX_UNLOCK(ha);
902
903 qlnx_release(ha);
904
905 return (0);
906}
907
908static int
909qlnx_init_hw(qlnx_host_t *ha)
910{
911 int rval = 0;
912 struct ecore_hw_prepare_params params;
913
914 ecore_init_struct(&ha->cdev);
915
916 /* ha->dp_module = ECORE_MSG_PROBE |
917 ECORE_MSG_INTR |
918 ECORE_MSG_SP |
919 ECORE_MSG_LINK |
920 ECORE_MSG_SPQ |
921 ECORE_MSG_RDMA;
922 ha->dp_level = ECORE_LEVEL_VERBOSE;*/
923 ha->dp_level = ECORE_LEVEL_NOTICE;
924
925 ecore_init_dp(&ha->cdev, ha->dp_module, ha->dp_level, ha->pci_dev);
926
927 ha->cdev.regview = ha->pci_reg;
928 ha->cdev.doorbells = ha->pci_dbells;
929 ha->cdev.db_phys_addr = ha->dbells_phys_addr;
930 ha->cdev.db_size = ha->dbells_size;
931
932 bzero(&params, sizeof (struct ecore_hw_prepare_params));
933
934 ha->personality = ECORE_PCI_DEFAULT;
935
936 params.personality = ha->personality;
937
938 params.drv_resc_alloc = false;
939 params.chk_reg_fifo = false;
940 params.initiate_pf_flr = true;
941 params.epoch = 0;
942
943 ecore_hw_prepare(&ha->cdev, &params);
944
945 qlnx_set_id(&ha->cdev, qlnx_name_str, qlnx_ver_str);
946
947 return (rval);
948}
949
950static void
951qlnx_release(qlnx_host_t *ha)
952{
953 device_t dev;
954 int i;
955
956 dev = ha->pci_dev;
957
958 QL_DPRINT2(ha, "enter\n");
959
960 for (i = 0; i < QLNX_MAX_HW_FUNCS; i++) {
961 if (ha->idle_chk[i] != NULL) {
962 free(ha->idle_chk[i], M_QLNXBUF);
963 ha->idle_chk[i] = NULL;
964 }
965
966 if (ha->grcdump[i] != NULL) {
967 free(ha->grcdump[i], M_QLNXBUF);
968 ha->grcdump[i] = NULL;
969 }
970 }
971
972 if (ha->flags.callout_init)
973 callout_drain(&ha->qlnx_callout);
974
975 if (ha->flags.slowpath_start) {
976 qlnx_slowpath_stop(ha);
977 }
978
979 ecore_hw_remove(&ha->cdev);
980
981 qlnx_del_cdev(ha);
982
983 if (ha->ifp != NULL)
984 ether_ifdetach(ha->ifp);
985
986 qlnx_free_tx_dma_tag(ha);
987
988 qlnx_free_rx_dma_tag(ha);
989
990 qlnx_free_parent_dma_tag(ha);
991
992 for (i = 0; i < ha->num_rss; i++) {
993 struct qlnx_fastpath *fp = &ha->fp_array[i];
994
995 if (ha->irq_vec[i].handle) {
996 (void)bus_teardown_intr(dev, ha->irq_vec[i].irq,
997 ha->irq_vec[i].handle);
998 }
999
1000 if (ha->irq_vec[i].irq) {
1001 (void)bus_release_resource(dev, SYS_RES_IRQ,
1002 ha->irq_vec[i].irq_rid,
1003 ha->irq_vec[i].irq);
1004 }
1005
1006 qlnx_free_tx_br(ha, fp);
1007 }
1008 qlnx_destroy_fp_taskqueues(ha);
1009
1010 for (i = 0; i < ha->cdev.num_hwfns; i++) {
1011 if (ha->sp_handle[i])
1012 (void)bus_teardown_intr(dev, ha->sp_irq[i],
1013 ha->sp_handle[i]);
1014
1015 if (ha->sp_irq[i])
1016 (void) bus_release_resource(dev, SYS_RES_IRQ,
1017 ha->sp_irq_rid[i], ha->sp_irq[i]);
1018 }
1019
1020 qlnx_destroy_sp_taskqueues(ha);
1021
1022 if (ha->msix_count)
1023 pci_release_msi(dev);
1024
1025 if (ha->flags.lock_init) {
1026 mtx_destroy(&ha->hw_lock);
1027 }
1028
1029 if (ha->pci_reg)
1030 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid,
1031 ha->pci_reg);
1032
1033 if (ha->pci_dbells)
1034 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->dbells_rid,
1035 ha->pci_dbells);
1036
1037 if (ha->msix_bar)
1038 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->msix_rid,
1039 ha->msix_bar);
1040
1041 QL_DPRINT2(ha, "exit\n");
1042 return;
1043}
1044
1045static void
1046qlnx_trigger_dump(qlnx_host_t *ha)
1047{
1048 int i;
1049
1050 if (ha->ifp != NULL)
1051 ha->ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
1052
1053 QL_DPRINT2(ha, "enter\n");
1054
1055 for (i = 0; i < ha->cdev.num_hwfns; i++) {
1056 qlnx_grc_dump(ha, &ha->grcdump_dwords[i], i);
1057 qlnx_idle_chk(ha, &ha->idle_chk_dwords[i], i);
1058 }
1059
1060 QL_DPRINT2(ha, "exit\n");
1061
1062 return;
1063}
1064
1065static int
1066qlnx_trigger_dump_sysctl(SYSCTL_HANDLER_ARGS)
1067{
1068 int err, ret = 0;
1069 qlnx_host_t *ha;
1070
1071 err = sysctl_handle_int(oidp, &ret, 0, req);
1072
1073 if (err || !req->newptr)
1074 return (err);
1075
1076 if (ret == 1) {
1077 ha = (qlnx_host_t *)arg1;
1078 qlnx_trigger_dump(ha);
1079 }
1080 return (err);
1081}
1082
1083static int
1084qlnx_set_tx_coalesce(SYSCTL_HANDLER_ARGS)
1085{
1086 int err, i, ret = 0, usecs = 0;
1087 qlnx_host_t *ha;
1088 struct ecore_hwfn *p_hwfn;
1089 struct qlnx_fastpath *fp;
1090
1091 err = sysctl_handle_int(oidp, &usecs, 0, req);
1092
1093 if (err || !req->newptr || !usecs || (usecs > 255))
1094 return (err);
1095
1096 ha = (qlnx_host_t *)arg1;
1097
1098 for (i = 0; i < ha->num_rss; i++) {
1099
1100 p_hwfn = &ha->cdev.hwfns[(i % ha->cdev.num_hwfns)];
1101
1102 fp = &ha->fp_array[i];
1103
1104 if (fp->txq[0]->handle != NULL) {
1105 ret = ecore_set_queue_coalesce(p_hwfn, 0,
1106 (uint16_t)usecs, fp->txq[0]->handle);
1107 }
1108 }
1109
1110 if (!ret)
1111 ha->tx_coalesce_usecs = (uint8_t)usecs;
1112
1113 return (err);
1114}
1115
1116static int
1117qlnx_set_rx_coalesce(SYSCTL_HANDLER_ARGS)
1118{
1119 int err, i, ret = 0, usecs = 0;
1120 qlnx_host_t *ha;
1121 struct ecore_hwfn *p_hwfn;
1122 struct qlnx_fastpath *fp;
1123
1124 err = sysctl_handle_int(oidp, &usecs, 0, req);
1125
1126 if (err || !req->newptr || !usecs || (usecs > 255))
1127 return (err);
1128
1129 ha = (qlnx_host_t *)arg1;
1130
1131 for (i = 0; i < ha->num_rss; i++) {
1132
1133 p_hwfn = &ha->cdev.hwfns[(i % ha->cdev.num_hwfns)];
1134
1135 fp = &ha->fp_array[i];
1136
1137 if (fp->rxq->handle != NULL) {
1138 ret = ecore_set_queue_coalesce(p_hwfn, (uint16_t)usecs,
1139 0, fp->rxq->handle);
1140 }
1141 }
1142
1143 if (!ret)
1144 ha->rx_coalesce_usecs = (uint8_t)usecs;
1145
1146 return (err);
1147}
1148
1149static void
1150qlnx_add_sp_stats_sysctls(qlnx_host_t *ha)
1151{
1152 struct sysctl_ctx_list *ctx;
1153 struct sysctl_oid_list *children;
1154 struct sysctl_oid *ctx_oid;
1155
1156 ctx = device_get_sysctl_ctx(ha->pci_dev);
1157 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1158
1159 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "spstat",
1160 CTLFLAG_RD, NULL, "spstat");
1161 children = SYSCTL_CHILDREN(ctx_oid);
1162
1163 SYSCTL_ADD_QUAD(ctx, children,
1164 OID_AUTO, "sp_interrupts",
1165 CTLFLAG_RD, &ha->sp_interrupts,
1166 "No. of slowpath interrupts");
1167
1168 return;
1169}
1170
1171static void
1172qlnx_add_fp_stats_sysctls(qlnx_host_t *ha)
1173{
1174 struct sysctl_ctx_list *ctx;
1175 struct sysctl_oid_list *children;
1176 struct sysctl_oid_list *node_children;
1177 struct sysctl_oid *ctx_oid;
1178 int i, j;
1179 uint8_t name_str[16];
1180
1181 ctx = device_get_sysctl_ctx(ha->pci_dev);
1182 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1183
1184 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "fpstat",
1185 CTLFLAG_RD, NULL, "fpstat");
1186 children = SYSCTL_CHILDREN(ctx_oid);
1187
1188 for (i = 0; i < ha->num_rss; i++) {
1189
1190 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str)));
1191 snprintf(name_str, sizeof(name_str), "%d", i);
1192
1193 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, name_str,
1194 CTLFLAG_RD, NULL, name_str);
1195 node_children = SYSCTL_CHILDREN(ctx_oid);
1196
1197 /* Tx Related */
1198
1199 SYSCTL_ADD_QUAD(ctx, node_children,
1200 OID_AUTO, "tx_pkts_processed",
1201 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_processed,
1202 "No. of packets processed for transmission");
1203
1204 SYSCTL_ADD_QUAD(ctx, node_children,
1205 OID_AUTO, "tx_pkts_freed",
1206 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_freed,
1207 "No. of freed packets");
1208
1209 SYSCTL_ADD_QUAD(ctx, node_children,
1210 OID_AUTO, "tx_pkts_transmitted",
1211 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_transmitted,
1212 "No. of transmitted packets");
1213
1214 SYSCTL_ADD_QUAD(ctx, node_children,
1215 OID_AUTO, "tx_pkts_completed",
1216 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_completed,
1217 "No. of transmit completions");
1218
1219 SYSCTL_ADD_QUAD(ctx, node_children,
1220 OID_AUTO, "tx_lso_wnd_min_len",
1221 CTLFLAG_RD, &ha->fp_array[i].tx_lso_wnd_min_len,
1222 "tx_lso_wnd_min_len");
1223
1224 SYSCTL_ADD_QUAD(ctx, node_children,
1225 OID_AUTO, "tx_defrag",
1226 CTLFLAG_RD, &ha->fp_array[i].tx_defrag,
1227 "tx_defrag");
1228
1229 SYSCTL_ADD_QUAD(ctx, node_children,
1230 OID_AUTO, "tx_nsegs_gt_elem_left",
1231 CTLFLAG_RD, &ha->fp_array[i].tx_nsegs_gt_elem_left,
1232 "tx_nsegs_gt_elem_left");
1233
1234 SYSCTL_ADD_UINT(ctx, node_children,
1235 OID_AUTO, "tx_tso_max_nsegs",
1236 CTLFLAG_RD, &ha->fp_array[i].tx_tso_max_nsegs,
1237 ha->fp_array[i].tx_tso_max_nsegs, "tx_tso_max_nsegs");
1238
1239 SYSCTL_ADD_UINT(ctx, node_children,
1240 OID_AUTO, "tx_tso_min_nsegs",
1241 CTLFLAG_RD, &ha->fp_array[i].tx_tso_min_nsegs,
1242 ha->fp_array[i].tx_tso_min_nsegs, "tx_tso_min_nsegs");
1243
1244 SYSCTL_ADD_UINT(ctx, node_children,
1245 OID_AUTO, "tx_tso_max_pkt_len",
1246 CTLFLAG_RD, &ha->fp_array[i].tx_tso_max_pkt_len,
1247 ha->fp_array[i].tx_tso_max_pkt_len,
1248 "tx_tso_max_pkt_len");
1249
1250 SYSCTL_ADD_UINT(ctx, node_children,
1251 OID_AUTO, "tx_tso_min_pkt_len",
1252 CTLFLAG_RD, &ha->fp_array[i].tx_tso_min_pkt_len,
1253 ha->fp_array[i].tx_tso_min_pkt_len,
1254 "tx_tso_min_pkt_len");
1255
1256 for (j = 0; j < QLNX_FP_MAX_SEGS; j++) {
1257
1258 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str)));
1259 snprintf(name_str, sizeof(name_str),
1260 "tx_pkts_nseg_%02d", (j+1));
1261
1262 SYSCTL_ADD_QUAD(ctx, node_children,
1263 OID_AUTO, name_str, CTLFLAG_RD,
1264 &ha->fp_array[i].tx_pkts[j], name_str);
1265 }
1266
1267 SYSCTL_ADD_QUAD(ctx, node_children,
1268 OID_AUTO, "err_tx_nsegs_gt_elem_left",
1269 CTLFLAG_RD, &ha->fp_array[i].err_tx_nsegs_gt_elem_left,
1270 "err_tx_nsegs_gt_elem_left");
1271
1272 SYSCTL_ADD_QUAD(ctx, node_children,
1273 OID_AUTO, "err_tx_dmamap_create",
1274 CTLFLAG_RD, &ha->fp_array[i].err_tx_dmamap_create,
1275 "err_tx_dmamap_create");
1276
1277 SYSCTL_ADD_QUAD(ctx, node_children,
1278 OID_AUTO, "err_tx_defrag_dmamap_load",
1279 CTLFLAG_RD, &ha->fp_array[i].err_tx_defrag_dmamap_load,
1280 "err_tx_defrag_dmamap_load");
1281
1282 SYSCTL_ADD_QUAD(ctx, node_children,
1283 OID_AUTO, "err_tx_non_tso_max_seg",
1284 CTLFLAG_RD, &ha->fp_array[i].err_tx_non_tso_max_seg,
1285 "err_tx_non_tso_max_seg");
1286
1287 SYSCTL_ADD_QUAD(ctx, node_children,
1288 OID_AUTO, "err_tx_dmamap_load",
1289 CTLFLAG_RD, &ha->fp_array[i].err_tx_dmamap_load,
1290 "err_tx_dmamap_load");
1291
1292 SYSCTL_ADD_QUAD(ctx, node_children,
1293 OID_AUTO, "err_tx_defrag",
1294 CTLFLAG_RD, &ha->fp_array[i].err_tx_defrag,
1295 "err_tx_defrag");
1296
1297 SYSCTL_ADD_QUAD(ctx, node_children,
1298 OID_AUTO, "err_tx_free_pkt_null",
1299 CTLFLAG_RD, &ha->fp_array[i].err_tx_free_pkt_null,
1300 "err_tx_free_pkt_null");
1301
1302 SYSCTL_ADD_QUAD(ctx, node_children,
1303 OID_AUTO, "err_tx_cons_idx_conflict",
1304 CTLFLAG_RD, &ha->fp_array[i].err_tx_cons_idx_conflict,
1305 "err_tx_cons_idx_conflict");
1306
1307 SYSCTL_ADD_QUAD(ctx, node_children,
1308 OID_AUTO, "lro_cnt_64",
1309 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_64,
1310 "lro_cnt_64");
1311
1312 SYSCTL_ADD_QUAD(ctx, node_children,
1313 OID_AUTO, "lro_cnt_128",
1314 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_128,
1315 "lro_cnt_128");
1316
1317 SYSCTL_ADD_QUAD(ctx, node_children,
1318 OID_AUTO, "lro_cnt_256",
1319 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_256,
1320 "lro_cnt_256");
1321
1322 SYSCTL_ADD_QUAD(ctx, node_children,
1323 OID_AUTO, "lro_cnt_512",
1324 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_512,
1325 "lro_cnt_512");
1326
1327 SYSCTL_ADD_QUAD(ctx, node_children,
1328 OID_AUTO, "lro_cnt_1024",
1329 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_1024,
1330 "lro_cnt_1024");
1331
1332 /* Rx Related */
1333
1334 SYSCTL_ADD_QUAD(ctx, node_children,
1335 OID_AUTO, "rx_pkts",
1336 CTLFLAG_RD, &ha->fp_array[i].rx_pkts,
1337 "No. of received packets");
1338
1339 SYSCTL_ADD_QUAD(ctx, node_children,
1340 OID_AUTO, "tpa_start",
1341 CTLFLAG_RD, &ha->fp_array[i].tpa_start,
1342 "No. of tpa_start packets");
1343
1344 SYSCTL_ADD_QUAD(ctx, node_children,
1345 OID_AUTO, "tpa_cont",
1346 CTLFLAG_RD, &ha->fp_array[i].tpa_cont,
1347 "No. of tpa_cont packets");
1348
1349 SYSCTL_ADD_QUAD(ctx, node_children,
1350 OID_AUTO, "tpa_end",
1351 CTLFLAG_RD, &ha->fp_array[i].tpa_end,
1352 "No. of tpa_end packets");
1353
1354 SYSCTL_ADD_QUAD(ctx, node_children,
1355 OID_AUTO, "err_m_getcl",
1356 CTLFLAG_RD, &ha->fp_array[i].err_m_getcl,
1357 "err_m_getcl");
1358
1359 SYSCTL_ADD_QUAD(ctx, node_children,
1360 OID_AUTO, "err_m_getjcl",
1361 CTLFLAG_RD, &ha->fp_array[i].err_m_getjcl,
1362 "err_m_getjcl");
1363
1364 SYSCTL_ADD_QUAD(ctx, node_children,
1365 OID_AUTO, "err_rx_hw_errors",
1366 CTLFLAG_RD, &ha->fp_array[i].err_rx_hw_errors,
1367 "err_rx_hw_errors");
1368
1369 SYSCTL_ADD_QUAD(ctx, node_children,
1370 OID_AUTO, "err_rx_alloc_errors",
1371 CTLFLAG_RD, &ha->fp_array[i].err_rx_alloc_errors,
1372 "err_rx_alloc_errors");
1373 }
1374
1375 return;
1376}
1377
1378static void
1379qlnx_add_hw_stats_sysctls(qlnx_host_t *ha)
1380{
1381 struct sysctl_ctx_list *ctx;
1382 struct sysctl_oid_list *children;
1383 struct sysctl_oid *ctx_oid;
1384
1385 ctx = device_get_sysctl_ctx(ha->pci_dev);
1386 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1387
1388 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "hwstat",
1389 CTLFLAG_RD, NULL, "hwstat");
1390 children = SYSCTL_CHILDREN(ctx_oid);
1391
1392 SYSCTL_ADD_QUAD(ctx, children,
1393 OID_AUTO, "no_buff_discards",
1394 CTLFLAG_RD, &ha->hw_stats.common.no_buff_discards,
1395 "No. of packets discarded due to lack of buffer");
1396
1397 SYSCTL_ADD_QUAD(ctx, children,
1398 OID_AUTO, "packet_too_big_discard",
1399 CTLFLAG_RD, &ha->hw_stats.common.packet_too_big_discard,
1400 "No. of packets discarded because packet was too big");
1401
1402 SYSCTL_ADD_QUAD(ctx, children,
1403 OID_AUTO, "ttl0_discard",
1404 CTLFLAG_RD, &ha->hw_stats.common.ttl0_discard,
1405 "ttl0_discard");
1406
1407 SYSCTL_ADD_QUAD(ctx, children,
1408 OID_AUTO, "rx_ucast_bytes",
1409 CTLFLAG_RD, &ha->hw_stats.common.rx_ucast_bytes,
1410 "rx_ucast_bytes");
1411
1412 SYSCTL_ADD_QUAD(ctx, children,
1413 OID_AUTO, "rx_mcast_bytes",
1414 CTLFLAG_RD, &ha->hw_stats.common.rx_mcast_bytes,
1415 "rx_mcast_bytes");
1416
1417 SYSCTL_ADD_QUAD(ctx, children,
1418 OID_AUTO, "rx_bcast_bytes",
1419 CTLFLAG_RD, &ha->hw_stats.common.rx_bcast_bytes,
1420 "rx_bcast_bytes");
1421
1422 SYSCTL_ADD_QUAD(ctx, children,
1423 OID_AUTO, "rx_ucast_pkts",
1424 CTLFLAG_RD, &ha->hw_stats.common.rx_ucast_pkts,
1425 "rx_ucast_pkts");
1426
1427 SYSCTL_ADD_QUAD(ctx, children,
1428 OID_AUTO, "rx_mcast_pkts",
1429 CTLFLAG_RD, &ha->hw_stats.common.rx_mcast_pkts,
1430 "rx_mcast_pkts");
1431
1432 SYSCTL_ADD_QUAD(ctx, children,
1433 OID_AUTO, "rx_bcast_pkts",
1434 CTLFLAG_RD, &ha->hw_stats.common.rx_bcast_pkts,
1435 "rx_bcast_pkts");
1436
1437 SYSCTL_ADD_QUAD(ctx, children,
1438 OID_AUTO, "mftag_filter_discards",
1439 CTLFLAG_RD, &ha->hw_stats.common.mftag_filter_discards,
1440 "mftag_filter_discards");
1441
1442 SYSCTL_ADD_QUAD(ctx, children,
1443 OID_AUTO, "mac_filter_discards",
1444 CTLFLAG_RD, &ha->hw_stats.common.mac_filter_discards,
1445 "mac_filter_discards");
1446
1447 SYSCTL_ADD_QUAD(ctx, children,
1448 OID_AUTO, "tx_ucast_bytes",
1449 CTLFLAG_RD, &ha->hw_stats.common.tx_ucast_bytes,
1450 "tx_ucast_bytes");
1451
1452 SYSCTL_ADD_QUAD(ctx, children,
1453 OID_AUTO, "tx_mcast_bytes",
1454 CTLFLAG_RD, &ha->hw_stats.common.tx_mcast_bytes,
1455 "tx_mcast_bytes");
1456
1457 SYSCTL_ADD_QUAD(ctx, children,
1458 OID_AUTO, "tx_bcast_bytes",
1459 CTLFLAG_RD, &ha->hw_stats.common.tx_bcast_bytes,
1460 "tx_bcast_bytes");
1461
1462 SYSCTL_ADD_QUAD(ctx, children,
1463 OID_AUTO, "tx_ucast_pkts",
1464 CTLFLAG_RD, &ha->hw_stats.common.tx_ucast_pkts,
1465 "tx_ucast_pkts");
1466
1467 SYSCTL_ADD_QUAD(ctx, children,
1468 OID_AUTO, "tx_mcast_pkts",
1469 CTLFLAG_RD, &ha->hw_stats.common.tx_mcast_pkts,
1470 "tx_mcast_pkts");
1471
1472 SYSCTL_ADD_QUAD(ctx, children,
1473 OID_AUTO, "tx_bcast_pkts",
1474 CTLFLAG_RD, &ha->hw_stats.common.tx_bcast_pkts,
1475 "tx_bcast_pkts");
1476
1477 SYSCTL_ADD_QUAD(ctx, children,
1478 OID_AUTO, "tx_err_drop_pkts",
1479 CTLFLAG_RD, &ha->hw_stats.common.tx_err_drop_pkts,
1480 "tx_err_drop_pkts");
1481
1482 SYSCTL_ADD_QUAD(ctx, children,
1483 OID_AUTO, "tpa_coalesced_pkts",
1484 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_pkts,
1485 "tpa_coalesced_pkts");
1486
1487 SYSCTL_ADD_QUAD(ctx, children,
1488 OID_AUTO, "tpa_coalesced_events",
1489 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_events,
1490 "tpa_coalesced_events");
1491
1492 SYSCTL_ADD_QUAD(ctx, children,
1493 OID_AUTO, "tpa_aborts_num",
1494 CTLFLAG_RD, &ha->hw_stats.common.tpa_aborts_num,
1495 "tpa_aborts_num");
1496
1497 SYSCTL_ADD_QUAD(ctx, children,
1498 OID_AUTO, "tpa_not_coalesced_pkts",
1499 CTLFLAG_RD, &ha->hw_stats.common.tpa_not_coalesced_pkts,
1500 "tpa_not_coalesced_pkts");
1501
1502 SYSCTL_ADD_QUAD(ctx, children,
1503 OID_AUTO, "tpa_coalesced_bytes",
1504 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_bytes,
1505 "tpa_coalesced_bytes");
1506
1507 SYSCTL_ADD_QUAD(ctx, children,
1508 OID_AUTO, "rx_64_byte_packets",
1509 CTLFLAG_RD, &ha->hw_stats.common.rx_64_byte_packets,
1510 "rx_64_byte_packets");
1511
1512 SYSCTL_ADD_QUAD(ctx, children,
1513 OID_AUTO, "rx_65_to_127_byte_packets",
1514 CTLFLAG_RD, &ha->hw_stats.common.rx_65_to_127_byte_packets,
1515 "rx_65_to_127_byte_packets");
1516
1517 SYSCTL_ADD_QUAD(ctx, children,
1518 OID_AUTO, "rx_128_to_255_byte_packets",
1519 CTLFLAG_RD, &ha->hw_stats.common.rx_128_to_255_byte_packets,
1520 "rx_128_to_255_byte_packets");
1521
1522 SYSCTL_ADD_QUAD(ctx, children,
1523 OID_AUTO, "rx_256_to_511_byte_packets",
1524 CTLFLAG_RD, &ha->hw_stats.common.rx_256_to_511_byte_packets,
1525 "rx_256_to_511_byte_packets");
1526
1527 SYSCTL_ADD_QUAD(ctx, children,
1528 OID_AUTO, "rx_512_to_1023_byte_packets",
1529 CTLFLAG_RD, &ha->hw_stats.common.rx_512_to_1023_byte_packets,
1530 "rx_512_to_1023_byte_packets");
1531
1532 SYSCTL_ADD_QUAD(ctx, children,
1533 OID_AUTO, "rx_1024_to_1518_byte_packets",
1534 CTLFLAG_RD, &ha->hw_stats.common.rx_1024_to_1518_byte_packets,
1535 "rx_1024_to_1518_byte_packets");
1536
1537 SYSCTL_ADD_QUAD(ctx, children,
1538 OID_AUTO, "rx_1519_to_1522_byte_packets",
1539 CTLFLAG_RD, &ha->hw_stats.bb.rx_1519_to_1522_byte_packets,
1540 "rx_1519_to_1522_byte_packets");
1541
1542 SYSCTL_ADD_QUAD(ctx, children,
1543 OID_AUTO, "rx_1523_to_2047_byte_packets",
1544 CTLFLAG_RD, &ha->hw_stats.bb.rx_1519_to_2047_byte_packets,
1545 "rx_1523_to_2047_byte_packets");
1546
1547 SYSCTL_ADD_QUAD(ctx, children,
1548 OID_AUTO, "rx_2048_to_4095_byte_packets",
1549 CTLFLAG_RD, &ha->hw_stats.bb.rx_2048_to_4095_byte_packets,
1550 "rx_2048_to_4095_byte_packets");
1551
1552 SYSCTL_ADD_QUAD(ctx, children,
1553 OID_AUTO, "rx_4096_to_9216_byte_packets",
1554 CTLFLAG_RD, &ha->hw_stats.bb.rx_4096_to_9216_byte_packets,
1555 "rx_4096_to_9216_byte_packets");
1556
1557 SYSCTL_ADD_QUAD(ctx, children,
1558 OID_AUTO, "rx_9217_to_16383_byte_packets",
1559 CTLFLAG_RD, &ha->hw_stats.bb.rx_9217_to_16383_byte_packets,
1560 "rx_9217_to_16383_byte_packets");
1561
1562 SYSCTL_ADD_QUAD(ctx, children,
1563 OID_AUTO, "rx_crc_errors",
1564 CTLFLAG_RD, &ha->hw_stats.common.rx_crc_errors,
1565 "rx_crc_errors");
1566
1567 SYSCTL_ADD_QUAD(ctx, children,
1568 OID_AUTO, "rx_mac_crtl_frames",
1569 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_crtl_frames,
1570 "rx_mac_crtl_frames");
1571
1572 SYSCTL_ADD_QUAD(ctx, children,
1573 OID_AUTO, "rx_pause_frames",
1574 CTLFLAG_RD, &ha->hw_stats.common.rx_pause_frames,
1575 "rx_pause_frames");
1576
1577 SYSCTL_ADD_QUAD(ctx, children,
1578 OID_AUTO, "rx_pfc_frames",
1579 CTLFLAG_RD, &ha->hw_stats.common.rx_pfc_frames,
1580 "rx_pfc_frames");
1581
1582 SYSCTL_ADD_QUAD(ctx, children,
1583 OID_AUTO, "rx_align_errors",
1584 CTLFLAG_RD, &ha->hw_stats.common.rx_align_errors,
1585 "rx_align_errors");
1586
1587 SYSCTL_ADD_QUAD(ctx, children,
1588 OID_AUTO, "rx_carrier_errors",
1589 CTLFLAG_RD, &ha->hw_stats.common.rx_carrier_errors,
1590 "rx_carrier_errors");
1591
1592 SYSCTL_ADD_QUAD(ctx, children,
1593 OID_AUTO, "rx_oversize_packets",
1594 CTLFLAG_RD, &ha->hw_stats.common.rx_oversize_packets,
1595 "rx_oversize_packets");
1596
1597 SYSCTL_ADD_QUAD(ctx, children,
1598 OID_AUTO, "rx_jabbers",
1599 CTLFLAG_RD, &ha->hw_stats.common.rx_jabbers,
1600 "rx_jabbers");
1601
1602 SYSCTL_ADD_QUAD(ctx, children,
1603 OID_AUTO, "rx_undersize_packets",
1604 CTLFLAG_RD, &ha->hw_stats.common.rx_undersize_packets,
1605 "rx_undersize_packets");
1606
1607 SYSCTL_ADD_QUAD(ctx, children,
1608 OID_AUTO, "rx_fragments",
1609 CTLFLAG_RD, &ha->hw_stats.common.rx_fragments,
1610 "rx_fragments");
1611
1612 SYSCTL_ADD_QUAD(ctx, children,
1613 OID_AUTO, "tx_64_byte_packets",
1614 CTLFLAG_RD, &ha->hw_stats.common.tx_64_byte_packets,
1615 "tx_64_byte_packets");
1616
1617 SYSCTL_ADD_QUAD(ctx, children,
1618 OID_AUTO, "tx_65_to_127_byte_packets",
1619 CTLFLAG_RD, &ha->hw_stats.common.tx_65_to_127_byte_packets,
1620 "tx_65_to_127_byte_packets");
1621
1622 SYSCTL_ADD_QUAD(ctx, children,
1623 OID_AUTO, "tx_128_to_255_byte_packets",
1624 CTLFLAG_RD, &ha->hw_stats.common.tx_128_to_255_byte_packets,
1625 "tx_128_to_255_byte_packets");
1626
1627 SYSCTL_ADD_QUAD(ctx, children,
1628 OID_AUTO, "tx_256_to_511_byte_packets",
1629 CTLFLAG_RD, &ha->hw_stats.common.tx_256_to_511_byte_packets,
1630 "tx_256_to_511_byte_packets");
1631
1632 SYSCTL_ADD_QUAD(ctx, children,
1633 OID_AUTO, "tx_512_to_1023_byte_packets",
1634 CTLFLAG_RD, &ha->hw_stats.common.tx_512_to_1023_byte_packets,
1635 "tx_512_to_1023_byte_packets");
1636
1637 SYSCTL_ADD_QUAD(ctx, children,
1638 OID_AUTO, "tx_1024_to_1518_byte_packets",
1639 CTLFLAG_RD, &ha->hw_stats.common.tx_1024_to_1518_byte_packets,
1640 "tx_1024_to_1518_byte_packets");
1641
1642 SYSCTL_ADD_QUAD(ctx, children,
1643 OID_AUTO, "tx_1519_to_2047_byte_packets",
1644 CTLFLAG_RD, &ha->hw_stats.bb.tx_1519_to_2047_byte_packets,
1645 "tx_1519_to_2047_byte_packets");
1646
1647 SYSCTL_ADD_QUAD(ctx, children,
1648 OID_AUTO, "tx_2048_to_4095_byte_packets",
1649 CTLFLAG_RD, &ha->hw_stats.bb.tx_2048_to_4095_byte_packets,
1650 "tx_2048_to_4095_byte_packets");
1651
1652 SYSCTL_ADD_QUAD(ctx, children,
1653 OID_AUTO, "tx_4096_to_9216_byte_packets",
1654 CTLFLAG_RD, &ha->hw_stats.bb.tx_4096_to_9216_byte_packets,
1655 "tx_4096_to_9216_byte_packets");
1656
1657 SYSCTL_ADD_QUAD(ctx, children,
1658 OID_AUTO, "tx_9217_to_16383_byte_packets",
1659 CTLFLAG_RD, &ha->hw_stats.bb.tx_9217_to_16383_byte_packets,
1660 "tx_9217_to_16383_byte_packets");
1661
1662 SYSCTL_ADD_QUAD(ctx, children,
1663 OID_AUTO, "tx_pause_frames",
1664 CTLFLAG_RD, &ha->hw_stats.common.tx_pause_frames,
1665 "tx_pause_frames");
1666
1667 SYSCTL_ADD_QUAD(ctx, children,
1668 OID_AUTO, "tx_pfc_frames",
1669 CTLFLAG_RD, &ha->hw_stats.common.tx_pfc_frames,
1670 "tx_pfc_frames");
1671
1672 SYSCTL_ADD_QUAD(ctx, children,
1673 OID_AUTO, "tx_lpi_entry_count",
1674 CTLFLAG_RD, &ha->hw_stats.bb.tx_lpi_entry_count,
1675 "tx_lpi_entry_count");
1676
1677 SYSCTL_ADD_QUAD(ctx, children,
1678 OID_AUTO, "tx_total_collisions",
1679 CTLFLAG_RD, &ha->hw_stats.bb.tx_total_collisions,
1680 "tx_total_collisions");
1681
1682 SYSCTL_ADD_QUAD(ctx, children,
1683 OID_AUTO, "brb_truncates",
1684 CTLFLAG_RD, &ha->hw_stats.common.brb_truncates,
1685 "brb_truncates");
1686
1687 SYSCTL_ADD_QUAD(ctx, children,
1688 OID_AUTO, "brb_discards",
1689 CTLFLAG_RD, &ha->hw_stats.common.brb_discards,
1690 "brb_discards");
1691
1692 SYSCTL_ADD_QUAD(ctx, children,
1693 OID_AUTO, "rx_mac_bytes",
1694 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_bytes,
1695 "rx_mac_bytes");
1696
1697 SYSCTL_ADD_QUAD(ctx, children,
1698 OID_AUTO, "rx_mac_uc_packets",
1699 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_uc_packets,
1700 "rx_mac_uc_packets");
1701
1702 SYSCTL_ADD_QUAD(ctx, children,
1703 OID_AUTO, "rx_mac_mc_packets",
1704 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_mc_packets,
1705 "rx_mac_mc_packets");
1706
1707 SYSCTL_ADD_QUAD(ctx, children,
1708 OID_AUTO, "rx_mac_bc_packets",
1709 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_bc_packets,
1710 "rx_mac_bc_packets");
1711
1712 SYSCTL_ADD_QUAD(ctx, children,
1713 OID_AUTO, "rx_mac_frames_ok",
1714 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_frames_ok,
1715 "rx_mac_frames_ok");
1716
1717 SYSCTL_ADD_QUAD(ctx, children,
1718 OID_AUTO, "tx_mac_bytes",
1719 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_bytes,
1720 "tx_mac_bytes");
1721
1722 SYSCTL_ADD_QUAD(ctx, children,
1723 OID_AUTO, "tx_mac_uc_packets",
1724 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_uc_packets,
1725 "tx_mac_uc_packets");
1726
1727 SYSCTL_ADD_QUAD(ctx, children,
1728 OID_AUTO, "tx_mac_mc_packets",
1729 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_mc_packets,
1730 "tx_mac_mc_packets");
1731
1732 SYSCTL_ADD_QUAD(ctx, children,
1733 OID_AUTO, "tx_mac_bc_packets",
1734 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_bc_packets,
1735 "tx_mac_bc_packets");
1736
1737 SYSCTL_ADD_QUAD(ctx, children,
1738 OID_AUTO, "tx_mac_ctrl_frames",
1739 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_ctrl_frames,
1740 "tx_mac_ctrl_frames");
1741 return;
1742}
1743
1744static void
1745qlnx_add_sysctls(qlnx_host_t *ha)
1746{
1747 device_t dev = ha->pci_dev;
1748 struct sysctl_ctx_list *ctx;
1749 struct sysctl_oid_list *children;
1750
1751 ctx = device_get_sysctl_ctx(dev);
1752 children = SYSCTL_CHILDREN(device_get_sysctl_tree(dev));
1753
1754 qlnx_add_fp_stats_sysctls(ha);
1755 qlnx_add_sp_stats_sysctls(ha);
1756 qlnx_add_hw_stats_sysctls(ha);
1757
1758 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "Driver_Version",
1759 CTLFLAG_RD, qlnx_ver_str, 0,
1760 "Driver Version");
1761
1762 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "STORMFW_Version",
1763 CTLFLAG_RD, ha->stormfw_ver, 0,
1764 "STORM Firmware Version");
1765
1766 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "MFW_Version",
1767 CTLFLAG_RD, ha->mfw_ver, 0,
1768 "Management Firmware Version");
1769
1770 SYSCTL_ADD_UINT(ctx, children,
1771 OID_AUTO, "personality", CTLFLAG_RD,
1772 &ha->personality, ha->personality,
1773 "\tpersonality = 0 => Ethernet Only\n"
1774 "\tpersonality = 3 => Ethernet and RoCE\n"
1775 "\tpersonality = 4 => Ethernet and iWARP\n"
1776 "\tpersonality = 6 => Default in Shared Memory\n");
1777
1778 ha->dbg_level = 0;
1779 SYSCTL_ADD_UINT(ctx, children,
1780 OID_AUTO, "debug", CTLFLAG_RW,
1781 &ha->dbg_level, ha->dbg_level, "Debug Level");
1782
1783 ha->dp_level = 0x01;
1784 SYSCTL_ADD_UINT(ctx, children,
1785 OID_AUTO, "dp_level", CTLFLAG_RW,
1786 &ha->dp_level, ha->dp_level, "DP Level");
1787
1788 ha->dbg_trace_lro_cnt = 0;
1789 SYSCTL_ADD_UINT(ctx, children,
1790 OID_AUTO, "dbg_trace_lro_cnt", CTLFLAG_RW,
1791 &ha->dbg_trace_lro_cnt, ha->dbg_trace_lro_cnt,
1792 "Trace LRO Counts");
1793
1794 ha->dbg_trace_tso_pkt_len = 0;
1795 SYSCTL_ADD_UINT(ctx, children,
1796 OID_AUTO, "dbg_trace_tso_pkt_len", CTLFLAG_RW,
1797 &ha->dbg_trace_tso_pkt_len, ha->dbg_trace_tso_pkt_len,
1798 "Trace TSO packet lengths");
1799
1800 ha->dp_module = 0;
1801 SYSCTL_ADD_UINT(ctx, children,
1802 OID_AUTO, "dp_module", CTLFLAG_RW,
1803 &ha->dp_module, ha->dp_module, "DP Module");
1804
1805 ha->err_inject = 0;
1806
1807 SYSCTL_ADD_UINT(ctx, children,
1808 OID_AUTO, "err_inject", CTLFLAG_RW,
1809 &ha->err_inject, ha->err_inject, "Error Inject");
1810
1811 ha->storm_stats_enable = 0;
1812
1813 SYSCTL_ADD_UINT(ctx, children,
1814 OID_AUTO, "storm_stats_enable", CTLFLAG_RW,
1815 &ha->storm_stats_enable, ha->storm_stats_enable,
1816 "Enable Storm Statistics Gathering");
1817
1818 ha->storm_stats_index = 0;
1819
1820 SYSCTL_ADD_UINT(ctx, children,
1821 OID_AUTO, "storm_stats_index", CTLFLAG_RD,
1822 &ha->storm_stats_index, ha->storm_stats_index,
1823 "Enable Storm Statistics Gathering Current Index");
1824
1825 ha->grcdump_taken = 0;
1826 SYSCTL_ADD_UINT(ctx, children,
1827 OID_AUTO, "grcdump_taken", CTLFLAG_RD,
1828 &ha->grcdump_taken, ha->grcdump_taken, "grcdump_taken");
1829
1830 ha->idle_chk_taken = 0;
1831 SYSCTL_ADD_UINT(ctx, children,
1832 OID_AUTO, "idle_chk_taken", CTLFLAG_RD,
1833 &ha->idle_chk_taken, ha->idle_chk_taken, "idle_chk_taken");
1834
1835 SYSCTL_ADD_UINT(ctx, children,
1836 OID_AUTO, "rx_coalesce_usecs", CTLFLAG_RD,
1837 &ha->rx_coalesce_usecs, ha->rx_coalesce_usecs,
1838 "rx_coalesce_usecs");
1839
1840 SYSCTL_ADD_UINT(ctx, children,
1841 OID_AUTO, "tx_coalesce_usecs", CTLFLAG_RD,
1842 &ha->tx_coalesce_usecs, ha->tx_coalesce_usecs,
1843 "tx_coalesce_usecs");
1844
1845 ha->rx_pkt_threshold = 128;
1846 SYSCTL_ADD_UINT(ctx, children,
1847 OID_AUTO, "rx_pkt_threshold", CTLFLAG_RW,
1848 &ha->rx_pkt_threshold, ha->rx_pkt_threshold,
1849 "No. of Rx Pkts to process at a time");
1850
1851 ha->rx_jumbo_buf_eq_mtu = 0;
1852 SYSCTL_ADD_UINT(ctx, children,
1853 OID_AUTO, "rx_jumbo_buf_eq_mtu", CTLFLAG_RW,
1854 &ha->rx_jumbo_buf_eq_mtu, ha->rx_jumbo_buf_eq_mtu,
1855 "== 0 => Rx Jumbo buffers are capped to 4Kbytes\n"
1856 "otherwise Rx Jumbo buffers are set to >= MTU size\n");
1857
1858 SYSCTL_ADD_PROC(ctx, children,
1859 OID_AUTO, "trigger_dump", CTLTYPE_INT | CTLFLAG_RW,
1860 (void *)ha, 0,
1861 qlnx_trigger_dump_sysctl, "I", "trigger_dump");
1862
1863 SYSCTL_ADD_PROC(ctx, children,
1864 OID_AUTO, "set_rx_coalesce_usecs", CTLTYPE_INT | CTLFLAG_RW,
1865 (void *)ha, 0,
1866 qlnx_set_rx_coalesce, "I",
1867 "rx interrupt coalesce period microseconds");
1868
1869 SYSCTL_ADD_PROC(ctx, children,
1870 OID_AUTO, "set_tx_coalesce_usecs", CTLTYPE_INT | CTLFLAG_RW,
1871 (void *)ha, 0,
1872 qlnx_set_tx_coalesce, "I",
1873 "tx interrupt coalesce period microseconds");
1874
1875 SYSCTL_ADD_QUAD(ctx, children,
1876 OID_AUTO, "err_illegal_intr", CTLFLAG_RD,
1877 &ha->err_illegal_intr, "err_illegal_intr");
1878
1879 SYSCTL_ADD_QUAD(ctx, children,
1880 OID_AUTO, "err_fp_null", CTLFLAG_RD,
1881 &ha->err_fp_null, "err_fp_null");
1882
1883 SYSCTL_ADD_QUAD(ctx, children,
1884 OID_AUTO, "err_get_proto_invalid_type", CTLFLAG_RD,
1885 &ha->err_get_proto_invalid_type, "err_get_proto_invalid_type");
1886 return;
1887}
1888
1889
1890
1891/*****************************************************************************
1892 * Operating System Network Interface Functions
1893 *****************************************************************************/
1894
1895static void
1896qlnx_init_ifnet(device_t dev, qlnx_host_t *ha)
1897{
1898 uint16_t device_id;
1899 struct ifnet *ifp;
1900
1901 ifp = ha->ifp = if_alloc(IFT_ETHER);
1902
1903 if (ifp == NULL)
1904 panic("%s: cannot if_alloc()\n", device_get_nameunit(dev));
1905
1906 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1907
1908 device_id = pci_get_device(ha->pci_dev);
1909
1910#if __FreeBSD_version >= 1000000
1911
1912 if (device_id == QLOGIC_PCI_DEVICE_ID_1634)
1913 ifp->if_baudrate = IF_Gbps(40);
522
523 mtx_unlock(&fp->tx_mtx);
524
525qlnx_fp_taskqueue_exit:
526 if (rx_int) {
527 if (fp->fp_taskqueue != NULL)
528 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
529 } else {
530 if (fp->tx_ring_full) {
531 qlnx_mdelay(__func__, 100);
532 }
533 ecore_sb_ack(fp->sb_info, IGU_INT_ENABLE, 1);
534 }
535
536 QL_DPRINT2(ha, "exit ret = %d\n", ret);
537 return;
538}
539
540static int
541qlnx_create_fp_taskqueues(qlnx_host_t *ha)
542{
543 int i;
544 uint8_t tq_name[32];
545 struct qlnx_fastpath *fp;
546
547 for (i = 0; i < ha->num_rss; i++) {
548
549 fp = &ha->fp_array[i];
550
551 bzero(tq_name, sizeof (tq_name));
552 snprintf(tq_name, sizeof (tq_name), "ql_fp_tq_%d", i);
553
554 TASK_INIT(&fp->fp_task, 0, qlnx_fp_taskqueue, fp);
555
556 fp->fp_taskqueue = taskqueue_create_fast(tq_name, M_NOWAIT,
557 taskqueue_thread_enqueue,
558 &fp->fp_taskqueue);
559
560 if (fp->fp_taskqueue == NULL)
561 return (-1);
562
563 taskqueue_start_threads(&fp->fp_taskqueue, 1, PI_NET, "%s",
564 tq_name);
565
566 QL_DPRINT1(ha, "%p\n",fp->fp_taskqueue);
567 }
568
569 return (0);
570}
571
572static void
573qlnx_destroy_fp_taskqueues(qlnx_host_t *ha)
574{
575 int i;
576 struct qlnx_fastpath *fp;
577
578 for (i = 0; i < ha->num_rss; i++) {
579
580 fp = &ha->fp_array[i];
581
582 if (fp->fp_taskqueue != NULL) {
583
584 taskqueue_drain(fp->fp_taskqueue, &fp->fp_task);
585 taskqueue_free(fp->fp_taskqueue);
586 fp->fp_taskqueue = NULL;
587 }
588 }
589 return;
590}
591
592static void
593qlnx_drain_fp_taskqueues(qlnx_host_t *ha)
594{
595 int i;
596 struct qlnx_fastpath *fp;
597
598 for (i = 0; i < ha->num_rss; i++) {
599 fp = &ha->fp_array[i];
600
601 if (fp->fp_taskqueue != NULL) {
602 QLNX_UNLOCK(ha);
603 taskqueue_drain(fp->fp_taskqueue, &fp->fp_task);
604 QLNX_LOCK(ha);
605 }
606 }
607 return;
608}
609
610/*
611 * Name: qlnx_pci_attach
612 * Function: attaches the device to the operating system
613 */
614static int
615qlnx_pci_attach(device_t dev)
616{
617 qlnx_host_t *ha = NULL;
618 uint32_t rsrc_len_reg = 0;
619 uint32_t rsrc_len_dbells = 0;
620 uint32_t rsrc_len_msix = 0;
621 int i;
622 uint32_t mfw_ver;
623
624 if ((ha = device_get_softc(dev)) == NULL) {
625 device_printf(dev, "cannot get softc\n");
626 return (ENOMEM);
627 }
628
629 memset(ha, 0, sizeof (qlnx_host_t));
630
631 if (qlnx_valid_device(dev) != 0) {
632 device_printf(dev, "device is not valid device\n");
633 return (ENXIO);
634 }
635 ha->pci_func = pci_get_function(dev);
636
637 ha->pci_dev = dev;
638
639 mtx_init(&ha->hw_lock, "qlnx_hw_lock", MTX_NETWORK_LOCK, MTX_DEF);
640
641 ha->flags.lock_init = 1;
642
643 pci_enable_busmaster(dev);
644
645 /*
646 * map the PCI BARs
647 */
648
649 ha->reg_rid = PCIR_BAR(0);
650 ha->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &ha->reg_rid,
651 RF_ACTIVE);
652
653 if (ha->pci_reg == NULL) {
654 device_printf(dev, "unable to map BAR0\n");
655 goto qlnx_pci_attach_err;
656 }
657
658 rsrc_len_reg = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
659 ha->reg_rid);
660
661 ha->dbells_rid = PCIR_BAR(2);
662 ha->pci_dbells = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
663 &ha->dbells_rid, RF_ACTIVE);
664
665 if (ha->pci_dbells == NULL) {
666 device_printf(dev, "unable to map BAR1\n");
667 goto qlnx_pci_attach_err;
668 }
669
670 rsrc_len_dbells = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
671 ha->dbells_rid);
672
673 ha->dbells_phys_addr = (uint64_t)
674 bus_get_resource_start(dev, SYS_RES_MEMORY, ha->dbells_rid);;
675 ha->dbells_size = rsrc_len_dbells;
676
677 ha->msix_rid = PCIR_BAR(4);
678 ha->msix_bar = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
679 &ha->msix_rid, RF_ACTIVE);
680
681 if (ha->msix_bar == NULL) {
682 device_printf(dev, "unable to map BAR2\n");
683 goto qlnx_pci_attach_err;
684 }
685
686 rsrc_len_msix = (uint32_t) bus_get_resource_count(dev, SYS_RES_MEMORY,
687 ha->msix_rid);
688 /*
689 * allocate dma tags
690 */
691
692 if (qlnx_alloc_parent_dma_tag(ha))
693 goto qlnx_pci_attach_err;
694
695 if (qlnx_alloc_tx_dma_tag(ha))
696 goto qlnx_pci_attach_err;
697
698 if (qlnx_alloc_rx_dma_tag(ha))
699 goto qlnx_pci_attach_err;
700
701
702 if (qlnx_init_hw(ha) != 0)
703 goto qlnx_pci_attach_err;
704
705 /*
706 * Allocate MSI-x vectors
707 */
708 ha->num_rss = QLNX_MAX_RSS;
709 ha->num_tc = QLNX_MAX_TC;
710
711 ha->msix_count = pci_msix_count(dev);
712
713 if (ha->msix_count > (mp_ncpus + ha->cdev.num_hwfns))
714 ha->msix_count = mp_ncpus + ha->cdev.num_hwfns;
715
716 if (!ha->msix_count ||
717 (ha->msix_count < (ha->cdev.num_hwfns + 1 ))) {
718 device_printf(dev, "%s: msix_count[%d] not enough\n", __func__,
719 ha->msix_count);
720 goto qlnx_pci_attach_err;
721 }
722
723 if (ha->msix_count > (ha->num_rss + ha->cdev.num_hwfns ))
724 ha->msix_count = ha->num_rss + ha->cdev.num_hwfns;
725 else
726 ha->num_rss = ha->msix_count - ha->cdev.num_hwfns;
727
728 QL_DPRINT1(ha, "\n\t\t\tpci_reg [%p, 0x%08x 0x%08x]"
729 "\n\t\t\tdbells [%p, 0x%08x 0x%08x]"
730 "\n\t\t\tmsix [%p, 0x%08x 0x%08x 0x%x 0x%x]"
731 "\n\t\t\t[ncpus = %d][num_rss = 0x%x] [num_tc = 0x%x]\n",
732 ha->pci_reg, rsrc_len_reg,
733 ha->reg_rid, ha->pci_dbells, rsrc_len_dbells, ha->dbells_rid,
734 ha->msix_bar, rsrc_len_msix, ha->msix_rid, pci_msix_count(dev),
735 ha->msix_count, mp_ncpus, ha->num_rss, ha->num_tc);
736 if (pci_alloc_msix(dev, &ha->msix_count)) {
737 device_printf(dev, "%s: pci_alloc_msix[%d] failed\n", __func__,
738 ha->msix_count);
739 ha->msix_count = 0;
740 goto qlnx_pci_attach_err;
741 }
742
743 /*
744 * Initialize slow path interrupt and task queue
745 */
746 if (qlnx_create_sp_taskqueues(ha) != 0)
747 goto qlnx_pci_attach_err;
748
749 for (i = 0; i < ha->cdev.num_hwfns; i++) {
750
751 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[i];
752
753 ha->sp_irq_rid[i] = i + 1;
754 ha->sp_irq[i] = bus_alloc_resource_any(dev, SYS_RES_IRQ,
755 &ha->sp_irq_rid[i],
756 (RF_ACTIVE | RF_SHAREABLE));
757 if (ha->sp_irq[i] == NULL) {
758 device_printf(dev,
759 "could not allocate mbx interrupt\n");
760 goto qlnx_pci_attach_err;
761 }
762
763 if (bus_setup_intr(dev, ha->sp_irq[i],
764 (INTR_TYPE_NET | INTR_MPSAFE), NULL,
765 qlnx_sp_intr, p_hwfn, &ha->sp_handle[i])) {
766 device_printf(dev,
767 "could not setup slow path interrupt\n");
768 goto qlnx_pci_attach_err;
769 }
770
771 QL_DPRINT1(ha, "p_hwfn [%p] sp_irq_rid %d"
772 " sp_irq %p sp_handle %p\n", p_hwfn,
773 ha->sp_irq_rid[i], ha->sp_irq[i], ha->sp_handle[i]);
774
775 }
776
777 /*
778 * initialize fast path interrupt
779 */
780 if (qlnx_create_fp_taskqueues(ha) != 0)
781 goto qlnx_pci_attach_err;
782
783 for (i = 0; i < ha->num_rss; i++) {
784 ha->irq_vec[i].rss_idx = i;
785 ha->irq_vec[i].ha = ha;
786 ha->irq_vec[i].irq_rid = (1 + ha->cdev.num_hwfns) + i;
787
788 ha->irq_vec[i].irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
789 &ha->irq_vec[i].irq_rid,
790 (RF_ACTIVE | RF_SHAREABLE));
791
792 if (ha->irq_vec[i].irq == NULL) {
793 device_printf(dev,
794 "could not allocate interrupt[%d]\n", i);
795 goto qlnx_pci_attach_err;
796 }
797
798 if (qlnx_alloc_tx_br(ha, &ha->fp_array[i])) {
799 device_printf(dev, "could not allocate tx_br[%d]\n", i);
800 goto qlnx_pci_attach_err;
801
802 }
803 }
804
805 callout_init(&ha->qlnx_callout, 1);
806 ha->flags.callout_init = 1;
807
808 for (i = 0; i < ha->cdev.num_hwfns; i++) {
809
810 if (qlnx_grc_dumpsize(ha, &ha->grcdump_size[i], i) != 0)
811 goto qlnx_pci_attach_err;
812 if (ha->grcdump_size[i] == 0)
813 goto qlnx_pci_attach_err;
814
815 ha->grcdump_size[i] = ha->grcdump_size[i] << 2;
816 QL_DPRINT1(ha, "grcdump_size[%d] = 0x%08x\n",
817 i, ha->grcdump_size[i]);
818
819 ha->grcdump[i] = qlnx_zalloc(ha->grcdump_size[i]);
820 if (ha->grcdump[i] == NULL) {
821 device_printf(dev, "grcdump alloc[%d] failed\n", i);
822 goto qlnx_pci_attach_err;
823 }
824
825 if (qlnx_idle_chk_size(ha, &ha->idle_chk_size[i], i) != 0)
826 goto qlnx_pci_attach_err;
827 if (ha->idle_chk_size[i] == 0)
828 goto qlnx_pci_attach_err;
829
830 ha->idle_chk_size[i] = ha->idle_chk_size[i] << 2;
831 QL_DPRINT1(ha, "idle_chk_size[%d] = 0x%08x\n",
832 i, ha->idle_chk_size[i]);
833
834 ha->idle_chk[i] = qlnx_zalloc(ha->idle_chk_size[i]);
835
836 if (ha->idle_chk[i] == NULL) {
837 device_printf(dev, "idle_chk alloc failed\n");
838 goto qlnx_pci_attach_err;
839 }
840 }
841
842 if (qlnx_slowpath_start(ha) != 0) {
843
844 qlnx_mdelay(__func__, 1000);
845 qlnx_trigger_dump(ha);
846
847 goto qlnx_pci_attach_err0;
848 } else
849 ha->flags.slowpath_start = 1;
850
851 if (qlnx_get_flash_size(ha, &ha->flash_size) != 0) {
852 qlnx_mdelay(__func__, 1000);
853 qlnx_trigger_dump(ha);
854
855 goto qlnx_pci_attach_err0;
856 }
857
858 if (qlnx_get_mfw_version(ha, &mfw_ver) != 0) {
859 qlnx_mdelay(__func__, 1000);
860 qlnx_trigger_dump(ha);
861
862 goto qlnx_pci_attach_err0;
863 }
864 snprintf(ha->mfw_ver, sizeof(ha->mfw_ver), "%d.%d.%d.%d",
865 ((mfw_ver >> 24) & 0xFF), ((mfw_ver >> 16) & 0xFF),
866 ((mfw_ver >> 8) & 0xFF), (mfw_ver & 0xFF));
867 snprintf(ha->stormfw_ver, sizeof(ha->stormfw_ver), "%d.%d.%d.%d",
868 FW_MAJOR_VERSION, FW_MINOR_VERSION, FW_REVISION_VERSION,
869 FW_ENGINEERING_VERSION);
870
871 QL_DPRINT1(ha, "STORM_FW version %s MFW version %s\n",
872 ha->stormfw_ver, ha->mfw_ver);
873
874 qlnx_init_ifnet(dev, ha);
875
876 /*
877 * add sysctls
878 */
879 qlnx_add_sysctls(ha);
880
881qlnx_pci_attach_err0:
882 /*
883 * create ioctl device interface
884 */
885 if (qlnx_make_cdev(ha)) {
886 device_printf(dev, "%s: ql_make_cdev failed\n", __func__);
887 goto qlnx_pci_attach_err;
888 }
889
890 QL_DPRINT2(ha, "success\n");
891
892 return (0);
893
894qlnx_pci_attach_err:
895
896 qlnx_release(ha);
897
898 return (ENXIO);
899}
900
901/*
902 * Name: qlnx_pci_detach
903 * Function: Unhooks the device from the operating system
904 */
905static int
906qlnx_pci_detach(device_t dev)
907{
908 qlnx_host_t *ha = NULL;
909
910 if ((ha = device_get_softc(dev)) == NULL) {
911 device_printf(dev, "cannot get softc\n");
912 return (ENOMEM);
913 }
914
915 QLNX_LOCK(ha);
916 qlnx_stop(ha);
917 QLNX_UNLOCK(ha);
918
919 qlnx_release(ha);
920
921 return (0);
922}
923
924static int
925qlnx_init_hw(qlnx_host_t *ha)
926{
927 int rval = 0;
928 struct ecore_hw_prepare_params params;
929
930 ecore_init_struct(&ha->cdev);
931
932 /* ha->dp_module = ECORE_MSG_PROBE |
933 ECORE_MSG_INTR |
934 ECORE_MSG_SP |
935 ECORE_MSG_LINK |
936 ECORE_MSG_SPQ |
937 ECORE_MSG_RDMA;
938 ha->dp_level = ECORE_LEVEL_VERBOSE;*/
939 ha->dp_level = ECORE_LEVEL_NOTICE;
940
941 ecore_init_dp(&ha->cdev, ha->dp_module, ha->dp_level, ha->pci_dev);
942
943 ha->cdev.regview = ha->pci_reg;
944 ha->cdev.doorbells = ha->pci_dbells;
945 ha->cdev.db_phys_addr = ha->dbells_phys_addr;
946 ha->cdev.db_size = ha->dbells_size;
947
948 bzero(&params, sizeof (struct ecore_hw_prepare_params));
949
950 ha->personality = ECORE_PCI_DEFAULT;
951
952 params.personality = ha->personality;
953
954 params.drv_resc_alloc = false;
955 params.chk_reg_fifo = false;
956 params.initiate_pf_flr = true;
957 params.epoch = 0;
958
959 ecore_hw_prepare(&ha->cdev, &params);
960
961 qlnx_set_id(&ha->cdev, qlnx_name_str, qlnx_ver_str);
962
963 return (rval);
964}
965
966static void
967qlnx_release(qlnx_host_t *ha)
968{
969 device_t dev;
970 int i;
971
972 dev = ha->pci_dev;
973
974 QL_DPRINT2(ha, "enter\n");
975
976 for (i = 0; i < QLNX_MAX_HW_FUNCS; i++) {
977 if (ha->idle_chk[i] != NULL) {
978 free(ha->idle_chk[i], M_QLNXBUF);
979 ha->idle_chk[i] = NULL;
980 }
981
982 if (ha->grcdump[i] != NULL) {
983 free(ha->grcdump[i], M_QLNXBUF);
984 ha->grcdump[i] = NULL;
985 }
986 }
987
988 if (ha->flags.callout_init)
989 callout_drain(&ha->qlnx_callout);
990
991 if (ha->flags.slowpath_start) {
992 qlnx_slowpath_stop(ha);
993 }
994
995 ecore_hw_remove(&ha->cdev);
996
997 qlnx_del_cdev(ha);
998
999 if (ha->ifp != NULL)
1000 ether_ifdetach(ha->ifp);
1001
1002 qlnx_free_tx_dma_tag(ha);
1003
1004 qlnx_free_rx_dma_tag(ha);
1005
1006 qlnx_free_parent_dma_tag(ha);
1007
1008 for (i = 0; i < ha->num_rss; i++) {
1009 struct qlnx_fastpath *fp = &ha->fp_array[i];
1010
1011 if (ha->irq_vec[i].handle) {
1012 (void)bus_teardown_intr(dev, ha->irq_vec[i].irq,
1013 ha->irq_vec[i].handle);
1014 }
1015
1016 if (ha->irq_vec[i].irq) {
1017 (void)bus_release_resource(dev, SYS_RES_IRQ,
1018 ha->irq_vec[i].irq_rid,
1019 ha->irq_vec[i].irq);
1020 }
1021
1022 qlnx_free_tx_br(ha, fp);
1023 }
1024 qlnx_destroy_fp_taskqueues(ha);
1025
1026 for (i = 0; i < ha->cdev.num_hwfns; i++) {
1027 if (ha->sp_handle[i])
1028 (void)bus_teardown_intr(dev, ha->sp_irq[i],
1029 ha->sp_handle[i]);
1030
1031 if (ha->sp_irq[i])
1032 (void) bus_release_resource(dev, SYS_RES_IRQ,
1033 ha->sp_irq_rid[i], ha->sp_irq[i]);
1034 }
1035
1036 qlnx_destroy_sp_taskqueues(ha);
1037
1038 if (ha->msix_count)
1039 pci_release_msi(dev);
1040
1041 if (ha->flags.lock_init) {
1042 mtx_destroy(&ha->hw_lock);
1043 }
1044
1045 if (ha->pci_reg)
1046 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->reg_rid,
1047 ha->pci_reg);
1048
1049 if (ha->pci_dbells)
1050 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->dbells_rid,
1051 ha->pci_dbells);
1052
1053 if (ha->msix_bar)
1054 (void) bus_release_resource(dev, SYS_RES_MEMORY, ha->msix_rid,
1055 ha->msix_bar);
1056
1057 QL_DPRINT2(ha, "exit\n");
1058 return;
1059}
1060
1061static void
1062qlnx_trigger_dump(qlnx_host_t *ha)
1063{
1064 int i;
1065
1066 if (ha->ifp != NULL)
1067 ha->ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
1068
1069 QL_DPRINT2(ha, "enter\n");
1070
1071 for (i = 0; i < ha->cdev.num_hwfns; i++) {
1072 qlnx_grc_dump(ha, &ha->grcdump_dwords[i], i);
1073 qlnx_idle_chk(ha, &ha->idle_chk_dwords[i], i);
1074 }
1075
1076 QL_DPRINT2(ha, "exit\n");
1077
1078 return;
1079}
1080
1081static int
1082qlnx_trigger_dump_sysctl(SYSCTL_HANDLER_ARGS)
1083{
1084 int err, ret = 0;
1085 qlnx_host_t *ha;
1086
1087 err = sysctl_handle_int(oidp, &ret, 0, req);
1088
1089 if (err || !req->newptr)
1090 return (err);
1091
1092 if (ret == 1) {
1093 ha = (qlnx_host_t *)arg1;
1094 qlnx_trigger_dump(ha);
1095 }
1096 return (err);
1097}
1098
1099static int
1100qlnx_set_tx_coalesce(SYSCTL_HANDLER_ARGS)
1101{
1102 int err, i, ret = 0, usecs = 0;
1103 qlnx_host_t *ha;
1104 struct ecore_hwfn *p_hwfn;
1105 struct qlnx_fastpath *fp;
1106
1107 err = sysctl_handle_int(oidp, &usecs, 0, req);
1108
1109 if (err || !req->newptr || !usecs || (usecs > 255))
1110 return (err);
1111
1112 ha = (qlnx_host_t *)arg1;
1113
1114 for (i = 0; i < ha->num_rss; i++) {
1115
1116 p_hwfn = &ha->cdev.hwfns[(i % ha->cdev.num_hwfns)];
1117
1118 fp = &ha->fp_array[i];
1119
1120 if (fp->txq[0]->handle != NULL) {
1121 ret = ecore_set_queue_coalesce(p_hwfn, 0,
1122 (uint16_t)usecs, fp->txq[0]->handle);
1123 }
1124 }
1125
1126 if (!ret)
1127 ha->tx_coalesce_usecs = (uint8_t)usecs;
1128
1129 return (err);
1130}
1131
1132static int
1133qlnx_set_rx_coalesce(SYSCTL_HANDLER_ARGS)
1134{
1135 int err, i, ret = 0, usecs = 0;
1136 qlnx_host_t *ha;
1137 struct ecore_hwfn *p_hwfn;
1138 struct qlnx_fastpath *fp;
1139
1140 err = sysctl_handle_int(oidp, &usecs, 0, req);
1141
1142 if (err || !req->newptr || !usecs || (usecs > 255))
1143 return (err);
1144
1145 ha = (qlnx_host_t *)arg1;
1146
1147 for (i = 0; i < ha->num_rss; i++) {
1148
1149 p_hwfn = &ha->cdev.hwfns[(i % ha->cdev.num_hwfns)];
1150
1151 fp = &ha->fp_array[i];
1152
1153 if (fp->rxq->handle != NULL) {
1154 ret = ecore_set_queue_coalesce(p_hwfn, (uint16_t)usecs,
1155 0, fp->rxq->handle);
1156 }
1157 }
1158
1159 if (!ret)
1160 ha->rx_coalesce_usecs = (uint8_t)usecs;
1161
1162 return (err);
1163}
1164
1165static void
1166qlnx_add_sp_stats_sysctls(qlnx_host_t *ha)
1167{
1168 struct sysctl_ctx_list *ctx;
1169 struct sysctl_oid_list *children;
1170 struct sysctl_oid *ctx_oid;
1171
1172 ctx = device_get_sysctl_ctx(ha->pci_dev);
1173 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1174
1175 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "spstat",
1176 CTLFLAG_RD, NULL, "spstat");
1177 children = SYSCTL_CHILDREN(ctx_oid);
1178
1179 SYSCTL_ADD_QUAD(ctx, children,
1180 OID_AUTO, "sp_interrupts",
1181 CTLFLAG_RD, &ha->sp_interrupts,
1182 "No. of slowpath interrupts");
1183
1184 return;
1185}
1186
1187static void
1188qlnx_add_fp_stats_sysctls(qlnx_host_t *ha)
1189{
1190 struct sysctl_ctx_list *ctx;
1191 struct sysctl_oid_list *children;
1192 struct sysctl_oid_list *node_children;
1193 struct sysctl_oid *ctx_oid;
1194 int i, j;
1195 uint8_t name_str[16];
1196
1197 ctx = device_get_sysctl_ctx(ha->pci_dev);
1198 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1199
1200 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "fpstat",
1201 CTLFLAG_RD, NULL, "fpstat");
1202 children = SYSCTL_CHILDREN(ctx_oid);
1203
1204 for (i = 0; i < ha->num_rss; i++) {
1205
1206 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str)));
1207 snprintf(name_str, sizeof(name_str), "%d", i);
1208
1209 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, name_str,
1210 CTLFLAG_RD, NULL, name_str);
1211 node_children = SYSCTL_CHILDREN(ctx_oid);
1212
1213 /* Tx Related */
1214
1215 SYSCTL_ADD_QUAD(ctx, node_children,
1216 OID_AUTO, "tx_pkts_processed",
1217 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_processed,
1218 "No. of packets processed for transmission");
1219
1220 SYSCTL_ADD_QUAD(ctx, node_children,
1221 OID_AUTO, "tx_pkts_freed",
1222 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_freed,
1223 "No. of freed packets");
1224
1225 SYSCTL_ADD_QUAD(ctx, node_children,
1226 OID_AUTO, "tx_pkts_transmitted",
1227 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_transmitted,
1228 "No. of transmitted packets");
1229
1230 SYSCTL_ADD_QUAD(ctx, node_children,
1231 OID_AUTO, "tx_pkts_completed",
1232 CTLFLAG_RD, &ha->fp_array[i].tx_pkts_completed,
1233 "No. of transmit completions");
1234
1235 SYSCTL_ADD_QUAD(ctx, node_children,
1236 OID_AUTO, "tx_lso_wnd_min_len",
1237 CTLFLAG_RD, &ha->fp_array[i].tx_lso_wnd_min_len,
1238 "tx_lso_wnd_min_len");
1239
1240 SYSCTL_ADD_QUAD(ctx, node_children,
1241 OID_AUTO, "tx_defrag",
1242 CTLFLAG_RD, &ha->fp_array[i].tx_defrag,
1243 "tx_defrag");
1244
1245 SYSCTL_ADD_QUAD(ctx, node_children,
1246 OID_AUTO, "tx_nsegs_gt_elem_left",
1247 CTLFLAG_RD, &ha->fp_array[i].tx_nsegs_gt_elem_left,
1248 "tx_nsegs_gt_elem_left");
1249
1250 SYSCTL_ADD_UINT(ctx, node_children,
1251 OID_AUTO, "tx_tso_max_nsegs",
1252 CTLFLAG_RD, &ha->fp_array[i].tx_tso_max_nsegs,
1253 ha->fp_array[i].tx_tso_max_nsegs, "tx_tso_max_nsegs");
1254
1255 SYSCTL_ADD_UINT(ctx, node_children,
1256 OID_AUTO, "tx_tso_min_nsegs",
1257 CTLFLAG_RD, &ha->fp_array[i].tx_tso_min_nsegs,
1258 ha->fp_array[i].tx_tso_min_nsegs, "tx_tso_min_nsegs");
1259
1260 SYSCTL_ADD_UINT(ctx, node_children,
1261 OID_AUTO, "tx_tso_max_pkt_len",
1262 CTLFLAG_RD, &ha->fp_array[i].tx_tso_max_pkt_len,
1263 ha->fp_array[i].tx_tso_max_pkt_len,
1264 "tx_tso_max_pkt_len");
1265
1266 SYSCTL_ADD_UINT(ctx, node_children,
1267 OID_AUTO, "tx_tso_min_pkt_len",
1268 CTLFLAG_RD, &ha->fp_array[i].tx_tso_min_pkt_len,
1269 ha->fp_array[i].tx_tso_min_pkt_len,
1270 "tx_tso_min_pkt_len");
1271
1272 for (j = 0; j < QLNX_FP_MAX_SEGS; j++) {
1273
1274 bzero(name_str, (sizeof(uint8_t) * sizeof(name_str)));
1275 snprintf(name_str, sizeof(name_str),
1276 "tx_pkts_nseg_%02d", (j+1));
1277
1278 SYSCTL_ADD_QUAD(ctx, node_children,
1279 OID_AUTO, name_str, CTLFLAG_RD,
1280 &ha->fp_array[i].tx_pkts[j], name_str);
1281 }
1282
1283 SYSCTL_ADD_QUAD(ctx, node_children,
1284 OID_AUTO, "err_tx_nsegs_gt_elem_left",
1285 CTLFLAG_RD, &ha->fp_array[i].err_tx_nsegs_gt_elem_left,
1286 "err_tx_nsegs_gt_elem_left");
1287
1288 SYSCTL_ADD_QUAD(ctx, node_children,
1289 OID_AUTO, "err_tx_dmamap_create",
1290 CTLFLAG_RD, &ha->fp_array[i].err_tx_dmamap_create,
1291 "err_tx_dmamap_create");
1292
1293 SYSCTL_ADD_QUAD(ctx, node_children,
1294 OID_AUTO, "err_tx_defrag_dmamap_load",
1295 CTLFLAG_RD, &ha->fp_array[i].err_tx_defrag_dmamap_load,
1296 "err_tx_defrag_dmamap_load");
1297
1298 SYSCTL_ADD_QUAD(ctx, node_children,
1299 OID_AUTO, "err_tx_non_tso_max_seg",
1300 CTLFLAG_RD, &ha->fp_array[i].err_tx_non_tso_max_seg,
1301 "err_tx_non_tso_max_seg");
1302
1303 SYSCTL_ADD_QUAD(ctx, node_children,
1304 OID_AUTO, "err_tx_dmamap_load",
1305 CTLFLAG_RD, &ha->fp_array[i].err_tx_dmamap_load,
1306 "err_tx_dmamap_load");
1307
1308 SYSCTL_ADD_QUAD(ctx, node_children,
1309 OID_AUTO, "err_tx_defrag",
1310 CTLFLAG_RD, &ha->fp_array[i].err_tx_defrag,
1311 "err_tx_defrag");
1312
1313 SYSCTL_ADD_QUAD(ctx, node_children,
1314 OID_AUTO, "err_tx_free_pkt_null",
1315 CTLFLAG_RD, &ha->fp_array[i].err_tx_free_pkt_null,
1316 "err_tx_free_pkt_null");
1317
1318 SYSCTL_ADD_QUAD(ctx, node_children,
1319 OID_AUTO, "err_tx_cons_idx_conflict",
1320 CTLFLAG_RD, &ha->fp_array[i].err_tx_cons_idx_conflict,
1321 "err_tx_cons_idx_conflict");
1322
1323 SYSCTL_ADD_QUAD(ctx, node_children,
1324 OID_AUTO, "lro_cnt_64",
1325 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_64,
1326 "lro_cnt_64");
1327
1328 SYSCTL_ADD_QUAD(ctx, node_children,
1329 OID_AUTO, "lro_cnt_128",
1330 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_128,
1331 "lro_cnt_128");
1332
1333 SYSCTL_ADD_QUAD(ctx, node_children,
1334 OID_AUTO, "lro_cnt_256",
1335 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_256,
1336 "lro_cnt_256");
1337
1338 SYSCTL_ADD_QUAD(ctx, node_children,
1339 OID_AUTO, "lro_cnt_512",
1340 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_512,
1341 "lro_cnt_512");
1342
1343 SYSCTL_ADD_QUAD(ctx, node_children,
1344 OID_AUTO, "lro_cnt_1024",
1345 CTLFLAG_RD, &ha->fp_array[i].lro_cnt_1024,
1346 "lro_cnt_1024");
1347
1348 /* Rx Related */
1349
1350 SYSCTL_ADD_QUAD(ctx, node_children,
1351 OID_AUTO, "rx_pkts",
1352 CTLFLAG_RD, &ha->fp_array[i].rx_pkts,
1353 "No. of received packets");
1354
1355 SYSCTL_ADD_QUAD(ctx, node_children,
1356 OID_AUTO, "tpa_start",
1357 CTLFLAG_RD, &ha->fp_array[i].tpa_start,
1358 "No. of tpa_start packets");
1359
1360 SYSCTL_ADD_QUAD(ctx, node_children,
1361 OID_AUTO, "tpa_cont",
1362 CTLFLAG_RD, &ha->fp_array[i].tpa_cont,
1363 "No. of tpa_cont packets");
1364
1365 SYSCTL_ADD_QUAD(ctx, node_children,
1366 OID_AUTO, "tpa_end",
1367 CTLFLAG_RD, &ha->fp_array[i].tpa_end,
1368 "No. of tpa_end packets");
1369
1370 SYSCTL_ADD_QUAD(ctx, node_children,
1371 OID_AUTO, "err_m_getcl",
1372 CTLFLAG_RD, &ha->fp_array[i].err_m_getcl,
1373 "err_m_getcl");
1374
1375 SYSCTL_ADD_QUAD(ctx, node_children,
1376 OID_AUTO, "err_m_getjcl",
1377 CTLFLAG_RD, &ha->fp_array[i].err_m_getjcl,
1378 "err_m_getjcl");
1379
1380 SYSCTL_ADD_QUAD(ctx, node_children,
1381 OID_AUTO, "err_rx_hw_errors",
1382 CTLFLAG_RD, &ha->fp_array[i].err_rx_hw_errors,
1383 "err_rx_hw_errors");
1384
1385 SYSCTL_ADD_QUAD(ctx, node_children,
1386 OID_AUTO, "err_rx_alloc_errors",
1387 CTLFLAG_RD, &ha->fp_array[i].err_rx_alloc_errors,
1388 "err_rx_alloc_errors");
1389 }
1390
1391 return;
1392}
1393
1394static void
1395qlnx_add_hw_stats_sysctls(qlnx_host_t *ha)
1396{
1397 struct sysctl_ctx_list *ctx;
1398 struct sysctl_oid_list *children;
1399 struct sysctl_oid *ctx_oid;
1400
1401 ctx = device_get_sysctl_ctx(ha->pci_dev);
1402 children = SYSCTL_CHILDREN(device_get_sysctl_tree(ha->pci_dev));
1403
1404 ctx_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "hwstat",
1405 CTLFLAG_RD, NULL, "hwstat");
1406 children = SYSCTL_CHILDREN(ctx_oid);
1407
1408 SYSCTL_ADD_QUAD(ctx, children,
1409 OID_AUTO, "no_buff_discards",
1410 CTLFLAG_RD, &ha->hw_stats.common.no_buff_discards,
1411 "No. of packets discarded due to lack of buffer");
1412
1413 SYSCTL_ADD_QUAD(ctx, children,
1414 OID_AUTO, "packet_too_big_discard",
1415 CTLFLAG_RD, &ha->hw_stats.common.packet_too_big_discard,
1416 "No. of packets discarded because packet was too big");
1417
1418 SYSCTL_ADD_QUAD(ctx, children,
1419 OID_AUTO, "ttl0_discard",
1420 CTLFLAG_RD, &ha->hw_stats.common.ttl0_discard,
1421 "ttl0_discard");
1422
1423 SYSCTL_ADD_QUAD(ctx, children,
1424 OID_AUTO, "rx_ucast_bytes",
1425 CTLFLAG_RD, &ha->hw_stats.common.rx_ucast_bytes,
1426 "rx_ucast_bytes");
1427
1428 SYSCTL_ADD_QUAD(ctx, children,
1429 OID_AUTO, "rx_mcast_bytes",
1430 CTLFLAG_RD, &ha->hw_stats.common.rx_mcast_bytes,
1431 "rx_mcast_bytes");
1432
1433 SYSCTL_ADD_QUAD(ctx, children,
1434 OID_AUTO, "rx_bcast_bytes",
1435 CTLFLAG_RD, &ha->hw_stats.common.rx_bcast_bytes,
1436 "rx_bcast_bytes");
1437
1438 SYSCTL_ADD_QUAD(ctx, children,
1439 OID_AUTO, "rx_ucast_pkts",
1440 CTLFLAG_RD, &ha->hw_stats.common.rx_ucast_pkts,
1441 "rx_ucast_pkts");
1442
1443 SYSCTL_ADD_QUAD(ctx, children,
1444 OID_AUTO, "rx_mcast_pkts",
1445 CTLFLAG_RD, &ha->hw_stats.common.rx_mcast_pkts,
1446 "rx_mcast_pkts");
1447
1448 SYSCTL_ADD_QUAD(ctx, children,
1449 OID_AUTO, "rx_bcast_pkts",
1450 CTLFLAG_RD, &ha->hw_stats.common.rx_bcast_pkts,
1451 "rx_bcast_pkts");
1452
1453 SYSCTL_ADD_QUAD(ctx, children,
1454 OID_AUTO, "mftag_filter_discards",
1455 CTLFLAG_RD, &ha->hw_stats.common.mftag_filter_discards,
1456 "mftag_filter_discards");
1457
1458 SYSCTL_ADD_QUAD(ctx, children,
1459 OID_AUTO, "mac_filter_discards",
1460 CTLFLAG_RD, &ha->hw_stats.common.mac_filter_discards,
1461 "mac_filter_discards");
1462
1463 SYSCTL_ADD_QUAD(ctx, children,
1464 OID_AUTO, "tx_ucast_bytes",
1465 CTLFLAG_RD, &ha->hw_stats.common.tx_ucast_bytes,
1466 "tx_ucast_bytes");
1467
1468 SYSCTL_ADD_QUAD(ctx, children,
1469 OID_AUTO, "tx_mcast_bytes",
1470 CTLFLAG_RD, &ha->hw_stats.common.tx_mcast_bytes,
1471 "tx_mcast_bytes");
1472
1473 SYSCTL_ADD_QUAD(ctx, children,
1474 OID_AUTO, "tx_bcast_bytes",
1475 CTLFLAG_RD, &ha->hw_stats.common.tx_bcast_bytes,
1476 "tx_bcast_bytes");
1477
1478 SYSCTL_ADD_QUAD(ctx, children,
1479 OID_AUTO, "tx_ucast_pkts",
1480 CTLFLAG_RD, &ha->hw_stats.common.tx_ucast_pkts,
1481 "tx_ucast_pkts");
1482
1483 SYSCTL_ADD_QUAD(ctx, children,
1484 OID_AUTO, "tx_mcast_pkts",
1485 CTLFLAG_RD, &ha->hw_stats.common.tx_mcast_pkts,
1486 "tx_mcast_pkts");
1487
1488 SYSCTL_ADD_QUAD(ctx, children,
1489 OID_AUTO, "tx_bcast_pkts",
1490 CTLFLAG_RD, &ha->hw_stats.common.tx_bcast_pkts,
1491 "tx_bcast_pkts");
1492
1493 SYSCTL_ADD_QUAD(ctx, children,
1494 OID_AUTO, "tx_err_drop_pkts",
1495 CTLFLAG_RD, &ha->hw_stats.common.tx_err_drop_pkts,
1496 "tx_err_drop_pkts");
1497
1498 SYSCTL_ADD_QUAD(ctx, children,
1499 OID_AUTO, "tpa_coalesced_pkts",
1500 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_pkts,
1501 "tpa_coalesced_pkts");
1502
1503 SYSCTL_ADD_QUAD(ctx, children,
1504 OID_AUTO, "tpa_coalesced_events",
1505 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_events,
1506 "tpa_coalesced_events");
1507
1508 SYSCTL_ADD_QUAD(ctx, children,
1509 OID_AUTO, "tpa_aborts_num",
1510 CTLFLAG_RD, &ha->hw_stats.common.tpa_aborts_num,
1511 "tpa_aborts_num");
1512
1513 SYSCTL_ADD_QUAD(ctx, children,
1514 OID_AUTO, "tpa_not_coalesced_pkts",
1515 CTLFLAG_RD, &ha->hw_stats.common.tpa_not_coalesced_pkts,
1516 "tpa_not_coalesced_pkts");
1517
1518 SYSCTL_ADD_QUAD(ctx, children,
1519 OID_AUTO, "tpa_coalesced_bytes",
1520 CTLFLAG_RD, &ha->hw_stats.common.tpa_coalesced_bytes,
1521 "tpa_coalesced_bytes");
1522
1523 SYSCTL_ADD_QUAD(ctx, children,
1524 OID_AUTO, "rx_64_byte_packets",
1525 CTLFLAG_RD, &ha->hw_stats.common.rx_64_byte_packets,
1526 "rx_64_byte_packets");
1527
1528 SYSCTL_ADD_QUAD(ctx, children,
1529 OID_AUTO, "rx_65_to_127_byte_packets",
1530 CTLFLAG_RD, &ha->hw_stats.common.rx_65_to_127_byte_packets,
1531 "rx_65_to_127_byte_packets");
1532
1533 SYSCTL_ADD_QUAD(ctx, children,
1534 OID_AUTO, "rx_128_to_255_byte_packets",
1535 CTLFLAG_RD, &ha->hw_stats.common.rx_128_to_255_byte_packets,
1536 "rx_128_to_255_byte_packets");
1537
1538 SYSCTL_ADD_QUAD(ctx, children,
1539 OID_AUTO, "rx_256_to_511_byte_packets",
1540 CTLFLAG_RD, &ha->hw_stats.common.rx_256_to_511_byte_packets,
1541 "rx_256_to_511_byte_packets");
1542
1543 SYSCTL_ADD_QUAD(ctx, children,
1544 OID_AUTO, "rx_512_to_1023_byte_packets",
1545 CTLFLAG_RD, &ha->hw_stats.common.rx_512_to_1023_byte_packets,
1546 "rx_512_to_1023_byte_packets");
1547
1548 SYSCTL_ADD_QUAD(ctx, children,
1549 OID_AUTO, "rx_1024_to_1518_byte_packets",
1550 CTLFLAG_RD, &ha->hw_stats.common.rx_1024_to_1518_byte_packets,
1551 "rx_1024_to_1518_byte_packets");
1552
1553 SYSCTL_ADD_QUAD(ctx, children,
1554 OID_AUTO, "rx_1519_to_1522_byte_packets",
1555 CTLFLAG_RD, &ha->hw_stats.bb.rx_1519_to_1522_byte_packets,
1556 "rx_1519_to_1522_byte_packets");
1557
1558 SYSCTL_ADD_QUAD(ctx, children,
1559 OID_AUTO, "rx_1523_to_2047_byte_packets",
1560 CTLFLAG_RD, &ha->hw_stats.bb.rx_1519_to_2047_byte_packets,
1561 "rx_1523_to_2047_byte_packets");
1562
1563 SYSCTL_ADD_QUAD(ctx, children,
1564 OID_AUTO, "rx_2048_to_4095_byte_packets",
1565 CTLFLAG_RD, &ha->hw_stats.bb.rx_2048_to_4095_byte_packets,
1566 "rx_2048_to_4095_byte_packets");
1567
1568 SYSCTL_ADD_QUAD(ctx, children,
1569 OID_AUTO, "rx_4096_to_9216_byte_packets",
1570 CTLFLAG_RD, &ha->hw_stats.bb.rx_4096_to_9216_byte_packets,
1571 "rx_4096_to_9216_byte_packets");
1572
1573 SYSCTL_ADD_QUAD(ctx, children,
1574 OID_AUTO, "rx_9217_to_16383_byte_packets",
1575 CTLFLAG_RD, &ha->hw_stats.bb.rx_9217_to_16383_byte_packets,
1576 "rx_9217_to_16383_byte_packets");
1577
1578 SYSCTL_ADD_QUAD(ctx, children,
1579 OID_AUTO, "rx_crc_errors",
1580 CTLFLAG_RD, &ha->hw_stats.common.rx_crc_errors,
1581 "rx_crc_errors");
1582
1583 SYSCTL_ADD_QUAD(ctx, children,
1584 OID_AUTO, "rx_mac_crtl_frames",
1585 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_crtl_frames,
1586 "rx_mac_crtl_frames");
1587
1588 SYSCTL_ADD_QUAD(ctx, children,
1589 OID_AUTO, "rx_pause_frames",
1590 CTLFLAG_RD, &ha->hw_stats.common.rx_pause_frames,
1591 "rx_pause_frames");
1592
1593 SYSCTL_ADD_QUAD(ctx, children,
1594 OID_AUTO, "rx_pfc_frames",
1595 CTLFLAG_RD, &ha->hw_stats.common.rx_pfc_frames,
1596 "rx_pfc_frames");
1597
1598 SYSCTL_ADD_QUAD(ctx, children,
1599 OID_AUTO, "rx_align_errors",
1600 CTLFLAG_RD, &ha->hw_stats.common.rx_align_errors,
1601 "rx_align_errors");
1602
1603 SYSCTL_ADD_QUAD(ctx, children,
1604 OID_AUTO, "rx_carrier_errors",
1605 CTLFLAG_RD, &ha->hw_stats.common.rx_carrier_errors,
1606 "rx_carrier_errors");
1607
1608 SYSCTL_ADD_QUAD(ctx, children,
1609 OID_AUTO, "rx_oversize_packets",
1610 CTLFLAG_RD, &ha->hw_stats.common.rx_oversize_packets,
1611 "rx_oversize_packets");
1612
1613 SYSCTL_ADD_QUAD(ctx, children,
1614 OID_AUTO, "rx_jabbers",
1615 CTLFLAG_RD, &ha->hw_stats.common.rx_jabbers,
1616 "rx_jabbers");
1617
1618 SYSCTL_ADD_QUAD(ctx, children,
1619 OID_AUTO, "rx_undersize_packets",
1620 CTLFLAG_RD, &ha->hw_stats.common.rx_undersize_packets,
1621 "rx_undersize_packets");
1622
1623 SYSCTL_ADD_QUAD(ctx, children,
1624 OID_AUTO, "rx_fragments",
1625 CTLFLAG_RD, &ha->hw_stats.common.rx_fragments,
1626 "rx_fragments");
1627
1628 SYSCTL_ADD_QUAD(ctx, children,
1629 OID_AUTO, "tx_64_byte_packets",
1630 CTLFLAG_RD, &ha->hw_stats.common.tx_64_byte_packets,
1631 "tx_64_byte_packets");
1632
1633 SYSCTL_ADD_QUAD(ctx, children,
1634 OID_AUTO, "tx_65_to_127_byte_packets",
1635 CTLFLAG_RD, &ha->hw_stats.common.tx_65_to_127_byte_packets,
1636 "tx_65_to_127_byte_packets");
1637
1638 SYSCTL_ADD_QUAD(ctx, children,
1639 OID_AUTO, "tx_128_to_255_byte_packets",
1640 CTLFLAG_RD, &ha->hw_stats.common.tx_128_to_255_byte_packets,
1641 "tx_128_to_255_byte_packets");
1642
1643 SYSCTL_ADD_QUAD(ctx, children,
1644 OID_AUTO, "tx_256_to_511_byte_packets",
1645 CTLFLAG_RD, &ha->hw_stats.common.tx_256_to_511_byte_packets,
1646 "tx_256_to_511_byte_packets");
1647
1648 SYSCTL_ADD_QUAD(ctx, children,
1649 OID_AUTO, "tx_512_to_1023_byte_packets",
1650 CTLFLAG_RD, &ha->hw_stats.common.tx_512_to_1023_byte_packets,
1651 "tx_512_to_1023_byte_packets");
1652
1653 SYSCTL_ADD_QUAD(ctx, children,
1654 OID_AUTO, "tx_1024_to_1518_byte_packets",
1655 CTLFLAG_RD, &ha->hw_stats.common.tx_1024_to_1518_byte_packets,
1656 "tx_1024_to_1518_byte_packets");
1657
1658 SYSCTL_ADD_QUAD(ctx, children,
1659 OID_AUTO, "tx_1519_to_2047_byte_packets",
1660 CTLFLAG_RD, &ha->hw_stats.bb.tx_1519_to_2047_byte_packets,
1661 "tx_1519_to_2047_byte_packets");
1662
1663 SYSCTL_ADD_QUAD(ctx, children,
1664 OID_AUTO, "tx_2048_to_4095_byte_packets",
1665 CTLFLAG_RD, &ha->hw_stats.bb.tx_2048_to_4095_byte_packets,
1666 "tx_2048_to_4095_byte_packets");
1667
1668 SYSCTL_ADD_QUAD(ctx, children,
1669 OID_AUTO, "tx_4096_to_9216_byte_packets",
1670 CTLFLAG_RD, &ha->hw_stats.bb.tx_4096_to_9216_byte_packets,
1671 "tx_4096_to_9216_byte_packets");
1672
1673 SYSCTL_ADD_QUAD(ctx, children,
1674 OID_AUTO, "tx_9217_to_16383_byte_packets",
1675 CTLFLAG_RD, &ha->hw_stats.bb.tx_9217_to_16383_byte_packets,
1676 "tx_9217_to_16383_byte_packets");
1677
1678 SYSCTL_ADD_QUAD(ctx, children,
1679 OID_AUTO, "tx_pause_frames",
1680 CTLFLAG_RD, &ha->hw_stats.common.tx_pause_frames,
1681 "tx_pause_frames");
1682
1683 SYSCTL_ADD_QUAD(ctx, children,
1684 OID_AUTO, "tx_pfc_frames",
1685 CTLFLAG_RD, &ha->hw_stats.common.tx_pfc_frames,
1686 "tx_pfc_frames");
1687
1688 SYSCTL_ADD_QUAD(ctx, children,
1689 OID_AUTO, "tx_lpi_entry_count",
1690 CTLFLAG_RD, &ha->hw_stats.bb.tx_lpi_entry_count,
1691 "tx_lpi_entry_count");
1692
1693 SYSCTL_ADD_QUAD(ctx, children,
1694 OID_AUTO, "tx_total_collisions",
1695 CTLFLAG_RD, &ha->hw_stats.bb.tx_total_collisions,
1696 "tx_total_collisions");
1697
1698 SYSCTL_ADD_QUAD(ctx, children,
1699 OID_AUTO, "brb_truncates",
1700 CTLFLAG_RD, &ha->hw_stats.common.brb_truncates,
1701 "brb_truncates");
1702
1703 SYSCTL_ADD_QUAD(ctx, children,
1704 OID_AUTO, "brb_discards",
1705 CTLFLAG_RD, &ha->hw_stats.common.brb_discards,
1706 "brb_discards");
1707
1708 SYSCTL_ADD_QUAD(ctx, children,
1709 OID_AUTO, "rx_mac_bytes",
1710 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_bytes,
1711 "rx_mac_bytes");
1712
1713 SYSCTL_ADD_QUAD(ctx, children,
1714 OID_AUTO, "rx_mac_uc_packets",
1715 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_uc_packets,
1716 "rx_mac_uc_packets");
1717
1718 SYSCTL_ADD_QUAD(ctx, children,
1719 OID_AUTO, "rx_mac_mc_packets",
1720 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_mc_packets,
1721 "rx_mac_mc_packets");
1722
1723 SYSCTL_ADD_QUAD(ctx, children,
1724 OID_AUTO, "rx_mac_bc_packets",
1725 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_bc_packets,
1726 "rx_mac_bc_packets");
1727
1728 SYSCTL_ADD_QUAD(ctx, children,
1729 OID_AUTO, "rx_mac_frames_ok",
1730 CTLFLAG_RD, &ha->hw_stats.common.rx_mac_frames_ok,
1731 "rx_mac_frames_ok");
1732
1733 SYSCTL_ADD_QUAD(ctx, children,
1734 OID_AUTO, "tx_mac_bytes",
1735 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_bytes,
1736 "tx_mac_bytes");
1737
1738 SYSCTL_ADD_QUAD(ctx, children,
1739 OID_AUTO, "tx_mac_uc_packets",
1740 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_uc_packets,
1741 "tx_mac_uc_packets");
1742
1743 SYSCTL_ADD_QUAD(ctx, children,
1744 OID_AUTO, "tx_mac_mc_packets",
1745 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_mc_packets,
1746 "tx_mac_mc_packets");
1747
1748 SYSCTL_ADD_QUAD(ctx, children,
1749 OID_AUTO, "tx_mac_bc_packets",
1750 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_bc_packets,
1751 "tx_mac_bc_packets");
1752
1753 SYSCTL_ADD_QUAD(ctx, children,
1754 OID_AUTO, "tx_mac_ctrl_frames",
1755 CTLFLAG_RD, &ha->hw_stats.common.tx_mac_ctrl_frames,
1756 "tx_mac_ctrl_frames");
1757 return;
1758}
1759
1760static void
1761qlnx_add_sysctls(qlnx_host_t *ha)
1762{
1763 device_t dev = ha->pci_dev;
1764 struct sysctl_ctx_list *ctx;
1765 struct sysctl_oid_list *children;
1766
1767 ctx = device_get_sysctl_ctx(dev);
1768 children = SYSCTL_CHILDREN(device_get_sysctl_tree(dev));
1769
1770 qlnx_add_fp_stats_sysctls(ha);
1771 qlnx_add_sp_stats_sysctls(ha);
1772 qlnx_add_hw_stats_sysctls(ha);
1773
1774 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "Driver_Version",
1775 CTLFLAG_RD, qlnx_ver_str, 0,
1776 "Driver Version");
1777
1778 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "STORMFW_Version",
1779 CTLFLAG_RD, ha->stormfw_ver, 0,
1780 "STORM Firmware Version");
1781
1782 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "MFW_Version",
1783 CTLFLAG_RD, ha->mfw_ver, 0,
1784 "Management Firmware Version");
1785
1786 SYSCTL_ADD_UINT(ctx, children,
1787 OID_AUTO, "personality", CTLFLAG_RD,
1788 &ha->personality, ha->personality,
1789 "\tpersonality = 0 => Ethernet Only\n"
1790 "\tpersonality = 3 => Ethernet and RoCE\n"
1791 "\tpersonality = 4 => Ethernet and iWARP\n"
1792 "\tpersonality = 6 => Default in Shared Memory\n");
1793
1794 ha->dbg_level = 0;
1795 SYSCTL_ADD_UINT(ctx, children,
1796 OID_AUTO, "debug", CTLFLAG_RW,
1797 &ha->dbg_level, ha->dbg_level, "Debug Level");
1798
1799 ha->dp_level = 0x01;
1800 SYSCTL_ADD_UINT(ctx, children,
1801 OID_AUTO, "dp_level", CTLFLAG_RW,
1802 &ha->dp_level, ha->dp_level, "DP Level");
1803
1804 ha->dbg_trace_lro_cnt = 0;
1805 SYSCTL_ADD_UINT(ctx, children,
1806 OID_AUTO, "dbg_trace_lro_cnt", CTLFLAG_RW,
1807 &ha->dbg_trace_lro_cnt, ha->dbg_trace_lro_cnt,
1808 "Trace LRO Counts");
1809
1810 ha->dbg_trace_tso_pkt_len = 0;
1811 SYSCTL_ADD_UINT(ctx, children,
1812 OID_AUTO, "dbg_trace_tso_pkt_len", CTLFLAG_RW,
1813 &ha->dbg_trace_tso_pkt_len, ha->dbg_trace_tso_pkt_len,
1814 "Trace TSO packet lengths");
1815
1816 ha->dp_module = 0;
1817 SYSCTL_ADD_UINT(ctx, children,
1818 OID_AUTO, "dp_module", CTLFLAG_RW,
1819 &ha->dp_module, ha->dp_module, "DP Module");
1820
1821 ha->err_inject = 0;
1822
1823 SYSCTL_ADD_UINT(ctx, children,
1824 OID_AUTO, "err_inject", CTLFLAG_RW,
1825 &ha->err_inject, ha->err_inject, "Error Inject");
1826
1827 ha->storm_stats_enable = 0;
1828
1829 SYSCTL_ADD_UINT(ctx, children,
1830 OID_AUTO, "storm_stats_enable", CTLFLAG_RW,
1831 &ha->storm_stats_enable, ha->storm_stats_enable,
1832 "Enable Storm Statistics Gathering");
1833
1834 ha->storm_stats_index = 0;
1835
1836 SYSCTL_ADD_UINT(ctx, children,
1837 OID_AUTO, "storm_stats_index", CTLFLAG_RD,
1838 &ha->storm_stats_index, ha->storm_stats_index,
1839 "Enable Storm Statistics Gathering Current Index");
1840
1841 ha->grcdump_taken = 0;
1842 SYSCTL_ADD_UINT(ctx, children,
1843 OID_AUTO, "grcdump_taken", CTLFLAG_RD,
1844 &ha->grcdump_taken, ha->grcdump_taken, "grcdump_taken");
1845
1846 ha->idle_chk_taken = 0;
1847 SYSCTL_ADD_UINT(ctx, children,
1848 OID_AUTO, "idle_chk_taken", CTLFLAG_RD,
1849 &ha->idle_chk_taken, ha->idle_chk_taken, "idle_chk_taken");
1850
1851 SYSCTL_ADD_UINT(ctx, children,
1852 OID_AUTO, "rx_coalesce_usecs", CTLFLAG_RD,
1853 &ha->rx_coalesce_usecs, ha->rx_coalesce_usecs,
1854 "rx_coalesce_usecs");
1855
1856 SYSCTL_ADD_UINT(ctx, children,
1857 OID_AUTO, "tx_coalesce_usecs", CTLFLAG_RD,
1858 &ha->tx_coalesce_usecs, ha->tx_coalesce_usecs,
1859 "tx_coalesce_usecs");
1860
1861 ha->rx_pkt_threshold = 128;
1862 SYSCTL_ADD_UINT(ctx, children,
1863 OID_AUTO, "rx_pkt_threshold", CTLFLAG_RW,
1864 &ha->rx_pkt_threshold, ha->rx_pkt_threshold,
1865 "No. of Rx Pkts to process at a time");
1866
1867 ha->rx_jumbo_buf_eq_mtu = 0;
1868 SYSCTL_ADD_UINT(ctx, children,
1869 OID_AUTO, "rx_jumbo_buf_eq_mtu", CTLFLAG_RW,
1870 &ha->rx_jumbo_buf_eq_mtu, ha->rx_jumbo_buf_eq_mtu,
1871 "== 0 => Rx Jumbo buffers are capped to 4Kbytes\n"
1872 "otherwise Rx Jumbo buffers are set to >= MTU size\n");
1873
1874 SYSCTL_ADD_PROC(ctx, children,
1875 OID_AUTO, "trigger_dump", CTLTYPE_INT | CTLFLAG_RW,
1876 (void *)ha, 0,
1877 qlnx_trigger_dump_sysctl, "I", "trigger_dump");
1878
1879 SYSCTL_ADD_PROC(ctx, children,
1880 OID_AUTO, "set_rx_coalesce_usecs", CTLTYPE_INT | CTLFLAG_RW,
1881 (void *)ha, 0,
1882 qlnx_set_rx_coalesce, "I",
1883 "rx interrupt coalesce period microseconds");
1884
1885 SYSCTL_ADD_PROC(ctx, children,
1886 OID_AUTO, "set_tx_coalesce_usecs", CTLTYPE_INT | CTLFLAG_RW,
1887 (void *)ha, 0,
1888 qlnx_set_tx_coalesce, "I",
1889 "tx interrupt coalesce period microseconds");
1890
1891 SYSCTL_ADD_QUAD(ctx, children,
1892 OID_AUTO, "err_illegal_intr", CTLFLAG_RD,
1893 &ha->err_illegal_intr, "err_illegal_intr");
1894
1895 SYSCTL_ADD_QUAD(ctx, children,
1896 OID_AUTO, "err_fp_null", CTLFLAG_RD,
1897 &ha->err_fp_null, "err_fp_null");
1898
1899 SYSCTL_ADD_QUAD(ctx, children,
1900 OID_AUTO, "err_get_proto_invalid_type", CTLFLAG_RD,
1901 &ha->err_get_proto_invalid_type, "err_get_proto_invalid_type");
1902 return;
1903}
1904
1905
1906
1907/*****************************************************************************
1908 * Operating System Network Interface Functions
1909 *****************************************************************************/
1910
1911static void
1912qlnx_init_ifnet(device_t dev, qlnx_host_t *ha)
1913{
1914 uint16_t device_id;
1915 struct ifnet *ifp;
1916
1917 ifp = ha->ifp = if_alloc(IFT_ETHER);
1918
1919 if (ifp == NULL)
1920 panic("%s: cannot if_alloc()\n", device_get_nameunit(dev));
1921
1922 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1923
1924 device_id = pci_get_device(ha->pci_dev);
1925
1926#if __FreeBSD_version >= 1000000
1927
1928 if (device_id == QLOGIC_PCI_DEVICE_ID_1634)
1929 ifp->if_baudrate = IF_Gbps(40);
1914 else if (device_id == QLOGIC_PCI_DEVICE_ID_1656)
1930 else if ((device_id == QLOGIC_PCI_DEVICE_ID_1656) ||
1931 (device_id == QLOGIC_PCI_DEVICE_ID_8070))
1915 ifp->if_baudrate = IF_Gbps(25);
1916 else if (device_id == QLOGIC_PCI_DEVICE_ID_1654)
1917 ifp->if_baudrate = IF_Gbps(50);
1918 else if (device_id == QLOGIC_PCI_DEVICE_ID_1644)
1919 ifp->if_baudrate = IF_Gbps(100);
1920
1921 ifp->if_capabilities = IFCAP_LINKSTATE;
1922#else
1923 ifp->if_mtu = ETHERMTU;
1924 ifp->if_baudrate = (1 * 1000 * 1000 *1000);
1925
1926#endif /* #if __FreeBSD_version >= 1000000 */
1927
1928 ifp->if_init = qlnx_init;
1929 ifp->if_softc = ha;
1930 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1931 ifp->if_ioctl = qlnx_ioctl;
1932 ifp->if_transmit = qlnx_transmit;
1933 ifp->if_qflush = qlnx_qflush;
1934
1935 IFQ_SET_MAXLEN(&ifp->if_snd, qlnx_get_ifq_snd_maxlen(ha));
1936 ifp->if_snd.ifq_drv_maxlen = qlnx_get_ifq_snd_maxlen(ha);
1937 IFQ_SET_READY(&ifp->if_snd);
1938
1939#if __FreeBSD_version >= 1100036
1940 if_setgetcounterfn(ifp, qlnx_get_counter);
1941#endif
1942
1943 ha->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1944
1945 memcpy(ha->primary_mac, qlnx_get_mac_addr(ha), ETH_ALEN);
1946 ether_ifattach(ifp, ha->primary_mac);
1947 bcopy(IF_LLADDR(ha->ifp), ha->primary_mac, ETHER_ADDR_LEN);
1948
1949 ifp->if_capabilities = IFCAP_HWCSUM;
1950 ifp->if_capabilities |= IFCAP_JUMBO_MTU;
1951
1952 ifp->if_capabilities |= IFCAP_VLAN_MTU;
1953 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING;
1954 ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
1955 ifp->if_capabilities |= IFCAP_VLAN_HWCSUM;
1956 ifp->if_capabilities |= IFCAP_VLAN_HWTSO;
1957 ifp->if_capabilities |= IFCAP_TSO4;
1958 ifp->if_capabilities |= IFCAP_TSO6;
1959 ifp->if_capabilities |= IFCAP_LRO;
1960
1961 ifp->if_capenable = ifp->if_capabilities;
1962
1963 ifp->if_hwassist = CSUM_IP;
1964 ifp->if_hwassist |= CSUM_TCP | CSUM_UDP;
1965 ifp->if_hwassist |= CSUM_TCP_IPV6 | CSUM_UDP_IPV6;
1966 ifp->if_hwassist |= CSUM_TSO;
1967
1968 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
1969
1970 ifmedia_init(&ha->media, IFM_IMASK, qlnx_media_change,\
1971 qlnx_media_status);
1972
1973 if (device_id == QLOGIC_PCI_DEVICE_ID_1634) {
1974 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_LR4), 0, NULL);
1975 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_SR4), 0, NULL);
1976 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_CR4), 0, NULL);
1932 ifp->if_baudrate = IF_Gbps(25);
1933 else if (device_id == QLOGIC_PCI_DEVICE_ID_1654)
1934 ifp->if_baudrate = IF_Gbps(50);
1935 else if (device_id == QLOGIC_PCI_DEVICE_ID_1644)
1936 ifp->if_baudrate = IF_Gbps(100);
1937
1938 ifp->if_capabilities = IFCAP_LINKSTATE;
1939#else
1940 ifp->if_mtu = ETHERMTU;
1941 ifp->if_baudrate = (1 * 1000 * 1000 *1000);
1942
1943#endif /* #if __FreeBSD_version >= 1000000 */
1944
1945 ifp->if_init = qlnx_init;
1946 ifp->if_softc = ha;
1947 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1948 ifp->if_ioctl = qlnx_ioctl;
1949 ifp->if_transmit = qlnx_transmit;
1950 ifp->if_qflush = qlnx_qflush;
1951
1952 IFQ_SET_MAXLEN(&ifp->if_snd, qlnx_get_ifq_snd_maxlen(ha));
1953 ifp->if_snd.ifq_drv_maxlen = qlnx_get_ifq_snd_maxlen(ha);
1954 IFQ_SET_READY(&ifp->if_snd);
1955
1956#if __FreeBSD_version >= 1100036
1957 if_setgetcounterfn(ifp, qlnx_get_counter);
1958#endif
1959
1960 ha->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1961
1962 memcpy(ha->primary_mac, qlnx_get_mac_addr(ha), ETH_ALEN);
1963 ether_ifattach(ifp, ha->primary_mac);
1964 bcopy(IF_LLADDR(ha->ifp), ha->primary_mac, ETHER_ADDR_LEN);
1965
1966 ifp->if_capabilities = IFCAP_HWCSUM;
1967 ifp->if_capabilities |= IFCAP_JUMBO_MTU;
1968
1969 ifp->if_capabilities |= IFCAP_VLAN_MTU;
1970 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING;
1971 ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
1972 ifp->if_capabilities |= IFCAP_VLAN_HWCSUM;
1973 ifp->if_capabilities |= IFCAP_VLAN_HWTSO;
1974 ifp->if_capabilities |= IFCAP_TSO4;
1975 ifp->if_capabilities |= IFCAP_TSO6;
1976 ifp->if_capabilities |= IFCAP_LRO;
1977
1978 ifp->if_capenable = ifp->if_capabilities;
1979
1980 ifp->if_hwassist = CSUM_IP;
1981 ifp->if_hwassist |= CSUM_TCP | CSUM_UDP;
1982 ifp->if_hwassist |= CSUM_TCP_IPV6 | CSUM_UDP_IPV6;
1983 ifp->if_hwassist |= CSUM_TSO;
1984
1985 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
1986
1987 ifmedia_init(&ha->media, IFM_IMASK, qlnx_media_change,\
1988 qlnx_media_status);
1989
1990 if (device_id == QLOGIC_PCI_DEVICE_ID_1634) {
1991 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_LR4), 0, NULL);
1992 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_SR4), 0, NULL);
1993 ifmedia_add(&ha->media, (IFM_ETHER | IFM_40G_CR4), 0, NULL);
1977 } else if (device_id == QLOGIC_PCI_DEVICE_ID_1656) {
1994 } else if ((device_id == QLOGIC_PCI_DEVICE_ID_1656) ||
1995 (device_id == QLOGIC_PCI_DEVICE_ID_8070)) {
1978 ifmedia_add(&ha->media, (IFM_ETHER | QLNX_IFM_25G_SR), 0, NULL);
1979 ifmedia_add(&ha->media, (IFM_ETHER | QLNX_IFM_25G_CR), 0, NULL);
1980 } else if (device_id == QLOGIC_PCI_DEVICE_ID_1654) {
1981 ifmedia_add(&ha->media, (IFM_ETHER | IFM_50G_KR2), 0, NULL);
1982 ifmedia_add(&ha->media, (IFM_ETHER | IFM_50G_CR2), 0, NULL);
1983 } else if (device_id == QLOGIC_PCI_DEVICE_ID_1644) {
1984 ifmedia_add(&ha->media,
1985 (IFM_ETHER | QLNX_IFM_100G_LR4), 0, NULL);
1986 ifmedia_add(&ha->media,
1987 (IFM_ETHER | QLNX_IFM_100G_SR4), 0, NULL);
1988 ifmedia_add(&ha->media,
1989 (IFM_ETHER | QLNX_IFM_100G_CR4), 0, NULL);
1990 }
1991
1992 ifmedia_add(&ha->media, (IFM_ETHER | IFM_FDX), 0, NULL);
1993 ifmedia_add(&ha->media, (IFM_ETHER | IFM_AUTO), 0, NULL);
1994
1995
1996 ifmedia_set(&ha->media, (IFM_ETHER | IFM_AUTO));
1997
1998 QL_DPRINT2(ha, "exit\n");
1999
2000 return;
2001}
2002
2003static void
2004qlnx_init_locked(qlnx_host_t *ha)
2005{
2006 struct ifnet *ifp = ha->ifp;
2007
2008 QL_DPRINT1(ha, "Driver Initialization start \n");
2009
2010 qlnx_stop(ha);
2011
2012 if (qlnx_load(ha) == 0) {
2013 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2014 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2015 }
2016
2017 return;
2018}
2019
2020static void
2021qlnx_init(void *arg)
2022{
2023 qlnx_host_t *ha;
2024
2025 ha = (qlnx_host_t *)arg;
2026
2027 QL_DPRINT2(ha, "enter\n");
2028
2029 QLNX_LOCK(ha);
2030 qlnx_init_locked(ha);
2031 QLNX_UNLOCK(ha);
2032
2033 QL_DPRINT2(ha, "exit\n");
2034
2035 return;
2036}
2037
2038static int
2039qlnx_config_mcast_mac_addr(qlnx_host_t *ha, uint8_t *mac_addr, uint32_t add_mac)
2040{
2041 struct ecore_filter_mcast *mcast;
2042 struct ecore_dev *cdev;
2043 int rc;
2044
2045 cdev = &ha->cdev;
2046
2047 mcast = &ha->ecore_mcast;
2048 bzero(mcast, sizeof(struct ecore_filter_mcast));
2049
2050 if (add_mac)
2051 mcast->opcode = ECORE_FILTER_ADD;
2052 else
2053 mcast->opcode = ECORE_FILTER_REMOVE;
2054
2055 mcast->num_mc_addrs = 1;
2056 memcpy(mcast->mac, mac_addr, ETH_ALEN);
2057
2058 rc = ecore_filter_mcast_cmd(cdev, mcast, ECORE_SPQ_MODE_CB, NULL);
2059
2060 return (rc);
2061}
2062
2063static int
2064qlnx_hw_add_mcast(qlnx_host_t *ha, uint8_t *mta)
2065{
2066 int i;
2067
2068 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
2069
2070 if (QL_MAC_CMP(ha->mcast[i].addr, mta) == 0)
2071 return 0; /* its been already added */
2072 }
2073
2074 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
2075
2076 if ((ha->mcast[i].addr[0] == 0) &&
2077 (ha->mcast[i].addr[1] == 0) &&
2078 (ha->mcast[i].addr[2] == 0) &&
2079 (ha->mcast[i].addr[3] == 0) &&
2080 (ha->mcast[i].addr[4] == 0) &&
2081 (ha->mcast[i].addr[5] == 0)) {
2082
2083 if (qlnx_config_mcast_mac_addr(ha, mta, 1))
2084 return (-1);
2085
2086 bcopy(mta, ha->mcast[i].addr, ETH_ALEN);
2087 ha->nmcast++;
2088
2089 return 0;
2090 }
2091 }
2092 return 0;
2093}
2094
2095static int
2096qlnx_hw_del_mcast(qlnx_host_t *ha, uint8_t *mta)
2097{
2098 int i;
2099
2100 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
2101 if (QL_MAC_CMP(ha->mcast[i].addr, mta) == 0) {
2102
2103 if (qlnx_config_mcast_mac_addr(ha, mta, 0))
2104 return (-1);
2105
2106 ha->mcast[i].addr[0] = 0;
2107 ha->mcast[i].addr[1] = 0;
2108 ha->mcast[i].addr[2] = 0;
2109 ha->mcast[i].addr[3] = 0;
2110 ha->mcast[i].addr[4] = 0;
2111 ha->mcast[i].addr[5] = 0;
2112
2113 ha->nmcast--;
2114
2115 return 0;
2116 }
2117 }
2118 return 0;
2119}
2120
2121/*
2122 * Name: qls_hw_set_multi
2123 * Function: Sets the Multicast Addresses provided the host O.S into the
2124 * hardware (for the given interface)
2125 */
2126static void
2127qlnx_hw_set_multi(qlnx_host_t *ha, uint8_t *mta, uint32_t mcnt,
2128 uint32_t add_mac)
2129{
2130 int i;
2131
2132 for (i = 0; i < mcnt; i++) {
2133 if (add_mac) {
2134 if (qlnx_hw_add_mcast(ha, mta))
2135 break;
2136 } else {
2137 if (qlnx_hw_del_mcast(ha, mta))
2138 break;
2139 }
2140
2141 mta += ETHER_HDR_LEN;
2142 }
2143 return;
2144}
2145
2146
2147#define QLNX_MCAST_ADDRS_SIZE (QLNX_MAX_NUM_MULTICAST_ADDRS * ETHER_HDR_LEN)
2148static int
2149qlnx_set_multi(qlnx_host_t *ha, uint32_t add_multi)
2150{
2151 uint8_t mta[QLNX_MCAST_ADDRS_SIZE];
2152 struct ifmultiaddr *ifma;
2153 int mcnt = 0;
2154 struct ifnet *ifp = ha->ifp;
2155 int ret = 0;
2156
2157 if_maddr_rlock(ifp);
2158
2159 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
2160
2161 if (ifma->ifma_addr->sa_family != AF_LINK)
2162 continue;
2163
2164 if (mcnt == QLNX_MAX_NUM_MULTICAST_ADDRS)
2165 break;
2166
2167 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
2168 &mta[mcnt * ETHER_HDR_LEN], ETHER_HDR_LEN);
2169
2170 mcnt++;
2171 }
2172
2173 if_maddr_runlock(ifp);
2174
2175 QLNX_LOCK(ha);
2176 qlnx_hw_set_multi(ha, mta, mcnt, add_multi);
2177 QLNX_UNLOCK(ha);
2178
2179 return (ret);
2180}
2181
2182static int
2183qlnx_set_promisc(qlnx_host_t *ha)
2184{
2185 int rc = 0;
2186 uint8_t filter;
2187
2188 filter = ha->filter;
2189 filter |= ECORE_ACCEPT_MCAST_UNMATCHED;
2190 filter |= ECORE_ACCEPT_UCAST_UNMATCHED;
2191
2192 rc = qlnx_set_rx_accept_filter(ha, filter);
2193 return (rc);
2194}
2195
2196static int
2197qlnx_set_allmulti(qlnx_host_t *ha)
2198{
2199 int rc = 0;
2200 uint8_t filter;
2201
2202 filter = ha->filter;
2203 filter |= ECORE_ACCEPT_MCAST_UNMATCHED;
2204 rc = qlnx_set_rx_accept_filter(ha, filter);
2205
2206 return (rc);
2207}
2208
2209
2210static int
2211qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
2212{
2213 int ret = 0, mask;
2214 struct ifreq *ifr = (struct ifreq *)data;
2215 struct ifaddr *ifa = (struct ifaddr *)data;
2216 qlnx_host_t *ha;
2217
2218 ha = (qlnx_host_t *)ifp->if_softc;
2219
2220 switch (cmd) {
2221 case SIOCSIFADDR:
2222 QL_DPRINT4(ha, "SIOCSIFADDR (0x%lx)\n", cmd);
2223
2224 if (ifa->ifa_addr->sa_family == AF_INET) {
2225 ifp->if_flags |= IFF_UP;
2226 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2227 QLNX_LOCK(ha);
2228 qlnx_init_locked(ha);
2229 QLNX_UNLOCK(ha);
2230 }
2231 QL_DPRINT4(ha, "SIOCSIFADDR (0x%lx) ipv4 [0x%08x]\n",
2232 cmd, ntohl(IA_SIN(ifa)->sin_addr.s_addr));
2233
2234 arp_ifinit(ifp, ifa);
2235 } else {
2236 ether_ioctl(ifp, cmd, data);
2237 }
2238 break;
2239
2240 case SIOCSIFMTU:
2241 QL_DPRINT4(ha, "SIOCSIFMTU (0x%lx)\n", cmd);
2242
2243 if (ifr->ifr_mtu > QLNX_MAX_MTU) {
2244 ret = EINVAL;
2245 } else {
2246 QLNX_LOCK(ha);
2247 ifp->if_mtu = ifr->ifr_mtu;
2248 ha->max_frame_size =
2249 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2250 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2251 qlnx_init_locked(ha);
2252 }
2253
2254 QLNX_UNLOCK(ha);
2255 }
2256
2257 break;
2258
2259 case SIOCSIFFLAGS:
2260 QL_DPRINT4(ha, "SIOCSIFFLAGS (0x%lx)\n", cmd);
2261
2262 QLNX_LOCK(ha);
2263
2264 if (ifp->if_flags & IFF_UP) {
2265 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2266 if ((ifp->if_flags ^ ha->if_flags) &
2267 IFF_PROMISC) {
2268 ret = qlnx_set_promisc(ha);
2269 } else if ((ifp->if_flags ^ ha->if_flags) &
2270 IFF_ALLMULTI) {
2271 ret = qlnx_set_allmulti(ha);
2272 }
2273 } else {
2274 ha->max_frame_size = ifp->if_mtu +
2275 ETHER_HDR_LEN + ETHER_CRC_LEN;
2276 qlnx_init_locked(ha);
2277 }
2278 } else {
2279 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2280 qlnx_stop(ha);
2281 ha->if_flags = ifp->if_flags;
2282 }
2283
2284 QLNX_UNLOCK(ha);
2285 break;
2286
2287 case SIOCADDMULTI:
2288 QL_DPRINT4(ha, "%s (0x%lx)\n", "SIOCADDMULTI", cmd);
2289
2290 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2291 if (qlnx_set_multi(ha, 1))
2292 ret = EINVAL;
2293 }
2294 break;
2295
2296 case SIOCDELMULTI:
2297 QL_DPRINT4(ha, "%s (0x%lx)\n", "SIOCDELMULTI", cmd);
2298
2299 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2300 if (qlnx_set_multi(ha, 0))
2301 ret = EINVAL;
2302 }
2303 break;
2304
2305 case SIOCSIFMEDIA:
2306 case SIOCGIFMEDIA:
2307 QL_DPRINT4(ha, "SIOCSIFMEDIA/SIOCGIFMEDIA (0x%lx)\n", cmd);
2308
2309 ret = ifmedia_ioctl(ifp, ifr, &ha->media, cmd);
2310 break;
2311
2312 case SIOCSIFCAP:
2313
2314 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
2315
2316 QL_DPRINT4(ha, "SIOCSIFCAP (0x%lx)\n", cmd);
2317
2318 if (mask & IFCAP_HWCSUM)
2319 ifp->if_capenable ^= IFCAP_HWCSUM;
2320 if (mask & IFCAP_TSO4)
2321 ifp->if_capenable ^= IFCAP_TSO4;
2322 if (mask & IFCAP_TSO6)
2323 ifp->if_capenable ^= IFCAP_TSO6;
2324 if (mask & IFCAP_VLAN_HWTAGGING)
2325 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
2326 if (mask & IFCAP_VLAN_HWTSO)
2327 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
2328 if (mask & IFCAP_LRO)
2329 ifp->if_capenable ^= IFCAP_LRO;
2330
2331 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
2332 qlnx_init(ha);
2333
2334 VLAN_CAPABILITIES(ifp);
2335 break;
2336
2337#if (__FreeBSD_version >= 1100101)
2338
2339 case SIOCGI2C:
2340 {
2341 struct ifi2creq i2c;
2342 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[0];
2343 struct ecore_ptt *p_ptt;
2344
2345 ret = copyin(ifr->ifr_data, &i2c, sizeof(i2c));
2346
2347 if (ret)
2348 break;
2349
2350 if ((i2c.len > sizeof (i2c.data)) ||
2351 (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2)) {
2352 ret = EINVAL;
2353 break;
2354 }
2355
2356 p_ptt = ecore_ptt_acquire(p_hwfn);
2357
2358 if (!p_ptt) {
2359 QL_DPRINT1(ha, "ecore_ptt_acquire failed\n");
2360 ret = -1;
2361 break;
2362 }
2363
2364 ret = ecore_mcp_phy_sfp_read(p_hwfn, p_ptt,
2365 (ha->pci_func & 0x1), i2c.dev_addr, i2c.offset,
2366 i2c.len, &i2c.data[0]);
2367
2368 ecore_ptt_release(p_hwfn, p_ptt);
2369
2370 if (ret) {
2371 ret = -1;
2372 break;
2373 }
2374
2375 ret = copyout(&i2c, ifr->ifr_data, sizeof(i2c));
2376
2377 QL_DPRINT8(ha, "SIOCGI2C copyout ret = %d \
2378 len = %d addr = 0x%02x offset = 0x%04x \
2379 data[0..7]=0x%02x 0x%02x 0x%02x 0x%02x 0x%02x \
2380 0x%02x 0x%02x 0x%02x\n",
2381 ret, i2c.len, i2c.dev_addr, i2c.offset,
2382 i2c.data[0], i2c.data[1], i2c.data[2], i2c.data[3],
2383 i2c.data[4], i2c.data[5], i2c.data[6], i2c.data[7]);
2384 break;
2385 }
2386#endif /* #if (__FreeBSD_version >= 1100101) */
2387
2388 default:
2389 QL_DPRINT4(ha, "default (0x%lx)\n", cmd);
2390 ret = ether_ioctl(ifp, cmd, data);
2391 break;
2392 }
2393
2394 return (ret);
2395}
2396
2397static int
2398qlnx_media_change(struct ifnet *ifp)
2399{
2400 qlnx_host_t *ha;
2401 struct ifmedia *ifm;
2402 int ret = 0;
2403
2404 ha = (qlnx_host_t *)ifp->if_softc;
2405
2406 QL_DPRINT2(ha, "enter\n");
2407
2408 ifm = &ha->media;
2409
2410 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
2411 ret = EINVAL;
2412
2413 QL_DPRINT2(ha, "exit\n");
2414
2415 return (ret);
2416}
2417
2418static void
2419qlnx_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
2420{
2421 qlnx_host_t *ha;
2422
2423 ha = (qlnx_host_t *)ifp->if_softc;
2424
2425 QL_DPRINT2(ha, "enter\n");
2426
2427 ifmr->ifm_status = IFM_AVALID;
2428 ifmr->ifm_active = IFM_ETHER;
2429
2430 if (ha->link_up) {
2431 ifmr->ifm_status |= IFM_ACTIVE;
2432 ifmr->ifm_active |=
2433 (IFM_FDX | qlnx_get_optics(ha, &ha->if_link));
2434
2435 if (ha->if_link.link_partner_caps &
2436 (QLNX_LINK_CAP_Pause | QLNX_LINK_CAP_Asym_Pause))
2437 ifmr->ifm_active |=
2438 (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
2439 }
2440
2441 QL_DPRINT2(ha, "exit (%s)\n", (ha->link_up ? "link_up" : "link_down"));
2442
2443 return;
2444}
2445
2446
2447static void
2448qlnx_free_tx_pkt(qlnx_host_t *ha, struct qlnx_fastpath *fp,
2449 struct qlnx_tx_queue *txq)
2450{
2451 u16 idx;
2452 struct mbuf *mp;
2453 bus_dmamap_t map;
2454 int i;
2455 struct eth_tx_bd *tx_data_bd;
2456 struct eth_tx_1st_bd *first_bd;
2457 int nbds = 0;
2458
2459 idx = txq->sw_tx_cons;
2460 mp = txq->sw_tx_ring[idx].mp;
2461 map = txq->sw_tx_ring[idx].map;
2462
2463 if ((mp == NULL) || QL_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_MBUF_NULL)){
2464
2465 QL_RESET_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_MBUF_NULL);
2466
2467 QL_DPRINT1(ha, "(mp == NULL) "
2468 " tx_idx = 0x%x"
2469 " ecore_prod_idx = 0x%x"
2470 " ecore_cons_idx = 0x%x"
2471 " hw_bd_cons = 0x%x"
2472 " txq_db_last = 0x%x"
2473 " elem_left = 0x%x\n",
2474 fp->rss_id,
2475 ecore_chain_get_prod_idx(&txq->tx_pbl),
2476 ecore_chain_get_cons_idx(&txq->tx_pbl),
2477 le16toh(*txq->hw_cons_ptr),
2478 txq->tx_db.raw,
2479 ecore_chain_get_elem_left(&txq->tx_pbl));
2480
2481 fp->err_tx_free_pkt_null++;
2482
2483 //DEBUG
2484 qlnx_trigger_dump(ha);
2485
2486 return;
2487 } else {
2488
2489 QLNX_INC_OPACKETS((ha->ifp));
2490 QLNX_INC_OBYTES((ha->ifp), (mp->m_pkthdr.len));
2491
2492 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_POSTWRITE);
2493 bus_dmamap_unload(ha->tx_tag, map);
2494
2495 fp->tx_pkts_freed++;
2496 fp->tx_pkts_completed++;
2497
2498 m_freem(mp);
2499 }
2500
2501 first_bd = (struct eth_tx_1st_bd *)ecore_chain_consume(&txq->tx_pbl);
2502 nbds = first_bd->data.nbds;
2503
2504// BD_SET_UNMAP_ADDR_LEN(first_bd, 0, 0);
2505
2506 for (i = 1; i < nbds; i++) {
2507 tx_data_bd = ecore_chain_consume(&txq->tx_pbl);
2508// BD_SET_UNMAP_ADDR_LEN(tx_data_bd, 0, 0);
2509 }
2510 txq->sw_tx_ring[idx].flags = 0;
2511 txq->sw_tx_ring[idx].mp = NULL;
2512 txq->sw_tx_ring[idx].map = (bus_dmamap_t)0;
2513
2514 return;
2515}
2516
2517static void
2518qlnx_tx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp,
2519 struct qlnx_tx_queue *txq)
2520{
2521 u16 hw_bd_cons;
2522 u16 ecore_cons_idx;
2523 uint16_t diff;
2524
2525 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
2526
2527 while (hw_bd_cons !=
2528 (ecore_cons_idx = ecore_chain_get_cons_idx(&txq->tx_pbl))) {
2529
2530 if (hw_bd_cons < ecore_cons_idx) {
2531 diff = (1 << 16) - (ecore_cons_idx - hw_bd_cons);
2532 } else {
2533 diff = hw_bd_cons - ecore_cons_idx;
2534 }
2535 if ((diff > TX_RING_SIZE) ||
2536 QL_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_DIFF)){
2537
2538 QL_RESET_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_DIFF);
2539
2540 QL_DPRINT1(ha, "(diff = 0x%x) "
2541 " tx_idx = 0x%x"
2542 " ecore_prod_idx = 0x%x"
2543 " ecore_cons_idx = 0x%x"
2544 " hw_bd_cons = 0x%x"
2545 " txq_db_last = 0x%x"
2546 " elem_left = 0x%x\n",
2547 diff,
2548 fp->rss_id,
2549 ecore_chain_get_prod_idx(&txq->tx_pbl),
2550 ecore_chain_get_cons_idx(&txq->tx_pbl),
2551 le16toh(*txq->hw_cons_ptr),
2552 txq->tx_db.raw,
2553 ecore_chain_get_elem_left(&txq->tx_pbl));
2554
2555 fp->err_tx_cons_idx_conflict++;
2556
2557 //DEBUG
2558 qlnx_trigger_dump(ha);
2559 }
2560
2561 qlnx_free_tx_pkt(ha, fp, txq);
2562
2563 txq->sw_tx_cons = (txq->sw_tx_cons + 1) & (TX_RING_SIZE - 1);
2564 }
2565 return;
2566}
2567
2568static int
2569qlnx_transmit(struct ifnet *ifp, struct mbuf *mp)
2570{
2571 qlnx_host_t *ha = (qlnx_host_t *)ifp->if_softc;
2572 struct qlnx_fastpath *fp;
2573 int rss_id = 0, ret = 0;
2574
2575 QL_DPRINT2(ha, "enter\n");
2576
2577#if __FreeBSD_version >= 1100000
2578 if (M_HASHTYPE_GET(mp) != M_HASHTYPE_NONE)
2579#else
2580 if (mp->m_flags & M_FLOWID)
2581#endif
2582 rss_id = (mp->m_pkthdr.flowid % ECORE_RSS_IND_TABLE_SIZE) %
2583 ha->num_rss;
2584
2585 fp = &ha->fp_array[rss_id];
2586
2587 if (fp->tx_br == NULL) {
2588 ret = EINVAL;
2589 goto qlnx_transmit_exit;
2590 }
2591
2592 if (mp != NULL) {
2593 ret = drbr_enqueue(ifp, fp->tx_br, mp);
2594 }
2595
2596 if (fp->fp_taskqueue != NULL)
2597 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
2598
2599 ret = 0;
2600
2601qlnx_transmit_exit:
2602
2603 QL_DPRINT2(ha, "exit ret = %d\n", ret);
2604 return ret;
2605}
2606
2607static void
2608qlnx_qflush(struct ifnet *ifp)
2609{
2610 int rss_id;
2611 struct qlnx_fastpath *fp;
2612 struct mbuf *mp;
2613 qlnx_host_t *ha;
2614
2615 ha = (qlnx_host_t *)ifp->if_softc;
2616
2617 QL_DPRINT2(ha, "enter\n");
2618
2619 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
2620
2621 fp = &ha->fp_array[rss_id];
2622
2623 if (fp == NULL)
2624 continue;
2625
2626 if (fp->tx_br) {
2627 mtx_lock(&fp->tx_mtx);
2628
2629 while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) {
2630 fp->tx_pkts_freed++;
2631 m_freem(mp);
2632 }
2633 mtx_unlock(&fp->tx_mtx);
2634 }
2635 }
2636 QL_DPRINT2(ha, "exit\n");
2637
2638 return;
2639}
2640
2641static void
2642qlnx_txq_doorbell_wr32(qlnx_host_t *ha, void *reg_addr, uint32_t value)
2643{
2644 struct ecore_dev *cdev;
2645 uint32_t offset;
2646
2647 cdev = &ha->cdev;
2648
2649 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)cdev->doorbells);
2650
2651 bus_write_4(ha->pci_dbells, offset, value);
2652 bus_barrier(ha->pci_reg, 0, 0, BUS_SPACE_BARRIER_READ);
2653 bus_barrier(ha->pci_dbells, 0, 0, BUS_SPACE_BARRIER_READ);
2654
2655 return;
2656}
2657
2658static uint32_t
2659qlnx_tcp_offset(qlnx_host_t *ha, struct mbuf *mp)
2660{
2661 struct ether_vlan_header *eh = NULL;
2662 struct ip *ip = NULL;
2663 struct ip6_hdr *ip6 = NULL;
2664 struct tcphdr *th = NULL;
2665 uint32_t ehdrlen = 0, ip_hlen = 0, offset = 0;
2666 uint16_t etype = 0;
2667 device_t dev;
2668 uint8_t buf[sizeof(struct ip6_hdr)];
2669
2670 dev = ha->pci_dev;
2671
2672 eh = mtod(mp, struct ether_vlan_header *);
2673
2674 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
2675 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
2676 etype = ntohs(eh->evl_proto);
2677 } else {
2678 ehdrlen = ETHER_HDR_LEN;
2679 etype = ntohs(eh->evl_encap_proto);
2680 }
2681
2682 switch (etype) {
2683
2684 case ETHERTYPE_IP:
2685 ip = (struct ip *)(mp->m_data + ehdrlen);
2686
2687 ip_hlen = sizeof (struct ip);
2688
2689 if (mp->m_len < (ehdrlen + ip_hlen)) {
2690 m_copydata(mp, ehdrlen, sizeof(struct ip), buf);
2691 ip = (struct ip *)buf;
2692 }
2693
2694 th = (struct tcphdr *)(ip + 1);
2695 offset = ip_hlen + ehdrlen + (th->th_off << 2);
2696 break;
2697
2698 case ETHERTYPE_IPV6:
2699 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
2700
2701 ip_hlen = sizeof(struct ip6_hdr);
2702
2703 if (mp->m_len < (ehdrlen + ip_hlen)) {
2704 m_copydata(mp, ehdrlen, sizeof (struct ip6_hdr),
2705 buf);
2706 ip6 = (struct ip6_hdr *)buf;
2707 }
2708 th = (struct tcphdr *)(ip6 + 1);
2709 offset = ip_hlen + ehdrlen + (th->th_off << 2);
2710 break;
2711
2712 default:
2713 break;
2714 }
2715
2716 return (offset);
2717}
2718
2719static __inline int
2720qlnx_tso_check(struct qlnx_fastpath *fp, bus_dma_segment_t *segs, int nsegs,
2721 uint32_t offset)
2722{
2723 int i;
2724 uint32_t sum, nbds_in_hdr = 1;
2725 bus_dma_segment_t *t_segs = segs;
2726
2727 /* count the number of segments spanned by TCP header */
2728
2729 i = 0;
2730 while ((i < nsegs) && (offset > t_segs->ds_len)) {
2731 nbds_in_hdr++;
2732 offset = offset - t_segs->ds_len;
2733 t_segs++;
2734 i++;
2735 }
2736
2737 while (nsegs >= QLNX_MAX_SEGMENTS_NON_TSO) {
2738
2739 sum = 0;
2740
2741 for (i = 0; i < (ETH_TX_LSO_WINDOW_BDS_NUM - nbds_in_hdr); i++){
2742 sum += segs->ds_len;
2743 segs++;
2744 }
2745
2746 if (sum < ETH_TX_LSO_WINDOW_MIN_LEN) {
2747 fp->tx_lso_wnd_min_len++;
2748 return (-1);
2749 }
2750
2751 nsegs -= QLNX_MAX_SEGMENTS_NON_TSO;
2752 }
2753
2754 return (0);
2755}
2756
2757static int
2758qlnx_send(qlnx_host_t *ha, struct qlnx_fastpath *fp, struct mbuf **m_headp)
2759{
2760 bus_dma_segment_t *segs;
2761 bus_dmamap_t map = 0;
2762 uint32_t nsegs = 0;
2763 int ret = -1;
2764 struct mbuf *m_head = *m_headp;
2765 uint16_t idx = 0;
2766 uint16_t elem_left;
2767
2768 uint8_t nbd = 0;
2769 struct qlnx_tx_queue *txq;
2770
2771 struct eth_tx_1st_bd *first_bd;
2772 struct eth_tx_2nd_bd *second_bd;
2773 struct eth_tx_3rd_bd *third_bd;
2774 struct eth_tx_bd *tx_data_bd;
2775
2776 int seg_idx = 0;
2777 uint32_t nbds_in_hdr = 0;
2778 uint32_t offset = 0;
2779
2780 QL_DPRINT8(ha, "enter\n");
2781
2782 if (!ha->link_up)
2783 return (-1);
2784
2785 first_bd = NULL;
2786 second_bd = NULL;
2787 third_bd = NULL;
2788 tx_data_bd = NULL;
2789
2790 txq = fp->txq[0];
2791
2792 if (fp->tx_ring_full) {
2793 elem_left = ecore_chain_get_elem_left(&txq->tx_pbl);
2794
2795 if (elem_left < (TX_RING_SIZE >> 4))
2796 return (-1);
2797 else
2798 fp->tx_ring_full = 0;
2799 }
2800
2801 idx = txq->sw_tx_prod;
2802
2803 map = txq->sw_tx_ring[idx].map;
2804 segs = txq->segs;
2805
2806 ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, segs, &nsegs,
2807 BUS_DMA_NOWAIT);
2808
2809 if (ha->dbg_trace_tso_pkt_len) {
2810 if (!fp->tx_tso_min_pkt_len) {
2811 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2812 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2813 } else {
2814 if (fp->tx_tso_min_pkt_len > m_head->m_pkthdr.len)
2815 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2816 if (fp->tx_tso_max_pkt_len < m_head->m_pkthdr.len)
2817 fp->tx_tso_max_pkt_len = m_head->m_pkthdr.len;
2818 }
2819 }
2820
2821 if (m_head->m_pkthdr.csum_flags & CSUM_TSO)
2822 offset = qlnx_tcp_offset(ha, m_head);
2823
2824 if ((ret == EFBIG) ||
2825 ((nsegs > QLNX_MAX_SEGMENTS_NON_TSO) && (
2826 (!(m_head->m_pkthdr.csum_flags & CSUM_TSO)) ||
2827 ((m_head->m_pkthdr.csum_flags & CSUM_TSO) &&
2828 qlnx_tso_check(fp, segs, nsegs, offset))))) {
2829
2830 struct mbuf *m;
2831
2832 QL_DPRINT8(ha, "EFBIG [%d]\n", m_head->m_pkthdr.len);
2833
2834 fp->tx_defrag++;
2835
2836 m = m_defrag(m_head, M_NOWAIT);
2837 if (m == NULL) {
2838 fp->err_tx_defrag++;
2839 fp->tx_pkts_freed++;
2840 m_freem(m_head);
2841 *m_headp = NULL;
2842 QL_DPRINT1(ha, "m_defrag() = NULL [%d]\n", ret);
2843 return (ENOBUFS);
2844 }
2845
2846 m_head = m;
2847 *m_headp = m_head;
2848
2849 if ((ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head,
2850 segs, &nsegs, BUS_DMA_NOWAIT))) {
2851
2852 fp->err_tx_defrag_dmamap_load++;
2853
2854 QL_DPRINT1(ha,
2855 "bus_dmamap_load_mbuf_sg failed0 [%d, %d]\n",
2856 ret, m_head->m_pkthdr.len);
2857
2858 fp->tx_pkts_freed++;
2859 m_freem(m_head);
2860 *m_headp = NULL;
2861
2862 return (ret);
2863 }
2864
2865 if ((nsegs > QLNX_MAX_SEGMENTS_NON_TSO) &&
2866 !(m_head->m_pkthdr.csum_flags & CSUM_TSO)) {
2867
2868 fp->err_tx_non_tso_max_seg++;
2869
2870 QL_DPRINT1(ha,
2871 "(%d) nsegs too many for non-TSO [%d, %d]\n",
2872 ret, nsegs, m_head->m_pkthdr.len);
2873
2874 fp->tx_pkts_freed++;
2875 m_freem(m_head);
2876 *m_headp = NULL;
2877
2878 return (ret);
2879 }
2880 if (m_head->m_pkthdr.csum_flags & CSUM_TSO)
2881 offset = qlnx_tcp_offset(ha, m_head);
2882
2883 } else if (ret) {
2884
2885 fp->err_tx_dmamap_load++;
2886
2887 QL_DPRINT1(ha, "bus_dmamap_load_mbuf_sg failed1 [%d, %d]\n",
2888 ret, m_head->m_pkthdr.len);
2889 fp->tx_pkts_freed++;
2890 m_freem(m_head);
2891 *m_headp = NULL;
2892 return (ret);
2893 }
2894
2895 QL_ASSERT(ha, (nsegs != 0), ("qlnx_send: empty packet"));
2896
2897 if (ha->dbg_trace_tso_pkt_len) {
2898 if (nsegs < QLNX_FP_MAX_SEGS)
2899 fp->tx_pkts[(nsegs - 1)]++;
2900 else
2901 fp->tx_pkts[(QLNX_FP_MAX_SEGS - 1)]++;
2902 }
2903
2904 if ((nsegs + QLNX_TX_ELEM_RESERVE) >
2905 (int)(elem_left = ecore_chain_get_elem_left(&txq->tx_pbl))) {
2906
2907 QL_DPRINT1(ha, "(%d, 0x%x) insuffient BDs"
2908 " in chain[%d] trying to free packets\n",
2909 nsegs, elem_left, fp->rss_id);
2910
2911 fp->tx_nsegs_gt_elem_left++;
2912
2913 (void)qlnx_tx_int(ha, fp, txq);
2914
2915 if ((nsegs + QLNX_TX_ELEM_RESERVE) > (int)(elem_left =
2916 ecore_chain_get_elem_left(&txq->tx_pbl))) {
2917
2918 QL_DPRINT1(ha,
2919 "(%d, 0x%x) insuffient BDs in chain[%d]\n",
2920 nsegs, elem_left, fp->rss_id);
2921
2922 fp->err_tx_nsegs_gt_elem_left++;
2923 fp->tx_ring_full = 1;
2924 ha->storm_stats_enable = 1;
2925 return (ENOBUFS);
2926 }
2927 }
2928
2929 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_PREWRITE);
2930
2931 txq->sw_tx_ring[idx].mp = m_head;
2932
2933 first_bd = (struct eth_tx_1st_bd *)ecore_chain_produce(&txq->tx_pbl);
2934
2935 memset(first_bd, 0, sizeof(*first_bd));
2936
2937 first_bd->data.bd_flags.bitfields =
2938 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
2939
2940 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, segs->ds_len);
2941
2942 nbd++;
2943
2944 if (m_head->m_pkthdr.csum_flags & CSUM_IP) {
2945 first_bd->data.bd_flags.bitfields |=
2946 (1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT);
2947 }
2948
2949 if (m_head->m_pkthdr.csum_flags &
2950 (CSUM_UDP | CSUM_TCP | CSUM_TCP_IPV6 | CSUM_UDP_IPV6)) {
2951 first_bd->data.bd_flags.bitfields |=
2952 (1 << ETH_TX_1ST_BD_FLAGS_L4_CSUM_SHIFT);
2953 }
2954
2955 if (m_head->m_flags & M_VLANTAG) {
2956 first_bd->data.vlan = m_head->m_pkthdr.ether_vtag;
2957 first_bd->data.bd_flags.bitfields |=
2958 (1 << ETH_TX_1ST_BD_FLAGS_VLAN_INSERTION_SHIFT);
2959 }
2960
2961 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
2962
2963 first_bd->data.bd_flags.bitfields |=
2964 (1 << ETH_TX_1ST_BD_FLAGS_LSO_SHIFT);
2965 first_bd->data.bd_flags.bitfields |=
2966 (1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT);
2967
2968 nbds_in_hdr = 1;
2969
2970 if (offset == segs->ds_len) {
2971 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, offset);
2972 segs++;
2973 seg_idx++;
2974
2975 second_bd = (struct eth_tx_2nd_bd *)
2976 ecore_chain_produce(&txq->tx_pbl);
2977 memset(second_bd, 0, sizeof(*second_bd));
2978 nbd++;
2979
2980 if (seg_idx < nsegs) {
2981 BD_SET_UNMAP_ADDR_LEN(second_bd, \
2982 (segs->ds_addr), (segs->ds_len));
2983 segs++;
2984 seg_idx++;
2985 }
2986
2987 third_bd = (struct eth_tx_3rd_bd *)
2988 ecore_chain_produce(&txq->tx_pbl);
2989 memset(third_bd, 0, sizeof(*third_bd));
2990 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
2991 third_bd->data.bitfields |=
2992 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
2993 nbd++;
2994
2995 if (seg_idx < nsegs) {
2996 BD_SET_UNMAP_ADDR_LEN(third_bd, \
2997 (segs->ds_addr), (segs->ds_len));
2998 segs++;
2999 seg_idx++;
3000 }
3001
3002 for (; seg_idx < nsegs; seg_idx++) {
3003 tx_data_bd = (struct eth_tx_bd *)
3004 ecore_chain_produce(&txq->tx_pbl);
3005 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3006 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, \
3007 segs->ds_addr,\
3008 segs->ds_len);
3009 segs++;
3010 nbd++;
3011 }
3012
3013 } else if (offset < segs->ds_len) {
3014 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, offset);
3015
3016 second_bd = (struct eth_tx_2nd_bd *)
3017 ecore_chain_produce(&txq->tx_pbl);
3018 memset(second_bd, 0, sizeof(*second_bd));
3019 BD_SET_UNMAP_ADDR_LEN(second_bd, \
3020 (segs->ds_addr + offset),\
3021 (segs->ds_len - offset));
3022 nbd++;
3023 segs++;
3024
3025 third_bd = (struct eth_tx_3rd_bd *)
3026 ecore_chain_produce(&txq->tx_pbl);
3027 memset(third_bd, 0, sizeof(*third_bd));
3028
3029 BD_SET_UNMAP_ADDR_LEN(third_bd, \
3030 segs->ds_addr,\
3031 segs->ds_len);
3032 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
3033 third_bd->data.bitfields |=
3034 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
3035 segs++;
3036 nbd++;
3037
3038 for (seg_idx = 2; seg_idx < nsegs; seg_idx++) {
3039 tx_data_bd = (struct eth_tx_bd *)
3040 ecore_chain_produce(&txq->tx_pbl);
3041 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3042 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, \
3043 segs->ds_addr,\
3044 segs->ds_len);
3045 segs++;
3046 nbd++;
3047 }
3048
3049 } else {
3050 offset = offset - segs->ds_len;
3051 segs++;
3052
3053 for (seg_idx = 1; seg_idx < nsegs; seg_idx++) {
3054
3055 if (offset)
3056 nbds_in_hdr++;
3057
3058 tx_data_bd = (struct eth_tx_bd *)
3059 ecore_chain_produce(&txq->tx_pbl);
3060 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3061
3062 if (second_bd == NULL) {
3063 second_bd = (struct eth_tx_2nd_bd *)
3064 tx_data_bd;
3065 } else if (third_bd == NULL) {
3066 third_bd = (struct eth_tx_3rd_bd *)
3067 tx_data_bd;
3068 }
3069
3070 if (offset && (offset < segs->ds_len)) {
3071 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
3072 segs->ds_addr, offset);
3073
3074 tx_data_bd = (struct eth_tx_bd *)
3075 ecore_chain_produce(&txq->tx_pbl);
3076
3077 memset(tx_data_bd, 0,
3078 sizeof(*tx_data_bd));
3079
3080 if (second_bd == NULL) {
3081 second_bd =
3082 (struct eth_tx_2nd_bd *)tx_data_bd;
3083 } else if (third_bd == NULL) {
3084 third_bd =
3085 (struct eth_tx_3rd_bd *)tx_data_bd;
3086 }
3087 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
3088 (segs->ds_addr + offset), \
3089 (segs->ds_len - offset));
3090 nbd++;
3091 offset = 0;
3092 } else {
3093 if (offset)
3094 offset = offset - segs->ds_len;
3095 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
3096 segs->ds_addr, segs->ds_len);
3097 }
3098 segs++;
3099 nbd++;
3100 }
3101
3102 if (third_bd == NULL) {
3103 third_bd = (struct eth_tx_3rd_bd *)
3104 ecore_chain_produce(&txq->tx_pbl);
3105 memset(third_bd, 0, sizeof(*third_bd));
3106 }
3107
3108 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
3109 third_bd->data.bitfields |=
3110 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
3111 }
3112 } else {
3113 segs++;
3114 for (seg_idx = 1; seg_idx < nsegs; seg_idx++) {
3115 tx_data_bd = (struct eth_tx_bd *)
3116 ecore_chain_produce(&txq->tx_pbl);
3117 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3118 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, segs->ds_addr,\
3119 segs->ds_len);
3120 segs++;
3121 nbd++;
3122 }
3123 first_bd->data.bitfields =
3124 (m_head->m_pkthdr.len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK)
3125 << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
3126 first_bd->data.bitfields =
3127 htole16(first_bd->data.bitfields);
3128 }
3129
3130
3131 first_bd->data.nbds = nbd;
3132
3133 if (ha->dbg_trace_tso_pkt_len) {
3134 if (fp->tx_tso_max_nsegs < nsegs)
3135 fp->tx_tso_max_nsegs = nsegs;
3136
3137 if ((nsegs < fp->tx_tso_min_nsegs) || (!fp->tx_tso_min_nsegs))
3138 fp->tx_tso_min_nsegs = nsegs;
3139 }
3140
3141 txq->sw_tx_ring[idx].nsegs = nsegs;
3142 txq->sw_tx_prod = (txq->sw_tx_prod + 1) & (TX_RING_SIZE - 1);
3143
3144 txq->tx_db.data.bd_prod =
3145 htole16(ecore_chain_get_prod_idx(&txq->tx_pbl));
3146
3147 qlnx_txq_doorbell_wr32(ha, txq->doorbell_addr, txq->tx_db.raw);
3148
3149 QL_DPRINT8(ha, "exit\n");
3150 return (0);
3151}
3152
3153static void
3154qlnx_stop(qlnx_host_t *ha)
3155{
3156 struct ifnet *ifp = ha->ifp;
3157 device_t dev;
3158 int i;
3159
3160 dev = ha->pci_dev;
3161
3162 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
3163
3164 /*
3165 * We simply lock and unlock each fp->tx_mtx to
3166 * propagate the if_drv_flags
3167 * state to each tx thread
3168 */
3169 QL_DPRINT1(ha, "QLNX STATE = %d\n",ha->state);
3170
3171 if (ha->state == QLNX_STATE_OPEN) {
3172 for (i = 0; i < ha->num_rss; i++) {
3173 struct qlnx_fastpath *fp = &ha->fp_array[i];
3174
3175 mtx_lock(&fp->tx_mtx);
3176 mtx_unlock(&fp->tx_mtx);
3177
3178 if (fp->fp_taskqueue != NULL)
3179 taskqueue_enqueue(fp->fp_taskqueue,
3180 &fp->fp_task);
3181 }
3182 }
3183
3184 qlnx_unload(ha);
3185
3186 return;
3187}
3188
3189static int
3190qlnx_get_ifq_snd_maxlen(qlnx_host_t *ha)
3191{
3192 return(TX_RING_SIZE - 1);
3193}
3194
3195uint8_t *
3196qlnx_get_mac_addr(qlnx_host_t *ha)
3197{
3198 struct ecore_hwfn *p_hwfn;
3199
3200 p_hwfn = &ha->cdev.hwfns[0];
3201 return (p_hwfn->hw_info.hw_mac_addr);
3202}
3203
3204static uint32_t
3205qlnx_get_optics(qlnx_host_t *ha, struct qlnx_link_output *if_link)
3206{
3207 uint32_t ifm_type = 0;
3208
3209 switch (if_link->media_type) {
3210
3211 case MEDIA_MODULE_FIBER:
3212 case MEDIA_UNSPECIFIED:
3213 if (if_link->speed == (100 * 1000))
3214 ifm_type = QLNX_IFM_100G_SR4;
3215 else if (if_link->speed == (40 * 1000))
3216 ifm_type = IFM_40G_SR4;
3217 else if (if_link->speed == (25 * 1000))
3218 ifm_type = QLNX_IFM_25G_SR;
1996 ifmedia_add(&ha->media, (IFM_ETHER | QLNX_IFM_25G_SR), 0, NULL);
1997 ifmedia_add(&ha->media, (IFM_ETHER | QLNX_IFM_25G_CR), 0, NULL);
1998 } else if (device_id == QLOGIC_PCI_DEVICE_ID_1654) {
1999 ifmedia_add(&ha->media, (IFM_ETHER | IFM_50G_KR2), 0, NULL);
2000 ifmedia_add(&ha->media, (IFM_ETHER | IFM_50G_CR2), 0, NULL);
2001 } else if (device_id == QLOGIC_PCI_DEVICE_ID_1644) {
2002 ifmedia_add(&ha->media,
2003 (IFM_ETHER | QLNX_IFM_100G_LR4), 0, NULL);
2004 ifmedia_add(&ha->media,
2005 (IFM_ETHER | QLNX_IFM_100G_SR4), 0, NULL);
2006 ifmedia_add(&ha->media,
2007 (IFM_ETHER | QLNX_IFM_100G_CR4), 0, NULL);
2008 }
2009
2010 ifmedia_add(&ha->media, (IFM_ETHER | IFM_FDX), 0, NULL);
2011 ifmedia_add(&ha->media, (IFM_ETHER | IFM_AUTO), 0, NULL);
2012
2013
2014 ifmedia_set(&ha->media, (IFM_ETHER | IFM_AUTO));
2015
2016 QL_DPRINT2(ha, "exit\n");
2017
2018 return;
2019}
2020
2021static void
2022qlnx_init_locked(qlnx_host_t *ha)
2023{
2024 struct ifnet *ifp = ha->ifp;
2025
2026 QL_DPRINT1(ha, "Driver Initialization start \n");
2027
2028 qlnx_stop(ha);
2029
2030 if (qlnx_load(ha) == 0) {
2031 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2032 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2033 }
2034
2035 return;
2036}
2037
2038static void
2039qlnx_init(void *arg)
2040{
2041 qlnx_host_t *ha;
2042
2043 ha = (qlnx_host_t *)arg;
2044
2045 QL_DPRINT2(ha, "enter\n");
2046
2047 QLNX_LOCK(ha);
2048 qlnx_init_locked(ha);
2049 QLNX_UNLOCK(ha);
2050
2051 QL_DPRINT2(ha, "exit\n");
2052
2053 return;
2054}
2055
2056static int
2057qlnx_config_mcast_mac_addr(qlnx_host_t *ha, uint8_t *mac_addr, uint32_t add_mac)
2058{
2059 struct ecore_filter_mcast *mcast;
2060 struct ecore_dev *cdev;
2061 int rc;
2062
2063 cdev = &ha->cdev;
2064
2065 mcast = &ha->ecore_mcast;
2066 bzero(mcast, sizeof(struct ecore_filter_mcast));
2067
2068 if (add_mac)
2069 mcast->opcode = ECORE_FILTER_ADD;
2070 else
2071 mcast->opcode = ECORE_FILTER_REMOVE;
2072
2073 mcast->num_mc_addrs = 1;
2074 memcpy(mcast->mac, mac_addr, ETH_ALEN);
2075
2076 rc = ecore_filter_mcast_cmd(cdev, mcast, ECORE_SPQ_MODE_CB, NULL);
2077
2078 return (rc);
2079}
2080
2081static int
2082qlnx_hw_add_mcast(qlnx_host_t *ha, uint8_t *mta)
2083{
2084 int i;
2085
2086 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
2087
2088 if (QL_MAC_CMP(ha->mcast[i].addr, mta) == 0)
2089 return 0; /* its been already added */
2090 }
2091
2092 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
2093
2094 if ((ha->mcast[i].addr[0] == 0) &&
2095 (ha->mcast[i].addr[1] == 0) &&
2096 (ha->mcast[i].addr[2] == 0) &&
2097 (ha->mcast[i].addr[3] == 0) &&
2098 (ha->mcast[i].addr[4] == 0) &&
2099 (ha->mcast[i].addr[5] == 0)) {
2100
2101 if (qlnx_config_mcast_mac_addr(ha, mta, 1))
2102 return (-1);
2103
2104 bcopy(mta, ha->mcast[i].addr, ETH_ALEN);
2105 ha->nmcast++;
2106
2107 return 0;
2108 }
2109 }
2110 return 0;
2111}
2112
2113static int
2114qlnx_hw_del_mcast(qlnx_host_t *ha, uint8_t *mta)
2115{
2116 int i;
2117
2118 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
2119 if (QL_MAC_CMP(ha->mcast[i].addr, mta) == 0) {
2120
2121 if (qlnx_config_mcast_mac_addr(ha, mta, 0))
2122 return (-1);
2123
2124 ha->mcast[i].addr[0] = 0;
2125 ha->mcast[i].addr[1] = 0;
2126 ha->mcast[i].addr[2] = 0;
2127 ha->mcast[i].addr[3] = 0;
2128 ha->mcast[i].addr[4] = 0;
2129 ha->mcast[i].addr[5] = 0;
2130
2131 ha->nmcast--;
2132
2133 return 0;
2134 }
2135 }
2136 return 0;
2137}
2138
2139/*
2140 * Name: qls_hw_set_multi
2141 * Function: Sets the Multicast Addresses provided the host O.S into the
2142 * hardware (for the given interface)
2143 */
2144static void
2145qlnx_hw_set_multi(qlnx_host_t *ha, uint8_t *mta, uint32_t mcnt,
2146 uint32_t add_mac)
2147{
2148 int i;
2149
2150 for (i = 0; i < mcnt; i++) {
2151 if (add_mac) {
2152 if (qlnx_hw_add_mcast(ha, mta))
2153 break;
2154 } else {
2155 if (qlnx_hw_del_mcast(ha, mta))
2156 break;
2157 }
2158
2159 mta += ETHER_HDR_LEN;
2160 }
2161 return;
2162}
2163
2164
2165#define QLNX_MCAST_ADDRS_SIZE (QLNX_MAX_NUM_MULTICAST_ADDRS * ETHER_HDR_LEN)
2166static int
2167qlnx_set_multi(qlnx_host_t *ha, uint32_t add_multi)
2168{
2169 uint8_t mta[QLNX_MCAST_ADDRS_SIZE];
2170 struct ifmultiaddr *ifma;
2171 int mcnt = 0;
2172 struct ifnet *ifp = ha->ifp;
2173 int ret = 0;
2174
2175 if_maddr_rlock(ifp);
2176
2177 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
2178
2179 if (ifma->ifma_addr->sa_family != AF_LINK)
2180 continue;
2181
2182 if (mcnt == QLNX_MAX_NUM_MULTICAST_ADDRS)
2183 break;
2184
2185 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
2186 &mta[mcnt * ETHER_HDR_LEN], ETHER_HDR_LEN);
2187
2188 mcnt++;
2189 }
2190
2191 if_maddr_runlock(ifp);
2192
2193 QLNX_LOCK(ha);
2194 qlnx_hw_set_multi(ha, mta, mcnt, add_multi);
2195 QLNX_UNLOCK(ha);
2196
2197 return (ret);
2198}
2199
2200static int
2201qlnx_set_promisc(qlnx_host_t *ha)
2202{
2203 int rc = 0;
2204 uint8_t filter;
2205
2206 filter = ha->filter;
2207 filter |= ECORE_ACCEPT_MCAST_UNMATCHED;
2208 filter |= ECORE_ACCEPT_UCAST_UNMATCHED;
2209
2210 rc = qlnx_set_rx_accept_filter(ha, filter);
2211 return (rc);
2212}
2213
2214static int
2215qlnx_set_allmulti(qlnx_host_t *ha)
2216{
2217 int rc = 0;
2218 uint8_t filter;
2219
2220 filter = ha->filter;
2221 filter |= ECORE_ACCEPT_MCAST_UNMATCHED;
2222 rc = qlnx_set_rx_accept_filter(ha, filter);
2223
2224 return (rc);
2225}
2226
2227
2228static int
2229qlnx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
2230{
2231 int ret = 0, mask;
2232 struct ifreq *ifr = (struct ifreq *)data;
2233 struct ifaddr *ifa = (struct ifaddr *)data;
2234 qlnx_host_t *ha;
2235
2236 ha = (qlnx_host_t *)ifp->if_softc;
2237
2238 switch (cmd) {
2239 case SIOCSIFADDR:
2240 QL_DPRINT4(ha, "SIOCSIFADDR (0x%lx)\n", cmd);
2241
2242 if (ifa->ifa_addr->sa_family == AF_INET) {
2243 ifp->if_flags |= IFF_UP;
2244 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2245 QLNX_LOCK(ha);
2246 qlnx_init_locked(ha);
2247 QLNX_UNLOCK(ha);
2248 }
2249 QL_DPRINT4(ha, "SIOCSIFADDR (0x%lx) ipv4 [0x%08x]\n",
2250 cmd, ntohl(IA_SIN(ifa)->sin_addr.s_addr));
2251
2252 arp_ifinit(ifp, ifa);
2253 } else {
2254 ether_ioctl(ifp, cmd, data);
2255 }
2256 break;
2257
2258 case SIOCSIFMTU:
2259 QL_DPRINT4(ha, "SIOCSIFMTU (0x%lx)\n", cmd);
2260
2261 if (ifr->ifr_mtu > QLNX_MAX_MTU) {
2262 ret = EINVAL;
2263 } else {
2264 QLNX_LOCK(ha);
2265 ifp->if_mtu = ifr->ifr_mtu;
2266 ha->max_frame_size =
2267 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2268 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2269 qlnx_init_locked(ha);
2270 }
2271
2272 QLNX_UNLOCK(ha);
2273 }
2274
2275 break;
2276
2277 case SIOCSIFFLAGS:
2278 QL_DPRINT4(ha, "SIOCSIFFLAGS (0x%lx)\n", cmd);
2279
2280 QLNX_LOCK(ha);
2281
2282 if (ifp->if_flags & IFF_UP) {
2283 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2284 if ((ifp->if_flags ^ ha->if_flags) &
2285 IFF_PROMISC) {
2286 ret = qlnx_set_promisc(ha);
2287 } else if ((ifp->if_flags ^ ha->if_flags) &
2288 IFF_ALLMULTI) {
2289 ret = qlnx_set_allmulti(ha);
2290 }
2291 } else {
2292 ha->max_frame_size = ifp->if_mtu +
2293 ETHER_HDR_LEN + ETHER_CRC_LEN;
2294 qlnx_init_locked(ha);
2295 }
2296 } else {
2297 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2298 qlnx_stop(ha);
2299 ha->if_flags = ifp->if_flags;
2300 }
2301
2302 QLNX_UNLOCK(ha);
2303 break;
2304
2305 case SIOCADDMULTI:
2306 QL_DPRINT4(ha, "%s (0x%lx)\n", "SIOCADDMULTI", cmd);
2307
2308 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2309 if (qlnx_set_multi(ha, 1))
2310 ret = EINVAL;
2311 }
2312 break;
2313
2314 case SIOCDELMULTI:
2315 QL_DPRINT4(ha, "%s (0x%lx)\n", "SIOCDELMULTI", cmd);
2316
2317 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2318 if (qlnx_set_multi(ha, 0))
2319 ret = EINVAL;
2320 }
2321 break;
2322
2323 case SIOCSIFMEDIA:
2324 case SIOCGIFMEDIA:
2325 QL_DPRINT4(ha, "SIOCSIFMEDIA/SIOCGIFMEDIA (0x%lx)\n", cmd);
2326
2327 ret = ifmedia_ioctl(ifp, ifr, &ha->media, cmd);
2328 break;
2329
2330 case SIOCSIFCAP:
2331
2332 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
2333
2334 QL_DPRINT4(ha, "SIOCSIFCAP (0x%lx)\n", cmd);
2335
2336 if (mask & IFCAP_HWCSUM)
2337 ifp->if_capenable ^= IFCAP_HWCSUM;
2338 if (mask & IFCAP_TSO4)
2339 ifp->if_capenable ^= IFCAP_TSO4;
2340 if (mask & IFCAP_TSO6)
2341 ifp->if_capenable ^= IFCAP_TSO6;
2342 if (mask & IFCAP_VLAN_HWTAGGING)
2343 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
2344 if (mask & IFCAP_VLAN_HWTSO)
2345 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
2346 if (mask & IFCAP_LRO)
2347 ifp->if_capenable ^= IFCAP_LRO;
2348
2349 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
2350 qlnx_init(ha);
2351
2352 VLAN_CAPABILITIES(ifp);
2353 break;
2354
2355#if (__FreeBSD_version >= 1100101)
2356
2357 case SIOCGI2C:
2358 {
2359 struct ifi2creq i2c;
2360 struct ecore_hwfn *p_hwfn = &ha->cdev.hwfns[0];
2361 struct ecore_ptt *p_ptt;
2362
2363 ret = copyin(ifr->ifr_data, &i2c, sizeof(i2c));
2364
2365 if (ret)
2366 break;
2367
2368 if ((i2c.len > sizeof (i2c.data)) ||
2369 (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2)) {
2370 ret = EINVAL;
2371 break;
2372 }
2373
2374 p_ptt = ecore_ptt_acquire(p_hwfn);
2375
2376 if (!p_ptt) {
2377 QL_DPRINT1(ha, "ecore_ptt_acquire failed\n");
2378 ret = -1;
2379 break;
2380 }
2381
2382 ret = ecore_mcp_phy_sfp_read(p_hwfn, p_ptt,
2383 (ha->pci_func & 0x1), i2c.dev_addr, i2c.offset,
2384 i2c.len, &i2c.data[0]);
2385
2386 ecore_ptt_release(p_hwfn, p_ptt);
2387
2388 if (ret) {
2389 ret = -1;
2390 break;
2391 }
2392
2393 ret = copyout(&i2c, ifr->ifr_data, sizeof(i2c));
2394
2395 QL_DPRINT8(ha, "SIOCGI2C copyout ret = %d \
2396 len = %d addr = 0x%02x offset = 0x%04x \
2397 data[0..7]=0x%02x 0x%02x 0x%02x 0x%02x 0x%02x \
2398 0x%02x 0x%02x 0x%02x\n",
2399 ret, i2c.len, i2c.dev_addr, i2c.offset,
2400 i2c.data[0], i2c.data[1], i2c.data[2], i2c.data[3],
2401 i2c.data[4], i2c.data[5], i2c.data[6], i2c.data[7]);
2402 break;
2403 }
2404#endif /* #if (__FreeBSD_version >= 1100101) */
2405
2406 default:
2407 QL_DPRINT4(ha, "default (0x%lx)\n", cmd);
2408 ret = ether_ioctl(ifp, cmd, data);
2409 break;
2410 }
2411
2412 return (ret);
2413}
2414
2415static int
2416qlnx_media_change(struct ifnet *ifp)
2417{
2418 qlnx_host_t *ha;
2419 struct ifmedia *ifm;
2420 int ret = 0;
2421
2422 ha = (qlnx_host_t *)ifp->if_softc;
2423
2424 QL_DPRINT2(ha, "enter\n");
2425
2426 ifm = &ha->media;
2427
2428 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
2429 ret = EINVAL;
2430
2431 QL_DPRINT2(ha, "exit\n");
2432
2433 return (ret);
2434}
2435
2436static void
2437qlnx_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
2438{
2439 qlnx_host_t *ha;
2440
2441 ha = (qlnx_host_t *)ifp->if_softc;
2442
2443 QL_DPRINT2(ha, "enter\n");
2444
2445 ifmr->ifm_status = IFM_AVALID;
2446 ifmr->ifm_active = IFM_ETHER;
2447
2448 if (ha->link_up) {
2449 ifmr->ifm_status |= IFM_ACTIVE;
2450 ifmr->ifm_active |=
2451 (IFM_FDX | qlnx_get_optics(ha, &ha->if_link));
2452
2453 if (ha->if_link.link_partner_caps &
2454 (QLNX_LINK_CAP_Pause | QLNX_LINK_CAP_Asym_Pause))
2455 ifmr->ifm_active |=
2456 (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
2457 }
2458
2459 QL_DPRINT2(ha, "exit (%s)\n", (ha->link_up ? "link_up" : "link_down"));
2460
2461 return;
2462}
2463
2464
2465static void
2466qlnx_free_tx_pkt(qlnx_host_t *ha, struct qlnx_fastpath *fp,
2467 struct qlnx_tx_queue *txq)
2468{
2469 u16 idx;
2470 struct mbuf *mp;
2471 bus_dmamap_t map;
2472 int i;
2473 struct eth_tx_bd *tx_data_bd;
2474 struct eth_tx_1st_bd *first_bd;
2475 int nbds = 0;
2476
2477 idx = txq->sw_tx_cons;
2478 mp = txq->sw_tx_ring[idx].mp;
2479 map = txq->sw_tx_ring[idx].map;
2480
2481 if ((mp == NULL) || QL_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_MBUF_NULL)){
2482
2483 QL_RESET_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_MBUF_NULL);
2484
2485 QL_DPRINT1(ha, "(mp == NULL) "
2486 " tx_idx = 0x%x"
2487 " ecore_prod_idx = 0x%x"
2488 " ecore_cons_idx = 0x%x"
2489 " hw_bd_cons = 0x%x"
2490 " txq_db_last = 0x%x"
2491 " elem_left = 0x%x\n",
2492 fp->rss_id,
2493 ecore_chain_get_prod_idx(&txq->tx_pbl),
2494 ecore_chain_get_cons_idx(&txq->tx_pbl),
2495 le16toh(*txq->hw_cons_ptr),
2496 txq->tx_db.raw,
2497 ecore_chain_get_elem_left(&txq->tx_pbl));
2498
2499 fp->err_tx_free_pkt_null++;
2500
2501 //DEBUG
2502 qlnx_trigger_dump(ha);
2503
2504 return;
2505 } else {
2506
2507 QLNX_INC_OPACKETS((ha->ifp));
2508 QLNX_INC_OBYTES((ha->ifp), (mp->m_pkthdr.len));
2509
2510 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_POSTWRITE);
2511 bus_dmamap_unload(ha->tx_tag, map);
2512
2513 fp->tx_pkts_freed++;
2514 fp->tx_pkts_completed++;
2515
2516 m_freem(mp);
2517 }
2518
2519 first_bd = (struct eth_tx_1st_bd *)ecore_chain_consume(&txq->tx_pbl);
2520 nbds = first_bd->data.nbds;
2521
2522// BD_SET_UNMAP_ADDR_LEN(first_bd, 0, 0);
2523
2524 for (i = 1; i < nbds; i++) {
2525 tx_data_bd = ecore_chain_consume(&txq->tx_pbl);
2526// BD_SET_UNMAP_ADDR_LEN(tx_data_bd, 0, 0);
2527 }
2528 txq->sw_tx_ring[idx].flags = 0;
2529 txq->sw_tx_ring[idx].mp = NULL;
2530 txq->sw_tx_ring[idx].map = (bus_dmamap_t)0;
2531
2532 return;
2533}
2534
2535static void
2536qlnx_tx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp,
2537 struct qlnx_tx_queue *txq)
2538{
2539 u16 hw_bd_cons;
2540 u16 ecore_cons_idx;
2541 uint16_t diff;
2542
2543 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
2544
2545 while (hw_bd_cons !=
2546 (ecore_cons_idx = ecore_chain_get_cons_idx(&txq->tx_pbl))) {
2547
2548 if (hw_bd_cons < ecore_cons_idx) {
2549 diff = (1 << 16) - (ecore_cons_idx - hw_bd_cons);
2550 } else {
2551 diff = hw_bd_cons - ecore_cons_idx;
2552 }
2553 if ((diff > TX_RING_SIZE) ||
2554 QL_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_DIFF)){
2555
2556 QL_RESET_ERR_INJECT(ha, QL_ERR_INJCT_TX_INT_DIFF);
2557
2558 QL_DPRINT1(ha, "(diff = 0x%x) "
2559 " tx_idx = 0x%x"
2560 " ecore_prod_idx = 0x%x"
2561 " ecore_cons_idx = 0x%x"
2562 " hw_bd_cons = 0x%x"
2563 " txq_db_last = 0x%x"
2564 " elem_left = 0x%x\n",
2565 diff,
2566 fp->rss_id,
2567 ecore_chain_get_prod_idx(&txq->tx_pbl),
2568 ecore_chain_get_cons_idx(&txq->tx_pbl),
2569 le16toh(*txq->hw_cons_ptr),
2570 txq->tx_db.raw,
2571 ecore_chain_get_elem_left(&txq->tx_pbl));
2572
2573 fp->err_tx_cons_idx_conflict++;
2574
2575 //DEBUG
2576 qlnx_trigger_dump(ha);
2577 }
2578
2579 qlnx_free_tx_pkt(ha, fp, txq);
2580
2581 txq->sw_tx_cons = (txq->sw_tx_cons + 1) & (TX_RING_SIZE - 1);
2582 }
2583 return;
2584}
2585
2586static int
2587qlnx_transmit(struct ifnet *ifp, struct mbuf *mp)
2588{
2589 qlnx_host_t *ha = (qlnx_host_t *)ifp->if_softc;
2590 struct qlnx_fastpath *fp;
2591 int rss_id = 0, ret = 0;
2592
2593 QL_DPRINT2(ha, "enter\n");
2594
2595#if __FreeBSD_version >= 1100000
2596 if (M_HASHTYPE_GET(mp) != M_HASHTYPE_NONE)
2597#else
2598 if (mp->m_flags & M_FLOWID)
2599#endif
2600 rss_id = (mp->m_pkthdr.flowid % ECORE_RSS_IND_TABLE_SIZE) %
2601 ha->num_rss;
2602
2603 fp = &ha->fp_array[rss_id];
2604
2605 if (fp->tx_br == NULL) {
2606 ret = EINVAL;
2607 goto qlnx_transmit_exit;
2608 }
2609
2610 if (mp != NULL) {
2611 ret = drbr_enqueue(ifp, fp->tx_br, mp);
2612 }
2613
2614 if (fp->fp_taskqueue != NULL)
2615 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
2616
2617 ret = 0;
2618
2619qlnx_transmit_exit:
2620
2621 QL_DPRINT2(ha, "exit ret = %d\n", ret);
2622 return ret;
2623}
2624
2625static void
2626qlnx_qflush(struct ifnet *ifp)
2627{
2628 int rss_id;
2629 struct qlnx_fastpath *fp;
2630 struct mbuf *mp;
2631 qlnx_host_t *ha;
2632
2633 ha = (qlnx_host_t *)ifp->if_softc;
2634
2635 QL_DPRINT2(ha, "enter\n");
2636
2637 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
2638
2639 fp = &ha->fp_array[rss_id];
2640
2641 if (fp == NULL)
2642 continue;
2643
2644 if (fp->tx_br) {
2645 mtx_lock(&fp->tx_mtx);
2646
2647 while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) {
2648 fp->tx_pkts_freed++;
2649 m_freem(mp);
2650 }
2651 mtx_unlock(&fp->tx_mtx);
2652 }
2653 }
2654 QL_DPRINT2(ha, "exit\n");
2655
2656 return;
2657}
2658
2659static void
2660qlnx_txq_doorbell_wr32(qlnx_host_t *ha, void *reg_addr, uint32_t value)
2661{
2662 struct ecore_dev *cdev;
2663 uint32_t offset;
2664
2665 cdev = &ha->cdev;
2666
2667 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)cdev->doorbells);
2668
2669 bus_write_4(ha->pci_dbells, offset, value);
2670 bus_barrier(ha->pci_reg, 0, 0, BUS_SPACE_BARRIER_READ);
2671 bus_barrier(ha->pci_dbells, 0, 0, BUS_SPACE_BARRIER_READ);
2672
2673 return;
2674}
2675
2676static uint32_t
2677qlnx_tcp_offset(qlnx_host_t *ha, struct mbuf *mp)
2678{
2679 struct ether_vlan_header *eh = NULL;
2680 struct ip *ip = NULL;
2681 struct ip6_hdr *ip6 = NULL;
2682 struct tcphdr *th = NULL;
2683 uint32_t ehdrlen = 0, ip_hlen = 0, offset = 0;
2684 uint16_t etype = 0;
2685 device_t dev;
2686 uint8_t buf[sizeof(struct ip6_hdr)];
2687
2688 dev = ha->pci_dev;
2689
2690 eh = mtod(mp, struct ether_vlan_header *);
2691
2692 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
2693 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
2694 etype = ntohs(eh->evl_proto);
2695 } else {
2696 ehdrlen = ETHER_HDR_LEN;
2697 etype = ntohs(eh->evl_encap_proto);
2698 }
2699
2700 switch (etype) {
2701
2702 case ETHERTYPE_IP:
2703 ip = (struct ip *)(mp->m_data + ehdrlen);
2704
2705 ip_hlen = sizeof (struct ip);
2706
2707 if (mp->m_len < (ehdrlen + ip_hlen)) {
2708 m_copydata(mp, ehdrlen, sizeof(struct ip), buf);
2709 ip = (struct ip *)buf;
2710 }
2711
2712 th = (struct tcphdr *)(ip + 1);
2713 offset = ip_hlen + ehdrlen + (th->th_off << 2);
2714 break;
2715
2716 case ETHERTYPE_IPV6:
2717 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
2718
2719 ip_hlen = sizeof(struct ip6_hdr);
2720
2721 if (mp->m_len < (ehdrlen + ip_hlen)) {
2722 m_copydata(mp, ehdrlen, sizeof (struct ip6_hdr),
2723 buf);
2724 ip6 = (struct ip6_hdr *)buf;
2725 }
2726 th = (struct tcphdr *)(ip6 + 1);
2727 offset = ip_hlen + ehdrlen + (th->th_off << 2);
2728 break;
2729
2730 default:
2731 break;
2732 }
2733
2734 return (offset);
2735}
2736
2737static __inline int
2738qlnx_tso_check(struct qlnx_fastpath *fp, bus_dma_segment_t *segs, int nsegs,
2739 uint32_t offset)
2740{
2741 int i;
2742 uint32_t sum, nbds_in_hdr = 1;
2743 bus_dma_segment_t *t_segs = segs;
2744
2745 /* count the number of segments spanned by TCP header */
2746
2747 i = 0;
2748 while ((i < nsegs) && (offset > t_segs->ds_len)) {
2749 nbds_in_hdr++;
2750 offset = offset - t_segs->ds_len;
2751 t_segs++;
2752 i++;
2753 }
2754
2755 while (nsegs >= QLNX_MAX_SEGMENTS_NON_TSO) {
2756
2757 sum = 0;
2758
2759 for (i = 0; i < (ETH_TX_LSO_WINDOW_BDS_NUM - nbds_in_hdr); i++){
2760 sum += segs->ds_len;
2761 segs++;
2762 }
2763
2764 if (sum < ETH_TX_LSO_WINDOW_MIN_LEN) {
2765 fp->tx_lso_wnd_min_len++;
2766 return (-1);
2767 }
2768
2769 nsegs -= QLNX_MAX_SEGMENTS_NON_TSO;
2770 }
2771
2772 return (0);
2773}
2774
2775static int
2776qlnx_send(qlnx_host_t *ha, struct qlnx_fastpath *fp, struct mbuf **m_headp)
2777{
2778 bus_dma_segment_t *segs;
2779 bus_dmamap_t map = 0;
2780 uint32_t nsegs = 0;
2781 int ret = -1;
2782 struct mbuf *m_head = *m_headp;
2783 uint16_t idx = 0;
2784 uint16_t elem_left;
2785
2786 uint8_t nbd = 0;
2787 struct qlnx_tx_queue *txq;
2788
2789 struct eth_tx_1st_bd *first_bd;
2790 struct eth_tx_2nd_bd *second_bd;
2791 struct eth_tx_3rd_bd *third_bd;
2792 struct eth_tx_bd *tx_data_bd;
2793
2794 int seg_idx = 0;
2795 uint32_t nbds_in_hdr = 0;
2796 uint32_t offset = 0;
2797
2798 QL_DPRINT8(ha, "enter\n");
2799
2800 if (!ha->link_up)
2801 return (-1);
2802
2803 first_bd = NULL;
2804 second_bd = NULL;
2805 third_bd = NULL;
2806 tx_data_bd = NULL;
2807
2808 txq = fp->txq[0];
2809
2810 if (fp->tx_ring_full) {
2811 elem_left = ecore_chain_get_elem_left(&txq->tx_pbl);
2812
2813 if (elem_left < (TX_RING_SIZE >> 4))
2814 return (-1);
2815 else
2816 fp->tx_ring_full = 0;
2817 }
2818
2819 idx = txq->sw_tx_prod;
2820
2821 map = txq->sw_tx_ring[idx].map;
2822 segs = txq->segs;
2823
2824 ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head, segs, &nsegs,
2825 BUS_DMA_NOWAIT);
2826
2827 if (ha->dbg_trace_tso_pkt_len) {
2828 if (!fp->tx_tso_min_pkt_len) {
2829 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2830 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2831 } else {
2832 if (fp->tx_tso_min_pkt_len > m_head->m_pkthdr.len)
2833 fp->tx_tso_min_pkt_len = m_head->m_pkthdr.len;
2834 if (fp->tx_tso_max_pkt_len < m_head->m_pkthdr.len)
2835 fp->tx_tso_max_pkt_len = m_head->m_pkthdr.len;
2836 }
2837 }
2838
2839 if (m_head->m_pkthdr.csum_flags & CSUM_TSO)
2840 offset = qlnx_tcp_offset(ha, m_head);
2841
2842 if ((ret == EFBIG) ||
2843 ((nsegs > QLNX_MAX_SEGMENTS_NON_TSO) && (
2844 (!(m_head->m_pkthdr.csum_flags & CSUM_TSO)) ||
2845 ((m_head->m_pkthdr.csum_flags & CSUM_TSO) &&
2846 qlnx_tso_check(fp, segs, nsegs, offset))))) {
2847
2848 struct mbuf *m;
2849
2850 QL_DPRINT8(ha, "EFBIG [%d]\n", m_head->m_pkthdr.len);
2851
2852 fp->tx_defrag++;
2853
2854 m = m_defrag(m_head, M_NOWAIT);
2855 if (m == NULL) {
2856 fp->err_tx_defrag++;
2857 fp->tx_pkts_freed++;
2858 m_freem(m_head);
2859 *m_headp = NULL;
2860 QL_DPRINT1(ha, "m_defrag() = NULL [%d]\n", ret);
2861 return (ENOBUFS);
2862 }
2863
2864 m_head = m;
2865 *m_headp = m_head;
2866
2867 if ((ret = bus_dmamap_load_mbuf_sg(ha->tx_tag, map, m_head,
2868 segs, &nsegs, BUS_DMA_NOWAIT))) {
2869
2870 fp->err_tx_defrag_dmamap_load++;
2871
2872 QL_DPRINT1(ha,
2873 "bus_dmamap_load_mbuf_sg failed0 [%d, %d]\n",
2874 ret, m_head->m_pkthdr.len);
2875
2876 fp->tx_pkts_freed++;
2877 m_freem(m_head);
2878 *m_headp = NULL;
2879
2880 return (ret);
2881 }
2882
2883 if ((nsegs > QLNX_MAX_SEGMENTS_NON_TSO) &&
2884 !(m_head->m_pkthdr.csum_flags & CSUM_TSO)) {
2885
2886 fp->err_tx_non_tso_max_seg++;
2887
2888 QL_DPRINT1(ha,
2889 "(%d) nsegs too many for non-TSO [%d, %d]\n",
2890 ret, nsegs, m_head->m_pkthdr.len);
2891
2892 fp->tx_pkts_freed++;
2893 m_freem(m_head);
2894 *m_headp = NULL;
2895
2896 return (ret);
2897 }
2898 if (m_head->m_pkthdr.csum_flags & CSUM_TSO)
2899 offset = qlnx_tcp_offset(ha, m_head);
2900
2901 } else if (ret) {
2902
2903 fp->err_tx_dmamap_load++;
2904
2905 QL_DPRINT1(ha, "bus_dmamap_load_mbuf_sg failed1 [%d, %d]\n",
2906 ret, m_head->m_pkthdr.len);
2907 fp->tx_pkts_freed++;
2908 m_freem(m_head);
2909 *m_headp = NULL;
2910 return (ret);
2911 }
2912
2913 QL_ASSERT(ha, (nsegs != 0), ("qlnx_send: empty packet"));
2914
2915 if (ha->dbg_trace_tso_pkt_len) {
2916 if (nsegs < QLNX_FP_MAX_SEGS)
2917 fp->tx_pkts[(nsegs - 1)]++;
2918 else
2919 fp->tx_pkts[(QLNX_FP_MAX_SEGS - 1)]++;
2920 }
2921
2922 if ((nsegs + QLNX_TX_ELEM_RESERVE) >
2923 (int)(elem_left = ecore_chain_get_elem_left(&txq->tx_pbl))) {
2924
2925 QL_DPRINT1(ha, "(%d, 0x%x) insuffient BDs"
2926 " in chain[%d] trying to free packets\n",
2927 nsegs, elem_left, fp->rss_id);
2928
2929 fp->tx_nsegs_gt_elem_left++;
2930
2931 (void)qlnx_tx_int(ha, fp, txq);
2932
2933 if ((nsegs + QLNX_TX_ELEM_RESERVE) > (int)(elem_left =
2934 ecore_chain_get_elem_left(&txq->tx_pbl))) {
2935
2936 QL_DPRINT1(ha,
2937 "(%d, 0x%x) insuffient BDs in chain[%d]\n",
2938 nsegs, elem_left, fp->rss_id);
2939
2940 fp->err_tx_nsegs_gt_elem_left++;
2941 fp->tx_ring_full = 1;
2942 ha->storm_stats_enable = 1;
2943 return (ENOBUFS);
2944 }
2945 }
2946
2947 bus_dmamap_sync(ha->tx_tag, map, BUS_DMASYNC_PREWRITE);
2948
2949 txq->sw_tx_ring[idx].mp = m_head;
2950
2951 first_bd = (struct eth_tx_1st_bd *)ecore_chain_produce(&txq->tx_pbl);
2952
2953 memset(first_bd, 0, sizeof(*first_bd));
2954
2955 first_bd->data.bd_flags.bitfields =
2956 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
2957
2958 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, segs->ds_len);
2959
2960 nbd++;
2961
2962 if (m_head->m_pkthdr.csum_flags & CSUM_IP) {
2963 first_bd->data.bd_flags.bitfields |=
2964 (1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT);
2965 }
2966
2967 if (m_head->m_pkthdr.csum_flags &
2968 (CSUM_UDP | CSUM_TCP | CSUM_TCP_IPV6 | CSUM_UDP_IPV6)) {
2969 first_bd->data.bd_flags.bitfields |=
2970 (1 << ETH_TX_1ST_BD_FLAGS_L4_CSUM_SHIFT);
2971 }
2972
2973 if (m_head->m_flags & M_VLANTAG) {
2974 first_bd->data.vlan = m_head->m_pkthdr.ether_vtag;
2975 first_bd->data.bd_flags.bitfields |=
2976 (1 << ETH_TX_1ST_BD_FLAGS_VLAN_INSERTION_SHIFT);
2977 }
2978
2979 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
2980
2981 first_bd->data.bd_flags.bitfields |=
2982 (1 << ETH_TX_1ST_BD_FLAGS_LSO_SHIFT);
2983 first_bd->data.bd_flags.bitfields |=
2984 (1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT);
2985
2986 nbds_in_hdr = 1;
2987
2988 if (offset == segs->ds_len) {
2989 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, offset);
2990 segs++;
2991 seg_idx++;
2992
2993 second_bd = (struct eth_tx_2nd_bd *)
2994 ecore_chain_produce(&txq->tx_pbl);
2995 memset(second_bd, 0, sizeof(*second_bd));
2996 nbd++;
2997
2998 if (seg_idx < nsegs) {
2999 BD_SET_UNMAP_ADDR_LEN(second_bd, \
3000 (segs->ds_addr), (segs->ds_len));
3001 segs++;
3002 seg_idx++;
3003 }
3004
3005 third_bd = (struct eth_tx_3rd_bd *)
3006 ecore_chain_produce(&txq->tx_pbl);
3007 memset(third_bd, 0, sizeof(*third_bd));
3008 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
3009 third_bd->data.bitfields |=
3010 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
3011 nbd++;
3012
3013 if (seg_idx < nsegs) {
3014 BD_SET_UNMAP_ADDR_LEN(third_bd, \
3015 (segs->ds_addr), (segs->ds_len));
3016 segs++;
3017 seg_idx++;
3018 }
3019
3020 for (; seg_idx < nsegs; seg_idx++) {
3021 tx_data_bd = (struct eth_tx_bd *)
3022 ecore_chain_produce(&txq->tx_pbl);
3023 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3024 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, \
3025 segs->ds_addr,\
3026 segs->ds_len);
3027 segs++;
3028 nbd++;
3029 }
3030
3031 } else if (offset < segs->ds_len) {
3032 BD_SET_UNMAP_ADDR_LEN(first_bd, segs->ds_addr, offset);
3033
3034 second_bd = (struct eth_tx_2nd_bd *)
3035 ecore_chain_produce(&txq->tx_pbl);
3036 memset(second_bd, 0, sizeof(*second_bd));
3037 BD_SET_UNMAP_ADDR_LEN(second_bd, \
3038 (segs->ds_addr + offset),\
3039 (segs->ds_len - offset));
3040 nbd++;
3041 segs++;
3042
3043 third_bd = (struct eth_tx_3rd_bd *)
3044 ecore_chain_produce(&txq->tx_pbl);
3045 memset(third_bd, 0, sizeof(*third_bd));
3046
3047 BD_SET_UNMAP_ADDR_LEN(third_bd, \
3048 segs->ds_addr,\
3049 segs->ds_len);
3050 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
3051 third_bd->data.bitfields |=
3052 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
3053 segs++;
3054 nbd++;
3055
3056 for (seg_idx = 2; seg_idx < nsegs; seg_idx++) {
3057 tx_data_bd = (struct eth_tx_bd *)
3058 ecore_chain_produce(&txq->tx_pbl);
3059 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3060 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, \
3061 segs->ds_addr,\
3062 segs->ds_len);
3063 segs++;
3064 nbd++;
3065 }
3066
3067 } else {
3068 offset = offset - segs->ds_len;
3069 segs++;
3070
3071 for (seg_idx = 1; seg_idx < nsegs; seg_idx++) {
3072
3073 if (offset)
3074 nbds_in_hdr++;
3075
3076 tx_data_bd = (struct eth_tx_bd *)
3077 ecore_chain_produce(&txq->tx_pbl);
3078 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3079
3080 if (second_bd == NULL) {
3081 second_bd = (struct eth_tx_2nd_bd *)
3082 tx_data_bd;
3083 } else if (third_bd == NULL) {
3084 third_bd = (struct eth_tx_3rd_bd *)
3085 tx_data_bd;
3086 }
3087
3088 if (offset && (offset < segs->ds_len)) {
3089 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
3090 segs->ds_addr, offset);
3091
3092 tx_data_bd = (struct eth_tx_bd *)
3093 ecore_chain_produce(&txq->tx_pbl);
3094
3095 memset(tx_data_bd, 0,
3096 sizeof(*tx_data_bd));
3097
3098 if (second_bd == NULL) {
3099 second_bd =
3100 (struct eth_tx_2nd_bd *)tx_data_bd;
3101 } else if (third_bd == NULL) {
3102 third_bd =
3103 (struct eth_tx_3rd_bd *)tx_data_bd;
3104 }
3105 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
3106 (segs->ds_addr + offset), \
3107 (segs->ds_len - offset));
3108 nbd++;
3109 offset = 0;
3110 } else {
3111 if (offset)
3112 offset = offset - segs->ds_len;
3113 BD_SET_UNMAP_ADDR_LEN(tx_data_bd,\
3114 segs->ds_addr, segs->ds_len);
3115 }
3116 segs++;
3117 nbd++;
3118 }
3119
3120 if (third_bd == NULL) {
3121 third_bd = (struct eth_tx_3rd_bd *)
3122 ecore_chain_produce(&txq->tx_pbl);
3123 memset(third_bd, 0, sizeof(*third_bd));
3124 }
3125
3126 third_bd->data.lso_mss = m_head->m_pkthdr.tso_segsz;
3127 third_bd->data.bitfields |=
3128 (nbds_in_hdr<<ETH_TX_DATA_3RD_BD_HDR_NBD_SHIFT);
3129 }
3130 } else {
3131 segs++;
3132 for (seg_idx = 1; seg_idx < nsegs; seg_idx++) {
3133 tx_data_bd = (struct eth_tx_bd *)
3134 ecore_chain_produce(&txq->tx_pbl);
3135 memset(tx_data_bd, 0, sizeof(*tx_data_bd));
3136 BD_SET_UNMAP_ADDR_LEN(tx_data_bd, segs->ds_addr,\
3137 segs->ds_len);
3138 segs++;
3139 nbd++;
3140 }
3141 first_bd->data.bitfields =
3142 (m_head->m_pkthdr.len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK)
3143 << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
3144 first_bd->data.bitfields =
3145 htole16(first_bd->data.bitfields);
3146 }
3147
3148
3149 first_bd->data.nbds = nbd;
3150
3151 if (ha->dbg_trace_tso_pkt_len) {
3152 if (fp->tx_tso_max_nsegs < nsegs)
3153 fp->tx_tso_max_nsegs = nsegs;
3154
3155 if ((nsegs < fp->tx_tso_min_nsegs) || (!fp->tx_tso_min_nsegs))
3156 fp->tx_tso_min_nsegs = nsegs;
3157 }
3158
3159 txq->sw_tx_ring[idx].nsegs = nsegs;
3160 txq->sw_tx_prod = (txq->sw_tx_prod + 1) & (TX_RING_SIZE - 1);
3161
3162 txq->tx_db.data.bd_prod =
3163 htole16(ecore_chain_get_prod_idx(&txq->tx_pbl));
3164
3165 qlnx_txq_doorbell_wr32(ha, txq->doorbell_addr, txq->tx_db.raw);
3166
3167 QL_DPRINT8(ha, "exit\n");
3168 return (0);
3169}
3170
3171static void
3172qlnx_stop(qlnx_host_t *ha)
3173{
3174 struct ifnet *ifp = ha->ifp;
3175 device_t dev;
3176 int i;
3177
3178 dev = ha->pci_dev;
3179
3180 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
3181
3182 /*
3183 * We simply lock and unlock each fp->tx_mtx to
3184 * propagate the if_drv_flags
3185 * state to each tx thread
3186 */
3187 QL_DPRINT1(ha, "QLNX STATE = %d\n",ha->state);
3188
3189 if (ha->state == QLNX_STATE_OPEN) {
3190 for (i = 0; i < ha->num_rss; i++) {
3191 struct qlnx_fastpath *fp = &ha->fp_array[i];
3192
3193 mtx_lock(&fp->tx_mtx);
3194 mtx_unlock(&fp->tx_mtx);
3195
3196 if (fp->fp_taskqueue != NULL)
3197 taskqueue_enqueue(fp->fp_taskqueue,
3198 &fp->fp_task);
3199 }
3200 }
3201
3202 qlnx_unload(ha);
3203
3204 return;
3205}
3206
3207static int
3208qlnx_get_ifq_snd_maxlen(qlnx_host_t *ha)
3209{
3210 return(TX_RING_SIZE - 1);
3211}
3212
3213uint8_t *
3214qlnx_get_mac_addr(qlnx_host_t *ha)
3215{
3216 struct ecore_hwfn *p_hwfn;
3217
3218 p_hwfn = &ha->cdev.hwfns[0];
3219 return (p_hwfn->hw_info.hw_mac_addr);
3220}
3221
3222static uint32_t
3223qlnx_get_optics(qlnx_host_t *ha, struct qlnx_link_output *if_link)
3224{
3225 uint32_t ifm_type = 0;
3226
3227 switch (if_link->media_type) {
3228
3229 case MEDIA_MODULE_FIBER:
3230 case MEDIA_UNSPECIFIED:
3231 if (if_link->speed == (100 * 1000))
3232 ifm_type = QLNX_IFM_100G_SR4;
3233 else if (if_link->speed == (40 * 1000))
3234 ifm_type = IFM_40G_SR4;
3235 else if (if_link->speed == (25 * 1000))
3236 ifm_type = QLNX_IFM_25G_SR;
3237 else if (if_link->speed == (10 * 1000))
3238 ifm_type = (IFM_10G_LR | IFM_10G_SR);
3239 else if (if_link->speed == (1 * 1000))
3240 ifm_type = (IFM_1000_SX | IFM_1000_LX);
3241
3219 break;
3220
3221 case MEDIA_DA_TWINAX:
3222 if (if_link->speed == (100 * 1000))
3223 ifm_type = QLNX_IFM_100G_CR4;
3224 else if (if_link->speed == (40 * 1000))
3225 ifm_type = IFM_40G_CR4;
3226 else if (if_link->speed == (25 * 1000))
3227 ifm_type = QLNX_IFM_25G_CR;
3242 break;
3243
3244 case MEDIA_DA_TWINAX:
3245 if (if_link->speed == (100 * 1000))
3246 ifm_type = QLNX_IFM_100G_CR4;
3247 else if (if_link->speed == (40 * 1000))
3248 ifm_type = IFM_40G_CR4;
3249 else if (if_link->speed == (25 * 1000))
3250 ifm_type = QLNX_IFM_25G_CR;
3251 else if (if_link->speed == (10 * 1000))
3252 ifm_type = IFM_10G_TWINAX;
3253
3228 break;
3229
3230 default :
3231 ifm_type = IFM_UNKNOWN;
3232 break;
3233 }
3234 return (ifm_type);
3235}
3236
3237
3238
3239/*****************************************************************************
3240 * Interrupt Service Functions
3241 *****************************************************************************/
3242
3243static int
3244qlnx_rx_jumbo_chain(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3245 struct mbuf *mp_head, uint16_t len)
3246{
3247 struct mbuf *mp, *mpf, *mpl;
3248 struct sw_rx_data *sw_rx_data;
3249 struct qlnx_rx_queue *rxq;
3250 uint16_t len_in_buffer;
3251
3252 rxq = fp->rxq;
3253 mpf = mpl = mp = NULL;
3254
3255 while (len) {
3256
3257 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3258
3259 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3260 mp = sw_rx_data->data;
3261
3262 if (mp == NULL) {
3263 QL_DPRINT1(ha, "mp = NULL\n");
3264 fp->err_rx_mp_null++;
3265 rxq->sw_rx_cons =
3266 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3267
3268 if (mpf != NULL)
3269 m_freem(mpf);
3270
3271 return (-1);
3272 }
3273 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3274 BUS_DMASYNC_POSTREAD);
3275
3276 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3277
3278 QL_DPRINT1(ha, "New buffer allocation failed, dropping"
3279 " incoming packet and reusing its buffer\n");
3280
3281 qlnx_reuse_rx_data(rxq);
3282 fp->err_rx_alloc_errors++;
3283
3284 if (mpf != NULL)
3285 m_freem(mpf);
3286
3287 return (-1);
3288 }
3289 ecore_chain_consume(&rxq->rx_bd_ring);
3290
3291 if (len > rxq->rx_buf_size)
3292 len_in_buffer = rxq->rx_buf_size;
3293 else
3294 len_in_buffer = len;
3295
3296 len = len - len_in_buffer;
3297
3298 mp->m_flags &= ~M_PKTHDR;
3299 mp->m_next = NULL;
3300 mp->m_len = len_in_buffer;
3301
3302 if (mpf == NULL)
3303 mpf = mpl = mp;
3304 else {
3305 mpl->m_next = mp;
3306 mpl = mp;
3307 }
3308 }
3309
3310 if (mpf != NULL)
3311 mp_head->m_next = mpf;
3312
3313 return (0);
3314}
3315
3316static void
3317qlnx_tpa_start(qlnx_host_t *ha,
3318 struct qlnx_fastpath *fp,
3319 struct qlnx_rx_queue *rxq,
3320 struct eth_fast_path_rx_tpa_start_cqe *cqe)
3321{
3322 uint32_t agg_index;
3323 struct ifnet *ifp = ha->ifp;
3324 struct mbuf *mp;
3325 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3326 struct sw_rx_data *sw_rx_data;
3327 dma_addr_t addr;
3328 bus_dmamap_t map;
3329 struct eth_rx_bd *rx_bd;
3330 int i;
3331 device_t dev;
3332#if __FreeBSD_version >= 1100000
3333 uint8_t hash_type;
3334#endif /* #if __FreeBSD_version >= 1100000 */
3335
3336 dev = ha->pci_dev;
3337 agg_index = cqe->tpa_agg_index;
3338
3339 QL_DPRINT7(ha, "[rss_id = %d]: enter\n \
3340 \t type = 0x%x\n \
3341 \t bitfields = 0x%x\n \
3342 \t seg_len = 0x%x\n \
3343 \t pars_flags = 0x%x\n \
3344 \t vlan_tag = 0x%x\n \
3345 \t rss_hash = 0x%x\n \
3346 \t len_on_first_bd = 0x%x\n \
3347 \t placement_offset = 0x%x\n \
3348 \t tpa_agg_index = 0x%x\n \
3349 \t header_len = 0x%x\n \
3350 \t ext_bd_len_list[0] = 0x%x\n \
3351 \t ext_bd_len_list[1] = 0x%x\n \
3352 \t ext_bd_len_list[2] = 0x%x\n \
3353 \t ext_bd_len_list[3] = 0x%x\n \
3354 \t ext_bd_len_list[4] = 0x%x\n",
3355 fp->rss_id, cqe->type, cqe->bitfields, cqe->seg_len,
3356 cqe->pars_flags.flags, cqe->vlan_tag,
3357 cqe->rss_hash, cqe->len_on_first_bd, cqe->placement_offset,
3358 cqe->tpa_agg_index, cqe->header_len,
3359 cqe->ext_bd_len_list[0], cqe->ext_bd_len_list[1],
3360 cqe->ext_bd_len_list[2], cqe->ext_bd_len_list[3],
3361 cqe->ext_bd_len_list[4]);
3362
3363 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3364 fp->err_rx_tpa_invalid_agg_num++;
3365 return;
3366 }
3367
3368 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3369 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map, BUS_DMASYNC_POSTREAD);
3370 mp = sw_rx_data->data;
3371
3372 QL_DPRINT7(ha, "[rss_id = %d]: mp = %p \n ", fp->rss_id, mp);
3373
3374 if (mp == NULL) {
3375 QL_DPRINT7(ha, "[%d]: mp = NULL\n", fp->rss_id);
3376 fp->err_rx_mp_null++;
3377 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3378
3379 return;
3380 }
3381
3382 if ((le16toh(cqe->pars_flags.flags)) & CQE_FLAGS_ERR) {
3383
3384 QL_DPRINT7(ha, "[%d]: CQE in CONS = %u has error,"
3385 " flags = %x, dropping incoming packet\n", fp->rss_id,
3386 rxq->sw_rx_cons, le16toh(cqe->pars_flags.flags));
3387
3388 fp->err_rx_hw_errors++;
3389
3390 qlnx_reuse_rx_data(rxq);
3391
3392 QLNX_INC_IERRORS(ifp);
3393
3394 return;
3395 }
3396
3397 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3398
3399 QL_DPRINT7(ha, "[%d]: New buffer allocation failed,"
3400 " dropping incoming packet and reusing its buffer\n",
3401 fp->rss_id);
3402
3403 fp->err_rx_alloc_errors++;
3404 QLNX_INC_IQDROPS(ifp);
3405
3406 /*
3407 * Load the tpa mbuf into the rx ring and save the
3408 * posted mbuf
3409 */
3410
3411 map = sw_rx_data->map;
3412 addr = sw_rx_data->dma_addr;
3413
3414 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_prod];
3415
3416 sw_rx_data->data = rxq->tpa_info[agg_index].rx_buf.data;
3417 sw_rx_data->dma_addr = rxq->tpa_info[agg_index].rx_buf.dma_addr;
3418 sw_rx_data->map = rxq->tpa_info[agg_index].rx_buf.map;
3419
3420 rxq->tpa_info[agg_index].rx_buf.data = mp;
3421 rxq->tpa_info[agg_index].rx_buf.dma_addr = addr;
3422 rxq->tpa_info[agg_index].rx_buf.map = map;
3423
3424 rx_bd = (struct eth_rx_bd *)
3425 ecore_chain_produce(&rxq->rx_bd_ring);
3426
3427 rx_bd->addr.hi = htole32(U64_HI(sw_rx_data->dma_addr));
3428 rx_bd->addr.lo = htole32(U64_LO(sw_rx_data->dma_addr));
3429
3430 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3431 BUS_DMASYNC_PREREAD);
3432
3433 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
3434 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3435
3436 ecore_chain_consume(&rxq->rx_bd_ring);
3437
3438 /* Now reuse any buffers posted in ext_bd_len_list */
3439 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3440
3441 if (cqe->ext_bd_len_list[i] == 0)
3442 break;
3443
3444 qlnx_reuse_rx_data(rxq);
3445 }
3446
3447 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_ERROR;
3448 return;
3449 }
3450
3451 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_NONE) {
3452
3453 QL_DPRINT7(ha, "[%d]: invalid aggregation state,"
3454 " dropping incoming packet and reusing its buffer\n",
3455 fp->rss_id);
3456
3457 QLNX_INC_IQDROPS(ifp);
3458
3459 /* if we already have mbuf head in aggregation free it */
3460 if (rxq->tpa_info[agg_index].mpf) {
3461 m_freem(rxq->tpa_info[agg_index].mpf);
3462 rxq->tpa_info[agg_index].mpl = NULL;
3463 }
3464 rxq->tpa_info[agg_index].mpf = mp;
3465 rxq->tpa_info[agg_index].mpl = NULL;
3466
3467 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3468 ecore_chain_consume(&rxq->rx_bd_ring);
3469
3470 /* Now reuse any buffers posted in ext_bd_len_list */
3471 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3472
3473 if (cqe->ext_bd_len_list[i] == 0)
3474 break;
3475
3476 qlnx_reuse_rx_data(rxq);
3477 }
3478 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_ERROR;
3479
3480 return;
3481 }
3482
3483 /*
3484 * first process the ext_bd_len_list
3485 * if this fails then we simply drop the packet
3486 */
3487 ecore_chain_consume(&rxq->rx_bd_ring);
3488 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3489
3490 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3491
3492 QL_DPRINT7(ha, "[%d]: 4\n ", fp->rss_id);
3493
3494 if (cqe->ext_bd_len_list[i] == 0)
3495 break;
3496
3497 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3498 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3499 BUS_DMASYNC_POSTREAD);
3500
3501 mpc = sw_rx_data->data;
3502
3503 if (mpc == NULL) {
3504 QL_DPRINT7(ha, "[%d]: mpc = NULL\n", fp->rss_id);
3505 fp->err_rx_mp_null++;
3506 if (mpf != NULL)
3507 m_freem(mpf);
3508 mpf = mpl = NULL;
3509 rxq->tpa_info[agg_index].agg_state =
3510 QLNX_AGG_STATE_ERROR;
3511 ecore_chain_consume(&rxq->rx_bd_ring);
3512 rxq->sw_rx_cons =
3513 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3514 continue;
3515 }
3516
3517 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3518 QL_DPRINT7(ha, "[%d]: New buffer allocation failed,"
3519 " dropping incoming packet and reusing its"
3520 " buffer\n", fp->rss_id);
3521
3522 qlnx_reuse_rx_data(rxq);
3523
3524 if (mpf != NULL)
3525 m_freem(mpf);
3526 mpf = mpl = NULL;
3527
3528 rxq->tpa_info[agg_index].agg_state =
3529 QLNX_AGG_STATE_ERROR;
3530
3531 ecore_chain_consume(&rxq->rx_bd_ring);
3532 rxq->sw_rx_cons =
3533 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3534
3535 continue;
3536 }
3537
3538 mpc->m_flags &= ~M_PKTHDR;
3539 mpc->m_next = NULL;
3540 mpc->m_len = cqe->ext_bd_len_list[i];
3541
3542
3543 if (mpf == NULL) {
3544 mpf = mpl = mpc;
3545 } else {
3546 mpl->m_len = ha->rx_buf_size;
3547 mpl->m_next = mpc;
3548 mpl = mpc;
3549 }
3550
3551 ecore_chain_consume(&rxq->rx_bd_ring);
3552 rxq->sw_rx_cons =
3553 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3554 }
3555
3556 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_NONE) {
3557
3558 QL_DPRINT7(ha, "[%d]: invalid aggregation state, dropping"
3559 " incoming packet and reusing its buffer\n",
3560 fp->rss_id);
3561
3562 QLNX_INC_IQDROPS(ifp);
3563
3564 rxq->tpa_info[agg_index].mpf = mp;
3565 rxq->tpa_info[agg_index].mpl = NULL;
3566
3567 return;
3568 }
3569
3570 rxq->tpa_info[agg_index].placement_offset = cqe->placement_offset;
3571
3572 if (mpf != NULL) {
3573 mp->m_len = ha->rx_buf_size;
3574 mp->m_next = mpf;
3575 rxq->tpa_info[agg_index].mpf = mp;
3576 rxq->tpa_info[agg_index].mpl = mpl;
3577 } else {
3578 mp->m_len = cqe->len_on_first_bd + cqe->placement_offset;
3579 rxq->tpa_info[agg_index].mpf = mp;
3580 rxq->tpa_info[agg_index].mpl = mp;
3581 mp->m_next = NULL;
3582 }
3583
3584 mp->m_flags |= M_PKTHDR;
3585
3586 /* assign packet to this interface interface */
3587 mp->m_pkthdr.rcvif = ifp;
3588
3589 /* assume no hardware checksum has complated */
3590 mp->m_pkthdr.csum_flags = 0;
3591
3592 //mp->m_pkthdr.flowid = fp->rss_id;
3593 mp->m_pkthdr.flowid = cqe->rss_hash;
3594
3595#if __FreeBSD_version >= 1100000
3596
3597 hash_type = cqe->bitfields &
3598 (ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_MASK <<
3599 ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_SHIFT);
3600
3601 switch (hash_type) {
3602
3603 case RSS_HASH_TYPE_IPV4:
3604 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV4);
3605 break;
3606
3607 case RSS_HASH_TYPE_TCP_IPV4:
3608 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV4);
3609 break;
3610
3611 case RSS_HASH_TYPE_IPV6:
3612 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV6);
3613 break;
3614
3615 case RSS_HASH_TYPE_TCP_IPV6:
3616 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV6);
3617 break;
3618
3619 default:
3620 M_HASHTYPE_SET(mp, M_HASHTYPE_OPAQUE);
3621 break;
3622 }
3623
3624#else
3625 mp->m_flags |= M_FLOWID;
3626#endif
3627
3628 mp->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED | CSUM_IP_VALID |
3629 CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
3630
3631 mp->m_pkthdr.csum_data = 0xFFFF;
3632
3633 if (CQE_HAS_VLAN(cqe->pars_flags.flags)) {
3634 mp->m_pkthdr.ether_vtag = le16toh(cqe->vlan_tag);
3635 mp->m_flags |= M_VLANTAG;
3636 }
3637
3638 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_START;
3639
3640 QL_DPRINT7(ha, "[%d]: 5\n\tagg_state = %d\n\t mpf = %p mpl = %p\n",
3641 fp->rss_id, rxq->tpa_info[agg_index].agg_state,
3642 rxq->tpa_info[agg_index].mpf, rxq->tpa_info[agg_index].mpl);
3643
3644 return;
3645}
3646
3647static void
3648qlnx_tpa_cont(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3649 struct qlnx_rx_queue *rxq,
3650 struct eth_fast_path_rx_tpa_cont_cqe *cqe)
3651{
3652 struct sw_rx_data *sw_rx_data;
3653 int i;
3654 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3655 struct mbuf *mp;
3656 uint32_t agg_index;
3657 device_t dev;
3658
3659 dev = ha->pci_dev;
3660
3661 QL_DPRINT7(ha, "[%d]: enter\n \
3662 \t type = 0x%x\n \
3663 \t tpa_agg_index = 0x%x\n \
3664 \t len_list[0] = 0x%x\n \
3665 \t len_list[1] = 0x%x\n \
3666 \t len_list[2] = 0x%x\n \
3667 \t len_list[3] = 0x%x\n \
3668 \t len_list[4] = 0x%x\n \
3669 \t len_list[5] = 0x%x\n",
3670 fp->rss_id, cqe->type, cqe->tpa_agg_index,
3671 cqe->len_list[0], cqe->len_list[1], cqe->len_list[2],
3672 cqe->len_list[3], cqe->len_list[4], cqe->len_list[5]);
3673
3674 agg_index = cqe->tpa_agg_index;
3675
3676 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3677 QL_DPRINT7(ha, "[%d]: 0\n ", fp->rss_id);
3678 fp->err_rx_tpa_invalid_agg_num++;
3679 return;
3680 }
3681
3682
3683 for (i = 0; i < ETH_TPA_CQE_CONT_LEN_LIST_SIZE; i++) {
3684
3685 QL_DPRINT7(ha, "[%d]: 1\n ", fp->rss_id);
3686
3687 if (cqe->len_list[i] == 0)
3688 break;
3689
3690 if (rxq->tpa_info[agg_index].agg_state !=
3691 QLNX_AGG_STATE_START) {
3692 qlnx_reuse_rx_data(rxq);
3693 continue;
3694 }
3695
3696 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3697 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3698 BUS_DMASYNC_POSTREAD);
3699
3700 mpc = sw_rx_data->data;
3701
3702 if (mpc == NULL) {
3703
3704 QL_DPRINT7(ha, "[%d]: mpc = NULL\n", fp->rss_id);
3705
3706 fp->err_rx_mp_null++;
3707 if (mpf != NULL)
3708 m_freem(mpf);
3709 mpf = mpl = NULL;
3710 rxq->tpa_info[agg_index].agg_state =
3711 QLNX_AGG_STATE_ERROR;
3712 ecore_chain_consume(&rxq->rx_bd_ring);
3713 rxq->sw_rx_cons =
3714 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3715 continue;
3716 }
3717
3718 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3719
3720 QL_DPRINT7(ha, "[%d]: New buffer allocation failed,"
3721 " dropping incoming packet and reusing its"
3722 " buffer\n", fp->rss_id);
3723
3724 qlnx_reuse_rx_data(rxq);
3725
3726 if (mpf != NULL)
3727 m_freem(mpf);
3728 mpf = mpl = NULL;
3729
3730 rxq->tpa_info[agg_index].agg_state =
3731 QLNX_AGG_STATE_ERROR;
3732
3733 ecore_chain_consume(&rxq->rx_bd_ring);
3734 rxq->sw_rx_cons =
3735 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3736
3737 continue;
3738 }
3739
3740 mpc->m_flags &= ~M_PKTHDR;
3741 mpc->m_next = NULL;
3742 mpc->m_len = cqe->len_list[i];
3743
3744
3745 if (mpf == NULL) {
3746 mpf = mpl = mpc;
3747 } else {
3748 mpl->m_len = ha->rx_buf_size;
3749 mpl->m_next = mpc;
3750 mpl = mpc;
3751 }
3752
3753 ecore_chain_consume(&rxq->rx_bd_ring);
3754 rxq->sw_rx_cons =
3755 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3756 }
3757
3758 QL_DPRINT7(ha, "[%d]: 2\n" "\tmpf = %p mpl = %p\n",
3759 fp->rss_id, mpf, mpl);
3760
3761 if (mpf != NULL) {
3762 mp = rxq->tpa_info[agg_index].mpl;
3763 mp->m_len = ha->rx_buf_size;
3764 mp->m_next = mpf;
3765 rxq->tpa_info[agg_index].mpl = mpl;
3766 }
3767
3768 return;
3769}
3770
3771static int
3772qlnx_tpa_end(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3773 struct qlnx_rx_queue *rxq,
3774 struct eth_fast_path_rx_tpa_end_cqe *cqe)
3775{
3776 struct sw_rx_data *sw_rx_data;
3777 int i;
3778 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3779 struct mbuf *mp;
3780 uint32_t agg_index;
3781 uint32_t len = 0;
3782 struct ifnet *ifp = ha->ifp;
3783 device_t dev;
3784
3785 dev = ha->pci_dev;
3786
3787 QL_DPRINT7(ha, "[%d]: enter\n \
3788 \t type = 0x%x\n \
3789 \t tpa_agg_index = 0x%x\n \
3790 \t total_packet_len = 0x%x\n \
3791 \t num_of_bds = 0x%x\n \
3792 \t end_reason = 0x%x\n \
3793 \t num_of_coalesced_segs = 0x%x\n \
3794 \t ts_delta = 0x%x\n \
3795 \t len_list[0] = 0x%x\n \
3796 \t len_list[1] = 0x%x\n \
3797 \t len_list[2] = 0x%x\n \
3798 \t len_list[3] = 0x%x\n",
3799 fp->rss_id, cqe->type, cqe->tpa_agg_index,
3800 cqe->total_packet_len, cqe->num_of_bds,
3801 cqe->end_reason, cqe->num_of_coalesced_segs, cqe->ts_delta,
3802 cqe->len_list[0], cqe->len_list[1], cqe->len_list[2],
3803 cqe->len_list[3]);
3804
3805 agg_index = cqe->tpa_agg_index;
3806
3807 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3808
3809 QL_DPRINT7(ha, "[%d]: 0\n ", fp->rss_id);
3810
3811 fp->err_rx_tpa_invalid_agg_num++;
3812 return (0);
3813 }
3814
3815
3816 for (i = 0; i < ETH_TPA_CQE_END_LEN_LIST_SIZE; i++) {
3817
3818 QL_DPRINT7(ha, "[%d]: 1\n ", fp->rss_id);
3819
3820 if (cqe->len_list[i] == 0)
3821 break;
3822
3823 if (rxq->tpa_info[agg_index].agg_state !=
3824 QLNX_AGG_STATE_START) {
3825
3826 QL_DPRINT7(ha, "[%d]: 2\n ", fp->rss_id);
3827
3828 qlnx_reuse_rx_data(rxq);
3829 continue;
3830 }
3831
3832 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3833 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3834 BUS_DMASYNC_POSTREAD);
3835
3836 mpc = sw_rx_data->data;
3837
3838 if (mpc == NULL) {
3839
3840 QL_DPRINT7(ha, "[%d]: mpc = NULL\n", fp->rss_id);
3841
3842 fp->err_rx_mp_null++;
3843 if (mpf != NULL)
3844 m_freem(mpf);
3845 mpf = mpl = NULL;
3846 rxq->tpa_info[agg_index].agg_state =
3847 QLNX_AGG_STATE_ERROR;
3848 ecore_chain_consume(&rxq->rx_bd_ring);
3849 rxq->sw_rx_cons =
3850 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3851 continue;
3852 }
3853
3854 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3855 QL_DPRINT7(ha, "[%d]: New buffer allocation failed,"
3856 " dropping incoming packet and reusing its"
3857 " buffer\n", fp->rss_id);
3858
3859 qlnx_reuse_rx_data(rxq);
3860
3861 if (mpf != NULL)
3862 m_freem(mpf);
3863 mpf = mpl = NULL;
3864
3865 rxq->tpa_info[agg_index].agg_state =
3866 QLNX_AGG_STATE_ERROR;
3867
3868 ecore_chain_consume(&rxq->rx_bd_ring);
3869 rxq->sw_rx_cons =
3870 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3871
3872 continue;
3873 }
3874
3875 mpc->m_flags &= ~M_PKTHDR;
3876 mpc->m_next = NULL;
3877 mpc->m_len = cqe->len_list[i];
3878
3879
3880 if (mpf == NULL) {
3881 mpf = mpl = mpc;
3882 } else {
3883 mpl->m_len = ha->rx_buf_size;
3884 mpl->m_next = mpc;
3885 mpl = mpc;
3886 }
3887
3888 ecore_chain_consume(&rxq->rx_bd_ring);
3889 rxq->sw_rx_cons =
3890 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3891 }
3892
3893 QL_DPRINT7(ha, "[%d]: 5\n ", fp->rss_id);
3894
3895 if (mpf != NULL) {
3896
3897 QL_DPRINT7(ha, "[%d]: 6\n ", fp->rss_id);
3898
3899 mp = rxq->tpa_info[agg_index].mpl;
3900 mp->m_len = ha->rx_buf_size;
3901 mp->m_next = mpf;
3902 }
3903
3904 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_START) {
3905
3906 QL_DPRINT7(ha, "[%d]: 7\n ", fp->rss_id);
3907
3908 if (rxq->tpa_info[agg_index].mpf != NULL)
3909 m_freem(rxq->tpa_info[agg_index].mpf);
3910 rxq->tpa_info[agg_index].mpf = NULL;
3911 rxq->tpa_info[agg_index].mpl = NULL;
3912 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_NONE;
3913 return (0);
3914 }
3915
3916 mp = rxq->tpa_info[agg_index].mpf;
3917 m_adj(mp, rxq->tpa_info[agg_index].placement_offset);
3918 mp->m_pkthdr.len = cqe->total_packet_len;
3919
3920 if (mp->m_next == NULL)
3921 mp->m_len = mp->m_pkthdr.len;
3922 else {
3923 /* compute the total packet length */
3924 mpf = mp;
3925 while (mpf != NULL) {
3926 len += mpf->m_len;
3927 mpf = mpf->m_next;
3928 }
3929
3930 if (cqe->total_packet_len > len) {
3931 mpl = rxq->tpa_info[agg_index].mpl;
3932 mpl->m_len += (cqe->total_packet_len - len);
3933 }
3934 }
3935
3936 QLNX_INC_IPACKETS(ifp);
3937 QLNX_INC_IBYTES(ifp, (cqe->total_packet_len));
3938
3939 QL_DPRINT7(ha, "[%d]: 8 csum_data = 0x%x csum_flags = 0x%lx\n \
3940 m_len = 0x%x m_pkthdr_len = 0x%x\n",
3941 fp->rss_id, mp->m_pkthdr.csum_data,
3942 mp->m_pkthdr.csum_flags, mp->m_len, mp->m_pkthdr.len);
3943
3944 (*ifp->if_input)(ifp, mp);
3945
3946 rxq->tpa_info[agg_index].mpf = NULL;
3947 rxq->tpa_info[agg_index].mpl = NULL;
3948 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_NONE;
3949
3950 return (cqe->num_of_coalesced_segs);
3951}
3952
3953static int
3954qlnx_rx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp, int budget,
3955 int lro_enable)
3956{
3957 uint16_t hw_comp_cons, sw_comp_cons;
3958 int rx_pkt = 0;
3959 struct qlnx_rx_queue *rxq = fp->rxq;
3960 struct ifnet *ifp = ha->ifp;
3961 struct ecore_dev *cdev = &ha->cdev;
3962 struct ecore_hwfn *p_hwfn;
3963
3964#ifdef QLNX_SOFT_LRO
3965 struct lro_ctrl *lro;
3966
3967 lro = &rxq->lro;
3968#endif /* #ifdef QLNX_SOFT_LRO */
3969
3970 hw_comp_cons = le16toh(*rxq->hw_cons_ptr);
3971 sw_comp_cons = ecore_chain_get_cons_idx(&rxq->rx_comp_ring);
3972
3973 p_hwfn = &ha->cdev.hwfns[(fp->rss_id % cdev->num_hwfns)];
3974
3975 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
3976 * / BD in the while-loop before reading hw_comp_cons. If the CQE is
3977 * read before it is written by FW, then FW writes CQE and SB, and then
3978 * the CPU reads the hw_comp_cons, it will use an old CQE.
3979 */
3980
3981 /* Loop to complete all indicated BDs */
3982 while (sw_comp_cons != hw_comp_cons) {
3983 union eth_rx_cqe *cqe;
3984 struct eth_fast_path_rx_reg_cqe *fp_cqe;
3985 struct sw_rx_data *sw_rx_data;
3986 register struct mbuf *mp;
3987 enum eth_rx_cqe_type cqe_type;
3988 uint16_t len, pad, len_on_first_bd;
3989 uint8_t *data;
3990#if __FreeBSD_version >= 1100000
3991 uint8_t hash_type;
3992#endif /* #if __FreeBSD_version >= 1100000 */
3993
3994 /* Get the CQE from the completion ring */
3995 cqe = (union eth_rx_cqe *)
3996 ecore_chain_consume(&rxq->rx_comp_ring);
3997 cqe_type = cqe->fast_path_regular.type;
3998
3999 if (cqe_type == ETH_RX_CQE_TYPE_SLOW_PATH) {
4000 QL_DPRINT3(ha, "Got a slowath CQE\n");
4001
4002 ecore_eth_cqe_completion(p_hwfn,
4003 (struct eth_slow_path_rx_cqe *)cqe);
4004 goto next_cqe;
4005 }
4006
4007 if (cqe_type != ETH_RX_CQE_TYPE_REGULAR) {
4008
4009 switch (cqe_type) {
4010
4011 case ETH_RX_CQE_TYPE_TPA_START:
4012 qlnx_tpa_start(ha, fp, rxq,
4013 &cqe->fast_path_tpa_start);
4014 fp->tpa_start++;
4015 break;
4016
4017 case ETH_RX_CQE_TYPE_TPA_CONT:
4018 qlnx_tpa_cont(ha, fp, rxq,
4019 &cqe->fast_path_tpa_cont);
4020 fp->tpa_cont++;
4021 break;
4022
4023 case ETH_RX_CQE_TYPE_TPA_END:
4024 rx_pkt += qlnx_tpa_end(ha, fp, rxq,
4025 &cqe->fast_path_tpa_end);
4026 fp->tpa_end++;
4027 break;
4028
4029 default:
4030 break;
4031 }
4032
4033 goto next_cqe;
4034 }
4035
4036 /* Get the data from the SW ring */
4037 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
4038 mp = sw_rx_data->data;
4039
4040 if (mp == NULL) {
4041 QL_DPRINT1(ha, "mp = NULL\n");
4042 fp->err_rx_mp_null++;
4043 rxq->sw_rx_cons =
4044 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
4045 goto next_cqe;
4046 }
4047 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
4048 BUS_DMASYNC_POSTREAD);
4049
4050 /* non GRO */
4051 fp_cqe = &cqe->fast_path_regular;/* MK CR TPA check assembly */
4052 len = le16toh(fp_cqe->pkt_len);
4053 pad = fp_cqe->placement_offset;
4054
4055 QL_DPRINT3(ha, "CQE type = %x, flags = %x, vlan = %x,"
4056 " len %u, parsing flags = %d pad = %d\n",
4057 cqe_type, fp_cqe->bitfields,
4058 le16toh(fp_cqe->vlan_tag),
4059 len, le16toh(fp_cqe->pars_flags.flags), pad);
4060
4061 data = mtod(mp, uint8_t *);
4062 data = data + pad;
4063
4064 if (0)
4065 qlnx_dump_buf8(ha, __func__, data, len);
4066
4067 /* For every Rx BD consumed, we allocate a new BD so the BD ring
4068 * is always with a fixed size. If allocation fails, we take the
4069 * consumed BD and return it to the ring in the PROD position.
4070 * The packet that was received on that BD will be dropped (and
4071 * not passed to the upper stack).
4072 */
4073 /* If this is an error packet then drop it */
4074 if ((le16toh(cqe->fast_path_regular.pars_flags.flags)) &
4075 CQE_FLAGS_ERR) {
4076
4077 QL_DPRINT1(ha, "CQE in CONS = %u has error, flags = %x,"
4078 " dropping incoming packet\n", sw_comp_cons,
4079 le16toh(cqe->fast_path_regular.pars_flags.flags));
4080 fp->err_rx_hw_errors++;
4081
4082 qlnx_reuse_rx_data(rxq);
4083
4084 QLNX_INC_IERRORS(ifp);
4085
4086 goto next_cqe;
4087 }
4088
4089 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
4090
4091 QL_DPRINT1(ha, "New buffer allocation failed, dropping"
4092 " incoming packet and reusing its buffer\n");
4093 qlnx_reuse_rx_data(rxq);
4094
4095 fp->err_rx_alloc_errors++;
4096
4097 QLNX_INC_IQDROPS(ifp);
4098
4099 goto next_cqe;
4100 }
4101
4102 ecore_chain_consume(&rxq->rx_bd_ring);
4103
4104 len_on_first_bd = fp_cqe->len_on_first_bd;
4105 m_adj(mp, pad);
4106 mp->m_pkthdr.len = len;
4107
4108 QL_DPRINT1(ha, "len = %d len_on_first_bd = %d\n",
4109 len, len_on_first_bd);
4110 if ((len > 60 ) && (len > len_on_first_bd)) {
4111
4112 mp->m_len = len_on_first_bd;
4113
4114 if (qlnx_rx_jumbo_chain(ha, fp, mp,
4115 (len - len_on_first_bd)) != 0) {
4116
4117 m_freem(mp);
4118
4119 QLNX_INC_IQDROPS(ifp);
4120
4121 goto next_cqe;
4122 }
4123
4124 } else if (len_on_first_bd < len) {
4125 fp->err_rx_jumbo_chain_pkts++;
4126 } else {
4127 mp->m_len = len;
4128 }
4129
4130 mp->m_flags |= M_PKTHDR;
4131
4132 /* assign packet to this interface interface */
4133 mp->m_pkthdr.rcvif = ifp;
4134
4135 /* assume no hardware checksum has complated */
4136 mp->m_pkthdr.csum_flags = 0;
4137
4138 mp->m_pkthdr.flowid = fp_cqe->rss_hash;
4139
4140#if __FreeBSD_version >= 1100000
4141
4142 hash_type = fp_cqe->bitfields &
4143 (ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_MASK <<
4144 ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_SHIFT);
4145
4146 switch (hash_type) {
4147
4148 case RSS_HASH_TYPE_IPV4:
4149 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV4);
4150 break;
4151
4152 case RSS_HASH_TYPE_TCP_IPV4:
4153 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV4);
4154 break;
4155
4156 case RSS_HASH_TYPE_IPV6:
4157 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV6);
4158 break;
4159
4160 case RSS_HASH_TYPE_TCP_IPV6:
4161 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV6);
4162 break;
4163
4164 default:
4165 M_HASHTYPE_SET(mp, M_HASHTYPE_OPAQUE);
4166 break;
4167 }
4168
4169#else
4170 mp->m_flags |= M_FLOWID;
4171#endif
4172
4173 if (CQE_L3_PACKET(fp_cqe->pars_flags.flags)) {
4174 mp->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
4175 }
4176
4177 if (!(CQE_IP_HDR_ERR(fp_cqe->pars_flags.flags))) {
4178 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
4179 }
4180
4181 if (CQE_L4_HAS_CSUM(fp_cqe->pars_flags.flags)) {
4182 mp->m_pkthdr.csum_data = 0xFFFF;
4183 mp->m_pkthdr.csum_flags |=
4184 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
4185 }
4186
4187 if (CQE_HAS_VLAN(fp_cqe->pars_flags.flags)) {
4188 mp->m_pkthdr.ether_vtag = le16toh(fp_cqe->vlan_tag);
4189 mp->m_flags |= M_VLANTAG;
4190 }
4191
4192 QLNX_INC_IPACKETS(ifp);
4193 QLNX_INC_IBYTES(ifp, len);
4194
4195#ifdef QLNX_SOFT_LRO
4196
4197 if (lro_enable) {
4198
4199#if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
4200
4201 tcp_lro_queue_mbuf(lro, mp);
4202
4203#else
4204
4205 if (tcp_lro_rx(lro, mp, 0))
4206 (*ifp->if_input)(ifp, mp);
4207
4208#endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
4209
4210 } else {
4211 (*ifp->if_input)(ifp, mp);
4212 }
4213#else
4214
4215 (*ifp->if_input)(ifp, mp);
4216
4217#endif /* #ifdef QLNX_SOFT_LRO */
4218
4219 rx_pkt++;
4220
4221 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
4222
4223next_cqe: /* don't consume bd rx buffer */
4224 ecore_chain_recycle_consumed(&rxq->rx_comp_ring);
4225 sw_comp_cons = ecore_chain_get_cons_idx(&rxq->rx_comp_ring);
4226
4227 /* CR TPA - revisit how to handle budget in TPA perhaps
4228 increase on "end" */
4229 if (rx_pkt == budget)
4230 break;
4231 } /* repeat while sw_comp_cons != hw_comp_cons... */
4232
4233 /* Update producers */
4234 qlnx_update_rx_prod(p_hwfn, rxq);
4235
4236 return rx_pkt;
4237}
4238
4239/*
4240 * fast path interrupt
4241 */
4242
4243static void
4244qlnx_fp_isr(void *arg)
4245{
4246 qlnx_ivec_t *ivec = arg;
4247 qlnx_host_t *ha;
4248 struct qlnx_fastpath *fp = NULL;
4249 int idx;
4250
4251 ha = ivec->ha;
4252
4253 if (ha->state != QLNX_STATE_OPEN) {
4254 return;
4255 }
4256
4257 idx = ivec->rss_idx;
4258
4259 if ((idx = ivec->rss_idx) >= ha->num_rss) {
4260 QL_DPRINT1(ha, "illegal interrupt[%d]\n", idx);
4261 ha->err_illegal_intr++;
4262 return;
4263 }
4264 fp = &ha->fp_array[idx];
4265
4266 if (fp == NULL) {
4267 ha->err_fp_null++;
4268 } else {
4269 ecore_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0);
4270 if (fp->fp_taskqueue != NULL)
4271 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
4272 }
4273
4274 return;
4275}
4276
4277
4278/*
4279 * slow path interrupt processing function
4280 * can be invoked in polled mode or in interrupt mode via taskqueue.
4281 */
4282void
4283qlnx_sp_isr(void *arg)
4284{
4285 struct ecore_hwfn *p_hwfn;
4286 qlnx_host_t *ha;
4287
4288 p_hwfn = arg;
4289
4290 ha = (qlnx_host_t *)p_hwfn->p_dev;
4291
4292 ha->sp_interrupts++;
4293
4294 QL_DPRINT2(ha, "enter\n");
4295
4296 ecore_int_sp_dpc(p_hwfn);
4297
4298 QL_DPRINT2(ha, "exit\n");
4299
4300 return;
4301}
4302
4303/*****************************************************************************
4304 * Support Functions for DMA'able Memory
4305 *****************************************************************************/
4306
4307static void
4308qlnx_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
4309{
4310 *((bus_addr_t *)arg) = 0;
4311
4312 if (error) {
4313 printf("%s: bus_dmamap_load failed (%d)\n", __func__, error);
4314 return;
4315 }
4316
4317 *((bus_addr_t *)arg) = segs[0].ds_addr;
4318
4319 return;
4320}
4321
4322static int
4323qlnx_alloc_dmabuf(qlnx_host_t *ha, qlnx_dma_t *dma_buf)
4324{
4325 int ret = 0;
4326 device_t dev;
4327 bus_addr_t b_addr;
4328
4329 dev = ha->pci_dev;
4330
4331 ret = bus_dma_tag_create(
4332 ha->parent_tag,/* parent */
4333 dma_buf->alignment,
4334 ((bus_size_t)(1ULL << 32)),/* boundary */
4335 BUS_SPACE_MAXADDR, /* lowaddr */
4336 BUS_SPACE_MAXADDR, /* highaddr */
4337 NULL, NULL, /* filter, filterarg */
4338 dma_buf->size, /* maxsize */
4339 1, /* nsegments */
4340 dma_buf->size, /* maxsegsize */
4341 0, /* flags */
4342 NULL, NULL, /* lockfunc, lockarg */
4343 &dma_buf->dma_tag);
4344
4345 if (ret) {
4346 QL_DPRINT1(ha, "could not create dma tag\n");
4347 goto qlnx_alloc_dmabuf_exit;
4348 }
4349 ret = bus_dmamem_alloc(dma_buf->dma_tag,
4350 (void **)&dma_buf->dma_b,
4351 (BUS_DMA_ZERO | BUS_DMA_COHERENT | BUS_DMA_NOWAIT),
4352 &dma_buf->dma_map);
4353 if (ret) {
4354 bus_dma_tag_destroy(dma_buf->dma_tag);
4355 QL_DPRINT1(ha, "bus_dmamem_alloc failed\n");
4356 goto qlnx_alloc_dmabuf_exit;
4357 }
4358
4359 ret = bus_dmamap_load(dma_buf->dma_tag,
4360 dma_buf->dma_map,
4361 dma_buf->dma_b,
4362 dma_buf->size,
4363 qlnx_dmamap_callback,
4364 &b_addr, BUS_DMA_NOWAIT);
4365
4366 if (ret || !b_addr) {
4367 bus_dma_tag_destroy(dma_buf->dma_tag);
4368 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b,
4369 dma_buf->dma_map);
4370 ret = -1;
4371 goto qlnx_alloc_dmabuf_exit;
4372 }
4373
4374 dma_buf->dma_addr = b_addr;
4375
4376qlnx_alloc_dmabuf_exit:
4377
4378 return ret;
4379}
4380
4381static void
4382qlnx_free_dmabuf(qlnx_host_t *ha, qlnx_dma_t *dma_buf)
4383{
4384 bus_dmamap_unload(dma_buf->dma_tag, dma_buf->dma_map);
4385 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, dma_buf->dma_map);
4386 bus_dma_tag_destroy(dma_buf->dma_tag);
4387 return;
4388}
4389
4390void *
4391qlnx_dma_alloc_coherent(void *ecore_dev, bus_addr_t *phys, uint32_t size)
4392{
4393 qlnx_dma_t dma_buf;
4394 qlnx_dma_t *dma_p;
4395 qlnx_host_t *ha;
4396 device_t dev;
4397
4398 ha = (qlnx_host_t *)ecore_dev;
4399 dev = ha->pci_dev;
4400
4401 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4402
4403 memset(&dma_buf, 0, sizeof (qlnx_dma_t));
4404
4405 dma_buf.size = size + PAGE_SIZE;
4406 dma_buf.alignment = 8;
4407
4408 if (qlnx_alloc_dmabuf((qlnx_host_t *)ecore_dev, &dma_buf) != 0)
4409 return (NULL);
4410 bzero((uint8_t *)dma_buf.dma_b, dma_buf.size);
4411
4412 *phys = dma_buf.dma_addr;
4413
4414 dma_p = (qlnx_dma_t *)((uint8_t *)dma_buf.dma_b + size);
4415
4416 memcpy(dma_p, &dma_buf, sizeof(qlnx_dma_t));
4417/*
4418 QL_DPRINT5(ha, "[%p %p %p %p 0x%08x ]\n",
4419 (void *)dma_buf.dma_map, (void *)dma_buf.dma_tag,
4420 dma_buf.dma_b, (void *)dma_buf.dma_addr, size);
4421*/
4422 return (dma_buf.dma_b);
4423}
4424
4425void
4426qlnx_dma_free_coherent(void *ecore_dev, void *v_addr, bus_addr_t phys,
4427 uint32_t size)
4428{
4429 qlnx_dma_t dma_buf, *dma_p;
4430 qlnx_host_t *ha;
4431 device_t dev;
4432
4433 ha = (qlnx_host_t *)ecore_dev;
4434 dev = ha->pci_dev;
4435
4436 if (v_addr == NULL)
4437 return;
4438
4439 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4440
4441 dma_p = (qlnx_dma_t *)((uint8_t *)v_addr + size);
4442/*
4443 QL_DPRINT5(ha, "[%p %p %p %p 0x%08x ]\n",
4444 (void *)dma_p->dma_map, (void *)dma_p->dma_tag,
4445 dma_p->dma_b, (void *)dma_p->dma_addr, size);
4446*/
4447 dma_buf = *dma_p;
4448
4449 qlnx_free_dmabuf((qlnx_host_t *)ecore_dev, &dma_buf);
4450 return;
4451}
4452
4453static int
4454qlnx_alloc_parent_dma_tag(qlnx_host_t *ha)
4455{
4456 int ret;
4457 device_t dev;
4458
4459 dev = ha->pci_dev;
4460
4461 /*
4462 * Allocate parent DMA Tag
4463 */
4464 ret = bus_dma_tag_create(
4465 bus_get_dma_tag(dev), /* parent */
4466 1,((bus_size_t)(1ULL << 32)),/* alignment, boundary */
4467 BUS_SPACE_MAXADDR, /* lowaddr */
4468 BUS_SPACE_MAXADDR, /* highaddr */
4469 NULL, NULL, /* filter, filterarg */
4470 BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
4471 0, /* nsegments */
4472 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
4473 0, /* flags */
4474 NULL, NULL, /* lockfunc, lockarg */
4475 &ha->parent_tag);
4476
4477 if (ret) {
4478 QL_DPRINT1(ha, "could not create parent dma tag\n");
4479 return (-1);
4480 }
4481
4482 ha->flags.parent_tag = 1;
4483
4484 return (0);
4485}
4486
4487static void
4488qlnx_free_parent_dma_tag(qlnx_host_t *ha)
4489{
4490 if (ha->parent_tag != NULL) {
4491 bus_dma_tag_destroy(ha->parent_tag);
4492 ha->parent_tag = NULL;
4493 }
4494 return;
4495}
4496
4497static int
4498qlnx_alloc_tx_dma_tag(qlnx_host_t *ha)
4499{
4500 if (bus_dma_tag_create(NULL, /* parent */
4501 1, 0, /* alignment, bounds */
4502 BUS_SPACE_MAXADDR, /* lowaddr */
4503 BUS_SPACE_MAXADDR, /* highaddr */
4504 NULL, NULL, /* filter, filterarg */
4505 QLNX_MAX_TSO_FRAME_SIZE, /* maxsize */
4506 QLNX_MAX_SEGMENTS, /* nsegments */
4507 (PAGE_SIZE * 4), /* maxsegsize */
4508 BUS_DMA_ALLOCNOW, /* flags */
4509 NULL, /* lockfunc */
4510 NULL, /* lockfuncarg */
4511 &ha->tx_tag)) {
4512
4513 QL_DPRINT1(ha, "tx_tag alloc failed\n");
4514 return (-1);
4515 }
4516
4517 return (0);
4518}
4519
4520static void
4521qlnx_free_tx_dma_tag(qlnx_host_t *ha)
4522{
4523 if (ha->tx_tag != NULL) {
4524 bus_dma_tag_destroy(ha->tx_tag);
4525 ha->tx_tag = NULL;
4526 }
4527 return;
4528}
4529
4530static int
4531qlnx_alloc_rx_dma_tag(qlnx_host_t *ha)
4532{
4533 if (bus_dma_tag_create(NULL, /* parent */
4534 1, 0, /* alignment, bounds */
4535 BUS_SPACE_MAXADDR, /* lowaddr */
4536 BUS_SPACE_MAXADDR, /* highaddr */
4537 NULL, NULL, /* filter, filterarg */
4538 MJUM9BYTES, /* maxsize */
4539 1, /* nsegments */
4540 MJUM9BYTES, /* maxsegsize */
4541 BUS_DMA_ALLOCNOW, /* flags */
4542 NULL, /* lockfunc */
4543 NULL, /* lockfuncarg */
4544 &ha->rx_tag)) {
4545
4546 QL_DPRINT1(ha, " rx_tag alloc failed\n");
4547
4548 return (-1);
4549 }
4550 return (0);
4551}
4552
4553static void
4554qlnx_free_rx_dma_tag(qlnx_host_t *ha)
4555{
4556 if (ha->rx_tag != NULL) {
4557 bus_dma_tag_destroy(ha->rx_tag);
4558 ha->rx_tag = NULL;
4559 }
4560 return;
4561}
4562
4563/*********************************
4564 * Exported functions
4565 *********************************/
4566uint32_t
4567qlnx_pci_bus_get_bar_size(void *ecore_dev, uint8_t bar_id)
4568{
4569 uint32_t bar_size;
4570
4571 bar_id = bar_id * 2;
4572
4573 bar_size = bus_get_resource_count(((qlnx_host_t *)ecore_dev)->pci_dev,
4574 SYS_RES_MEMORY,
4575 PCIR_BAR(bar_id));
4576
4577 return (bar_size);
4578}
4579
4580uint32_t
4581qlnx_pci_read_config_byte(void *ecore_dev, uint32_t pci_reg, uint8_t *reg_value)
4582{
4583 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4584 pci_reg, 1);
4585 return 0;
4586}
4587
4588uint32_t
4589qlnx_pci_read_config_word(void *ecore_dev, uint32_t pci_reg,
4590 uint16_t *reg_value)
4591{
4592 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4593 pci_reg, 2);
4594 return 0;
4595}
4596
4597uint32_t
4598qlnx_pci_read_config_dword(void *ecore_dev, uint32_t pci_reg,
4599 uint32_t *reg_value)
4600{
4601 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4602 pci_reg, 4);
4603 return 0;
4604}
4605
4606void
4607qlnx_pci_write_config_byte(void *ecore_dev, uint32_t pci_reg, uint8_t reg_value)
4608{
4609 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4610 pci_reg, reg_value, 1);
4611 return;
4612}
4613
4614void
4615qlnx_pci_write_config_word(void *ecore_dev, uint32_t pci_reg,
4616 uint16_t reg_value)
4617{
4618 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4619 pci_reg, reg_value, 2);
4620 return;
4621}
4622
4623void
4624qlnx_pci_write_config_dword(void *ecore_dev, uint32_t pci_reg,
4625 uint32_t reg_value)
4626{
4627 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4628 pci_reg, reg_value, 4);
4629 return;
4630}
4631
4632
4633int
4634qlnx_pci_find_capability(void *ecore_dev, int cap)
4635{
4636 int reg;
4637 qlnx_host_t *ha;
4638
4639 ha = ecore_dev;
4640
4641 if (pci_find_cap(ha->pci_dev, PCIY_EXPRESS, &reg) == 0)
4642 return reg;
4643 else {
4644 QL_DPRINT1(ha, "failed\n");
4645 return 0;
4646 }
4647}
4648
4649uint32_t
4650qlnx_reg_rd32(void *hwfn, uint32_t reg_addr)
4651{
4652 uint32_t data32;
4653 struct ecore_dev *cdev;
4654 struct ecore_hwfn *p_hwfn;
4655
4656 p_hwfn = hwfn;
4657
4658 cdev = p_hwfn->p_dev;
4659
4660 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4661 (uint8_t *)(cdev->regview)) + reg_addr;
4662
4663 data32 = bus_read_4(((qlnx_host_t *)cdev)->pci_reg, reg_addr);
4664
4665 return (data32);
4666}
4667
4668void
4669qlnx_reg_wr32(void *hwfn, uint32_t reg_addr, uint32_t value)
4670{
4671 struct ecore_dev *cdev;
4672 struct ecore_hwfn *p_hwfn;
4673
4674 p_hwfn = hwfn;
4675
4676 cdev = p_hwfn->p_dev;
4677
4678 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4679 (uint8_t *)(cdev->regview)) + reg_addr;
4680
4681 bus_write_4(((qlnx_host_t *)cdev)->pci_reg, reg_addr, value);
4682
4683 return;
4684}
4685
4686void
4687qlnx_reg_wr16(void *hwfn, uint32_t reg_addr, uint16_t value)
4688{
4689 struct ecore_dev *cdev;
4690 struct ecore_hwfn *p_hwfn;
4691
4692 p_hwfn = hwfn;
4693
4694 cdev = p_hwfn->p_dev;
4695
4696 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4697 (uint8_t *)(cdev->regview)) + reg_addr;
4698
4699 bus_write_2(((qlnx_host_t *)cdev)->pci_reg, reg_addr, value);
4700
4701 return;
4702}
4703
4704void
4705qlnx_dbell_wr32(void *hwfn, uint32_t reg_addr, uint32_t value)
4706{
4707 struct ecore_dev *cdev;
4708 struct ecore_hwfn *p_hwfn;
4709
4710 p_hwfn = hwfn;
4711
4712 cdev = p_hwfn->p_dev;
4713
4714 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->doorbells) -
4715 (uint8_t *)(cdev->doorbells)) + reg_addr;
4716
4717 bus_write_4(((qlnx_host_t *)cdev)->pci_dbells, reg_addr, value);
4718
4719 return;
4720}
4721
4722uint32_t
4723qlnx_direct_reg_rd32(void *p_hwfn, uint32_t *reg_addr)
4724{
4725 uint32_t data32;
4726 uint32_t offset;
4727 struct ecore_dev *cdev;
4728
4729 cdev = ((struct ecore_hwfn *)p_hwfn)->p_dev;
4730 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)(cdev->regview));
4731
4732 data32 = bus_read_4(((qlnx_host_t *)cdev)->pci_reg, offset);
4733
4734 return (data32);
4735}
4736
4737void
4738qlnx_direct_reg_wr32(void *p_hwfn, void *reg_addr, uint32_t value)
4739{
4740 uint32_t offset;
4741 struct ecore_dev *cdev;
4742
4743 cdev = ((struct ecore_hwfn *)p_hwfn)->p_dev;
4744 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)(cdev->regview));
4745
4746 bus_write_4(((qlnx_host_t *)cdev)->pci_reg, offset, value);
4747
4748 return;
4749}
4750
3254 break;
3255
3256 default :
3257 ifm_type = IFM_UNKNOWN;
3258 break;
3259 }
3260 return (ifm_type);
3261}
3262
3263
3264
3265/*****************************************************************************
3266 * Interrupt Service Functions
3267 *****************************************************************************/
3268
3269static int
3270qlnx_rx_jumbo_chain(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3271 struct mbuf *mp_head, uint16_t len)
3272{
3273 struct mbuf *mp, *mpf, *mpl;
3274 struct sw_rx_data *sw_rx_data;
3275 struct qlnx_rx_queue *rxq;
3276 uint16_t len_in_buffer;
3277
3278 rxq = fp->rxq;
3279 mpf = mpl = mp = NULL;
3280
3281 while (len) {
3282
3283 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3284
3285 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3286 mp = sw_rx_data->data;
3287
3288 if (mp == NULL) {
3289 QL_DPRINT1(ha, "mp = NULL\n");
3290 fp->err_rx_mp_null++;
3291 rxq->sw_rx_cons =
3292 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3293
3294 if (mpf != NULL)
3295 m_freem(mpf);
3296
3297 return (-1);
3298 }
3299 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3300 BUS_DMASYNC_POSTREAD);
3301
3302 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3303
3304 QL_DPRINT1(ha, "New buffer allocation failed, dropping"
3305 " incoming packet and reusing its buffer\n");
3306
3307 qlnx_reuse_rx_data(rxq);
3308 fp->err_rx_alloc_errors++;
3309
3310 if (mpf != NULL)
3311 m_freem(mpf);
3312
3313 return (-1);
3314 }
3315 ecore_chain_consume(&rxq->rx_bd_ring);
3316
3317 if (len > rxq->rx_buf_size)
3318 len_in_buffer = rxq->rx_buf_size;
3319 else
3320 len_in_buffer = len;
3321
3322 len = len - len_in_buffer;
3323
3324 mp->m_flags &= ~M_PKTHDR;
3325 mp->m_next = NULL;
3326 mp->m_len = len_in_buffer;
3327
3328 if (mpf == NULL)
3329 mpf = mpl = mp;
3330 else {
3331 mpl->m_next = mp;
3332 mpl = mp;
3333 }
3334 }
3335
3336 if (mpf != NULL)
3337 mp_head->m_next = mpf;
3338
3339 return (0);
3340}
3341
3342static void
3343qlnx_tpa_start(qlnx_host_t *ha,
3344 struct qlnx_fastpath *fp,
3345 struct qlnx_rx_queue *rxq,
3346 struct eth_fast_path_rx_tpa_start_cqe *cqe)
3347{
3348 uint32_t agg_index;
3349 struct ifnet *ifp = ha->ifp;
3350 struct mbuf *mp;
3351 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3352 struct sw_rx_data *sw_rx_data;
3353 dma_addr_t addr;
3354 bus_dmamap_t map;
3355 struct eth_rx_bd *rx_bd;
3356 int i;
3357 device_t dev;
3358#if __FreeBSD_version >= 1100000
3359 uint8_t hash_type;
3360#endif /* #if __FreeBSD_version >= 1100000 */
3361
3362 dev = ha->pci_dev;
3363 agg_index = cqe->tpa_agg_index;
3364
3365 QL_DPRINT7(ha, "[rss_id = %d]: enter\n \
3366 \t type = 0x%x\n \
3367 \t bitfields = 0x%x\n \
3368 \t seg_len = 0x%x\n \
3369 \t pars_flags = 0x%x\n \
3370 \t vlan_tag = 0x%x\n \
3371 \t rss_hash = 0x%x\n \
3372 \t len_on_first_bd = 0x%x\n \
3373 \t placement_offset = 0x%x\n \
3374 \t tpa_agg_index = 0x%x\n \
3375 \t header_len = 0x%x\n \
3376 \t ext_bd_len_list[0] = 0x%x\n \
3377 \t ext_bd_len_list[1] = 0x%x\n \
3378 \t ext_bd_len_list[2] = 0x%x\n \
3379 \t ext_bd_len_list[3] = 0x%x\n \
3380 \t ext_bd_len_list[4] = 0x%x\n",
3381 fp->rss_id, cqe->type, cqe->bitfields, cqe->seg_len,
3382 cqe->pars_flags.flags, cqe->vlan_tag,
3383 cqe->rss_hash, cqe->len_on_first_bd, cqe->placement_offset,
3384 cqe->tpa_agg_index, cqe->header_len,
3385 cqe->ext_bd_len_list[0], cqe->ext_bd_len_list[1],
3386 cqe->ext_bd_len_list[2], cqe->ext_bd_len_list[3],
3387 cqe->ext_bd_len_list[4]);
3388
3389 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3390 fp->err_rx_tpa_invalid_agg_num++;
3391 return;
3392 }
3393
3394 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3395 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map, BUS_DMASYNC_POSTREAD);
3396 mp = sw_rx_data->data;
3397
3398 QL_DPRINT7(ha, "[rss_id = %d]: mp = %p \n ", fp->rss_id, mp);
3399
3400 if (mp == NULL) {
3401 QL_DPRINT7(ha, "[%d]: mp = NULL\n", fp->rss_id);
3402 fp->err_rx_mp_null++;
3403 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3404
3405 return;
3406 }
3407
3408 if ((le16toh(cqe->pars_flags.flags)) & CQE_FLAGS_ERR) {
3409
3410 QL_DPRINT7(ha, "[%d]: CQE in CONS = %u has error,"
3411 " flags = %x, dropping incoming packet\n", fp->rss_id,
3412 rxq->sw_rx_cons, le16toh(cqe->pars_flags.flags));
3413
3414 fp->err_rx_hw_errors++;
3415
3416 qlnx_reuse_rx_data(rxq);
3417
3418 QLNX_INC_IERRORS(ifp);
3419
3420 return;
3421 }
3422
3423 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3424
3425 QL_DPRINT7(ha, "[%d]: New buffer allocation failed,"
3426 " dropping incoming packet and reusing its buffer\n",
3427 fp->rss_id);
3428
3429 fp->err_rx_alloc_errors++;
3430 QLNX_INC_IQDROPS(ifp);
3431
3432 /*
3433 * Load the tpa mbuf into the rx ring and save the
3434 * posted mbuf
3435 */
3436
3437 map = sw_rx_data->map;
3438 addr = sw_rx_data->dma_addr;
3439
3440 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_prod];
3441
3442 sw_rx_data->data = rxq->tpa_info[agg_index].rx_buf.data;
3443 sw_rx_data->dma_addr = rxq->tpa_info[agg_index].rx_buf.dma_addr;
3444 sw_rx_data->map = rxq->tpa_info[agg_index].rx_buf.map;
3445
3446 rxq->tpa_info[agg_index].rx_buf.data = mp;
3447 rxq->tpa_info[agg_index].rx_buf.dma_addr = addr;
3448 rxq->tpa_info[agg_index].rx_buf.map = map;
3449
3450 rx_bd = (struct eth_rx_bd *)
3451 ecore_chain_produce(&rxq->rx_bd_ring);
3452
3453 rx_bd->addr.hi = htole32(U64_HI(sw_rx_data->dma_addr));
3454 rx_bd->addr.lo = htole32(U64_LO(sw_rx_data->dma_addr));
3455
3456 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3457 BUS_DMASYNC_PREREAD);
3458
3459 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
3460 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3461
3462 ecore_chain_consume(&rxq->rx_bd_ring);
3463
3464 /* Now reuse any buffers posted in ext_bd_len_list */
3465 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3466
3467 if (cqe->ext_bd_len_list[i] == 0)
3468 break;
3469
3470 qlnx_reuse_rx_data(rxq);
3471 }
3472
3473 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_ERROR;
3474 return;
3475 }
3476
3477 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_NONE) {
3478
3479 QL_DPRINT7(ha, "[%d]: invalid aggregation state,"
3480 " dropping incoming packet and reusing its buffer\n",
3481 fp->rss_id);
3482
3483 QLNX_INC_IQDROPS(ifp);
3484
3485 /* if we already have mbuf head in aggregation free it */
3486 if (rxq->tpa_info[agg_index].mpf) {
3487 m_freem(rxq->tpa_info[agg_index].mpf);
3488 rxq->tpa_info[agg_index].mpl = NULL;
3489 }
3490 rxq->tpa_info[agg_index].mpf = mp;
3491 rxq->tpa_info[agg_index].mpl = NULL;
3492
3493 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3494 ecore_chain_consume(&rxq->rx_bd_ring);
3495
3496 /* Now reuse any buffers posted in ext_bd_len_list */
3497 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3498
3499 if (cqe->ext_bd_len_list[i] == 0)
3500 break;
3501
3502 qlnx_reuse_rx_data(rxq);
3503 }
3504 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_ERROR;
3505
3506 return;
3507 }
3508
3509 /*
3510 * first process the ext_bd_len_list
3511 * if this fails then we simply drop the packet
3512 */
3513 ecore_chain_consume(&rxq->rx_bd_ring);
3514 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3515
3516 for (i = 0; i < ETH_TPA_CQE_START_LEN_LIST_SIZE; i++) {
3517
3518 QL_DPRINT7(ha, "[%d]: 4\n ", fp->rss_id);
3519
3520 if (cqe->ext_bd_len_list[i] == 0)
3521 break;
3522
3523 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3524 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3525 BUS_DMASYNC_POSTREAD);
3526
3527 mpc = sw_rx_data->data;
3528
3529 if (mpc == NULL) {
3530 QL_DPRINT7(ha, "[%d]: mpc = NULL\n", fp->rss_id);
3531 fp->err_rx_mp_null++;
3532 if (mpf != NULL)
3533 m_freem(mpf);
3534 mpf = mpl = NULL;
3535 rxq->tpa_info[agg_index].agg_state =
3536 QLNX_AGG_STATE_ERROR;
3537 ecore_chain_consume(&rxq->rx_bd_ring);
3538 rxq->sw_rx_cons =
3539 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3540 continue;
3541 }
3542
3543 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3544 QL_DPRINT7(ha, "[%d]: New buffer allocation failed,"
3545 " dropping incoming packet and reusing its"
3546 " buffer\n", fp->rss_id);
3547
3548 qlnx_reuse_rx_data(rxq);
3549
3550 if (mpf != NULL)
3551 m_freem(mpf);
3552 mpf = mpl = NULL;
3553
3554 rxq->tpa_info[agg_index].agg_state =
3555 QLNX_AGG_STATE_ERROR;
3556
3557 ecore_chain_consume(&rxq->rx_bd_ring);
3558 rxq->sw_rx_cons =
3559 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3560
3561 continue;
3562 }
3563
3564 mpc->m_flags &= ~M_PKTHDR;
3565 mpc->m_next = NULL;
3566 mpc->m_len = cqe->ext_bd_len_list[i];
3567
3568
3569 if (mpf == NULL) {
3570 mpf = mpl = mpc;
3571 } else {
3572 mpl->m_len = ha->rx_buf_size;
3573 mpl->m_next = mpc;
3574 mpl = mpc;
3575 }
3576
3577 ecore_chain_consume(&rxq->rx_bd_ring);
3578 rxq->sw_rx_cons =
3579 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3580 }
3581
3582 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_NONE) {
3583
3584 QL_DPRINT7(ha, "[%d]: invalid aggregation state, dropping"
3585 " incoming packet and reusing its buffer\n",
3586 fp->rss_id);
3587
3588 QLNX_INC_IQDROPS(ifp);
3589
3590 rxq->tpa_info[agg_index].mpf = mp;
3591 rxq->tpa_info[agg_index].mpl = NULL;
3592
3593 return;
3594 }
3595
3596 rxq->tpa_info[agg_index].placement_offset = cqe->placement_offset;
3597
3598 if (mpf != NULL) {
3599 mp->m_len = ha->rx_buf_size;
3600 mp->m_next = mpf;
3601 rxq->tpa_info[agg_index].mpf = mp;
3602 rxq->tpa_info[agg_index].mpl = mpl;
3603 } else {
3604 mp->m_len = cqe->len_on_first_bd + cqe->placement_offset;
3605 rxq->tpa_info[agg_index].mpf = mp;
3606 rxq->tpa_info[agg_index].mpl = mp;
3607 mp->m_next = NULL;
3608 }
3609
3610 mp->m_flags |= M_PKTHDR;
3611
3612 /* assign packet to this interface interface */
3613 mp->m_pkthdr.rcvif = ifp;
3614
3615 /* assume no hardware checksum has complated */
3616 mp->m_pkthdr.csum_flags = 0;
3617
3618 //mp->m_pkthdr.flowid = fp->rss_id;
3619 mp->m_pkthdr.flowid = cqe->rss_hash;
3620
3621#if __FreeBSD_version >= 1100000
3622
3623 hash_type = cqe->bitfields &
3624 (ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_MASK <<
3625 ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_SHIFT);
3626
3627 switch (hash_type) {
3628
3629 case RSS_HASH_TYPE_IPV4:
3630 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV4);
3631 break;
3632
3633 case RSS_HASH_TYPE_TCP_IPV4:
3634 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV4);
3635 break;
3636
3637 case RSS_HASH_TYPE_IPV6:
3638 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV6);
3639 break;
3640
3641 case RSS_HASH_TYPE_TCP_IPV6:
3642 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV6);
3643 break;
3644
3645 default:
3646 M_HASHTYPE_SET(mp, M_HASHTYPE_OPAQUE);
3647 break;
3648 }
3649
3650#else
3651 mp->m_flags |= M_FLOWID;
3652#endif
3653
3654 mp->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED | CSUM_IP_VALID |
3655 CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
3656
3657 mp->m_pkthdr.csum_data = 0xFFFF;
3658
3659 if (CQE_HAS_VLAN(cqe->pars_flags.flags)) {
3660 mp->m_pkthdr.ether_vtag = le16toh(cqe->vlan_tag);
3661 mp->m_flags |= M_VLANTAG;
3662 }
3663
3664 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_START;
3665
3666 QL_DPRINT7(ha, "[%d]: 5\n\tagg_state = %d\n\t mpf = %p mpl = %p\n",
3667 fp->rss_id, rxq->tpa_info[agg_index].agg_state,
3668 rxq->tpa_info[agg_index].mpf, rxq->tpa_info[agg_index].mpl);
3669
3670 return;
3671}
3672
3673static void
3674qlnx_tpa_cont(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3675 struct qlnx_rx_queue *rxq,
3676 struct eth_fast_path_rx_tpa_cont_cqe *cqe)
3677{
3678 struct sw_rx_data *sw_rx_data;
3679 int i;
3680 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3681 struct mbuf *mp;
3682 uint32_t agg_index;
3683 device_t dev;
3684
3685 dev = ha->pci_dev;
3686
3687 QL_DPRINT7(ha, "[%d]: enter\n \
3688 \t type = 0x%x\n \
3689 \t tpa_agg_index = 0x%x\n \
3690 \t len_list[0] = 0x%x\n \
3691 \t len_list[1] = 0x%x\n \
3692 \t len_list[2] = 0x%x\n \
3693 \t len_list[3] = 0x%x\n \
3694 \t len_list[4] = 0x%x\n \
3695 \t len_list[5] = 0x%x\n",
3696 fp->rss_id, cqe->type, cqe->tpa_agg_index,
3697 cqe->len_list[0], cqe->len_list[1], cqe->len_list[2],
3698 cqe->len_list[3], cqe->len_list[4], cqe->len_list[5]);
3699
3700 agg_index = cqe->tpa_agg_index;
3701
3702 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3703 QL_DPRINT7(ha, "[%d]: 0\n ", fp->rss_id);
3704 fp->err_rx_tpa_invalid_agg_num++;
3705 return;
3706 }
3707
3708
3709 for (i = 0; i < ETH_TPA_CQE_CONT_LEN_LIST_SIZE; i++) {
3710
3711 QL_DPRINT7(ha, "[%d]: 1\n ", fp->rss_id);
3712
3713 if (cqe->len_list[i] == 0)
3714 break;
3715
3716 if (rxq->tpa_info[agg_index].agg_state !=
3717 QLNX_AGG_STATE_START) {
3718 qlnx_reuse_rx_data(rxq);
3719 continue;
3720 }
3721
3722 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3723 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3724 BUS_DMASYNC_POSTREAD);
3725
3726 mpc = sw_rx_data->data;
3727
3728 if (mpc == NULL) {
3729
3730 QL_DPRINT7(ha, "[%d]: mpc = NULL\n", fp->rss_id);
3731
3732 fp->err_rx_mp_null++;
3733 if (mpf != NULL)
3734 m_freem(mpf);
3735 mpf = mpl = NULL;
3736 rxq->tpa_info[agg_index].agg_state =
3737 QLNX_AGG_STATE_ERROR;
3738 ecore_chain_consume(&rxq->rx_bd_ring);
3739 rxq->sw_rx_cons =
3740 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3741 continue;
3742 }
3743
3744 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3745
3746 QL_DPRINT7(ha, "[%d]: New buffer allocation failed,"
3747 " dropping incoming packet and reusing its"
3748 " buffer\n", fp->rss_id);
3749
3750 qlnx_reuse_rx_data(rxq);
3751
3752 if (mpf != NULL)
3753 m_freem(mpf);
3754 mpf = mpl = NULL;
3755
3756 rxq->tpa_info[agg_index].agg_state =
3757 QLNX_AGG_STATE_ERROR;
3758
3759 ecore_chain_consume(&rxq->rx_bd_ring);
3760 rxq->sw_rx_cons =
3761 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3762
3763 continue;
3764 }
3765
3766 mpc->m_flags &= ~M_PKTHDR;
3767 mpc->m_next = NULL;
3768 mpc->m_len = cqe->len_list[i];
3769
3770
3771 if (mpf == NULL) {
3772 mpf = mpl = mpc;
3773 } else {
3774 mpl->m_len = ha->rx_buf_size;
3775 mpl->m_next = mpc;
3776 mpl = mpc;
3777 }
3778
3779 ecore_chain_consume(&rxq->rx_bd_ring);
3780 rxq->sw_rx_cons =
3781 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3782 }
3783
3784 QL_DPRINT7(ha, "[%d]: 2\n" "\tmpf = %p mpl = %p\n",
3785 fp->rss_id, mpf, mpl);
3786
3787 if (mpf != NULL) {
3788 mp = rxq->tpa_info[agg_index].mpl;
3789 mp->m_len = ha->rx_buf_size;
3790 mp->m_next = mpf;
3791 rxq->tpa_info[agg_index].mpl = mpl;
3792 }
3793
3794 return;
3795}
3796
3797static int
3798qlnx_tpa_end(qlnx_host_t *ha, struct qlnx_fastpath *fp,
3799 struct qlnx_rx_queue *rxq,
3800 struct eth_fast_path_rx_tpa_end_cqe *cqe)
3801{
3802 struct sw_rx_data *sw_rx_data;
3803 int i;
3804 struct mbuf *mpf = NULL, *mpl = NULL, *mpc = NULL;
3805 struct mbuf *mp;
3806 uint32_t agg_index;
3807 uint32_t len = 0;
3808 struct ifnet *ifp = ha->ifp;
3809 device_t dev;
3810
3811 dev = ha->pci_dev;
3812
3813 QL_DPRINT7(ha, "[%d]: enter\n \
3814 \t type = 0x%x\n \
3815 \t tpa_agg_index = 0x%x\n \
3816 \t total_packet_len = 0x%x\n \
3817 \t num_of_bds = 0x%x\n \
3818 \t end_reason = 0x%x\n \
3819 \t num_of_coalesced_segs = 0x%x\n \
3820 \t ts_delta = 0x%x\n \
3821 \t len_list[0] = 0x%x\n \
3822 \t len_list[1] = 0x%x\n \
3823 \t len_list[2] = 0x%x\n \
3824 \t len_list[3] = 0x%x\n",
3825 fp->rss_id, cqe->type, cqe->tpa_agg_index,
3826 cqe->total_packet_len, cqe->num_of_bds,
3827 cqe->end_reason, cqe->num_of_coalesced_segs, cqe->ts_delta,
3828 cqe->len_list[0], cqe->len_list[1], cqe->len_list[2],
3829 cqe->len_list[3]);
3830
3831 agg_index = cqe->tpa_agg_index;
3832
3833 if (agg_index >= ETH_TPA_MAX_AGGS_NUM) {
3834
3835 QL_DPRINT7(ha, "[%d]: 0\n ", fp->rss_id);
3836
3837 fp->err_rx_tpa_invalid_agg_num++;
3838 return (0);
3839 }
3840
3841
3842 for (i = 0; i < ETH_TPA_CQE_END_LEN_LIST_SIZE; i++) {
3843
3844 QL_DPRINT7(ha, "[%d]: 1\n ", fp->rss_id);
3845
3846 if (cqe->len_list[i] == 0)
3847 break;
3848
3849 if (rxq->tpa_info[agg_index].agg_state !=
3850 QLNX_AGG_STATE_START) {
3851
3852 QL_DPRINT7(ha, "[%d]: 2\n ", fp->rss_id);
3853
3854 qlnx_reuse_rx_data(rxq);
3855 continue;
3856 }
3857
3858 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
3859 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
3860 BUS_DMASYNC_POSTREAD);
3861
3862 mpc = sw_rx_data->data;
3863
3864 if (mpc == NULL) {
3865
3866 QL_DPRINT7(ha, "[%d]: mpc = NULL\n", fp->rss_id);
3867
3868 fp->err_rx_mp_null++;
3869 if (mpf != NULL)
3870 m_freem(mpf);
3871 mpf = mpl = NULL;
3872 rxq->tpa_info[agg_index].agg_state =
3873 QLNX_AGG_STATE_ERROR;
3874 ecore_chain_consume(&rxq->rx_bd_ring);
3875 rxq->sw_rx_cons =
3876 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3877 continue;
3878 }
3879
3880 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
3881 QL_DPRINT7(ha, "[%d]: New buffer allocation failed,"
3882 " dropping incoming packet and reusing its"
3883 " buffer\n", fp->rss_id);
3884
3885 qlnx_reuse_rx_data(rxq);
3886
3887 if (mpf != NULL)
3888 m_freem(mpf);
3889 mpf = mpl = NULL;
3890
3891 rxq->tpa_info[agg_index].agg_state =
3892 QLNX_AGG_STATE_ERROR;
3893
3894 ecore_chain_consume(&rxq->rx_bd_ring);
3895 rxq->sw_rx_cons =
3896 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3897
3898 continue;
3899 }
3900
3901 mpc->m_flags &= ~M_PKTHDR;
3902 mpc->m_next = NULL;
3903 mpc->m_len = cqe->len_list[i];
3904
3905
3906 if (mpf == NULL) {
3907 mpf = mpl = mpc;
3908 } else {
3909 mpl->m_len = ha->rx_buf_size;
3910 mpl->m_next = mpc;
3911 mpl = mpc;
3912 }
3913
3914 ecore_chain_consume(&rxq->rx_bd_ring);
3915 rxq->sw_rx_cons =
3916 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
3917 }
3918
3919 QL_DPRINT7(ha, "[%d]: 5\n ", fp->rss_id);
3920
3921 if (mpf != NULL) {
3922
3923 QL_DPRINT7(ha, "[%d]: 6\n ", fp->rss_id);
3924
3925 mp = rxq->tpa_info[agg_index].mpl;
3926 mp->m_len = ha->rx_buf_size;
3927 mp->m_next = mpf;
3928 }
3929
3930 if (rxq->tpa_info[agg_index].agg_state != QLNX_AGG_STATE_START) {
3931
3932 QL_DPRINT7(ha, "[%d]: 7\n ", fp->rss_id);
3933
3934 if (rxq->tpa_info[agg_index].mpf != NULL)
3935 m_freem(rxq->tpa_info[agg_index].mpf);
3936 rxq->tpa_info[agg_index].mpf = NULL;
3937 rxq->tpa_info[agg_index].mpl = NULL;
3938 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_NONE;
3939 return (0);
3940 }
3941
3942 mp = rxq->tpa_info[agg_index].mpf;
3943 m_adj(mp, rxq->tpa_info[agg_index].placement_offset);
3944 mp->m_pkthdr.len = cqe->total_packet_len;
3945
3946 if (mp->m_next == NULL)
3947 mp->m_len = mp->m_pkthdr.len;
3948 else {
3949 /* compute the total packet length */
3950 mpf = mp;
3951 while (mpf != NULL) {
3952 len += mpf->m_len;
3953 mpf = mpf->m_next;
3954 }
3955
3956 if (cqe->total_packet_len > len) {
3957 mpl = rxq->tpa_info[agg_index].mpl;
3958 mpl->m_len += (cqe->total_packet_len - len);
3959 }
3960 }
3961
3962 QLNX_INC_IPACKETS(ifp);
3963 QLNX_INC_IBYTES(ifp, (cqe->total_packet_len));
3964
3965 QL_DPRINT7(ha, "[%d]: 8 csum_data = 0x%x csum_flags = 0x%lx\n \
3966 m_len = 0x%x m_pkthdr_len = 0x%x\n",
3967 fp->rss_id, mp->m_pkthdr.csum_data,
3968 mp->m_pkthdr.csum_flags, mp->m_len, mp->m_pkthdr.len);
3969
3970 (*ifp->if_input)(ifp, mp);
3971
3972 rxq->tpa_info[agg_index].mpf = NULL;
3973 rxq->tpa_info[agg_index].mpl = NULL;
3974 rxq->tpa_info[agg_index].agg_state = QLNX_AGG_STATE_NONE;
3975
3976 return (cqe->num_of_coalesced_segs);
3977}
3978
3979static int
3980qlnx_rx_int(qlnx_host_t *ha, struct qlnx_fastpath *fp, int budget,
3981 int lro_enable)
3982{
3983 uint16_t hw_comp_cons, sw_comp_cons;
3984 int rx_pkt = 0;
3985 struct qlnx_rx_queue *rxq = fp->rxq;
3986 struct ifnet *ifp = ha->ifp;
3987 struct ecore_dev *cdev = &ha->cdev;
3988 struct ecore_hwfn *p_hwfn;
3989
3990#ifdef QLNX_SOFT_LRO
3991 struct lro_ctrl *lro;
3992
3993 lro = &rxq->lro;
3994#endif /* #ifdef QLNX_SOFT_LRO */
3995
3996 hw_comp_cons = le16toh(*rxq->hw_cons_ptr);
3997 sw_comp_cons = ecore_chain_get_cons_idx(&rxq->rx_comp_ring);
3998
3999 p_hwfn = &ha->cdev.hwfns[(fp->rss_id % cdev->num_hwfns)];
4000
4001 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
4002 * / BD in the while-loop before reading hw_comp_cons. If the CQE is
4003 * read before it is written by FW, then FW writes CQE and SB, and then
4004 * the CPU reads the hw_comp_cons, it will use an old CQE.
4005 */
4006
4007 /* Loop to complete all indicated BDs */
4008 while (sw_comp_cons != hw_comp_cons) {
4009 union eth_rx_cqe *cqe;
4010 struct eth_fast_path_rx_reg_cqe *fp_cqe;
4011 struct sw_rx_data *sw_rx_data;
4012 register struct mbuf *mp;
4013 enum eth_rx_cqe_type cqe_type;
4014 uint16_t len, pad, len_on_first_bd;
4015 uint8_t *data;
4016#if __FreeBSD_version >= 1100000
4017 uint8_t hash_type;
4018#endif /* #if __FreeBSD_version >= 1100000 */
4019
4020 /* Get the CQE from the completion ring */
4021 cqe = (union eth_rx_cqe *)
4022 ecore_chain_consume(&rxq->rx_comp_ring);
4023 cqe_type = cqe->fast_path_regular.type;
4024
4025 if (cqe_type == ETH_RX_CQE_TYPE_SLOW_PATH) {
4026 QL_DPRINT3(ha, "Got a slowath CQE\n");
4027
4028 ecore_eth_cqe_completion(p_hwfn,
4029 (struct eth_slow_path_rx_cqe *)cqe);
4030 goto next_cqe;
4031 }
4032
4033 if (cqe_type != ETH_RX_CQE_TYPE_REGULAR) {
4034
4035 switch (cqe_type) {
4036
4037 case ETH_RX_CQE_TYPE_TPA_START:
4038 qlnx_tpa_start(ha, fp, rxq,
4039 &cqe->fast_path_tpa_start);
4040 fp->tpa_start++;
4041 break;
4042
4043 case ETH_RX_CQE_TYPE_TPA_CONT:
4044 qlnx_tpa_cont(ha, fp, rxq,
4045 &cqe->fast_path_tpa_cont);
4046 fp->tpa_cont++;
4047 break;
4048
4049 case ETH_RX_CQE_TYPE_TPA_END:
4050 rx_pkt += qlnx_tpa_end(ha, fp, rxq,
4051 &cqe->fast_path_tpa_end);
4052 fp->tpa_end++;
4053 break;
4054
4055 default:
4056 break;
4057 }
4058
4059 goto next_cqe;
4060 }
4061
4062 /* Get the data from the SW ring */
4063 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_cons];
4064 mp = sw_rx_data->data;
4065
4066 if (mp == NULL) {
4067 QL_DPRINT1(ha, "mp = NULL\n");
4068 fp->err_rx_mp_null++;
4069 rxq->sw_rx_cons =
4070 (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
4071 goto next_cqe;
4072 }
4073 bus_dmamap_sync(ha->rx_tag, sw_rx_data->map,
4074 BUS_DMASYNC_POSTREAD);
4075
4076 /* non GRO */
4077 fp_cqe = &cqe->fast_path_regular;/* MK CR TPA check assembly */
4078 len = le16toh(fp_cqe->pkt_len);
4079 pad = fp_cqe->placement_offset;
4080
4081 QL_DPRINT3(ha, "CQE type = %x, flags = %x, vlan = %x,"
4082 " len %u, parsing flags = %d pad = %d\n",
4083 cqe_type, fp_cqe->bitfields,
4084 le16toh(fp_cqe->vlan_tag),
4085 len, le16toh(fp_cqe->pars_flags.flags), pad);
4086
4087 data = mtod(mp, uint8_t *);
4088 data = data + pad;
4089
4090 if (0)
4091 qlnx_dump_buf8(ha, __func__, data, len);
4092
4093 /* For every Rx BD consumed, we allocate a new BD so the BD ring
4094 * is always with a fixed size. If allocation fails, we take the
4095 * consumed BD and return it to the ring in the PROD position.
4096 * The packet that was received on that BD will be dropped (and
4097 * not passed to the upper stack).
4098 */
4099 /* If this is an error packet then drop it */
4100 if ((le16toh(cqe->fast_path_regular.pars_flags.flags)) &
4101 CQE_FLAGS_ERR) {
4102
4103 QL_DPRINT1(ha, "CQE in CONS = %u has error, flags = %x,"
4104 " dropping incoming packet\n", sw_comp_cons,
4105 le16toh(cqe->fast_path_regular.pars_flags.flags));
4106 fp->err_rx_hw_errors++;
4107
4108 qlnx_reuse_rx_data(rxq);
4109
4110 QLNX_INC_IERRORS(ifp);
4111
4112 goto next_cqe;
4113 }
4114
4115 if (qlnx_alloc_rx_buffer(ha, rxq) != 0) {
4116
4117 QL_DPRINT1(ha, "New buffer allocation failed, dropping"
4118 " incoming packet and reusing its buffer\n");
4119 qlnx_reuse_rx_data(rxq);
4120
4121 fp->err_rx_alloc_errors++;
4122
4123 QLNX_INC_IQDROPS(ifp);
4124
4125 goto next_cqe;
4126 }
4127
4128 ecore_chain_consume(&rxq->rx_bd_ring);
4129
4130 len_on_first_bd = fp_cqe->len_on_first_bd;
4131 m_adj(mp, pad);
4132 mp->m_pkthdr.len = len;
4133
4134 QL_DPRINT1(ha, "len = %d len_on_first_bd = %d\n",
4135 len, len_on_first_bd);
4136 if ((len > 60 ) && (len > len_on_first_bd)) {
4137
4138 mp->m_len = len_on_first_bd;
4139
4140 if (qlnx_rx_jumbo_chain(ha, fp, mp,
4141 (len - len_on_first_bd)) != 0) {
4142
4143 m_freem(mp);
4144
4145 QLNX_INC_IQDROPS(ifp);
4146
4147 goto next_cqe;
4148 }
4149
4150 } else if (len_on_first_bd < len) {
4151 fp->err_rx_jumbo_chain_pkts++;
4152 } else {
4153 mp->m_len = len;
4154 }
4155
4156 mp->m_flags |= M_PKTHDR;
4157
4158 /* assign packet to this interface interface */
4159 mp->m_pkthdr.rcvif = ifp;
4160
4161 /* assume no hardware checksum has complated */
4162 mp->m_pkthdr.csum_flags = 0;
4163
4164 mp->m_pkthdr.flowid = fp_cqe->rss_hash;
4165
4166#if __FreeBSD_version >= 1100000
4167
4168 hash_type = fp_cqe->bitfields &
4169 (ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_MASK <<
4170 ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE_SHIFT);
4171
4172 switch (hash_type) {
4173
4174 case RSS_HASH_TYPE_IPV4:
4175 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV4);
4176 break;
4177
4178 case RSS_HASH_TYPE_TCP_IPV4:
4179 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV4);
4180 break;
4181
4182 case RSS_HASH_TYPE_IPV6:
4183 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_IPV6);
4184 break;
4185
4186 case RSS_HASH_TYPE_TCP_IPV6:
4187 M_HASHTYPE_SET(mp, M_HASHTYPE_RSS_TCP_IPV6);
4188 break;
4189
4190 default:
4191 M_HASHTYPE_SET(mp, M_HASHTYPE_OPAQUE);
4192 break;
4193 }
4194
4195#else
4196 mp->m_flags |= M_FLOWID;
4197#endif
4198
4199 if (CQE_L3_PACKET(fp_cqe->pars_flags.flags)) {
4200 mp->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
4201 }
4202
4203 if (!(CQE_IP_HDR_ERR(fp_cqe->pars_flags.flags))) {
4204 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
4205 }
4206
4207 if (CQE_L4_HAS_CSUM(fp_cqe->pars_flags.flags)) {
4208 mp->m_pkthdr.csum_data = 0xFFFF;
4209 mp->m_pkthdr.csum_flags |=
4210 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
4211 }
4212
4213 if (CQE_HAS_VLAN(fp_cqe->pars_flags.flags)) {
4214 mp->m_pkthdr.ether_vtag = le16toh(fp_cqe->vlan_tag);
4215 mp->m_flags |= M_VLANTAG;
4216 }
4217
4218 QLNX_INC_IPACKETS(ifp);
4219 QLNX_INC_IBYTES(ifp, len);
4220
4221#ifdef QLNX_SOFT_LRO
4222
4223 if (lro_enable) {
4224
4225#if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
4226
4227 tcp_lro_queue_mbuf(lro, mp);
4228
4229#else
4230
4231 if (tcp_lro_rx(lro, mp, 0))
4232 (*ifp->if_input)(ifp, mp);
4233
4234#endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
4235
4236 } else {
4237 (*ifp->if_input)(ifp, mp);
4238 }
4239#else
4240
4241 (*ifp->if_input)(ifp, mp);
4242
4243#endif /* #ifdef QLNX_SOFT_LRO */
4244
4245 rx_pkt++;
4246
4247 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
4248
4249next_cqe: /* don't consume bd rx buffer */
4250 ecore_chain_recycle_consumed(&rxq->rx_comp_ring);
4251 sw_comp_cons = ecore_chain_get_cons_idx(&rxq->rx_comp_ring);
4252
4253 /* CR TPA - revisit how to handle budget in TPA perhaps
4254 increase on "end" */
4255 if (rx_pkt == budget)
4256 break;
4257 } /* repeat while sw_comp_cons != hw_comp_cons... */
4258
4259 /* Update producers */
4260 qlnx_update_rx_prod(p_hwfn, rxq);
4261
4262 return rx_pkt;
4263}
4264
4265/*
4266 * fast path interrupt
4267 */
4268
4269static void
4270qlnx_fp_isr(void *arg)
4271{
4272 qlnx_ivec_t *ivec = arg;
4273 qlnx_host_t *ha;
4274 struct qlnx_fastpath *fp = NULL;
4275 int idx;
4276
4277 ha = ivec->ha;
4278
4279 if (ha->state != QLNX_STATE_OPEN) {
4280 return;
4281 }
4282
4283 idx = ivec->rss_idx;
4284
4285 if ((idx = ivec->rss_idx) >= ha->num_rss) {
4286 QL_DPRINT1(ha, "illegal interrupt[%d]\n", idx);
4287 ha->err_illegal_intr++;
4288 return;
4289 }
4290 fp = &ha->fp_array[idx];
4291
4292 if (fp == NULL) {
4293 ha->err_fp_null++;
4294 } else {
4295 ecore_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0);
4296 if (fp->fp_taskqueue != NULL)
4297 taskqueue_enqueue(fp->fp_taskqueue, &fp->fp_task);
4298 }
4299
4300 return;
4301}
4302
4303
4304/*
4305 * slow path interrupt processing function
4306 * can be invoked in polled mode or in interrupt mode via taskqueue.
4307 */
4308void
4309qlnx_sp_isr(void *arg)
4310{
4311 struct ecore_hwfn *p_hwfn;
4312 qlnx_host_t *ha;
4313
4314 p_hwfn = arg;
4315
4316 ha = (qlnx_host_t *)p_hwfn->p_dev;
4317
4318 ha->sp_interrupts++;
4319
4320 QL_DPRINT2(ha, "enter\n");
4321
4322 ecore_int_sp_dpc(p_hwfn);
4323
4324 QL_DPRINT2(ha, "exit\n");
4325
4326 return;
4327}
4328
4329/*****************************************************************************
4330 * Support Functions for DMA'able Memory
4331 *****************************************************************************/
4332
4333static void
4334qlnx_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
4335{
4336 *((bus_addr_t *)arg) = 0;
4337
4338 if (error) {
4339 printf("%s: bus_dmamap_load failed (%d)\n", __func__, error);
4340 return;
4341 }
4342
4343 *((bus_addr_t *)arg) = segs[0].ds_addr;
4344
4345 return;
4346}
4347
4348static int
4349qlnx_alloc_dmabuf(qlnx_host_t *ha, qlnx_dma_t *dma_buf)
4350{
4351 int ret = 0;
4352 device_t dev;
4353 bus_addr_t b_addr;
4354
4355 dev = ha->pci_dev;
4356
4357 ret = bus_dma_tag_create(
4358 ha->parent_tag,/* parent */
4359 dma_buf->alignment,
4360 ((bus_size_t)(1ULL << 32)),/* boundary */
4361 BUS_SPACE_MAXADDR, /* lowaddr */
4362 BUS_SPACE_MAXADDR, /* highaddr */
4363 NULL, NULL, /* filter, filterarg */
4364 dma_buf->size, /* maxsize */
4365 1, /* nsegments */
4366 dma_buf->size, /* maxsegsize */
4367 0, /* flags */
4368 NULL, NULL, /* lockfunc, lockarg */
4369 &dma_buf->dma_tag);
4370
4371 if (ret) {
4372 QL_DPRINT1(ha, "could not create dma tag\n");
4373 goto qlnx_alloc_dmabuf_exit;
4374 }
4375 ret = bus_dmamem_alloc(dma_buf->dma_tag,
4376 (void **)&dma_buf->dma_b,
4377 (BUS_DMA_ZERO | BUS_DMA_COHERENT | BUS_DMA_NOWAIT),
4378 &dma_buf->dma_map);
4379 if (ret) {
4380 bus_dma_tag_destroy(dma_buf->dma_tag);
4381 QL_DPRINT1(ha, "bus_dmamem_alloc failed\n");
4382 goto qlnx_alloc_dmabuf_exit;
4383 }
4384
4385 ret = bus_dmamap_load(dma_buf->dma_tag,
4386 dma_buf->dma_map,
4387 dma_buf->dma_b,
4388 dma_buf->size,
4389 qlnx_dmamap_callback,
4390 &b_addr, BUS_DMA_NOWAIT);
4391
4392 if (ret || !b_addr) {
4393 bus_dma_tag_destroy(dma_buf->dma_tag);
4394 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b,
4395 dma_buf->dma_map);
4396 ret = -1;
4397 goto qlnx_alloc_dmabuf_exit;
4398 }
4399
4400 dma_buf->dma_addr = b_addr;
4401
4402qlnx_alloc_dmabuf_exit:
4403
4404 return ret;
4405}
4406
4407static void
4408qlnx_free_dmabuf(qlnx_host_t *ha, qlnx_dma_t *dma_buf)
4409{
4410 bus_dmamap_unload(dma_buf->dma_tag, dma_buf->dma_map);
4411 bus_dmamem_free(dma_buf->dma_tag, dma_buf->dma_b, dma_buf->dma_map);
4412 bus_dma_tag_destroy(dma_buf->dma_tag);
4413 return;
4414}
4415
4416void *
4417qlnx_dma_alloc_coherent(void *ecore_dev, bus_addr_t *phys, uint32_t size)
4418{
4419 qlnx_dma_t dma_buf;
4420 qlnx_dma_t *dma_p;
4421 qlnx_host_t *ha;
4422 device_t dev;
4423
4424 ha = (qlnx_host_t *)ecore_dev;
4425 dev = ha->pci_dev;
4426
4427 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4428
4429 memset(&dma_buf, 0, sizeof (qlnx_dma_t));
4430
4431 dma_buf.size = size + PAGE_SIZE;
4432 dma_buf.alignment = 8;
4433
4434 if (qlnx_alloc_dmabuf((qlnx_host_t *)ecore_dev, &dma_buf) != 0)
4435 return (NULL);
4436 bzero((uint8_t *)dma_buf.dma_b, dma_buf.size);
4437
4438 *phys = dma_buf.dma_addr;
4439
4440 dma_p = (qlnx_dma_t *)((uint8_t *)dma_buf.dma_b + size);
4441
4442 memcpy(dma_p, &dma_buf, sizeof(qlnx_dma_t));
4443/*
4444 QL_DPRINT5(ha, "[%p %p %p %p 0x%08x ]\n",
4445 (void *)dma_buf.dma_map, (void *)dma_buf.dma_tag,
4446 dma_buf.dma_b, (void *)dma_buf.dma_addr, size);
4447*/
4448 return (dma_buf.dma_b);
4449}
4450
4451void
4452qlnx_dma_free_coherent(void *ecore_dev, void *v_addr, bus_addr_t phys,
4453 uint32_t size)
4454{
4455 qlnx_dma_t dma_buf, *dma_p;
4456 qlnx_host_t *ha;
4457 device_t dev;
4458
4459 ha = (qlnx_host_t *)ecore_dev;
4460 dev = ha->pci_dev;
4461
4462 if (v_addr == NULL)
4463 return;
4464
4465 size = (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4466
4467 dma_p = (qlnx_dma_t *)((uint8_t *)v_addr + size);
4468/*
4469 QL_DPRINT5(ha, "[%p %p %p %p 0x%08x ]\n",
4470 (void *)dma_p->dma_map, (void *)dma_p->dma_tag,
4471 dma_p->dma_b, (void *)dma_p->dma_addr, size);
4472*/
4473 dma_buf = *dma_p;
4474
4475 qlnx_free_dmabuf((qlnx_host_t *)ecore_dev, &dma_buf);
4476 return;
4477}
4478
4479static int
4480qlnx_alloc_parent_dma_tag(qlnx_host_t *ha)
4481{
4482 int ret;
4483 device_t dev;
4484
4485 dev = ha->pci_dev;
4486
4487 /*
4488 * Allocate parent DMA Tag
4489 */
4490 ret = bus_dma_tag_create(
4491 bus_get_dma_tag(dev), /* parent */
4492 1,((bus_size_t)(1ULL << 32)),/* alignment, boundary */
4493 BUS_SPACE_MAXADDR, /* lowaddr */
4494 BUS_SPACE_MAXADDR, /* highaddr */
4495 NULL, NULL, /* filter, filterarg */
4496 BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
4497 0, /* nsegments */
4498 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
4499 0, /* flags */
4500 NULL, NULL, /* lockfunc, lockarg */
4501 &ha->parent_tag);
4502
4503 if (ret) {
4504 QL_DPRINT1(ha, "could not create parent dma tag\n");
4505 return (-1);
4506 }
4507
4508 ha->flags.parent_tag = 1;
4509
4510 return (0);
4511}
4512
4513static void
4514qlnx_free_parent_dma_tag(qlnx_host_t *ha)
4515{
4516 if (ha->parent_tag != NULL) {
4517 bus_dma_tag_destroy(ha->parent_tag);
4518 ha->parent_tag = NULL;
4519 }
4520 return;
4521}
4522
4523static int
4524qlnx_alloc_tx_dma_tag(qlnx_host_t *ha)
4525{
4526 if (bus_dma_tag_create(NULL, /* parent */
4527 1, 0, /* alignment, bounds */
4528 BUS_SPACE_MAXADDR, /* lowaddr */
4529 BUS_SPACE_MAXADDR, /* highaddr */
4530 NULL, NULL, /* filter, filterarg */
4531 QLNX_MAX_TSO_FRAME_SIZE, /* maxsize */
4532 QLNX_MAX_SEGMENTS, /* nsegments */
4533 (PAGE_SIZE * 4), /* maxsegsize */
4534 BUS_DMA_ALLOCNOW, /* flags */
4535 NULL, /* lockfunc */
4536 NULL, /* lockfuncarg */
4537 &ha->tx_tag)) {
4538
4539 QL_DPRINT1(ha, "tx_tag alloc failed\n");
4540 return (-1);
4541 }
4542
4543 return (0);
4544}
4545
4546static void
4547qlnx_free_tx_dma_tag(qlnx_host_t *ha)
4548{
4549 if (ha->tx_tag != NULL) {
4550 bus_dma_tag_destroy(ha->tx_tag);
4551 ha->tx_tag = NULL;
4552 }
4553 return;
4554}
4555
4556static int
4557qlnx_alloc_rx_dma_tag(qlnx_host_t *ha)
4558{
4559 if (bus_dma_tag_create(NULL, /* parent */
4560 1, 0, /* alignment, bounds */
4561 BUS_SPACE_MAXADDR, /* lowaddr */
4562 BUS_SPACE_MAXADDR, /* highaddr */
4563 NULL, NULL, /* filter, filterarg */
4564 MJUM9BYTES, /* maxsize */
4565 1, /* nsegments */
4566 MJUM9BYTES, /* maxsegsize */
4567 BUS_DMA_ALLOCNOW, /* flags */
4568 NULL, /* lockfunc */
4569 NULL, /* lockfuncarg */
4570 &ha->rx_tag)) {
4571
4572 QL_DPRINT1(ha, " rx_tag alloc failed\n");
4573
4574 return (-1);
4575 }
4576 return (0);
4577}
4578
4579static void
4580qlnx_free_rx_dma_tag(qlnx_host_t *ha)
4581{
4582 if (ha->rx_tag != NULL) {
4583 bus_dma_tag_destroy(ha->rx_tag);
4584 ha->rx_tag = NULL;
4585 }
4586 return;
4587}
4588
4589/*********************************
4590 * Exported functions
4591 *********************************/
4592uint32_t
4593qlnx_pci_bus_get_bar_size(void *ecore_dev, uint8_t bar_id)
4594{
4595 uint32_t bar_size;
4596
4597 bar_id = bar_id * 2;
4598
4599 bar_size = bus_get_resource_count(((qlnx_host_t *)ecore_dev)->pci_dev,
4600 SYS_RES_MEMORY,
4601 PCIR_BAR(bar_id));
4602
4603 return (bar_size);
4604}
4605
4606uint32_t
4607qlnx_pci_read_config_byte(void *ecore_dev, uint32_t pci_reg, uint8_t *reg_value)
4608{
4609 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4610 pci_reg, 1);
4611 return 0;
4612}
4613
4614uint32_t
4615qlnx_pci_read_config_word(void *ecore_dev, uint32_t pci_reg,
4616 uint16_t *reg_value)
4617{
4618 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4619 pci_reg, 2);
4620 return 0;
4621}
4622
4623uint32_t
4624qlnx_pci_read_config_dword(void *ecore_dev, uint32_t pci_reg,
4625 uint32_t *reg_value)
4626{
4627 *reg_value = pci_read_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4628 pci_reg, 4);
4629 return 0;
4630}
4631
4632void
4633qlnx_pci_write_config_byte(void *ecore_dev, uint32_t pci_reg, uint8_t reg_value)
4634{
4635 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4636 pci_reg, reg_value, 1);
4637 return;
4638}
4639
4640void
4641qlnx_pci_write_config_word(void *ecore_dev, uint32_t pci_reg,
4642 uint16_t reg_value)
4643{
4644 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4645 pci_reg, reg_value, 2);
4646 return;
4647}
4648
4649void
4650qlnx_pci_write_config_dword(void *ecore_dev, uint32_t pci_reg,
4651 uint32_t reg_value)
4652{
4653 pci_write_config(((qlnx_host_t *)ecore_dev)->pci_dev,
4654 pci_reg, reg_value, 4);
4655 return;
4656}
4657
4658
4659int
4660qlnx_pci_find_capability(void *ecore_dev, int cap)
4661{
4662 int reg;
4663 qlnx_host_t *ha;
4664
4665 ha = ecore_dev;
4666
4667 if (pci_find_cap(ha->pci_dev, PCIY_EXPRESS, &reg) == 0)
4668 return reg;
4669 else {
4670 QL_DPRINT1(ha, "failed\n");
4671 return 0;
4672 }
4673}
4674
4675uint32_t
4676qlnx_reg_rd32(void *hwfn, uint32_t reg_addr)
4677{
4678 uint32_t data32;
4679 struct ecore_dev *cdev;
4680 struct ecore_hwfn *p_hwfn;
4681
4682 p_hwfn = hwfn;
4683
4684 cdev = p_hwfn->p_dev;
4685
4686 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4687 (uint8_t *)(cdev->regview)) + reg_addr;
4688
4689 data32 = bus_read_4(((qlnx_host_t *)cdev)->pci_reg, reg_addr);
4690
4691 return (data32);
4692}
4693
4694void
4695qlnx_reg_wr32(void *hwfn, uint32_t reg_addr, uint32_t value)
4696{
4697 struct ecore_dev *cdev;
4698 struct ecore_hwfn *p_hwfn;
4699
4700 p_hwfn = hwfn;
4701
4702 cdev = p_hwfn->p_dev;
4703
4704 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4705 (uint8_t *)(cdev->regview)) + reg_addr;
4706
4707 bus_write_4(((qlnx_host_t *)cdev)->pci_reg, reg_addr, value);
4708
4709 return;
4710}
4711
4712void
4713qlnx_reg_wr16(void *hwfn, uint32_t reg_addr, uint16_t value)
4714{
4715 struct ecore_dev *cdev;
4716 struct ecore_hwfn *p_hwfn;
4717
4718 p_hwfn = hwfn;
4719
4720 cdev = p_hwfn->p_dev;
4721
4722 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->regview) -
4723 (uint8_t *)(cdev->regview)) + reg_addr;
4724
4725 bus_write_2(((qlnx_host_t *)cdev)->pci_reg, reg_addr, value);
4726
4727 return;
4728}
4729
4730void
4731qlnx_dbell_wr32(void *hwfn, uint32_t reg_addr, uint32_t value)
4732{
4733 struct ecore_dev *cdev;
4734 struct ecore_hwfn *p_hwfn;
4735
4736 p_hwfn = hwfn;
4737
4738 cdev = p_hwfn->p_dev;
4739
4740 reg_addr = (uint32_t)((uint8_t *)(p_hwfn->doorbells) -
4741 (uint8_t *)(cdev->doorbells)) + reg_addr;
4742
4743 bus_write_4(((qlnx_host_t *)cdev)->pci_dbells, reg_addr, value);
4744
4745 return;
4746}
4747
4748uint32_t
4749qlnx_direct_reg_rd32(void *p_hwfn, uint32_t *reg_addr)
4750{
4751 uint32_t data32;
4752 uint32_t offset;
4753 struct ecore_dev *cdev;
4754
4755 cdev = ((struct ecore_hwfn *)p_hwfn)->p_dev;
4756 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)(cdev->regview));
4757
4758 data32 = bus_read_4(((qlnx_host_t *)cdev)->pci_reg, offset);
4759
4760 return (data32);
4761}
4762
4763void
4764qlnx_direct_reg_wr32(void *p_hwfn, void *reg_addr, uint32_t value)
4765{
4766 uint32_t offset;
4767 struct ecore_dev *cdev;
4768
4769 cdev = ((struct ecore_hwfn *)p_hwfn)->p_dev;
4770 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)(cdev->regview));
4771
4772 bus_write_4(((qlnx_host_t *)cdev)->pci_reg, offset, value);
4773
4774 return;
4775}
4776
4777void
4778qlnx_direct_reg_wr64(void *p_hwfn, void *reg_addr, uint64_t value)
4779{
4780 uint32_t offset;
4781 struct ecore_dev *cdev;
4782
4783 cdev = ((struct ecore_hwfn *)p_hwfn)->p_dev;
4784 offset = (uint32_t)((uint8_t *)reg_addr - (uint8_t *)(cdev->regview));
4785
4786 bus_write_8(((qlnx_host_t *)cdev)->pci_reg, offset, value);
4787 return;
4788}
4789
4751void *
4752qlnx_zalloc(uint32_t size)
4753{
4754 caddr_t va;
4755
4756 va = malloc((unsigned long)size, M_QLNXBUF, M_NOWAIT);
4757 bzero(va, size);
4758 return ((void *)va);
4759}
4760
4761void
4762qlnx_barrier(void *p_hwfn)
4763{
4764 qlnx_host_t *ha;
4765
4766 ha = (qlnx_host_t *)((struct ecore_hwfn *)p_hwfn)->p_dev;
4767 bus_barrier(ha->pci_reg, 0, 0, BUS_SPACE_BARRIER_WRITE);
4768}
4769
4770void
4771qlnx_link_update(void *p_hwfn)
4772{
4773 qlnx_host_t *ha;
4774 int prev_link_state;
4775
4776 ha = (qlnx_host_t *)((struct ecore_hwfn *)p_hwfn)->p_dev;
4777
4778 qlnx_fill_link(p_hwfn, &ha->if_link);
4779
4780 prev_link_state = ha->link_up;
4781 ha->link_up = ha->if_link.link_up;
4782
4783 if (prev_link_state != ha->link_up) {
4784 if (ha->link_up) {
4785 if_link_state_change(ha->ifp, LINK_STATE_UP);
4786 } else {
4787 if_link_state_change(ha->ifp, LINK_STATE_DOWN);
4788 }
4789 }
4790 return;
4791}
4792
4793void
4794qlnx_fill_link(struct ecore_hwfn *hwfn, struct qlnx_link_output *if_link)
4795{
4796 struct ecore_mcp_link_params link_params;
4797 struct ecore_mcp_link_state link_state;
4798
4799 memset(if_link, 0, sizeof(*if_link));
4800 memset(&link_params, 0, sizeof(struct ecore_mcp_link_params));
4801 memset(&link_state, 0, sizeof(struct ecore_mcp_link_state));
4802
4803 /* Prepare source inputs */
4804 /* we only deal with physical functions */
4805 memcpy(&link_params, ecore_mcp_get_link_params(hwfn),
4806 sizeof(link_params));
4807 memcpy(&link_state, ecore_mcp_get_link_state(hwfn),
4808 sizeof(link_state));
4809
4810 ecore_mcp_get_media_type(hwfn->p_dev, &if_link->media_type);
4811
4812 /* Set the link parameters to pass to protocol driver */
4813 if (link_state.link_up) {
4814 if_link->link_up = true;
4815 if_link->speed = link_state.speed;
4816 }
4817
4818 if_link->supported_caps = QLNX_LINK_CAP_FIBRE;
4819
4820 if (link_params.speed.autoneg)
4821 if_link->supported_caps |= QLNX_LINK_CAP_Autoneg;
4822
4823 if (link_params.pause.autoneg ||
4824 (link_params.pause.forced_rx && link_params.pause.forced_tx))
4825 if_link->supported_caps |= QLNX_LINK_CAP_Asym_Pause;
4826
4827 if (link_params.pause.autoneg || link_params.pause.forced_rx ||
4828 link_params.pause.forced_tx)
4829 if_link->supported_caps |= QLNX_LINK_CAP_Pause;
4830
4831 if (link_params.speed.advertised_speeds &
4832 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
4833 if_link->supported_caps |= QLNX_LINK_CAP_1000baseT_Half |
4834 QLNX_LINK_CAP_1000baseT_Full;
4835
4836 if (link_params.speed.advertised_speeds &
4837 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
4838 if_link->supported_caps |= QLNX_LINK_CAP_10000baseKR_Full;
4839
4840 if (link_params.speed.advertised_speeds &
4841 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
4842 if_link->supported_caps |= QLNX_LINK_CAP_25000baseKR_Full;
4843
4844 if (link_params.speed.advertised_speeds &
4845 NVM_CFG1_PORT_DRV_LINK_SPEED_40G)
4846 if_link->supported_caps |= QLNX_LINK_CAP_40000baseLR4_Full;
4847
4848 if (link_params.speed.advertised_speeds &
4849 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
4850 if_link->supported_caps |= QLNX_LINK_CAP_50000baseKR2_Full;
4851
4852 if (link_params.speed.advertised_speeds &
4853 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
4854 if_link->supported_caps |= QLNX_LINK_CAP_100000baseKR4_Full;
4855
4856 if_link->advertised_caps = if_link->supported_caps;
4857
4858 if_link->autoneg = link_params.speed.autoneg;
4859 if_link->duplex = QLNX_LINK_DUPLEX;
4860
4861 /* Link partner capabilities */
4862
4863 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_1G_HD)
4864 if_link->link_partner_caps |= QLNX_LINK_CAP_1000baseT_Half;
4865
4866 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_1G_FD)
4867 if_link->link_partner_caps |= QLNX_LINK_CAP_1000baseT_Full;
4868
4869 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_10G)
4870 if_link->link_partner_caps |= QLNX_LINK_CAP_10000baseKR_Full;
4871
4872 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_25G)
4873 if_link->link_partner_caps |= QLNX_LINK_CAP_25000baseKR_Full;
4874
4875 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_40G)
4876 if_link->link_partner_caps |= QLNX_LINK_CAP_40000baseLR4_Full;
4877
4878 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_50G)
4879 if_link->link_partner_caps |= QLNX_LINK_CAP_50000baseKR2_Full;
4880
4881 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_100G)
4882 if_link->link_partner_caps |= QLNX_LINK_CAP_100000baseKR4_Full;
4883
4884 if (link_state.an_complete)
4885 if_link->link_partner_caps |= QLNX_LINK_CAP_Autoneg;
4886
4887 if (link_state.partner_adv_pause)
4888 if_link->link_partner_caps |= QLNX_LINK_CAP_Pause;
4889
4890 if ((link_state.partner_adv_pause ==
4891 ECORE_LINK_PARTNER_ASYMMETRIC_PAUSE) ||
4892 (link_state.partner_adv_pause ==
4893 ECORE_LINK_PARTNER_BOTH_PAUSE))
4894 if_link->link_partner_caps |= QLNX_LINK_CAP_Asym_Pause;
4895
4896 return;
4897}
4898
4899static int
4900qlnx_nic_setup(struct ecore_dev *cdev, struct ecore_pf_params *func_params)
4901{
4902 int rc, i;
4903
4904 for (i = 0; i < cdev->num_hwfns; i++) {
4905 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
4906 p_hwfn->pf_params = *func_params;
4907 }
4908
4909 rc = ecore_resc_alloc(cdev);
4910 if (rc)
4911 goto qlnx_nic_setup_exit;
4912
4913 ecore_resc_setup(cdev);
4914
4915qlnx_nic_setup_exit:
4916
4917 return rc;
4918}
4919
4920static int
4921qlnx_nic_start(struct ecore_dev *cdev)
4922{
4923 int rc;
4924 struct ecore_hw_init_params params;
4925
4926 bzero(&params, sizeof (struct ecore_hw_init_params));
4927
4928 params.p_tunn = NULL;
4929 params.b_hw_start = true;
4930 params.int_mode = cdev->int_mode;
4931 params.allow_npar_tx_switch = true;
4932 params.bin_fw_data = NULL;
4933
4934 rc = ecore_hw_init(cdev, &params);
4935 if (rc) {
4936 ecore_resc_free(cdev);
4937 return rc;
4938 }
4939
4940 return 0;
4941}
4942
4943static int
4944qlnx_slowpath_start(qlnx_host_t *ha)
4945{
4946 struct ecore_dev *cdev;
4947 struct ecore_pf_params pf_params;
4948 int rc;
4949
4950 memset(&pf_params, 0, sizeof(struct ecore_pf_params));
4951 pf_params.eth_pf_params.num_cons =
4952 (ha->num_rss) * (ha->num_tc + 1);
4953
4954 cdev = &ha->cdev;
4955
4956 rc = qlnx_nic_setup(cdev, &pf_params);
4957 if (rc)
4958 goto qlnx_slowpath_start_exit;
4959
4960 cdev->int_mode = ECORE_INT_MODE_MSIX;
4961 cdev->int_coalescing_mode = ECORE_COAL_MODE_ENABLE;
4962
4963#ifdef QLNX_MAX_COALESCE
4964 cdev->rx_coalesce_usecs = 255;
4965 cdev->tx_coalesce_usecs = 255;
4966#endif
4967
4968 rc = qlnx_nic_start(cdev);
4969
4970 ha->rx_coalesce_usecs = cdev->rx_coalesce_usecs;
4971 ha->tx_coalesce_usecs = cdev->tx_coalesce_usecs;
4972
4973qlnx_slowpath_start_exit:
4974
4975 return (rc);
4976}
4977
4978static int
4979qlnx_slowpath_stop(qlnx_host_t *ha)
4980{
4981 struct ecore_dev *cdev;
4982 device_t dev = ha->pci_dev;
4983 int i;
4984
4985 cdev = &ha->cdev;
4986
4987 ecore_hw_stop(cdev);
4988
4989 for (i = 0; i < ha->cdev.num_hwfns; i++) {
4990
4991 if (ha->sp_handle[i])
4992 (void)bus_teardown_intr(dev, ha->sp_irq[i],
4993 ha->sp_handle[i]);
4994
4995 ha->sp_handle[i] = NULL;
4996
4997 if (ha->sp_irq[i])
4998 (void) bus_release_resource(dev, SYS_RES_IRQ,
4999 ha->sp_irq_rid[i], ha->sp_irq[i]);
5000 ha->sp_irq[i] = NULL;
5001 }
5002
5003 ecore_resc_free(cdev);
5004
5005 return 0;
5006}
5007
5008static void
5009qlnx_set_id(struct ecore_dev *cdev, char name[NAME_SIZE],
5010 char ver_str[VER_SIZE])
5011{
5012 int i;
5013
5014 memcpy(cdev->name, name, NAME_SIZE);
5015
5016 for_each_hwfn(cdev, i) {
5017 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
5018 }
5019
5020 cdev->drv_type = DRV_ID_DRV_TYPE_FREEBSD;
5021
5022 return ;
5023}
5024
5025void
5026qlnx_get_protocol_stats(void *cdev, int proto_type, void *proto_stats)
5027{
5028 enum ecore_mcp_protocol_type type;
5029 union ecore_mcp_protocol_stats *stats;
5030 struct ecore_eth_stats eth_stats;
5031 qlnx_host_t *ha;
5032
5033 ha = cdev;
5034 stats = proto_stats;
5035 type = proto_type;
5036
5037 switch (type) {
5038
5039 case ECORE_MCP_LAN_STATS:
5040 ecore_get_vport_stats((struct ecore_dev *)cdev, &eth_stats);
5041 stats->lan_stats.ucast_rx_pkts = eth_stats.common.rx_ucast_pkts;
5042 stats->lan_stats.ucast_tx_pkts = eth_stats.common.tx_ucast_pkts;
5043 stats->lan_stats.fcs_err = -1;
5044 break;
5045
5046 default:
5047 ha->err_get_proto_invalid_type++;
5048
5049 QL_DPRINT1(ha, "invalid protocol type 0x%x\n", type);
5050 break;
5051 }
5052 return;
5053}
5054
5055static int
5056qlnx_get_mfw_version(qlnx_host_t *ha, uint32_t *mfw_ver)
5057{
5058 struct ecore_hwfn *p_hwfn;
5059 struct ecore_ptt *p_ptt;
5060
5061 p_hwfn = &ha->cdev.hwfns[0];
5062 p_ptt = ecore_ptt_acquire(p_hwfn);
5063
5064 if (p_ptt == NULL) {
5065 QL_DPRINT1(ha, "ecore_ptt_acquire failed\n");
5066 return (-1);
5067 }
5068 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, mfw_ver, NULL);
5069
5070 ecore_ptt_release(p_hwfn, p_ptt);
5071
5072 return (0);
5073}
5074
5075static int
5076qlnx_get_flash_size(qlnx_host_t *ha, uint32_t *flash_size)
5077{
5078 struct ecore_hwfn *p_hwfn;
5079 struct ecore_ptt *p_ptt;
5080
5081 p_hwfn = &ha->cdev.hwfns[0];
5082 p_ptt = ecore_ptt_acquire(p_hwfn);
5083
5084 if (p_ptt == NULL) {
5085 QL_DPRINT1(ha,"ecore_ptt_acquire failed\n");
5086 return (-1);
5087 }
5088 ecore_mcp_get_flash_size(p_hwfn, p_ptt, flash_size);
5089
5090 ecore_ptt_release(p_hwfn, p_ptt);
5091
5092 return (0);
5093}
5094
5095static int
5096qlnx_alloc_mem_arrays(qlnx_host_t *ha)
5097{
5098 struct ecore_dev *cdev;
5099
5100 cdev = &ha->cdev;
5101
5102 bzero(&ha->txq_array[0], (sizeof(struct qlnx_tx_queue) * QLNX_MAX_RSS));
5103 bzero(&ha->rxq_array[0], (sizeof(struct qlnx_rx_queue) * QLNX_MAX_RSS));
5104 bzero(&ha->sb_array[0], (sizeof(struct ecore_sb_info) * QLNX_MAX_RSS));
5105
5106 return 0;
5107}
5108
5109static void
5110qlnx_init_fp(qlnx_host_t *ha)
5111{
5112 int rss_id, txq_array_index, tc;
5113
5114 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
5115
5116 struct qlnx_fastpath *fp = &ha->fp_array[rss_id];
5117
5118 fp->rss_id = rss_id;
5119 fp->edev = ha;
5120 fp->sb_info = &ha->sb_array[rss_id];
5121 fp->rxq = &ha->rxq_array[rss_id];
5122 fp->rxq->rxq_id = rss_id;
5123
5124 for (tc = 0; tc < ha->num_tc; tc++) {
5125 txq_array_index = tc * ha->num_rss + rss_id;
5126 fp->txq[tc] = &ha->txq_array[txq_array_index];
5127 fp->txq[tc]->index = txq_array_index;
5128 }
5129
5130 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d", qlnx_name_str,
5131 rss_id);
5132
5133 fp->tx_ring_full = 0;
5134
5135 /* reset all the statistics counters */
5136
5137 fp->tx_pkts_processed = 0;
5138 fp->tx_pkts_freed = 0;
5139 fp->tx_pkts_transmitted = 0;
5140 fp->tx_pkts_completed = 0;
5141 fp->tx_lso_wnd_min_len = 0;
5142 fp->tx_defrag = 0;
5143 fp->tx_nsegs_gt_elem_left = 0;
5144 fp->tx_tso_max_nsegs = 0;
5145 fp->tx_tso_min_nsegs = 0;
5146 fp->err_tx_nsegs_gt_elem_left = 0;
5147 fp->err_tx_dmamap_create = 0;
5148 fp->err_tx_defrag_dmamap_load = 0;
5149 fp->err_tx_non_tso_max_seg = 0;
5150 fp->err_tx_dmamap_load = 0;
5151 fp->err_tx_defrag = 0;
5152 fp->err_tx_free_pkt_null = 0;
5153 fp->err_tx_cons_idx_conflict = 0;
5154
5155 fp->rx_pkts = 0;
5156 fp->err_m_getcl = 0;
5157 fp->err_m_getjcl = 0;
5158 }
5159 return;
5160}
5161
5162static void
5163qlnx_free_mem_sb(qlnx_host_t *ha, struct ecore_sb_info *sb_info)
5164{
5165 struct ecore_dev *cdev;
5166
5167 cdev = &ha->cdev;
5168
5169 if (sb_info->sb_virt) {
5170 OSAL_DMA_FREE_COHERENT(cdev, ((void *)sb_info->sb_virt),
5171 (sb_info->sb_phys), (sizeof(*sb_info->sb_virt)));
5172 sb_info->sb_virt = NULL;
5173 }
5174}
5175
5176static int
5177qlnx_sb_init(struct ecore_dev *cdev, struct ecore_sb_info *sb_info,
5178 void *sb_virt_addr, bus_addr_t sb_phy_addr, u16 sb_id)
5179{
5180 struct ecore_hwfn *p_hwfn;
5181 int hwfn_index, rc;
5182 u16 rel_sb_id;
5183
5184 hwfn_index = sb_id % cdev->num_hwfns;
5185 p_hwfn = &cdev->hwfns[hwfn_index];
5186 rel_sb_id = sb_id / cdev->num_hwfns;
5187
5188 QL_DPRINT2(((qlnx_host_t *)cdev),
5189 "hwfn_index = %d p_hwfn = %p sb_id = 0x%x rel_sb_id = 0x%x \
5190 sb_info = %p sb_virt_addr = %p sb_phy_addr = %p\n",
5191 hwfn_index, p_hwfn, sb_id, rel_sb_id, sb_info,
5192 sb_virt_addr, (void *)sb_phy_addr);
5193
5194 rc = ecore_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
5195 sb_virt_addr, sb_phy_addr, rel_sb_id);
5196
5197 return rc;
5198}
5199
5200/* This function allocates fast-path status block memory */
5201static int
5202qlnx_alloc_mem_sb(qlnx_host_t *ha, struct ecore_sb_info *sb_info, u16 sb_id)
5203{
4790void *
4791qlnx_zalloc(uint32_t size)
4792{
4793 caddr_t va;
4794
4795 va = malloc((unsigned long)size, M_QLNXBUF, M_NOWAIT);
4796 bzero(va, size);
4797 return ((void *)va);
4798}
4799
4800void
4801qlnx_barrier(void *p_hwfn)
4802{
4803 qlnx_host_t *ha;
4804
4805 ha = (qlnx_host_t *)((struct ecore_hwfn *)p_hwfn)->p_dev;
4806 bus_barrier(ha->pci_reg, 0, 0, BUS_SPACE_BARRIER_WRITE);
4807}
4808
4809void
4810qlnx_link_update(void *p_hwfn)
4811{
4812 qlnx_host_t *ha;
4813 int prev_link_state;
4814
4815 ha = (qlnx_host_t *)((struct ecore_hwfn *)p_hwfn)->p_dev;
4816
4817 qlnx_fill_link(p_hwfn, &ha->if_link);
4818
4819 prev_link_state = ha->link_up;
4820 ha->link_up = ha->if_link.link_up;
4821
4822 if (prev_link_state != ha->link_up) {
4823 if (ha->link_up) {
4824 if_link_state_change(ha->ifp, LINK_STATE_UP);
4825 } else {
4826 if_link_state_change(ha->ifp, LINK_STATE_DOWN);
4827 }
4828 }
4829 return;
4830}
4831
4832void
4833qlnx_fill_link(struct ecore_hwfn *hwfn, struct qlnx_link_output *if_link)
4834{
4835 struct ecore_mcp_link_params link_params;
4836 struct ecore_mcp_link_state link_state;
4837
4838 memset(if_link, 0, sizeof(*if_link));
4839 memset(&link_params, 0, sizeof(struct ecore_mcp_link_params));
4840 memset(&link_state, 0, sizeof(struct ecore_mcp_link_state));
4841
4842 /* Prepare source inputs */
4843 /* we only deal with physical functions */
4844 memcpy(&link_params, ecore_mcp_get_link_params(hwfn),
4845 sizeof(link_params));
4846 memcpy(&link_state, ecore_mcp_get_link_state(hwfn),
4847 sizeof(link_state));
4848
4849 ecore_mcp_get_media_type(hwfn->p_dev, &if_link->media_type);
4850
4851 /* Set the link parameters to pass to protocol driver */
4852 if (link_state.link_up) {
4853 if_link->link_up = true;
4854 if_link->speed = link_state.speed;
4855 }
4856
4857 if_link->supported_caps = QLNX_LINK_CAP_FIBRE;
4858
4859 if (link_params.speed.autoneg)
4860 if_link->supported_caps |= QLNX_LINK_CAP_Autoneg;
4861
4862 if (link_params.pause.autoneg ||
4863 (link_params.pause.forced_rx && link_params.pause.forced_tx))
4864 if_link->supported_caps |= QLNX_LINK_CAP_Asym_Pause;
4865
4866 if (link_params.pause.autoneg || link_params.pause.forced_rx ||
4867 link_params.pause.forced_tx)
4868 if_link->supported_caps |= QLNX_LINK_CAP_Pause;
4869
4870 if (link_params.speed.advertised_speeds &
4871 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
4872 if_link->supported_caps |= QLNX_LINK_CAP_1000baseT_Half |
4873 QLNX_LINK_CAP_1000baseT_Full;
4874
4875 if (link_params.speed.advertised_speeds &
4876 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
4877 if_link->supported_caps |= QLNX_LINK_CAP_10000baseKR_Full;
4878
4879 if (link_params.speed.advertised_speeds &
4880 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
4881 if_link->supported_caps |= QLNX_LINK_CAP_25000baseKR_Full;
4882
4883 if (link_params.speed.advertised_speeds &
4884 NVM_CFG1_PORT_DRV_LINK_SPEED_40G)
4885 if_link->supported_caps |= QLNX_LINK_CAP_40000baseLR4_Full;
4886
4887 if (link_params.speed.advertised_speeds &
4888 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
4889 if_link->supported_caps |= QLNX_LINK_CAP_50000baseKR2_Full;
4890
4891 if (link_params.speed.advertised_speeds &
4892 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
4893 if_link->supported_caps |= QLNX_LINK_CAP_100000baseKR4_Full;
4894
4895 if_link->advertised_caps = if_link->supported_caps;
4896
4897 if_link->autoneg = link_params.speed.autoneg;
4898 if_link->duplex = QLNX_LINK_DUPLEX;
4899
4900 /* Link partner capabilities */
4901
4902 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_1G_HD)
4903 if_link->link_partner_caps |= QLNX_LINK_CAP_1000baseT_Half;
4904
4905 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_1G_FD)
4906 if_link->link_partner_caps |= QLNX_LINK_CAP_1000baseT_Full;
4907
4908 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_10G)
4909 if_link->link_partner_caps |= QLNX_LINK_CAP_10000baseKR_Full;
4910
4911 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_25G)
4912 if_link->link_partner_caps |= QLNX_LINK_CAP_25000baseKR_Full;
4913
4914 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_40G)
4915 if_link->link_partner_caps |= QLNX_LINK_CAP_40000baseLR4_Full;
4916
4917 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_50G)
4918 if_link->link_partner_caps |= QLNX_LINK_CAP_50000baseKR2_Full;
4919
4920 if (link_state.partner_adv_speed & ECORE_LINK_PARTNER_SPEED_100G)
4921 if_link->link_partner_caps |= QLNX_LINK_CAP_100000baseKR4_Full;
4922
4923 if (link_state.an_complete)
4924 if_link->link_partner_caps |= QLNX_LINK_CAP_Autoneg;
4925
4926 if (link_state.partner_adv_pause)
4927 if_link->link_partner_caps |= QLNX_LINK_CAP_Pause;
4928
4929 if ((link_state.partner_adv_pause ==
4930 ECORE_LINK_PARTNER_ASYMMETRIC_PAUSE) ||
4931 (link_state.partner_adv_pause ==
4932 ECORE_LINK_PARTNER_BOTH_PAUSE))
4933 if_link->link_partner_caps |= QLNX_LINK_CAP_Asym_Pause;
4934
4935 return;
4936}
4937
4938static int
4939qlnx_nic_setup(struct ecore_dev *cdev, struct ecore_pf_params *func_params)
4940{
4941 int rc, i;
4942
4943 for (i = 0; i < cdev->num_hwfns; i++) {
4944 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
4945 p_hwfn->pf_params = *func_params;
4946 }
4947
4948 rc = ecore_resc_alloc(cdev);
4949 if (rc)
4950 goto qlnx_nic_setup_exit;
4951
4952 ecore_resc_setup(cdev);
4953
4954qlnx_nic_setup_exit:
4955
4956 return rc;
4957}
4958
4959static int
4960qlnx_nic_start(struct ecore_dev *cdev)
4961{
4962 int rc;
4963 struct ecore_hw_init_params params;
4964
4965 bzero(&params, sizeof (struct ecore_hw_init_params));
4966
4967 params.p_tunn = NULL;
4968 params.b_hw_start = true;
4969 params.int_mode = cdev->int_mode;
4970 params.allow_npar_tx_switch = true;
4971 params.bin_fw_data = NULL;
4972
4973 rc = ecore_hw_init(cdev, &params);
4974 if (rc) {
4975 ecore_resc_free(cdev);
4976 return rc;
4977 }
4978
4979 return 0;
4980}
4981
4982static int
4983qlnx_slowpath_start(qlnx_host_t *ha)
4984{
4985 struct ecore_dev *cdev;
4986 struct ecore_pf_params pf_params;
4987 int rc;
4988
4989 memset(&pf_params, 0, sizeof(struct ecore_pf_params));
4990 pf_params.eth_pf_params.num_cons =
4991 (ha->num_rss) * (ha->num_tc + 1);
4992
4993 cdev = &ha->cdev;
4994
4995 rc = qlnx_nic_setup(cdev, &pf_params);
4996 if (rc)
4997 goto qlnx_slowpath_start_exit;
4998
4999 cdev->int_mode = ECORE_INT_MODE_MSIX;
5000 cdev->int_coalescing_mode = ECORE_COAL_MODE_ENABLE;
5001
5002#ifdef QLNX_MAX_COALESCE
5003 cdev->rx_coalesce_usecs = 255;
5004 cdev->tx_coalesce_usecs = 255;
5005#endif
5006
5007 rc = qlnx_nic_start(cdev);
5008
5009 ha->rx_coalesce_usecs = cdev->rx_coalesce_usecs;
5010 ha->tx_coalesce_usecs = cdev->tx_coalesce_usecs;
5011
5012qlnx_slowpath_start_exit:
5013
5014 return (rc);
5015}
5016
5017static int
5018qlnx_slowpath_stop(qlnx_host_t *ha)
5019{
5020 struct ecore_dev *cdev;
5021 device_t dev = ha->pci_dev;
5022 int i;
5023
5024 cdev = &ha->cdev;
5025
5026 ecore_hw_stop(cdev);
5027
5028 for (i = 0; i < ha->cdev.num_hwfns; i++) {
5029
5030 if (ha->sp_handle[i])
5031 (void)bus_teardown_intr(dev, ha->sp_irq[i],
5032 ha->sp_handle[i]);
5033
5034 ha->sp_handle[i] = NULL;
5035
5036 if (ha->sp_irq[i])
5037 (void) bus_release_resource(dev, SYS_RES_IRQ,
5038 ha->sp_irq_rid[i], ha->sp_irq[i]);
5039 ha->sp_irq[i] = NULL;
5040 }
5041
5042 ecore_resc_free(cdev);
5043
5044 return 0;
5045}
5046
5047static void
5048qlnx_set_id(struct ecore_dev *cdev, char name[NAME_SIZE],
5049 char ver_str[VER_SIZE])
5050{
5051 int i;
5052
5053 memcpy(cdev->name, name, NAME_SIZE);
5054
5055 for_each_hwfn(cdev, i) {
5056 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
5057 }
5058
5059 cdev->drv_type = DRV_ID_DRV_TYPE_FREEBSD;
5060
5061 return ;
5062}
5063
5064void
5065qlnx_get_protocol_stats(void *cdev, int proto_type, void *proto_stats)
5066{
5067 enum ecore_mcp_protocol_type type;
5068 union ecore_mcp_protocol_stats *stats;
5069 struct ecore_eth_stats eth_stats;
5070 qlnx_host_t *ha;
5071
5072 ha = cdev;
5073 stats = proto_stats;
5074 type = proto_type;
5075
5076 switch (type) {
5077
5078 case ECORE_MCP_LAN_STATS:
5079 ecore_get_vport_stats((struct ecore_dev *)cdev, &eth_stats);
5080 stats->lan_stats.ucast_rx_pkts = eth_stats.common.rx_ucast_pkts;
5081 stats->lan_stats.ucast_tx_pkts = eth_stats.common.tx_ucast_pkts;
5082 stats->lan_stats.fcs_err = -1;
5083 break;
5084
5085 default:
5086 ha->err_get_proto_invalid_type++;
5087
5088 QL_DPRINT1(ha, "invalid protocol type 0x%x\n", type);
5089 break;
5090 }
5091 return;
5092}
5093
5094static int
5095qlnx_get_mfw_version(qlnx_host_t *ha, uint32_t *mfw_ver)
5096{
5097 struct ecore_hwfn *p_hwfn;
5098 struct ecore_ptt *p_ptt;
5099
5100 p_hwfn = &ha->cdev.hwfns[0];
5101 p_ptt = ecore_ptt_acquire(p_hwfn);
5102
5103 if (p_ptt == NULL) {
5104 QL_DPRINT1(ha, "ecore_ptt_acquire failed\n");
5105 return (-1);
5106 }
5107 ecore_mcp_get_mfw_ver(p_hwfn, p_ptt, mfw_ver, NULL);
5108
5109 ecore_ptt_release(p_hwfn, p_ptt);
5110
5111 return (0);
5112}
5113
5114static int
5115qlnx_get_flash_size(qlnx_host_t *ha, uint32_t *flash_size)
5116{
5117 struct ecore_hwfn *p_hwfn;
5118 struct ecore_ptt *p_ptt;
5119
5120 p_hwfn = &ha->cdev.hwfns[0];
5121 p_ptt = ecore_ptt_acquire(p_hwfn);
5122
5123 if (p_ptt == NULL) {
5124 QL_DPRINT1(ha,"ecore_ptt_acquire failed\n");
5125 return (-1);
5126 }
5127 ecore_mcp_get_flash_size(p_hwfn, p_ptt, flash_size);
5128
5129 ecore_ptt_release(p_hwfn, p_ptt);
5130
5131 return (0);
5132}
5133
5134static int
5135qlnx_alloc_mem_arrays(qlnx_host_t *ha)
5136{
5137 struct ecore_dev *cdev;
5138
5139 cdev = &ha->cdev;
5140
5141 bzero(&ha->txq_array[0], (sizeof(struct qlnx_tx_queue) * QLNX_MAX_RSS));
5142 bzero(&ha->rxq_array[0], (sizeof(struct qlnx_rx_queue) * QLNX_MAX_RSS));
5143 bzero(&ha->sb_array[0], (sizeof(struct ecore_sb_info) * QLNX_MAX_RSS));
5144
5145 return 0;
5146}
5147
5148static void
5149qlnx_init_fp(qlnx_host_t *ha)
5150{
5151 int rss_id, txq_array_index, tc;
5152
5153 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
5154
5155 struct qlnx_fastpath *fp = &ha->fp_array[rss_id];
5156
5157 fp->rss_id = rss_id;
5158 fp->edev = ha;
5159 fp->sb_info = &ha->sb_array[rss_id];
5160 fp->rxq = &ha->rxq_array[rss_id];
5161 fp->rxq->rxq_id = rss_id;
5162
5163 for (tc = 0; tc < ha->num_tc; tc++) {
5164 txq_array_index = tc * ha->num_rss + rss_id;
5165 fp->txq[tc] = &ha->txq_array[txq_array_index];
5166 fp->txq[tc]->index = txq_array_index;
5167 }
5168
5169 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d", qlnx_name_str,
5170 rss_id);
5171
5172 fp->tx_ring_full = 0;
5173
5174 /* reset all the statistics counters */
5175
5176 fp->tx_pkts_processed = 0;
5177 fp->tx_pkts_freed = 0;
5178 fp->tx_pkts_transmitted = 0;
5179 fp->tx_pkts_completed = 0;
5180 fp->tx_lso_wnd_min_len = 0;
5181 fp->tx_defrag = 0;
5182 fp->tx_nsegs_gt_elem_left = 0;
5183 fp->tx_tso_max_nsegs = 0;
5184 fp->tx_tso_min_nsegs = 0;
5185 fp->err_tx_nsegs_gt_elem_left = 0;
5186 fp->err_tx_dmamap_create = 0;
5187 fp->err_tx_defrag_dmamap_load = 0;
5188 fp->err_tx_non_tso_max_seg = 0;
5189 fp->err_tx_dmamap_load = 0;
5190 fp->err_tx_defrag = 0;
5191 fp->err_tx_free_pkt_null = 0;
5192 fp->err_tx_cons_idx_conflict = 0;
5193
5194 fp->rx_pkts = 0;
5195 fp->err_m_getcl = 0;
5196 fp->err_m_getjcl = 0;
5197 }
5198 return;
5199}
5200
5201static void
5202qlnx_free_mem_sb(qlnx_host_t *ha, struct ecore_sb_info *sb_info)
5203{
5204 struct ecore_dev *cdev;
5205
5206 cdev = &ha->cdev;
5207
5208 if (sb_info->sb_virt) {
5209 OSAL_DMA_FREE_COHERENT(cdev, ((void *)sb_info->sb_virt),
5210 (sb_info->sb_phys), (sizeof(*sb_info->sb_virt)));
5211 sb_info->sb_virt = NULL;
5212 }
5213}
5214
5215static int
5216qlnx_sb_init(struct ecore_dev *cdev, struct ecore_sb_info *sb_info,
5217 void *sb_virt_addr, bus_addr_t sb_phy_addr, u16 sb_id)
5218{
5219 struct ecore_hwfn *p_hwfn;
5220 int hwfn_index, rc;
5221 u16 rel_sb_id;
5222
5223 hwfn_index = sb_id % cdev->num_hwfns;
5224 p_hwfn = &cdev->hwfns[hwfn_index];
5225 rel_sb_id = sb_id / cdev->num_hwfns;
5226
5227 QL_DPRINT2(((qlnx_host_t *)cdev),
5228 "hwfn_index = %d p_hwfn = %p sb_id = 0x%x rel_sb_id = 0x%x \
5229 sb_info = %p sb_virt_addr = %p sb_phy_addr = %p\n",
5230 hwfn_index, p_hwfn, sb_id, rel_sb_id, sb_info,
5231 sb_virt_addr, (void *)sb_phy_addr);
5232
5233 rc = ecore_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
5234 sb_virt_addr, sb_phy_addr, rel_sb_id);
5235
5236 return rc;
5237}
5238
5239/* This function allocates fast-path status block memory */
5240static int
5241qlnx_alloc_mem_sb(qlnx_host_t *ha, struct ecore_sb_info *sb_info, u16 sb_id)
5242{
5204 struct status_block *sb_virt;
5243 struct status_block_e4 *sb_virt;
5205 bus_addr_t sb_phys;
5206 int rc;
5207 uint32_t size;
5208 struct ecore_dev *cdev;
5209
5210 cdev = &ha->cdev;
5211
5212 size = sizeof(*sb_virt);
5213 sb_virt = OSAL_DMA_ALLOC_COHERENT(cdev, (&sb_phys), size);
5214
5215 if (!sb_virt) {
5216 QL_DPRINT1(ha, "Status block allocation failed\n");
5217 return -ENOMEM;
5218 }
5219
5220 rc = qlnx_sb_init(cdev, sb_info, sb_virt, sb_phys, sb_id);
5221 if (rc) {
5222 OSAL_DMA_FREE_COHERENT(cdev, sb_virt, sb_phys, size);
5223 }
5224
5225 return rc;
5226}
5227
5228static void
5229qlnx_free_rx_buffers(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5230{
5231 int i;
5232 struct sw_rx_data *rx_buf;
5233
5234 for (i = 0; i < rxq->num_rx_buffers; i++) {
5235
5236 rx_buf = &rxq->sw_rx_ring[i];
5237
5238 if (rx_buf->data != NULL) {
5239 if (rx_buf->map != NULL) {
5240 bus_dmamap_unload(ha->rx_tag, rx_buf->map);
5241 bus_dmamap_destroy(ha->rx_tag, rx_buf->map);
5242 rx_buf->map = NULL;
5243 }
5244 m_freem(rx_buf->data);
5245 rx_buf->data = NULL;
5246 }
5247 }
5248 return;
5249}
5250
5251static void
5252qlnx_free_mem_rxq(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5253{
5254 struct ecore_dev *cdev;
5255 int i;
5256
5257 cdev = &ha->cdev;
5258
5259 qlnx_free_rx_buffers(ha, rxq);
5260
5261 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
5262 qlnx_free_tpa_mbuf(ha, &rxq->tpa_info[i]);
5263 if (rxq->tpa_info[i].mpf != NULL)
5264 m_freem(rxq->tpa_info[i].mpf);
5265 }
5266
5267 bzero((void *)&rxq->sw_rx_ring[0],
5268 (sizeof (struct sw_rx_data) * RX_RING_SIZE));
5269
5270 /* Free the real RQ ring used by FW */
5271 if (rxq->rx_bd_ring.p_virt_addr) {
5272 ecore_chain_free(cdev, &rxq->rx_bd_ring);
5273 rxq->rx_bd_ring.p_virt_addr = NULL;
5274 }
5275
5276 /* Free the real completion ring used by FW */
5277 if (rxq->rx_comp_ring.p_virt_addr &&
5278 rxq->rx_comp_ring.pbl_sp.p_virt_table) {
5279 ecore_chain_free(cdev, &rxq->rx_comp_ring);
5280 rxq->rx_comp_ring.p_virt_addr = NULL;
5281 rxq->rx_comp_ring.pbl_sp.p_virt_table = NULL;
5282 }
5283
5284#ifdef QLNX_SOFT_LRO
5285 {
5286 struct lro_ctrl *lro;
5287
5288 lro = &rxq->lro;
5289 tcp_lro_free(lro);
5290 }
5291#endif /* #ifdef QLNX_SOFT_LRO */
5292
5293 return;
5294}
5295
5296static int
5297qlnx_alloc_rx_buffer(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5298{
5299 register struct mbuf *mp;
5300 uint16_t rx_buf_size;
5301 struct sw_rx_data *sw_rx_data;
5302 struct eth_rx_bd *rx_bd;
5303 dma_addr_t dma_addr;
5304 bus_dmamap_t map;
5305 bus_dma_segment_t segs[1];
5306 int nsegs;
5307 int ret;
5308 struct ecore_dev *cdev;
5309
5310 cdev = &ha->cdev;
5311
5312 rx_buf_size = rxq->rx_buf_size;
5313
5314 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, rx_buf_size);
5315
5316 if (mp == NULL) {
5317 QL_DPRINT1(ha, "Failed to allocate Rx data\n");
5318 return -ENOMEM;
5319 }
5320
5321 mp->m_len = mp->m_pkthdr.len = rx_buf_size;
5322
5323 map = (bus_dmamap_t)0;
5324
5325 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, map, mp, segs, &nsegs,
5326 BUS_DMA_NOWAIT);
5327 dma_addr = segs[0].ds_addr;
5328
5329 if (ret || !dma_addr || (nsegs != 1)) {
5330 m_freem(mp);
5331 QL_DPRINT1(ha, "bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
5332 ret, (long long unsigned int)dma_addr, nsegs);
5333 return -ENOMEM;
5334 }
5335
5336 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_prod];
5337 sw_rx_data->data = mp;
5338 sw_rx_data->dma_addr = dma_addr;
5339 sw_rx_data->map = map;
5340
5341 /* Advance PROD and get BD pointer */
5342 rx_bd = (struct eth_rx_bd *)ecore_chain_produce(&rxq->rx_bd_ring);
5343 rx_bd->addr.hi = htole32(U64_HI(dma_addr));
5344 rx_bd->addr.lo = htole32(U64_LO(dma_addr));
5345 bus_dmamap_sync(ha->rx_tag, map, BUS_DMASYNC_PREREAD);
5346
5347 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
5348
5349 return 0;
5350}
5351
5352static int
5353qlnx_alloc_tpa_mbuf(qlnx_host_t *ha, uint16_t rx_buf_size,
5354 struct qlnx_agg_info *tpa)
5355{
5356 struct mbuf *mp;
5357 dma_addr_t dma_addr;
5358 bus_dmamap_t map;
5359 bus_dma_segment_t segs[1];
5360 int nsegs;
5361 int ret;
5362 struct sw_rx_data *rx_buf;
5363
5364 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, rx_buf_size);
5365
5366 if (mp == NULL) {
5367 QL_DPRINT1(ha, "Failed to allocate Rx data\n");
5368 return -ENOMEM;
5369 }
5370
5371 mp->m_len = mp->m_pkthdr.len = rx_buf_size;
5372
5373 map = (bus_dmamap_t)0;
5374
5375 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, map, mp, segs, &nsegs,
5376 BUS_DMA_NOWAIT);
5377 dma_addr = segs[0].ds_addr;
5378
5379 if (ret || !dma_addr || (nsegs != 1)) {
5380 m_freem(mp);
5381 QL_DPRINT1(ha, "bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
5382 ret, (long long unsigned int)dma_addr, nsegs);
5383 return -ENOMEM;
5384 }
5385
5386 rx_buf = &tpa->rx_buf;
5387
5388 memset(rx_buf, 0, sizeof (struct sw_rx_data));
5389
5390 rx_buf->data = mp;
5391 rx_buf->dma_addr = dma_addr;
5392 rx_buf->map = map;
5393
5394 bus_dmamap_sync(ha->rx_tag, map, BUS_DMASYNC_PREREAD);
5395
5396 return (0);
5397}
5398
5399static void
5400qlnx_free_tpa_mbuf(qlnx_host_t *ha, struct qlnx_agg_info *tpa)
5401{
5402 struct sw_rx_data *rx_buf;
5403
5404 rx_buf = &tpa->rx_buf;
5405
5406 if (rx_buf->data != NULL) {
5407 if (rx_buf->map != NULL) {
5408 bus_dmamap_unload(ha->rx_tag, rx_buf->map);
5409 bus_dmamap_destroy(ha->rx_tag, rx_buf->map);
5410 rx_buf->map = NULL;
5411 }
5412 m_freem(rx_buf->data);
5413 rx_buf->data = NULL;
5414 }
5415 return;
5416}
5417
5418/* This function allocates all memory needed per Rx queue */
5419static int
5420qlnx_alloc_mem_rxq(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5421{
5422 int i, rc, num_allocated;
5423 struct ifnet *ifp;
5424 struct ecore_dev *cdev;
5425
5426 cdev = &ha->cdev;
5427 ifp = ha->ifp;
5428
5429 rxq->num_rx_buffers = RX_RING_SIZE;
5430
5431 rxq->rx_buf_size = ha->rx_buf_size;
5432
5433 /* Allocate the parallel driver ring for Rx buffers */
5434 bzero((void *)&rxq->sw_rx_ring[0],
5435 (sizeof (struct sw_rx_data) * RX_RING_SIZE));
5436
5437 /* Allocate FW Rx ring */
5438
5439 rc = ecore_chain_alloc(cdev,
5440 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
5441 ECORE_CHAIN_MODE_NEXT_PTR,
5442 ECORE_CHAIN_CNT_TYPE_U16,
5443 RX_RING_SIZE,
5444 sizeof(struct eth_rx_bd),
5445 &rxq->rx_bd_ring, NULL);
5446
5447 if (rc)
5448 goto err;
5449
5450 /* Allocate FW completion ring */
5451 rc = ecore_chain_alloc(cdev,
5452 ECORE_CHAIN_USE_TO_CONSUME,
5453 ECORE_CHAIN_MODE_PBL,
5454 ECORE_CHAIN_CNT_TYPE_U16,
5455 RX_RING_SIZE,
5456 sizeof(union eth_rx_cqe),
5457 &rxq->rx_comp_ring, NULL);
5458
5459 if (rc)
5460 goto err;
5461
5462 /* Allocate buffers for the Rx ring */
5463
5464 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
5465 rc = qlnx_alloc_tpa_mbuf(ha, rxq->rx_buf_size,
5466 &rxq->tpa_info[i]);
5467 if (rc)
5468 break;
5469
5470 }
5471
5472 for (i = 0; i < rxq->num_rx_buffers; i++) {
5473 rc = qlnx_alloc_rx_buffer(ha, rxq);
5474 if (rc)
5475 break;
5476 }
5477 num_allocated = i;
5478 if (!num_allocated) {
5479 QL_DPRINT1(ha, "Rx buffers allocation failed\n");
5480 goto err;
5481 } else if (num_allocated < rxq->num_rx_buffers) {
5482 QL_DPRINT1(ha, "Allocated less buffers than"
5483 " desired (%d allocated)\n", num_allocated);
5484 }
5485
5486#ifdef QLNX_SOFT_LRO
5487
5488 {
5489 struct lro_ctrl *lro;
5490
5491 lro = &rxq->lro;
5492
5493#if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
5494 if (tcp_lro_init_args(lro, ifp, 0, rxq->num_rx_buffers)) {
5495 QL_DPRINT1(ha, "tcp_lro_init[%d] failed\n",
5496 rxq->rxq_id);
5497 goto err;
5498 }
5499#else
5500 if (tcp_lro_init(lro)) {
5501 QL_DPRINT1(ha, "tcp_lro_init[%d] failed\n",
5502 rxq->rxq_id);
5503 goto err;
5504 }
5505#endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
5506
5507 lro->ifp = ha->ifp;
5508 }
5509#endif /* #ifdef QLNX_SOFT_LRO */
5510 return 0;
5511
5512err:
5513 qlnx_free_mem_rxq(ha, rxq);
5514 return -ENOMEM;
5515}
5516
5517
5518static void
5519qlnx_free_mem_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
5520 struct qlnx_tx_queue *txq)
5521{
5522 struct ecore_dev *cdev;
5523
5524 cdev = &ha->cdev;
5525
5526 bzero((void *)&txq->sw_tx_ring[0],
5527 (sizeof (struct sw_tx_bd) * TX_RING_SIZE));
5528
5529 /* Free the real RQ ring used by FW */
5530 if (txq->tx_pbl.p_virt_addr) {
5531 ecore_chain_free(cdev, &txq->tx_pbl);
5532 txq->tx_pbl.p_virt_addr = NULL;
5533 }
5534 return;
5535}
5536
5537/* This function allocates all memory needed per Tx queue */
5538static int
5539qlnx_alloc_mem_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
5540 struct qlnx_tx_queue *txq)
5541{
5542 int ret = ECORE_SUCCESS;
5543 union eth_tx_bd_types *p_virt;
5544 struct ecore_dev *cdev;
5545
5546 cdev = &ha->cdev;
5547
5548 bzero((void *)&txq->sw_tx_ring[0],
5549 (sizeof (struct sw_tx_bd) * TX_RING_SIZE));
5550
5551 /* Allocate the real Tx ring to be used by FW */
5552 ret = ecore_chain_alloc(cdev,
5553 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
5554 ECORE_CHAIN_MODE_PBL,
5555 ECORE_CHAIN_CNT_TYPE_U16,
5556 TX_RING_SIZE,
5557 sizeof(*p_virt),
5558 &txq->tx_pbl, NULL);
5559
5560 if (ret != ECORE_SUCCESS) {
5561 goto err;
5562 }
5563
5564 txq->num_tx_buffers = TX_RING_SIZE;
5565
5566 return 0;
5567
5568err:
5569 qlnx_free_mem_txq(ha, fp, txq);
5570 return -ENOMEM;
5571}
5572
5573static void
5574qlnx_free_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5575{
5576 struct mbuf *mp;
5577 struct ifnet *ifp = ha->ifp;
5578
5579 if (mtx_initialized(&fp->tx_mtx)) {
5580
5581 if (fp->tx_br != NULL) {
5582
5583 mtx_lock(&fp->tx_mtx);
5584
5585 while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) {
5586 fp->tx_pkts_freed++;
5587 m_freem(mp);
5588 }
5589
5590 mtx_unlock(&fp->tx_mtx);
5591
5592 buf_ring_free(fp->tx_br, M_DEVBUF);
5593 fp->tx_br = NULL;
5594 }
5595 mtx_destroy(&fp->tx_mtx);
5596 }
5597 return;
5598}
5599
5600static void
5601qlnx_free_mem_fp(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5602{
5603 int tc;
5604
5605 qlnx_free_mem_sb(ha, fp->sb_info);
5606
5607 qlnx_free_mem_rxq(ha, fp->rxq);
5608
5609 for (tc = 0; tc < ha->num_tc; tc++)
5610 qlnx_free_mem_txq(ha, fp, fp->txq[tc]);
5611
5612 return;
5613}
5614
5615static int
5616qlnx_alloc_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5617{
5618 snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
5619 "qlnx%d_fp%d_tx_mq_lock", ha->dev_unit, fp->rss_id);
5620
5621 mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
5622
5623 fp->tx_br = buf_ring_alloc(TX_RING_SIZE, M_DEVBUF,
5624 M_NOWAIT, &fp->tx_mtx);
5625 if (fp->tx_br == NULL) {
5626 QL_DPRINT1(ha, "buf_ring_alloc failed for fp[%d, %d]\n",
5627 ha->dev_unit, fp->rss_id);
5628 return -ENOMEM;
5629 }
5630 return 0;
5631}
5632
5633static int
5634qlnx_alloc_mem_fp(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5635{
5636 int rc, tc;
5637
5638 rc = qlnx_alloc_mem_sb(ha, fp->sb_info, fp->rss_id);
5639 if (rc)
5640 goto err;
5641
5642 if (ha->rx_jumbo_buf_eq_mtu) {
5643 if (ha->max_frame_size <= MCLBYTES)
5644 ha->rx_buf_size = MCLBYTES;
5645 else if (ha->max_frame_size <= MJUMPAGESIZE)
5646 ha->rx_buf_size = MJUMPAGESIZE;
5647 else if (ha->max_frame_size <= MJUM9BYTES)
5648 ha->rx_buf_size = MJUM9BYTES;
5649 else if (ha->max_frame_size <= MJUM16BYTES)
5650 ha->rx_buf_size = MJUM16BYTES;
5651 } else {
5652 if (ha->max_frame_size <= MCLBYTES)
5653 ha->rx_buf_size = MCLBYTES;
5654 else
5655 ha->rx_buf_size = MJUMPAGESIZE;
5656 }
5657
5658 rc = qlnx_alloc_mem_rxq(ha, fp->rxq);
5659 if (rc)
5660 goto err;
5661
5662 for (tc = 0; tc < ha->num_tc; tc++) {
5663 rc = qlnx_alloc_mem_txq(ha, fp, fp->txq[tc]);
5664 if (rc)
5665 goto err;
5666 }
5667
5668 return 0;
5669
5670err:
5671 qlnx_free_mem_fp(ha, fp);
5672 return -ENOMEM;
5673}
5674
5675static void
5676qlnx_free_mem_load(qlnx_host_t *ha)
5677{
5678 int i;
5679 struct ecore_dev *cdev;
5680
5681 cdev = &ha->cdev;
5682
5683 for (i = 0; i < ha->num_rss; i++) {
5684 struct qlnx_fastpath *fp = &ha->fp_array[i];
5685
5686 qlnx_free_mem_fp(ha, fp);
5687 }
5688 return;
5689}
5690
5691static int
5692qlnx_alloc_mem_load(qlnx_host_t *ha)
5693{
5694 int rc = 0, rss_id;
5695
5696 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
5697 struct qlnx_fastpath *fp = &ha->fp_array[rss_id];
5698
5699 rc = qlnx_alloc_mem_fp(ha, fp);
5700 if (rc)
5701 break;
5702 }
5703 return (rc);
5704}
5705
5706static int
5707qlnx_start_vport(struct ecore_dev *cdev,
5708 u8 vport_id,
5709 u16 mtu,
5710 u8 drop_ttl0_flg,
5711 u8 inner_vlan_removal_en_flg,
5712 u8 tx_switching,
5713 u8 hw_lro_enable)
5714{
5715 int rc, i;
5716 struct ecore_sp_vport_start_params vport_start_params = { 0 };
5717 qlnx_host_t *ha;
5718
5719 ha = (qlnx_host_t *)cdev;
5720
5721 vport_start_params.remove_inner_vlan = inner_vlan_removal_en_flg;
5722 vport_start_params.tx_switching = 0;
5723 vport_start_params.handle_ptp_pkts = 0;
5724 vport_start_params.only_untagged = 0;
5725 vport_start_params.drop_ttl0 = drop_ttl0_flg;
5726
5727 vport_start_params.tpa_mode =
5728 (hw_lro_enable ? ECORE_TPA_MODE_RSC : ECORE_TPA_MODE_NONE);
5729 vport_start_params.max_buffers_per_cqe = QLNX_TPA_MAX_AGG_BUFFERS;
5730
5731 vport_start_params.vport_id = vport_id;
5732 vport_start_params.mtu = mtu;
5733
5734
5735 QL_DPRINT2(ha, "Setting mtu to %d and VPORT ID = %d\n", mtu, vport_id);
5736
5737 for_each_hwfn(cdev, i) {
5738 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
5739
5740 vport_start_params.concrete_fid = p_hwfn->hw_info.concrete_fid;
5741 vport_start_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
5742
5743 rc = ecore_sp_vport_start(p_hwfn, &vport_start_params);
5744
5745 if (rc) {
5746 QL_DPRINT1(ha, "Failed to start VPORT V-PORT %d"
5747 " with MTU %d\n" , vport_id, mtu);
5748 return -ENOMEM;
5749 }
5750
5751 ecore_hw_start_fastpath(p_hwfn);
5752
5753 QL_DPRINT2(ha, "Started V-PORT %d with MTU %d\n",
5754 vport_id, mtu);
5755 }
5756 return 0;
5757}
5758
5759
5760static int
5761qlnx_update_vport(struct ecore_dev *cdev,
5762 struct qlnx_update_vport_params *params)
5763{
5764 struct ecore_sp_vport_update_params sp_params;
5765 int rc, i, j, fp_index;
5766 struct ecore_hwfn *p_hwfn;
5767 struct ecore_rss_params *rss;
5768 qlnx_host_t *ha = (qlnx_host_t *)cdev;
5769 struct qlnx_fastpath *fp;
5770
5771 memset(&sp_params, 0, sizeof(sp_params));
5772 /* Translate protocol params into sp params */
5773 sp_params.vport_id = params->vport_id;
5774
5775 sp_params.update_vport_active_rx_flg =
5776 params->update_vport_active_rx_flg;
5777 sp_params.vport_active_rx_flg = params->vport_active_rx_flg;
5778
5779 sp_params.update_vport_active_tx_flg =
5780 params->update_vport_active_tx_flg;
5781 sp_params.vport_active_tx_flg = params->vport_active_tx_flg;
5782
5783 sp_params.update_inner_vlan_removal_flg =
5784 params->update_inner_vlan_removal_flg;
5785 sp_params.inner_vlan_removal_flg = params->inner_vlan_removal_flg;
5786
5787 sp_params.sge_tpa_params = params->sge_tpa_params;
5788
5789 /* RSS - is a bit tricky, since upper-layer isn't familiar with hwfns.
5790 * We need to re-fix the rss values per engine for CMT.
5791 */
5792 if (params->rss_params->update_rss_config)
5793 sp_params.rss_params = params->rss_params;
5794 else
5795 sp_params.rss_params = NULL;
5796
5797 for_each_hwfn(cdev, i) {
5798
5799 p_hwfn = &cdev->hwfns[i];
5800
5801 if ((cdev->num_hwfns > 1) &&
5802 params->rss_params->update_rss_config &&
5803 params->rss_params->rss_enable) {
5804
5805 rss = params->rss_params;
5806
5807 for (j = 0; j < ECORE_RSS_IND_TABLE_SIZE; j++) {
5808
5809 fp_index = ((cdev->num_hwfns * j) + i) %
5810 ha->num_rss;
5811
5812 fp = &ha->fp_array[fp_index];
5813 rss->rss_ind_table[j] = fp->rxq->handle;
5814 }
5815
5816 for (j = 0; j < ECORE_RSS_IND_TABLE_SIZE;) {
5817 QL_DPRINT3(ha, "%p %p %p %p %p %p %p %p \n",
5818 rss->rss_ind_table[j],
5819 rss->rss_ind_table[j+1],
5820 rss->rss_ind_table[j+2],
5821 rss->rss_ind_table[j+3],
5822 rss->rss_ind_table[j+4],
5823 rss->rss_ind_table[j+5],
5824 rss->rss_ind_table[j+6],
5825 rss->rss_ind_table[j+7]);
5826 j += 8;
5827 }
5828 }
5829
5830 sp_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
5831
5832 QL_DPRINT1(ha, "Update sp vport ID=%d\n", params->vport_id);
5833
5834 rc = ecore_sp_vport_update(p_hwfn, &sp_params,
5835 ECORE_SPQ_MODE_EBLOCK, NULL);
5836 if (rc) {
5837 QL_DPRINT1(ha, "Failed to update VPORT\n");
5838 return rc;
5839 }
5840
5841 QL_DPRINT2(ha, "Updated V-PORT %d: tx_active_flag %d, \
5842 rx_active_flag %d [tx_update %d], [rx_update %d]\n",
5843 params->vport_id, params->vport_active_tx_flg,
5844 params->vport_active_rx_flg,
5845 params->update_vport_active_tx_flg,
5846 params->update_vport_active_rx_flg);
5847 }
5848
5849 return 0;
5850}
5851
5852static void
5853qlnx_reuse_rx_data(struct qlnx_rx_queue *rxq)
5854{
5855 struct eth_rx_bd *rx_bd_cons =
5856 ecore_chain_consume(&rxq->rx_bd_ring);
5857 struct eth_rx_bd *rx_bd_prod =
5858 ecore_chain_produce(&rxq->rx_bd_ring);
5859 struct sw_rx_data *sw_rx_data_cons =
5860 &rxq->sw_rx_ring[rxq->sw_rx_cons];
5861 struct sw_rx_data *sw_rx_data_prod =
5862 &rxq->sw_rx_ring[rxq->sw_rx_prod];
5863
5864 sw_rx_data_prod->data = sw_rx_data_cons->data;
5865 memcpy(rx_bd_prod, rx_bd_cons, sizeof(struct eth_rx_bd));
5866
5867 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
5868 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
5869
5870 return;
5871}
5872
5873static void
5874qlnx_update_rx_prod(struct ecore_hwfn *p_hwfn, struct qlnx_rx_queue *rxq)
5875{
5876
5877 uint16_t bd_prod;
5878 uint16_t cqe_prod;
5879 union {
5880 struct eth_rx_prod_data rx_prod_data;
5881 uint32_t data32;
5882 } rx_prods;
5883
5884 bd_prod = ecore_chain_get_prod_idx(&rxq->rx_bd_ring);
5885 cqe_prod = ecore_chain_get_prod_idx(&rxq->rx_comp_ring);
5886
5887 /* Update producers */
5888 rx_prods.rx_prod_data.bd_prod = htole16(bd_prod);
5889 rx_prods.rx_prod_data.cqe_prod = htole16(cqe_prod);
5890
5891 /* Make sure that the BD and SGE data is updated before updating the
5892 * producers since FW might read the BD/SGE right after the producer
5893 * is updated.
5894 */
5895 wmb();
5896
5897 internal_ram_wr(p_hwfn, rxq->hw_rxq_prod_addr,
5898 sizeof(rx_prods), &rx_prods.data32);
5899
5900 /* mmiowb is needed to synchronize doorbell writes from more than one
5901 * processor. It guarantees that the write arrives to the device before
5902 * the napi lock is released and another qlnx_poll is called (possibly
5903 * on another CPU). Without this barrier, the next doorbell can bypass
5904 * this doorbell. This is applicable to IA64/Altix systems.
5905 */
5906 wmb();
5907
5908 return;
5909}
5910
5911static uint32_t qlnx_hash_key[] = {
5912 ((0x6d << 24)|(0x5a << 16)|(0x56 << 8)|0xda),
5913 ((0x25 << 24)|(0x5b << 16)|(0x0e << 8)|0xc2),
5914 ((0x41 << 24)|(0x67 << 16)|(0x25 << 8)|0x3d),
5915 ((0x43 << 24)|(0xa3 << 16)|(0x8f << 8)|0xb0),
5916 ((0xd0 << 24)|(0xca << 16)|(0x2b << 8)|0xcb),
5917 ((0xae << 24)|(0x7b << 16)|(0x30 << 8)|0xb4),
5918 ((0x77 << 24)|(0xcb << 16)|(0x2d << 8)|0xa3),
5919 ((0x80 << 24)|(0x30 << 16)|(0xf2 << 8)|0x0c),
5920 ((0x6a << 24)|(0x42 << 16)|(0xb7 << 8)|0x3b),
5921 ((0xbe << 24)|(0xac << 16)|(0x01 << 8)|0xfa)};
5922
5923static int
5924qlnx_start_queues(qlnx_host_t *ha)
5925{
5926 int rc, tc, i, vport_id = 0,
5927 drop_ttl0_flg = 1, vlan_removal_en = 1,
5928 tx_switching = 0, hw_lro_enable = 0;
5929 struct ecore_dev *cdev = &ha->cdev;
5930 struct ecore_rss_params *rss_params = &ha->rss_params;
5931 struct qlnx_update_vport_params vport_update_params;
5932 struct ifnet *ifp;
5933 struct ecore_hwfn *p_hwfn;
5934 struct ecore_sge_tpa_params tpa_params;
5935 struct ecore_queue_start_common_params qparams;
5936 struct qlnx_fastpath *fp;
5937
5938 ifp = ha->ifp;
5939
5940 QL_DPRINT1(ha, "Num RSS = %d\n", ha->num_rss);
5941
5942 if (!ha->num_rss) {
5943 QL_DPRINT1(ha, "Cannot update V-VPORT as active as there"
5944 " are no Rx queues\n");
5945 return -EINVAL;
5946 }
5947
5948#ifndef QLNX_SOFT_LRO
5949 hw_lro_enable = ifp->if_capenable & IFCAP_LRO;
5950#endif /* #ifndef QLNX_SOFT_LRO */
5951
5952 rc = qlnx_start_vport(cdev, vport_id, ifp->if_mtu, drop_ttl0_flg,
5953 vlan_removal_en, tx_switching, hw_lro_enable);
5954
5955 if (rc) {
5956 QL_DPRINT1(ha, "Start V-PORT failed %d\n", rc);
5957 return rc;
5958 }
5959
5960 QL_DPRINT2(ha, "Start vport ramrod passed, "
5961 "vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
5962 vport_id, (int)(ifp->if_mtu + 0xe), vlan_removal_en);
5963
5964 for_each_rss(i) {
5965 struct ecore_rxq_start_ret_params rx_ret_params;
5966 struct ecore_txq_start_ret_params tx_ret_params;
5967
5968 fp = &ha->fp_array[i];
5969 p_hwfn = &cdev->hwfns[(fp->rss_id % cdev->num_hwfns)];
5970
5971 bzero(&qparams, sizeof(struct ecore_queue_start_common_params));
5972 bzero(&rx_ret_params,
5973 sizeof (struct ecore_rxq_start_ret_params));
5974
5975 qparams.queue_id = i ;
5976 qparams.vport_id = vport_id;
5977 qparams.stats_id = vport_id;
5978 qparams.p_sb = fp->sb_info;
5979 qparams.sb_idx = RX_PI;
5980
5981
5982 rc = ecore_eth_rx_queue_start(p_hwfn,
5983 p_hwfn->hw_info.opaque_fid,
5984 &qparams,
5985 fp->rxq->rx_buf_size, /* bd_max_bytes */
5986 /* bd_chain_phys_addr */
5987 fp->rxq->rx_bd_ring.p_phys_addr,
5988 /* cqe_pbl_addr */
5989 ecore_chain_get_pbl_phys(&fp->rxq->rx_comp_ring),
5990 /* cqe_pbl_size */
5991 ecore_chain_get_page_cnt(&fp->rxq->rx_comp_ring),
5992 &rx_ret_params);
5993
5994 if (rc) {
5995 QL_DPRINT1(ha, "Start RXQ #%d failed %d\n", i, rc);
5996 return rc;
5997 }
5998
5999 fp->rxq->hw_rxq_prod_addr = rx_ret_params.p_prod;
6000 fp->rxq->handle = rx_ret_params.p_handle;
6001 fp->rxq->hw_cons_ptr =
6002 &fp->sb_info->sb_virt->pi_array[RX_PI];
6003
6004 qlnx_update_rx_prod(p_hwfn, fp->rxq);
6005
6006 for (tc = 0; tc < ha->num_tc; tc++) {
6007 struct qlnx_tx_queue *txq = fp->txq[tc];
6008
6009 bzero(&qparams,
6010 sizeof(struct ecore_queue_start_common_params));
6011 bzero(&tx_ret_params,
6012 sizeof (struct ecore_txq_start_ret_params));
6013
6014 qparams.queue_id = txq->index / cdev->num_hwfns ;
6015 qparams.vport_id = vport_id;
6016 qparams.stats_id = vport_id;
6017 qparams.p_sb = fp->sb_info;
6018 qparams.sb_idx = TX_PI(tc);
6019
6020 rc = ecore_eth_tx_queue_start(p_hwfn,
6021 p_hwfn->hw_info.opaque_fid,
6022 &qparams, tc,
6023 /* bd_chain_phys_addr */
6024 ecore_chain_get_pbl_phys(&txq->tx_pbl),
6025 ecore_chain_get_page_cnt(&txq->tx_pbl),
6026 &tx_ret_params);
6027
6028 if (rc) {
6029 QL_DPRINT1(ha, "Start TXQ #%d failed %d\n",
6030 txq->index, rc);
6031 return rc;
6032 }
6033
6034 txq->doorbell_addr = tx_ret_params.p_doorbell;
6035 txq->handle = tx_ret_params.p_handle;
6036
6037 txq->hw_cons_ptr =
6038 &fp->sb_info->sb_virt->pi_array[TX_PI(tc)];
6039 SET_FIELD(txq->tx_db.data.params,
6040 ETH_DB_DATA_DEST, DB_DEST_XCM);
6041 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD,
6042 DB_AGG_CMD_SET);
6043 SET_FIELD(txq->tx_db.data.params,
6044 ETH_DB_DATA_AGG_VAL_SEL,
6045 DQ_XCM_ETH_TX_BD_PROD_CMD);
6046
6047 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
6048 }
6049 }
6050
6051 /* Fill struct with RSS params */
6052 if (ha->num_rss > 1) {
6053
6054 rss_params->update_rss_config = 1;
6055 rss_params->rss_enable = 1;
6056 rss_params->update_rss_capabilities = 1;
6057 rss_params->update_rss_ind_table = 1;
6058 rss_params->update_rss_key = 1;
6059 rss_params->rss_caps = ECORE_RSS_IPV4 | ECORE_RSS_IPV6 |
6060 ECORE_RSS_IPV4_TCP | ECORE_RSS_IPV6_TCP;
6061 rss_params->rss_table_size_log = 7; /* 2^7 = 128 */
6062
6063 for (i = 0; i < ECORE_RSS_IND_TABLE_SIZE; i++) {
6064 fp = &ha->fp_array[(i % ha->num_rss)];
6065 rss_params->rss_ind_table[i] = fp->rxq->handle;
6066 }
6067
6068 for (i = 0; i < ECORE_RSS_KEY_SIZE; i++)
6069 rss_params->rss_key[i] = (__le32)qlnx_hash_key[i];
6070
6071 } else {
6072 memset(rss_params, 0, sizeof(*rss_params));
6073 }
6074
6075
6076 /* Prepare and send the vport enable */
6077 memset(&vport_update_params, 0, sizeof(vport_update_params));
6078 vport_update_params.vport_id = vport_id;
6079 vport_update_params.update_vport_active_tx_flg = 1;
6080 vport_update_params.vport_active_tx_flg = 1;
6081 vport_update_params.update_vport_active_rx_flg = 1;
6082 vport_update_params.vport_active_rx_flg = 1;
6083 vport_update_params.rss_params = rss_params;
6084 vport_update_params.update_inner_vlan_removal_flg = 1;
6085 vport_update_params.inner_vlan_removal_flg = 1;
6086
6087 if (hw_lro_enable) {
6088 memset(&tpa_params, 0, sizeof (struct ecore_sge_tpa_params));
6089
6090 tpa_params.max_buffers_per_cqe = QLNX_TPA_MAX_AGG_BUFFERS;
6091
6092 tpa_params.update_tpa_en_flg = 1;
6093 tpa_params.tpa_ipv4_en_flg = 1;
6094 tpa_params.tpa_ipv6_en_flg = 1;
6095
6096 tpa_params.update_tpa_param_flg = 1;
6097 tpa_params.tpa_pkt_split_flg = 0;
6098 tpa_params.tpa_hdr_data_split_flg = 0;
6099 tpa_params.tpa_gro_consistent_flg = 0;
6100 tpa_params.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
6101 tpa_params.tpa_max_size = (uint16_t)(-1);
6102 tpa_params.tpa_min_size_to_start = ifp->if_mtu/2;
6103 tpa_params.tpa_min_size_to_cont = ifp->if_mtu/2;
6104
6105 vport_update_params.sge_tpa_params = &tpa_params;
6106 }
6107
6108 rc = qlnx_update_vport(cdev, &vport_update_params);
6109 if (rc) {
6110 QL_DPRINT1(ha, "Update V-PORT failed %d\n", rc);
6111 return rc;
6112 }
6113
6114 return 0;
6115}
6116
6117static int
6118qlnx_drain_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
6119 struct qlnx_tx_queue *txq)
6120{
6121 uint16_t hw_bd_cons;
6122 uint16_t ecore_cons_idx;
6123
6124 QL_DPRINT2(ha, "enter\n");
6125
6126 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
6127
6128 while (hw_bd_cons !=
6129 (ecore_cons_idx = ecore_chain_get_cons_idx(&txq->tx_pbl))) {
6130
6131 mtx_lock(&fp->tx_mtx);
6132
6133 (void)qlnx_tx_int(ha, fp, txq);
6134
6135 mtx_unlock(&fp->tx_mtx);
6136
6137 qlnx_mdelay(__func__, 2);
6138
6139 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
6140 }
6141
6142 QL_DPRINT2(ha, "[%d, %d]: done\n", fp->rss_id, txq->index);
6143
6144 return 0;
6145}
6146
6147static int
6148qlnx_stop_queues(qlnx_host_t *ha)
6149{
6150 struct qlnx_update_vport_params vport_update_params;
6151 struct ecore_dev *cdev;
6152 struct qlnx_fastpath *fp;
6153 int rc, tc, i;
6154
6155 cdev = &ha->cdev;
6156
6157 /* Disable the vport */
6158
6159 memset(&vport_update_params, 0, sizeof(vport_update_params));
6160
6161 vport_update_params.vport_id = 0;
6162 vport_update_params.update_vport_active_tx_flg = 1;
6163 vport_update_params.vport_active_tx_flg = 0;
6164 vport_update_params.update_vport_active_rx_flg = 1;
6165 vport_update_params.vport_active_rx_flg = 0;
6166 vport_update_params.rss_params = &ha->rss_params;
6167 vport_update_params.rss_params->update_rss_config = 0;
6168 vport_update_params.rss_params->rss_enable = 0;
6169 vport_update_params.update_inner_vlan_removal_flg = 0;
6170 vport_update_params.inner_vlan_removal_flg = 0;
6171
6172 QL_DPRINT1(ha, "Update vport ID= %d\n", vport_update_params.vport_id);
6173
6174 rc = qlnx_update_vport(cdev, &vport_update_params);
6175 if (rc) {
6176 QL_DPRINT1(ha, "Failed to update vport\n");
6177 return rc;
6178 }
6179
6180 /* Flush Tx queues. If needed, request drain from MCP */
6181 for_each_rss(i) {
6182 fp = &ha->fp_array[i];
6183
6184 for (tc = 0; tc < ha->num_tc; tc++) {
6185 struct qlnx_tx_queue *txq = fp->txq[tc];
6186
6187 rc = qlnx_drain_txq(ha, fp, txq);
6188 if (rc)
6189 return rc;
6190 }
6191 }
6192
6193 /* Stop all Queues in reverse order*/
6194 for (i = ha->num_rss - 1; i >= 0; i--) {
6195
6196 struct ecore_hwfn *p_hwfn = &cdev->hwfns[(i % cdev->num_hwfns)];
6197
6198 fp = &ha->fp_array[i];
6199
6200 /* Stop the Tx Queue(s)*/
6201 for (tc = 0; tc < ha->num_tc; tc++) {
6202 int tx_queue_id;
6203
6204 tx_queue_id = tc * ha->num_rss + i;
6205 rc = ecore_eth_tx_queue_stop(p_hwfn,
6206 fp->txq[tc]->handle);
6207
6208 if (rc) {
6209 QL_DPRINT1(ha, "Failed to stop TXQ #%d\n",
6210 tx_queue_id);
6211 return rc;
6212 }
6213 }
6214
6215 /* Stop the Rx Queue*/
6216 rc = ecore_eth_rx_queue_stop(p_hwfn, fp->rxq->handle, false,
6217 false);
6218 if (rc) {
6219 QL_DPRINT1(ha, "Failed to stop RXQ #%d\n", i);
6220 return rc;
6221 }
6222 }
6223
6224 /* Stop the vport */
6225 for_each_hwfn(cdev, i) {
6226
6227 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
6228
6229 rc = ecore_sp_vport_stop(p_hwfn, p_hwfn->hw_info.opaque_fid, 0);
6230
6231 if (rc) {
6232 QL_DPRINT1(ha, "Failed to stop VPORT\n");
6233 return rc;
6234 }
6235 }
6236
6237 return rc;
6238}
6239
6240static int
6241qlnx_set_ucast_rx_mac(qlnx_host_t *ha,
6242 enum ecore_filter_opcode opcode,
6243 unsigned char mac[ETH_ALEN])
6244{
6245 struct ecore_filter_ucast ucast;
6246 struct ecore_dev *cdev;
6247 int rc;
6248
6249 cdev = &ha->cdev;
6250
6251 bzero(&ucast, sizeof(struct ecore_filter_ucast));
6252
6253 ucast.opcode = opcode;
6254 ucast.type = ECORE_FILTER_MAC;
6255 ucast.is_rx_filter = 1;
6256 ucast.vport_to_add_to = 0;
6257 memcpy(&ucast.mac[0], mac, ETH_ALEN);
6258
6259 rc = ecore_filter_ucast_cmd(cdev, &ucast, ECORE_SPQ_MODE_CB, NULL);
6260
6261 return (rc);
6262}
6263
6264static int
6265qlnx_remove_all_ucast_mac(qlnx_host_t *ha)
6266{
6267 struct ecore_filter_ucast ucast;
6268 struct ecore_dev *cdev;
6269 int rc;
6270
6271 bzero(&ucast, sizeof(struct ecore_filter_ucast));
6272
6273 ucast.opcode = ECORE_FILTER_REPLACE;
6274 ucast.type = ECORE_FILTER_MAC;
6275 ucast.is_rx_filter = 1;
6276
6277 cdev = &ha->cdev;
6278
6279 rc = ecore_filter_ucast_cmd(cdev, &ucast, ECORE_SPQ_MODE_CB, NULL);
6280
6281 return (rc);
6282}
6283
6284static int
6285qlnx_remove_all_mcast_mac(qlnx_host_t *ha)
6286{
6287 struct ecore_filter_mcast *mcast;
6288 struct ecore_dev *cdev;
6289 int rc, i;
6290
6291 cdev = &ha->cdev;
6292
6293 mcast = &ha->ecore_mcast;
6294 bzero(mcast, sizeof(struct ecore_filter_mcast));
6295
6296 mcast->opcode = ECORE_FILTER_REMOVE;
6297
6298 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
6299
6300 if (ha->mcast[i].addr[0] || ha->mcast[i].addr[1] ||
6301 ha->mcast[i].addr[2] || ha->mcast[i].addr[3] ||
6302 ha->mcast[i].addr[4] || ha->mcast[i].addr[5]) {
6303
6304 memcpy(&mcast->mac[i], &ha->mcast[i].addr[0], ETH_ALEN);
6305 mcast->num_mc_addrs++;
6306 }
6307 }
6308 mcast = &ha->ecore_mcast;
6309
6310 rc = ecore_filter_mcast_cmd(cdev, mcast, ECORE_SPQ_MODE_CB, NULL);
6311
6312 bzero(ha->mcast, (sizeof(qlnx_mcast_t) * QLNX_MAX_NUM_MULTICAST_ADDRS));
6313 ha->nmcast = 0;
6314
6315 return (rc);
6316}
6317
6318static int
6319qlnx_clean_filters(qlnx_host_t *ha)
6320{
6321 int rc = 0;
6322
6323 /* Remove all unicast macs */
6324 rc = qlnx_remove_all_ucast_mac(ha);
6325 if (rc)
6326 return rc;
6327
6328 /* Remove all multicast macs */
6329 rc = qlnx_remove_all_mcast_mac(ha);
6330 if (rc)
6331 return rc;
6332
6333 rc = qlnx_set_ucast_rx_mac(ha, ECORE_FILTER_FLUSH, ha->primary_mac);
6334
6335 return (rc);
6336}
6337
6338static int
6339qlnx_set_rx_accept_filter(qlnx_host_t *ha, uint8_t filter)
6340{
6341 struct ecore_filter_accept_flags accept;
6342 int rc = 0;
6343 struct ecore_dev *cdev;
6344
6345 cdev = &ha->cdev;
6346
6347 bzero(&accept, sizeof(struct ecore_filter_accept_flags));
6348
6349 accept.update_rx_mode_config = 1;
6350 accept.rx_accept_filter = filter;
6351
6352 accept.update_tx_mode_config = 1;
6353 accept.tx_accept_filter = ECORE_ACCEPT_UCAST_MATCHED |
6354 ECORE_ACCEPT_MCAST_MATCHED | ECORE_ACCEPT_BCAST;
6355
6356 rc = ecore_filter_accept_cmd(cdev, 0, accept, false, false,
6357 ECORE_SPQ_MODE_CB, NULL);
6358
6359 return (rc);
6360}
6361
6362static int
6363qlnx_set_rx_mode(qlnx_host_t *ha)
6364{
6365 int rc = 0;
6366 uint8_t filter;
6367
6368 rc = qlnx_set_ucast_rx_mac(ha, ECORE_FILTER_REPLACE, ha->primary_mac);
6369 if (rc)
6370 return rc;
6371
6372 rc = qlnx_remove_all_mcast_mac(ha);
6373 if (rc)
6374 return rc;
6375
6376 filter = ECORE_ACCEPT_UCAST_MATCHED |
6377 ECORE_ACCEPT_MCAST_MATCHED |
6378 ECORE_ACCEPT_BCAST;
6379 ha->filter = filter;
6380
6381 rc = qlnx_set_rx_accept_filter(ha, filter);
6382
6383 return (rc);
6384}
6385
6386static int
6387qlnx_set_link(qlnx_host_t *ha, bool link_up)
6388{
6389 int i, rc = 0;
6390 struct ecore_dev *cdev;
6391 struct ecore_hwfn *hwfn;
6392 struct ecore_ptt *ptt;
6393
6394 cdev = &ha->cdev;
6395
6396 for_each_hwfn(cdev, i) {
6397
6398 hwfn = &cdev->hwfns[i];
6399
6400 ptt = ecore_ptt_acquire(hwfn);
6401 if (!ptt)
6402 return -EBUSY;
6403
6404 rc = ecore_mcp_set_link(hwfn, ptt, link_up);
6405
6406 ecore_ptt_release(hwfn, ptt);
6407
6408 if (rc)
6409 return rc;
6410 }
6411 return (rc);
6412}
6413
6414#if __FreeBSD_version >= 1100000
6415static uint64_t
6416qlnx_get_counter(if_t ifp, ift_counter cnt)
6417{
6418 qlnx_host_t *ha;
6419 uint64_t count;
6420
6421 ha = (qlnx_host_t *)if_getsoftc(ifp);
6422
6423 switch (cnt) {
6424
6425 case IFCOUNTER_IPACKETS:
6426 count = ha->hw_stats.common.rx_ucast_pkts +
6427 ha->hw_stats.common.rx_mcast_pkts +
6428 ha->hw_stats.common.rx_bcast_pkts;
6429 break;
6430
6431 case IFCOUNTER_IERRORS:
6432 count = ha->hw_stats.common.rx_crc_errors +
6433 ha->hw_stats.common.rx_align_errors +
6434 ha->hw_stats.common.rx_oversize_packets +
6435 ha->hw_stats.common.rx_undersize_packets;
6436 break;
6437
6438 case IFCOUNTER_OPACKETS:
6439 count = ha->hw_stats.common.tx_ucast_pkts +
6440 ha->hw_stats.common.tx_mcast_pkts +
6441 ha->hw_stats.common.tx_bcast_pkts;
6442 break;
6443
6444 case IFCOUNTER_OERRORS:
6445 count = ha->hw_stats.common.tx_err_drop_pkts;
6446 break;
6447
6448 case IFCOUNTER_COLLISIONS:
6449 return (0);
6450
6451 case IFCOUNTER_IBYTES:
6452 count = ha->hw_stats.common.rx_ucast_bytes +
6453 ha->hw_stats.common.rx_mcast_bytes +
6454 ha->hw_stats.common.rx_bcast_bytes;
6455 break;
6456
6457 case IFCOUNTER_OBYTES:
6458 count = ha->hw_stats.common.tx_ucast_bytes +
6459 ha->hw_stats.common.tx_mcast_bytes +
6460 ha->hw_stats.common.tx_bcast_bytes;
6461 break;
6462
6463 case IFCOUNTER_IMCASTS:
6464 count = ha->hw_stats.common.rx_mcast_bytes;
6465 break;
6466
6467 case IFCOUNTER_OMCASTS:
6468 count = ha->hw_stats.common.tx_mcast_bytes;
6469 break;
6470
6471 case IFCOUNTER_IQDROPS:
6472 case IFCOUNTER_OQDROPS:
6473 case IFCOUNTER_NOPROTO:
6474
6475 default:
6476 return (if_get_counter_default(ifp, cnt));
6477 }
6478 return (count);
6479}
6480#endif
6481
6482
6483static void
6484qlnx_timer(void *arg)
6485{
6486 qlnx_host_t *ha;
6487
6488 ha = (qlnx_host_t *)arg;
6489
6490 ecore_get_vport_stats(&ha->cdev, &ha->hw_stats);
6491
6492 if (ha->storm_stats_enable)
6493 qlnx_sample_storm_stats(ha);
6494
6495 callout_reset(&ha->qlnx_callout, hz, qlnx_timer, ha);
6496
6497 return;
6498}
6499
6500static int
6501qlnx_load(qlnx_host_t *ha)
6502{
6503 int i;
6504 int rc = 0;
6505 struct ecore_dev *cdev;
6506 device_t dev;
6507
6508 cdev = &ha->cdev;
6509 dev = ha->pci_dev;
6510
6511 QL_DPRINT2(ha, "enter\n");
6512
6513 rc = qlnx_alloc_mem_arrays(ha);
6514 if (rc)
6515 goto qlnx_load_exit0;
6516
6517 qlnx_init_fp(ha);
6518
6519 rc = qlnx_alloc_mem_load(ha);
6520 if (rc)
6521 goto qlnx_load_exit1;
6522
6523 QL_DPRINT2(ha, "Allocated %d RSS queues on %d TC/s\n",
6524 ha->num_rss, ha->num_tc);
6525
6526 for (i = 0; i < ha->num_rss; i++) {
6527
6528 if ((rc = bus_setup_intr(dev, ha->irq_vec[i].irq,
6529 (INTR_TYPE_NET | INTR_MPSAFE),
6530 NULL, qlnx_fp_isr, &ha->irq_vec[i],
6531 &ha->irq_vec[i].handle))) {
6532
6533 QL_DPRINT1(ha, "could not setup interrupt\n");
6534 goto qlnx_load_exit2;
6535 }
6536
6537 QL_DPRINT2(ha, "rss_id = %d irq_rid %d \
6538 irq %p handle %p\n", i,
6539 ha->irq_vec[i].irq_rid,
6540 ha->irq_vec[i].irq, ha->irq_vec[i].handle);
6541
6542 bus_bind_intr(dev, ha->irq_vec[i].irq, (i % mp_ncpus));
6543 }
6544
6545 rc = qlnx_start_queues(ha);
6546 if (rc)
6547 goto qlnx_load_exit2;
6548
6549 QL_DPRINT2(ha, "Start VPORT, RXQ and TXQ succeeded\n");
6550
6551 /* Add primary mac and set Rx filters */
6552 rc = qlnx_set_rx_mode(ha);
6553 if (rc)
6554 goto qlnx_load_exit2;
6555
6556 /* Ask for link-up using current configuration */
6557 qlnx_set_link(ha, true);
6558
6559 ha->state = QLNX_STATE_OPEN;
6560
6561 bzero(&ha->hw_stats, sizeof(struct ecore_eth_stats));
6562
6563 if (ha->flags.callout_init)
6564 callout_reset(&ha->qlnx_callout, hz, qlnx_timer, ha);
6565
6566 goto qlnx_load_exit0;
6567
6568qlnx_load_exit2:
6569 qlnx_free_mem_load(ha);
6570
6571qlnx_load_exit1:
6572 ha->num_rss = 0;
6573
6574qlnx_load_exit0:
6575 QL_DPRINT2(ha, "exit [%d]\n", rc);
6576 return rc;
6577}
6578
6579static void
6580qlnx_drain_soft_lro(qlnx_host_t *ha)
6581{
6582#ifdef QLNX_SOFT_LRO
6583
6584 struct ifnet *ifp;
6585 int i;
6586
6587 ifp = ha->ifp;
6588
6589
6590 if (ifp->if_capenable & IFCAP_LRO) {
6591
6592 for (i = 0; i < ha->num_rss; i++) {
6593
6594 struct qlnx_fastpath *fp = &ha->fp_array[i];
6595 struct lro_ctrl *lro;
6596
6597 lro = &fp->rxq->lro;
6598
6599#if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
6600
6601 tcp_lro_flush_all(lro);
6602
6603#else
6604 struct lro_entry *queued;
6605
6606 while ((!SLIST_EMPTY(&lro->lro_active))){
6607 queued = SLIST_FIRST(&lro->lro_active);
6608 SLIST_REMOVE_HEAD(&lro->lro_active, next);
6609 tcp_lro_flush(lro, queued);
6610 }
6611
6612#endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
6613
6614 }
6615 }
6616
6617#endif /* #ifdef QLNX_SOFT_LRO */
6618
6619 return;
6620}
6621
6622static void
6623qlnx_unload(qlnx_host_t *ha)
6624{
6625 struct ecore_dev *cdev;
6626 device_t dev;
6627 int i;
6628
6629 cdev = &ha->cdev;
6630 dev = ha->pci_dev;
6631
6632 QL_DPRINT2(ha, "enter\n");
6633 QL_DPRINT1(ha, " QLNX STATE = %d\n",ha->state);
6634
6635 if (ha->state == QLNX_STATE_OPEN) {
6636
6637 qlnx_set_link(ha, false);
6638 qlnx_clean_filters(ha);
6639 qlnx_stop_queues(ha);
6640 ecore_hw_stop_fastpath(cdev);
6641
6642 for (i = 0; i < ha->num_rss; i++) {
6643 if (ha->irq_vec[i].handle) {
6644 (void)bus_teardown_intr(dev,
6645 ha->irq_vec[i].irq,
6646 ha->irq_vec[i].handle);
6647 ha->irq_vec[i].handle = NULL;
6648 }
6649 }
6650
6651 qlnx_drain_fp_taskqueues(ha);
6652 qlnx_drain_soft_lro(ha);
6653 qlnx_free_mem_load(ha);
6654 }
6655
6656 if (ha->flags.callout_init)
6657 callout_drain(&ha->qlnx_callout);
6658
6659 qlnx_mdelay(__func__, 1000);
6660
6661 ha->state = QLNX_STATE_CLOSED;
6662
6663 QL_DPRINT2(ha, "exit\n");
6664 return;
6665}
6666
6667static int
6668qlnx_grc_dumpsize(qlnx_host_t *ha, uint32_t *num_dwords, int hwfn_index)
6669{
6670 int rval = -1;
6671 struct ecore_hwfn *p_hwfn;
6672 struct ecore_ptt *p_ptt;
6673
6674 ecore_dbg_set_app_ver(ecore_dbg_get_fw_func_ver());
6675
6676 p_hwfn = &ha->cdev.hwfns[hwfn_index];
6677 p_ptt = ecore_ptt_acquire(p_hwfn);
6678
6679 if (!p_ptt) {
6680 QL_DPRINT1(ha, "ecore_ptt_acquire failed\n");
6681 return (rval);
6682 }
6683
6684 rval = ecore_dbg_grc_get_dump_buf_size(p_hwfn, p_ptt, num_dwords);
6685
6686 if (rval == DBG_STATUS_OK)
6687 rval = 0;
6688 else {
6689 QL_DPRINT1(ha, "ecore_dbg_grc_get_dump_buf_size failed"
6690 "[0x%x]\n", rval);
6691 }
6692
6693 ecore_ptt_release(p_hwfn, p_ptt);
6694
6695 return (rval);
6696}
6697
6698static int
6699qlnx_idle_chk_size(qlnx_host_t *ha, uint32_t *num_dwords, int hwfn_index)
6700{
6701 int rval = -1;
6702 struct ecore_hwfn *p_hwfn;
6703 struct ecore_ptt *p_ptt;
6704
6705 ecore_dbg_set_app_ver(ecore_dbg_get_fw_func_ver());
6706
6707 p_hwfn = &ha->cdev.hwfns[hwfn_index];
6708 p_ptt = ecore_ptt_acquire(p_hwfn);
6709
6710 if (!p_ptt) {
6711 QL_DPRINT1(ha, "ecore_ptt_acquire failed\n");
6712 return (rval);
6713 }
6714
6715 rval = ecore_dbg_idle_chk_get_dump_buf_size(p_hwfn, p_ptt, num_dwords);
6716
6717 if (rval == DBG_STATUS_OK)
6718 rval = 0;
6719 else {
6720 QL_DPRINT1(ha, "ecore_dbg_idle_chk_get_dump_buf_size failed"
6721 " [0x%x]\n", rval);
6722 }
6723
6724 ecore_ptt_release(p_hwfn, p_ptt);
6725
6726 return (rval);
6727}
6728
6729
6730static void
6731qlnx_sample_storm_stats(qlnx_host_t *ha)
6732{
6733 int i, index;
6734 struct ecore_dev *cdev;
6735 qlnx_storm_stats_t *s_stats;
6736 uint32_t reg;
6737 struct ecore_ptt *p_ptt;
6738 struct ecore_hwfn *hwfn;
6739
6740 if (ha->storm_stats_index >= QLNX_STORM_STATS_SAMPLES_PER_HWFN) {
6741 ha->storm_stats_enable = 0;
6742 return;
6743 }
6744
6745 cdev = &ha->cdev;
6746
6747 for_each_hwfn(cdev, i) {
6748
6749 hwfn = &cdev->hwfns[i];
6750
6751 p_ptt = ecore_ptt_acquire(hwfn);
6752 if (!p_ptt)
6753 return;
6754
6755 index = ha->storm_stats_index +
6756 (i * QLNX_STORM_STATS_SAMPLES_PER_HWFN);
6757
6758 s_stats = &ha->storm_stats[index];
6759
6760 /* XSTORM */
6761 reg = XSEM_REG_FAST_MEMORY +
6762 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6763 s_stats->xstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6764
6765 reg = XSEM_REG_FAST_MEMORY +
6766 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6767 s_stats->xstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6768
6769 reg = XSEM_REG_FAST_MEMORY +
6770 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6771 s_stats->xstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6772
6773 reg = XSEM_REG_FAST_MEMORY +
6774 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6775 s_stats->xstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6776
6777 /* YSTORM */
6778 reg = YSEM_REG_FAST_MEMORY +
6779 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6780 s_stats->ystorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6781
6782 reg = YSEM_REG_FAST_MEMORY +
6783 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6784 s_stats->ystorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6785
6786 reg = YSEM_REG_FAST_MEMORY +
6787 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6788 s_stats->ystorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6789
6790 reg = YSEM_REG_FAST_MEMORY +
6791 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6792 s_stats->ystorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6793
6794 /* PSTORM */
6795 reg = PSEM_REG_FAST_MEMORY +
6796 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6797 s_stats->pstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6798
6799 reg = PSEM_REG_FAST_MEMORY +
6800 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6801 s_stats->pstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6802
6803 reg = PSEM_REG_FAST_MEMORY +
6804 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6805 s_stats->pstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6806
6807 reg = PSEM_REG_FAST_MEMORY +
6808 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6809 s_stats->pstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6810
6811 /* TSTORM */
6812 reg = TSEM_REG_FAST_MEMORY +
6813 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6814 s_stats->tstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6815
6816 reg = TSEM_REG_FAST_MEMORY +
6817 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6818 s_stats->tstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6819
6820 reg = TSEM_REG_FAST_MEMORY +
6821 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6822 s_stats->tstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6823
6824 reg = TSEM_REG_FAST_MEMORY +
6825 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6826 s_stats->tstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6827
6828 /* MSTORM */
6829 reg = MSEM_REG_FAST_MEMORY +
6830 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6831 s_stats->mstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6832
6833 reg = MSEM_REG_FAST_MEMORY +
6834 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6835 s_stats->mstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6836
6837 reg = MSEM_REG_FAST_MEMORY +
6838 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6839 s_stats->mstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6840
6841 reg = MSEM_REG_FAST_MEMORY +
6842 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6843 s_stats->mstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6844
6845 /* USTORM */
6846 reg = USEM_REG_FAST_MEMORY +
6847 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6848 s_stats->ustorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6849
6850 reg = USEM_REG_FAST_MEMORY +
6851 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6852 s_stats->ustorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6853
6854 reg = USEM_REG_FAST_MEMORY +
6855 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6856 s_stats->ustorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6857
6858 reg = USEM_REG_FAST_MEMORY +
6859 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6860 s_stats->ustorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6861
6862 ecore_ptt_release(hwfn, p_ptt);
6863 }
6864
6865 ha->storm_stats_index++;
6866
6867 return;
6868}
6869
6870/*
6871 * Name: qlnx_dump_buf8
6872 * Function: dumps a buffer as bytes
6873 */
6874static void
6875qlnx_dump_buf8(qlnx_host_t *ha, const char *msg, void *dbuf, uint32_t len)
6876{
6877 device_t dev;
6878 uint32_t i = 0;
6879 uint8_t *buf;
6880
6881 dev = ha->pci_dev;
6882 buf = dbuf;
6883
6884 device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
6885
6886 while (len >= 16) {
6887 device_printf(dev,"0x%08x:"
6888 " %02x %02x %02x %02x %02x %02x %02x %02x"
6889 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
6890 buf[0], buf[1], buf[2], buf[3],
6891 buf[4], buf[5], buf[6], buf[7],
6892 buf[8], buf[9], buf[10], buf[11],
6893 buf[12], buf[13], buf[14], buf[15]);
6894 i += 16;
6895 len -= 16;
6896 buf += 16;
6897 }
6898 switch (len) {
6899 case 1:
6900 device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
6901 break;
6902 case 2:
6903 device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
6904 break;
6905 case 3:
6906 device_printf(dev,"0x%08x: %02x %02x %02x\n",
6907 i, buf[0], buf[1], buf[2]);
6908 break;
6909 case 4:
6910 device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
6911 buf[0], buf[1], buf[2], buf[3]);
6912 break;
6913 case 5:
6914 device_printf(dev,"0x%08x:"
6915 " %02x %02x %02x %02x %02x\n", i,
6916 buf[0], buf[1], buf[2], buf[3], buf[4]);
6917 break;
6918 case 6:
6919 device_printf(dev,"0x%08x:"
6920 " %02x %02x %02x %02x %02x %02x\n", i,
6921 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
6922 break;
6923 case 7:
6924 device_printf(dev,"0x%08x:"
6925 " %02x %02x %02x %02x %02x %02x %02x\n", i,
6926 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
6927 break;
6928 case 8:
6929 device_printf(dev,"0x%08x:"
6930 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
6931 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6932 buf[7]);
6933 break;
6934 case 9:
6935 device_printf(dev,"0x%08x:"
6936 " %02x %02x %02x %02x %02x %02x %02x %02x"
6937 " %02x\n", i,
6938 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6939 buf[7], buf[8]);
6940 break;
6941 case 10:
6942 device_printf(dev,"0x%08x:"
6943 " %02x %02x %02x %02x %02x %02x %02x %02x"
6944 " %02x %02x\n", i,
6945 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6946 buf[7], buf[8], buf[9]);
6947 break;
6948 case 11:
6949 device_printf(dev,"0x%08x:"
6950 " %02x %02x %02x %02x %02x %02x %02x %02x"
6951 " %02x %02x %02x\n", i,
6952 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6953 buf[7], buf[8], buf[9], buf[10]);
6954 break;
6955 case 12:
6956 device_printf(dev,"0x%08x:"
6957 " %02x %02x %02x %02x %02x %02x %02x %02x"
6958 " %02x %02x %02x %02x\n", i,
6959 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6960 buf[7], buf[8], buf[9], buf[10], buf[11]);
6961 break;
6962 case 13:
6963 device_printf(dev,"0x%08x:"
6964 " %02x %02x %02x %02x %02x %02x %02x %02x"
6965 " %02x %02x %02x %02x %02x\n", i,
6966 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6967 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
6968 break;
6969 case 14:
6970 device_printf(dev,"0x%08x:"
6971 " %02x %02x %02x %02x %02x %02x %02x %02x"
6972 " %02x %02x %02x %02x %02x %02x\n", i,
6973 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6974 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
6975 buf[13]);
6976 break;
6977 case 15:
6978 device_printf(dev,"0x%08x:"
6979 " %02x %02x %02x %02x %02x %02x %02x %02x"
6980 " %02x %02x %02x %02x %02x %02x %02x\n", i,
6981 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6982 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
6983 buf[13], buf[14]);
6984 break;
6985 default:
6986 break;
6987 }
6988
6989 device_printf(dev, "%s: %s dump end\n", __func__, msg);
6990
6991 return;
6992}
6993
5244 bus_addr_t sb_phys;
5245 int rc;
5246 uint32_t size;
5247 struct ecore_dev *cdev;
5248
5249 cdev = &ha->cdev;
5250
5251 size = sizeof(*sb_virt);
5252 sb_virt = OSAL_DMA_ALLOC_COHERENT(cdev, (&sb_phys), size);
5253
5254 if (!sb_virt) {
5255 QL_DPRINT1(ha, "Status block allocation failed\n");
5256 return -ENOMEM;
5257 }
5258
5259 rc = qlnx_sb_init(cdev, sb_info, sb_virt, sb_phys, sb_id);
5260 if (rc) {
5261 OSAL_DMA_FREE_COHERENT(cdev, sb_virt, sb_phys, size);
5262 }
5263
5264 return rc;
5265}
5266
5267static void
5268qlnx_free_rx_buffers(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5269{
5270 int i;
5271 struct sw_rx_data *rx_buf;
5272
5273 for (i = 0; i < rxq->num_rx_buffers; i++) {
5274
5275 rx_buf = &rxq->sw_rx_ring[i];
5276
5277 if (rx_buf->data != NULL) {
5278 if (rx_buf->map != NULL) {
5279 bus_dmamap_unload(ha->rx_tag, rx_buf->map);
5280 bus_dmamap_destroy(ha->rx_tag, rx_buf->map);
5281 rx_buf->map = NULL;
5282 }
5283 m_freem(rx_buf->data);
5284 rx_buf->data = NULL;
5285 }
5286 }
5287 return;
5288}
5289
5290static void
5291qlnx_free_mem_rxq(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5292{
5293 struct ecore_dev *cdev;
5294 int i;
5295
5296 cdev = &ha->cdev;
5297
5298 qlnx_free_rx_buffers(ha, rxq);
5299
5300 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
5301 qlnx_free_tpa_mbuf(ha, &rxq->tpa_info[i]);
5302 if (rxq->tpa_info[i].mpf != NULL)
5303 m_freem(rxq->tpa_info[i].mpf);
5304 }
5305
5306 bzero((void *)&rxq->sw_rx_ring[0],
5307 (sizeof (struct sw_rx_data) * RX_RING_SIZE));
5308
5309 /* Free the real RQ ring used by FW */
5310 if (rxq->rx_bd_ring.p_virt_addr) {
5311 ecore_chain_free(cdev, &rxq->rx_bd_ring);
5312 rxq->rx_bd_ring.p_virt_addr = NULL;
5313 }
5314
5315 /* Free the real completion ring used by FW */
5316 if (rxq->rx_comp_ring.p_virt_addr &&
5317 rxq->rx_comp_ring.pbl_sp.p_virt_table) {
5318 ecore_chain_free(cdev, &rxq->rx_comp_ring);
5319 rxq->rx_comp_ring.p_virt_addr = NULL;
5320 rxq->rx_comp_ring.pbl_sp.p_virt_table = NULL;
5321 }
5322
5323#ifdef QLNX_SOFT_LRO
5324 {
5325 struct lro_ctrl *lro;
5326
5327 lro = &rxq->lro;
5328 tcp_lro_free(lro);
5329 }
5330#endif /* #ifdef QLNX_SOFT_LRO */
5331
5332 return;
5333}
5334
5335static int
5336qlnx_alloc_rx_buffer(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5337{
5338 register struct mbuf *mp;
5339 uint16_t rx_buf_size;
5340 struct sw_rx_data *sw_rx_data;
5341 struct eth_rx_bd *rx_bd;
5342 dma_addr_t dma_addr;
5343 bus_dmamap_t map;
5344 bus_dma_segment_t segs[1];
5345 int nsegs;
5346 int ret;
5347 struct ecore_dev *cdev;
5348
5349 cdev = &ha->cdev;
5350
5351 rx_buf_size = rxq->rx_buf_size;
5352
5353 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, rx_buf_size);
5354
5355 if (mp == NULL) {
5356 QL_DPRINT1(ha, "Failed to allocate Rx data\n");
5357 return -ENOMEM;
5358 }
5359
5360 mp->m_len = mp->m_pkthdr.len = rx_buf_size;
5361
5362 map = (bus_dmamap_t)0;
5363
5364 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, map, mp, segs, &nsegs,
5365 BUS_DMA_NOWAIT);
5366 dma_addr = segs[0].ds_addr;
5367
5368 if (ret || !dma_addr || (nsegs != 1)) {
5369 m_freem(mp);
5370 QL_DPRINT1(ha, "bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
5371 ret, (long long unsigned int)dma_addr, nsegs);
5372 return -ENOMEM;
5373 }
5374
5375 sw_rx_data = &rxq->sw_rx_ring[rxq->sw_rx_prod];
5376 sw_rx_data->data = mp;
5377 sw_rx_data->dma_addr = dma_addr;
5378 sw_rx_data->map = map;
5379
5380 /* Advance PROD and get BD pointer */
5381 rx_bd = (struct eth_rx_bd *)ecore_chain_produce(&rxq->rx_bd_ring);
5382 rx_bd->addr.hi = htole32(U64_HI(dma_addr));
5383 rx_bd->addr.lo = htole32(U64_LO(dma_addr));
5384 bus_dmamap_sync(ha->rx_tag, map, BUS_DMASYNC_PREREAD);
5385
5386 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
5387
5388 return 0;
5389}
5390
5391static int
5392qlnx_alloc_tpa_mbuf(qlnx_host_t *ha, uint16_t rx_buf_size,
5393 struct qlnx_agg_info *tpa)
5394{
5395 struct mbuf *mp;
5396 dma_addr_t dma_addr;
5397 bus_dmamap_t map;
5398 bus_dma_segment_t segs[1];
5399 int nsegs;
5400 int ret;
5401 struct sw_rx_data *rx_buf;
5402
5403 mp = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, rx_buf_size);
5404
5405 if (mp == NULL) {
5406 QL_DPRINT1(ha, "Failed to allocate Rx data\n");
5407 return -ENOMEM;
5408 }
5409
5410 mp->m_len = mp->m_pkthdr.len = rx_buf_size;
5411
5412 map = (bus_dmamap_t)0;
5413
5414 ret = bus_dmamap_load_mbuf_sg(ha->rx_tag, map, mp, segs, &nsegs,
5415 BUS_DMA_NOWAIT);
5416 dma_addr = segs[0].ds_addr;
5417
5418 if (ret || !dma_addr || (nsegs != 1)) {
5419 m_freem(mp);
5420 QL_DPRINT1(ha, "bus_dmamap_load failed[%d, 0x%016llx, %d]\n",
5421 ret, (long long unsigned int)dma_addr, nsegs);
5422 return -ENOMEM;
5423 }
5424
5425 rx_buf = &tpa->rx_buf;
5426
5427 memset(rx_buf, 0, sizeof (struct sw_rx_data));
5428
5429 rx_buf->data = mp;
5430 rx_buf->dma_addr = dma_addr;
5431 rx_buf->map = map;
5432
5433 bus_dmamap_sync(ha->rx_tag, map, BUS_DMASYNC_PREREAD);
5434
5435 return (0);
5436}
5437
5438static void
5439qlnx_free_tpa_mbuf(qlnx_host_t *ha, struct qlnx_agg_info *tpa)
5440{
5441 struct sw_rx_data *rx_buf;
5442
5443 rx_buf = &tpa->rx_buf;
5444
5445 if (rx_buf->data != NULL) {
5446 if (rx_buf->map != NULL) {
5447 bus_dmamap_unload(ha->rx_tag, rx_buf->map);
5448 bus_dmamap_destroy(ha->rx_tag, rx_buf->map);
5449 rx_buf->map = NULL;
5450 }
5451 m_freem(rx_buf->data);
5452 rx_buf->data = NULL;
5453 }
5454 return;
5455}
5456
5457/* This function allocates all memory needed per Rx queue */
5458static int
5459qlnx_alloc_mem_rxq(qlnx_host_t *ha, struct qlnx_rx_queue *rxq)
5460{
5461 int i, rc, num_allocated;
5462 struct ifnet *ifp;
5463 struct ecore_dev *cdev;
5464
5465 cdev = &ha->cdev;
5466 ifp = ha->ifp;
5467
5468 rxq->num_rx_buffers = RX_RING_SIZE;
5469
5470 rxq->rx_buf_size = ha->rx_buf_size;
5471
5472 /* Allocate the parallel driver ring for Rx buffers */
5473 bzero((void *)&rxq->sw_rx_ring[0],
5474 (sizeof (struct sw_rx_data) * RX_RING_SIZE));
5475
5476 /* Allocate FW Rx ring */
5477
5478 rc = ecore_chain_alloc(cdev,
5479 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
5480 ECORE_CHAIN_MODE_NEXT_PTR,
5481 ECORE_CHAIN_CNT_TYPE_U16,
5482 RX_RING_SIZE,
5483 sizeof(struct eth_rx_bd),
5484 &rxq->rx_bd_ring, NULL);
5485
5486 if (rc)
5487 goto err;
5488
5489 /* Allocate FW completion ring */
5490 rc = ecore_chain_alloc(cdev,
5491 ECORE_CHAIN_USE_TO_CONSUME,
5492 ECORE_CHAIN_MODE_PBL,
5493 ECORE_CHAIN_CNT_TYPE_U16,
5494 RX_RING_SIZE,
5495 sizeof(union eth_rx_cqe),
5496 &rxq->rx_comp_ring, NULL);
5497
5498 if (rc)
5499 goto err;
5500
5501 /* Allocate buffers for the Rx ring */
5502
5503 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
5504 rc = qlnx_alloc_tpa_mbuf(ha, rxq->rx_buf_size,
5505 &rxq->tpa_info[i]);
5506 if (rc)
5507 break;
5508
5509 }
5510
5511 for (i = 0; i < rxq->num_rx_buffers; i++) {
5512 rc = qlnx_alloc_rx_buffer(ha, rxq);
5513 if (rc)
5514 break;
5515 }
5516 num_allocated = i;
5517 if (!num_allocated) {
5518 QL_DPRINT1(ha, "Rx buffers allocation failed\n");
5519 goto err;
5520 } else if (num_allocated < rxq->num_rx_buffers) {
5521 QL_DPRINT1(ha, "Allocated less buffers than"
5522 " desired (%d allocated)\n", num_allocated);
5523 }
5524
5525#ifdef QLNX_SOFT_LRO
5526
5527 {
5528 struct lro_ctrl *lro;
5529
5530 lro = &rxq->lro;
5531
5532#if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
5533 if (tcp_lro_init_args(lro, ifp, 0, rxq->num_rx_buffers)) {
5534 QL_DPRINT1(ha, "tcp_lro_init[%d] failed\n",
5535 rxq->rxq_id);
5536 goto err;
5537 }
5538#else
5539 if (tcp_lro_init(lro)) {
5540 QL_DPRINT1(ha, "tcp_lro_init[%d] failed\n",
5541 rxq->rxq_id);
5542 goto err;
5543 }
5544#endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
5545
5546 lro->ifp = ha->ifp;
5547 }
5548#endif /* #ifdef QLNX_SOFT_LRO */
5549 return 0;
5550
5551err:
5552 qlnx_free_mem_rxq(ha, rxq);
5553 return -ENOMEM;
5554}
5555
5556
5557static void
5558qlnx_free_mem_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
5559 struct qlnx_tx_queue *txq)
5560{
5561 struct ecore_dev *cdev;
5562
5563 cdev = &ha->cdev;
5564
5565 bzero((void *)&txq->sw_tx_ring[0],
5566 (sizeof (struct sw_tx_bd) * TX_RING_SIZE));
5567
5568 /* Free the real RQ ring used by FW */
5569 if (txq->tx_pbl.p_virt_addr) {
5570 ecore_chain_free(cdev, &txq->tx_pbl);
5571 txq->tx_pbl.p_virt_addr = NULL;
5572 }
5573 return;
5574}
5575
5576/* This function allocates all memory needed per Tx queue */
5577static int
5578qlnx_alloc_mem_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
5579 struct qlnx_tx_queue *txq)
5580{
5581 int ret = ECORE_SUCCESS;
5582 union eth_tx_bd_types *p_virt;
5583 struct ecore_dev *cdev;
5584
5585 cdev = &ha->cdev;
5586
5587 bzero((void *)&txq->sw_tx_ring[0],
5588 (sizeof (struct sw_tx_bd) * TX_RING_SIZE));
5589
5590 /* Allocate the real Tx ring to be used by FW */
5591 ret = ecore_chain_alloc(cdev,
5592 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
5593 ECORE_CHAIN_MODE_PBL,
5594 ECORE_CHAIN_CNT_TYPE_U16,
5595 TX_RING_SIZE,
5596 sizeof(*p_virt),
5597 &txq->tx_pbl, NULL);
5598
5599 if (ret != ECORE_SUCCESS) {
5600 goto err;
5601 }
5602
5603 txq->num_tx_buffers = TX_RING_SIZE;
5604
5605 return 0;
5606
5607err:
5608 qlnx_free_mem_txq(ha, fp, txq);
5609 return -ENOMEM;
5610}
5611
5612static void
5613qlnx_free_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5614{
5615 struct mbuf *mp;
5616 struct ifnet *ifp = ha->ifp;
5617
5618 if (mtx_initialized(&fp->tx_mtx)) {
5619
5620 if (fp->tx_br != NULL) {
5621
5622 mtx_lock(&fp->tx_mtx);
5623
5624 while ((mp = drbr_dequeue(ifp, fp->tx_br)) != NULL) {
5625 fp->tx_pkts_freed++;
5626 m_freem(mp);
5627 }
5628
5629 mtx_unlock(&fp->tx_mtx);
5630
5631 buf_ring_free(fp->tx_br, M_DEVBUF);
5632 fp->tx_br = NULL;
5633 }
5634 mtx_destroy(&fp->tx_mtx);
5635 }
5636 return;
5637}
5638
5639static void
5640qlnx_free_mem_fp(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5641{
5642 int tc;
5643
5644 qlnx_free_mem_sb(ha, fp->sb_info);
5645
5646 qlnx_free_mem_rxq(ha, fp->rxq);
5647
5648 for (tc = 0; tc < ha->num_tc; tc++)
5649 qlnx_free_mem_txq(ha, fp, fp->txq[tc]);
5650
5651 return;
5652}
5653
5654static int
5655qlnx_alloc_tx_br(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5656{
5657 snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
5658 "qlnx%d_fp%d_tx_mq_lock", ha->dev_unit, fp->rss_id);
5659
5660 mtx_init(&fp->tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
5661
5662 fp->tx_br = buf_ring_alloc(TX_RING_SIZE, M_DEVBUF,
5663 M_NOWAIT, &fp->tx_mtx);
5664 if (fp->tx_br == NULL) {
5665 QL_DPRINT1(ha, "buf_ring_alloc failed for fp[%d, %d]\n",
5666 ha->dev_unit, fp->rss_id);
5667 return -ENOMEM;
5668 }
5669 return 0;
5670}
5671
5672static int
5673qlnx_alloc_mem_fp(qlnx_host_t *ha, struct qlnx_fastpath *fp)
5674{
5675 int rc, tc;
5676
5677 rc = qlnx_alloc_mem_sb(ha, fp->sb_info, fp->rss_id);
5678 if (rc)
5679 goto err;
5680
5681 if (ha->rx_jumbo_buf_eq_mtu) {
5682 if (ha->max_frame_size <= MCLBYTES)
5683 ha->rx_buf_size = MCLBYTES;
5684 else if (ha->max_frame_size <= MJUMPAGESIZE)
5685 ha->rx_buf_size = MJUMPAGESIZE;
5686 else if (ha->max_frame_size <= MJUM9BYTES)
5687 ha->rx_buf_size = MJUM9BYTES;
5688 else if (ha->max_frame_size <= MJUM16BYTES)
5689 ha->rx_buf_size = MJUM16BYTES;
5690 } else {
5691 if (ha->max_frame_size <= MCLBYTES)
5692 ha->rx_buf_size = MCLBYTES;
5693 else
5694 ha->rx_buf_size = MJUMPAGESIZE;
5695 }
5696
5697 rc = qlnx_alloc_mem_rxq(ha, fp->rxq);
5698 if (rc)
5699 goto err;
5700
5701 for (tc = 0; tc < ha->num_tc; tc++) {
5702 rc = qlnx_alloc_mem_txq(ha, fp, fp->txq[tc]);
5703 if (rc)
5704 goto err;
5705 }
5706
5707 return 0;
5708
5709err:
5710 qlnx_free_mem_fp(ha, fp);
5711 return -ENOMEM;
5712}
5713
5714static void
5715qlnx_free_mem_load(qlnx_host_t *ha)
5716{
5717 int i;
5718 struct ecore_dev *cdev;
5719
5720 cdev = &ha->cdev;
5721
5722 for (i = 0; i < ha->num_rss; i++) {
5723 struct qlnx_fastpath *fp = &ha->fp_array[i];
5724
5725 qlnx_free_mem_fp(ha, fp);
5726 }
5727 return;
5728}
5729
5730static int
5731qlnx_alloc_mem_load(qlnx_host_t *ha)
5732{
5733 int rc = 0, rss_id;
5734
5735 for (rss_id = 0; rss_id < ha->num_rss; rss_id++) {
5736 struct qlnx_fastpath *fp = &ha->fp_array[rss_id];
5737
5738 rc = qlnx_alloc_mem_fp(ha, fp);
5739 if (rc)
5740 break;
5741 }
5742 return (rc);
5743}
5744
5745static int
5746qlnx_start_vport(struct ecore_dev *cdev,
5747 u8 vport_id,
5748 u16 mtu,
5749 u8 drop_ttl0_flg,
5750 u8 inner_vlan_removal_en_flg,
5751 u8 tx_switching,
5752 u8 hw_lro_enable)
5753{
5754 int rc, i;
5755 struct ecore_sp_vport_start_params vport_start_params = { 0 };
5756 qlnx_host_t *ha;
5757
5758 ha = (qlnx_host_t *)cdev;
5759
5760 vport_start_params.remove_inner_vlan = inner_vlan_removal_en_flg;
5761 vport_start_params.tx_switching = 0;
5762 vport_start_params.handle_ptp_pkts = 0;
5763 vport_start_params.only_untagged = 0;
5764 vport_start_params.drop_ttl0 = drop_ttl0_flg;
5765
5766 vport_start_params.tpa_mode =
5767 (hw_lro_enable ? ECORE_TPA_MODE_RSC : ECORE_TPA_MODE_NONE);
5768 vport_start_params.max_buffers_per_cqe = QLNX_TPA_MAX_AGG_BUFFERS;
5769
5770 vport_start_params.vport_id = vport_id;
5771 vport_start_params.mtu = mtu;
5772
5773
5774 QL_DPRINT2(ha, "Setting mtu to %d and VPORT ID = %d\n", mtu, vport_id);
5775
5776 for_each_hwfn(cdev, i) {
5777 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
5778
5779 vport_start_params.concrete_fid = p_hwfn->hw_info.concrete_fid;
5780 vport_start_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
5781
5782 rc = ecore_sp_vport_start(p_hwfn, &vport_start_params);
5783
5784 if (rc) {
5785 QL_DPRINT1(ha, "Failed to start VPORT V-PORT %d"
5786 " with MTU %d\n" , vport_id, mtu);
5787 return -ENOMEM;
5788 }
5789
5790 ecore_hw_start_fastpath(p_hwfn);
5791
5792 QL_DPRINT2(ha, "Started V-PORT %d with MTU %d\n",
5793 vport_id, mtu);
5794 }
5795 return 0;
5796}
5797
5798
5799static int
5800qlnx_update_vport(struct ecore_dev *cdev,
5801 struct qlnx_update_vport_params *params)
5802{
5803 struct ecore_sp_vport_update_params sp_params;
5804 int rc, i, j, fp_index;
5805 struct ecore_hwfn *p_hwfn;
5806 struct ecore_rss_params *rss;
5807 qlnx_host_t *ha = (qlnx_host_t *)cdev;
5808 struct qlnx_fastpath *fp;
5809
5810 memset(&sp_params, 0, sizeof(sp_params));
5811 /* Translate protocol params into sp params */
5812 sp_params.vport_id = params->vport_id;
5813
5814 sp_params.update_vport_active_rx_flg =
5815 params->update_vport_active_rx_flg;
5816 sp_params.vport_active_rx_flg = params->vport_active_rx_flg;
5817
5818 sp_params.update_vport_active_tx_flg =
5819 params->update_vport_active_tx_flg;
5820 sp_params.vport_active_tx_flg = params->vport_active_tx_flg;
5821
5822 sp_params.update_inner_vlan_removal_flg =
5823 params->update_inner_vlan_removal_flg;
5824 sp_params.inner_vlan_removal_flg = params->inner_vlan_removal_flg;
5825
5826 sp_params.sge_tpa_params = params->sge_tpa_params;
5827
5828 /* RSS - is a bit tricky, since upper-layer isn't familiar with hwfns.
5829 * We need to re-fix the rss values per engine for CMT.
5830 */
5831 if (params->rss_params->update_rss_config)
5832 sp_params.rss_params = params->rss_params;
5833 else
5834 sp_params.rss_params = NULL;
5835
5836 for_each_hwfn(cdev, i) {
5837
5838 p_hwfn = &cdev->hwfns[i];
5839
5840 if ((cdev->num_hwfns > 1) &&
5841 params->rss_params->update_rss_config &&
5842 params->rss_params->rss_enable) {
5843
5844 rss = params->rss_params;
5845
5846 for (j = 0; j < ECORE_RSS_IND_TABLE_SIZE; j++) {
5847
5848 fp_index = ((cdev->num_hwfns * j) + i) %
5849 ha->num_rss;
5850
5851 fp = &ha->fp_array[fp_index];
5852 rss->rss_ind_table[j] = fp->rxq->handle;
5853 }
5854
5855 for (j = 0; j < ECORE_RSS_IND_TABLE_SIZE;) {
5856 QL_DPRINT3(ha, "%p %p %p %p %p %p %p %p \n",
5857 rss->rss_ind_table[j],
5858 rss->rss_ind_table[j+1],
5859 rss->rss_ind_table[j+2],
5860 rss->rss_ind_table[j+3],
5861 rss->rss_ind_table[j+4],
5862 rss->rss_ind_table[j+5],
5863 rss->rss_ind_table[j+6],
5864 rss->rss_ind_table[j+7]);
5865 j += 8;
5866 }
5867 }
5868
5869 sp_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
5870
5871 QL_DPRINT1(ha, "Update sp vport ID=%d\n", params->vport_id);
5872
5873 rc = ecore_sp_vport_update(p_hwfn, &sp_params,
5874 ECORE_SPQ_MODE_EBLOCK, NULL);
5875 if (rc) {
5876 QL_DPRINT1(ha, "Failed to update VPORT\n");
5877 return rc;
5878 }
5879
5880 QL_DPRINT2(ha, "Updated V-PORT %d: tx_active_flag %d, \
5881 rx_active_flag %d [tx_update %d], [rx_update %d]\n",
5882 params->vport_id, params->vport_active_tx_flg,
5883 params->vport_active_rx_flg,
5884 params->update_vport_active_tx_flg,
5885 params->update_vport_active_rx_flg);
5886 }
5887
5888 return 0;
5889}
5890
5891static void
5892qlnx_reuse_rx_data(struct qlnx_rx_queue *rxq)
5893{
5894 struct eth_rx_bd *rx_bd_cons =
5895 ecore_chain_consume(&rxq->rx_bd_ring);
5896 struct eth_rx_bd *rx_bd_prod =
5897 ecore_chain_produce(&rxq->rx_bd_ring);
5898 struct sw_rx_data *sw_rx_data_cons =
5899 &rxq->sw_rx_ring[rxq->sw_rx_cons];
5900 struct sw_rx_data *sw_rx_data_prod =
5901 &rxq->sw_rx_ring[rxq->sw_rx_prod];
5902
5903 sw_rx_data_prod->data = sw_rx_data_cons->data;
5904 memcpy(rx_bd_prod, rx_bd_cons, sizeof(struct eth_rx_bd));
5905
5906 rxq->sw_rx_cons = (rxq->sw_rx_cons + 1) & (RX_RING_SIZE - 1);
5907 rxq->sw_rx_prod = (rxq->sw_rx_prod + 1) & (RX_RING_SIZE - 1);
5908
5909 return;
5910}
5911
5912static void
5913qlnx_update_rx_prod(struct ecore_hwfn *p_hwfn, struct qlnx_rx_queue *rxq)
5914{
5915
5916 uint16_t bd_prod;
5917 uint16_t cqe_prod;
5918 union {
5919 struct eth_rx_prod_data rx_prod_data;
5920 uint32_t data32;
5921 } rx_prods;
5922
5923 bd_prod = ecore_chain_get_prod_idx(&rxq->rx_bd_ring);
5924 cqe_prod = ecore_chain_get_prod_idx(&rxq->rx_comp_ring);
5925
5926 /* Update producers */
5927 rx_prods.rx_prod_data.bd_prod = htole16(bd_prod);
5928 rx_prods.rx_prod_data.cqe_prod = htole16(cqe_prod);
5929
5930 /* Make sure that the BD and SGE data is updated before updating the
5931 * producers since FW might read the BD/SGE right after the producer
5932 * is updated.
5933 */
5934 wmb();
5935
5936 internal_ram_wr(p_hwfn, rxq->hw_rxq_prod_addr,
5937 sizeof(rx_prods), &rx_prods.data32);
5938
5939 /* mmiowb is needed to synchronize doorbell writes from more than one
5940 * processor. It guarantees that the write arrives to the device before
5941 * the napi lock is released and another qlnx_poll is called (possibly
5942 * on another CPU). Without this barrier, the next doorbell can bypass
5943 * this doorbell. This is applicable to IA64/Altix systems.
5944 */
5945 wmb();
5946
5947 return;
5948}
5949
5950static uint32_t qlnx_hash_key[] = {
5951 ((0x6d << 24)|(0x5a << 16)|(0x56 << 8)|0xda),
5952 ((0x25 << 24)|(0x5b << 16)|(0x0e << 8)|0xc2),
5953 ((0x41 << 24)|(0x67 << 16)|(0x25 << 8)|0x3d),
5954 ((0x43 << 24)|(0xa3 << 16)|(0x8f << 8)|0xb0),
5955 ((0xd0 << 24)|(0xca << 16)|(0x2b << 8)|0xcb),
5956 ((0xae << 24)|(0x7b << 16)|(0x30 << 8)|0xb4),
5957 ((0x77 << 24)|(0xcb << 16)|(0x2d << 8)|0xa3),
5958 ((0x80 << 24)|(0x30 << 16)|(0xf2 << 8)|0x0c),
5959 ((0x6a << 24)|(0x42 << 16)|(0xb7 << 8)|0x3b),
5960 ((0xbe << 24)|(0xac << 16)|(0x01 << 8)|0xfa)};
5961
5962static int
5963qlnx_start_queues(qlnx_host_t *ha)
5964{
5965 int rc, tc, i, vport_id = 0,
5966 drop_ttl0_flg = 1, vlan_removal_en = 1,
5967 tx_switching = 0, hw_lro_enable = 0;
5968 struct ecore_dev *cdev = &ha->cdev;
5969 struct ecore_rss_params *rss_params = &ha->rss_params;
5970 struct qlnx_update_vport_params vport_update_params;
5971 struct ifnet *ifp;
5972 struct ecore_hwfn *p_hwfn;
5973 struct ecore_sge_tpa_params tpa_params;
5974 struct ecore_queue_start_common_params qparams;
5975 struct qlnx_fastpath *fp;
5976
5977 ifp = ha->ifp;
5978
5979 QL_DPRINT1(ha, "Num RSS = %d\n", ha->num_rss);
5980
5981 if (!ha->num_rss) {
5982 QL_DPRINT1(ha, "Cannot update V-VPORT as active as there"
5983 " are no Rx queues\n");
5984 return -EINVAL;
5985 }
5986
5987#ifndef QLNX_SOFT_LRO
5988 hw_lro_enable = ifp->if_capenable & IFCAP_LRO;
5989#endif /* #ifndef QLNX_SOFT_LRO */
5990
5991 rc = qlnx_start_vport(cdev, vport_id, ifp->if_mtu, drop_ttl0_flg,
5992 vlan_removal_en, tx_switching, hw_lro_enable);
5993
5994 if (rc) {
5995 QL_DPRINT1(ha, "Start V-PORT failed %d\n", rc);
5996 return rc;
5997 }
5998
5999 QL_DPRINT2(ha, "Start vport ramrod passed, "
6000 "vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
6001 vport_id, (int)(ifp->if_mtu + 0xe), vlan_removal_en);
6002
6003 for_each_rss(i) {
6004 struct ecore_rxq_start_ret_params rx_ret_params;
6005 struct ecore_txq_start_ret_params tx_ret_params;
6006
6007 fp = &ha->fp_array[i];
6008 p_hwfn = &cdev->hwfns[(fp->rss_id % cdev->num_hwfns)];
6009
6010 bzero(&qparams, sizeof(struct ecore_queue_start_common_params));
6011 bzero(&rx_ret_params,
6012 sizeof (struct ecore_rxq_start_ret_params));
6013
6014 qparams.queue_id = i ;
6015 qparams.vport_id = vport_id;
6016 qparams.stats_id = vport_id;
6017 qparams.p_sb = fp->sb_info;
6018 qparams.sb_idx = RX_PI;
6019
6020
6021 rc = ecore_eth_rx_queue_start(p_hwfn,
6022 p_hwfn->hw_info.opaque_fid,
6023 &qparams,
6024 fp->rxq->rx_buf_size, /* bd_max_bytes */
6025 /* bd_chain_phys_addr */
6026 fp->rxq->rx_bd_ring.p_phys_addr,
6027 /* cqe_pbl_addr */
6028 ecore_chain_get_pbl_phys(&fp->rxq->rx_comp_ring),
6029 /* cqe_pbl_size */
6030 ecore_chain_get_page_cnt(&fp->rxq->rx_comp_ring),
6031 &rx_ret_params);
6032
6033 if (rc) {
6034 QL_DPRINT1(ha, "Start RXQ #%d failed %d\n", i, rc);
6035 return rc;
6036 }
6037
6038 fp->rxq->hw_rxq_prod_addr = rx_ret_params.p_prod;
6039 fp->rxq->handle = rx_ret_params.p_handle;
6040 fp->rxq->hw_cons_ptr =
6041 &fp->sb_info->sb_virt->pi_array[RX_PI];
6042
6043 qlnx_update_rx_prod(p_hwfn, fp->rxq);
6044
6045 for (tc = 0; tc < ha->num_tc; tc++) {
6046 struct qlnx_tx_queue *txq = fp->txq[tc];
6047
6048 bzero(&qparams,
6049 sizeof(struct ecore_queue_start_common_params));
6050 bzero(&tx_ret_params,
6051 sizeof (struct ecore_txq_start_ret_params));
6052
6053 qparams.queue_id = txq->index / cdev->num_hwfns ;
6054 qparams.vport_id = vport_id;
6055 qparams.stats_id = vport_id;
6056 qparams.p_sb = fp->sb_info;
6057 qparams.sb_idx = TX_PI(tc);
6058
6059 rc = ecore_eth_tx_queue_start(p_hwfn,
6060 p_hwfn->hw_info.opaque_fid,
6061 &qparams, tc,
6062 /* bd_chain_phys_addr */
6063 ecore_chain_get_pbl_phys(&txq->tx_pbl),
6064 ecore_chain_get_page_cnt(&txq->tx_pbl),
6065 &tx_ret_params);
6066
6067 if (rc) {
6068 QL_DPRINT1(ha, "Start TXQ #%d failed %d\n",
6069 txq->index, rc);
6070 return rc;
6071 }
6072
6073 txq->doorbell_addr = tx_ret_params.p_doorbell;
6074 txq->handle = tx_ret_params.p_handle;
6075
6076 txq->hw_cons_ptr =
6077 &fp->sb_info->sb_virt->pi_array[TX_PI(tc)];
6078 SET_FIELD(txq->tx_db.data.params,
6079 ETH_DB_DATA_DEST, DB_DEST_XCM);
6080 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD,
6081 DB_AGG_CMD_SET);
6082 SET_FIELD(txq->tx_db.data.params,
6083 ETH_DB_DATA_AGG_VAL_SEL,
6084 DQ_XCM_ETH_TX_BD_PROD_CMD);
6085
6086 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
6087 }
6088 }
6089
6090 /* Fill struct with RSS params */
6091 if (ha->num_rss > 1) {
6092
6093 rss_params->update_rss_config = 1;
6094 rss_params->rss_enable = 1;
6095 rss_params->update_rss_capabilities = 1;
6096 rss_params->update_rss_ind_table = 1;
6097 rss_params->update_rss_key = 1;
6098 rss_params->rss_caps = ECORE_RSS_IPV4 | ECORE_RSS_IPV6 |
6099 ECORE_RSS_IPV4_TCP | ECORE_RSS_IPV6_TCP;
6100 rss_params->rss_table_size_log = 7; /* 2^7 = 128 */
6101
6102 for (i = 0; i < ECORE_RSS_IND_TABLE_SIZE; i++) {
6103 fp = &ha->fp_array[(i % ha->num_rss)];
6104 rss_params->rss_ind_table[i] = fp->rxq->handle;
6105 }
6106
6107 for (i = 0; i < ECORE_RSS_KEY_SIZE; i++)
6108 rss_params->rss_key[i] = (__le32)qlnx_hash_key[i];
6109
6110 } else {
6111 memset(rss_params, 0, sizeof(*rss_params));
6112 }
6113
6114
6115 /* Prepare and send the vport enable */
6116 memset(&vport_update_params, 0, sizeof(vport_update_params));
6117 vport_update_params.vport_id = vport_id;
6118 vport_update_params.update_vport_active_tx_flg = 1;
6119 vport_update_params.vport_active_tx_flg = 1;
6120 vport_update_params.update_vport_active_rx_flg = 1;
6121 vport_update_params.vport_active_rx_flg = 1;
6122 vport_update_params.rss_params = rss_params;
6123 vport_update_params.update_inner_vlan_removal_flg = 1;
6124 vport_update_params.inner_vlan_removal_flg = 1;
6125
6126 if (hw_lro_enable) {
6127 memset(&tpa_params, 0, sizeof (struct ecore_sge_tpa_params));
6128
6129 tpa_params.max_buffers_per_cqe = QLNX_TPA_MAX_AGG_BUFFERS;
6130
6131 tpa_params.update_tpa_en_flg = 1;
6132 tpa_params.tpa_ipv4_en_flg = 1;
6133 tpa_params.tpa_ipv6_en_flg = 1;
6134
6135 tpa_params.update_tpa_param_flg = 1;
6136 tpa_params.tpa_pkt_split_flg = 0;
6137 tpa_params.tpa_hdr_data_split_flg = 0;
6138 tpa_params.tpa_gro_consistent_flg = 0;
6139 tpa_params.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
6140 tpa_params.tpa_max_size = (uint16_t)(-1);
6141 tpa_params.tpa_min_size_to_start = ifp->if_mtu/2;
6142 tpa_params.tpa_min_size_to_cont = ifp->if_mtu/2;
6143
6144 vport_update_params.sge_tpa_params = &tpa_params;
6145 }
6146
6147 rc = qlnx_update_vport(cdev, &vport_update_params);
6148 if (rc) {
6149 QL_DPRINT1(ha, "Update V-PORT failed %d\n", rc);
6150 return rc;
6151 }
6152
6153 return 0;
6154}
6155
6156static int
6157qlnx_drain_txq(qlnx_host_t *ha, struct qlnx_fastpath *fp,
6158 struct qlnx_tx_queue *txq)
6159{
6160 uint16_t hw_bd_cons;
6161 uint16_t ecore_cons_idx;
6162
6163 QL_DPRINT2(ha, "enter\n");
6164
6165 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
6166
6167 while (hw_bd_cons !=
6168 (ecore_cons_idx = ecore_chain_get_cons_idx(&txq->tx_pbl))) {
6169
6170 mtx_lock(&fp->tx_mtx);
6171
6172 (void)qlnx_tx_int(ha, fp, txq);
6173
6174 mtx_unlock(&fp->tx_mtx);
6175
6176 qlnx_mdelay(__func__, 2);
6177
6178 hw_bd_cons = le16toh(*txq->hw_cons_ptr);
6179 }
6180
6181 QL_DPRINT2(ha, "[%d, %d]: done\n", fp->rss_id, txq->index);
6182
6183 return 0;
6184}
6185
6186static int
6187qlnx_stop_queues(qlnx_host_t *ha)
6188{
6189 struct qlnx_update_vport_params vport_update_params;
6190 struct ecore_dev *cdev;
6191 struct qlnx_fastpath *fp;
6192 int rc, tc, i;
6193
6194 cdev = &ha->cdev;
6195
6196 /* Disable the vport */
6197
6198 memset(&vport_update_params, 0, sizeof(vport_update_params));
6199
6200 vport_update_params.vport_id = 0;
6201 vport_update_params.update_vport_active_tx_flg = 1;
6202 vport_update_params.vport_active_tx_flg = 0;
6203 vport_update_params.update_vport_active_rx_flg = 1;
6204 vport_update_params.vport_active_rx_flg = 0;
6205 vport_update_params.rss_params = &ha->rss_params;
6206 vport_update_params.rss_params->update_rss_config = 0;
6207 vport_update_params.rss_params->rss_enable = 0;
6208 vport_update_params.update_inner_vlan_removal_flg = 0;
6209 vport_update_params.inner_vlan_removal_flg = 0;
6210
6211 QL_DPRINT1(ha, "Update vport ID= %d\n", vport_update_params.vport_id);
6212
6213 rc = qlnx_update_vport(cdev, &vport_update_params);
6214 if (rc) {
6215 QL_DPRINT1(ha, "Failed to update vport\n");
6216 return rc;
6217 }
6218
6219 /* Flush Tx queues. If needed, request drain from MCP */
6220 for_each_rss(i) {
6221 fp = &ha->fp_array[i];
6222
6223 for (tc = 0; tc < ha->num_tc; tc++) {
6224 struct qlnx_tx_queue *txq = fp->txq[tc];
6225
6226 rc = qlnx_drain_txq(ha, fp, txq);
6227 if (rc)
6228 return rc;
6229 }
6230 }
6231
6232 /* Stop all Queues in reverse order*/
6233 for (i = ha->num_rss - 1; i >= 0; i--) {
6234
6235 struct ecore_hwfn *p_hwfn = &cdev->hwfns[(i % cdev->num_hwfns)];
6236
6237 fp = &ha->fp_array[i];
6238
6239 /* Stop the Tx Queue(s)*/
6240 for (tc = 0; tc < ha->num_tc; tc++) {
6241 int tx_queue_id;
6242
6243 tx_queue_id = tc * ha->num_rss + i;
6244 rc = ecore_eth_tx_queue_stop(p_hwfn,
6245 fp->txq[tc]->handle);
6246
6247 if (rc) {
6248 QL_DPRINT1(ha, "Failed to stop TXQ #%d\n",
6249 tx_queue_id);
6250 return rc;
6251 }
6252 }
6253
6254 /* Stop the Rx Queue*/
6255 rc = ecore_eth_rx_queue_stop(p_hwfn, fp->rxq->handle, false,
6256 false);
6257 if (rc) {
6258 QL_DPRINT1(ha, "Failed to stop RXQ #%d\n", i);
6259 return rc;
6260 }
6261 }
6262
6263 /* Stop the vport */
6264 for_each_hwfn(cdev, i) {
6265
6266 struct ecore_hwfn *p_hwfn = &cdev->hwfns[i];
6267
6268 rc = ecore_sp_vport_stop(p_hwfn, p_hwfn->hw_info.opaque_fid, 0);
6269
6270 if (rc) {
6271 QL_DPRINT1(ha, "Failed to stop VPORT\n");
6272 return rc;
6273 }
6274 }
6275
6276 return rc;
6277}
6278
6279static int
6280qlnx_set_ucast_rx_mac(qlnx_host_t *ha,
6281 enum ecore_filter_opcode opcode,
6282 unsigned char mac[ETH_ALEN])
6283{
6284 struct ecore_filter_ucast ucast;
6285 struct ecore_dev *cdev;
6286 int rc;
6287
6288 cdev = &ha->cdev;
6289
6290 bzero(&ucast, sizeof(struct ecore_filter_ucast));
6291
6292 ucast.opcode = opcode;
6293 ucast.type = ECORE_FILTER_MAC;
6294 ucast.is_rx_filter = 1;
6295 ucast.vport_to_add_to = 0;
6296 memcpy(&ucast.mac[0], mac, ETH_ALEN);
6297
6298 rc = ecore_filter_ucast_cmd(cdev, &ucast, ECORE_SPQ_MODE_CB, NULL);
6299
6300 return (rc);
6301}
6302
6303static int
6304qlnx_remove_all_ucast_mac(qlnx_host_t *ha)
6305{
6306 struct ecore_filter_ucast ucast;
6307 struct ecore_dev *cdev;
6308 int rc;
6309
6310 bzero(&ucast, sizeof(struct ecore_filter_ucast));
6311
6312 ucast.opcode = ECORE_FILTER_REPLACE;
6313 ucast.type = ECORE_FILTER_MAC;
6314 ucast.is_rx_filter = 1;
6315
6316 cdev = &ha->cdev;
6317
6318 rc = ecore_filter_ucast_cmd(cdev, &ucast, ECORE_SPQ_MODE_CB, NULL);
6319
6320 return (rc);
6321}
6322
6323static int
6324qlnx_remove_all_mcast_mac(qlnx_host_t *ha)
6325{
6326 struct ecore_filter_mcast *mcast;
6327 struct ecore_dev *cdev;
6328 int rc, i;
6329
6330 cdev = &ha->cdev;
6331
6332 mcast = &ha->ecore_mcast;
6333 bzero(mcast, sizeof(struct ecore_filter_mcast));
6334
6335 mcast->opcode = ECORE_FILTER_REMOVE;
6336
6337 for (i = 0; i < QLNX_MAX_NUM_MULTICAST_ADDRS; i++) {
6338
6339 if (ha->mcast[i].addr[0] || ha->mcast[i].addr[1] ||
6340 ha->mcast[i].addr[2] || ha->mcast[i].addr[3] ||
6341 ha->mcast[i].addr[4] || ha->mcast[i].addr[5]) {
6342
6343 memcpy(&mcast->mac[i], &ha->mcast[i].addr[0], ETH_ALEN);
6344 mcast->num_mc_addrs++;
6345 }
6346 }
6347 mcast = &ha->ecore_mcast;
6348
6349 rc = ecore_filter_mcast_cmd(cdev, mcast, ECORE_SPQ_MODE_CB, NULL);
6350
6351 bzero(ha->mcast, (sizeof(qlnx_mcast_t) * QLNX_MAX_NUM_MULTICAST_ADDRS));
6352 ha->nmcast = 0;
6353
6354 return (rc);
6355}
6356
6357static int
6358qlnx_clean_filters(qlnx_host_t *ha)
6359{
6360 int rc = 0;
6361
6362 /* Remove all unicast macs */
6363 rc = qlnx_remove_all_ucast_mac(ha);
6364 if (rc)
6365 return rc;
6366
6367 /* Remove all multicast macs */
6368 rc = qlnx_remove_all_mcast_mac(ha);
6369 if (rc)
6370 return rc;
6371
6372 rc = qlnx_set_ucast_rx_mac(ha, ECORE_FILTER_FLUSH, ha->primary_mac);
6373
6374 return (rc);
6375}
6376
6377static int
6378qlnx_set_rx_accept_filter(qlnx_host_t *ha, uint8_t filter)
6379{
6380 struct ecore_filter_accept_flags accept;
6381 int rc = 0;
6382 struct ecore_dev *cdev;
6383
6384 cdev = &ha->cdev;
6385
6386 bzero(&accept, sizeof(struct ecore_filter_accept_flags));
6387
6388 accept.update_rx_mode_config = 1;
6389 accept.rx_accept_filter = filter;
6390
6391 accept.update_tx_mode_config = 1;
6392 accept.tx_accept_filter = ECORE_ACCEPT_UCAST_MATCHED |
6393 ECORE_ACCEPT_MCAST_MATCHED | ECORE_ACCEPT_BCAST;
6394
6395 rc = ecore_filter_accept_cmd(cdev, 0, accept, false, false,
6396 ECORE_SPQ_MODE_CB, NULL);
6397
6398 return (rc);
6399}
6400
6401static int
6402qlnx_set_rx_mode(qlnx_host_t *ha)
6403{
6404 int rc = 0;
6405 uint8_t filter;
6406
6407 rc = qlnx_set_ucast_rx_mac(ha, ECORE_FILTER_REPLACE, ha->primary_mac);
6408 if (rc)
6409 return rc;
6410
6411 rc = qlnx_remove_all_mcast_mac(ha);
6412 if (rc)
6413 return rc;
6414
6415 filter = ECORE_ACCEPT_UCAST_MATCHED |
6416 ECORE_ACCEPT_MCAST_MATCHED |
6417 ECORE_ACCEPT_BCAST;
6418 ha->filter = filter;
6419
6420 rc = qlnx_set_rx_accept_filter(ha, filter);
6421
6422 return (rc);
6423}
6424
6425static int
6426qlnx_set_link(qlnx_host_t *ha, bool link_up)
6427{
6428 int i, rc = 0;
6429 struct ecore_dev *cdev;
6430 struct ecore_hwfn *hwfn;
6431 struct ecore_ptt *ptt;
6432
6433 cdev = &ha->cdev;
6434
6435 for_each_hwfn(cdev, i) {
6436
6437 hwfn = &cdev->hwfns[i];
6438
6439 ptt = ecore_ptt_acquire(hwfn);
6440 if (!ptt)
6441 return -EBUSY;
6442
6443 rc = ecore_mcp_set_link(hwfn, ptt, link_up);
6444
6445 ecore_ptt_release(hwfn, ptt);
6446
6447 if (rc)
6448 return rc;
6449 }
6450 return (rc);
6451}
6452
6453#if __FreeBSD_version >= 1100000
6454static uint64_t
6455qlnx_get_counter(if_t ifp, ift_counter cnt)
6456{
6457 qlnx_host_t *ha;
6458 uint64_t count;
6459
6460 ha = (qlnx_host_t *)if_getsoftc(ifp);
6461
6462 switch (cnt) {
6463
6464 case IFCOUNTER_IPACKETS:
6465 count = ha->hw_stats.common.rx_ucast_pkts +
6466 ha->hw_stats.common.rx_mcast_pkts +
6467 ha->hw_stats.common.rx_bcast_pkts;
6468 break;
6469
6470 case IFCOUNTER_IERRORS:
6471 count = ha->hw_stats.common.rx_crc_errors +
6472 ha->hw_stats.common.rx_align_errors +
6473 ha->hw_stats.common.rx_oversize_packets +
6474 ha->hw_stats.common.rx_undersize_packets;
6475 break;
6476
6477 case IFCOUNTER_OPACKETS:
6478 count = ha->hw_stats.common.tx_ucast_pkts +
6479 ha->hw_stats.common.tx_mcast_pkts +
6480 ha->hw_stats.common.tx_bcast_pkts;
6481 break;
6482
6483 case IFCOUNTER_OERRORS:
6484 count = ha->hw_stats.common.tx_err_drop_pkts;
6485 break;
6486
6487 case IFCOUNTER_COLLISIONS:
6488 return (0);
6489
6490 case IFCOUNTER_IBYTES:
6491 count = ha->hw_stats.common.rx_ucast_bytes +
6492 ha->hw_stats.common.rx_mcast_bytes +
6493 ha->hw_stats.common.rx_bcast_bytes;
6494 break;
6495
6496 case IFCOUNTER_OBYTES:
6497 count = ha->hw_stats.common.tx_ucast_bytes +
6498 ha->hw_stats.common.tx_mcast_bytes +
6499 ha->hw_stats.common.tx_bcast_bytes;
6500 break;
6501
6502 case IFCOUNTER_IMCASTS:
6503 count = ha->hw_stats.common.rx_mcast_bytes;
6504 break;
6505
6506 case IFCOUNTER_OMCASTS:
6507 count = ha->hw_stats.common.tx_mcast_bytes;
6508 break;
6509
6510 case IFCOUNTER_IQDROPS:
6511 case IFCOUNTER_OQDROPS:
6512 case IFCOUNTER_NOPROTO:
6513
6514 default:
6515 return (if_get_counter_default(ifp, cnt));
6516 }
6517 return (count);
6518}
6519#endif
6520
6521
6522static void
6523qlnx_timer(void *arg)
6524{
6525 qlnx_host_t *ha;
6526
6527 ha = (qlnx_host_t *)arg;
6528
6529 ecore_get_vport_stats(&ha->cdev, &ha->hw_stats);
6530
6531 if (ha->storm_stats_enable)
6532 qlnx_sample_storm_stats(ha);
6533
6534 callout_reset(&ha->qlnx_callout, hz, qlnx_timer, ha);
6535
6536 return;
6537}
6538
6539static int
6540qlnx_load(qlnx_host_t *ha)
6541{
6542 int i;
6543 int rc = 0;
6544 struct ecore_dev *cdev;
6545 device_t dev;
6546
6547 cdev = &ha->cdev;
6548 dev = ha->pci_dev;
6549
6550 QL_DPRINT2(ha, "enter\n");
6551
6552 rc = qlnx_alloc_mem_arrays(ha);
6553 if (rc)
6554 goto qlnx_load_exit0;
6555
6556 qlnx_init_fp(ha);
6557
6558 rc = qlnx_alloc_mem_load(ha);
6559 if (rc)
6560 goto qlnx_load_exit1;
6561
6562 QL_DPRINT2(ha, "Allocated %d RSS queues on %d TC/s\n",
6563 ha->num_rss, ha->num_tc);
6564
6565 for (i = 0; i < ha->num_rss; i++) {
6566
6567 if ((rc = bus_setup_intr(dev, ha->irq_vec[i].irq,
6568 (INTR_TYPE_NET | INTR_MPSAFE),
6569 NULL, qlnx_fp_isr, &ha->irq_vec[i],
6570 &ha->irq_vec[i].handle))) {
6571
6572 QL_DPRINT1(ha, "could not setup interrupt\n");
6573 goto qlnx_load_exit2;
6574 }
6575
6576 QL_DPRINT2(ha, "rss_id = %d irq_rid %d \
6577 irq %p handle %p\n", i,
6578 ha->irq_vec[i].irq_rid,
6579 ha->irq_vec[i].irq, ha->irq_vec[i].handle);
6580
6581 bus_bind_intr(dev, ha->irq_vec[i].irq, (i % mp_ncpus));
6582 }
6583
6584 rc = qlnx_start_queues(ha);
6585 if (rc)
6586 goto qlnx_load_exit2;
6587
6588 QL_DPRINT2(ha, "Start VPORT, RXQ and TXQ succeeded\n");
6589
6590 /* Add primary mac and set Rx filters */
6591 rc = qlnx_set_rx_mode(ha);
6592 if (rc)
6593 goto qlnx_load_exit2;
6594
6595 /* Ask for link-up using current configuration */
6596 qlnx_set_link(ha, true);
6597
6598 ha->state = QLNX_STATE_OPEN;
6599
6600 bzero(&ha->hw_stats, sizeof(struct ecore_eth_stats));
6601
6602 if (ha->flags.callout_init)
6603 callout_reset(&ha->qlnx_callout, hz, qlnx_timer, ha);
6604
6605 goto qlnx_load_exit0;
6606
6607qlnx_load_exit2:
6608 qlnx_free_mem_load(ha);
6609
6610qlnx_load_exit1:
6611 ha->num_rss = 0;
6612
6613qlnx_load_exit0:
6614 QL_DPRINT2(ha, "exit [%d]\n", rc);
6615 return rc;
6616}
6617
6618static void
6619qlnx_drain_soft_lro(qlnx_host_t *ha)
6620{
6621#ifdef QLNX_SOFT_LRO
6622
6623 struct ifnet *ifp;
6624 int i;
6625
6626 ifp = ha->ifp;
6627
6628
6629 if (ifp->if_capenable & IFCAP_LRO) {
6630
6631 for (i = 0; i < ha->num_rss; i++) {
6632
6633 struct qlnx_fastpath *fp = &ha->fp_array[i];
6634 struct lro_ctrl *lro;
6635
6636 lro = &fp->rxq->lro;
6637
6638#if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO)
6639
6640 tcp_lro_flush_all(lro);
6641
6642#else
6643 struct lro_entry *queued;
6644
6645 while ((!SLIST_EMPTY(&lro->lro_active))){
6646 queued = SLIST_FIRST(&lro->lro_active);
6647 SLIST_REMOVE_HEAD(&lro->lro_active, next);
6648 tcp_lro_flush(lro, queued);
6649 }
6650
6651#endif /* #if (__FreeBSD_version >= 1100101) || (defined QLNX_QSORT_LRO) */
6652
6653 }
6654 }
6655
6656#endif /* #ifdef QLNX_SOFT_LRO */
6657
6658 return;
6659}
6660
6661static void
6662qlnx_unload(qlnx_host_t *ha)
6663{
6664 struct ecore_dev *cdev;
6665 device_t dev;
6666 int i;
6667
6668 cdev = &ha->cdev;
6669 dev = ha->pci_dev;
6670
6671 QL_DPRINT2(ha, "enter\n");
6672 QL_DPRINT1(ha, " QLNX STATE = %d\n",ha->state);
6673
6674 if (ha->state == QLNX_STATE_OPEN) {
6675
6676 qlnx_set_link(ha, false);
6677 qlnx_clean_filters(ha);
6678 qlnx_stop_queues(ha);
6679 ecore_hw_stop_fastpath(cdev);
6680
6681 for (i = 0; i < ha->num_rss; i++) {
6682 if (ha->irq_vec[i].handle) {
6683 (void)bus_teardown_intr(dev,
6684 ha->irq_vec[i].irq,
6685 ha->irq_vec[i].handle);
6686 ha->irq_vec[i].handle = NULL;
6687 }
6688 }
6689
6690 qlnx_drain_fp_taskqueues(ha);
6691 qlnx_drain_soft_lro(ha);
6692 qlnx_free_mem_load(ha);
6693 }
6694
6695 if (ha->flags.callout_init)
6696 callout_drain(&ha->qlnx_callout);
6697
6698 qlnx_mdelay(__func__, 1000);
6699
6700 ha->state = QLNX_STATE_CLOSED;
6701
6702 QL_DPRINT2(ha, "exit\n");
6703 return;
6704}
6705
6706static int
6707qlnx_grc_dumpsize(qlnx_host_t *ha, uint32_t *num_dwords, int hwfn_index)
6708{
6709 int rval = -1;
6710 struct ecore_hwfn *p_hwfn;
6711 struct ecore_ptt *p_ptt;
6712
6713 ecore_dbg_set_app_ver(ecore_dbg_get_fw_func_ver());
6714
6715 p_hwfn = &ha->cdev.hwfns[hwfn_index];
6716 p_ptt = ecore_ptt_acquire(p_hwfn);
6717
6718 if (!p_ptt) {
6719 QL_DPRINT1(ha, "ecore_ptt_acquire failed\n");
6720 return (rval);
6721 }
6722
6723 rval = ecore_dbg_grc_get_dump_buf_size(p_hwfn, p_ptt, num_dwords);
6724
6725 if (rval == DBG_STATUS_OK)
6726 rval = 0;
6727 else {
6728 QL_DPRINT1(ha, "ecore_dbg_grc_get_dump_buf_size failed"
6729 "[0x%x]\n", rval);
6730 }
6731
6732 ecore_ptt_release(p_hwfn, p_ptt);
6733
6734 return (rval);
6735}
6736
6737static int
6738qlnx_idle_chk_size(qlnx_host_t *ha, uint32_t *num_dwords, int hwfn_index)
6739{
6740 int rval = -1;
6741 struct ecore_hwfn *p_hwfn;
6742 struct ecore_ptt *p_ptt;
6743
6744 ecore_dbg_set_app_ver(ecore_dbg_get_fw_func_ver());
6745
6746 p_hwfn = &ha->cdev.hwfns[hwfn_index];
6747 p_ptt = ecore_ptt_acquire(p_hwfn);
6748
6749 if (!p_ptt) {
6750 QL_DPRINT1(ha, "ecore_ptt_acquire failed\n");
6751 return (rval);
6752 }
6753
6754 rval = ecore_dbg_idle_chk_get_dump_buf_size(p_hwfn, p_ptt, num_dwords);
6755
6756 if (rval == DBG_STATUS_OK)
6757 rval = 0;
6758 else {
6759 QL_DPRINT1(ha, "ecore_dbg_idle_chk_get_dump_buf_size failed"
6760 " [0x%x]\n", rval);
6761 }
6762
6763 ecore_ptt_release(p_hwfn, p_ptt);
6764
6765 return (rval);
6766}
6767
6768
6769static void
6770qlnx_sample_storm_stats(qlnx_host_t *ha)
6771{
6772 int i, index;
6773 struct ecore_dev *cdev;
6774 qlnx_storm_stats_t *s_stats;
6775 uint32_t reg;
6776 struct ecore_ptt *p_ptt;
6777 struct ecore_hwfn *hwfn;
6778
6779 if (ha->storm_stats_index >= QLNX_STORM_STATS_SAMPLES_PER_HWFN) {
6780 ha->storm_stats_enable = 0;
6781 return;
6782 }
6783
6784 cdev = &ha->cdev;
6785
6786 for_each_hwfn(cdev, i) {
6787
6788 hwfn = &cdev->hwfns[i];
6789
6790 p_ptt = ecore_ptt_acquire(hwfn);
6791 if (!p_ptt)
6792 return;
6793
6794 index = ha->storm_stats_index +
6795 (i * QLNX_STORM_STATS_SAMPLES_PER_HWFN);
6796
6797 s_stats = &ha->storm_stats[index];
6798
6799 /* XSTORM */
6800 reg = XSEM_REG_FAST_MEMORY +
6801 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6802 s_stats->xstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6803
6804 reg = XSEM_REG_FAST_MEMORY +
6805 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6806 s_stats->xstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6807
6808 reg = XSEM_REG_FAST_MEMORY +
6809 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6810 s_stats->xstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6811
6812 reg = XSEM_REG_FAST_MEMORY +
6813 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6814 s_stats->xstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6815
6816 /* YSTORM */
6817 reg = YSEM_REG_FAST_MEMORY +
6818 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6819 s_stats->ystorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6820
6821 reg = YSEM_REG_FAST_MEMORY +
6822 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6823 s_stats->ystorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6824
6825 reg = YSEM_REG_FAST_MEMORY +
6826 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6827 s_stats->ystorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6828
6829 reg = YSEM_REG_FAST_MEMORY +
6830 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6831 s_stats->ystorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6832
6833 /* PSTORM */
6834 reg = PSEM_REG_FAST_MEMORY +
6835 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6836 s_stats->pstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6837
6838 reg = PSEM_REG_FAST_MEMORY +
6839 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6840 s_stats->pstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6841
6842 reg = PSEM_REG_FAST_MEMORY +
6843 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6844 s_stats->pstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6845
6846 reg = PSEM_REG_FAST_MEMORY +
6847 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6848 s_stats->pstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6849
6850 /* TSTORM */
6851 reg = TSEM_REG_FAST_MEMORY +
6852 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6853 s_stats->tstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6854
6855 reg = TSEM_REG_FAST_MEMORY +
6856 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6857 s_stats->tstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6858
6859 reg = TSEM_REG_FAST_MEMORY +
6860 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6861 s_stats->tstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6862
6863 reg = TSEM_REG_FAST_MEMORY +
6864 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6865 s_stats->tstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6866
6867 /* MSTORM */
6868 reg = MSEM_REG_FAST_MEMORY +
6869 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6870 s_stats->mstorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6871
6872 reg = MSEM_REG_FAST_MEMORY +
6873 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6874 s_stats->mstorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6875
6876 reg = MSEM_REG_FAST_MEMORY +
6877 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6878 s_stats->mstorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6879
6880 reg = MSEM_REG_FAST_MEMORY +
6881 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6882 s_stats->mstorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6883
6884 /* USTORM */
6885 reg = USEM_REG_FAST_MEMORY +
6886 SEM_FAST_REG_STORM_ACTIVE_CYCLES_BB_K2;
6887 s_stats->ustorm_active_cycles = ecore_rd(hwfn, p_ptt, reg);
6888
6889 reg = USEM_REG_FAST_MEMORY +
6890 SEM_FAST_REG_STORM_STALL_CYCLES_BB_K2;
6891 s_stats->ustorm_stall_cycles = ecore_rd(hwfn, p_ptt, reg);
6892
6893 reg = USEM_REG_FAST_MEMORY +
6894 SEM_FAST_REG_IDLE_SLEEPING_CYCLES_BB_K2;
6895 s_stats->ustorm_sleeping_cycles = ecore_rd(hwfn, p_ptt, reg);
6896
6897 reg = USEM_REG_FAST_MEMORY +
6898 SEM_FAST_REG_IDLE_INACTIVE_CYCLES_BB_K2;
6899 s_stats->ustorm_inactive_cycles = ecore_rd(hwfn, p_ptt, reg);
6900
6901 ecore_ptt_release(hwfn, p_ptt);
6902 }
6903
6904 ha->storm_stats_index++;
6905
6906 return;
6907}
6908
6909/*
6910 * Name: qlnx_dump_buf8
6911 * Function: dumps a buffer as bytes
6912 */
6913static void
6914qlnx_dump_buf8(qlnx_host_t *ha, const char *msg, void *dbuf, uint32_t len)
6915{
6916 device_t dev;
6917 uint32_t i = 0;
6918 uint8_t *buf;
6919
6920 dev = ha->pci_dev;
6921 buf = dbuf;
6922
6923 device_printf(dev, "%s: %s 0x%x dump start\n", __func__, msg, len);
6924
6925 while (len >= 16) {
6926 device_printf(dev,"0x%08x:"
6927 " %02x %02x %02x %02x %02x %02x %02x %02x"
6928 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
6929 buf[0], buf[1], buf[2], buf[3],
6930 buf[4], buf[5], buf[6], buf[7],
6931 buf[8], buf[9], buf[10], buf[11],
6932 buf[12], buf[13], buf[14], buf[15]);
6933 i += 16;
6934 len -= 16;
6935 buf += 16;
6936 }
6937 switch (len) {
6938 case 1:
6939 device_printf(dev,"0x%08x: %02x\n", i, buf[0]);
6940 break;
6941 case 2:
6942 device_printf(dev,"0x%08x: %02x %02x\n", i, buf[0], buf[1]);
6943 break;
6944 case 3:
6945 device_printf(dev,"0x%08x: %02x %02x %02x\n",
6946 i, buf[0], buf[1], buf[2]);
6947 break;
6948 case 4:
6949 device_printf(dev,"0x%08x: %02x %02x %02x %02x\n", i,
6950 buf[0], buf[1], buf[2], buf[3]);
6951 break;
6952 case 5:
6953 device_printf(dev,"0x%08x:"
6954 " %02x %02x %02x %02x %02x\n", i,
6955 buf[0], buf[1], buf[2], buf[3], buf[4]);
6956 break;
6957 case 6:
6958 device_printf(dev,"0x%08x:"
6959 " %02x %02x %02x %02x %02x %02x\n", i,
6960 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
6961 break;
6962 case 7:
6963 device_printf(dev,"0x%08x:"
6964 " %02x %02x %02x %02x %02x %02x %02x\n", i,
6965 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
6966 break;
6967 case 8:
6968 device_printf(dev,"0x%08x:"
6969 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
6970 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6971 buf[7]);
6972 break;
6973 case 9:
6974 device_printf(dev,"0x%08x:"
6975 " %02x %02x %02x %02x %02x %02x %02x %02x"
6976 " %02x\n", i,
6977 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6978 buf[7], buf[8]);
6979 break;
6980 case 10:
6981 device_printf(dev,"0x%08x:"
6982 " %02x %02x %02x %02x %02x %02x %02x %02x"
6983 " %02x %02x\n", i,
6984 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6985 buf[7], buf[8], buf[9]);
6986 break;
6987 case 11:
6988 device_printf(dev,"0x%08x:"
6989 " %02x %02x %02x %02x %02x %02x %02x %02x"
6990 " %02x %02x %02x\n", i,
6991 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6992 buf[7], buf[8], buf[9], buf[10]);
6993 break;
6994 case 12:
6995 device_printf(dev,"0x%08x:"
6996 " %02x %02x %02x %02x %02x %02x %02x %02x"
6997 " %02x %02x %02x %02x\n", i,
6998 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
6999 buf[7], buf[8], buf[9], buf[10], buf[11]);
7000 break;
7001 case 13:
7002 device_printf(dev,"0x%08x:"
7003 " %02x %02x %02x %02x %02x %02x %02x %02x"
7004 " %02x %02x %02x %02x %02x\n", i,
7005 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
7006 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
7007 break;
7008 case 14:
7009 device_printf(dev,"0x%08x:"
7010 " %02x %02x %02x %02x %02x %02x %02x %02x"
7011 " %02x %02x %02x %02x %02x %02x\n", i,
7012 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
7013 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
7014 buf[13]);
7015 break;
7016 case 15:
7017 device_printf(dev,"0x%08x:"
7018 " %02x %02x %02x %02x %02x %02x %02x %02x"
7019 " %02x %02x %02x %02x %02x %02x %02x\n", i,
7020 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
7021 buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
7022 buf[13], buf[14]);
7023 break;
7024 default:
7025 break;
7026 }
7027
7028 device_printf(dev, "%s: %s dump end\n", __func__, msg);
7029
7030 return;
7031}
7032