#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/bitstring.h>
#include <sys/kernel.h>
#include <sys/socket.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/iflib.h>
#include "aq_common.h"
#include "aq_device.h"
#include "aq_ring.h"
#include "aq_dbg.h"
#include "aq_hw.h"
#include "aq_hw_llh.h"
int
aq_update_hw_stats(struct aq_dev *aq_dev)
{
struct aq_hw *hw = &aq_dev->hw;
struct aq_hw_stats stats;
memset(&stats, 0, sizeof(stats));
if (aq_hw_mpi_read_stats(hw, &stats) != 0)
return (0);
#define AQ_SDELTA(_N_) do { \
int32_t _d = (int32_t)(stats._N_ - aq_dev->last_stats._N_); \
if (_d > 0) \
aq_dev->curr_stats._N_ += _d; \
} while (0)
if (aq_dev->linkup) {
AQ_SDELTA(uprc);
AQ_SDELTA(mprc);
AQ_SDELTA(bprc);
AQ_SDELTA(cprc);
AQ_SDELTA(erpt);
AQ_SDELTA(uptc);
AQ_SDELTA(mptc);
AQ_SDELTA(bptc);
AQ_SDELTA(erpr);
AQ_SDELTA(ubrc);
AQ_SDELTA(ubtc);
AQ_SDELTA(mbrc);
AQ_SDELTA(mbtc);
AQ_SDELTA(bbrc);
AQ_SDELTA(bbtc);
AQ_SDELTA(ptc);
AQ_SDELTA(prc);
AQ_SDELTA(dpc);
if (stats.ubrc | stats.mbrc | stats.bbrc)
aq_dev->curr_stats.brc = aq_dev->curr_stats.ubrc +
aq_dev->curr_stats.mbrc + aq_dev->curr_stats.bbrc;
else
AQ_SDELTA(brc);
if (stats.ubtc | stats.mbtc | stats.bbtc)
aq_dev->curr_stats.btc = aq_dev->curr_stats.ubtc +
aq_dev->curr_stats.mbtc + aq_dev->curr_stats.bbtc;
else
AQ_SDELTA(btc);
}
#undef AQ_SDELTA
memcpy(&aq_dev->last_stats, &stats, sizeof(stats));
return (0);
}
void
aq_if_update_admin_status(if_ctx_t ctx)
{
struct aq_dev *aq_dev = iflib_get_softc(ctx);
struct aq_hw *hw = &aq_dev->hw;
uint32_t link_speed;
struct aq_hw_fc_info fc_neg;
aq_hw_get_link_state(hw, &link_speed, &fc_neg);
if (link_speed && !aq_dev->linkup) {
device_printf(aq_dev->dev, "atlantic: link UP: speed=%d\n", link_speed);
aq_dev->linkup = 1;
rpb_rx_xoff_en_per_tc_set(hw, fc_neg.fc_rx, 0);
iflib_link_state_change(ctx, LINK_STATE_UP, IF_Mbps(link_speed));
aq_mediastatus_update(aq_dev, link_speed, &fc_neg);
aq_hw_interrupt_moderation_set(hw);
} else if (link_speed == 0U && aq_dev->linkup) {
device_printf(aq_dev->dev, "atlantic: link DOWN\n");
aq_dev->linkup = 0;
rpb_rx_xoff_en_per_tc_set(hw, 0, 0);
iflib_link_state_change(ctx, LINK_STATE_DOWN, 0);
aq_mediastatus_update(aq_dev, link_speed, &fc_neg);
}
aq_update_hw_stats(aq_dev);
}
int
aq_isr_rx(void *arg)
{
struct aq_ring *ring = arg;
struct aq_dev *aq_dev = ring->dev;
struct aq_hw *hw = &aq_dev->hw;
itr_irq_status_clearlsw_set(hw, BIT(ring->msix));
AQ_HW_FLUSH(hw);
counter_u64_add(ring->stats.irq, 1);
return (FILTER_SCHEDULE_THREAD);
}
int
aq_linkstat_isr(void *arg)
{
struct aq_dev *aq_dev = arg;
struct aq_hw *hw = &aq_dev->hw;
itr_irq_status_clearlsw_set(hw, BIT(aq_dev->msix));
AQ_HW_FLUSH(hw);
iflib_admin_intr_deferred(aq_dev->ctx);
return (FILTER_HANDLED);
}