Lines Matching defs:vdev

20 void *vnic_dev_priv(struct vnic_dev *vdev)
22 return vdev->priv;
25 void vnic_register_cbacks(struct vnic_dev *vdev,
32 vdev->alloc_consistent = alloc_consistent;
33 vdev->free_consistent = free_consistent;
36 static int vnic_dev_discover_res(struct vnic_dev *vdev,
39 struct enic_softc *softc = vdev->softc;
107 vdev->res[type].count = count;
108 bcopy(&softc->mem, &vdev->res[type].bar, sizeof(softc->mem));
109 vdev->res[type].bar.offset = bar_offset;
119 unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
122 return vdev->res[type].count;
125 void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
130 if (!vdev->res[type].bar.tag)
134 bcopy(&vdev->res[type], res, sizeof(*res));
182 static int _vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
185 struct vnic_res __iomem *devcmd = vdev->devcmd;
202 ENIC_BUS_WRITE_REGION_4(devcmd, DEVCMD_ARGS(0), (void *)&vdev->args[0], VNIC_DEVCMD_NARGS * 2);
233 ENIC_BUS_READ_REGION_4(devcmd, bar, DEVCMD_ARGS(0), (void *)&vdev->args[0], VNIC_DEVCMD_NARGS * 2);
244 static int _vnic_dev_cmd2(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
247 struct devcmd2_controller *dc2c = vdev->devcmd2;
262 device_printf(dev_from_vnic_dev(vdev),
275 dc2c->cmd_ring[posted].args[i] = vdev->args[i];
298 device_printf(dev_from_vnic_dev(vdev),
305 vdev->args[i] = result->results[i];
312 device_printf(dev_from_vnic_dev(vdev),
319 static int vnic_dev_cmd_proxy(struct vnic_dev *vdev,
334 memset(vdev->args, 0, sizeof(vdev->args));
336 vdev->args[0] = vdev->proxy_index;
337 vdev->args[1] = cmd;
338 memcpy(&vdev->args[2], args, nargs * sizeof(args[0]));
340 err = vdev->devcmd_rtn(vdev, proxy_cmd, wait);
344 status = (u32)vdev->args[0];
346 err = (int)vdev->args[1];
353 memcpy(args, &vdev->args[1], nargs * sizeof(args[0]));
358 static int vnic_dev_cmd_no_proxy(struct vnic_dev *vdev,
367 memset(vdev->args, 0, sizeof(vdev->args));
368 memcpy(vdev->args, args, nargs * sizeof(args[0]));
370 err = vdev->devcmd_rtn(vdev, cmd, wait);
372 memcpy(args, vdev->args, nargs * sizeof(args[0]));
377 int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
385 memset(vdev->args, 0, sizeof(vdev->args));
387 switch (vdev->proxy) {
389 err = vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_INDEX, cmd,
393 err = vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_BDF, cmd,
398 err = vnic_dev_cmd_no_proxy(vdev, cmd, args, 2, wait);
410 int vnic_dev_cmd_args(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
413 switch (vdev->proxy) {
415 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_INDEX, cmd,
418 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_BDF, cmd,
422 return vnic_dev_cmd_no_proxy(vdev, cmd, args, nargs, wait);
426 static int vnic_dev_advanced_filters_cap(struct vnic_dev *vdev, u64 *args,
432 return vnic_dev_cmd_args(vdev, CMD_CAPABILITY, args, nargs, 1000);
435 int vnic_dev_capable_adv_filters(struct vnic_dev *vdev)
441 err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
457 int vnic_dev_capable_filter_mode(struct vnic_dev *vdev, u32 *mode,
464 err = vnic_dev_advanced_filters_cap(vdev, args, 4);
477 err = vnic_dev_cmd_args(vdev, CMD_CAPABILITY, args, 2, 1000);
501 void vnic_dev_capable_udp_rss_weak(struct vnic_dev *vdev, bool *cfg_chk,
510 err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
517 int vnic_dev_capable(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd)
523 err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
528 int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, size_t size,
538 err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait);
561 int vnic_dev_stats_clear(struct vnic_dev *vdev)
566 return vnic_dev_cmd(vdev, CMD_STATS_CLEAR, &a0, &a1, wait);
569 int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats)
575 if (!vdev->stats)
578 *stats = vdev->stats;
579 a0 = vdev->stats_res.idi_paddr;
582 bus_dmamap_sync(vdev->stats_res.idi_tag,
583 vdev->stats_res.idi_map,
585 rc = vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait);
586 bus_dmamap_sync(vdev->stats_res.idi_tag,
587 vdev->stats_res.idi_map,
595 int vnic_dev_counter_dma_cfg(struct vnic_dev *vdev, u32 period,
609 args[1] = vdev->flow_counters_res.idi_paddr;
611 bus_dmamap_sync(vdev->flow_counters_res.idi_tag,
612 vdev->flow_counters_res.idi_map,
614 err = vnic_dev_cmd_args(vdev, CMD_COUNTER_DMA_CONFIG, args, 3, wait);
615 bus_dmamap_sync(vdev->flow_counters_res.idi_tag,
616 vdev->flow_counters_res.idi_map,
621 vdev->flow_counters_dma_active = (num_counters != 0 &&
627 int vnic_dev_close(struct vnic_dev *vdev)
632 return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait);
635 int vnic_dev_enable_wait(struct vnic_dev *vdev)
640 if (vnic_dev_capable(vdev, CMD_ENABLE_WAIT))
641 return vnic_dev_cmd(vdev, CMD_ENABLE_WAIT, &a0, &a1, wait);
643 return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
646 int vnic_dev_disable(struct vnic_dev *vdev)
651 return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait);
654 int vnic_dev_open(struct vnic_dev *vdev, int arg)
659 return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait);
662 int vnic_dev_open_done(struct vnic_dev *vdev, int *done)
670 err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait);
679 int vnic_dev_get_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
688 err = vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
698 int vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast,
711 err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait);
718 int vnic_dev_add_addr(struct vnic_dev *vdev, u8 *addr)
728 err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
737 int vnic_dev_del_addr(struct vnic_dev *vdev, u8 *addr)
747 err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait);
756 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev *vdev,
762 if (vnic_dev_capable(vdev, CMD_IG_VLAN_REWRITE_MODE))
763 return vnic_dev_cmd(vdev, CMD_IG_VLAN_REWRITE_MODE,
769 void vnic_dev_set_reset_flag(struct vnic_dev *vdev, int state)
771 vdev->in_reset = state;
774 static inline int vnic_dev_in_reset(struct vnic_dev *vdev)
776 return vdev->in_reset;
779 int vnic_dev_notify_setcmd(struct vnic_dev *vdev,
786 bus_dmamap_sync(vdev->notify_res.idi_tag,
787 vdev->notify_res.idi_map,
790 bus_dmamap_sync(vdev->notify_res.idi_tag,
791 vdev->notify_res.idi_map,
793 if (!vnic_dev_in_reset(vdev)) {
794 vdev->notify = notify_addr;
795 vdev->notify_pa = notify_pa;
802 r = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
803 if (!vnic_dev_in_reset(vdev))
804 vdev->notify_sz = (r == 0) ? (u32)a1 : 0;
809 int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr)
816 if (vdev->notify || vdev->notify_pa) {
817 return vnic_dev_notify_setcmd(vdev, vdev->notify,
818 vdev->notify_pa, intr);
820 if (!vnic_dev_in_reset(vdev)) {
823 iflib_dma_alloc(vdev->softc->ctx,
825 &vdev->notify_res, BUS_DMA_NOWAIT);
826 notify_pa = vdev->notify_res.idi_paddr;
827 notify_addr = vdev->notify_res.idi_vaddr;
830 return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr);
833 int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev)
843 err = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
844 if (!vnic_dev_in_reset(vdev)) {
845 vdev->notify = NULL;
846 vdev->notify_pa = 0;
847 vdev->notify_sz = 0;
853 int vnic_dev_notify_unset(struct vnic_dev *vdev)
855 if (vdev->notify && !vnic_dev_in_reset(vdev)) {
856 iflib_dma_free(&vdev->notify_res);
859 return vnic_dev_notify_unsetcmd(vdev);
862 static int vnic_dev_notify_ready(struct vnic_dev *vdev)
865 unsigned int nwords = vdev->notify_sz / 4;
869 if (!vdev->notify || !vdev->notify_sz)
874 bus_dmamap_sync(vdev->notify_res.idi_tag,
875 vdev->notify_res.idi_map,
877 memcpy(&vdev->notify_copy, vdev->notify, vdev->notify_sz);
878 bus_dmamap_sync(vdev->notify_res.idi_tag,
879 vdev->notify_res.idi_map,
881 words = (u32 *)&vdev->notify_copy;
890 int vnic_dev_init(struct vnic_dev *vdev, int arg)
896 if (vnic_dev_capable(vdev, CMD_INIT))
897 r = vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait);
899 vnic_dev_cmd(vdev, CMD_INIT_v1, &a0, &a1, wait);
904 vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
905 vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
911 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev *vdev)
914 vdev->intr_coal_timer_info.mul = 2;
915 vdev->intr_coal_timer_info.div = 3;
916 vdev->intr_coal_timer_info.max_usec =
917 vnic_dev_intr_coal_timer_hw_to_usec(vdev, 0xffff);
920 int vnic_dev_link_status(struct vnic_dev *vdev)
922 if (!vnic_dev_notify_ready(vdev))
925 return vdev->notify_copy.link_state;
928 u32 vnic_dev_port_speed(struct vnic_dev *vdev)
930 if (!vnic_dev_notify_ready(vdev))
933 return vdev->notify_copy.port_speed;
936 u32 vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev *vdev, u32 usec)
938 return (usec * vdev->intr_coal_timer_info.mul) /
939 vdev->intr_coal_timer_info.div;
942 u32 vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev *vdev, u32 hw_cycles)
944 return (hw_cycles * vdev->intr_coal_timer_info.div) /
945 vdev->intr_coal_timer_info.mul;
948 u32 vnic_dev_get_intr_coal_timer_max(struct vnic_dev *vdev)
950 return vdev->intr_coal_timer_info.max_usec;
953 u32 vnic_dev_mtu(struct vnic_dev *vdev)
955 if (!vnic_dev_notify_ready(vdev))
958 return vdev->notify_copy.mtu;
961 void vnic_dev_set_intr_mode(struct vnic_dev *vdev,
964 vdev->intr_mode = intr_mode;
968 struct vnic_dev *vdev)
970 return vdev->intr_mode;
974 int vnic_dev_alloc_stats_mem(struct vnic_dev *vdev)
980 softc = vdev->softc;
983 iflib_dma_alloc(softc->ctx, sizeof(struct vnic_stats), &vdev->stats_res, 0);
984 vdev->stats = (struct vnic_stats *)vdev->stats_res.idi_vaddr;
985 return vdev->stats == NULL ? -ENOMEM : 0;
991 int vnic_dev_alloc_counter_mem(struct vnic_dev *vdev)
997 softc = vdev->softc;
1000 iflib_dma_alloc(softc->ctx, sizeof(struct vnic_counter_counts) * VNIC_MAX_FLOW_COUNTERS, &vdev->flow_counters_res, 0);
1001 vdev->flow_counters = (struct vnic_counter_counts *)vdev->flow_counters_res.idi_vaddr;
1002 vdev->flow_counters_dma_active = 0;
1003 return (vdev->flow_counters == NULL ? ENOMEM : 0);
1006 struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
1009 if (vnic_dev_discover_res(vdev, NULL, num_bars))
1012 vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0);
1013 if (!vdev->devcmd)
1016 return vdev;
1022 static int vnic_dev_init_devcmd1(struct vnic_dev *vdev)
1024 vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0);
1025 if (!vdev->devcmd)
1027 vdev->devcmd_rtn = _vnic_dev_cmd;
1032 static int vnic_dev_init_devcmd2(struct vnic_dev *vdev)
1040 if (vdev->devcmd2)
1043 vdev->devcmd2 = malloc(sizeof(*vdev->devcmd2), M_DEVBUF,
1046 if (!vdev->devcmd2) {
1050 vdev->devcmd2->color = 1;
1051 vdev->devcmd2->result_size = DEVCMD2_RING_SIZE;
1053 err = enic_wq_devcmd2_alloc(vdev, &vdev->devcmd2->wq, DEVCMD2_RING_SIZE,
1059 vdev->devcmd2->wq_ctrl = vdev->devcmd2->wq.ctrl;
1060 vdev->devcmd2->cmd_ring = vdev->devcmd2->wq.ring.descs;
1062 fetch_index = ENIC_BUS_READ_4(vdev->devcmd2->wq.ctrl, TX_FETCH_INDEX);
1066 enic_wq_init_start(&vdev->devcmd2->wq, 0, fetch_index, fetch_index, 0,
1068 vdev->devcmd2->posted = fetch_index;
1069 vnic_wq_enable(&vdev->devcmd2->wq);
1071 err = vnic_dev_alloc_desc_ring(vdev, &vdev->devcmd2->results_ring,
1076 vdev->devcmd2->result = vdev->devcmd2->results_ring.descs;
1077 vdev->args[0] = (u64)vdev->devcmd2->results_ring.base_addr |
1079 vdev->args[1] = DEVCMD2_RING_SIZE;
1081 err = _vnic_dev_cmd2(vdev, CMD_INITIALIZE_DEVCMD2, 1000);
1085 vdev->devcmd_rtn = _vnic_dev_cmd2;
1091 if (vdev->devcmd2->wq_ctrl)
1092 vnic_wq_free(&vdev->devcmd2->wq);
1093 if (vdev->devcmd2->result)
1094 vnic_dev_free_desc_ring(vdev, &vdev->devcmd2->results_ring);
1095 free(vdev->devcmd2, M_DEVBUF);
1096 vdev->devcmd2 = NULL;
1103 * @vdev: vdev of the device
1117 int vnic_dev_overlay_offload_ctrl(struct vnic_dev *vdev, u8 overlay, u8 config)
1123 return vnic_dev_cmd(vdev, CMD_OVERLAY_OFFLOAD_CTRL, &a0, &a1, wait);
1126 int vnic_dev_overlay_offload_cfg(struct vnic_dev *vdev, u8 overlay,
1133 return vnic_dev_cmd(vdev, CMD_OVERLAY_OFFLOAD_CFG, &a0, &a1, wait);
1136 int vnic_dev_capable_vxlan(struct vnic_dev *vdev)
1143 ret = vnic_dev_cmd(vdev, CMD_GET_SUPP_FEATURE_VER, &a0, &a1, wait);
1150 bool vnic_dev_counter_alloc(struct vnic_dev *vdev, uint32_t *idx)
1156 if (vnic_dev_cmd(vdev, CMD_COUNTER_ALLOC, &a0, &a1, wait))
1162 bool vnic_dev_counter_free(struct vnic_dev *vdev, uint32_t idx)
1168 return vnic_dev_cmd(vdev, CMD_COUNTER_FREE, &a0, &a1,
1172 bool vnic_dev_counter_query(struct vnic_dev *vdev, uint32_t idx,
1181 if (vnic_dev_cmd(vdev, CMD_COUNTER_QUERY, &a0, &a1, wait))
1187 *packets = vdev->flow_counters[idx].vcc_packets;
1188 *bytes = vdev->flow_counters[idx].vcc_bytes;
1193 device_t dev_from_vnic_dev(struct vnic_dev *vdev) {
1194 return (vdev->softc->dev);
1197 int vnic_dev_cmd_init(struct vnic_dev *vdev) {
1201 res = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD2, 0);
1203 err = vnic_dev_init_devcmd2(vdev);
1205 device_printf(dev_from_vnic_dev(vdev),
1211 err = vnic_dev_init_devcmd1(vdev);