1 /**************************************************************************
3 * Copyright (C) 2000-2008 Alacritech, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALACRITECH, INC. OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * The views and conclusions contained in the software and documentation
30 * are those of the authors and should not be interpreted as representing
31 * official policies, either expressed or implied, of Alacritech, Inc.
33 **************************************************************************/
36 * FILENAME: sxg_ethtool.c
38 * The ethtool support for SXG driver for Alacritech's 10Gbe products.
40 * NOTE: This is the standard, non-accelerated version of Alacritech's
43 #include <linux/kernel.h>
44 #include <linux/errno.h>
45 #include <linux/module.h>
46 #include <linux/netdevice.h>
47 #include <linux/etherdevice.h>
48 #include <linux/ethtool.h>
49 #include <linux/skbuff.h>
50 #include <linux/pci.h>
57 struct sxg_nic_stats {
58 char stat_string[ETH_GSTRING_LEN];
63 #define SXG_NIC_STATS(m) sizeof(((struct adapter_t *)0)->m), \
64 offsetof(struct adapter_t, m)
66 #define USER_VIEWABLE_EEPROM_SIZE 28
68 static struct sxg_nic_stats sxg_nic_gstrings_stats[] = {
69 {"xmit_ring_0_full", SXG_NIC_STATS(Stats.XmtZeroFull)},
71 /* May be will need in future */
72 /* {"dumb_xmit_broadcast_packets", SXG_NIC_STATS(Stats.DumbXmtBcastPkts)},
73 {"dumb_xmit_broadcast_bytes", SXG_NIC_STATS(Stats.DumbXmtBcastBytes)},
74 {"dumb_xmit_unicast_packets", SXG_NIC_STATS(Stats.DumbXmtUcastPkts)},
75 {"dumb_xmit_unicast_bytes", SXG_NIC_STATS(Stats.DumbXmtUcastBytes)},
77 {"xmit_queue_length", SXG_NIC_STATS(Stats.XmtQLen)},
78 {"memory_allocation_failure", SXG_NIC_STATS(Stats.NoMem)},
79 {"Interrupts", SXG_NIC_STATS(Stats.NumInts)},
80 {"false_interrupts", SXG_NIC_STATS(Stats.FalseInts)},
81 {"processed_data_queue_full", SXG_NIC_STATS(Stats.PdqFull)},
82 {"event_ring_full", SXG_NIC_STATS(Stats.EventRingFull)},
83 {"transport_checksum_error", SXG_NIC_STATS(Stats.TransportCsum)},
84 {"transport_underflow_error", SXG_NIC_STATS(Stats.TransportUflow)},
85 {"transport_header_length_error", SXG_NIC_STATS(Stats.TransportHdrLen)},
86 {"network_checksum_error", SXG_NIC_STATS(Stats.NetworkCsum)},
87 {"network_underflow_error", SXG_NIC_STATS(Stats.NetworkUflow)},
88 {"network_header_length_error", SXG_NIC_STATS(Stats.NetworkHdrLen)},
89 {"receive_parity_error", SXG_NIC_STATS(Stats.Parity)},
90 {"link_parity_error", SXG_NIC_STATS(Stats.LinkParity)},
91 {"link/data early_error", SXG_NIC_STATS(Stats.LinkEarly)},
92 {"buffer_overflow_error", SXG_NIC_STATS(Stats.LinkBufOflow)},
93 {"link_code_error", SXG_NIC_STATS(Stats.LinkCode)},
94 {"dribble nibble", SXG_NIC_STATS(Stats.LinkDribble)},
95 {"CRC_error", SXG_NIC_STATS(Stats.LinkCrc)},
96 {"link_overflow_error", SXG_NIC_STATS(Stats.LinkOflow)},
97 {"link_underflow_error", SXG_NIC_STATS(Stats.LinkUflow)},
99 /* May be need in future */
100 /* {"dumb_rcv_broadcast_packets", SXG_NIC_STATS(Stats.DumbRcvBcastPkts)},
101 {"dumb_rcv_broadcast_bytes", SXG_NIC_STATS(Stats.DumbRcvBcastBytes)},
102 {"dumb_rcv_multicast_packets", SXG_NIC_STATS(Stats.DumbRcvMcastPkts)},
103 {"dumb_rcv_multicast_bytes", SXG_NIC_STATS(Stats.DumbRcvMcastBytes)},
104 {"dumb_rcv_unicast_packets", SXG_NIC_STATS(Stats.DumbRcvUcastPkts)},
105 {"dumb_rcv_unicast_bytes", SXG_NIC_STATS(Stats.DumbRcvUcastBytes)},
107 {"no_sgl_buffer", SXG_NIC_STATS(Stats.NoSglBuf)},
110 #define SXG_NIC_STATS_LEN ARRAY_SIZE(sxg_nic_gstrings_stats)
112 static inline void sxg_reg32_write(void __iomem *reg, u32 value, bool flush)
119 static inline void sxg_reg64_write(struct adapter_t *adapter, void __iomem *reg,
122 u32 value_high = (u32) (value >> 32);
123 u32 value_low = (u32) (value & 0x00000000FFFFFFFF);
126 spin_lock_irqsave(&adapter->Bit64RegLock, flags);
127 writel(value_high, (void __iomem *)(&adapter->UcodeRegs[cpu].Upper));
128 writel(value_low, reg);
129 spin_unlock_irqrestore(&adapter->Bit64RegLock, flags);
133 sxg_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
135 struct adapter_t *adapter = netdev_priv(dev);
136 strncpy(drvinfo->driver, sxg_driver_name, 32);
137 strncpy(drvinfo->version, SXG_DRV_VERSION, 32);
138 // strncpy(drvinfo->fw_version, SAHARA_UCODE_VERS_STRING, 32);
139 strncpy(drvinfo->bus_info, pci_name(adapter->pcidev), 32);
140 /* TODO : Read the major and minor number of firmware. Is this
141 * from the FLASH/EEPROM or download file ?
143 /* LINSYS : Check if this is correct or if not find the right value
144 * Also check what is the right EEPROM length : EEPROM_SIZE_XFMR or EEPROM_SIZE_NO_XFMR
148 static int sxg_nic_set_settings(struct net_device *netdev,
149 struct ethtool_cmd *ecmd)
151 /* No settings are applicable as we support only 10Gb/FIBRE_media */
156 sxg_nic_get_strings(struct net_device *netdev, u32 stringset, u8 * data)
162 /* return -EOPNOTSUPP; */
165 for (index = 0; index < SXG_NIC_STATS_LEN; index++) {
166 memcpy(data + index * ETH_GSTRING_LEN,
167 sxg_nic_gstrings_stats[index].stat_string,
175 sxg_nic_get_ethtool_stats(struct net_device *netdev,
176 struct ethtool_stats *stats, u64 * data)
178 struct adapter_t *adapter = netdev_priv(netdev);
180 for (index = 0; index < SXG_NIC_STATS_LEN; index++) {
181 char *p = (char *)adapter +
182 sxg_nic_gstrings_stats[index].stat_offset;
183 data[index] = (sxg_nic_gstrings_stats[index].sizeof_stat ==
184 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
188 static int sxg_nic_get_sset_count(struct net_device *netdev, int sset)
192 return SXG_NIC_STATS_LEN;
198 static int sxg_nic_get_settings(struct net_device *netdev,
199 struct ethtool_cmd *ecmd)
201 struct adapter_t *adapter = netdev_priv(netdev);
203 ecmd->supported = SUPPORTED_10000baseT_Full;
204 ecmd->autoneg = AUTONEG_ENABLE; //VSS check This
205 ecmd->transceiver = XCVR_EXTERNAL; //VSS check This
207 /* For Fibre Channel */
208 ecmd->supported |= SUPPORTED_FIBRE;
209 ecmd->advertising = (ADVERTISED_10000baseT_Full |
211 ecmd->port = PORT_FIBRE;
215 if(adapter->LinkState & SXG_LINK_UP) {
216 ecmd->speed = SPEED_10000; //adapter->LinkSpeed;
217 ecmd->duplex = DUPLEX_FULL;
222 static u32 sxg_nic_get_rx_csum(struct net_device *netdev)
224 struct adapter_t *adapter = netdev_priv(netdev);
225 return ((adapter->flags & SXG_RCV_IP_CSUM_ENABLED) ||
226 (adapter->flags & SXG_RCV_TCP_CSUM_ENABLED));
229 static int sxg_nic_set_rx_csum(struct net_device *netdev, u32 data)
231 struct adapter_t *adapter = netdev_priv(netdev);
233 adapter->flags |= SXG_RCV_IP_CSUM_ENABLED;
235 adapter->flags &= ~SXG_RCV_IP_CSUM_ENABLED;
237 /* Reset the card here (call the reset functions .. currently unavailable)*/
242 static int sxg_nic_get_regs_len(struct net_device *dev)
244 return (SXG_HWREG_MEMSIZE + SXG_UCODEREG_MEMSIZE);
247 static void sxg_nic_get_regs(struct net_device *netdev,
248 struct ethtool_regs *regs, void *p)
250 struct adapter_t *adapter = netdev_priv(netdev);
251 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
252 struct sxg_ucode_regs *UcodeRegs = adapter->UcodeRegs;
255 memset(p, 0, (sizeof(struct sxg_hw_regs)+sizeof(struct sxg_ucode_regs)));
256 memcpy(buff, HwRegs, sizeof(struct sxg_hw_regs));
257 memcpy((buff+sizeof(struct sxg_hw_regs)), UcodeRegs, sizeof(struct sxg_ucode_regs));
260 static void sxg_nic_get_wol(struct net_device *netdev,
261 struct ethtool_wolinfo *wol)
263 /* We dont support wake-on-lan */
265 memset(&wol->sopass, 0, sizeof(wol->sopass));
268 static int sxg_nic_get_eeprom_len(struct net_device *netdev)
270 return (USER_VIEWABLE_EEPROM_SIZE);
273 static int sxg_nic_get_eeprom(struct net_device *netdev,
274 struct ethtool_eeprom *eeprom, u8 *bytes)
276 struct adapter_t *adapter = netdev_priv(netdev);
277 struct sw_cfg_data *data;
278 unsigned long i, status;
281 data = pci_alloc_consistent(adapter->pcidev, sizeof(struct sw_cfg_data),
285 * We cant get even this much memory. Raise a hell
288 printk(KERN_ERR"%s : Could not allocate memory for reading \
289 EEPROM\n", __FUNCTION__);
293 WRITE_REG(adapter->UcodeRegs[0].ConfigStat, SXG_CFG_TIMEOUT, TRUE);
294 WRITE_REG64(adapter, adapter->UcodeRegs[0].Config, p_addr, 0);
295 for(i=0; i<1000; i++) {
296 READ_REG(adapter->UcodeRegs[0].ConfigStat, status);
297 if (status != SXG_CFG_TIMEOUT)
299 mdelay(1); /* Do we really need this */
302 memset(bytes, 0, eeprom->len);
303 memcpy(bytes, data->MacAddr[0].MacAddr, sizeof(struct sxg_config_mac));
304 memcpy(bytes+6, data->AtkFru.PartNum, 6);
305 memcpy(bytes+12, data->AtkFru.Revision, 2);
306 memcpy(bytes+14, data->AtkFru.Serial, 14);
311 struct ethtool_ops sxg_nic_ethtool_ops = {
312 .get_settings = sxg_nic_get_settings,
313 .set_settings = sxg_nic_set_settings,
314 .get_drvinfo = sxg_nic_get_drvinfo,
315 .get_regs_len = sxg_nic_get_regs_len,
316 .get_regs = sxg_nic_get_regs,
317 .get_link = ethtool_op_get_link,
318 .get_wol = sxg_nic_get_wol,
319 .get_eeprom_len = sxg_nic_get_eeprom_len,
320 .get_eeprom = sxg_nic_get_eeprom,
321 // .get_ringparam = sxg_nic_get_ringparam,
322 // .get_pauseparam = sxg_nic_get_pauseparam,
323 // .set_pauseparam = sxg_nic_set_pauseparam,
324 .set_tx_csum = ethtool_op_set_tx_csum,
325 .get_sg = ethtool_op_get_sg,
326 .set_sg = ethtool_op_set_sg,
327 // .get_tso = sxg_nic_get_tso,
328 // .set_tso = sxg_nic_set_tso,
329 // .self_test = sxg_nic_diag_test,
330 .get_strings = sxg_nic_get_strings,
331 .get_ethtool_stats = sxg_nic_get_ethtool_stats,
332 .get_sset_count = sxg_nic_get_sset_count,
333 .get_rx_csum = sxg_nic_get_rx_csum,
334 .set_rx_csum = sxg_nic_set_rx_csum,
335 // .get_coalesce = sxg_nic_get_intr_coalesce,
336 // .set_coalesce = sxg_nic_set_intr_coalesce,