Commit Graph

37110 Commits

Author SHA1 Message Date
Gleb Smirnoff
1a49612526 Mechanically convert INP_INFO_RLOCK() to NET_EPOCH_ENTER().
Remove few outdated comments and extraneous assertions.  No
functional change here.
2019-11-07 00:08:34 +00:00
Ed Maste
fcb71d3f8e mgb: Correct spello - recieve -> receive
Reported by:	N. J. Mann
MFC with:	r354410
2019-11-06 20:43:40 +00:00
Ed Maste
8890ab7758 Introduce if_mgb driver for Microchip LAN743x PCIe NIC
The Microchip LAN7430 is a PCIe 10/100/1000 Ethernet MAC with integrated
PHY, and the LAN7431 is a MAC with RGMII interface.

To be connected to the build after further testing and review.
Committing now so that changes like r354345 (adding a common
ETHER_IS_ZERO macro) will update this driver too.

Submitted by:	Gerald ND Aryeetey <aryeeteygerald_rogers.com>
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D20079
2019-11-06 19:51:40 +00:00
Mark Johnston
7e7876c7d9 Convert ksyms(4) to use an OBJT_PHYS object.
The pages stored in the ksyms object are not pageable.  Moreover, this
obviates the need to set OBJ_NOSPLIT.

Reviewed by:	alc, kib
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D22229
2019-11-06 17:03:06 +00:00
Emmanuel Vadot
9c3a56d076 regulator: Add regulator_check_voltage function
This function will call the regnode_check_voltage method for a given regulator
and check if the desired voltage in reachable by it.
Also adds a default method that check the std_param and which should be enough
for most regulators and add it as the method for axp* rk805 and fixed regulators.

Reviewed by:	mmel
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D22260
2019-11-06 14:55:24 +00:00
Andriy Gapon
236204ee0f if_ixv: disable RSS configuration on 82599 and X540 VFs
It is reported that those VFs share their RSS configuration with PF and,
thus, they cannot be configured independently.

Also:
- add missing opt_rss.h to if_ixv.c, otherwise RSS kernel option could
  not be seen
- do not enable IXGBE_FEATURE_RSS on the older VFs
- set flowid / hash type to M_HASHTYPE_NONE or M_HASHTYPE_OPAQUE_HASH
  (based on what the hardware reports) if IXGBE_FEATURE_RSS is not set

Reviewed by:	nobody
MFC after:	4 weeks
Sponsored by: Panzura
Differential Revision: https://reviews.freebsd.org/D21705
2019-11-05 06:34:20 +00:00
Eric Joyner
74954211d6 net: add ETHER_IS_ZERO macro similar to ETHER_IS_BROADCAST
Some places in network code may need to verify that an ethernet address
is not the 'zero' address. Provide a standard macro ETHER_IS_ZERO for
this purpose, similar to the ETHER_IS_BROADCAST macro already available.

This patch also removes previous ETHER_IS_ZERO definitions in several
USB ethernet drivers, in favor of this centrally-located macro.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>

Submitted by:	Jacob Keller <jacob.e.keller@intel.com>
Reviewed by:	erj@
Sponsored by:	Intel Corporation
Differential Revision:	https://reviews.freebsd.org/D21240
2019-11-05 00:12:21 +00:00
Eric Joyner
e81998f407 net: prefer ETHER_ADDR_LEN over ETH_ADDR_LEN
A couple of drivers and one place in if.c use ETH_ADDR_LEN, even though
net/ethernet.h provides an equivalent ETHER_ADDR_LEN definition.

Cleanup all of the locations which refer to ETH_ADDR_LEN to use the
standard ETHER_ADDR_LEN instead.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>

Submitted by:	Jacob Keller <jacob.e.keller@intel.com>
Reviewed by:	erj@, jpaetzel@
Sponsored by:	Intel Corporation
Differential Revision:	https://reviews.freebsd.org/D21239
2019-11-04 22:57:36 +00:00
Vladimir Kondratyev
69fac7c3af [ig4] Try to workaround MIPS namespace pollution issue 2019-11-04 02:29:58 +00:00
Vladimir Kondratyev
371d37d89f [ig4] Convert ithread interrupt handler to filter based one. 2019-11-03 21:17:50 +00:00
Vladimir Kondratyev
b97c743766 [ig4] Enable additional registers support on Appolo Lake controllers
To be inline with intel-lpss Linux driver
2019-11-03 21:17:01 +00:00
Vladimir Kondratyev
81e8183814 [ig4] Add support for CannonLake controllers
They are clocked at 216MHz rate, much higher than previous models.

