Lines Matching refs:priv
54 gve_verify_driver_compatibility(struct gve_priv *priv) in gve_verify_driver_compatibility() argument
60 err = gve_dma_alloc_coherent(priv, sizeof(struct gve_driver_info), in gve_verify_driver_compatibility()
90 err = gve_adminq_verify_driver_compatibility(priv, in gve_verify_driver_compatibility()
103 gve_up(struct gve_priv *priv) in gve_up() argument
105 if_t ifp = priv->ifp; in gve_up()
108 GVE_IFACE_LOCK_ASSERT(priv->gve_iface_lock); in gve_up()
110 if (device_is_attached(priv->dev) == 0) { in gve_up()
111 device_printf(priv->dev, "Cannot bring the iface up when detached\n"); in gve_up()
115 if (gve_get_state_flag(priv, GVE_STATE_FLAG_QUEUES_UP)) in gve_up()
128 if (gve_is_qpl(priv)) { in gve_up()
129 err = gve_register_qpls(priv); in gve_up()
134 err = gve_create_rx_rings(priv); in gve_up()
138 err = gve_create_tx_rings(priv); in gve_up()
144 if (!gve_get_state_flag(priv, GVE_STATE_FLAG_LINK_UP)) { in gve_up()
146 gve_set_state_flag(priv, GVE_STATE_FLAG_LINK_UP); in gve_up()
149 gve_unmask_all_queue_irqs(priv); in gve_up()
150 gve_set_state_flag(priv, GVE_STATE_FLAG_QUEUES_UP); in gve_up()
151 priv->interface_up_cnt++; in gve_up()
155 gve_schedule_reset(priv); in gve_up()
160 gve_down(struct gve_priv *priv) in gve_down() argument
162 GVE_IFACE_LOCK_ASSERT(priv->gve_iface_lock); in gve_down()
164 if (!gve_get_state_flag(priv, GVE_STATE_FLAG_QUEUES_UP)) in gve_down()
167 if (gve_get_state_flag(priv, GVE_STATE_FLAG_LINK_UP)) { in gve_down()
168 if_link_state_change(priv->ifp, LINK_STATE_DOWN); in gve_down()
169 gve_clear_state_flag(priv, GVE_STATE_FLAG_LINK_UP); in gve_down()
172 if_setdrvflagbits(priv->ifp, IFF_DRV_OACTIVE, IFF_DRV_RUNNING); in gve_down()
174 if (gve_destroy_rx_rings(priv) != 0) in gve_down()
177 if (gve_destroy_tx_rings(priv) != 0) in gve_down()
180 if (gve_is_qpl(priv)) { in gve_down()
181 if (gve_unregister_qpls(priv) != 0) in gve_down()
185 if (gve_is_gqi(priv)) in gve_down()
186 gve_mask_all_queue_irqs(priv); in gve_down()
187 gve_clear_state_flag(priv, GVE_STATE_FLAG_QUEUES_UP); in gve_down()
188 priv->interface_down_cnt++; in gve_down()
192 gve_schedule_reset(priv); in gve_down()
198 struct gve_priv *priv = if_getsoftc(ifp); in gve_set_mtu() local
201 if ((new_mtu > priv->max_mtu) || (new_mtu < ETHERMIN)) { in gve_set_mtu()
202 device_printf(priv->dev, "Invalid new MTU setting. new mtu: %d max mtu: %d min mtu: %d\n", in gve_set_mtu()
203 new_mtu, priv->max_mtu, ETHERMIN); in gve_set_mtu()
207 err = gve_adminq_set_mtu(priv, new_mtu); in gve_set_mtu()
210 device_printf(priv->dev, "MTU set to %d\n", new_mtu); in gve_set_mtu()
213 device_printf(priv->dev, "Failed to set MTU to %d\n", new_mtu); in gve_set_mtu()
222 struct gve_priv *priv = (struct gve_priv *)arg; in gve_init() local
224 if (!gve_get_state_flag(priv, GVE_STATE_FLAG_QUEUES_UP)) { in gve_init()
225 GVE_IFACE_LOCK_LOCK(priv->gve_iface_lock); in gve_init()
226 gve_up(priv); in gve_init()
227 GVE_IFACE_LOCK_UNLOCK(priv->gve_iface_lock); in gve_init()
234 struct gve_priv *priv; in gve_ioctl() local
238 priv = if_getsoftc(ifp); in gve_ioctl()
245 GVE_IFACE_LOCK_LOCK(priv->gve_iface_lock); in gve_ioctl()
246 gve_down(priv); in gve_ioctl()
248 rc = gve_up(priv); in gve_ioctl()
249 GVE_IFACE_LOCK_UNLOCK(priv->gve_iface_lock); in gve_ioctl()
255 GVE_IFACE_LOCK_LOCK(priv->gve_iface_lock); in gve_ioctl()
256 rc = gve_up(priv); in gve_ioctl()
257 GVE_IFACE_LOCK_UNLOCK(priv->gve_iface_lock); in gve_ioctl()
261 GVE_IFACE_LOCK_LOCK(priv->gve_iface_lock); in gve_ioctl()
262 gve_down(priv); in gve_ioctl()
263 GVE_IFACE_LOCK_UNLOCK(priv->gve_iface_lock); in gve_ioctl()
271 GVE_IFACE_LOCK_LOCK(priv->gve_iface_lock); in gve_ioctl()
272 gve_down(priv); in gve_ioctl()
274 rc = gve_up(priv); in gve_ioctl()
275 GVE_IFACE_LOCK_UNLOCK(priv->gve_iface_lock); in gve_ioctl()
281 rc = ifmedia_ioctl(ifp, ifr, &priv->media, command); in gve_ioctl()
295 struct gve_priv *priv = if_getsoftc(ifp); in gve_media_change() local
297 device_printf(priv->dev, "Media change not supported\n"); in gve_media_change()
304 struct gve_priv *priv = if_getsoftc(ifp); in gve_media_status() local
306 GVE_IFACE_LOCK_LOCK(priv->gve_iface_lock); in gve_media_status()
311 if (gve_get_state_flag(priv, GVE_STATE_FLAG_LINK_UP)) { in gve_media_status()
318 GVE_IFACE_LOCK_UNLOCK(priv->gve_iface_lock); in gve_media_status()
324 struct gve_priv *priv; in gve_get_counter() local
332 priv = if_getsoftc(ifp); in gve_get_counter()
334 gve_accum_stats(priv, &rpackets, &rbytes, &rx_dropped_pkt, &tpackets, in gve_get_counter()
362 gve_setup_ifnet(device_t dev, struct gve_priv *priv) in gve_setup_ifnet() argument
367 ifp = priv->ifp = if_alloc(IFT_ETHER); in gve_setup_ifnet()
369 if_setsoftc(ifp, priv); in gve_setup_ifnet()
382 if (!gve_is_gqi(priv) && !gve_is_qpl(priv)) { in gve_setup_ifnet()
394 ifmedia_init(&priv->media, IFM_IMASK, gve_media_change, gve_media_status); in gve_setup_ifnet()
403 if ((priv->supported_features & GVE_SUP_JUMBO_FRAMES_MASK) != 0) in gve_setup_ifnet()
410 device_printf(priv->dev, "Setting initial MTU to %d\n", priv->max_mtu); in gve_setup_ifnet()
411 if_setmtu(ifp, priv->max_mtu); in gve_setup_ifnet()
413 ether_ifattach(ifp, priv->mac); in gve_setup_ifnet()
415 ifmedia_add(&priv->media, IFM_ETHER | IFM_AUTO, 0, NULL); in gve_setup_ifnet()
416 ifmedia_set(&priv->media, IFM_ETHER | IFM_AUTO); in gve_setup_ifnet()
420 gve_alloc_counter_array(struct gve_priv *priv) in gve_alloc_counter_array() argument
424 err = gve_dma_alloc_coherent(priv, sizeof(uint32_t) * priv->num_event_counters, in gve_alloc_counter_array()
425 PAGE_SIZE, &priv->counter_array_mem); in gve_alloc_counter_array()
429 priv->counters = priv->counter_array_mem.cpu_addr; in gve_alloc_counter_array()
434 gve_free_counter_array(struct gve_priv *priv) in gve_free_counter_array() argument
436 if (priv->counters != NULL) in gve_free_counter_array()
437 gve_dma_free_coherent(&priv->counter_array_mem); in gve_free_counter_array()
438 priv->counter_array_mem = (struct gve_dma_handle){}; in gve_free_counter_array()
442 gve_alloc_irq_db_array(struct gve_priv *priv) in gve_alloc_irq_db_array() argument
446 err = gve_dma_alloc_coherent(priv, in gve_alloc_irq_db_array()
447 sizeof(struct gve_irq_db) * (priv->num_queues), PAGE_SIZE, in gve_alloc_irq_db_array()
448 &priv->irqs_db_mem); in gve_alloc_irq_db_array()
452 priv->irq_db_indices = priv->irqs_db_mem.cpu_addr; in gve_alloc_irq_db_array()
457 gve_free_irq_db_array(struct gve_priv *priv) in gve_free_irq_db_array() argument
459 if (priv->irq_db_indices != NULL) in gve_free_irq_db_array()
460 gve_dma_free_coherent(&priv->irqs_db_mem); in gve_free_irq_db_array()
461 priv->irqs_db_mem = (struct gve_dma_handle){}; in gve_free_irq_db_array()
465 gve_free_rings(struct gve_priv *priv) in gve_free_rings() argument
467 gve_free_irqs(priv); in gve_free_rings()
468 gve_free_tx_rings(priv); in gve_free_rings()
469 gve_free_rx_rings(priv); in gve_free_rings()
470 if (gve_is_qpl(priv)) in gve_free_rings()
471 gve_free_qpls(priv); in gve_free_rings()
475 gve_alloc_rings(struct gve_priv *priv) in gve_alloc_rings() argument
479 if (gve_is_qpl(priv)) { in gve_alloc_rings()
480 err = gve_alloc_qpls(priv); in gve_alloc_rings()
485 err = gve_alloc_rx_rings(priv); in gve_alloc_rings()
489 err = gve_alloc_tx_rings(priv); in gve_alloc_rings()
493 err = gve_alloc_irqs(priv); in gve_alloc_rings()
500 gve_free_rings(priv); in gve_alloc_rings()
505 gve_deconfigure_resources(struct gve_priv *priv) in gve_deconfigure_resources() argument
509 if (gve_get_state_flag(priv, GVE_STATE_FLAG_RESOURCES_OK)) { in gve_deconfigure_resources()
510 err = gve_adminq_deconfigure_device_resources(priv); in gve_deconfigure_resources()
512 device_printf(priv->dev, "Failed to deconfigure device resources: err=%d\n", in gve_deconfigure_resources()
517 device_printf(priv->dev, "Deconfigured device resources\n"); in gve_deconfigure_resources()
518 gve_clear_state_flag(priv, GVE_STATE_FLAG_RESOURCES_OK); in gve_deconfigure_resources()
521 gve_free_irq_db_array(priv); in gve_deconfigure_resources()
522 gve_free_counter_array(priv); in gve_deconfigure_resources()
524 if (priv->ptype_lut_dqo) { in gve_deconfigure_resources()
525 free(priv->ptype_lut_dqo, M_GVE); in gve_deconfigure_resources()
526 priv->ptype_lut_dqo = NULL; in gve_deconfigure_resources()
531 gve_configure_resources(struct gve_priv *priv) in gve_configure_resources() argument
535 if (gve_get_state_flag(priv, GVE_STATE_FLAG_RESOURCES_OK)) in gve_configure_resources()
538 err = gve_alloc_counter_array(priv); in gve_configure_resources()
542 err = gve_alloc_irq_db_array(priv); in gve_configure_resources()
546 err = gve_adminq_configure_device_resources(priv); in gve_configure_resources()
548 device_printf(priv->dev, "Failed to configure device resources: err=%d\n", in gve_configure_resources()
554 if (!gve_is_gqi(priv)) { in gve_configure_resources()
555 priv->ptype_lut_dqo = malloc(sizeof(*priv->ptype_lut_dqo), M_GVE, in gve_configure_resources()
558 err = gve_adminq_get_ptype_map_dqo(priv, priv->ptype_lut_dqo); in gve_configure_resources()
560 device_printf(priv->dev, "Failed to configure ptype lut: err=%d\n", in gve_configure_resources()
566 gve_set_state_flag(priv, GVE_STATE_FLAG_RESOURCES_OK); in gve_configure_resources()
568 device_printf(priv->dev, "Configured device resources\n"); in gve_configure_resources()
572 gve_deconfigure_resources(priv); in gve_configure_resources()
577 gve_set_queue_cnts(struct gve_priv *priv) in gve_set_queue_cnts() argument
579 priv->tx_cfg.max_queues = gve_reg_bar_read_4(priv, MAX_TX_QUEUES); in gve_set_queue_cnts()
580 priv->rx_cfg.max_queues = gve_reg_bar_read_4(priv, MAX_RX_QUEUES); in gve_set_queue_cnts()
581 priv->tx_cfg.num_queues = priv->tx_cfg.max_queues; in gve_set_queue_cnts()
582 priv->rx_cfg.num_queues = priv->rx_cfg.max_queues; in gve_set_queue_cnts()
584 if (priv->default_num_queues > 0) { in gve_set_queue_cnts()
585 priv->tx_cfg.num_queues = MIN(priv->default_num_queues, in gve_set_queue_cnts()
586 priv->tx_cfg.num_queues); in gve_set_queue_cnts()
587 priv->rx_cfg.num_queues = MIN(priv->default_num_queues, in gve_set_queue_cnts()
588 priv->rx_cfg.num_queues); in gve_set_queue_cnts()
591 priv->num_queues = priv->tx_cfg.num_queues + priv->rx_cfg.num_queues; in gve_set_queue_cnts()
592 priv->mgmt_msix_idx = priv->num_queues; in gve_set_queue_cnts()
596 gve_alloc_adminq_and_describe_device(struct gve_priv *priv) in gve_alloc_adminq_and_describe_device() argument
600 if ((err = gve_adminq_alloc(priv)) != 0) in gve_alloc_adminq_and_describe_device()
603 if ((err = gve_verify_driver_compatibility(priv)) != 0) { in gve_alloc_adminq_and_describe_device()
604 device_printf(priv->dev, in gve_alloc_adminq_and_describe_device()
609 if ((err = gve_adminq_describe_device(priv)) != 0) in gve_alloc_adminq_and_describe_device()
612 gve_set_queue_cnts(priv); in gve_alloc_adminq_and_describe_device()
614 priv->num_registered_pages = 0; in gve_alloc_adminq_and_describe_device()
618 gve_release_adminq(priv); in gve_alloc_adminq_and_describe_device()
623 gve_schedule_reset(struct gve_priv *priv) in gve_schedule_reset() argument
625 if (gve_get_state_flag(priv, GVE_STATE_FLAG_IN_RESET)) in gve_schedule_reset()
628 device_printf(priv->dev, "Scheduling reset task!\n"); in gve_schedule_reset()
629 gve_set_state_flag(priv, GVE_STATE_FLAG_DO_RESET); in gve_schedule_reset()
630 taskqueue_enqueue(priv->service_tq, &priv->service_task); in gve_schedule_reset()
634 gve_destroy(struct gve_priv *priv) in gve_destroy() argument
636 gve_down(priv); in gve_destroy()
637 gve_deconfigure_resources(priv); in gve_destroy()
638 gve_release_adminq(priv); in gve_destroy()
642 gve_restore(struct gve_priv *priv) in gve_restore() argument
646 err = gve_adminq_alloc(priv); in gve_restore()
650 err = gve_configure_resources(priv); in gve_restore()
654 err = gve_up(priv); in gve_restore()
661 device_printf(priv->dev, "Restore failed!\n"); in gve_restore()
666 gve_handle_reset(struct gve_priv *priv) in gve_handle_reset() argument
668 if (!gve_get_state_flag(priv, GVE_STATE_FLAG_DO_RESET)) in gve_handle_reset()
671 gve_clear_state_flag(priv, GVE_STATE_FLAG_DO_RESET); in gve_handle_reset()
672 gve_set_state_flag(priv, GVE_STATE_FLAG_IN_RESET); in gve_handle_reset()
674 GVE_IFACE_LOCK_LOCK(priv->gve_iface_lock); in gve_handle_reset()
676 if_setdrvflagbits(priv->ifp, IFF_DRV_OACTIVE, IFF_DRV_RUNNING); in gve_handle_reset()
677 if_link_state_change(priv->ifp, LINK_STATE_DOWN); in gve_handle_reset()
678 gve_clear_state_flag(priv, GVE_STATE_FLAG_LINK_UP); in gve_handle_reset()
689 gve_release_adminq(priv); in gve_handle_reset()
690 gve_clear_state_flag(priv, GVE_STATE_FLAG_RESOURCES_OK); in gve_handle_reset()
691 gve_clear_state_flag(priv, GVE_STATE_FLAG_QPLREG_OK); in gve_handle_reset()
692 gve_clear_state_flag(priv, GVE_STATE_FLAG_RX_RINGS_OK); in gve_handle_reset()
693 gve_clear_state_flag(priv, GVE_STATE_FLAG_TX_RINGS_OK); in gve_handle_reset()
695 gve_down(priv); in gve_handle_reset()
696 gve_restore(priv); in gve_handle_reset()
698 GVE_IFACE_LOCK_UNLOCK(priv->gve_iface_lock); in gve_handle_reset()
700 priv->reset_cnt++; in gve_handle_reset()
701 gve_clear_state_flag(priv, GVE_STATE_FLAG_IN_RESET); in gve_handle_reset()
705 gve_handle_link_status(struct gve_priv *priv) in gve_handle_link_status() argument
707 uint32_t status = gve_reg_bar_read_4(priv, DEVICE_STATUS); in gve_handle_link_status()
710 if (link_up == gve_get_state_flag(priv, GVE_STATE_FLAG_LINK_UP)) in gve_handle_link_status()
715 device_printf(priv->dev, "Device link is up.\n"); in gve_handle_link_status()
716 if_link_state_change(priv->ifp, LINK_STATE_UP); in gve_handle_link_status()
717 gve_set_state_flag(priv, GVE_STATE_FLAG_LINK_UP); in gve_handle_link_status()
719 device_printf(priv->dev, "Device link is down.\n"); in gve_handle_link_status()
720 if_link_state_change(priv->ifp, LINK_STATE_DOWN); in gve_handle_link_status()
721 gve_clear_state_flag(priv, GVE_STATE_FLAG_LINK_UP); in gve_handle_link_status()
728 struct gve_priv *priv = (struct gve_priv *)arg; in gve_service_task() local
729 uint32_t status = gve_reg_bar_read_4(priv, DEVICE_STATUS); in gve_service_task()
732 !gve_get_state_flag(priv, GVE_STATE_FLAG_IN_RESET)) { in gve_service_task()
733 device_printf(priv->dev, "Device requested reset\n"); in gve_service_task()
734 gve_set_state_flag(priv, GVE_STATE_FLAG_DO_RESET); in gve_service_task()
737 gve_handle_reset(priv); in gve_service_task()
738 gve_handle_link_status(priv); in gve_service_task()
761 gve_free_sys_res_mem(struct gve_priv *priv) in gve_free_sys_res_mem() argument
763 if (priv->msix_table != NULL) in gve_free_sys_res_mem()
764 bus_release_resource(priv->dev, SYS_RES_MEMORY, in gve_free_sys_res_mem()
765 rman_get_rid(priv->msix_table), priv->msix_table); in gve_free_sys_res_mem()
767 if (priv->db_bar != NULL) in gve_free_sys_res_mem()
768 bus_release_resource(priv->dev, SYS_RES_MEMORY, in gve_free_sys_res_mem()
769 rman_get_rid(priv->db_bar), priv->db_bar); in gve_free_sys_res_mem()
771 if (priv->reg_bar != NULL) in gve_free_sys_res_mem()
772 bus_release_resource(priv->dev, SYS_RES_MEMORY, in gve_free_sys_res_mem()
773 rman_get_rid(priv->reg_bar), priv->reg_bar); in gve_free_sys_res_mem()
779 struct gve_priv *priv; in gve_attach() local
786 priv = device_get_softc(dev); in gve_attach()
787 priv->dev = dev; in gve_attach()
788 GVE_IFACE_LOCK_INIT(priv->gve_iface_lock); in gve_attach()
793 priv->reg_bar = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in gve_attach()
795 if (priv->reg_bar == NULL) { in gve_attach()
802 priv->db_bar = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in gve_attach()
804 if (priv->db_bar == NULL) { in gve_attach()
810 rid = pci_msix_table_bar(priv->dev); in gve_attach()
811 priv->msix_table = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in gve_attach()
813 if (priv->msix_table == NULL) { in gve_attach()
819 err = gve_alloc_adminq_and_describe_device(priv); in gve_attach()
823 err = gve_configure_resources(priv); in gve_attach()
827 err = gve_alloc_rings(priv); in gve_attach()
831 gve_setup_ifnet(dev, priv); in gve_attach()
833 priv->rx_copybreak = GVE_DEFAULT_RX_COPYBREAK; in gve_attach()
835 bus_write_multi_1(priv->reg_bar, DRIVER_VERSION, GVE_DRIVER_VERSION, in gve_attach()
838 TASK_INIT(&priv->service_task, 0, gve_service_task, priv); in gve_attach()
839 priv->service_tq = taskqueue_create("gve service", M_WAITOK | M_ZERO, in gve_attach()
840 taskqueue_thread_enqueue, &priv->service_tq); in gve_attach()
841 taskqueue_start_threads(&priv->service_tq, 1, PI_NET, "%s service tq", in gve_attach()
842 device_get_nameunit(priv->dev)); in gve_attach()
844 gve_setup_sysctl(priv); in gve_attach()
847 device_printf(priv->dev, "Successfully attached %s", GVE_DRIVER_VERSION); in gve_attach()
851 gve_free_rings(priv); in gve_attach()
852 gve_deconfigure_resources(priv); in gve_attach()
853 gve_release_adminq(priv); in gve_attach()
854 gve_free_sys_res_mem(priv); in gve_attach()
855 GVE_IFACE_LOCK_DESTROY(priv->gve_iface_lock); in gve_attach()
862 struct gve_priv *priv = device_get_softc(dev); in gve_detach() local
863 if_t ifp = priv->ifp; in gve_detach()
872 GVE_IFACE_LOCK_LOCK(priv->gve_iface_lock); in gve_detach()
873 gve_destroy(priv); in gve_detach()
874 GVE_IFACE_LOCK_UNLOCK(priv->gve_iface_lock); in gve_detach()
876 gve_free_rings(priv); in gve_detach()
877 gve_free_sys_res_mem(priv); in gve_detach()
878 GVE_IFACE_LOCK_DESTROY(priv->gve_iface_lock); in gve_detach()
880 while (taskqueue_cancel(priv->service_tq, &priv->service_task, NULL)) in gve_detach()
881 taskqueue_drain(priv->service_tq, &priv->service_task); in gve_detach()
882 taskqueue_free(priv->service_tq); in gve_detach()