/* This is the time (in jiffies) between invocations of the hardware *monitor.
*/ staticunsignedint efx_monitor_interval = 1 * HZ;
/* How often and how many times to poll for a reset while waiting for a *BISTthatanotherfunctionstartedtocomplete.
*/ #define BIST_WAIT_DELAY_MS 100 #define BIST_WAIT_DELAY_COUNT 100
/* Default stats update time */ #define STATS_PERIOD_MS_DEFAULT 1000
/* Reset workqueue. If any NIC has a hardware failure then a reset will be *queuedontothisworkqueue.Thisisnotaper-nicworkqueue,because *efx_reset_work()acquiresthertnllock,soresetsarenaturallyserialised.
*/ staticstruct workqueue_struct *reset_workqueue;
int efx_create_reset_workqueue(void)
{
reset_workqueue = create_singlethread_workqueue("sfc_reset"); if (!reset_workqueue) {
printk(KERN_ERR "Failed to create reset workqueue\n"); return -ENOMEM;
}
if (efx->port_enabled)
queue_work(efx->workqueue, &efx->mac_work); /* Otherwise efx_start_port() will do this */
}
int efx_set_features(struct net_device *net_dev, netdev_features_t data)
{ struct efx_nic *efx = efx_netdev_priv(net_dev); int rc;
/* If disabling RX n-tuple filtering, clear existing filters */ if (net_dev->features & ~data & NETIF_F_NTUPLE) {
rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL); if (rc) return rc;
}
/* If Rx VLAN filter is changed, update filters via mac_reconfigure. *Ifrx-fcsischanged,mac_reconfigureupdatesthattoo.
*/ if ((net_dev->features ^ data) & (NETIF_F_HW_VLAN_CTAG_FILTER |
NETIF_F_RXFCS)) { /* efx_set_rx_mode() will schedule MAC work to update filters *whenanewfeaturesarefinallysetinnet_dev.
*/
efx_set_rx_mode(net_dev);
}
return0;
}
/* This ensures that the kernel is kept informed (via *netif_carrier_on/off)ofthelinkstatus,andalsomaintainsthe *linkstatus'sstopontheport'sTXqueue.
*/ void efx_link_status_changed(struct efx_nic *efx)
{ struct efx_link_state *link_state = &efx->link_state;
/* SFC Bug 5356: A net_dev notifier is registered, so we must ensure *thatnoeventsaretriggeredbetweenunregister_netdev()andthe *driverunloading.AmoregeneralconditionisthatNETDEV_CHANGE *canonlybegeneratedbetweenNETDEV_UPandNETDEV_DOWN
*/ if (!netif_running(efx->net_dev)) return;
if (link_state->up != netif_carrier_ok(efx->net_dev)) {
efx->n_link_state_changes++;
if (link_state->up)
netif_carrier_on(efx->net_dev); else
netif_carrier_off(efx->net_dev);
}
/* Status message for kernel log */ if (link_state->up)
netif_info(efx, link, efx->net_dev, "link up at %uMbps %s-duplex (MTU %d)\n",
link_state->speed, link_state->fd ? "full" : "half",
efx->net_dev->mtu); else
netif_info(efx, link, efx->net_dev, "link down\n");
}
unsignedint efx_xdp_max_mtu(struct efx_nic *efx)
{ /* The maximum MTU that we can fit in a single page, allowing for *framing,overheadandXDPheadroom+tailroom.
*/ int overhead = EFX_MAX_FRAME_LEN(0) + sizeof(struct efx_rx_page_state) +
efx->rx_prefix_size + efx->type->rx_buffer_padding +
efx->rx_ip_align + EFX_XDP_HEADROOM + EFX_XDP_TAILROOM;
return PAGE_SIZE - overhead;
}
/* Context: process, rtnl_lock() held. */ int efx_change_mtu(struct net_device *net_dev, int new_mtu)
{ struct efx_nic *efx = efx_netdev_priv(net_dev); int rc;
rc = efx_check_disabled(efx); if (rc) return rc;
if (rtnl_dereference(efx->xdp_prog) &&
new_mtu > efx_xdp_max_mtu(efx)) {
netif_err(efx, drv, efx->net_dev, "Requested MTU of %d too big for XDP (max: %d)\n",
new_mtu, efx_xdp_max_mtu(efx)); return -EINVAL;
}
netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
/* Run periodically off the general workqueue */ staticvoid efx_monitor(struct work_struct *data)
{ struct efx_nic *efx = container_of(data, struct efx_nic,
monitor_work.work);
netif_vdbg(efx, timer, efx->net_dev, "hardware monitor executing on CPU %d\n",
raw_smp_processor_id());
BUG_ON(efx->type->monitor == NULL);
/* If the mac_lock is already held then it is likely a port *reconfigurationisalreadyinplace,whichwilllikelydo *mostoftheworkofmonitor()anyway.
*/ if (mutex_trylock(&efx->mac_lock)) { if (efx->port_enabled && efx->type->monitor)
efx->type->monitor(efx);
mutex_unlock(&efx->mac_lock);
}
/* Restore previously fixed features in hw_features and remove *featureswhicharefixednow
*/
efx->net_dev->hw_features |= efx->net_dev->features;
efx->net_dev->hw_features &= ~efx->fixed_features;
efx->net_dev->features |= efx->fixed_features; if (efx->net_dev->features != old_features)
netdev_features_change(efx->net_dev);
/* RX filters may also have scatter-enabled flags */ if ((efx->rx_scatter != old_rx_scatter) &&
efx->type->filter_update_rx_scatter)
efx->type->filter_update_rx_scatter(efx);
/* We must keep at least one descriptor in a TX ring empty. *Wecouldavoidthiswhenthequeuesizedoesnotexactly *matchthehardwareringsize,butit'snotthatimportant. *Thereforewestopthequeuewhenonemoreskbmightfill *theringcompletely.Wewakeitwhenhalfwaybackto *empty.
*/
efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
/* Initialise the channels */
efx_start_channels(efx);
efx_ptp_start_datapath(efx);
if (netif_device_present(efx->net_dev))
netif_tx_wake_all_queues(efx->net_dev);
}
/* If the interface is supposed to be running but is not, start *thehardwareandsoftwaredatapath,regularactivityfortheport *(MACstatistics,linkpolling,etc.)andscheduletheporttobe *reconfigured.Interruptsmustalreadybeenabled.Thisfunction *issafetocallmultipletimes,solongastheNICisnotdisabled. *RequirestheRTNLlock.
*/ void efx_start_all(struct efx_nic *efx)
{
EFX_ASSERT_RESET_SERIALISED(efx);
BUG_ON(efx->state == STATE_DISABLED);
/* Check that it is appropriate to restart the interface. All *oftheseflagsaresafetoreadunderjustthertnllock
*/ if (efx->port_enabled || !netif_running(efx->net_dev) ||
efx->reset_pending) return;
efx_start_port(efx);
efx_start_datapath(efx);
/* Start the hardware monitor if there is one */
efx_start_monitor(efx);
efx_selftest_async_start(efx);
/* Link state detection is normally event-driven; we have *topollnowbecausewecouldhavemissedachange
*/
mutex_lock(&efx->mac_lock); if (efx_mcdi_phy_poll(efx))
efx_link_status_changed(efx);
mutex_unlock(&efx->mac_lock);
/* Quiesce the hardware and software data path, and regular activity *fortheportwithoutbringingthelinkdown.Safetocallmultiple *timeswiththeNICinalmostanystate,butinterruptsshouldbe *enabled.RequirestheRTNLlock.
*/ void efx_stop_all(struct efx_nic *efx)
{
EFX_ASSERT_RESET_SERIALISED(efx);
/* port_enabled can be read safely under the rtnl lock */ if (!efx->port_enabled) return;
if (efx->type->update_stats) { /* update stats before we go down so we can accurately count *rx_nodesc_drops
*/
efx->type->pull_stats(efx);
spin_lock_bh(&efx->stats_lock);
efx->type->update_stats(efx, NULL, NULL);
spin_unlock_bh(&efx->stats_lock);
efx->type->stop_stats(efx);
}
efx_stop_port(efx);
/* Stop the kernel transmit interface. This is only valid if *thedeviceisstoppedordetached;otherwisethewatchdog *mayfireimmediately.
*/
WARN_ON(netif_running(efx->net_dev) &&
netif_device_present(efx->net_dev));
netif_tx_disable(efx->net_dev);
staticvoid efx_wait_for_bist_end(struct efx_nic *efx)
{ int i;
for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) { if (efx_mcdi_poll_reboot(efx)) goto out;
msleep(BIST_WAIT_DELAY_MS);
}
netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
out: /* Either way unset the BIST flag. If we found no reboot we probably *won'trecover,butweshouldtry.
*/
efx->mc_bist_for_other_fn = false;
}
/* Try recovery mechanisms. *FornowonlyEEHissupported. *Returns0iftherecoverymechanismsareunsuccessful. *Returnsanon-zerovalueotherwise.
*/ int efx_try_recovery(struct efx_nic *efx)
{ #ifdef CONFIG_EEH /* A PCI error can occur and not be seen by EEH because nothing *happensonthePCIbus.Inthiscasethedrivermayfailand *schedulea'recoverorreset',leadingtothisrecoveryhandler. *Manuallycalltheeehfailurecheckfunction.
*/ struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev); if (eeh_dev_check_failure(eehdev)) { /* The EEH mechanisms will handle the error and reset the *deviceifnecessary.
*/ return1;
} #endif return0;
}
/* Tears down the entire software state and most of the hardware state *beforereset.
*/ void efx_reset_down(struct efx_nic *efx, enum reset_type method)
{
EFX_ASSERT_RESET_SERIALISED(efx);
if (method == RESET_TYPE_MCDI_TIMEOUT)
efx->type->prepare_flr(efx);
/* This function will always ensure that the locks acquired in *efx_reset_down()arereleased.Afailurereturncodeindicates *thatwewereunabletoreinitialisethehardware,andthe *drivershouldbedisabled.Ifokisfalse,thentherxandtx *enginesarenotrestarted,pendingaRESET_DISABLE.
*/ int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
{ int rc;
EFX_ASSERT_RESET_SERIALISED(efx);
if (method == RESET_TYPE_MCDI_TIMEOUT)
efx->type->finish_flr(efx);
/* Ensure that SRAM is initialised even if we're disabling the device */
rc = efx->type->init(efx); if (rc) {
netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n"); goto fail;
}
if (!ok) goto fail;
if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
method != RESET_TYPE_DATAPATH) {
rc = efx_mcdi_port_reconfigure(efx); if (rc && rc != -EPERM)
netif_err(efx, drv, efx->net_dev, "could not restore PHY settings\n");
}
rc = efx_enable_interrupts(efx); if (rc) goto fail;
#ifdef CONFIG_SFC_SRIOV
rc = efx->type->vswitching_restore(efx); if (rc) /* not fatal; the PF will still work fine */
netif_warn(efx, probe, efx->net_dev, "failed to restore vswitching rc=%d;" " VFs may not function\n", rc); #endif
if (efx->type->rx_restore_rss_contexts)
efx->type->rx_restore_rss_contexts(efx);
mutex_unlock(&efx->net_dev->ethtool->rss_lock);
efx->type->filter_table_restore(efx);
up_write(&efx->filter_sem);
mutex_unlock(&efx->mac_lock);
efx_start_all(efx);
if (efx->type->udp_tnl_push_ports)
efx->type->udp_tnl_push_ports(efx);
/* Reset the NIC using the specified method. Note that the reset may *fail,inwhichcasethecardwillbeleftinanunusablestate. * *Callermustholdthertnl_lock.
*/ int efx_reset(struct efx_nic *efx, enum reset_type method)
{ int rc, rc2 = 0; bool disabled;
efx_device_detach_sync(efx); /* efx_reset_down() grabs locks that prevent recovery on EF100. *EF100resetishandledintheefx_nic_typecallbackbelow.
*/ if (efx_nic_rev(efx) != EFX_REV_EF100)
efx_reset_down(efx, method);
rc = efx->type->reset(efx, method); if (rc) {
netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n"); goto out;
}
/* Clear flags for the scopes we covered. We assume the NIC and *driverarenowquiescentsothatthereisnoracehere.
*/ if (method < RESET_TYPE_MAX_METHOD)
efx->reset_pending &= -(1 << (method + 1)); else/* it doesn't fit into the well-ordered scope hierarchy */
__clear_bit(method, &efx->reset_pending);
/* Reinitialise bus-mastering, which may have been turned off before *theresetwasscheduled.Thisisstillappropriate,eveninthe *RESET_TYPE_DISABLEsincethisdrivergenerallyassumesthehardware *canrespondtorequests.
*/
pci_set_master(efx->pci_dev);
out: /* Leave device stopped if necessary */
disabled = rc ||
method == RESET_TYPE_DISABLE ||
method == RESET_TYPE_RECOVER_OR_DISABLE; if (efx_nic_rev(efx) != EFX_REV_EF100)
rc2 = efx_reset_up(efx, method, !disabled); if (rc2) {
disabled = true; if (!rc)
rc = rc2;
}
/* We checked the state in efx_schedule_reset() but it may *havechangedbynow.NowthatwehavetheRTNLlock, *itcannotchangeagain.
*/ if (efx_net_active(efx->state))
(void)efx_reset(efx, method);
switch (type) { case RESET_TYPE_INVISIBLE: case RESET_TYPE_ALL: case RESET_TYPE_RECOVER_OR_ALL: case RESET_TYPE_WORLD: case RESET_TYPE_DISABLE: case RESET_TYPE_RECOVER_OR_DISABLE: case RESET_TYPE_DATAPATH: case RESET_TYPE_MC_BIST: case RESET_TYPE_MCDI_TIMEOUT:
method = type;
netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
RESET_TYPE(method)); break; default:
method = efx->type->map_reset_reason(type);
netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset for %s\n",
RESET_TYPE(method), RESET_TYPE(type)); break;
}
set_bit(method, &efx->reset_pending);
smp_mb(); /* ensure we change reset_pending before checking state */
/* If we're not READY then just leave the flags set as the cue *toabortprobingorrescheduletheresetlater.
*/ if (!efx_net_active(READ_ONCE(efx->state))) return;
/* efx_process_channel() will no longer read events once a *resetisscheduled.Soswitchbacktopoll'dMCDIcompletions.
*/
efx_mcdi_mode_poll(efx);
/* This zeroes out and then fills in the invariants in a struct *efx_nic(includingallsub-structures).
*/ int efx_init_struct(struct efx_nic *efx, struct pci_dev *pci_dev)
{ int rc = -ENOMEM;
/* Would be good to use the net_dev name, but we're too early */
snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
pci_name(pci_dev));
efx->workqueue = create_singlethread_workqueue(efx->workqueue_name); if (!efx->workqueue) {
rc = -ENOMEM; goto fail;
}
if (efx->workqueue) {
destroy_workqueue(efx->workqueue);
efx->workqueue = NULL;
}
}
/* This configures the PCI device to enable I/O and DMA. */ int efx_init_io(struct efx_nic *efx, int bar, dma_addr_t dma_mask, unsignedint mem_map_size)
{ struct pci_dev *pci_dev = efx->pci_dev; int rc;
rc = pci_enable_device(pci_dev); if (rc) {
pci_err(pci_dev, "failed to enable PCI device\n"); goto fail1;
}
pci_set_master(pci_dev);
rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask); if (rc) {
pci_err(efx->pci_dev, "could not find a suitable DMA mask\n"); goto fail2;
}
pci_dbg(efx->pci_dev, "using DMA mask %llx\n", (unsignedlonglong)dma_mask);
efx->membase_phys = pci_resource_start(efx->pci_dev, bar); if (!efx->membase_phys) {
pci_err(efx->pci_dev, "ERROR: No BAR%d mapping from the BIOS. Try pci=realloc on the kernel command line\n",
bar);
rc = -ENODEV; goto fail3;
}
rc = pci_request_region(pci_dev, bar, "sfc"); if (rc) {
pci_err(efx->pci_dev, "request for memory BAR[%d] failed\n", bar);
rc = -EIO; goto fail3;
}
efx->mem_bar = bar;
efx->membase = ioremap(efx->membase_phys, mem_map_size); if (!efx->membase) {
pci_err(efx->pci_dev, "could not map memory BAR[%d] at %llx+%x\n", bar,
(unsignedlonglong)efx->membase_phys, mem_map_size);
rc = -ENOMEM; goto fail4;
}
pci_dbg(efx->pci_dev, "memory BAR[%d] at %llx+%x (virtual %p)\n", bar,
(unsignedlonglong)efx->membase_phys, mem_map_size,
efx->membase);
if (efx_net_active(efx->state)) {
efx_stop_all(efx);
efx_disable_interrupts(efx);
}
status = PCI_ERS_RESULT_NEED_RESET;
} else { /* If the interface is disabled we don't want to do anything *withit.
*/
status = PCI_ERS_RESULT_RECOVERED;
}
rtnl_unlock();
pci_disable_device(pdev);
return status;
}
/* Fake a successful reset, which will be performed later in efx_io_resume. */ static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
{ struct efx_nic *efx = pci_get_drvdata(pdev);
pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
if (pci_enable_device(pdev)) {
netif_err(efx, hw, efx->net_dev, "Cannot re-enable PCI device after reset.\n");
status = PCI_ERS_RESULT_DISCONNECT;
}
return status;
}
/* Perform the actual reset and resume I/O operations. */ staticvoid efx_io_resume(struct pci_dev *pdev)
{ struct efx_nic *efx = pci_get_drvdata(pdev); int rc;
rtnl_lock();
if (efx->state == STATE_DISABLED) goto out;
rc = efx_reset(efx, RESET_TYPE_ALL); if (rc) {
netif_err(efx, hw, efx->net_dev, "efx_reset failed after PCI error (%d)\n", rc);
} else {
efx->state = efx_recovered(efx->state);
netif_dbg(efx, hw, efx->net_dev, "Done resetting and resuming IO after PCI error.\n");
}
out:
rtnl_unlock();
}
/* For simplicity and reliability, we always require a slot reset and try to *resetthehardwarewhenapcierroraffectingthedeviceisdetected. *Weleaveboththelink_resetandmmio_enabledcallbackunimplemented: *withourrequestforslotresetthemmio_enabledcallbackwillneverbe *called,andthelink_resetcallbackisnotusedbyAERorEEHmechanisms.
*/ conststruct pci_error_handlers efx_err_handlers = {
.error_detected = efx_io_error_detected,
.slot_reset = efx_io_slot_reset,
.resume = efx_io_resume,
};
/* Determine whether the NIC will be able to handle TX offloads for a given *encapsulatedpacket.
*/ staticbool efx_can_encap_offloads(struct efx_nic *efx, struct sk_buff *skb)
{ struct gre_base_hdr *greh;
__be16 dst_port;
u8 ipproto;
/* Does the NIC support encap offloads? *Ifnot,weshouldnevergethere,becauseweshouldn'thave *advertisedencapoffloadfeatureflagsinthefirstplace.
*/ if (WARN_ON_ONCE(!efx->type->udp_tnl_has_port)) returnfalse;
/* Determine encapsulation protocol in use */ switch (skb->protocol) { case htons(ETH_P_IP):
ipproto = ip_hdr(skb)->protocol; break; case htons(ETH_P_IPV6): /* If there are extension headers, this will cause us to *thinkwecan'toffloadsomethingthatwemaybecouldhave.
*/
ipproto = ipv6_hdr(skb)->nexthdr; break; default: /* Not IP, so can't offload it */ returnfalse;
} switch (ipproto) { case IPPROTO_GRE: /* We support NVGRE but not IP over GRE or random gretaps. *Specifically,theNICwillacceptGREasencapsulatedif *theinnerprotocolisEthernet,butonlyhandleit *correctlyiftheGREheaderis8byteslong.Moreover, *itwillnotupdatetheChecksumorSequenceNumberfields *iftheyarepresent.(TheRoutingPresentflag, *GRE_ROUTING,cannotbesetelsetheheaderwouldbemore *than8byteslong;sowedon'thavetoworryaboutit.)
*/ if (skb->inner_protocol_type != ENCAP_TYPE_ETHER) returnfalse; if (ntohs(skb->inner_protocol) != ETH_P_TEB) returnfalse; if (skb_inner_mac_header(skb) - skb_transport_header(skb) != 8) returnfalse;
greh = (struct gre_base_hdr *)skb_transport_header(skb); return !(greh->flags & (GRE_CSUM | GRE_SEQ)); case IPPROTO_UDP: /* If the port is registered for a UDP tunnel, we assume the *packetisforthattunnel,andtheNICwillhandleitas *such.Ifnot,theNICwon'tknowwhattodowithit.
*/
dst_port = udp_hdr(skb)->dest; return efx->type->udp_tnl_has_port(efx, dst_port); default: returnfalse;
}
}
if (skb->encapsulation) { if (features & NETIF_F_GSO_MASK) /* Hardware can only do TSO with at most 208 bytes *ofheaders.
*/ if (skb_inner_transport_offset(skb) >
EFX_TSO2_MAX_HDRLEN)
features &= ~(NETIF_F_GSO_MASK); if (features & (NETIF_F_GSO_MASK | NETIF_F_CSUM_MASK)) if (!efx_can_encap_offloads(efx, skb))
features &= ~(NETIF_F_GSO_MASK |
NETIF_F_CSUM_MASK);
} return features;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.