PR:		240485
Submitted by:	Neel Chauhan <neel@neelc.org>
2019-11-03 21:16:06 +00:00
Vladimir Kondratyev
fceaa2ec31 [ig4] Add generic resource methods to bus interface
That allows ig4 children to allocate IRQs
2019-11-03 21:15:01 +00:00
Vladimir Kondratyev
bff2755582 [ig4] Minor improvement of write pipelining
With leaving some data queued in the TX FIFO at the end of write cycle.
2019-11-03 21:14:08 +00:00
Vladimir Kondratyev
0eb21d1b6e [ig4] wait for bus stop condition after stop command issued
It gives better error detection and ig4 driver's lock coverage
in a pipelined write case
2019-11-03 21:12:59 +00:00
Vladimir Kondratyev
ae73652c4f [ig4] On SkyLake controllers issue reset on attach unconditionally.
It is very helpful during debugging of I2C issues.
It is done only for SkyLakes due to lack of testing on other hardware.
2019-11-03 21:10:47 +00:00
Vladimir Kondratyev
847f557cb4 [ig4] Set STOP condition and flush TX/RX FIFOs on error
if controller has not it done for us yet.

Reset controller when transfer abort is failed.
2019-11-03 21:08:26 +00:00
Vladimir Kondratyev
e3a56ba233 [ig4] Improve error detection
Handle error bits of INTR_STAT and TX_ABORT registers.

Move interrupt clearing from interrupt handler to polling loop to get
common execution path with polled mode.

Do not clear interrupts with reading of IG4_REG_CLR_INTR register as
interrupts, triggered during the period from reg_read(IG4_REG_INTR_STAT)
to reg_read(IG4_REG_CLR_INTR) will be missed.
Instead, read each IG4_REG_CLR_* register separately.
2019-11-03 21:07:12 +00:00
Vladimir Kondratyev
b0eb9d3e08 [ig4] Convert polling loop from status-based to interrupt-based
INTR_STAT register exposes more useful informaton then STA register does
e.g. it exposes error and I2C bus STOP conditions. Make it a main source
of I2C transfer state.
2019-11-03 21:06:06 +00:00
Vladimir Kondratyev
7f6aee646a [ig4] Use interrupts for waiting for empty TX FIFO 2019-11-03 21:04:51 +00:00
Vladimir Kondratyev
7814f978e2 [ig4] Convert last remaining usage of TX_NOTFULL status to TX_EMPTY
in ig4iic_read routine. It makes possible interrupt utilization while
waiting for empty space in TX FIFO.
2019-11-03 21:03:55 +00:00
Vladimir Kondratyev
023c42edae [ig4] Rewrite ig4iic_write routine to use TX_EMPTY status flag
rather than TX_NOTFULL. It makes possible interrupt utilization while
waiting for empty space in TX FIFO.
2019-11-03 21:03:07 +00:00
Vladimir Kondratyev
6f0c4b8583 [ig4] Remove dead code inherited from DragonflyBSD 2019-11-03 21:01:53 +00:00
Vladimir Kondratyev
db7caa2ea7 [ig4] Add suspend/resume support
That is done with re-execution of controller initialization procedure
from resume handler.

PR:		238037
2019-11-03 21:00:55 +00:00
Vladimir Kondratyev
83a66b9bda [ig4] Implement burst mode for data reads
In this mode DATA_CMD register reads and writes are performed in
TX/RX FIFO-sized bursts to increase I2C bus utilization.

That reduces read time from 60us to 30us per byte when read data is fit
in to RX FIFO buffer in FAST speed mode in my setup.
2019-11-03 20:59:04 +00:00
Vladimir Kondratyev
885128387e [ig4] Set clock registers based on controller model
IC clock rates are varied between different controller models so we have
to adjust timing registers in each case individually. Borrow intresting
constants and formulas from Intel specs, i2c-designware and lpss_intel
drivers and apply them to FreeBSD supported controller models.

Implement fetching of timing data via ACPI methods execution if available.
2019-11-03 20:57:59 +00:00
Vladimir Kondratyev
38cca60be5 [ig4] dump IG4_REG_COMP_PARAM1 and IG4_REG_COMP_VER registers unconditionally
They appeared to be supported (although undocumented) on SkyLakes+ too.
2019-11-03 20:56:53 +00:00
Vladimir Kondratyev
6825cefb23 [cyapa] Postpone start of the polling thread until sleep is available
After recent ig4 changes cyapa driver can be attached before timers
initialization is completed. Start polling thread from config_intrhook
to avoid busy loops in that case.
2019-11-03 20:55:28 +00:00
Vladimir Kondratyev
6777ccd98b [ig4] Do not wait until interrupts are enabled at attach stage
as the driver is fully functional on a cold boot through utilization of
polled mode.

