1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER START
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The contents of this file are subject to the terms of the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Common Development and Distribution License (the "License").
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You may not use this file except in compliance with the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * See the License for the specific language governing permissions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * and limitations under the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * When distributing Covered Code, include this CDDL HEADER in each
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * If applicable, add the following below this CDDL HEADER, with the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * fields enclosed by brackets "[]" replaced with your own identifying
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * information: Portions Copyright [yyyy] [name of copyright owner]
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER END
a862df29af145cac620492c4ebe1f42c1906c66eSriharsha Basavapatna * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Function prototypes.
34683adecebe88ca2c857e28be4749f3a083f9fcsgstatic int vsw_get_md_physname(vsw_t *, md_t *, mde_cookie_t, char *);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic int vsw_get_md_smodes(vsw_t *, md_t *, mde_cookie_t, uint8_t *);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* MDEG routines */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int vsw_mdeg_cb(void *cb_argp, mdeg_result_t *);
34683adecebe88ca2c857e28be4749f3a083f9fcsgstatic int vsw_port_mdeg_cb(void *cb_argp, mdeg_result_t *);
19b65a69adc64b3289ccb2fc32b805782e3f4540sbstatic int vsw_get_initial_md_properties(vsw_t *vswp, md_t *, mde_cookie_t);
c1c61f44e88f4c8c155272ee56d868043146096asbstatic void vsw_vlan_read_ids(void *arg, int type, md_t *mdp,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mde_cookie_t node, uint16_t *pvidp, vsw_vlanid_t **vidspp,
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANGstatic void vsw_port_read_bandwidth(vsw_port_t *portp, md_t *mdp,
c1c61f44e88f4c8c155272ee56d868043146096asbstatic int vsw_port_read_props(vsw_port_t *portp, vsw_t *vswp,
f0ca1d9a12d54d304791bc74525e2010ca924726sbstatic void vsw_read_pri_eth_types(vsw_t *vswp, md_t *mdp,
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatnastatic void vsw_mtu_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node,
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatnastatic int vsw_mtu_update(vsw_t *vswp, uint32_t mtu);
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatnastatic void vsw_linkprop_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node,
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANGstatic void vsw_bandwidth_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node,
34683adecebe88ca2c857e28be4749f3a083f9fcsgstatic void vsw_update_md_prop(vsw_t *, md_t *, mde_cookie_t);
06db247c678f0e3956535e8a6dec31d6c2108827raghuramstatic void vsw_save_lmacaddr(vsw_t *vswp, uint64_t macaddr);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic boolean_t vsw_cmp_vids(vsw_vlanid_t *vids1,
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* Mac driver related routines */
06db247c678f0e3956535e8a6dec31d6c2108827raghuramstatic int vsw_m_unicst(void *arg, const uint8_t *);
06db247c678f0e3956535e8a6dec31d6c2108827raghuramstatic int vsw_m_multicst(void *arg, boolean_t, const uint8_t *);
d8a518c84b0b033745c344594c3478e1294f3a9aSriharsha Basavapatnavoid vsw_mac_link_update(vsw_t *vswp, link_state_t link_state);
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatnavoid vsw_physlink_state_update(vsw_t *vswp);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Functions imported from other files.
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatnaextern void vsw_setup_switching_thread(void *arg);
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatnaextern int vsw_setup_switching_start(vsw_t *vswp);
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatnaextern void vsw_setup_switching_stop(vsw_t *vswp);
7a327842c3ad1ec3b602c454b218df4ebbc716fbwentaoyextern void vsw_switch_frame_nop(vsw_t *vswp, mblk_t *mp, int caller,
06db247c678f0e3956535e8a6dec31d6c2108827raghuramextern int vsw_add_mcst(vsw_t *, uint8_t, uint64_t, void *);
06db247c678f0e3956535e8a6dec31d6c2108827raghuramextern int vsw_del_mcst(vsw_t *, uint8_t, uint64_t, void *);
06db247c678f0e3956535e8a6dec31d6c2108827raghuramextern mcst_addr_t *vsw_del_addr(uint8_t devtype, void *arg, uint64_t addr);
06db247c678f0e3956535e8a6dec31d6c2108827raghuramextern int vsw_port_add(vsw_t *vswp, md_t *mdp, mde_cookie_t *node);
06db247c678f0e3956535e8a6dec31d6c2108827raghuramextern int vsw_port_detach(vsw_t *vswp, int p_instance);
c1c61f44e88f4c8c155272ee56d868043146096asbstatic int vsw_port_update(vsw_t *vswp, md_t *curr_mdp, mde_cookie_t curr_mdex,
06db247c678f0e3956535e8a6dec31d6c2108827raghuramextern vsw_port_t *vsw_lookup_port(vsw_t *vswp, int p_instance);
d8a518c84b0b033745c344594c3478e1294f3a9aSriharsha Basavapatnaextern void vsw_setup_switching_post_process(vsw_t *vswp);
c1c61f44e88f4c8c155272ee56d868043146096asbextern void vsw_vlan_unaware_port_reset(vsw_port_t *portp);
c1c61f44e88f4c8c155272ee56d868043146096asbextern uint32_t vsw_vlan_frame_untag(void *arg, int type, mblk_t **np,
c1c61f44e88f4c8c155272ee56d868043146096asbextern mblk_t *vsw_vlan_frame_pretag(void *arg, int type, mblk_t *mp);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern void vsw_hio_port_update(vsw_port_t *portp, boolean_t hio_enabled);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern int vsw_mac_multicast_add(vsw_t *, vsw_port_t *, mcst_addr_t *, int);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern void vsw_mac_multicast_remove(vsw_t *, vsw_port_t *, mcst_addr_t *, int);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern void vsw_mac_port_reconfig_vlans(vsw_port_t *portp, uint16_t new_pvid,
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern int vsw_mac_client_init(vsw_t *vswp, vsw_port_t *port, int type);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern void vsw_mac_client_cleanup(vsw_t *vswp, vsw_port_t *port, int type);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern void vsw_if_mac_reconfig(vsw_t *vswp, boolean_t update_vlans,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint16_t new_pvid, vsw_vlanid_t *new_vids, int new_nvids);
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatnaextern void vsw_reset_ports(vsw_t *vswp);
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatnaextern void vsw_port_reset(vsw_port_t *portp);
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatnaextern void vsw_physlink_update_ports(vsw_t *vswp);
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANGextern void vsw_update_bandwidth(vsw_t *vswp, vsw_port_t *port, int type,
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Internal tunables.
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsbint vsw_num_handshakes = VNET_NUM_HANDSHAKES; /* # of handshake attempts */
19b65a69adc64b3289ccb2fc32b805782e3f4540sbint vsw_setup_switching_delay = 3; /* setup sw timeout interval in sec */
0e8b4070e8262256f51dbb1aae9d22fa2f1366fcsbint vsw_mac_open_retries = 300; /* max # of mac_open() retries */
0e8b4070e8262256f51dbb1aae9d22fa2f1366fcsb /* 300*3 = 900sec(15min) of max tmout */
06db247c678f0e3956535e8a6dec31d6c2108827raghuramint vsw_ldc_tx_delay = 5; /* delay(ticks) for tx retries */
06db247c678f0e3956535e8a6dec31d6c2108827raghuramint vsw_ldc_tx_retries = 10; /* # of ldc tx retries */
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANGint vsw_ldc_retries = 5; /* # of ldc_close() retries */
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANGint vsw_ldc_delay = 1000; /* 1 ms delay for ldc_close() */
06db247c678f0e3956535e8a6dec31d6c2108827raghuramboolean_t vsw_ldc_rxthr_enabled = B_TRUE; /* LDC Rx thread enabled */
06db247c678f0e3956535e8a6dec31d6c2108827raghuramboolean_t vsw_ldc_txthr_enabled = B_TRUE; /* LDC Tx thread enabled */
34b64c01c6a2242177691e1420a386e2789f79dcWENTAO YANGint vsw_rxpool_cleanup_delay = 100000; /* 100ms */
c1c61f44e88f4c8c155272ee56d868043146096asbuint32_t vsw_fdb_nchains = 8; /* # of chains in fdb hash table */
c1c61f44e88f4c8c155272ee56d868043146096asbuint32_t vsw_vlan_nchains = 4; /* # of chains in vlan id hash table */
c1c61f44e88f4c8c155272ee56d868043146096asb/* delay in usec to wait for all references on a fdb entry to be dropped */
c1c61f44e88f4c8c155272ee56d868043146096asb * Default vlan id. This is only used internally when the "default-vlan-id"
c1c61f44e88f4c8c155272ee56d868043146096asb * property is not present in the MD device node. Therefore, this should not be
c1c61f44e88f4c8c155272ee56d868043146096asb * used as a tunable; if this value is changed, the corresponding variable
c1c61f44e88f4c8c155272ee56d868043146096asb * should be updated to the same value in all vnets connected to this vsw.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * Workaround for a version handshake bug in obp's vnet.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * If vsw initiates version negotiation starting from the highest version,
f0ca1d9a12d54d304791bc74525e2010ca924726sb * obp sends a nack and terminates version handshake. To workaround
f0ca1d9a12d54d304791bc74525e2010ca924726sb * this, we do not initiate version handshake when the channel comes up.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * Instead, we wait for the peer to send its version info msg and go through
f0ca1d9a12d54d304791bc74525e2010ca924726sb * the version protocol exchange. If we successfully negotiate a version,
f0ca1d9a12d54d304791bc74525e2010ca924726sb * before sending the ack, we send our version info msg to the peer
f0ca1d9a12d54d304791bc74525e2010ca924726sb * using the <major,minor> version that we are about to ack.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * In the absence of "priority-ether-types" property in MD, the following
f0ca1d9a12d54d304791bc74525e2010ca924726sb * internal tunable can be set to specify a single priority ethertype.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * Number of transmit priority buffers that are preallocated per device.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * This number is chosen to be a small value to throttle transmission
f0ca1d9a12d54d304791bc74525e2010ca924726sb * of priority packets. Note: Must be a power of 2 for vio_create_mblks().
51aa9d07dcd9c8ed955768d19058f8c15460fd7csb * Number of RARP packets sent to announce macaddr to the physical switch,
51aa9d07dcd9c8ed955768d19058f8c15460fd7csb * after vsw's physical device is changed dynamically or after a guest (client
51aa9d07dcd9c8ed955768d19058f8c15460fd7csb * vnet) is live migrated in.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * Max retries for HybridIO cleanup
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * 10ms delay for HybridIO cleanup
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * Descriptor ring modes of LDC data transfer:
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * 1) TxDring mode:
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * In versions < v1.6 of VIO Protocol, we support only TxDring mode. In this
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * mode, we create a transmit descriptor ring and export it to the peer through
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * dring registration process of handshake. The descriptor ring is exported
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * using LDC shared memory. Each descriptor is associated with a data buffer.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * The data buffer is also exported over LDC and the cookies for this data
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * buffer are provided in the descriptor. The peer maps this ring as its
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * receive ring. Similarly, the peer exports a transmit descriptor ring which
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * is mapped by this device as its receive ring. In this mode, in a given data
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * transfer direction, the transmitter copies the data to the exported data
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * buffer (owned by itself), bound to the descriptor. The receiver uses the LDC
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * cookies specified in the descriptor to copy the data into the receiving
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * guest through the hypervisor (ldc_mem_copy()).
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * 2) RxDringData mode:
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * In versions >= v1.6 of VIO Protocol, we also support RxDringData mode. In
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * this mode, we create a receive descriptor ring and export it to the peer
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * through dring registration process of handshake. In addition, we export a
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * receive buffer area and provide that information also in the dring
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * registration message. The descriptor ring and the data buffer area are
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * exported using LDC shared memory. Each descriptor is associated with a data
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * buffer in the data buffer area and the offset of the specific data buffer
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * within this area is specified in the descriptor. The peer maps this ring
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * along with the data buffer area as its transmit ring. Similarly, the peer
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * exports a receive ring which is mapped by this device as its transmit ring,
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * along with its buffer area. In this mode, in a given data transfer
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * direction, the transmitter copies the data to the data buffer offset
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * specified in the descriptor. The receiver simply picks up the data buffer
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * (owned by itself) without any copy operation into the receiving guest.
34f94fbc7a730740933e4776ade5f74009afe4ceWENTAO YANG * We enable RxDringData mode during handshake negotiations if LDC supports
34f94fbc7a730740933e4776ade5f74009afe4ceWENTAO YANG * mapping in large areas of shared memory(see ldc_is_viotsb_configured() API),
34f94fbc7a730740933e4776ade5f74009afe4ceWENTAO YANG * which is required to support RxDringData mode.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * Number of descriptors; must be power of 2.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatnauint32_t vsw_num_descriptors = VSW_NUM_DESCRIPTORS;
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * In RxDringData mode, # of buffers is determined by multiplying the # of
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * descriptors with the factor below. Note that the factor must be > 1; i.e,
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * the # of buffers must always be > # of descriptors. This is needed because,
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * while the shared memory buffers are sent up the stack on the receiver, the
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * sender needs additional buffers that can be used for further transmits.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * See vsw_setup_rx_dring() for details.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * Delay when rx descr not ready; used in both dring modes.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * Retry when rx descr not ready; used in both dring modes.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Max number of mblks received in one receive operation.
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * Internal tunables for receive buffer pools, that is, the size and number of
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * mblks for each pool. At least 3 sizes must be specified if these are used.
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * The sizes must be specified in increasing order. Non-zero value of the first
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * size will be used as a hint to use these values instead of the algorithm
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * that determines the sizes based on MTU. Used in TxDring mode only.
06db247c678f0e3956535e8a6dec31d6c2108827raghuramuint32_t vsw_num_mblks1 = VSW_NUM_MBLKS; /* number of mblks for pool1 */
06db247c678f0e3956535e8a6dec31d6c2108827raghuramuint32_t vsw_num_mblks2 = VSW_NUM_MBLKS; /* number of mblks for pool2 */
06db247c678f0e3956535e8a6dec31d6c2108827raghuramuint32_t vsw_num_mblks3 = VSW_NUM_MBLKS; /* number of mblks for pool3 */
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatnauint32_t vsw_num_mblks4 = VSW_NUM_MBLKS; /* number of mblks for pool4 */
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * Set this to non-zero to enable additional internal receive buffer pools
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * based on the MTU of the device for better performance at the cost of more
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * memory consumption. This is turned off by default, to use allocb(9F) for
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * receive buffer allocations of sizes > 2K.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * vsw_max_tx_qcount is the maximum # of packets that can be queued
f0ca1d9a12d54d304791bc74525e2010ca924726sb * before the tx worker thread begins processing the queue. Its value
f0ca1d9a12d54d304791bc74525e2010ca924726sb * is chosen to be 4x the default length of tx descriptor ring.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatnauint32_t vsw_max_tx_qcount = 4 * VSW_NUM_DESCRIPTORS;
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * MAC callbacks
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo 0, /* devo_refcnt */
205eeb1ae627fcf67b5705c443a2b56a8263406blm "sun4v Virtual Switch",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Driver soft state ptr */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Linked list of "vsw_t" structures - one per instance.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Property names
f0ca1d9a12d54d304791bc74525e2010ca924726sbstatic char pri_types_propname[] = "priority-ether-types";
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatnastatic char vsw_mtu_propname[] = "mtu";
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatnastatic char vsw_linkprop_propname[] = "linkprop";
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Matching criteria passed to the MDEG to register interest
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * in changes to 'virtual-device-port' nodes identified by their
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 'id' property.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic mdeg_node_match_t vport_match = { "virtual-device-port",
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Matching criteria passed to the MDEG to register interest
34683adecebe88ca2c857e28be4749f3a083f9fcsg * in changes to 'virtual-device' nodes (i.e. vsw nodes) identified
34683adecebe88ca2c857e28be4749f3a083f9fcsg * by their 'name' and 'cfg-handle' properties.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Specification of an MD node passed to the MDEG to filter any
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 'vport' nodes that do not belong to the specified node. This
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * template is copied for each vsw instance and filled in with
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * the appropriate 'cfg-handle' value before being passed to the MDEG.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VSW_SET_MDEG_PROP_INST(specp, val) (specp)[1].ps_val = (val);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Print debug messages - set to 0x1f to enable all msgs
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * or 0x0 to turn all off.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * debug levels:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 0x01: Function entry/exit tracing
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 0x02: Internal function messages
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 0x04: Verbose internal messages
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 0x08: Warning messages
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 0x10: Error messages
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif /* DEBUG */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo status = ddi_soft_state_init(&vsw_state, sizeof (vsw_t), 1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (status != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (status != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo switch (cmd) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* nothing to do for this non-device */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ddi_soft_state_zalloc(vsw_state, instance) != DDI_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo DERR(NULL, "vsw%d: ddi_soft_state_zalloc failed", instance);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo DERR(NULL, "vsw%d: ddi_get_soft_state failed", instance);
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna vswp->phys_link_state = LINK_STATE_UNKNOWN;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_init(&vswp->mac_lock, NULL, MUTEX_DRIVER, NULL);
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna mutex_init(&vswp->sw_thr_lock, NULL, MUTEX_DRIVER, NULL);
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna cv_init(&vswp->sw_thr_cv, NULL, CV_DRIVER, NULL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rw_init(&vswp->maccl_rwlock, NULL, RW_DRIVER, NULL);
19b65a69adc64b3289ccb2fc32b805782e3f4540sb if (rv != 0)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* setup the unicast forwarding database */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) snprintf(hashname, MAXNAMELEN, "vsw_unicst_table-%d",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D2(vswp, "creating unicast hash table (%s)...", hashname);
c1c61f44e88f4c8c155272ee56d868043146096asb vswp->fdb_hashp = mod_hash_create_ptrhash(hashname, vswp->fdb_nchains,
205eeb1ae627fcf67b5705c443a2b56a8263406blm mod_hash_null_valdtor, sizeof (void *));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* setup the multicast fowarding database */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) snprintf(hashname, MAXNAMELEN, "vsw_mcst_table-%d",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D2(vswp, "creating multicast hash table %s)...", hashname);
c1c61f44e88f4c8c155272ee56d868043146096asb vswp->mfdb = mod_hash_create_ptrhash(hashname, vsw_fdb_nchains,
205eeb1ae627fcf67b5705c443a2b56a8263406blm mod_hash_null_valdtor, sizeof (void *));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Create the taskq which will process all the VIO
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * control messages.
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna (void) snprintf(qname, TASKQ_NAMELEN, "taskq%d", vswp->instance);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((vswp->taskq_p = ddi_taskq_create(vswp->dip, qname, 1,
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna (void) snprintf(qname, TASKQ_NAMELEN, "rxpool_taskq%d",
34b64c01c6a2242177691e1420a386e2789f79dcWENTAO YANG if ((vswp->rxp_taskq = ddi_taskq_create(vswp->dip, qname, 1,
34b64c01c6a2242177691e1420a386e2789f79dcWENTAO YANG cmn_err(CE_WARN, "!vsw%d: Unable to create rxp task queue",
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* prevent auto-detaching */
7a327842c3ad1ec3b602c454b218df4ebbc716fbwentaoy * The null switching function is set to avoid panic until
7a327842c3ad1ec3b602c454b218df4ebbc716fbwentaoy * switch mode is setup.
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna * Setup the required switching mode, based on the mdprops that we read
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna * earlier. We start a thread to do this, to avoid calling mac_open()
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna * directly from attach().
19b65a69adc64b3289ccb2fc32b805782e3f4540sb /* Register with mac layer as a provider */
19b65a69adc64b3289ccb2fc32b805782e3f4540sb if (rv != 0)
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Now we have everything setup, register an interest in
34683adecebe88ca2c857e28be4749f3a083f9fcsg * specific MD nodes.
34683adecebe88ca2c857e28be4749f3a083f9fcsg * The callback is invoked in 2 cases, firstly if upon mdeg
34683adecebe88ca2c857e28be4749f3a083f9fcsg * registration there are existing nodes which match our specified
34683adecebe88ca2c857e28be4749f3a083f9fcsg * criteria, and secondly if the MD is changed (and again, there
34683adecebe88ca2c857e28be4749f3a083f9fcsg * are nodes which we are interested in present within it. Note
34683adecebe88ca2c857e28be4749f3a083f9fcsg * that our callback will be invoked even if our specified nodes
34683adecebe88ca2c857e28be4749f3a083f9fcsg * have not actually changed).
19b65a69adc64b3289ccb2fc32b805782e3f4540sb if (rv != 0)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo switch (cmd) {
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG for (vswpp = &vsw_head; *vswpp; vswpp = &(*vswpp)->next) {
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * Common routine to handle vsw_attach() failure and vsw_detach(). Note that
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * the only reason this function could fail is if mac_unregister() fails.
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * Otherwise, this function must ensure that all resources are freed and return
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * Unregister from the gldv3 subsystem. This can fail, in particular
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * if there are still any open references to this mac device; in which
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * case we just return failure without continuing to detach further.
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG cmn_err(CE_WARN, "!vsw%d: Unable to detach from "
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * Now that we have unregistered from gldv3, we must finish all other
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * steps and successfully return from this function; otherwise we will
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * end up leaving the device in a broken/unusable state.
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * If we have registered with mdeg, unregister now to stop further
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * callbacks to this vsw device and/or its ports. Then, detach any
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * existing ports.
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * If we have started a thread to setup the switching mode, stop it, if
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * it is still running. If it has finished setting up the switching
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * mode, then we need to clean up some additional things if we are
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * running in L2 mode: first free up any hybrid resources; then stop
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * and close the underlying physical device. Note that we would have
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * already released all per mac_client resources (ucast, mcast addrs,
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * hio-shares etc) as all the ports are detached and if the vsw device
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * itself was in use as an interface, it has been unplumbed (otherwise
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG * mac_unregister() above would fail).
34b64c01c6a2242177691e1420a386e2789f79dcWENTAO YANG * We now destroy the taskq used to clean up rx mblk pools that
34b64c01c6a2242177691e1420a386e2789f79dcWENTAO YANG * couldn't be destroyed when the ports/channels were detached.
34b64c01c6a2242177691e1420a386e2789f79dcWENTAO YANG * We implicitly wait for those tasks to complete in
34b64c01c6a2242177691e1420a386e2789f79dcWENTAO YANG * ddi_taskq_destroy().
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * By now any pending tasks have finished and the underlying
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * ldc's have been destroyed, so its safe to delete the control
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * message taskq.
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG /* Destroy the multicast hash table */
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANG /* Destroy the vlan hash table and fdb */
34b64c01c6a2242177691e1420a386e2789f79dcWENTAO YANG vio_mblk_pool_t *poolp = (vio_mblk_pool_t *)arg;
a862df29af145cac620492c4ebe1f42c1906c66eSriharsha Basavapatna delay(drv_usectohz(vsw_rxpool_cleanup_delay));
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Get the value of the "vsw-phys-dev" property in the specified
34683adecebe88ca2c857e28be4749f3a083f9fcsg * node. This property is the name of the physical device that
34683adecebe88ca2c857e28be4749f3a083f9fcsg * the virtual switch will use to talk to the outside world.
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Note it is valid for this property to be NULL (but the property
34683adecebe88ca2c857e28be4749f3a083f9fcsg * itself must exist). Callers of this routine should verify that
34683adecebe88ca2c857e28be4749f3a083f9fcsg * the value returned is what they expected (i.e. either NULL or non NULL).
34683adecebe88ca2c857e28be4749f3a083f9fcsg * On success returns value of the property in region pointed to by
34683adecebe88ca2c857e28be4749f3a083f9fcsg * the 'name' argument, and with return value of 0. Otherwise returns 1.
34683adecebe88ca2c857e28be4749f3a083f9fcsgvsw_get_md_physname(vsw_t *vswp, md_t *mdp, mde_cookie_t node, char *name)
f2b610cf6e03184d9538e3aaec99bcaf65124714wentaoy (void) snprintf(myname, MAXNAMELEN, "%s%d", dev_name, instance);
34683adecebe88ca2c857e28be4749f3a083f9fcsg cmn_err(CE_WARN, "!vsw%d: Unable to get name(s) of physical "
34683adecebe88ca2c857e28be4749f3a083f9fcsg return (1);
34683adecebe88ca2c857e28be4749f3a083f9fcsg return (1);
f2b610cf6e03184d9538e3aaec99bcaf65124714wentaoy * Prevent the vswitch from opening itself as the
f2b610cf6e03184d9538e3aaec99bcaf65124714wentaoy * network device.
f2b610cf6e03184d9538e3aaec99bcaf65124714wentaoy cmn_err(CE_WARN, "!vsw%d: %s is an invalid device name",
f2b610cf6e03184d9538e3aaec99bcaf65124714wentaoy return (1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * As a temporary measure to aid testing we check to see if there
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * is a vsw.conf file present. If there is we use the value of the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * vsw_physname property in the file as the name of the physical
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * device, overriding the value from the MD.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * There may be multiple devices listed, but for the moment
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * we just use the first one.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ddi_prop_lookup_string(DDI_DEV_T_ANY, vswp->dip, 0,
34683adecebe88ca2c857e28be4749f3a083f9fcsg return (1);
34683adecebe88ca2c857e28be4749f3a083f9fcsg return (0);
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Read the 'vsw-switch-mode' property from the specified MD node.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Returns 0 on success, otherwise returns 1.
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvsw_get_md_smodes(vsw_t *vswp, md_t *mdp, mde_cookie_t node, uint8_t *mode)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Get the switch-mode property. The modes are listed in
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * decreasing order of preference, i.e. prefered mode is
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * first item in list.
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * Unable to get switch-mode property from MD, nothing
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * more we can do.
34683adecebe88ca2c857e28be4749f3a083f9fcsg cmn_err(CE_WARN, "!vsw%d: Unable to get switch mode property"
34683adecebe88ca2c857e28be4749f3a083f9fcsg return (1);
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * Modes of operation:
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * 'switched' - layer 2 switching, underlying HW in
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * programmed mode.
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * 'promiscuous' - layer 2 switching, underlying HW in
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * promiscuous mode.
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * 'routed' - layer 3 (i.e. IP) routing, underlying HW
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm * in non-promiscuous mode.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng cmn_err(CE_WARN, "!vsw%d: Unknown switch mode %s, "
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng "setting to default switched mode",
34683adecebe88ca2c857e28be4749f3a083f9fcsg return (0);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Register with the MAC layer as a network device, so we
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * can be plumbed if necessary.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (rv != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Treat this as a non-fatal error as we may be
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * able to operate in some other mode.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (rv != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* mark i/f as down and unregistered */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* return stats from underlying device */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (0);
19b65a69adc64b3289ccb2fc32b805782e3f4540sbstatic void
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /* Cleanup and close the mac client */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vsw_mac_client_cleanup(vswp, NULL, VSW_LOCALDEV);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D1(vswp, "%s: exit (state = %d)", __func__, vswp->if_state);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * If the switching mode has not been setup yet, just
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * return. The unicast address will be programmed
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * after the physical device is successfully setup by the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * timeout handler.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (0);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* if in layer2 mode, program unicast address. */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /* Init a mac client and program addresses */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rv = vsw_mac_client_init(vswp, NULL, VSW_LOCALDEV);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (rv != 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng "!vsw%d: failed to program interface "
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D1(vswp, "%s: exit (state = %d)", __func__, vswp->if_state);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (0);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Change the local interface address.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Note: we don't support this entry point. The local
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * mac address of the switch can only be changed via its
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * MD node properties.
06db247c678f0e3956535e8a6dec31d6c2108827raghuramvsw_m_multicst(void *arg, boolean_t add, const uint8_t *mca)
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Convert address into form that can be used
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * as hash table key.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram for (i = 0; i < ETHERADDRL; i++) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (vsw_add_mcst(vswp, VSW_LOCALDEV, addr, NULL) == 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Update the list of multicast addresses
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * contained within the vsw_t structure to
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * include this new one.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram mcst_p = kmem_zalloc(sizeof (mcst_addr_t), KM_NOSLEEP);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (1);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Call into the underlying driver to program the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * address into HW.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng cmn_err(CE_WARN, "!vsw%d: unable to add multicast "
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Remove the address from the hash table..
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (vsw_del_mcst(vswp, VSW_LOCALDEV, addr, NULL) == 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * ..and then from the list maintained in the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * vsw_t structure.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vsw_mac_multicast_remove(vswp, NULL, mcst_p, VSW_LOCALDEV);
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram vswp->vsw_switch_frame(vswp, mp, VSW_LOCALDEV, NULL, NULL);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Register for machine description (MD) updates.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Returns 0 on success, 1 on failure.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Allocate and initialize a per-instance copy
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * of the global property spec array that will
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * uniquely identify this vsw instance.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* initialize the complete prop spec structure */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram inst_specp = kmem_zalloc(sizeof (mdeg_node_spec_t), KM_SLEEP);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D2(vswp, "%s: instance %d registering with mdeg", __func__,
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Register an interest in 'virtual-device' nodes with a
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * 'name' property of 'virtual-network-switch'
06db247c678f0e3956535e8a6dec31d6c2108827raghuram rv = mdeg_register(inst_specp, &vdev_match, vsw_mdeg_cb,
06db247c678f0e3956535e8a6dec31d6c2108827raghuram DERR(vswp, "%s: mdeg_register failed (%d) for vsw node",
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Register an interest in 'vsw-port' nodes.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram rv = mdeg_register(inst_specp, &vport_match, vsw_port_mdeg_cb,
06db247c678f0e3956535e8a6dec31d6c2108827raghuram DERR(vswp, "%s: mdeg_register failed (%d)\n", __func__, rv);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* save off data that will be needed later */
19b65a69adc64b3289ccb2fc32b805782e3f4540sb return (0);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_WARN, "!vsw%d: Unable to register MDEG callbacks",
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (1);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram (void) kmem_free(vswp->inst_spec, sizeof (mdeg_node_spec_t));
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Mdeg callback invoked for the vsw node itself.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D1(vswp, "%s: added %d : removed %d : curr matched %d"
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * We get an initial callback for this node as 'added'
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * after registering with mdeg. Note that we would have
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * already gathered information about this vsw node by
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * walking MD earlier during attach (in vsw_read_mdprops()).
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * So, there is a window where the properties of this
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * node might have changed when we get this initial 'added'
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * callback. We handle this as if an update occured
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * and invoke the same function which handles updates to
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * the properties of this vsw-node if any.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * A non-zero 'match' value indicates that the MD has been
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * updated and that a virtual-network-switch node is
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * present which may or may not have been updated. It is
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * up to the clients to examine their own nodes and
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * determine if they have changed.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram "invalid: %d\n", vswp->instance, resp->added.nelem);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_NOTE, "!vsw%d: number of nodes updated "
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* Validate name and instance */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_str(mdp, node, "name", &node_name) != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram DERR(vswp, "%s: unable to get node name\n", __func__);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* is this a virtual-network-switch? */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_val(mdp, node, "cfg-handle", &inst)) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* is this the right instance of vsw? */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Mdeg callback invoked for changes to the vsw-port nodes
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * under the vsw node.
06db247c678f0e3956535e8a6dec31d6c2108827raghuramvsw_port_mdeg_cb(void *cb_argp, mdeg_result_t *resp)
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D2(vswp, "%s: added %d : removed %d : curr matched %d"
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* process added ports */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D2(vswp, "%s: adding node(%d) 0x%lx", __func__, idx, node);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* process removed ports */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_val(mdp, node, id_propname, &inst)) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D2(vswp, "%s: removing node(%d) 0x%lx", __func__, idx, node);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_WARN, "!vsw%d: Unable to remove port %ld",
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Scan the machine description for this instance of vsw
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * and read its properties. Called only from vsw_attach().
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Returns: 0 on success, 1 on failure.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * In each 'virtual-device' node in the MD there is a
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * 'cfg-handle' property which is the MD's concept of
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * an instance number (this may be completely different from
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * the device drivers instance #). OBP reads that value and
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * stores it in the 'reg' property of the appropriate node in
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * the device tree. We first read this reg property and use this
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * to compare against the 'cfg-handle' property of vsw nodes
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * in MD to get to this specific vsw instance and then read
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * other properties that we are interested in.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * We also cache the value of 'reg' property and use it later
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * to register callbacks with mdeg (see vsw_mdeg_register())
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_NOTE, "!vsw%d: Unable to read %s property from "
19b65a69adc64b3289ccb2fc32b805782e3f4540sb return (rv);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram listp = (mde_cookie_t *)kmem_zalloc(listsz, KM_SLEEP);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* search for all "virtual_device" nodes */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram DWARN(vswp, "%s: invalid num_devs:%d\n", __func__, num_devs);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Now loop through the list of virtual-devices looking for
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * devices with name "virtual-network-switch" and for each
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * such device compare its instance with what we have from
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * the 'reg' property to find the right node in MD and then
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * read all its properties.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram for (i = 0; i < num_devs; i++) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_str(mdp, listp[i], "name", &name) != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* is this a virtual-network-switch? */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_val(mdp, listp[i], "cfg-handle", &cfgh) != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* is this the required instance of vsw? */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* now read all properties of this vsw instance */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram rv = vsw_get_initial_md_properties(vswp, mdp, listp[i]);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Read the initial start-of-day values from the specified MD node.
06db247c678f0e3956535e8a6dec31d6c2108827raghuramvsw_get_initial_md_properties(vsw_t *vswp, md_t *mdp, mde_cookie_t node)
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (vsw_get_md_physname(vswp, mdp, node, vswp->physname) != 0) {
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm return (1);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* mac address for vswitch device itself */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_val(mdp, node, macaddr_propname, &macaddr) != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_WARN, "!vsw%d: Unable to get MAC address from MD",
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm return (1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (vsw_get_md_smodes(vswp, mdp, node, &vswp->smode)) {
1ef0bbb5af03e2721bb767e58ada1c58265e9fdenarayan DWARN(vswp, "%s: Unable to read %s property from MD, "
1ef0bbb5af03e2721bb767e58ada1c58265e9fdenarayan "defaulting to 'switched' mode",
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna * Read the 'linkprop' property to know if this
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna * vsw device wants to get physical link updates.
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna vsw_linkprop_read(vswp, mdp, node, &vswp->pls_update);
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna vsw_mtu_read(vswp, mdp, node, &vswp->mtu);
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna if (vswp->mtu < ETHERMTU || vswp->mtu > VNET_MAX_MTU) {
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna vswp->max_frame_size = vswp->mtu + sizeof (struct ether_header) +
c1c61f44e88f4c8c155272ee56d868043146096asb /* read vlan id properties of this vsw instance */
c1c61f44e88f4c8c155272ee56d868043146096asb vsw_vlan_read_ids(vswp, VSW_LOCALDEV, mdp, node, &vswp->pvid,
c1c61f44e88f4c8c155272ee56d868043146096asb /* read priority-ether-types */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG /* read bandwidth property of this vsw instance */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG vsw_bandwidth_read(vswp, mdp, node, &vswp->bandwidth);
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm return (0);
c1c61f44e88f4c8c155272ee56d868043146096asb * Read vlan id properties of the given MD node.
c1c61f44e88f4c8c155272ee56d868043146096asb * Arguments:
c1c61f44e88f4c8c155272ee56d868043146096asb * arg: device argument(vsw device or a port)
c1c61f44e88f4c8c155272ee56d868043146096asb * type: type of arg; VSW_LOCALDEV(vsw device) or VSW_VNETPORT(port)
c1c61f44e88f4c8c155272ee56d868043146096asb * mdp: machine description
c1c61f44e88f4c8c155272ee56d868043146096asb * node: md node cookie
c1c61f44e88f4c8c155272ee56d868043146096asb * Returns:
c1c61f44e88f4c8c155272ee56d868043146096asb * pvidp: port-vlan-id of the node
c1c61f44e88f4c8c155272ee56d868043146096asb * vidspp: list of vlan-ids of the node
c1c61f44e88f4c8c155272ee56d868043146096asb * nvidsp: # of vlan-ids in the list
c1c61f44e88f4c8c155272ee56d868043146096asb * default_idp: default-vlan-id of the node(if node is vsw device)
c1c61f44e88f4c8c155272ee56d868043146096asbstatic void
c1c61f44e88f4c8c155272ee56d868043146096asbvsw_vlan_read_ids(void *arg, int type, md_t *mdp, mde_cookie_t node,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint16_t *pvidp, vsw_vlanid_t **vidspp, uint16_t *nvidsp,
c1c61f44e88f4c8c155272ee56d868043146096asb rv = md_get_prop_val(mdp, node, vsw_dvid_propname, &val);
c1c61f44e88f4c8c155272ee56d868043146096asb if (rv != 0) {
c1c61f44e88f4c8c155272ee56d868043146096asb if (rv != 0) {
c1c61f44e88f4c8c155272ee56d868043146096asb DWARN(vswp, "%s: prop(%s) not found", __func__, pvid_propname);
c1c61f44e88f4c8c155272ee56d868043146096asb rv = md_get_prop_data(mdp, node, vid_propname, (uint8_t **)&data,
c1c61f44e88f4c8c155272ee56d868043146096asb if (rv != 0) {
c1c61f44e88f4c8c155272ee56d868043146096asb D2(vswp, "%s: prop(%s) not found", __func__, vid_propname);
c1c61f44e88f4c8c155272ee56d868043146096asb if (nvids != 0) {
c1c61f44e88f4c8c155272ee56d868043146096asb for (i = 0; i < nvids; i++) {
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANGvsw_port_read_bandwidth(vsw_port_t *portp, md_t *mdp, mde_cookie_t node,
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG rv = md_get_prop_val(mdp, node, port_maxbw_propname, &val);
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG D3(vswp, "%s: %s nodes found", __func__, port_maxbw_propname);
f0ca1d9a12d54d304791bc74525e2010ca924726sb * This function reads "priority-ether-types" property from md. This property
f0ca1d9a12d54d304791bc74525e2010ca924726sb * is used to enable support for priority frames. Applications which need
f0ca1d9a12d54d304791bc74525e2010ca924726sb * guaranteed and timely delivery of certain high priority frames to/from
f0ca1d9a12d54d304791bc74525e2010ca924726sb * a vnet or vsw within ldoms, should configure this property by providing
f0ca1d9a12d54d304791bc74525e2010ca924726sb * the ether type(s) for which the priority facility is needed.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * Normal data frames are delivered over a ldc channel using the descriptor
f0ca1d9a12d54d304791bc74525e2010ca924726sb * ring mechanism which is constrained by factors such as descriptor ring size,
f0ca1d9a12d54d304791bc74525e2010ca924726sb * the rate at which the ring is processed at the peer ldc end point, etc.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * The priority mechanism provides an Out-Of-Band path to send/receive frames
f0ca1d9a12d54d304791bc74525e2010ca924726sb * as raw pkt data (VIO_PKT_DATA) messages over the channel, avoiding the
f0ca1d9a12d54d304791bc74525e2010ca924726sb * descriptor ring path and enables a more reliable and timely delivery of
f0ca1d9a12d54d304791bc74525e2010ca924726sb * frames to the peer.
f0ca1d9a12d54d304791bc74525e2010ca924726sbstatic void
f0ca1d9a12d54d304791bc74525e2010ca924726sbvsw_read_pri_eth_types(vsw_t *vswp, md_t *mdp, mde_cookie_t node)
f0ca1d9a12d54d304791bc74525e2010ca924726sb if (rv != 0) {
f0ca1d9a12d54d304791bc74525e2010ca924726sb * Property may not exist if we are running pre-ldoms1.1 f/w.
f0ca1d9a12d54d304791bc74525e2010ca924726sb * Check if 'vsw_pri_eth_type' has been set in that case.
f0ca1d9a12d54d304791bc74525e2010ca924726sb if (size == 0) {
f0ca1d9a12d54d304791bc74525e2010ca924726sb * we have some priority-ether-types defined;
f0ca1d9a12d54d304791bc74525e2010ca924726sb * allocate a table of these types and also
f0ca1d9a12d54d304791bc74525e2010ca924726sb * allocate a pool of mblks to transmit these
f0ca1d9a12d54d304791bc74525e2010ca924726sb * priority packets.
f0ca1d9a12d54d304791bc74525e2010ca924726sb vswp->pri_types = kmem_zalloc(size * sizeof (uint16_t), KM_SLEEP);
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna (void) vio_create_mblks(vsw_pri_tx_nmblks, mblk_sz, NULL,
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatnavsw_mtu_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node, uint32_t *mtu)
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna rv = md_get_prop_val(mdp, node, mtu_propname, &val);
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna D3(vswp, "%s: prop(%s) not found", __func__, mtu_propname);
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna D2(vswp, "%s: %s(%d): (%d)\n", __func__,
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * Update the mtu of the vsw device. We first check if the device has been
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * plumbed and if so fail the mtu update. Otherwise, we continue to update the
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * new mtu and reset all ports to initiate handshake re-negotiation with peers
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna * using the new mtu.
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatnavsw_mtu_update(vsw_t *vswp, uint32_t mtu)
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna cmn_err(CE_NOTE, "!vsw%d: Unable to process mtu update"
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna " as the device is plumbed\n", vswp->instance);
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna D2(vswp, "%s: curr_mtu(%d) new_mtu(%d)\n",
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna sizeof (struct ether_header) + VLAN_TAGSZ;
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna rv = mac_maxsdu_update(vswp->if_mh, mtu);
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna "!vsw%d: Unable to update mtu with mac"
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna /* Reset ports to renegotiate with the new mtu */
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatnavsw_linkprop_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node,
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna rv = md_get_prop_val(mdp, node, linkpropname, &val);
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna D3(vswp, "%s: prop(%s) not found", __func__, linkpropname);
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna *pls = (val & 0x1) ? B_TRUE : B_FALSE;
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna D2(vswp, "%s: %s(%d): (%d)\n", __func__, linkpropname,
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatnavsw_mac_link_update(vsw_t *vswp, link_state_t link_state)
d8a518c84b0b033745c344594c3478e1294f3a9aSriharsha Basavapatna mac_link_update(vswp->if_mh, link_state);
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna vsw_mac_link_update(vswp, vswp->phys_link_state);
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANGvsw_bandwidth_read(vsw_t *vswp, md_t *mdp, mde_cookie_t node, uint64_t *bw)
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG /* read the vsw bandwidth from md */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG rv = md_get_prop_val(mdp, node, vsw_maxbw_propname, &val);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Check to see if the relevant properties in the specified node have
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * changed, and if so take the appropriate action.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * If any of the properties are missing or invalid we don't take
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * any action, as this function should only be invoked when modifications
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * have been made to what we assume is a working configuration, which
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * we leave active.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Note it is legal for this routine to be invoked even if none of the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * properties in the port node within the MD have actually changed.
5f94e909a253b6d0625c7c7425f59848f0cfb850sgstatic void
06db247c678f0e3956535e8a6dec31d6c2108827raghuramvsw_update_md_prop(vsw_t *vswp, md_t *mdp, mde_cookie_t node)
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Check if name of physical device in MD has changed.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (vsw_get_md_physname(vswp, mdp, node, (char *)&physname) == 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Do basic sanity check on new device name/instance,
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * if its non NULL. It is valid for the device name to
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * have changed from a non NULL to a NULL value, i.e.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * the vsw is being changed to 'routed' mode.
1ef0bbb5af03e2721bb767e58ada1c58265e9fdenarayan cmn_err(CE_WARN, "!vsw%d: physical device %s is not"
06db247c678f0e3956535e8a6dec31d6c2108827raghuram " a valid device name/instance",
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_WARN, "!vsw%d: Unable to read name of physical "
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Check if MAC address has changed.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_val(mdp, node, macaddr_propname, &macaddr) != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_WARN, "!vsw%d: Unable to get MAC address from MD",
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Check if switching modes have changed.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (vsw_get_md_smodes(vswp, mdp, node, &new_smode)) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_WARN, "!vsw%d: Unable to read %s property from MD",
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng D2(vswp, "%s: switching mode changed from %d to %d",
c1c61f44e88f4c8c155272ee56d868043146096asb /* Read the vlan ids */
c1c61f44e88f4c8c155272ee56d868043146096asb vsw_vlan_read_ids(vswp, VSW_LOCALDEV, mdp, node, &pvid, &vids,
c1c61f44e88f4c8c155272ee56d868043146096asb /* Determine if there are any vlan id updates */
c1c61f44e88f4c8c155272ee56d868043146096asb ((nvids != 0) && (vswp->nvids != 0) && /* vids changed? */
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna if (mtu >= ETHERMTU && mtu <= VNET_MAX_MTU) {
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna cmn_err(CE_NOTE, "!vsw%d: Unable to process mtu update"
7b1f684a14f99a2b9b1b2561f484ff648eff6d9bSriharsha Basavapatna " as the specified value:%d is invalid\n",
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna * Read the 'linkprop' property.
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna vsw_linkprop_read(vswp, mdp, node, &pls_update);
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG /* Read bandwidth */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG cmn_err(CE_NOTE, "!vsw%d: Unable to process bandwidth"
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG " update as the specified value:%ld is invalid\n",
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Now make any changes which are needed...
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna /* save the updated property. */
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna * Phys link state update is now disabled for this vsw
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna * interface. If we had previously reported a link-down
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna * to the stack, undo that by sending a link-up.
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna if (vswp->phys_link_state == LINK_STATE_DOWN) {
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna vsw_mac_link_update(vswp, LINK_STATE_UP);
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna * Phys link state update is now enabled. Send up an
1107ea9346159bcc8ea154084897667347c4e6d5Sriharsha Basavapatna * update based on the current phys link state.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (updated & (MD_physname | MD_smode | MD_mtu)) {
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna * Stop any pending thread to setup switching mode.
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Cleanup HybridIO */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Remove unicst, mcst addrs of vsw interface
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * and ports from the physdev. This also closes
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * the corresponding mac clients.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Stop, detach and close the old device..
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Update phys name.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Update array with the new switch mode values.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /* Update mtu */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (rv != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * ..and attach, start the new device.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Unable to setup switching mode.
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna * As the error is EAGAIN, schedule a thread to retry
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * and return. Programming addresses of ports and
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna * vsw interface will be done by the thread when the
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna * switching setup completes successfully.
808f26a819b6259a3340d8d53074a2f1635315cbSriharsha Basavapatna if (vsw_setup_switching_start(vswp) != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram } else if (rv) {
d8a518c84b0b033745c344594c3478e1294f3a9aSriharsha Basavapatna vsw_setup_switching_post_process(vswp);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * We enter here if only MD_macaddr is exclusively updated.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * If MD_physname and/or MD_smode are also updated, then
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * as part of that, we would have implicitly processed
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * MD_macaddr update (above).
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_NOTE, "!vsw%d: changing mac address to 0x%lx",
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /* reconfigure with new address */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Notify the MAC layer of the changed address.
c1c61f44e88f4c8c155272ee56d868043146096asb /* Remove existing vlan ids from the hash table. */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vsw_if_mac_reconfig(vswp, B_TRUE, pvid, vids, nvids);
c1c61f44e88f4c8c155272ee56d868043146096asb /* add these new vlan ids into hash table */
c1c61f44e88f4c8c155272ee56d868043146096asb if (nvids != 0) {
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG vsw_update_bandwidth(vswp, NULL, VSW_LOCALDEV, maxbw);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram cmn_err(CE_WARN, "!vsw%d: configuration unchanged", vswp->instance);
c1c61f44e88f4c8c155272ee56d868043146096asb * Read the port's md properties.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_val(mdp, *node, id_propname, &inst)) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (1);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * Find the channel endpoint node(s) (which should be under this
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * port node) which contain the channel id(s).
06db247c678f0e3956535e8a6dec31d6c2108827raghuram DERR(vswp, "%s: invalid number of nodes found (%d)",
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (1);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D2(vswp, "%s: %d nodes found", __func__, num_nodes);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* allocate enough space for node list */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram nchan = md_scan_dag(mdp, *node, md_find_name(mdp, chan_propname),
06db247c678f0e3956535e8a6dec31d6c2108827raghuram DWARN(vswp, "%s: no %s nodes found", __func__, chan_propname);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (1);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D2(vswp, "%s: %d %s nodes found", __func__, nchan, chan_propname);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* use property from first node found */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram if (md_get_prop_val(mdp, listp[0], id_propname, &ldc_id)) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (1);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* don't need list any more */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* read mac-address property */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (1);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram D2(vswp, "%s: remote mac address 0x%llx", __func__, macaddr);
c1c61f44e88f4c8c155272ee56d868043146096asb /* now update all properties into the port */
c1c61f44e88f4c8c155272ee56d868043146096asb bcopy(&ldc_id, (portp->ldc_ids), sizeof (uint64_t) * nchan);
c1c61f44e88f4c8c155272ee56d868043146096asb /* read vlan id properties of this port node */
c1c61f44e88f4c8c155272ee56d868043146096asb vsw_vlan_read_ids(portp, VSW_VNETPORT, mdp, *node, &portp->pvid,
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Check if hybrid property is present */
678453a8ed49104d8adad58f3ba591bdc39883e8speer if (md_get_prop_val(mdp, *node, hybrid_propname, &val) == 0) {
678453a8ed49104d8adad58f3ba591bdc39883e8speer D1(vswp, "%s: prop(%s) found\n", __func__, hybrid_propname);
678453a8ed49104d8adad58f3ba591bdc39883e8speer * Port hio capability determined after version
678453a8ed49104d8adad58f3ba591bdc39883e8speer * negotiation, i.e., when we know the peer is HybridIO capable.
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG /* Read bandwidth of this port */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG vsw_port_read_bandwidth(portp, mdp, *node, &portp->p_bandwidth);
c1c61f44e88f4c8c155272ee56d868043146096asb return (0);
c1c61f44e88f4c8c155272ee56d868043146096asb * Add a new port to the system.
c1c61f44e88f4c8c155272ee56d868043146096asb * Returns 0 on success, 1 on failure.
c1c61f44e88f4c8c155272ee56d868043146096asb if (rv != 0) {
c1c61f44e88f4c8c155272ee56d868043146096asb return (1);
c1c61f44e88f4c8c155272ee56d868043146096asb if (rv != 0) {
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (1);
c1c61f44e88f4c8c155272ee56d868043146096asb return (0);
c1c61f44e88f4c8c155272ee56d868043146096asbvsw_port_update(vsw_t *vswp, md_t *curr_mdp, mde_cookie_t curr_mdex,
c1c61f44e88f4c8c155272ee56d868043146096asb * For now, we get port updates only if vlan ids changed.
c1c61f44e88f4c8c155272ee56d868043146096asb * We read the port num and do some sanity check.
c1c61f44e88f4c8c155272ee56d868043146096asb if (md_get_prop_val(curr_mdp, curr_mdex, id_propname, &cport_num)) {
c1c61f44e88f4c8c155272ee56d868043146096asb return (1);
c1c61f44e88f4c8c155272ee56d868043146096asb if (md_get_prop_val(prev_mdp, prev_mdex, id_propname, &pport_num)) {
c1c61f44e88f4c8c155272ee56d868043146096asb return (1);
c1c61f44e88f4c8c155272ee56d868043146096asb return (1);
c1c61f44e88f4c8c155272ee56d868043146096asb return (1);
c1c61f44e88f4c8c155272ee56d868043146096asb /* Read the vlan ids */
c1c61f44e88f4c8c155272ee56d868043146096asb vsw_vlan_read_ids(portp, VSW_VNETPORT, curr_mdp, curr_mdex, &pvid,
c1c61f44e88f4c8c155272ee56d868043146096asb /* Determine if there are any vlan id updates */
c1c61f44e88f4c8c155272ee56d868043146096asb ((nvids != 0) && (portp->nvids != 0) && /* vids changed? */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG /* Check if hybrid property is present */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG if (md_get_prop_val(curr_mdp, curr_mdex, hybrid_propname, &val) == 0) {
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG D1(vswp, "%s: prop(%s) found\n", __func__, hybrid_propname);
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG /* Check if maxbw property is present */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG vsw_port_read_bandwidth(portp, curr_mdp, curr_mdex, &maxbw);
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG cmn_err(CE_NOTE, "!vsw%d: Unable to process bandwidth"
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG " update for port %d as the specified value:%ld"
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG " is invalid\n",
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Remove existing vlan ids from the hash table. */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /* Reconfigure vlans with network device */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vsw_mac_port_reconfig_vlans(portp, pvid, vids, nvids);
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* add these new vlan ids into hash table */
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* reset the port if it is vlan unaware (ver < 1.3) */
bce0a86e5d4d65341c5aca6da2595c848297b2aaWENTAO YANG vsw_update_bandwidth(NULL, portp, VSW_VNETPORT, maxbw);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram return (0);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * vsw_mac_rx -- A common function to send packets to the interface.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * By default this function check if the interface is UP or not, the
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * rest of the behaviour depends on the flags as below:
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * VSW_MACRX_PROMISC -- Check if the promisc mode set or not.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * VSW_MACRX_COPYMSG -- Make a copy of the message(s).
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * VSW_MACRX_FREEMSG -- Free if the messages cannot be sent up the stack.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* Check if the interface is up */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* Free messages only if FREEMSG flag specified */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * If PROMISC flag is passed, then check if
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * the interface is in the PROMISC mode.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * If not, drop the messages.
06db247c678f0e3956535e8a6dec31d6c2108827raghuram /* Free messages only if FREEMSG flag specified */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * If COPYMSG flag is passed, then make a copy
06db247c678f0e3956535e8a6dec31d6c2108827raghuram * of the message chain and send up the copy.
c1c61f44e88f4c8c155272ee56d868043146096asb (void) vsw_vlan_frame_untag(vswp, VSW_LOCALDEV, &mp, &mpt);
06db247c678f0e3956535e8a6dec31d6c2108827raghuram/* copy mac address of vsw into soft state structure */
06db247c678f0e3956535e8a6dec31d6c2108827raghuram vswp->if_addr.ether_addr_octet[i] = macaddr & 0xFF;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/* Compare VLAN ids, array size expected to be same. */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvsw_cmp_vids(vsw_vlanid_t *vids1, vsw_vlanid_t *vids2, int nvids)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (i = 0; i < nvids; i++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (j = 0; j < nvids; j++) {