1862cd659SVeerasenareddy Burru /* SPDX-License-Identifier: GPL-2.0 */
2862cd659SVeerasenareddy Burru /* Marvell Octeon EP (EndPoint) Ethernet Driver
3862cd659SVeerasenareddy Burru *
4862cd659SVeerasenareddy Burru * Copyright (C) 2020 Marvell.
5862cd659SVeerasenareddy Burru *
6862cd659SVeerasenareddy Burru */
7862cd659SVeerasenareddy Burru
8862cd659SVeerasenareddy Burru #ifndef _OCTEP_MAIN_H_
9862cd659SVeerasenareddy Burru #define _OCTEP_MAIN_H_
10862cd659SVeerasenareddy Burru
11862cd659SVeerasenareddy Burru #include "octep_tx.h"
12862cd659SVeerasenareddy Burru #include "octep_rx.h"
13862cd659SVeerasenareddy Burru #include "octep_ctrl_mbox.h"
14862cd659SVeerasenareddy Burru
15862cd659SVeerasenareddy Burru #define OCTEP_DRV_NAME "octeon_ep"
16862cd659SVeerasenareddy Burru #define OCTEP_DRV_STRING "Marvell Octeon EndPoint NIC Driver"
17862cd659SVeerasenareddy Burru
18862cd659SVeerasenareddy Burru #define OCTEP_PCIID_CN93_PF 0xB200177d
19862cd659SVeerasenareddy Burru #define OCTEP_PCIID_CN93_VF 0xB203177d
20862cd659SVeerasenareddy Burru
21068b2b64SShinas Rasheed #define OCTEP_PCI_DEVICE_ID_CN98_PF 0xB100
22862cd659SVeerasenareddy Burru #define OCTEP_PCI_DEVICE_ID_CN93_PF 0xB200
23862cd659SVeerasenareddy Burru #define OCTEP_PCI_DEVICE_ID_CN93_VF 0xB203
24862cd659SVeerasenareddy Burru
2563d9e129SVeerasenareddy Burru #define OCTEP_PCI_DEVICE_ID_CNF95N_PF 0xB400 //95N PF
2663d9e129SVeerasenareddy Burru
270807dc76SShinas Rasheed #define OCTEP_PCI_DEVICE_ID_CN10KA_PF 0xB900 //CN10KA PF
280807dc76SShinas Rasheed #define OCTEP_PCI_DEVICE_ID_CNF10KA_PF 0xBA00 //CNF10KA PF
290807dc76SShinas Rasheed #define OCTEP_PCI_DEVICE_ID_CNF10KB_PF 0xBC00 //CNF10KB PF
300807dc76SShinas Rasheed #define OCTEP_PCI_DEVICE_ID_CN10KB_PF 0xBD00 //CN10KB PF
310807dc76SShinas Rasheed
32862cd659SVeerasenareddy Burru #define OCTEP_MAX_QUEUES 63
33862cd659SVeerasenareddy Burru #define OCTEP_MAX_IQ OCTEP_MAX_QUEUES
34862cd659SVeerasenareddy Burru #define OCTEP_MAX_OQ OCTEP_MAX_QUEUES
35862cd659SVeerasenareddy Burru #define OCTEP_MAX_VF 64
36862cd659SVeerasenareddy Burru
37862cd659SVeerasenareddy Burru #define OCTEP_MAX_MSIX_VECTORS OCTEP_MAX_OQ
38862cd659SVeerasenareddy Burru
39862cd659SVeerasenareddy Burru /* Flags to disable and enable Interrupts */
40862cd659SVeerasenareddy Burru #define OCTEP_INPUT_INTR (1)
41862cd659SVeerasenareddy Burru #define OCTEP_OUTPUT_INTR (2)
42862cd659SVeerasenareddy Burru #define OCTEP_MBOX_INTR (4)
43862cd659SVeerasenareddy Burru #define OCTEP_ALL_INTR 0xff
44862cd659SVeerasenareddy Burru
45862cd659SVeerasenareddy Burru #define OCTEP_IQ_INTR_RESEND_BIT 59
46862cd659SVeerasenareddy Burru #define OCTEP_OQ_INTR_RESEND_BIT 59
47862cd659SVeerasenareddy Burru
48862cd659SVeerasenareddy Burru #define OCTEP_MMIO_REGIONS 3
49dc9c02b7SShinas Rasheed
50dc9c02b7SShinas Rasheed #define IQ_INSTR_PENDING(iq) ({ typeof(iq) iq__ = (iq); \
51dc9c02b7SShinas Rasheed ((iq__)->host_write_index - (iq__)->flush_index) & \
52dc9c02b7SShinas Rasheed (iq__)->ring_size_mask; \
53dc9c02b7SShinas Rasheed })
54dc9c02b7SShinas Rasheed #define IQ_INSTR_SPACE(iq) ({ typeof(iq) iq_ = (iq); \
55dc9c02b7SShinas Rasheed (iq_)->max_count - IQ_INSTR_PENDING(iq_); \
56dc9c02b7SShinas Rasheed })
57dc9c02b7SShinas Rasheed
58862cd659SVeerasenareddy Burru /* PCI address space mapping information.
59862cd659SVeerasenareddy Burru * Each of the 3 address spaces given by BAR0, BAR2 and BAR4 of
60862cd659SVeerasenareddy Burru * Octeon gets mapped to different physical address spaces in
61862cd659SVeerasenareddy Burru * the kernel.
62862cd659SVeerasenareddy Burru */
63862cd659SVeerasenareddy Burru struct octep_mmio {
64862cd659SVeerasenareddy Burru /* The physical address to which the PCI address space is mapped. */
65862cd659SVeerasenareddy Burru u8 __iomem *hw_addr;
66862cd659SVeerasenareddy Burru
67862cd659SVeerasenareddy Burru /* Flag indicating the mapping was successful. */
68862cd659SVeerasenareddy Burru int mapped;
69862cd659SVeerasenareddy Burru };
70862cd659SVeerasenareddy Burru
71862cd659SVeerasenareddy Burru struct octep_pci_win_regs {
72862cd659SVeerasenareddy Burru u8 __iomem *pci_win_wr_addr;
73862cd659SVeerasenareddy Burru u8 __iomem *pci_win_rd_addr;
74862cd659SVeerasenareddy Burru u8 __iomem *pci_win_wr_data;
75862cd659SVeerasenareddy Burru u8 __iomem *pci_win_rd_data;
76862cd659SVeerasenareddy Burru };
77862cd659SVeerasenareddy Burru
78862cd659SVeerasenareddy Burru struct octep_hw_ops {
79862cd659SVeerasenareddy Burru void (*setup_iq_regs)(struct octep_device *oct, int q);
80862cd659SVeerasenareddy Burru void (*setup_oq_regs)(struct octep_device *oct, int q);
81862cd659SVeerasenareddy Burru void (*setup_mbox_regs)(struct octep_device *oct, int mbox);
82862cd659SVeerasenareddy Burru
83cde29af9SShinas Rasheed irqreturn_t (*mbox_intr_handler)(void *ioq_vector);
840b8ef824SShinas Rasheed irqreturn_t (*oei_intr_handler)(void *ioq_vector);
850b8ef824SShinas Rasheed irqreturn_t (*ire_intr_handler)(void *ioq_vector);
860b8ef824SShinas Rasheed irqreturn_t (*ore_intr_handler)(void *ioq_vector);
870b8ef824SShinas Rasheed irqreturn_t (*vfire_intr_handler)(void *ioq_vector);
880b8ef824SShinas Rasheed irqreturn_t (*vfore_intr_handler)(void *ioq_vector);
890b8ef824SShinas Rasheed irqreturn_t (*dma_intr_handler)(void *ioq_vector);
900b8ef824SShinas Rasheed irqreturn_t (*dma_vf_intr_handler)(void *ioq_vector);
910b8ef824SShinas Rasheed irqreturn_t (*pp_vf_intr_handler)(void *ioq_vector);
920b8ef824SShinas Rasheed irqreturn_t (*misc_intr_handler)(void *ioq_vector);
930b8ef824SShinas Rasheed irqreturn_t (*rsvd_intr_handler)(void *ioq_vector);
94862cd659SVeerasenareddy Burru irqreturn_t (*ioq_intr_handler)(void *ioq_vector);
95862cd659SVeerasenareddy Burru int (*soft_reset)(struct octep_device *oct);
96862cd659SVeerasenareddy Burru void (*reinit_regs)(struct octep_device *oct);
97862cd659SVeerasenareddy Burru u32 (*update_iq_read_idx)(struct octep_iq *iq);
98862cd659SVeerasenareddy Burru
99862cd659SVeerasenareddy Burru void (*enable_interrupts)(struct octep_device *oct);
100862cd659SVeerasenareddy Burru void (*disable_interrupts)(struct octep_device *oct);
1010b8ef824SShinas Rasheed void (*poll_non_ioq_interrupts)(struct octep_device *oct);
102862cd659SVeerasenareddy Burru
103862cd659SVeerasenareddy Burru void (*enable_io_queues)(struct octep_device *oct);
104862cd659SVeerasenareddy Burru void (*disable_io_queues)(struct octep_device *oct);
105862cd659SVeerasenareddy Burru void (*enable_iq)(struct octep_device *oct, int q);
106862cd659SVeerasenareddy Burru void (*disable_iq)(struct octep_device *oct, int q);
107862cd659SVeerasenareddy Burru void (*enable_oq)(struct octep_device *oct, int q);
108862cd659SVeerasenareddy Burru void (*disable_oq)(struct octep_device *oct, int q);
109862cd659SVeerasenareddy Burru void (*reset_io_queues)(struct octep_device *oct);
110862cd659SVeerasenareddy Burru void (*dump_registers)(struct octep_device *oct);
111862cd659SVeerasenareddy Burru };
112862cd659SVeerasenareddy Burru
113862cd659SVeerasenareddy Burru /* Octeon mailbox data */
114862cd659SVeerasenareddy Burru struct octep_mbox_data {
115862cd659SVeerasenareddy Burru u32 cmd;
116862cd659SVeerasenareddy Burru u32 total_len;
117862cd659SVeerasenareddy Burru u32 recv_len;
118862cd659SVeerasenareddy Burru u32 rsvd;
119862cd659SVeerasenareddy Burru u64 *data;
120862cd659SVeerasenareddy Burru };
121862cd659SVeerasenareddy Burru
122cde29af9SShinas Rasheed #define MAX_VF_PF_MBOX_DATA_SIZE 384
123cde29af9SShinas Rasheed /* wrappers around work structs */
124cde29af9SShinas Rasheed struct octep_pfvf_mbox_wk {
125cde29af9SShinas Rasheed struct work_struct work;
126cde29af9SShinas Rasheed void *ctxptr;
127cde29af9SShinas Rasheed u64 ctxul;
128cde29af9SShinas Rasheed };
129cde29af9SShinas Rasheed
130862cd659SVeerasenareddy Burru /* Octeon device mailbox */
131862cd659SVeerasenareddy Burru struct octep_mbox {
132cde29af9SShinas Rasheed /* A mutex to protect access to this q_mbox. */
133cde29af9SShinas Rasheed struct mutex lock;
134cde29af9SShinas Rasheed u32 vf_id;
135cde29af9SShinas Rasheed u32 config_data_index;
136cde29af9SShinas Rasheed u32 message_len;
137cde29af9SShinas Rasheed u8 __iomem *pf_vf_data_reg;
138cde29af9SShinas Rasheed u8 __iomem *vf_pf_data_reg;
139cde29af9SShinas Rasheed struct octep_pfvf_mbox_wk wk;
140cde29af9SShinas Rasheed struct octep_device *oct;
141862cd659SVeerasenareddy Burru struct octep_mbox_data mbox_data;
142cde29af9SShinas Rasheed u8 config_data[MAX_VF_PF_MBOX_DATA_SIZE];
143862cd659SVeerasenareddy Burru };
144862cd659SVeerasenareddy Burru
145862cd659SVeerasenareddy Burru /* Tx/Rx queue vector per interrupt. */
146862cd659SVeerasenareddy Burru struct octep_ioq_vector {
147862cd659SVeerasenareddy Burru char name[OCTEP_MSIX_NAME_SIZE];
148862cd659SVeerasenareddy Burru struct napi_struct napi;
149862cd659SVeerasenareddy Burru struct octep_device *octep_dev;
150862cd659SVeerasenareddy Burru struct octep_iq *iq;
151862cd659SVeerasenareddy Burru struct octep_oq *oq;
152862cd659SVeerasenareddy Burru cpumask_t affinity_mask;
153862cd659SVeerasenareddy Burru };
154862cd659SVeerasenareddy Burru
155862cd659SVeerasenareddy Burru /* Octeon hardware/firmware offload capability flags. */
156862cd659SVeerasenareddy Burru #define OCTEP_CAP_TX_CHECKSUM BIT(0)
157862cd659SVeerasenareddy Burru #define OCTEP_CAP_RX_CHECKSUM BIT(1)
158862cd659SVeerasenareddy Burru #define OCTEP_CAP_TSO BIT(2)
159862cd659SVeerasenareddy Burru
160862cd659SVeerasenareddy Burru /* Link modes */
161862cd659SVeerasenareddy Burru enum octep_link_mode_bit_indices {
162862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_10GBASE_T = 0,
163862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_10GBASE_R,
164862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_10GBASE_CR,
165862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_10GBASE_KR,
166862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_10GBASE_LR,
167862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_10GBASE_SR,
168862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_25GBASE_CR,
169862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_25GBASE_KR,
170862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_25GBASE_SR,
171862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_40GBASE_CR4,
172862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_40GBASE_KR4,
173862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_40GBASE_LR4,
174862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_40GBASE_SR4,
175862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_50GBASE_CR2,
176862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_50GBASE_KR2,
177862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_50GBASE_SR2,
178862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_50GBASE_CR,
179862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_50GBASE_KR,
180862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_50GBASE_LR,
181862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_50GBASE_SR,
182862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_100GBASE_CR4,
183862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_100GBASE_KR4,
184862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_100GBASE_LR4,
185862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_100GBASE_SR4,
186862cd659SVeerasenareddy Burru OCTEP_LINK_MODE_NBITS
187862cd659SVeerasenareddy Burru };
188862cd659SVeerasenareddy Burru
189862cd659SVeerasenareddy Burru /* Hardware interface link state information. */
190862cd659SVeerasenareddy Burru struct octep_iface_link_info {
191862cd659SVeerasenareddy Burru /* Bitmap of Supported link speeds/modes. */
192862cd659SVeerasenareddy Burru u64 supported_modes;
193862cd659SVeerasenareddy Burru
194862cd659SVeerasenareddy Burru /* Bitmap of Advertised link speeds/modes. */
195862cd659SVeerasenareddy Burru u64 advertised_modes;
196862cd659SVeerasenareddy Burru
197862cd659SVeerasenareddy Burru /* Negotiated link speed in Mbps. */
198862cd659SVeerasenareddy Burru u32 speed;
199862cd659SVeerasenareddy Burru
200862cd659SVeerasenareddy Burru /* MTU */
201862cd659SVeerasenareddy Burru u16 mtu;
202862cd659SVeerasenareddy Burru
203862cd659SVeerasenareddy Burru /* Autonegotation state. */
204862cd659SVeerasenareddy Burru #define OCTEP_LINK_MODE_AUTONEG_SUPPORTED BIT(0)
205862cd659SVeerasenareddy Burru #define OCTEP_LINK_MODE_AUTONEG_ADVERTISED BIT(1)
206862cd659SVeerasenareddy Burru u8 autoneg;
207862cd659SVeerasenareddy Burru
208862cd659SVeerasenareddy Burru /* Pause frames setting. */
209862cd659SVeerasenareddy Burru #define OCTEP_LINK_MODE_PAUSE_SUPPORTED BIT(0)
210862cd659SVeerasenareddy Burru #define OCTEP_LINK_MODE_PAUSE_ADVERTISED BIT(1)
211862cd659SVeerasenareddy Burru u8 pause;
212862cd659SVeerasenareddy Burru
213862cd659SVeerasenareddy Burru /* Admin state of the link (ifconfig <iface> up/down */
214862cd659SVeerasenareddy Burru u8 admin_up;
215862cd659SVeerasenareddy Burru
216862cd659SVeerasenareddy Burru /* Operational state of the link: physical link is up down */
217862cd659SVeerasenareddy Burru u8 oper_up;
218862cd659SVeerasenareddy Burru };
219862cd659SVeerasenareddy Burru
220cde29af9SShinas Rasheed /* The Octeon VF device specific info data structure.*/
221cde29af9SShinas Rasheed struct octep_pfvf_info {
222cde29af9SShinas Rasheed u8 mac_addr[ETH_ALEN];
223*c130e589SShinas Rasheed u32 mbox_version;
224cde29af9SShinas Rasheed };
225cde29af9SShinas Rasheed
226862cd659SVeerasenareddy Burru /* The Octeon device specific private data structure.
227862cd659SVeerasenareddy Burru * Each Octeon device has this structure to represent all its components.
228862cd659SVeerasenareddy Burru */
229862cd659SVeerasenareddy Burru struct octep_device {
230862cd659SVeerasenareddy Burru struct octep_config *conf;
231862cd659SVeerasenareddy Burru
232862cd659SVeerasenareddy Burru /* Octeon Chip type. */
233862cd659SVeerasenareddy Burru u16 chip_id;
234862cd659SVeerasenareddy Burru u16 rev_id;
235862cd659SVeerasenareddy Burru
236862cd659SVeerasenareddy Burru /* Device capabilities enabled */
237862cd659SVeerasenareddy Burru u64 caps_enabled;
238862cd659SVeerasenareddy Burru /* Device capabilities supported */
239862cd659SVeerasenareddy Burru u64 caps_supported;
240862cd659SVeerasenareddy Burru
241862cd659SVeerasenareddy Burru /* Pointer to basic Linux device */
242862cd659SVeerasenareddy Burru struct device *dev;
243862cd659SVeerasenareddy Burru /* Linux PCI device pointer */
244862cd659SVeerasenareddy Burru struct pci_dev *pdev;
245862cd659SVeerasenareddy Burru /* Netdev corresponding to the Octeon device */
246862cd659SVeerasenareddy Burru struct net_device *netdev;
247862cd659SVeerasenareddy Burru
248862cd659SVeerasenareddy Burru /* memory mapped io range */
249862cd659SVeerasenareddy Burru struct octep_mmio mmio[OCTEP_MMIO_REGIONS];
250862cd659SVeerasenareddy Burru
251862cd659SVeerasenareddy Burru /* MAC address */
252862cd659SVeerasenareddy Burru u8 mac_addr[ETH_ALEN];
253862cd659SVeerasenareddy Burru
254862cd659SVeerasenareddy Burru /* Tx queues (IQ: Instruction Queue) */
255862cd659SVeerasenareddy Burru u16 num_iqs;
2565aa00e9eSShinas Rasheed
257862cd659SVeerasenareddy Burru /* Pointers to Octeon Tx queues */
258862cd659SVeerasenareddy Burru struct octep_iq *iq[OCTEP_MAX_IQ];
259862cd659SVeerasenareddy Burru
260862cd659SVeerasenareddy Burru /* Rx queues (OQ: Output Queue) */
261862cd659SVeerasenareddy Burru u16 num_oqs;
262862cd659SVeerasenareddy Burru /* Pointers to Octeon Rx queues */
263862cd659SVeerasenareddy Burru struct octep_oq *oq[OCTEP_MAX_OQ];
264862cd659SVeerasenareddy Burru
265862cd659SVeerasenareddy Burru /* Hardware port number of the PCIe interface */
266862cd659SVeerasenareddy Burru u16 pcie_port;
267862cd659SVeerasenareddy Burru
268862cd659SVeerasenareddy Burru /* PCI Window registers to access some hardware CSRs */
269862cd659SVeerasenareddy Burru struct octep_pci_win_regs pci_win_regs;
270862cd659SVeerasenareddy Burru /* Hardware operations */
271862cd659SVeerasenareddy Burru struct octep_hw_ops hw_ops;
272862cd659SVeerasenareddy Burru
273862cd659SVeerasenareddy Burru /* IRQ info */
274862cd659SVeerasenareddy Burru u16 num_irqs;
275862cd659SVeerasenareddy Burru u16 num_non_ioq_irqs;
276862cd659SVeerasenareddy Burru char *non_ioq_irq_names;
277862cd659SVeerasenareddy Burru struct msix_entry *msix_entries;
278862cd659SVeerasenareddy Burru /* IOq information of it's corresponding MSI-X interrupt. */
279862cd659SVeerasenareddy Burru struct octep_ioq_vector *ioq_vector[OCTEP_MAX_QUEUES];
280862cd659SVeerasenareddy Burru
281862cd659SVeerasenareddy Burru /* Hardware Interface Tx statistics */
282862cd659SVeerasenareddy Burru struct octep_iface_tx_stats iface_tx_stats;
283862cd659SVeerasenareddy Burru /* Hardware Interface Rx statistics */
284862cd659SVeerasenareddy Burru struct octep_iface_rx_stats iface_rx_stats;
285862cd659SVeerasenareddy Burru
286862cd659SVeerasenareddy Burru /* Hardware Interface Link info like supported modes, aneg support */
287862cd659SVeerasenareddy Burru struct octep_iface_link_info link_info;
288862cd659SVeerasenareddy Burru
289862cd659SVeerasenareddy Burru /* Mailbox to talk to VFs */
290862cd659SVeerasenareddy Burru struct octep_mbox *mbox[OCTEP_MAX_VF];
291cde29af9SShinas Rasheed /* VFs info */
292cde29af9SShinas Rasheed struct octep_pfvf_info vf_info[OCTEP_MAX_VF];
293862cd659SVeerasenareddy Burru
294862cd659SVeerasenareddy Burru /* Work entry to handle Tx timeout */
295862cd659SVeerasenareddy Burru struct work_struct tx_timeout_task;
296862cd659SVeerasenareddy Burru
297862cd659SVeerasenareddy Burru /* control mbox over pf */
298862cd659SVeerasenareddy Burru struct octep_ctrl_mbox ctrl_mbox;
299862cd659SVeerasenareddy Burru
300862cd659SVeerasenareddy Burru /* offset for iface stats */
301862cd659SVeerasenareddy Burru u32 ctrl_mbox_ifstats_offset;
302862cd659SVeerasenareddy Burru
303862cd659SVeerasenareddy Burru /* Work entry to handle ctrl mbox interrupt */
304862cd659SVeerasenareddy Burru struct work_struct ctrl_mbox_task;
30524d43332SVeerasenareddy Burru /* Wait queue for host to firmware requests */
30624d43332SVeerasenareddy Burru wait_queue_head_t ctrl_req_wait_q;
30724d43332SVeerasenareddy Burru /* List of objects waiting for h2f response */
30824d43332SVeerasenareddy Burru struct list_head ctrl_req_wait_list;
309862cd659SVeerasenareddy Burru
31024d43332SVeerasenareddy Burru /* Enable non-ioq interrupt polling */
31124d43332SVeerasenareddy Burru bool poll_non_ioq_intr;
31224d43332SVeerasenareddy Burru /* Work entry to poll non-ioq interrupts */
31324d43332SVeerasenareddy Burru struct delayed_work intr_poll_task;
3145cb96c29SVeerasenareddy Burru
3155cb96c29SVeerasenareddy Burru /* Firmware heartbeat timer */
3165cb96c29SVeerasenareddy Burru struct timer_list hb_timer;
3175cb96c29SVeerasenareddy Burru /* Firmware heartbeat miss count tracked by timer */
3185cb96c29SVeerasenareddy Burru atomic_t hb_miss_cnt;
3195cb96c29SVeerasenareddy Burru /* Task to reset device on heartbeat miss */
3205cb96c29SVeerasenareddy Burru struct delayed_work hb_task;
321862cd659SVeerasenareddy Burru };
322862cd659SVeerasenareddy Burru
OCTEP_MAJOR_REV(struct octep_device * oct)323862cd659SVeerasenareddy Burru static inline u16 OCTEP_MAJOR_REV(struct octep_device *oct)
324862cd659SVeerasenareddy Burru {
325862cd659SVeerasenareddy Burru u16 rev = (oct->rev_id & 0xC) >> 2;
326862cd659SVeerasenareddy Burru
327862cd659SVeerasenareddy Burru return (rev == 0) ? 1 : rev;
328862cd659SVeerasenareddy Burru }
329862cd659SVeerasenareddy Burru
OCTEP_MINOR_REV(struct octep_device * oct)330862cd659SVeerasenareddy Burru static inline u16 OCTEP_MINOR_REV(struct octep_device *oct)
331862cd659SVeerasenareddy Burru {
332862cd659SVeerasenareddy Burru return (oct->rev_id & 0x3);
333862cd659SVeerasenareddy Burru }
334862cd659SVeerasenareddy Burru
335862cd659SVeerasenareddy Burru /* Octeon CSR read/write access APIs */
336862cd659SVeerasenareddy Burru #define octep_write_csr(octep_dev, reg_off, value) \
3371f2c2d0cSVeerasenareddy Burru writel(value, (octep_dev)->mmio[0].hw_addr + (reg_off))
338862cd659SVeerasenareddy Burru
339862cd659SVeerasenareddy Burru #define octep_write_csr64(octep_dev, reg_off, val64) \
340862cd659SVeerasenareddy Burru writeq(val64, (octep_dev)->mmio[0].hw_addr + (reg_off))
341862cd659SVeerasenareddy Burru
342862cd659SVeerasenareddy Burru #define octep_read_csr(octep_dev, reg_off) \
3431f2c2d0cSVeerasenareddy Burru readl((octep_dev)->mmio[0].hw_addr + (reg_off))
344862cd659SVeerasenareddy Burru
345862cd659SVeerasenareddy Burru #define octep_read_csr64(octep_dev, reg_off) \
346862cd659SVeerasenareddy Burru readq((octep_dev)->mmio[0].hw_addr + (reg_off))
347862cd659SVeerasenareddy Burru
348862cd659SVeerasenareddy Burru /* Read windowed register.
349862cd659SVeerasenareddy Burru * @param oct - pointer to the Octeon device.
350862cd659SVeerasenareddy Burru * @param addr - Address of the register to read.
351862cd659SVeerasenareddy Burru *
352862cd659SVeerasenareddy Burru * This routine is called to read from the indirectly accessed
353862cd659SVeerasenareddy Burru * Octeon registers that are visible through a PCI BAR0 mapped window
354862cd659SVeerasenareddy Burru * register.
355862cd659SVeerasenareddy Burru * @return - 64 bit value read from the register.
356862cd659SVeerasenareddy Burru */
357862cd659SVeerasenareddy Burru static inline u64
OCTEP_PCI_WIN_READ(struct octep_device * oct,u64 addr)358862cd659SVeerasenareddy Burru OCTEP_PCI_WIN_READ(struct octep_device *oct, u64 addr)
359862cd659SVeerasenareddy Burru {
360862cd659SVeerasenareddy Burru u64 val64;
361862cd659SVeerasenareddy Burru
362862cd659SVeerasenareddy Burru addr |= 1ull << 53; /* read 8 bytes */
363862cd659SVeerasenareddy Burru writeq(addr, oct->pci_win_regs.pci_win_rd_addr);
364862cd659SVeerasenareddy Burru val64 = readq(oct->pci_win_regs.pci_win_rd_data);
365862cd659SVeerasenareddy Burru
366862cd659SVeerasenareddy Burru dev_dbg(&oct->pdev->dev,
367862cd659SVeerasenareddy Burru "%s: reg: 0x%016llx val: 0x%016llx\n", __func__, addr, val64);
368862cd659SVeerasenareddy Burru
369862cd659SVeerasenareddy Burru return val64;
370862cd659SVeerasenareddy Burru }
371862cd659SVeerasenareddy Burru
372862cd659SVeerasenareddy Burru /* Write windowed register.
373862cd659SVeerasenareddy Burru * @param oct - pointer to the Octeon device.
374862cd659SVeerasenareddy Burru * @param addr - Address of the register to write
375862cd659SVeerasenareddy Burru * @param val - Value to write
376862cd659SVeerasenareddy Burru *
377862cd659SVeerasenareddy Burru * This routine is called to write to the indirectly accessed
378862cd659SVeerasenareddy Burru * Octeon registers that are visible through a PCI BAR0 mapped window
379862cd659SVeerasenareddy Burru * register.
380862cd659SVeerasenareddy Burru * @return Nothing.
381862cd659SVeerasenareddy Burru */
382862cd659SVeerasenareddy Burru static inline void
OCTEP_PCI_WIN_WRITE(struct octep_device * oct,u64 addr,u64 val)383862cd659SVeerasenareddy Burru OCTEP_PCI_WIN_WRITE(struct octep_device *oct, u64 addr, u64 val)
384862cd659SVeerasenareddy Burru {
385862cd659SVeerasenareddy Burru writeq(addr, oct->pci_win_regs.pci_win_wr_addr);
386862cd659SVeerasenareddy Burru writeq(val, oct->pci_win_regs.pci_win_wr_data);
387862cd659SVeerasenareddy Burru
388862cd659SVeerasenareddy Burru dev_dbg(&oct->pdev->dev,
389862cd659SVeerasenareddy Burru "%s: reg: 0x%016llx val: 0x%016llx\n", __func__, addr, val);
390862cd659SVeerasenareddy Burru }
391862cd659SVeerasenareddy Burru
3921f2c2d0cSVeerasenareddy Burru extern struct workqueue_struct *octep_wq;
3931f2c2d0cSVeerasenareddy Burru
394862cd659SVeerasenareddy Burru int octep_device_setup(struct octep_device *oct);
395862cd659SVeerasenareddy Burru int octep_setup_iqs(struct octep_device *oct);
396862cd659SVeerasenareddy Burru void octep_free_iqs(struct octep_device *oct);
397862cd659SVeerasenareddy Burru void octep_clean_iqs(struct octep_device *oct);
398862cd659SVeerasenareddy Burru int octep_setup_oqs(struct octep_device *oct);
399862cd659SVeerasenareddy Burru void octep_free_oqs(struct octep_device *oct);
400862cd659SVeerasenareddy Burru void octep_oq_dbell_init(struct octep_device *oct);
401862cd659SVeerasenareddy Burru void octep_device_setup_cn93_pf(struct octep_device *oct);
4020807dc76SShinas Rasheed void octep_device_setup_cnxk_pf(struct octep_device *oct);
403862cd659SVeerasenareddy Burru int octep_iq_process_completions(struct octep_iq *iq, u16 budget);
404862cd659SVeerasenareddy Burru int octep_oq_process_rx(struct octep_oq *oq, int budget);
405862cd659SVeerasenareddy Burru void octep_set_ethtool_ops(struct net_device *netdev);
406862cd659SVeerasenareddy Burru
407862cd659SVeerasenareddy Burru #endif /* _OCTEP_MAIN_H_ */
408