Lines Matching refs:efx

25 #include "efx.h"
103 static void efx_remove_port(struct efx_nic *efx);
104 static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog);
115 static void efx_fini_port(struct efx_nic *efx);
117 static int efx_probe_port(struct efx_nic *efx)
121 netif_dbg(efx, probe, efx->net_dev, "create port\n");
124 efx->phy_mode = PHY_MODE_SPECIAL;
127 rc = efx->type->probe_port(efx);
132 eth_hw_addr_set(efx->net_dev, efx->net_dev->perm_addr);
137 static int efx_init_port(struct efx_nic *efx)
141 netif_dbg(efx, drv, efx->net_dev, "init port\n");
143 mutex_lock(&efx->mac_lock);
145 efx->port_initialized = true;
148 rc = efx_mcdi_port_reconfigure(efx);
152 mutex_unlock(&efx->mac_lock);
156 mutex_unlock(&efx->mac_lock);
160 static void efx_fini_port(struct efx_nic *efx)
162 netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
164 if (!efx->port_initialized)
167 efx->port_initialized = false;
169 efx->link_state.up = false;
170 efx_link_status_changed(efx);
173 static void efx_remove_port(struct efx_nic *efx)
175 netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
177 efx->type->remove_port(efx);
196 static void efx_associate(struct efx_nic *efx)
200 if (efx->primary == efx) {
203 netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
204 list_add_tail(&efx->node, &efx_primary_list);
208 if (efx_same_controller(efx, other)) {
212 pci_name(efx->pci_dev),
213 efx->net_dev->name);
215 &efx->secondary_list);
216 other->primary = efx;
223 if (efx_same_controller(efx, other)) {
224 netif_dbg(efx, probe, efx->net_dev,
228 list_add_tail(&efx->node,
230 efx->primary = other;
235 netif_dbg(efx, probe, efx->net_dev,
237 list_add_tail(&efx->node, &efx_unassociated_list);
241 static void efx_dissociate(struct efx_nic *efx)
245 list_del(&efx->node);
246 efx->primary = NULL;
248 list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
257 static int efx_probe_nic(struct efx_nic *efx)
261 netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
264 rc = efx->type->probe(efx);
269 if (!efx->max_channels || !efx->max_tx_channels) {
270 netif_err(efx, drv, efx->net_dev,
280 rc = efx_probe_interrupts(efx);
284 rc = efx_set_channels(efx);
289 rc = efx->type->dimension_resources(efx);
295 efx_remove_interrupts(efx);
299 if (efx->n_channels > 1)
300 netdev_rss_key_fill(efx->rss_context.rx_hash_key,
301 sizeof(efx->rss_context.rx_hash_key));
302 efx_set_default_rx_indir_table(efx, &efx->rss_context);
305 efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
306 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
312 efx_remove_interrupts(efx);
314 efx->type->remove(efx);
318 static void efx_remove_nic(struct efx_nic *efx)
320 netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
322 efx_remove_interrupts(efx);
323 efx->type->remove(efx);
332 static int efx_probe_all(struct efx_nic *efx)
336 rc = efx_probe_nic(efx);
338 netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
342 rc = efx_probe_port(efx);
344 netif_err(efx, probe, efx->net_dev, "failed to create port\n");
349 if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
355 rc = efx->type->vswitching_probe(efx);
357 netif_warn(efx, probe, efx->net_dev,
362 rc = efx_probe_filters(efx);
364 netif_err(efx, probe, efx->net_dev,
369 rc = efx_probe_channels(efx);
373 efx->state = STATE_NET_DOWN;
378 efx_remove_filters(efx);
381 efx->type->vswitching_remove(efx);
384 efx_remove_port(efx);
386 efx_remove_nic(efx);
391 static void efx_remove_all(struct efx_nic *efx)
394 efx_xdp_setup_prog(efx, NULL);
397 efx_remove_channels(efx);
398 efx_remove_filters(efx);
400 efx->type->vswitching_remove(efx);
402 efx_remove_port(efx);
403 efx_remove_nic(efx);
411 unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
415 if (usecs * 1000 < efx->timer_quantum_ns)
417 return usecs * 1000 / efx->timer_quantum_ns;
420 unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
425 return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
429 int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
436 EFX_ASSERT_RESET_SERIALISED(efx);
438 timer_max_us = efx->timer_max_ns / 1000;
443 if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
445 netif_err(efx, drv, efx->net_dev, "Channels are shared. "
450 efx->irq_rx_adaptive = rx_adaptive;
451 efx->irq_rx_moderation_us = rx_usecs;
452 efx_for_each_channel(channel, efx) {
464 void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
467 *rx_adaptive = efx->irq_rx_adaptive;
468 *rx_usecs = efx->irq_rx_moderation_us;
474 if (efx->tx_channel_offset == 0) {
479 tx_channel = efx->channel[efx->tx_channel_offset];
495 struct efx_nic *efx = efx_netdev_priv(net_dev);
499 return efx_ptp_set_ts_config(efx, ifr);
501 return efx_ptp_get_ts_config(efx, ifr);
508 return mdio_mii_ioctl(&efx->mdio, data, cmd);
520 struct efx_nic *efx = efx_netdev_priv(net_dev);
523 netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
526 rc = efx_check_disabled(efx);
529 if (efx->phy_mode & PHY_MODE_SPECIAL)
531 if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
536 efx_link_status_changed(efx);
538 efx_start_all(efx);
539 if (efx->state == STATE_DISABLED || efx->reset_pending)
540 netif_device_detach(efx->net_dev);
542 efx->state = STATE_NET_UP;
553 struct efx_nic *efx = efx_netdev_priv(net_dev);
555 netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
559 efx_stop_all(efx);
566 struct efx_nic *efx = efx_netdev_priv(net_dev);
568 if (efx->type->vlan_rx_add_vid)
569 return efx->type->vlan_rx_add_vid(efx, proto, vid);
576 struct efx_nic *efx = efx_netdev_priv(net_dev);
578 if (efx->type->vlan_rx_kill_vid)
579 return efx->type->vlan_rx_kill_vid(efx, proto, vid);
615 static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)
619 if (efx->xdp_rxq_info_failed) {
620 netif_err(efx, drv, efx->net_dev,
625 if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) {
626 netif_err(efx, drv, efx->net_dev,
628 efx->net_dev->mtu, efx_xdp_max_mtu(efx));
632 old_prog = rtnl_dereference(efx->xdp_prog);
633 rcu_assign_pointer(efx->xdp_prog, prog);
644 struct efx_nic *efx = efx_netdev_priv(dev);
648 return efx_xdp_setup_prog(efx, xdp->prog);
657 struct efx_nic *efx = efx_netdev_priv(dev);
662 return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH);
665 static void efx_update_name(struct efx_nic *efx)
667 strcpy(efx->name, efx->net_dev->name);
668 efx_mtd_rename(efx);
669 efx_set_channel_names(efx);
691 struct efx_nic *efx = dev_get_drvdata(dev);
692 return sprintf(buf, "%d\n", efx->phy_type);
696 static int efx_register_netdev(struct efx_nic *efx)
698 struct net_device *net_dev = efx->net_dev;
703 net_dev->irq = efx->pci_dev->irq;
705 if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
718 if (efx->reset_pending) {
719 pci_err(efx->pci_dev, "aborting probe due to scheduled reset\n");
727 efx_update_name(efx);
736 efx_for_each_channel(channel, efx) {
742 efx_associate(efx);
744 efx->state = STATE_NET_DOWN;
748 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
750 netif_err(efx, drv, efx->net_dev,
755 efx_init_mcdi_logging(efx);
761 efx_dissociate(efx);
764 efx->state = STATE_UNINIT;
766 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
770 static void efx_unregister_netdev(struct efx_nic *efx)
772 if (!efx->net_dev)
775 if (WARN_ON(efx_netdev_priv(efx->net_dev) != efx))
778 if (efx_dev_registered(efx)) {
779 strscpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
780 efx_fini_mcdi_logging(efx);
781 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
782 unregister_netdev(efx->net_dev);
819 void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
824 efx_for_each_channel(channel, efx)
827 stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
839 static void efx_pci_remove_main(struct efx_nic *efx)
844 WARN_ON(efx_net_active(efx->state));
845 efx_flush_reset_workqueue(efx);
847 efx_disable_interrupts(efx);
848 efx_clear_interrupt_affinity(efx);
849 efx_nic_fini_interrupt(efx);
850 efx_fini_port(efx);
851 efx->type->fini(efx);
852 efx_fini_napi(efx);
853 efx_remove_all(efx);
863 struct efx_nic *efx;
865 efx = pci_get_drvdata(pci_dev);
866 if (!efx)
871 efx_dissociate(efx);
872 dev_close(efx->net_dev);
873 efx_disable_interrupts(efx);
874 efx->state = STATE_UNINIT;
877 if (efx->type->sriov_fini)
878 efx->type->sriov_fini(efx);
880 efx_fini_devlink_lock(efx);
881 efx_unregister_netdev(efx);
883 efx_mtd_remove(efx);
885 efx_pci_remove_main(efx);
887 efx_fini_io(efx);
888 pci_dbg(efx->pci_dev, "shutdown successful\n");
890 efx_fini_devlink_and_unlock(efx);
891 efx_fini_struct(efx);
892 free_netdev(efx->net_dev);
893 probe_data = container_of(efx, struct efx_probe_data, efx);
901 static void efx_probe_vpd_strings(struct efx_nic *efx)
903 struct pci_dev *dev = efx->pci_dev;
926 efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL);
935 static int efx_pci_probe_main(struct efx_nic *efx)
940 rc = efx_probe_all(efx);
944 efx_init_napi(efx);
946 down_write(&efx->filter_sem);
947 rc = efx->type->init(efx);
948 up_write(&efx->filter_sem);
950 pci_err(efx->pci_dev, "failed to initialise NIC\n");
954 rc = efx_init_port(efx);
956 netif_err(efx, probe, efx->net_dev,
961 rc = efx_nic_init_interrupt(efx);
965 efx_set_interrupt_affinity(efx);
966 rc = efx_enable_interrupts(efx);
973 efx_clear_interrupt_affinity(efx);
974 efx_nic_fini_interrupt(efx);
976 efx_fini_port(efx);
978 efx->type->fini(efx);
980 efx_fini_napi(efx);
981 efx_remove_all(efx);
986 static int efx_pci_probe_post_io(struct efx_nic *efx)
988 struct net_device *net_dev = efx->net_dev;
989 int rc = efx_pci_probe_main(efx);
994 if (efx->type->sriov_init) {
995 rc = efx->type->sriov_init(efx);
997 pci_err(efx->pci_dev, "SR-IOV can't be enabled rc %d\n",
1002 net_dev->features |= efx->type->offload_features;
1005 if (efx->type->tso_versions && efx->type->tso_versions(efx))
1014 net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
1024 net_dev->features |= efx->fixed_features;
1031 rc = efx_probe_devlink_and_lock(efx);
1033 pci_err(efx->pci_dev, "devlink registration failed");
1035 rc = efx_register_netdev(efx);
1036 efx_probe_devlink_unlock(efx);
1040 efx_pci_remove_main(efx);
1058 struct efx_nic *efx;
1066 efx = &probe_data->efx;
1076 efx->net_dev = net_dev;
1077 efx->type = (const struct efx_nic_type *) entry->driver_data;
1078 efx->fixed_features |= NETIF_F_HIGHDMA;
1080 pci_set_drvdata(pci_dev, efx);
1082 rc = efx_init_struct(efx, pci_dev);
1085 efx->mdio.dev = net_dev;
1089 if (!efx->type->is_vf)
1090 efx_probe_vpd_strings(efx);
1093 rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask,
1094 efx->type->mem_map_size(efx));
1098 rc = efx_pci_probe_post_io(efx);
1103 efx->reset_pending = 0;
1104 rc = efx_pci_probe_post_io(efx);
1113 efx->reset_pending = 0;
1114 rc = efx_pci_probe_post_io(efx);
1120 netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
1124 rc = efx_mtd_probe(efx);
1127 netif_warn(efx, probe, efx->net_dev,
1130 if (efx->type->udp_tnl_push_ports)
1131 efx->type->udp_tnl_push_ports(efx);
1136 efx_fini_io(efx);
1138 efx_fini_struct(efx);
1141 netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
1155 struct efx_nic *efx = pci_get_drvdata(dev);
1157 if (efx->type->sriov_configure) {
1158 rc = efx->type->sriov_configure(efx, num_vfs);
1170 struct efx_nic *efx = dev_get_drvdata(dev);
1174 if (efx_net_active(efx->state)) {
1175 efx_device_detach_sync(efx);
1177 efx_stop_all(efx);
1178 efx_disable_interrupts(efx);
1180 efx->state = efx_freeze(efx->state);
1190 struct efx_nic *efx = pci_get_drvdata(pci_dev);
1192 if (!efx)
1202 struct efx_nic *efx = dev_get_drvdata(dev);
1206 if (efx_frozen(efx->state)) {
1207 rc = efx_enable_interrupts(efx);
1211 mutex_lock(&efx->mac_lock);
1212 efx_mcdi_port_reconfigure(efx);
1213 mutex_unlock(&efx->mac_lock);
1215 efx_start_all(efx);
1217 efx_device_attach_if_not_resetting(efx);
1219 efx->state = efx_thaw(efx->state);
1221 efx->type->resume_wol(efx);
1227 efx_queue_reset_work(efx);
1240 struct efx_nic *efx = pci_get_drvdata(pci_dev);
1242 efx->type->fini(efx);
1244 efx->reset_pending = 0;
1254 struct efx_nic *efx = pci_get_drvdata(pci_dev);
1264 pci_set_master(efx->pci_dev);
1265 rc = efx->type->reset(efx, RESET_TYPE_ALL);
1268 down_write(&efx->filter_sem);
1269 rc = efx->type->init(efx);
1270 up_write(&efx->filter_sem);