19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/errno.h>
27 #include <linux/netdevice.h>
36 #include <asm/uaccess.h>
37 #include <linux/module.h>
39 #include <asm/types.h>
40 #include <linux/ethtool.h>
41 #include <linux/mii.h>
44 #include <linux/if_vlan.h>
52 #define GFAR_MAX_COAL_USECS 0xffff
53 #define GFAR_MAX_COAL_FRAMES 0xff
69 "rx-dropped-by-kernel",
70 "rx-large-frame-errors",
71 "rx-short-frame-errors",
72 "rx-non-octet-errors",
77 "rx-truncated-frames",
81 "rx-skb-missing-errors",
84 "tx-rx-65-127-frames",
85 "tx-rx-128-255-frames",
86 "tx-rx-256-511-frames",
87 "tx-rx-512-1023-frames",
88 "tx-rx-1024-1518-frames",
89 "tx-rx-1519-1522-good-vlan",
93 "receive-multicast-packet",
94 "receive-broadcast-packet",
95 "rx-control-frame-packets",
96 "rx-pause-frame-packets",
99 "rx-frame-length-error",
101 "rx-carrier-sense-error",
102 "rx-undersize-packets",
103 "rx-oversize-packets",
104 "rx-fragmented-frames",
109 "tx-multicast-packets",
110 "tx-broadcast-packets",
111 "tx-pause-control-frames",
112 "tx-deferral-packets",
113 "tx-excessive-deferral-packets",
114 "tx-single-collision-packets",
115 "tx-multiple-collision-packets",
116 "tx-late-collision-packets",
117 "tx-excessive-collision-packets",
118 "tx-total-collision",
124 "tx-oversize-frames",
125 "tx-undersize-frames",
126 "tx-fragmented-frames",
138 memcpy(buf, stat_gstrings,
159 stats->rmon[i] = (
u64) gfar_read(&rmon[i]);
162 stats->extra[i] = extra[i];
168 static int gfar_sset_count(
struct net_device *dev,
int sset)
184 static void gfar_gdrvinfo(
struct net_device *dev,
230 static int gfar_reglen(
struct net_device *dev)
232 return sizeof (
struct gfar);
242 u32 *buf = (
u32 *) regbuf;
245 buf[i] = gfar_read(&theregs[i]);
250 static unsigned int gfar_usecs2ticks(
struct gfar_private *priv,
256 switch (priv->
phydev->speed) {
271 return (usecs * 1000 + count - 1) /
count;
275 static unsigned int gfar_ticks2usecs(
struct gfar_private *priv,
281 switch (priv->
phydev->speed) {
296 return (ticks * count) / 1000;
301 static int gfar_gcoalesce(
struct net_device *dev,
307 unsigned long rxtime;
308 unsigned long rxcount;
367 static int gfar_scoalesce(
struct net_device *dev,
384 priv->
rx_queue[i]->rxcoalescing = 0;
387 priv->
rx_queue[i]->rxcoalescing = 1;
395 pr_info(
"Coalescing is limited to %d microseconds\n",
401 pr_info(
"Coalescing is limited to %d frames\n",
416 priv->
tx_queue[i]->txcoalescing = 0;
419 priv->
tx_queue[i]->txcoalescing = 1;
424 pr_info(
"Coalescing is limited to %d microseconds\n",
430 pr_info(
"Coalescing is limited to %d frames\n",
449 static void gfar_gringparam(
struct net_device *dev,
478 static int gfar_sringparam(
struct net_device *dev,
488 netdev_err(dev,
"Ring sizes must be a power of 2\n");
496 netdev_err(dev,
"Ring sizes must be a power of 2\n");
536 netif_tx_wake_all_queues(dev);
578 netif_tx_wake_all_queues(dev);
625 priv->
wol_en = !!device_may_wakeup(&dev->
dev);
626 spin_unlock_irqrestore(&priv->
bflock, flags);
632 static void ethflow_to_filer_rules (
struct gfar_private *priv,
u64 ethflow)
707 static int gfar_ethflow_to_filer_table(
struct gfar_private *priv,
u64 ethflow,
711 unsigned int cmp_rqfpr;
712 unsigned int *local_rqfpr;
713 unsigned int *local_rqfcr;
714 int i = 0x0,
k = 0x0;
722 if (!local_rqfpr || !local_rqfcr) {
723 pr_err(
"Out of memory\n");
742 pr_err(
"Right now this class is not supported\n");
757 if (i == MAX_FILER_IDX + 1) {
758 pr_err(
"No parse rule found, can't create hash rules\n");
772 gfar_write_filer(priv, l, priv->
ftp_rqfcr[l],
791 ethflow_to_filer_rules(priv, ethflow);
798 local_rqfcr[
k], local_rqfpr[k]);
810 static int gfar_set_hash_opts(
struct gfar_private *priv,
814 if (!gfar_ethflow_to_filer_table(priv, cmd->
data, cmd->
flow_type))
820 static int gfar_check_filer_hardware(
struct gfar_private *priv)
828 i = gfar_read(®s->
ecntrl);
831 netdev_notice(priv->
ndev,
"Interface in FIFO mode\n");
832 i = gfar_read(®s->
rctrl);
835 netdev_info(priv->
ndev,
836 "Receive Queue Filtering enabled\n");
838 netdev_warn(priv->
ndev,
839 "Receive Queue Filtering disabled\n");
845 i = gfar_read(®s->
rctrl);
848 netdev_info(priv->
ndev,
849 "Receive Queue Filtering enabled\n");
851 netdev_warn(priv->
ndev,
852 "Receive Queue Filtering disabled\n");
860 regs->
rbifx = 0xC0C1C2C3;
864 static int gfar_comp_asc(
const void *
a,
const void *
b)
869 static int gfar_comp_desc(
const void *
a,
const void *
b)
874 static void gfar_swap(
void *
a,
void *
b,
int size)
896 gfar_set_mask(mask, tab);
906 gfar_set_mask(mask, tab);
980 gfar_set_general_attribute(value, mask, flag, tab);
1010 static void gfar_set_ether(
struct ethhdr *value,
struct ethhdr *mask,
1013 u32 upper_temp_mask = 0;
1014 u32 lower_temp_mask = 0;
1017 if (!is_broadcast_ether_addr(mask->
h_source)) {
1018 if (is_zero_ether_addr(mask->
h_source)) {
1019 upper_temp_mask = 0xFFFFFFFF;
1020 lower_temp_mask = 0xFFFFFFFF;
1022 upper_temp_mask = mask->
h_source[0] << 16 |
1025 lower_temp_mask = mask->
h_source[3] << 16 |
1030 gfar_set_attribute(value->
h_source[0] << 16 |
1035 gfar_set_attribute(value->
h_source[3] << 16 |
1041 if (!is_broadcast_ether_addr(mask->
h_dest)) {
1043 if ((is_broadcast_ether_addr(value->
h_dest) &&
1044 is_zero_ether_addr(mask->
h_dest))) {
1047 if (is_zero_ether_addr(mask->
h_dest)) {
1048 upper_temp_mask = 0xFFFFFFFF;
1049 lower_temp_mask = 0xFFFFFFFF;
1051 upper_temp_mask = mask->
h_dest[0] << 16 |
1054 lower_temp_mask = mask->
h_dest[3] << 16 |
1060 gfar_set_attribute(value->
h_dest[0] << 16 |
1065 gfar_set_attribute(value->
h_dest[3] << 16 |
1080 u32 id = 0, id_mask = 0;
1081 u32 cfi = 0, cfi_mask = 0;
1087 if (!rule->
m_ext.vlan_tci)
1088 rule->
m_ext.vlan_tci = 0xFFFF;
1142 gfar_set_parse_bits(vlan, vlan_mask, tab);
1143 gfar_set_ether((
struct ethhdr *) &rule->
h_u,
1157 if (tab->
index == old_index) {
1158 gfar_set_mask(0xFFFFFFFF, tab);
1159 tab->
fe[tab->
index].ctrl = 0x20;
1160 tab->
fe[tab->
index].prop = 0x0;
1165 tab->
fe[tab->
index - 1].ctrl &= (~RQFCR_AND);
1174 if (tab->
index > (old_index + 2)) {
1210 length = end - begin;
1213 while (end < tab->
index) {
1214 tab->
fe[begin].ctrl = tab->
fe[
end].ctrl;
1215 tab->
fe[begin++].prop = tab->
fe[end++].prop;
1219 while (begin < tab->index) {
1220 tab->
fe[begin].ctrl = 0x60;
1221 tab->
fe[begin].prop = 0xFFFFFFFF;
1230 static int gfar_expand_filer_entries(
u32 begin,
u32 length,
1237 gfar_copy_filer_entries(&(tab->
fe[begin + length]), &(tab->
fe[begin]),
1238 tab->
index - length + 1);
1248 if ((tab->
fe[start].ctrl & (RQFCR_AND | RQFCR_CLE)) ==
1255 static int gfar_get_next_cluster_end(
int start,
struct filer_table *tab)
1259 if ((tab->
fe[start].ctrl & (RQFCR_AND | RQFCR_CLE)) ==
1269 static void gfar_cluster_filer(
struct filer_table *tab)
1271 s32 i = -1,
j, iend, jend;
1273 while ((i = gfar_get_next_cluster_start(++i, tab)) != -1) {
1275 while ((j = gfar_get_next_cluster_start(++j, tab)) != -1) {
1279 if (tab->
fe[i].ctrl != tab->
fe[j].ctrl)
1281 if (tab->
fe[i].prop != tab->
fe[j].prop)
1283 if (tab->
fe[i - 1].ctrl != tab->
fe[j - 1].ctrl)
1285 if (tab->
fe[i - 1].prop != tab->
fe[j - 1].prop)
1287 iend = gfar_get_next_cluster_end(i, tab);
1288 jend = gfar_get_next_cluster_end(j, tab);
1289 if (jend == -1 || iend == -1)
1296 if (gfar_expand_filer_entries(iend, (jend - j), tab) ==
1300 gfar_copy_filer_entries(&(tab->
fe[iend + 1]),
1301 &(tab->
fe[jend + 1]), jend - j);
1303 if (gfar_trim_filer_entries(jend - 1,
1331 a1->
ctrl |= temp[1];
1332 a2->
ctrl |= temp[0];
1333 b1->
ctrl |= temp[3];
1334 b2->
ctrl |= temp[2];
1346 for (i = 0; i < tab->
index; i++) {
1349 if (!(tab->
fe[i].ctrl & 0xF)) {
1350 mask_table[and_index].
mask = tab->
fe[
i].prop;
1351 mask_table[and_index].
start =
i;
1354 mask_table[and_index - 1].
end = i - 1;
1360 if (tab->
fe[i].ctrl & RQFCR_CLE)
1363 if (!(tab->
fe[i].ctrl & RQFCR_AND))
1367 mask_table[and_index - 1].
end = i - 1;
1381 int (*gfar_comp)(
const void *,
const void *);
1383 u32 i, size = 0, start = 0,
prev = 1;
1384 u32 old_first, old_last, new_first, new_last;
1386 gfar_comp = &gfar_comp_desc;
1388 for (i = 0; i < and_index; i++) {
1391 old_last = mask_table[i - 1].
end;
1392 sort(mask_table + start, size,
1394 gfar_comp, &gfar_swap);
1399 if (gfar_comp == gfar_comp_desc)
1400 gfar_comp = &gfar_comp_asc;
1402 gfar_comp = &gfar_comp_desc;
1405 new_last = mask_table[i - 1].
end;
1407 gfar_swap_bits(&temp_table->
fe[new_first],
1408 &temp_table->
fe[old_first],
1409 &temp_table->
fe[new_last],
1410 &temp_table->
fe[old_last],
1428 static int gfar_optimize_filer_masks(
struct filer_table *tab)
1433 u32 and_index = 0, previous_mask = 0, i = 0, j = 0, size = 0;
1440 if (temp_table ==
NULL)
1446 if (mask_table ==
NULL) {
1451 and_index = gfar_generate_mask_table(mask_table, tab);
1453 gfar_sort_mask_table(mask_table, temp_table, and_index);
1458 for (i = 0; i < and_index; i++) {
1459 size = mask_table[
i].
end - mask_table[
i].
start + 1;
1460 gfar_copy_filer_entries(&(tab->
fe[j]),
1461 &(temp_table->
fe[mask_table[i].
start]), size);
1469 if (tab->
fe[i].ctrl == 0x80) {
1470 previous_mask = i++;
1475 if (tab->
fe[i].ctrl == 0x80) {
1476 if (tab->
fe[i].prop == tab->
fe[previous_mask].prop) {
1480 gfar_trim_filer_entries(i, i, tab);
1488 end:
kfree(temp_table);
1493 static int gfar_write_filer_table(
struct gfar_private *priv,
1497 if (tab->
index > MAX_FILER_IDX - 1)
1504 for (; i < MAX_FILER_IDX - 1 && (tab->
fe[
i].ctrl | tab->
fe[
i].ctrl);
1506 gfar_write_filer(priv, i, tab->
fe[i].ctrl, tab->
fe[i].prop);
1508 for (; i < MAX_FILER_IDX - 1; i++)
1509 gfar_write_filer(priv, i, 0x60, 0xFFFFFFFF);
1513 gfar_write_filer(priv, i, 0x20, 0x0);
1525 if (~flow->
m_ext.data[0] || ~flow->
m_ext.data[1])
1526 netdev_warn(priv->
ndev,
1527 "User-specific data not supported!\n");
1528 if (~flow->
m_ext.vlan_etype)
1529 netdev_warn(priv->
ndev,
1530 "VLAN-etype not supported!\n");
1534 netdev_warn(priv->
ndev,
1535 "IP-Version differing from IPv4 not supported!\n");
1540 static int gfar_process_filer_changes(
struct gfar_private *priv)
1556 ret = gfar_convert_to_filer(&j->
fs, tab);
1557 if (ret == -
EBUSY) {
1558 netdev_err(priv->
ndev,
1559 "Rule not added: No free space!\n");
1563 netdev_err(priv->
ndev,
1564 "Rule not added: Unsupported Flow-type!\n");
1572 gfar_cluster_filer(tab);
1573 gfar_optimize_filer_masks(tab);
1576 "\tData on hardware: %d\n"
1577 "\tCompression rate: %d%%\n",
1581 ret = gfar_write_filer_table(priv, tab);
1582 if (ret == -
EBUSY) {
1583 netdev_err(priv->
ndev,
"Rule not added: No free space!\n");
1596 for (i = 0; i <
sizeof(flow->
m_u); i++)
1599 flow->
m_ext.vlan_etype ^= 0xFFFF;
1600 flow->
m_ext.vlan_tci ^= 0xFFFF;
1601 flow->
m_ext.data[0] ^= ~0;
1602 flow->
m_ext.data[1] ^= ~0;
1616 gfar_invert_masks(&temp->
fs);
1617 ret = gfar_check_capability(&temp->
fs, priv);
1621 if (list_empty(&priv->
rx_list.list)) {
1622 ret = gfar_check_filer_hardware(priv);
1634 netdev_err(priv->
ndev,
1635 "Rule not added: ID %d not free!\n",
1645 ret = gfar_process_filer_changes(priv);
1663 if (list_empty(&priv->
rx_list.list))
1667 if (comp->
fs.location == loc) {
1671 gfar_process_filer_changes(priv);
1686 if (comp->
fs.location == cmd->
fs.location) {
1688 gfar_invert_masks(&cmd->
fs);
1706 rule_locs[
i] = comp->
fs.location;
1725 ret = gfar_set_hash_opts(priv, cmd);
1730 cmd->
fs.location >= MAX_FILER_IDX) {
1734 ret = gfar_add_cls(priv, &cmd->
fs);
1737 ret = gfar_del_cls(priv, cmd->
fs.location);
1762 ret = gfar_get_cls(priv, cmd);
1765 ret = gfar_get_cls_all(priv, cmd, rule_locs);
1778 static int gfar_get_ts_info(
struct net_device *dev,
1801 .get_settings = gfar_gsettings,
1802 .set_settings = gfar_ssettings,
1803 .get_drvinfo = gfar_gdrvinfo,
1804 .get_regs_len = gfar_reglen,
1805 .get_regs = gfar_get_regs,
1807 .get_coalesce = gfar_gcoalesce,
1808 .set_coalesce = gfar_scoalesce,
1809 .get_ringparam = gfar_gringparam,
1810 .set_ringparam = gfar_sringparam,
1811 .get_strings = gfar_gstrings,
1812 .get_sset_count = gfar_sset_count,
1813 .get_ethtool_stats = gfar_fill_stats,
1814 .get_msglevel = gfar_get_msglevel,
1815 .set_msglevel = gfar_set_msglevel,
1817 .get_wol = gfar_get_wol,
1818 .set_wol = gfar_set_wol,
1820 .set_rxnfc = gfar_set_nfc,
1821 .get_rxnfc = gfar_get_nfc,
1822 .get_ts_info = gfar_get_ts_info,