As a side effect, ig4 children probe and attach methods can be called
earlier in the boot sequence, so now it is up to the child drivers
to wait for a kernel initialization completion if it is required.
2019-11-03 20:54:17 +00:00
Vladimir Kondratyev
41b24e0917 [ig4] Allow enabling of polled mode from iicbus allocation callback
If controller is allocated with IIC_NOWAIT option ig4 enables polled mode
for a period of allocation that makes possible to start I2C transfers
from the contexts where sleeping is not allowed e.g. from ithreads or
callouts.
2019-11-03 20:53:13 +00:00
Vladimir Kondratyev
c59aca578e [ig4] Add support for polled mode
Currently ig4 internally depends on it's own interrupts and uses mtx_sleep()
to wait for them. That means it can not be used from any context where
sleeping is disallowed e.g. on cold boot, from DDB/KDB, from other device
driver's interrupt handlers and so on.

This change replaces sleeps with busy loops in cold boot and DDB cases.
2019-11-03 20:51:22 +00:00
Vladimir Kondratyev
d117e36316 [ig4] disable controller before initialization of clock counters
It is required by controller specifications.
2019-11-03 20:50:06 +00:00
Vladimir Kondratyev
edcf6a9f7a [ig4] Stop I2C controller after checking that it's kind of functional.
Obtained from:	DragonfliBSD (0b3eedb)
2019-11-03 20:49:04 +00:00
Vladimir Kondratyev
811ff4dd37 [ig4] We actually need to set the Rx threshold register one smaller.
Setting the IG4_REG_RX_TL register to 1 was actually generating an
interrupt after 2 bytes were available in the Rx fifo. We need to set the
register to 0 to get an interrupt for 1 byte already.

Obtained from:	DragonflyBSD (02f0bf2)
2019-11-03 20:47:49 +00:00
Vladimir Kondratyev
0a6b1b56d9 [ig4] Ignore stray interrupts 2019-11-03 20:46:20 +00:00
Vladimir Kondratyev
733d657a74 [ig4] Reduce scope of io_lock
Now io_lock is used as condition variable to synchronize active process with
the interrupt handler. It is not used for tasks other than waiting for
interrupt and passing parameters to and from it's handler.
2019-11-03 20:45:25 +00:00
Vladimir Kondratyev
85cd895fc0 [ig4] Do not wait for interrupts in set_controller() routine
Specs shows no dedicated interrupt firing on disable of the controller.

Remove io lock acquisitions around set_controller() calls as they are
not needed anymore.
2019-11-03 20:44:16 +00:00
Vladimir Kondratyev
eca74de013 [ig4] Drop driver's internal RX FIFO
There is no need to read all controller's RX FIFO data to clear RX_FULL
bit in interrupt handler as interrupts are masked permanently since
previous commit.
2019-11-03 20:43:02 +00:00
Vladimir Kondratyev
21e459c61b [ig4] Only enable interrupts when we want them. Otherwise keep mask at 0.
This avoids possible interrupt storms, depending on the state of the I2C
controller before the driver attached.

During attaching this clears the interrupt mask.

Revert r338215 as this change makes it no-op.

Obtained from:	DragonflyBSD (d7c8555)
2019-11-03 20:42:04 +00:00
Vladimir Kondratyev
bf9c3c58ca [ig4] Handle controller startup errors
Fail the attach on controller startup errors.  For some reason the
dell xps 13 says there's I2C controller, but the controller appears
to be permanente disabled and will refuse to enable.

Obtained from:	DragonflyBSD (509820b)
2019-11-03 20:40:55 +00:00
Vladimir Kondratyev
984ed3e493 [ig4] Give common name to PCI and ACPI device drivers
They share common device driver code with different bus attachments

This commit starts a bunch of changes which have following properties:

Reviewed by:		imp (previous version)
MFC after:		1 month
Differential Revision:	https://reviews.freebsd.org/D22016
2019-11-03 20:39:46 +00:00
Warner Losh
1c028d7227 Make valdiate_rx_req_id static inline because it uses other static
inline functions. gcc complains about this, most likely due to
the subtle differences between inline and static inline functions
defined in headers.
2019-11-02 02:05:09 +00:00
Vincenzo Maffione
c7c7805531 add valectl to the system commands
The valectl(4) program is used to manage vale(4) switches.
Add it to the system commands so that it can be used right away.
This program was previously called vale-ctl, and stored in
tools/tools/netmap

