blob: f46e2cea8ca9bf7030d91a8ba1029f7ba324e30e [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
Ben Hutchings0a6f40c2011-02-25 00:01:34 +00004 * Copyright 2006-2011 Solarflare Communications Inc.
Ben Hutchings8ceee662008-04-27 12:55:59 +01005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
Ben Hutchings744093c2009-11-29 15:12:08 +000011#ifndef EFX_NIC_H
12#define EFX_NIC_H
Ben Hutchings8ceee662008-04-27 12:55:59 +010013
Ben Hutchings5c16a962009-11-23 16:05:28 +000014#include <linux/i2c-algo-bit.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010015#include "net_driver.h"
Ben Hutchings177dfcd2008-12-12 21:50:08 -080016#include "efx.h"
Ben Hutchings8880f4e2009-11-29 15:15:41 +000017#include "mcdi.h"
Ben Hutchings4de92182010-12-02 13:47:29 +000018#include "spi.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010019
20/*
21 * Falcon hardware control
22 */
23
Ben Hutchingsdaeda632009-11-28 05:36:04 +000024enum {
25 EFX_REV_FALCON_A0 = 0,
26 EFX_REV_FALCON_A1 = 1,
27 EFX_REV_FALCON_B0 = 2,
Ben Hutchings8880f4e2009-11-29 15:15:41 +000028 EFX_REV_SIENA_A0 = 3,
Ben Hutchings8ceee662008-04-27 12:55:59 +010029};
30
Ben Hutchingsdaeda632009-11-28 05:36:04 +000031static inline int efx_nic_rev(struct efx_nic *efx)
Ben Hutchings55668612008-05-16 21:16:10 +010032{
Ben Hutchingsdaeda632009-11-28 05:36:04 +000033 return efx->type->revision;
Ben Hutchings55668612008-05-16 21:16:10 +010034}
Ben Hutchings8ceee662008-04-27 12:55:59 +010035
Ben Hutchings152b6a62009-11-29 03:43:56 +000036extern u32 efx_nic_fpga_ver(struct efx_nic *efx);
37
38/* NIC has two interlinked PCI functions for the same port. */
39static inline bool efx_nic_is_dual_func(struct efx_nic *efx)
40{
41 return efx_nic_rev(efx) < EFX_REV_FALCON_B0;
42}
43
Ben Hutchingsc1c4f452009-11-29 15:08:55 +000044enum {
45 PHY_TYPE_NONE = 0,
46 PHY_TYPE_TXC43128 = 1,
47 PHY_TYPE_88E1111 = 2,
48 PHY_TYPE_SFX7101 = 3,
49 PHY_TYPE_QT2022C2 = 4,
50 PHY_TYPE_PM8358 = 6,
51 PHY_TYPE_SFT9001A = 8,
52 PHY_TYPE_QT2025C = 9,
53 PHY_TYPE_SFT9001B = 10,
54};
55
56#define FALCON_XMAC_LOOPBACKS \
57 ((1 << LOOPBACK_XGMII) | \
58 (1 << LOOPBACK_XGXS) | \
59 (1 << LOOPBACK_XAUI))
60
61#define FALCON_GMAC_LOOPBACKS \
62 (1 << LOOPBACK_GMAC)
63
Ben Hutchings5b6262d2012-02-02 21:21:15 +000064/* Alignment of PCIe DMA boundaries (4KB) */
65#define EFX_PAGE_SIZE 4096
66/* Size and alignment of buffer table entries (same) */
67#define EFX_BUF_SIZE EFX_PAGE_SIZE
68
Ben Hutchings5c16a962009-11-23 16:05:28 +000069/**
Ben Hutchings44838a42009-11-25 16:09:41 +000070 * struct falcon_board_type - board operations and type information
71 * @id: Board type id, as found in NVRAM
72 * @ref_model: Model number of Solarflare reference design
73 * @gen_type: Generic board type description
Ben Hutchings37594332009-11-23 16:05:45 +000074 * @init: Allocate resources and initialise peripheral hardware
75 * @init_phy: Do board-specific PHY initialisation
Ben Hutchings44838a42009-11-25 16:09:41 +000076 * @fini: Shut down hardware and free resources
Ben Hutchings37594332009-11-23 16:05:45 +000077 * @set_id_led: Set state of identifying LED or revert to automatic function
78 * @monitor: Board-specific health check function
Ben Hutchings44838a42009-11-25 16:09:41 +000079 */
80struct falcon_board_type {
81 u8 id;
82 const char *ref_model;
83 const char *gen_type;
84 int (*init) (struct efx_nic *nic);
85 void (*init_phy) (struct efx_nic *efx);
86 void (*fini) (struct efx_nic *nic);
87 void (*set_id_led) (struct efx_nic *efx, enum efx_led_mode mode);
88 int (*monitor) (struct efx_nic *nic);
89};
90
91/**
92 * struct falcon_board - board information
93 * @type: Type of board
94 * @major: Major rev. ('A', 'B' ...)
95 * @minor: Minor rev. (0, 1, ...)
Ben Hutchingse775fb92009-11-23 16:06:02 +000096 * @i2c_adap: I2C adapter for on-board peripherals
97 * @i2c_data: Data for bit-banging algorithm
Ben Hutchings37594332009-11-23 16:05:45 +000098 * @hwmon_client: I2C client for hardware monitor
99 * @ioexp_client: I2C client for power/port control
100 */
101struct falcon_board {
Ben Hutchings44838a42009-11-25 16:09:41 +0000102 const struct falcon_board_type *type;
Ben Hutchings37594332009-11-23 16:05:45 +0000103 int major;
104 int minor;
Ben Hutchingse775fb92009-11-23 16:06:02 +0000105 struct i2c_adapter i2c_adap;
106 struct i2c_algo_bit_data i2c_data;
Ben Hutchings37594332009-11-23 16:05:45 +0000107 struct i2c_client *hwmon_client, *ioexp_client;
108};
109
110/**
Ben Hutchings5c16a962009-11-23 16:05:28 +0000111 * struct falcon_nic_data - Falcon NIC state
Ben Hutchings89863522009-11-25 16:09:04 +0000112 * @pci_dev2: Secondary function of Falcon A
Ben Hutchings37594332009-11-23 16:05:45 +0000113 * @board: Board state and functions
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000114 * @stats_disable_count: Nest count for disabling statistics fetches
115 * @stats_pending: Is there a pending DMA of MAC statistics.
116 * @stats_timer: A timer for regularly fetching MAC statistics.
117 * @stats_dma_done: Pointer to the flag which indicates DMA completion.
Ben Hutchings4de92182010-12-02 13:47:29 +0000118 * @spi_flash: SPI flash device
119 * @spi_eeprom: SPI EEPROM device
120 * @spi_lock: SPI bus lock
Ben Hutchings4833f022010-12-02 13:47:35 +0000121 * @mdio_lock: MDIO bus lock
Ben Hutchingscef68bd2010-12-02 13:47:51 +0000122 * @xmac_poll_required: XMAC link state needs polling
Ben Hutchings5c16a962009-11-23 16:05:28 +0000123 */
124struct falcon_nic_data {
125 struct pci_dev *pci_dev2;
Ben Hutchings37594332009-11-23 16:05:45 +0000126 struct falcon_board board;
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000127 unsigned int stats_disable_count;
128 bool stats_pending;
129 struct timer_list stats_timer;
130 u32 *stats_dma_done;
Ben Hutchings4de92182010-12-02 13:47:29 +0000131 struct efx_spi_device spi_flash;
132 struct efx_spi_device spi_eeprom;
133 struct mutex spi_lock;
Ben Hutchings4833f022010-12-02 13:47:35 +0000134 struct mutex mdio_lock;
Ben Hutchingscef68bd2010-12-02 13:47:51 +0000135 bool xmac_poll_required;
Ben Hutchings5c16a962009-11-23 16:05:28 +0000136};
137
Ben Hutchings278c0622009-11-23 16:05:12 +0000138static inline struct falcon_board *falcon_board(struct efx_nic *efx)
139{
Ben Hutchings37594332009-11-23 16:05:45 +0000140 struct falcon_nic_data *data = efx->nic_data;
141 return &data->board;
Ben Hutchings278c0622009-11-23 16:05:12 +0000142}
143
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000144/**
145 * struct siena_nic_data - Siena NIC state
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000146 * @mcdi: Management-Controller-to-Driver Interface
147 * @wol_filter_id: Wake-on-LAN packet filter id
Ben Hutchings55c5e0f82012-01-06 20:25:39 +0000148 * @hwmon: Hardware monitor state
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000149 */
150struct siena_nic_data {
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000151 struct efx_mcdi_iface mcdi;
152 int wol_filter_id;
Ben Hutchings55c5e0f82012-01-06 20:25:39 +0000153#ifdef CONFIG_SFC_MCDI_MON
154 struct efx_mcdi_mon hwmon;
155#endif
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000156};
157
Ben Hutchings55c5e0f82012-01-06 20:25:39 +0000158#ifdef CONFIG_SFC_MCDI_MON
159static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx)
160{
161 struct siena_nic_data *nic_data;
162 EFX_BUG_ON_PARANOID(efx_nic_rev(efx) < EFX_REV_SIENA_A0);
163 nic_data = efx->nic_data;
164 return &nic_data->hwmon;
165}
166#endif
167
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000168/*
169 * On the SFC9000 family each port is associated with 1 PCI physical
170 * function (PF) handled by sfc and a configurable number of virtual
171 * functions (VFs) that may be handled by some other driver, often in
172 * a VM guest. The queue pointer registers are mapped in both PF and
173 * VF BARs such that an 8K region provides access to a single RX, TX
174 * and event queue (collectively a Virtual Interface, VI or VNIC).
175 *
176 * The PF has access to all 1024 VIs while VFs are mapped to VIs
177 * according to VI_BASE and VI_SCALE: VF i has access to VIs numbered
178 * in range [VI_BASE + i << VI_SCALE, VI_BASE + i + 1 << VI_SCALE).
179 * The number of VIs and the VI_SCALE value are configurable but must
180 * be established at boot time by firmware.
181 */
182
183/* Maximum VI_SCALE parameter supported by Siena */
184#define EFX_VI_SCALE_MAX 6
185/* Base VI to use for SR-IOV. Must be aligned to (1 << EFX_VI_SCALE_MAX),
186 * so this is the smallest allowed value. */
187#define EFX_VI_BASE 128U
188/* Maximum number of VFs allowed */
189#define EFX_VF_COUNT_MAX 127
190/* Limit EVQs on VFs to be only 8k to reduce buffer table reservation */
191#define EFX_MAX_VF_EVQ_SIZE 8192UL
192/* The number of buffer table entries reserved for each VI on a VF */
193#define EFX_VF_BUFTBL_PER_VI \
194 ((EFX_MAX_VF_EVQ_SIZE + 2 * EFX_MAX_DMAQ_SIZE) * \
195 sizeof(efx_qword_t) / EFX_BUF_SIZE)
196
197#ifdef CONFIG_SFC_SRIOV
198
199static inline bool efx_sriov_wanted(struct efx_nic *efx)
200{
201 return efx->vf_count != 0;
202}
203static inline bool efx_sriov_enabled(struct efx_nic *efx)
204{
205 return efx->vf_init_count != 0;
206}
207static inline unsigned int efx_vf_size(struct efx_nic *efx)
208{
209 return 1 << efx->vi_scale;
210}
211
212extern int efx_init_sriov(void);
213extern void efx_sriov_probe(struct efx_nic *efx);
214extern int efx_sriov_init(struct efx_nic *efx);
215extern void efx_sriov_mac_address_changed(struct efx_nic *efx);
216extern void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event);
217extern void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event);
218extern void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event);
219extern void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq);
220extern void efx_sriov_flr(struct efx_nic *efx, unsigned flr);
221extern void efx_sriov_reset(struct efx_nic *efx);
222extern void efx_sriov_fini(struct efx_nic *efx);
223extern void efx_fini_sriov(void);
224
225#else
226
227static inline bool efx_sriov_wanted(struct efx_nic *efx) { return false; }
228static inline bool efx_sriov_enabled(struct efx_nic *efx) { return false; }
229static inline unsigned int efx_vf_size(struct efx_nic *efx) { return 0; }
230
231static inline int efx_init_sriov(void) { return 0; }
232static inline void efx_sriov_probe(struct efx_nic *efx) {}
233static inline int efx_sriov_init(struct efx_nic *efx) { return -EOPNOTSUPP; }
234static inline void efx_sriov_mac_address_changed(struct efx_nic *efx) {}
235static inline void efx_sriov_tx_flush_done(struct efx_nic *efx,
236 efx_qword_t *event) {}
237static inline void efx_sriov_rx_flush_done(struct efx_nic *efx,
238 efx_qword_t *event) {}
239static inline void efx_sriov_event(struct efx_channel *channel,
240 efx_qword_t *event) {}
241static inline void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq) {}
242static inline void efx_sriov_flr(struct efx_nic *efx, unsigned flr) {}
243static inline void efx_sriov_reset(struct efx_nic *efx) {}
244static inline void efx_sriov_fini(struct efx_nic *efx) {}
245static inline void efx_fini_sriov(void) {}
246
247#endif
248
249extern int efx_sriov_set_vf_mac(struct net_device *dev, int vf, u8 *mac);
250extern int efx_sriov_set_vf_vlan(struct net_device *dev, int vf,
251 u16 vlan, u8 qos);
252extern int efx_sriov_get_vf_config(struct net_device *dev, int vf,
253 struct ifla_vf_info *ivf);
254extern int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf,
255 bool spoofchk);
256
stephen hemminger6c8c2512011-04-14 05:50:12 +0000257extern const struct efx_nic_type falcon_a1_nic_type;
258extern const struct efx_nic_type falcon_b0_nic_type;
259extern const struct efx_nic_type siena_a0_nic_type;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100260
261/**************************************************************************
262 *
263 * Externs
264 *
265 **************************************************************************
266 */
267
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000268extern int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
Ben Hutchings5087b542009-10-23 08:29:51 +0000269
Ben Hutchings8ceee662008-04-27 12:55:59 +0100270/* TX data path */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000271extern int efx_nic_probe_tx(struct efx_tx_queue *tx_queue);
272extern void efx_nic_init_tx(struct efx_tx_queue *tx_queue);
273extern void efx_nic_fini_tx(struct efx_tx_queue *tx_queue);
274extern void efx_nic_remove_tx(struct efx_tx_queue *tx_queue);
275extern void efx_nic_push_buffers(struct efx_tx_queue *tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100276
277/* RX data path */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000278extern int efx_nic_probe_rx(struct efx_rx_queue *rx_queue);
279extern void efx_nic_init_rx(struct efx_rx_queue *rx_queue);
280extern void efx_nic_fini_rx(struct efx_rx_queue *rx_queue);
281extern void efx_nic_remove_rx(struct efx_rx_queue *rx_queue);
282extern void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue);
Ben Hutchings2ae75da2012-02-07 23:49:52 +0000283extern void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100284
285/* Event data path */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000286extern int efx_nic_probe_eventq(struct efx_channel *channel);
287extern void efx_nic_init_eventq(struct efx_channel *channel);
288extern void efx_nic_fini_eventq(struct efx_channel *channel);
289extern void efx_nic_remove_eventq(struct efx_channel *channel);
290extern int efx_nic_process_eventq(struct efx_channel *channel, int rx_quota);
291extern void efx_nic_eventq_read_ack(struct efx_channel *channel);
Ben Hutchingsd4fabcc2011-04-04 14:22:11 +0100292extern bool efx_nic_event_present(struct efx_channel *channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100293
Ben Hutchings8ceee662008-04-27 12:55:59 +0100294/* MAC/PHY */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100295extern void falcon_drain_tx_fifo(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100296extern void falcon_reconfigure_mac_wrapper(struct efx_nic *efx);
Ben Hutchings710b2082011-09-03 00:15:00 +0100297extern bool falcon_xmac_check_fault(struct efx_nic *efx);
298extern int falcon_reconfigure_xmac(struct efx_nic *efx);
299extern void falcon_update_stats_xmac(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100300
301/* Interrupts and test events */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000302extern int efx_nic_init_interrupt(struct efx_nic *efx);
303extern void efx_nic_enable_interrupts(struct efx_nic *efx);
Ben Hutchingseee6f6a2012-02-28 23:37:35 +0000304extern void efx_nic_event_test_start(struct efx_channel *channel);
305extern void efx_nic_irq_test_start(struct efx_nic *efx);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000306extern void efx_nic_disable_interrupts(struct efx_nic *efx);
307extern void efx_nic_fini_interrupt(struct efx_nic *efx);
308extern irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx);
309extern irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id);
310extern void falcon_irq_ack_a1(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100311
Ben Hutchingseee6f6a2012-02-28 23:37:35 +0000312static inline int efx_nic_event_test_irq_cpu(struct efx_channel *channel)
313{
Ben Hutchingsdd407812012-02-28 23:40:21 +0000314 return ACCESS_ONCE(channel->event_test_cpu);
Ben Hutchingseee6f6a2012-02-28 23:37:35 +0000315}
316static inline int efx_nic_irq_test_irq_cpu(struct efx_nic *efx)
317{
318 return ACCESS_ONCE(efx->last_irq_cpu);
319}
320
Ben Hutchings8ceee662008-04-27 12:55:59 +0100321/* Global Resources */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000322extern int efx_nic_flush_queues(struct efx_nic *efx);
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000323extern void falcon_start_nic_stats(struct efx_nic *efx);
324extern void falcon_stop_nic_stats(struct efx_nic *efx);
Steve Hodgsonb7b40ee2010-04-28 09:28:10 +0000325extern void falcon_setup_xaui(struct efx_nic *efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100326extern int falcon_reset_xaui(struct efx_nic *efx);
Ben Hutchings28e47c42012-02-15 01:58:49 +0000327extern void
328efx_nic_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000329extern void efx_nic_init_common(struct efx_nic *efx);
Ben Hutchings765c9f42010-06-30 05:06:28 +0000330extern void efx_nic_push_rx_indir_table(struct efx_nic *efx);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000331
332int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
333 unsigned int len);
334void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100335
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100336/* Tests */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000337struct efx_nic_register_test {
338 unsigned address;
339 efx_oword_t mask;
340};
341extern int efx_nic_test_registers(struct efx_nic *efx,
342 const struct efx_nic_register_test *regs,
343 size_t n_regs);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100344
Ben Hutchings5b98c1b2010-06-21 03:06:53 +0000345extern size_t efx_nic_get_regs_len(struct efx_nic *efx);
346extern void efx_nic_get_regs(struct efx_nic *efx, void *buf);
347
Ben Hutchings8ceee662008-04-27 12:55:59 +0100348/**************************************************************************
349 *
350 * Falcon MAC stats
351 *
352 **************************************************************************
353 */
354
355#define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset)
356#define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH)
357
358/* Retrieve statistic from statistics block */
359#define FALCON_STAT(efx, falcon_stat, efx_stat) do { \
360 if (FALCON_STAT_WIDTH(falcon_stat) == 16) \
361 (efx)->mac_stats.efx_stat += le16_to_cpu( \
362 *((__force __le16 *) \
363 (efx->stats_buffer.addr + \
364 FALCON_STAT_OFFSET(falcon_stat)))); \
365 else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \
366 (efx)->mac_stats.efx_stat += le32_to_cpu( \
367 *((__force __le32 *) \
368 (efx->stats_buffer.addr + \
369 FALCON_STAT_OFFSET(falcon_stat)))); \
370 else \
371 (efx)->mac_stats.efx_stat += le64_to_cpu( \
372 *((__force __le64 *) \
373 (efx->stats_buffer.addr + \
374 FALCON_STAT_OFFSET(falcon_stat)))); \
375 } while (0)
376
377#define FALCON_MAC_STATS_SIZE 0x100
378
379#define MAC_DATA_LBN 0
380#define MAC_DATA_WIDTH 32
381
Ben Hutchings90893002012-02-10 22:23:41 +0000382extern void efx_generate_event(struct efx_nic *efx, unsigned int evq,
383 efx_qword_t *event);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100384
Ben Hutchings9007b9f2009-11-25 16:12:01 +0000385extern void falcon_poll_xmac(struct efx_nic *efx);
386
Ben Hutchings744093c2009-11-29 15:12:08 +0000387#endif /* EFX_NIC_H */