···146146extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);147147extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);148148extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx);149149+extern int efx_mcdi_flush_rxqs(struct efx_nic *efx);150150+extern int efx_mcdi_set_mac(struct efx_nic *efx);149151extern int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr,150152 u32 dma_len, int enable, int clear);151153extern int efx_mcdi_mac_reconfigure(struct efx_nic *efx);
···280280 --part;281281 efx_mtd_remove_partition(part);282282 }283283- /* mtd_device_register() returns 1 if the MTD table is full */283283+ /* Failure is unlikely here, but probably means we're out of memory */284284 return -ENOMEM;285285}286286
+97-26
drivers/net/ethernet/sfc/net_driver.h
···2424#include <linux/device.h>2525#include <linux/highmem.h>2626#include <linux/workqueue.h>2727+#include <linux/mutex.h>2728#include <linux/vmalloc.h>2829#include <linux/i2c.h>2930···5352 *5453 **************************************************************************/55545656-#define EFX_MAX_CHANNELS 325555+#define EFX_MAX_CHANNELS 32U5756#define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS5757+#define EFX_EXTRA_CHANNEL_IOV 05858+#define EFX_MAX_EXTRA_CHANNELS 1U58595960/* Checksum generation is a per-queue option in hardware, so each6061 * queue visible to the networking core is backed by two hardware TX···8481 void *addr;8582 dma_addr_t dma_addr;8683 unsigned int len;8787- int index;8888- int entries;8989-};9090-9191-enum efx_flush_state {9292- FLUSH_NONE,9393- FLUSH_PENDING,9494- FLUSH_FAILED,9595- FLUSH_DONE,8484+ unsigned int index;8585+ unsigned int entries;9686};97879888/**···134138 * @txd: The hardware descriptor ring135139 * @ptr_mask: The size of the ring minus 1.136140 * @initialised: Has hardware queue been initialised?137137- * @flushed: Used when handling queue flushing138141 * @read_count: Current read pointer.139142 * This is the number of buffers that have been removed from both rings.140143 * @old_write_count: The value of @write_count when last checked.···176181 struct efx_special_buffer txd;177182 unsigned int ptr_mask;178183 bool initialised;179179- enum efx_flush_state flushed;180184181185 /* Members used mainly on the completion path */182186 unsigned int read_count ____cacheline_aligned_in_smp;···243249 * @buffer: The software buffer ring244250 * @rxd: The hardware descriptor ring245251 * @ptr_mask: The size of the ring minus 1.252252+ * @enabled: Receive queue enabled indicator.253253+ * @flush_pending: Set when a RX flush is pending. Has the same lifetime as254254+ * @rxq_flush_pending.246255 * @added_count: Number of buffers added to the receive queue.247256 * @notified_count: Number of buffers given to NIC (<= @added_count).248257 * @removed_count: Number of buffers removed from the receive queue.···260263 * @alloc_page_count: RX allocation strategy counter.261264 * @alloc_skb_count: RX allocation strategy counter.262265 * @slow_fill: Timer used to defer efx_nic_generate_fill_event().263263- * @flushed: Use when handling queue flushing264266 */265267struct efx_rx_queue {266268 struct efx_nic *efx;267269 struct efx_rx_buffer *buffer;268270 struct efx_special_buffer rxd;269271 unsigned int ptr_mask;272272+ bool enabled;273273+ bool flush_pending;270274271275 int added_count;272276 int notified_count;···281283 unsigned int alloc_skb_count;282284 struct timer_list slow_fill;283285 unsigned int slow_fill_count;284284-285285- enum efx_flush_state flushed;286286};287287288288/**···314318 *315319 * @efx: Associated Efx NIC316320 * @channel: Channel instance number321321+ * @type: Channel type definition317322 * @enabled: Channel enabled indicator318323 * @irq: IRQ number (MSI and MSI-X only)319324 * @irq_moderation: IRQ moderation value (in hardware ticks)···345348struct efx_channel {346349 struct efx_nic *efx;347350 int channel;351351+ const struct efx_channel_type *type;348352 bool enabled;349353 int irq;350354 unsigned int irq_moderation;···382384383385 struct efx_rx_queue rx_queue;384386 struct efx_tx_queue tx_queue[EFX_TXQ_TYPES];387387+};388388+389389+/**390390+ * struct efx_channel_type - distinguishes traffic and extra channels391391+ * @handle_no_channel: Handle failure to allocate an extra channel392392+ * @pre_probe: Set up extra state prior to initialisation393393+ * @post_remove: Tear down extra state after finalisation, if allocated.394394+ * May be called on channels that have not been probed.395395+ * @get_name: Generate the channel's name (used for its IRQ handler)396396+ * @copy: Copy the channel state prior to reallocation. May be %NULL if397397+ * reallocation is not supported.398398+ * @keep_eventq: Flag for whether event queue should be kept initialised399399+ * while the device is stopped400400+ */401401+struct efx_channel_type {402402+ void (*handle_no_channel)(struct efx_nic *);403403+ int (*pre_probe)(struct efx_channel *);404404+ void (*get_name)(struct efx_channel *, char *buf, size_t len);405405+ struct efx_channel *(*copy)(const struct efx_channel *);406406+ bool keep_eventq;385407};386408387409enum efx_led_mode {···631613};632614633615struct efx_filter_state;616616+struct efx_vf;617617+struct vfdi_status;634618635619/**636620 * struct efx_nic - an Efx NIC···658638 * @rx_queue: RX DMA queues659639 * @channel: Channels660640 * @channel_name: Names for channels and their IRQs641641+ * @extra_channel_types: Types of extra (non-traffic) channels that642642+ * should be allocated for this NIC661643 * @rxq_entries: Size of receive queues requested by user.662644 * @txq_entries: Size of transmit queues requested by user.645645+ * @tx_dc_base: Base qword address in SRAM of TX queue descriptor caches646646+ * @rx_dc_base: Base qword address in SRAM of RX queue descriptor caches647647+ * @sram_lim_qw: Qword address limit of SRAM663648 * @next_buffer_table: First available buffer table id664649 * @n_channels: Number of channels in use665650 * @n_rx_channels: Number of channels used for RX (= number of RX queues)···702677 * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.703678 * @multicast_hash: Multicast hash table704679 * @wanted_fc: Wanted flow control flags680680+ * @fc_disable: When non-zero flow control is disabled. Typically used to681681+ * ensure that network back pressure doesn't delay dma queue flushes.682682+ * Serialised by the rtnl lock.705683 * @mac_work: Work item for changing MAC promiscuity and multicast hash706684 * @loopback_mode: Loopback status707685 * @loopback_modes: Supported loopback mode bitmask708686 * @loopback_selftest: Offline self-test private state687687+ * @drain_pending: Count of RX and TX queues that haven't been flushed and drained.688688+ * @rxq_flush_pending: Count of number of receive queues that need to be flushed.689689+ * Decremented when the efx_flush_rx_queue() is called.690690+ * @rxq_flush_outstanding: Count of number of RX flushes started but not yet691691+ * completed (either success or failure). Not used when MCDI is used to692692+ * flush receive queues.693693+ * @flush_wq: wait queue used by efx_nic_flush_queues() to wait for flush completions.694694+ * @vf: Array of &struct efx_vf objects.695695+ * @vf_count: Number of VFs intended to be enabled.696696+ * @vf_init_count: Number of VFs that have been fully initialised.697697+ * @vi_scale: log2 number of vnics per VF.698698+ * @vf_buftbl_base: The zeroth buffer table index used to back VF queues.699699+ * @vfdi_status: Common VFDI status page to be dmad to VF address space.700700+ * @local_addr_list: List of local addresses. Protected by %local_lock.701701+ * @local_page_list: List of DMA addressable pages used to broadcast702702+ * %local_addr_list. Protected by %local_lock.703703+ * @local_lock: Mutex protecting %local_addr_list and %local_page_list.704704+ * @peer_work: Work item to broadcast peer addresses to VMs.709705 * @monitor_work: Hardware monitor workitem710706 * @biu_lock: BIU (bus interface unit) lock711707 * @last_irq_cpu: Last CPU to handle a possible test interrupt. This···766720767721 struct efx_channel *channel[EFX_MAX_CHANNELS];768722 char channel_name[EFX_MAX_CHANNELS][IFNAMSIZ + 6];723723+ const struct efx_channel_type *724724+ extra_channel_type[EFX_MAX_EXTRA_CHANNELS];769725770726 unsigned rxq_entries;771727 unsigned txq_entries;728728+ unsigned tx_dc_base;729729+ unsigned rx_dc_base;730730+ unsigned sram_lim_qw;772731 unsigned next_buffer_table;773732 unsigned n_channels;774733 unsigned n_rx_channels;734734+ unsigned rss_spread;775735 unsigned tx_channel_offset;776736 unsigned n_tx_channels;777737 unsigned int rx_buffer_len;···821769 bool promiscuous;822770 union efx_multicast_hash multicast_hash;823771 u8 wanted_fc;772772+ unsigned fc_disable;824773825774 atomic_t rx_reset;826775 enum efx_loopback_mode loopback_mode;···830777 void *loopback_selftest;831778832779 struct efx_filter_state *filter_state;780780+781781+ atomic_t drain_pending;782782+ atomic_t rxq_flush_pending;783783+ atomic_t rxq_flush_outstanding;784784+ wait_queue_head_t flush_wq;785785+786786+#ifdef CONFIG_SFC_SRIOV787787+ struct efx_channel *vfdi_channel;788788+ struct efx_vf *vf;789789+ unsigned vf_count;790790+ unsigned vf_init_count;791791+ unsigned vi_scale;792792+ unsigned vf_buftbl_base;793793+ struct efx_buffer vfdi_status;794794+ struct list_head local_addr_list;795795+ struct list_head local_page_list;796796+ struct mutex local_lock;797797+ struct work_struct peer_work;798798+#endif833799834800 /* The following fields may be written more often */835801···875803 * @probe: Probe the controller876804 * @remove: Free resources allocated by probe()877805 * @init: Initialise the controller806806+ * @dimension_resources: Dimension controller resources (buffer table,807807+ * and VIs once the available interrupt resources are clear)878808 * @fini: Shut down the controller879809 * @monitor: Periodic function for polling link state and hardware monitor880810 * @map_reset_reason: Map ethtool reset reason to a reset method···916842 * @phys_addr_channels: Number of channels with physically addressed917843 * descriptors918844 * @timer_period_max: Maximum period of interrupt timer (in ticks)919919- * @tx_dc_base: Base address in SRAM of TX queue descriptor caches920920- * @rx_dc_base: Base address in SRAM of RX queue descriptor caches921845 * @offload_features: net_device feature flags for protocol offload922846 * features implemented in hardware923847 */···923851 int (*probe)(struct efx_nic *efx);924852 void (*remove)(struct efx_nic *efx);925853 int (*init)(struct efx_nic *efx);854854+ void (*dimension_resources)(struct efx_nic *efx);926855 void (*fini)(struct efx_nic *efx);927856 void (*monitor)(struct efx_nic *efx);928857 enum reset_type (*map_reset_reason)(enum reset_type reason);···960887 unsigned int max_interrupt_mode;961888 unsigned int phys_addr_channels;962889 unsigned int timer_period_max;963963- unsigned int tx_dc_base;964964- unsigned int rx_dc_base;965890 netdev_features_t offload_features;966891};967892···982911 _channel; \983912 _channel = (_channel->channel + 1 < (_efx)->n_channels) ? \984913 (_efx)->channel[_channel->channel + 1] : NULL)914914+915915+/* Iterate over all used channels in reverse */916916+#define efx_for_each_channel_rev(_channel, _efx) \917917+ for (_channel = (_efx)->channel[(_efx)->n_channels - 1]; \918918+ _channel; \919919+ _channel = _channel->channel ? \920920+ (_efx)->channel[_channel->channel - 1] : NULL)985921986922static inline struct efx_tx_queue *987923efx_get_tx_queue(struct efx_nic *efx, unsigned index, unsigned type)···1033955 for (_tx_queue = (_channel)->tx_queue; \1034956 _tx_queue < (_channel)->tx_queue + EFX_TXQ_TYPES; \1035957 _tx_queue++)10361036-10371037-static inline struct efx_rx_queue *10381038-efx_get_rx_queue(struct efx_nic *efx, unsigned index)10391039-{10401040- EFX_BUG_ON_PARANOID(index >= efx->n_rx_channels);10411041- return &efx->channel[index]->rx_queue;10421042-}10439581044959static inline bool efx_channel_has_rx_queue(struct efx_channel *channel)1045960{
+308-214
drivers/net/ethernet/sfc/nic.c
···4949#define EFX_INT_ERROR_EXPIRE 36005050#define EFX_MAX_INT_ERRORS 551515252-/* We poll for events every FLUSH_INTERVAL ms, and check FLUSH_POLL_COUNT times5353- */5454-#define EFX_FLUSH_INTERVAL 105555-#define EFX_FLUSH_POLL_COUNT 1005656-5757-/* Size and alignment of special buffers (4KB) */5858-#define EFX_BUF_SIZE 40965959-6052/* Depth of RX flush request fifo */6153#define EFX_RX_FLUSH_COUNT 462546363-/* Generated event code for efx_generate_test_event() */6464-#define EFX_CHANNEL_MAGIC_TEST(_channel) \6565- (0x00010100 + (_channel)->channel)5555+/* Driver generated events */5656+#define _EFX_CHANNEL_MAGIC_TEST 0x0001015757+#define _EFX_CHANNEL_MAGIC_FILL 0x0001025858+#define _EFX_CHANNEL_MAGIC_RX_DRAIN 0x0001035959+#define _EFX_CHANNEL_MAGIC_TX_DRAIN 0x00010466606767-/* Generated event code for efx_generate_fill_event() */6868-#define EFX_CHANNEL_MAGIC_FILL(_channel) \6969- (0x00010200 + (_channel)->channel)6161+#define _EFX_CHANNEL_MAGIC(_code, _data) ((_code) << 8 | (_data))6262+#define _EFX_CHANNEL_MAGIC_CODE(_magic) ((_magic) >> 8)6363+6464+#define EFX_CHANNEL_MAGIC_TEST(_channel) \6565+ _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_TEST, (_channel)->channel)6666+#define EFX_CHANNEL_MAGIC_FILL(_rx_queue) \6767+ _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_FILL, \6868+ efx_rx_queue_index(_rx_queue))6969+#define EFX_CHANNEL_MAGIC_RX_DRAIN(_rx_queue) \7070+ _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_RX_DRAIN, \7171+ efx_rx_queue_index(_rx_queue))7272+#define EFX_CHANNEL_MAGIC_TX_DRAIN(_tx_queue) \7373+ _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_TX_DRAIN, \7474+ (_tx_queue)->queue)70757176/**************************************************************************7277 *···192187efx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)193188{194189 efx_qword_t buf_desc;195195- int index;190190+ unsigned int index;196191 dma_addr_t dma_addr;197192 int i;198193···201196 /* Write buffer descriptors to NIC */202197 for (i = 0; i < buffer->entries; i++) {203198 index = buffer->index + i;204204- dma_addr = buffer->dma_addr + (i * 4096);199199+ dma_addr = buffer->dma_addr + (i * EFX_BUF_SIZE);205200 netif_dbg(efx, probe, efx->net_dev,206201 "mapping special buffer %d at %llx\n",207202 index, (unsigned long long)dma_addr);···264259 /* Select new buffer ID */265260 buffer->index = efx->next_buffer_table;266261 efx->next_buffer_table += buffer->entries;262262+#ifdef CONFIG_SFC_SRIOV263263+ BUG_ON(efx_sriov_enabled(efx) &&264264+ efx->vf_buftbl_base < efx->next_buffer_table);265265+#endif267266268267 netif_dbg(efx, probe, efx->net_dev,269268 "allocating special buffers %d-%d at %llx+%x "···439430 struct efx_nic *efx = tx_queue->efx;440431 efx_oword_t reg;441432442442- tx_queue->flushed = FLUSH_NONE;443443-444433 /* Pin TX descriptor ring */445434 efx_init_special_buffer(efx, &tx_queue->txd);446435···495488 struct efx_nic *efx = tx_queue->efx;496489 efx_oword_t tx_flush_descq;497490498498- tx_queue->flushed = FLUSH_PENDING;499499-500500- /* Post a flush command */501491 EFX_POPULATE_OWORD_2(tx_flush_descq,502492 FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,503493 FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue);···505501{506502 struct efx_nic *efx = tx_queue->efx;507503 efx_oword_t tx_desc_ptr;508508-509509- /* The queue should have been flushed */510510- WARN_ON(tx_queue->flushed != FLUSH_DONE);511504512505 /* Remove TX descriptor ring from card */513506 EFX_ZERO_OWORD(tx_desc_ptr);···596595 efx_rx_queue_index(rx_queue), rx_queue->rxd.index,597596 rx_queue->rxd.index + rx_queue->rxd.entries - 1);598597599599- rx_queue->flushed = FLUSH_NONE;600600-601598 /* Pin RX descriptor ring */602599 efx_init_special_buffer(efx, &rx_queue->rxd);603600···624625 struct efx_nic *efx = rx_queue->efx;625626 efx_oword_t rx_flush_descq;626627627627- rx_queue->flushed = FLUSH_PENDING;628628-629629- /* Post a flush command */630628 EFX_POPULATE_OWORD_2(rx_flush_descq,631629 FRF_AZ_RX_FLUSH_DESCQ_CMD, 1,632630 FRF_AZ_RX_FLUSH_DESCQ,···635639{636640 efx_oword_t rx_desc_ptr;637641 struct efx_nic *efx = rx_queue->efx;638638-639639- /* The queue should already have been flushed */640640- WARN_ON(rx_queue->flushed != FLUSH_DONE);641642642643 /* Remove RX descriptor ring from card */643644 EFX_ZERO_OWORD(rx_desc_ptr);···649656void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)650657{651658 efx_free_special_buffer(rx_queue->efx, &rx_queue->rxd);659659+}660660+661661+/**************************************************************************662662+ *663663+ * Flush handling664664+ *665665+ **************************************************************************/666666+667667+/* efx_nic_flush_queues() must be woken up when all flushes are completed,668668+ * or more RX flushes can be kicked off.669669+ */670670+static bool efx_flush_wake(struct efx_nic *efx)671671+{672672+ /* Ensure that all updates are visible to efx_nic_flush_queues() */673673+ smp_mb();674674+675675+ return (atomic_read(&efx->drain_pending) == 0 ||676676+ (atomic_read(&efx->rxq_flush_outstanding) < EFX_RX_FLUSH_COUNT677677+ && atomic_read(&efx->rxq_flush_pending) > 0));678678+}679679+680680+/* Flush all the transmit queues, and continue flushing receive queues until681681+ * they're all flushed. Wait for the DRAIN events to be recieved so that there682682+ * are no more RX and TX events left on any channel. */683683+int efx_nic_flush_queues(struct efx_nic *efx)684684+{685685+ unsigned timeout = msecs_to_jiffies(5000); /* 5s for all flushes and drains */686686+ struct efx_channel *channel;687687+ struct efx_rx_queue *rx_queue;688688+ struct efx_tx_queue *tx_queue;689689+ int rc = 0;690690+691691+ efx->fc_disable++;692692+ efx->type->prepare_flush(efx);693693+694694+ efx_for_each_channel(channel, efx) {695695+ efx_for_each_channel_tx_queue(tx_queue, channel) {696696+ atomic_inc(&efx->drain_pending);697697+ efx_flush_tx_queue(tx_queue);698698+ }699699+ efx_for_each_channel_rx_queue(rx_queue, channel) {700700+ atomic_inc(&efx->drain_pending);701701+ rx_queue->flush_pending = true;702702+ atomic_inc(&efx->rxq_flush_pending);703703+ }704704+ }705705+706706+ while (timeout && atomic_read(&efx->drain_pending) > 0) {707707+ /* If SRIOV is enabled, then offload receive queue flushing to708708+ * the firmware (though we will still have to poll for709709+ * completion). If that fails, fall back to the old scheme.710710+ */711711+ if (efx_sriov_enabled(efx)) {712712+ rc = efx_mcdi_flush_rxqs(efx);713713+ if (!rc)714714+ goto wait;715715+ }716716+717717+ /* The hardware supports four concurrent rx flushes, each of718718+ * which may need to be retried if there is an outstanding719719+ * descriptor fetch720720+ */721721+ efx_for_each_channel(channel, efx) {722722+ efx_for_each_channel_rx_queue(rx_queue, channel) {723723+ if (atomic_read(&efx->rxq_flush_outstanding) >=724724+ EFX_RX_FLUSH_COUNT)725725+ break;726726+727727+ if (rx_queue->flush_pending) {728728+ rx_queue->flush_pending = false;729729+ atomic_dec(&efx->rxq_flush_pending);730730+ atomic_inc(&efx->rxq_flush_outstanding);731731+ efx_flush_rx_queue(rx_queue);732732+ }733733+ }734734+ }735735+736736+ wait:737737+ timeout = wait_event_timeout(efx->flush_wq, efx_flush_wake(efx),738738+ timeout);739739+ }740740+741741+ if (atomic_read(&efx->drain_pending)) {742742+ netif_err(efx, hw, efx->net_dev, "failed to flush %d queues "743743+ "(rx %d+%d)\n", atomic_read(&efx->drain_pending),744744+ atomic_read(&efx->rxq_flush_outstanding),745745+ atomic_read(&efx->rxq_flush_pending));746746+ rc = -ETIMEDOUT;747747+748748+ atomic_set(&efx->drain_pending, 0);749749+ atomic_set(&efx->rxq_flush_pending, 0);750750+ atomic_set(&efx->rxq_flush_outstanding, 0);751751+ }752752+753753+ efx->fc_disable--;754754+755755+ return rc;652756}653757654758/**************************************************************************···772682}773683774684/* Use HW to insert a SW defined event */775775-static void efx_generate_event(struct efx_channel *channel, efx_qword_t *event)685685+void efx_generate_event(struct efx_nic *efx, unsigned int evq,686686+ efx_qword_t *event)776687{777688 efx_oword_t drv_ev_reg;778689···783692 drv_ev_reg.u32[1] = event->u32[1];784693 drv_ev_reg.u32[2] = 0;785694 drv_ev_reg.u32[3] = 0;786786- EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, channel->channel);787787- efx_writeo(channel->efx, &drv_ev_reg, FR_AZ_DRV_EV);695695+ EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, evq);696696+ efx_writeo(efx, &drv_ev_reg, FR_AZ_DRV_EV);697697+}698698+699699+static void efx_magic_event(struct efx_channel *channel, u32 magic)700700+{701701+ efx_qword_t event;702702+703703+ EFX_POPULATE_QWORD_2(event, FSF_AZ_EV_CODE,704704+ FSE_AZ_EV_CODE_DRV_GEN_EV,705705+ FSF_AZ_DRV_GEN_EV_MAGIC, magic);706706+ efx_generate_event(channel->efx, channel->channel, &event);788707}789708790709/* Handle a transmit completion event···810709 struct efx_tx_queue *tx_queue;811710 struct efx_nic *efx = channel->efx;812711 int tx_packets = 0;712712+713713+ if (unlikely(ACCESS_ONCE(efx->reset_pending)))714714+ return 0;813715814716 if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) {815717 /* Transmit completion */···955851 bool rx_ev_pkt_ok;956852 u16 flags;957853 struct efx_rx_queue *rx_queue;854854+ struct efx_nic *efx = channel->efx;855855+856856+ if (unlikely(ACCESS_ONCE(efx->reset_pending)))857857+ return;958858959859 /* Basic packet information */960860 rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT);···1005897 efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt, flags);1006898}1007899900900+/* If this flush done event corresponds to a &struct efx_tx_queue, then901901+ * send an %EFX_CHANNEL_MAGIC_TX_DRAIN event to drain the event queue902902+ * of all transmit completions.903903+ */904904+static void905905+efx_handle_tx_flush_done(struct efx_nic *efx, efx_qword_t *event)906906+{907907+ struct efx_tx_queue *tx_queue;908908+ int qid;909909+910910+ qid = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);911911+ if (qid < EFX_TXQ_TYPES * efx->n_tx_channels) {912912+ tx_queue = efx_get_tx_queue(efx, qid / EFX_TXQ_TYPES,913913+ qid % EFX_TXQ_TYPES);914914+915915+ efx_magic_event(tx_queue->channel,916916+ EFX_CHANNEL_MAGIC_TX_DRAIN(tx_queue));917917+ }918918+}919919+920920+/* If this flush done event corresponds to a &struct efx_rx_queue: If the flush921921+ * was succesful then send an %EFX_CHANNEL_MAGIC_RX_DRAIN, otherwise add922922+ * the RX queue back to the mask of RX queues in need of flushing.923923+ */924924+static void925925+efx_handle_rx_flush_done(struct efx_nic *efx, efx_qword_t *event)926926+{927927+ struct efx_channel *channel;928928+ struct efx_rx_queue *rx_queue;929929+ int qid;930930+ bool failed;931931+932932+ qid = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);933933+ failed = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);934934+ if (qid >= efx->n_channels)935935+ return;936936+ channel = efx_get_channel(efx, qid);937937+ if (!efx_channel_has_rx_queue(channel))938938+ return;939939+ rx_queue = efx_channel_get_rx_queue(channel);940940+941941+ if (failed) {942942+ netif_info(efx, hw, efx->net_dev,943943+ "RXQ %d flush retry\n", qid);944944+ rx_queue->flush_pending = true;945945+ atomic_inc(&efx->rxq_flush_pending);946946+ } else {947947+ efx_magic_event(efx_rx_queue_channel(rx_queue),948948+ EFX_CHANNEL_MAGIC_RX_DRAIN(rx_queue));949949+ }950950+ atomic_dec(&efx->rxq_flush_outstanding);951951+ if (efx_flush_wake(efx))952952+ wake_up(&efx->flush_wq);953953+}954954+955955+static void956956+efx_handle_drain_event(struct efx_channel *channel)957957+{958958+ struct efx_nic *efx = channel->efx;959959+960960+ WARN_ON(atomic_read(&efx->drain_pending) == 0);961961+ atomic_dec(&efx->drain_pending);962962+ if (efx_flush_wake(efx))963963+ wake_up(&efx->flush_wq);964964+}965965+1008966static void1009967efx_handle_generated_event(struct efx_channel *channel, efx_qword_t *event)1010968{1011969 struct efx_nic *efx = channel->efx;10121012- unsigned code;970970+ struct efx_rx_queue *rx_queue =971971+ efx_channel_has_rx_queue(channel) ?972972+ efx_channel_get_rx_queue(channel) : NULL;973973+ unsigned magic, code;101397410141014- code = EFX_QWORD_FIELD(*event, FSF_AZ_DRV_GEN_EV_MAGIC);10151015- if (code == EFX_CHANNEL_MAGIC_TEST(channel))10161016- ; /* ignore */10171017- else if (code == EFX_CHANNEL_MAGIC_FILL(channel))975975+ magic = EFX_QWORD_FIELD(*event, FSF_AZ_DRV_GEN_EV_MAGIC);976976+ code = _EFX_CHANNEL_MAGIC_CODE(magic);977977+978978+ if (magic == EFX_CHANNEL_MAGIC_TEST(channel)) {979979+ /* ignore */980980+ } else if (rx_queue && magic == EFX_CHANNEL_MAGIC_FILL(rx_queue)) {1018981 /* The queue must be empty, so we won't receive any rx1019982 * events, so efx_process_channel() won't refill the1020983 * queue. Refill it here */10211021- efx_fast_push_rx_descriptors(efx_channel_get_rx_queue(channel));10221022- else984984+ efx_fast_push_rx_descriptors(rx_queue);985985+ } else if (rx_queue && magic == EFX_CHANNEL_MAGIC_RX_DRAIN(rx_queue)) {986986+ rx_queue->enabled = false;987987+ efx_handle_drain_event(channel);988988+ } else if (code == _EFX_CHANNEL_MAGIC_TX_DRAIN) {989989+ efx_handle_drain_event(channel);990990+ } else {1023991 netif_dbg(efx, hw, efx->net_dev, "channel %d received "1024992 "generated event "EFX_QWORD_FMT"\n",1025993 channel->channel, EFX_QWORD_VAL(*event));994994+ }1026995}10279961028997static void···1116931 case FSE_AZ_TX_DESCQ_FLS_DONE_EV:1117932 netif_vdbg(efx, hw, efx->net_dev, "channel %d TXQ %d flushed\n",1118933 channel->channel, ev_sub_data);934934+ efx_handle_tx_flush_done(efx, event);935935+ efx_sriov_tx_flush_done(efx, event);1119936 break;1120937 case FSE_AZ_RX_DESCQ_FLS_DONE_EV:1121938 netif_vdbg(efx, hw, efx->net_dev, "channel %d RXQ %d flushed\n",1122939 channel->channel, ev_sub_data);940940+ efx_handle_rx_flush_done(efx, event);941941+ efx_sriov_rx_flush_done(efx, event);1123942 break;1124943 case FSE_AZ_EVQ_INIT_DONE_EV:1125944 netif_dbg(efx, hw, efx->net_dev,···1155966 RESET_TYPE_DISABLE);1156967 break;1157968 case FSE_BZ_RX_DSC_ERROR_EV:11581158- netif_err(efx, rx_err, efx->net_dev,11591159- "RX DMA Q %d reports descriptor fetch error."11601160- " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);11611161- efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);969969+ if (ev_sub_data < EFX_VI_BASE) {970970+ netif_err(efx, rx_err, efx->net_dev,971971+ "RX DMA Q %d reports descriptor fetch error."972972+ " RX Q %d is disabled.\n", ev_sub_data,973973+ ev_sub_data);974974+ efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);975975+ } else976976+ efx_sriov_desc_fetch_err(efx, ev_sub_data);1162977 break;1163978 case FSE_BZ_TX_DSC_ERROR_EV:11641164- netif_err(efx, tx_err, efx->net_dev,11651165- "TX DMA Q %d reports descriptor fetch error."11661166- " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);11671167- efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);979979+ if (ev_sub_data < EFX_VI_BASE) {980980+ netif_err(efx, tx_err, efx->net_dev,981981+ "TX DMA Q %d reports descriptor fetch error."982982+ " TX Q %d is disabled.\n", ev_sub_data,983983+ ev_sub_data);984984+ efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);985985+ } else986986+ efx_sriov_desc_fetch_err(efx, ev_sub_data);1168987 break;1169988 default:1170989 netif_vdbg(efx, hw, efx->net_dev,···12311034 break;12321035 case FSE_AZ_EV_CODE_DRIVER_EV:12331036 efx_handle_driver_event(channel, &event);10371037+ break;10381038+ case FSE_CZ_EV_CODE_USER_EV:10391039+ efx_sriov_event(channel, &event);12341040 break;12351041 case FSE_CZ_EV_CODE_MCDI_EV:12361042 efx_mcdi_process_event(channel, &event);···1335113513361136void efx_nic_generate_test_event(struct efx_channel *channel)13371137{13381338- unsigned int magic = EFX_CHANNEL_MAGIC_TEST(channel);13391339- efx_qword_t test_event;13401340-13411341- EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,13421342- FSE_AZ_EV_CODE_DRV_GEN_EV,13431343- FSF_AZ_DRV_GEN_EV_MAGIC, magic);13441344- efx_generate_event(channel, &test_event);11381138+ efx_magic_event(channel, EFX_CHANNEL_MAGIC_TEST(channel));13451139}1346114013471347-void efx_nic_generate_fill_event(struct efx_channel *channel)11411141+void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)13481142{13491349- unsigned int magic = EFX_CHANNEL_MAGIC_FILL(channel);13501350- efx_qword_t test_event;13511351-13521352- EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,13531353- FSE_AZ_EV_CODE_DRV_GEN_EV,13541354- FSF_AZ_DRV_GEN_EV_MAGIC, magic);13551355- efx_generate_event(channel, &test_event);13561356-}13571357-13581358-/**************************************************************************13591359- *13601360- * Flush handling13611361- *13621362- **************************************************************************/13631363-13641364-13651365-static void efx_poll_flush_events(struct efx_nic *efx)13661366-{13671367- struct efx_channel *channel = efx_get_channel(efx, 0);13681368- struct efx_tx_queue *tx_queue;13691369- struct efx_rx_queue *rx_queue;13701370- unsigned int read_ptr = channel->eventq_read_ptr;13711371- unsigned int end_ptr = read_ptr + channel->eventq_mask - 1;13721372-13731373- do {13741374- efx_qword_t *event = efx_event(channel, read_ptr);13751375- int ev_code, ev_sub_code, ev_queue;13761376- bool ev_failed;13771377-13781378- if (!efx_event_present(event))13791379- break;13801380-13811381- ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);13821382- ev_sub_code = EFX_QWORD_FIELD(*event,13831383- FSF_AZ_DRIVER_EV_SUBCODE);13841384- if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&13851385- ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {13861386- ev_queue = EFX_QWORD_FIELD(*event,13871387- FSF_AZ_DRIVER_EV_SUBDATA);13881388- if (ev_queue < EFX_TXQ_TYPES * efx->n_tx_channels) {13891389- tx_queue = efx_get_tx_queue(13901390- efx, ev_queue / EFX_TXQ_TYPES,13911391- ev_queue % EFX_TXQ_TYPES);13921392- tx_queue->flushed = FLUSH_DONE;13931393- }13941394- } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&13951395- ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {13961396- ev_queue = EFX_QWORD_FIELD(13971397- *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);13981398- ev_failed = EFX_QWORD_FIELD(13991399- *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);14001400- if (ev_queue < efx->n_rx_channels) {14011401- rx_queue = efx_get_rx_queue(efx, ev_queue);14021402- rx_queue->flushed =14031403- ev_failed ? FLUSH_FAILED : FLUSH_DONE;14041404- }14051405- }14061406-14071407- /* We're about to destroy the queue anyway, so14081408- * it's ok to throw away every non-flush event */14091409- EFX_SET_QWORD(*event);14101410-14111411- ++read_ptr;14121412- } while (read_ptr != end_ptr);14131413-14141414- channel->eventq_read_ptr = read_ptr;14151415-}14161416-14171417-/* Handle tx and rx flushes at the same time, since they run in14181418- * parallel in the hardware and there's no reason for us to14191419- * serialise them */14201420-int efx_nic_flush_queues(struct efx_nic *efx)14211421-{14221422- struct efx_channel *channel;14231423- struct efx_rx_queue *rx_queue;14241424- struct efx_tx_queue *tx_queue;14251425- int i, tx_pending, rx_pending;14261426-14271427- /* If necessary prepare the hardware for flushing */14281428- efx->type->prepare_flush(efx);14291429-14301430- /* Flush all tx queues in parallel */14311431- efx_for_each_channel(channel, efx) {14321432- efx_for_each_possible_channel_tx_queue(tx_queue, channel) {14331433- if (tx_queue->initialised)14341434- efx_flush_tx_queue(tx_queue);14351435- }14361436- }14371437-14381438- /* The hardware supports four concurrent rx flushes, each of which may14391439- * need to be retried if there is an outstanding descriptor fetch */14401440- for (i = 0; i < EFX_FLUSH_POLL_COUNT; ++i) {14411441- rx_pending = tx_pending = 0;14421442- efx_for_each_channel(channel, efx) {14431443- efx_for_each_channel_rx_queue(rx_queue, channel) {14441444- if (rx_queue->flushed == FLUSH_PENDING)14451445- ++rx_pending;14461446- }14471447- }14481448- efx_for_each_channel(channel, efx) {14491449- efx_for_each_channel_rx_queue(rx_queue, channel) {14501450- if (rx_pending == EFX_RX_FLUSH_COUNT)14511451- break;14521452- if (rx_queue->flushed == FLUSH_FAILED ||14531453- rx_queue->flushed == FLUSH_NONE) {14541454- efx_flush_rx_queue(rx_queue);14551455- ++rx_pending;14561456- }14571457- }14581458- efx_for_each_possible_channel_tx_queue(tx_queue, channel) {14591459- if (tx_queue->initialised &&14601460- tx_queue->flushed != FLUSH_DONE)14611461- ++tx_pending;14621462- }14631463- }14641464-14651465- if (rx_pending == 0 && tx_pending == 0)14661466- return 0;14671467-14681468- msleep(EFX_FLUSH_INTERVAL);14691469- efx_poll_flush_events(efx);14701470- }14711471-14721472- /* Mark the queues as all flushed. We're going to return failure14731473- * leading to a reset, or fake up success anyway */14741474- efx_for_each_channel(channel, efx) {14751475- efx_for_each_possible_channel_tx_queue(tx_queue, channel) {14761476- if (tx_queue->initialised &&14771477- tx_queue->flushed != FLUSH_DONE)14781478- netif_err(efx, hw, efx->net_dev,14791479- "tx queue %d flush command timed out\n",14801480- tx_queue->queue);14811481- tx_queue->flushed = FLUSH_DONE;14821482- }14831483- efx_for_each_channel_rx_queue(rx_queue, channel) {14841484- if (rx_queue->flushed != FLUSH_DONE)14851485- netif_err(efx, hw, efx->net_dev,14861486- "rx queue %d flush command timed out\n",14871487- efx_rx_queue_index(rx_queue));14881488- rx_queue->flushed = FLUSH_DONE;14891489- }14901490- }14911491-14921492- return -ETIMEDOUT;11431143+ efx_magic_event(efx_rx_queue_channel(rx_queue),11441144+ EFX_CHANNEL_MAGIC_FILL(rx_queue));14931145}1494114614951147/**************************************************************************···1367131513681316void efx_nic_enable_interrupts(struct efx_nic *efx)13691317{13701370- struct efx_channel *channel;13711371-13721318 EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));13731319 wmb(); /* Ensure interrupt vector is clear before interrupts enabled */1374132013751375- /* Enable interrupts */13761321 efx_nic_interrupts(efx, true, false);13771377-13781378- /* Force processing of all the channels to get the EVQ RPTRs up to13791379- date */13801380- efx_for_each_channel(channel, efx)13811381- efx_schedule_channel(channel);13821322}1383132313841324void efx_nic_disable_interrupts(struct efx_nic *efx)···16371593 free_irq(efx->legacy_irq, efx);16381594}1639159515961596+/* Looks at available SRAM resources and works out how many queues we15971597+ * can support, and where things like descriptor caches should live.15981598+ *15991599+ * SRAM is split up as follows:16001600+ * 0 buftbl entries for channels16011601+ * efx->vf_buftbl_base buftbl entries for SR-IOV16021602+ * efx->rx_dc_base RX descriptor caches16031603+ * efx->tx_dc_base TX descriptor caches16041604+ */16051605+void efx_nic_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw)16061606+{16071607+ unsigned vi_count, buftbl_min;16081608+16091609+ /* Account for the buffer table entries backing the datapath channels16101610+ * and the descriptor caches for those channels.16111611+ */16121612+ buftbl_min = ((efx->n_rx_channels * EFX_MAX_DMAQ_SIZE +16131613+ efx->n_tx_channels * EFX_TXQ_TYPES * EFX_MAX_DMAQ_SIZE +16141614+ efx->n_channels * EFX_MAX_EVQ_SIZE)16151615+ * sizeof(efx_qword_t) / EFX_BUF_SIZE);16161616+ vi_count = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);16171617+16181618+#ifdef CONFIG_SFC_SRIOV16191619+ if (efx_sriov_wanted(efx)) {16201620+ unsigned vi_dc_entries, buftbl_free, entries_per_vf, vf_limit;16211621+16221622+ efx->vf_buftbl_base = buftbl_min;16231623+16241624+ vi_dc_entries = RX_DC_ENTRIES + TX_DC_ENTRIES;16251625+ vi_count = max(vi_count, EFX_VI_BASE);16261626+ buftbl_free = (sram_lim_qw - buftbl_min -16271627+ vi_count * vi_dc_entries);16281628+16291629+ entries_per_vf = ((vi_dc_entries + EFX_VF_BUFTBL_PER_VI) *16301630+ efx_vf_size(efx));16311631+ vf_limit = min(buftbl_free / entries_per_vf,16321632+ (1024U - EFX_VI_BASE) >> efx->vi_scale);16331633+16341634+ if (efx->vf_count > vf_limit) {16351635+ netif_err(efx, probe, efx->net_dev,16361636+ "Reducing VF count from from %d to %d\n",16371637+ efx->vf_count, vf_limit);16381638+ efx->vf_count = vf_limit;16391639+ }16401640+ vi_count += efx->vf_count * efx_vf_size(efx);16411641+ }16421642+#endif16431643+16441644+ efx->tx_dc_base = sram_lim_qw - vi_count * TX_DC_ENTRIES;16451645+ efx->rx_dc_base = efx->tx_dc_base - vi_count * RX_DC_ENTRIES;16461646+}16471647+16401648u32 efx_nic_fpga_ver(struct efx_nic *efx)16411649{16421650 efx_oword_t altera_build;···17011605 efx_oword_t temp;1702160617031607 /* Set positions of descriptor caches in SRAM. */17041704- EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR,17051705- efx->type->tx_dc_base / 8);16081608+ EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR, efx->tx_dc_base);17061609 efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);17071707- EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR,17081708- efx->type->rx_dc_base / 8);16101610+ EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR, efx->rx_dc_base);17091611 efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);1710161217111613 /* Set TX descriptor cache size. */
+99-3
drivers/net/ethernet/sfc/nic.h
···6565#define FALCON_GMAC_LOOPBACKS \6666 (1 << LOOPBACK_GMAC)67676868+/* Alignment of PCIe DMA boundaries (4KB) */6969+#define EFX_PAGE_SIZE 40967070+/* Size and alignment of buffer table entries (same) */7171+#define EFX_BUF_SIZE EFX_PAGE_SIZE7272+6873/**6974 * struct falcon_board_type - board operations and type information7075 * @id: Board type id, as found in NVRAM···169164}170165#endif171166167167+/*168168+ * On the SFC9000 family each port is associated with 1 PCI physical169169+ * function (PF) handled by sfc and a configurable number of virtual170170+ * functions (VFs) that may be handled by some other driver, often in171171+ * a VM guest. The queue pointer registers are mapped in both PF and172172+ * VF BARs such that an 8K region provides access to a single RX, TX173173+ * and event queue (collectively a Virtual Interface, VI or VNIC).174174+ *175175+ * The PF has access to all 1024 VIs while VFs are mapped to VIs176176+ * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered177177+ * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE).178178+ * The number of VIs and the VI_SCALE value are configurable but must179179+ * be established at boot time by firmware.180180+ */181181+182182+/* Maximum VI_SCALE parameter supported by Siena */183183+#define EFX_VI_SCALE_MAX 6184184+/* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX),185185+ * so this is the smallest allowed value. */186186+#define EFX_VI_BASE 128U187187+/* Maximum number of VFs allowed */188188+#define EFX_VF_COUNT_MAX 127189189+/* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */190190+#define EFX_MAX_VF_EVQ_SIZE 8192UL191191+/* The number of buffer table entries reserved for each VI on a VF */192192+#define EFX_VF_BUFTBL_PER_VI \193193+ ((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) * \194194+ sizeof(efx_qword_t) / EFX_BUF_SIZE)195195+196196+#ifdef CONFIG_SFC_SRIOV197197+198198+static inline bool efx_sriov_wanted(struct efx_nic *efx)199199+{200200+ return efx->vf_count != 0;201201+}202202+static inline bool efx_sriov_enabled(struct efx_nic *efx)203203+{204204+ return efx->vf_init_count != 0;205205+}206206+static inline unsigned int efx_vf_size(struct efx_nic *efx)207207+{208208+ return 1 << efx->vi_scale;209209+}210210+211211+extern int efx_init_sriov(void);212212+extern void efx_sriov_probe(struct efx_nic *efx);213213+extern int efx_sriov_init(struct efx_nic *efx);214214+extern void efx_sriov_mac_address_changed(struct efx_nic *efx);215215+extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event);216216+extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event);217217+extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event);218218+extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq);219219+extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr);220220+extern void efx_sriov_reset(struct efx_nic *efx);221221+extern void efx_sriov_fini(struct efx_nic *efx);222222+extern void efx_fini_sriov(void);223223+224224+#else225225+226226+static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; }227227+static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; }228228+static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; }229229+230230+static inline int efx_init_sriov(void) { return 0; }231231+static inline void efx_sriov_probe(struct efx_nic *efx) {}232232+static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; }233233+static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {}234234+static inline void efx_sriov_tx_flush_done(struct efx_nic *efx,235235+ efx_qword_t *event) {}236236+static inline void efx_sriov_rx_flush_done(struct efx_nic *efx,237237+ efx_qword_t *event) {}238238+static inline void efx_sriov_event(struct efx_channel *channel,239239+ efx_qword_t *event) {}240240+static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {}241241+static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {}242242+static inline void efx_sriov_reset(struct efx_nic *efx) {}243243+static inline void efx_sriov_fini(struct efx_nic *efx) {}244244+static inline void efx_fini_sriov(void) {}245245+246246+#endif247247+248248+extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac);249249+extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf,250250+ u16 vlan, u8 qos);251251+extern int efx_sriov_get_vf_config(struct net_device *dev, int vf,252252+ struct ifla_vf_info *ivf);253253+extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf,254254+ bool spoofchk);255255+172256extern const struct efx_nic_type falcon_a1_nic_type;173257extern const struct efx_nic_type falcon_b0_nic_type;174258extern const struct efx_nic_type siena_a0_nic_type;···284190extern void efx_nic_fini_rx(struct efx_rx_queue *rx_queue);285191extern void efx_nic_remove_rx(struct efx_rx_queue *rx_queue);286192extern void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue);193193+extern void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue);287194288195/* Event data path */289196extern int efx_nic_probe_eventq(struct efx_channel *channel);···306211extern int efx_nic_init_interrupt(struct efx_nic *efx);307212extern void efx_nic_enable_interrupts(struct efx_nic *efx);308213extern void efx_nic_generate_test_event(struct efx_channel *channel);309309-extern void efx_nic_generate_fill_event(struct efx_channel *channel);310214extern void efx_nic_generate_interrupt(struct efx_nic *efx);311215extern void efx_nic_disable_interrupts(struct efx_nic *efx);312216extern void efx_nic_fini_interrupt(struct efx_nic *efx);···319225extern void falcon_stop_nic_stats(struct efx_nic *efx);320226extern void falcon_setup_xaui(struct efx_nic *efx);321227extern int falcon_reset_xaui(struct efx_nic *efx);228228+extern void229229+efx_nic_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);322230extern void efx_nic_init_common(struct efx_nic *efx);323231extern void efx_nic_push_rx_indir_table(struct efx_nic *efx);324232···374278#define MAC_DATA_LBN 0375279#define MAC_DATA_WIDTH 32376280377377-extern void efx_nic_generate_event(struct efx_channel *channel,378378- efx_qword_t *event);281281+extern void efx_generate_event(struct efx_nic *efx, unsigned int evq,282282+ efx_qword_t *event);379283380284extern void falcon_poll_xmac(struct efx_nic *efx);381285
+10-10
drivers/net/ethernet/sfc/regs.h
···24462446#define FRF_CZ_RMFT_RXQ_ID_WIDTH 1224472447#define FRF_CZ_RMFT_WILDCARD_MATCH_LBN 6024482448#define FRF_CZ_RMFT_WILDCARD_MATCH_WIDTH 124492449-#define FRF_CZ_RMFT_DEST_MAC_LBN 1624502450-#define FRF_CZ_RMFT_DEST_MAC_WIDTH 4424492449+#define FRF_CZ_RMFT_DEST_MAC_LBN 1224502450+#define FRF_CZ_RMFT_DEST_MAC_WIDTH 4824512451#define FRF_CZ_RMFT_VLAN_ID_LBN 024522452#define FRF_CZ_RMFT_VLAN_ID_WIDTH 1224532453···25232523#define FRF_CZ_TMFT_TXQ_ID_WIDTH 1225242524#define FRF_CZ_TMFT_WILDCARD_MATCH_LBN 6025252525#define FRF_CZ_TMFT_WILDCARD_MATCH_WIDTH 125262526-#define FRF_CZ_TMFT_SRC_MAC_LBN 1625272527-#define FRF_CZ_TMFT_SRC_MAC_WIDTH 4425262526+#define FRF_CZ_TMFT_SRC_MAC_LBN 1225272527+#define FRF_CZ_TMFT_SRC_MAC_WIDTH 4825282528#define FRF_CZ_TMFT_VLAN_ID_LBN 025292529#define FRF_CZ_TMFT_VLAN_ID_WIDTH 1225302530···2895289528962896/* RX_MAC_FILTER_TBL0 */28972897/* RMFT_DEST_MAC is wider than 32 bits */28982898-#define FRF_CZ_RMFT_DEST_MAC_LO_LBN 1228982898+#define FRF_CZ_RMFT_DEST_MAC_LO_LBN FRF_CZ_RMFT_DEST_MAC_LBN28992899#define FRF_CZ_RMFT_DEST_MAC_LO_WIDTH 3229002900-#define FRF_CZ_RMFT_DEST_MAC_HI_LBN 4429012901-#define FRF_CZ_RMFT_DEST_MAC_HI_WIDTH 1629002900+#define FRF_CZ_RMFT_DEST_MAC_HI_LBN (FRF_CZ_RMFT_DEST_MAC_LBN + 32)29012901+#define FRF_CZ_RMFT_DEST_MAC_HI_WIDTH (FRF_CZ_RMFT_DEST_MAC_WIDTH - 32)2902290229032903/* TX_MAC_FILTER_TBL0 */29042904/* TMFT_SRC_MAC is wider than 32 bits */29052905-#define FRF_CZ_TMFT_SRC_MAC_LO_LBN 1229052905+#define FRF_CZ_TMFT_SRC_MAC_LO_LBN FRF_CZ_TMFT_SRC_MAC_LBN29062906#define FRF_CZ_TMFT_SRC_MAC_LO_WIDTH 3229072907-#define FRF_CZ_TMFT_SRC_MAC_HI_LBN 4429082908-#define FRF_CZ_TMFT_SRC_MAC_HI_WIDTH 1629072907+#define FRF_CZ_TMFT_SRC_MAC_HI_LBN (FRF_CZ_TMFT_SRC_MAC_LBN + 32)29082908+#define FRF_CZ_TMFT_SRC_MAC_HI_WIDTH (FRF_CZ_TMFT_SRC_MAC_WIDTH - 32)2909290929102910/* TX_PACE_TBL */29112911/* Values >20 are documented as reserved, but will result in a queue going
+5-2
drivers/net/ethernet/sfc/rx.c
···405405void efx_rx_slow_fill(unsigned long context)406406{407407 struct efx_rx_queue *rx_queue = (struct efx_rx_queue *)context;408408- struct efx_channel *channel = efx_rx_queue_channel(rx_queue);409408410409 /* Post an event to cause NAPI to run and refill the queue */411411- efx_nic_generate_fill_event(channel);410410+ efx_nic_generate_fill_event(rx_queue);412411 ++rx_queue->slow_fill_count;413412}414413···705706 rx_queue->fast_fill_limit = limit;706707707708 /* Set up RX descriptor ring */709709+ rx_queue->enabled = true;708710 efx_nic_init_rx(rx_queue);709711}710712···716716717717 netif_dbg(rx_queue->efx, drv, rx_queue->efx->net_dev,718718 "shutting down RX queue %d\n", efx_rx_queue_index(rx_queue));719719+720720+ /* A flush failure might have left rx_queue->enabled */721721+ rx_queue->enabled = false;719722720723 del_timer_sync(&rx_queue->slow_fill);721724 efx_nic_fini_rx(rx_queue);
+12-2
drivers/net/ethernet/sfc/siena.c
···225225 return rc;226226}227227228228+static void siena_dimension_resources(struct efx_nic *efx)229229+{230230+ /* Each port has a small block of internal SRAM dedicated to231231+ * the buffer table and descriptor caches. In theory we can232232+ * map both blocks to one port, but we don't.233233+ */234234+ efx_nic_dimension_resources(efx, FR_CZ_BUF_FULL_TBL_ROWS / 2);235235+}236236+228237static int siena_probe_nic(struct efx_nic *efx)229238{230239 struct siena_nic_data *nic_data;···312303 rc = efx_mcdi_mon_probe(efx);313304 if (rc)314305 goto fail5;306306+307307+ efx_sriov_probe(efx);315308316309 return 0;317310···630619 .probe = siena_probe_nic,631620 .remove = siena_remove_nic,632621 .init = siena_init_nic,622622+ .dimension_resources = siena_dimension_resources,633623 .fini = efx_port_dummy_op_void,634624 .monitor = NULL,635625 .map_reset_reason = siena_map_reset_reason,···669657 * interrupt handler only supports 32670658 * channels */671659 .timer_period_max = 1 << FRF_CZ_TC_TIMER_VAL_WIDTH,672672- .tx_dc_base = 0x88000,673673- .rx_dc_base = 0x68000,674660 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |675661 NETIF_F_RXHASH | NETIF_F_NTUPLE),676662};
+1642
drivers/net/ethernet/sfc/siena_sriov.c
···11+/****************************************************************************22+ * Driver for Solarflare Solarstorm network controllers and boards33+ * Copyright 2010-2011 Solarflare Communications Inc.44+ *55+ * This program is free software; you can redistribute it and/or modify it66+ * under the terms of the GNU General Public License version 2 as published77+ * by the Free Software Foundation, incorporated herein by reference.88+ */99+#include <linux/pci.h>1010+#include <linux/module.h>1111+#include "net_driver.h"1212+#include "efx.h"1313+#include "nic.h"1414+#include "io.h"1515+#include "mcdi.h"1616+#include "filter.h"1717+#include "mcdi_pcol.h"1818+#include "regs.h"1919+#include "vfdi.h"2020+2121+/* Number of longs required to track all the VIs in a VF */2222+#define VI_MASK_LENGTH BITS_TO_LONGS(1 << EFX_VI_SCALE_MAX)2323+2424+/**2525+ * enum efx_vf_tx_filter_mode - TX MAC filtering behaviour2626+ * @VF_TX_FILTER_OFF: Disabled2727+ * @VF_TX_FILTER_AUTO: Enabled if MAC address assigned to VF and only2828+ * 2 TX queues allowed per VF.2929+ * @VF_TX_FILTER_ON: Enabled3030+ */3131+enum efx_vf_tx_filter_mode {3232+ VF_TX_FILTER_OFF,3333+ VF_TX_FILTER_AUTO,3434+ VF_TX_FILTER_ON,3535+};3636+3737+/**3838+ * struct efx_vf - Back-end resource and protocol state for a PCI VF3939+ * @efx: The Efx NIC owning this VF4040+ * @pci_rid: The PCI requester ID for this VF4141+ * @pci_name: The PCI name (formatted address) of this VF4242+ * @index: Index of VF within its port and PF.4343+ * @req: VFDI incoming request work item. Incoming USR_EV events are received4444+ * by the NAPI handler, but must be handled by executing MCDI requests4545+ * inside a work item.4646+ * @req_addr: VFDI incoming request DMA address (in VF's PCI address space).4747+ * @req_type: Expected next incoming (from VF) %VFDI_EV_TYPE member.4848+ * @req_seqno: Expected next incoming (from VF) %VFDI_EV_SEQ member.4949+ * @msg_seqno: Next %VFDI_EV_SEQ member to reply to VF. Protected by5050+ * @status_lock5151+ * @busy: VFDI request queued to be processed or being processed. Receiving5252+ * a VFDI request when @busy is set is an error condition.5353+ * @buf: Incoming VFDI requests are DMA from the VF into this buffer.5454+ * @buftbl_base: Buffer table entries for this VF start at this index.5555+ * @rx_filtering: Receive filtering has been requested by the VF driver.5656+ * @rx_filter_flags: The flags sent in the %VFDI_OP_INSERT_FILTER request.5757+ * @rx_filter_qid: VF relative qid for RX filter requested by VF.5858+ * @rx_filter_id: Receive MAC filter ID. Only one filter per VF is supported.5959+ * @tx_filter_mode: Transmit MAC filtering mode.6060+ * @tx_filter_id: Transmit MAC filter ID.6161+ * @addr: The MAC address and outer vlan tag of the VF.6262+ * @status_addr: VF DMA address of page for &struct vfdi_status updates.6363+ * @status_lock: Mutex protecting @msg_seqno, @status_addr, @addr,6464+ * @peer_page_addrs and @peer_page_count from simultaneous6565+ * updates by the VM and consumption by6666+ * efx_sriov_update_vf_addr()6767+ * @peer_page_addrs: Pointer to an array of guest pages for local addresses.6868+ * @peer_page_count: Number of entries in @peer_page_count.6969+ * @evq0_addrs: Array of guest pages backing evq0.7070+ * @evq0_count: Number of entries in @evq0_addrs.7171+ * @flush_waitq: wait queue used by %VFDI_OP_FINI_ALL_QUEUES handler7272+ * to wait for flush completions.7373+ * @txq_lock: Mutex for TX queue allocation.7474+ * @txq_mask: Mask of initialized transmit queues.7575+ * @txq_count: Number of initialized transmit queues.7676+ * @rxq_mask: Mask of initialized receive queues.7777+ * @rxq_count: Number of initialized receive queues.7878+ * @rxq_retry_mask: Mask or receive queues that need to be flushed again7979+ * due to flush failure.8080+ * @rxq_retry_count: Number of receive queues in @rxq_retry_mask.8181+ * @reset_work: Work item to schedule a VF reset.8282+ */8383+struct efx_vf {8484+ struct efx_nic *efx;8585+ unsigned int pci_rid;8686+ char pci_name[13]; /* dddd:bb:dd.f */8787+ unsigned int index;8888+ struct work_struct req;8989+ u64 req_addr;9090+ int req_type;9191+ unsigned req_seqno;9292+ unsigned msg_seqno;9393+ bool busy;9494+ struct efx_buffer buf;9595+ unsigned buftbl_base;9696+ bool rx_filtering;9797+ enum efx_filter_flags rx_filter_flags;9898+ unsigned rx_filter_qid;9999+ int rx_filter_id;100100+ enum efx_vf_tx_filter_mode tx_filter_mode;101101+ int tx_filter_id;102102+ struct vfdi_endpoint addr;103103+ u64 status_addr;104104+ struct mutex status_lock;105105+ u64 *peer_page_addrs;106106+ unsigned peer_page_count;107107+ u64 evq0_addrs[EFX_MAX_VF_EVQ_SIZE * sizeof(efx_qword_t) /108108+ EFX_BUF_SIZE];109109+ unsigned evq0_count;110110+ wait_queue_head_t flush_waitq;111111+ struct mutex txq_lock;112112+ unsigned long txq_mask[VI_MASK_LENGTH];113113+ unsigned txq_count;114114+ unsigned long rxq_mask[VI_MASK_LENGTH];115115+ unsigned rxq_count;116116+ unsigned long rxq_retry_mask[VI_MASK_LENGTH];117117+ atomic_t rxq_retry_count;118118+ struct work_struct reset_work;119119+};120120+121121+struct efx_memcpy_req {122122+ unsigned int from_rid;123123+ void *from_buf;124124+ u64 from_addr;125125+ unsigned int to_rid;126126+ u64 to_addr;127127+ unsigned length;128128+};129129+130130+/**131131+ * struct efx_local_addr - A MAC address on the vswitch without a VF.132132+ *133133+ * Siena does not have a switch, so VFs can't transmit data to each134134+ * other. Instead the VFs must be made aware of the local addresses135135+ * on the vswitch, so that they can arrange for an alternative136136+ * software datapath to be used.137137+ *138138+ * @link: List head for insertion into efx->local_addr_list.139139+ * @addr: Ethernet address140140+ */141141+struct efx_local_addr {142142+ struct list_head link;143143+ u8 addr[ETH_ALEN];144144+};145145+146146+/**147147+ * struct efx_endpoint_page - Page of vfdi_endpoint structures148148+ *149149+ * @link: List head for insertion into efx->local_page_list.150150+ * @ptr: Pointer to page.151151+ * @addr: DMA address of page.152152+ */153153+struct efx_endpoint_page {154154+ struct list_head link;155155+ void *ptr;156156+ dma_addr_t addr;157157+};158158+159159+/* Buffer table entries are reserved txq0,rxq0,evq0,txq1,rxq1,evq1 */160160+#define EFX_BUFTBL_TXQ_BASE(_vf, _qid) \161161+ ((_vf)->buftbl_base + EFX_VF_BUFTBL_PER_VI * (_qid))162162+#define EFX_BUFTBL_RXQ_BASE(_vf, _qid) \163163+ (EFX_BUFTBL_TXQ_BASE(_vf, _qid) + \164164+ (EFX_MAX_DMAQ_SIZE * sizeof(efx_qword_t) / EFX_BUF_SIZE))165165+#define EFX_BUFTBL_EVQ_BASE(_vf, _qid) \166166+ (EFX_BUFTBL_TXQ_BASE(_vf, _qid) + \167167+ (2 * EFX_MAX_DMAQ_SIZE * sizeof(efx_qword_t) / EFX_BUF_SIZE))168168+169169+#define EFX_FIELD_MASK(_field) \170170+ ((1 << _field ## _WIDTH) - 1)171171+172172+/* VFs can only use this many transmit channels */173173+static unsigned int vf_max_tx_channels = 2;174174+module_param(vf_max_tx_channels, uint, 0444);175175+MODULE_PARM_DESC(vf_max_tx_channels,176176+ "Limit the number of TX channels VFs can use");177177+178178+static int max_vfs = -1;179179+module_param(max_vfs, int, 0444);180180+MODULE_PARM_DESC(max_vfs,181181+ "Reduce the number of VFs initialized by the driver");182182+183183+/* Workqueue used by VFDI communication. We can't use the global184184+ * workqueue because it may be running the VF driver's probe()185185+ * routine, which will be blocked there waiting for a VFDI response.186186+ */187187+static struct workqueue_struct *vfdi_workqueue;188188+189189+static unsigned abs_index(struct efx_vf *vf, unsigned index)190190+{191191+ return EFX_VI_BASE + vf->index * efx_vf_size(vf->efx) + index;192192+}193193+194194+static int efx_sriov_cmd(struct efx_nic *efx, bool enable,195195+ unsigned *vi_scale_out, unsigned *vf_total_out)196196+{197197+ u8 inbuf[MC_CMD_SRIOV_IN_LEN];198198+ u8 outbuf[MC_CMD_SRIOV_OUT_LEN];199199+ unsigned vi_scale, vf_total;200200+ size_t outlen;201201+ int rc;202202+203203+ MCDI_SET_DWORD(inbuf, SRIOV_IN_ENABLE, enable ? 1 : 0);204204+ MCDI_SET_DWORD(inbuf, SRIOV_IN_VI_BASE, EFX_VI_BASE);205205+ MCDI_SET_DWORD(inbuf, SRIOV_IN_VF_COUNT, efx->vf_count);206206+207207+ rc = efx_mcdi_rpc(efx, MC_CMD_SRIOV, inbuf, MC_CMD_SRIOV_IN_LEN,208208+ outbuf, MC_CMD_SRIOV_OUT_LEN, &outlen);209209+ if (rc)210210+ return rc;211211+ if (outlen < MC_CMD_SRIOV_OUT_LEN)212212+ return -EIO;213213+214214+ vf_total = MCDI_DWORD(outbuf, SRIOV_OUT_VF_TOTAL);215215+ vi_scale = MCDI_DWORD(outbuf, SRIOV_OUT_VI_SCALE);216216+ if (vi_scale > EFX_VI_SCALE_MAX)217217+ return -EOPNOTSUPP;218218+219219+ if (vi_scale_out)220220+ *vi_scale_out = vi_scale;221221+ if (vf_total_out)222222+ *vf_total_out = vf_total;223223+224224+ return 0;225225+}226226+227227+static void efx_sriov_usrev(struct efx_nic *efx, bool enabled)228228+{229229+ efx_oword_t reg;230230+231231+ EFX_POPULATE_OWORD_2(reg,232232+ FRF_CZ_USREV_DIS, enabled ? 0 : 1,233233+ FRF_CZ_DFLT_EVQ, efx->vfdi_channel->channel);234234+ efx_writeo(efx, ®, FR_CZ_USR_EV_CFG);235235+}236236+237237+static int efx_sriov_memcpy(struct efx_nic *efx, struct efx_memcpy_req *req,238238+ unsigned int count)239239+{240240+ u8 *inbuf, *record;241241+ unsigned int used;242242+ u32 from_rid, from_hi, from_lo;243243+ int rc;244244+245245+ mb(); /* Finish writing source/reading dest before DMA starts */246246+247247+ used = MC_CMD_MEMCPY_IN_LEN(count);248248+ if (WARN_ON(used > MCDI_CTL_SDU_LEN_MAX))249249+ return -ENOBUFS;250250+251251+ /* Allocate room for the largest request */252252+ inbuf = kzalloc(MCDI_CTL_SDU_LEN_MAX, GFP_KERNEL);253253+ if (inbuf == NULL)254254+ return -ENOMEM;255255+256256+ record = inbuf;257257+ MCDI_SET_DWORD(record, MEMCPY_IN_RECORD, count);258258+ while (count-- > 0) {259259+ MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_TO_RID,260260+ req->to_rid);261261+ MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_TO_ADDR_LO,262262+ (u32)req->to_addr);263263+ MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_TO_ADDR_HI,264264+ (u32)(req->to_addr >> 32));265265+ if (req->from_buf == NULL) {266266+ from_rid = req->from_rid;267267+ from_lo = (u32)req->from_addr;268268+ from_hi = (u32)(req->from_addr >> 32);269269+ } else {270270+ if (WARN_ON(used + req->length > MCDI_CTL_SDU_LEN_MAX)) {271271+ rc = -ENOBUFS;272272+ goto out;273273+ }274274+275275+ from_rid = MC_CMD_MEMCPY_RECORD_TYPEDEF_RID_INLINE;276276+ from_lo = used;277277+ from_hi = 0;278278+ memcpy(inbuf + used, req->from_buf, req->length);279279+ used += req->length;280280+ }281281+282282+ MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_RID, from_rid);283283+ MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_ADDR_LO,284284+ from_lo);285285+ MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_ADDR_HI,286286+ from_hi);287287+ MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_LENGTH,288288+ req->length);289289+290290+ ++req;291291+ record += MC_CMD_MEMCPY_IN_RECORD_LEN;292292+ }293293+294294+ rc = efx_mcdi_rpc(efx, MC_CMD_MEMCPY, inbuf, used, NULL, 0, NULL);295295+out:296296+ kfree(inbuf);297297+298298+ mb(); /* Don't write source/read dest before DMA is complete */299299+300300+ return rc;301301+}302302+303303+/* The TX filter is entirely controlled by this driver, and is modified304304+ * underneath the feet of the VF305305+ */306306+static void efx_sriov_reset_tx_filter(struct efx_vf *vf)307307+{308308+ struct efx_nic *efx = vf->efx;309309+ struct efx_filter_spec filter;310310+ u16 vlan;311311+ int rc;312312+313313+ if (vf->tx_filter_id != -1) {314314+ efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,315315+ vf->tx_filter_id);316316+ netif_dbg(efx, hw, efx->net_dev, "Removed vf %s tx filter %d\n",317317+ vf->pci_name, vf->tx_filter_id);318318+ vf->tx_filter_id = -1;319319+ }320320+321321+ if (is_zero_ether_addr(vf->addr.mac_addr))322322+ return;323323+324324+ /* Turn on TX filtering automatically if not explicitly325325+ * enabled or disabled.326326+ */327327+ if (vf->tx_filter_mode == VF_TX_FILTER_AUTO && vf_max_tx_channels <= 2)328328+ vf->tx_filter_mode = VF_TX_FILTER_ON;329329+330330+ vlan = ntohs(vf->addr.tci) & VLAN_VID_MASK;331331+ efx_filter_init_tx(&filter, abs_index(vf, 0));332332+ rc = efx_filter_set_eth_local(&filter,333333+ vlan ? vlan : EFX_FILTER_VID_UNSPEC,334334+ vf->addr.mac_addr);335335+ BUG_ON(rc);336336+337337+ rc = efx_filter_insert_filter(efx, &filter, true);338338+ if (rc < 0) {339339+ netif_warn(efx, hw, efx->net_dev,340340+ "Unable to migrate tx filter for vf %s\n",341341+ vf->pci_name);342342+ } else {343343+ netif_dbg(efx, hw, efx->net_dev, "Inserted vf %s tx filter %d\n",344344+ vf->pci_name, rc);345345+ vf->tx_filter_id = rc;346346+ }347347+}348348+349349+/* The RX filter is managed here on behalf of the VF driver */350350+static void efx_sriov_reset_rx_filter(struct efx_vf *vf)351351+{352352+ struct efx_nic *efx = vf->efx;353353+ struct efx_filter_spec filter;354354+ u16 vlan;355355+ int rc;356356+357357+ if (vf->rx_filter_id != -1) {358358+ efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,359359+ vf->rx_filter_id);360360+ netif_dbg(efx, hw, efx->net_dev, "Removed vf %s rx filter %d\n",361361+ vf->pci_name, vf->rx_filter_id);362362+ vf->rx_filter_id = -1;363363+ }364364+365365+ if (!vf->rx_filtering || is_zero_ether_addr(vf->addr.mac_addr))366366+ return;367367+368368+ vlan = ntohs(vf->addr.tci) & VLAN_VID_MASK;369369+ efx_filter_init_rx(&filter, EFX_FILTER_PRI_REQUIRED,370370+ vf->rx_filter_flags,371371+ abs_index(vf, vf->rx_filter_qid));372372+ rc = efx_filter_set_eth_local(&filter,373373+ vlan ? vlan : EFX_FILTER_VID_UNSPEC,374374+ vf->addr.mac_addr);375375+ BUG_ON(rc);376376+377377+ rc = efx_filter_insert_filter(efx, &filter, true);378378+ if (rc < 0) {379379+ netif_warn(efx, hw, efx->net_dev,380380+ "Unable to insert rx filter for vf %s\n",381381+ vf->pci_name);382382+ } else {383383+ netif_dbg(efx, hw, efx->net_dev, "Inserted vf %s rx filter %d\n",384384+ vf->pci_name, rc);385385+ vf->rx_filter_id = rc;386386+ }387387+}388388+389389+static void __efx_sriov_update_vf_addr(struct efx_vf *vf)390390+{391391+ efx_sriov_reset_tx_filter(vf);392392+ efx_sriov_reset_rx_filter(vf);393393+ queue_work(vfdi_workqueue, &vf->efx->peer_work);394394+}395395+396396+/* Push the peer list to this VF. The caller must hold status_lock to interlock397397+ * with VFDI requests, and they must be serialised against manipulation of398398+ * local_page_list, either by acquiring local_lock or by running from399399+ * efx_sriov_peer_work()400400+ */401401+static void __efx_sriov_push_vf_status(struct efx_vf *vf)402402+{403403+ struct efx_nic *efx = vf->efx;404404+ struct vfdi_status *status = efx->vfdi_status.addr;405405+ struct efx_memcpy_req copy[4];406406+ struct efx_endpoint_page *epp;407407+ unsigned int pos, count;408408+ unsigned data_offset;409409+ efx_qword_t event;410410+411411+ WARN_ON(!mutex_is_locked(&vf->status_lock));412412+ WARN_ON(!vf->status_addr);413413+414414+ status->local = vf->addr;415415+ status->generation_end = ++status->generation_start;416416+417417+ memset(copy, '\0', sizeof(copy));418418+ /* Write generation_start */419419+ copy[0].from_buf = &status->generation_start;420420+ copy[0].to_rid = vf->pci_rid;421421+ copy[0].to_addr = vf->status_addr + offsetof(struct vfdi_status,422422+ generation_start);423423+ copy[0].length = sizeof(status->generation_start);424424+ /* DMA the rest of the structure (excluding the generations). This425425+ * assumes that the non-generation portion of vfdi_status is in426426+ * one chunk starting at the version member.427427+ */428428+ data_offset = offsetof(struct vfdi_status, version);429429+ copy[1].from_rid = efx->pci_dev->devfn;430430+ copy[1].from_addr = efx->vfdi_status.dma_addr + data_offset;431431+ copy[1].to_rid = vf->pci_rid;432432+ copy[1].to_addr = vf->status_addr + data_offset;433433+ copy[1].length = status->length - data_offset;434434+435435+ /* Copy the peer pages */436436+ pos = 2;437437+ count = 0;438438+ list_for_each_entry(epp, &efx->local_page_list, link) {439439+ if (count == vf->peer_page_count) {440440+ /* The VF driver will know they need to provide more441441+ * pages because peer_addr_count is too large.442442+ */443443+ break;444444+ }445445+ copy[pos].from_buf = NULL;446446+ copy[pos].from_rid = efx->pci_dev->devfn;447447+ copy[pos].from_addr = epp->addr;448448+ copy[pos].to_rid = vf->pci_rid;449449+ copy[pos].to_addr = vf->peer_page_addrs[count];450450+ copy[pos].length = EFX_PAGE_SIZE;451451+452452+ if (++pos == ARRAY_SIZE(copy)) {453453+ efx_sriov_memcpy(efx, copy, ARRAY_SIZE(copy));454454+ pos = 0;455455+ }456456+ ++count;457457+ }458458+459459+ /* Write generation_end */460460+ copy[pos].from_buf = &status->generation_end;461461+ copy[pos].to_rid = vf->pci_rid;462462+ copy[pos].to_addr = vf->status_addr + offsetof(struct vfdi_status,463463+ generation_end);464464+ copy[pos].length = sizeof(status->generation_end);465465+ efx_sriov_memcpy(efx, copy, pos + 1);466466+467467+ /* Notify the guest */468468+ EFX_POPULATE_QWORD_3(event,469469+ FSF_AZ_EV_CODE, FSE_CZ_EV_CODE_USER_EV,470470+ VFDI_EV_SEQ, (vf->msg_seqno & 0xff),471471+ VFDI_EV_TYPE, VFDI_EV_TYPE_STATUS);472472+ ++vf->msg_seqno;473473+ efx_generate_event(efx, EFX_VI_BASE + vf->index * efx_vf_size(efx),474474+ &event);475475+}476476+477477+static void efx_sriov_bufs(struct efx_nic *efx, unsigned offset,478478+ u64 *addr, unsigned count)479479+{480480+ efx_qword_t buf;481481+ unsigned pos;482482+483483+ for (pos = 0; pos < count; ++pos) {484484+ EFX_POPULATE_QWORD_3(buf,485485+ FRF_AZ_BUF_ADR_REGION, 0,486486+ FRF_AZ_BUF_ADR_FBUF,487487+ addr ? addr[pos] >> 12 : 0,488488+ FRF_AZ_BUF_OWNER_ID_FBUF, 0);489489+ efx_sram_writeq(efx, efx->membase + FR_BZ_BUF_FULL_TBL,490490+ &buf, offset + pos);491491+ }492492+}493493+494494+static bool bad_vf_index(struct efx_nic *efx, unsigned index)495495+{496496+ return index >= efx_vf_size(efx);497497+}498498+499499+static bool bad_buf_count(unsigned buf_count, unsigned max_entry_count)500500+{501501+ unsigned max_buf_count = max_entry_count *502502+ sizeof(efx_qword_t) / EFX_BUF_SIZE;503503+504504+ return ((buf_count & (buf_count - 1)) || buf_count > max_buf_count);505505+}506506+507507+/* Check that VI specified by per-port index belongs to a VF.508508+ * Optionally set VF index and VI index within the VF.509509+ */510510+static bool map_vi_index(struct efx_nic *efx, unsigned abs_index,511511+ struct efx_vf **vf_out, unsigned *rel_index_out)512512+{513513+ unsigned vf_i;514514+515515+ if (abs_index < EFX_VI_BASE)516516+ return true;517517+ vf_i = (abs_index - EFX_VI_BASE) * efx_vf_size(efx);518518+ if (vf_i >= efx->vf_init_count)519519+ return true;520520+521521+ if (vf_out)522522+ *vf_out = efx->vf + vf_i;523523+ if (rel_index_out)524524+ *rel_index_out = abs_index % efx_vf_size(efx);525525+ return false;526526+}527527+528528+static int efx_vfdi_init_evq(struct efx_vf *vf)529529+{530530+ struct efx_nic *efx = vf->efx;531531+ struct vfdi_req *req = vf->buf.addr;532532+ unsigned vf_evq = req->u.init_evq.index;533533+ unsigned buf_count = req->u.init_evq.buf_count;534534+ unsigned abs_evq = abs_index(vf, vf_evq);535535+ unsigned buftbl = EFX_BUFTBL_EVQ_BASE(vf, vf_evq);536536+ efx_oword_t reg;537537+538538+ if (bad_vf_index(efx, vf_evq) ||539539+ bad_buf_count(buf_count, EFX_MAX_VF_EVQ_SIZE)) {540540+ if (net_ratelimit())541541+ netif_err(efx, hw, efx->net_dev,542542+ "ERROR: Invalid INIT_EVQ from %s: evq %d bufs %d\n",543543+ vf->pci_name, vf_evq, buf_count);544544+ return VFDI_RC_EINVAL;545545+ }546546+547547+ efx_sriov_bufs(efx, buftbl, req->u.init_evq.addr, buf_count);548548+549549+ EFX_POPULATE_OWORD_3(reg,550550+ FRF_CZ_TIMER_Q_EN, 1,551551+ FRF_CZ_HOST_NOTIFY_MODE, 0,552552+ FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);553553+ efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, abs_evq);554554+ EFX_POPULATE_OWORD_3(reg,555555+ FRF_AZ_EVQ_EN, 1,556556+ FRF_AZ_EVQ_SIZE, __ffs(buf_count),557557+ FRF_AZ_EVQ_BUF_BASE_ID, buftbl);558558+ efx_writeo_table(efx, ®, FR_BZ_EVQ_PTR_TBL, abs_evq);559559+560560+ if (vf_evq == 0) {561561+ memcpy(vf->evq0_addrs, req->u.init_evq.addr,562562+ buf_count * sizeof(u64));563563+ vf->evq0_count = buf_count;564564+ }565565+566566+ return VFDI_RC_SUCCESS;567567+}568568+569569+static int efx_vfdi_init_rxq(struct efx_vf *vf)570570+{571571+ struct efx_nic *efx = vf->efx;572572+ struct vfdi_req *req = vf->buf.addr;573573+ unsigned vf_rxq = req->u.init_rxq.index;574574+ unsigned vf_evq = req->u.init_rxq.evq;575575+ unsigned buf_count = req->u.init_rxq.buf_count;576576+ unsigned buftbl = EFX_BUFTBL_RXQ_BASE(vf, vf_rxq);577577+ unsigned label;578578+ efx_oword_t reg;579579+580580+ if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_rxq) ||581581+ bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) {582582+ if (net_ratelimit())583583+ netif_err(efx, hw, efx->net_dev,584584+ "ERROR: Invalid INIT_RXQ from %s: rxq %d evq %d "585585+ "buf_count %d\n", vf->pci_name, vf_rxq,586586+ vf_evq, buf_count);587587+ return VFDI_RC_EINVAL;588588+ }589589+ if (__test_and_set_bit(req->u.init_rxq.index, vf->rxq_mask))590590+ ++vf->rxq_count;591591+ efx_sriov_bufs(efx, buftbl, req->u.init_rxq.addr, buf_count);592592+593593+ label = req->u.init_rxq.label & EFX_FIELD_MASK(FRF_AZ_RX_DESCQ_LABEL);594594+ EFX_POPULATE_OWORD_6(reg,595595+ FRF_AZ_RX_DESCQ_BUF_BASE_ID, buftbl,596596+ FRF_AZ_RX_DESCQ_EVQ_ID, abs_index(vf, vf_evq),597597+ FRF_AZ_RX_DESCQ_LABEL, label,598598+ FRF_AZ_RX_DESCQ_SIZE, __ffs(buf_count),599599+ FRF_AZ_RX_DESCQ_JUMBO,600600+ !!(req->u.init_rxq.flags &601601+ VFDI_RXQ_FLAG_SCATTER_EN),602602+ FRF_AZ_RX_DESCQ_EN, 1);603603+ efx_writeo_table(efx, ®, FR_BZ_RX_DESC_PTR_TBL,604604+ abs_index(vf, vf_rxq));605605+606606+ return VFDI_RC_SUCCESS;607607+}608608+609609+static int efx_vfdi_init_txq(struct efx_vf *vf)610610+{611611+ struct efx_nic *efx = vf->efx;612612+ struct vfdi_req *req = vf->buf.addr;613613+ unsigned vf_txq = req->u.init_txq.index;614614+ unsigned vf_evq = req->u.init_txq.evq;615615+ unsigned buf_count = req->u.init_txq.buf_count;616616+ unsigned buftbl = EFX_BUFTBL_TXQ_BASE(vf, vf_txq);617617+ unsigned label, eth_filt_en;618618+ efx_oword_t reg;619619+620620+ if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_txq) ||621621+ vf_txq >= vf_max_tx_channels ||622622+ bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) {623623+ if (net_ratelimit())624624+ netif_err(efx, hw, efx->net_dev,625625+ "ERROR: Invalid INIT_TXQ from %s: txq %d evq %d "626626+ "buf_count %d\n", vf->pci_name, vf_txq,627627+ vf_evq, buf_count);628628+ return VFDI_RC_EINVAL;629629+ }630630+631631+ mutex_lock(&vf->txq_lock);632632+ if (__test_and_set_bit(req->u.init_txq.index, vf->txq_mask))633633+ ++vf->txq_count;634634+ mutex_unlock(&vf->txq_lock);635635+ efx_sriov_bufs(efx, buftbl, req->u.init_txq.addr, buf_count);636636+637637+ eth_filt_en = vf->tx_filter_mode == VF_TX_FILTER_ON;638638+639639+ label = req->u.init_txq.label & EFX_FIELD_MASK(FRF_AZ_TX_DESCQ_LABEL);640640+ EFX_POPULATE_OWORD_8(reg,641641+ FRF_CZ_TX_DPT_Q_MASK_WIDTH, min(efx->vi_scale, 1U),642642+ FRF_CZ_TX_DPT_ETH_FILT_EN, eth_filt_en,643643+ FRF_AZ_TX_DESCQ_EN, 1,644644+ FRF_AZ_TX_DESCQ_BUF_BASE_ID, buftbl,645645+ FRF_AZ_TX_DESCQ_EVQ_ID, abs_index(vf, vf_evq),646646+ FRF_AZ_TX_DESCQ_LABEL, label,647647+ FRF_AZ_TX_DESCQ_SIZE, __ffs(buf_count),648648+ FRF_BZ_TX_NON_IP_DROP_DIS, 1);649649+ efx_writeo_table(efx, ®, FR_BZ_TX_DESC_PTR_TBL,650650+ abs_index(vf, vf_txq));651651+652652+ return VFDI_RC_SUCCESS;653653+}654654+655655+/* Returns true when efx_vfdi_fini_all_queues should wake */656656+static bool efx_vfdi_flush_wake(struct efx_vf *vf)657657+{658658+ /* Ensure that all updates are visible to efx_vfdi_fini_all_queues() */659659+ smp_mb();660660+661661+ return (!vf->txq_count && !vf->rxq_count) ||662662+ atomic_read(&vf->rxq_retry_count);663663+}664664+665665+static void efx_vfdi_flush_clear(struct efx_vf *vf)666666+{667667+ memset(vf->txq_mask, 0, sizeof(vf->txq_mask));668668+ vf->txq_count = 0;669669+ memset(vf->rxq_mask, 0, sizeof(vf->rxq_mask));670670+ vf->rxq_count = 0;671671+ memset(vf->rxq_retry_mask, 0, sizeof(vf->rxq_retry_mask));672672+ atomic_set(&vf->rxq_retry_count, 0);673673+}674674+675675+static int efx_vfdi_fini_all_queues(struct efx_vf *vf)676676+{677677+ struct efx_nic *efx = vf->efx;678678+ efx_oword_t reg;679679+ unsigned count = efx_vf_size(efx);680680+ unsigned vf_offset = EFX_VI_BASE + vf->index * efx_vf_size(efx);681681+ unsigned timeout = HZ;682682+ unsigned index, rxqs_count;683683+ __le32 *rxqs;684684+ int rc;685685+686686+ rxqs = kmalloc(count * sizeof(*rxqs), GFP_KERNEL);687687+ if (rxqs == NULL)688688+ return VFDI_RC_ENOMEM;689689+690690+ rtnl_lock();691691+ if (efx->fc_disable++ == 0)692692+ efx_mcdi_set_mac(efx);693693+ rtnl_unlock();694694+695695+ /* Flush all the initialized queues */696696+ rxqs_count = 0;697697+ for (index = 0; index < count; ++index) {698698+ if (test_bit(index, vf->txq_mask)) {699699+ EFX_POPULATE_OWORD_2(reg,700700+ FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,701701+ FRF_AZ_TX_FLUSH_DESCQ,702702+ vf_offset + index);703703+ efx_writeo(efx, ®, FR_AZ_TX_FLUSH_DESCQ);704704+ }705705+ if (test_bit(index, vf->rxq_mask))706706+ rxqs[rxqs_count++] = cpu_to_le32(vf_offset + index);707707+ }708708+709709+ atomic_set(&vf->rxq_retry_count, 0);710710+ while (timeout && (vf->rxq_count || vf->txq_count)) {711711+ rc = efx_mcdi_rpc(efx, MC_CMD_FLUSH_RX_QUEUES, (u8 *)rxqs,712712+ rxqs_count * sizeof(*rxqs), NULL, 0, NULL);713713+ WARN_ON(rc < 0);714714+715715+ timeout = wait_event_timeout(vf->flush_waitq,716716+ efx_vfdi_flush_wake(vf),717717+ timeout);718718+ rxqs_count = 0;719719+ for (index = 0; index < count; ++index) {720720+ if (test_and_clear_bit(index, vf->rxq_retry_mask)) {721721+ atomic_dec(&vf->rxq_retry_count);722722+ rxqs[rxqs_count++] =723723+ cpu_to_le32(vf_offset + index);724724+ }725725+ }726726+ }727727+728728+ rtnl_lock();729729+ if (--efx->fc_disable == 0)730730+ efx_mcdi_set_mac(efx);731731+ rtnl_unlock();732732+733733+ /* Irrespective of success/failure, fini the queues */734734+ EFX_ZERO_OWORD(reg);735735+ for (index = 0; index < count; ++index) {736736+ efx_writeo_table(efx, ®, FR_BZ_RX_DESC_PTR_TBL,737737+ vf_offset + index);738738+ efx_writeo_table(efx, ®, FR_BZ_TX_DESC_PTR_TBL,739739+ vf_offset + index);740740+ efx_writeo_table(efx, ®, FR_BZ_EVQ_PTR_TBL,741741+ vf_offset + index);742742+ efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL,743743+ vf_offset + index);744744+ }745745+ efx_sriov_bufs(efx, vf->buftbl_base, NULL,746746+ EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx));747747+ kfree(rxqs);748748+ efx_vfdi_flush_clear(vf);749749+750750+ vf->evq0_count = 0;751751+752752+ return timeout ? 0 : VFDI_RC_ETIMEDOUT;753753+}754754+755755+static int efx_vfdi_insert_filter(struct efx_vf *vf)756756+{757757+ struct efx_nic *efx = vf->efx;758758+ struct vfdi_req *req = vf->buf.addr;759759+ unsigned vf_rxq = req->u.mac_filter.rxq;760760+ unsigned flags;761761+762762+ if (bad_vf_index(efx, vf_rxq) || vf->rx_filtering) {763763+ if (net_ratelimit())764764+ netif_err(efx, hw, efx->net_dev,765765+ "ERROR: Invalid INSERT_FILTER from %s: rxq %d "766766+ "flags 0x%x\n", vf->pci_name, vf_rxq,767767+ req->u.mac_filter.flags);768768+ return VFDI_RC_EINVAL;769769+ }770770+771771+ flags = 0;772772+ if (req->u.mac_filter.flags & VFDI_MAC_FILTER_FLAG_RSS)773773+ flags |= EFX_FILTER_FLAG_RX_RSS;774774+ if (req->u.mac_filter.flags & VFDI_MAC_FILTER_FLAG_SCATTER)775775+ flags |= EFX_FILTER_FLAG_RX_SCATTER;776776+ vf->rx_filter_flags = flags;777777+ vf->rx_filter_qid = vf_rxq;778778+ vf->rx_filtering = true;779779+780780+ efx_sriov_reset_rx_filter(vf);781781+ queue_work(vfdi_workqueue, &efx->peer_work);782782+783783+ return VFDI_RC_SUCCESS;784784+}785785+786786+static int efx_vfdi_remove_all_filters(struct efx_vf *vf)787787+{788788+ vf->rx_filtering = false;789789+ efx_sriov_reset_rx_filter(vf);790790+ queue_work(vfdi_workqueue, &vf->efx->peer_work);791791+792792+ return VFDI_RC_SUCCESS;793793+}794794+795795+static int efx_vfdi_set_status_page(struct efx_vf *vf)796796+{797797+ struct efx_nic *efx = vf->efx;798798+ struct vfdi_req *req = vf->buf.addr;799799+ unsigned int page_count;800800+801801+ page_count = req->u.set_status_page.peer_page_count;802802+ if (!req->u.set_status_page.dma_addr || EFX_PAGE_SIZE <803803+ offsetof(struct vfdi_req,804804+ u.set_status_page.peer_page_addr[page_count])) {805805+ if (net_ratelimit())806806+ netif_err(efx, hw, efx->net_dev,807807+ "ERROR: Invalid SET_STATUS_PAGE from %s\n",808808+ vf->pci_name);809809+ return VFDI_RC_EINVAL;810810+ }811811+812812+ mutex_lock(&efx->local_lock);813813+ mutex_lock(&vf->status_lock);814814+ vf->status_addr = req->u.set_status_page.dma_addr;815815+816816+ kfree(vf->peer_page_addrs);817817+ vf->peer_page_addrs = NULL;818818+ vf->peer_page_count = 0;819819+820820+ if (page_count) {821821+ vf->peer_page_addrs = kcalloc(page_count, sizeof(u64),822822+ GFP_KERNEL);823823+ if (vf->peer_page_addrs) {824824+ memcpy(vf->peer_page_addrs,825825+ req->u.set_status_page.peer_page_addr,826826+ page_count * sizeof(u64));827827+ vf->peer_page_count = page_count;828828+ }829829+ }830830+831831+ __efx_sriov_push_vf_status(vf);832832+ mutex_unlock(&vf->status_lock);833833+ mutex_unlock(&efx->local_lock);834834+835835+ return VFDI_RC_SUCCESS;836836+}837837+838838+static int efx_vfdi_clear_status_page(struct efx_vf *vf)839839+{840840+ mutex_lock(&vf->status_lock);841841+ vf->status_addr = 0;842842+ mutex_unlock(&vf->status_lock);843843+844844+ return VFDI_RC_SUCCESS;845845+}846846+847847+typedef int (*efx_vfdi_op_t)(struct efx_vf *vf);848848+849849+static const efx_vfdi_op_t vfdi_ops[VFDI_OP_LIMIT] = {850850+ [VFDI_OP_INIT_EVQ] = efx_vfdi_init_evq,851851+ [VFDI_OP_INIT_TXQ] = efx_vfdi_init_txq,852852+ [VFDI_OP_INIT_RXQ] = efx_vfdi_init_rxq,853853+ [VFDI_OP_FINI_ALL_QUEUES] = efx_vfdi_fini_all_queues,854854+ [VFDI_OP_INSERT_FILTER] = efx_vfdi_insert_filter,855855+ [VFDI_OP_REMOVE_ALL_FILTERS] = efx_vfdi_remove_all_filters,856856+ [VFDI_OP_SET_STATUS_PAGE] = efx_vfdi_set_status_page,857857+ [VFDI_OP_CLEAR_STATUS_PAGE] = efx_vfdi_clear_status_page,858858+};859859+860860+static void efx_sriov_vfdi(struct work_struct *work)861861+{862862+ struct efx_vf *vf = container_of(work, struct efx_vf, req);863863+ struct efx_nic *efx = vf->efx;864864+ struct vfdi_req *req = vf->buf.addr;865865+ struct efx_memcpy_req copy[2];866866+ int rc;867867+868868+ /* Copy this page into the local address space */869869+ memset(copy, '\0', sizeof(copy));870870+ copy[0].from_rid = vf->pci_rid;871871+ copy[0].from_addr = vf->req_addr;872872+ copy[0].to_rid = efx->pci_dev->devfn;873873+ copy[0].to_addr = vf->buf.dma_addr;874874+ copy[0].length = EFX_PAGE_SIZE;875875+ rc = efx_sriov_memcpy(efx, copy, 1);876876+ if (rc) {877877+ /* If we can't get the request, we can't reply to the caller */878878+ if (net_ratelimit())879879+ netif_err(efx, hw, efx->net_dev,880880+ "ERROR: Unable to fetch VFDI request from %s rc %d\n",881881+ vf->pci_name, -rc);882882+ vf->busy = false;883883+ return;884884+ }885885+886886+ if (req->op < VFDI_OP_LIMIT && vfdi_ops[req->op] != NULL) {887887+ rc = vfdi_ops[req->op](vf);888888+ if (rc == 0) {889889+ netif_dbg(efx, hw, efx->net_dev,890890+ "vfdi request %d from %s ok\n",891891+ req->op, vf->pci_name);892892+ }893893+ } else {894894+ netif_dbg(efx, hw, efx->net_dev,895895+ "ERROR: Unrecognised request %d from VF %s addr "896896+ "%llx\n", req->op, vf->pci_name,897897+ (unsigned long long)vf->req_addr);898898+ rc = VFDI_RC_EOPNOTSUPP;899899+ }900900+901901+ /* Allow subsequent VF requests */902902+ vf->busy = false;903903+ smp_wmb();904904+905905+ /* Respond to the request */906906+ req->rc = rc;907907+ req->op = VFDI_OP_RESPONSE;908908+909909+ memset(copy, '\0', sizeof(copy));910910+ copy[0].from_buf = &req->rc;911911+ copy[0].to_rid = vf->pci_rid;912912+ copy[0].to_addr = vf->req_addr + offsetof(struct vfdi_req, rc);913913+ copy[0].length = sizeof(req->rc);914914+ copy[1].from_buf = &req->op;915915+ copy[1].to_rid = vf->pci_rid;916916+ copy[1].to_addr = vf->req_addr + offsetof(struct vfdi_req, op);917917+ copy[1].length = sizeof(req->op);918918+919919+ (void) efx_sriov_memcpy(efx, copy, ARRAY_SIZE(copy));920920+}921921+922922+923923+924924+/* After a reset the event queues inside the guests no longer exist. Fill the925925+ * event ring in guest memory with VFDI reset events, then (re-initialise) the926926+ * event queue to raise an interrupt. The guest driver will then recover.927927+ */928928+static void efx_sriov_reset_vf(struct efx_vf *vf, struct efx_buffer *buffer)929929+{930930+ struct efx_nic *efx = vf->efx;931931+ struct efx_memcpy_req copy_req[4];932932+ efx_qword_t event;933933+ unsigned int pos, count, k, buftbl, abs_evq;934934+ efx_oword_t reg;935935+ efx_dword_t ptr;936936+ int rc;937937+938938+ BUG_ON(buffer->len != EFX_PAGE_SIZE);939939+940940+ if (!vf->evq0_count)941941+ return;942942+ BUG_ON(vf->evq0_count & (vf->evq0_count - 1));943943+944944+ mutex_lock(&vf->status_lock);945945+ EFX_POPULATE_QWORD_3(event,946946+ FSF_AZ_EV_CODE, FSE_CZ_EV_CODE_USER_EV,947947+ VFDI_EV_SEQ, vf->msg_seqno,948948+ VFDI_EV_TYPE, VFDI_EV_TYPE_RESET);949949+ vf->msg_seqno++;950950+ for (pos = 0; pos < EFX_PAGE_SIZE; pos += sizeof(event))951951+ memcpy(buffer->addr + pos, &event, sizeof(event));952952+953953+ for (pos = 0; pos < vf->evq0_count; pos += count) {954954+ count = min_t(unsigned, vf->evq0_count - pos,955955+ ARRAY_SIZE(copy_req));956956+ for (k = 0; k < count; k++) {957957+ copy_req[k].from_buf = NULL;958958+ copy_req[k].from_rid = efx->pci_dev->devfn;959959+ copy_req[k].from_addr = buffer->dma_addr;960960+ copy_req[k].to_rid = vf->pci_rid;961961+ copy_req[k].to_addr = vf->evq0_addrs[pos + k];962962+ copy_req[k].length = EFX_PAGE_SIZE;963963+ }964964+ rc = efx_sriov_memcpy(efx, copy_req, count);965965+ if (rc) {966966+ if (net_ratelimit())967967+ netif_err(efx, hw, efx->net_dev,968968+ "ERROR: Unable to notify %s of reset"969969+ ": %d\n", vf->pci_name, -rc);970970+ break;971971+ }972972+ }973973+974974+ /* Reinitialise, arm and trigger evq0 */975975+ abs_evq = abs_index(vf, 0);976976+ buftbl = EFX_BUFTBL_EVQ_BASE(vf, 0);977977+ efx_sriov_bufs(efx, buftbl, vf->evq0_addrs, vf->evq0_count);978978+979979+ EFX_POPULATE_OWORD_3(reg,980980+ FRF_CZ_TIMER_Q_EN, 1,981981+ FRF_CZ_HOST_NOTIFY_MODE, 0,982982+ FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);983983+ efx_writeo_table(efx, ®, FR_BZ_TIMER_TBL, abs_evq);984984+ EFX_POPULATE_OWORD_3(reg,985985+ FRF_AZ_EVQ_EN, 1,986986+ FRF_AZ_EVQ_SIZE, __ffs(vf->evq0_count),987987+ FRF_AZ_EVQ_BUF_BASE_ID, buftbl);988988+ efx_writeo_table(efx, ®, FR_BZ_EVQ_PTR_TBL, abs_evq);989989+ EFX_POPULATE_DWORD_1(ptr, FRF_AZ_EVQ_RPTR, 0);990990+ efx_writed_table(efx, &ptr, FR_BZ_EVQ_RPTR, abs_evq);991991+992992+ mutex_unlock(&vf->status_lock);993993+}994994+995995+static void efx_sriov_reset_vf_work(struct work_struct *work)996996+{997997+ struct efx_vf *vf = container_of(work, struct efx_vf, req);998998+ struct efx_nic *efx = vf->efx;999999+ struct efx_buffer buf;10001000+10011001+ if (!efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE)) {10021002+ efx_sriov_reset_vf(vf, &buf);10031003+ efx_nic_free_buffer(efx, &buf);10041004+ }10051005+}10061006+10071007+static void efx_sriov_handle_no_channel(struct efx_nic *efx)10081008+{10091009+ netif_err(efx, drv, efx->net_dev,10101010+ "ERROR: IOV requires MSI-X and 1 additional interrupt"10111011+ "vector. IOV disabled\n");10121012+ efx->vf_count = 0;10131013+}10141014+10151015+static int efx_sriov_probe_channel(struct efx_channel *channel)10161016+{10171017+ channel->efx->vfdi_channel = channel;10181018+ return 0;10191019+}10201020+10211021+static void10221022+efx_sriov_get_channel_name(struct efx_channel *channel, char *buf, size_t len)10231023+{10241024+ snprintf(buf, len, "%s-iov", channel->efx->name);10251025+}10261026+10271027+static const struct efx_channel_type efx_sriov_channel_type = {10281028+ .handle_no_channel = efx_sriov_handle_no_channel,10291029+ .pre_probe = efx_sriov_probe_channel,10301030+ .get_name = efx_sriov_get_channel_name,10311031+ /* no copy operation; channel must not be reallocated */10321032+ .keep_eventq = true,10331033+};10341034+10351035+void efx_sriov_probe(struct efx_nic *efx)10361036+{10371037+ unsigned count;10381038+10391039+ if (!max_vfs)10401040+ return;10411041+10421042+ if (efx_sriov_cmd(efx, false, &efx->vi_scale, &count))10431043+ return;10441044+ if (count > 0 && count > max_vfs)10451045+ count = max_vfs;10461046+10471047+ /* efx_nic_dimension_resources() will reduce vf_count as appopriate */10481048+ efx->vf_count = count;10491049+10501050+ efx->extra_channel_type[EFX_EXTRA_CHANNEL_IOV] = &efx_sriov_channel_type;10511051+}10521052+10531053+/* Copy the list of individual addresses into the vfdi_status.peers10541054+ * array and auxillary pages, protected by %local_lock. Drop that lock10551055+ * and then broadcast the address list to every VF.10561056+ */10571057+static void efx_sriov_peer_work(struct work_struct *data)10581058+{10591059+ struct efx_nic *efx = container_of(data, struct efx_nic, peer_work);10601060+ struct vfdi_status *vfdi_status = efx->vfdi_status.addr;10611061+ struct efx_vf *vf;10621062+ struct efx_local_addr *local_addr;10631063+ struct vfdi_endpoint *peer;10641064+ struct efx_endpoint_page *epp;10651065+ struct list_head pages;10661066+ unsigned int peer_space;10671067+ unsigned int peer_count;10681068+ unsigned int pos;10691069+10701070+ mutex_lock(&efx->local_lock);10711071+10721072+ /* Move the existing peer pages off %local_page_list */10731073+ INIT_LIST_HEAD(&pages);10741074+ list_splice_tail_init(&efx->local_page_list, &pages);10751075+10761076+ /* Populate the VF addresses starting from entry 1 (entry 0 is10771077+ * the PF address)10781078+ */10791079+ peer = vfdi_status->peers + 1;10801080+ peer_space = ARRAY_SIZE(vfdi_status->peers) - 1;10811081+ peer_count = 1;10821082+ for (pos = 0; pos < efx->vf_count; ++pos) {10831083+ vf = efx->vf + pos;10841084+10851085+ mutex_lock(&vf->status_lock);10861086+ if (vf->rx_filtering && !is_zero_ether_addr(vf->addr.mac_addr)) {10871087+ *peer++ = vf->addr;10881088+ ++peer_count;10891089+ --peer_space;10901090+ BUG_ON(peer_space == 0);10911091+ }10921092+ mutex_unlock(&vf->status_lock);10931093+ }10941094+10951095+ /* Fill the remaining addresses */10961096+ list_for_each_entry(local_addr, &efx->local_addr_list, link) {10971097+ memcpy(peer->mac_addr, local_addr->addr, ETH_ALEN);10981098+ peer->tci = 0;10991099+ ++peer;11001100+ ++peer_count;11011101+ if (--peer_space == 0) {11021102+ if (list_empty(&pages)) {11031103+ epp = kmalloc(sizeof(*epp), GFP_KERNEL);11041104+ if (!epp)11051105+ break;11061106+ epp->ptr = dma_alloc_coherent(11071107+ &efx->pci_dev->dev, EFX_PAGE_SIZE,11081108+ &epp->addr, GFP_KERNEL);11091109+ if (!epp->ptr) {11101110+ kfree(epp);11111111+ break;11121112+ }11131113+ } else {11141114+ epp = list_first_entry(11151115+ &pages, struct efx_endpoint_page, link);11161116+ list_del(&epp->link);11171117+ }11181118+11191119+ list_add_tail(&epp->link, &efx->local_page_list);11201120+ peer = (struct vfdi_endpoint *)epp->ptr;11211121+ peer_space = EFX_PAGE_SIZE / sizeof(struct vfdi_endpoint);11221122+ }11231123+ }11241124+ vfdi_status->peer_count = peer_count;11251125+ mutex_unlock(&efx->local_lock);11261126+11271127+ /* Free any now unused endpoint pages */11281128+ while (!list_empty(&pages)) {11291129+ epp = list_first_entry(11301130+ &pages, struct efx_endpoint_page, link);11311131+ list_del(&epp->link);11321132+ dma_free_coherent(&efx->pci_dev->dev, EFX_PAGE_SIZE,11331133+ epp->ptr, epp->addr);11341134+ kfree(epp);11351135+ }11361136+11371137+ /* Finally, push the pages */11381138+ for (pos = 0; pos < efx->vf_count; ++pos) {11391139+ vf = efx->vf + pos;11401140+11411141+ mutex_lock(&vf->status_lock);11421142+ if (vf->status_addr)11431143+ __efx_sriov_push_vf_status(vf);11441144+ mutex_unlock(&vf->status_lock);11451145+ }11461146+}11471147+11481148+static void efx_sriov_free_local(struct efx_nic *efx)11491149+{11501150+ struct efx_local_addr *local_addr;11511151+ struct efx_endpoint_page *epp;11521152+11531153+ while (!list_empty(&efx->local_addr_list)) {11541154+ local_addr = list_first_entry(&efx->local_addr_list,11551155+ struct efx_local_addr, link);11561156+ list_del(&local_addr->link);11571157+ kfree(local_addr);11581158+ }11591159+11601160+ while (!list_empty(&efx->local_page_list)) {11611161+ epp = list_first_entry(&efx->local_page_list,11621162+ struct efx_endpoint_page, link);11631163+ list_del(&epp->link);11641164+ dma_free_coherent(&efx->pci_dev->dev, EFX_PAGE_SIZE,11651165+ epp->ptr, epp->addr);11661166+ kfree(epp);11671167+ }11681168+}11691169+11701170+static int efx_sriov_vf_alloc(struct efx_nic *efx)11711171+{11721172+ unsigned index;11731173+ struct efx_vf *vf;11741174+11751175+ efx->vf = kzalloc(sizeof(struct efx_vf) * efx->vf_count, GFP_KERNEL);11761176+ if (!efx->vf)11771177+ return -ENOMEM;11781178+11791179+ for (index = 0; index < efx->vf_count; ++index) {11801180+ vf = efx->vf + index;11811181+11821182+ vf->efx = efx;11831183+ vf->index = index;11841184+ vf->rx_filter_id = -1;11851185+ vf->tx_filter_mode = VF_TX_FILTER_AUTO;11861186+ vf->tx_filter_id = -1;11871187+ INIT_WORK(&vf->req, efx_sriov_vfdi);11881188+ INIT_WORK(&vf->reset_work, efx_sriov_reset_vf_work);11891189+ init_waitqueue_head(&vf->flush_waitq);11901190+ mutex_init(&vf->status_lock);11911191+ mutex_init(&vf->txq_lock);11921192+ }11931193+11941194+ return 0;11951195+}11961196+11971197+static void efx_sriov_vfs_fini(struct efx_nic *efx)11981198+{11991199+ struct efx_vf *vf;12001200+ unsigned int pos;12011201+12021202+ for (pos = 0; pos < efx->vf_count; ++pos) {12031203+ vf = efx->vf + pos;12041204+12051205+ efx_nic_free_buffer(efx, &vf->buf);12061206+ kfree(vf->peer_page_addrs);12071207+ vf->peer_page_addrs = NULL;12081208+ vf->peer_page_count = 0;12091209+12101210+ vf->evq0_count = 0;12111211+ }12121212+}12131213+12141214+static int efx_sriov_vfs_init(struct efx_nic *efx)12151215+{12161216+ struct pci_dev *pci_dev = efx->pci_dev;12171217+ unsigned index, devfn, sriov, buftbl_base;12181218+ u16 offset, stride;12191219+ struct efx_vf *vf;12201220+ int rc;12211221+12221222+ sriov = pci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_SRIOV);12231223+ if (!sriov)12241224+ return -ENOENT;12251225+12261226+ pci_read_config_word(pci_dev, sriov + PCI_SRIOV_VF_OFFSET, &offset);12271227+ pci_read_config_word(pci_dev, sriov + PCI_SRIOV_VF_STRIDE, &stride);12281228+12291229+ buftbl_base = efx->vf_buftbl_base;12301230+ devfn = pci_dev->devfn + offset;12311231+ for (index = 0; index < efx->vf_count; ++index) {12321232+ vf = efx->vf + index;12331233+12341234+ /* Reserve buffer entries */12351235+ vf->buftbl_base = buftbl_base;12361236+ buftbl_base += EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx);12371237+12381238+ vf->pci_rid = devfn;12391239+ snprintf(vf->pci_name, sizeof(vf->pci_name),12401240+ "%04x:%02x:%02x.%d",12411241+ pci_domain_nr(pci_dev->bus), pci_dev->bus->number,12421242+ PCI_SLOT(devfn), PCI_FUNC(devfn));12431243+12441244+ rc = efx_nic_alloc_buffer(efx, &vf->buf, EFX_PAGE_SIZE);12451245+ if (rc)12461246+ goto fail;12471247+12481248+ devfn += stride;12491249+ }12501250+12511251+ return 0;12521252+12531253+fail:12541254+ efx_sriov_vfs_fini(efx);12551255+ return rc;12561256+}12571257+12581258+int efx_sriov_init(struct efx_nic *efx)12591259+{12601260+ struct net_device *net_dev = efx->net_dev;12611261+ struct vfdi_status *vfdi_status;12621262+ int rc;12631263+12641264+ /* Ensure there's room for vf_channel */12651265+ BUILD_BUG_ON(EFX_MAX_CHANNELS + 1 >= EFX_VI_BASE);12661266+ /* Ensure that VI_BASE is aligned on VI_SCALE */12671267+ BUILD_BUG_ON(EFX_VI_BASE & ((1 << EFX_VI_SCALE_MAX) - 1));12681268+12691269+ if (efx->vf_count == 0)12701270+ return 0;12711271+12721272+ rc = efx_sriov_cmd(efx, true, NULL, NULL);12731273+ if (rc)12741274+ goto fail_cmd;12751275+12761276+ rc = efx_nic_alloc_buffer(efx, &efx->vfdi_status, sizeof(*vfdi_status));12771277+ if (rc)12781278+ goto fail_status;12791279+ vfdi_status = efx->vfdi_status.addr;12801280+ memset(vfdi_status, 0, sizeof(*vfdi_status));12811281+ vfdi_status->version = 1;12821282+ vfdi_status->length = sizeof(*vfdi_status);12831283+ vfdi_status->max_tx_channels = vf_max_tx_channels;12841284+ vfdi_status->vi_scale = efx->vi_scale;12851285+ vfdi_status->rss_rxq_count = efx->rss_spread;12861286+ vfdi_status->peer_count = 1 + efx->vf_count;12871287+ vfdi_status->timer_quantum_ns = efx->timer_quantum_ns;12881288+12891289+ rc = efx_sriov_vf_alloc(efx);12901290+ if (rc)12911291+ goto fail_alloc;12921292+12931293+ mutex_init(&efx->local_lock);12941294+ INIT_WORK(&efx->peer_work, efx_sriov_peer_work);12951295+ INIT_LIST_HEAD(&efx->local_addr_list);12961296+ INIT_LIST_HEAD(&efx->local_page_list);12971297+12981298+ rc = efx_sriov_vfs_init(efx);12991299+ if (rc)13001300+ goto fail_vfs;13011301+13021302+ rtnl_lock();13031303+ memcpy(vfdi_status->peers[0].mac_addr,13041304+ net_dev->dev_addr, ETH_ALEN);13051305+ efx->vf_init_count = efx->vf_count;13061306+ rtnl_unlock();13071307+13081308+ efx_sriov_usrev(efx, true);13091309+13101310+ /* At this point we must be ready to accept VFDI requests */13111311+13121312+ rc = pci_enable_sriov(efx->pci_dev, efx->vf_count);13131313+ if (rc)13141314+ goto fail_pci;13151315+13161316+ netif_info(efx, probe, net_dev,13171317+ "enabled SR-IOV for %d VFs, %d VI per VF\n",13181318+ efx->vf_count, efx_vf_size(efx));13191319+ return 0;13201320+13211321+fail_pci:13221322+ efx_sriov_usrev(efx, false);13231323+ rtnl_lock();13241324+ efx->vf_init_count = 0;13251325+ rtnl_unlock();13261326+ efx_sriov_vfs_fini(efx);13271327+fail_vfs:13281328+ cancel_work_sync(&efx->peer_work);13291329+ efx_sriov_free_local(efx);13301330+ kfree(efx->vf);13311331+fail_alloc:13321332+ efx_nic_free_buffer(efx, &efx->vfdi_status);13331333+fail_status:13341334+ efx_sriov_cmd(efx, false, NULL, NULL);13351335+fail_cmd:13361336+ return rc;13371337+}13381338+13391339+void efx_sriov_fini(struct efx_nic *efx)13401340+{13411341+ struct efx_vf *vf;13421342+ unsigned int pos;13431343+13441344+ if (efx->vf_init_count == 0)13451345+ return;13461346+13471347+ /* Disable all interfaces to reconfiguration */13481348+ BUG_ON(efx->vfdi_channel->enabled);13491349+ efx_sriov_usrev(efx, false);13501350+ rtnl_lock();13511351+ efx->vf_init_count = 0;13521352+ rtnl_unlock();13531353+13541354+ /* Flush all reconfiguration work */13551355+ for (pos = 0; pos < efx->vf_count; ++pos) {13561356+ vf = efx->vf + pos;13571357+ cancel_work_sync(&vf->req);13581358+ cancel_work_sync(&vf->reset_work);13591359+ }13601360+ cancel_work_sync(&efx->peer_work);13611361+13621362+ pci_disable_sriov(efx->pci_dev);13631363+13641364+ /* Tear down back-end state */13651365+ efx_sriov_vfs_fini(efx);13661366+ efx_sriov_free_local(efx);13671367+ kfree(efx->vf);13681368+ efx_nic_free_buffer(efx, &efx->vfdi_status);13691369+ efx_sriov_cmd(efx, false, NULL, NULL);13701370+}13711371+13721372+void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event)13731373+{13741374+ struct efx_nic *efx = channel->efx;13751375+ struct efx_vf *vf;13761376+ unsigned qid, seq, type, data;13771377+13781378+ qid = EFX_QWORD_FIELD(*event, FSF_CZ_USER_QID);13791379+13801380+ /* USR_EV_REG_VALUE is dword0, so access the VFDI_EV fields directly */13811381+ BUILD_BUG_ON(FSF_CZ_USER_EV_REG_VALUE_LBN != 0);13821382+ seq = EFX_QWORD_FIELD(*event, VFDI_EV_SEQ);13831383+ type = EFX_QWORD_FIELD(*event, VFDI_EV_TYPE);13841384+ data = EFX_QWORD_FIELD(*event, VFDI_EV_DATA);13851385+13861386+ netif_vdbg(efx, hw, efx->net_dev,13871387+ "USR_EV event from qid %d seq 0x%x type %d data 0x%x\n",13881388+ qid, seq, type, data);13891389+13901390+ if (map_vi_index(efx, qid, &vf, NULL))13911391+ return;13921392+ if (vf->busy)13931393+ goto error;13941394+13951395+ if (type == VFDI_EV_TYPE_REQ_WORD0) {13961396+ /* Resynchronise */13971397+ vf->req_type = VFDI_EV_TYPE_REQ_WORD0;13981398+ vf->req_seqno = seq + 1;13991399+ vf->req_addr = 0;14001400+ } else if (seq != (vf->req_seqno++ & 0xff) || type != vf->req_type)14011401+ goto error;14021402+14031403+ switch (vf->req_type) {14041404+ case VFDI_EV_TYPE_REQ_WORD0:14051405+ case VFDI_EV_TYPE_REQ_WORD1:14061406+ case VFDI_EV_TYPE_REQ_WORD2:14071407+ vf->req_addr |= (u64)data << (vf->req_type << 4);14081408+ ++vf->req_type;14091409+ return;14101410+14111411+ case VFDI_EV_TYPE_REQ_WORD3:14121412+ vf->req_addr |= (u64)data << 48;14131413+ vf->req_type = VFDI_EV_TYPE_REQ_WORD0;14141414+ vf->busy = true;14151415+ queue_work(vfdi_workqueue, &vf->req);14161416+ return;14171417+ }14181418+14191419+error:14201420+ if (net_ratelimit())14211421+ netif_err(efx, hw, efx->net_dev,14221422+ "ERROR: Screaming VFDI request from %s\n",14231423+ vf->pci_name);14241424+ /* Reset the request and sequence number */14251425+ vf->req_type = VFDI_EV_TYPE_REQ_WORD0;14261426+ vf->req_seqno = seq + 1;14271427+}14281428+14291429+void efx_sriov_flr(struct efx_nic *efx, unsigned vf_i)14301430+{14311431+ struct efx_vf *vf;14321432+14331433+ if (vf_i > efx->vf_init_count)14341434+ return;14351435+ vf = efx->vf + vf_i;14361436+ netif_info(efx, hw, efx->net_dev,14371437+ "FLR on VF %s\n", vf->pci_name);14381438+14391439+ vf->status_addr = 0;14401440+ efx_vfdi_remove_all_filters(vf);14411441+ efx_vfdi_flush_clear(vf);14421442+14431443+ vf->evq0_count = 0;14441444+}14451445+14461446+void efx_sriov_mac_address_changed(struct efx_nic *efx)14471447+{14481448+ struct vfdi_status *vfdi_status = efx->vfdi_status.addr;14491449+14501450+ if (!efx->vf_init_count)14511451+ return;14521452+ memcpy(vfdi_status->peers[0].mac_addr,14531453+ efx->net_dev->dev_addr, ETH_ALEN);14541454+ queue_work(vfdi_workqueue, &efx->peer_work);14551455+}14561456+14571457+void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event)14581458+{14591459+ struct efx_vf *vf;14601460+ unsigned queue, qid;14611461+14621462+ queue = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);14631463+ if (map_vi_index(efx, queue, &vf, &qid))14641464+ return;14651465+ /* Ignore flush completions triggered by an FLR */14661466+ if (!test_bit(qid, vf->txq_mask))14671467+ return;14681468+14691469+ __clear_bit(qid, vf->txq_mask);14701470+ --vf->txq_count;14711471+14721472+ if (efx_vfdi_flush_wake(vf))14731473+ wake_up(&vf->flush_waitq);14741474+}14751475+14761476+void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event)14771477+{14781478+ struct efx_vf *vf;14791479+ unsigned ev_failed, queue, qid;14801480+14811481+ queue = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);14821482+ ev_failed = EFX_QWORD_FIELD(*event,14831483+ FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);14841484+ if (map_vi_index(efx, queue, &vf, &qid))14851485+ return;14861486+ if (!test_bit(qid, vf->rxq_mask))14871487+ return;14881488+14891489+ if (ev_failed) {14901490+ set_bit(qid, vf->rxq_retry_mask);14911491+ atomic_inc(&vf->rxq_retry_count);14921492+ } else {14931493+ __clear_bit(qid, vf->rxq_mask);14941494+ --vf->rxq_count;14951495+ }14961496+ if (efx_vfdi_flush_wake(vf))14971497+ wake_up(&vf->flush_waitq);14981498+}14991499+15001500+/* Called from napi. Schedule the reset work item */15011501+void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq)15021502+{15031503+ struct efx_vf *vf;15041504+ unsigned int rel;15051505+15061506+ if (map_vi_index(efx, dmaq, &vf, &rel))15071507+ return;15081508+15091509+ if (net_ratelimit())15101510+ netif_err(efx, hw, efx->net_dev,15111511+ "VF %d DMA Q %d reports descriptor fetch error.\n",15121512+ vf->index, rel);15131513+ queue_work(vfdi_workqueue, &vf->reset_work);15141514+}15151515+15161516+/* Reset all VFs */15171517+void efx_sriov_reset(struct efx_nic *efx)15181518+{15191519+ unsigned int vf_i;15201520+ struct efx_buffer buf;15211521+ struct efx_vf *vf;15221522+15231523+ ASSERT_RTNL();15241524+15251525+ if (efx->vf_init_count == 0)15261526+ return;15271527+15281528+ efx_sriov_usrev(efx, true);15291529+ (void)efx_sriov_cmd(efx, true, NULL, NULL);15301530+15311531+ if (efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE))15321532+ return;15331533+15341534+ for (vf_i = 0; vf_i < efx->vf_init_count; ++vf_i) {15351535+ vf = efx->vf + vf_i;15361536+ efx_sriov_reset_vf(vf, &buf);15371537+ }15381538+15391539+ efx_nic_free_buffer(efx, &buf);15401540+}15411541+15421542+int efx_init_sriov(void)15431543+{15441544+ /* A single threaded workqueue is sufficient. efx_sriov_vfdi() and15451545+ * efx_sriov_peer_work() spend almost all their time sleeping for15461546+ * MCDI to complete anyway15471547+ */15481548+ vfdi_workqueue = create_singlethread_workqueue("sfc_vfdi");15491549+ if (!vfdi_workqueue)15501550+ return -ENOMEM;15511551+15521552+ return 0;15531553+}15541554+15551555+void efx_fini_sriov(void)15561556+{15571557+ destroy_workqueue(vfdi_workqueue);15581558+}15591559+15601560+int efx_sriov_set_vf_mac(struct net_device *net_dev, int vf_i, u8 *mac)15611561+{15621562+ struct efx_nic *efx = netdev_priv(net_dev);15631563+ struct efx_vf *vf;15641564+15651565+ if (vf_i >= efx->vf_init_count)15661566+ return -EINVAL;15671567+ vf = efx->vf + vf_i;15681568+15691569+ mutex_lock(&vf->status_lock);15701570+ memcpy(vf->addr.mac_addr, mac, ETH_ALEN);15711571+ __efx_sriov_update_vf_addr(vf);15721572+ mutex_unlock(&vf->status_lock);15731573+15741574+ return 0;15751575+}15761576+15771577+int efx_sriov_set_vf_vlan(struct net_device *net_dev, int vf_i,15781578+ u16 vlan, u8 qos)15791579+{15801580+ struct efx_nic *efx = netdev_priv(net_dev);15811581+ struct efx_vf *vf;15821582+ u16 tci;15831583+15841584+ if (vf_i >= efx->vf_init_count)15851585+ return -EINVAL;15861586+ vf = efx->vf + vf_i;15871587+15881588+ mutex_lock(&vf->status_lock);15891589+ tci = (vlan & VLAN_VID_MASK) | ((qos & 0x7) << VLAN_PRIO_SHIFT);15901590+ vf->addr.tci = htons(tci);15911591+ __efx_sriov_update_vf_addr(vf);15921592+ mutex_unlock(&vf->status_lock);15931593+15941594+ return 0;15951595+}15961596+15971597+int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf_i,15981598+ bool spoofchk)15991599+{16001600+ struct efx_nic *efx = netdev_priv(net_dev);16011601+ struct efx_vf *vf;16021602+ int rc;16031603+16041604+ if (vf_i >= efx->vf_init_count)16051605+ return -EINVAL;16061606+ vf = efx->vf + vf_i;16071607+16081608+ mutex_lock(&vf->txq_lock);16091609+ if (vf->txq_count == 0) {16101610+ vf->tx_filter_mode =16111611+ spoofchk ? VF_TX_FILTER_ON : VF_TX_FILTER_OFF;16121612+ rc = 0;16131613+ } else {16141614+ /* This cannot be changed while TX queues are running */16151615+ rc = -EBUSY;16161616+ }16171617+ mutex_unlock(&vf->txq_lock);16181618+ return rc;16191619+}16201620+16211621+int efx_sriov_get_vf_config(struct net_device *net_dev, int vf_i,16221622+ struct ifla_vf_info *ivi)16231623+{16241624+ struct efx_nic *efx = netdev_priv(net_dev);16251625+ struct efx_vf *vf;16261626+ u16 tci;16271627+16281628+ if (vf_i >= efx->vf_init_count)16291629+ return -EINVAL;16301630+ vf = efx->vf + vf_i;16311631+16321632+ ivi->vf = vf_i;16331633+ memcpy(ivi->mac, vf->addr.mac_addr, ETH_ALEN);16341634+ ivi->tx_rate = 0;16351635+ tci = ntohs(vf->addr.tci);16361636+ ivi->vlan = tci & VLAN_VID_MASK;16371637+ ivi->qos = (tci >> VLAN_PRIO_SHIFT) & 0x7;16381638+ ivi->spoofchk = vf->tx_filter_mode == VF_TX_FILTER_ON;16391639+16401640+ return 0;16411641+}16421642+
+1-1
drivers/net/ethernet/sfc/tx.c
···110110 * little benefit from using descriptors that cross those111111 * boundaries and we keep things simple by not doing so.112112 */113113- unsigned len = (~dma_addr & 0xfff) + 1;113113+ unsigned len = (~dma_addr & (EFX_PAGE_SIZE - 1)) + 1;114114115115 /* Work around hardware bug for unaligned buffers. */116116 if (EFX_WORKAROUND_5391(efx) && (dma_addr & 0xf))
+254
drivers/net/ethernet/sfc/vfdi.h
···11+/****************************************************************************22+ * Driver for Solarflare Solarstorm network controllers and boards33+ * Copyright 2010-2012 Solarflare Communications Inc.44+ *55+ * This program is free software; you can redistribute it and/or modify it66+ * under the terms of the GNU General Public License version 2 as published77+ * by the Free Software Foundation, incorporated herein by reference.88+ */99+#ifndef _VFDI_H1010+#define _VFDI_H1111+1212+/**1313+ * DOC: Virtual Function Driver Interface1414+ *1515+ * This file contains software structures used to form a two way1616+ * communication channel between the VF driver and the PF driver,1717+ * named Virtual Function Driver Interface (VFDI).1818+ *1919+ * For the purposes of VFDI, a page is a memory region with size and2020+ * alignment of 4K. All addresses are DMA addresses to be used within2121+ * the domain of the relevant VF.2222+ *2323+ * The only hardware-defined channels for a VF driver to communicate2424+ * with the PF driver are the event mailboxes (%FR_CZ_USR_EV2525+ * registers). Writing to these registers generates an event with2626+ * EV_CODE = EV_CODE_USR_EV, USER_QID set to the index of the mailbox2727+ * and USER_EV_REG_VALUE set to the value written. The PF driver may2828+ * direct or disable delivery of these events by setting2929+ * %FR_CZ_USR_EV_CFG.3030+ *3131+ * The PF driver can send arbitrary events to arbitrary event queues.3232+ * However, for consistency, VFDI events from the PF are defined to3333+ * follow the same form and be sent to the first event queue assigned3434+ * to the VF while that queue is enabled by the VF driver.3535+ *3636+ * The general form of the variable bits of VFDI events is:3737+ *3838+ * 0 16 24 313939+ * | DATA | TYPE | SEQ |4040+ *4141+ * SEQ is a sequence number which should be incremented by 1 (modulo4242+ * 256) for each event. The sequence numbers used in each direction4343+ * are independent.4444+ *4545+ * The VF submits requests of type &struct vfdi_req by sending the4646+ * address of the request (ADDR) in a series of 4 events:4747+ *4848+ * 0 16 24 314949+ * | ADDR[0:15] | VFDI_EV_TYPE_REQ_WORD0 | SEQ |5050+ * | ADDR[16:31] | VFDI_EV_TYPE_REQ_WORD1 | SEQ+1 |5151+ * | ADDR[32:47] | VFDI_EV_TYPE_REQ_WORD2 | SEQ+2 |5252+ * | ADDR[48:63] | VFDI_EV_TYPE_REQ_WORD3 | SEQ+3 |5353+ *5454+ * The address must be page-aligned. After receiving such a valid5555+ * series of events, the PF driver will attempt to read the request5656+ * and write a response to the same address. In case of an invalid5757+ * sequence of events or a DMA error, there will be no response.5858+ *5959+ * The VF driver may request that the PF driver writes status6060+ * information into its domain asynchronously. After writing the6161+ * status, the PF driver will send an event of the form:6262+ *6363+ * 0 16 24 316464+ * | reserved | VFDI_EV_TYPE_STATUS | SEQ |6565+ *6666+ * In case the VF must be reset for any reason, the PF driver will6767+ * send an event of the form:6868+ *6969+ * 0 16 24 317070+ * | reserved | VFDI_EV_TYPE_RESET | SEQ |7171+ *7272+ * It is then the responsibility of the VF driver to request7373+ * reinitialisation of its queues.7474+ */7575+#define VFDI_EV_SEQ_LBN 247676+#define VFDI_EV_SEQ_WIDTH 87777+#define VFDI_EV_TYPE_LBN 167878+#define VFDI_EV_TYPE_WIDTH 87979+#define VFDI_EV_TYPE_REQ_WORD0 08080+#define VFDI_EV_TYPE_REQ_WORD1 18181+#define VFDI_EV_TYPE_REQ_WORD2 28282+#define VFDI_EV_TYPE_REQ_WORD3 38383+#define VFDI_EV_TYPE_STATUS 48484+#define VFDI_EV_TYPE_RESET 58585+#define VFDI_EV_DATA_LBN 08686+#define VFDI_EV_DATA_WIDTH 168787+8888+struct vfdi_endpoint {8989+ u8 mac_addr[ETH_ALEN];9090+ __be16 tci;9191+};9292+9393+/**9494+ * enum vfdi_op - VFDI operation enumeration9595+ * @VFDI_OP_RESPONSE: Indicates a response to the request.9696+ * @VFDI_OP_INIT_EVQ: Initialize SRAM entries and initialize an EVQ.9797+ * @VFDI_OP_INIT_RXQ: Initialize SRAM entries and initialize an RXQ.9898+ * @VFDI_OP_INIT_TXQ: Initialize SRAM entries and initialize a TXQ.9999+ * @VFDI_OP_FINI_ALL_QUEUES: Flush all queues, finalize all queues, then100100+ * finalize the SRAM entries.101101+ * @VFDI_OP_INSERT_FILTER: Insert a MAC filter targetting the given RXQ.102102+ * @VFDI_OP_REMOVE_ALL_FILTERS: Remove all filters.103103+ * @VFDI_OP_SET_STATUS_PAGE: Set the DMA page(s) used for status updates104104+ * from PF and write the initial status.105105+ * @VFDI_OP_CLEAR_STATUS_PAGE: Clear the DMA page(s) used for status106106+ * updates from PF.107107+ */108108+enum vfdi_op {109109+ VFDI_OP_RESPONSE = 0,110110+ VFDI_OP_INIT_EVQ = 1,111111+ VFDI_OP_INIT_RXQ = 2,112112+ VFDI_OP_INIT_TXQ = 3,113113+ VFDI_OP_FINI_ALL_QUEUES = 4,114114+ VFDI_OP_INSERT_FILTER = 5,115115+ VFDI_OP_REMOVE_ALL_FILTERS = 6,116116+ VFDI_OP_SET_STATUS_PAGE = 7,117117+ VFDI_OP_CLEAR_STATUS_PAGE = 8,118118+ VFDI_OP_LIMIT,119119+};120120+121121+/* Response codes for VFDI operations. Other values may be used in future. */122122+#define VFDI_RC_SUCCESS 0123123+#define VFDI_RC_ENOMEM (-12)124124+#define VFDI_RC_EINVAL (-22)125125+#define VFDI_RC_EOPNOTSUPP (-95)126126+#define VFDI_RC_ETIMEDOUT (-110)127127+128128+/**129129+ * struct vfdi_req - Request from VF driver to PF driver130130+ * @op: Operation code or response indicator, taken from &enum vfdi_op.131131+ * @rc: Response code. Set to 0 on success or a negative error code on failure.132132+ * @u.init_evq.index: Index of event queue to create.133133+ * @u.init_evq.buf_count: Number of 4k buffers backing event queue.134134+ * @u.init_evq.addr: Array of length %u.init_evq.buf_count containing DMA135135+ * address of each page backing the event queue.136136+ * @u.init_rxq.index: Index of receive queue to create.137137+ * @u.init_rxq.buf_count: Number of 4k buffers backing receive queue.138138+ * @u.init_rxq.evq: Instance of event queue to target receive events at.139139+ * @u.init_rxq.label: Label used in receive events.140140+ * @u.init_rxq.flags: Unused.141141+ * @u.init_rxq.addr: Array of length %u.init_rxq.buf_count containing DMA142142+ * address of each page backing the receive queue.143143+ * @u.init_txq.index: Index of transmit queue to create.144144+ * @u.init_txq.buf_count: Number of 4k buffers backing transmit queue.145145+ * @u.init_txq.evq: Instance of event queue to target transmit completion146146+ * events at.147147+ * @u.init_txq.label: Label used in transmit completion events.148148+ * @u.init_txq.flags: Checksum offload flags.149149+ * @u.init_txq.addr: Array of length %u.init_txq.buf_count containing DMA150150+ * address of each page backing the transmit queue.151151+ * @u.mac_filter.rxq: Insert MAC filter at VF local address/VLAN targetting152152+ * all traffic at this receive queue.153153+ * @u.mac_filter.flags: MAC filter flags.154154+ * @u.set_status_page.dma_addr: Base address for the &struct vfdi_status.155155+ * This address must be such that the structure fits within a page.156156+ * @u.set_status_page.peer_page_count: Number of additional pages the VF157157+ * has provided into which peer addresses may be DMAd.158158+ * @u.set_status_page.peer_page_addr: Array of DMA addresses of pages.159159+ * If the number of peers exceeds 256, then the VF must provide160160+ * additional pages in this array. The PF will then DMA up to161161+ * 512 vfdi_endpoint structures into each page. These addresses162162+ * must be page-aligned.163163+ */164164+struct vfdi_req {165165+ u32 op;166166+ u32 reserved1;167167+ s32 rc;168168+ u32 reserved2;169169+ union {170170+ struct {171171+ u32 index;172172+ u32 buf_count;173173+ u64 addr[];174174+ } init_evq;175175+ struct {176176+ u32 index;177177+ u32 buf_count;178178+ u32 evq;179179+ u32 label;180180+ u32 flags;181181+#define VFDI_RXQ_FLAG_SCATTER_EN 1182182+ u32 reserved;183183+ u64 addr[];184184+ } init_rxq;185185+ struct {186186+ u32 index;187187+ u32 buf_count;188188+ u32 evq;189189+ u32 label;190190+ u32 flags;191191+#define VFDI_TXQ_FLAG_IP_CSUM_DIS 1192192+#define VFDI_TXQ_FLAG_TCPUDP_CSUM_DIS 2193193+ u32 reserved;194194+ u64 addr[];195195+ } init_txq;196196+ struct {197197+ u32 rxq;198198+ u32 flags;199199+#define VFDI_MAC_FILTER_FLAG_RSS 1200200+#define VFDI_MAC_FILTER_FLAG_SCATTER 2201201+ } mac_filter;202202+ struct {203203+ u64 dma_addr;204204+ u64 peer_page_count;205205+ u64 peer_page_addr[];206206+ } set_status_page;207207+ } u;208208+};209209+210210+/**211211+ * struct vfdi_status - Status provided by PF driver to VF driver212212+ * @generation_start: A generation count DMA'd to VF *before* the213213+ * rest of the structure.214214+ * @generation_end: A generation count DMA'd to VF *after* the215215+ * rest of the structure.216216+ * @version: Version of this structure; currently set to 1. Later217217+ * versions must either be layout-compatible or only be sent to VFs218218+ * that specifically request them.219219+ * @length: Total length of this structure including embedded tables220220+ * @vi_scale: log2 the number of VIs available on this VF. This quantity221221+ * is used by the hardware for register decoding.222222+ * @max_tx_channels: The maximum number of transmit queues the VF can use.223223+ * @rss_rxq_count: The number of receive queues present in the shared RSS224224+ * indirection table.225225+ * @peer_count: Total number of peers in the complete peer list. If larger226226+ * than ARRAY_SIZE(%peers), then the VF must provide sufficient227227+ * additional pages each of which is filled with vfdi_endpoint structures.228228+ * @local: The MAC address and outer VLAN tag of *this* VF229229+ * @peers: Table of peer addresses. The @tci fields in these structures230230+ * are currently unused and must be ignored. Additional peers are231231+ * written into any additional pages provided by the VF.232232+ * @timer_quantum_ns: Timer quantum (nominal period between timer ticks)233233+ * for interrupt moderation timers, in nanoseconds. This member is only234234+ * present if @length is sufficiently large.235235+ */236236+struct vfdi_status {237237+ u32 generation_start;238238+ u32 generation_end;239239+ u32 version;240240+ u32 length;241241+ u8 vi_scale;242242+ u8 max_tx_channels;243243+ u8 rss_rxq_count;244244+ u8 reserved1;245245+ u16 peer_count;246246+ u16 reserved2;247247+ struct vfdi_endpoint local;248248+ struct vfdi_endpoint peers[256];249249+250250+ /* Members below here extend version 1 of this structure */251251+ u32 timer_quantum_ns;252252+};253253+254254+#endif