18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2013 Johannes Berg <johannes@sipsolutions.net>
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci *  This file is free software: you may copy, redistribute and/or modify it
58c2ecf20Sopenharmony_ci *  under the terms of the GNU General Public License as published by the
68c2ecf20Sopenharmony_ci *  Free Software Foundation, either version 2 of the License, or (at your
78c2ecf20Sopenharmony_ci *  option) any later version.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *  This file is distributed in the hope that it will be useful, but
108c2ecf20Sopenharmony_ci *  WITHOUT ANY WARRANTY; without even the implied warranty of
118c2ecf20Sopenharmony_ci *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
128c2ecf20Sopenharmony_ci *  General Public License for more details.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *  You should have received a copy of the GNU General Public License
158c2ecf20Sopenharmony_ci *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * This file incorporates work covered by the following copyright and
188c2ecf20Sopenharmony_ci * permission notice:
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * Copyright (c) 2012 Qualcomm Atheros, Inc.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
238c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
248c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
278c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
288c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
298c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
308c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
318c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
328c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef _ALX_H_
368c2ecf20Sopenharmony_ci#define _ALX_H_
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <linux/types.h>
398c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
408c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
418c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
428c2ecf20Sopenharmony_ci#include "hw.h"
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define ALX_WATCHDOG_TIME   (5 * HZ)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct alx_buffer {
478c2ecf20Sopenharmony_ci	struct sk_buff *skb;
488c2ecf20Sopenharmony_ci	DEFINE_DMA_UNMAP_ADDR(dma);
498c2ecf20Sopenharmony_ci	DEFINE_DMA_UNMAP_LEN(size);
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistruct alx_rx_queue {
538c2ecf20Sopenharmony_ci	struct net_device *netdev;
548c2ecf20Sopenharmony_ci	struct device *dev;
558c2ecf20Sopenharmony_ci	struct alx_napi *np;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	struct alx_rrd *rrd;
588c2ecf20Sopenharmony_ci	dma_addr_t rrd_dma;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	struct alx_rfd *rfd;
618c2ecf20Sopenharmony_ci	dma_addr_t rfd_dma;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	struct alx_buffer *bufs;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	u16 count;
668c2ecf20Sopenharmony_ci	u16 write_idx, read_idx;
678c2ecf20Sopenharmony_ci	u16 rrd_read_idx;
688c2ecf20Sopenharmony_ci	u16 queue_idx;
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci#define ALX_RX_ALLOC_THRESH	32
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistruct alx_tx_queue {
738c2ecf20Sopenharmony_ci	struct net_device *netdev;
748c2ecf20Sopenharmony_ci	struct device *dev;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	struct alx_txd *tpd;
778c2ecf20Sopenharmony_ci	dma_addr_t tpd_dma;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	struct alx_buffer *bufs;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	u16 count;
828c2ecf20Sopenharmony_ci	u16 write_idx, read_idx;
838c2ecf20Sopenharmony_ci	u16 queue_idx;
848c2ecf20Sopenharmony_ci	u16 p_reg, c_reg;
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define ALX_DEFAULT_TX_WORK 128
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cienum alx_device_quirks {
908c2ecf20Sopenharmony_ci	ALX_DEV_QUIRK_MSI_INTX_DISABLE_BUG = BIT(0),
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct alx_napi {
948c2ecf20Sopenharmony_ci	struct napi_struct	napi;
958c2ecf20Sopenharmony_ci	struct alx_priv		*alx;
968c2ecf20Sopenharmony_ci	struct alx_rx_queue	*rxq;
978c2ecf20Sopenharmony_ci	struct alx_tx_queue	*txq;
988c2ecf20Sopenharmony_ci	int			vec_idx;
998c2ecf20Sopenharmony_ci	u32			vec_mask;
1008c2ecf20Sopenharmony_ci	char			irq_lbl[IFNAMSIZ + 8];
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define ALX_MAX_NAPIS 8
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistruct alx_priv {
1068c2ecf20Sopenharmony_ci	struct net_device *dev;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	struct alx_hw hw;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	/* msi-x vectors */
1118c2ecf20Sopenharmony_ci	int num_vec;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	/* all descriptor memory */
1148c2ecf20Sopenharmony_ci	struct {
1158c2ecf20Sopenharmony_ci		dma_addr_t dma;
1168c2ecf20Sopenharmony_ci		void *virt;
1178c2ecf20Sopenharmony_ci		unsigned int size;
1188c2ecf20Sopenharmony_ci	} descmem;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	struct alx_napi *qnapi[ALX_MAX_NAPIS];
1218c2ecf20Sopenharmony_ci	int num_txq;
1228c2ecf20Sopenharmony_ci	int num_rxq;
1238c2ecf20Sopenharmony_ci	int num_napi;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	/* protect int_mask updates */
1268c2ecf20Sopenharmony_ci	spinlock_t irq_lock;
1278c2ecf20Sopenharmony_ci	u32 int_mask;
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	unsigned int tx_ringsz;
1308c2ecf20Sopenharmony_ci	unsigned int rx_ringsz;
1318c2ecf20Sopenharmony_ci	unsigned int rxbuf_size;
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	struct work_struct link_check_wk;
1348c2ecf20Sopenharmony_ci	struct work_struct reset_wk;
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	u16 msg_enable;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	/* protects hw.stats */
1398c2ecf20Sopenharmony_ci	spinlock_t stats_lock;
1408c2ecf20Sopenharmony_ci};
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ciextern const struct ethtool_ops alx_ethtool_ops;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#endif
145