Print this page
Use #pragma pack() per Hans
Hans review comments, but no pragma packed yet.
Add virtio net feature bit order string
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Code review changes

*** 53,65 **** #include <sys/stat.h> #include <sys/modctl.h> #include <sys/debug.h> #include <sys/pci.h> #include <sys/ethernet.h> - #define VLAN_TAGSZ 4 - #include <sys/dlpi.h> #include <sys/taskq.h> #include <sys/cyclic.h> #include <sys/pattr.h> --- 53,64 ---- #include <sys/stat.h> #include <sys/modctl.h> #include <sys/debug.h> #include <sys/pci.h> #include <sys/ethernet.h> + #include <sys/vlan.h> #include <sys/dlpi.h> #include <sys/taskq.h> #include <sys/cyclic.h> #include <sys/pattr.h>
*** 74,87 **** #include <sys/mac_ether.h> #include "virtiovar.h" #include "virtioreg.h" - #if !defined(__packed) - #define __packed __attribute__((packed)) - #endif /* __packed */ - /* Configuration registers */ #define VIRTIO_NET_CONFIG_MAC 0 /* 8bit x 6byte */ #define VIRTIO_NET_CONFIG_STATUS 6 /* 16bit */ /* Feature bits */ --- 73,82 ----
*** 102,123 **** --- 97,141 ---- #define VIRTIO_NET_F_CTRL_VQ (1 << 17) /* Control channel available */ #define VIRTIO_NET_F_CTRL_RX (1 << 18) /* Control channel RX mode support */ #define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* Control channel VLAN filtering */ #define VIRTIO_NET_F_CTRL_RX_EXTRA (1 << 20) /* Extra RX mode control support */ + #define VIRTIO_NET_FEATURE_BITS \ + "\020" \ + "\1CSUM" \ + "\2GUEST_CSUM" \ + "\6MAC" \ + "\7GSO" \ + "\10GUEST_TSO4" \ + "\11GUEST_TSO6" \ + "\12GUEST_ECN" \ + "\13GUEST_UFO" \ + "\14HOST_TSO4" \ + "\15HOST_TSO6" \ + "\16HOST_ECN" \ + "\17HOST_UFO" \ + "\20MRG_RXBUF" \ + "\21STATUS" \ + "\22CTRL_VQ" \ + "\23CTRL_RX" \ + "\24CTRL_VLAN" \ + "\25CTRL_RX_EXTRA" + /* Status */ #define VIRTIO_NET_S_LINK_UP 1 + #pragma pack(1) /* Packet header structure */ struct virtio_net_hdr { uint8_t flags; uint8_t gso_type; uint16_t hdr_len; uint16_t gso_size; uint16_t csum_start; uint16_t csum_offset; }; + #pragma pack() #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* flags */ #define VIRTIO_NET_HDR_GSO_NONE 0 /* gso_type */ #define VIRTIO_NET_HDR_GSO_TCPV4 1 /* gso_type */ #define VIRTIO_NET_HDR_GSO_UDP 3 /* gso_type */
*** 124,137 **** #define VIRTIO_NET_HDR_GSO_TCPV6 4 /* gso_type */ #define VIRTIO_NET_HDR_GSO_ECN 0x80 /* gso_type, |'ed */ /* Control virtqueue */ struct virtio_net_ctrl_cmd { uint8_t class; uint8_t command; ! } __packed; #define VIRTIO_NET_CTRL_RX 0 #define VIRTIO_NET_CTRL_RX_PROMISC 0 #define VIRTIO_NET_CTRL_RX_ALLMULTI 1 --- 142,157 ---- #define VIRTIO_NET_HDR_GSO_TCPV6 4 /* gso_type */ #define VIRTIO_NET_HDR_GSO_ECN 0x80 /* gso_type, |'ed */ /* Control virtqueue */ + #pragma pack(1) struct virtio_net_ctrl_cmd { uint8_t class; uint8_t command; ! }; ! #pragma pack() #define VIRTIO_NET_CTRL_RX 0 #define VIRTIO_NET_CTRL_RX_PROMISC 0 #define VIRTIO_NET_CTRL_RX_ALLMULTI 1
*** 140,165 **** #define VIRTIO_NET_CTRL_VLAN 2 #define VIRTIO_NET_CTRL_VLAN_ADD 0 #define VIRTIO_NET_CTRL_VLAN_DEL 1 struct virtio_net_ctrl_status { uint8_t ack; ! } __packed; struct virtio_net_ctrl_rx { uint8_t onoff; ! } __packed; struct virtio_net_ctrl_mac_tbl { uint32_t nentries; uint8_t macs[][ETHERADDRL]; ! } __packed; struct virtio_net_ctrl_vlan { uint16_t id; ! } __packed; static int vioif_quiesce(dev_info_t *); static int vioif_attach(dev_info_t *, ddi_attach_cmd_t); static int vioif_detach(dev_info_t *, ddi_detach_cmd_t); --- 160,187 ---- #define VIRTIO_NET_CTRL_VLAN 2 #define VIRTIO_NET_CTRL_VLAN_ADD 0 #define VIRTIO_NET_CTRL_VLAN_DEL 1 + #pragma pack(1) struct virtio_net_ctrl_status { uint8_t ack; ! }; struct virtio_net_ctrl_rx { uint8_t onoff; ! }; struct virtio_net_ctrl_mac_tbl { uint32_t nentries; uint8_t macs[][ETHERADDRL]; ! }; struct virtio_net_ctrl_vlan { uint16_t id; ! }; ! #pragma pack() static int vioif_quiesce(dev_info_t *); static int vioif_attach(dev_info_t *, ddi_attach_cmd_t); static int vioif_detach(dev_info_t *, ddi_detach_cmd_t);
*** 842,852 **** } mp->b_wptr = mp->b_rptr + len; atomic_inc_ulong(&sc->sc_rxloan); /* ! * Buffer loaned, we will have to allocte a new one * for this slot. */ sc->sc_rxbufs[ve->qe_index] = NULL; } --- 864,874 ---- } mp->b_wptr = mp->b_rptr + len; atomic_inc_ulong(&sc->sc_rxloan); /* ! * Buffer loaned, we will have to allocate a new one * for this slot. */ sc->sc_rxbufs[ve->qe_index] = NULL; }
*** 1073,1085 **** /* Use the inline buffer of the first entry for the virtio_net_hdr. */ (void) memset(buf->tb_inline_mapping.vbm_buf, 0, sizeof (struct virtio_net_hdr)); ! /* LINTED E_BAD_PTR_CAST_ALIGN */ ! net_header = (struct virtio_net_hdr *) ! buf->tb_inline_mapping.vbm_buf; mac_hcksum_get(mp, &csum_start, &csum_stuff, NULL, NULL, &csum_flags); /* They want us to do the TCP/UDP csum calculation. */ --- 1095,1105 ---- /* Use the inline buffer of the first entry for the virtio_net_hdr. */ (void) memset(buf->tb_inline_mapping.vbm_buf, 0, sizeof (struct virtio_net_hdr)); ! net_header = (struct virtio_net_hdr *)buf->tb_inline_mapping.vbm_buf; mac_hcksum_get(mp, &csum_start, &csum_stuff, NULL, NULL, &csum_flags); /* They want us to do the TCP/UDP csum calculation. */
*** 1457,1533 **** char *bufp = buf; char *bufend = buf + sizeof (buf); /* LINTED E_PTRDIFF_OVERFLOW */ bufp += snprintf(bufp, bufend - bufp, prefix); - /* LINTED E_PTRDIFF_OVERFLOW */ bufp += virtio_show_features(features, bufp, bufend - bufp); - - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "Vioif ( "); - - if (features & VIRTIO_NET_F_CSUM) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "CSUM "); - if (features & VIRTIO_NET_F_GUEST_CSUM) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "GUEST_CSUM "); - if (features & VIRTIO_NET_F_MAC) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "MAC "); - if (features & VIRTIO_NET_F_GSO) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "GSO "); - if (features & VIRTIO_NET_F_GUEST_TSO4) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "GUEST_TSO4 "); - if (features & VIRTIO_NET_F_GUEST_TSO6) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "GUEST_TSO6 "); - if (features & VIRTIO_NET_F_GUEST_ECN) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "GUEST_ECN "); - if (features & VIRTIO_NET_F_GUEST_UFO) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "GUEST_UFO "); - if (features & VIRTIO_NET_F_HOST_TSO4) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "HOST_TSO4 "); - if (features & VIRTIO_NET_F_HOST_TSO6) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "HOST_TSO6 "); - if (features & VIRTIO_NET_F_HOST_ECN) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "HOST_ECN "); - if (features & VIRTIO_NET_F_HOST_UFO) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "HOST_UFO "); - if (features & VIRTIO_NET_F_MRG_RXBUF) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "MRG_RXBUF "); - if (features & VIRTIO_NET_F_STATUS) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "STATUS "); - if (features & VIRTIO_NET_F_CTRL_VQ) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "CTRL_VQ "); - if (features & VIRTIO_NET_F_CTRL_RX) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "CTRL_RX "); - if (features & VIRTIO_NET_F_CTRL_VLAN) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "CTRL_VLAN "); - if (features & VIRTIO_NET_F_CTRL_RX_EXTRA) - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, "CTRL_RX_EXTRA "); - - /* LINTED E_PTRDIFF_OVERFLOW */ - bufp += snprintf(bufp, bufend - bufp, ")"); *bufp = '\0'; ! dev_err(sc->sc_dev, CE_NOTE, "%s", buf); } /* * Find out which features are supported by the device and * choose which ones we wish to use. --- 1477,1494 ---- char *bufp = buf; char *bufend = buf + sizeof (buf); /* LINTED E_PTRDIFF_OVERFLOW */ bufp += snprintf(bufp, bufend - bufp, prefix); /* LINTED E_PTRDIFF_OVERFLOW */ bufp += virtio_show_features(features, bufp, bufend - bufp); *bufp = '\0'; ! ! /* Using '!' to only CE_NOTE this to the system log. */ ! dev_err(sc->sc_dev, CE_NOTE, "!%s Vioif (%b)", buf, features, ! VIRTIO_NET_FEATURE_BITS); } /* * Find out which features are supported by the device and * choose which ones we wish to use.
*** 1702,1716 **** case DDI_ATTACH: break; case DDI_RESUME: case DDI_PM_RESUME: ! /* not supported yet */ goto exit; default: - /* unrecognized command */ goto exit; } sc = kmem_zalloc(sizeof (struct vioif_softc), KM_SLEEP); ddi_set_driver_private(devinfo, sc); --- 1663,1676 ---- case DDI_ATTACH: break; case DDI_RESUME: case DDI_PM_RESUME: ! /* We do not support suspend/resume for vioif. */ goto exit; default: goto exit; } sc = kmem_zalloc(sizeof (struct vioif_softc), KM_SLEEP); ddi_set_driver_private(devinfo, sc);
*** 1885,1905 **** switch (cmd) { case DDI_DETACH: break; case DDI_PM_SUSPEND: ! /* not supported yet */ return (DDI_FAILURE); default: - /* unrecognized command */ return (DDI_FAILURE); } if (sc->sc_rxloan) { ! cmn_err(CE_NOTE, "Some rx buffers are still upstream, " ! "Not detaching"); return (DDI_FAILURE); } virtio_stop_vq_intr(sc->sc_rx_vq); virtio_stop_vq_intr(sc->sc_tx_vq); --- 1845,1864 ---- switch (cmd) { case DDI_DETACH: break; case DDI_PM_SUSPEND: ! /* We do not support suspend/resume for vioif. */ return (DDI_FAILURE); default: return (DDI_FAILURE); } if (sc->sc_rxloan) { ! dev_err(devinfo, CE_WARN, "!Some rx buffers are still upstream," ! " not detaching."); return (DDI_FAILURE); } virtio_stop_vq_intr(sc->sc_rx_vq); virtio_stop_vq_intr(sc->sc_tx_vq);