]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/sxg/sxg_ethtool.c
Staging: sxg: Firmware updates
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / sxg / sxg_ethtool.c
CommitLineData
371d7a9e
MT
1/**************************************************************************
2 *
3 * Copyright (C) 2000-2008 Alacritech, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
15 *
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
27 * SUCH DAMAGE.
28 *
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.
32 *
33 **************************************************************************/
34
35/*
36 * FILENAME: sxg_ethtool.c
37 *
38 * The ethtool support for SXG driver for Alacritech's 10Gbe products.
39 *
40 * NOTE: This is the standard, non-accelerated version of Alacritech's
41 * IS-NIC driver.
42 */
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>
51
52#include "sxg_os.h"
53#include "sxghw.h"
54#include "sxghif.h"
55#include "sxg.h"
56//#include "sxg.c"
a3915dd8
MT
57#define SXG_UCODE_DBG 0 /* Turn on for debugging */
58#ifdef SXG_UCODE_DBG
59#include "saharadbgdownload.c"
60#include "saharadbgdownloadB.c"
61#else
62#include "saharadownload.c"
63#include "saharadownloadB.c"
64#endif
371d7a9e
MT
65
66struct sxg_nic_stats {
67 char stat_string[ETH_GSTRING_LEN];
68 int sizeof_stat;
69 int stat_offset;
70};
71
72#define SXG_NIC_STATS(m) sizeof(((struct adapter_t *)0)->m), \
73 offsetof(struct adapter_t, m)
74
75#define USER_VIEWABLE_EEPROM_SIZE 28
76
77static struct sxg_nic_stats sxg_nic_gstrings_stats[] = {
78 {"xmit_ring_0_full", SXG_NIC_STATS(Stats.XmtZeroFull)},
79
80 /* May be will need in future */
81/* {"dumb_xmit_broadcast_packets", SXG_NIC_STATS(Stats.DumbXmtBcastPkts)},
82 {"dumb_xmit_broadcast_bytes", SXG_NIC_STATS(Stats.DumbXmtBcastBytes)},
83 {"dumb_xmit_unicast_packets", SXG_NIC_STATS(Stats.DumbXmtUcastPkts)},
84 {"dumb_xmit_unicast_bytes", SXG_NIC_STATS(Stats.DumbXmtUcastBytes)},
85*/
86 {"xmit_queue_length", SXG_NIC_STATS(Stats.XmtQLen)},
87 {"memory_allocation_failure", SXG_NIC_STATS(Stats.NoMem)},
88 {"Interrupts", SXG_NIC_STATS(Stats.NumInts)},
89 {"false_interrupts", SXG_NIC_STATS(Stats.FalseInts)},
90 {"processed_data_queue_full", SXG_NIC_STATS(Stats.PdqFull)},
91 {"event_ring_full", SXG_NIC_STATS(Stats.EventRingFull)},
92 {"transport_checksum_error", SXG_NIC_STATS(Stats.TransportCsum)},
93 {"transport_underflow_error", SXG_NIC_STATS(Stats.TransportUflow)},
94 {"transport_header_length_error", SXG_NIC_STATS(Stats.TransportHdrLen)},
95 {"network_checksum_error", SXG_NIC_STATS(Stats.NetworkCsum)},
96 {"network_underflow_error", SXG_NIC_STATS(Stats.NetworkUflow)},
97 {"network_header_length_error", SXG_NIC_STATS(Stats.NetworkHdrLen)},
98 {"receive_parity_error", SXG_NIC_STATS(Stats.Parity)},
99 {"link_parity_error", SXG_NIC_STATS(Stats.LinkParity)},
100 {"link/data early_error", SXG_NIC_STATS(Stats.LinkEarly)},
101 {"buffer_overflow_error", SXG_NIC_STATS(Stats.LinkBufOflow)},
102 {"link_code_error", SXG_NIC_STATS(Stats.LinkCode)},
103 {"dribble nibble", SXG_NIC_STATS(Stats.LinkDribble)},
104 {"CRC_error", SXG_NIC_STATS(Stats.LinkCrc)},
105 {"link_overflow_error", SXG_NIC_STATS(Stats.LinkOflow)},
106 {"link_underflow_error", SXG_NIC_STATS(Stats.LinkUflow)},
107
108 /* May be need in future */
109/* {"dumb_rcv_broadcast_packets", SXG_NIC_STATS(Stats.DumbRcvBcastPkts)},
110 {"dumb_rcv_broadcast_bytes", SXG_NIC_STATS(Stats.DumbRcvBcastBytes)},
111 {"dumb_rcv_multicast_packets", SXG_NIC_STATS(Stats.DumbRcvMcastPkts)},
112 {"dumb_rcv_multicast_bytes", SXG_NIC_STATS(Stats.DumbRcvMcastBytes)},
113 {"dumb_rcv_unicast_packets", SXG_NIC_STATS(Stats.DumbRcvUcastPkts)},
114 {"dumb_rcv_unicast_bytes", SXG_NIC_STATS(Stats.DumbRcvUcastBytes)},
115*/
116 {"no_sgl_buffer", SXG_NIC_STATS(Stats.NoSglBuf)},
117};
118
119#define SXG_NIC_STATS_LEN ARRAY_SIZE(sxg_nic_gstrings_stats)
120
121static inline void sxg_reg32_write(void __iomem *reg, u32 value, bool flush)
122{
123 writel(value, reg);
124 if (flush)
125 mb();
126}
127
128static inline void sxg_reg64_write(struct adapter_t *adapter, void __iomem *reg,
129 u64 value, u32 cpu)
130{
131 u32 value_high = (u32) (value >> 32);
132 u32 value_low = (u32) (value & 0x00000000FFFFFFFF);
133 unsigned long flags;
134
135 spin_lock_irqsave(&adapter->Bit64RegLock, flags);
136 writel(value_high, (void __iomem *)(&adapter->UcodeRegs[cpu].Upper));
137 writel(value_low, reg);
138 spin_unlock_irqrestore(&adapter->Bit64RegLock, flags);
139}
140
141static void
142sxg_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
143{
144 struct adapter_t *adapter = netdev_priv(dev);
145 strncpy(drvinfo->driver, sxg_driver_name, 32);
146 strncpy(drvinfo->version, SXG_DRV_VERSION, 32);
d9d578bf 147// strncpy(drvinfo->fw_version, SAHARA_UCODE_VERS_STRING, 32);
371d7a9e
MT
148 strncpy(drvinfo->bus_info, pci_name(adapter->pcidev), 32);
149 /* TODO : Read the major and minor number of firmware. Is this
150 * from the FLASH/EEPROM or download file ?
151 */
152 /* LINSYS : Check if this is correct or if not find the right value
153 * Also check what is the right EEPROM length : EEPROM_SIZE_XFMR or EEPROM_SIZE_NO_XFMR
154 */
155}
156
157static int sxg_nic_set_settings(struct net_device *netdev,
158 struct ethtool_cmd *ecmd)
159{
160 /* No settings are applicable as we support only 10Gb/FIBRE_media */
161 return -EOPNOTSUPP;
162}
163
164static int
165sxg_nic_get_strings(struct net_device *netdev, u32 stringset, u8 * data)
166{
167 int index;
168
169 switch(stringset) {
170 case ETH_SS_TEST:
171 return -EOPNOTSUPP;
172 break;
173 case ETH_SS_STATS:
174 for (index = 0; index < SXG_NIC_STATS_LEN; index++) {
175 memcpy(data + index * ETH_GSTRING_LEN,
176 sxg_nic_gstrings_stats[index].stat_string,
177 ETH_GSTRING_LEN);
178 }
179 break;
180 }
181}
182
183static void
184sxg_nic_get_ethtool_stats(struct net_device *netdev,
185 struct ethtool_stats *stats, u64 * data)
186{
187 struct adapter_t *adapter = netdev_priv(netdev);
188 int index;
189 for (index = 0; index < SXG_NIC_STATS_LEN; index++) {
190 char *p = (char *)adapter +
191 sxg_nic_gstrings_stats[index].stat_offset;
192 data[index] = (sxg_nic_gstrings_stats[index].sizeof_stat ==
193 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
194 }
195}
196
197static int sxg_nic_get_sset_count(struct net_device *netdev, int sset)
198{
199 switch (sset) {
200 case ETH_SS_STATS:
201 return SXG_NIC_STATS_LEN;
202 default:
203 return -EOPNOTSUPP;
204 }
205}
206
207static int sxg_nic_get_settings(struct net_device *netdev,
208 struct ethtool_cmd *ecmd)
209{
210 struct adapter_t *adapter = netdev_priv(netdev);
211
212 ecmd->supported = SUPPORTED_10000baseT_Full;
213 ecmd->autoneg = AUTONEG_ENABLE; //VSS check This
214 ecmd->transceiver = XCVR_EXTERNAL; //VSS check This
215
216 /* For Fibre Channel */
217 ecmd->supported |= SUPPORTED_FIBRE;
218 ecmd->advertising = (ADVERTISED_10000baseT_Full |
219 ADVERTISED_FIBRE);
220 ecmd->port = PORT_FIBRE;
221
222
223 /* Link Speed */
224 if(adapter->LinkState & SXG_LINK_UP) {
225 ecmd->speed = SPEED_10000; //adapter->LinkSpeed;
226 ecmd->duplex = DUPLEX_FULL;
227 }
228 return 0;
229}
230
231static int sxg_nic_get_rx_csum(struct net_device *netdev)
232{
233 struct adapter_t *adapter = netdev_priv(netdev);
234 return ((adapter->flags & SXG_RCV_IP_CSUM_ENABLED) ||
235 (adapter->flags & SXG_RCV_TCP_CSUM_ENABLED));
236}
237
238static int sxg_nic_set_rx_csum(struct net_device *netdev, u32 data)
239{
240 struct adapter_t *adapter = netdev_priv(netdev);
241 if (data)
242 adapter->flags |= SXG_RCV_IP_CSUM_ENABLED;
243 else
244 adapter->flags &= ~SXG_RCV_IP_CSUM_ENABLED;
245
246 /* Reset the card here (call the reset functions .. currently unavailable)*/
247
248 return 0;
249}
250
251static int sxg_nic_get_regs_len(struct net_device *dev)
252{
253 return (SXG_HWREG_MEMSIZE + SXG_UCODEREG_MEMSIZE);
254}
255
256static void sxg_nic_get_regs(struct net_device *netdev,
257 struct ethtool_regs *regs, void *p)
258{
259 struct adapter_t *adapter = netdev_priv(netdev);
260 struct sxg_hw_regs *HwRegs = adapter->HwRegs;
261 struct sxg_ucode_regs *UcodeRegs = adapter->UcodeRegs;
262 u32 *buff = p;
263
264 memset(p, 0, (sizeof(struct sxg_hw_regs)+sizeof(struct sxg_ucode_regs)));
265 memcpy(buff, HwRegs, sizeof(struct sxg_hw_regs));
266 memcpy((buff+sizeof(struct sxg_hw_regs)), UcodeRegs, sizeof(struct sxg_ucode_regs));
267}
268
269static int sxg_nic_get_wol(struct net_device *netdev,
270 struct ethtool_wolinfo *wol)
271{
272 /* We dont support wake-on-lan */
273 return -EOPNOTSUPP;
274}
275
276static int sxg_nic_get_eeprom_len(struct net_device *netdev)
277{
278 return (USER_VIEWABLE_EEPROM_SIZE);
279}
280
281static int sxg_nic_get_eeprom(struct net_device *netdev,
282 struct ethtool_eeprom *eeprom, u8 *bytes)
283{
284 struct adapter_t *adapter = netdev_priv(netdev);
285 struct sw_cfg_data *data;
286 unsigned long i, status;
287 dma_addr_t p_addr;
288
289 data = pci_alloc_consistent(adapter->pcidev, sizeof(struct sw_cfg_data),
290 &p_addr);
291 if(!data) {
292 /*
293 * We cant get even this much memory. Raise a hell
294 * Get out of here
295 */
296 printk(KERN_ERR"%s : Could not allocate memory for reading \
297 EEPROM\n", __FUNCTION__);
298 return -ENOMEM;
299 }
300
301 WRITE_REG(adapter->UcodeRegs[0].ConfigStat, SXG_CFG_TIMEOUT, TRUE);
302 WRITE_REG64(adapter, adapter->UcodeRegs[0].Config, p_addr, 0);
303 for(i=0; i<1000; i++) {
304 READ_REG(adapter->UcodeRegs[0].ConfigStat, status);
305 if (status != SXG_CFG_TIMEOUT)
306 break;
307 mdelay(1); /* Do we really need this */
308 }
309
310 memset(bytes, 0, eeprom->len);
311 memcpy(bytes, data->MacAddr[0].MacAddr, sizeof(struct sxg_config_mac));
312 memcpy(bytes+6, data->AtkFru.PartNum, 6);
313 memcpy(bytes+12, data->AtkFru.Revision, 2);
314 memcpy(bytes+14, data->AtkFru.Serial, 14);
315
316 return 0;
317}
318
319struct ethtool_ops sxg_nic_ethtool_ops = {
320 .get_settings = sxg_nic_get_settings,
321 .set_settings = sxg_nic_set_settings,
322 .get_drvinfo = sxg_nic_get_drvinfo,
323 .get_regs_len = sxg_nic_get_regs_len,
324 .get_regs = sxg_nic_get_regs,
325 .get_link = ethtool_op_get_link,
326 .get_wol = sxg_nic_get_wol,
327 .get_eeprom_len = sxg_nic_get_eeprom_len,
328 .get_eeprom = sxg_nic_get_eeprom,
329// .get_ringparam = sxg_nic_get_ringparam,
330// .get_pauseparam = sxg_nic_get_pauseparam,
331// .set_pauseparam = sxg_nic_set_pauseparam,
332 .set_tx_csum = ethtool_op_set_tx_csum,
333 .get_sg = ethtool_op_get_sg,
334 .set_sg = ethtool_op_set_sg,
335// .get_tso = sxg_nic_get_tso,
336// .set_tso = sxg_nic_set_tso,
337// .self_test = sxg_nic_diag_test,
338 .get_strings = sxg_nic_get_strings,
339 .get_ethtool_stats = sxg_nic_get_ethtool_stats,
340 .get_sset_count = sxg_nic_get_sset_count,
341 .get_rx_csum = sxg_nic_get_rx_csum,
342 .set_rx_csum = sxg_nic_set_rx_csum,
343// .get_coalesce = sxg_nic_get_intr_coalesce,
344// .set_coalesce = sxg_nic_set_intr_coalesce,
345};