hyperv/hn: Pull ether address and link status extraction up.

MFC after:	1 week
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D7831
This commit is contained in:
sephe 2016-09-12 06:12:28 +00:00
parent ffce674242
commit 684e8a79fe
5 changed files with 21 additions and 38 deletions

View File

@ -99,11 +99,6 @@ struct vmbus_channel;
#define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE) #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
#define NETVSC_PACKET_MAXPAGE 32 #define NETVSC_PACKET_MAXPAGE 32
typedef struct {
uint8_t mac_addr[ETHER_ADDR_LEN];
uint32_t link_state;
} netvsc_device_info;
#define HN_XACT_REQ_PGCNT 2 #define HN_XACT_REQ_PGCNT 2
#define HN_XACT_RESP_PGCNT 2 #define HN_XACT_RESP_PGCNT 2
#define HN_XACT_REQ_SIZE (HN_XACT_REQ_PGCNT * PAGE_SIZE) #define HN_XACT_REQ_SIZE (HN_XACT_REQ_PGCNT * PAGE_SIZE)

View File

@ -440,7 +440,8 @@ netvsc_attach(device_t dev)
{ {
struct sysctl_oid_list *child; struct sysctl_oid_list *child;
struct sysctl_ctx_list *ctx; struct sysctl_ctx_list *ctx;
netvsc_device_info device_info; uint8_t eaddr[ETHER_ADDR_LEN];
uint32_t link_status;
hn_softc_t *sc; hn_softc_t *sc;
int unit = device_get_unit(dev); int unit = device_get_unit(dev);
struct ifnet *ifp = NULL; struct ifnet *ifp = NULL;
@ -564,7 +565,7 @@ netvsc_attach(device_t dev)
if (sc->hn_xact == NULL) if (sc->hn_xact == NULL)
goto failed; goto failed;
error = hv_rf_on_device_add(sc, &device_info, &ring_cnt, ETHERMTU); error = hv_rf_on_device_add(sc, &ring_cnt, ETHERMTU);
if (error) if (error)
goto failed; goto failed;
KASSERT(ring_cnt > 0 && ring_cnt <= sc->hn_rx_ring_inuse, KASSERT(ring_cnt > 0 && ring_cnt <= sc->hn_rx_ring_inuse,
@ -597,9 +598,11 @@ netvsc_attach(device_t dev)
} }
#endif #endif
if (device_info.link_state == NDIS_MEDIA_STATE_CONNECTED) { error = hn_rndis_get_linkstatus(sc, &link_status);
if (error)
goto failed;
if (link_status == NDIS_MEDIA_STATE_CONNECTED)
sc->hn_carrier = 1; sc->hn_carrier = 1;
}
#if __FreeBSD_version >= 1100045 #if __FreeBSD_version >= 1100045
tso_maxlen = hn_tso_maxlen; tso_maxlen = hn_tso_maxlen;
@ -612,7 +615,10 @@ netvsc_attach(device_t dev)
(ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN); (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
#endif #endif
ether_ifattach(ifp, device_info.mac_addr); error = hn_rndis_get_eaddr(sc, eaddr);
if (error)
goto failed;
ether_ifattach(ifp, eaddr);
#if __FreeBSD_version >= 1100045 #if __FreeBSD_version >= 1100045
if_printf(ifp, "TSO: %u/%u/%u\n", ifp->if_hw_tsomax, if_printf(ifp, "TSO: %u/%u/%u\n", ifp->if_hw_tsomax,
@ -1503,7 +1509,6 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
#ifdef INET #ifdef INET
struct ifaddr *ifa = (struct ifaddr *)data; struct ifaddr *ifa = (struct ifaddr *)data;
#endif #endif
netvsc_device_info device_info;
int mask, error = 0, ring_cnt; int mask, error = 0, ring_cnt;
int retry_cnt = 500; int retry_cnt = 500;
@ -1583,8 +1588,7 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
hn_chan_attach(sc, sc->hn_prichan); /* XXX check error */ hn_chan_attach(sc, sc->hn_prichan); /* XXX check error */
ring_cnt = sc->hn_rx_ring_inuse; ring_cnt = sc->hn_rx_ring_inuse;
error = hv_rf_on_device_add(sc, &device_info, &ring_cnt, error = hv_rf_on_device_add(sc, &ring_cnt, ifr->ifr_mtu);
ifr->ifr_mtu);
if (error) { if (error) {
NV_LOCK(sc); NV_LOCK(sc);
sc->temp_unusable = FALSE; sc->temp_unusable = FALSE;

View File

@ -75,9 +75,6 @@ static void hv_rf_receive_indicate_status(struct hn_softc *sc,
const void *data, int dlen); const void *data, int dlen);
static void hv_rf_receive_data(struct hn_rx_ring *rxr, static void hv_rf_receive_data(struct hn_rx_ring *rxr,
const void *data, int dlen); const void *data, int dlen);
static int hv_rf_query_device_mac(struct hn_softc *sc, uint8_t *eaddr);
static int hv_rf_query_device_link_status(struct hn_softc *sc,
uint32_t *link_status);
static int hn_rndis_query(struct hn_softc *sc, uint32_t oid, static int hn_rndis_query(struct hn_softc *sc, uint32_t oid,
const void *idata, size_t idlen, void *odata, size_t *odlen0); const void *idata, size_t idlen, void *odata, size_t *odlen0);
@ -479,11 +476,8 @@ hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
} }
} }
/* int
* RNDIS filter query device MAC address hn_rndis_get_eaddr(struct hn_softc *sc, uint8_t *eaddr)
*/
static int
hv_rf_query_device_mac(struct hn_softc *sc, uint8_t *eaddr)
{ {
size_t eaddr_len; size_t eaddr_len;
int error; int error;
@ -500,11 +494,8 @@ hv_rf_query_device_mac(struct hn_softc *sc, uint8_t *eaddr)
return (0); return (0);
} }
/* int
* RNDIS filter query device link status hn_rndis_get_linkstatus(struct hn_softc *sc, uint32_t *link_status)
*/
static int
hv_rf_query_device_link_status(struct hn_softc *sc, uint32_t *link_status)
{ {
size_t size; size_t size;
int error; int error;
@ -1024,11 +1015,9 @@ hn_rndis_attach(struct hn_softc *sc)
} }
int int
hv_rf_on_device_add(struct hn_softc *sc, void *additl_info, hv_rf_on_device_add(struct hn_softc *sc, int *nchan0, int mtu)
int *nchan0, int mtu)
{ {
int ret; int ret;
netvsc_device_info *dev_info = (netvsc_device_info *)additl_info;
device_t dev = sc->hn_dev; device_t dev = sc->hn_dev;
int nchan = *nchan0, rxr_cnt, nsubch; int nchan = *nchan0, rxr_cnt, nsubch;
@ -1040,13 +1029,6 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
if (ret != 0) if (ret != 0)
return (ret); return (ret);
/* Get the mac address */
ret = hv_rf_query_device_mac(sc, dev_info->mac_addr);
if (ret != 0) {
/* TODO: shut down rndis device and the channel */
}
hv_rf_query_device_link_status(sc, &dev_info->link_state);
if (sc->hn_ndis_ver < HN_NDIS_VERSION_6_30 || nchan == 1) { if (sc->hn_ndis_ver < HN_NDIS_VERSION_6_30 || nchan == 1) {
/* /*
* Either RSS is not supported, or multiple RX/TX rings * Either RSS is not supported, or multiple RX/TX rings

View File

@ -43,8 +43,7 @@ struct hn_rx_ring;
void hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr, void hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
const void *data, int dlen); const void *data, int dlen);
void hv_rf_channel_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr); void hv_rf_channel_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr);
int hv_rf_on_device_add(struct hn_softc *sc, void *additl_info, int *nchan, int hv_rf_on_device_add(struct hn_softc *sc, int *nchan, int mtu);
int mtu);
int hv_rf_on_device_remove(struct hn_softc *sc); int hv_rf_on_device_remove(struct hn_softc *sc);
int hv_rf_on_open(struct hn_softc *sc); int hv_rf_on_open(struct hn_softc *sc);
int hv_rf_on_close(struct hn_softc *sc); int hv_rf_on_close(struct hn_softc *sc);

View File

@ -122,6 +122,9 @@ void hn_chim_free(struct hn_softc *sc, uint32_t chim_idx);
void *hn_rndis_pktinfo_append(struct rndis_packet_msg *, void *hn_rndis_pktinfo_append(struct rndis_packet_msg *,
size_t pktsize, size_t pi_dlen, uint32_t pi_type); size_t pktsize, size_t pi_dlen, uint32_t pi_type);
int hn_rndis_get_eaddr(struct hn_softc *sc, uint8_t *eaddr);
int hn_rndis_get_linkstatus(struct hn_softc *sc,
uint32_t *link_status);
int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch); int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch);
int hn_rxpkt(struct hn_rx_ring *rxr, const void *data, int dlen, int hn_rxpkt(struct hn_rx_ring *rxr, const void *data, int dlen,
const struct hn_recvinfo *info); const struct hn_recvinfo *info);