diff options
| author | Nick Price <nick@spun.io> | 2026-06-20 19:03:09 +0000 |
|---|---|---|
| committer | Adrian Chadd <adrian@FreeBSD.org> | 2026-06-20 19:10:16 +0000 |
| commit | 5409e03a0ef1f2d71da94bedd433fbaa7b6b21f2 (patch) | |
| tree | f0c5ed0bf9a9d22b16307610dab912ff89b1a6f7 | |
| parent | b64408358d7f27a69b84d9fd1e23e239e8bd00fc (diff) | |
aq(4): modernize and de-Linuxify the vendor driver
Dead-code removal, device_printf(9) logging, style(9) de-Linuxification,
const F/W-ops tables, and readability cleanups. No change for valid
traffic.
Dead code and logging:
- Remove the sub-gigabit TSO-masking block in the link-state ISR: it
cleared IFCAP_TSO from the static isc_capabilities record (read only at
attach / SIOCSIFCAP, never on the datapath), so it never gated TSO and
only corrupted the validation mask. The Atlantic has no sub-gigabit TSO
erratum.
- Tidy the RX buffer-size handling: drop the dead switch(MCLBYTES) in
aq_if_rx_queues_alloc, rename rx_max_frame_size -> rx_buf_size, and bound
the per-fragment length from the wb.pkt_len writeback (EBADMSG on
underflow or a final fragment longer than the RX buffer).
- Drop every __FreeBSD__/__FreeBSD_version branch (FreeBSD 14.0 baseline);
the pre-13 arms used pre-opaque-if_t APIs since removed and one never
built.
- Route all log messages through device_printf(9) (MAC via %6D), adding a
device_t to struct aq_hw; drop the dead AQ_XXX_UNIMPLEMENTED_FUNCTION and
aq_log_error macros and the per-ring init console spam.
- Minor: comma -> semicolon in aq_if_attach_pre; (uint64_t) -> (uint32_t)
TX high-word cast; MODULE_VERSION(atlantic, 1); remove unused/duplicate
#includes.
style(9) and types:
- Remove all typedef'd struct/enum/union types (aq_dev_t, the speed/fc/
debug enums, the volatile RX/TX descriptor types, the firmware-file
types) in favor of bare tags; for the DMA descriptors the volatile
qualifier moves to the pointer/use sites. Drop the _s/_e tag suffixes
and the "#define aq_hw_s aq_hw" alias. Rename the OOP-style *self
parameter to hw. Replace usec_delay/msec_delay/ARRAY_SIZE/LOWORD with
FreeBSD equivalents (BIT kept). __attribute__((__packed__)) -> __packed.
F/W-ops vtable:
- Rename the leftover hal parameter to hw; make aq_fw1x_ops/aq_fw2x_ops
const (read-only data); drop the always-true "fw_ops &&" and
always-present dispatch guards (only led_control, absent in F/W 1.x,
keeps its NULL check).
Readability:
- aq_isc_rxd_pkt_get: fold the four identical RX-error blocks into one
rx_err: label. aq_isc_rxd_available: hoist the shared descriptor advance
out of the EOP test and drop the redundant continue. aq_hw_offload_set:
drop the dead "int err = 0". Fix a stale "10 ms" comment on a 50 ms
DELAY and the redundant literal parentheses.
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D57438
| -rw-r--r-- | sys/dev/aq/aq_common.h | 12 | ||||
| -rw-r--r-- | sys/dev/aq/aq_dbg.c | 2 | ||||
| -rw-r--r-- | sys/dev/aq/aq_dbg.h | 11 | ||||
| -rw-r--r-- | sys/dev/aq/aq_device.h | 16 | ||||
| -rw-r--r-- | sys/dev/aq/aq_fw.c | 49 | ||||
| -rw-r--r-- | sys/dev/aq/aq_fw.h | 20 | ||||
| -rw-r--r-- | sys/dev/aq/aq_fw1x.c | 56 | ||||
| -rw-r--r-- | sys/dev/aq/aq_fw2x.c | 80 | ||||
| -rw-r--r-- | sys/dev/aq/aq_hw.c | 157 | ||||
| -rw-r--r-- | sys/dev/aq/aq_hw.h | 42 | ||||
| -rw-r--r-- | sys/dev/aq/aq_hw_llh.c | 86 | ||||
| -rw-r--r-- | sys/dev/aq/aq_irq.c | 17 | ||||
| -rw-r--r-- | sys/dev/aq/aq_main.c | 104 | ||||
| -rw-r--r-- | sys/dev/aq/aq_media.c | 13 | ||||
| -rw-r--r-- | sys/dev/aq/aq_ring.c | 88 | ||||
| -rw-r--r-- | sys/dev/aq/aq_ring.h | 26 |
16 files changed, 328 insertions, 451 deletions
diff --git a/sys/dev/aq/aq_common.h b/sys/dev/aq/aq_common.h index 6529f249ff62..5c497d071802 100644 --- a/sys/dev/aq/aq_common.h +++ b/sys/dev/aq/aq_common.h @@ -40,24 +40,14 @@ #define BIT(nr) (1UL << (nr)) -#define usec_delay(x) DELAY(x) - -#ifndef msec_delay -#define msec_delay(x) DELAY(x*1000) -#define msec_delay_irq(x) DELAY(x*1000) -#endif - #define AQ_HW_WAIT_FOR(_B_, _US_, _N_) ({ \ unsigned int _i; \ for (_i = (_N_); !(_B_) && _i; --_i) \ - usec_delay(_US_); \ + DELAY(_US_); \ (_i == 0) ? ETIMEDOUT : 0; \ }) -#define LOWORD(a) ((uint16_t)(a)) -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) - #define AQ_VER "0.0.5" #endif // _AQ_COMMON_H_ diff --git a/sys/dev/aq/aq_dbg.c b/sys/dev/aq/aq_dbg.c index bed29b3d0755..ec3954185749 100644 --- a/sys/dev/aq/aq_dbg.c +++ b/sys/dev/aq/aq_dbg.c @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$"); #include "aq_dbg.h" -const aq_debug_level dbg_level_ = lvl_detail; +const enum aq_debug_level dbg_level_ = lvl_detail; const uint32_t dbg_categories_ = dbg_init | dbg_config | dbg_fw; diff --git a/sys/dev/aq/aq_dbg.h b/sys/dev/aq/aq_dbg.h index d90a8599e085..280572e7d5da 100644 --- a/sys/dev/aq/aq_dbg.h +++ b/sys/dev/aq/aq_dbg.h @@ -88,15 +88,15 @@ Debug levels: #define AQ_DBG_DUMP_DESC(desc) #endif -typedef enum aq_debug_level +enum aq_debug_level { lvl_error = LOG_ERR, lvl_warn = LOG_WARNING, lvl_trace = LOG_NOTICE, lvl_detail = LOG_INFO, -} aq_debug_level; +}; -typedef enum aq_debug_category +enum aq_debug_category { dbg_init = 1, dbg_config = 1 << 1, @@ -104,12 +104,12 @@ typedef enum aq_debug_category dbg_rx = 1 << 3, dbg_intr = 1 << 4, dbg_fw = 1 << 5, -} aq_debug_category; +}; #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) -extern const aq_debug_level dbg_level_; +extern const enum aq_debug_level dbg_level_; extern const uint32_t dbg_categories_; #define log_base_(_lvl, _fmt, args...) printf( "atlantic: " _fmt "\n", ##args) @@ -120,7 +120,6 @@ extern const uint32_t dbg_categories_; #define trace_base_(_lvl, _cat, _fmt, ...) do {} while (0) #endif // AQ_CFG_DEBUG_LVL > 0 -#define aq_log_error(_fmt, args...) log_base_(lvl_error, "[!] " _fmt, ##args) #define aq_log_warn(_fmt, args...) log_base_(lvl_warn, "/!\\ " _fmt, ##args) #define aq_log(_fmt, args...) log_base_(lvl_trace, _fmt, ##args) #define aq_log_detail(_fmt, args...) log_base_(lvl_detail, _fmt, ##args) diff --git a/sys/dev/aq/aq_device.h b/sys/dev/aq/aq_device.h index 64edbd138b3a..23785c1854c5 100644 --- a/sys/dev/aq/aq_device.h +++ b/sys/dev/aq/aq_device.h @@ -53,7 +53,7 @@ enum aq_media_type { #define AQ_LINK_ALL (AQ_LINK_100M | AQ_LINK_1G | AQ_LINK_2G5 | AQ_LINK_5G | \ AQ_LINK_10G ) -struct aq_stats_s { +struct aq_stats { uint64_t prc; uint64_t uprc; uint64_t mprc; @@ -77,7 +77,7 @@ struct aq_stats_s { uint64_t bbtc; }; -enum aq_dev_state_e { +enum aq_dev_state { AQ_DEV_STATE_UNLOAD, AQ_DEV_STATE_PCI_STOP, AQ_DEV_STATE_DOWN, @@ -126,8 +126,8 @@ struct aq_dev { bool linkup; int media_active; - struct aq_hw_stats_s last_stats; - struct aq_stats_s curr_stats; + struct aq_hw_stats last_stats; + struct aq_stats curr_stats; bitstr_t *vlan_tags; int mcnt; @@ -136,13 +136,11 @@ struct aq_dev { uint8_t rss_table[HW_ATL_RSS_INDIRECTION_TABLE_MAX]; }; -typedef struct aq_dev aq_dev_t; - -int aq_update_hw_stats(aq_dev_t *aq_dev); -void aq_initmedia(aq_dev_t *aq_dev); +int aq_update_hw_stats(struct aq_dev *aq_dev); +void aq_initmedia(struct aq_dev *aq_dev); int aq_linkstat_isr(void *arg); int aq_isr_rx(void *arg); -void aq_mediastatus_update(aq_dev_t *aq_dev, uint32_t link_speed, const struct aq_hw_fc_info *fc_neg); +void aq_mediastatus_update(struct aq_dev *aq_dev, uint32_t link_speed, const struct aq_hw_fc_info *fc_neg); void aq_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr); int aq_mediachange(struct ifnet *ifp); void aq_if_update_admin_status(if_ctx_t ctx); diff --git a/sys/dev/aq/aq_fw.c b/sys/dev/aq/aq_fw.c index 487137e9c61e..7f9496add875 100644 --- a/sys/dev/aq/aq_fw.c +++ b/sys/dev/aq/aq_fw.c @@ -48,18 +48,17 @@ __FBSDID("$FreeBSD$"); #include "aq_hw_llh_internal.h" #include "aq_fw.h" -#include "aq_common.h" #include "aq_dbg.h" -typedef enum aq_fw_bootloader_mode +enum aq_fw_bootloader_mode { boot_mode_unknown = 0, boot_mode_flb, boot_mode_rbl_flash, boot_mode_rbl_host_bootload, -} aq_fw_bootloader_mode; +}; #define AQ_CFG_HOST_BOOT_DISABLE 0 @@ -86,13 +85,13 @@ const uint32_t RBL_STATUS_HOST_BOOT = 0xf1a7; const uint32_t SCRATCHPAD_FW_LOADER_STATUS = (0x40 / sizeof(uint32_t)); -extern struct aq_firmware_ops aq_fw1x_ops; -extern struct aq_firmware_ops aq_fw2x_ops; +extern const struct aq_firmware_ops aq_fw1x_ops; +extern const struct aq_firmware_ops aq_fw2x_ops; -int mac_soft_reset_(struct aq_hw* hw, aq_fw_bootloader_mode* mode); +int mac_soft_reset_(struct aq_hw* hw, enum aq_fw_bootloader_mode* mode); int mac_soft_reset_flb_(struct aq_hw* hw); -int mac_soft_reset_rbl_(struct aq_hw* hw, aq_fw_bootloader_mode* mode); +int mac_soft_reset_rbl_(struct aq_hw* hw, enum aq_fw_bootloader_mode* mode); int wait_init_mac_firmware_(struct aq_hw* hw); @@ -111,7 +110,7 @@ aq_fw_reset(struct aq_hw* hw) } if (k == 1000) { - aq_log_error("Neither RBL nor FLB started"); + device_printf(hw->dev, "Neither RBL nor FLB started\n"); return (EBUSY); } @@ -131,10 +130,10 @@ aq_fw_reset(struct aq_hw* hw) return (0); } - aq_fw_bootloader_mode mode = boot_mode_unknown; + enum aq_fw_bootloader_mode mode = boot_mode_unknown; int err = mac_soft_reset_(hw, &mode); if (err != 0) { - aq_log_error("MAC reset failed: %d", err); + device_printf(hw->dev, "MAC reset failed: %d\n", err); return (err); } @@ -150,12 +149,12 @@ aq_fw_reset(struct aq_hw* hw) return wait_init_mac_firmware_(hw); case boot_mode_unknown: - aq_log_error("F/W bootload error: unknown bootloader type"); + device_printf(hw->dev, "F/W bootload error: unknown bootloader type\n"); return (ENOTSUP); case boot_mode_rbl_host_bootload: #if AQ_CFG_HOST_BOOT_DISABLE - aq_log_error("RBL> Host Bootload mode: this driver does not support Host Boot"); + device_printf(hw->dev, "RBL> Host Bootload mode: this driver does not support Host Boot\n"); return (ENOTSUP); #else trace(dbg_init, "RBL> Host Bootload mode"); @@ -166,7 +165,7 @@ aq_fw_reset(struct aq_hw* hw) /* * #todo: Host Boot */ - aq_log_error("RBL> F/W Host Bootload not implemented"); + device_printf(hw->dev, "RBL> F/W Host Bootload not implemented\n"); return (ENOTSUP); } @@ -191,14 +190,14 @@ aq_fw_ops_init(struct aq_hw* hw) return (0); } - aq_log_error("aq_fw_ops_init(): invalid F/W version %#x", + device_printf(hw->dev, "aq_fw_ops_init(): invalid F/W version %#x\n", hw->fw_version.raw); return (ENOTSUP); } int -mac_soft_reset_(struct aq_hw* hw, aq_fw_bootloader_mode* mode /*= nullptr*/) +mac_soft_reset_(struct aq_hw* hw, enum aq_fw_bootloader_mode* mode /*= nullptr*/) { if (hw->rbl_enabled) { return mac_soft_reset_rbl_(hw, mode); @@ -218,7 +217,7 @@ mac_soft_reset_flb_(struct aq_hw* hw) reg_global_ctl2_set(hw, 0x40e1); // Let Felicity hardware complete SMBUS transaction before Global // software reset. - msec_delay(50); + DELAY((50) * 1000); /* * If SPI burst transaction was interrupted(before running the script), @@ -228,7 +227,7 @@ mac_soft_reset_flb_(struct aq_hw* hw) reg_glb_nvr_provisioning2_set(hw, 0xa0); reg_glb_nvr_interface1_set(hw, 0x9f); reg_glb_nvr_interface1_set(hw, 0x809f); - msec_delay(50); + DELAY((50) * 1000); reg_glb_standard_ctl1_set(hw, (reg_glb_standard_ctl1_get(hw) & ~glb_reg_res_dis_msk) | glb_soft_res_msk); @@ -242,7 +241,7 @@ mac_soft_reset_flb_(struct aq_hw* hw) * For the case SPI burst transaction was interrupted (by MCP reset * above), wait until it is completed by hardware. */ - msec_delay(50); // Sleep for 10 ms. + DELAY(50 * 1000); /* MAC Kickstart */ if (!hw->fast_start_enabled) { @@ -254,7 +253,7 @@ mac_soft_reset_flb_(struct aq_hw* hw) flb_status = reg_glb_daisy_chain_status1_get(hw) & 0x10; if (flb_status != 0) break; - msec_delay(10); // Sleep for 10 ms. + DELAY(10 * 1000); } if (flb_status == 0) { @@ -268,7 +267,7 @@ mac_soft_reset_flb_(struct aq_hw* hw) reg_global_ctl2_set(hw, 0x80e0); // Let Felicity hardware complete SMBUS transaction before // Global software reset. - msec_delay(50); + DELAY((50) * 1000); } reg_glb_cpu_sem_set(hw, 1, 0); @@ -285,7 +284,7 @@ mac_soft_reset_flb_(struct aq_hw* hw) restart_completed = reg_glb_fw_image_id1_get(hw) != 0; if (restart_completed) break; - msec_delay(10); + DELAY((10) * 1000); } if (!restart_completed) { @@ -298,7 +297,7 @@ mac_soft_reset_flb_(struct aq_hw* hw) } int -mac_soft_reset_rbl_(struct aq_hw* hw, aq_fw_bootloader_mode* mode) +mac_soft_reset_rbl_(struct aq_hw* hw, enum aq_fw_bootloader_mode* mode) { trace(dbg_init, "RBL> MAC reset STARTED!"); @@ -322,11 +321,11 @@ mac_soft_reset_rbl_(struct aq_hw* hw, aq_fw_bootloader_mode* mode) // Wait for RBL to finish boot process. uint16_t rbl_status = 0; for (int k = 0; k < RBL_TIMEOUT_MS; ++k) { - rbl_status = LOWORD(reg_glb_cpu_no_reset_scratchpad_get(hw, NO_RESET_SCRATCHPAD_RBL_STATUS)); + rbl_status = ((uint16_t)(reg_glb_cpu_no_reset_scratchpad_get(hw, NO_RESET_SCRATCHPAD_RBL_STATUS))); if (rbl_status != 0 && rbl_status != 0xDEAD) break; - msec_delay(1); + DELAY((1) * 1000); } if (rbl_status == 0 || rbl_status == 0xDEAD) { @@ -357,7 +356,7 @@ wait_init_mac_firmware_(struct aq_hw* hw) if ((hw->fw_version.raw = AQ_READ_REG(hw, 0x18)) != 0) return (0); - msec_delay(1); + DELAY((1) * 1000); } trace_error(dbg_init, diff --git a/sys/dev/aq/aq_fw.h b/sys/dev/aq/aq_fw.h index ea2c37b6c92c..9195c91d6b5f 100644 --- a/sys/dev/aq/aq_fw.h +++ b/sys/dev/aq/aq_fw.h @@ -36,7 +36,7 @@ struct aq_hw; -typedef enum aq_fw_link_speed +enum aq_fw_link_speed { aq_fw_none = 0, aq_fw_100M = (1 << 0), @@ -44,30 +44,30 @@ typedef enum aq_fw_link_speed aq_fw_2G5 = (1 << 2), aq_fw_5G = (1 << 3), aq_fw_10G = (1 << 4), -} aq_fw_link_speed_t; +}; -typedef enum aq_fw_link_fc +enum aq_fw_link_fc { aq_fw_fc_none = 0, aq_fw_fc_ENABLE_RX = BIT(0), aq_fw_fc_ENABLE_TX = BIT(1), aq_fw_fc_ENABLE_ALL = aq_fw_fc_ENABLE_RX | aq_fw_fc_ENABLE_TX, -} aq_fw_link_fc_t; +}; #define aq_fw_speed_auto \ (aq_fw_100M | aq_fw_1G | aq_fw_2G5 | aq_fw_5G | aq_fw_10G) struct aq_firmware_ops { - int (*reset)(struct aq_hw* hal); + int (*reset)(struct aq_hw* hw); - int (*set_mode)(struct aq_hw* hal, enum aq_hw_fw_mpi_state_e mode, aq_fw_link_speed_t speed); - int (*get_mode)(struct aq_hw* hal, enum aq_hw_fw_mpi_state_e* mode, aq_fw_link_speed_t* speed, aq_fw_link_fc_t* fc); + int (*set_mode)(struct aq_hw* hw, enum aq_hw_fw_mpi_state mode, enum aq_fw_link_speed speed); + int (*get_mode)(struct aq_hw* hw, enum aq_hw_fw_mpi_state* mode, enum aq_fw_link_speed* speed, enum aq_fw_link_fc* fc); - int (*get_mac_addr)(struct aq_hw* hal, uint8_t* mac_addr); - int (*get_stats)(struct aq_hw* hal, struct aq_hw_stats_s* stats); + int (*get_mac_addr)(struct aq_hw* hw, uint8_t* mac_addr); + int (*get_stats)(struct aq_hw* hw, struct aq_hw_stats* stats); - int (*led_control)(struct aq_hw* hal, uint32_t mode); + int (*led_control)(struct aq_hw* hw, uint32_t mode); }; diff --git a/sys/dev/aq/aq_fw1x.c b/sys/dev/aq/aq_fw1x.c index f5458b174c3f..731370e94f3e 100644 --- a/sys/dev/aq/aq_fw1x.c +++ b/sys/dev/aq/aq_fw1x.c @@ -49,14 +49,14 @@ __FBSDID("$FreeBSD$"); #define FW1X_MPI_STATE_ADR 0x36C -typedef enum fw1x_mode { +enum fw1x_mode { FW1X_MPI_DEINIT = 0, FW1X_MPI_RESERVED = 1, FW1X_MPI_INIT = 2, FW1X_MPI_POWER = 4, -} fw1x_mode; +}; -typedef enum aq_fw1x_rate { +enum aq_fw1x_rate { FW1X_RATE_10G = 1 << 0, FW1X_RATE_5G = 1 << 1, FW1X_RATE_5GSR = 1 << 2, @@ -64,9 +64,9 @@ typedef enum aq_fw1x_rate { FW1X_RATE_1G = 1 << 4, FW1X_RATE_100M = 1 << 5, FW1X_RATE_INVALID = 1 << 6, -} aq_fw1x_rate; +}; -typedef union fw1x_state_reg { +union fw1x_state_reg { uint32_t val; struct { uint8_t mode; @@ -77,20 +77,20 @@ typedef union fw1x_state_reg { uint8_t reserved3 : 2; uint8_t downshift : 4; }; -} fw1x_state_reg; +}; int fw1x_reset(struct aq_hw* hw); -int fw1x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e mode, - aq_fw_link_speed_t speed); -int fw1x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e* mode, - aq_fw_link_speed_t* speed, aq_fw_link_fc_t* fc); +int fw1x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state mode, + enum aq_fw_link_speed speed); +int fw1x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state* mode, + enum aq_fw_link_speed* speed, enum aq_fw_link_fc* fc); int fw1x_get_mac_addr(struct aq_hw* hw, uint8_t* mac_addr); -int fw1x_get_stats(struct aq_hw* hw, struct aq_hw_stats_s* stats); +int fw1x_get_stats(struct aq_hw* hw, struct aq_hw_stats* stats); -static fw1x_mode -mpi_mode_to_fw1x_(enum aq_hw_fw_mpi_state_e mode) +static enum fw1x_mode +mpi_mode_to_fw1x_(enum aq_hw_fw_mpi_state mode) { switch (mode) { case MPI_DEINIT: @@ -113,7 +113,7 @@ mpi_mode_to_fw1x_(enum aq_hw_fw_mpi_state_e mode) return (FW1X_MPI_RESERVED); } -static aq_fw1x_rate +static enum aq_fw1x_rate link_speed_mask_to_fw1x_(uint32_t /*aq_fw_link_speed*/ speed) { uint32_t rate = 0; @@ -134,11 +134,11 @@ link_speed_mask_to_fw1x_(uint32_t /*aq_fw_link_speed*/ speed) if (speed & aq_fw_100M) rate |= FW1X_RATE_100M; - return ((aq_fw1x_rate)rate); + return ((enum aq_fw1x_rate)rate); } -static aq_fw_link_speed_t -fw1x_rate_to_link_speed_(aq_fw1x_rate rate) +static enum aq_fw_link_speed +fw1x_rate_to_link_speed_(enum aq_fw1x_rate rate) { switch (rate) { case FW1X_RATE_10G: @@ -164,7 +164,7 @@ fw1x_rate_to_link_speed_(aq_fw1x_rate rate) } int -fw1x_reset(struct aq_hw* hal) +fw1x_reset(struct aq_hw* hw) { uint32_t tid0 = ~0u; /*< Initial value of MBOX transactionId. */ struct aq_hw_fw_mbox mbox; @@ -173,7 +173,7 @@ fw1x_reset(struct aq_hw* hal) for (int i = 0; i < retryCount; ++i) { // Read the beginning of Statistics structure to capture the // Transaction ID. - aq_hw_fw_downld_dwords(hal, hal->mbox_addr, (uint32_t*)&mbox, + aq_hw_fw_downld_dwords(hw, hw->mbox_addr, (uint32_t*)&mbox, (uint32_t)((char*)&mbox.stats - (char*)&mbox) / sizeof(uint32_t)); // Successfully read the stats. @@ -193,7 +193,7 @@ fw1x_reset(struct aq_hw* hal) * Transaction ID value haven't changed since last time. * Try reading the stats again. */ - usec_delay(10); + DELAY(10); } trace_error(dbg_init, "F/W 1.x reset finalize timeout"); @@ -201,8 +201,8 @@ fw1x_reset(struct aq_hw* hal) } int -fw1x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e mode, - aq_fw_link_speed_t speed) +fw1x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state mode, + enum aq_fw_link_speed speed) { union fw1x_state_reg state = {0}; state.mode = mpi_mode_to_fw1x_(mode); @@ -217,15 +217,15 @@ fw1x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e mode, } int -fw1x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e* mode, - aq_fw_link_speed_t* speed, aq_fw_link_fc_t* fc) +fw1x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state* mode, + enum aq_fw_link_speed* speed, enum aq_fw_link_fc* fc) { union fw1x_state_reg state = { .val = AQ_READ_REG(hw, AQ_HW_MPI_STATE_ADR) }; trace(dbg_init, "fw1x> get_mode(): 0x36c -> %x, 0x368 -> %x", state.val, AQ_READ_REG(hw, AQ_HW_MPI_CONTROL_ADR)); - enum aq_hw_fw_mpi_state_e md = MPI_DEINIT; + enum aq_hw_fw_mpi_state md = MPI_DEINIT; switch (state.mode) { case FW1X_MPI_DEINIT: @@ -271,7 +271,7 @@ fw1x_get_mac_addr(struct aq_hw* hw, uint8_t* mac) } err = aq_hw_fw_downld_dwords(hw, efuse_shadow_addr + (40 * 4), - mac_addr, ARRAY_SIZE(mac_addr)); + mac_addr, nitems(mac_addr)); if (err != 0) { mac_addr[0] = 0; mac_addr[1] = 0; @@ -292,7 +292,7 @@ fw1x_get_mac_addr(struct aq_hw* hw, uint8_t* mac) } int -fw1x_get_stats(struct aq_hw* hw, struct aq_hw_stats_s* stats) +fw1x_get_stats(struct aq_hw* hw, struct aq_hw_stats* stats) { int err = 0; @@ -311,7 +311,7 @@ fw1x_get_stats(struct aq_hw* hw, struct aq_hw_stats_s* stats) return (err); } -struct aq_firmware_ops aq_fw1x_ops = +const struct aq_firmware_ops aq_fw1x_ops = { .reset = fw1x_reset, diff --git a/sys/dev/aq/aq_fw2x.c b/sys/dev/aq/aq_fw2x.c index 0a6d433a48fc..04935e9368d4 100644 --- a/sys/dev/aq/aq_fw2x.c +++ b/sys/dev/aq/aq_fw2x.c @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$"); #include "aq_dbg.h" -typedef enum { +enum fw2x_caps_lo { CAPS_LO_10BASET_HD = 0x00, CAPS_LO_10BASET_FD, CAPS_LO_100BASETX_HD, @@ -64,9 +64,9 @@ typedef enum { CAPS_LO_2P5GBASET_FD, CAPS_LO_5GBASET_FD, CAPS_LO_10GBASET_FD, -} fw2x_caps_lo; +}; -typedef enum { +enum fw2x_caps_hi { CAPS_HI_RESERVED1 = 0x00, CAPS_HI_10BASET_EEE, CAPS_HI_RESERVED2, @@ -99,19 +99,19 @@ typedef enum { CAPS_HI_WOL_TIMER, CAPS_HI_STATISTICS, CAPS_HI_TRANSACTION_ID, -} fw2x_caps_hi; +}; -typedef enum aq_fw2x_rate +enum aq_fw2x_rate { FW2X_RATE_100M = 0x20, FW2X_RATE_1G = 0x100, FW2X_RATE_2G5 = 0x200, FW2X_RATE_5G = 0x400, FW2X_RATE_10G = 0x800, -} aq_fw2x_rate; +}; -typedef struct fw2x_msm_statistics +struct fw2x_msm_statistics { uint32_t uprc; uint32_t mprc; @@ -129,36 +129,36 @@ typedef struct fw2x_msm_statistics uint32_t ubtc; uint32_t ptc; uint32_t prc; -} fw2x_msm_statistics; +}; -typedef struct fw2x_phy_cable_diag_data +struct fw2x_phy_cable_diag_data { uint32_t lane_data[4]; -} fw2x_phy_cable_diag_data; +}; -typedef struct fw2x_capabilities { +struct fw2x_capabilities { uint32_t caps_lo; uint32_t caps_hi; -} fw2x_capabilities; +}; -typedef struct fw2x_mailbox // struct fwHostInterface +struct fw2x_mailbox // struct fwHostInterface { uint32_t version; uint32_t transaction_id; int32_t error; - fw2x_msm_statistics msm; // msmStatistics_t msm; + struct fw2x_msm_statistics msm; // msmStatistics_t msm; uint16_t phy_h_bit; uint16_t phy_fault_code; int16_t phy_temperature; uint8_t cable_len; uint8_t reserved1; - fw2x_phy_cable_diag_data diag_data; + struct fw2x_phy_cable_diag_data diag_data; uint32_t reserved[8]; - fw2x_capabilities caps; + struct fw2x_capabilities caps; /* ... */ -} fw2x_mailbox; +}; // EEE caps @@ -195,13 +195,13 @@ typedef struct fw2x_mailbox // struct fwHostInterface // Firmware v2-3.x specific functions. int fw2x_reset(struct aq_hw* hw); -int fw2x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e mode, - aq_fw_link_speed_t speed); -int fw2x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e* mode, - aq_fw_link_speed_t* speed, aq_fw_link_fc_t* fc); +int fw2x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state mode, + enum aq_fw_link_speed speed); +int fw2x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state* mode, + enum aq_fw_link_speed* speed, enum aq_fw_link_fc* fc); int fw2x_get_mac_addr(struct aq_hw* hw, uint8_t* mac); -int fw2x_get_stats(struct aq_hw* hw, struct aq_hw_stats_s* stats); +int fw2x_get_stats(struct aq_hw* hw, struct aq_hw_stats* stats); static uint64_t @@ -242,10 +242,10 @@ set_mpi_ctrl_(struct aq_hw* hw, uint64_t value) int fw2x_reset(struct aq_hw* hw) { - fw2x_capabilities caps = {0}; + struct fw2x_capabilities caps = {0}; AQ_DBG_ENTER(); int err = aq_hw_fw_downld_dwords(hw, - hw->mbox_addr + offsetof(fw2x_mailbox, caps), + hw->mbox_addr + offsetof(struct fw2x_mailbox, caps), (uint32_t*)&caps, sizeof caps/sizeof(uint32_t)); if (err == 0) { hw->fw_caps = caps.caps_lo | ((uint64_t)caps.caps_hi << 32); @@ -262,7 +262,7 @@ fw2x_reset(struct aq_hw* hw) } -static aq_fw2x_rate +static enum aq_fw2x_rate link_speed_mask_to_fw2x_(uint32_t speed) { uint32_t rate = 0; @@ -284,13 +284,13 @@ link_speed_mask_to_fw2x_(uint32_t speed) rate |= FW2X_RATE_100M; AQ_DBG_EXIT(rate); - return ((aq_fw2x_rate)rate); + return ((enum aq_fw2x_rate)rate); } int -fw2x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e mode, - aq_fw_link_speed_t speed) +fw2x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state mode, + enum aq_fw_link_speed speed) { uint64_t mpi_ctrl = get_mpi_ctrl_(hw); @@ -326,8 +326,8 @@ fw2x_set_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e mode, } int -fw2x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e* mode, - aq_fw_link_speed_t* link_speed, aq_fw_link_fc_t* fc) +fw2x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state* mode, + enum aq_fw_link_speed* link_speed, enum aq_fw_link_fc* fc) { uint64_t mpi_state = get_mpi_state_(hw); uint32_t rates = mpi_state & FW2X_RATE_MASK; @@ -342,7 +342,7 @@ fw2x_get_mode(struct aq_hw* hw, enum aq_hw_fw_mpi_state_e* mode, *mode = MPI_DEINIT; } - aq_fw_link_speed_t speed = aq_fw_none; + enum aq_fw_link_speed speed = aq_fw_none; if (rates & FW2X_RATE_10G) speed = aq_fw_10G; @@ -382,7 +382,7 @@ fw2x_get_mac_addr(struct aq_hw* hw, uint8_t* mac) } err = aq_hw_fw_downld_dwords(hw, efuse_shadow_addr + (40 * 4), mac_addr, - ARRAY_SIZE(mac_addr)); + nitems(mac_addr)); if (err != 0) { mac_addr[0] = 0; mac_addr[1] = 0; @@ -400,8 +400,8 @@ fw2x_get_mac_addr(struct aq_hw* hw, uint8_t* mac) } static inline void -fw2x_stats_to_fw_stats_(struct aq_hw_stats_s* dst, - const fw2x_msm_statistics* src) +fw2x_stats_to_fw_stats_(struct aq_hw_stats* dst, + const struct fw2x_msm_statistics* src) { dst->uprc = src->uprc; dst->mprc = src->mprc; @@ -454,7 +454,7 @@ toggle_mpi_ctrl_and_wait_(struct aq_hw* hw, uint64_t mask, uint32_t timeout_ms, // AQ_DBG_EXIT(true); return (true); } - msec_delay(timeout_ms); + DELAY((timeout_ms) * 1000); } trace_detail(dbg_fw, @@ -466,10 +466,10 @@ toggle_mpi_ctrl_and_wait_(struct aq_hw* hw, uint64_t mask, uint32_t timeout_ms, int -fw2x_get_stats(struct aq_hw* hw, struct aq_hw_stats_s* stats) +fw2x_get_stats(struct aq_hw* hw, struct aq_hw_stats* stats) { int err = 0; - fw2x_msm_statistics fw2x_stats = {0}; + struct fw2x_msm_statistics fw2x_stats = {0}; // AQ_DBG_ENTER(); @@ -486,7 +486,7 @@ fw2x_get_stats(struct aq_hw* hw, struct aq_hw_stats_s* stats) } err = aq_hw_fw_downld_dwords(hw, - hw->mbox_addr + offsetof(fw2x_mailbox, msm), + hw->mbox_addr + offsetof(struct fw2x_mailbox, msm), (uint32_t*)&fw2x_stats, sizeof fw2x_stats/sizeof(uint32_t)); fw2x_stats_to_fw_stats_(stats, &fw2x_stats); @@ -506,7 +506,7 @@ fw2x_led_control(struct aq_hw* hw, uint32_t onoff) AQ_DBG_ENTER(); - aq_hw_fw_version ver_expected = { .raw = FW2X_FW_MIN_VER_LED}; + struct aq_hw_fw_version ver_expected = { .raw = FW2X_FW_MIN_VER_LED}; if (aq_hw_ver_match(&ver_expected, &hw->fw_version)) AQ_WRITE_REG(hw, FW2X_MPI_LED_ADDR, (onoff) ? ((FW2X_LED_BLINK) | (FW2X_LED_BLINK << 2) | (FW2X_LED_BLINK << 4)): @@ -516,7 +516,7 @@ fw2x_led_control(struct aq_hw* hw, uint32_t onoff) return (err); } -struct aq_firmware_ops aq_fw2x_ops = +const struct aq_firmware_ops aq_fw2x_ops = { .reset = fw2x_reset, diff --git a/sys/dev/aq/aq_hw.c b/sys/dev/aq/aq_hw.c index 882fdf1807f2..da07c876b959 100644 --- a/sys/dev/aq/aq_hw.c +++ b/sys/dev/aq/aq_hw.c @@ -37,7 +37,6 @@ #include <sys/endian.h> #include <sys/socket.h> #include <machine/cpu.h> -#include <net/if.h> #include "aq_hw.h" #include "aq_dbg.h" @@ -133,8 +132,8 @@ err_exit: } int -aq_hw_ver_match(const aq_hw_fw_version* ver_expected, - const aq_hw_fw_version* ver_actual) +aq_hw_ver_match(const struct aq_hw_fw_version* ver_expected, + const struct aq_hw_fw_version* ver_actual) { AQ_DBG_ENTER(); @@ -155,14 +154,14 @@ aq_hw_init_ucp(struct aq_hw *hw) err = aq_fw_reset(hw); if (err != 0) { - aq_log_error("aq_hw_init_ucp(): F/W reset failed, err %d", err); + device_printf(hw->dev, "aq_hw_init_ucp(): F/W reset failed, err %d\n", err); return (err); } aq_hw_chip_features_init(hw, &hw->chip_features); err = aq_fw_ops_init(hw); if (err != 0) { - aq_log_error("could not initialize F/W ops, err %d", err); + device_printf(hw->dev, "could not initialize F/W ops, err %d\n", err); return (err); } @@ -183,9 +182,9 @@ aq_hw_init_ucp(struct aq_hw *hw) /* check 10 times by 1ms */ err = AQ_HW_WAIT_FOR((hw->mbox_addr = AQ_READ_REG(hw, 0x360)) != 0, 400U, 20); - aq_hw_fw_version ver_expected = { .raw = AQ_CFG_FW_MIN_VER_EXPECTED }; + struct aq_hw_fw_version ver_expected = { .raw = AQ_CFG_FW_MIN_VER_EXPECTED }; if (!aq_hw_ver_match(&ver_expected, &hw->fw_version)) - aq_log_error("atlantic: aq_hw_init_ucp(), wrong FW version: expected:%x actual:%x", + device_printf(hw->dev, "aq_hw_init_ucp(), wrong FW version: expected:%x actual:%x\n", AQ_CFG_FW_MIN_VER_EXPECTED, hw->fw_version.raw); AQ_DBG_EXIT(err); @@ -210,15 +209,10 @@ err_exit: int aq_hw_mpi_read_stats(struct aq_hw *hw, struct aq_hw_fw_mbox *pmbox) { - int err = 0; + int err; // AQ_DBG_ENTER(); - if (hw->fw_ops && hw->fw_ops->get_stats) { - err = hw->fw_ops->get_stats(hw, &pmbox->stats); - } else { - err = ENOTSUP; - aq_log_error("get_stats() not supported by F/W"); - } + err = hw->fw_ops->get_stats(hw, &pmbox->stats); if (err == 0) { pmbox->stats.dpc = reg_rx_dma_stat_counter7get(hw); @@ -230,16 +224,12 @@ aq_hw_mpi_read_stats(struct aq_hw *hw, struct aq_hw_fw_mbox *pmbox) } static int -aq_hw_mpi_set(struct aq_hw *hw, enum aq_hw_fw_mpi_state_e state, uint32_t speed) +aq_hw_mpi_set(struct aq_hw *hw, enum aq_hw_fw_mpi_state state, uint32_t speed) { - int err = ENOTSUP; + int err; AQ_DBG_ENTERA("speed %d", speed); - if (hw->fw_ops && hw->fw_ops->set_mode) { - err = hw->fw_ops->set_mode(hw, state, speed); - } else { - aq_log_error("set_mode() not supported by F/W"); - } + err = hw->fw_ops->set_mode(hw, state, speed); AQ_DBG_EXIT(err); return (err); @@ -258,20 +248,14 @@ aq_hw_get_link_state(struct aq_hw *hw, uint32_t *link_speed, struct aq_hw_fc_inf // AQ_DBG_ENTER(); - enum aq_hw_fw_mpi_state_e mode; - aq_fw_link_speed_t speed = aq_fw_none; - aq_fw_link_fc_t fc; + enum aq_hw_fw_mpi_state mode; + enum aq_fw_link_speed speed = aq_fw_none; + enum aq_fw_link_fc fc; - if (hw->fw_ops && hw->fw_ops->get_mode) { - err = hw->fw_ops->get_mode(hw, &mode, &speed, &fc); - } else { - aq_log_error("get_mode() not supported by F/W"); - AQ_DBG_EXIT(ENOTSUP); - return (ENOTSUP); - } + err = hw->fw_ops->get_mode(hw, &mode, &speed, &fc); if (err != 0) { - aq_log_error("get_mode() failed, err %d", err); + device_printf(hw->dev, "get_mode() failed, err %d\n", err); AQ_DBG_EXIT(err); return (err); } @@ -310,11 +294,10 @@ aq_hw_get_link_state(struct aq_hw *hw, uint32_t *link_speed, struct aq_hw_fc_inf int aq_hw_get_mac_permanent(struct aq_hw *hw, uint8_t *mac) { - int err = ENOTSUP; + int err; AQ_DBG_ENTER(); - if (hw->fw_ops && hw->fw_ops->get_mac_addr) - err = hw->fw_ops->get_mac_addr(hw, mac); + err = hw->fw_ops->get_mac_addr(hw, mac); /* Couldn't get MAC address from HW. Use auto-generated one. */ if ((mac[0] & 1) || ((mac[0] | mac[1] | mac[2]) == 0)) { @@ -322,8 +305,9 @@ aq_hw_get_mac_permanent(struct aq_hw *hw, uint8_t *mac) uint32_t h = 0; uint32_t l = 0; - printf("atlantic: HW MAC address %x:%x:%x:%x:%x:%x is multicast or empty MAC", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - printf("atlantic: Use random MAC address"); + device_printf(hw->dev, + "invalid (multicast/empty) HW MAC %6D; using random\n", + mac, ":"); rnd = arc4random(); @@ -387,12 +371,11 @@ aq_hw_reset(struct aq_hw *hw) /* check 10 times by 1ms */ err = AQ_HW_WAIT_FOR(itr_res_irq_get(hw) == 0, 1000, 10); if (err != 0) { - printf("atlantic: IRQ reset failed: %d", err); + device_printf(hw->dev, "IRQ reset failed: %d\n", err); goto err_exit; } - if (hw->fw_ops && hw->fw_ops->reset) - hw->fw_ops->reset(hw); + hw->fw_ops->reset(hw); err = aq_hw_err_from_flags(hw); @@ -462,7 +445,7 @@ aq_hw_qos_set(struct aq_hw *hw) static int aq_hw_offload_set(struct aq_hw *hw) { - int err = 0; + int err; AQ_DBG_ENTER(); /* TX checksums offloads*/ @@ -546,7 +529,7 @@ aq_hw_init_tx_path(struct aq_hw *hw) static int aq_hw_init_rx_path(struct aq_hw *hw) { - //struct aq_nic_cfg_s *cfg = hw->aq_nic_cfg; + //struct aq_nic_cfg *cfg = hw->aq_nic_cfg; unsigned int control_reg_val = 0U; int i; int err; @@ -766,63 +749,63 @@ aq_hw_interrupt_moderation_set(struct aq_hw *hw) * for the particular vlan ids. * Note: use this function under vlan promisc mode not to lost the traffic * - * @param aq_hw_s + * @param aq_hw * @param aq_rx_filter_vlan VLAN filter configuration * @return 0 - OK, <0 - error */ int -hw_atl_b0_hw_vlan_set(struct aq_hw_s *self, struct aq_rx_filter_vlan *aq_vlans) +hw_atl_b0_hw_vlan_set(struct aq_hw *hw, struct aq_rx_filter_vlan *aq_vlans) { int i; for (i = 0; i < AQ_HW_VLAN_MAX_FILTERS; i++) { - hw_atl_rpf_vlan_flr_en_set(self, 0U, i); - hw_atl_rpf_vlan_rxq_en_flr_set(self, 0U, i); + hw_atl_rpf_vlan_flr_en_set(hw, 0U, i); + hw_atl_rpf_vlan_rxq_en_flr_set(hw, 0U, i); if (aq_vlans[i].enable) { - hw_atl_rpf_vlan_id_flr_set(self, + hw_atl_rpf_vlan_id_flr_set(hw, aq_vlans[i].vlan_id, i); - hw_atl_rpf_vlan_flr_act_set(self, 1U, i); - hw_atl_rpf_vlan_flr_en_set(self, 1U, i); + hw_atl_rpf_vlan_flr_act_set(hw, 1U, i); + hw_atl_rpf_vlan_flr_en_set(hw, 1U, i); if (aq_vlans[i].queue != 0xFF) { - hw_atl_rpf_vlan_rxq_flr_set(self, + hw_atl_rpf_vlan_rxq_flr_set(hw, aq_vlans[i].queue, i); - hw_atl_rpf_vlan_rxq_en_flr_set(self, 1U, i); + hw_atl_rpf_vlan_rxq_en_flr_set(hw, 1U, i); } } } - return aq_hw_err_from_flags(self); + return aq_hw_err_from_flags(hw); } int -hw_atl_b0_hw_vlan_promisc_set(struct aq_hw_s *self, bool promisc) +hw_atl_b0_hw_vlan_promisc_set(struct aq_hw *hw, bool promisc) { - hw_atl_rpf_vlan_prom_mode_en_set(self, promisc); - return aq_hw_err_from_flags(self); + hw_atl_rpf_vlan_prom_mode_en_set(hw, promisc); + return aq_hw_err_from_flags(hw); } void -aq_hw_set_promisc(struct aq_hw_s *self, bool l2_promisc, bool vlan_promisc, +aq_hw_set_promisc(struct aq_hw *hw, bool l2_promisc, bool vlan_promisc, bool mc_promisc) { AQ_DBG_ENTERA("promisc %d, vlan_promisc %d, allmulti %d", l2_promisc, vlan_promisc, mc_promisc); - rpfl2promiscuous_mode_en_set(self, l2_promisc); + rpfl2promiscuous_mode_en_set(hw, l2_promisc); - hw_atl_b0_hw_vlan_promisc_set(self, l2_promisc | vlan_promisc); + hw_atl_b0_hw_vlan_promisc_set(hw, l2_promisc | vlan_promisc); - rpfl2_accept_all_mc_packets_set(self, mc_promisc); - rpfl2multicast_flr_en_set(self, mc_promisc, 0); + rpfl2_accept_all_mc_packets_set(hw, mc_promisc); + rpfl2multicast_flr_en_set(hw, mc_promisc, 0); AQ_DBG_EXIT(0); } int -aq_hw_rss_hash_set(struct aq_hw_s *self, +aq_hw_rss_hash_set(struct aq_hw *hw, uint8_t rss_key[HW_ATL_RSS_HASHKEY_SIZE]) { uint32_t rss_key_dw[HW_ATL_RSS_HASHKEY_SIZE / 4]; @@ -836,16 +819,16 @@ aq_hw_rss_hash_set(struct aq_hw_s *self, for (i = 10, addr = 0U; i--; ++addr) { uint32_t key_data = bswap32(rss_key_dw[i]); - rpf_rss_key_wr_data_set(self, key_data); - rpf_rss_key_addr_set(self, addr); - rpf_rss_key_wr_en_set(self, 1U); - err = AQ_HW_WAIT_FOR(rpf_rss_key_wr_en_get(self) == 0, + rpf_rss_key_wr_data_set(hw, key_data); + rpf_rss_key_addr_set(hw, addr); + rpf_rss_key_wr_en_set(hw, 1U); + err = AQ_HW_WAIT_FOR(rpf_rss_key_wr_en_get(hw) == 0, 1000U, 10U); if (err != 0) goto err_exit; } - err = aq_hw_err_from_flags(self); + err = aq_hw_err_from_flags(hw); err_exit: AQ_DBG_EXIT(err); @@ -853,7 +836,7 @@ err_exit: } int -aq_hw_rss_hash_get(struct aq_hw_s *self, +aq_hw_rss_hash_get(struct aq_hw *hw, uint8_t rss_key[HW_ATL_RSS_HASHKEY_SIZE]) { uint32_t rss_key_dw[HW_ATL_RSS_HASHKEY_SIZE / 4]; @@ -864,19 +847,19 @@ aq_hw_rss_hash_get(struct aq_hw_s *self, AQ_DBG_ENTER(); for (i = 10, addr = 0U; i--; ++addr) { - rpf_rss_key_addr_set(self, addr); - rss_key_dw[i] = bswap32(rpf_rss_key_rd_data_get(self)); + rpf_rss_key_addr_set(hw, addr); + rss_key_dw[i] = bswap32(rpf_rss_key_rd_data_get(hw)); } memcpy(rss_key, rss_key_dw, HW_ATL_RSS_HASHKEY_SIZE); - err = aq_hw_err_from_flags(self); + err = aq_hw_err_from_flags(hw); AQ_DBG_EXIT(err); return (err); } int -aq_hw_rss_set(struct aq_hw_s *self, +aq_hw_rss_set(struct aq_hw *hw, uint8_t rss_table[HW_ATL_RSS_INDIRECTION_TABLE_MAX]) { uint16_t bitary[(HW_ATL_RSS_INDIRECTION_TABLE_MAX * @@ -895,28 +878,28 @@ aq_hw_rss_set(struct aq_hw_s *self, bitary[word] |= (uint16_t)field; if (shift + HW_ATL_RSS_INDIRECTION_ENTRY_BITS > 16U && - word + 1U < ARRAY_SIZE(bitary)) + word + 1U < nitems(bitary)) bitary[word + 1U] |= (uint16_t)(field >> 16); } - for (i = ARRAY_SIZE(bitary); i--;) { - rpf_rss_redir_tbl_wr_data_set(self, bitary[i]); - rpf_rss_redir_tbl_addr_set(self, i); - rpf_rss_redir_wr_en_set(self, 1U); - err = AQ_HW_WAIT_FOR(rpf_rss_redir_wr_en_get(self) == 0, + for (i = nitems(bitary); i--;) { + rpf_rss_redir_tbl_wr_data_set(hw, bitary[i]); + rpf_rss_redir_tbl_addr_set(hw, i); + rpf_rss_redir_wr_en_set(hw, 1U); + err = AQ_HW_WAIT_FOR(rpf_rss_redir_wr_en_get(hw) == 0, 1000U, 10U); if (err != 0) goto err_exit; } - err = aq_hw_err_from_flags(self); + err = aq_hw_err_from_flags(hw); err_exit: return (err); } int -aq_hw_udp_rss_enable(struct aq_hw_s *self, bool enable) +aq_hw_udp_rss_enable(struct aq_hw *hw, bool enable) { int err = 0; if (!enable) { @@ -925,17 +908,17 @@ aq_hw_udp_rss_enable(struct aq_hw_s *self, bool enable) * HW does not track RSS stream for fragmenged UDP, * 0x5040 control reg does not work. */ - hw_atl_rpf_l3_l4_enf_set(self, true, 0); - hw_atl_rpf_l4_protf_en_set(self, true, 0); - hw_atl_rpf_l3_l4_rxqf_en_set(self, true, 0); - hw_atl_rpf_l3_l4_actf_set(self, L2_FILTER_ACTION_HOST, 0); - hw_atl_rpf_l3_l4_rxqf_set(self, 0, 0); - hw_atl_rpf_l4_protf_set(self, HW_ATL_RX_UDP, 0); + hw_atl_rpf_l3_l4_enf_set(hw, true, 0); + hw_atl_rpf_l4_protf_en_set(hw, true, 0); + hw_atl_rpf_l3_l4_rxqf_en_set(hw, true, 0); + hw_atl_rpf_l3_l4_actf_set(hw, L2_FILTER_ACTION_HOST, 0); + hw_atl_rpf_l3_l4_rxqf_set(hw, 0, 0); + hw_atl_rpf_l4_protf_set(hw, HW_ATL_RX_UDP, 0); } else { - hw_atl_rpf_l3_l4_enf_set(self, false, 0); + hw_atl_rpf_l3_l4_enf_set(hw, false, 0); } - err = aq_hw_err_from_flags(self); + err = aq_hw_err_from_flags(hw); return (err); } diff --git a/sys/dev/aq/aq_hw.h b/sys/dev/aq/aq_hw.h index f954f6055a4c..339c7cb7bea0 100644 --- a/sys/dev/aq/aq_hw.h +++ b/sys/dev/aq/aq_hw.h @@ -37,6 +37,7 @@ #include <sys/types.h> #include <sys/cdefs.h> +#include <sys/bus.h> #include <machine/atomic.h> #include <machine/cpufunc.h> #include <machine/bus.h> @@ -78,10 +79,6 @@ extern uint32_t aq_hw_read_reg(struct aq_hw *hw, uint32_t reg); /* Statistics */ struct aq_hw_stats { - uint64_t crcerrs; -}; - -struct aq_hw_stats_s { uint32_t uprc; uint32_t mprc; uint32_t bprc; @@ -100,7 +97,7 @@ struct aq_hw_stats_s { uint32_t prc; uint32_t dpc; uint32_t cprc; -} __attribute__((__packed__)); +} __packed; union ip_addr { struct { @@ -110,16 +107,16 @@ union ip_addr { uint8_t padding[12]; uint8_t addr[4]; } v4; -} __attribute__((__packed__)); +} __packed; struct aq_hw_fw_mbox { uint32_t version; uint32_t transaction_id; int error; - struct aq_hw_stats_s stats; -} __attribute__((__packed__)); + struct aq_hw_stats stats; +} __packed; -typedef struct aq_hw_fw_version { +struct aq_hw_fw_version { union { struct { uint16_t build_number; @@ -128,7 +125,7 @@ typedef struct aq_hw_fw_version { }; uint32_t raw; }; -} aq_hw_fw_version; +}; enum aq_hw_irq_type { aq_irq_invalid = 0, @@ -144,6 +141,7 @@ struct aq_hw_fc_info { struct aq_hw { void *aq_dev; + device_t dev; bus_space_tag_t hw_tag; bus_space_handle_t hw_handle; uint32_t regs_size; @@ -165,7 +163,7 @@ struct aq_hw { int itr; /* Firmware-related stuff. */ - aq_hw_fw_version fw_version; + struct aq_hw_fw_version fw_version; const struct aq_firmware_ops* fw_ops; bool rbl_enabled; bool fast_start_enabled; @@ -183,8 +181,6 @@ struct aq_hw { uint32_t tx_rings_count; }; -#define aq_hw_s aq_hw - #define AQ_HW_MAC 0U #define AQ_HW_MAC_MIN 1U #define AQ_HW_MAC_MAX 33U @@ -320,7 +316,7 @@ enum hw_atl_rx_ctrl_registers_l3l4 { #define HW_ATL_GET_REG_LOCATION_FL3L4(location) \ ((location) - AQ_RX_FIRST_LOC_FL3L4) -enum aq_hw_fw_mpi_state_e { +enum aq_hw_fw_mpi_state { MPI_DEINIT = 0, MPI_RESET = 1, MPI_INIT = 2, @@ -355,24 +351,24 @@ int aq_hw_get_fw_version(struct aq_hw *hw, uint32_t *fw_version); int aq_hw_deinit(struct aq_hw *hw); -int aq_hw_ver_match(const aq_hw_fw_version* ver_expected, - const aq_hw_fw_version* ver_actual); +int aq_hw_ver_match(const struct aq_hw_fw_version* ver_expected, + const struct aq_hw_fw_version* ver_actual); -void aq_hw_set_promisc(struct aq_hw_s *self, bool l2_promisc, bool vlan_promisc, +void aq_hw_set_promisc(struct aq_hw *hw, bool l2_promisc, bool vlan_promisc, bool mc_promisc); int aq_hw_set_power(struct aq_hw *hw, unsigned int power_state); int aq_hw_err_from_flags(struct aq_hw *hw); -int hw_atl_b0_hw_vlan_promisc_set(struct aq_hw_s *self, bool promisc); +int hw_atl_b0_hw_vlan_promisc_set(struct aq_hw *hw, bool promisc); -int hw_atl_b0_hw_vlan_set(struct aq_hw_s *self, +int hw_atl_b0_hw_vlan_set(struct aq_hw *hw, struct aq_rx_filter_vlan *aq_vlans); -int aq_hw_rss_hash_set(struct aq_hw_s *self, uint8_t rss_key[HW_ATL_RSS_HASHKEY_SIZE]); -int aq_hw_rss_hash_get(struct aq_hw_s *self, uint8_t rss_key[HW_ATL_RSS_HASHKEY_SIZE]); -int aq_hw_rss_set(struct aq_hw_s *self, uint8_t rss_table[HW_ATL_RSS_INDIRECTION_TABLE_MAX]); -int aq_hw_udp_rss_enable(struct aq_hw_s *self, bool enable); +int aq_hw_rss_hash_set(struct aq_hw *hw, uint8_t rss_key[HW_ATL_RSS_HASHKEY_SIZE]); +int aq_hw_rss_hash_get(struct aq_hw *hw, uint8_t rss_key[HW_ATL_RSS_HASHKEY_SIZE]); +int aq_hw_rss_set(struct aq_hw *hw, uint8_t rss_table[HW_ATL_RSS_INDIRECTION_TABLE_MAX]); +int aq_hw_udp_rss_enable(struct aq_hw *hw, bool enable); #endif // _AQ_HW_H_ diff --git a/sys/dev/aq/aq_hw_llh.c b/sys/dev/aq/aq_hw_llh.c index 43f966becf50..eb053a4bdce6 100644 --- a/sys/dev/aq/aq_hw_llh.c +++ b/sys/dev/aq/aq_hw_llh.c @@ -1000,7 +1000,7 @@ rpf_tpo_to_rpf_sys_lbk_set(struct aq_hw *aq_hw, uint32_t tpo_to_rpf_sys_lbk) void -hw_atl_rpf_vlan_inner_etht_set(struct aq_hw_s *aq_hw, uint32_t vlan_inner_etht) +hw_atl_rpf_vlan_inner_etht_set(struct aq_hw *aq_hw, uint32_t vlan_inner_etht) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_INNER_TPID_ADR, HW_ATL_RPF_VL_INNER_TPID_MSK, @@ -1009,7 +1009,7 @@ hw_atl_rpf_vlan_inner_etht_set(struct aq_hw_s *aq_hw, uint32_t vlan_inner_etht) } void -hw_atl_rpf_vlan_outer_etht_set(struct aq_hw_s *aq_hw, uint32_t vlan_outer_etht) +hw_atl_rpf_vlan_outer_etht_set(struct aq_hw *aq_hw, uint32_t vlan_outer_etht) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_OUTER_TPID_ADR, HW_ATL_RPF_VL_OUTER_TPID_MSK, @@ -1018,7 +1018,7 @@ hw_atl_rpf_vlan_outer_etht_set(struct aq_hw_s *aq_hw, uint32_t vlan_outer_etht) } void -hw_atl_rpf_vlan_prom_mode_en_set(struct aq_hw_s *aq_hw, +hw_atl_rpf_vlan_prom_mode_en_set(struct aq_hw *aq_hw, uint32_t vlan_prom_mode_en) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_PROMIS_MODE_ADR, @@ -1028,7 +1028,7 @@ hw_atl_rpf_vlan_prom_mode_en_set(struct aq_hw_s *aq_hw, } void -hw_atl_rpf_vlan_accept_untagged_packets_set(struct aq_hw_s *aq_hw, +hw_atl_rpf_vlan_accept_untagged_packets_set(struct aq_hw *aq_hw, uint32_t vlan_acc_untagged_packets) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_ACCEPT_UNTAGGED_MODE_ADR, @@ -1038,7 +1038,7 @@ hw_atl_rpf_vlan_accept_untagged_packets_set(struct aq_hw_s *aq_hw, } void -hw_atl_rpf_vlan_untagged_act_set(struct aq_hw_s *aq_hw, +hw_atl_rpf_vlan_untagged_act_set(struct aq_hw *aq_hw, uint32_t vlan_untagged_act) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_UNTAGGED_ACT_ADR, @@ -1048,7 +1048,7 @@ hw_atl_rpf_vlan_untagged_act_set(struct aq_hw_s *aq_hw, } void -hw_atl_rpf_vlan_flr_en_set(struct aq_hw_s *aq_hw, uint32_t vlan_flr_en, +hw_atl_rpf_vlan_flr_en_set(struct aq_hw *aq_hw, uint32_t vlan_flr_en, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_EN_F_ADR(filter), @@ -1058,7 +1058,7 @@ hw_atl_rpf_vlan_flr_en_set(struct aq_hw_s *aq_hw, uint32_t vlan_flr_en, } void -hw_atl_rpf_vlan_flr_act_set(struct aq_hw_s *aq_hw, uint32_t vlan_flr_act, +hw_atl_rpf_vlan_flr_act_set(struct aq_hw *aq_hw, uint32_t vlan_flr_act, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_ACT_F_ADR(filter), @@ -1068,7 +1068,7 @@ hw_atl_rpf_vlan_flr_act_set(struct aq_hw_s *aq_hw, uint32_t vlan_flr_act, } void -hw_atl_rpf_vlan_id_flr_set(struct aq_hw_s *aq_hw, uint32_t vlan_id_flr, +hw_atl_rpf_vlan_id_flr_set(struct aq_hw *aq_hw, uint32_t vlan_id_flr, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_ID_F_ADR(filter), @@ -1078,7 +1078,7 @@ hw_atl_rpf_vlan_id_flr_set(struct aq_hw_s *aq_hw, uint32_t vlan_id_flr, } void -hw_atl_rpf_vlan_rxq_en_flr_set(struct aq_hw_s *aq_hw, uint32_t vlan_rxq_en, +hw_atl_rpf_vlan_rxq_en_flr_set(struct aq_hw *aq_hw, uint32_t vlan_rxq_en, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_RXQ_EN_F_ADR(filter), @@ -1088,7 +1088,7 @@ hw_atl_rpf_vlan_rxq_en_flr_set(struct aq_hw_s *aq_hw, uint32_t vlan_rxq_en, } void -hw_atl_rpf_vlan_rxq_flr_set(struct aq_hw_s *aq_hw, uint32_t vlan_rxq, +hw_atl_rpf_vlan_rxq_flr_set(struct aq_hw *aq_hw, uint32_t vlan_rxq, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_VL_RXQ_F_ADR(filter), @@ -1098,7 +1098,7 @@ hw_atl_rpf_vlan_rxq_flr_set(struct aq_hw_s *aq_hw, uint32_t vlan_rxq, }; void -hw_atl_rpf_etht_flr_en_set(struct aq_hw_s *aq_hw, uint32_t etht_flr_en, +hw_atl_rpf_etht_flr_en_set(struct aq_hw *aq_hw, uint32_t etht_flr_en, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_ET_ENF_ADR(filter), @@ -1107,7 +1107,7 @@ hw_atl_rpf_etht_flr_en_set(struct aq_hw_s *aq_hw, uint32_t etht_flr_en, } void -hw_atl_rpf_etht_user_priority_en_set(struct aq_hw_s *aq_hw, +hw_atl_rpf_etht_user_priority_en_set(struct aq_hw *aq_hw, uint32_t etht_user_priority_en, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_ET_UPFEN_ADR(filter), @@ -1116,7 +1116,7 @@ hw_atl_rpf_etht_user_priority_en_set(struct aq_hw_s *aq_hw, } void -hw_atl_rpf_etht_rx_queue_en_set(struct aq_hw_s *aq_hw, +hw_atl_rpf_etht_rx_queue_en_set(struct aq_hw *aq_hw, uint32_t etht_rx_queue_en, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_ET_RXQFEN_ADR(filter), @@ -1126,7 +1126,7 @@ hw_atl_rpf_etht_rx_queue_en_set(struct aq_hw_s *aq_hw, } void -hw_atl_rpf_etht_user_priority_set(struct aq_hw_s *aq_hw, +hw_atl_rpf_etht_user_priority_set(struct aq_hw *aq_hw, uint32_t etht_user_priority, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_ET_UPF_ADR(filter), @@ -1135,7 +1135,7 @@ hw_atl_rpf_etht_user_priority_set(struct aq_hw_s *aq_hw, } void -hw_atl_rpf_etht_rx_queue_set(struct aq_hw_s *aq_hw, uint32_t etht_rx_queue, +hw_atl_rpf_etht_rx_queue_set(struct aq_hw *aq_hw, uint32_t etht_rx_queue, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_ET_RXQF_ADR(filter), @@ -1144,7 +1144,7 @@ hw_atl_rpf_etht_rx_queue_set(struct aq_hw_s *aq_hw, uint32_t etht_rx_queue, } void -hw_atl_rpf_etht_mgt_queue_set(struct aq_hw_s *aq_hw, uint32_t etht_mgt_queue, +hw_atl_rpf_etht_mgt_queue_set(struct aq_hw *aq_hw, uint32_t etht_mgt_queue, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_ET_MNG_RXQF_ADR(filter), @@ -1154,7 +1154,7 @@ hw_atl_rpf_etht_mgt_queue_set(struct aq_hw_s *aq_hw, uint32_t etht_mgt_queue, } void -hw_atl_rpf_etht_flr_act_set(struct aq_hw_s *aq_hw, uint32_t etht_flr_act, +hw_atl_rpf_etht_flr_act_set(struct aq_hw *aq_hw, uint32_t etht_flr_act, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_ET_ACTF_ADR(filter), @@ -1163,7 +1163,7 @@ hw_atl_rpf_etht_flr_act_set(struct aq_hw_s *aq_hw, uint32_t etht_flr_act, } void -hw_atl_rpf_etht_flr_set(struct aq_hw_s *aq_hw, uint32_t etht_flr, +hw_atl_rpf_etht_flr_set(struct aq_hw *aq_hw, uint32_t etht_flr, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_ET_VALF_ADR(filter), @@ -1172,7 +1172,7 @@ hw_atl_rpf_etht_flr_set(struct aq_hw_s *aq_hw, uint32_t etht_flr, } void -hw_atl_rpf_l3_l4_enf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l3_l4_enf_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_L4_ENF_ADR(filter), HW_ATL_RPF_L3_L4_ENF_MSK, @@ -1180,7 +1180,7 @@ hw_atl_rpf_l3_l4_enf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l3_v6_enf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l3_v6_enf_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_V6_ENF_ADR(filter), HW_ATL_RPF_L3_V6_ENF_MSK, @@ -1188,7 +1188,7 @@ hw_atl_rpf_l3_v6_enf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l3_saf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l3_saf_en_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_SAF_EN_ADR(filter), HW_ATL_RPF_L3_SAF_EN_MSK, @@ -1196,7 +1196,7 @@ hw_atl_rpf_l3_saf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l3_daf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l3_daf_en_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_DAF_EN_ADR(filter), HW_ATL_RPF_L3_DAF_EN_MSK, @@ -1204,7 +1204,7 @@ hw_atl_rpf_l3_daf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l4_spf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l4_spf_en_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L4_SPF_EN_ADR(filter), HW_ATL_RPF_L4_SPF_EN_MSK, @@ -1212,7 +1212,7 @@ hw_atl_rpf_l4_spf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l4_dpf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l4_dpf_en_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L4_DPF_EN_ADR(filter), HW_ATL_RPF_L4_DPF_EN_MSK, @@ -1220,7 +1220,7 @@ hw_atl_rpf_l4_dpf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l4_protf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l4_protf_en_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L4_PROTF_EN_ADR(filter), HW_ATL_RPF_L4_PROTF_EN_MSK, @@ -1228,7 +1228,7 @@ hw_atl_rpf_l4_protf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l3_arpf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l3_arpf_en_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_ARPF_EN_ADR(filter), HW_ATL_RPF_L3_ARPF_EN_MSK, @@ -1236,7 +1236,7 @@ hw_atl_rpf_l3_arpf_en_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l3_l4_rxqf_en_set(struct aq_hw_s *aq_hw, uint32_t val, +hw_atl_rpf_l3_l4_rxqf_en_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_L4_RXQF_EN_ADR(filter), @@ -1245,7 +1245,7 @@ hw_atl_rpf_l3_l4_rxqf_en_set(struct aq_hw_s *aq_hw, uint32_t val, } void -hw_atl_rpf_l3_l4_mng_rxqf_set(struct aq_hw_s *aq_hw, uint32_t val, +hw_atl_rpf_l3_l4_mng_rxqf_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_L4_MNG_RXQF_ADR(filter), @@ -1254,7 +1254,7 @@ hw_atl_rpf_l3_l4_mng_rxqf_set(struct aq_hw_s *aq_hw, uint32_t val, } void -hw_atl_rpf_l3_l4_actf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l3_l4_actf_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_L4_ACTF_ADR(filter), HW_ATL_RPF_L3_L4_ACTF_MSK, @@ -1262,7 +1262,7 @@ hw_atl_rpf_l3_l4_actf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l3_l4_rxqf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l3_l4_rxqf_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L3_L4_RXQF_ADR(filter), HW_ATL_RPF_L3_L4_RXQF_MSK, @@ -1270,7 +1270,7 @@ hw_atl_rpf_l3_l4_rxqf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l4_protf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l4_protf_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L4_PROTF_ADR(filter), HW_ATL_RPF_L4_PROTF_MSK, @@ -1278,7 +1278,7 @@ hw_atl_rpf_l4_protf_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l4_spd_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l4_spd_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L4_SPD_ADR(filter), HW_ATL_RPF_L4_SPD_MSK, @@ -1286,7 +1286,7 @@ hw_atl_rpf_l4_spd_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) } void -hw_atl_rpf_l4_dpd_set(struct aq_hw_s *aq_hw, uint32_t val, uint32_t filter) +hw_atl_rpf_l4_dpd_set(struct aq_hw *aq_hw, uint32_t val, uint32_t filter) { aq_hw_write_reg_bit(aq_hw, HW_ATL_RPF_L4_DPD_ADR(filter), HW_ATL_RPF_L4_DPD_MSK, @@ -2008,25 +2008,25 @@ mif_mcp_up_mailbox_data_get(struct aq_hw *hw) } void -hw_atl_rpfl3l4_ipv4_dest_addr_clear(struct aq_hw_s *aq_hw, uint8_t location) +hw_atl_rpfl3l4_ipv4_dest_addr_clear(struct aq_hw *aq_hw, uint8_t location) { aq_hw_write_reg(aq_hw, HW_ATL_RX_GET_ADDR_DESTA_FL3L4(location), 0U); } void -hw_atl_rpfl3l4_ipv4_src_addr_clear(struct aq_hw_s *aq_hw, uint8_t location) +hw_atl_rpfl3l4_ipv4_src_addr_clear(struct aq_hw *aq_hw, uint8_t location) { aq_hw_write_reg(aq_hw, HW_ATL_RX_GET_ADDR_SRCA_FL3L4(location), 0U); } void -hw_atl_rpfl3l4_cmd_clear(struct aq_hw_s *aq_hw, uint8_t location) +hw_atl_rpfl3l4_cmd_clear(struct aq_hw *aq_hw, uint8_t location) { aq_hw_write_reg(aq_hw, HW_ATL_RX_GET_ADDR_CTRL_FL3L4(location), 0U); } void -hw_atl_rpfl3l4_ipv6_dest_addr_clear(struct aq_hw_s *aq_hw, uint8_t location) +hw_atl_rpfl3l4_ipv6_dest_addr_clear(struct aq_hw *aq_hw, uint8_t location) { int i; @@ -2036,7 +2036,7 @@ hw_atl_rpfl3l4_ipv6_dest_addr_clear(struct aq_hw_s *aq_hw, uint8_t location) } void -hw_atl_rpfl3l4_ipv6_src_addr_clear(struct aq_hw_s *aq_hw, uint8_t location) +hw_atl_rpfl3l4_ipv6_src_addr_clear(struct aq_hw *aq_hw, uint8_t location) { int i; @@ -2046,7 +2046,7 @@ hw_atl_rpfl3l4_ipv6_src_addr_clear(struct aq_hw_s *aq_hw, uint8_t location) } void -hw_atl_rpfl3l4_ipv4_dest_addr_set(struct aq_hw_s *aq_hw, uint8_t location, +hw_atl_rpfl3l4_ipv4_dest_addr_set(struct aq_hw *aq_hw, uint8_t location, uint32_t ipv4_dest) { aq_hw_write_reg(aq_hw, HW_ATL_RX_GET_ADDR_DESTA_FL3L4(location), @@ -2054,7 +2054,7 @@ hw_atl_rpfl3l4_ipv4_dest_addr_set(struct aq_hw_s *aq_hw, uint8_t location, } void -hw_atl_rpfl3l4_ipv4_src_addr_set(struct aq_hw_s *aq_hw, uint8_t location, +hw_atl_rpfl3l4_ipv4_src_addr_set(struct aq_hw *aq_hw, uint8_t location, uint32_t ipv4_src) { aq_hw_write_reg(aq_hw, HW_ATL_RX_GET_ADDR_SRCA_FL3L4(location), @@ -2062,13 +2062,13 @@ hw_atl_rpfl3l4_ipv4_src_addr_set(struct aq_hw_s *aq_hw, uint8_t location, } void -hw_atl_rpfl3l4_cmd_set(struct aq_hw_s *aq_hw, uint8_t location, uint32_t cmd) +hw_atl_rpfl3l4_cmd_set(struct aq_hw *aq_hw, uint8_t location, uint32_t cmd) { aq_hw_write_reg(aq_hw, HW_ATL_RX_GET_ADDR_CTRL_FL3L4(location), cmd); } void -hw_atl_rpfl3l4_ipv6_src_addr_set(struct aq_hw_s *aq_hw, uint8_t location, +hw_atl_rpfl3l4_ipv6_src_addr_set(struct aq_hw *aq_hw, uint8_t location, uint32_t *ipv6_src) { int i; @@ -2079,7 +2079,7 @@ hw_atl_rpfl3l4_ipv6_src_addr_set(struct aq_hw_s *aq_hw, uint8_t location, } void -hw_atl_rpfl3l4_ipv6_dest_addr_set(struct aq_hw_s *aq_hw, uint8_t location, +hw_atl_rpfl3l4_ipv6_dest_addr_set(struct aq_hw *aq_hw, uint8_t location, uint32_t *ipv6_dest) { int i; diff --git a/sys/dev/aq/aq_irq.c b/sys/dev/aq/aq_irq.c index 9f8138868eac..efd37b359d6f 100644 --- a/sys/dev/aq/aq_irq.c +++ b/sys/dev/aq/aq_irq.c @@ -42,8 +42,6 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <net/ethernet.h> #include <net/if.h> -#include <net/if_dl.h> -#include <net/if_media.h> #include <net/if_var.h> #include <net/iflib.h> @@ -55,7 +53,7 @@ __FBSDID("$FreeBSD$"); #include "aq_hw_llh.h" int -aq_update_hw_stats(aq_dev_t *aq_dev) +aq_update_hw_stats(struct aq_dev *aq_dev) { struct aq_hw *hw = &aq_dev->hw; struct aq_hw_fw_mbox mbox; @@ -105,7 +103,7 @@ aq_update_hw_stats(aq_dev_t *aq_dev) void aq_if_update_admin_status(if_ctx_t ctx) { - aq_dev_t *aq_dev = iflib_get_softc(ctx); + struct aq_dev *aq_dev = iflib_get_softc(ctx); struct aq_hw *hw = &aq_dev->hw; uint32_t link_speed; @@ -119,15 +117,6 @@ aq_if_update_admin_status(if_ctx_t ctx) aq_dev->linkup = 1; -#if __FreeBSD__ >= 12 - /* Disable TSO if link speed < 1G */ - if (link_speed < 1000 && (iflib_get_softc_ctx(ctx)->isc_capabilities & (IFCAP_TSO4 | IFCAP_TSO6))) { - iflib_get_softc_ctx(ctx)->isc_capabilities &= ~(IFCAP_TSO4 | IFCAP_TSO6); - device_printf(aq_dev->dev, "atlantic: TSO disabled for link speed < 1G"); - }else{ - iflib_get_softc_ctx(ctx)->isc_capabilities |= (IFCAP_TSO4 | IFCAP_TSO6); - } -#endif /* turn on/off RX Pause in RPB */ rpb_rx_xoff_en_per_tc_set(hw, fc_neg.fc_rx, 0); @@ -175,7 +164,7 @@ aq_isr_rx(void *arg) int aq_linkstat_isr(void *arg) { - aq_dev_t *aq_dev = arg; + struct aq_dev *aq_dev = arg; struct aq_hw *hw = &aq_dev->hw; itr_irq_status_clearlsw_set(hw, BIT(aq_dev->msix)); diff --git a/sys/dev/aq/aq_main.c b/sys/dev/aq/aq_main.c index e159ce7e72ff..ecb7e66e5b15 100644 --- a/sys/dev/aq/aq_main.c +++ b/sys/dev/aq/aq_main.c @@ -42,15 +42,12 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/bitstring.h> #include <sys/bus.h> -#include <sys/endian.h> #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/module.h> -#include <sys/priv.h> #include <sys/rman.h> #include <sys/sbuf.h> #include <sys/socket.h> -#include <sys/sockio.h> #include <sys/sysctl.h> #include <machine/bus.h> @@ -76,12 +73,6 @@ __FBSDID("$FreeBSD$"); #include "aq_ring.h" #include "aq_dbg.h" - -#define AQ_XXX_UNIMPLEMENTED_FUNCTION do { \ - printf("atlantic: unimplemented function: %s@%s:%d\n", __func__, \ - __FILE__, __LINE__); \ -} while (0) - MALLOC_DEFINE(M_AQ, "aq", "Aquantia"); char aq_driver_version[] = AQ_VER; @@ -210,13 +201,9 @@ static driver_t aq_driver = { "aq", aq_methods, sizeof(struct aq_dev), }; -#if __FreeBSD_version >= 1400058 DRIVER_MODULE(atlantic, pci, aq_driver, 0, 0); -#else -static devclass_t aq_devclass; -DRIVER_MODULE(atlantic, pci, aq_driver, aq_devclass, 0, 0); -#endif +MODULE_VERSION(atlantic, 1); MODULE_DEPEND(atlantic, pci, 1, 1, 1); MODULE_DEPEND(atlantic, ether, 1, 1, 1); MODULE_DEPEND(atlantic, iflib, 1, 1, 1); @@ -276,10 +263,8 @@ static struct if_shared_ctx aq_sctx_init = { .isc_q_align = PAGE_SIZE, .isc_tx_maxsize = HW_ATL_B0_TSO_SIZE, .isc_tx_maxsegsize = HW_ATL_B0_MTU_JUMBO, -#if __FreeBSD__ >= 12 .isc_tso_maxsize = HW_ATL_B0_TSO_SIZE, .isc_tso_maxsegsize = HW_ATL_B0_MTU_JUMBO, -#endif .isc_rx_maxsize = HW_ATL_B0_MTU_JUMBO, .isc_rx_nsegments = 16, .isc_rx_maxsegsize = PAGE_SIZE, @@ -297,8 +282,8 @@ static struct if_shared_ctx aq_sctx_init = { .isc_ntxd_min = {HW_ATL_B0_MIN_TXD}, .isc_nrxd_max = {HW_ATL_B0_MAX_RXD}, .isc_ntxd_max = {HW_ATL_B0_MAX_TXD}, - .isc_nrxd_default = {PAGE_SIZE / sizeof(aq_txc_desc_t) * 4}, - .isc_ntxd_default = {PAGE_SIZE / sizeof(aq_txc_desc_t) * 4}, + .isc_nrxd_default = {PAGE_SIZE / sizeof(volatile union aq_txc_desc) * 4}, + .isc_ntxd_default = {PAGE_SIZE / sizeof(volatile union aq_txc_desc) * 4}, }; /* @@ -355,6 +340,7 @@ aq_if_attach_pre(if_ctx_t ctx) softc->mmio_size = rman_get_size(softc->mmio_res); softc->hw.hw_tag = softc->mmio_tag; softc->hw.hw_handle = softc->mmio_handle; + softc->hw.dev = softc->dev; hw = &softc->hw; hw->link_rate = aq_fw_speed_auto; hw->itr = -1; @@ -365,44 +351,32 @@ aq_if_attach_pre(if_ctx_t ctx) /* Look up ops and caps. */ rc = aq_hw_mpi_create(hw); if (rc != 0) { - AQ_DBG_ERROR(" %s: aq_hw_mpi_create fail err=%d", __func__, rc); + device_printf(softc->dev, + "%s: aq_hw_mpi_create failed, err=%d\n", __func__, rc); goto fail; } - if (hw->fast_start_enabled) { - if (hw->fw_ops && hw->fw_ops->reset) - hw->fw_ops->reset(hw); - } else + if (hw->fast_start_enabled) + hw->fw_ops->reset(hw); + else aq_hw_reset(&softc->hw); aq_hw_capabilities(softc); rc = aq_hw_get_mac_permanent(hw, hw->mac_addr); if (rc != 0) { - AQ_DBG_ERROR("Unable to get mac addr from hw"); + device_printf(softc->dev, "unable to get MAC address from HW\n"); goto fail; } softc->admin_ticks = 0; iflib_set_mac(ctx, hw->mac_addr); -#if __FreeBSD__ < 13 - /* since FreeBSD13 deadlock due to calling iflib_led_func() under CTX_LOCK() */ - iflib_led_create(ctx); -#endif scctx->isc_tx_csum_flags = CSUM_IP | CSUM_TCP | CSUM_UDP | CSUM_TSO; -#if __FreeBSD__ >= 12 scctx->isc_capabilities = IFCAP_RXCSUM | IFCAP_TXCSUM | IFCAP_HWCSUM | IFCAP_TSO | IFCAP_LRO | IFCAP_JUMBO_MTU | IFCAP_VLAN_HWFILTER | IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWCSUM; scctx->isc_capenable = scctx->isc_capabilities; -#else - if_t ifp; - ifp = iflib_get_ifp(ctx); - if_setcapenable(ifp, IFCAP_RXCSUM | IFCAP_TXCSUM | IFCAP_HWCSUM | - IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_VLAN_HWFILTER | IFCAP_VLAN_MTU | - IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWCSUM; -#endif - scctx->isc_tx_nsegments = 31, + scctx->isc_tx_nsegments = 31; scctx->isc_tx_tso_segments_max = 31; scctx->isc_tx_tso_size_max = HW_ATL_B0_TSO_SIZE - sizeof(struct ether_vlan_header); @@ -412,8 +386,8 @@ aq_if_attach_pre(if_ctx_t ctx) ETHER_VLAN_ENCAP_LEN; scctx->isc_txrx = &aq_txrx; - scctx->isc_txqsizes[0] = sizeof(aq_tx_desc_t) * scctx->isc_ntxd[0]; - scctx->isc_rxqsizes[0] = sizeof(aq_rx_desc_t) * scctx->isc_nrxd[0]; + scctx->isc_txqsizes[0] = sizeof(volatile struct aq_tx_desc) * scctx->isc_ntxd[0]; + scctx->isc_rxqsizes[0] = sizeof(volatile struct aq_rx_desc) * scctx->isc_nrxd[0]; scctx->isc_ntxqsets_max = HW_ATL_B0_RINGS_MAX; scctx->isc_nrxqsets_max = HW_ATL_RSS_INDIRECTION_QUEUES_MAX; @@ -476,7 +450,7 @@ aq_if_attach_post(if_ctx_t ctx) /* RSS */ arc4rand(softc->rss_key, HW_ATL_RSS_HASHKEY_SIZE, 0); uint32_t rss_qs = MIN(softc->rx_rings_count, HW_ATL_RSS_INDIRECTION_QUEUES_MAX); - for (int i = ARRAY_SIZE(softc->rss_table); i--;){ + for (int i = nitems(softc->rss_table); i--;){ softc->rss_table[i] = i % rss_qs; } exit: @@ -600,7 +574,7 @@ aq_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, device_printf(softc->dev, "atlantic: tx_ring malloc fail\n"); goto fail; } - ring->tx_descs = (aq_tx_desc_t*)vaddrs[i]; + ring->tx_descs = (volatile struct aq_tx_desc*)vaddrs[i]; ring->tx_size = softc->scctx->isc_ntxd[0]; ring->tx_descs_phys = paddrs[i]; ring->tx_head = ring->tx_tail = 0; @@ -647,23 +621,12 @@ aq_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, goto fail; } - ring->rx_descs = (aq_rx_desc_t*)vaddrs[i]; + ring->rx_descs = (volatile struct aq_rx_desc*)vaddrs[i]; ring->rx_descs_phys = paddrs[i]; ring->rx_size = softc->scctx->isc_nrxd[0]; ring->index = i; ring->dev = softc; - switch (MCLBYTES) { - case (4 * 1024): - case (8 * 1024): - case (16 * 1024): - ring->rx_max_frame_size = MCLBYTES; - break; - default: - ring->rx_max_frame_size = 2048; - break; - } - softc->rx_rings_count++; rc = aq_ring_stats_alloc(ring); @@ -755,7 +718,7 @@ aq_if_init(if_ctx_t ctx) } for (i = 0; i < softc->rx_rings_count; i++) { struct aq_ring *ring = softc->rx_rings[i]; - ring->rx_max_frame_size = iflib_get_rx_mbuf_sz(ctx); + ring->rx_buf_size = iflib_get_rx_mbuf_sz(ctx); err = aq_ring_rx_init(&softc->hw, ring); if (err) { device_printf(softc->dev, @@ -829,7 +792,6 @@ aq_if_get_counter(if_ctx_t ctx, ift_counter cnt) } } -#if __FreeBSD_version >= 1300054 static u_int aq_mc_filter_apply(void *arg, struct sockaddr_dl *dl, u_int count) { @@ -846,26 +808,6 @@ aq_mc_filter_apply(void *arg, struct sockaddr_dl *dl, u_int count) aq_log_detail("set %d mc address %6D", count + 1, mac_addr, ":"); return (1); } -#else -static int -aq_mc_filter_apply(void *arg, struct ifmultiaddr *ifma, int count) -{ - struct aq_dev *softc = arg; - struct aq_hw *hw = &softc->hw; - uint8_t *mac_addr = NULL; - - if (ifma->ifma_addr->sa_family != AF_LINK) - return (0); - if (count == AQ_HW_MAC_MAX) - return (0); - - mac_addr = LLADDR((struct sockaddr_dl *)ifma->ifma_addr); - aq_hw_mac_addr_set(hw, mac_addr, count + 1); - - aq_log_detail("set %d mc address %6D", count + 1, mac_addr, ":"); - return (1); -} -#endif static bool aq_is_mc_promisc_required(struct aq_dev *softc) @@ -880,21 +822,13 @@ aq_if_multi_set(if_ctx_t ctx) if_t ifp = iflib_get_ifp(ctx); struct aq_hw *hw = &softc->hw; AQ_DBG_ENTER(); -#if __FreeBSD_version >= 1300054 softc->mcnt = if_llmaddr_count(iflib_get_ifp(ctx)); -#else - softc->mcnt = if_multiaddr_count(iflib_get_ifp(ctx), AQ_HW_MAC_MAX); -#endif if (softc->mcnt >= AQ_HW_MAC_MAX) { aq_hw_set_promisc(hw, !!(if_getflags(ifp) & IFF_PROMISC), aq_is_vlan_promisc_required(softc), !!(if_getflags(ifp) & IFF_ALLMULTI) || aq_is_mc_promisc_required(softc)); } else { -#if __FreeBSD_version >= 1300054 if_foreach_llmaddr(iflib_get_ifp(ctx), &aq_mc_filter_apply, softc); -#else - if_multi_apply(iflib_get_ifp(ctx), aq_mc_filter_apply, softc); -#endif } AQ_DBG_EXIT(0); } @@ -1192,7 +1126,7 @@ aq_if_led_func(if_ctx_t ctx, int onoff) struct aq_hw *hw = &softc->hw; AQ_DBG_ENTERA("%d", onoff); - if (hw->fw_ops && hw->fw_ops->led_control) + if (hw->fw_ops->led_control) hw->fw_ops->led_control(hw, onoff); AQ_DBG_EXIT(0); @@ -1366,7 +1300,7 @@ aq_add_stats_sysctls(struct aq_dev *softc) struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev); struct sysctl_oid *tree = device_get_sysctl_tree(dev); struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree); - struct aq_stats_s *stats = &softc->curr_stats; + struct aq_stats *stats = &softc->curr_stats; struct sysctl_oid *stat_node, *queue_node; struct sysctl_oid_list *stat_list, *queue_list; diff --git a/sys/dev/aq/aq_media.c b/sys/dev/aq/aq_media.c index 655b060e7bd2..21834215c582 100644 --- a/sys/dev/aq/aq_media.c +++ b/sys/dev/aq/aq_media.c @@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$"); #include <net/if.h> #include <net/if_media.h> #include <net/if_var.h> -#include <net/if_dl.h> #include <net/iflib.h> #include "aq_device.h" @@ -54,7 +53,7 @@ __FBSDID("$FreeBSD$"); #define AQ_HW_SUPPORT_SPEED(softc, s) ((softc)->link_speeds & s) void -aq_mediastatus_update(aq_dev_t *aq_dev, uint32_t link_speed, +aq_mediastatus_update(struct aq_dev *aq_dev, uint32_t link_speed, const struct aq_hw_fc_info *fc_neg) { struct aq_hw *hw = &aq_dev->hw; @@ -94,7 +93,7 @@ const struct aq_hw_fc_info *fc_neg) void aq_mediastatus(if_t ifp, struct ifmediareq *ifmr) { - aq_dev_t *aq_dev = iflib_get_softc(if_getsoftc(ifp)); + struct aq_dev *aq_dev = iflib_get_softc(if_getsoftc(ifp)); ifmr->ifm_active = IFM_ETHER; ifmr->ifm_status = IFM_AVALID; @@ -108,7 +107,7 @@ aq_mediastatus(if_t ifp, struct ifmediareq *ifmr) int aq_mediachange(if_t ifp) { - aq_dev_t *aq_dev = iflib_get_softc(if_getsoftc(ifp)); + struct aq_dev *aq_dev = iflib_get_softc(if_getsoftc(ifp)); struct aq_hw *hw = &aq_dev->hw; int old_media_rate = if_getbaudrate(ifp); int old_link_speed = hw->link_rate; @@ -163,7 +162,7 @@ aq_mediachange(if_t ifp) break; default: // should never happen - aq_log_error("unknown media: 0x%X", user_media); + device_printf(hw->dev, "unknown media: 0x%X\n", user_media); return (0); } hw->fc.fc_rx = (ifm->ifm_media & IFM_ETH_RXPAUSE) ? 1 : 0; @@ -184,7 +183,7 @@ aq_mediachange(if_t ifp) } static void -aq_add_media_types(aq_dev_t *aq_dev, int media_link_speed) +aq_add_media_types(struct aq_dev *aq_dev, int media_link_speed) { ifmedia_add(aq_dev->media, IFM_ETHER | media_link_speed | IFM_FDX, 0, NULL); @@ -196,7 +195,7 @@ aq_add_media_types(aq_dev_t *aq_dev, int media_link_speed) IFM_ETH_TXPAUSE, 0, NULL); } void -aq_initmedia(aq_dev_t *aq_dev) +aq_initmedia(struct aq_dev *aq_dev) { AQ_DBG_ENTER(); diff --git a/sys/dev/aq/aq_ring.c b/sys/dev/aq/aq_ring.c index 9b7f6ae2bf0e..311a5c9abf28 100644 --- a/sys/dev/aq/aq_ring.c +++ b/sys/dev/aq/aq_ring.c @@ -42,8 +42,6 @@ __FBSDID("$FreeBSD$"); #include <machine/param.h> #include <net/ethernet.h> #include <net/if.h> -#include <net/if_dl.h> -#include <net/if_media.h> #include <net/if_var.h> #include <net/iflib.h> #include <netinet/in.h> @@ -107,10 +105,7 @@ aq_ring_rx_init(struct aq_hw *hw, struct aq_ring *ring) rdm_rx_desc_len_set(hw, ring->rx_size / 8U, ring->index); - device_printf(ring->dev->dev, - "ring %d: __PAGESIZE=%d MCLBYTES=%d hw->max_frame_size=%d\n", - ring->index, PAGE_SIZE, MCLBYTES, ring->rx_max_frame_size); - rdm_rx_desc_data_buff_size_set(hw, ring->rx_max_frame_size / 1024U, + rdm_rx_desc_data_buff_size_set(hw, ring->rx_buf_size / 1024U, ring->index); rdm_rx_desc_head_buff_size_set(hw, 0U, ring->index); @@ -143,7 +138,7 @@ aq_ring_tx_init(struct aq_hw *hw, struct aq_ring *ring) { int err; uint32_t dma_desc_addr_lsw = (uint32_t)ring->tx_descs_phys & 0xffffffff; - uint32_t dma_desc_addr_msw = (uint64_t)(ring->tx_descs_phys >> 32); + uint32_t dma_desc_addr_msw = (uint32_t)(ring->tx_descs_phys >> 32); AQ_DBG_ENTERA("[%d]", ring->index); @@ -236,8 +231,8 @@ aq_ring_rx_stop(struct aq_hw *hw, struct aq_ring *ring) static void aq_ring_rx_refill(void* arg, if_rxd_update_t iru) { - aq_dev_t *aq_dev = arg; - aq_rx_desc_t *rx_desc; + struct aq_dev *aq_dev = arg; + volatile struct aq_rx_desc *rx_desc; struct aq_ring *ring; qidx_t i, pidx; @@ -248,7 +243,7 @@ aq_ring_rx_refill(void* arg, if_rxd_update_t iru) pidx = iru->iru_pidx; for (i = 0; i < iru->iru_count; i++) { - rx_desc = (aq_rx_desc_t *) &ring->rx_descs[pidx]; + rx_desc = (volatile struct aq_rx_desc *) &ring->rx_descs[pidx]; rx_desc->read.buf_addr = htole64(iru->iru_paddrs[i]); rx_desc->read.hdr_addr = 0; @@ -261,7 +256,7 @@ aq_ring_rx_refill(void* arg, if_rxd_update_t iru) static void aq_isc_rxd_flush(void *arg, uint16_t rxqid, uint8_t flid __unused, qidx_t pidx) { - aq_dev_t *aq_dev = arg; + struct aq_dev *aq_dev = arg; struct aq_ring *ring = aq_dev->rx_rings[rxqid]; AQ_DBG_ENTERA("[%d] tail=%u", ring->index, pidx); @@ -272,9 +267,9 @@ aq_isc_rxd_flush(void *arg, uint16_t rxqid, uint8_t flid __unused, qidx_t pidx) static int aq_isc_rxd_available(void *arg, uint16_t rxqid, qidx_t idx, qidx_t budget) { - aq_dev_t *aq_dev = arg; + struct aq_dev *aq_dev = arg; struct aq_ring *ring = aq_dev->rx_rings[rxqid]; - aq_rx_desc_t *rx_desc = (aq_rx_desc_t *) ring->rx_descs; + volatile struct aq_rx_desc *rx_desc = (volatile struct aq_rx_desc *) ring->rx_descs; int cnt, i, iter; AQ_DBG_ENTERA("[%d] head=%u, budget %d", ring->index, idx, budget); @@ -286,17 +281,10 @@ aq_isc_rxd_available(void *arg, uint16_t rxqid, qidx_t idx, qidx_t budget) if (!rx_desc[i].wb.dd) break; - if (rx_desc[i].wb.eop) { - iter++; - i = aq_next(i, ring->rx_size - 1); - + if (rx_desc[i].wb.eop) cnt++; - } else { - /* Jumbo frame spans descriptors; advance. */ - iter++; - i = aq_next(i, ring->rx_size - 1); - continue; - } + iter++; + i = aq_next(i, ring->rx_size - 1); } AQ_DBG_EXIT(cnt); @@ -304,7 +292,7 @@ aq_isc_rxd_available(void *arg, uint16_t rxqid, qidx_t idx, qidx_t budget) } static void -aq_rx_set_cso_flags(aq_rx_desc_t *rx_desc, if_rxd_info_t ri) +aq_rx_set_cso_flags(volatile struct aq_rx_desc *rx_desc, if_rxd_info_t ri) { if ((rx_desc->wb.pkt_type & 0x3) == 0) { // IPv4 if (rx_desc->wb.rx_cntl & BIT(0)) { // IPv4 csum checked @@ -337,9 +325,9 @@ static uint8_t bsd_rss_type[16] = { static int aq_isc_rxd_pkt_get(void *arg, if_rxd_info_t ri) { - aq_dev_t *aq_dev = arg; + struct aq_dev *aq_dev = arg; struct aq_ring *ring = aq_dev->rx_rings[ri->iri_qsidx]; - aq_rx_desc_t *rx_desc; + volatile struct aq_rx_desc *rx_desc; if_t ifp; int cidx, rc = 0, i; size_t len, total_len; @@ -350,28 +338,26 @@ aq_isc_rxd_pkt_get(void *arg, if_rxd_info_t ri) i = 0; do { - if (i >= aq_dev->sctx->isc_rx_nsegments) { - counter_u64_add(ring->stats.rx_err, 1); - rc = (EBADMSG); - goto exit; - } + if (i >= aq_dev->sctx->isc_rx_nsegments) + goto rx_err; - rx_desc = (aq_rx_desc_t *) &ring->rx_descs[cidx]; + rx_desc = (volatile struct aq_rx_desc *) &ring->rx_descs[cidx]; trace_aq_rx_descr(ring->index, cidx, (volatile uint64_t *)rx_desc); - if ((rx_desc->wb.rx_stat & BIT(0)) != 0) { - counter_u64_add(ring->stats.rx_err, 1); - rc = (EBADMSG); - goto exit; - } + if ((rx_desc->wb.rx_stat & BIT(0)) != 0) + goto rx_err; if (!rx_desc->wb.eop) { - len = ring->rx_max_frame_size; + len = ring->rx_buf_size; } else { total_len = le32toh(rx_desc->wb.pkt_len); - len = total_len - (size_t)i * ring->rx_max_frame_size; + if (total_len < (size_t)i * ring->rx_buf_size) + goto rx_err; + len = total_len - (size_t)i * ring->rx_buf_size; + if (len > (size_t)ring->rx_buf_size) + goto rx_err; } ri->iri_frags[i].irf_flid = 0; ri->iri_frags[i].irf_idx = cidx; @@ -399,7 +385,11 @@ aq_isc_rxd_pkt_get(void *arg, if_rxd_info_t ri) counter_u64_add(ring->stats.rx_bytes, total_len); counter_u64_add(ring->stats.rx_pkts, 1); + goto exit; +rx_err: + counter_u64_add(ring->stats.rx_err, 1); + rc = EBADMSG; exit: AQ_DBG_EXIT(rc); return (rc); @@ -410,7 +400,7 @@ exit: /*****************************************************************************/ static void -aq_setup_offloads(aq_dev_t *aq_dev, if_pkt_info_t pi, aq_tx_desc_t *txd, +aq_setup_offloads(struct aq_dev *aq_dev, if_pkt_info_t pi, volatile struct aq_tx_desc *txd, uint32_t tx_cmd) { AQ_DBG_ENTER(); @@ -425,8 +415,8 @@ aq_setup_offloads(aq_dev_t *aq_dev, if_pkt_info_t pi, aq_tx_desc_t *txd, } static int -aq_ring_tso_setup(aq_dev_t *aq_dev, if_pkt_info_t pi, uint32_t *hdrlen, - aq_txc_desc_t *txc) +aq_ring_tso_setup(struct aq_dev *aq_dev, if_pkt_info_t pi, uint32_t *hdrlen, + volatile union aq_txc_desc *txc) { uint32_t tx_cmd = 0; @@ -471,10 +461,10 @@ aq_ring_tso_setup(aq_dev_t *aq_dev, if_pkt_info_t pi, uint32_t *hdrlen, static int aq_isc_txd_encap(void *arg, if_pkt_info_t pi) { - aq_dev_t *aq_dev = arg; + struct aq_dev *aq_dev = arg; struct aq_ring *ring; - aq_txc_desc_t *txc; - aq_tx_desc_t *txd = NULL; + volatile union aq_txc_desc *txc; + volatile struct aq_tx_desc *txd = NULL; bus_dma_segment_t *segs; qidx_t pidx; uint32_t hdrlen=0, pay_len; @@ -486,7 +476,7 @@ aq_isc_txd_encap(void *arg, if_pkt_info_t pi) segs = pi->ipi_segs; pidx = pi->ipi_pidx; - txc = (aq_txc_desc_t *)&ring->tx_descs[pidx]; + txc = (volatile union aq_txc_desc *)&ring->tx_descs[pidx]; AQ_DBG_PRINT("txc at 0x%p, txd at 0x%p len %d", txc, txd, pi->ipi_len); pay_len = pi->ipi_len; @@ -506,7 +496,7 @@ aq_isc_txd_encap(void *arg, if_pkt_info_t pi) txd = &ring->tx_descs[pidx]; txd->flags = 0U; } else { - txd = (aq_tx_desc_t *)txc; + txd = (volatile struct aq_tx_desc *)txc; } AQ_DBG_PRINT("txc at 0x%p, txd at 0x%p", txc, txd); @@ -563,7 +553,7 @@ aq_isc_txd_encap(void *arg, if_pkt_info_t pi) static void aq_isc_txd_flush(void *arg, uint16_t txqid, qidx_t pidx) { - aq_dev_t *aq_dev = arg; + struct aq_dev *aq_dev = arg; struct aq_ring *ring = aq_dev->tx_rings[txqid]; AQ_DBG_ENTERA("[%d] tail=%d", ring->index, pidx); @@ -582,7 +572,7 @@ aq_avail_desc(int a, int b, int size) static int aq_isc_txd_credits_update(void *arg, uint16_t txqid, bool clear) { - aq_dev_t *aq_dev = arg; + struct aq_dev *aq_dev = arg; struct aq_ring *ring = aq_dev->tx_rings[txqid]; uint32_t head; int avail; diff --git a/sys/dev/aq/aq_ring.h b/sys/dev/aq/aq_ring.h index 2f33fbf75d55..1b248913d4f8 100644 --- a/sys/dev/aq/aq_ring.h +++ b/sys/dev/aq/aq_ring.h @@ -42,7 +42,7 @@ #define REFILL_THRESHOLD 128 -typedef volatile struct { +struct aq_rx_wb { uint32_t rss_type:4; uint32_t pkt_type:8; uint32_t rdm_err:1; @@ -59,9 +59,9 @@ typedef volatile struct { uint16_t pkt_len; uint16_t next_desp; uint16_t vlan; -} __attribute__((__packed__)) aq_rx_wb_t; +} __packed; -typedef volatile struct { +struct aq_rx_desc { union { /* HW RX descriptor */ struct __packed { @@ -70,12 +70,12 @@ typedef volatile struct { } read; /* HW RX descriptor writeback */ - aq_rx_wb_t wb; + struct aq_rx_wb wb; }; -} __attribute__((__packed__)) aq_rx_desc_t; +} __packed; /* Hardware tx descriptor */ -typedef volatile struct { +struct aq_tx_desc { uint64_t buf_addr; union { @@ -90,10 +90,10 @@ typedef volatile struct { uint32_t ct_idx:1; uint32_t ct_en:1; uint32_t pay_len:18; - } __attribute__((__packed__)); + } __packed; uint64_t flags; }; -} __attribute__((__packed__)) aq_tx_desc_t; +} __packed; enum aq_tx_desc_type { tx_desc_type_desc = 1, @@ -110,7 +110,7 @@ enum aq_tx_desc_cmd { }; /* Hardware tx context descriptor */ -typedef volatile union { +union aq_txc_desc { struct __packed { uint64_t flags1; uint64_t flags2; @@ -129,7 +129,7 @@ typedef volatile union { uint32_t l4_len:8; uint32_t mss_len:16; }; -} __attribute__((__packed__)) aq_txc_desc_t; +} __packed; struct aq_ring_stats { counter_u64_t rx_pkts; @@ -151,16 +151,16 @@ struct aq_ring { int msix; /* RX */ qidx_t rx_size; - int rx_max_frame_size; + int rx_buf_size; void *rx_desc_area_ptr; - aq_rx_desc_t *rx_descs; + volatile struct aq_rx_desc *rx_descs; uint64_t rx_descs_phys; /* TX */ int tx_head, tx_tail; qidx_t tx_size; void *tx_desc_area_ptr; - aq_tx_desc_t *tx_descs; + volatile struct aq_tx_desc *tx_descs; uint64_t tx_descs_phys; struct aq_ring_stats stats; |
