678453a8ed49104d8adad58f3ba591bdc39883e8speer * CDDL HEADER START
678453a8ed49104d8adad58f3ba591bdc39883e8speer * The contents of this file are subject to the terms of the
678453a8ed49104d8adad58f3ba591bdc39883e8speer * Common Development and Distribution License (the "License").
678453a8ed49104d8adad58f3ba591bdc39883e8speer * You may not use this file except in compliance with the License.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
678453a8ed49104d8adad58f3ba591bdc39883e8speer * See the License for the specific language governing permissions
678453a8ed49104d8adad58f3ba591bdc39883e8speer * and limitations under the License.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * When distributing Covered Code, include this CDDL HEADER in each
678453a8ed49104d8adad58f3ba591bdc39883e8speer * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * If applicable, add the following below this CDDL HEADER, with the
678453a8ed49104d8adad58f3ba591bdc39883e8speer * fields enclosed by brackets "[]" replaced with your own identifying
678453a8ed49104d8adad58f3ba591bdc39883e8speer * information: Portions Copyright [yyyy] [name of copyright owner]
678453a8ed49104d8adad58f3ba591bdc39883e8speer * CDDL HEADER END
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * Use is subject to license terms.
678453a8ed49104d8adad58f3ba591bdc39883e8speer#define VSW_DDS_NEXT_REQID(vsharep) (++vsharep->vs_req_id)
678453a8ed49104d8adad58f3ba591bdc39883e8speerextern boolean_t vsw_hio_enabled; /* HybridIO enabled? */
678453a8ed49104d8adad58f3ba591bdc39883e8speer/* Functions imported from other files */
678453a8ed49104d8adad58f3ba591bdc39883e8speerextern int vsw_send_msg(vsw_ldc_t *, void *, int, boolean_t);
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuramextern void vsw_hio_port_reset(vsw_port_t *portp, boolean_t immediate);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengextern void vsw_port_mac_reconfig(vsw_port_t *portp, boolean_t update_vlans,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint16_t new_pvid, vsw_vlanid_t *new_vids, int new_nvids);
678453a8ed49104d8adad58f3ba591bdc39883e8speer/* Functions exported to other files */
678453a8ed49104d8adad58f3ba591bdc39883e8speervoid vsw_process_dds_msg(vsw_t *vswp, vsw_ldc_t *ldcp, void *msg);
678453a8ed49104d8adad58f3ba591bdc39883e8speer/* Support functions */
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuramstatic void vsw_hio_free_all_shares(vsw_t *vswp, boolean_t reboot);
678453a8ed49104d8adad58f3ba591bdc39883e8speerstatic vsw_share_t *vsw_hio_alloc_share(vsw_t *vswp, vsw_ldc_t *ldcp);
678453a8ed49104d8adad58f3ba591bdc39883e8speerstatic vsw_share_t *vsw_hio_find_free_share(vsw_t *vswp);
678453a8ed49104d8adad58f3ba591bdc39883e8speerstatic vsw_share_t *vsw_hio_find_vshare_ldcid(vsw_t *vswp, uint64_t ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speerstatic vsw_share_t *vsw_hio_find_vshare_port(vsw_t *vswp, vsw_port_t *portp);
678453a8ed49104d8adad58f3ba591bdc39883e8speerstatic int vsw_send_dds_msg(vsw_ldc_t *ldcp, uint8_t dds_subclass,
678453a8ed49104d8adad58f3ba591bdc39883e8speerstatic int vsw_send_dds_resp_msg(vsw_ldc_t *ldcp, vio_dds_msg_t *dmsg, int ack);
678453a8ed49104d8adad58f3ba591bdc39883e8speerstatic int vsw_hio_send_delshare_msg(vsw_share_t *vsharep);
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuramstatic boolean_t vsw_hio_reboot_callb(void *arg, int code);
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuramstatic boolean_t vsw_hio_panic_callb(void *arg, int code);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Locking strategy for HybridIO is followed as below:
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * - As the Shares are associated with a network device, the
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * the global lock('vswp>mac_lock') is used for all Shares
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * related operations.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * - The 'port->maccl_rwlock' is used to synchronize only the
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * the operations that operate on that port's mac client. That
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * is, the share_bind and unbind operations only.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * - The locking hierarchy follows that the global mac_lock is
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * acquired first and then the ports mac client lock(maccl_rwlock)
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANGstatic kstat_t *vsw_hio_setup_kstats(char *ks_mod, char *ks_name, vsw_t *vswp);
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANGstatic int vsw_hio_kstats_update(kstat_t *ksp, int rw);
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_init -- Initialize the HybridIO related info.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * - Query SHARES and RINGS capability. Both capabilities
678453a8ed49104d8adad58f3ba591bdc39883e8speer * need to be supported by the physical-device.
678453a8ed49104d8adad58f3ba591bdc39883e8speer D2(vswp, "%s: %s is not HybridIO capable\n", __func__,
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * Register to get reboot and panic events so that
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * we can cleanup HybridIO resources gracefully.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram vswp->hio_reboot_cb_id = callb_add(vsw_hio_reboot_callb,
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram vswp->hio_panic_cb_id = callb_add(vsw_hio_panic_callb,
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG /* setup kstats for hybrid resources */
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG hiop->vh_ksp = vsw_hio_setup_kstats(DRV_NAME, "hio", vswp);
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG DERR(vswp, "%s: kstats setup failed", __func__);
678453a8ed49104d8adad58f3ba591bdc39883e8speer D2(vswp, "%s: %s is HybridIO capable num_shares=%d\n", __func__,
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_alloc_share -- Allocate and setup the share for a guest domain.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * - Allocate a free share.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * - Bind the Guest's MAC address.
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* No free shares available */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rv = mac_share_bind(portp->p_mch, ldc_id, &vsharep->vs_cookie);
678453a8ed49104d8adad58f3ba591bdc39883e8speer if (rv != 0) {
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Cache some useful info */
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_find_free_share -- Find a free Share.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_find_vshare_ldcid -- Given ldc_id, find the corresponding
678453a8ed49104d8adad58f3ba591bdc39883e8speer * share structure.
678453a8ed49104d8adad58f3ba591bdc39883e8speervsw_hio_find_vshare_ldcid(vsw_t *vswp, uint64_t ldc_id)
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_find_vshare_port -- Given portp, find the corresponding
678453a8ed49104d8adad58f3ba591bdc39883e8speer * share structure.
678453a8ed49104d8adad58f3ba591bdc39883e8speervsw_hio_find_vshare_port(vsw_t *vswp, vsw_port_t *portp)
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_free_share -- Unbind the MAC address and free share.
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* DERR only for printing by default */
678453a8ed49104d8adad58f3ba591bdc39883e8speer DERR(vswp, "Share freed for ldc_id=0x%lx Cookie=0x%lX",
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * vsw_hio_cleanup -- Cleanup the HybridIO. It unregisters the callbs
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * and frees all shares.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram /* Unregister reboot and panic callbs. */
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * vsw_hio_free_all_shares -- A routine to free all shares gracefully.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * The following are the steps followed to accomplish this:
678453a8ed49104d8adad58f3ba591bdc39883e8speer * - First clear 'hio_capable' to avoid further share allocations.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * - If a share is in accepted(ACKD) state, that means the guest
678453a8ed49104d8adad58f3ba591bdc39883e8speer * has HybridIO setup etc. If so, send a DEL_SHARE message and
678453a8ed49104d8adad58f3ba591bdc39883e8speer * give some time(delay) for the guest to ACK.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * - If the Share is another state, give some time to transition to
678453a8ed49104d8adad58f3ba591bdc39883e8speer * ACKD state, then try the above.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * - After max retries, reset the ports to brute force the shares
678453a8ed49104d8adad58f3ba591bdc39883e8speer * to be freed. Give a little delay for the LDC reset code to
678453a8ed49104d8adad58f3ba591bdc39883e8speer * free the Share.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuramvsw_hio_free_all_shares(vsw_t *vswp, boolean_t reboot)
678453a8ed49104d8adad58f3ba591bdc39883e8speer * Acquire plist->lockrw to make the locking a bit easier
678453a8ed49104d8adad58f3ba591bdc39883e8speer * and keep the ports in a stable state while we are cleaningup
678453a8ed49104d8adad58f3ba591bdc39883e8speer * HybridIO.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * first clear the hio_capable flag so that no more
678453a8ed49104d8adad58f3ba591bdc39883e8speer * HybridIO operations are initiated.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * If the share is in DDS_ACKD state, then
678453a8ed49104d8adad58f3ba591bdc39883e8speer * send DEL_SHARE message so that guest can
678453a8ed49104d8adad58f3ba591bdc39883e8speer * release its Hybrid resource.
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* send DDS_DEL_SHARE */
678453a8ed49104d8adad58f3ba591bdc39883e8speer if (rv != 0) {
678453a8ed49104d8adad58f3ba591bdc39883e8speer * No alternative, reset the port
678453a8ed49104d8adad58f3ba591bdc39883e8speer * to force the release of Hybrid
678453a8ed49104d8adad58f3ba591bdc39883e8speer * resources.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * Last retry, reset the port.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * If it is reboot case, issue an immediate
678453a8ed49104d8adad58f3ba591bdc39883e8speer " cause a reset to trigger cleanup for "
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Clean up is done */
678453a8ed49104d8adad58f3ba591bdc39883e8speer * Release the lock so that reply for DEL_SHARE
678453a8ed49104d8adad58f3ba591bdc39883e8speer * messages come and get processed, that is, shares
678453a8ed49104d8adad58f3ba591bdc39883e8speer * get freed.
678453a8ed49104d8adad58f3ba591bdc39883e8speer * This delay is also needed for the port reset to
678453a8ed49104d8adad58f3ba591bdc39883e8speer * release the Hybrid resource.
678453a8ed49104d8adad58f3ba591bdc39883e8speer } while ((free_shares < hiop->vh_num_shares) && (max_retries > 0));
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* By now, all shares should be freed */
678453a8ed49104d8adad58f3ba591bdc39883e8speer kmem_free(hiop->vh_shares, sizeof (vsw_share_t) * hiop->vh_num_shares);
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_start_ports -- Start HybridIO for ports that have
678453a8ed49104d8adad58f3ba591bdc39883e8speer * already established connection before HybridIO is intialized.
678453a8ed49104d8adad58f3ba591bdc39883e8speer for (portp = plist->head; portp != NULL; portp = portp->p_next) {
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Cause a rest to trigger HybridIO setup */
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_start -- Start HybridIO for a guest(given LDC)
678453a8ed49104d8adad58f3ba591bdc39883e8speer D1(vswp, "%s:enter ldc=0x%lx", __func__, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Verify if a share was already allocated */
678453a8ed49104d8adad58f3ba591bdc39883e8speer vsharep = vsw_hio_find_vshare_ldcid(vswp, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer rv = vsw_send_dds_msg(ldcp, DDS_VNET_ADD_SHARE, vsharep->vs_cookie,
678453a8ed49104d8adad58f3ba591bdc39883e8speer if (rv != 0) {
678453a8ed49104d8adad58f3ba591bdc39883e8speer * Failed to send a DDS message, so cleanup now.
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* DERR only to print by default */
678453a8ed49104d8adad58f3ba591bdc39883e8speer DERR(vswp, "Share allocated for ldc_id=0x%lx Cookie=0x%lX",
678453a8ed49104d8adad58f3ba591bdc39883e8speer D1(vswp, "%s:exit ldc=0x%lx", __func__, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_stop -- Stop/clean the HybridIO config for a guest(given ldc).
678453a8ed49104d8adad58f3ba591bdc39883e8speer D1(vswp, "%s:enter ldc=0x%lx", __func__, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer vsharep = vsw_hio_find_vshare_ldcid(vswp, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer D1(vswp, "%s:exit ldc=0x%lx", __func__, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_send_delshare_msg -- Send a DEL_SHARE message to the guest.
678453a8ed49104d8adad58f3ba591bdc39883e8speer return (0);
678453a8ed49104d8adad58f3ba591bdc39883e8speer if ((ldcp == NULL) || (ldcp->ldc_id != vsharep->vs_ldcid)) {
678453a8ed49104d8adad58f3ba591bdc39883e8speer return (0);
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram if (rv == 0) {
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_send_dds_msg -- Send a DDS message.
678453a8ed49104d8adad58f3ba591bdc39883e8speervsw_send_dds_msg(vsw_ldc_t *ldcp, uint8_t dds_subclass, uint64_t
678453a8ed49104d8adad58f3ba591bdc39883e8speer rv = vsw_send_msg(ldcp, &vmsg, sizeof (vmsg), B_FALSE);
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_process_dds_msg -- Process a DDS message received from a guest.
678453a8ed49104d8adad58f3ba591bdc39883e8speervsw_process_dds_msg(vsw_t *vswp, vsw_ldc_t *ldcp, void *msg)
678453a8ed49104d8adad58f3ba591bdc39883e8speer D1(vswp, "%s:enter ldc=0x%lx\n", __func__, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* discard */
678453a8ed49104d8adad58f3ba591bdc39883e8speer * We expect to receive DDS messages only from guests that
678453a8ed49104d8adad58f3ba591bdc39883e8speer * have HybridIO started.
678453a8ed49104d8adad58f3ba591bdc39883e8speer vsharep = vsw_hio_find_vshare_ldcid(vswp, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* A response for ADD_SHARE message. */
678453a8ed49104d8adad58f3ba591bdc39883e8speer DWARN(vswp, "%s: invalid req_id in ADD_SHARE response"
678453a8ed49104d8adad58f3ba591bdc39883e8speer " message req_id=0x%X share's req_id=0x%X",
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* cleanup for NACK */
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* A response for DEL_SHARE message */
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram DWARN(vswp, "%s: invalid DEL_SHARE response message "
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram DWARN(vswp, "%s: invalid req_id in DEL_SHARE response"
678453a8ed49104d8adad58f3ba591bdc39883e8speer " message share req_id=0x%X share's req_id=0x%X",
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* There is nothing we can do, free share now */
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Guest has released Share voluntarily, so free it now */
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* send ACK */
678453a8ed49104d8adad58f3ba591bdc39883e8speer D1(vswp, "%s:exit ldc=0x%lx\n", __func__, ldcp->ldc_id);
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_send_dds_resp_msg -- Send a DDS response message.
678453a8ed49104d8adad58f3ba591bdc39883e8speervsw_send_dds_resp_msg(vsw_ldc_t *ldcp, vio_dds_msg_t *dmsg, int ack)
678453a8ed49104d8adad58f3ba591bdc39883e8speer rv = vsw_send_msg(ldcp, dmsg, sizeof (vio_dds_msg_t), B_FALSE);
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_port_update -- update Hybrid mode change for a port.
678453a8ed49104d8adad58f3ba591bdc39883e8speervsw_hio_port_update(vsw_port_t *portp, boolean_t hio_enabled)
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Verify if the mode really changed */
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Hybrid Mode is disabled, so stop HybridIO */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vsw_port_mac_reconfig(portp, B_FALSE, 0, NULL, 0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vsw_port_mac_reconfig(portp, B_FALSE, 0, NULL, 0);
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* reset the port to initiate HybridIO setup */
678453a8ed49104d8adad58f3ba591bdc39883e8speer * vsw_hio_stop_port -- Stop HybridIO for a given port. Sequence
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * followed is similar to vsw_hio_free_all_shares().
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* send DDS_DEL_SHARE */
678453a8ed49104d8adad58f3ba591bdc39883e8speer if (rv != 0) {
678453a8ed49104d8adad58f3ba591bdc39883e8speer * Cause a port reset to trigger
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* last retry */
678453a8ed49104d8adad58f3ba591bdc39883e8speer " cause a reset to trigger cleanup for "
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Check if the share still assigned to this port */
678453a8ed49104d8adad58f3ba591bdc39883e8speer * Release the lock so that reply for DEL_SHARE
678453a8ed49104d8adad58f3ba591bdc39883e8speer * messages come and get processed, that is, shares
678453a8ed49104d8adad58f3ba591bdc39883e8speer * get freed.
678453a8ed49104d8adad58f3ba591bdc39883e8speer /* Check if the share still assigned to this port */
678453a8ed49104d8adad58f3ba591bdc39883e8speer } while ((vsharep->vs_state != VSW_SHARE_FREE) && (max_retries > 0));
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * vsw_hio_rest_all -- Resets all ports that have shares allocated.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * It is called only in the panic code path, so the LDC channels
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * are reset immediately.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * Reset the port with immediate flag enabled,
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * to cause LDC reset immediately.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * vsw_hio_reboot_callb -- Called for reboot event. It tries to
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * free all currently allocated shares.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram/* ARGSUSED */
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * vsw_hio_panic_callb -- Called from panic event. It resets all
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * the ports that have shares allocated. This is done to
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram * trigger the cleanup in the guest ahead of HV reset.
cdfc78ad277d82b1080e7c86213063d1b73e7789raghuram/* ARGSUSED */
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG * Setup kstats for hio statistics.
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANGvsw_hio_setup_kstats(char *ks_mod, char *ks_name, vsw_t *vswp)
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG * vsw_hio_stats_t structure is variable size structure
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG * having fields defined only for one share. So, we need
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG * allocate additional space for the rest of the shares.
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG size = sizeof (vsw_hio_kstats_t) / sizeof (kstat_named_t);
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG ksp = kstat_create(ks_mod, vswp->instance, ks_name, "misc",
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG hiokp = (vsw_hio_kstats_t *)kmem_zalloc(sizeof (kstat_named_t) *
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG kstat_named_init(&hiokp->hio_capable, "hio_capable", KSTAT_DATA_CHAR);
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG kstat_named_init(&hiokp->hio_num_shares, "hio_num_shares",
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG (void) sprintf(share_assigned_info, "%s%d", "hio_share_", i);
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG * Destroy hio kstats.
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG kmem_free(hiop->vh_kstatsp, sizeof (kstat_named_t) *
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG * Update hio kstats.
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG (void) strcpy(hiokp->hio_capable.value.c, "Yes");
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG /* not hio capable, just return */
6ab6cb20c72ce71fe6022b1c164f36dfe716e425WENTAO YANG (void) strcpy(hiokp->hio_capable.value.c, "No");