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