/* Fill in a buffer with the strings which correspond to the
* stats */ staticvoid gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
{ struct gfar_private *priv = netdev_priv(dev); int i;
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) for (i = 0; i < GFAR_STATS_LEN; i++)
ethtool_puts(&buf, stat_gstrings[i]); else for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
ethtool_puts(&buf, stat_gstrings[i]);
}
/* Fill in an array of 64-bit statistics from various sources. * This array will be appended to the end of the ethtool_stats * structure, and returned to user space
*/ staticvoid gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
u64 *buf)
{ int i; struct gfar_private *priv = netdev_priv(dev); struct gfar __iomem *regs = priv->gfargrp[0].regs;
atomic64_t *extra = (atomic64_t *)&priv->extra_stats;
for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
buf[i] = atomic64_read(&extra[i]);
switch (sset) { case ETH_SS_STATS: if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) return GFAR_STATS_LEN; else return GFAR_EXTRA_STATS_LEN; default: return -EOPNOTSUPP;
}
}
/* Fills in the drvinfo structure with some basic info */ staticvoid gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
{
strscpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
}
/* Return the length of the register structure */ staticint gfar_reglen(struct net_device *dev)
{ returnsizeof (struct gfar);
}
/* Return a dump of the GFAR register space */ staticvoid gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
{ int i; struct gfar_private *priv = netdev_priv(dev);
u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp[0].regs;
u32 *buf = (u32 *) regbuf;
for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)
buf[i] = gfar_read(&theregs[i]);
}
/* Convert microseconds to ethernet clock ticks, which changes
* depending on what speed the controller is running at */ staticunsignedint gfar_usecs2ticks(struct gfar_private *priv, unsignedint usecs)
{ struct net_device *ndev = priv->ndev; struct phy_device *phydev = ndev->phydev; unsignedint count;
/* The timer is different, depending on the interface speed */ switch (phydev->speed) { case SPEED_1000:
count = GFAR_GBIT_TIME; break; case SPEED_100:
count = GFAR_100_TIME; break; case SPEED_10: default:
count = GFAR_10_TIME; break;
}
/* Make sure we return a number greater than 0
* if usecs > 0 */ return DIV_ROUND_UP(usecs * 1000, count);
}
/* The timer is different, depending on the interface speed */ switch (phydev->speed) { case SPEED_1000:
count = GFAR_GBIT_TIME; break; case SPEED_100:
count = GFAR_100_TIME; break; case SPEED_10: default:
count = GFAR_10_TIME; break;
}
/* Make sure we return a number greater than 0 */ /* if ticks is > 0 */ return (ticks * count) / 1000;
}
/* Get the coalescing parameters, and put them in the cvals
* structure. */ staticint gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals, struct kernel_ethtool_coalesce *kernel_coal, struct netlink_ext_ack *extack)
{ struct gfar_private *priv = netdev_priv(dev); struct gfar_priv_rx_q *rx_queue = NULL; struct gfar_priv_tx_q *tx_queue = NULL; unsignedlong rxtime; unsignedlong rxcount; unsignedlong txtime; unsignedlong txcount;
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) return -EOPNOTSUPP;
/* Change the coalescing values. * Both cvals->*_usecs and cvals->*_frames have to be > 0 * in order for coalescing to be active
*/ staticint gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals, struct kernel_ethtool_coalesce *kernel_coal, struct netlink_ext_ack *extack)
{ struct gfar_private *priv = netdev_priv(dev); int i, err = 0;
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) return -EOPNOTSUPP;
if (!dev->phydev) return -ENODEV;
/* Check the bounds of the values */ if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
netdev_info(dev, "Coalescing is limited to %d microseconds\n",
GFAR_MAX_COAL_USECS); return -EINVAL;
}
if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
netdev_info(dev, "Coalescing is limited to %d frames\n",
GFAR_MAX_COAL_FRAMES); return -EINVAL;
}
/* Check the bounds of the values */ if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
netdev_info(dev, "Coalescing is limited to %d microseconds\n",
GFAR_MAX_COAL_USECS); return -EINVAL;
}
if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
netdev_info(dev, "Coalescing is limited to %d frames\n",
GFAR_MAX_COAL_FRAMES); return -EINVAL;
}
while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
cpu_relax();
/* Set up rx coalescing */ if ((cvals->rx_coalesce_usecs == 0) ||
(cvals->rx_max_coalesced_frames == 0)) { for (i = 0; i < priv->num_rx_queues; i++)
priv->rx_queue[i]->rxcoalescing = 0;
} else { for (i = 0; i < priv->num_rx_queues; i++)
priv->rx_queue[i]->rxcoalescing = 1;
}
for (i = 0; i < priv->num_rx_queues; i++) {
priv->rx_queue[i]->rxic = mk_ic_value(
cvals->rx_max_coalesced_frames,
gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs));
}
/* Set up tx coalescing */ if ((cvals->tx_coalesce_usecs == 0) ||
(cvals->tx_max_coalesced_frames == 0)) { for (i = 0; i < priv->num_tx_queues; i++)
priv->tx_queue[i]->txcoalescing = 0;
} else { for (i = 0; i < priv->num_tx_queues; i++)
priv->tx_queue[i]->txcoalescing = 1;
}
for (i = 0; i < priv->num_tx_queues; i++) {
priv->tx_queue[i]->txic = mk_ic_value(
cvals->tx_max_coalesced_frames,
gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs));
}
/* Fills in rvals with the current ring parameters. Currently, * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
* jumbo are ignored by the driver */ staticvoid gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals, struct kernel_ethtool_ringparam *kernel_rvals, struct netlink_ext_ack *extack)
{ struct gfar_private *priv = netdev_priv(dev); struct gfar_priv_tx_q *tx_queue = NULL; struct gfar_priv_rx_q *rx_queue = NULL;
/* Values changeable by the user. The valid values are * in the range 1 to the "*_max_pending" counterpart above.
*/
rvals->rx_pending = rx_queue->rx_ring_size;
rvals->rx_mini_pending = rx_queue->rx_ring_size;
rvals->rx_jumbo_pending = rx_queue->rx_ring_size;
rvals->tx_pending = tx_queue->tx_ring_size;
}
/* Change the current ring parameters, stopping the controller if * necessary so that we don't mess things up while we're in motion.
*/ staticint gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals, struct kernel_ethtool_ringparam *kernel_rvals, struct netlink_ext_ack *extack)
{ struct gfar_private *priv = netdev_priv(dev); int err = 0, i;
if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) return -EINVAL;
if (!is_power_of_2(rvals->rx_pending)) {
netdev_err(dev, "Ring sizes must be a power of 2\n"); return -EINVAL;
}
if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE) return -EINVAL;
if (!is_power_of_2(rvals->tx_pending)) {
netdev_err(dev, "Ring sizes must be a power of 2\n"); return -EINVAL;
}
while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
cpu_relax();
if (dev->flags & IFF_UP)
stop_gfar(dev);
/* Change the sizes */ for (i = 0; i < priv->num_rx_queues; i++)
priv->rx_queue[i]->rx_ring_size = rvals->rx_pending;
for (i = 0; i < priv->num_tx_queues; i++)
priv->tx_queue[i]->tx_ring_size = rvals->tx_pending;
/* Rebuild the rings with the new size */ if (dev->flags & IFF_UP)
err = startup_gfar(dev);
staticint gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,
u64 class)
{ unsignedint cmp_rqfpr; unsignedint *local_rqfpr; unsignedint *local_rqfcr; int i = 0x0, k = 0x0; int j = MAX_FILER_IDX, l = 0x0; int ret = 1;
switch (class) { case TCP_V4_FLOW:
cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP; break; case UDP_V4_FLOW:
cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP; break; case TCP_V6_FLOW:
cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP; break; case UDP_V6_FLOW:
cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP; break; default:
netdev_err(priv->ndev, "Right now this class is not supported\n");
ret = 0; goto err;
}
for (i = 0; i < MAX_FILER_IDX + 1; i++) {
local_rqfpr[j] = priv->ftp_rqfpr[i];
local_rqfcr[j] = priv->ftp_rqfcr[i];
j--; if ((priv->ftp_rqfcr[i] ==
(RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND)) &&
(priv->ftp_rqfpr[i] == cmp_rqfpr)) break;
}
if (i == MAX_FILER_IDX + 1) {
netdev_err(priv->ndev, "No parse rule found, can't create hash rules\n");
ret = 0; goto err;
}
/* If a match was found, then it begins the starting of a cluster rule * if it was already programmed, we need to overwrite these rules
*/ for (l = i+1; l < MAX_FILER_IDX; l++) { if ((priv->ftp_rqfcr[l] & RQFCR_CLE) &&
!(priv->ftp_rqfcr[l] & RQFCR_AND)) {
priv->ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT |
RQFCR_HASHTBL_0 | RQFCR_PID_MASK;
priv->ftp_rqfpr[l] = FPR_FILER_MASK;
gfar_write_filer(priv, l, priv->ftp_rqfcr[l],
priv->ftp_rqfpr[l]); break;
}
/* Check if we are in FIFO mode */
i = gfar_read(®s->ecntrl);
i &= ECNTRL_FIFM; if (i == ECNTRL_FIFM) {
netdev_notice(priv->ndev, "Interface in FIFO mode\n");
i = gfar_read(®s->rctrl);
i &= RCTRL_PRSDEP_MASK | RCTRL_PRSFM; if (i == (RCTRL_PRSDEP_MASK | RCTRL_PRSFM)) {
netdev_info(priv->ndev, "Receive Queue Filtering enabled\n");
} else {
netdev_warn(priv->ndev, "Receive Queue Filtering disabled\n"); return -EOPNOTSUPP;
}
} /* Or in standard mode */ else {
i = gfar_read(®s->rctrl);
i &= RCTRL_PRSDEP_MASK; if (i == RCTRL_PRSDEP_MASK) {
netdev_info(priv->ndev, "Receive Queue Filtering enabled\n");
} else {
netdev_warn(priv->ndev, "Receive Queue Filtering disabled\n"); return -EOPNOTSUPP;
}
}
/* Sets the properties for arbitrary filer rule * to the first 4 Layer 4 Bytes
*/
gfar_write(®s->rbifx, 0xC0C1C2C3); return 0;
}
/* For setting a tuple of value and mask of type flag * Example: * IP-Src = 10.0.0.0/255.0.0.0 * value: 0x0A000000 mask: FF000000 flag: RQFPR_IPV4 * * Ethtool gives us a value=0 and mask=~0 for don't care a tuple * For a don't care mask it gives us a 0 * * The check if don't care and the mask adjustment if mask=0 is done for VLAN * and MAC stuff on an upper level (due to missing information on this level). * For these guys we can discard them if they are value=0 and mask=0. * * Further the all masks are one-padded for better hardware efficiency.
*/ staticvoid gfar_set_attribute(u32 value, u32 mask, u32 flag, struct filer_table *tab)
{ switch (flag) { /* 3bit */ case RQFCR_PID_PRI: if (!(value | mask)) return;
mask |= RQFCR_PID_PRI_MASK; break; /* 8bit */ case RQFCR_PID_L4P: case RQFCR_PID_TOS: if (!~(mask | RQFCR_PID_L4P_MASK)) return; if (!mask)
mask = ~0; else
mask |= RQFCR_PID_L4P_MASK; break; /* 12bit */ case RQFCR_PID_VID: if (!(value | mask)) return;
mask |= RQFCR_PID_VID_MASK; break; /* 16bit */ case RQFCR_PID_DPT: case RQFCR_PID_SPT: case RQFCR_PID_ETY: if (!~(mask | RQFCR_PID_PORT_MASK)) return; if (!mask)
mask = ~0; else
mask |= RQFCR_PID_PORT_MASK; break; /* 24bit */ case RQFCR_PID_DAH: case RQFCR_PID_DAL: case RQFCR_PID_SAH: case RQFCR_PID_SAL: if (!(value | mask)) return;
mask |= RQFCR_PID_MAC_MASK; break; /* for all real 32bit masks */ default: if (!~mask) return; if (!mask)
mask = ~0; break;
}
gfar_set_general_attribute(value, mask, flag, tab);
}
/* Set the vlan attributes in the end */ if (vlan) {
gfar_set_attribute(id, id_mask, RQFCR_PID_VID, tab);
gfar_set_attribute(prio, prio_mask, RQFCR_PID_PRI, tab);
}
/* If there has been nothing written till now, it must be a default */ if (tab->index == old_index) {
gfar_set_mask(0xFFFFFFFF, tab);
tab->fe[tab->index].ctrl = 0x20;
tab->fe[tab->index].prop = 0x0;
tab->index++;
}
/* Remove last AND */
tab->fe[tab->index - 1].ctrl &= (~RQFCR_AND);
/* Specify which queue to use or to drop */ if (rule->ring_cookie == RX_CLS_FLOW_DISC)
tab->fe[tab->index - 1].ctrl |= RQFCR_RJE; else
tab->fe[tab->index - 1].ctrl |= (rule->ring_cookie << 10);
/* Only big enough entries can be clustered */ if (tab->index > (old_index + 2)) {
tab->fe[old_index + 1].ctrl |= RQFCR_CLE;
tab->fe[tab->index - 1].ctrl |= RQFCR_CLE;
}
/* In rare cases the cache can be full while there is * free space in hw
*/ if (tab->index > MAX_FILER_CACHE_IDX - 1) return -EBUSY;
return 0;
}
/* Write the bit-pattern from software's buffer to hardware registers */ staticint gfar_write_filer_table(struct gfar_private *priv, struct filer_table *tab)
{
u32 i = 0; if (tab->index > MAX_FILER_IDX - 1) return -EBUSY;
/* Fill regular entries */ for (; i < MAX_FILER_IDX && (tab->fe[i].ctrl | tab->fe[i].prop); i++)
gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop); /* Fill the rest with fall-troughs */ for (; i < MAX_FILER_IDX; i++)
gfar_write_filer(priv, i, 0x60, 0xFFFFFFFF); /* Last entry must be default accept * because that's what people expect
*/
gfar_write_filer(priv, i, 0x20, 0x0);
if (flow->flow_type & FLOW_EXT) { if (~flow->m_ext.data[0] || ~flow->m_ext.data[1])
netdev_warn(priv->ndev, "User-specific data not supported!\n"); if (~flow->m_ext.vlan_etype)
netdev_warn(priv->ndev, "VLAN-etype not supported!\n");
} if (flow->flow_type == IP_USER_FLOW) if (flow->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4)
netdev_warn(priv->ndev, "IP-Version differing from IPv4 not supported!\n");
/* So index is set to zero, too! */
tab = kzalloc(sizeof(*tab), GFP_KERNEL); if (tab == NULL) return -ENOMEM;
/* Now convert the existing filer data from flow_spec into * filer tables binary format
*/
list_for_each_entry(j, &priv->rx_list.list, list) {
ret = gfar_convert_to_filer(&j->fs, tab); if (ret == -EBUSY) {
netdev_err(priv->ndev, "Rule not added: No free space!\n"); goto end;
} if (ret == -1) {
netdev_err(priv->ndev, "Rule not added: Unsupported Flow-type!\n"); goto end;
}
}
/* Write everything to hardware */
ret = gfar_write_filer_table(priv, tab); if (ret == -EBUSY) {
netdev_err(priv->ndev, "Rule not added: No free space!\n"); goto end;
}
end:
kfree(tab); return ret;
}
staticvoid gfar_invert_masks(struct ethtool_rx_flow_spec *flow)
{
u32 i = 0;
for (i = 0; i < sizeof(flow->m_u); i++)
flow->m_u.hdata[i] ^= 0xFF;
gfar_invert_masks(&temp->fs);
ret = gfar_check_capability(&temp->fs, priv); if (ret) goto clean_mem; /* Link in the new element at the right @location */ if (list_empty(&priv->rx_list.list)) {
ret = gfar_check_filer_hardware(priv); if (ret != 0) goto clean_mem;
list_add(&temp->list, &priv->rx_list.list); goto process;
} else {
list_for_each_entry(comp, &priv->rx_list.list, list) { if (comp->fs.location > flow->location) {
list_add_tail(&temp->list, &comp->list); goto process;
} if (comp->fs.location == flow->location) {
netdev_err(priv->ndev, "Rule not added: ID %d not free!\n",
flow->location);
ret = -EBUSY; goto clean_mem;
}
}
list_add_tail(&temp->list, &priv->rx_list.list);
}
process:
priv->rx_list.count++;
ret = gfar_process_filer_changes(priv); if (ret) goto clean_list; return ret;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.