156b2bdd1SGireesh Nagabhushana /*
256b2bdd1SGireesh Nagabhushana  * This file and its contents are supplied under the terms of the
356b2bdd1SGireesh Nagabhushana  * Common Development and Distribution License ("CDDL"), version 1.0.
456b2bdd1SGireesh Nagabhushana  * You may only use this file in accordance with the terms of version
556b2bdd1SGireesh Nagabhushana  * 1.0 of the CDDL.
656b2bdd1SGireesh Nagabhushana  *
756b2bdd1SGireesh Nagabhushana  * A full copy of the text of the CDDL should have accompanied this
856b2bdd1SGireesh Nagabhushana  * source. A copy of the CDDL is also available via the Internet at
956b2bdd1SGireesh Nagabhushana  * http://www.illumos.org/license/CDDL.
1056b2bdd1SGireesh Nagabhushana  */
1156b2bdd1SGireesh Nagabhushana 
1256b2bdd1SGireesh Nagabhushana /*
1356b2bdd1SGireesh Nagabhushana  * This file is part of the Chelsio T4 support code.
1456b2bdd1SGireesh Nagabhushana  *
1556b2bdd1SGireesh Nagabhushana  * Copyright (C) 2010-2013 Chelsio Communications.  All rights reserved.
1656b2bdd1SGireesh Nagabhushana  *
1756b2bdd1SGireesh Nagabhushana  * This program is distributed in the hope that it will be useful, but WITHOUT
1856b2bdd1SGireesh Nagabhushana  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1956b2bdd1SGireesh Nagabhushana  * FITNESS FOR A PARTICULAR PURPOSE.  See the LICENSE file included in this
2056b2bdd1SGireesh Nagabhushana  * release for licensing terms and conditions.
2156b2bdd1SGireesh Nagabhushana  */
2256b2bdd1SGireesh Nagabhushana 
23d77e6e0fSPaul Winder /*
24d77e6e0fSPaul Winder  * Copyright 2020 RackTop Systems, Inc.
25d75c6062SRobert Mustacchi  * Copyright 2021 Oxide Computer Company
26d77e6e0fSPaul Winder  */
27d77e6e0fSPaul Winder 
2856b2bdd1SGireesh Nagabhushana #include <sys/ddi.h>
2956b2bdd1SGireesh Nagabhushana #include <sys/sunddi.h>
3056b2bdd1SGireesh Nagabhushana #include <sys/dlpi.h>
3156b2bdd1SGireesh Nagabhushana #include <sys/mac_provider.h>
3256b2bdd1SGireesh Nagabhushana #include <sys/mac_ether.h>
3356b2bdd1SGireesh Nagabhushana #include <sys/strsubr.h>
3456b2bdd1SGireesh Nagabhushana #include <sys/queue.h>
3556b2bdd1SGireesh Nagabhushana 
3656b2bdd1SGireesh Nagabhushana #include "common/common.h"
3756b2bdd1SGireesh Nagabhushana #include "common/t4_regs.h"
3856b2bdd1SGireesh Nagabhushana 
3956b2bdd1SGireesh Nagabhushana static int t4_mc_getstat(void *arg, uint_t stat, uint64_t *val);
4056b2bdd1SGireesh Nagabhushana static int t4_mc_start(void *arg);
4156b2bdd1SGireesh Nagabhushana static void t4_mc_stop(void *arg);
4256b2bdd1SGireesh Nagabhushana static int t4_mc_setpromisc(void *arg, boolean_t on);
4356b2bdd1SGireesh Nagabhushana static int t4_mc_multicst(void *arg, boolean_t add, const uint8_t *mcaddr);
4456b2bdd1SGireesh Nagabhushana static int t4_mc_unicst(void *arg, const uint8_t *ucaddr);
4556b2bdd1SGireesh Nagabhushana static boolean_t t4_mc_getcapab(void *arg, mac_capab_t cap, void *data);
4656b2bdd1SGireesh Nagabhushana static int t4_mc_setprop(void *arg, const char *name, mac_prop_id_t id,
4756b2bdd1SGireesh Nagabhushana     uint_t size, const void *val);
4856b2bdd1SGireesh Nagabhushana static int t4_mc_getprop(void *arg, const char *name, mac_prop_id_t id,
4956b2bdd1SGireesh Nagabhushana     uint_t size, void *val);
5056b2bdd1SGireesh Nagabhushana static void t4_mc_propinfo(void *arg, const char *name, mac_prop_id_t id,
5156b2bdd1SGireesh Nagabhushana     mac_prop_info_handle_t ph);
5256b2bdd1SGireesh Nagabhushana 
5356b2bdd1SGireesh Nagabhushana static int t4_init_synchronized(struct port_info *pi);
5456b2bdd1SGireesh Nagabhushana static int t4_uninit_synchronized(struct port_info *pi);
5556b2bdd1SGireesh Nagabhushana static void propinfo(struct port_info *pi, const char *name,
5656b2bdd1SGireesh Nagabhushana     mac_prop_info_handle_t ph);
5756b2bdd1SGireesh Nagabhushana static int getprop(struct port_info *pi, const char *name, uint_t size,
5856b2bdd1SGireesh Nagabhushana     void *val);
5956b2bdd1SGireesh Nagabhushana static int setprop(struct port_info *pi, const char *name, const void *val);
6056b2bdd1SGireesh Nagabhushana 
6156b2bdd1SGireesh Nagabhushana mac_callbacks_t t4_m_callbacks = {
6256b2bdd1SGireesh Nagabhushana 	.mc_callbacks	= MC_GETCAPAB | MC_PROPERTIES,
6356b2bdd1SGireesh Nagabhushana 	.mc_getstat	= t4_mc_getstat,
6456b2bdd1SGireesh Nagabhushana 	.mc_start	= t4_mc_start,
6556b2bdd1SGireesh Nagabhushana 	.mc_stop	= t4_mc_stop,
6656b2bdd1SGireesh Nagabhushana 	.mc_setpromisc	= t4_mc_setpromisc,
6756b2bdd1SGireesh Nagabhushana 	.mc_multicst	= t4_mc_multicst,
683dde7c95SVishal Kulkarni 	.mc_unicst =    t4_mc_unicst,
693dde7c95SVishal Kulkarni 	.mc_tx =        t4_mc_tx,
703dde7c95SVishal Kulkarni 	.mc_getcapab =	t4_mc_getcapab,
713dde7c95SVishal Kulkarni 	.mc_setprop =	t4_mc_setprop,
723dde7c95SVishal Kulkarni 	.mc_getprop =	t4_mc_getprop,
733dde7c95SVishal Kulkarni 	.mc_propinfo =	t4_mc_propinfo,
743dde7c95SVishal Kulkarni };
753dde7c95SVishal Kulkarni 
763dde7c95SVishal Kulkarni /* I couldn't comeup with a better idea of not redefine
773dde7c95SVishal Kulkarni  * another strcture and instead somehow reuse the earlier
783dde7c95SVishal Kulkarni  * above structure and modify its members.
793dde7c95SVishal Kulkarni  */
803dde7c95SVishal Kulkarni mac_callbacks_t t4_m_ring_callbacks = {
813dde7c95SVishal Kulkarni 	.mc_callbacks =	MC_GETCAPAB | MC_PROPERTIES,
823dde7c95SVishal Kulkarni 	.mc_getstat =	t4_mc_getstat,
833dde7c95SVishal Kulkarni 	.mc_start =	t4_mc_start,
843dde7c95SVishal Kulkarni 	.mc_stop =	t4_mc_stop,
853dde7c95SVishal Kulkarni 	.mc_setpromisc =t4_mc_setpromisc,
863dde7c95SVishal Kulkarni 	.mc_multicst =	t4_mc_multicst,
873dde7c95SVishal Kulkarni 	.mc_unicst =    NULL, /* t4_addmac */
883dde7c95SVishal Kulkarni 	.mc_tx =        NULL, /* t4_eth_tx */
8956b2bdd1SGireesh Nagabhushana 	.mc_getcapab	= t4_mc_getcapab,
9056b2bdd1SGireesh Nagabhushana 	.mc_setprop	= t4_mc_setprop,
9156b2bdd1SGireesh Nagabhushana 	.mc_getprop	= t4_mc_getprop,
9256b2bdd1SGireesh Nagabhushana 	.mc_propinfo	= t4_mc_propinfo,
9356b2bdd1SGireesh Nagabhushana };
9456b2bdd1SGireesh Nagabhushana 
9556b2bdd1SGireesh Nagabhushana #define	T4PROP_TMR_IDX "_holdoff_timer_idx"
9656b2bdd1SGireesh Nagabhushana #define	T4PROP_PKTC_IDX "_holdoff_pktc_idx"
9756b2bdd1SGireesh Nagabhushana #define	T4PROP_MTU "_mtu"
9856b2bdd1SGireesh Nagabhushana #define	T4PROP_HW_CSUM	"_hw_csum"
9956b2bdd1SGireesh Nagabhushana #define	T4PROP_HW_LSO	"_hw_lso"
10056b2bdd1SGireesh Nagabhushana #define	T4PROP_TX_PAUSE	"_tx_pause"
10156b2bdd1SGireesh Nagabhushana #define	T4PROP_RX_PAUSE	"_rx_pause"
10256b2bdd1SGireesh Nagabhushana 
10356b2bdd1SGireesh Nagabhushana char *t4_priv_props[] = {
10456b2bdd1SGireesh Nagabhushana 	T4PROP_TMR_IDX,
10556b2bdd1SGireesh Nagabhushana 	T4PROP_PKTC_IDX,
10656b2bdd1SGireesh Nagabhushana #if MAC_VERSION == 1
10756b2bdd1SGireesh Nagabhushana 	/* MAC_VERSION 1 doesn't seem to use MAC_PROP_MTU, hmmmm */
10856b2bdd1SGireesh Nagabhushana 	T4PROP_MTU,
10956b2bdd1SGireesh Nagabhushana #endif
11056b2bdd1SGireesh Nagabhushana 	T4PROP_HW_CSUM,
11156b2bdd1SGireesh Nagabhushana 	T4PROP_HW_LSO,
11256b2bdd1SGireesh Nagabhushana 	T4PROP_TX_PAUSE,
11356b2bdd1SGireesh Nagabhushana 	T4PROP_RX_PAUSE,
11456b2bdd1SGireesh Nagabhushana 	NULL
11556b2bdd1SGireesh Nagabhushana };
11656b2bdd1SGireesh Nagabhushana 
11756b2bdd1SGireesh Nagabhushana static int
t4_mc_getstat(void * arg,uint_t stat,uint64_t * val)11856b2bdd1SGireesh Nagabhushana t4_mc_getstat(void *arg, uint_t stat, uint64_t *val)
11956b2bdd1SGireesh Nagabhushana {
12056b2bdd1SGireesh Nagabhushana 	struct port_info *pi = arg;
12156b2bdd1SGireesh Nagabhushana 	struct adapter *sc = pi->adapter;
12256b2bdd1SGireesh Nagabhushana 	struct link_config *lc = &pi->link_cfg;
12356b2bdd1SGireesh Nagabhushana 
12456b2bdd1SGireesh Nagabhushana #define	GET_STAT(name) \
12556b2bdd1SGireesh Nagabhushana 	t4_read_reg64(sc, PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_##name##_L))
12656b2bdd1SGireesh Nagabhushana 
12756b2bdd1SGireesh Nagabhushana 	switch (stat) {
12856b2bdd1SGireesh Nagabhushana 	case MAC_STAT_IFSPEED:
12956b2bdd1SGireesh Nagabhushana 		if (lc->link_ok != 0) {
130*6feac2e3SRahul Lakkireddy 			*val = t4_link_fwcap_to_speed(lc->link_caps);
13156b2bdd1SGireesh Nagabhushana 			*val *= 1000000;
13256b2bdd1SGireesh Nagabhushana 		} else
13356b2bdd1SGireesh Nagabhushana 			*val = 0;
13456b2bdd1SGireesh Nagabhushana 		break;
13556b2bdd1SGireesh Nagabhushana 
13656b2bdd1SGireesh Nagabhushana 	case MAC_STAT_MULTIRCV:
13756b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(RX_PORT_MCAST);
13856b2bdd1SGireesh Nagabhushana 		break;
13956b2bdd1SGireesh Nagabhushana 
14056b2bdd1SGireesh Nagabhushana 	case MAC_STAT_BRDCSTRCV:
14156b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(RX_PORT_BCAST);
14256b2bdd1SGireesh Nagabhushana 		break;
14356b2bdd1SGireesh Nagabhushana 
14456b2bdd1SGireesh Nagabhushana 	case MAC_STAT_MULTIXMT:
14556b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(TX_PORT_MCAST);
14656b2bdd1SGireesh Nagabhushana 		break;
14756b2bdd1SGireesh Nagabhushana 
14856b2bdd1SGireesh Nagabhushana 	case MAC_STAT_BRDCSTXMT:
14956b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(TX_PORT_BCAST);
15056b2bdd1SGireesh Nagabhushana 		break;
15156b2bdd1SGireesh Nagabhushana 
15256b2bdd1SGireesh Nagabhushana 	case MAC_STAT_NORCVBUF:
15356b2bdd1SGireesh Nagabhushana 		*val = 0;	/* TODO should come from rxq->nomem */
15456b2bdd1SGireesh Nagabhushana 		break;
15556b2bdd1SGireesh Nagabhushana 
15656b2bdd1SGireesh Nagabhushana 	case MAC_STAT_IERRORS:
15756b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(RX_PORT_MTU_ERROR) +
15856b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_MTU_CRC_ERROR) +
15956b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_CRC_ERROR) +
16056b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_LEN_ERROR) +
16156b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_SYM_ERROR) +
16256b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_LESS_64B);
16356b2bdd1SGireesh Nagabhushana 		break;
16456b2bdd1SGireesh Nagabhushana 
16556b2bdd1SGireesh Nagabhushana 	case MAC_STAT_UNKNOWNS:
16656b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
16756b2bdd1SGireesh Nagabhushana 
16856b2bdd1SGireesh Nagabhushana 	case MAC_STAT_NOXMTBUF:
16956b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(TX_PORT_DROP);
17056b2bdd1SGireesh Nagabhushana 		break;
17156b2bdd1SGireesh Nagabhushana 
17256b2bdd1SGireesh Nagabhushana 	case MAC_STAT_OERRORS:
17356b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(TX_PORT_ERROR);
17456b2bdd1SGireesh Nagabhushana 		break;
17556b2bdd1SGireesh Nagabhushana 
17656b2bdd1SGireesh Nagabhushana 	case MAC_STAT_COLLISIONS:
17756b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
17856b2bdd1SGireesh Nagabhushana 
17956b2bdd1SGireesh Nagabhushana 	case MAC_STAT_RBYTES:
18056b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(RX_PORT_BYTES);
18156b2bdd1SGireesh Nagabhushana 		break;
18256b2bdd1SGireesh Nagabhushana 
18356b2bdd1SGireesh Nagabhushana 	case MAC_STAT_IPACKETS:
18456b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(RX_PORT_FRAMES);
18556b2bdd1SGireesh Nagabhushana 		break;
18656b2bdd1SGireesh Nagabhushana 
18756b2bdd1SGireesh Nagabhushana 	case MAC_STAT_OBYTES:
18856b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(TX_PORT_BYTES);
18956b2bdd1SGireesh Nagabhushana 		break;
19056b2bdd1SGireesh Nagabhushana 
19156b2bdd1SGireesh Nagabhushana 	case MAC_STAT_OPACKETS:
19256b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(TX_PORT_FRAMES);
19356b2bdd1SGireesh Nagabhushana 		break;
19456b2bdd1SGireesh Nagabhushana 
19556b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_ALIGN_ERRORS:
19656b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
19756b2bdd1SGireesh Nagabhushana 
19856b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_FCS_ERRORS:
19956b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(RX_PORT_CRC_ERROR);
20056b2bdd1SGireesh Nagabhushana 		break;
20156b2bdd1SGireesh Nagabhushana 
20256b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_FIRST_COLLISIONS:
20356b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_MULTI_COLLISIONS:
20456b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_SQE_ERRORS:
20556b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_DEFER_XMTS:
20656b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_TX_LATE_COLLISIONS:
20756b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_EX_COLLISIONS:
20856b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
20956b2bdd1SGireesh Nagabhushana 
21056b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_MACXMT_ERRORS:
21156b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(TX_PORT_ERROR);
21256b2bdd1SGireesh Nagabhushana 		break;
21356b2bdd1SGireesh Nagabhushana 
21456b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CARRIER_ERRORS:
21556b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
21656b2bdd1SGireesh Nagabhushana 
21756b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_TOOLONG_ERRORS:
21856b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(RX_PORT_MTU_ERROR);
21956b2bdd1SGireesh Nagabhushana 		break;
22056b2bdd1SGireesh Nagabhushana 
22156b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_MACRCV_ERRORS:
22256b2bdd1SGireesh Nagabhushana 		*val = GET_STAT(RX_PORT_MTU_ERROR) +
22356b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_MTU_CRC_ERROR) +
22456b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_CRC_ERROR) +
22556b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_LEN_ERROR) +
22656b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_SYM_ERROR) +
22756b2bdd1SGireesh Nagabhushana 		    GET_STAT(RX_PORT_LESS_64B);
22856b2bdd1SGireesh Nagabhushana 		break;
22956b2bdd1SGireesh Nagabhushana 
23056b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_XCVR_ADDR:
23156b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_XCVR_ID:
23256b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_XCVR_INUSE:
23356b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
23456b2bdd1SGireesh Nagabhushana 
2353dde7c95SVishal Kulkarni 	case ETHER_STAT_CAP_100GFDX:
2367e6ad469SVishal Kulkarni 		*val = !!(lc->pcaps & FW_PORT_CAP32_SPEED_100G);
2373dde7c95SVishal Kulkarni 		break;
2383dde7c95SVishal Kulkarni 
239*6feac2e3SRahul Lakkireddy 	case ETHER_STAT_CAP_50GFDX:
240*6feac2e3SRahul Lakkireddy 		*val = !!(lc->pcaps & FW_PORT_CAP32_SPEED_50G);
241*6feac2e3SRahul Lakkireddy 		break;
242*6feac2e3SRahul Lakkireddy 
2433dde7c95SVishal Kulkarni 	case ETHER_STAT_CAP_40GFDX:
2447e6ad469SVishal Kulkarni 		*val = !!(lc->pcaps & FW_PORT_CAP32_SPEED_40G);
2453dde7c95SVishal Kulkarni 		break;
2463dde7c95SVishal Kulkarni 
2473dde7c95SVishal Kulkarni 	case ETHER_STAT_CAP_25GFDX:
2487e6ad469SVishal Kulkarni 		*val = !!(lc->pcaps & FW_PORT_CAP32_SPEED_25G);
2493dde7c95SVishal Kulkarni 		break;
2503dde7c95SVishal Kulkarni 
2513dde7c95SVishal Kulkarni 	case ETHER_STAT_CAP_10GFDX:
2527e6ad469SVishal Kulkarni 		*val = !!(lc->pcaps & FW_PORT_CAP32_SPEED_10G);
2533dde7c95SVishal Kulkarni 		break;
2543dde7c95SVishal Kulkarni 
25556b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CAP_1000FDX:
2567e6ad469SVishal Kulkarni 		*val = !!(lc->pcaps & FW_PORT_CAP32_SPEED_1G);
25756b2bdd1SGireesh Nagabhushana 		break;
25856b2bdd1SGireesh Nagabhushana 
25956b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CAP_100FDX:
2607e6ad469SVishal Kulkarni 		*val = !!(lc->pcaps & FW_PORT_CAP32_SPEED_100M);
26156b2bdd1SGireesh Nagabhushana 		break;
26256b2bdd1SGireesh Nagabhushana 
263*6feac2e3SRahul Lakkireddy 	case ETHER_STAT_CAP_1000HDX:
26456b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CAP_100HDX:
26556b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CAP_10FDX:
26656b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CAP_10HDX:
26756b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
26856b2bdd1SGireesh Nagabhushana 
26956b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CAP_ASMPAUSE:
270*6feac2e3SRahul Lakkireddy 		*val = !!(lc->pcaps & FW_PORT_CAP32_FC_RX);
27156b2bdd1SGireesh Nagabhushana 		break;
27256b2bdd1SGireesh Nagabhushana 
27356b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CAP_PAUSE:
274*6feac2e3SRahul Lakkireddy 		*val = !!(lc->pcaps & FW_PORT_CAP32_FC_TX);
27556b2bdd1SGireesh Nagabhushana 		break;
27656b2bdd1SGireesh Nagabhushana 
27756b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_CAP_AUTONEG:
2787e6ad469SVishal Kulkarni 		*val = !!(lc->pcaps & FW_PORT_CAP32_ANEG);
27956b2bdd1SGireesh Nagabhushana 		break;
28056b2bdd1SGireesh Nagabhushana 
28156b2bdd1SGireesh Nagabhushana 	/*
28256b2bdd1SGireesh Nagabhushana 	 * We have set flow control configuration based on tx_pause and rx_pause
28356b2bdd1SGireesh Nagabhushana 	 * values supported through ndd. Now, we need to translate the settings
28456b2bdd1SGireesh Nagabhushana 	 * we have in link_config structure to adv_cap_asmpause and
28556b2bdd1SGireesh Nagabhushana 	 * adv_cap_pause.
28656b2bdd1SGireesh Nagabhushana 	 *
28756b2bdd1SGireesh Nagabhushana 	 * There are 4 combinations possible and the translation is as below:
28856b2bdd1SGireesh Nagabhushana 	 * tx_pause = 0 => We don't send pause frames during Rx congestion
28956b2bdd1SGireesh Nagabhushana 	 * tx_pause = 1 => We send pause frames during Rx congestion
29056b2bdd1SGireesh Nagabhushana 	 * rx_pause = 0 => We ignore received pause frames
29156b2bdd1SGireesh Nagabhushana 	 * rx_pause = 1 => We pause transmission when we receive pause frames
29256b2bdd1SGireesh Nagabhushana 	 *
29356b2bdd1SGireesh Nagabhushana 	 * +----------------------------+----------------------------------+
29456b2bdd1SGireesh Nagabhushana 	 * |  tx_pause	|    rx_pause	| adv_cap_asmpause | adv_cap_pause |
29556b2bdd1SGireesh Nagabhushana 	 * +-------------------------+-------------------------------------+
29656b2bdd1SGireesh Nagabhushana 	 * |	0	|	0	|	0	   |	0	   |
29756b2bdd1SGireesh Nagabhushana 	 * |	0	|	1	|	1	   |	0	   |
29856b2bdd1SGireesh Nagabhushana 	 * |	1	|	0	|	1	   |	1	   |
29956b2bdd1SGireesh Nagabhushana 	 * |	1	|	1	|	0	   |	1	   |
30056b2bdd1SGireesh Nagabhushana 	 * +----------------------------+----------------------------------+
30156b2bdd1SGireesh Nagabhushana 	 */
30256b2bdd1SGireesh Nagabhushana 
30356b2bdd1SGireesh Nagabhushana 	/* Advertised asymmetric pause capability */
30456b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_ADV_CAP_ASMPAUSE:
305*6feac2e3SRahul Lakkireddy 		if (lc->pcaps & FW_PORT_CAP32_802_3_ASM_DIR)
306*6feac2e3SRahul Lakkireddy 			*val = !!(lc->admin_caps & FW_PORT_CAP32_802_3_ASM_DIR);
307*6feac2e3SRahul Lakkireddy 		else
308*6feac2e3SRahul Lakkireddy 			*val = (!!(lc->admin_caps & FW_PORT_CAP32_FC_TX)) ^
309*6feac2e3SRahul Lakkireddy 			       (!!(lc->admin_caps & FW_PORT_CAP32_FC_RX));
31056b2bdd1SGireesh Nagabhushana 		break;
31156b2bdd1SGireesh Nagabhushana 
31256b2bdd1SGireesh Nagabhushana 	/* Advertised pause capability */
31356b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_ADV_CAP_PAUSE:
314*6feac2e3SRahul Lakkireddy 		if (lc->pcaps & FW_PORT_CAP32_802_3_PAUSE)
315*6feac2e3SRahul Lakkireddy 			*val = !!(lc->admin_caps & FW_PORT_CAP32_802_3_PAUSE);
316*6feac2e3SRahul Lakkireddy 		else
317*6feac2e3SRahul Lakkireddy 			*val = !!(lc->admin_caps & FW_PORT_CAP32_FC_TX);
31856b2bdd1SGireesh Nagabhushana 		break;
31956b2bdd1SGireesh Nagabhushana 
3203dde7c95SVishal Kulkarni 	case ETHER_STAT_ADV_CAP_100GFDX:
321*6feac2e3SRahul Lakkireddy 		*val = !!(lc->admin_caps & FW_PORT_CAP32_SPEED_100G);
322*6feac2e3SRahul Lakkireddy 		break;
323*6feac2e3SRahul Lakkireddy 
324*6feac2e3SRahul Lakkireddy 	case ETHER_STAT_ADV_CAP_50GFDX:
325*6feac2e3SRahul Lakkireddy 		*val = !!(lc->admin_caps & FW_PORT_CAP32_SPEED_50G);
3263dde7c95SVishal Kulkarni 		break;
3273dde7c95SVishal Kulkarni 
3283dde7c95SVishal Kulkarni 	case ETHER_STAT_ADV_CAP_40GFDX:
329*6feac2e3SRahul Lakkireddy 		*val = !!(lc->admin_caps & FW_PORT_CAP32_SPEED_40G);
3303dde7c95SVishal Kulkarni 		break;
3313dde7c95SVishal Kulkarni 
3323dde7c95SVishal Kulkarni 	case ETHER_STAT_ADV_CAP_25GFDX:
333*6feac2e3SRahul Lakkireddy 		*val = !!(lc->admin_caps & FW_PORT_CAP32_SPEED_25G);
3343dde7c95SVishal Kulkarni 		break;
3353dde7c95SVishal Kulkarni 
3363dde7c95SVishal Kulkarni 	case ETHER_STAT_ADV_CAP_10GFDX:
337*6feac2e3SRahul Lakkireddy 		*val = !!(lc->admin_caps & FW_PORT_CAP32_SPEED_10G);
3383dde7c95SVishal Kulkarni 		break;
3393dde7c95SVishal Kulkarni 
34056b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_ADV_CAP_1000FDX:
341*6feac2e3SRahul Lakkireddy 		*val = !!(lc->admin_caps & FW_PORT_CAP32_SPEED_1G);
342*6feac2e3SRahul Lakkireddy 		break;
343*6feac2e3SRahul Lakkireddy 
344*6feac2e3SRahul Lakkireddy 	case ETHER_STAT_ADV_CAP_100FDX:
345*6feac2e3SRahul Lakkireddy 		*val = !!(lc->admin_caps & FW_PORT_CAP32_SPEED_100M);
3463dde7c95SVishal Kulkarni 		break;
3473dde7c95SVishal Kulkarni 
3483dde7c95SVishal Kulkarni 	case ETHER_STAT_ADV_CAP_AUTONEG:
349*6feac2e3SRahul Lakkireddy 		*val = !!(lc->admin_caps & FW_PORT_CAP32_ANEG);
3503dde7c95SVishal Kulkarni 		break;
3513dde7c95SVishal Kulkarni 
35256b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_ADV_CAP_1000HDX:
35356b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_ADV_CAP_100HDX:
35456b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_ADV_CAP_10FDX:
35556b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_ADV_CAP_10HDX:
35656b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);	/* TODO */
35756b2bdd1SGireesh Nagabhushana 
358*6feac2e3SRahul Lakkireddy 	case ETHER_STAT_LP_CAP_ASMPAUSE:
359*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
360*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
361*6feac2e3SRahul Lakkireddy 
362*6feac2e3SRahul Lakkireddy 		if (lc->pcaps & FW_PORT_CAP32_802_3_ASM_DIR)
363*6feac2e3SRahul Lakkireddy 			*val = !!(lc->lpacaps & FW_PORT_CAP32_802_3_ASM_DIR);
364*6feac2e3SRahul Lakkireddy 		else
365*6feac2e3SRahul Lakkireddy 			*val = (!!(lc->lpacaps & FW_PORT_CAP32_FC_TX)) ^
366*6feac2e3SRahul Lakkireddy 			       (!!(lc->lpacaps & FW_PORT_CAP32_FC_RX));
367*6feac2e3SRahul Lakkireddy 		break;
368*6feac2e3SRahul Lakkireddy 
369*6feac2e3SRahul Lakkireddy 	case ETHER_STAT_LP_CAP_PAUSE:
370*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
371*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
372*6feac2e3SRahul Lakkireddy 
373*6feac2e3SRahul Lakkireddy 		if (lc->pcaps & FW_PORT_CAP32_802_3_PAUSE)
374*6feac2e3SRahul Lakkireddy 			*val = !!(lc->lpacaps & FW_PORT_CAP32_802_3_PAUSE);
375*6feac2e3SRahul Lakkireddy 		else
376*6feac2e3SRahul Lakkireddy 			*val = !!(lc->lpacaps & FW_PORT_CAP32_FC_TX);
377*6feac2e3SRahul Lakkireddy 		break;
3783dde7c95SVishal Kulkarni 
3793dde7c95SVishal Kulkarni 	case ETHER_STAT_LP_CAP_100GFDX:
380*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
381*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
382*6feac2e3SRahul Lakkireddy 
383*6feac2e3SRahul Lakkireddy 		*val = !!(lc->lpacaps & FW_PORT_CAP32_SPEED_100G);
384*6feac2e3SRahul Lakkireddy 		break;
385*6feac2e3SRahul Lakkireddy 
386*6feac2e3SRahul Lakkireddy 	case ETHER_STAT_LP_CAP_50GFDX:
387*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
388*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
389*6feac2e3SRahul Lakkireddy 
390*6feac2e3SRahul Lakkireddy 		*val = !!(lc->lpacaps & FW_PORT_CAP32_SPEED_50G);
3913dde7c95SVishal Kulkarni 		break;
3923dde7c95SVishal Kulkarni 
3933dde7c95SVishal Kulkarni 	case ETHER_STAT_LP_CAP_40GFDX:
394*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
395*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
396*6feac2e3SRahul Lakkireddy 
397*6feac2e3SRahul Lakkireddy 		*val = !!(lc->lpacaps & FW_PORT_CAP32_SPEED_40G);
3983dde7c95SVishal Kulkarni 		break;
3993dde7c95SVishal Kulkarni 
4003dde7c95SVishal Kulkarni 	case ETHER_STAT_LP_CAP_25GFDX:
401*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
402*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
403*6feac2e3SRahul Lakkireddy 
404*6feac2e3SRahul Lakkireddy 		*val = !!(lc->lpacaps & FW_PORT_CAP32_SPEED_25G);
4053dde7c95SVishal Kulkarni 		break;
4063dde7c95SVishal Kulkarni 
4073dde7c95SVishal Kulkarni 	case ETHER_STAT_LP_CAP_10GFDX:
408*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
409*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
410*6feac2e3SRahul Lakkireddy 
411*6feac2e3SRahul Lakkireddy 		*val = !!(lc->lpacaps & FW_PORT_CAP32_SPEED_10G);
4123dde7c95SVishal Kulkarni 		break;
4133dde7c95SVishal Kulkarni 
41456b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LP_CAP_1000FDX:
415*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
416*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
417*6feac2e3SRahul Lakkireddy 
418*6feac2e3SRahul Lakkireddy 		*val = !!(lc->lpacaps & FW_PORT_CAP32_SPEED_1G);
419*6feac2e3SRahul Lakkireddy 		break;
420*6feac2e3SRahul Lakkireddy 
421*6feac2e3SRahul Lakkireddy 	case ETHER_STAT_LP_CAP_100FDX:
422*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
423*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
424*6feac2e3SRahul Lakkireddy 
425*6feac2e3SRahul Lakkireddy 		*val = !!(lc->lpacaps & FW_PORT_CAP32_SPEED_100M);
4263dde7c95SVishal Kulkarni 		break;
4273dde7c95SVishal Kulkarni 
4283dde7c95SVishal Kulkarni 	case ETHER_STAT_LP_CAP_AUTONEG:
429*6feac2e3SRahul Lakkireddy 		if (!(lc->acaps & FW_PORT_CAP32_ANEG))
430*6feac2e3SRahul Lakkireddy 			return (ENOTSUP);
431*6feac2e3SRahul Lakkireddy 
432*6feac2e3SRahul Lakkireddy 		*val = !!(lc->lpacaps & FW_PORT_CAP32_ANEG);
4333dde7c95SVishal Kulkarni 		break;
4343dde7c95SVishal Kulkarni 
43556b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LP_CAP_1000HDX:
43656b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LP_CAP_100HDX:
43756b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LP_CAP_10FDX:
43856b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LP_CAP_10HDX:
43956b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
44056b2bdd1SGireesh Nagabhushana 
44156b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LINK_ASMPAUSE:
442*6feac2e3SRahul Lakkireddy 		*val = (!!(lc->link_caps & FW_PORT_CAP32_FC_TX)) ^
443*6feac2e3SRahul Lakkireddy 		       (!!(lc->link_caps & FW_PORT_CAP32_FC_RX));
44456b2bdd1SGireesh Nagabhushana 		break;
44556b2bdd1SGireesh Nagabhushana 
44656b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LINK_PAUSE:
447*6feac2e3SRahul Lakkireddy 		*val = !!(lc->link_caps & FW_PORT_CAP32_FC_TX);
44856b2bdd1SGireesh Nagabhushana 		break;
44956b2bdd1SGireesh Nagabhushana 
45056b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LINK_AUTONEG:
451*6feac2e3SRahul Lakkireddy 		*val = !!(lc->link_caps & FW_PORT_CAP32_ANEG);
45256b2bdd1SGireesh Nagabhushana 		break;
45356b2bdd1SGireesh Nagabhushana 
45456b2bdd1SGireesh Nagabhushana 	case ETHER_STAT_LINK_DUPLEX:
45556b2bdd1SGireesh Nagabhushana 		if (lc->link_ok != 0)
45656b2bdd1SGireesh Nagabhushana 			*val = LINK_DUPLEX_FULL;
45756b2bdd1SGireesh Nagabhushana 		else
45856b2bdd1SGireesh Nagabhushana 			*val = LINK_DUPLEX_UNKNOWN;
45956b2bdd1SGireesh Nagabhushana 		break;
46056b2bdd1SGireesh Nagabhushana 
46156b2bdd1SGireesh Nagabhushana 	default:
46256b2bdd1SGireesh Nagabhushana #ifdef DEBUG
46356b2bdd1SGireesh Nagabhushana 		cxgb_printf(pi->dip, CE_NOTE, "stat %d not implemented.", stat);
46456b2bdd1SGireesh Nagabhushana #endif
46556b2bdd1SGireesh Nagabhushana 		return (ENOTSUP);
46656b2bdd1SGireesh Nagabhushana 	}
46756b2bdd1SGireesh Nagabhushana #undef GET_STAT
46856b2bdd1SGireesh Nagabhushana 
46956b2bdd1SGireesh Nagabhushana 	return (0);
47056b2bdd1SGireesh Nagabhushana }
47156b2bdd1SGireesh Nagabhushana 
47256b2bdd1SGireesh Nagabhushana static int
t4_mc_start(void * arg)47356b2bdd1SGireesh Nagabhushana t4_mc_start(void *arg)
47456b2bdd1SGireesh Nagabhushana {
47556b2bdd1SGireesh Nagabhushana 	struct port_info *pi = arg;
47656b2bdd1SGireesh Nagabhushana 	int rc;
47756b2bdd1SGireesh Nagabhushana 
47856b2bdd1SGireesh Nagabhushana 	rc = begin_synchronized_op(pi, 0, 1);
47956b2bdd1SGireesh Nagabhushana 	if (rc != 0)
48056b2bdd1SGireesh Nagabhushana 		return (rc);
48156b2bdd1SGireesh Nagabhushana 	rc = t4_init_synchronized(pi);
48256b2bdd1SGireesh Nagabhushana 	end_synchronized_op(pi, 0);
48356b2bdd1SGireesh Nagabhushana 
48456b2bdd1SGireesh Nagabhushana 	return (rc);
48556b2bdd1SGireesh Nagabhushana }
48656b2bdd1SGireesh Nagabhushana 
48756b2bdd1SGireesh Nagabhushana static void
t4_mc_stop(void * arg)48856b2bdd1SGireesh Nagabhushana t4_mc_stop(void *arg)
48956b2bdd1SGireesh Nagabhushana {
49056b2bdd1SGireesh Nagabhushana 	struct port_info *pi = arg;
49156b2bdd1SGireesh Nagabhushana 
49256b2bdd1SGireesh Nagabhushana 	while (begin_synchronized_op(pi, 0, 1) != 0)
49356b2bdd1SGireesh Nagabhushana 		continue;
49456b2bdd1SGireesh Nagabhushana 	(void) t4_uninit_synchronized(pi);
49556b2bdd1SGireesh Nagabhushana 	end_synchronized_op(pi, 0);
49656b2bdd1SGireesh Nagabhushana }
49756b2bdd1SGireesh Nagabhushana 
49856b2bdd1SGireesh Nagabhushana static int
t4_mc_setpromisc(void * arg,boolean_t on)49956b2bdd1SGireesh Nagabhushana t4_mc_setpromisc(void *arg, boolean_t on)
50056b2bdd1SGireesh Nagabhushana {
50156b2bdd1SGireesh Nagabhushana 	struct port_info *pi = arg;
50256b2bdd1SGireesh Nagabhushana 	struct adapter *sc = pi->adapter;
50356b2bdd1SGireesh Nagabhushana 	int rc;
50456b2bdd1SGireesh Nagabhushana 
50556b2bdd1SGireesh Nagabhushana 	rc = begin_synchronized_op(pi, 1, 1);
50656b2bdd1SGireesh Nagabhushana 	if (rc != 0)
50756b2bdd1SGireesh Nagabhushana 		return (rc);
50856b2bdd1SGireesh Nagabhushana 	rc = -t4_set_rxmode(sc, sc->mbox, pi->viid, -1, on ? 1 : 0, -1, -1, -1,
50956b2bdd1SGireesh Nagabhushana 	    false);
51056b2bdd1SGireesh Nagabhushana 	end_synchronized_op(pi, 1);
51156b2bdd1SGireesh Nagabhushana 
51256b2bdd1SGireesh Nagabhushana 	return (rc);
51356b2bdd1SGireesh Nagabhushana }
51456b2bdd1SGireesh Nagabhushana 
51556b2bdd1SGireesh Nagabhushana /*
51656b2bdd1SGireesh Nagabhushana  * TODO: Starts failing as soon as the 336 entry table fills up.  Need to use
51756b2bdd1SGireesh Nagabhushana  * hash in that case.
51856b2bdd1SGireesh Nagabhushana  */
51956b2bdd1SGireesh Nagabhushana static int
t4_mc_multicst(void * arg,boolean_t add,const uint8_t * mcaddr)52056b2bdd1SGireesh Nagabhushana t4_mc_multicst(void *arg, boolean_t add, const uint8_t *mcaddr)
52156b2bdd1SGireesh Nagabhushana {
52256b2bdd1SGireesh Nagabhushana 	struct port_info *pi = arg;
52356b2bdd1SGireesh Nagabhushana 	struct adapter *sc = pi->adapter;
52456b2bdd1SGireesh Nagabhushana 	struct fw_vi_mac_cmd c;
52556b2bdd1SGireesh Nagabhushana 	int len16, rc;
52656b2bdd1SGireesh Nagabhushana 
52756b2bdd1SGireesh Nagabhushana 	len16 = howmany(sizeof (c.op_to_viid) + sizeof (c.freemacs_to_len16) +
52856b2bdd1SGireesh Nagabhushana 	    sizeof (c.u.exact[0]), 16);
52956b2bdd1SGireesh Nagabhushana 	c.op_to_viid = htonl(V_FW_CMD_OP(FW_VI_MAC_CMD) | F_FW_CMD_REQUEST |
53056b2bdd1SGireesh Nagabhushana 	    F_FW_CMD_WRITE | V_FW_VI_MAC_CMD_VIID(pi->viid));
53156b2bdd1SGireesh Nagabhushana 	c.freemacs_to_len16 = htonl(V_FW_CMD_LEN16(len16));
53256b2bdd1SGireesh Nagabhushana 	c.u.exact[0].valid_to_idx = htons(F_FW_VI_MAC_CMD_VALID |
53356b2bdd1SGireesh Nagabhushana 	    V_FW_VI_MAC_CMD_IDX(add ? FW_VI_MAC_ADD_MAC :
53456b2bdd1SGireesh Nagabhushana 	    FW_VI_MAC_MAC_BASED_FREE));
53556b2bdd1SGireesh Nagabhushana 	bcopy(mcaddr, &c.u.exact[0].macaddr, ETHERADDRL);
53656b2bdd1SGireesh Nagabhushana 
53756b2bdd1SGireesh Nagabhushana 	rc = begin_synchronized_op(pi, 1, 1);
53856b2bdd1SGireesh Nagabhushana 	if (rc != 0)
53956b2bdd1SGireesh Nagabhushana 		return (rc);
54056b2bdd1SGireesh Nagabhushana 	rc = -t4_wr_mbox_meat(sc, sc->mbox, &c, len16 * 16, &c, true);
54156b2bdd1SGireesh Nagabhushana 	end_synchronized_op(pi, 1);
54256b2bdd1SGireesh Nagabhushana 	if (rc != 0)
54356b2bdd1SGireesh Nagabhushana 		return (rc);
54456b2bdd1SGireesh Nagabhushana #ifdef DEBUG
54556b2bdd1SGireesh Nagabhushana 	/*
54656b2bdd1SGireesh Nagabhushana 	 * TODO: Firmware doesn't seem to return the correct index on removal
54756b2bdd1SGireesh Nagabhushana 	 * (it gives back 0x3fd FW_VI_MAC_MAC_BASED_FREE unchanged. Remove this
54856b2bdd1SGireesh Nagabhushana 	 * code once it is fixed.
54956b2bdd1SGireesh Nagabhushana 	 */
55056b2bdd1SGireesh Nagabhushana 	else {
55156b2bdd1SGireesh Nagabhushana 		uint16_t idx;
55256b2bdd1SGireesh Nagabhushana 
55356b2bdd1SGireesh Nagabhushana 		idx = G_FW_VI_MAC_CMD_IDX(ntohs(c.u.exact[0].valid_to_idx));
55456b2bdd1SGireesh Nagabhushana 		cxgb_printf(pi->dip, CE_NOTE,
55556b2bdd1SGireesh Nagabhushana 		    "%02x:%02x:%02x:%02x:%02x:%02x %s %d", mcaddr[0],
55656b2bdd1SGireesh Nagabhushana 		    mcaddr[1], mcaddr[2], mcaddr[3], mcaddr[4], mcaddr[5],
55756b2bdd1SGireesh Nagabhushana 		    add ? "added at index" : "removed from index", idx);
55856b2bdd1SGireesh Nagabhushana 	}
55956b2bdd1SGireesh Nagabhushana #endif
56056b2bdd1SGireesh Nagabhushana 
56156b2bdd1SGireesh Nagabhushana 	return (0);
56256b2bdd1SGireesh Nagabhushana }
56356b2bdd1SGireesh Nagabhushana 
5643dde7c95SVishal Kulkarni int
t4_mc_unicst(void * arg,const uint8_t * ucaddr)56556b2bdd1SGireesh Nagabhushana t4_mc_unicst(void *arg, const uint8_t *ucaddr)
56656b2bdd1SGireesh Nagabhushana {
56756b2bdd1SGireesh Nagabhushana 	struct port_info *pi = arg;
56856b2bdd1SGireesh Nagabhushana 	struct adapter *sc = pi->adapter;
56956b2bdd1SGireesh Nagabhushana 	int rc;
57056b2bdd1SGireesh Nagabhushana 
5713dde7c95SVishal Kulkarni 	if (ucaddr == NULL)
5723dde7c95SVishal Kulkarni 		return (EINVAL);
5733dde7c95SVishal Kulkarni 
57456b2bdd1SGireesh Nagabhushana 	rc = begin_synchronized_op(pi, 1, 1);
57556b2bdd1SGireesh Nagabhushana 	if (rc != 0)
57656b2bdd1SGireesh Nagabhushana 		return (rc);
5773dde7c95SVishal Kulkarni 
5783dde7c95SVishal Kulkarni 	/* We will support adding only one mac address */
5793dde7c95SVishal Kulkarni 	if (pi->adapter->props.multi_rings && pi->macaddr_cnt) {
5803dde7c95SVishal Kulkarni 		end_synchronized_op(pi, 1);
5813dde7c95SVishal Kulkarni 		return (ENOSPC);
5823dde7c95SVishal Kulkarni 	}
58356b2bdd1SGireesh Nagabhushana 	rc = t4_change_mac(sc, sc->mbox, pi->viid, pi->xact_addr_filt, ucaddr,
5847e6ad469SVishal Kulkarni 			   true, &pi->smt_idx);
58556b2bdd1SGireesh Nagabhushana 	if (rc < 0)
58656b2bdd1SGireesh Nagabhushana 		rc = -rc;
58756b2bdd1SGireesh Nagabhushana 	else {
5883dde7c95SVishal Kulkarni 		pi->macaddr_cnt++;
58956b2bdd1SGireesh Nagabhushana 		pi->xact_addr_filt = rc;
59056b2bdd1SGireesh Nagabhushana 		rc = 0;
59156b2bdd1SGireesh Nagabhushana 	}
59256b2bdd1SGireesh Nagabhushana 	end_synchronized_op(pi, 1);
59356b2bdd1SGireesh Nagabhushana 
59456b2bdd1SGireesh Nagabhushana 	return (rc);
59556b2bdd1SGireesh Nagabhushana }
59656b2bdd1SGireesh Nagabhushana 
5973dde7c95SVishal Kulkarni int
t4_addmac(void * arg,const uint8_t * ucaddr)5983dde7c95SVishal Kulkarni t4_addmac(void *arg, const uint8_t *ucaddr)
5993dde7c95SVishal Kulkarni {
6003dde7c95SVishal Kulkarni 	return (t4_mc_unicst(arg, ucaddr));
6013dde7c95SVishal Kulkarni }
6023dde7c95SVishal Kulkarni 
6033dde7c95SVishal Kulkarni static int
t4_remmac(void * arg,const uint8_t * mac_addr)6043dde7c95SVishal Kulkarni t4_remmac(void *arg, const uint8_t *mac_addr)
6053dde7c95SVishal Kulkarni {
6063dde7c95SVishal Kulkarni 	struct port_info *pi = arg;
6073dde7c95SVishal Kulkarni 	int rc;
6083dde7c95SVishal Kulkarni 
6093dde7c95SVishal Kulkarni 	rc = begin_synchronized_op(pi, 1, 1);
6103dde7c95SVishal Kulkarni 	if (rc != 0)
6113dde7c95SVishal Kulkarni 		return (rc);
6123dde7c95SVishal Kulkarni 
6133dde7c95SVishal Kulkarni 	pi->macaddr_cnt--;
6143dde7c95SVishal Kulkarni 	end_synchronized_op(pi, 1);
6153dde7c95SVishal Kulkarni 
6163dde7c95SVishal Kulkarni 	return (0);
6173dde7c95SVishal Kulkarni }
6183dde7c95SVishal Kulkarni 
6193dde7c95SVishal Kulkarni /*
6203dde7c95SVishal Kulkarni  * Callback funtion for MAC layer to register all groups.
6213dde7c95SVishal Kulkarni  */
6223dde7c95SVishal Kulkarni void
t4_fill_group(void * arg,mac_ring_type_t rtype,const int rg_index,mac_group_info_t * infop,mac_group_handle_t gh)6233dde7c95SVishal Kulkarni t4_fill_group(void *arg, mac_ring_type_t rtype, const int rg_index,
6243dde7c95SVishal Kulkarni 	      mac_group_info_t *infop, mac_group_handle_t gh)
6253dde7c95SVishal Kulkarni {
6263dde7c95SVishal Kulkarni 	struct port_info *pi = arg;
6273dde7c95SVishal Kulkarni 
6283dde7c95SVishal Kulkarni 	switch (rtype) {
6293dde7c95SVishal Kulkarni 	case MAC_RING_TYPE_RX: {
6303dde7c95SVishal Kulkarni 		infop->mgi_driver = (mac_group_driver_t)arg;
6313dde7c95SVishal Kulkarni 		infop->mgi_start = NULL;
6323dde7c95SVishal Kulkarni 		infop->mgi_stop = NULL;
6333dde7c95SVishal Kulkarni 		infop->mgi_addmac = t4_addmac;
6343dde7c95SVishal Kulkarni 		infop->mgi_remmac = t4_remmac;
6353dde7c95SVishal Kulkarni 		infop->mgi_count = pi->nrxq;
6363dde7c95SVishal Kulkarni 		break;
6373dde7c95SVishal Kulkarni 	}
6383dde7c95SVishal Kulkarni 	case MAC_RING_TYPE_TX:
6393dde7c95SVishal Kulkarni 	default:
6403dde7c95SVishal Kulkarni 		ASSERT(0);
6413dde7c95SVishal Kulkarni 		break;
6423dde7c95SVishal Kulkarni 	}
6433dde7c95SVishal Kulkarni }
6443dde7c95SVishal Kulkarni 
6453dde7c95SVishal Kulkarni static int
t4_ring_start(mac_ring_driver_t rh,uint64_t mr_gen_num)6463dde7c95SVishal Kulkarni t4_ring_start(mac_ring_driver_t rh, uint64_t mr_gen_num)
6473dde7c95SVishal Kulkarni {
6483dde7c95SVishal Kulkarni 	struct sge_rxq *rxq = (struct sge_rxq *)rh;
6493dde7c95SVishal Kulkarni 
6503dde7c95SVishal Kulkarni 	RXQ_LOCK(rxq);
6513dde7c95SVishal Kulkarni 	rxq->ring_gen_num = mr_gen_num;
6523dde7c95SVishal Kulkarni 	RXQ_UNLOCK(rxq);
6533dde7c95SVishal Kulkarni 	return (0);
6543dde7c95SVishal Kulkarni }
6553dde7c95SVishal Kulkarni 
6563dde7c95SVishal Kulkarni /*
6573dde7c95SVishal Kulkarni  * Enable interrupt on the specificed rx ring.
6583dde7c95SVishal Kulkarni  */
6593dde7c95SVishal Kulkarni int
t4_ring_intr_enable(mac_intr_handle_t intrh)6603dde7c95SVishal Kulkarni t4_ring_intr_enable(mac_intr_handle_t intrh)
6613dde7c95SVishal Kulkarni {
6623dde7c95SVishal Kulkarni 	struct sge_rxq *rxq = (struct sge_rxq *)intrh;
6633dde7c95SVishal Kulkarni 	struct adapter *sc = rxq->port->adapter;
6643dde7c95SVishal Kulkarni 	struct sge_iq *iq;
6653dde7c95SVishal Kulkarni 
6663dde7c95SVishal Kulkarni 	iq = &rxq->iq;
6673dde7c95SVishal Kulkarni 	RXQ_LOCK(rxq);
6683dde7c95SVishal Kulkarni 	iq->polling = 0;
6693dde7c95SVishal Kulkarni 	iq->state = IQS_IDLE;
6703dde7c95SVishal Kulkarni 	t4_write_reg(sc, MYPF_REG(A_SGE_PF_GTS),
6713dde7c95SVishal Kulkarni 		     V_SEINTARM(iq->intr_params) | V_INGRESSQID(iq->cntxt_id));
6723dde7c95SVishal Kulkarni 	RXQ_UNLOCK(rxq);
6733dde7c95SVishal Kulkarni 	return (0);
6743dde7c95SVishal Kulkarni }
6753dde7c95SVishal Kulkarni 
6763dde7c95SVishal Kulkarni /*
6773dde7c95SVishal Kulkarni  * Disable interrupt on the specificed rx ring.
6783dde7c95SVishal Kulkarni  */
6793dde7c95SVishal Kulkarni int
t4_ring_intr_disable(mac_intr_handle_t intrh)6803dde7c95SVishal Kulkarni t4_ring_intr_disable(mac_intr_handle_t intrh)
6813dde7c95SVishal Kulkarni {
6823dde7c95SVishal Kulkarni 	struct sge_rxq *rxq = (struct sge_rxq *)intrh;
6833dde7c95SVishal Kulkarni 	struct sge_iq *iq;
6843dde7c95SVishal Kulkarni 
6853dde7c95SVishal Kulkarni 	/* Nothing to be done here wrt interrupt, as it
6863dde7c95SVishal Kulkarni 	 * will not fire, until we write back to
6873dde7c95SVishal Kulkarni 	 * A_SGE_PF_GTS.SEIntArm in t4_ring_intr_enable.
6883dde7c95SVishal Kulkarni 	 */
6893dde7c95SVishal Kulkarni 
6903dde7c95SVishal Kulkarni 	iq = &rxq->iq;
6913dde7c95SVishal Kulkarni 	RXQ_LOCK(rxq);
6923dde7c95SVishal Kulkarni 	iq->polling = 1;
6933dde7c95SVishal Kulkarni 	iq->state = IQS_BUSY;
6943dde7c95SVishal Kulkarni 	RXQ_UNLOCK(rxq);
6953dde7c95SVishal Kulkarni 	return (0);
6963dde7c95SVishal Kulkarni }
6973dde7c95SVishal Kulkarni 
6983dde7c95SVishal Kulkarni mblk_t *
t4_poll_ring(void * arg,int n_bytes)6993dde7c95SVishal Kulkarni t4_poll_ring(void *arg, int n_bytes)
7003dde7c95SVishal Kulkarni {
7013dde7c95SVishal Kulkarni 	struct sge_rxq *rxq = (struct sge_rxq *)arg;
7023dde7c95SVishal Kulkarni 	mblk_t *mp = NULL;
7033dde7c95SVishal Kulkarni 
7043dde7c95SVishal Kulkarni 	ASSERT(n_bytes >= 0);
7053dde7c95SVishal Kulkarni 	if (n_bytes == 0)
7063dde7c95SVishal Kulkarni 		return (NULL);
7073dde7c95SVishal Kulkarni 
7083dde7c95SVishal Kulkarni 	RXQ_LOCK(rxq);
7093dde7c95SVishal Kulkarni 	mp = t4_ring_rx(rxq, n_bytes);
7103dde7c95SVishal Kulkarni 	RXQ_UNLOCK(rxq);
7113dde7c95SVishal Kulkarni 
7123dde7c95SVishal Kulkarni 	return (mp);
7133dde7c95SVishal Kulkarni }
7143dde7c95SVishal Kulkarni 
7153dde7c95SVishal Kulkarni /*
7163dde7c95SVishal Kulkarni  * Retrieve a value for one of the statistics for a particular rx ring
7173dde7c95SVishal Kulkarni  */
7183dde7c95SVishal Kulkarni int
t4_rx_stat(mac_ring_driver_t rh,uint_t stat,uint64_t * val)7193dde7c95SVishal Kulkarni t4_rx_stat(mac_ring_driver_t rh, uint_t stat, uint64_t *val)
7203dde7c95SVishal Kulkarni {
7213dde7c95SVishal Kulkarni 	struct sge_rxq *rxq = (struct sge_rxq *)rh;
7223dde7c95SVishal Kulkarni 
7233dde7c95SVishal Kulkarni 	switch (stat) {
7243dde7c95SVishal Kulkarni 	case MAC_STAT_RBYTES:
7253dde7c95SVishal Kulkarni 		*val = rxq->rxbytes;
7263dde7c95SVishal Kulkarni 		break;
7273dde7c95SVishal Kulkarni 
7283dde7c95SVishal Kulkarni 	case MAC_STAT_IPACKETS:
7293dde7c95SVishal Kulkarni 		*val = rxq->rxpkts;
7303dde7c95SVishal Kulkarni 		break;
7313dde7c95SVishal Kulkarni 
7323dde7c95SVishal Kulkarni 	default:
7333dde7c95SVishal Kulkarni 		*val = 0;
7343dde7c95SVishal Kulkarni 		return (ENOTSUP);
7353dde7c95SVishal Kulkarni 	}
7363dde7c95SVishal Kulkarni 
7373dde7c95SVishal Kulkarni 	return (0);
7383dde7c95SVishal Kulkarni }
7393dde7c95SVishal Kulkarni 
7403dde7c95SVishal Kulkarni /*
7413dde7c95SVishal Kulkarni  * Retrieve a value for one of the statistics for a particular tx ring
7423dde7c95SVishal Kulkarni  */
7433dde7c95SVishal Kulkarni int
t4_tx_stat(mac_ring_driver_t rh,uint_t stat,uint64_t * val)7443dde7c95SVishal Kulkarni t4_tx_stat(mac_ring_driver_t rh, uint_t stat, uint64_t *val)
7453dde7c95SVishal Kulkarni {
7463dde7c95SVishal Kulkarni 	struct sge_txq *txq = (struct sge_txq *)rh;
7473dde7c95SVishal Kulkarni 
7483dde7c95SVishal Kulkarni 	switch (stat) {
7493dde7c95SVishal Kulkarni 	case MAC_STAT_RBYTES:
7503dde7c95SVishal Kulkarni 		*val = txq->txbytes;
7513dde7c95SVishal Kulkarni 		break;
7523dde7c95SVishal Kulkarni 
7533dde7c95SVishal Kulkarni 	case MAC_STAT_IPACKETS:
7543dde7c95SVishal Kulkarni 		*val = txq->txpkts;
7553dde7c95SVishal Kulkarni 		break;
7563dde7c95SVishal Kulkarni 
7573dde7c95SVishal Kulkarni 	default:
7583dde7c95SVishal Kulkarni 		*val = 0;
7593dde7c95SVishal Kulkarni 		return (ENOTSUP);
7603dde7c95SVishal Kulkarni 	}
7613dde7c95SVishal Kulkarni 
7623dde7c95SVishal Kulkarni 	return (0);
7633dde7c95SVishal Kulkarni }
7643dde7c95SVishal Kulkarni 
7653dde7c95SVishal Kulkarni /*
7663dde7c95SVishal Kulkarni  * Callback funtion for MAC layer to register all rings
7673dde7c95SVishal Kulkarni  * for given ring_group, noted by group_index.
7683dde7c95SVishal Kulkarni  * Since we have only one group, ring index becomes
7693dde7c95SVishal Kulkarni  * absolute index.
7703dde7c95SVishal Kulkarni  */
7713dde7c95SVishal Kulkarni void
t4_fill_ring(void * arg,mac_ring_type_t rtype,const int group_index,const int ring_index,mac_ring_info_t * infop,mac_ring_handle_t rh)7723dde7c95SVishal Kulkarni t4_fill_ring(void *arg, mac_ring_type_t rtype, const int group_index,
7733dde7c95SVishal Kulkarni 	     const int ring_index, mac_ring_info_t *infop, mac_ring_handle_t rh)
7743dde7c95SVishal Kulkarni {
7753dde7c95SVishal Kulkarni 	struct port_info *pi = arg;
7763dde7c95SVishal Kulkarni 	mac_intr_t *mintr;
7773dde7c95SVishal Kulkarni 
7783dde7c95SVishal Kulkarni 	switch (rtype) {
7793dde7c95SVishal Kulkarni 	case MAC_RING_TYPE_RX: {
7803dde7c95SVishal Kulkarni 		struct sge_rxq *rxq;
7813dde7c95SVishal Kulkarni 
7823dde7c95SVishal Kulkarni 		rxq = &pi->adapter->sge.rxq[pi->first_rxq + ring_index];
7833dde7c95SVishal Kulkarni 		rxq->ring_handle = rh;
7843dde7c95SVishal Kulkarni 
7853dde7c95SVishal Kulkarni 		infop->mri_driver = (mac_ring_driver_t)rxq;
7863dde7c95SVishal Kulkarni 		infop->mri_start = t4_ring_start;
7873dde7c95SVishal Kulkarni 		infop->mri_stop = NULL;
7883dde7c95SVishal Kulkarni 		infop->mri_poll = t4_poll_ring;
7893dde7c95SVishal Kulkarni 		infop->mri_stat = t4_rx_stat;
7903dde7c95SVishal Kulkarni 
7913dde7c95SVishal Kulkarni 		mintr = &infop->mri_intr;
7923dde7c95SVishal Kulkarni 		mintr->mi_handle = (mac_intr_handle_t)rxq;
7933dde7c95SVishal Kulkarni 		mintr->mi_enable = t4_ring_intr_enable;
7943dde7c95SVishal Kulkarni 		mintr->mi_disable = t4_ring_intr_disable;
7953dde7c95SVishal Kulkarni 
7963dde7c95SVishal Kulkarni 		break;
7973dde7c95SVishal Kulkarni 	}
7983dde7c95SVishal Kulkarni 	case MAC_RING_TYPE_TX: {
7993dde7c95SVishal Kulkarni 		struct sge_txq *txq = &pi->adapter->sge.txq[pi->first_txq + ring_index];
8003dde7c95SVishal Kulkarni 		txq->ring_handle = rh;
8013dde7c95SVishal Kulkarni 		infop->mri_driver = (mac_ring_driver_t)txq;
8023dde7c95SVishal Kulkarni 		infop->mri_start = NULL;
8033dde7c95SVishal Kulkarni 		infop->mri_stop = NULL;
8043dde7c95SVishal Kulkarni 		infop->mri_tx = t4_eth_tx;
8053dde7c95SVishal Kulkarni 		infop->mri_stat = t4_tx_stat;
8063dde7c95SVishal Kulkarni 		break;
8073dde7c95SVishal Kulkarni 	}
8083dde7c95SVishal Kulkarni 	default:
8093dde7c95SVishal Kulkarni 		ASSERT(0);
8103dde7c95SVishal Kulkarni 		break;
8113dde7c95SVishal Kulkarni 	}
8123dde7c95SVishal Kulkarni }
8133dde7c95SVishal Kulkarni 
8143dde7c95SVishal Kulkarni mblk_t *
t4_mc_tx(void * arg,mblk_t * m)81556b2bdd1SGireesh Nagabhushana t4_mc_tx(void *arg, mblk_t *m)
81656b2bdd1SGireesh Nagabhushana {
81756b2bdd1SGireesh Nagabhushana 	struct port_info *pi = arg;
81856b2bdd1SGireesh Nagabhushana 	struct adapter *sc = pi->adapter;
81956b2bdd1SGireesh Nagabhushana 	struct sge_txq *txq = &sc->sge.txq[pi->first_txq];
82056b2bdd1SGireesh Nagabhushana 
8213dde7c95SVishal Kulkarni 	return (t4_eth_tx(txq, m));
82256b2bdd1SGireesh Nagabhushana }
82356b2bdd1SGireesh Nagabhushana 
824017c366dSRobert Mustacchi static int
t4_mc_transceiver_info(void * arg,uint_t id,mac_transceiver_info_t * infop)825017c366dSRobert Mustacchi t4_mc_transceiver_info(void *arg, uint_t id, mac_transceiver_info_t *infop)
826017c366dSRobert Mustacchi {
827017c366dSRobert Mustacchi 	struct port_info *pi = arg;
828017c366dSRobert Mustacchi 
829017c366dSRobert Mustacchi 	if (id != 0 || infop == NULL)
830017c366dSRobert Mustacchi 		return (EINVAL);
831017c366dSRobert Mustacchi 
832017c366dSRobert Mustacchi 	switch (pi->mod_type) {
833017c366dSRobert Mustacchi 	case FW_PORT_MOD_TYPE_NONE:
834017c366dSRobert Mustacchi 		mac_transceiver_info_set_present(infop, B_FALSE);
835017c366dSRobert Mustacchi 		break;
836017c366dSRobert Mustacchi 	case FW_PORT_MOD_TYPE_NOTSUPPORTED:
837017c366dSRobert Mustacchi 		mac_transceiver_info_set_present(infop, B_TRUE);
838017c366dSRobert Mustacchi 		mac_transceiver_info_set_usable(infop, B_FALSE);
839017c366dSRobert Mustacchi 		break;
840017c366dSRobert Mustacchi 	default:
841017c366dSRobert Mustacchi 		mac_transceiver_info_set_present(infop, B_TRUE);
842017c366dSRobert Mustacchi 		mac_transceiver_info_set_usable(infop, B_TRUE);
843017c366dSRobert Mustacchi 		break;
844017c366dSRobert Mustacchi 	}
845017c366dSRobert Mustacchi 
846017c366dSRobert Mustacchi 	return (0);
847017c366dSRobert Mustacchi }
848017c366dSRobert Mustacchi 
849017c366dSRobert Mustacchi static int
t4_mc_transceiver_read(void * arg,uint_t id,uint_t page,void * bp,size_t nbytes,off_t offset,size_t * nread)850017c366dSRobert Mustacchi t4_mc_transceiver_read(void *arg, uint_t id, uint_t page, void *bp,
851017c366dSRobert Mustacchi     size_t nbytes, off_t offset, size_t *nread)
852017c366dSRobert Mustacchi {
853017c366dSRobert Mustacchi 	struct port_info *pi = arg;
854017c366dSRobert Mustacchi 	struct adapter *sc = pi->adapter;
855017c366dSRobert Mustacchi 	int rc;
856017c366dSRobert Mustacchi 	size_t i, maxread;
857017c366dSRobert Mustacchi 	/* LINTED: E_FUNC_VAR_UNUSED */
858017c366dSRobert Mustacchi 	struct fw_ldst_cmd ldst __unused;
859017c366dSRobert Mustacchi 
860017c366dSRobert Mustacchi 	if (id != 0 || bp == NULL || nbytes == 0 || nread == NULL ||
861017c366dSRobert Mustacchi 	    (page != 0xa0 && page != 0xa2) || offset < 0)
862017c366dSRobert Mustacchi 		return (EINVAL);
863017c366dSRobert Mustacchi 
864017c366dSRobert Mustacchi 	if (nbytes > 256 || offset >= 256 || (offset + nbytes > 256))
865017c366dSRobert Mustacchi 		return (