11ae08745Sheppo /* 21ae08745Sheppo * CDDL HEADER START 31ae08745Sheppo * 41ae08745Sheppo * The contents of this file are subject to the terms of the 51ae08745Sheppo * Common Development and Distribution License (the "License"). 61ae08745Sheppo * You may not use this file except in compliance with the License. 71ae08745Sheppo * 81ae08745Sheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91ae08745Sheppo * or http://www.opensolaris.org/os/licensing. 101ae08745Sheppo * See the License for the specific language governing permissions 111ae08745Sheppo * and limitations under the License. 121ae08745Sheppo * 131ae08745Sheppo * When distributing Covered Code, include this CDDL HEADER in each 141ae08745Sheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151ae08745Sheppo * If applicable, add the following below this CDDL HEADER, with the 161ae08745Sheppo * fields enclosed by brackets "[]" replaced with your own identifying 171ae08745Sheppo * information: Portions Copyright [yyyy] [name of copyright owner] 181ae08745Sheppo * 191ae08745Sheppo * CDDL HEADER END 201ae08745Sheppo */ 211ae08745Sheppo 221ae08745Sheppo /* 23a862df29SSriharsha Basavapatna * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 241ae08745Sheppo */ 251ae08745Sheppo 261ae08745Sheppo #include <sys/types.h> 271ae08745Sheppo #include <sys/errno.h> 281ae08745Sheppo #include <sys/debug.h> 291ae08745Sheppo #include <sys/time.h> 301ae08745Sheppo #include <sys/sysmacros.h> 311ae08745Sheppo #include <sys/systm.h> 321ae08745Sheppo #include <sys/user.h> 331ae08745Sheppo #include <sys/stropts.h> 341ae08745Sheppo #include <sys/stream.h> 351ae08745Sheppo #include <sys/strlog.h> 361ae08745Sheppo #include <sys/strsubr.h> 371ae08745Sheppo #include <sys/cmn_err.h> 381ae08745Sheppo #include <sys/cpu.h> 391ae08745Sheppo #include <sys/kmem.h> 401ae08745Sheppo #include <sys/conf.h> 411ae08745Sheppo #include <sys/ddi.h> 421ae08745Sheppo #include <sys/sunddi.h> 431ae08745Sheppo #include <sys/ksynch.h> 441ae08745Sheppo #include <sys/stat.h> 451ae08745Sheppo #include <sys/kstat.h> 461ae08745Sheppo #include <sys/vtrace.h> 471ae08745Sheppo #include <sys/strsun.h> 481ae08745Sheppo #include <sys/dlpi.h> 491ae08745Sheppo #include <sys/ethernet.h> 501ae08745Sheppo #include <net/if.h> 511ae08745Sheppo #include <sys/varargs.h> 521ae08745Sheppo #include <sys/machsystm.h> 531ae08745Sheppo #include <sys/modctl.h> 541ae08745Sheppo #include <sys/modhash.h> 55da14cebeSEric Cheng #include <sys/mac_provider.h> 56ba2e4443Sseb #include <sys/mac_ether.h> 571ae08745Sheppo #include <sys/taskq.h> 581ae08745Sheppo #include <sys/note.h> 591ae08745Sheppo #include <sys/mach_descrip.h> 60da14cebeSEric Cheng #include <sys/mac_provider.h> 611ae08745Sheppo #include <sys/mdeg.h> 621ae08745Sheppo #include <sys/ldc.h> 631ae08745Sheppo #include <sys/vsw_fdb.h> 641ae08745Sheppo #include <sys/vsw.h> 651ae08745Sheppo #include <sys/vio_mailbox.h> 661ae08745Sheppo #include <sys/vnet_mailbox.h> 671ae08745Sheppo #include <sys/vnet_common.h> 68d10e4ef2Snarayan #include <sys/vio_util.h> 69d10e4ef2Snarayan #include <sys/sdt.h> 7019b65a69Ssb155480 #include <sys/atomic.h> 7106db247cSraghuram #include <sys/callb.h> 72c1c61f44Ssb155480 #include <sys/vlan.h> 731ae08745Sheppo 741ae08745Sheppo /* 751ae08745Sheppo * Function prototypes. 761ae08745Sheppo */ 771ae08745Sheppo static int vsw_attach(dev_info_t *, ddi_attach_cmd_t); 781ae08745Sheppo static int vsw_detach(dev_info_t *, ddi_detach_cmd_t); 796f09f0feSWENTAO YANG static int vsw_unattach(vsw_t *vswp); 8034683adeSsg70180 static int vsw_get_md_physname(vsw_t *, md_t *, mde_cookie_t, char *); 81da14cebeSEric Cheng static int vsw_get_md_smodes(vsw_t *, md_t *, mde_cookie_t, uint8_t *); 8234b64c01SWENTAO YANG void vsw_destroy_rxpools(void *); 831ae08745Sheppo 841ae08745Sheppo /* MDEG routines */ 8534683adeSsg70180 static int vsw_mdeg_register(vsw_t *vswp); 861ae08745Sheppo static void vsw_mdeg_unregister(vsw_t *vswp); 871ae08745Sheppo static int vsw_mdeg_cb(void *cb_argp, mdeg_result_t *); 8834683adeSsg70180 static int vsw_port_mdeg_cb(void *cb_argp, mdeg_result_t *); 8919b65a69Ssb155480 static int vsw_get_initial_md_properties(vsw_t *vswp, md_t *, mde_cookie_t); 90c1c61f44Ssb155480 static int vsw_read_mdprops(vsw_t *vswp); 91c1c61f44Ssb155480 static void vsw_vlan_read_ids(void *arg, int type, md_t *mdp, 92da14cebeSEric Cheng mde_cookie_t node, uint16_t *pvidp, vsw_vlanid_t **vidspp, 93c1c61f44Ssb155480 uint16_t *nvidsp, uint16_t *default_idp); 94bce0a86eSWENTAO YANG static void vsw_port_read_bandwidth(vsw_port_t *portp, md_t *mdp, 95bce0a86eSWENTAO YANG mde_cookie_t node, uint64_t *bw); 96c1c61f44Ssb155480 static int vsw_port_read_props(vsw_port_t *portp, vsw_t *vswp, 97c1c61f44Ssb155480 md_t *mdp, mde_cookie_t *node); 98f0ca1d9aSsb155480 static void vsw_read_pri_eth_types(vsw_t *vswp, md_t *mdp, 99f0ca1d9aSsb155480 mde_cookie_t node); 1007b1f684aSSriharsha Basavapatna static void vsw_mtu_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node, 1017b1f684aSSriharsha Basavapatna uint32_t *mtu); 1027b1f684aSSriharsha Basavapatna static int vsw_mtu_update(vsw_t *vswp, uint32_t mtu); 1031107ea93SSriharsha Basavapatna static void vsw_linkprop_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node, 1041107ea93SSriharsha Basavapatna boolean_t *pls); 105bce0a86eSWENTAO YANG static void vsw_bandwidth_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node, 106bce0a86eSWENTAO YANG uint64_t *bw); 10734683adeSsg70180 static void vsw_update_md_prop(vsw_t *, md_t *, mde_cookie_t); 10819b65a69Ssb155480 static void vsw_save_lmacaddr(vsw_t *vswp, uint64_t macaddr); 109da14cebeSEric Cheng static boolean_t vsw_cmp_vids(vsw_vlanid_t *vids1, 110da14cebeSEric Cheng vsw_vlanid_t *vids2, int nvids); 1111ae08745Sheppo 11206db247cSraghuram /* Mac driver related routines */ 11306db247cSraghuram static int vsw_mac_register(vsw_t *); 11406db247cSraghuram static int vsw_mac_unregister(vsw_t *); 11506db247cSraghuram static int vsw_m_stat(void *, uint_t, uint64_t *); 11606db247cSraghuram static void vsw_m_stop(void *arg); 11706db247cSraghuram static int vsw_m_start(void *arg); 11806db247cSraghuram static int vsw_m_unicst(void *arg, const uint8_t *); 11906db247cSraghuram static int vsw_m_multicst(void *arg, boolean_t, const uint8_t *); 12006db247cSraghuram static int vsw_m_promisc(void *arg, boolean_t); 12106db247cSraghuram static mblk_t *vsw_m_tx(void *arg, mblk_t *); 122d8a518c8SSriharsha Basavapatna void vsw_mac_link_update(vsw_t *vswp, link_state_t link_state); 123f0ca1d9aSsb155480 void vsw_mac_rx(vsw_t *vswp, mac_resource_handle_t mrh, 124f0ca1d9aSsb155480 mblk_t *mp, vsw_macrx_flags_t flags); 1251107ea93SSriharsha Basavapatna void vsw_physlink_state_update(vsw_t *vswp); 1261ae08745Sheppo 12706db247cSraghuram /* 12806db247cSraghuram * Functions imported from other files. 12906db247cSraghuram */ 130808f26a8SSriharsha Basavapatna extern void vsw_setup_switching_thread(void *arg); 131808f26a8SSriharsha Basavapatna extern int vsw_setup_switching_start(vsw_t *vswp); 132808f26a8SSriharsha Basavapatna extern void vsw_setup_switching_stop(vsw_t *vswp); 13306db247cSraghuram extern int vsw_setup_switching(vsw_t *); 1347a327842Swentaoy extern void vsw_switch_frame_nop(vsw_t *vswp, mblk_t *mp, int caller, 1357a327842Swentaoy vsw_port_t *port, mac_resource_handle_t mrh); 13606db247cSraghuram extern int vsw_add_mcst(vsw_t *, uint8_t, uint64_t, void *); 13706db247cSraghuram extern int vsw_del_mcst(vsw_t *, uint8_t, uint64_t, void *); 13806db247cSraghuram extern void vsw_del_mcst_vsw(vsw_t *); 13906db247cSraghuram extern mcst_addr_t *vsw_del_addr(uint8_t devtype, void *arg, uint64_t addr); 1406f09f0feSWENTAO YANG extern void vsw_detach_ports(vsw_t *vswp); 14106db247cSraghuram extern int vsw_port_add(vsw_t *vswp, md_t *mdp, mde_cookie_t *node); 14206db247cSraghuram extern int vsw_port_detach(vsw_t *vswp, int p_instance); 143c1c61f44Ssb155480 static int vsw_port_update(vsw_t *vswp, md_t *curr_mdp, mde_cookie_t curr_mdex, 144c1c61f44Ssb155480 md_t *prev_mdp, mde_cookie_t prev_mdex); 145c1c61f44Ssb155480 extern int vsw_port_attach(vsw_port_t *port); 14606db247cSraghuram extern vsw_port_t *vsw_lookup_port(vsw_t *vswp, int p_instance); 14706db247cSraghuram extern int vsw_mac_open(vsw_t *vswp); 14806db247cSraghuram extern void vsw_mac_close(vsw_t *vswp); 149da14cebeSEric Cheng extern void vsw_mac_cleanup_ports(vsw_t *vswp); 15006db247cSraghuram extern void vsw_unset_addrs(vsw_t *vswp); 151d8a518c8SSriharsha Basavapatna extern void vsw_setup_switching_post_process(vsw_t *vswp); 152c1c61f44Ssb155480 extern void vsw_create_vlans(void *arg, int type); 153c1c61f44Ssb155480 extern void vsw_destroy_vlans(void *arg, int type); 154c1c61f44Ssb155480 extern void vsw_vlan_add_ids(void *arg, int type); 155c1c61f44Ssb155480 extern void vsw_vlan_remove_ids(void *arg, int type); 156c1c61f44Ssb155480 extern void vsw_vlan_unaware_port_reset(vsw_port_t *portp); 157c1c61f44Ssb155480 extern uint32_t vsw_vlan_frame_untag(void *arg, int type, mblk_t **np, 158c1c61f44Ssb155480 mblk_t **npt); 159c1c61f44Ssb155480 extern mblk_t *vsw_vlan_frame_pretag(void *arg, int type, mblk_t *mp); 160678453a8Sspeer extern void vsw_hio_cleanup(vsw_t *vswp); 161da14cebeSEric Cheng extern void vsw_hio_start_ports(vsw_t *vswp); 162da14cebeSEric Cheng extern void vsw_hio_port_update(vsw_port_t *portp, boolean_t hio_enabled); 163da14cebeSEric Cheng extern int vsw_mac_multicast_add(vsw_t *, vsw_port_t *, mcst_addr_t *, int); 164da14cebeSEric Cheng extern void vsw_mac_multicast_remove(vsw_t *, vsw_port_t *, mcst_addr_t *, int); 165da14cebeSEric Cheng extern void vsw_mac_port_reconfig_vlans(vsw_port_t *portp, uint16_t new_pvid, 166da14cebeSEric Cheng vsw_vlanid_t *new_vids, int new_nvids); 167da14cebeSEric Cheng extern int vsw_mac_client_init(vsw_t *vswp, vsw_port_t *port, int type); 168da14cebeSEric Cheng extern void vsw_mac_client_cleanup(vsw_t *vswp, vsw_port_t *port, int type); 169da14cebeSEric Cheng extern void vsw_if_mac_reconfig(vsw_t *vswp, boolean_t update_vlans, 170da14cebeSEric Cheng uint16_t new_pvid, vsw_vlanid_t *new_vids, int new_nvids); 1717b1f684aSSriharsha Basavapatna extern void vsw_reset_ports(vsw_t *vswp); 1727b1f684aSSriharsha Basavapatna extern void vsw_port_reset(vsw_port_t *portp); 1731107ea93SSriharsha Basavapatna extern void vsw_physlink_update_ports(vsw_t *vswp); 174bce0a86eSWENTAO YANG extern void vsw_update_bandwidth(vsw_t *vswp, vsw_port_t *port, int type, 175bce0a86eSWENTAO YANG uint64_t maxbw); 17606db247cSraghuram 17706db247cSraghuram /* 17806db247cSraghuram * Internal tunables. 17906db247cSraghuram */ 180445b4c2eSsb155480 int vsw_num_handshakes = VNET_NUM_HANDSHAKES; /* # of handshake attempts */ 1811ae08745Sheppo int vsw_wretries = 100; /* # of write attempts */ 18219b65a69Ssb155480 int vsw_setup_switching_delay = 3; /* setup sw timeout interval in sec */ 1830e8b4070Ssb155480 int vsw_mac_open_retries = 300; /* max # of mac_open() retries */ 1840e8b4070Ssb155480 /* 300*3 = 900sec(15min) of max tmout */ 18506db247cSraghuram int vsw_ldc_tx_delay = 5; /* delay(ticks) for tx retries */ 18606db247cSraghuram int vsw_ldc_tx_retries = 10; /* # of ldc tx retries */ 1876f09f0feSWENTAO YANG int vsw_ldc_retries = 5; /* # of ldc_close() retries */ 1886f09f0feSWENTAO YANG int vsw_ldc_delay = 1000; /* 1 ms delay for ldc_close() */ 18906db247cSraghuram boolean_t vsw_ldc_rxthr_enabled = B_TRUE; /* LDC Rx thread enabled */ 19006db247cSraghuram boolean_t vsw_ldc_txthr_enabled = B_TRUE; /* LDC Tx thread enabled */ 19134b64c01SWENTAO YANG int vsw_rxpool_cleanup_delay = 100000; /* 100ms */ 19234b64c01SWENTAO YANG 193d10e4ef2Snarayan 194c1c61f44Ssb155480 uint32_t vsw_fdb_nchains = 8; /* # of chains in fdb hash table */ 195c1c61f44Ssb155480 uint32_t vsw_vlan_nchains = 4; /* # of chains in vlan id hash table */ 196c1c61f44Ssb155480 uint32_t vsw_ethermtu = 1500; /* mtu of the device */ 197c1c61f44Ssb155480 198c1c61f44Ssb155480 /* delay in usec to wait for all references on a fdb entry to be dropped */ 199c1c61f44Ssb155480 uint32_t vsw_fdbe_refcnt_delay = 10; 200c1c61f44Ssb155480 201c1c61f44Ssb155480 /* 202c1c61f44Ssb155480 * Default vlan id. This is only used internally when the "default-vlan-id" 203c1c61f44Ssb155480 * property is not present in the MD device node. Therefore, this should not be 204c1c61f44Ssb155480 * used as a tunable; if this value is changed, the corresponding variable 205c1c61f44Ssb155480 * should be updated to the same value in all vnets connected to this vsw. 206c1c61f44Ssb155480 */ 207c1c61f44Ssb155480 uint16_t vsw_default_vlan_id = 1; 208c1c61f44Ssb155480 209f0ca1d9aSsb155480 /* 210f0ca1d9aSsb155480 * Workaround for a version handshake bug in obp's vnet. 211f0ca1d9aSsb155480 * If vsw initiates version negotiation starting from the highest version, 212f0ca1d9aSsb155480 * obp sends a nack and terminates version handshake. To workaround 213f0ca1d9aSsb155480 * this, we do not initiate version handshake when the channel comes up. 214f0ca1d9aSsb155480 * Instead, we wait for the peer to send its version info msg and go through 215f0ca1d9aSsb155480 * the version protocol exchange. If we successfully negotiate a version, 216f0ca1d9aSsb155480 * before sending the ack, we send our version info msg to the peer 217f0ca1d9aSsb155480 * using the <major,minor> version that we are about to ack. 218f0ca1d9aSsb155480 */ 219f0ca1d9aSsb155480 boolean_t vsw_obp_ver_proto_workaround = B_TRUE; 220f0ca1d9aSsb155480 221f0ca1d9aSsb155480 /* 222f0ca1d9aSsb155480 * In the absence of "priority-ether-types" property in MD, the following 223f0ca1d9aSsb155480 * internal tunable can be set to specify a single priority ethertype. 224f0ca1d9aSsb155480 */ 225f0ca1d9aSsb155480 uint64_t vsw_pri_eth_type = 0; 226f0ca1d9aSsb155480 227f0ca1d9aSsb155480 /* 228f0ca1d9aSsb155480 * Number of transmit priority buffers that are preallocated per device. 229f0ca1d9aSsb155480 * This number is chosen to be a small value to throttle transmission 230f0ca1d9aSsb155480 * of priority packets. Note: Must be a power of 2 for vio_create_mblks(). 231f0ca1d9aSsb155480 */ 232f0ca1d9aSsb155480 uint32_t vsw_pri_tx_nmblks = 64; 233d10e4ef2Snarayan 23451aa9d07Ssb155480 /* 23551aa9d07Ssb155480 * Number of RARP packets sent to announce macaddr to the physical switch, 23651aa9d07Ssb155480 * after vsw's physical device is changed dynamically or after a guest (client 23751aa9d07Ssb155480 * vnet) is live migrated in. 23851aa9d07Ssb155480 */ 23951aa9d07Ssb155480 uint32_t vsw_publish_macaddr_count = 3; 24051aa9d07Ssb155480 2417bd3a2e2SSriharsha Basavapatna /* 2427bd3a2e2SSriharsha Basavapatna * Enable/disable HybridIO 2437bd3a2e2SSriharsha Basavapatna */ 2447bd3a2e2SSriharsha Basavapatna boolean_t vsw_hio_enabled = B_TRUE; 245678453a8Sspeer 2467bd3a2e2SSriharsha Basavapatna /* 2477bd3a2e2SSriharsha Basavapatna * Max retries for HybridIO cleanup 2487bd3a2e2SSriharsha Basavapatna */ 2497bd3a2e2SSriharsha Basavapatna int vsw_hio_max_cleanup_retries = 10; 2507bd3a2e2SSriharsha Basavapatna 2517bd3a2e2SSriharsha Basavapatna /* 2527bd3a2e2SSriharsha Basavapatna * 10ms delay for HybridIO cleanup 2537bd3a2e2SSriharsha Basavapatna */ 2547bd3a2e2SSriharsha Basavapatna int vsw_hio_cleanup_delay = 10000; 2557bd3a2e2SSriharsha Basavapatna 2567bd3a2e2SSriharsha Basavapatna /* 2577bd3a2e2SSriharsha Basavapatna * Descriptor ring modes of LDC data transfer: 2587bd3a2e2SSriharsha Basavapatna * 2597bd3a2e2SSriharsha Basavapatna * 1) TxDring mode: 2607bd3a2e2SSriharsha Basavapatna * In versions < v1.6 of VIO Protocol, we support only TxDring mode. In this 2617bd3a2e2SSriharsha Basavapatna * mode, we create a transmit descriptor ring and export it to the peer through 2627bd3a2e2SSriharsha Basavapatna * dring registration process of handshake. The descriptor ring is exported 2637bd3a2e2SSriharsha Basavapatna * using LDC shared memory. Each descriptor is associated with a data buffer. 2647bd3a2e2SSriharsha Basavapatna * The data buffer is also exported over LDC and the cookies for this data 2657bd3a2e2SSriharsha Basavapatna * buffer are provided in the descriptor. The peer maps this ring as its 2667bd3a2e2SSriharsha Basavapatna * receive ring. Similarly, the peer exports a transmit descriptor ring which 2677bd3a2e2SSriharsha Basavapatna * is mapped by this device as its receive ring. In this mode, in a given data 2687bd3a2e2SSriharsha Basavapatna * transfer direction, the transmitter copies the data to the exported data 2697bd3a2e2SSriharsha Basavapatna * buffer (owned by itself), bound to the descriptor. The receiver uses the LDC 2707bd3a2e2SSriharsha Basavapatna * cookies specified in the descriptor to copy the data into the receiving 2717bd3a2e2SSriharsha Basavapatna * guest through the hypervisor (ldc_mem_copy()). 2727bd3a2e2SSriharsha Basavapatna * 2737bd3a2e2SSriharsha Basavapatna * 2) RxDringData mode: 2747bd3a2e2SSriharsha Basavapatna * In versions >= v1.6 of VIO Protocol, we also support RxDringData mode. In 2757bd3a2e2SSriharsha Basavapatna * this mode, we create a receive descriptor ring and export it to the peer 2767bd3a2e2SSriharsha Basavapatna * through dring registration process of handshake. In addition, we export a 2777bd3a2e2SSriharsha Basavapatna * receive buffer area and provide that information also in the dring 2787bd3a2e2SSriharsha Basavapatna * registration message. The descriptor ring and the data buffer area are 2797bd3a2e2SSriharsha Basavapatna * exported using LDC shared memory. Each descriptor is associated with a data 2807bd3a2e2SSriharsha Basavapatna * buffer in the data buffer area and the offset of the specific data buffer 2817bd3a2e2SSriharsha Basavapatna * within this area is specified in the descriptor. The peer maps this ring 2827bd3a2e2SSriharsha Basavapatna * along with the data buffer area as its transmit ring. Similarly, the peer 2837bd3a2e2SSriharsha Basavapatna * exports a receive ring which is mapped by this device as its transmit ring, 2847bd3a2e2SSriharsha Basavapatna * along with its buffer area. In this mode, in a given data transfer 2857bd3a2e2SSriharsha Basavapatna * direction, the transmitter copies the data to the data buffer offset 2867bd3a2e2SSriharsha Basavapatna * specified in the descriptor. The receiver simply picks up the data buffer 2877bd3a2e2SSriharsha Basavapatna * (owned by itself) without any copy operation into the receiving guest. 2887bd3a2e2SSriharsha Basavapatna * 28934f94fbcSWENTAO YANG * We enable RxDringData mode during handshake negotiations if LDC supports 29034f94fbcSWENTAO YANG * mapping in large areas of shared memory(see ldc_is_viotsb_configured() API), 29134f94fbcSWENTAO YANG * which is required to support RxDringData mode. 2927bd3a2e2SSriharsha Basavapatna */ 2937bd3a2e2SSriharsha Basavapatna 2947bd3a2e2SSriharsha Basavapatna /* 2957bd3a2e2SSriharsha Basavapatna * Number of descriptors; must be power of 2. 2967bd3a2e2SSriharsha Basavapatna */ 2977bd3a2e2SSriharsha Basavapatna uint32_t vsw_num_descriptors = VSW_NUM_DESCRIPTORS; 2987bd3a2e2SSriharsha Basavapatna 2997bd3a2e2SSriharsha Basavapatna /* 3007bd3a2e2SSriharsha Basavapatna * In RxDringData mode, # of buffers is determined by multiplying the # of 3017bd3a2e2SSriharsha Basavapatna * descriptors with the factor below. Note that the factor must be > 1; i.e, 3027bd3a2e2SSriharsha Basavapatna * the # of buffers must always be > # of descriptors. This is needed because, 3037bd3a2e2SSriharsha Basavapatna * while the shared memory buffers are sent up the stack on the receiver, the 3047bd3a2e2SSriharsha Basavapatna * sender needs additional buffers that can be used for further transmits. 3057bd3a2e2SSriharsha Basavapatna * See vsw_setup_rx_dring() for details. 3067bd3a2e2SSriharsha Basavapatna */ 3077bd3a2e2SSriharsha Basavapatna uint32_t vsw_nrbufs_factor = 2; 3087bd3a2e2SSriharsha Basavapatna 3097bd3a2e2SSriharsha Basavapatna /* 3107bd3a2e2SSriharsha Basavapatna * Delay when rx descr not ready; used in both dring modes. 3117bd3a2e2SSriharsha Basavapatna */ 3127bd3a2e2SSriharsha Basavapatna int vsw_recv_delay = 0; 3137bd3a2e2SSriharsha Basavapatna 3147bd3a2e2SSriharsha Basavapatna /* 3157bd3a2e2SSriharsha Basavapatna * Retry when rx descr not ready; used in both dring modes. 3167bd3a2e2SSriharsha Basavapatna */ 3177bd3a2e2SSriharsha Basavapatna int vsw_recv_retries = 5; 318f0ca1d9aSsb155480 31906db247cSraghuram /* 32006db247cSraghuram * Max number of mblks received in one receive operation. 32106db247cSraghuram */ 32206db247cSraghuram uint32_t vsw_chain_len = (VSW_NUM_MBLKS * 0.6); 32306db247cSraghuram 32406db247cSraghuram /* 3257b1f684aSSriharsha Basavapatna * Internal tunables for receive buffer pools, that is, the size and number of 3267b1f684aSSriharsha Basavapatna * mblks for each pool. At least 3 sizes must be specified if these are used. 3277b1f684aSSriharsha Basavapatna * The sizes must be specified in increasing order. Non-zero value of the first 3287b1f684aSSriharsha Basavapatna * size will be used as a hint to use these values instead of the algorithm 3297bd3a2e2SSriharsha Basavapatna * that determines the sizes based on MTU. Used in TxDring mode only. 33006db247cSraghuram */ 3317b1f684aSSriharsha Basavapatna uint32_t vsw_mblk_size1 = 0; 3327b1f684aSSriharsha Basavapatna uint32_t vsw_mblk_size2 = 0; 3337b1f684aSSriharsha Basavapatna uint32_t vsw_mblk_size3 = 0; 3347b1f684aSSriharsha Basavapatna uint32_t vsw_mblk_size4 = 0; 33506db247cSraghuram uint32_t vsw_num_mblks1 = VSW_NUM_MBLKS; /* number of mblks for pool1 */ 33606db247cSraghuram uint32_t vsw_num_mblks2 = VSW_NUM_MBLKS; /* number of mblks for pool2 */ 33706db247cSraghuram uint32_t vsw_num_mblks3 = VSW_NUM_MBLKS; /* number of mblks for pool3 */ 3387b1f684aSSriharsha Basavapatna uint32_t vsw_num_mblks4 = VSW_NUM_MBLKS; /* number of mblks for pool4 */ 3397b1f684aSSriharsha Basavapatna 3407b1f684aSSriharsha Basavapatna /* 3417b1f684aSSriharsha Basavapatna * Set this to non-zero to enable additional internal receive buffer pools 3427b1f684aSSriharsha Basavapatna * based on the MTU of the device for better performance at the cost of more 3437b1f684aSSriharsha Basavapatna * memory consumption. This is turned off by default, to use allocb(9F) for 3447b1f684aSSriharsha Basavapatna * receive buffer allocations of sizes > 2K. 3457b1f684aSSriharsha Basavapatna */ 3467b1f684aSSriharsha Basavapatna boolean_t vsw_jumbo_rxpools = B_FALSE; 34706db247cSraghuram 34806db247cSraghuram /* 349f0ca1d9aSsb155480 * vsw_max_tx_qcount is the maximum # of packets that can be queued 350f0ca1d9aSsb155480 * before the tx worker thread begins processing the queue. Its value 351f0ca1d9aSsb155480 * is chosen to be 4x the default length of tx descriptor ring. 352f0ca1d9aSsb155480 */ 3537bd3a2e2SSriharsha Basavapatna uint32_t vsw_max_tx_qcount = 4 * VSW_NUM_DESCRIPTORS; 354f0ca1d9aSsb155480 355f0ca1d9aSsb155480 /* 35606db247cSraghuram * MAC callbacks 35706db247cSraghuram */ 358ba2e4443Sseb static mac_callbacks_t vsw_m_callbacks = { 359ba2e4443Sseb 0, 360ba2e4443Sseb vsw_m_stat, 361ba2e4443Sseb vsw_m_start, 362ba2e4443Sseb vsw_m_stop, 363ba2e4443Sseb vsw_m_promisc, 364ba2e4443Sseb vsw_m_multicst, 365ba2e4443Sseb vsw_m_unicst, 3660dc2366fSVenugopal Iyer vsw_m_tx 367ba2e4443Sseb }; 368ba2e4443Sseb 3691ae08745Sheppo static struct cb_ops vsw_cb_ops = { 3701ae08745Sheppo nulldev, /* cb_open */ 3711ae08745Sheppo nulldev, /* cb_close */ 3721ae08745Sheppo nodev, /* cb_strategy */ 3731ae08745Sheppo nodev, /* cb_print */ 3741ae08745Sheppo nodev, /* cb_dump */ 3751ae08745Sheppo nodev, /* cb_read */ 3761ae08745Sheppo nodev, /* cb_write */ 3771ae08745Sheppo nodev, /* cb_ioctl */ 3781ae08745Sheppo nodev, /* cb_devmap */ 3791ae08745Sheppo nodev, /* cb_mmap */ 3801ae08745Sheppo nodev, /* cb_segmap */ 3811ae08745Sheppo nochpoll, /* cb_chpoll */ 3821ae08745Sheppo ddi_prop_op, /* cb_prop_op */ 3831ae08745Sheppo NULL, /* cb_stream */ 3841ae08745Sheppo D_MP, /* cb_flag */ 3851ae08745Sheppo CB_REV, /* rev */ 3861ae08745Sheppo nodev, /* int (*cb_aread)() */ 3871ae08745Sheppo nodev /* int (*cb_awrite)() */ 3881ae08745Sheppo }; 3891ae08745Sheppo 3901ae08745Sheppo static struct dev_ops vsw_ops = { 3911ae08745Sheppo DEVO_REV, /* devo_rev */ 3921ae08745Sheppo 0, /* devo_refcnt */ 39371184a40SWENTAO YANG NULL, /* devo_getinfo */ 3941ae08745Sheppo nulldev, /* devo_identify */ 3951ae08745Sheppo nulldev, /* devo_probe */ 3961ae08745Sheppo vsw_attach, /* devo_attach */ 3971ae08745Sheppo vsw_detach, /* devo_detach */ 3981ae08745Sheppo nodev, /* devo_reset */ 3991ae08745Sheppo &vsw_cb_ops, /* devo_cb_ops */ 4001ae08745Sheppo (struct bus_ops *)NULL, /* devo_bus_ops */ 4011ae08745Sheppo ddi_power /* devo_power */ 4021ae08745Sheppo }; 4031ae08745Sheppo 4041ae08745Sheppo extern struct mod_ops mod_driverops; 4051ae08745Sheppo static struct modldrv vswmodldrv = { 4061ae08745Sheppo &mod_driverops, 407205eeb1aSlm66018 "sun4v Virtual Switch", 4081ae08745Sheppo &vsw_ops, 4091ae08745Sheppo }; 4101ae08745Sheppo 4111ae08745Sheppo #define LDC_ENTER_LOCK(ldcp) \ 4121ae08745Sheppo mutex_enter(&((ldcp)->ldc_cblock));\ 41306db247cSraghuram mutex_enter(&((ldcp)->ldc_rxlock));\ 4141ae08745Sheppo mutex_enter(&((ldcp)->ldc_txlock)); 4151ae08745Sheppo #define LDC_EXIT_LOCK(ldcp) \ 4161ae08745Sheppo mutex_exit(&((ldcp)->ldc_txlock));\ 41706db247cSraghuram mutex_exit(&((ldcp)->ldc_rxlock));\ 4181ae08745Sheppo mutex_exit(&((ldcp)->ldc_cblock)); 4191ae08745Sheppo 4201ae08745Sheppo /* Driver soft state ptr */ 4211ae08745Sheppo static void *vsw_state; 4221ae08745Sheppo 4231ae08745Sheppo /* 4241ae08745Sheppo * Linked list of "vsw_t" structures - one per instance. 4251ae08745Sheppo */ 4261ae08745Sheppo vsw_t *vsw_head = NULL; 4271ae08745Sheppo krwlock_t vsw_rw; 4281ae08745Sheppo 4291ae08745Sheppo /* 4301ae08745Sheppo * Property names 4311ae08745Sheppo */ 4321ae08745Sheppo static char vdev_propname[] = "virtual-device"; 4331ae08745Sheppo static char vsw_propname[] = "virtual-network-switch"; 4341ae08745Sheppo static char physdev_propname[] = "vsw-phys-dev"; 4351ae08745Sheppo static char smode_propname[] = "vsw-switch-mode"; 4361ae08745Sheppo static char macaddr_propname[] = "local-mac-address"; 4371ae08745Sheppo static char remaddr_propname[] = "remote-mac-address"; 4381ae08745Sheppo static char ldcids_propname[] = "ldc-ids"; 4391ae08745Sheppo static char chan_propname[] = "channel-endpoint"; 4401ae08745Sheppo static char id_propname[] = "id"; 4411ae08745Sheppo static char reg_propname[] = "reg"; 442f0ca1d9aSsb155480 static char pri_types_propname[] = "priority-ether-types"; 443c1c61f44Ssb155480 static char vsw_pvid_propname[] = "port-vlan-id"; 444c1c61f44Ssb155480 static char vsw_vid_propname[] = "vlan-id"; 445c1c61f44Ssb155480 static char vsw_dvid_propname[] = "default-vlan-id"; 446c1c61f44Ssb155480 static char port_pvid_propname[] = "remote-port-vlan-id"; 447c1c61f44Ssb155480 static char port_vid_propname[] = "remote-vlan-id"; 448678453a8Sspeer static char hybrid_propname[] = "hybrid"; 4497b1f684aSSriharsha Basavapatna static char vsw_mtu_propname[] = "mtu"; 4501107ea93SSriharsha Basavapatna static char vsw_linkprop_propname[] = "linkprop"; 451bce0a86eSWENTAO YANG static char vsw_maxbw_propname[] = "maxbw"; 452bce0a86eSWENTAO YANG static char port_maxbw_propname[] = "maxbw"; 4531ae08745Sheppo 4541ae08745Sheppo /* 4551ae08745Sheppo * Matching criteria passed to the MDEG to register interest 4561ae08745Sheppo * in changes to 'virtual-device-port' nodes identified by their 4571ae08745Sheppo * 'id' property. 4581ae08745Sheppo */ 4591ae08745Sheppo static md_prop_match_t vport_prop_match[] = { 4601ae08745Sheppo { MDET_PROP_VAL, "id" }, 4611ae08745Sheppo { MDET_LIST_END, NULL } 4621ae08745Sheppo }; 4631ae08745Sheppo 4641ae08745Sheppo static mdeg_node_match_t vport_match = { "virtual-device-port", 4651ae08745Sheppo vport_prop_match }; 4661ae08745Sheppo 4671ae08745Sheppo /* 46834683adeSsg70180 * Matching criteria passed to the MDEG to register interest 46934683adeSsg70180 * in changes to 'virtual-device' nodes (i.e. vsw nodes) identified 47034683adeSsg70180 * by their 'name' and 'cfg-handle' properties. 47134683adeSsg70180 */ 47234683adeSsg70180 static md_prop_match_t vdev_prop_match[] = { 47334683adeSsg70180 { MDET_PROP_STR, "name" }, 47434683adeSsg70180 { MDET_PROP_VAL, "cfg-handle" }, 47534683adeSsg70180 { MDET_LIST_END, NULL } 47634683adeSsg70180 }; 47734683adeSsg70180 47834683adeSsg70180 static mdeg_node_match_t vdev_match = { "virtual-device", 47934683adeSsg70180 vdev_prop_match }; 48034683adeSsg70180 48134683adeSsg70180 48234683adeSsg70180 /* 4831ae08745Sheppo * Specification of an MD node passed to the MDEG to filter any 4841ae08745Sheppo * 'vport' nodes that do not belong to the specified node. This 4851ae08745Sheppo * template is copied for each vsw instance and filled in with 4861ae08745Sheppo * the appropriate 'cfg-handle' value before being passed to the MDEG. 4871ae08745Sheppo */ 4881ae08745Sheppo static mdeg_prop_spec_t vsw_prop_template[] = { 4891ae08745Sheppo { MDET_PROP_STR, "name", vsw_propname }, 4901ae08745Sheppo { MDET_PROP_VAL, "cfg-handle", NULL }, 4911ae08745Sheppo { MDET_LIST_END, NULL, NULL } 4921ae08745Sheppo }; 4931ae08745Sheppo 4941ae08745Sheppo #define VSW_SET_MDEG_PROP_INST(specp, val) (specp)[1].ps_val = (val); 4951ae08745Sheppo 49606db247cSraghuram #ifdef DEBUG 4977636cb21Slm66018 /* 4981ae08745Sheppo * Print debug messages - set to 0x1f to enable all msgs 4991ae08745Sheppo * or 0x0 to turn all off. 5001ae08745Sheppo */ 5011ae08745Sheppo int vswdbg = 0x0; 5021ae08745Sheppo 5031ae08745Sheppo /* 5041ae08745Sheppo * debug levels: 5051ae08745Sheppo * 0x01: Function entry/exit tracing 5061ae08745Sheppo * 0x02: Internal function messages 5071ae08745Sheppo * 0x04: Verbose internal messages 5081ae08745Sheppo * 0x08: Warning messages 5091ae08745Sheppo * 0x10: Error messages 5101ae08745Sheppo */ 5111ae08745Sheppo 51206db247cSraghuram void 5131ae08745Sheppo vswdebug(vsw_t *vswp, const char *fmt, ...) 5141ae08745Sheppo { 5151ae08745Sheppo char buf[512]; 5161ae08745Sheppo va_list ap; 5171ae08745Sheppo 5181ae08745Sheppo va_start(ap, fmt); 5191ae08745Sheppo (void) vsprintf(buf, fmt, ap); 5201ae08745Sheppo va_end(ap); 5211ae08745Sheppo 5221ae08745Sheppo if (vswp == NULL) 5231ae08745Sheppo cmn_err(CE_CONT, "%s\n", buf); 5241ae08745Sheppo else 5251ae08745Sheppo cmn_err(CE_CONT, "vsw%d: %s\n", vswp->instance, buf); 5261ae08745Sheppo } 5271ae08745Sheppo 5281ae08745Sheppo #endif /* DEBUG */ 5291ae08745Sheppo 5301ae08745Sheppo static struct modlinkage modlinkage = { 5311ae08745Sheppo MODREV_1, 5321ae08745Sheppo &vswmodldrv, 5331ae08745Sheppo NULL 5341ae08745Sheppo }; 5351ae08745Sheppo 5361ae08745Sheppo int 5371ae08745Sheppo _init(void) 5381ae08745Sheppo { 5391ae08745Sheppo int status; 5401ae08745Sheppo 5411ae08745Sheppo rw_init(&vsw_rw, NULL, RW_DRIVER, NULL); 5421ae08745Sheppo 5431ae08745Sheppo status = ddi_soft_state_init(&vsw_state, sizeof (vsw_t), 1); 5441ae08745Sheppo if (status != 0) { 5451ae08745Sheppo return (status); 5461ae08745Sheppo } 5471ae08745Sheppo 54806db247cSraghuram mac_init_ops(&vsw_ops, DRV_NAME); 5491ae08745Sheppo status = mod_install(&modlinkage); 5501ae08745Sheppo if (status != 0) { 5511ae08745Sheppo ddi_soft_state_fini(&vsw_state); 5521ae08745Sheppo } 5531ae08745Sheppo return (status); 5541ae08745Sheppo } 5551ae08745Sheppo 5561ae08745Sheppo int 5571ae08745Sheppo _fini(void) 5581ae08745Sheppo { 5591ae08745Sheppo int status; 5601ae08745Sheppo 5611ae08745Sheppo status = mod_remove(&modlinkage); 5621ae08745Sheppo if (status != 0) 5631ae08745Sheppo return (status); 5641ae08745Sheppo mac_fini_ops(&vsw_ops); 5651ae08745Sheppo ddi_soft_state_fini(&vsw_state); 5661ae08745Sheppo 5671ae08745Sheppo rw_destroy(&vsw_rw); 5681ae08745Sheppo 5691ae08745Sheppo return (status); 5701ae08745Sheppo } 5711ae08745Sheppo 5721ae08745Sheppo int 5731ae08745Sheppo _info(struct modinfo *modinfop) 5741ae08745Sheppo { 5751ae08745Sheppo return (mod_info(&modlinkage, modinfop)); 5761ae08745Sheppo } 5771ae08745Sheppo 5781ae08745Sheppo static int 5791ae08745Sheppo vsw_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 5801ae08745Sheppo { 5811ae08745Sheppo vsw_t *vswp; 58234683adeSsg70180 int instance; 5831ae08745Sheppo char hashname[MAXNAMELEN]; 5841ae08745Sheppo char qname[TASKQ_NAMELEN]; 5856f09f0feSWENTAO YANG vsw_attach_progress_t progress = PROG_init; 58619b65a69Ssb155480 int rv; 5871ae08745Sheppo 5881ae08745Sheppo switch (cmd) { 5891ae08745Sheppo case DDI_ATTACH: 5901ae08745Sheppo break; 5911ae08745Sheppo case DDI_RESUME: 5921ae08745Sheppo /* nothing to do for this non-device */ 5931ae08745Sheppo return (DDI_SUCCESS); 5941ae08745Sheppo case DDI_PM_RESUME: 5951ae08745Sheppo default: 5961ae08745Sheppo return (DDI_FAILURE); 5971ae08745Sheppo } 5981ae08745Sheppo 5991ae08745Sheppo instance = ddi_get_instance(dip); 6001ae08745Sheppo if (ddi_soft_state_zalloc(vsw_state, instance) != DDI_SUCCESS) { 6011ae08745Sheppo DERR(NULL, "vsw%d: ddi_soft_state_zalloc failed", instance); 6021ae08745Sheppo return (DDI_FAILURE); 6031ae08745Sheppo } 6041ae08745Sheppo vswp = ddi_get_soft_state(vsw_state, instance); 6051ae08745Sheppo 6061ae08745Sheppo if (vswp == NULL) { 6071ae08745Sheppo DERR(NULL, "vsw%d: ddi_get_soft_state failed", instance); 6081ae08745Sheppo goto vsw_attach_fail; 6091ae08745Sheppo } 6101ae08745Sheppo 6111ae08745Sheppo vswp->dip = dip; 6121ae08745Sheppo vswp->instance = instance; 6131107ea93SSriharsha Basavapatna vswp->phys_link_state = LINK_STATE_UNKNOWN; 6141ae08745Sheppo ddi_set_driver_private(dip, (caddr_t)vswp); 6151ae08745Sheppo 616da14cebeSEric Cheng mutex_init(&vswp->mac_lock, NULL, MUTEX_DRIVER, NULL); 61719b65a69Ssb155480 mutex_init(&vswp->mca_lock, NULL, MUTEX_DRIVER, NULL); 618808f26a8SSriharsha Basavapatna mutex_init(&vswp->sw_thr_lock, NULL, MUTEX_DRIVER, NULL); 619808f26a8SSriharsha Basavapatna cv_init(&vswp->sw_thr_cv, NULL, CV_DRIVER, NULL); 620da14cebeSEric Cheng rw_init(&vswp->maccl_rwlock, NULL, RW_DRIVER, NULL); 6211ae08745Sheppo rw_init(&vswp->if_lockrw, NULL, RW_DRIVER, NULL); 62219b65a69Ssb155480 rw_init(&vswp->mfdbrw, NULL, RW_DRIVER, NULL); 62319b65a69Ssb155480 rw_init(&vswp->plist.lockrw, NULL, RW_DRIVER, NULL); 62419b65a69Ssb155480 62519b65a69Ssb155480 progress |= PROG_locks; 62619b65a69Ssb155480 62719b65a69Ssb155480 rv = vsw_read_mdprops(vswp); 62819b65a69Ssb155480 if (rv != 0) 62919b65a69Ssb155480 goto vsw_attach_fail; 63019b65a69Ssb155480 63119b65a69Ssb155480 progress |= PROG_readmd; 6321ae08745Sheppo 6331ae08745Sheppo /* setup the unicast forwarding database */ 6341ae08745Sheppo (void) snprintf(hashname, MAXNAMELEN, "vsw_unicst_table-%d", 6351ae08745Sheppo vswp->instance); 6361ae08745Sheppo D2(vswp, "creating unicast hash table (%s)...", hashname); 637c1c61f44Ssb155480 vswp->fdb_nchains = vsw_fdb_nchains; 638c1c61f44Ssb155480 vswp->fdb_hashp = mod_hash_create_ptrhash(hashname, vswp->fdb_nchains, 6391ae08745Sheppo mod_hash_null_valdtor, sizeof (void *)); 640c1c61f44Ssb155480 vsw_create_vlans((void *)vswp, VSW_LOCALDEV); 6411ae08745Sheppo progress |= PROG_fdb; 6421ae08745Sheppo 6431ae08745Sheppo /* setup the multicast fowarding database */ 6441ae08745Sheppo (void) snprintf(hashname, MAXNAMELEN, "vsw_mcst_table-%d", 6451ae08745Sheppo vswp->instance); 6461ae08745Sheppo D2(vswp, "creating multicast hash table %s)...", hashname); 647c1c61f44Ssb155480 vswp->mfdb = mod_hash_create_ptrhash(hashname, vsw_fdb_nchains, 6481ae08745Sheppo mod_hash_null_valdtor, sizeof (void *)); 6491ae08745Sheppo 6501ae08745Sheppo progress |= PROG_mfdb; 6511ae08745Sheppo 6521ae08745Sheppo /* 6531ae08745Sheppo * Create the taskq which will process all the VIO 6541ae08745Sheppo * control messages. 6551ae08745Sheppo */ 6567bd3a2e2SSriharsha Basavapatna (void) snprintf(qname, TASKQ_NAMELEN, "taskq%d", vswp->instance); 6571ae08745Sheppo if ((vswp->taskq_p = ddi_taskq_create(vswp->dip, qname, 1, 6581ae08745Sheppo TASKQ_DEFAULTPRI, 0)) == NULL) { 65934683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to create task queue", 66034683adeSsg70180 vswp->instance); 6611ae08745Sheppo goto vsw_attach_fail; 6621ae08745Sheppo } 6631ae08745Sheppo 6641ae08745Sheppo progress |= PROG_taskq; 6651ae08745Sheppo 6667bd3a2e2SSriharsha Basavapatna (void) snprintf(qname, TASKQ_NAMELEN, "rxpool_taskq%d", 66734b64c01SWENTAO YANG vswp->instance); 66834b64c01SWENTAO YANG if ((vswp->rxp_taskq = ddi_taskq_create(vswp->dip, qname, 1, 66934b64c01SWENTAO YANG TASKQ_DEFAULTPRI, 0)) == NULL) { 67034b64c01SWENTAO YANG cmn_err(CE_WARN, "!vsw%d: Unable to create rxp task queue", 67134b64c01SWENTAO YANG vswp->instance); 67234b64c01SWENTAO YANG goto vsw_attach_fail; 67334b64c01SWENTAO YANG } 67434b64c01SWENTAO YANG 67534b64c01SWENTAO YANG progress |= PROG_rxp_taskq; 67634b64c01SWENTAO YANG 677d10e4ef2Snarayan /* prevent auto-detaching */ 678d10e4ef2Snarayan if (ddi_prop_update_int(DDI_DEV_T_NONE, vswp->dip, 679d10e4ef2Snarayan DDI_NO_AUTODETACH, 1) != DDI_SUCCESS) { 68034683adeSsg70180 cmn_err(CE_NOTE, "!Unable to set \"%s\" property for " 681d10e4ef2Snarayan "instance %u", DDI_NO_AUTODETACH, instance); 682d10e4ef2Snarayan } 683d10e4ef2Snarayan 6841ae08745Sheppo /* 6857a327842Swentaoy * The null switching function is set to avoid panic until 6867a327842Swentaoy * switch mode is setup. 6877a327842Swentaoy */ 6887a327842Swentaoy vswp->vsw_switch_frame = vsw_switch_frame_nop; 6897a327842Swentaoy 6907a327842Swentaoy /* 691808f26a8SSriharsha Basavapatna * Setup the required switching mode, based on the mdprops that we read 692808f26a8SSriharsha Basavapatna * earlier. We start a thread to do this, to avoid calling mac_open() 693808f26a8SSriharsha Basavapatna * directly from attach(). 69419b65a69Ssb155480 */ 695808f26a8SSriharsha Basavapatna rv = vsw_setup_switching_start(vswp); 696808f26a8SSriharsha Basavapatna if (rv != 0) { 697808f26a8SSriharsha Basavapatna goto vsw_attach_fail; 698808f26a8SSriharsha Basavapatna } 69919b65a69Ssb155480 70019b65a69Ssb155480 progress |= PROG_swmode; 70119b65a69Ssb155480 70219b65a69Ssb155480 /* Register with mac layer as a provider */ 70319b65a69Ssb155480 rv = vsw_mac_register(vswp); 70419b65a69Ssb155480 if (rv != 0) 70519b65a69Ssb155480 goto vsw_attach_fail; 70619b65a69Ssb155480 70719b65a69Ssb155480 progress |= PROG_macreg; 70819b65a69Ssb155480 70919b65a69Ssb155480 /* 71034683adeSsg70180 * Now we have everything setup, register an interest in 71134683adeSsg70180 * specific MD nodes. 71234683adeSsg70180 * 71334683adeSsg70180 * The callback is invoked in 2 cases, firstly if upon mdeg 71434683adeSsg70180 * registration there are existing nodes which match our specified 71534683adeSsg70180 * criteria, and secondly if the MD is changed (and again, there 71634683adeSsg70180 * are nodes which we are interested in present within it. Note 71734683adeSsg70180 * that our callback will be invoked even if our specified nodes 71834683adeSsg70180 * have not actually changed). 71934683adeSsg70180 * 7201ae08745Sheppo */ 72119b65a69Ssb155480 rv = vsw_mdeg_register(vswp); 72219b65a69Ssb155480 if (rv != 0) 72334683adeSsg70180 goto vsw_attach_fail; 7241ae08745Sheppo 72519b65a69Ssb155480 progress |= PROG_mdreg; 72619b65a69Ssb155480 7276f09f0feSWENTAO YANG vswp->attach_progress = progress; 7286f09f0feSWENTAO YANG 72919b65a69Ssb155480 WRITE_ENTER(&vsw_rw); 73019b65a69Ssb155480 vswp->next = vsw_head; 73119b65a69Ssb155480 vsw_head = vswp; 73219b65a69Ssb155480 RW_EXIT(&vsw_rw); 73319b65a69Ssb155480 73419b65a69Ssb155480 ddi_report_dev(vswp->dip); 7351ae08745Sheppo return (DDI_SUCCESS); 7361ae08745Sheppo 7371ae08745Sheppo vsw_attach_fail: 7381ae08745Sheppo DERR(NULL, "vsw_attach: failed"); 7391ae08745Sheppo 7406f09f0feSWENTAO YANG vswp->attach_progress = progress; 7416f09f0feSWENTAO YANG (void) vsw_unattach(vswp); 7421ae08745Sheppo ddi_soft_state_free(vsw_state, instance); 7431ae08745Sheppo return (DDI_FAILURE); 7441ae08745Sheppo } 7451ae08745Sheppo 7461ae08745Sheppo static int 7471ae08745Sheppo vsw_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 7481ae08745Sheppo { 7491ae08745Sheppo vsw_t **vswpp, *vswp; 7501ae08745Sheppo int instance; 7511ae08745Sheppo 7521ae08745Sheppo instance = ddi_get_instance(dip); 7531ae08745Sheppo vswp = ddi_get_soft_state(vsw_state, instance); 7541ae08745Sheppo 7551ae08745Sheppo if (vswp == NULL) { 7561ae08745Sheppo return (DDI_FAILURE); 7571ae08745Sheppo } 7581ae08745Sheppo 7591ae08745Sheppo switch (cmd) { 7601ae08745Sheppo case DDI_DETACH: 7611ae08745Sheppo break; 7621ae08745Sheppo case DDI_SUSPEND: 7631ae08745Sheppo case DDI_PM_SUSPEND: 7641ae08745Sheppo default: 7651ae08745Sheppo return (DDI_FAILURE); 7661ae08745Sheppo } 7671ae08745Sheppo 7681ae08745Sheppo D2(vswp, "detaching instance %d", instance); 7691ae08745Sheppo 7706f09f0feSWENTAO YANG if (vsw_unattach(vswp) != 0) { 7711ae08745Sheppo return (DDI_FAILURE); 7721ae08745Sheppo } 773f0ca1d9aSsb155480 7741ae08745Sheppo ddi_remove_minor_node(dip, NULL); 7751ae08745Sheppo 7761ae08745Sheppo WRITE_ENTER(&vsw_rw); 7771ae08745Sheppo for (vswpp = &vsw_head; *vswpp; vswpp = &(*vswpp)->next) { 7781ae08745Sheppo if (*vswpp == vswp) { 7791ae08745Sheppo *vswpp = vswp->next; 7801ae08745Sheppo break; 7811ae08745Sheppo } 7821ae08745Sheppo } 7831ae08745Sheppo RW_EXIT(&vsw_rw); 7846f09f0feSWENTAO YANG 7851ae08745Sheppo ddi_soft_state_free(vsw_state, instance); 7861ae08745Sheppo 7871ae08745Sheppo return (DDI_SUCCESS); 7881ae08745Sheppo } 7891ae08745Sheppo 7901ae08745Sheppo /* 7916f09f0feSWENTAO YANG * Common routine to handle vsw_attach() failure and vsw_detach(). Note that 7926f09f0feSWENTAO YANG * the only reason this function could fail is if mac_unregister() fails. 7936f09f0feSWENTAO YANG * Otherwise, this function must ensure that all resources are freed and return 7946f09f0feSWENTAO YANG * success. 7956f09f0feSWENTAO YANG */ 7966f09f0feSWENTAO YANG static int 7976f09f0feSWENTAO YANG vsw_unattach(vsw_t *vswp) 7986f09f0feSWENTAO YANG { 7996f09f0feSWENTAO YANG vsw_attach_progress_t progress; 8006f09f0feSWENTAO YANG 8016f09f0feSWENTAO YANG progress = vswp->attach_progress; 8026f09f0feSWENTAO YANG 8036f09f0feSWENTAO YANG /* 8046f09f0feSWENTAO YANG * Unregister from the gldv3 subsystem. This can fail, in particular 8056f09f0feSWENTAO YANG * if there are still any open references to this mac device; in which 8066f09f0feSWENTAO YANG * case we just return failure without continuing to detach further. 8076f09f0feSWENTAO YANG */ 8086f09f0feSWENTAO YANG if (progress & PROG_macreg) { 8096f09f0feSWENTAO YANG if (vsw_mac_unregister(vswp) != 0) { 8106f09f0feSWENTAO YANG cmn_err(CE_WARN, "!vsw%d: Unable to detach from " 8116f09f0feSWENTAO YANG "MAC layer", vswp->instance); 8126f09f0feSWENTAO YANG return (1); 8136f09f0feSWENTAO YANG } 8146f09f0feSWENTAO YANG progress &= ~PROG_macreg; 8156f09f0feSWENTAO YANG } 8166f09f0feSWENTAO YANG 8176f09f0feSWENTAO YANG /* 8186f09f0feSWENTAO YANG * Now that we have unregistered from gldv3, we must finish all other 8196f09f0feSWENTAO YANG * steps and successfully return from this function; otherwise we will 8206f09f0feSWENTAO YANG * end up leaving the device in a broken/unusable state. 8216f09f0feSWENTAO YANG * 8226f09f0feSWENTAO YANG * If we have registered with mdeg, unregister now to stop further 8236f09f0feSWENTAO YANG * callbacks to this vsw device and/or its ports. Then, detach any 8246f09f0feSWENTAO YANG * existing ports. 8256f09f0feSWENTAO YANG */ 8266f09f0feSWENTAO YANG if (progress & PROG_mdreg) { 8276f09f0feSWENTAO YANG vsw_mdeg_unregister(vswp); 8286f09f0feSWENTAO YANG vsw_detach_ports(vswp); 8296f09f0feSWENTAO YANG progress &= ~PROG_mdreg; 8306f09f0feSWENTAO YANG } 8316f09f0feSWENTAO YANG 8326f09f0feSWENTAO YANG /* 8336f09f0feSWENTAO YANG * If we have started a thread to setup the switching mode, stop it, if 8346f09f0feSWENTAO YANG * it is still running. If it has finished setting up the switching 8356f09f0feSWENTAO YANG * mode, then we need to clean up some additional things if we are 8366f09f0feSWENTAO YANG * running in L2 mode: first free up any hybrid resources; then stop 8376f09f0feSWENTAO YANG * and close the underlying physical device. Note that we would have 8386f09f0feSWENTAO YANG * already released all per mac_client resources (ucast, mcast addrs, 8396f09f0feSWENTAO YANG * hio-shares etc) as all the ports are detached and if the vsw device 8406f09f0feSWENTAO YANG * itself was in use as an interface, it has been unplumbed (otherwise 8416f09f0feSWENTAO YANG * mac_unregister() above would fail). 8426f09f0feSWENTAO YANG */ 8436f09f0feSWENTAO YANG if (progress & PROG_swmode) { 8446f09f0feSWENTAO YANG 8456f09f0feSWENTAO YANG vsw_setup_switching_stop(vswp); 8466f09f0feSWENTAO YANG 8476f09f0feSWENTAO YANG if (vswp->hio_capable == B_TRUE) { 8486f09f0feSWENTAO YANG vsw_hio_cleanup(vswp); 8496f09f0feSWENTAO YANG vswp->hio_capable = B_FALSE; 8506f09f0feSWENTAO YANG } 8516f09f0feSWENTAO YANG 8526f09f0feSWENTAO YANG mutex_enter(&vswp->mac_lock); 8536f09f0feSWENTAO YANG vsw_mac_close(vswp); 8546f09f0feSWENTAO YANG mutex_exit(&vswp->mac_lock); 8556f09f0feSWENTAO YANG 8566f09f0feSWENTAO YANG progress &= ~PROG_swmode; 8576f09f0feSWENTAO YANG } 8586f09f0feSWENTAO YANG 8596f09f0feSWENTAO YANG /* 86034b64c01SWENTAO YANG * We now destroy the taskq used to clean up rx mblk pools that 86134b64c01SWENTAO YANG * couldn't be destroyed when the ports/channels were detached. 86234b64c01SWENTAO YANG * We implicitly wait for those tasks to complete in 86334b64c01SWENTAO YANG * ddi_taskq_destroy(). 86434b64c01SWENTAO YANG */ 86534b64c01SWENTAO YANG if (progress & PROG_rxp_taskq) { 86634b64c01SWENTAO YANG ddi_taskq_destroy(vswp->rxp_taskq); 86734b64c01SWENTAO YANG progress &= ~PROG_rxp_taskq; 86834b64c01SWENTAO YANG } 86934b64c01SWENTAO YANG 87034b64c01SWENTAO YANG /* 8716f09f0feSWENTAO YANG * By now any pending tasks have finished and the underlying 8726f09f0feSWENTAO YANG * ldc's have been destroyed, so its safe to delete the control 8736f09f0feSWENTAO YANG * message taskq. 8746f09f0feSWENTAO YANG */ 8756f09f0feSWENTAO YANG if (progress & PROG_taskq) { 8766f09f0feSWENTAO YANG ddi_taskq_destroy(vswp->taskq_p); 8776f09f0feSWENTAO YANG progress &= ~PROG_taskq; 8786f09f0feSWENTAO YANG } 8796f09f0feSWENTAO YANG 8806f09f0feSWENTAO YANG /* Destroy the multicast hash table */ 8816f09f0feSWENTAO YANG if (progress & PROG_mfdb) { 8826f09f0feSWENTAO YANG mod_hash_destroy_hash(vswp->mfdb); 8836f09f0feSWENTAO YANG progress &= ~PROG_mfdb; 8846f09f0feSWENTAO YANG } 8856f09f0feSWENTAO YANG 8866f09f0feSWENTAO YANG /* Destroy the vlan hash table and fdb */ 8876f09f0feSWENTAO YANG if (progress & PROG_fdb) { 8886f09f0feSWENTAO YANG vsw_destroy_vlans(vswp, VSW_LOCALDEV); 8896f09f0feSWENTAO YANG mod_hash_destroy_hash(vswp->fdb_hashp); 8906f09f0feSWENTAO YANG progress &= ~PROG_fdb; 8916f09f0feSWENTAO YANG } 8926f09f0feSWENTAO YANG 8936f09f0feSWENTAO YANG if (progress & PROG_readmd) { 8946f09f0feSWENTAO YANG if (VSW_PRI_ETH_DEFINED(vswp)) { 8956f09f0feSWENTAO YANG kmem_free(vswp->pri_types, 8966f09f0feSWENTAO YANG sizeof (uint16_t) * vswp->pri_num_types); 8976f09f0feSWENTAO YANG (void) vio_destroy_mblks(vswp->pri_tx_vmp); 8986f09f0feSWENTAO YANG } 8996f09f0feSWENTAO YANG progress &= ~PROG_readmd; 9006f09f0feSWENTAO YANG } 9016f09f0feSWENTAO YANG 9026f09f0feSWENTAO YANG if (progress & PROG_locks) { 9036f09f0feSWENTAO YANG rw_destroy(&vswp->plist.lockrw); 9046f09f0feSWENTAO YANG rw_destroy(&vswp->mfdbrw); 9056f09f0feSWENTAO YANG rw_destroy(&vswp->if_lockrw); 9066f09f0feSWENTAO YANG rw_destroy(&vswp->maccl_rwlock); 9076f09f0feSWENTAO YANG cv_destroy(&vswp->sw_thr_cv); 9086f09f0feSWENTAO YANG mutex_destroy(&vswp->sw_thr_lock); 9096f09f0feSWENTAO YANG mutex_destroy(&vswp->mca_lock); 9106f09f0feSWENTAO YANG mutex_destroy(&vswp->mac_lock); 9116f09f0feSWENTAO YANG progress &= ~PROG_locks; 9126f09f0feSWENTAO YANG } 9136f09f0feSWENTAO YANG 9146f09f0feSWENTAO YANG vswp->attach_progress = progress; 9156f09f0feSWENTAO YANG 9166f09f0feSWENTAO YANG return (0); 9176f09f0feSWENTAO YANG } 9186f09f0feSWENTAO YANG 91934b64c01SWENTAO YANG void 92034b64c01SWENTAO YANG vsw_destroy_rxpools(void *arg) 9216f09f0feSWENTAO YANG { 92234b64c01SWENTAO YANG vio_mblk_pool_t *poolp = (vio_mblk_pool_t *)arg; 92334b64c01SWENTAO YANG vio_mblk_pool_t *npoolp; 9246f09f0feSWENTAO YANG 9256f09f0feSWENTAO YANG while (poolp != NULL) { 92634b64c01SWENTAO YANG npoolp = poolp->nextp; 92734b64c01SWENTAO YANG while (vio_destroy_mblks(poolp) != 0) { 928a862df29SSriharsha Basavapatna delay(drv_usectohz(vsw_rxpool_cleanup_delay)); 9296f09f0feSWENTAO YANG } 9306f09f0feSWENTAO YANG poolp = npoolp; 9316f09f0feSWENTAO YANG } 9326f09f0feSWENTAO YANG } 9336f09f0feSWENTAO YANG 9346f09f0feSWENTAO YANG /* 93534683adeSsg70180 * Get the value of the "vsw-phys-dev" property in the specified 93634683adeSsg70180 * node. This property is the name of the physical device that 93734683adeSsg70180 * the virtual switch will use to talk to the outside world. 93834683adeSsg70180 * 93934683adeSsg70180 * Note it is valid for this property to be NULL (but the property 94034683adeSsg70180 * itself must exist). Callers of this routine should verify that 94134683adeSsg70180 * the value returned is what they expected (i.e. either NULL or non NULL). 94234683adeSsg70180 * 94334683adeSsg70180 * On success returns value of the property in region pointed to by 94434683adeSsg70180 * the 'name' argument, and with return value of 0. Otherwise returns 1. 9451ae08745Sheppo */ 94634683adeSsg70180 static int 94734683adeSsg70180 vsw_get_md_physname(vsw_t *vswp, md_t *mdp, mde_cookie_t node, char *name) 9481ae08745Sheppo { 94934683adeSsg70180 int len = 0; 950f2b610cfSwentaoy int instance; 9511ae08745Sheppo char *physname = NULL; 9521ae08745Sheppo char *dev; 953f2b610cfSwentaoy const char *dev_name; 954f2b610cfSwentaoy char myname[MAXNAMELEN]; 955f2b610cfSwentaoy 956f2b610cfSwentaoy dev_name = ddi_driver_name(vswp->dip); 957f2b610cfSwentaoy instance = ddi_get_instance(vswp->dip); 958f2b610cfSwentaoy (void) snprintf(myname, MAXNAMELEN, "%s%d", dev_name, instance); 9591ae08745Sheppo 96034683adeSsg70180 if (md_get_prop_data(mdp, node, physdev_propname, 9611ae08745Sheppo (uint8_t **)(&physname), &len) != 0) { 96234683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to get name(s) of physical " 96334683adeSsg70180 "device(s) from MD", vswp->instance); 96434683adeSsg70180 return (1); 9651ae08745Sheppo } else if ((strlen(physname) + 1) > LIFNAMSIZ) { 96634683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: %s is too long a device name", 96734683adeSsg70180 vswp->instance, physname); 96834683adeSsg70180 return (1); 969f2b610cfSwentaoy } else if (strcmp(myname, physname) == 0) { 970f2b610cfSwentaoy /* 971f2b610cfSwentaoy * Prevent the vswitch from opening itself as the 972f2b610cfSwentaoy * network device. 973f2b610cfSwentaoy */ 974f2b610cfSwentaoy cmn_err(CE_WARN, "!vsw%d: %s is an invalid device name", 975f2b610cfSwentaoy vswp->instance, physname); 976f2b610cfSwentaoy return (1); 9771ae08745Sheppo } else { 97834683adeSsg70180 (void) strncpy(name, physname, strlen(physname) + 1); 9791ae08745Sheppo D2(vswp, "%s: using first device specified (%s)", 98034683adeSsg70180 __func__, physname); 9811ae08745Sheppo } 9821ae08745Sheppo 9831ae08745Sheppo #ifdef DEBUG 9841ae08745Sheppo /* 9851ae08745Sheppo * As a temporary measure to aid testing we check to see if there 9861ae08745Sheppo * is a vsw.conf file present. If there is we use the value of the 9871ae08745Sheppo * vsw_physname property in the file as the name of the physical 9881ae08745Sheppo * device, overriding the value from the MD. 9891ae08745Sheppo * 9901ae08745Sheppo * There may be multiple devices listed, but for the moment 9911ae08745Sheppo * we just use the first one. 9921ae08745Sheppo */ 9931ae08745Sheppo if (ddi_prop_lookup_string(DDI_DEV_T_ANY, vswp->dip, 0, 9941ae08745Sheppo "vsw_physname", &dev) == DDI_PROP_SUCCESS) { 9951ae08745Sheppo if ((strlen(dev) + 1) > LIFNAMSIZ) { 99634683adeSsg70180 cmn_err(CE_WARN, "vsw%d: %s is too long a device name", 99734683adeSsg70180 vswp->instance, dev); 99834683adeSsg70180 ddi_prop_free(dev); 99934683adeSsg70180 return (1); 10001ae08745Sheppo } else { 100134683adeSsg70180 cmn_err(CE_NOTE, "vsw%d: Using device name (%s) from " 100234683adeSsg70180 "config file", vswp->instance, dev); 10031ae08745Sheppo 100434683adeSsg70180 (void) strncpy(name, dev, strlen(dev) + 1); 10051ae08745Sheppo } 10061ae08745Sheppo 10071ae08745Sheppo ddi_prop_free(dev); 10081ae08745Sheppo } 10091ae08745Sheppo #endif 10101ae08745Sheppo 101134683adeSsg70180 return (0); 101234683adeSsg70180 } 1013e1ebb9ecSlm66018 1014e1ebb9ecSlm66018 /* 101534683adeSsg70180 * Read the 'vsw-switch-mode' property from the specified MD node. 101634683adeSsg70180 * 1017da14cebeSEric Cheng * Returns 0 on success, otherwise returns 1. 1018e1ebb9ecSlm66018 */ 101934683adeSsg70180 static int 1020da14cebeSEric Cheng vsw_get_md_smodes(vsw_t *vswp, md_t *mdp, mde_cookie_t node, uint8_t *mode) 102134683adeSsg70180 { 102234683adeSsg70180 int len = 0; 102334683adeSsg70180 char *smode = NULL; 102434683adeSsg70180 char *curr_mode = NULL; 102534683adeSsg70180 102634683adeSsg70180 D1(vswp, "%s: enter", __func__); 10271ae08745Sheppo 10281ae08745Sheppo /* 10291ae08745Sheppo * Get the switch-mode property. The modes are listed in 10301ae08745Sheppo * decreasing order of preference, i.e. prefered mode is 10311ae08745Sheppo * first item in list. 10321ae08745Sheppo */ 10331ae08745Sheppo len = 0; 103434683adeSsg70180 if (md_get_prop_data(mdp, node, smode_propname, 10351ae08745Sheppo (uint8_t **)(&smode), &len) != 0) { 10361ae08745Sheppo /* 1037e1ebb9ecSlm66018 * Unable to get switch-mode property from MD, nothing 1038e1ebb9ecSlm66018 * more we can do. 10391ae08745Sheppo */ 104034683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to get switch mode property" 104134683adeSsg70180 " from the MD", vswp->instance); 104234683adeSsg70180 return (1); 1043e1ebb9ecSlm66018 } 1044e1ebb9ecSlm66018 10451ae08745Sheppo curr_mode = smode; 10461ae08745Sheppo /* 10471ae08745Sheppo * Modes of operation: 10481ae08745Sheppo * 'switched' - layer 2 switching, underlying HW in 1049e1ebb9ecSlm66018 * programmed mode. 10501ae08745Sheppo * 'promiscuous' - layer 2 switching, underlying HW in 10511ae08745Sheppo * promiscuous mode. 10521ae08745Sheppo * 'routed' - layer 3 (i.e. IP) routing, underlying HW 10531ae08745Sheppo * in non-promiscuous mode. 10541ae08745Sheppo */ 1055da14cebeSEric Cheng while (curr_mode < (smode + len)) { 10561ae08745Sheppo D2(vswp, "%s: curr_mode = [%s]", __func__, curr_mode); 1057e1ebb9ecSlm66018 if (strcmp(curr_mode, "switched") == 0) { 1058da14cebeSEric Cheng *mode = VSW_LAYER2; 1059e1ebb9ecSlm66018 } else if (strcmp(curr_mode, "promiscuous") == 0) { 1060da14cebeSEric Cheng *mode = VSW_LAYER2 | VSW_LAYER2_PROMISC; 1061e1ebb9ecSlm66018 } else if (strcmp(curr_mode, "routed") == 0) { 1062da14cebeSEric Cheng *mode = VSW_LAYER3; 1063e1ebb9ecSlm66018 } else { 1064da14cebeSEric Cheng cmn_err(CE_WARN, "!vsw%d: Unknown switch mode %s, " 1065da14cebeSEric Cheng "setting to default switched mode", 1066da14cebeSEric Cheng vswp->instance, curr_mode); 1067da14cebeSEric Cheng *mode = VSW_LAYER2; 10681ae08745Sheppo } 10691ae08745Sheppo curr_mode += strlen(curr_mode) + 1; 10701ae08745Sheppo } 10711ae08745Sheppo 1072da14cebeSEric Cheng D2(vswp, "%s: %d mode", __func__, *mode); 10731ae08745Sheppo 10741ae08745Sheppo D1(vswp, "%s: exit", __func__); 107534683adeSsg70180 107634683adeSsg70180 return (0); 10771ae08745Sheppo } 10781ae08745Sheppo 1079e1ebb9ecSlm66018 /* 10801ae08745Sheppo * Register with the MAC layer as a network device, so we 10811ae08745Sheppo * can be plumbed if necessary. 10821ae08745Sheppo */ 10831ae08745Sheppo static int 10841ae08745Sheppo vsw_mac_register(vsw_t *vswp) 10851ae08745Sheppo { 1086ba2e4443Sseb mac_register_t *macp; 1087ba2e4443Sseb int rv; 10881ae08745Sheppo 10891ae08745Sheppo D1(vswp, "%s: enter", __func__); 10901ae08745Sheppo 1091ba2e4443Sseb if ((macp = mac_alloc(MAC_VERSION)) == NULL) 1092ba2e4443Sseb return (EINVAL); 1093ba2e4443Sseb macp->m_type_ident = MAC_PLUGIN_IDENT_ETHER; 10941ae08745Sheppo macp->m_driver = vswp; 1095ba2e4443Sseb macp->m_dip = vswp->dip; 1096ba2e4443Sseb macp->m_src_addr = (uint8_t *)&vswp->if_addr; 1097ba2e4443Sseb macp->m_callbacks = &vsw_m_callbacks; 1098ba2e4443Sseb macp->m_min_sdu = 0; 10997b1f684aSSriharsha Basavapatna macp->m_max_sdu = vswp->mtu; 1100c1c61f44Ssb155480 macp->m_margin = VLAN_TAGSZ; 1101ba2e4443Sseb rv = mac_register(macp, &vswp->if_mh); 1102ba2e4443Sseb mac_free(macp); 110319b65a69Ssb155480 if (rv != 0) { 110419b65a69Ssb155480 /* 110519b65a69Ssb155480 * Treat this as a non-fatal error as we may be 110619b65a69Ssb155480 * able to operate in some other mode. 110719b65a69Ssb155480 */ 110819b65a69Ssb155480 cmn_err(CE_NOTE, "!vsw%d: Unable to register as " 110919b65a69Ssb155480 "a provider with MAC layer", vswp->instance); 111019b65a69Ssb155480 return (rv); 111119b65a69Ssb155480 } 111219b65a69Ssb155480 1113ba2e4443Sseb vswp->if_state |= VSW_IF_REG; 11141ae08745Sheppo 11151ae08745Sheppo D1(vswp, "%s: exit", __func__); 11161ae08745Sheppo 11171ae08745Sheppo return (rv); 11181ae08745Sheppo } 11191ae08745Sheppo 11201ae08745Sheppo static int 11211ae08745Sheppo vsw_mac_unregister(vsw_t *vswp) 11221ae08745Sheppo { 11231ae08745Sheppo int rv = 0; 11241ae08745Sheppo 11251ae08745Sheppo D1(vswp, "%s: enter", __func__); 11261ae08745Sheppo 11271ae08745Sheppo WRITE_ENTER(&vswp->if_lockrw); 11281ae08745Sheppo 1129ba2e4443Sseb if (vswp->if_state & VSW_IF_REG) { 1130ba2e4443Sseb rv = mac_unregister(vswp->if_mh); 11311ae08745Sheppo if (rv != 0) { 11321ae08745Sheppo DWARN(vswp, "%s: unable to unregister from MAC " 11331ae08745Sheppo "framework", __func__); 11341ae08745Sheppo 11351ae08745Sheppo RW_EXIT(&vswp->if_lockrw); 11361ae08745Sheppo D1(vswp, "%s: fail exit", __func__); 11371ae08745Sheppo return (rv); 11381ae08745Sheppo } 11391ae08745Sheppo 1140ba2e4443Sseb /* mark i/f as down and unregistered */ 1141ba2e4443Sseb vswp->if_state &= ~(VSW_IF_UP | VSW_IF_REG); 11421ae08745Sheppo } 11431ae08745Sheppo RW_EXIT(&vswp->if_lockrw); 11441ae08745Sheppo 11451ae08745Sheppo D1(vswp, "%s: exit", __func__); 11461ae08745Sheppo 11471ae08745Sheppo return (rv); 11481ae08745Sheppo } 11491ae08745Sheppo 1150ba2e4443Sseb static int 1151ba2e4443Sseb vsw_m_stat(void *arg, uint_t stat, uint64_t *val) 11521ae08745Sheppo { 11531ae08745Sheppo vsw_t *vswp = (vsw_t *)arg; 11541ae08745Sheppo 11551ae08745Sheppo D1(vswp, "%s: enter", __func__); 11561ae08745Sheppo 1157da14cebeSEric Cheng mutex_enter(&vswp->mac_lock); 115834683adeSsg70180 if (vswp->mh == NULL) { 1159da14cebeSEric Cheng mutex_exit(&vswp->mac_lock); 1160ba2e4443Sseb return (EINVAL); 116134683adeSsg70180 } 11621ae08745Sheppo 11631ae08745Sheppo /* return stats from underlying device */ 1164ba2e4443Sseb *val = mac_stat_get(vswp->mh, stat); 116534683adeSsg70180 1166da14cebeSEric Cheng mutex_exit(&vswp->mac_lock); 116734683adeSsg70180 1168ba2e4443Sseb return (0); 11691ae08745Sheppo } 11701ae08745Sheppo 11711ae08745Sheppo static void 11721ae08745Sheppo vsw_m_stop(void *arg) 11731ae08745Sheppo { 11741ae08745Sheppo vsw_t *vswp = (vsw_t *)arg; 11751ae08745Sheppo 11761ae08745Sheppo D1(vswp, "%s: enter", __func__); 11771ae08745Sheppo 11781ae08745Sheppo WRITE_ENTER(&vswp->if_lockrw); 11791ae08745Sheppo vswp->if_state &= ~VSW_IF_UP; 11801ae08745Sheppo RW_EXIT(&vswp->if_lockrw); 11811ae08745Sheppo 1182da14cebeSEric Cheng /* Cleanup and close the mac client */ 1183da14cebeSEric Cheng vsw_mac_client_cleanup(vswp, NULL, VSW_LOCALDEV); 11845f94e909Ssg70180 11851ae08745Sheppo D1(vswp, "%s: exit (state = %d)", __func__, vswp->if_state); 11861ae08745Sheppo } 11871ae08745Sheppo 11881ae08745Sheppo static int 11891ae08745Sheppo vsw_m_start(void *arg) 11901ae08745Sheppo { 1191da14cebeSEric Cheng int rv; 11921ae08745Sheppo vsw_t *vswp = (vsw_t *)arg; 11931ae08745Sheppo 11941ae08745Sheppo D1(vswp, "%s: enter", __func__); 11951ae08745Sheppo 11961ae08745Sheppo WRITE_ENTER(&vswp->if_lockrw); 11971ae08745Sheppo 119819b65a69Ssb155480 vswp->if_state |= VSW_IF_UP; 119919b65a69Ssb155480 120019b65a69Ssb155480 if (vswp->switching_setup_done == B_FALSE) { 120119b65a69Ssb155480 /* 120219b65a69Ssb155480 * If the switching mode has not been setup yet, just 120319b65a69Ssb155480 * return. The unicast address will be programmed 120419b65a69Ssb155480 * after the physical device is successfully setup by the 120519b65a69Ssb155480 * timeout handler. 120619b65a69Ssb155480 */ 120719b65a69Ssb155480 RW_EXIT(&vswp->if_lockrw); 120819b65a69Ssb155480 return (0); 120919b65a69Ssb155480 } 121019b65a69Ssb155480 121119b65a69Ssb155480 /* if in layer2 mode, program unicast address. */ 121219b65a69Ssb155480 if (vswp->mh != NULL) { 1213da14cebeSEric Cheng /* Init a mac client and program addresses */ 1214da14cebeSEric Cheng rv = vsw_mac_client_init(vswp, NULL, VSW_LOCALDEV); 1215da14cebeSEric Cheng if (rv != 0) { 1216da14cebeSEric Cheng cmn_err(CE_NOTE, 1217da14cebeSEric Cheng "!vsw%d: failed to program interface " 1218da14cebeSEric Cheng "unicast address\n", vswp->instance); 1219da14cebeSEric Cheng } 122019b65a69Ssb155480 } 122119b65a69Ssb155480 122219b65a69Ssb155480 RW_EXIT(&vswp->if_lockrw); 12235f94e909Ssg70180 12241ae08745Sheppo D1(vswp, "%s: exit (state = %d)", __func__, vswp->if_state); 12251ae08745Sheppo return (0); 12261ae08745Sheppo } 12271ae08745Sheppo 12281ae08745Sheppo /* 12291ae08745Sheppo * Change the local interface address. 12305f94e909Ssg70180 * 12315f94e909Ssg70180 * Note: we don't support this entry point. The local 12325f94e909Ssg70180 * mac address of the switch can only be changed via its 12335f94e909Ssg70180 * MD node properties. 12341ae08745Sheppo */ 12351ae08745Sheppo static int 12361ae08745Sheppo vsw_m_unicst(void *arg, const uint8_t *macaddr) 12371ae08745Sheppo { 12385f94e909Ssg70180 _NOTE(ARGUNUSED(arg, macaddr)) 12391ae08745Sheppo 12405f94e909Ssg70180 return (DDI_FAILURE); 12411ae08745Sheppo } 12421ae08745Sheppo 12431ae08745Sheppo static int 12441ae08745Sheppo vsw_m_multicst(void *arg, boolean_t add, const uint8_t *mca) 12451ae08745Sheppo { 12461ae08745Sheppo vsw_t *vswp = (vsw_t *)arg; 12471ae08745Sheppo mcst_addr_t *mcst_p = NULL; 12481ae08745Sheppo uint64_t addr = 0x0; 1249e1ebb9ecSlm66018 int i, ret = 0; 12501ae08745Sheppo 12511ae08745Sheppo D1(vswp, "%s: enter", __func__); 12521ae08745Sheppo 12531ae08745Sheppo /* 12541ae08745Sheppo * Convert address into form that can be used 12551ae08745Sheppo * as hash table key. 12561ae08745Sheppo */ 12571ae08745Sheppo for (i = 0; i < ETHERADDRL; i++) { 12581ae08745Sheppo addr = (addr << 8) | mca[i]; 12591ae08745Sheppo } 12601ae08745Sheppo 12611ae08745Sheppo D2(vswp, "%s: addr = 0x%llx", __func__, addr); 12621ae08745Sheppo 12631ae08745Sheppo if (add) { 12641ae08745Sheppo D2(vswp, "%s: adding multicast", __func__); 12651ae08745Sheppo if (vsw_add_mcst(vswp, VSW_LOCALDEV, addr, NULL) == 0) { 12661ae08745Sheppo /* 12671ae08745Sheppo * Update the list of multicast addresses 12681ae08745Sheppo * contained within the vsw_t structure to 12691ae08745Sheppo * include this new one. 12701ae08745Sheppo */ 12711ae08745Sheppo mcst_p = kmem_zalloc(sizeof (mcst_addr_t), KM_NOSLEEP); 12721ae08745Sheppo if (mcst_p == NULL) { 12731ae08745Sheppo DERR(vswp, "%s unable to alloc mem", __func__); 127419b65a69Ssb155480 (void) vsw_del_mcst(vswp, 127519b65a69Ssb155480 VSW_LOCALDEV, addr, NULL); 12761ae08745Sheppo return (1); 12771ae08745Sheppo } 12781ae08745Sheppo mcst_p->addr = addr; 127919b65a69Ssb155480 ether_copy(mca, &mcst_p->mca); 12801ae08745Sheppo 12811ae08745Sheppo /* 12821ae08745Sheppo * Call into the underlying driver to program the 12831ae08745Sheppo * address into HW. 12841ae08745Sheppo */ 1285da14cebeSEric Cheng ret = vsw_mac_multicast_add(vswp, NULL, mcst_p, 1286da14cebeSEric Cheng VSW_LOCALDEV); 1287e1ebb9ecSlm66018 if (ret != 0) { 128819b65a69Ssb155480 (void) vsw_del_mcst(vswp, 128919b65a69Ssb155480 VSW_LOCALDEV, addr, NULL); 129019b65a69Ssb155480 kmem_free(mcst_p, sizeof (*mcst_p)); 129119b65a69Ssb155480 return (ret); 1292e1ebb9ecSlm66018 } 129319b65a69Ssb155480 129419b65a69Ssb155480 mutex_enter(&vswp->mca_lock); 129519b65a69Ssb155480 mcst_p->nextp = vswp->mcap; 129619b65a69Ssb155480 vswp->mcap = mcst_p; 129719b65a69Ssb155480 mutex_exit(&vswp->mca_lock); 12981ae08745Sheppo } else { 1299da14cebeSEric Cheng cmn_err(CE_WARN, "!vsw%d: unable to add multicast " 130034683adeSsg70180 "address", vswp->instance); 1301e1ebb9ecSlm66018 } 1302e1ebb9ecSlm66018 return (ret); 1303e1ebb9ecSlm66018 } 1304e1ebb9ecSlm66018 13051ae08745Sheppo D2(vswp, "%s: removing multicast", __func__); 13061ae08745Sheppo /* 13071ae08745Sheppo * Remove the address from the hash table.. 13081ae08745Sheppo */ 13091ae08745Sheppo if (vsw_del_mcst(vswp, VSW_LOCALDEV, addr, NULL) == 0) { 13101ae08745Sheppo 13111ae08745Sheppo /* 13121ae08745Sheppo * ..and then from the list maintained in the 13131ae08745Sheppo * vsw_t structure. 13141ae08745Sheppo */ 131519b65a69Ssb155480 mcst_p = vsw_del_addr(VSW_LOCALDEV, vswp, addr); 131619b65a69Ssb155480 ASSERT(mcst_p != NULL); 13171ae08745Sheppo 1318da14cebeSEric Cheng vsw_mac_multicast_remove(vswp, NULL, mcst_p, VSW_LOCALDEV); 131919b65a69Ssb155480 kmem_free(mcst_p, sizeof (*mcst_p)); 13201ae08745Sheppo } 13211ae08745Sheppo 13221ae08745Sheppo D1(vswp, "%s: exit", __func__); 13231ae08745Sheppo 13241ae08745Sheppo return (0); 13251ae08745Sheppo } 13261ae08745Sheppo 13271ae08745Sheppo static int 13281ae08745Sheppo vsw_m_promisc(void *arg, boolean_t on) 13291ae08745Sheppo { 13301ae08745Sheppo vsw_t *vswp = (vsw_t *)arg; 13311ae08745Sheppo 13321ae08745Sheppo D1(vswp, "%s: enter", __func__); 13331ae08745Sheppo 13341ae08745Sheppo WRITE_ENTER(&vswp->if_lockrw); 13351ae08745Sheppo if (on) 13361ae08745Sheppo vswp->if_state |= VSW_IF_PROMISC; 13371ae08745Sheppo else 13381ae08745Sheppo vswp->if_state &= ~VSW_IF_PROMISC; 13391ae08745Sheppo RW_EXIT(&vswp->if_lockrw); 13401ae08745Sheppo 13411ae08745Sheppo D1(vswp, "%s: exit", __func__); 13421ae08745Sheppo 13431ae08745Sheppo return (0); 13441ae08745Sheppo } 13451ae08745Sheppo 13461ae08745Sheppo static mblk_t * 13471ae08745Sheppo vsw_m_tx(void *arg, mblk_t *mp) 13481ae08745Sheppo { 13491ae08745Sheppo vsw_t *vswp = (vsw_t *)arg; 13501ae08745Sheppo 13511ae08745Sheppo D1(vswp, "%s: enter", __func__); 13521ae08745Sheppo 1353c1c61f44Ssb155480 mp = vsw_vlan_frame_pretag(vswp, VSW_LOCALDEV, mp); 1354c1c61f44Ssb155480 1355c1c61f44Ssb155480 if (mp == NULL) { 1356c1c61f44Ssb155480 return (NULL); 1357c1c61f44Ssb155480 } 1358c1c61f44Ssb155480 135934683adeSsg70180 vswp->vsw_switch_frame(vswp, mp, VSW_LOCALDEV, NULL, NULL); 13601ae08745Sheppo 13611ae08745Sheppo D1(vswp, "%s: exit", __func__); 13621ae08745Sheppo 13631ae08745Sheppo return (NULL); 13641ae08745Sheppo } 13651ae08745Sheppo 13661ae08745Sheppo /* 13671ae08745Sheppo * Register for machine description (MD) updates. 136834683adeSsg70180 * 136934683adeSsg70180 * Returns 0 on success, 1 on failure. 13701ae08745Sheppo */ 137134683adeSsg70180 static int 13721ae08745Sheppo vsw_mdeg_register(vsw_t *vswp) 13731ae08745Sheppo { 13741ae08745Sheppo mdeg_prop_spec_t *pspecp; 13751ae08745Sheppo mdeg_node_spec_t *inst_specp; 137634683adeSsg70180 mdeg_handle_t mdeg_hdl, mdeg_port_hdl; 13771ae08745Sheppo size_t templatesz; 137819b65a69Ssb155480 int rv; 13791ae08745Sheppo 13801ae08745Sheppo D1(vswp, "%s: enter", __func__); 13811ae08745Sheppo 138234683adeSsg70180 /* 13831ae08745Sheppo * Allocate and initialize a per-instance copy 13841ae08745Sheppo * of the global property spec array that will 13851ae08745Sheppo * uniquely identify this vsw instance. 13861ae08745Sheppo */ 13871ae08745Sheppo templatesz = sizeof (vsw_prop_template); 13881ae08745Sheppo pspecp = kmem_zalloc(templatesz, KM_SLEEP); 13891ae08745Sheppo 13901ae08745Sheppo bcopy(vsw_prop_template, pspecp, templatesz); 13911ae08745Sheppo 139219b65a69Ssb155480 VSW_SET_MDEG_PROP_INST(pspecp, vswp->regprop); 13931ae08745Sheppo 13941ae08745Sheppo /* initialize the complete prop spec structure */ 13951ae08745Sheppo inst_specp = kmem_zalloc(sizeof (mdeg_node_spec_t), KM_SLEEP); 13961ae08745Sheppo inst_specp->namep = "virtual-device"; 13971ae08745Sheppo inst_specp->specp = pspecp; 13981ae08745Sheppo 139919b65a69Ssb155480 D2(vswp, "%s: instance %d registering with mdeg", __func__, 140019b65a69Ssb155480 vswp->regprop); 140134683adeSsg70180 /* 140234683adeSsg70180 * Register an interest in 'virtual-device' nodes with a 140334683adeSsg70180 * 'name' property of 'virtual-network-switch' 140434683adeSsg70180 */ 140534683adeSsg70180 rv = mdeg_register(inst_specp, &vdev_match, vsw_mdeg_cb, 14061ae08745Sheppo (void *)vswp, &mdeg_hdl); 140734683adeSsg70180 if (rv != MDEG_SUCCESS) { 140834683adeSsg70180 DERR(vswp, "%s: mdeg_register failed (%d) for vsw node", 140934683adeSsg70180 __func__, rv); 141034683adeSsg70180 goto mdeg_reg_fail; 141134683adeSsg70180 } 14121ae08745Sheppo 141334683adeSsg70180 /* 141434683adeSsg70180 * Register an interest in 'vsw-port' nodes. 141534683adeSsg70180 */ 141634683adeSsg70180 rv = mdeg_register(inst_specp, &vport_match, vsw_port_mdeg_cb, 141734683adeSsg70180 (void *)vswp, &mdeg_port_hdl); 14181ae08745Sheppo if (rv != MDEG_SUCCESS) { 14191ae08745Sheppo DERR(vswp, "%s: mdeg_register failed (%d)\n", __func__, rv); 142034683adeSsg70180 (void) mdeg_unregister(mdeg_hdl); 142134683adeSsg70180 goto mdeg_reg_fail; 14221ae08745Sheppo } 14231ae08745Sheppo 14241ae08745Sheppo /* save off data that will be needed later */ 14251ae08745Sheppo vswp->inst_spec = inst_specp; 14261ae08745Sheppo vswp->mdeg_hdl = mdeg_hdl; 142734683adeSsg70180 vswp->mdeg_port_hdl = mdeg_port_hdl; 14281ae08745Sheppo 14291ae08745Sheppo D1(vswp, "%s: exit", __func__); 143034683adeSsg70180 return (0); 143134683adeSsg70180 143234683adeSsg70180 mdeg_reg_fail: 143334683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to register MDEG callbacks", 143434683adeSsg70180 vswp->instance); 143534683adeSsg70180 kmem_free(pspecp, templatesz); 143634683adeSsg70180 kmem_free(inst_specp, sizeof (mdeg_node_spec_t)); 143734683adeSsg70180 143834683adeSsg70180 vswp->mdeg_hdl = NULL; 143934683adeSsg70180 vswp->mdeg_port_hdl = NULL; 144034683adeSsg70180 144134683adeSsg70180 return (1); 14421ae08745Sheppo } 14431ae08745Sheppo 14441ae08745Sheppo static void 14451ae08745Sheppo vsw_mdeg_unregister(vsw_t *vswp) 14461ae08745Sheppo { 14471ae08745Sheppo D1(vswp, "vsw_mdeg_unregister: enter"); 14481ae08745Sheppo 144934683adeSsg70180 if (vswp->mdeg_hdl != NULL) 14501ae08745Sheppo (void) mdeg_unregister(vswp->mdeg_hdl); 14511ae08745Sheppo 145234683adeSsg70180 if (vswp->mdeg_port_hdl != NULL) 145334683adeSsg70180 (void) mdeg_unregister(vswp->mdeg_port_hdl); 145434683adeSsg70180 145534683adeSsg70180 if (vswp->inst_spec != NULL) { 14561ae08745Sheppo if (vswp->inst_spec->specp != NULL) { 14571ae08745Sheppo (void) kmem_free(vswp->inst_spec->specp, 14581ae08745Sheppo sizeof (vsw_prop_template)); 14591ae08745Sheppo vswp->inst_spec->specp = NULL; 14601ae08745Sheppo } 14611ae08745Sheppo 1462205eeb1aSlm66018 (void) kmem_free(vswp->inst_spec, sizeof (mdeg_node_spec_t)); 14631ae08745Sheppo vswp->inst_spec = NULL; 14641ae08745Sheppo } 14651ae08745Sheppo 14661ae08745Sheppo D1(vswp, "vsw_mdeg_unregister: exit"); 14671ae08745Sheppo } 14681ae08745Sheppo 146934683adeSsg70180 /* 147034683adeSsg70180 * Mdeg callback invoked for the vsw node itself. 147134683adeSsg70180 */ 14721ae08745Sheppo static int 14731ae08745Sheppo vsw_mdeg_cb(void *cb_argp, mdeg_result_t *resp) 14741ae08745Sheppo { 14751ae08745Sheppo vsw_t *vswp; 14761ae08745Sheppo md_t *mdp; 14771ae08745Sheppo mde_cookie_t node; 14781ae08745Sheppo uint64_t inst; 147934683adeSsg70180 char *node_name = NULL; 14801ae08745Sheppo 14811ae08745Sheppo if (resp == NULL) 14821ae08745Sheppo return (MDEG_FAILURE); 14831ae08745Sheppo 14841ae08745Sheppo vswp = (vsw_t *)cb_argp; 14851ae08745Sheppo 148634683adeSsg70180 D1(vswp, "%s: added %d : removed %d : curr matched %d" 148734683adeSsg70180 " : prev matched %d", __func__, resp->added.nelem, 148834683adeSsg70180 resp->removed.nelem, resp->match_curr.nelem, 148934683adeSsg70180 resp->match_prev.nelem); 149034683adeSsg70180 149134683adeSsg70180 /* 149219b65a69Ssb155480 * We get an initial callback for this node as 'added' 149319b65a69Ssb155480 * after registering with mdeg. Note that we would have 149419b65a69Ssb155480 * already gathered information about this vsw node by 149519b65a69Ssb155480 * walking MD earlier during attach (in vsw_read_mdprops()). 149619b65a69Ssb155480 * So, there is a window where the properties of this 149719b65a69Ssb155480 * node might have changed when we get this initial 'added' 149819b65a69Ssb155480 * callback. We handle this as if an update occured 149919b65a69Ssb155480 * and invoke the same function which handles updates to 150019b65a69Ssb155480 * the properties of this vsw-node if any. 150119b65a69Ssb155480 * 150234683adeSsg70180 * A non-zero 'match' value indicates that the MD has been 150319b65a69Ssb155480 * updated and that a virtual-network-switch node is 150419b65a69Ssb155480 * present which may or may not have been updated. It is 150519b65a69Ssb155480 * up to the clients to examine their own nodes and 150619b65a69Ssb155480 * determine if they have changed. 150734683adeSsg70180 */ 150819b65a69Ssb155480 if (resp->added.nelem != 0) { 150934683adeSsg70180 151019b65a69Ssb155480 if (resp->added.nelem != 1) { 151119b65a69Ssb155480 cmn_err(CE_NOTE, "!vsw%d: number of nodes added " 151219b65a69Ssb155480 "invalid: %d\n", vswp->instance, resp->added.nelem); 151319b65a69Ssb155480 return (MDEG_FAILURE); 151419b65a69Ssb155480 } 151519b65a69Ssb155480 151619b65a69Ssb155480 mdp = resp->added.mdp; 151719b65a69Ssb155480 node = resp->added.mdep[0]; 151819b65a69Ssb155480 151919b65a69Ssb155480 } else if (resp->match_curr.nelem != 0) { 152019b65a69Ssb155480 152119b65a69Ssb155480 if (resp->match_curr.nelem != 1) { 152219b65a69Ssb155480 cmn_err(CE_NOTE, "!vsw%d: number of nodes updated " 152319b65a69Ssb155480 "invalid: %d\n", vswp->instance, 152419b65a69Ssb155480 resp->match_curr.nelem); 152519b65a69Ssb155480 return (MDEG_FAILURE); 152619b65a69Ssb155480 } 152719b65a69Ssb155480 152819b65a69Ssb155480 mdp = resp->match_curr.mdp; 152919b65a69Ssb155480 node = resp->match_curr.mdep[0]; 153019b65a69Ssb155480 153119b65a69Ssb155480 } else { 153219b65a69Ssb155480 return (MDEG_FAILURE); 153319b65a69Ssb155480 } 153419b65a69Ssb155480 153519b65a69Ssb155480 /* Validate name and instance */ 153634683adeSsg70180 if (md_get_prop_str(mdp, node, "name", &node_name) != 0) { 153719b65a69Ssb155480 DERR(vswp, "%s: unable to get node name\n", __func__); 153819b65a69Ssb155480 return (MDEG_FAILURE); 153919b65a69Ssb155480 } 154019b65a69Ssb155480 154119b65a69Ssb155480 /* is this a virtual-network-switch? */ 154219b65a69Ssb155480 if (strcmp(node_name, vsw_propname) != 0) { 154319b65a69Ssb155480 DERR(vswp, "%s: Invalid node name: %s\n", 154419b65a69Ssb155480 __func__, node_name); 154519b65a69Ssb155480 return (MDEG_FAILURE); 154634683adeSsg70180 } 154734683adeSsg70180 154834683adeSsg70180 if (md_get_prop_val(mdp, node, "cfg-handle", &inst)) { 154919b65a69Ssb155480 DERR(vswp, "%s: prop(cfg-handle) not found\n", 155019b65a69Ssb155480 __func__); 155119b65a69Ssb155480 return (MDEG_FAILURE); 155234683adeSsg70180 } 155334683adeSsg70180 155419b65a69Ssb155480 /* is this the right instance of vsw? */ 155519b65a69Ssb155480 if (inst != vswp->regprop) { 155619b65a69Ssb155480 DERR(vswp, "%s: Invalid cfg-handle: %lx\n", 155719b65a69Ssb155480 __func__, inst); 155819b65a69Ssb155480 return (MDEG_FAILURE); 155919b65a69Ssb155480 } 156034683adeSsg70180 156134683adeSsg70180 vsw_update_md_prop(vswp, mdp, node); 156234683adeSsg70180 156334683adeSsg70180 return (MDEG_SUCCESS); 156434683adeSsg70180 } 156534683adeSsg70180 156634683adeSsg70180 /* 156734683adeSsg70180 * Mdeg callback invoked for changes to the vsw-port nodes 156834683adeSsg70180 * under the vsw node. 156934683adeSsg70180 */ 157034683adeSsg70180 static int 157134683adeSsg70180 vsw_port_mdeg_cb(void *cb_argp, mdeg_result_t *resp) 157234683adeSsg70180 { 157334683adeSsg70180 vsw_t *vswp; 157434683adeSsg70180 int idx; 157534683adeSsg70180 md_t *mdp; 157634683adeSsg70180 mde_cookie_t node; 157734683adeSsg70180 uint64_t inst; 15781ef0bbb5Snarayan int rv; 157934683adeSsg70180 158034683adeSsg70180 if ((resp == NULL) || (cb_argp == NULL)) 158134683adeSsg70180 return (MDEG_FAILURE); 158234683adeSsg70180 158334683adeSsg70180 vswp = (vsw_t *)cb_argp; 158434683adeSsg70180 158534683adeSsg70180 D2(vswp, "%s: added %d : removed %d : curr matched %d" 158634683adeSsg70180 " : prev matched %d", __func__, resp->added.nelem, 158734683adeSsg70180 resp->removed.nelem, resp->match_curr.nelem, 15881ae08745Sheppo resp->match_prev.nelem); 15891ae08745Sheppo 15901ae08745Sheppo /* process added ports */ 15911ae08745Sheppo for (idx = 0; idx < resp->added.nelem; idx++) { 15921ae08745Sheppo mdp = resp->added.mdp; 15931ae08745Sheppo node = resp->added.mdep[idx]; 15941ae08745Sheppo 15951ae08745Sheppo D2(vswp, "%s: adding node(%d) 0x%lx", __func__, idx, node); 15961ae08745Sheppo 15971ef0bbb5Snarayan if ((rv = vsw_port_add(vswp, mdp, &node)) != 0) { 159834683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to add new port " 15991ef0bbb5Snarayan "(0x%lx), err=%d", vswp->instance, node, rv); 16001ae08745Sheppo } 16011ae08745Sheppo } 16021ae08745Sheppo 16031ae08745Sheppo /* process removed ports */ 16041ae08745Sheppo for (idx = 0; idx < resp->removed.nelem; idx++) { 16051ae08745Sheppo mdp = resp->removed.mdp; 16061ae08745Sheppo node = resp->removed.mdep[idx]; 16071ae08745Sheppo 16081ae08745Sheppo if (md_get_prop_val(mdp, node, id_propname, &inst)) { 160934683adeSsg70180 DERR(vswp, "%s: prop(%s) not found in port(%d)", 16101ae08745Sheppo __func__, id_propname, idx); 16111ae08745Sheppo continue; 16121ae08745Sheppo } 16131ae08745Sheppo 16141ae08745Sheppo D2(vswp, "%s: removing node(%d) 0x%lx", __func__, idx, node); 16151ae08745Sheppo 16161ae08745Sheppo if (vsw_port_detach(vswp, inst) != 0) { 161734683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to remove port %ld", 161834683adeSsg70180 vswp->instance, inst); 16191ae08745Sheppo } 16201ae08745Sheppo } 16211ae08745Sheppo 1622c1c61f44Ssb155480 for (idx = 0; idx < resp->match_curr.nelem; idx++) { 1623c1c61f44Ssb155480 (void) vsw_port_update(vswp, resp->match_curr.mdp, 1624c1c61f44Ssb155480 resp->match_curr.mdep[idx], 1625c1c61f44Ssb155480 resp->match_prev.mdp, 1626c1c61f44Ssb155480 resp->match_prev.mdep[idx]); 1627c1c61f44Ssb155480 } 16281ae08745Sheppo 16291ae08745Sheppo D1(vswp, "%s: exit", __func__); 16301ae08745Sheppo 16311ae08745Sheppo return (MDEG_SUCCESS); 16321ae08745Sheppo } 16331ae08745Sheppo 16341ae08745Sheppo /* 163519b65a69Ssb155480 * Scan the machine description for this instance of vsw 163619b65a69Ssb155480 * and read its properties. Called only from vsw_attach(). 163719b65a69Ssb155480 * Returns: 0 on success, 1 on failure. 163819b65a69Ssb155480 */ 163919b65a69Ssb155480 static int 164019b65a69Ssb155480 vsw_read_mdprops(vsw_t *vswp) 164119b65a69Ssb155480 { 164219b65a69Ssb155480 md_t *mdp = NULL; 164319b65a69Ssb155480 mde_cookie_t rootnode; 164419b65a69Ssb155480 mde_cookie_t *listp = NULL; 164519b65a69Ssb155480 uint64_t inst; 164619b65a69Ssb155480 uint64_t cfgh; 164719b65a69Ssb155480 char *name; 164819b65a69Ssb155480 int rv = 1; 164919b65a69Ssb155480 int num_nodes = 0; 165019b65a69Ssb155480 int num_devs = 0; 165119b65a69Ssb155480 int listsz = 0; 165219b65a69Ssb155480 int i; 165319b65a69Ssb155480 165419b65a69Ssb155480 /* 165519b65a69Ssb155480 * In each 'virtual-device' node in the MD there is a 165619b65a69Ssb155480 * 'cfg-handle' property which is the MD's concept of 165719b65a69Ssb155480 * an instance number (this may be completely different from 165819b65a69Ssb155480 * the device drivers instance #). OBP reads that value and 165919b65a69Ssb155480 * stores it in the 'reg' property of the appropriate node in 166019b65a69Ssb155480 * the device tree. We first read this reg property and use this 166119b65a69Ssb155480 * to compare against the 'cfg-handle' property of vsw nodes 166219b65a69Ssb155480 * in MD to get to this specific vsw instance and then read 166319b65a69Ssb155480 * other properties that we are interested in. 166419b65a69Ssb155480 * We also cache the value of 'reg' property and use it later 166519b65a69Ssb155480 * to register callbacks with mdeg (see vsw_mdeg_register()) 166619b65a69Ssb155480 */ 166719b65a69Ssb155480 inst = ddi_prop_get_int(DDI_DEV_T_ANY, vswp->dip, 166819b65a69Ssb155480 DDI_PROP_DONTPASS, reg_propname, -1); 166919b65a69Ssb155480 if (inst == -1) { 167019b65a69Ssb155480 cmn_err(CE_NOTE, "!vsw%d: Unable to read %s property from " 167119b65a69Ssb155480 "OBP device tree", vswp->instance, reg_propname); 167219b65a69Ssb155480 return (rv); 167319b65a69Ssb155480 } 167419b65a69Ssb155480 167519b65a69Ssb155480 vswp->regprop = inst; 167619b65a69Ssb155480 167719b65a69Ssb155480 if ((mdp = md_get_handle()) == NULL) { 167819b65a69Ssb155480 DWARN(vswp, "%s: cannot init MD\n", __func__); 167919b65a69Ssb155480 return (rv); 168019b65a69Ssb155480 } 168119b65a69Ssb155480 168219b65a69Ssb155480 num_nodes = md_node_count(mdp); 168319b65a69Ssb155480 ASSERT(num_nodes > 0); 168419b65a69Ssb155480 168519b65a69Ssb155480 listsz = num_nodes * sizeof (mde_cookie_t); 168619b65a69Ssb155480 listp = (mde_cookie_t *)kmem_zalloc(listsz, KM_SLEEP); 168719b65a69Ssb155480 168819b65a69Ssb155480 rootnode = md_root_node(mdp); 168919b65a69Ssb155480 169019b65a69Ssb155480 /* search for all "virtual_device" nodes */ 169119b65a69Ssb155480 num_devs = md_scan_dag(mdp, rootnode, 169219b65a69Ssb155480 md_find_name(mdp, vdev_propname), 169319b65a69Ssb155480 md_find_name(mdp, "fwd"), listp); 169419b65a69Ssb155480 if (num_devs <= 0) { 169519b65a69Ssb155480 DWARN(vswp, "%s: invalid num_devs:%d\n", __func__, num_devs); 169619b65a69Ssb155480 goto vsw_readmd_exit; 169719b65a69Ssb155480 } 169819b65a69Ssb155480 169919b65a69Ssb155480 /* 170019b65a69Ssb155480 * Now loop through the list of virtual-devices looking for 170119b65a69Ssb155480 * devices with name "virtual-network-switch" and for each 170219b65a69Ssb155480 * such device compare its instance with what we have from 170319b65a69Ssb155480 * the 'reg' property to find the right node in MD and then 170419b65a69Ssb155480 * read all its properties. 170519b65a69Ssb155480 */ 170619b65a69Ssb155480 for (i = 0; i < num_devs; i++) { 170719b65a69Ssb155480 170819b65a69Ssb155480 if (md_get_prop_str(mdp, listp[i], "name", &name) != 0) { 170919b65a69Ssb155480 DWARN(vswp, "%s: name property not found\n", 171019b65a69Ssb155480 __func__); 171119b65a69Ssb155480 goto vsw_readmd_exit; 171219b65a69Ssb155480 } 171319b65a69Ssb155480 171419b65a69Ssb155480 /* is this a virtual-network-switch? */ 171519b65a69Ssb155480 if (strcmp(name, vsw_propname) != 0) 171619b65a69Ssb155480 continue; 171719b65a69Ssb155480 171819b65a69Ssb155480 if (md_get_prop_val(mdp, listp[i], "cfg-handle", &cfgh) != 0) { 171919b65a69Ssb155480 DWARN(vswp, "%s: cfg-handle property not found\n", 172019b65a69Ssb155480 __func__); 172119b65a69Ssb155480 goto vsw_readmd_exit; 172219b65a69Ssb155480 } 172319b65a69Ssb155480 172419b65a69Ssb155480 /* is this the required instance of vsw? */ 172519b65a69Ssb155480 if (inst != cfgh) 172619b65a69Ssb155480 continue; 172719b65a69Ssb155480 172819b65a69Ssb155480 /* now read all properties of this vsw instance */ 172919b65a69Ssb155480 rv = vsw_get_initial_md_properties(vswp, mdp, listp[i]); 173019b65a69Ssb155480 break; 173119b65a69Ssb155480 } 173219b65a69Ssb155480 173319b65a69Ssb155480 vsw_readmd_exit: 173419b65a69Ssb155480 173519b65a69Ssb155480 kmem_free(listp, listsz); 173619b65a69Ssb155480 (void) md_fini_handle(mdp); 173719b65a69Ssb155480 return (rv); 173819b65a69Ssb155480 } 173919b65a69Ssb155480 174019b65a69Ssb155480 /* 174134683adeSsg70180 * Read the initial start-of-day values from the specified MD node. 174234683adeSsg70180 */ 174319b65a69Ssb155480 static int 174434683adeSsg70180 vsw_get_initial_md_properties(vsw_t *vswp, md_t *mdp, mde_cookie_t node) 174534683adeSsg70180 { 174634683adeSsg70180 uint64_t macaddr = 0; 174734683adeSsg70180 174834683adeSsg70180 D1(vswp, "%s: enter", __func__); 174934683adeSsg70180 175019b65a69Ssb155480 if (vsw_get_md_physname(vswp, mdp, node, vswp->physname) != 0) { 175119b65a69Ssb155480 return (1); 175234683adeSsg70180 } 175334683adeSsg70180 175434683adeSsg70180 /* mac address for vswitch device itself */ 175534683adeSsg70180 if (md_get_prop_val(mdp, node, macaddr_propname, &macaddr) != 0) { 175634683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to get MAC address from MD", 175734683adeSsg70180 vswp->instance); 175819b65a69Ssb155480 return (1); 175919b65a69Ssb155480 } 176034683adeSsg70180 176119b65a69Ssb155480 vsw_save_lmacaddr(vswp, macaddr); 176234683adeSsg70180 1763da14cebeSEric Cheng if (vsw_get_md_smodes(vswp, mdp, node, &vswp->smode)) { 17641ef0bbb5Snarayan DWARN(vswp, "%s: Unable to read %s property from MD, " 17651ef0bbb5Snarayan "defaulting to 'switched' mode", 17661ef0bbb5Snarayan __func__, smode_propname); 176734683adeSsg70180 1768da14cebeSEric Cheng vswp->smode = VSW_LAYER2; 176934683adeSsg70180 } 177034683adeSsg70180 17711107ea93SSriharsha Basavapatna /* 17721107ea93SSriharsha Basavapatna * Read the 'linkprop' property to know if this 17731107ea93SSriharsha Basavapatna * vsw device wants to get physical link updates. 17741107ea93SSriharsha Basavapatna */ 17751107ea93SSriharsha Basavapatna vsw_linkprop_read(vswp, mdp, node, &vswp->pls_update); 17761107ea93SSriharsha Basavapatna 17777b1f684aSSriharsha Basavapatna /* read mtu */ 17787b1f684aSSriharsha Basavapatna vsw_mtu_read(vswp, mdp, node, &vswp->mtu); 17797b1f684aSSriharsha Basavapatna if (vswp->mtu < ETHERMTU || vswp->mtu > VNET_MAX_MTU) { 17807b1f684aSSriharsha Basavapatna vswp->mtu = ETHERMTU; 17817b1f684aSSriharsha Basavapatna } 17827b1f684aSSriharsha Basavapatna vswp->max_frame_size = vswp->mtu + sizeof (struct ether_header) + 17837b1f684aSSriharsha Basavapatna VLAN_TAGSZ; 17847b1f684aSSriharsha Basavapatna 1785c1c61f44Ssb155480 /* read vlan id properties of this vsw instance */ 1786c1c61f44Ssb155480 vsw_vlan_read_ids(vswp, VSW_LOCALDEV, mdp, node, &vswp->pvid, 1787c1c61f44Ssb155480 &vswp->vids, &vswp->nvids, &vswp->default_vlan_id); 1788c1c61f44Ssb155480 1789c1c61f44Ssb155480 /* read priority-ether-types */ 1790f0ca1d9aSsb155480 vsw_read_pri_eth_types(vswp, mdp, node); 1791f0ca1d9aSsb155480 1792bce0a86eSWENTAO YANG /* read bandwidth property of this vsw instance */ 1793bce0a86eSWENTAO YANG vsw_bandwidth_read(vswp, mdp, node, &vswp->bandwidth); 1794bce0a86eSWENTAO YANG 179534683adeSsg70180 D1(vswp, "%s: exit", __func__); 179619b65a69Ssb155480 return (0); 179734683adeSsg70180 } 179834683adeSsg70180 179934683adeSsg70180 /* 1800c1c61f44Ssb155480 * Read vlan id properties of the given MD node. 1801c1c61f44Ssb155480 * Arguments: 1802c1c61f44Ssb155480 * arg: device argument(vsw device or a port) 1803c1c61f44Ssb155480 * type: type of arg; VSW_LOCALDEV(vsw device) or VSW_VNETPORT(port) 1804c1c61f44Ssb155480 * mdp: machine description 1805c1c61f44Ssb155480 * node: md node cookie 1806c1c61f44Ssb155480 * 1807c1c61f44Ssb155480 * Returns: 1808c1c61f44Ssb155480 * pvidp: port-vlan-id of the node 1809c1c61f44Ssb155480 * vidspp: list of vlan-ids of the node 1810c1c61f44Ssb155480 * nvidsp: # of vlan-ids in the list 1811c1c61f44Ssb155480 * default_idp: default-vlan-id of the node(if node is vsw device) 1812c1c61f44Ssb155480 */ 1813c1c61f44Ssb155480 static void 1814c1c61f44Ssb155480 vsw_vlan_read_ids(void *arg, int type, md_t *mdp, mde_cookie_t node, 1815da14cebeSEric Cheng uint16_t *pvidp, vsw_vlanid_t **vidspp, uint16_t *nvidsp, 1816c1c61f44Ssb155480 uint16_t *default_idp) 1817c1c61f44Ssb155480 { 1818c1c61f44Ssb155480 vsw_t *vswp; 1819c1c61f44Ssb155480 vsw_port_t *portp; 1820c1c61f44Ssb155480 char *pvid_propname; 1821c1c61f44Ssb155480 char *vid_propname; 1822c1c61f44Ssb155480 uint_t nvids = 0; 1823c1c61f44Ssb155480 uint32_t vids_size; 1824c1c61f44Ssb155480 int rv; 1825c1c61f44Ssb155480 int i; 1826c1c61f44Ssb155480 uint64_t *data; 1827c1c61f44Ssb155480 uint64_t val; 1828c1c61f44Ssb155480 int size; 1829c1c61f44Ssb155480 int inst; 1830c1c61f44Ssb155480 1831c1c61f44Ssb155480 if (type == VSW_LOCALDEV) { 1832c1c61f44Ssb155480 1833c1c61f44Ssb155480 vswp = (vsw_t *)arg; 1834c1c61f44Ssb155480 pvid_propname = vsw_pvid_propname; 1835c1c61f44Ssb155480 vid_propname = vsw_vid_propname; 1836c1c61f44Ssb155480 inst = vswp->instance; 1837c1c61f44Ssb155480 1838c1c61f44Ssb155480 } else if (type == VSW_VNETPORT) { 1839c1c61f44Ssb155480 1840c1c61f44Ssb155480 portp = (vsw_port_t *)arg; 1841c1c61f44Ssb155480 vswp = portp->p_vswp; 1842c1c61f44Ssb155480 pvid_propname = port_pvid_propname; 1843c1c61f44Ssb155480 vid_propname = port_vid_propname; 1844c1c61f44Ssb155480 inst = portp->p_instance; 1845c1c61f44Ssb155480 1846c1c61f44Ssb155480 } else { 1847c1c61f44Ssb155480 return; 1848c1c61f44Ssb155480 } 1849c1c61f44Ssb155480 1850c1c61f44Ssb155480 if (type == VSW_LOCALDEV && default_idp != NULL) { 1851c1c61f44Ssb155480 rv = md_get_prop_val(mdp, node, vsw_dvid_propname, &val); 1852c1c61f44Ssb155480 if (rv != 0) { 1853c1c61f44Ssb155480 DWARN(vswp, "%s: prop(%s) not found", __func__, 1854c1c61f44Ssb155480 vsw_dvid_propname); 1855c1c61f44Ssb155480 1856c1c61f44Ssb155480 *default_idp = vsw_default_vlan_id; 1857c1c61f44Ssb155480 } else { 1858c1c61f44Ssb155480 *default_idp = val & 0xFFF; 1859c1c61f44Ssb155480 D2(vswp, "%s: %s(%d): (%d)\n", __func__, 1860c1c61f44Ssb155480 vsw_dvid_propname, inst, *default_idp); 1861c1c61f44Ssb155480 } 1862c1c61f44Ssb155480 } 1863c1c61f44Ssb155480 1864c1c61f44Ssb155480 rv = md_get_prop_val(mdp, node, pvid_propname, &val); 1865c1c61f44Ssb155480 if (rv != 0) { 1866c1c61f44Ssb155480 DWARN(vswp, "%s: prop(%s) not found", __func__, pvid_propname); 1867c1c61f44Ssb155480 *pvidp = vsw_default_vlan_id; 1868c1c61f44Ssb155480 } else { 1869c1c61f44Ssb155480 1870c1c61f44Ssb155480 *pvidp = val & 0xFFF; 1871c1c61f44Ssb155480 D2(vswp, "%s: %s(%d): (%d)\n", __func__, 1872c1c61f44Ssb155480 pvid_propname, inst, *pvidp); 1873c1c61f44Ssb155480 } 1874c1c61f44Ssb155480 1875c1c61f44Ssb155480 rv = md_get_prop_data(mdp, node, vid_propname, (uint8_t **)&data, 1876c1c61f44Ssb155480 &size); 1877c1c61f44Ssb155480 if (rv != 0) { 1878c1c61f44Ssb155480 D2(vswp, "%s: prop(%s) not found", __func__, vid_propname); 1879c1c61f44Ssb155480 size = 0; 1880c1c61f44Ssb155480 } else { 1881c1c61f44Ssb155480 size /= sizeof (uint64_t); 1882c1c61f44Ssb155480 } 1883c1c61f44Ssb155480 nvids = size; 1884c1c61f44Ssb155480 1885c1c61f44Ssb155480 if (nvids != 0) { 1886c1c61f44Ssb155480 D2(vswp, "%s: %s(%d): ", __func__, vid_propname, inst); 1887da14cebeSEric Cheng vids_size = sizeof (vsw_vlanid_t) * nvids; 1888c1c61f44Ssb155480 *vidspp = kmem_zalloc(vids_size, KM_SLEEP); 1889c1c61f44Ssb155480 for (i = 0; i < nvids; i++) { 1890da14cebeSEric Cheng (*vidspp)[i].vl_vid = data[i] & 0xFFFF; 1891da14cebeSEric Cheng (*vidspp)[i].vl_set = B_FALSE; 1892da14cebeSEric Cheng D2(vswp, " %d ", (*vidspp)[i].vl_vid); 1893c1c61f44Ssb155480 } 1894c1c61f44Ssb155480 D2(vswp, "\n"); 1895c1c61f44Ssb155480 } 1896c1c61f44Ssb155480 1897c1c61f44Ssb155480 *nvidsp = nvids; 1898c1c61f44Ssb155480 } 1899c1c61f44Ssb155480 1900bce0a86eSWENTAO YANG static void 1901bce0a86eSWENTAO YANG vsw_port_read_bandwidth(vsw_port_t *portp, md_t *mdp, mde_cookie_t node, 1902bce0a86eSWENTAO YANG uint64_t *bw) 1903bce0a86eSWENTAO YANG { 1904bce0a86eSWENTAO YANG int rv; 1905bce0a86eSWENTAO YANG uint64_t val; 1906bce0a86eSWENTAO YANG vsw_t *vswp; 1907bce0a86eSWENTAO YANG 1908bce0a86eSWENTAO YANG vswp = portp->p_vswp; 1909bce0a86eSWENTAO YANG 1910bce0a86eSWENTAO YANG rv = md_get_prop_val(mdp, node, port_maxbw_propname, &val); 1911bce0a86eSWENTAO YANG 1912bce0a86eSWENTAO YANG if (rv != 0) { 1913bce0a86eSWENTAO YANG *bw = 0; 1914bce0a86eSWENTAO YANG D3(vswp, "%s: prop(%s) not found\n", __func__, 1915bce0a86eSWENTAO YANG port_maxbw_propname); 1916bce0a86eSWENTAO YANG } else { 1917bce0a86eSWENTAO YANG *bw = val; 1918bce0a86eSWENTAO YANG D3(vswp, "%s: %s nodes found", __func__, port_maxbw_propname); 1919bce0a86eSWENTAO YANG } 1920bce0a86eSWENTAO YANG } 1921bce0a86eSWENTAO YANG 1922c1c61f44Ssb155480 /* 1923f0ca1d9aSsb155480 * This function reads "priority-ether-types" property from md. This property 1924f0ca1d9aSsb155480 * is used to enable support for priority frames. Applications which need 1925f0ca1d9aSsb155480 * guaranteed and timely delivery of certain high priority frames to/from 1926f0ca1d9aSsb155480 * a vnet or vsw within ldoms, should configure this property by providing 1927f0ca1d9aSsb155480 * the ether type(s) for which the priority facility is needed. 1928f0ca1d9aSsb155480 * Normal data frames are delivered over a ldc channel using the descriptor 1929f0ca1d9aSsb155480 * ring mechanism which is constrained by factors such as descriptor ring size, 1930f0ca1d9aSsb155480 * the rate at which the ring is processed at the peer ldc end point, etc. 1931f0ca1d9aSsb155480 * The priority mechanism provides an Out-Of-Band path to send/receive frames 1932f0ca1d9aSsb155480 * as raw pkt data (VIO_PKT_DATA) messages over the channel, avoiding the 1933f0ca1d9aSsb155480 * descriptor ring path and enables a more reliable and timely delivery of 1934f0ca1d9aSsb155480 * frames to the peer. 1935f0ca1d9aSsb155480 */ 1936f0ca1d9aSsb155480 static void 1937f0ca1d9aSsb155480 vsw_read_pri_eth_types(vsw_t *vswp, md_t *mdp, mde_cookie_t node) 1938f0ca1d9aSsb155480 { 1939f0ca1d9aSsb155480 int rv; 1940f0ca1d9aSsb155480 uint16_t *types; 1941f0ca1d9aSsb155480 uint64_t *data; 1942f0ca1d9aSsb155480 int size; 1943f0ca1d9aSsb155480 int i; 1944f0ca1d9aSsb155480 size_t mblk_sz; 1945f0ca1d9aSsb155480 1946f0ca1d9aSsb155480 rv = md_get_prop_data(mdp, node, pri_types_propname, 1947f0ca1d9aSsb155480 (uint8_t **)&data, &size); 1948f0ca1d9aSsb155480 if (rv != 0) { 1949f0ca1d9aSsb155480 /* 1950f0ca1d9aSsb155480 * Property may not exist if we are running pre-ldoms1.1 f/w. 1951f0ca1d9aSsb155480 * Check if 'vsw_pri_eth_type' has been set in that case. 1952f0ca1d9aSsb155480 */ 1953f0ca1d9aSsb155480 if (vsw_pri_eth_type != 0) { 1954f0ca1d9aSsb155480 size = sizeof (vsw_pri_eth_type); 1955f0ca1d9aSsb155480 data = &vsw_pri_eth_type; 1956f0ca1d9aSsb155480 } else { 1957f0ca1d9aSsb155480 D3(vswp, "%s: prop(%s) not found", __func__, 1958f0ca1d9aSsb155480 pri_types_propname); 1959f0ca1d9aSsb155480 size = 0; 1960f0ca1d9aSsb155480 } 1961f0ca1d9aSsb155480 } 1962f0ca1d9aSsb155480 1963f0ca1d9aSsb155480 if (size == 0) { 1964f0ca1d9aSsb155480 vswp->pri_num_types = 0; 1965f0ca1d9aSsb155480 return; 1966f0ca1d9aSsb155480 } 1967f0ca1d9aSsb155480 1968f0ca1d9aSsb155480 /* 1969f0ca1d9aSsb155480 * we have some priority-ether-types defined; 1970f0ca1d9aSsb155480 * allocate a table of these types and also 1971f0ca1d9aSsb155480 * allocate a pool of mblks to transmit these 1972f0ca1d9aSsb155480 * priority packets. 1973f0ca1d9aSsb155480 */ 1974f0ca1d9aSsb155480 size /= sizeof (uint64_t); 1975f0ca1d9aSsb155480 vswp->pri_num_types = size; 1976f0ca1d9aSsb155480 vswp->pri_types = kmem_zalloc(size * sizeof (uint16_t), KM_SLEEP); 1977f0ca1d9aSsb155480 for (i = 0, types = vswp->pri_types; i < size; i++) { 1978f0ca1d9aSsb155480 types[i] = data[i] & 0xFFFF; 1979f0ca1d9aSsb155480 } 1980f0ca1d9aSsb155480 mblk_sz = (VIO_PKT_DATA_HDRSIZE + ETHERMAX + 7) & ~7; 19817bd3a2e2SSriharsha Basavapatna (void) vio_create_mblks(vsw_pri_tx_nmblks, mblk_sz, NULL, 19827bd3a2e2SSriharsha Basavapatna &vswp->pri_tx_vmp); 1983f0ca1d9aSsb155480 } 1984f0ca1d9aSsb155480 19857b1f684aSSriharsha Basavapatna static void 19867b1f684aSSriharsha Basavapatna vsw_mtu_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node, uint32_t *mtu) 19877b1f684aSSriharsha Basavapatna { 19887b1f684aSSriharsha Basavapatna int rv; 19897b1f684aSSriharsha Basavapatna int inst; 19907b1f684aSSriharsha Basavapatna uint64_t val; 19917b1f684aSSriharsha Basavapatna char *mtu_propname; 19927b1f684aSSriharsha Basavapatna 19937b1f684aSSriharsha Basavapatna mtu_propname = vsw_mtu_propname; 19947b1f684aSSriharsha Basavapatna inst = vswp->instance; 19957b1f684aSSriharsha Basavapatna 19967b1f684aSSriharsha Basavapatna rv = md_get_prop_val(mdp, node, mtu_propname, &val); 19977b1f684aSSriharsha Basavapatna if (rv != 0) { 19987b1f684aSSriharsha Basavapatna D3(vswp, "%s: prop(%s) not found", __func__, mtu_propname); 19997b1f684aSSriharsha Basavapatna *mtu = vsw_ethermtu; 20007b1f684aSSriharsha Basavapatna } else { 20017b1f684aSSriharsha Basavapatna 20027b1f684aSSriharsha Basavapatna *mtu = val & 0xFFFF; 20037b1f684aSSriharsha Basavapatna D2(vswp, "%s: %s(%d): (%d)\n", __func__, 20047b1f684aSSriharsha Basavapatna mtu_propname, inst, *mtu); 20057b1f684aSSriharsha Basavapatna } 20067b1f684aSSriharsha Basavapatna } 20077b1f684aSSriharsha Basavapatna 20087b1f684aSSriharsha Basavapatna /* 20097b1f684aSSriharsha Basavapatna * Update the mtu of the vsw device. We first check if the device has been 20107b1f684aSSriharsha Basavapatna * plumbed and if so fail the mtu update. Otherwise, we continue to update the 20117b1f684aSSriharsha Basavapatna * new mtu and reset all ports to initiate handshake re-negotiation with peers 20127b1f684aSSriharsha Basavapatna * using the new mtu. 20137b1f684aSSriharsha Basavapatna */ 20147b1f684aSSriharsha Basavapatna static int 20157b1f684aSSriharsha Basavapatna vsw_mtu_update(vsw_t *vswp, uint32_t mtu) 20167b1f684aSSriharsha Basavapatna { 20177b1f684aSSriharsha Basavapatna int rv; 20187b1f684aSSriharsha Basavapatna 20197b1f684aSSriharsha Basavapatna WRITE_ENTER(&vswp->if_lockrw); 20207b1f684aSSriharsha Basavapatna 20217b1f684aSSriharsha Basavapatna if (vswp->if_state & VSW_IF_UP) { 20227b1f684aSSriharsha Basavapatna 20237b1f684aSSriharsha Basavapatna RW_EXIT(&vswp->if_lockrw); 20247b1f684aSSriharsha Basavapatna 20257b1f684aSSriharsha Basavapatna cmn_err(CE_NOTE, "!vsw%d: Unable to process mtu update" 20267b1f684aSSriharsha Basavapatna " as the device is plumbed\n", vswp->instance); 20277b1f684aSSriharsha Basavapatna return (EBUSY); 20287b1f684aSSriharsha Basavapatna 20297b1f684aSSriharsha Basavapatna } else { 20307b1f684aSSriharsha Basavapatna 20317b1f684aSSriharsha Basavapatna D2(vswp, "%s: curr_mtu(%d) new_mtu(%d)\n", 20327b1f684aSSriharsha Basavapatna __func__, vswp->mtu, mtu); 20337b1f684aSSriharsha Basavapatna 20347b1f684aSSriharsha Basavapatna vswp->mtu = mtu; 20357b1f684aSSriharsha Basavapatna vswp->max_frame_size = vswp->mtu + 20367b1f684aSSriharsha Basavapatna sizeof (struct ether_header) + VLAN_TAGSZ; 20377b1f684aSSriharsha Basavapatna 20387b1f684aSSriharsha Basavapatna rv = mac_maxsdu_update(vswp->if_mh, mtu); 20397b1f684aSSriharsha Basavapatna if (rv != 0) { 20407b1f684aSSriharsha Basavapatna cmn_err(CE_NOTE, 20417b1f684aSSriharsha Basavapatna "!vsw%d: Unable to update mtu with mac" 20427b1f684aSSriharsha Basavapatna " layer\n", vswp->instance); 20437b1f684aSSriharsha Basavapatna } 20447b1f684aSSriharsha Basavapatna 20457b1f684aSSriharsha Basavapatna RW_EXIT(&vswp->if_lockrw); 20467b1f684aSSriharsha Basavapatna 20477b1f684aSSriharsha Basavapatna /* Reset ports to renegotiate with the new mtu */ 20487b1f684aSSriharsha Basavapatna vsw_reset_ports(vswp); 20497b1f684aSSriharsha Basavapatna 20507b1f684aSSriharsha Basavapatna } 20517b1f684aSSriharsha Basavapatna 20527b1f684aSSriharsha Basavapatna return (0); 20537b1f684aSSriharsha Basavapatna } 20547b1f684aSSriharsha Basavapatna 20551107ea93SSriharsha Basavapatna static void 20561107ea93SSriharsha Basavapatna vsw_linkprop_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node, 20571107ea93SSriharsha Basavapatna boolean_t *pls) 20581107ea93SSriharsha Basavapatna { 20591107ea93SSriharsha Basavapatna int rv; 20601107ea93SSriharsha Basavapatna uint64_t val; 20611107ea93SSriharsha Basavapatna char *linkpropname; 20621107ea93SSriharsha Basavapatna 20631107ea93SSriharsha Basavapatna linkpropname = vsw_linkprop_propname; 20641107ea93SSriharsha Basavapatna 20651107ea93SSriharsha Basavapatna rv = md_get_prop_val(mdp, node, linkpropname, &val); 20661107ea93SSriharsha Basavapatna if (rv != 0) { 20671107ea93SSriharsha Basavapatna D3(vswp, "%s: prop(%s) not found", __func__, linkpropname); 20681107ea93SSriharsha Basavapatna *pls = B_FALSE; 20691107ea93SSriharsha Basavapatna } else { 20701107ea93SSriharsha Basavapatna 20711107ea93SSriharsha Basavapatna *pls = (val & 0x1) ? B_TRUE : B_FALSE; 20721107ea93SSriharsha Basavapatna D2(vswp, "%s: %s(%d): (%d)\n", __func__, linkpropname, 20731107ea93SSriharsha Basavapatna vswp->instance, *pls); 20741107ea93SSriharsha Basavapatna } 20751107ea93SSriharsha Basavapatna } 20761107ea93SSriharsha Basavapatna 2077d8a518c8SSriharsha Basavapatna void 20781107ea93SSriharsha Basavapatna vsw_mac_link_update(vsw_t *vswp, link_state_t link_state) 20791107ea93SSriharsha Basavapatna { 20801107ea93SSriharsha Basavapatna READ_ENTER(&vswp->if_lockrw); 20811107ea93SSriharsha Basavapatna 2082d8a518c8SSriharsha Basavapatna if (vswp->if_state & VSW_IF_REG) { 20831107ea93SSriharsha Basavapatna mac_link_update(vswp->if_mh, link_state); 20841107ea93SSriharsha Basavapatna } 20851107ea93SSriharsha Basavapatna 2086d8a518c8SSriharsha Basavapatna RW_EXIT(&vswp->if_lockrw); 2087d8a518c8SSriharsha Basavapatna } 2088d8a518c8SSriharsha Basavapatna 20891107ea93SSriharsha Basavapatna void 20901107ea93SSriharsha Basavapatna vsw_physlink_state_update(vsw_t *vswp) 20911107ea93SSriharsha Basavapatna { 20921107ea93SSriharsha Basavapatna if (vswp->pls_update == B_TRUE) { 20931107ea93SSriharsha Basavapatna vsw_mac_link_update(vswp, vswp->phys_link_state); 20941107ea93SSriharsha Basavapatna } 20951107ea93SSriharsha Basavapatna vsw_physlink_update_ports(vswp); 20961107ea93SSriharsha Basavapatna } 20971107ea93SSriharsha Basavapatna 2098bce0a86eSWENTAO YANG static void 2099bce0a86eSWENTAO YANG vsw_bandwidth_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node, uint64_t *bw) 2100bce0a86eSWENTAO YANG { 2101bce0a86eSWENTAO YANG /* read the vsw bandwidth from md */ 2102bce0a86eSWENTAO YANG int rv; 2103bce0a86eSWENTAO YANG uint64_t val; 2104bce0a86eSWENTAO YANG 2105bce0a86eSWENTAO YANG rv = md_get_prop_val(mdp, node, vsw_maxbw_propname, &val); 2106bce0a86eSWENTAO YANG if (rv != 0) { 2107bce0a86eSWENTAO YANG *bw = 0; 2108bce0a86eSWENTAO YANG D3(vswp, "%s: prop(%s) not found", __func__, 2109bce0a86eSWENTAO YANG vsw_maxbw_propname); 2110bce0a86eSWENTAO YANG } else { 2111bce0a86eSWENTAO YANG *bw = val; 2112bce0a86eSWENTAO YANG D3(vswp, "%s: %s(%d): (%ld)\n", __func__, 2113bce0a86eSWENTAO YANG vsw_maxbw_propname, vswp->instance, *bw); 2114bce0a86eSWENTAO YANG } 2115bce0a86eSWENTAO YANG } 2116bce0a86eSWENTAO YANG 2117f0ca1d9aSsb155480 /* 211834683adeSsg70180 * Check to see if the relevant properties in the specified node have 211934683adeSsg70180 * changed, and if so take the appropriate action. 212034683adeSsg70180 * 212134683adeSsg70180 * If any of the properties are missing or invalid we don't take 212234683adeSsg70180 * any action, as this function should only be invoked when modifications 212334683adeSsg70180 * have been made to what we assume is a working configuration, which 212434683adeSsg70180 * we leave active. 212534683adeSsg70180 * 212634683adeSsg70180 * Note it is legal for this routine to be invoked even if none of the 212734683adeSsg70180 * properties in the port node within the MD have actually changed. 212834683adeSsg70180 */ 212934683adeSsg70180 static void 213034683adeSsg70180 vsw_update_md_prop(vsw_t *vswp, md_t *mdp, mde_cookie_t node) 213134683adeSsg70180 { 213234683adeSsg70180 char physname[LIFNAMSIZ]; 213334683adeSsg70180 char drv[LIFNAMSIZ]; 213434683adeSsg70180 uint_t ddi_instance; 2135da14cebeSEric Cheng uint8_t new_smode; 2136da14cebeSEric Cheng int i; 213734683adeSsg70180 uint64_t macaddr = 0; 213834683adeSsg70180 enum {MD_init = 0x1, 213934683adeSsg70180 MD_physname = 0x2, 214034683adeSsg70180 MD_macaddr = 0x4, 2141c1c61f44Ssb155480 MD_smode = 0x8, 21427b1f684aSSriharsha Basavapatna MD_vlans = 0x10, 21431107ea93SSriharsha Basavapatna MD_mtu = 0x20, 2144bce0a86eSWENTAO YANG MD_pls = 0x40, 2145bce0a86eSWENTAO YANG MD_bw = 0x80} updated; 214619b65a69Ssb155480 int rv; 2147c1c61f44Ssb155480 uint16_t pvid; 2148da14cebeSEric Cheng vsw_vlanid_t *vids; 2149c1c61f44Ssb155480 uint16_t nvids; 21507b1f684aSSriharsha Basavapatna uint32_t mtu; 21511107ea93SSriharsha Basavapatna boolean_t pls_update; 2152bce0a86eSWENTAO YANG uint64_t maxbw; 215334683adeSsg70180 215434683adeSsg70180 updated = MD_init; 215534683adeSsg70180 215634683adeSsg70180 D1(vswp, "%s: enter", __func__); 215734683adeSsg70180 215834683adeSsg70180 /* 215934683adeSsg70180 * Check if name of physical device in MD has changed. 216034683adeSsg70180 */ 216134683adeSsg70180 if (vsw_get_md_physname(vswp, mdp, node, (char *)&physname) == 0) { 216234683adeSsg70180 /* 216334683adeSsg70180 * Do basic sanity check on new device name/instance, 216434683adeSsg70180 * if its non NULL. It is valid for the device name to 216534683adeSsg70180 * have changed from a non NULL to a NULL value, i.e. 216634683adeSsg70180 * the vsw is being changed to 'routed' mode. 216734683adeSsg70180 */ 216834683adeSsg70180 if ((strlen(physname) != 0) && 2169*ccdeb6b6SDan McDonald (ddi_parse(physname, drv, &ddi_instance) != DDI_SUCCESS)) { 21701ef0bbb5Snarayan cmn_err(CE_WARN, "!vsw%d: physical device %s is not" 217134683adeSsg70180 " a valid device name/instance", 217234683adeSsg70180 vswp->instance, physname); 217334683adeSsg70180 goto fail_reconf; 217434683adeSsg70180 } 217534683adeSsg70180 217634683adeSsg70180 if (strcmp(physname, vswp->physname)) { 217734683adeSsg70180 D2(vswp, "%s: device name changed from %s to %s", 217834683adeSsg70180 __func__, vswp->physname, physname); 217934683adeSsg70180 218034683adeSsg70180 updated |= MD_physname; 218134683adeSsg70180 } else { 218234683adeSsg70180 D2(vswp, "%s: device name unchanged at %s", 218334683adeSsg70180 __func__, vswp->physname); 218434683adeSsg70180 } 218534683adeSsg70180 } else { 218634683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to read name of physical " 218734683adeSsg70180 "device from updated MD.", vswp->instance); 218834683adeSsg70180 goto fail_reconf; 218934683adeSsg70180 } 219034683adeSsg70180 219134683adeSsg70180 /* 219234683adeSsg70180 * Check if MAC address has changed. 219334683adeSsg70180 */ 219434683adeSsg70180 if (md_get_prop_val(mdp, node, macaddr_propname, &macaddr) != 0) { 219534683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to get MAC address from MD", 219634683adeSsg70180 vswp->instance); 219734683adeSsg70180 goto fail_reconf; 219834683adeSsg70180 } else { 219919b65a69Ssb155480 uint64_t maddr = macaddr; 220034683adeSsg70180 READ_ENTER(&vswp->if_lockrw); 220134683adeSsg70180 for (i = ETHERADDRL - 1; i >= 0; i--) { 220219b65a69Ssb155480 if (vswp->if_addr.ether_addr_octet[i] 220319b65a69Ssb155480 != (macaddr & 0xFF)) { 220434683adeSsg70180 D2(vswp, "%s: octet[%d] 0x%x != 0x%x", 220534683adeSsg70180 __func__, i, 220634683adeSsg70180 vswp->if_addr.ether_addr_octet[i], 220734683adeSsg70180 (macaddr & 0xFF)); 220834683adeSsg70180 updated |= MD_macaddr; 220919b65a69Ssb155480 macaddr = maddr; 221034683adeSsg70180 break; 221134683adeSsg70180 } 221234683adeSsg70180 macaddr >>= 8; 221334683adeSsg70180 } 221434683adeSsg70180 RW_EXIT(&vswp->if_lockrw); 221519b65a69Ssb155480 if (updated & MD_macaddr) { 221619b65a69Ssb155480 vsw_save_lmacaddr(vswp, macaddr); 221719b65a69Ssb155480 } 221834683adeSsg70180 } 221934683adeSsg70180 222034683adeSsg70180 /* 222134683adeSsg70180 * Check if switching modes have changed. 222234683adeSsg70180 */ 2223da14cebeSEric Cheng if (vsw_get_md_smodes(vswp, mdp, node, &new_smode)) { 222434683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: Unable to read %s property from MD", 222534683adeSsg70180 vswp->instance, smode_propname); 222634683adeSsg70180 goto fail_reconf; 222734683adeSsg70180 } else { 2228da14cebeSEric Cheng if (new_smode != vswp->smode) { 2229da14cebeSEric Cheng D2(vswp, "%s: switching mode changed from %d to %d", 2230da14cebeSEric Cheng __func__, vswp->smode, new_smode); 223134683adeSsg70180 223234683adeSsg70180 updated |= MD_smode; 223334683adeSsg70180 } 223434683adeSsg70180 } 223534683adeSsg70180 2236c1c61f44Ssb155480 /* Read the vlan ids */ 2237c1c61f44Ssb155480 vsw_vlan_read_ids(vswp, VSW_LOCALDEV, mdp, node, &pvid, &vids, 2238c1c61f44Ssb155480 &nvids, NULL); 2239c1c61f44Ssb155480 2240c1c61f44Ssb155480 /* Determine if there are any vlan id updates */ 2241c1c61f44Ssb155480 if ((pvid != vswp->pvid) || /* pvid changed? */ 2242c1c61f44Ssb155480 (nvids != vswp->nvids) || /* # of vids changed? */ 2243c1c61f44Ssb155480 ((nvids != 0) && (vswp->nvids != 0) && /* vids changed? */ 2244da14cebeSEric Cheng !vsw_cmp_vids(vids, vswp->vids, nvids))) { 2245c1c61f44Ssb155480 updated |= MD_vlans; 2246c1c61f44Ssb155480 } 2247c1c61f44Ssb155480 22487b1f684aSSriharsha Basavapatna /* Read mtu */ 22497b1f684aSSriharsha Basavapatna vsw_mtu_read(vswp, mdp, node, &mtu); 22507b1f684aSSriharsha Basavapatna if (mtu != vswp->mtu) { 22517b1f684aSSriharsha Basavapatna if (mtu >= ETHERMTU && mtu <= VNET_MAX_MTU) { 22527b1f684aSSriharsha Basavapatna updated |= MD_mtu; 22537b1f684aSSriharsha Basavapatna } else { 22547b1f684aSSriharsha Basavapatna cmn_err(CE_NOTE, "!vsw%d: Unable to process mtu update" 22557b1f684aSSriharsha Basavapatna " as the specified value:%d is invalid\n", 22567b1f684aSSriharsha Basavapatna vswp->instance, mtu); 22577b1f684aSSriharsha Basavapatna } 22587b1f684aSSriharsha Basavapatna } 22597b1f684aSSriharsha Basavapatna 226034683adeSsg70180 /* 22611107ea93SSriharsha Basavapatna * Read the 'linkprop' property. 22621107ea93SSriharsha Basavapatna */ 22631107ea93SSriharsha Basavapatna vsw_linkprop_read(vswp, mdp, node, &pls_update); 22641107ea93SSriharsha Basavapatna if (pls_update != vswp->pls_update) { 22651107ea93SSriharsha Basavapatna updated |= MD_pls; 22661107ea93SSriharsha Basavapatna } 22671107ea93SSriharsha Basavapatna 2268bce0a86eSWENTAO YANG /* Read bandwidth */ 2269bce0a86eSWENTAO YANG vsw_bandwidth_read(vswp, mdp, node, &maxbw); 2270bce0a86eSWENTAO YANG if (maxbw != vswp->bandwidth) { 2271bce0a86eSWENTAO YANG if (maxbw >= MRP_MAXBW_MINVAL || maxbw == 0) { 2272bce0a86eSWENTAO YANG updated |= MD_bw; 2273bce0a86eSWENTAO YANG } else { 2274bce0a86eSWENTAO YANG cmn_err(CE_NOTE, "!vsw%d: Unable to process bandwidth" 2275bce0a86eSWENTAO YANG " update as the specified value:%ld is invalid\n", 2276bce0a86eSWENTAO YANG vswp->instance, maxbw); 2277bce0a86eSWENTAO YANG } 2278bce0a86eSWENTAO YANG } 2279bce0a86eSWENTAO YANG 22801107ea93SSriharsha Basavapatna /* 228134683adeSsg70180 * Now make any changes which are needed... 228234683adeSsg70180 */ 22831107ea93SSriharsha Basavapatna if (updated & MD_pls) { 22841107ea93SSriharsha Basavapatna 22851107ea93SSriharsha Basavapatna /* save the updated property. */ 22861107ea93SSriharsha Basavapatna vswp->pls_update = pls_update; 22871107ea93SSriharsha Basavapatna 22881107ea93SSriharsha Basavapatna if (pls_update == B_FALSE) { 22891107ea93SSriharsha Basavapatna /* 22901107ea93SSriharsha Basavapatna * Phys link state update is now disabled for this vsw 22911107ea93SSriharsha Basavapatna * interface. If we had previously reported a link-down 22921107ea93SSriharsha Basavapatna * to the stack, undo that by sending a link-up. 22931107ea93SSriharsha Basavapatna */ 22941107ea93SSriharsha Basavapatna if (vswp->phys_link_state == LINK_STATE_DOWN) { 22951107ea93SSriharsha Basavapatna vsw_mac_link_update(vswp, LINK_STATE_UP); 22961107ea93SSriharsha Basavapatna } 22971107ea93SSriharsha Basavapatna } else { 22981107ea93SSriharsha Basavapatna /* 22991107ea93SSriharsha Basavapatna * Phys link state update is now enabled. Send up an 23001107ea93SSriharsha Basavapatna * update based on the current phys link state. 23011107ea93SSriharsha Basavapatna */ 2302d8a518c8SSriharsha Basavapatna if (vswp->smode & VSW_LAYER2) { 2303d8a518c8SSriharsha Basavapatna vsw_mac_link_update(vswp, 2304d8a518c8SSriharsha Basavapatna vswp->phys_link_state); 2305d8a518c8SSriharsha Basavapatna } 23061107ea93SSriharsha Basavapatna } 23071107ea93SSriharsha Basavapatna 23081107ea93SSriharsha Basavapatna } 230934683adeSsg70180 2310da14cebeSEric Cheng if (updated & (MD_physname | MD_smode | MD_mtu)) { 231134683adeSsg70180 231234683adeSsg70180 /* 2313808f26a8SSriharsha Basavapatna * Stop any pending thread to setup switching mode. 231434683adeSsg70180 */ 2315808f26a8SSriharsha Basavapatna vsw_setup_switching_stop(vswp); 231619b65a69Ssb155480 2317678453a8Sspeer /* Cleanup HybridIO */ 2318678453a8Sspeer vsw_hio_cleanup(vswp); 2319678453a8Sspeer 232019b65a69Ssb155480 /* 232119b65a69Ssb155480 * Remove unicst, mcst addrs of vsw interface 2322da14cebeSEric Cheng * and ports from the physdev. This also closes 2323da14cebeSEric Cheng * the corresponding mac clients. 232419b65a69Ssb155480 */ 232519b65a69Ssb155480 vsw_unset_addrs(vswp); 232619b65a69Ssb155480 232719b65a69Ssb155480 /* 232819b65a69Ssb155480 * Stop, detach and close the old device.. 232919b65a69Ssb155480 */ 2330da14cebeSEric Cheng mutex_enter(&vswp->mac_lock); 233119b65a69Ssb155480 vsw_mac_close(vswp); 2332da14cebeSEric Cheng mutex_exit(&vswp->mac_lock); 233334683adeSsg70180 233434683adeSsg70180 /* 233534683adeSsg70180 * Update phys name. 233634683adeSsg70180 */ 233734683adeSsg70180 if (updated & MD_physname) { 233834683adeSsg70180 cmn_err(CE_NOTE, "!vsw%d: changing from %s to %s", 233934683adeSsg70180 vswp->instance, vswp->physname, physname); 234034683adeSsg70180 (void) strncpy(vswp->physname, 234134683adeSsg70180 physname, strlen(physname) + 1); 234234683adeSsg70180 } 234334683adeSsg70180 234434683adeSsg70180 /* 234534683adeSsg70180 * Update array with the new switch mode values. 234634683adeSsg70180 */ 234734683adeSsg70180 if (updated & MD_smode) { 2348da14cebeSEric Cheng vswp->smode = new_smode; 2349da14cebeSEric Cheng } 235034683adeSsg70180 2351da14cebeSEric Cheng /* Update mtu */ 2352da14cebeSEric Cheng if (updated & MD_mtu) { 2353da14cebeSEric Cheng rv = vsw_mtu_update(vswp, mtu); 2354da14cebeSEric Cheng if (rv != 0) { 2355da14cebeSEric Cheng goto fail_update; 2356da14cebeSEric Cheng } 235734683adeSsg70180 } 235834683adeSsg70180 235934683adeSsg70180 /* 236034683adeSsg70180 * ..and attach, start the new device. 236134683adeSsg70180 */ 236219b65a69Ssb155480 rv = vsw_setup_switching(vswp); 236319b65a69Ssb155480 if (rv == EAGAIN) { 236419b65a69Ssb155480 /* 236519b65a69Ssb155480 * Unable to setup switching mode. 2366808f26a8SSriharsha Basavapatna * As the error is EAGAIN, schedule a thread to retry 236719b65a69Ssb155480 * and return. Programming addresses of ports and 2368808f26a8SSriharsha Basavapatna * vsw interface will be done by the thread when the 2369808f26a8SSriharsha Basavapatna * switching setup completes successfully. 237019b65a69Ssb155480 */ 2371808f26a8SSriharsha Basavapatna if (vsw_setup_switching_start(vswp) != 0) { 2372808f26a8SSriharsha Basavapatna goto fail_update; 2373808f26a8SSriharsha Basavapatna } 237419b65a69Ssb155480 return; 237519b65a69Ssb155480 237619b65a69Ssb155480 } else if (rv) { 237734683adeSsg70180 goto fail_update; 237819b65a69Ssb155480 } 237934683adeSsg70180 2380d8a518c8SSriharsha Basavapatna vsw_setup_switching_post_process(vswp); 238119b65a69Ssb155480 } else if (updated & MD_macaddr) { 238219b65a69Ssb155480 /* 238319b65a69Ssb155480 * We enter here if only MD_macaddr is exclusively updated. 238419b65a69Ssb155480 * If MD_physname and/or MD_smode are also updated, then 238519b65a69Ssb155480 * as part of that, we would have implicitly processed 238619b65a69Ssb155480 * MD_macaddr update (above). 238719b65a69Ssb155480 */ 238834683adeSsg70180 cmn_err(CE_NOTE, "!vsw%d: changing mac address to 0x%lx", 238934683adeSsg70180 vswp->instance, macaddr); 239034683adeSsg70180 239119b65a69Ssb155480 READ_ENTER(&vswp->if_lockrw); 239219b65a69Ssb155480 if (vswp->if_state & VSW_IF_UP) { 2393da14cebeSEric Cheng /* reconfigure with new address */ 2394da14cebeSEric Cheng vsw_if_mac_reconfig(vswp, B_FALSE, 0, NULL, 0); 239534683adeSsg70180 23965f94e909Ssg70180 /* 239734683adeSsg70180 * Notify the MAC layer of the changed address. 239834683adeSsg70180 */ 239919b65a69Ssb155480 mac_unicst_update(vswp->if_mh, 240019b65a69Ssb155480 (uint8_t *)&vswp->if_addr); 240119b65a69Ssb155480 240219b65a69Ssb155480 } 240319b65a69Ssb155480 RW_EXIT(&vswp->if_lockrw); 240419b65a69Ssb155480 240534683adeSsg70180 } 240634683adeSsg70180 2407c1c61f44Ssb155480 if (updated & MD_vlans) { 2408c1c61f44Ssb155480 /* Remove existing vlan ids from the hash table. */ 2409c1c61f44Ssb155480 vsw_vlan_remove_ids(vswp, VSW_LOCALDEV); 2410c1c61f44Ssb155480 2411da14cebeSEric Cheng if (vswp->if_state & VSW_IF_UP) { 2412da14cebeSEric Cheng vsw_if_mac_reconfig(vswp, B_TRUE, pvid, vids, nvids); 2413da14cebeSEric Cheng } else { 2414c1c61f44Ssb155480 if (vswp->nvids != 0) { 2415da14cebeSEric Cheng kmem_free(vswp->vids, 2416da14cebeSEric Cheng sizeof (vsw_vlanid_t) * vswp->nvids); 2417c1c61f44Ssb155480 } 2418c1c61f44Ssb155480 vswp->vids = vids; 2419da14cebeSEric Cheng vswp->nvids = nvids; 2420da14cebeSEric Cheng vswp->pvid = pvid; 2421c1c61f44Ssb155480 } 2422c1c61f44Ssb155480 2423c1c61f44Ssb155480 /* add these new vlan ids into hash table */ 2424c1c61f44Ssb155480 vsw_vlan_add_ids(vswp, VSW_LOCALDEV); 2425c1c61f44Ssb155480 } else { 2426c1c61f44Ssb155480 if (nvids != 0) { 2427da14cebeSEric Cheng kmem_free(vids, sizeof (vsw_vlanid_t) * nvids); 2428c1c61f44Ssb155480 } 2429c1c61f44Ssb155480 } 2430c1c61f44Ssb155480 2431bce0a86eSWENTAO YANG if (updated & MD_bw) { 2432bce0a86eSWENTAO YANG vsw_update_bandwidth(vswp, NULL, VSW_LOCALDEV, maxbw); 2433bce0a86eSWENTAO YANG } 2434bce0a86eSWENTAO YANG 243534683adeSsg70180 return; 243634683adeSsg70180 243734683adeSsg70180 fail_reconf: 243834683adeSsg70180 cmn_err(CE_WARN, "!vsw%d: configuration unchanged", vswp->instance); 243934683adeSsg70180 return; 244034683adeSsg70180 244134683adeSsg70180 fail_update: 24421ef0bbb5Snarayan cmn_err(CE_WARN, "!vsw%d: re-configuration failed", 244334683adeSsg70180 vswp->instance); 244434683adeSsg70180 } 244534683adeSsg70180 244634683adeSsg70180 /* 2447c1c61f44Ssb155480 * Read the port's md properties. 24481ae08745Sheppo */ 2449c1c61f44Ssb155480 static int 2450c1c61f44Ssb155480 vsw_port_read_props(vsw_port_t *portp, vsw_t *vswp, 2451c1c61f44Ssb155480 md_t *mdp, mde_cookie_t *node) 24521ae08745Sheppo { 24531ae08745Sheppo uint64_t ldc_id; 24541ae08745Sheppo uint8_t *addrp; 24551ae08745Sheppo int i, addrsz; 24561ae08745Sheppo int num_nodes = 0, nchan = 0; 24571ae08745Sheppo int listsz = 0; 24581ae08745Sheppo mde_cookie_t *listp = NULL; 24591ae08745Sheppo struct ether_addr ea; 24601ae08745Sheppo uint64_t macaddr; 24611ae08745Sheppo uint64_t inst = 0; 2462678453a8Sspeer uint64_t val; 24631ae08745Sheppo 24641ae08745Sheppo if (md_get_prop_val(mdp, *node, id_propname, &inst)) { 24651ae08745Sheppo DWARN(vswp, "%s: prop(%s) not found", __func__, 24661ae08745Sheppo id_propname); 24671ae08745Sheppo return (1); 24681ae08745Sheppo } 24691ae08745Sheppo 24701ae08745Sheppo /* 24711ae08745Sheppo * Find the channel endpoint node(s) (which should be under this 24721ae08745Sheppo * port node) which contain the channel id(s). 24731ae08745Sheppo */ 24741ae08745Sheppo if ((num_nodes = md_node_count(mdp)) <= 0) { 24751ae08745Sheppo DERR(vswp, "%s: invalid number of nodes found (%d)", 24761ae08745Sheppo __func__, num_nodes); 24771ae08745Sheppo return (1); 24781ae08745Sheppo } 24791ae08745Sheppo 248034683adeSsg70180 D2(vswp, "%s: %d nodes found", __func__, num_nodes); 248134683adeSsg70180 24821ae08745Sheppo /* allocate enough space for node list */ 24831ae08745Sheppo listsz = num_nodes * sizeof (mde_cookie_t); 24841ae08745Sheppo listp = kmem_zalloc(listsz, KM_SLEEP); 24851ae08745Sheppo 2486205eeb1aSlm66018 nchan = md_scan_dag(mdp, *node, md_find_name(mdp, chan_propname), 24871ae08745Sheppo md_find_name(mdp, "fwd"), listp); 24881ae08745Sheppo 24891ae08745Sheppo if (nchan <= 0) { 24901ae08745Sheppo DWARN(vswp, "%s: no %s nodes found", __func__, chan_propname); 24911ae08745Sheppo kmem_free(listp, listsz); 24921ae08745Sheppo return (1); 24931ae08745Sheppo } 24941ae08745Sheppo 24951ae08745Sheppo D2(vswp, "%s: %d %s nodes found", __func__, nchan, chan_propname); 24961ae08745Sheppo 24971ae08745Sheppo /* use property from first node found */ 24981ae08745Sheppo if (md_get_prop_val(mdp, listp[0], id_propname, &ldc_id)) { 24991ae08745Sheppo DWARN(vswp, "%s: prop(%s) not found\n", __func__, 25001ae08745Sheppo id_propname); 25011ae08745Sheppo kmem_free(listp, listsz); 25021ae08745Sheppo return (1); 25031ae08745Sheppo } 25041ae08745Sheppo 25051ae08745Sheppo /* don't need list any more */ 25061ae08745Sheppo kmem_free(listp, listsz); 25071ae08745Sheppo 25081ae08745Sheppo D2(vswp, "%s: ldc_id 0x%llx", __func__, ldc_id); 25091ae08745Sheppo 25101ae08745Sheppo /* read mac-address property */ 25111ae08745Sheppo if (md_get_prop_data(mdp, *node, remaddr_propname, 25121ae08745Sheppo &addrp, &addrsz)) { 25131ae08745Sheppo DWARN(vswp, "%s: prop(%s) not found", 25141ae08745Sheppo __func__, remaddr_propname); 25151ae08745Sheppo return (1); 25161ae08745Sheppo } 25171ae08745Sheppo 25181ae08745Sheppo if (addrsz < ETHERADDRL) { 25191ae08745Sheppo DWARN(vswp, "%s: invalid address size", __func__); 25201ae08745Sheppo return (1); 25211ae08745Sheppo } 25221ae08745Sheppo 25231ae08745Sheppo macaddr = *((uint64_t *)addrp); 25241ae08745Sheppo D2(vswp, "%s: remote mac address 0x%llx", __func__, macaddr); 25251ae08745Sheppo 25261ae08745Sheppo for (i = ETHERADDRL - 1; i >= 0; i--) { 25271ae08745Sheppo ea.ether_addr_octet[i] = macaddr & 0xFF; 25281ae08745Sheppo macaddr >>= 8; 25291ae08745Sheppo } 25301ae08745Sheppo 2531c1c61f44Ssb155480 /* now update all properties into the port */ 2532c1c61f44Ssb155480 portp->p_vswp = vswp; 2533c1c61f44Ssb155480 portp->p_instance = inst; 2534da14cebeSEric Cheng portp->addr_set = B_FALSE; 2535c1c61f44Ssb155480 ether_copy(&ea, &portp->p_macaddr); 2536c1c61f44Ssb155480 if (nchan > VSW_PORT_MAX_LDCS) { 2537c1c61f44Ssb155480 D2(vswp, "%s: using first of %d ldc ids", 2538c1c61f44Ssb155480 __func__, nchan); 2539c1c61f44Ssb155480 nchan = VSW_PORT_MAX_LDCS; 2540c1c61f44Ssb155480 } 2541c1c61f44Ssb155480 portp->num_ldcs = nchan; 2542c1c61f44Ssb155480 portp->ldc_ids = 2543c1c61f44Ssb155480 kmem_zalloc(sizeof (uint64_t) * nchan, KM_SLEEP); 2544c1c61f44Ssb155480 bcopy(&ldc_id, (portp->ldc_ids), sizeof (uint64_t) * nchan); 2545c1c61f44Ssb155480 2546c1c61f44Ssb155480 /* read vlan id properties of this port node */ 2547c1c61f44Ssb155480 vsw_vlan_read_ids(portp, VSW_VNETPORT, mdp, *node, &portp->pvid, 2548c1c61f44Ssb155480 &portp->vids, &portp->nvids, NULL); 2549c1c61f44Ssb155480 2550678453a8Sspeer /* Check if hybrid property is present */ 2551678453a8Sspeer if (md_get_prop_val(mdp, *node, hybrid_propname, &val) == 0) { 2552678453a8Sspeer D1(vswp, "%s: prop(%s) found\n", __func__, hybrid_propname); 2553678453a8Sspeer portp->p_hio_enabled = B_TRUE; 2554678453a8Sspeer } else { 2555678453a8Sspeer portp->p_hio_enabled = B_FALSE; 2556678453a8Sspeer } 2557678453a8Sspeer /* 2558678453a8Sspeer * Port hio capability determined after version 2559678453a8Sspeer * negotiation, i.e., when we know the peer is HybridIO capable. 2560678453a8Sspeer */ 2561678453a8Sspeer portp->p_hio_capable = B_FALSE; 2562bce0a86eSWENTAO YANG 2563bce0a86eSWENTAO YANG /* Read bandwidth of this port */ 2564bce0a86eSWENTAO YANG vsw_port_read_bandwidth(portp, mdp, *node, &portp->p_bandwidth); 2565bce0a86eSWENTAO YANG 2566c1c61f44Ssb155480 return (0); 2567c1c61f44Ssb155480 } 2568c1c61f44Ssb155480 2569c1c61f44Ssb155480 /* 2570c1c61f44Ssb155480 * Add a new port to the system. 2571c1c61f44Ssb155480 * 2572c1c61f44Ssb155480 * Returns 0 on success, 1 on failure. 2573c1c61f44Ssb155480 */ 2574c1c61f44Ssb155480 int 2575c1c61f44Ssb155480 vsw_port_add(vsw_t *vswp, md_t *mdp, mde_cookie_t *node) 2576c1c61f44Ssb155480 { 2577c1c61f44Ssb155480 vsw_port_t *portp; 2578c1c61f44Ssb155480 int rv; 2579c1c61f44Ssb155480 2580c1c61f44Ssb155480 portp = kmem_zalloc(sizeof (vsw_port_t), KM_SLEEP); 2581c1c61f44Ssb155480 2582c1c61f44Ssb155480 rv = vsw_port_read_props(portp, vswp, mdp, node); 2583c1c61f44Ssb155480 if (rv != 0) { 2584c1c61f44Ssb155480 kmem_free(portp, sizeof (*portp)); 2585c1c61f44Ssb155480 return (1); 2586c1c61f44Ssb155480 } 2587c1c61f44Ssb155480 2588c1c61f44Ssb155480 rv = vsw_port_attach(portp); 2589c1c61f44Ssb155480 if (rv != 0) { 25901ae08745Sheppo DERR(vswp, "%s: failed to attach port", __func__); 25911ae08745Sheppo return (1); 25921ae08745Sheppo } 25931ae08745Sheppo 2594c1c61f44Ssb155480 return (0); 2595c1c61f44Ssb155480 } 25961ae08745Sheppo 2597c1c61f44Ssb155480 static int 2598c1c61f44Ssb155480 vsw_port_update(vsw_t *vswp, md_t *curr_mdp, mde_cookie_t curr_mdex, 2599c1c61f44Ssb155480 md_t *prev_mdp, mde_cookie_t prev_mdex) 2600c1c61f44Ssb155480 { 2601c1c61f44Ssb155480 uint64_t cport_num; 2602c1c61f44Ssb155480 uint64_t pport_num; 2603c1c61f44Ssb155480 vsw_port_list_t *plistp; 2604c1c61f44Ssb155480 vsw_port_t *portp; 2605c1c61f44Ssb155480 uint16_t pvid; 2606da14cebeSEric Cheng vsw_vlanid_t *vids; 2607c1c61f44Ssb155480 uint16_t nvids; 2608678453a8Sspeer uint64_t val; 2609678453a8Sspeer boolean_t hio_enabled = B_FALSE; 2610bce0a86eSWENTAO YANG uint64_t maxbw; 2611bce0a86eSWENTAO YANG enum {P_MD_init = 0x1, 2612bce0a86eSWENTAO YANG P_MD_vlans = 0x2, 2613bce0a86eSWENTAO YANG P_MD_hio = 0x4, 2614bce0a86eSWENTAO YANG P_MD_maxbw = 0x8} updated; 2615bce0a86eSWENTAO YANG 2616bce0a86eSWENTAO YANG updated = P_MD_init; 2617c1c61f44Ssb155480 2618c1c61f44Ssb155480 /* 2619c1c61f44Ssb155480 * For now, we get port updates only if vlan ids changed. 2620c1c61f44Ssb155480 * We read the port num and do some sanity check. 2621c1c61f44Ssb155480 */ 2622c1c61f44Ssb155480 if (md_get_prop_val(curr_mdp, curr_mdex, id_propname, &cport_num)) { 2623c1c61f44Ssb155480 return (1); 2624c1c61f44Ssb155480 } 2625c1c61f44Ssb155480 2626c1c61f44Ssb155480 if (md_get_prop_val(prev_mdp, prev_mdex, id_propname, &pport_num)) { 2627c1c61f44Ssb155480 return (1); 2628c1c61f44Ssb155480 } 2629c1c61f44Ssb155480 if (cport_num != pport_num) 2630c1c61f44Ssb155480 return (1); 2631c1c61f44Ssb155480 2632c1c61f44Ssb155480 plistp = &(vswp->plist); 2633c1c61f44Ssb155480 2634c1c61f44Ssb155480 READ_ENTER(&plistp->lockrw); 2635c1c61f44Ssb155480 2636c1c61f44Ssb155480 portp = vsw_lookup_port(vswp, cport_num); 2637c1c61f44Ssb155480 if (portp == NULL) { 2638c1c61f44Ssb155480 RW_EXIT(&plistp->lockrw); 2639c1c61f44Ssb155480 return (1); 2640c1c61f44Ssb155480 } 2641c1c61f44Ssb155480 2642c1c61f44Ssb155480 /* Read the vlan ids */ 2643c1c61f44Ssb155480 vsw_vlan_read_ids(portp, VSW_VNETPORT, curr_mdp, curr_mdex, &pvid, 2644c1c61f44Ssb155480 &vids, &nvids, NULL); 2645c1c61f44Ssb155480 2646c1c61f44Ssb155480 /* Determine if there are any vlan id updates */ 2647c1c61f44Ssb155480 if ((pvid != portp->pvid) || /* pvid changed? */ 2648c1c61f44Ssb155480 (nvids != portp->nvids) || /* # of vids changed? */ 2649c1c61f44Ssb155480 ((nvids != 0) && (portp->nvids != 0) && /* vids changed? */ 2650da14cebeSEric Cheng !vsw_cmp_vids(vids, portp->vids, nvids))) { 2651bce0a86eSWENTAO YANG updated |= P_MD_vlans; 2652c1c61f44Ssb155480 } 2653c1c61f44Ssb155480 2654bce0a86eSWENTAO YANG /* Check if hybrid property is present */ 2655bce0a86eSWENTAO YANG if (md_get_prop_val(curr_mdp, curr_mdex, hybrid_propname, &val) == 0) { 2656bce0a86eSWENTAO YANG D1(vswp, "%s: prop(%s) found\n", __func__, hybrid_propname); 2657bce0a86eSWENTAO YANG hio_enabled = B_TRUE; 2658bce0a86eSWENTAO YANG } 2659c1c61f44Ssb155480 2660bce0a86eSWENTAO YANG if (portp->p_hio_enabled != hio_enabled) { 2661bce0a86eSWENTAO YANG updated |= P_MD_hio; 2662bce0a86eSWENTAO YANG } 2663bce0a86eSWENTAO YANG 2664bce0a86eSWENTAO YANG /* Check if maxbw property is present */ 2665bce0a86eSWENTAO YANG vsw_port_read_bandwidth(portp, curr_mdp, curr_mdex, &maxbw); 2666bce0a86eSWENTAO YANG if (maxbw != portp->p_bandwidth) { 2667bce0a86eSWENTAO YANG if (maxbw >= MRP_MAXBW_MINVAL || maxbw == 0) { 2668bce0a86eSWENTAO YANG updated |= P_MD_maxbw; 2669bce0a86eSWENTAO YANG } else { 2670bce0a86eSWENTAO YANG cmn_err(CE_NOTE, "!vsw%d: Unable to process bandwidth" 2671bce0a86eSWENTAO YANG " update for port %d as the specified value:%ld" 2672bce0a86eSWENTAO YANG " is invalid\n", 2673bce0a86eSWENTAO YANG vswp->instance, portp->p_instance, maxbw); 2674bce0a86eSWENTAO YANG } 2675bce0a86eSWENTAO YANG } 2676bce0a86eSWENTAO YANG 2677bce0a86eSWENTAO YANG if (updated & P_MD_vlans) { 2678c1c61f44Ssb155480 /* Remove existing vlan ids from the hash table. */ 2679c1c61f44Ssb155480 vsw_vlan_remove_ids(portp, VSW_VNETPORT); 2680c1c61f44Ssb155480 2681da14cebeSEric Cheng /* Reconfigure vlans with network device */ 2682da14cebeSEric Cheng vsw_mac_port_reconfig_vlans(portp, pvid, vids, nvids); 2683c1c61f44Ssb155480 2684c1c61f44Ssb155480 /* add these new vlan ids into hash table */ 2685c1c61f44Ssb155480 vsw_vlan_add_ids(portp, VSW_VNETPORT); 2686c1c61f44Ssb155480 2687c1c61f44Ssb155480 /* reset the port if it is vlan unaware (ver < 1.3) */ 2688c1c61f44Ssb155480 vsw_vlan_unaware_port_reset(portp); 2689678453a8Sspeer } 2690678453a8Sspeer 2691bce0a86eSWENTAO YANG if (updated & P_MD_hio) { 2692bce0a86eSWENTAO YANG vsw_hio_port_update(portp, hio_enabled); 2693678453a8Sspeer } 2694678453a8Sspeer 2695bce0a86eSWENTAO YANG if (updated & P_MD_maxbw) { 2696bce0a86eSWENTAO YANG vsw_update_bandwidth(NULL, portp, VSW_VNETPORT, maxbw); 2697678453a8Sspeer } 2698c1c61f44Ssb155480 2699c1c61f44Ssb155480 RW_EXIT(&plistp->lockrw); 27001ae08745Sheppo 27011ae08745Sheppo return (0); 27021ae08745Sheppo } 27031ae08745Sheppo 27041ae08745Sheppo /* 270506db247cSraghuram * vsw_mac_rx -- A common function to send packets to the interface. 270606db247cSraghuram * By default this function check if the interface is UP or not, the 270706db247cSraghuram * rest of the behaviour depends on the flags as below: 27081ae08745Sheppo * 270906db247cSraghuram * VSW_MACRX_PROMISC -- Check if the promisc mode set or not. 271006db247cSraghuram * VSW_MACRX_COPYMSG -- Make a copy of the message(s). 271106db247cSraghuram * VSW_MACRX_FREEMSG -- Free if the messages cannot be sent up the stack. 27121ae08745Sheppo */ 27131ae08745Sheppo void 2714f0ca1d9aSsb155480 vsw_mac_rx(vsw_t *vswp, mac_resource_handle_t mrh, 2715f0ca1d9aSsb155480 mblk_t *mp, vsw_macrx_flags_t flags) 27161ae08745Sheppo { 2717c1c61f44Ssb155480 mblk_t *mpt; 2718c1c61f44Ssb155480 271906db247cSraghuram D1(vswp, "%s:enter\n", __func__); 27201ae08745Sheppo READ_ENTER(&vswp->if_lockrw); 272106db247cSraghuram /* Check if the interface is up */ 272206db247cSraghuram if (!(vswp->if_state & VSW_IF_UP)) { 27231ae08745Sheppo RW_EXIT(&vswp->if_lockrw); 272406db247cSraghuram /* Free messages only if FREEMSG flag specified */ 272506db247cSraghuram if (flags & VSW_MACRX_FREEMSG) { 272606db247cSraghuram freemsgchain(mp); 272706db247cSraghuram } 272806db247cSraghuram D1(vswp, "%s:exit\n", __func__); 272906db247cSraghuram return; 273006db247cSraghuram } 273106db247cSraghuram /* 273206db247cSraghuram * If PROMISC flag is passed, then check if 273306db247cSraghuram * the interface is in the PROMISC mode. 273406db247cSraghuram * If not, drop the messages. 273506db247cSraghuram */ 273606db247cSraghuram if (flags & VSW_MACRX_PROMISC) { 273706db247cSraghuram if (!(vswp->if_state & VSW_IF_PROMISC)) { 273806db247cSraghuram RW_EXIT(&vswp->if_lockrw); 273906db247cSraghuram /* Free messages only if FREEMSG flag specified */ 274006db247cSraghuram if (flags & VSW_MACRX_FREEMSG) { 274106db247cSraghuram freemsgchain(mp); 274206db247cSraghuram } 274306db247cSraghuram D1(vswp, "%s:exit\n", __func__); 274406db247cSraghuram return; 274506db247cSraghuram } 274606db247cSraghuram } 274706db247cSraghuram RW_EXIT(&vswp->if_lockrw); 274806db247cSraghuram /* 274906db247cSraghuram * If COPYMSG flag is passed, then make a copy 275006db247cSraghuram * of the message chain and send up the copy. 275106db247cSraghuram */ 275206db247cSraghuram if (flags & VSW_MACRX_COPYMSG) { 275306db247cSraghuram mp = copymsgchain(mp); 2754f0ca1d9aSsb155480 if (mp == NULL) { 275506db247cSraghuram D1(vswp, "%s:exit\n", __func__); 275606db247cSraghuram return; 275706db247cSraghuram } 275806db247cSraghuram } 275906db247cSraghuram 2760f0ca1d9aSsb155480 D2(vswp, "%s: sending up stack", __func__); 2761c1c61f44Ssb155480 2762c1c61f44Ssb155480 mpt = NULL; 2763c1c61f44Ssb155480 (void) vsw_vlan_frame_untag(vswp, VSW_LOCALDEV, &mp, &mpt); 2764c1c61f44Ssb155480 if (mp != NULL) { 2765ba2e4443Sseb mac_rx(vswp->if_mh, mrh, mp); 2766c1c61f44Ssb155480 } 276706db247cSraghuram D1(vswp, "%s:exit\n", __func__); 27681ae08745Sheppo } 27691ae08745Sheppo 277006db247cSraghuram /* copy mac address of vsw into soft state structure */ 27711ae08745Sheppo static void 277206db247cSraghuram vsw_save_lmacaddr(vsw_t *vswp, uint64_t macaddr) 27731ae08745Sheppo { 27741ae08745Sheppo int i; 27751ae08745Sheppo 277606db247cSraghuram WRITE_ENTER(&vswp->if_lockrw); 277706db247cSraghuram for (i = ETHERADDRL - 1; i >= 0; i--) { 277806db247cSraghuram vswp->if_addr.ether_addr_octet[i] = macaddr & 0xFF; 277906db247cSraghuram macaddr >>= 8; 27801ae08745Sheppo } 278106db247cSraghuram RW_EXIT(&vswp->if_lockrw); 27821ae08745Sheppo } 2783da14cebeSEric Cheng 2784da14cebeSEric Cheng /* Compare VLAN ids, array size expected to be same. */ 2785da14cebeSEric Cheng static boolean_t 2786da14cebeSEric Cheng vsw_cmp_vids(vsw_vlanid_t *vids1, vsw_vlanid_t *vids2, int nvids) 2787da14cebeSEric Cheng { 2788da14cebeSEric Cheng int i, j; 2789da14cebeSEric Cheng uint16_t vid; 2790da14cebeSEric Cheng 2791da14cebeSEric Cheng for (i = 0; i < nvids; i++) { 2792da14cebeSEric Cheng vid = vids1[i].vl_vid; 2793da14cebeSEric Cheng for (j = 0; j < nvids; j++) { 2794da14cebeSEric Cheng if (vid == vids2[i].vl_vid) 2795da14cebeSEric Cheng break; 2796da14cebeSEric Cheng } 2797da14cebeSEric Cheng if (j == nvids) { 2798da14cebeSEric Cheng return (B_FALSE); 2799da14cebeSEric Cheng } 2800da14cebeSEric Cheng } 2801da14cebeSEric Cheng return (B_TRUE); 2802da14cebeSEric Cheng } 2803