xref: /freebsd/sys/dev/cxgbe/common/common.h (revision 81b22a98)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2011 Chelsio Communications, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  *
30  */
31 
32 #ifndef __CHELSIO_COMMON_H
33 #define __CHELSIO_COMMON_H
34 
35 #include "t4_hw.h"
36 
37 enum {
38 	MAX_NPORTS     = 4,     /* max # of ports */
39 	SERNUM_LEN     = 24,    /* Serial # length */
40 	EC_LEN         = 16,    /* E/C length */
41 	ID_LEN         = 16,    /* ID length */
42 	PN_LEN         = 16,    /* Part Number length */
43 	MD_LEN         = 16,    /* MFG diags version length */
44 	MACADDR_LEN    = 12,    /* MAC Address length */
45 };
46 
47 enum {
48 	T4_REGMAP_SIZE = (160 * 1024),
49 	T5_REGMAP_SIZE = (332 * 1024),
50 };
51 
52 enum { MEM_EDC0, MEM_EDC1, MEM_MC, MEM_MC0 = MEM_MC, MEM_MC1, MEM_HMA };
53 
54 enum dev_master { MASTER_CANT, MASTER_MAY, MASTER_MUST };
55 
56 enum dev_state { DEV_STATE_UNINIT, DEV_STATE_INIT, DEV_STATE_ERR };
57 
58 enum {
59 	PAUSE_RX      = 1 << 0,
60 	PAUSE_TX      = 1 << 1,
61 	PAUSE_AUTONEG = 1 << 2
62 };
63 
64 enum {
65 	/*
66 	 * Real FECs.  In the same order as the FEC portion of caps32 so that
67 	 * the code can do (fec & M_FW_PORT_CAP32_FEC) to get all the real FECs.
68 	 */
69 	FEC_RS        = 1 << 0,	/* Reed-Solomon */
70 	FEC_BASER_RS  = 1 << 1,	/* BASE-R, aka Firecode */
71 	FEC_NONE      = 1 << 2,	/* no FEC */
72 
73 	/*
74 	 * Pseudo FECs that translate to real FECs.  The firmware knows nothing
75 	 * about these and they start at M_FW_PORT_CAP32_FEC + 1.  AUTO should
76 	 * be set all by itself.
77 	 */
78 	FEC_AUTO      = 1 << 5,
79 	FEC_MODULE    = 1 << 6,	/* FEC suggested by the cable/transceiver. */
80 };
81 
82 enum t4_bar2_qtype { T4_BAR2_QTYPE_EGRESS, T4_BAR2_QTYPE_INGRESS };
83 
84 struct port_stats {
85 	u64 tx_octets;            /* total # of octets in good frames */
86 	u64 tx_frames;            /* all good frames */
87 	u64 tx_bcast_frames;      /* all broadcast frames */
88 	u64 tx_mcast_frames;      /* all multicast frames */
89 	u64 tx_ucast_frames;      /* all unicast frames */
90 	u64 tx_error_frames;      /* all error frames */
91 
92 	u64 tx_frames_64;         /* # of Tx frames in a particular range */
93 	u64 tx_frames_65_127;
94 	u64 tx_frames_128_255;
95 	u64 tx_frames_256_511;
96 	u64 tx_frames_512_1023;
97 	u64 tx_frames_1024_1518;
98 	u64 tx_frames_1519_max;
99 
100 	u64 tx_drop;              /* # of dropped Tx frames */
101 	u64 tx_pause;             /* # of transmitted pause frames */
102 	u64 tx_ppp0;              /* # of transmitted PPP prio 0 frames */
103 	u64 tx_ppp1;              /* # of transmitted PPP prio 1 frames */
104 	u64 tx_ppp2;              /* # of transmitted PPP prio 2 frames */
105 	u64 tx_ppp3;              /* # of transmitted PPP prio 3 frames */
106 	u64 tx_ppp4;              /* # of transmitted PPP prio 4 frames */
107 	u64 tx_ppp5;              /* # of transmitted PPP prio 5 frames */
108 	u64 tx_ppp6;              /* # of transmitted PPP prio 6 frames */
109 	u64 tx_ppp7;              /* # of transmitted PPP prio 7 frames */
110 
111 	u64 rx_octets;            /* total # of octets in good frames */
112 	u64 rx_frames;            /* all good frames */
113 	u64 rx_bcast_frames;      /* all broadcast frames */
114 	u64 rx_mcast_frames;      /* all multicast frames */
115 	u64 rx_ucast_frames;      /* all unicast frames */
116 	u64 rx_too_long;          /* # of frames exceeding MTU */
117 	u64 rx_jabber;            /* # of jabber frames */
118 	u64 rx_fcs_err;           /* # of received frames with bad FCS */
119 	u64 rx_len_err;           /* # of received frames with length error */
120 	u64 rx_symbol_err;        /* symbol errors */
121 	u64 rx_runt;              /* # of short frames */
122 
123 	u64 rx_frames_64;         /* # of Rx frames in a particular range */
124 	u64 rx_frames_65_127;
125 	u64 rx_frames_128_255;
126 	u64 rx_frames_256_511;
127 	u64 rx_frames_512_1023;
128 	u64 rx_frames_1024_1518;
129 	u64 rx_frames_1519_max;
130 
131 	u64 rx_pause;             /* # of received pause frames */
132 	u64 rx_ppp0;              /* # of received PPP prio 0 frames */
133 	u64 rx_ppp1;              /* # of received PPP prio 1 frames */
134 	u64 rx_ppp2;              /* # of received PPP prio 2 frames */
135 	u64 rx_ppp3;              /* # of received PPP prio 3 frames */
136 	u64 rx_ppp4;              /* # of received PPP prio 4 frames */
137 	u64 rx_ppp5;              /* # of received PPP prio 5 frames */
138 	u64 rx_ppp6;              /* # of received PPP prio 6 frames */
139 	u64 rx_ppp7;              /* # of received PPP prio 7 frames */
140 
141 	u64 rx_ovflow0;           /* drops due to buffer-group 0 overflows */
142 	u64 rx_ovflow1;           /* drops due to buffer-group 1 overflows */
143 	u64 rx_ovflow2;           /* drops due to buffer-group 2 overflows */
144 	u64 rx_ovflow3;           /* drops due to buffer-group 3 overflows */
145 	u64 rx_trunc0;            /* buffer-group 0 truncated packets */
146 	u64 rx_trunc1;            /* buffer-group 1 truncated packets */
147 	u64 rx_trunc2;            /* buffer-group 2 truncated packets */
148 	u64 rx_trunc3;            /* buffer-group 3 truncated packets */
149 };
150 
151 struct lb_port_stats {
152 	u64 octets;
153 	u64 frames;
154 	u64 bcast_frames;
155 	u64 mcast_frames;
156 	u64 ucast_frames;
157 	u64 error_frames;
158 
159 	u64 frames_64;
160 	u64 frames_65_127;
161 	u64 frames_128_255;
162 	u64 frames_256_511;
163 	u64 frames_512_1023;
164 	u64 frames_1024_1518;
165 	u64 frames_1519_max;
166 
167 	u64 drop;
168 
169 	u64 ovflow0;
170 	u64 ovflow1;
171 	u64 ovflow2;
172 	u64 ovflow3;
173 	u64 trunc0;
174 	u64 trunc1;
175 	u64 trunc2;
176 	u64 trunc3;
177 };
178 
179 struct tp_tcp_stats {
180 	u32 tcp_out_rsts;
181 	u64 tcp_in_segs;
182 	u64 tcp_out_segs;
183 	u64 tcp_retrans_segs;
184 };
185 
186 struct tp_usm_stats {
187 	u32 frames;
188 	u32 drops;
189 	u64 octets;
190 };
191 
192 struct tp_tid_stats {
193 	u32 del;
194 	u32 inv;
195 	u32 act;
196 	u32 pas;
197 };
198 
199 struct tp_fcoe_stats {
200 	u32 frames_ddp;
201 	u32 frames_drop;
202 	u64 octets_ddp;
203 };
204 
205 struct tp_err_stats {
206 	u32 mac_in_errs[MAX_NCHAN];
207 	u32 hdr_in_errs[MAX_NCHAN];
208 	u32 tcp_in_errs[MAX_NCHAN];
209 	u32 tnl_cong_drops[MAX_NCHAN];
210 	u32 ofld_chan_drops[MAX_NCHAN];
211 	u32 tnl_tx_drops[MAX_NCHAN];
212 	u32 ofld_vlan_drops[MAX_NCHAN];
213 	u32 tcp6_in_errs[MAX_NCHAN];
214 	u32 ofld_no_neigh;
215 	u32 ofld_cong_defer;
216 };
217 
218 struct tp_tnl_stats {
219 	u32 out_pkt[MAX_NCHAN];
220 	u32 in_pkt[MAX_NCHAN];
221 };
222 
223 struct tp_proxy_stats {
224 	u32 proxy[MAX_NCHAN];
225 };
226 
227 struct tp_cpl_stats {
228 	u32 req[MAX_NCHAN];
229 	u32 rsp[MAX_NCHAN];
230 };
231 
232 struct tp_rdma_stats {
233 	u32 rqe_dfr_pkt;
234 	u32 rqe_dfr_mod;
235 };
236 
237 struct sge_params {
238 	int timer_val[SGE_NTIMERS];	/* final, scaled values */
239 	int counter_val[SGE_NCOUNTERS];
240 	int fl_starve_threshold;
241 	int fl_starve_threshold2;
242 	int page_shift;
243 	int eq_s_qpp;
244 	int iq_s_qpp;
245 	int spg_len;
246 	int pad_boundary;
247 	int pack_boundary;
248 	int fl_pktshift;
249 	u32 sge_control;
250 	u32 sge_fl_buffer_size[SGE_FLBUF_SIZES];
251 };
252 
253 struct tp_params {
254 	unsigned int tre;            /* log2 of core clocks per TP tick */
255 	unsigned int dack_re;        /* DACK timer resolution */
256 	unsigned int la_mask;        /* what events are recorded by TP LA */
257 	unsigned short tx_modq[MAX_NCHAN];  /* channel to modulation queue map */
258 
259 	uint16_t filter_mode;
260 	uint16_t filter_mask;	/* Used by TOE and hashfilters */
261 	int vnic_mode;
262 	uint32_t max_rx_pdu;
263 	uint32_t max_tx_pdu;
264 	bool rx_pkt_encap;
265 
266 	int8_t fcoe_shift;
267 	int8_t port_shift;
268 	int8_t vnic_shift;
269 	int8_t vlan_shift;
270 	int8_t tos_shift;
271 	int8_t protocol_shift;
272 	int8_t ethertype_shift;
273 	int8_t macmatch_shift;
274 	int8_t matchtype_shift;
275 	int8_t frag_shift;
276 };
277 
278 struct vpd_params {
279 	unsigned int cclk;
280 	u8 ec[EC_LEN + 1];
281 	u8 sn[SERNUM_LEN + 1];
282 	u8 id[ID_LEN + 1];
283 	u8 pn[PN_LEN + 1];
284 	u8 na[MACADDR_LEN + 1];
285 	u8 md[MD_LEN + 1];
286 };
287 
288 struct pci_params {
289 	unsigned int vpd_cap_addr;
290 	unsigned int mps;
291 	unsigned short speed;
292 	unsigned short width;
293 };
294 
295 /*
296  * Firmware device log.
297  */
298 struct devlog_params {
299 	u32 memtype;			/* which memory (FW_MEMTYPE_* ) */
300 	u32 start;			/* start of log in firmware memory */
301 	u32 size;			/* size of log */
302 	u32 addr;			/* start address in flat addr space */
303 };
304 
305 /* Stores chip specific parameters */
306 struct chip_params {
307 	u8 nchan;
308 	u8 pm_stats_cnt;
309 	u8 cng_ch_bits_log;		/* congestion channel map bits width */
310 	u8 nsched_cls;
311 	u8 cim_num_obq;
312 	u8 filter_opt_len;
313 	u16 mps_rplc_size;
314 	u16 vfcount;
315 	u32 sge_fl_db;
316 	u16 mps_tcam_size;
317 	u16 rss_nentries;
318 };
319 
320 /* VF-only parameters. */
321 
322 /*
323  * Global Receive Side Scaling (RSS) parameters in host-native format.
324  */
325 struct rss_params {
326 	unsigned int mode;		/* RSS mode */
327 	union {
328 	    struct {
329 		u_int synmapen:1;	/* SYN Map Enable */
330 		u_int syn4tupenipv6:1;	/* enable hashing 4-tuple IPv6 SYNs */
331 		u_int syn2tupenipv6:1;	/* enable hashing 2-tuple IPv6 SYNs */
332 		u_int syn4tupenipv4:1;	/* enable hashing 4-tuple IPv4 SYNs */
333 		u_int syn2tupenipv4:1;	/* enable hashing 2-tuple IPv4 SYNs */
334 		u_int ofdmapen:1;	/* Offload Map Enable */
335 		u_int tnlmapen:1;	/* Tunnel Map Enable */
336 		u_int tnlalllookup:1;	/* Tunnel All Lookup */
337 		u_int hashtoeplitz:1;	/* use Toeplitz hash */
338 	    } basicvirtual;
339 	} u;
340 };
341 
342 /*
343  * Maximum resources provisioned for a PCI VF.
344  */
345 struct vf_resources {
346 	unsigned int nvi;		/* N virtual interfaces */
347 	unsigned int neq;		/* N egress Qs */
348 	unsigned int nethctrl;		/* N egress ETH or CTRL Qs */
349 	unsigned int niqflint;		/* N ingress Qs/w free list(s) & intr */
350 	unsigned int niq;		/* N ingress Qs */
351 	unsigned int tc;		/* PCI-E traffic class */
352 	unsigned int pmask;		/* port access rights mask */
353 	unsigned int nexactf;		/* N exact MPS filters */
354 	unsigned int r_caps;		/* read capabilities */
355 	unsigned int wx_caps;		/* write/execute capabilities */
356 };
357 
358 struct adapter_params {
359 	struct sge_params sge;
360 	struct tp_params  tp;		/* PF-only */
361 	struct vpd_params vpd;
362 	struct pci_params pci;
363 	struct devlog_params devlog;	/* PF-only */
364 	struct rss_params rss;		/* VF-only */
365 	struct vf_resources vfres;	/* VF-only */
366 	unsigned int core_vdd;
367 
368 	unsigned int sf_size;             /* serial flash size in bytes */
369 	unsigned int sf_nsec;             /* # of flash sectors */
370 
371 	unsigned int fw_vers;		/* firmware version */
372 	unsigned int bs_vers;		/* bootstrap version */
373 	unsigned int tp_vers;		/* TP microcode version */
374 	unsigned int er_vers;		/* expansion ROM version */
375 	unsigned int scfg_vers;		/* Serial Configuration version */
376 	unsigned int vpd_vers;		/* VPD version */
377 
378 	unsigned short mtus[NMTUS];
379 	unsigned short a_wnd[NCCTRL_WIN];
380 	unsigned short b_wnd[NCCTRL_WIN];
381 
382 	unsigned int cim_la_size;
383 
384 	uint8_t nports;		/* # of ethernet ports */
385 	uint8_t portvec;
386 	unsigned int chipid:4;	/* chip ID.  T4 = 4, T5 = 5, ... */
387 	unsigned int rev:4;	/* chip revision */
388 	unsigned int fpga:1;	/* this is an FPGA */
389 	unsigned int offload:1;	/* hw is TOE capable, fw has divvied up card
390 				   resources for TOE operation. */
391 	unsigned int bypass:1;	/* this is a bypass card */
392 	unsigned int ethoffload:1;
393 	unsigned int hash_filter:1;
394 	unsigned int filter2_wr_support:1;
395 	unsigned int port_caps32:1;
396 	unsigned int smac_add_support:1;
397 
398 	unsigned int ofldq_wr_cred;
399 	unsigned int eo_wr_cred;
400 
401 	unsigned int max_ordird_qp;
402 	unsigned int max_ird_adapter;
403 
404 	uint32_t mps_bg_map;	/* rx buffer group map for all ports (upto 4) */
405 
406 	bool ulptx_memwrite_dsgl;	/* use of T5 DSGL allowed */
407 	bool fr_nsmr_tpte_wr_support;	/* FW support for FR_NSMR_TPTE_WR */
408 	bool dev_512sgl_mr;		/* FW support for 512 SGL per FR MR */
409 	bool viid_smt_extn_support;	/* FW returns vin, vfvld & smt index? */
410 	unsigned int max_pkts_per_eth_tx_pkts_wr;
411 	uint8_t nsched_cls;		/* # of usable sched classes per port */
412 };
413 
414 #define CHELSIO_T4		0x4
415 #define CHELSIO_T5		0x5
416 #define CHELSIO_T6		0x6
417 
418 /*
419  * State needed to monitor the forward progress of SGE Ingress DMA activities
420  * and possible hangs.
421  */
422 struct sge_idma_monitor_state {
423 	unsigned int idma_1s_thresh;	/* 1s threshold in Core Clock ticks */
424 	unsigned int idma_stalled[2];	/* synthesized stalled timers in HZ */
425 	unsigned int idma_state[2];	/* IDMA Hang detect state */
426 	unsigned int idma_qid[2];	/* IDMA Hung Ingress Queue ID */
427 	unsigned int idma_warn[2];	/* time to warning in HZ */
428 };
429 
430 struct trace_params {
431 	u32 data[TRACE_LEN / 4];
432 	u32 mask[TRACE_LEN / 4];
433 	unsigned short snap_len;
434 	unsigned short min_len;
435 	unsigned char skip_ofst;
436 	unsigned char skip_len;
437 	unsigned char invert;
438 	unsigned char port;
439 };
440 
441 struct link_config {
442 	/* OS-specific code owns all the requested_* fields. */
443 	int8_t requested_aneg;	/* link autonegotiation */
444 	int8_t requested_fc;	/* flow control */
445 	int8_t requested_fec;	/* FEC */
446 	u_int requested_speed;	/* speed (Mbps) */
447 	uint32_t requested_caps;/* rcap in last l1cfg issued by the driver. */
448 
449 	uint32_t pcaps;		/* link capabilities */
450 	uint32_t acaps;		/* advertised capabilities */
451 	uint32_t lpacaps;	/* peer advertised capabilities */
452 	u_int speed;		/* actual link speed (Mbps) */
453 	int8_t fc;		/* actual link flow control */
454 	int8_t fec_hint;	/* cable/transceiver recommended fec */
455 	int8_t fec;		/* actual FEC */
456 	bool link_ok;		/* link up? */
457 	uint8_t link_down_rc;	/* link down reason */
458 };
459 
460 #include "adapter.h"
461 
462 #ifndef PCI_VENDOR_ID_CHELSIO
463 # define PCI_VENDOR_ID_CHELSIO 0x1425
464 #endif
465 
466 #define for_each_port(adapter, iter) \
467 	for (iter = 0; iter < (adapter)->params.nports; ++iter)
468 
469 static inline int is_ftid(const struct adapter *sc, u_int tid)
470 {
471 
472 	return (sc->tids.nftids > 0 && tid >= sc->tids.ftid_base &&
473 	    tid <= sc->tids.ftid_end);
474 }
475 
476 static inline int is_hpftid(const struct adapter *sc, u_int tid)
477 {
478 
479 	return (sc->tids.nhpftids > 0 && tid >= sc->tids.hpftid_base &&
480 	    tid <= sc->tids.hpftid_end);
481 }
482 
483 static inline int is_etid(const struct adapter *sc, u_int tid)
484 {
485 
486 	return (sc->tids.netids > 0 && tid >= sc->tids.etid_base &&
487 	    tid <= sc->tids.etid_end);
488 }
489 
490 static inline int is_offload(const struct adapter *adap)
491 {
492 	return adap->params.offload;
493 }
494 
495 static inline int is_ethoffload(const struct adapter *adap)
496 {
497 	return adap->params.ethoffload;
498 }
499 
500 static inline int is_hashfilter(const struct adapter *adap)
501 {
502 	return adap->params.hash_filter;
503 }
504 
505 static inline int is_ktls(const struct adapter *adap)
506 {
507 	return adap->cryptocaps & FW_CAPS_CONFIG_TLS_HW;
508 }
509 
510 static inline int chip_id(struct adapter *adap)
511 {
512 	return adap->params.chipid;
513 }
514 
515 static inline int chip_rev(struct adapter *adap)
516 {
517 	return adap->params.rev;
518 }
519 
520 static inline int is_t4(struct adapter *adap)
521 {
522 	return adap->params.chipid == CHELSIO_T4;
523 }
524 
525 static inline int is_t5(struct adapter *adap)
526 {
527 	return adap->params.chipid == CHELSIO_T5;
528 }
529 
530 static inline int is_t6(struct adapter *adap)
531 {
532 	return adap->params.chipid == CHELSIO_T6;
533 }
534 
535 static inline int is_fpga(struct adapter *adap)
536 {
537 	 return adap->params.fpga;
538 }
539 
540 static inline unsigned int core_ticks_per_usec(const struct adapter *adap)
541 {
542 	return adap->params.vpd.cclk / 1000;
543 }
544 
545 static inline unsigned int us_to_core_ticks(const struct adapter *adap,
546 					    unsigned int us)
547 {
548 	return (us * adap->params.vpd.cclk) / 1000;
549 }
550 
551 static inline unsigned int core_ticks_to_us(const struct adapter *adapter,
552 					    unsigned int ticks)
553 {
554 	/* add Core Clock / 2 to round ticks to nearest uS */
555 	return ((ticks * 1000 + adapter->params.vpd.cclk/2) /
556 		adapter->params.vpd.cclk);
557 }
558 
559 static inline unsigned int dack_ticks_to_usec(const struct adapter *adap,
560 					      unsigned int ticks)
561 {
562 	return (ticks << adap->params.tp.dack_re) / core_ticks_per_usec(adap);
563 }
564 
565 static inline u_int us_to_tcp_ticks(const struct adapter *adap, u_long us)
566 {
567 
568 	return (us * adap->params.vpd.cclk / 1000 >> adap->params.tp.tre);
569 }
570 
571 static inline u_int tcp_ticks_to_us(const struct adapter *adap, u_int ticks)
572 {
573 	return ((uint64_t)ticks << adap->params.tp.tre) /
574 	    core_ticks_per_usec(adap);
575 }
576 
577 void t4_set_reg_field(struct adapter *adap, unsigned int addr, u32 mask, u32 val);
578 
579 int t4_wr_mbox_meat_timeout(struct adapter *adap, int mbox, const void *cmd,
580 			    int size, void *rpl, bool sleep_ok, int timeout);
581 int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
582 		    void *rpl, bool sleep_ok);
583 
584 static inline int t4_wr_mbox_timeout(struct adapter *adap, int mbox,
585 				     const void *cmd, int size, void *rpl,
586 				     int timeout)
587 {
588 	return t4_wr_mbox_meat_timeout(adap, mbox, cmd, size, rpl, true,
589 				       timeout);
590 }
591 
592 static inline int t4_wr_mbox(struct adapter *adap, int mbox, const void *cmd,
593 			     int size, void *rpl)
594 {
595 	return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, true);
596 }
597 
598 static inline int t4_wr_mbox_ns(struct adapter *adap, int mbox, const void *cmd,
599 				int size, void *rpl)
600 {
601 	return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, false);
602 }
603 
604 void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
605 		      unsigned int data_reg, u32 *vals, unsigned int nregs,
606 		      unsigned int start_idx);
607 void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
608 		       unsigned int data_reg, const u32 *vals,
609 		       unsigned int nregs, unsigned int start_idx);
610 
611 u32 t4_hw_pci_read_cfg4(adapter_t *adapter, int reg);
612 
613 struct fw_filter_wr;
614 
615 void t4_intr_enable(struct adapter *adapter);
616 void t4_intr_disable(struct adapter *adapter);
617 void t4_intr_clear(struct adapter *adapter);
618 int t4_slow_intr_handler(struct adapter *adapter, bool verbose);
619 
620 int t4_hash_mac_addr(const u8 *addr);
621 int t4_link_l1cfg(struct adapter *adap, unsigned int mbox, unsigned int port,
622 		  struct link_config *lc);
623 int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port);
624 int t4_seeprom_read(struct adapter *adapter, u32 addr, u32 *data);
625 int t4_seeprom_write(struct adapter *adapter, u32 addr, u32 data);
626 int t4_eeprom_ptov(unsigned int phys_addr, unsigned int fn, unsigned int sz);
627 int t4_seeprom_wp(struct adapter *adapter, int enable);
628 int t4_read_flash(struct adapter *adapter, unsigned int addr, unsigned int nwords,
629 		  u32 *data, int byte_oriented);
630 int t4_write_flash(struct adapter *adapter, unsigned int addr,
631 		   unsigned int n, const u8 *data, int byte_oriented);
632 int t4_load_fw(struct adapter *adapter, const u8 *fw_data, unsigned int size);
633 int t4_fwcache(struct adapter *adap, enum fw_params_param_dev_fwcache op);
634 int t5_fw_init_extern_mem(struct adapter *adap);
635 int t4_load_bootcfg(struct adapter *adapter, const u8 *cfg_data, unsigned int size);
636 int t4_load_boot(struct adapter *adap, u8 *boot_data,
637                  unsigned int boot_addr, unsigned int size);
638 int t4_flash_erase_sectors(struct adapter *adapter, int start, int end);
639 int t4_flash_cfg_addr(struct adapter *adapter);
640 int t4_load_cfg(struct adapter *adapter, const u8 *cfg_data, unsigned int size);
641 int t4_get_fw_version(struct adapter *adapter, u32 *vers);
642 int t4_get_fw_hdr(struct adapter *adapter, struct fw_hdr *hdr);
643 int t4_get_bs_version(struct adapter *adapter, u32 *vers);
644 int t4_get_tp_version(struct adapter *adapter, u32 *vers);
645 int t4_get_exprom_version(struct adapter *adapter, u32 *vers);
646 int t4_get_scfg_version(struct adapter *adapter, u32 *vers);
647 int t4_get_vpd_version(struct adapter *adapter, u32 *vers);
648 int t4_get_version_info(struct adapter *adapter);
649 int t4_init_hw(struct adapter *adapter, u32 fw_params);
650 const struct chip_params *t4_get_chip_params(int chipid);
651 int t4_prep_adapter(struct adapter *adapter, u32 *buf);
652 int t4_shutdown_adapter(struct adapter *adapter);
653 int t4_init_devlog_params(struct adapter *adapter, int fw_attach);
654 int t4_init_sge_params(struct adapter *adapter);
655 int t4_init_tp_params(struct adapter *adap);
656 int t4_filter_field_shift(const struct adapter *adap, int filter_sel);
657 int t4_port_init(struct adapter *adap, int mbox, int pf, int vf, int port_id);
658 void t4_fatal_err(struct adapter *adapter, bool fw_error);
659 int t4_set_trace_filter(struct adapter *adapter, const struct trace_params *tp,
660 			int filter_index, int enable);
661 void t4_get_trace_filter(struct adapter *adapter, struct trace_params *tp,
662 			 int filter_index, int *enabled);
663 int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
664 			int start, int n, const u16 *rspq, unsigned int nrspq);
665 int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
666 		       unsigned int flags);
667 int t4_config_vi_rss(struct adapter *adapter, int mbox, unsigned int viid,
668 		     unsigned int flags, unsigned int defq, unsigned int skeyidx,
669 		     unsigned int skey);
670 int t4_read_rss(struct adapter *adapter, u16 *entries);
671 void t4_read_rss_key(struct adapter *adapter, u32 *key, bool sleep_ok);
672 void t4_write_rss_key(struct adapter *adap, const u32 *key, int idx,
673 		      bool sleep_ok);
674 void t4_read_rss_pf_config(struct adapter *adapter, unsigned int index,
675 			   u32 *valp, bool sleep_ok);
676 void t4_write_rss_pf_config(struct adapter *adapter, unsigned int index,
677 			    u32 val, bool sleep_ok);
678 void t4_read_rss_vf_config(struct adapter *adapter, unsigned int index,
679 			   u32 *vfl, u32 *vfh, bool sleep_ok);
680 void t4_write_rss_vf_config(struct adapter *adapter, unsigned int index,
681 			    u32 vfl, u32 vfh, bool sleep_ok);
682 u32 t4_read_rss_pf_map(struct adapter *adapter, bool sleep_ok);
683 void t4_write_rss_pf_map(struct adapter *adapter, u32 pfmap, bool sleep_ok);
684 u32 t4_read_rss_pf_mask(struct adapter *adapter, bool sleep_ok);
685 void t4_write_rss_pf_mask(struct adapter *adapter, u32 pfmask, bool sleep_ok);
686 int t4_mps_set_active_ports(struct adapter *adap, unsigned int port_mask);
687 void t4_pmtx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[]);
688 void t4_pmrx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[]);
689 void t4_read_cimq_cfg(struct adapter *adap, u16 *base, u16 *size, u16 *thres);
690 int t4_read_cim_ibq(struct adapter *adap, unsigned int qid, u32 *data, size_t n);
691 int t4_read_cim_obq(struct adapter *adap, unsigned int qid, u32 *data, size_t n);
692 int t4_cim_read(struct adapter *adap, unsigned int addr, unsigned int n,
693 		unsigned int *valp);
694 int t4_cim_write(struct adapter *adap, unsigned int addr, unsigned int n,
695 		 const unsigned int *valp);
696 int t4_cim_ctl_read(struct adapter *adap, unsigned int addr, unsigned int n,
697 		    unsigned int *valp);
698 int t4_cim_read_la(struct adapter *adap, u32 *la_buf, unsigned int *wrptr);
699 void t4_cim_read_pif_la(struct adapter *adap, u32 *pif_req, u32 *pif_rsp,
700 		unsigned int *pif_req_wrptr, unsigned int *pif_rsp_wrptr);
701 void t4_cim_read_ma_la(struct adapter *adap, u32 *ma_req, u32 *ma_rsp);
702 int t4_get_flash_params(struct adapter *adapter);
703 
704 u32 t4_read_pcie_cfg4(struct adapter *adap, int reg, int drv_fw_attach);
705 int t4_mc_read(struct adapter *adap, int idx, u32 addr,
706 	       __be32 *data, u64 *parity);
707 int t4_edc_read(struct adapter *adap, int idx, u32 addr, __be32 *data, u64 *parity);
708 int t4_mem_read(struct adapter *adap, int mtype, u32 addr, u32 size,
709 		__be32 *data);
710 void t4_idma_monitor_init(struct adapter *adapter,
711 			  struct sge_idma_monitor_state *idma);
712 void t4_idma_monitor(struct adapter *adapter,
713 		     struct sge_idma_monitor_state *idma,
714 		     int hz, int ticks);
715 int t4_set_vf_mac(struct adapter *adapter, unsigned int pf, unsigned int vf,
716 		  unsigned int naddr, u8 *addr);
717 
718 unsigned int t4_get_regs_len(struct adapter *adapter);
719 void t4_get_regs(struct adapter *adap, u8 *buf, size_t buf_size);
720 
721 const char *t4_get_port_type_description(enum fw_port_type port_type);
722 void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p);
723 void t4_get_port_stats_offset(struct adapter *adap, int idx,
724 		struct port_stats *stats,
725 		struct port_stats *offset);
726 void t4_get_lb_stats(struct adapter *adap, int idx, struct lb_port_stats *p);
727 void t4_clr_port_stats(struct adapter *adap, int idx);
728 
729 void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log);
730 void t4_read_cong_tbl(struct adapter *adap, u16 incr[NMTUS][NCCTRL_WIN]);
731 void t4_read_pace_tbl(struct adapter *adap, unsigned int pace_vals[NTX_SCHED]);
732 void t4_get_tx_sched(struct adapter *adap, unsigned int sched, unsigned int *kbps,
733 		     unsigned int *ipg, bool sleep_ok);
734 void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
735 			    unsigned int mask, unsigned int val);
736 void t4_tp_read_la(struct adapter *adap, u64 *la_buf, unsigned int *wrptr);
737 void t4_tp_get_err_stats(struct adapter *adap, struct tp_err_stats *st,
738 			 bool sleep_ok);
739 void t4_tp_get_tnl_stats(struct adapter *adap, struct tp_tnl_stats *st,
740 			 bool sleep_ok);
741 void t4_tp_get_proxy_stats(struct adapter *adap, struct tp_proxy_stats *st,
742     			   bool sleep_ok);
743 void t4_tp_get_cpl_stats(struct adapter *adap, struct tp_cpl_stats *st,
744 			 bool sleep_ok);
745 void t4_tp_get_rdma_stats(struct adapter *adap, struct tp_rdma_stats *st,
746 			  bool sleep_ok);
747 void t4_get_usm_stats(struct adapter *adap, struct tp_usm_stats *st,
748 		      bool sleep_ok);
749 void t4_tp_get_tid_stats(struct adapter *adap, struct tp_tid_stats *st,
750 		      bool sleep_ok);
751 void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
752 			 struct tp_tcp_stats *v6, bool sleep_ok);
753 void t4_get_fcoe_stats(struct adapter *adap, unsigned int idx,
754 		       struct tp_fcoe_stats *st, bool sleep_ok);
755 void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
756 		  const unsigned short *alpha, const unsigned short *beta);
757 
758 void t4_ulprx_read_la(struct adapter *adap, u32 *la_buf);
759 
760 int t4_set_sched_bps(struct adapter *adap, int sched, unsigned int kbps);
761 int t4_set_sched_ipg(struct adapter *adap, int sched, unsigned int ipg);
762 int t4_set_pace_tbl(struct adapter *adap, const unsigned int *pace_vals,
763 		    unsigned int start, unsigned int n);
764 void t4_get_chan_txrate(struct adapter *adap, u64 *nic_rate, u64 *ofld_rate);
765 int t4_set_filter_cfg(struct adapter *adap, int mode, int mask, int vnic_mode);
766 void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid);
767 
768 void t4_wol_magic_enable(struct adapter *adap, unsigned int port, const u8 *addr);
769 int t4_wol_pat_enable(struct adapter *adap, unsigned int port, unsigned int map,
770 		      u64 mask0, u64 mask1, unsigned int crc, bool enable);
771 
772 int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
773 		enum dev_master master, enum dev_state *state);
774 int t4_fw_bye(struct adapter *adap, unsigned int mbox);
775 int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset);
776 int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force);
777 int t4_fw_restart(struct adapter *adap, unsigned int mbox);
778 int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
779 		  const u8 *fw_data, unsigned int size, int force);
780 int t4_fw_initialize(struct adapter *adap, unsigned int mbox);
781 int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
782 		    unsigned int vf, unsigned int nparams, const u32 *params,
783 		    u32 *val);
784 int t4_query_params_rw(struct adapter *adap, unsigned int mbox, unsigned int pf,
785 		       unsigned int vf, unsigned int nparams, const u32 *params,
786 		       u32 *val, int rw);
787 int t4_set_params_timeout(struct adapter *adap, unsigned int mbox,
788 			  unsigned int pf, unsigned int vf,
789 			  unsigned int nparams, const u32 *params,
790 			  const u32 *val, int timeout);
791 int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
792 		  unsigned int vf, unsigned int nparams, const u32 *params,
793 		  const u32 *val);
794 int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
795 		unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
796 		unsigned int rxqi, unsigned int rxq, unsigned int tc,
797 		unsigned int vi, unsigned int cmask, unsigned int pmask,
798 		unsigned int exactf, unsigned int rcaps, unsigned int wxcaps);
799 int t4_alloc_vi_func(struct adapter *adap, unsigned int mbox,
800 		     unsigned int port, unsigned int pf, unsigned int vf,
801 		     unsigned int nmac, u8 *mac, u16 *rss_size,
802 		     uint8_t *vfvld, uint16_t *vin,
803 		     unsigned int portfunc, unsigned int idstype);
804 int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
805 		unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
806 		u16 *rss_size, uint8_t *vfvld, uint16_t *vin);
807 int t4_free_vi(struct adapter *adap, unsigned int mbox,
808 	       unsigned int pf, unsigned int vf,
809 	       unsigned int viid);
810 int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
811 		  int mtu, int promisc, int all_multi, int bcast, int vlanex,
812 		  bool sleep_ok);
813 int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox, unsigned int viid,
814 		      bool free, unsigned int naddr, const u8 **addr, u16 *idx,
815 		      u64 *hash, bool sleep_ok);
816 int t4_free_mac_filt(struct adapter *adap, unsigned int mbox,
817 		      unsigned int viid, unsigned int naddr,
818 		      const u8 **addr, bool sleep_ok);
819 int t4_free_encap_mac_filt(struct adapter *adap, unsigned int viid,
820 			   int idx, bool sleep_ok);
821 int t4_free_raw_mac_filt(struct adapter *adap, unsigned int viid,
822 			 const u8 *addr, const u8 *mask, unsigned int idx,
823 			 u8 lookup_type, u8 port_id, bool sleep_ok);
824 int t4_alloc_raw_mac_filt(struct adapter *adap, unsigned int viid,
825 			  const u8 *addr, const u8 *mask, unsigned int idx,
826 			  u8 lookup_type, u8 port_id, bool sleep_ok);
827 int t4_alloc_encap_mac_filt(struct adapter *adap, unsigned int viid,
828 			    const u8 *addr, const u8 *mask, unsigned int vni,
829 			    unsigned int vni_mask, u8 dip_hit, u8 lookup_type,
830 			    bool sleep_ok);
831 int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
832 		  int idx, const u8 *addr, bool persist, uint16_t *smt_idx);
833 int t4_del_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
834 	       const u8 *addr, bool smac);
835 int t4_add_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
836 	       int idx, const u8 *addr, bool persist, u8 *smt_idx, bool smac);
837 int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
838 		     bool ucast, u64 vec, bool sleep_ok);
839 int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
840 			unsigned int viid, bool rx_en, bool tx_en, bool dcb_en);
841 int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
842 		 bool rx_en, bool tx_en);
843 int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
844 		     unsigned int nblinks);
845 int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
846 	       unsigned int mmd, unsigned int reg, unsigned int *valp);
847 int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
848 	       unsigned int mmd, unsigned int reg, unsigned int val);
849 int t4_i2c_io(struct adapter *adap, unsigned int mbox,
850 	      int port, unsigned int devid,
851 	      unsigned int offset, unsigned int len,
852 	      u8 *buf, bool write);
853 int t4_i2c_rd(struct adapter *adap, unsigned int mbox,
854 	      int port, unsigned int devid,
855 	      unsigned int offset, unsigned int len,
856 	      u8 *buf);
857 int t4_i2c_wr(struct adapter *adap, unsigned int mbox,
858 	      int port, unsigned int devid,
859 	      unsigned int offset, unsigned int len,
860 	      u8 *buf);
861 int t4_iq_stop(struct adapter *adap, unsigned int mbox, unsigned int pf,
862 	       unsigned int vf, unsigned int iqtype, unsigned int iqid,
863 	       unsigned int fl0id, unsigned int fl1id);
864 int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
865 	       unsigned int vf, unsigned int iqtype, unsigned int iqid,
866 	       unsigned int fl0id, unsigned int fl1id);
867 int t4_eth_eq_stop(struct adapter *adap, unsigned int mbox, unsigned int pf,
868                    unsigned int vf, unsigned int eqid);
869 int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
870 		   unsigned int vf, unsigned int eqid);
871 int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
872 		    unsigned int vf, unsigned int eqid);
873 int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
874 		    unsigned int vf, unsigned int eqid);
875 int t4_sge_ctxt_rd(struct adapter *adap, unsigned int mbox, unsigned int cid,
876 		   enum ctxt_type ctype, u32 *data);
877 int t4_sge_ctxt_rd_bd(struct adapter *adap, unsigned int cid, enum ctxt_type ctype,
878 		      u32 *data);
879 int t4_sge_ctxt_flush(struct adapter *adap, unsigned int mbox, int ctxt_type);
880 const char *t4_link_down_rc_str(unsigned char link_down_rc);
881 int t4_update_port_info(struct port_info *pi);
882 int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl);
883 int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox, u32 addr, u32 val);
884 int t4_sched_config(struct adapter *adapter, int type, int minmaxen,
885 		    int sleep_ok);
886 int t4_sched_params(struct adapter *adapter, int type, int level, int mode,
887 		    int rateunit, int ratemode, int channel, int cl,
888 		    int minrate, int maxrate, int weight, int pktsize,
889 		    int burstsize, int sleep_ok);
890 int t4_sched_params_ch_rl(struct adapter *adapter, int channel, int ratemode,
891 			  unsigned int maxrate, int sleep_ok);
892 int t4_sched_params_cl_wrr(struct adapter *adapter, int channel, int cl,
893 			   int weight, int sleep_ok);
894 int t4_sched_params_cl_rl_kbps(struct adapter *adapter, int channel, int cl,
895 			       int mode, unsigned int maxrate, int pktsize,
896 			       int sleep_ok);
897 int t4_config_watchdog(struct adapter *adapter, unsigned int mbox,
898 		       unsigned int pf, unsigned int vf,
899 		       unsigned int timeout, unsigned int action);
900 int t4_get_devlog_level(struct adapter *adapter, unsigned int *level);
901 int t4_set_devlog_level(struct adapter *adapter, unsigned int level);
902 void t4_sge_decode_idma_state(struct adapter *adapter, int state);
903 
904 void t4_tp_pio_read(struct adapter *adap, u32 *buff, u32 nregs,
905 		    u32 start_index, bool sleep_ok);
906 void t4_tp_pio_write(struct adapter *adap, const u32 *buff, u32 nregs,
907 		     u32 start_index, bool sleep_ok);
908 void t4_tp_tm_pio_read(struct adapter *adap, u32 *buff, u32 nregs,
909 		       u32 start_index, bool sleep_ok);
910 void t4_tp_mib_read(struct adapter *adap, u32 *buff, u32 nregs,
911 		    u32 start_index, bool sleep_ok);
912 int t4_configure_ringbb(struct adapter *adap);
913 int t4_configure_add_smac(struct adapter *adap);
914 int t4_set_vlan_acl(struct adapter *adap, unsigned int mbox, unsigned int vf,
915 		    u16 vlan);
916 
917 static inline int t4vf_query_params(struct adapter *adapter,
918 				    unsigned int nparams, const u32 *params,
919 				    u32 *vals)
920 {
921 	return t4_query_params(adapter, 0, 0, 0, nparams, params, vals);
922 }
923 
924 static inline int t4vf_set_params(struct adapter *adapter,
925 				  unsigned int nparams, const u32 *params,
926 				  const u32 *vals)
927 {
928 	return t4_set_params(adapter, 0, 0, 0, nparams, params, vals);
929 }
930 
931 static inline int t4vf_wr_mbox(struct adapter *adap, const void *cmd,
932 			       int size, void *rpl)
933 {
934 	return t4_wr_mbox(adap, adap->mbox, cmd, size, rpl);
935 }
936 
937 int t4vf_wait_dev_ready(struct adapter *adapter);
938 int t4vf_fw_reset(struct adapter *adapter);
939 int t4vf_get_sge_params(struct adapter *adapter);
940 int t4vf_get_rss_glb_config(struct adapter *adapter);
941 int t4vf_get_vfres(struct adapter *adapter);
942 int t4vf_prep_adapter(struct adapter *adapter);
943 int t4vf_get_vf_mac(struct adapter *adapter, unsigned int port,
944 		    unsigned int *naddr, u8 *addr);
945 int t4_bar2_sge_qregs(struct adapter *adapter, unsigned int qid,
946 		enum t4_bar2_qtype qtype, int user, u64 *pbar2_qoffset,
947 		unsigned int *pbar2_qid);
948 unsigned int fwcap_to_speed(uint32_t caps);
949 uint32_t speed_to_fwcap(unsigned int speed);
950 uint32_t fwcap_top_speed(uint32_t caps);
951 
952 static inline int
953 port_top_speed(const struct port_info *pi)
954 {
955 
956 	/* Mbps -> Gbps */
957 	return (fwcap_to_speed(pi->link_cfg.pcaps) / 1000);
958 }
959 
960 #endif /* __CHELSIO_COMMON_H */
961