162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2013 Johannes Berg <johannes@sipsolutions.net>
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci *  This file is free software: you may copy, redistribute and/or modify it
562306a36Sopenharmony_ci *  under the terms of the GNU General Public License as published by the
662306a36Sopenharmony_ci *  Free Software Foundation, either version 2 of the License, or (at your
762306a36Sopenharmony_ci *  option) any later version.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci *  This file is distributed in the hope that it will be useful, but
1062306a36Sopenharmony_ci *  WITHOUT ANY WARRANTY; without even the implied warranty of
1162306a36Sopenharmony_ci *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1262306a36Sopenharmony_ci *  General Public License for more details.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci *  You should have received a copy of the GNU General Public License
1562306a36Sopenharmony_ci *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * This file incorporates work covered by the following copyright and
1862306a36Sopenharmony_ci * permission notice:
1962306a36Sopenharmony_ci *
2062306a36Sopenharmony_ci * Copyright (c) 2012 Qualcomm Atheros, Inc.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
2362306a36Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
2462306a36Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2762306a36Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
2862306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
2962306a36Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3062306a36Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3162306a36Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3262306a36Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3362306a36Sopenharmony_ci */
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#ifndef _ALX_H_
3662306a36Sopenharmony_ci#define _ALX_H_
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#include <linux/types.h>
3962306a36Sopenharmony_ci#include <linux/etherdevice.h>
4062306a36Sopenharmony_ci#include <linux/dma-mapping.h>
4162306a36Sopenharmony_ci#include <linux/spinlock.h>
4262306a36Sopenharmony_ci#include "hw.h"
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#define ALX_WATCHDOG_TIME   (5 * HZ)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_cistruct alx_buffer {
4762306a36Sopenharmony_ci	struct sk_buff *skb;
4862306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_ADDR(dma);
4962306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_LEN(size);
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistruct alx_rx_queue {
5362306a36Sopenharmony_ci	struct net_device *netdev;
5462306a36Sopenharmony_ci	struct device *dev;
5562306a36Sopenharmony_ci	struct alx_napi *np;
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci	struct alx_rrd *rrd;
5862306a36Sopenharmony_ci	dma_addr_t rrd_dma;
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	struct alx_rfd *rfd;
6162306a36Sopenharmony_ci	dma_addr_t rfd_dma;
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	struct alx_buffer *bufs;
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci	u16 count;
6662306a36Sopenharmony_ci	u16 write_idx, read_idx;
6762306a36Sopenharmony_ci	u16 rrd_read_idx;
6862306a36Sopenharmony_ci	u16 queue_idx;
6962306a36Sopenharmony_ci};
7062306a36Sopenharmony_ci#define ALX_RX_ALLOC_THRESH	32
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_cistruct alx_tx_queue {
7362306a36Sopenharmony_ci	struct net_device *netdev;
7462306a36Sopenharmony_ci	struct device *dev;
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	struct alx_txd *tpd;
7762306a36Sopenharmony_ci	dma_addr_t tpd_dma;
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci	struct alx_buffer *bufs;
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci	u16 count;
8262306a36Sopenharmony_ci	u16 write_idx, read_idx;
8362306a36Sopenharmony_ci	u16 queue_idx;
8462306a36Sopenharmony_ci	u16 p_reg, c_reg;
8562306a36Sopenharmony_ci};
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define ALX_DEFAULT_TX_WORK 128
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cienum alx_device_quirks {
9062306a36Sopenharmony_ci	ALX_DEV_QUIRK_MSI_INTX_DISABLE_BUG = BIT(0),
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_cistruct alx_napi {
9462306a36Sopenharmony_ci	struct napi_struct	napi;
9562306a36Sopenharmony_ci	struct alx_priv		*alx;
9662306a36Sopenharmony_ci	struct alx_rx_queue	*rxq;
9762306a36Sopenharmony_ci	struct alx_tx_queue	*txq;
9862306a36Sopenharmony_ci	int			vec_idx;
9962306a36Sopenharmony_ci	u32			vec_mask;
10062306a36Sopenharmony_ci	char			irq_lbl[IFNAMSIZ + 8];
10162306a36Sopenharmony_ci};
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#define ALX_MAX_NAPIS 8
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistruct alx_priv {
10662306a36Sopenharmony_ci	struct net_device *dev;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	struct alx_hw hw;
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	/* msi-x vectors */
11162306a36Sopenharmony_ci	int num_vec;
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	/* all descriptor memory */
11462306a36Sopenharmony_ci	struct {
11562306a36Sopenharmony_ci		dma_addr_t dma;
11662306a36Sopenharmony_ci		void *virt;
11762306a36Sopenharmony_ci		unsigned int size;
11862306a36Sopenharmony_ci	} descmem;
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	struct alx_napi *qnapi[ALX_MAX_NAPIS];
12162306a36Sopenharmony_ci	int num_txq;
12262306a36Sopenharmony_ci	int num_rxq;
12362306a36Sopenharmony_ci	int num_napi;
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci	/* protect int_mask updates */
12662306a36Sopenharmony_ci	spinlock_t irq_lock;
12762306a36Sopenharmony_ci	u32 int_mask;
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	unsigned int tx_ringsz;
13062306a36Sopenharmony_ci	unsigned int rx_ringsz;
13162306a36Sopenharmony_ci	unsigned int rxbuf_size;
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci	struct work_struct link_check_wk;
13462306a36Sopenharmony_ci	struct work_struct reset_wk;
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	u16 msg_enable;
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	/* protects hw.stats */
13962306a36Sopenharmony_ci	spinlock_t stats_lock;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci	struct mutex mtx;
14262306a36Sopenharmony_ci};
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ciextern const struct ethtool_ops alx_ethtool_ops;
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci#endif
147