Reviewed by:	hrs, bcr, lwhsu, kevans
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D22146
2019-10-31 21:01:34 +00:00
Marcin Wojtas
2731abe8e6 Update ENA version to v2.1.0
In this release the netmap support was introduced.

Moreover, it is also now possible to use the LLQ mode of the driver on
the arm64 AWS instances (A1 type).

Differential Revision: https://reviews.freebsd.org/D21938
Submitted by: Michal Krawczyk <mk@semihalf.com>
Obtained from: Semihalf
Sponsored by:  Amazon, Inc.
2019-10-31 16:03:43 +00:00
Marcin Wojtas
358bcc4c6c Add support for ENA NETMAP partial initialization
In NETMAP mode not all queues need to be allocated to NETMAP. Some of
them could be left to the kernel. Configuration is managed by the flags
nr_mode and nr_pending_mode provided per each NETMAP kring.

ENA driver checks those flags and perform proper rings initialization.

Differential Revision: https://reviews.freebsd.org/D21937
Submitted by: Rafal Kozik <rk@semihalf.com>
              Michal Krawczyk <mk@semihalf.com>
Obtained from: Semihalf
Sponsored by:  Amazon, Inc.
2019-10-31 16:02:42 +00:00
Marcin Wojtas
6f2128c7ed Add support for ENA NETMAP Tx
Two new tables are added to ena_tx_buffer structure:
* netmap_map_seg stores DMA mapping structures,
* netmap_buf_idx stores buff indexes taken from the slots.

When Tx resources are being set, the new mapping structures are created
and netmap Tx rings are being reset.

When Tx resources are being released, used netmap bufs are unmapped from
DMA and then mapping structures are destroyed.

When Tx interrupt occurrs, ena_netmap_tx_irq is called.

ena_netmap_txsync callback signalizes that there are new packets which
should be transmitted.
First, it fills ena_netmap_ctx. Then it performs two actions:
* ena_netmap_tx_frames moves packets from netmap ring to NIC,
* ena_netmap_tx_cleanup restores buffers from NIC and gives them back
to the userspace app.
0 is returned in case of Tx error that could be handled by the driver.

ena_netmap_tx_frames checks if there are packets ready for transmission.
Then, for each of them, ena_netmap_tx_frame is called. If error occurs,
transmitting is stopped, but if the error was cause due to HW ring being
full, information about that is not propagated to the userspace app.
When all packets are ready, doorbell is written to NIC and netmap ring
state is updated.

Parsing of one packet is done by the ena_netmap_tx_frame function.
First, it checks if number of slots does not exceed NIC limit. Invalid
packets are being dropped and the error is propagated to the upper
layer. As each netmap buffer has equal size, which is typically greater
then 2KiB, there shouldn't be any packets which contain too many slots.
Then, the ena_com_tx_ctx structure is being filled. As netmap does not
support any hardware offloads, ena_com_tx_meta structure is set to zero.
After that, ena_netmap_map_slots maps all memory slots for DMA.
If the device works in the LLQ mode, the push header is being determined
by checking if the header fits within the first socket.
If so, the portion of data is being copied directly from the slot.
In other case, the data is copied to the intermediate buffer.
First slots are treated the same as as the others, because DMA mapping
has no impact on LLQ mode. Index of each netmap buffer is taken from
slot and stored in netmap_buf_idx array. In case of mapping error,
memory is unmapped and packets are put back to the netmap ring.

ena_netmap_tx_cleanup performs out of order cleanup of sent buffers.
First, req_id is taken and is validated. As validate_tx_req_id from
ena.c is specific to kernels mbuf, another implementation is provided.
Each req_id is cleaned up by ena_netmap_tx_clean_one function. Buffers
are being unmaped from DMA and put back to netmap ring. In the end,
state of netmap and NIC rings are being updated.

Differential Revision: https://reviews.freebsd.org/D21936
Submitted by: Rafal Kozik <rk@semihalf.com>
              Michal Krawczyk <mk@semihalf.com>
Obtained from: Semihalf
Sponsored by:  Amazon, Inc.
2019-10-31 15:59:29 +00:00
Marcin Wojtas
9a0f2079ca Add support for ENA NETMAP Rx
Most of code used for Rx ring initialization could be reused in NETMAP.
Reset of NETMAP ring and new alloc method was added. Driver decides if
use kernels mbufs or NETMAPs slots based on IFCAP_NETMAP flag. It
allows to reuse ena_refill_rx_bufs, which provides proper handling of
Rx out of order completion.

