0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "net_driver.h"
0012 #include "mcdi_port_common.h"
0013 #include "mcdi_functions.h"
0014 #include "efx_common.h"
0015 #include "efx_channels.h"
0016 #include "tx_common.h"
0017 #include "ef100_netdev.h"
0018 #include "ef100_ethtool.h"
0019 #include "nic_common.h"
0020 #include "ef100_nic.h"
0021 #include "ef100_tx.h"
0022 #include "ef100_regs.h"
0023 #include "mcdi_filters.h"
0024 #include "rx_common.h"
0025 #include "ef100_sriov.h"
0026
0027 static void ef100_update_name(struct efx_nic *efx)
0028 {
0029 strcpy(efx->name, efx->net_dev->name);
0030 }
0031
0032 static int ef100_alloc_vis(struct efx_nic *efx, unsigned int *allocated_vis)
0033 {
0034
0035
0036
0037
0038 unsigned int tx_vis = efx->n_tx_channels + efx->n_extra_tx_channels;
0039 unsigned int rx_vis = efx->n_rx_channels;
0040 unsigned int min_vis, max_vis;
0041
0042 EFX_WARN_ON_PARANOID(efx->tx_queues_per_channel != 1);
0043
0044 tx_vis += efx->n_xdp_channels * efx->xdp_tx_per_channel;
0045
0046 max_vis = max(rx_vis, tx_vis);
0047
0048
0049
0050 min_vis = max_vis;
0051
0052 return efx_mcdi_alloc_vis(efx, min_vis, max_vis,
0053 NULL, allocated_vis);
0054 }
0055
0056 static int ef100_remap_bar(struct efx_nic *efx, int max_vis)
0057 {
0058 unsigned int uc_mem_map_size;
0059 void __iomem *membase;
0060
0061 efx->max_vis = max_vis;
0062 uc_mem_map_size = PAGE_ALIGN(max_vis * efx->vi_stride);
0063
0064
0065 membase = ioremap(efx->membase_phys, uc_mem_map_size);
0066 if (!membase) {
0067 netif_err(efx, probe, efx->net_dev,
0068 "could not extend memory BAR to %x\n",
0069 uc_mem_map_size);
0070 return -ENOMEM;
0071 }
0072 iounmap(efx->membase);
0073 efx->membase = membase;
0074 return 0;
0075 }
0076
0077
0078
0079
0080
0081 static int ef100_net_stop(struct net_device *net_dev)
0082 {
0083 struct efx_nic *efx = efx_netdev_priv(net_dev);
0084
0085 netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
0086 raw_smp_processor_id());
0087
0088 efx_detach_reps(efx);
0089 netif_stop_queue(net_dev);
0090 efx_stop_all(efx);
0091 efx_mcdi_mac_fini_stats(efx);
0092 efx_disable_interrupts(efx);
0093 efx_clear_interrupt_affinity(efx);
0094 efx_nic_fini_interrupt(efx);
0095 efx_remove_filters(efx);
0096 efx_fini_napi(efx);
0097 efx_remove_channels(efx);
0098 efx_mcdi_free_vis(efx);
0099 efx_remove_interrupts(efx);
0100
0101 efx->state = STATE_NET_DOWN;
0102
0103 return 0;
0104 }
0105
0106
0107 static int ef100_net_open(struct net_device *net_dev)
0108 {
0109 struct efx_nic *efx = efx_netdev_priv(net_dev);
0110 unsigned int allocated_vis;
0111 int rc;
0112
0113 ef100_update_name(efx);
0114 netif_dbg(efx, ifup, net_dev, "opening device on CPU %d\n",
0115 raw_smp_processor_id());
0116
0117 rc = efx_check_disabled(efx);
0118 if (rc)
0119 goto fail;
0120
0121 rc = efx_probe_interrupts(efx);
0122 if (rc)
0123 goto fail;
0124
0125 rc = efx_set_channels(efx);
0126 if (rc)
0127 goto fail;
0128
0129 rc = efx_mcdi_free_vis(efx);
0130 if (rc)
0131 goto fail;
0132
0133 rc = ef100_alloc_vis(efx, &allocated_vis);
0134 if (rc)
0135 goto fail;
0136
0137 rc = efx_probe_channels(efx);
0138 if (rc)
0139 return rc;
0140
0141 rc = ef100_remap_bar(efx, allocated_vis);
0142 if (rc)
0143 goto fail;
0144
0145 efx_init_napi(efx);
0146
0147 rc = efx_probe_filters(efx);
0148 if (rc)
0149 goto fail;
0150
0151 rc = efx_nic_init_interrupt(efx);
0152 if (rc)
0153 goto fail;
0154 efx_set_interrupt_affinity(efx);
0155
0156 rc = efx_enable_interrupts(efx);
0157 if (rc)
0158 goto fail;
0159
0160
0161
0162
0163 (void) efx_mcdi_poll_reboot(efx);
0164
0165 rc = efx_mcdi_mac_init_stats(efx);
0166 if (rc)
0167 goto fail;
0168
0169 efx_start_all(efx);
0170
0171
0172
0173
0174 mutex_lock(&efx->mac_lock);
0175 if (efx_mcdi_phy_poll(efx))
0176 efx_link_status_changed(efx);
0177 mutex_unlock(&efx->mac_lock);
0178
0179 efx->state = STATE_NET_UP;
0180 if (netif_running(efx->net_dev))
0181 efx_attach_reps(efx);
0182
0183 return 0;
0184
0185 fail:
0186 ef100_net_stop(net_dev);
0187 return rc;
0188 }
0189
0190
0191
0192
0193
0194
0195
0196
0197 static netdev_tx_t ef100_hard_start_xmit(struct sk_buff *skb,
0198 struct net_device *net_dev)
0199 {
0200 struct efx_nic *efx = efx_netdev_priv(net_dev);
0201
0202 return __ef100_hard_start_xmit(skb, efx, net_dev, NULL);
0203 }
0204
0205 netdev_tx_t __ef100_hard_start_xmit(struct sk_buff *skb,
0206 struct efx_nic *efx,
0207 struct net_device *net_dev,
0208 struct efx_rep *efv)
0209 {
0210 struct efx_tx_queue *tx_queue;
0211 struct efx_channel *channel;
0212 int rc;
0213
0214 channel = efx_get_tx_channel(efx, skb_get_queue_mapping(skb));
0215 netif_vdbg(efx, tx_queued, efx->net_dev,
0216 "%s len %d data %d channel %d\n", __func__,
0217 skb->len, skb->data_len, channel->channel);
0218 if (!efx->n_channels || !efx->n_tx_channels || !channel) {
0219 netif_stop_queue(net_dev);
0220 goto err;
0221 }
0222
0223 tx_queue = &channel->tx_queue[0];
0224 rc = __ef100_enqueue_skb(tx_queue, skb, efv);
0225 if (rc == 0)
0226 return NETDEV_TX_OK;
0227
0228 err:
0229 net_dev->stats.tx_dropped++;
0230 return NETDEV_TX_OK;
0231 }
0232
0233 static const struct net_device_ops ef100_netdev_ops = {
0234 .ndo_open = ef100_net_open,
0235 .ndo_stop = ef100_net_stop,
0236 .ndo_start_xmit = ef100_hard_start_xmit,
0237 .ndo_tx_timeout = efx_watchdog,
0238 .ndo_get_stats64 = efx_net_stats,
0239 .ndo_change_mtu = efx_change_mtu,
0240 .ndo_validate_addr = eth_validate_addr,
0241 .ndo_set_mac_address = efx_set_mac_address,
0242 .ndo_set_rx_mode = efx_set_rx_mode,
0243 .ndo_set_features = efx_set_features,
0244 .ndo_get_phys_port_id = efx_get_phys_port_id,
0245 .ndo_get_phys_port_name = efx_get_phys_port_name,
0246 #ifdef CONFIG_RFS_ACCEL
0247 .ndo_rx_flow_steer = efx_filter_rfs,
0248 #endif
0249 };
0250
0251
0252
0253 int ef100_netdev_event(struct notifier_block *this,
0254 unsigned long event, void *ptr)
0255 {
0256 struct efx_nic *efx = container_of(this, struct efx_nic, netdev_notifier);
0257 struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
0258
0259 if (efx->net_dev == net_dev &&
0260 (event == NETDEV_CHANGENAME || event == NETDEV_REGISTER))
0261 ef100_update_name(efx);
0262
0263 return NOTIFY_DONE;
0264 }
0265
0266 static int ef100_register_netdev(struct efx_nic *efx)
0267 {
0268 struct net_device *net_dev = efx->net_dev;
0269 int rc;
0270
0271 net_dev->watchdog_timeo = 5 * HZ;
0272 net_dev->irq = efx->pci_dev->irq;
0273 net_dev->netdev_ops = &ef100_netdev_ops;
0274 net_dev->min_mtu = EFX_MIN_MTU;
0275 net_dev->max_mtu = EFX_MAX_MTU;
0276 net_dev->ethtool_ops = &ef100_ethtool_ops;
0277
0278 rtnl_lock();
0279
0280 rc = dev_alloc_name(net_dev, net_dev->name);
0281 if (rc < 0)
0282 goto fail_locked;
0283 ef100_update_name(efx);
0284
0285 rc = register_netdevice(net_dev);
0286 if (rc)
0287 goto fail_locked;
0288
0289
0290 netif_carrier_off(net_dev);
0291
0292 efx->state = STATE_NET_DOWN;
0293 rtnl_unlock();
0294 efx_init_mcdi_logging(efx);
0295
0296 return 0;
0297
0298 fail_locked:
0299 rtnl_unlock();
0300 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
0301 return rc;
0302 }
0303
0304 static void ef100_unregister_netdev(struct efx_nic *efx)
0305 {
0306 if (efx_dev_registered(efx)) {
0307 efx_fini_mcdi_logging(efx);
0308 efx->state = STATE_PROBED;
0309 unregister_netdev(efx->net_dev);
0310 }
0311 }
0312
0313 void ef100_remove_netdev(struct efx_probe_data *probe_data)
0314 {
0315 struct efx_nic *efx = &probe_data->efx;
0316
0317 if (!efx->net_dev)
0318 return;
0319
0320 rtnl_lock();
0321 dev_close(efx->net_dev);
0322 rtnl_unlock();
0323
0324 unregister_netdevice_notifier(&efx->netdev_notifier);
0325 #if defined(CONFIG_SFC_SRIOV)
0326 if (!efx->type->is_vf)
0327 efx_ef100_pci_sriov_disable(efx, true);
0328 #endif
0329
0330 ef100_unregister_netdev(efx);
0331
0332 #ifdef CONFIG_SFC_SRIOV
0333 efx_fini_tc(efx);
0334 #endif
0335
0336 down_write(&efx->filter_sem);
0337 efx_mcdi_filter_table_remove(efx);
0338 up_write(&efx->filter_sem);
0339 efx_fini_channels(efx);
0340 kfree(efx->phy_data);
0341 efx->phy_data = NULL;
0342
0343 free_netdev(efx->net_dev);
0344 efx->net_dev = NULL;
0345 efx->state = STATE_PROBED;
0346 }
0347
0348 int ef100_probe_netdev(struct efx_probe_data *probe_data)
0349 {
0350 struct efx_nic *efx = &probe_data->efx;
0351 struct efx_probe_data **probe_ptr;
0352 struct net_device *net_dev;
0353 int rc;
0354
0355 if (efx->mcdi->fn_flags &
0356 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_NO_ACTIVE_PORT)) {
0357 pci_info(efx->pci_dev, "No network port on this PCI function");
0358 return 0;
0359 }
0360
0361
0362 net_dev = alloc_etherdev_mq(sizeof(probe_data), EFX_MAX_CORE_TX_QUEUES);
0363 if (!net_dev)
0364 return -ENOMEM;
0365 probe_ptr = netdev_priv(net_dev);
0366 *probe_ptr = probe_data;
0367 efx->net_dev = net_dev;
0368 SET_NETDEV_DEV(net_dev, &efx->pci_dev->dev);
0369
0370 net_dev->features |= efx->type->offload_features;
0371 net_dev->hw_features |= efx->type->offload_features;
0372 net_dev->hw_enc_features |= efx->type->offload_features;
0373 net_dev->vlan_features |= NETIF_F_HW_CSUM | NETIF_F_SG |
0374 NETIF_F_HIGHDMA | NETIF_F_ALL_TSO;
0375 netif_set_tso_max_segs(net_dev,
0376 ESE_EF100_DP_GZ_TSO_MAX_HDR_NUM_SEGS_DEFAULT);
0377 efx->mdio.dev = net_dev;
0378
0379 rc = efx_ef100_init_datapath_caps(efx);
0380 if (rc < 0)
0381 goto fail;
0382
0383 rc = ef100_phy_probe(efx);
0384 if (rc)
0385 goto fail;
0386
0387 rc = efx_init_channels(efx);
0388 if (rc)
0389 goto fail;
0390
0391 down_write(&efx->filter_sem);
0392 rc = ef100_filter_table_probe(efx);
0393 up_write(&efx->filter_sem);
0394 if (rc)
0395 goto fail;
0396
0397 netdev_rss_key_fill(efx->rss_context.rx_hash_key,
0398 sizeof(efx->rss_context.rx_hash_key));
0399
0400
0401 efx_mcdi_push_default_indir_table(efx, efx->n_rx_channels);
0402
0403 rc = ef100_register_netdev(efx);
0404 if (rc)
0405 goto fail;
0406
0407 if (!efx->type->is_vf) {
0408 rc = ef100_probe_netdev_pf(efx);
0409 if (rc)
0410 goto fail;
0411 }
0412
0413 efx->netdev_notifier.notifier_call = ef100_netdev_event;
0414 rc = register_netdevice_notifier(&efx->netdev_notifier);
0415 if (rc) {
0416 netif_err(efx, probe, efx->net_dev,
0417 "Failed to register netdevice notifier, rc=%d\n", rc);
0418 goto fail;
0419 }
0420
0421 fail:
0422 return rc;
0423 }