xref: /dragonfly/sys/dev/netif/oce/oce_if.h (revision 31524921)
1 /*-
2  * Copyright (C) 2013 Emulex
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 are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  *
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  * 3. Neither the name of the Emulex Corporation nor the names of its
16  *    contributors may be used to endorse or promote products derived from
17  *    this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Contact Information:
32  * freebsd-drivers@emulex.com
33  *
34  * Emulex
35  * 3333 Susan Street
36  * Costa Mesa, CA 92626
37  */
38 
39 
40 /* $FreeBSD: src/sys/dev/oce/oce_if.h,v 1.6 2013/07/07 00:30:13 svnexp Exp $ */
41 
42 #include <sys/param.h>
43 #include <sys/endian.h>
44 #include <sys/module.h>
45 #include <sys/kernel.h>
46 #include <sys/bus.h>
47 #include <sys/mbuf.h>
48 #include <sys/rman.h>
49 #include <sys/socket.h>
50 #include <sys/sockio.h>
51 #include <sys/queue.h>
52 #include <sys/taskqueue.h>
53 #include <sys/lock.h>
54 #include <sys/sysctl.h>
55 #include <sys/random.h>
56 #include <sys/firmware.h>
57 #include <sys/systm.h>
58 #include <sys/proc.h>
59 
60 #include <bus/pci/pcireg.h>
61 #include <bus/pci/pcivar.h>
62 
63 #include <net/bpf.h>
64 #include <net/ethernet.h>
65 #include <net/if.h>
66 #include <net/if_types.h>
67 #include <net/if_media.h>
68 #include <net/ifq_var.h>
69 #include <net/vlan/if_vlan_ether.h>
70 #include <net/vlan/if_vlan_var.h>
71 #include <net/if_dl.h>
72 
73 #include <netinet/in.h>
74 #include <netinet/in_systm.h>
75 #include <netinet/in_var.h>
76 #include <netinet/if_ether.h>
77 #include <netinet/ip.h>
78 #include <netinet/ip6.h>
79 #include <netinet6/in6_var.h>
80 #include <netinet6/ip6_mroute.h>
81 
82 #include <netinet/udp.h>
83 #include <netinet/tcp.h>
84 #if 0 /* XXX swildner: LRO */
85 #include <netinet/tcp_lro.h>
86 #endif
87 
88 #include "oce_hw.h"
89 
90 #define COMPONENT_REVISION "4.6.95.0"
91 
92 /* OCE devices supported by this driver */
93 #define PCI_VENDOR_EMULEX		0x10df	/* Emulex */
94 #define PCI_VENDOR_SERVERENGINES	0x19a2	/* ServerEngines (BE) */
95 #define PCI_PRODUCT_BE2			0x0700	/* BE2 network adapter */
96 #define PCI_PRODUCT_BE3			0x0710	/* BE3 network adapter */
97 #define PCI_PRODUCT_XE201		0xe220	/* XE201 network adapter */
98 #define PCI_PRODUCT_XE201_VF		0xe228	/* XE201 with VF in Lancer */
99 #define PCI_PRODUCT_SH			0x0720	/* Skyhawk network adapter */
100 
101 #define IS_BE(sc)	(((sc->flags & OCE_FLAGS_BE3) | \
102 			 (sc->flags & OCE_FLAGS_BE2))? 1:0)
103 #define IS_BE3(sc)	(sc->flags & OCE_FLAGS_BE3)
104 #define IS_BE2(sc)	(sc->flags & OCE_FLAGS_BE2)
105 #define IS_XE201(sc)	((sc->flags & OCE_FLAGS_XE201) ? 1:0)
106 #define HAS_A0_CHIP(sc)	((sc->flags & OCE_FLAGS_HAS_A0_CHIP) ? 1:0)
107 #define IS_SH(sc)	((sc->flags & OCE_FLAGS_SH) ? 1 : 0)
108 
109 #define is_be_mode_mc(sc)	((sc->function_mode & FNM_FLEX10_MODE) ||	\
110 				(sc->function_mode & FNM_UMC_MODE)    ||	\
111 				(sc->function_mode & FNM_VNIC_MODE))
112 #define OCE_FUNCTION_CAPS_SUPER_NIC	0x40
113 #define IS_PROFILE_SUPER_NIC(sc) (sc->function_caps & OCE_FUNCTION_CAPS_SUPER_NIC)
114 
115 
116 /* proportion Service Level Interface queues */
117 #define OCE_MAX_UNITS			2
118 #define OCE_MAX_PPORT			OCE_MAX_UNITS
119 #define OCE_MAX_VPORT			OCE_MAX_UNITS
120 
121 #define OCE_NCPUS			ncpus
122 
123 /* This should be powers of 2. Like 2,4,8 & 16 */
124 #define OCE_MAX_RSS			8
125 #define OCE_LEGACY_MODE_RSS		4 /* For BE3 Legacy mode*/
126 #if 0 /* XXX swildner: RSS */
127 #define is_rss_enabled(sc)		((sc->function_caps & FNC_RSS) && !is_be_mode_mc(sc))
128 #else
129 #define is_rss_enabled(sc)		0
130 #endif
131 
132 #define OCE_MIN_RQ			1
133 #define OCE_MIN_WQ			1
134 
135 #define OCE_MAX_RQ			OCE_MAX_RSS + 1 /* one default queue */
136 #define OCE_MAX_WQ			8
137 
138 #define OCE_MAX_EQ			32
139 #define OCE_MAX_CQ			OCE_MAX_RQ + OCE_MAX_WQ + 1 /* one MCC queue */
140 #define OCE_MAX_CQ_EQ			8 /* Max CQ that can attached to an EQ */
141 
142 #define OCE_DEFAULT_WQ_EQD		16
143 #define OCE_MAX_PACKET_Q		16
144 #define OCE_RQ_BUF_SIZE			2048
145 #define OCE_LSO_MAX_SIZE		(64 * 1024)
146 #define LONG_TIMEOUT			30
147 #define OCE_MAX_JUMBO_FRAME_SIZE	9018
148 #define OCE_MAX_MTU			(OCE_MAX_JUMBO_FRAME_SIZE - \
149 						ETHER_VLAN_ENCAP_LEN - \
150 						ETHER_HDR_LEN)
151 
152 #define OCE_MAX_TX_ELEMENTS		29
153 #define OCE_MAX_TX_DESC			1024
154 #define OCE_MAX_TX_SIZE			65535
155 #define OCE_MAX_RX_SIZE			4096
156 #define OCE_MAX_RQ_POSTS		255
157 #define OCE_DEFAULT_PROMISCUOUS		0
158 
159 
160 #define RSS_ENABLE_IPV4			0x1
161 #define RSS_ENABLE_TCP_IPV4		0x2
162 #define RSS_ENABLE_IPV6			0x4
163 #define RSS_ENABLE_TCP_IPV6		0x8
164 
165 #define INDIRECTION_TABLE_ENTRIES	128
166 
167 /* flow control definitions */
168 #define OCE_FC_NONE			0x00000000
169 #define OCE_FC_TX			0x00000001
170 #define OCE_FC_RX			0x00000002
171 #define OCE_DEFAULT_FLOW_CONTROL	(OCE_FC_TX | OCE_FC_RX)
172 
173 
174 /* Interface capabilities to give device when creating interface */
175 #define  OCE_CAPAB_FLAGS 		(MBX_RX_IFACE_FLAGS_BROADCAST    | \
176 					MBX_RX_IFACE_FLAGS_UNTAGGED      | \
177 					MBX_RX_IFACE_FLAGS_PROMISCUOUS      | \
178 					MBX_RX_IFACE_FLAGS_MCAST_PROMISCUOUS   | \
179 					MBX_RX_IFACE_FLAGS_RSS | \
180 					MBX_RX_IFACE_FLAGS_PASS_L3L4_ERR)
181 
182 /* Interface capabilities to enable by default (others set dynamically) */
183 #define  OCE_CAPAB_ENABLE		(MBX_RX_IFACE_FLAGS_BROADCAST | \
184 					MBX_RX_IFACE_FLAGS_UNTAGGED   | \
185 					MBX_RX_IFACE_FLAGS_PASS_L3L4_ERR)
186 
187 #define OCE_IF_HWASSIST			(CSUM_IP | CSUM_TCP | CSUM_UDP)
188 #define OCE_IF_CAPABILITIES		(IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING | \
189 					IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM | \
190 					IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU)
191 #define OCE_IF_HWASSIST_NONE		0
192 #define OCE_IF_CAPABILITIES_NONE 	0
193 
194 
195 #define ETH_ADDR_LEN			6
196 #define MAX_VLANFILTER_SIZE		64
197 #define MAX_VLANS			4096
198 
199 #define upper_32_bits(n)		((uint32_t)(((n) >> 16) >> 16))
200 #define BSWAP_8(x)			((x) & 0xff)
201 #define BSWAP_16(x)			((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
202 #define BSWAP_32(x)			((BSWAP_16(x) << 16) | \
203 					 BSWAP_16((x) >> 16))
204 #define BSWAP_64(x)			((BSWAP_32(x) << 32) | \
205 					BSWAP_32((x) >> 32))
206 
207 #define for_all_wq_queues(sc, wq, i) 	\
208 		for (i = 0, wq = sc->wq[0]; i < sc->nwqs; i++, wq = sc->wq[i])
209 #define for_all_rq_queues(sc, rq, i) 	\
210 		for (i = 0, rq = sc->rq[0]; i < sc->nrqs; i++, rq = sc->rq[i])
211 #define for_all_rss_queues(sc, rq, i) 	\
212 		for (i = 0, rq = sc->rq[i + 1]; i < (sc->nrqs - 1); \
213 		     i++, rq = sc->rq[i + 1])
214 #define for_all_evnt_queues(sc, eq, i) 	\
215 		for (i = 0, eq = sc->eq[0]; i < sc->neqs; i++, eq = sc->eq[i])
216 #define for_all_cq_queues(sc, cq, i) 	\
217 		for (i = 0, cq = sc->cq[0]; i < sc->ncqs; i++, cq = sc->cq[i])
218 
219 
220 /* Flash specific */
221 #define IOCTL_COOKIE			"SERVERENGINES CORP"
222 #define MAX_FLASH_COMP			32
223 
224 #define IMG_ISCSI			160
225 #define IMG_REDBOOT			224
226 #define IMG_BIOS			34
227 #define IMG_PXEBIOS			32
228 #define IMG_FCOEBIOS			33
229 #define IMG_ISCSI_BAK			176
230 #define IMG_FCOE			162
231 #define IMG_FCOE_BAK			178
232 #define IMG_NCSI			16
233 #define IMG_PHY				192
234 #define FLASHROM_OPER_FLASH		1
235 #define FLASHROM_OPER_SAVE		2
236 #define FLASHROM_OPER_REPORT		4
237 #define FLASHROM_OPER_FLASH_PHY		9
238 #define FLASHROM_OPER_SAVE_PHY		10
239 #define TN_8022				13
240 
241 enum {
242 	PHY_TYPE_CX4_10GB = 0,
243 	PHY_TYPE_XFP_10GB,
244 	PHY_TYPE_SFP_1GB,
245 	PHY_TYPE_SFP_PLUS_10GB,
246 	PHY_TYPE_KR_10GB,
247 	PHY_TYPE_KX4_10GB,
248 	PHY_TYPE_BASET_10GB,
249 	PHY_TYPE_BASET_1GB,
250 	PHY_TYPE_BASEX_1GB,
251 	PHY_TYPE_SGMII,
252 	PHY_TYPE_DISABLED = 255
253 };
254 
255 /**
256  * @brief Define and hold all necessary info for a single interrupt
257  */
258 #define OCE_MAX_MSI			32 /* Message Signaled Interrupts */
259 #define OCE_MAX_MSIX			2048 /* PCI Express MSI Interrrupts */
260 
261 typedef struct oce_intr_info {
262 	void *tag;		/* cookie returned by bus_setup_intr */
263 	struct resource *intr_res;	/* PCI resource container */
264 	int irq_rr;		/* resource id for the interrupt */
265 	int irq_type;		/* interrupt type */
266 	struct oce_softc *sc;	/* pointer to the parent soft c */
267 	struct oce_eq *eq;	/* pointer to the connected EQ */
268 	struct taskqueue *tq;	/* Associated task queue */
269 	struct task task;	/* task queue task */
270 	char task_name[32];	/* task name */
271 	int vector;		/* interrupt vector number */
272 } OCE_INTR_INFO, *POCE_INTR_INFO;
273 
274 
275 /* Ring related */
276 #define	GET_Q_NEXT(_START, _STEP, _END)	\
277 	(((_START) + (_STEP)) < (_END) ? ((_START) + (_STEP)) \
278 	: (((_START) + (_STEP)) - (_END)))
279 
280 #define	DBUF_PA(obj)			((obj)->addr)
281 #define	DBUF_VA(obj) 			((obj)->ptr)
282 #define	DBUF_TAG(obj) 			((obj)->tag)
283 #define	DBUF_MAP(obj) 			((obj)->map)
284 #define	DBUF_SYNC(obj, flags) 		\
285 		(void) bus_dmamap_sync(DBUF_TAG(obj), DBUF_MAP(obj), (flags))
286 
287 #define	RING_NUM_PENDING(ring)		ring->num_used
288 #define	RING_FULL(ring) 		(ring->num_used == ring->num_items)
289 #define	RING_EMPTY(ring) 		(ring->num_used == 0)
290 #define	RING_NUM_FREE(ring)		\
291 		(uint32_t)(ring->num_items - ring->num_used)
292 #define	RING_GET(ring, n)		\
293 		ring->cidx = GET_Q_NEXT(ring->cidx, n, ring->num_items)
294 #define	RING_PUT(ring, n)		\
295 		ring->pidx = GET_Q_NEXT(ring->pidx, n, ring->num_items)
296 
297 #define	RING_GET_CONSUMER_ITEM_VA(ring, type) 	\
298 	(void*)((type *)DBUF_VA(&ring->dma) + ring->cidx)
299 #define	RING_GET_CONSUMER_ITEM_PA(ring, type)		\
300 	(uint64_t)(((type *)DBUF_PA(ring->dbuf)) + ring->cidx)
301 #define	RING_GET_PRODUCER_ITEM_VA(ring, type)		\
302 	(void *)(((type *)DBUF_VA(&ring->dma)) + ring->pidx)
303 #define	RING_GET_PRODUCER_ITEM_PA(ring, type)		\
304 	(uint64_t)(((type *)DBUF_PA(ring->dbuf)) + ring->pidx)
305 
306 #define OCE_DMAPTR(o, c) 		((c *)(o)->ptr)
307 
308 struct oce_packet_desc {
309 	struct mbuf *mbuf;
310 	bus_dmamap_t map;
311 	int nsegs;
312 	uint32_t wqe_idx;
313 };
314 
315 typedef struct oce_dma_mem {
316 	bus_dma_tag_t tag;
317 	bus_dmamap_t map;
318 	void *ptr;
319 	bus_addr_t paddr;
320 } OCE_DMA_MEM, *POCE_DMA_MEM;
321 
322 typedef struct oce_ring_buffer_s {
323 	uint16_t cidx;	/* Get ptr */
324 	uint16_t pidx;	/* Put Ptr */
325 	size_t item_size;
326 	size_t num_items;
327 	uint32_t num_used;
328 	OCE_DMA_MEM dma;
329 } oce_ring_buffer_t;
330 
331 /* Stats */
332 #define OCE_UNICAST_PACKET	0
333 #define OCE_MULTICAST_PACKET	1
334 #define OCE_BROADCAST_PACKET	2
335 #define OCE_RSVD_PACKET		3
336 
337 struct oce_rx_stats {
338 	/* Total Receive Stats*/
339 	uint64_t t_rx_pkts;
340 	uint64_t t_rx_bytes;
341 	uint32_t t_rx_frags;
342 	uint32_t t_rx_mcast_pkts;
343 	uint32_t t_rx_ucast_pkts;
344 	uint32_t t_rxcp_errs;
345 };
346 struct oce_tx_stats {
347 	/*Total Transmit Stats */
348 	uint64_t t_tx_pkts;
349 	uint64_t t_tx_bytes;
350 	uint32_t t_tx_reqs;
351 	uint32_t t_tx_stops;
352 	uint32_t t_tx_wrbs;
353 	uint32_t t_tx_compl;
354 	uint32_t t_ipv6_ext_hdr_tx_drop;
355 };
356 
357 struct oce_be_stats {
358 	uint8_t  be_on_die_temperature;
359 	uint32_t be_tx_events;
360 	uint32_t eth_red_drops;
361 	uint32_t rx_drops_no_pbuf;
362 	uint32_t rx_drops_no_txpb;
363 	uint32_t rx_drops_no_erx_descr;
364 	uint32_t rx_drops_no_tpre_descr;
365 	uint32_t rx_drops_too_many_frags;
366 	uint32_t rx_drops_invalid_ring;
367 	uint32_t forwarded_packets;
368 	uint32_t rx_drops_mtu;
369 	uint32_t rx_crc_errors;
370 	uint32_t rx_alignment_symbol_errors;
371 	uint32_t rx_pause_frames;
372 	uint32_t rx_priority_pause_frames;
373 	uint32_t rx_control_frames;
374 	uint32_t rx_in_range_errors;
375 	uint32_t rx_out_range_errors;
376 	uint32_t rx_frame_too_long;
377 	uint32_t rx_address_match_errors;
378 	uint32_t rx_dropped_too_small;
379 	uint32_t rx_dropped_too_short;
380 	uint32_t rx_dropped_header_too_small;
381 	uint32_t rx_dropped_tcp_length;
382 	uint32_t rx_dropped_runt;
383 	uint32_t rx_ip_checksum_errs;
384 	uint32_t rx_tcp_checksum_errs;
385 	uint32_t rx_udp_checksum_errs;
386 	uint32_t rx_switched_unicast_packets;
387 	uint32_t rx_switched_multicast_packets;
388 	uint32_t rx_switched_broadcast_packets;
389 	uint32_t tx_pauseframes;
390 	uint32_t tx_priority_pauseframes;
391 	uint32_t tx_controlframes;
392 	uint32_t rxpp_fifo_overflow_drop;
393 	uint32_t rx_input_fifo_overflow_drop;
394 	uint32_t pmem_fifo_overflow_drop;
395 	uint32_t jabber_events;
396 };
397 
398 struct oce_xe201_stats {
399 	uint64_t tx_pkts;
400 	uint64_t tx_unicast_pkts;
401 	uint64_t tx_multicast_pkts;
402 	uint64_t tx_broadcast_pkts;
403 	uint64_t tx_bytes;
404 	uint64_t tx_unicast_bytes;
405 	uint64_t tx_multicast_bytes;
406 	uint64_t tx_broadcast_bytes;
407 	uint64_t tx_discards;
408 	uint64_t tx_errors;
409 	uint64_t tx_pause_frames;
410 	uint64_t tx_pause_on_frames;
411 	uint64_t tx_pause_off_frames;
412 	uint64_t tx_internal_mac_errors;
413 	uint64_t tx_control_frames;
414 	uint64_t tx_pkts_64_bytes;
415 	uint64_t tx_pkts_65_to_127_bytes;
416 	uint64_t tx_pkts_128_to_255_bytes;
417 	uint64_t tx_pkts_256_to_511_bytes;
418 	uint64_t tx_pkts_512_to_1023_bytes;
419 	uint64_t tx_pkts_1024_to_1518_bytes;
420 	uint64_t tx_pkts_1519_to_2047_bytes;
421 	uint64_t tx_pkts_2048_to_4095_bytes;
422 	uint64_t tx_pkts_4096_to_8191_bytes;
423 	uint64_t tx_pkts_8192_to_9216_bytes;
424 	uint64_t tx_lso_pkts;
425 	uint64_t rx_pkts;
426 	uint64_t rx_unicast_pkts;
427 	uint64_t rx_multicast_pkts;
428 	uint64_t rx_broadcast_pkts;
429 	uint64_t rx_bytes;
430 	uint64_t rx_unicast_bytes;
431 	uint64_t rx_multicast_bytes;
432 	uint64_t rx_broadcast_bytes;
433 	uint32_t rx_unknown_protos;
434 	uint64_t rx_discards;
435 	uint64_t rx_errors;
436 	uint64_t rx_crc_errors;
437 	uint64_t rx_alignment_errors;
438 	uint64_t rx_symbol_errors;
439 	uint64_t rx_pause_frames;
440 	uint64_t rx_pause_on_frames;
441 	uint64_t rx_pause_off_frames;
442 	uint64_t rx_frames_too_long;
443 	uint64_t rx_internal_mac_errors;
444 	uint32_t rx_undersize_pkts;
445 	uint32_t rx_oversize_pkts;
446 	uint32_t rx_fragment_pkts;
447 	uint32_t rx_jabbers;
448 	uint64_t rx_control_frames;
449 	uint64_t rx_control_frames_unknown_opcode;
450 	uint32_t rx_in_range_errors;
451 	uint32_t rx_out_of_range_errors;
452 	uint32_t rx_address_match_errors;
453 	uint32_t rx_vlan_mismatch_errors;
454 	uint32_t rx_dropped_too_small;
455 	uint32_t rx_dropped_too_short;
456 	uint32_t rx_dropped_header_too_small;
457 	uint32_t rx_dropped_invalid_tcp_length;
458 	uint32_t rx_dropped_runt;
459 	uint32_t rx_ip_checksum_errors;
460 	uint32_t rx_tcp_checksum_errors;
461 	uint32_t rx_udp_checksum_errors;
462 	uint32_t rx_non_rss_pkts;
463 	uint64_t rx_ipv4_pkts;
464 	uint64_t rx_ipv6_pkts;
465 	uint64_t rx_ipv4_bytes;
466 	uint64_t rx_ipv6_bytes;
467 	uint64_t rx_nic_pkts;
468 	uint64_t rx_tcp_pkts;
469 	uint64_t rx_iscsi_pkts;
470 	uint64_t rx_management_pkts;
471 	uint64_t rx_switched_unicast_pkts;
472 	uint64_t rx_switched_multicast_pkts;
473 	uint64_t rx_switched_broadcast_pkts;
474 	uint64_t num_forwards;
475 	uint32_t rx_fifo_overflow;
476 	uint32_t rx_input_fifo_overflow;
477 	uint64_t rx_drops_too_many_frags;
478 	uint32_t rx_drops_invalid_queue;
479 	uint64_t rx_drops_mtu;
480 	uint64_t rx_pkts_64_bytes;
481 	uint64_t rx_pkts_65_to_127_bytes;
482 	uint64_t rx_pkts_128_to_255_bytes;
483 	uint64_t rx_pkts_256_to_511_bytes;
484 	uint64_t rx_pkts_512_to_1023_bytes;
485 	uint64_t rx_pkts_1024_to_1518_bytes;
486 	uint64_t rx_pkts_1519_to_2047_bytes;
487 	uint64_t rx_pkts_2048_to_4095_bytes;
488 	uint64_t rx_pkts_4096_to_8191_bytes;
489 	uint64_t rx_pkts_8192_to_9216_bytes;
490 };
491 
492 struct oce_drv_stats {
493 	struct oce_rx_stats rx;
494 	struct oce_tx_stats tx;
495 	union {
496 		struct oce_be_stats be;
497 		struct oce_xe201_stats xe201;
498 	} u0;
499 };
500 
501 #define INTR_RATE_HWM                   15000
502 #define INTR_RATE_LWM                   10000
503 
504 #define OCE_MAX_EQD 128u
505 #define OCE_MIN_EQD 50u
506 
507 struct oce_set_eqd {
508 	uint32_t eq_id;
509 	uint32_t phase;
510 	uint32_t delay_multiplier;
511 };
512 
513 struct oce_aic_obj {             /* Adaptive interrupt coalescing (AIC) info */
514 	boolean_t enable;
515 	uint32_t  min_eqd;            /* in usecs */
516 	uint32_t  max_eqd;            /* in usecs */
517 	uint32_t  cur_eqd;            /* in usecs */
518 	uint32_t  et_eqd;             /* configured value when aic is off */
519 	uint64_t  ticks;
520 	uint64_t  intr_prev;
521 };
522 
523 #define MAX_LOCK_DESC_LEN			32
524 struct oce_lock {
525 	struct lock lock;
526 	char name[MAX_LOCK_DESC_LEN+1];
527 };
528 #define OCE_LOCK				struct oce_lock
529 
530 #define LOCK_CREATE(ocelock, desc) 		{ \
531 	strncpy((ocelock)->name, (desc), MAX_LOCK_DESC_LEN); \
532 	(ocelock)->name[MAX_LOCK_DESC_LEN] = '\0'; \
533 	lockinit(&(ocelock)->lock, (ocelock)->name, 0, LK_CANRECURSE); \
534 }
535 #define LOCK_DESTROY(ocelock) 			\
536 		/* if (mtx_initialized(&(lock)->mutex))	*/ \
537 			lockuninit(&(ocelock)->lock)
538 #define LOCK(ocelock)				lockmgr(&(ocelock)->lock, LK_EXCLUSIVE)
539 #define LOCKED(ocelock)				lockowned(&(ocelock)->lock)
540 #define UNLOCK(ocelock)				lockmgr(&(ocelock)->lock, LK_RELEASE)
541 
542 #define	DEFAULT_MQ_MBOX_TIMEOUT			(5 * 1000 * 1000)
543 #define	MBX_READY_TIMEOUT			(1 * 1000 * 1000)
544 #define	DEFAULT_DRAIN_TIME			200
545 #define	MBX_TIMEOUT_SEC				5
546 #define	STAT_TIMEOUT				2000000
547 
548 /* size of the packet descriptor array in a transmit queue */
549 #define OCE_TX_RING_SIZE			2048
550 #define OCE_RX_RING_SIZE			1024
551 #define OCE_WQ_PACKET_ARRAY_SIZE		(OCE_TX_RING_SIZE/2)
552 #define OCE_RQ_PACKET_ARRAY_SIZE		(OCE_RX_RING_SIZE)
553 
554 struct oce_dev;
555 
556 enum eq_len {
557 	EQ_LEN_256  = 256,
558 	EQ_LEN_512  = 512,
559 	EQ_LEN_1024 = 1024,
560 	EQ_LEN_2048 = 2048,
561 	EQ_LEN_4096 = 4096
562 };
563 
564 enum eqe_size {
565 	EQE_SIZE_4  = 4,
566 	EQE_SIZE_16 = 16
567 };
568 
569 enum qtype {
570 	QTYPE_EQ,
571 	QTYPE_MQ,
572 	QTYPE_WQ,
573 	QTYPE_RQ,
574 	QTYPE_CQ,
575 	QTYPE_RSS
576 };
577 
578 typedef enum qstate_e {
579 	QDELETED = 0x0,
580 	QCREATED = 0x1
581 } qstate_t;
582 
583 struct eq_config {
584 	enum eq_len q_len;
585 	enum eqe_size item_size;
586 	uint32_t q_vector_num;
587 	uint8_t min_eqd;
588 	uint8_t max_eqd;
589 	uint8_t cur_eqd;
590 	uint8_t pad;
591 };
592 
593 struct oce_eq {
594 	uint32_t eq_id;
595 	void *parent;
596 	void *cb_context;
597 	oce_ring_buffer_t *ring;
598 	uint32_t ref_count;
599 	qstate_t qstate;
600 	struct oce_cq *cq[OCE_MAX_CQ_EQ];
601 	int cq_valid;
602 	struct eq_config eq_cfg;
603 	int vector;
604 	uint64_t intr;
605 };
606 
607 enum cq_len {
608 	CQ_LEN_256  = 256,
609 	CQ_LEN_512  = 512,
610 	CQ_LEN_1024 = 1024
611 };
612 
613 struct cq_config {
614 	enum cq_len q_len;
615 	uint32_t item_size;
616 	boolean_t is_eventable;
617 	boolean_t sol_eventable;
618 	boolean_t nodelay;
619 	uint16_t dma_coalescing;
620 };
621 
622 typedef uint16_t(*cq_handler_t) (void *arg1);
623 
624 struct oce_cq {
625 	uint32_t cq_id;
626 	void *parent;
627 	struct oce_eq *eq;
628 	cq_handler_t cq_handler;
629 	void *cb_arg;
630 	oce_ring_buffer_t *ring;
631 	qstate_t qstate;
632 	struct cq_config cq_cfg;
633 	uint32_t ref_count;
634 };
635 
636 
637 struct mq_config {
638 	uint32_t eqd;
639 	uint8_t q_len;
640 	uint8_t pad[3];
641 };
642 
643 
644 struct oce_mq {
645 	void *parent;
646 	oce_ring_buffer_t *ring;
647 	uint32_t mq_id;
648 	struct oce_cq *cq;
649 	struct oce_cq *async_cq;
650 	uint32_t mq_free;
651 	qstate_t qstate;
652 	struct mq_config cfg;
653 };
654 
655 struct oce_mbx_ctx {
656 	struct oce_mbx *mbx;
657 	void (*cb) (void *ctx);
658 	void *cb_ctx;
659 };
660 
661 struct wq_config {
662 	uint8_t wq_type;
663 	uint16_t buf_size;
664 	uint8_t pad[1];
665 	uint32_t q_len;
666 	uint16_t pd_id;
667 	uint16_t pci_fn_num;
668 	uint32_t eqd;	/* interrupt delay */
669 	uint32_t nbufs;
670 	uint32_t nhdl;
671 };
672 
673 struct oce_tx_queue_stats {
674 	uint64_t tx_pkts;
675 	uint64_t tx_bytes;
676 	uint32_t tx_reqs;
677 	uint32_t tx_stops; /* number of times TX Q was stopped */
678 	uint32_t tx_wrbs;
679 	uint32_t tx_compl;
680 	uint32_t tx_rate;
681 	uint32_t ipv6_ext_hdr_tx_drop;
682 };
683 
684 struct oce_wq {
685 	OCE_LOCK tx_lock;
686 	void *parent;
687 	oce_ring_buffer_t *ring;
688 	struct oce_cq *cq;
689 	bus_dma_tag_t tag;
690 	struct oce_packet_desc pckts[OCE_WQ_PACKET_ARRAY_SIZE];
691 	uint32_t pkt_desc_tail;
692 	uint32_t pkt_desc_head;
693 	uint32_t wqm_used;
694 	boolean_t resched;
695 	uint32_t wq_free;
696 	uint32_t tx_deferd;
697 	uint32_t pkt_drops;
698 	qstate_t qstate;
699 	uint16_t wq_id;
700 	struct wq_config cfg;
701 	int queue_index;
702 	struct oce_tx_queue_stats tx_stats;
703 	struct buf_ring *br;
704 	struct task txtask;
705 	uint32_t db_offset;
706 };
707 
708 struct rq_config {
709 	uint32_t q_len;
710 	uint32_t frag_size;
711 	uint32_t mtu;
712 	uint32_t if_id;
713 	uint32_t is_rss_queue;
714 	uint32_t eqd;
715 	uint32_t nbufs;
716 };
717 
718 struct oce_rx_queue_stats {
719 	uint32_t rx_post_fail;
720 	uint32_t rx_ucast_pkts;
721 	uint32_t rx_compl;
722 	uint64_t rx_bytes;
723 	uint64_t rx_bytes_prev;
724 	uint64_t rx_pkts;
725 	uint32_t rx_rate;
726 	uint32_t rx_mcast_pkts;
727 	uint32_t rxcp_err;
728 	uint32_t rx_frags;
729 	uint32_t prev_rx_frags;
730 	uint32_t rx_fps;
731 };
732 
733 
734 struct oce_rq {
735 	struct rq_config cfg;
736 	uint32_t rq_id;
737 	int queue_index;
738 	uint32_t rss_cpuid;
739 	void *parent;
740 	oce_ring_buffer_t *ring;
741 	struct oce_cq *cq;
742 	void *pad1;
743 	bus_dma_tag_t tag;
744 	struct oce_packet_desc pckts[OCE_RQ_PACKET_ARRAY_SIZE];
745 	uint32_t packets_in;
746 	uint32_t packets_out;
747 	uint32_t pending;
748 #ifdef notdef
749 	struct mbuf *head;
750 	struct mbuf *tail;
751 	int fragsleft;
752 #endif
753 	qstate_t qstate;
754 	OCE_LOCK rx_lock;
755 	struct oce_rx_queue_stats rx_stats;
756 #if 0 /* XXX swildner: LRO */
757 	struct lro_ctrl lro;
758 	int lro_pkts_queued;
759 #endif
760 
761 };
762 
763 struct link_status {
764 	uint8_t physical_port;
765 	uint8_t mac_duplex;
766 	uint8_t mac_speed;
767 	uint8_t mac_fault;
768 	uint8_t mgmt_mac_duplex;
769 	uint8_t mgmt_mac_speed;
770 	uint16_t qos_link_speed;
771 	uint32_t logical_link_status;
772 };
773 
774 
775 
776 #define OCE_FLAGS_PCIX			0x00000001
777 #define OCE_FLAGS_PCIE			0x00000002
778 #define OCE_FLAGS_MSI_CAPABLE		0x00000004
779 #define OCE_FLAGS_MSIX_CAPABLE		0x00000008
780 #define OCE_FLAGS_USING_MSI		0x00000010
781 #define OCE_FLAGS_USING_MSIX		0x00000020
782 #define OCE_FLAGS_FUNCRESET_RQD		0x00000040
783 #define OCE_FLAGS_VIRTUAL_PORT		0x00000080
784 #define OCE_FLAGS_MBOX_ENDIAN_RQD	0x00000100
785 #define OCE_FLAGS_BE3			0x00000200
786 #define OCE_FLAGS_XE201			0x00000400
787 #define OCE_FLAGS_BE2			0x00000800
788 #define OCE_FLAGS_SH			0x00001000
789 
790 #define OCE_DEV_BE2_CFG_BAR		1
791 #define OCE_DEV_CFG_BAR			0
792 #define OCE_PCI_CSR_BAR			2
793 #define OCE_PCI_DB_BAR			4
794 
795 typedef struct oce_softc {
796 	device_t dev;
797 	OCE_LOCK dev_lock;
798 
799 	uint32_t flags;
800 
801 	uint32_t pcie_link_speed;
802 	uint32_t pcie_link_width;
803 
804 	uint8_t fn; /* PCI function number */
805 
806 	struct resource *devcfg_res;
807 	bus_space_tag_t devcfg_btag;
808 	bus_space_handle_t devcfg_bhandle;
809 	void *devcfg_vhandle;
810 
811 	struct resource *csr_res;
812 	bus_space_tag_t csr_btag;
813 	bus_space_handle_t csr_bhandle;
814 	void *csr_vhandle;
815 
816 	struct resource *db_res;
817 	bus_space_tag_t db_btag;
818 	bus_space_handle_t db_bhandle;
819 	void *db_vhandle;
820 
821 	OCE_INTR_INFO intrs[OCE_MAX_EQ];
822 	int intr_count;
823 
824 	struct ifnet *ifp;
825 
826 	struct ifmedia media;
827 	uint8_t link_status;
828 	uint8_t link_speed;
829 	uint8_t duplex;
830 	uint32_t qos_link_speed;
831 	uint32_t speed;
832 
833 	char fw_version[32];
834 	struct mac_address_format macaddr;
835 
836 	OCE_DMA_MEM bsmbx;
837 	OCE_LOCK bmbx_lock;
838 
839 	uint32_t config_number;
840 	uint32_t asic_revision;
841 	uint32_t port_id;
842 	uint32_t function_mode;
843 	uint32_t function_caps;
844 	uint32_t max_tx_rings;
845 	uint32_t max_rx_rings;
846 
847 	struct oce_wq *wq[OCE_MAX_WQ];	/* TX work queues */
848 	struct oce_rq *rq[OCE_MAX_RQ];	/* RX work queues */
849 	struct oce_cq *cq[OCE_MAX_CQ];	/* Completion queues */
850 	struct oce_eq *eq[OCE_MAX_EQ];	/* Event queues */
851 	struct oce_mq *mq;		/* Mailbox queue */
852 
853 	uint32_t neqs;
854 	uint32_t ncqs;
855 	uint32_t nrqs;
856 	uint32_t nwqs;
857 	uint32_t nrssqs;
858 
859 	uint32_t tx_ring_size;
860 	uint32_t rx_ring_size;
861 	uint32_t rq_frag_size;
862 
863 	uint32_t if_id;		/* interface ID */
864 	uint32_t nifs;		/* number of adapter interfaces, 0 or 1 */
865 	uint32_t pmac_id;	/* PMAC id */
866 
867 	uint32_t if_cap_flags;
868 
869 	uint32_t flow_control;
870 	uint32_t promisc;
871 
872 	struct oce_aic_obj aic_obj[OCE_MAX_EQ];
873 
874 	/*Vlan Filtering related */
875 	eventhandler_tag vlan_attach;
876 	eventhandler_tag vlan_detach;
877 	uint16_t vlans_added;
878 	uint8_t vlan_tag[MAX_VLANS];
879 	/*stats */
880 	OCE_DMA_MEM stats_mem;
881 	struct oce_drv_stats oce_stats_info;
882 	struct callout  timer;
883 	int8_t be3_native;
884 	uint16_t qnq_debug_event;
885 	uint16_t qnqid;
886 	uint16_t pvid;
887 
888 } OCE_SOFTC, *POCE_SOFTC;
889 
890 
891 
892 /**************************************************
893  * BUS memory read/write macros
894  * BE3: accesses three BAR spaces (CFG, CSR, DB)
895  * Lancer: accesses one BAR space (CFG)
896  **************************************************/
897 #define OCE_READ_CSR_MPU(sc, space, o) \
898 	((IS_BE(sc)) ? (bus_space_read_4((sc)->space##_btag, \
899 					(sc)->space##_bhandle,o)) \
900 				: (bus_space_read_4((sc)->devcfg_btag, \
901 					(sc)->devcfg_bhandle,o)))
902 #define OCE_READ_REG32(sc, space, o) \
903 	((IS_BE(sc) || IS_SH(sc)) ? (bus_space_read_4((sc)->space##_btag, \
904 					(sc)->space##_bhandle,o)) \
905 				: (bus_space_read_4((sc)->devcfg_btag, \
906 					(sc)->devcfg_bhandle,o)))
907 #define OCE_READ_REG16(sc, space, o) \
908 	((IS_BE(sc) || IS_SH(sc)) ? (bus_space_read_2((sc)->space##_btag, \
909 					(sc)->space##_bhandle,o)) \
910 				: (bus_space_read_2((sc)->devcfg_btag, \
911 					(sc)->devcfg_bhandle,o)))
912 #define OCE_READ_REG8(sc, space, o) \
913 	((IS_BE(sc) || IS_SH(sc)) ? (bus_space_read_1((sc)->space##_btag, \
914 					(sc)->space##_bhandle,o)) \
915 				: (bus_space_read_1((sc)->devcfg_btag, \
916 					(sc)->devcfg_bhandle,o)))
917 
918 #define OCE_WRITE_CSR_MPU(sc, space, o, v) \
919 	((IS_BE(sc)) ? (bus_space_write_4((sc)->space##_btag, \
920 				       (sc)->space##_bhandle,o,v)) \
921 				: (bus_space_write_4((sc)->devcfg_btag, \
922 					(sc)->devcfg_bhandle,o,v)))
923 #define OCE_WRITE_REG32(sc, space, o, v) \
924 	((IS_BE(sc) || IS_SH(sc)) ? (bus_space_write_4((sc)->space##_btag, \
925 				       (sc)->space##_bhandle,o,v)) \
926 				: (bus_space_write_4((sc)->devcfg_btag, \
927 					(sc)->devcfg_bhandle,o,v)))
928 #define OCE_WRITE_REG16(sc, space, o, v) \
929 	((IS_BE(sc) || IS_SH(sc)) ? (bus_space_write_2((sc)->space##_btag, \
930 				       (sc)->space##_bhandle,o,v)) \
931 				: (bus_space_write_2((sc)->devcfg_btag, \
932 					(sc)->devcfg_bhandle,o,v)))
933 #define OCE_WRITE_REG8(sc, space, o, v) \
934 	((IS_BE(sc) || IS_SH(sc)) ? (bus_space_write_1((sc)->space##_btag, \
935 				       (sc)->space##_bhandle,o,v)) \
936 				: (bus_space_write_1((sc)->devcfg_btag, \
937 					(sc)->devcfg_bhandle,o,v)))
938 
939 
940 /***********************************************************
941  * DMA memory functions
942  ***********************************************************/
943 #define oce_dma_sync(d, f)		bus_dmamap_sync((d)->tag, (d)->map, f)
944 int oce_dma_alloc(POCE_SOFTC sc, bus_size_t size, POCE_DMA_MEM dma, int flags);
945 void oce_dma_free(POCE_SOFTC sc, POCE_DMA_MEM dma);
946 void oce_dma_map_addr(void *arg, bus_dma_segment_t * segs, int nseg, int error);
947 void oce_destroy_ring_buffer(POCE_SOFTC sc, oce_ring_buffer_t *ring);
948 oce_ring_buffer_t *oce_create_ring_buffer(POCE_SOFTC sc,
949 					  uint32_t q_len, uint32_t num_entries);
950 /************************************************************
951  * oce_hw_xxx functions
952  ************************************************************/
953 int oce_clear_rx_buf(struct oce_rq *rq);
954 int oce_hw_pci_alloc(POCE_SOFTC sc);
955 int oce_hw_init(POCE_SOFTC sc);
956 int oce_hw_start(POCE_SOFTC sc);
957 int oce_create_nw_interface(POCE_SOFTC sc);
958 int oce_pci_soft_reset(POCE_SOFTC sc);
959 int oce_hw_update_multicast(POCE_SOFTC sc);
960 void oce_delete_nw_interface(POCE_SOFTC sc);
961 void oce_hw_shutdown(POCE_SOFTC sc);
962 void oce_hw_intr_enable(POCE_SOFTC sc);
963 void oce_hw_intr_disable(POCE_SOFTC sc);
964 void oce_hw_pci_free(POCE_SOFTC sc);
965 
966 /***********************************************************
967  * oce_queue_xxx functions
968  ***********************************************************/
969 int oce_queue_init_all(POCE_SOFTC sc);
970 int oce_start_rq(struct oce_rq *rq);
971 int oce_start_wq(struct oce_wq *wq);
972 int oce_start_mq(struct oce_mq *mq);
973 int oce_start_rx(POCE_SOFTC sc);
974 void oce_arm_eq(POCE_SOFTC sc,
975 		int16_t qid, int npopped, uint32_t rearm, uint32_t clearint);
976 void oce_queue_release_all(POCE_SOFTC sc);
977 void oce_arm_cq(POCE_SOFTC sc, int16_t qid, int npopped, uint32_t rearm);
978 void oce_drain_eq(struct oce_eq *eq);
979 void oce_drain_mq_cq(void *arg);
980 void oce_drain_rq_cq(struct oce_rq *rq);
981 void oce_drain_wq_cq(struct oce_wq *wq);
982 
983 uint32_t oce_page_list(oce_ring_buffer_t *ring, struct phys_addr *pa_list);
984 
985 /***********************************************************
986  * cleanup  functions
987  ***********************************************************/
988 void oce_stop_rx(POCE_SOFTC sc);
989 void oce_intr_free(POCE_SOFTC sc);
990 void oce_free_posted_rxbuf(struct oce_rq *rq);
991 #if defined(INET6) || defined(INET)
992 void oce_free_lro(POCE_SOFTC sc);
993 #endif
994 
995 
996 /************************************************************
997  * Mailbox functions
998  ************************************************************/
999 int oce_fw_clean(POCE_SOFTC sc);
1000 int oce_reset_fun(POCE_SOFTC sc);
1001 int oce_mbox_init(POCE_SOFTC sc);
1002 int oce_mbox_dispatch(POCE_SOFTC sc, uint32_t tmo_sec);
1003 int oce_get_fw_version(POCE_SOFTC sc);
1004 int oce_first_mcc_cmd(POCE_SOFTC sc);
1005 
1006 int oce_read_mac_addr(POCE_SOFTC sc, uint32_t if_id, uint8_t perm,
1007 			uint8_t type, struct mac_address_format *mac);
1008 int oce_get_fw_config(POCE_SOFTC sc);
1009 int oce_if_create(POCE_SOFTC sc, uint32_t cap_flags, uint32_t en_flags,
1010 		uint16_t vlan_tag, uint8_t *mac_addr, uint32_t *if_id);
1011 int oce_if_del(POCE_SOFTC sc, uint32_t if_id);
1012 int oce_config_vlan(POCE_SOFTC sc, uint32_t if_id,
1013 		struct normal_vlan *vtag_arr, uint8_t vtag_cnt,
1014 		uint32_t untagged, uint32_t enable_promisc);
1015 int oce_set_flow_control(POCE_SOFTC sc, uint32_t flow_control);
1016 int oce_config_nic_rss(POCE_SOFTC sc, uint32_t if_id, uint16_t enable_rss);
1017 int oce_rxf_set_promiscuous(POCE_SOFTC sc, uint32_t enable);
1018 int oce_set_common_iface_rx_filter(POCE_SOFTC sc, POCE_DMA_MEM sgl);
1019 int oce_get_link_status(POCE_SOFTC sc, struct link_status *link);
1020 int oce_mbox_get_nic_stats_v0(POCE_SOFTC sc, POCE_DMA_MEM pstats_dma_mem);
1021 int oce_mbox_get_nic_stats(POCE_SOFTC sc, POCE_DMA_MEM pstats_dma_mem);
1022 int oce_mbox_get_pport_stats(POCE_SOFTC sc, POCE_DMA_MEM pstats_dma_mem,
1023 				uint32_t reset_stats);
1024 int oce_mbox_get_vport_stats(POCE_SOFTC sc, POCE_DMA_MEM pstats_dma_mem,
1025 				uint32_t req_size, uint32_t reset_stats);
1026 int oce_update_multicast(POCE_SOFTC sc, POCE_DMA_MEM pdma_mem);
1027 int oce_pass_through_mbox(POCE_SOFTC sc, POCE_DMA_MEM dma_mem, uint32_t req_size);
1028 int oce_mbox_macaddr_del(POCE_SOFTC sc, uint32_t if_id, uint32_t pmac_id);
1029 int oce_mbox_macaddr_add(POCE_SOFTC sc, uint8_t *mac_addr,
1030 		uint32_t if_id, uint32_t *pmac_id);
1031 int oce_mbox_cmd_test_loopback(POCE_SOFTC sc, uint32_t port_num,
1032 	uint32_t loopback_type, uint32_t pkt_size, uint32_t num_pkts,
1033 	uint64_t pattern);
1034 
1035 int oce_mbox_cmd_set_loopback(POCE_SOFTC sc, uint8_t port_num,
1036 	uint8_t loopback_type, uint8_t enable);
1037 
1038 int oce_mbox_check_native_mode(POCE_SOFTC sc);
1039 int oce_mbox_post(POCE_SOFTC sc,
1040 		  struct oce_mbx *mbx, struct oce_mbx_ctx *mbxctx);
1041 int oce_mbox_write_flashrom(POCE_SOFTC sc, uint32_t optype,uint32_t opcode,
1042 				POCE_DMA_MEM pdma_mem, uint32_t num_bytes);
1043 int oce_mbox_lancer_write_flashrom(POCE_SOFTC sc, uint32_t data_size,
1044 			uint32_t data_offset,POCE_DMA_MEM pdma_mem,
1045 			uint32_t *written_data, uint32_t *additional_status);
1046 
1047 int oce_mbox_get_flashrom_crc(POCE_SOFTC sc, uint8_t *flash_crc,
1048 				uint32_t offset, uint32_t optype);
1049 int oce_mbox_get_phy_info(POCE_SOFTC sc, struct oce_phy_info *phy_info);
1050 int oce_mbox_create_rq(struct oce_rq *rq);
1051 int oce_mbox_create_wq(struct oce_wq *wq);
1052 int oce_mbox_create_eq(struct oce_eq *eq);
1053 int oce_mbox_cq_create(struct oce_cq *cq, uint32_t ncoalesce,
1054 			 uint32_t is_eventable);
1055 int oce_mbox_read_transrecv_data(POCE_SOFTC sc, uint32_t page_num);
1056 void oce_mbox_eqd_modify_periodic(POCE_SOFTC sc, struct oce_set_eqd *set_eqd,
1057 					int num);
1058 int oce_get_profile_config(POCE_SOFTC sc);
1059 int oce_get_func_config(POCE_SOFTC sc);
1060 void mbx_common_req_hdr_init(struct mbx_hdr *hdr,
1061 			     uint8_t dom,
1062 			     uint8_t port,
1063 			     uint8_t subsys,
1064 			     uint8_t opcode,
1065 			     uint32_t timeout, uint32_t pyld_len,
1066 			     uint8_t version);
1067 
1068 
1069 uint16_t oce_mq_handler(void *arg);
1070 
1071 /************************************************************
1072  * Transmit functions
1073  ************************************************************/
1074 uint16_t oce_wq_handler(void *arg);
1075 void	 oce_start_locked(struct ifnet *ifp);
1076 void	 oce_start(struct ifnet *ifp, struct ifaltq_subque *ifsq);
1077 void	 oce_tx_task(void *arg, int npending);
1078 
1079 /************************************************************
1080  * Receive functions
1081  ************************************************************/
1082 int	 oce_alloc_rx_bufs(struct oce_rq *rq, int count);
1083 uint16_t oce_rq_handler(void *arg);
1084 
1085 
1086 /* Sysctl functions */
1087 void oce_add_sysctls(POCE_SOFTC sc);
1088 void oce_refresh_queue_stats(POCE_SOFTC sc);
1089 int  oce_refresh_nic_stats(POCE_SOFTC sc);
1090 int  oce_stats_init(POCE_SOFTC sc);
1091 void oce_stats_free(POCE_SOFTC sc);
1092 
1093 /* Capabilities */
1094 #define OCE_MODCAP_RSS			1
1095 #define OCE_MAX_RSP_HANDLED		64
1096 extern uint32_t oce_max_rsp_handled;	/* max responses */
1097 
1098 #define OCE_MAC_LOOPBACK		0x0
1099 #define OCE_PHY_LOOPBACK		0x1
1100 #define OCE_ONE_PORT_EXT_LOOPBACK	0x2
1101 #define OCE_NO_LOOPBACK			0xff
1102 
1103 #define atomic_inc_32(x)		atomic_add_32(x, 1)
1104 #define atomic_dec_32(x)		atomic_subtract_32(x, 1)
1105 
1106 #define LE_64(x)			htole64(x)
1107 #define LE_32(x)			htole32(x)
1108 #define LE_16(x)			htole16(x)
1109 #define HOST_64(x)			le64toh(x)
1110 #define HOST_32(x)			le32toh(x)
1111 #define HOST_16(x)			le16toh(x)
1112 #define DW_SWAP(x, l)
1113 #define IS_ALIGNED(x,a)			((x % a) == 0)
1114 #define ADDR_HI(x)			((uint32_t)((uint64_t)(x) >> 32))
1115 #define ADDR_LO(x)			((uint32_t)((uint64_t)(x) & 0xffffffff));
1116 
1117 #define IF_LRO_ENABLED(sc)  (((sc)->ifp->if_capenable & IFCAP_LRO) ? 1:0)
1118 #define IF_LSO_ENABLED(sc)  (((sc)->ifp->if_capenable & IFCAP_TSO4) ? 1:0)
1119 #define IF_CSUM_ENABLED(sc) (((sc)->ifp->if_capenable & IFCAP_HWCSUM) ? 1:0)
1120 
1121 #define OCE_LOG2(x) 			(oce_highbit(x))
1122 static inline uint32_t oce_highbit(uint32_t x)
1123 {
1124 	int i;
1125 	int c;
1126 	int b;
1127 
1128 	c = 0;
1129 	b = 0;
1130 
1131 	for (i = 0; i < 32; i++) {
1132 		if ((1 << i) & x) {
1133 			c++;
1134 			b = i;
1135 		}
1136 	}
1137 
1138 	if (c == 1)
1139 		return b;
1140 
1141 	return 0;
1142 }
1143 
1144 static inline int MPU_EP_SEMAPHORE(POCE_SOFTC sc)
1145 {
1146 	if (IS_BE(sc))
1147 		return MPU_EP_SEMAPHORE_BE3;
1148 	else if (IS_SH(sc))
1149 		return MPU_EP_SEMAPHORE_SH;
1150 	else
1151 		return MPU_EP_SEMAPHORE_XE201;
1152 }
1153 
1154 #define TRANSCEIVER_DATA_NUM_ELE 64
1155 #define TRANSCEIVER_DATA_SIZE 256
1156 #define TRANSCEIVER_A0_SIZE 128
1157 #define TRANSCEIVER_A2_SIZE 128
1158 #define PAGE_NUM_A0 0xa0
1159 #define PAGE_NUM_A2 0xa2
1160 #define IS_QNQ_OR_UMC(sc) ((sc->pvid && (sc->function_mode & FNM_UMC_MODE ))\
1161 		     || (sc->qnqid && (sc->function_mode & FNM_FLEX10_MODE)))
1162