ena_netmap_alloc_rx_slot takes exactly the same arguments as
ena_alloc_rx_mbuf, but instead of allocating one mbuf it takes one slot
from NETMAP ring. Based on queue id proper netmap_ring is found. As
NETMAP provides the "partial opening" feature not all of the rings are
avaiable. Not used points to invalid ring. If there is available slot,
it is taken from the ring. Its buffer is mapped to DMA and its index is
stored in ena_rx_buffer field in ena_rx_buffer structure. Then ena_buf
is filled with addresses and ring state is updated.

Cleanup is handled by ena_netmap_free_rx_slot. It unmaps DMA and returns
buffer to ring. As we could not return more bufs than we have taken and
we should not override occupied slots, buf_index should be 0. It is
being checked by assertion.

ena_netmap_rxsync callback puts received packets back to NETMAP ring and
passes them to user space by updating ring pointers. First it fills
ena_netmap_ctx.
Then it performs two actions:
* ena_netmap_rx_frames moves received frames from NIC to NETMAP ring,
* ena_netmap_rx_cleanup fills NIC ring with slots released by userspace
app.

In case of Rx error that could be handled by NIC driver (for example by
performing reset) rx sync should return 0.

ena_netmap_rx_frames first checks if NETMAP ring is in consistent
state and then in the loop receives new frames. When all available
frames are taken nr_hwtail is updated.

Receiving one frame is handled by ena_netmap_rx_frame. If no error
occurrs, each Descriptor is loaded by ena_netmap_rx_load_desc function.
If packets take more than one segments NS_MOREFRAG flag must be set in
all, but not last slot. In case of wrong req_id packet is removed from
NETMAP ring. If packet is successful received counters are updated.

Refiling of NIC ring is performed by ena_netmap_rx_cleanup function.
It calculates number of available slots and call ena_refill_rx_bufs with
proper number.

Differential Revision: https://reviews.freebsd.org/D21935
Submitted by: Rafal Kozik <rk@semihalf.com>
              Michal Krawczyk <mk@semihalf.com>
Obtained from: Semihalf
Sponsored by:  Amazon, Inc.
2019-10-31 15:57:44 +00:00
Marcin Wojtas
d17b7d87ee Introduce NETMAP support in ENA
Mock implementation of NETMAP routines is located in ena_netmap.c/.h
files. All code is protected under the DEV_NETMAP macro. Makefile was
updated with files and flag.

As ENA driver provide own implementations of (un)likely it must be
undefined before including NETMAP headers.

ena_netmap_attach function is called on the end of NIC attach. It fills
structure with NIC configuration and callbacks. Then provides it to
netmap_attach. Similarly netmap_detach is called during ena_detach.

Three callbacks are used.
nm_register is implemented by ena_netmap_reg. It is called when user
space application open or close NIC in NETMAP mode. Current action is
recognized based on onoff parameter: true means on and false off. As
NICs rings need to be reconfigured ena_down and ena_up are reused.
When user space application wants to receive new packets from NIC
nm_rxsync is called, and when there are new packets ready for Tx
nm_txsync is called.

Differential Revision: https://reviews.freebsd.org/D21934
Submitted by: Rafal Kozik <rk@semihalf.com>
              Michal Krawczyk <mk@semihalf.com>
Obtained from: Semihalf
Sponsored by:  Amazon, Inc.
2019-10-31 15:51:18 +00:00
Marcin Wojtas
38c7b96517 Split Rx/Tx from initialization code in ENA driver
Move Rx/Tx routines to separate file.
Some functions:
* ena_restore_device,
* ena_destroy_device,
* ena_up,
* ena_down,
* ena_refill_rx_bufs
could be reused in upcoming netmap code in the driver. To make it
possible, they were moved to ena.h header.

Differential Revision: https://reviews.freebsd.org/D21933
Submitted by:  Rafal Kozik <rk@semihalf.com>
Obtained from: Semihalf
Sponsored by:  Amazon, Inc.
2019-10-31 15:44:26 +00:00
Marcin Wojtas
2439228158 Fix ENA keep-alive timeout due to prolonged reset
When the ENA_FLAG_DEVICE_RUNNING flag is disabled, the AENQ handlers
aren't executed. To fix that, the watchdog timestamp should be updated
just before enabling the watchdog.

Timer service was always being enabled, even if the device wasn't up
before the reset. That shouldn't happen, as the timer service is being
executed only for working interface.

Differential Revision: https://reviews.freebsd.org/D21932
Submitted by:  Michal Krawczyk <mk@semihalf.com>
Obtained from: Semihalf
Sponsored by:  Amazon, Inc.
2019-10-31 15:39:54 +00:00