blob: 9b0be527909bf9a794989d7a7fa8deaeb8d4ea8e [file] [log] [blame]
Sunil Goutham4863dea2015-05-26 19:20:15 -07001/*
2 * Copyright (C) 2015 Cavium, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
7 */
8
9#ifndef NIC_H
10#define NIC_H
11
12#include <linux/netdevice.h>
13#include <linux/interrupt.h>
14#include "thunder_bgx.h"
15
16/* PCI device IDs */
17#define PCI_DEVICE_ID_THUNDER_NIC_PF 0xA01E
18#define PCI_DEVICE_ID_THUNDER_PASS1_NIC_VF 0x0011
19#define PCI_DEVICE_ID_THUNDER_NIC_VF 0xA034
20#define PCI_DEVICE_ID_THUNDER_BGX 0xA026
21
22/* PCI BAR nos */
23#define PCI_CFG_REG_BAR_NUM 0
24#define PCI_MSIX_REG_BAR_NUM 4
25
26/* NIC SRIOV VF count */
27#define MAX_NUM_VFS_SUPPORTED 128
28#define DEFAULT_NUM_VF_ENABLED 8
29
30#define NIC_TNS_BYPASS_MODE 0
31#define NIC_TNS_MODE 1
32
33/* NIC priv flags */
34#define NIC_SRIOV_ENABLED BIT(0)
35
36/* Min/Max packet size */
37#define NIC_HW_MIN_FRS 64
38#define NIC_HW_MAX_FRS 9200 /* 9216 max packet including FCS */
39
40/* Max pkinds */
41#define NIC_MAX_PKIND 16
42
43/* Rx Channels */
44/* Receive channel configuration in TNS bypass mode
45 * Below is configuration in TNS bypass mode
46 * BGX0-LMAC0-CHAN0 - VNIC CHAN0
47 * BGX0-LMAC1-CHAN0 - VNIC CHAN16
48 * ...
49 * BGX1-LMAC0-CHAN0 - VNIC CHAN128
50 * ...
51 * BGX1-LMAC3-CHAN0 - VNIC CHAN174
52 */
53#define NIC_INTF_COUNT 2 /* Interfaces btw VNIC and TNS/BGX */
54#define NIC_CHANS_PER_INF 128
55#define NIC_MAX_CHANS (NIC_INTF_COUNT * NIC_CHANS_PER_INF)
56#define NIC_CPI_COUNT 2048 /* No of channel parse indices */
57
58/* TNS bypass mode: 1-1 mapping between VNIC and BGX:LMAC */
59#define NIC_MAX_BGX MAX_BGX_PER_CN88XX
60#define NIC_CPI_PER_BGX (NIC_CPI_COUNT / NIC_MAX_BGX)
61#define NIC_MAX_CPI_PER_LMAC 64 /* Max when CPI_ALG is IP diffserv */
62#define NIC_RSSI_PER_BGX (NIC_RSSI_COUNT / NIC_MAX_BGX)
63
64/* Tx scheduling */
65#define NIC_MAX_TL4 1024
66#define NIC_MAX_TL4_SHAPERS 256 /* 1 shaper for 4 TL4s */
67#define NIC_MAX_TL3 256
68#define NIC_MAX_TL3_SHAPERS 64 /* 1 shaper for 4 TL3s */
69#define NIC_MAX_TL2 64
70#define NIC_MAX_TL2_SHAPERS 2 /* 1 shaper for 32 TL2s */
71#define NIC_MAX_TL1 2
72
73/* TNS bypass mode */
74#define NIC_TL2_PER_BGX 32
75#define NIC_TL4_PER_BGX (NIC_MAX_TL4 / NIC_MAX_BGX)
76#define NIC_TL4_PER_LMAC (NIC_MAX_TL4 / NIC_CHANS_PER_INF)
77
78/* NIC VF Interrupts */
79#define NICVF_INTR_CQ 0
80#define NICVF_INTR_SQ 1
81#define NICVF_INTR_RBDR 2
82#define NICVF_INTR_PKT_DROP 3
83#define NICVF_INTR_TCP_TIMER 4
84#define NICVF_INTR_MBOX 5
85#define NICVF_INTR_QS_ERR 6
86
87#define NICVF_INTR_CQ_SHIFT 0
88#define NICVF_INTR_SQ_SHIFT 8
89#define NICVF_INTR_RBDR_SHIFT 16
90#define NICVF_INTR_PKT_DROP_SHIFT 20
91#define NICVF_INTR_TCP_TIMER_SHIFT 21
92#define NICVF_INTR_MBOX_SHIFT 22
93#define NICVF_INTR_QS_ERR_SHIFT 23
94
95#define NICVF_INTR_CQ_MASK (0xFF << NICVF_INTR_CQ_SHIFT)
96#define NICVF_INTR_SQ_MASK (0xFF << NICVF_INTR_SQ_SHIFT)
97#define NICVF_INTR_RBDR_MASK (0x03 << NICVF_INTR_RBDR_SHIFT)
98#define NICVF_INTR_PKT_DROP_MASK BIT(NICVF_INTR_PKT_DROP_SHIFT)
99#define NICVF_INTR_TCP_TIMER_MASK BIT(NICVF_INTR_TCP_TIMER_SHIFT)
100#define NICVF_INTR_MBOX_MASK BIT(NICVF_INTR_MBOX_SHIFT)
101#define NICVF_INTR_QS_ERR_MASK BIT(NICVF_INTR_QS_ERR_SHIFT)
102
103/* MSI-X interrupts */
104#define NIC_PF_MSIX_VECTORS 10
105#define NIC_VF_MSIX_VECTORS 20
106
107#define NIC_PF_INTR_ID_ECC0_SBE 0
108#define NIC_PF_INTR_ID_ECC0_DBE 1
109#define NIC_PF_INTR_ID_ECC1_SBE 2
110#define NIC_PF_INTR_ID_ECC1_DBE 3
111#define NIC_PF_INTR_ID_ECC2_SBE 4
112#define NIC_PF_INTR_ID_ECC2_DBE 5
113#define NIC_PF_INTR_ID_ECC3_SBE 6
114#define NIC_PF_INTR_ID_ECC3_DBE 7
115#define NIC_PF_INTR_ID_MBOX0 8
116#define NIC_PF_INTR_ID_MBOX1 9
117
118/* Global timer for CQ timer thresh interrupts
119 * Calculated for SCLK of 700Mhz
120 * value written should be a 1/16th of what is expected
121 *
122 * 1 tick per 0.05usec = value of 2.2
123 * This 10% would be covered in CQ timer thresh value
124 */
125#define NICPF_CLK_PER_INT_TICK 2
126
127struct nicvf_cq_poll {
128 u8 cq_idx; /* Completion queue index */
129 struct napi_struct napi;
130};
131
132#define NIC_RSSI_COUNT 4096 /* Total no of RSS indices */
133#define NIC_MAX_RSS_HASH_BITS 8
134#define NIC_MAX_RSS_IDR_TBL_SIZE (1 << NIC_MAX_RSS_HASH_BITS)
135#define RSS_HASH_KEY_SIZE 5 /* 320 bit key */
136
137struct nicvf_rss_info {
138 bool enable;
139#define RSS_L2_EXTENDED_HASH_ENA BIT(0)
140#define RSS_IP_HASH_ENA BIT(1)
141#define RSS_TCP_HASH_ENA BIT(2)
142#define RSS_TCP_SYN_DIS BIT(3)
143#define RSS_UDP_HASH_ENA BIT(4)
144#define RSS_L4_EXTENDED_HASH_ENA BIT(5)
145#define RSS_ROCE_ENA BIT(6)
146#define RSS_L3_BI_DIRECTION_ENA BIT(7)
147#define RSS_L4_BI_DIRECTION_ENA BIT(8)
148 u64 cfg;
149 u8 hash_bits;
150 u16 rss_size;
151 u8 ind_tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
152 u64 key[RSS_HASH_KEY_SIZE];
153} ____cacheline_aligned_in_smp;
154
155enum rx_stats_reg_offset {
156 RX_OCTS = 0x0,
157 RX_UCAST = 0x1,
158 RX_BCAST = 0x2,
159 RX_MCAST = 0x3,
160 RX_RED = 0x4,
161 RX_RED_OCTS = 0x5,
162 RX_ORUN = 0x6,
163 RX_ORUN_OCTS = 0x7,
164 RX_FCS = 0x8,
165 RX_L2ERR = 0x9,
166 RX_DRP_BCAST = 0xa,
167 RX_DRP_MCAST = 0xb,
168 RX_DRP_L3BCAST = 0xc,
169 RX_DRP_L3MCAST = 0xd,
170 RX_STATS_ENUM_LAST,
171};
172
173enum tx_stats_reg_offset {
174 TX_OCTS = 0x0,
175 TX_UCAST = 0x1,
176 TX_BCAST = 0x2,
177 TX_MCAST = 0x3,
178 TX_DROP = 0x4,
179 TX_STATS_ENUM_LAST,
180};
181
182struct nicvf_hw_stats {
183 u64 rx_bytes_ok;
184 u64 rx_ucast_frames_ok;
185 u64 rx_bcast_frames_ok;
186 u64 rx_mcast_frames_ok;
187 u64 rx_fcs_errors;
188 u64 rx_l2_errors;
189 u64 rx_drop_red;
190 u64 rx_drop_red_bytes;
191 u64 rx_drop_overrun;
192 u64 rx_drop_overrun_bytes;
193 u64 rx_drop_bcast;
194 u64 rx_drop_mcast;
195 u64 rx_drop_l3_bcast;
196 u64 rx_drop_l3_mcast;
197 u64 tx_bytes_ok;
198 u64 tx_ucast_frames_ok;
199 u64 tx_bcast_frames_ok;
200 u64 tx_mcast_frames_ok;
201 u64 tx_drops;
202};
203
204struct nicvf_drv_stats {
205 /* Rx */
206 u64 rx_frames_ok;
207 u64 rx_frames_64;
208 u64 rx_frames_127;
209 u64 rx_frames_255;
210 u64 rx_frames_511;
211 u64 rx_frames_1023;
212 u64 rx_frames_1518;
213 u64 rx_frames_jumbo;
214 u64 rx_drops;
215 /* Tx */
216 u64 tx_frames_ok;
217 u64 tx_drops;
218 u64 tx_busy;
219 u64 tx_tso;
220};
221
222struct nicvf {
223 struct net_device *netdev;
224 struct pci_dev *pdev;
225 u8 vf_id;
226 u8 node;
227 u8 tns_mode;
228 u16 mtu;
229 struct queue_set *qs;
230 void __iomem *reg_base;
231 bool link_up;
232 u8 duplex;
233 u32 speed;
234 struct page *rb_page;
235 u32 rb_page_offset;
236 bool rb_alloc_fail;
237 bool rb_work_scheduled;
238 struct delayed_work rbdr_work;
239 struct tasklet_struct rbdr_task;
240 struct tasklet_struct qs_err_task;
241 struct tasklet_struct cq_task;
242 struct nicvf_cq_poll *napi[8];
243 struct nicvf_rss_info rss_info;
244 u8 cpi_alg;
245 /* Interrupt coalescing settings */
246 u32 cq_coalesce_usecs;
247
248 u32 msg_enable;
249 struct nicvf_hw_stats stats;
250 struct nicvf_drv_stats drv_stats;
251 struct bgx_stats bgx_stats;
252 struct work_struct reset_task;
253
254 /* MSI-X */
255 bool msix_enabled;
256 u8 num_vec;
257 struct msix_entry msix_entries[NIC_VF_MSIX_VECTORS];
258 char irq_name[NIC_VF_MSIX_VECTORS][20];
259 bool irq_allocated[NIC_VF_MSIX_VECTORS];
260
261 bool pf_ready_to_rcv_msg;
262 bool pf_acked;
263 bool pf_nacked;
264 bool bgx_stats_acked;
265} ____cacheline_aligned_in_smp;
266
267/* PF <--> VF Mailbox communication
268 * Eight 64bit registers are shared between PF and VF.
269 * Separate set for each VF.
270 * Writing '1' into last register mbx7 means end of message.
271 */
272
273/* PF <--> VF mailbox communication */
274#define NIC_PF_VF_MAILBOX_SIZE 2
275#define NIC_MBOX_MSG_TIMEOUT 2000 /* ms */
276
277/* Mailbox message types */
278#define NIC_MBOX_MSG_READY 0x01 /* Is PF ready to rcv msgs */
279#define NIC_MBOX_MSG_ACK 0x02 /* ACK the message received */
280#define NIC_MBOX_MSG_NACK 0x03 /* NACK the message received */
281#define NIC_MBOX_MSG_QS_CFG 0x04 /* Configure Qset */
282#define NIC_MBOX_MSG_RQ_CFG 0x05 /* Configure receive queue */
283#define NIC_MBOX_MSG_SQ_CFG 0x06 /* Configure Send queue */
284#define NIC_MBOX_MSG_RQ_DROP_CFG 0x07 /* Configure receive queue */
285#define NIC_MBOX_MSG_SET_MAC 0x08 /* Add MAC ID to DMAC filter */
286#define NIC_MBOX_MSG_SET_MAX_FRS 0x09 /* Set max frame size */
287#define NIC_MBOX_MSG_CPI_CFG 0x0A /* Config CPI, RSSI */
288#define NIC_MBOX_MSG_RSS_SIZE 0x0B /* Get RSS indir_tbl size */
289#define NIC_MBOX_MSG_RSS_CFG 0x0C /* Config RSS table */
290#define NIC_MBOX_MSG_RSS_CFG_CONT 0x0D /* RSS config continuation */
291#define NIC_MBOX_MSG_RQ_BP_CFG 0x0E /* RQ backpressure config */
292#define NIC_MBOX_MSG_RQ_SW_SYNC 0x0F /* Flush inflight pkts to RQ */
293#define NIC_MBOX_MSG_BGX_STATS 0x10 /* Get stats from BGX */
294#define NIC_MBOX_MSG_BGX_LINK_CHANGE 0x11 /* BGX:LMAC link status */
295#define NIC_MBOX_MSG_CFG_DONE 0x12 /* VF configuration done */
296#define NIC_MBOX_MSG_SHUTDOWN 0x13 /* VF is being shutdown */
297
298struct nic_cfg_msg {
299 u8 msg;
300 u8 vf_id;
301 u8 tns_mode;
302 u8 node_id;
303 u64 mac_addr;
304};
305
306/* Qset configuration */
307struct qs_cfg_msg {
308 u8 msg;
309 u8 num;
310 u64 cfg;
311};
312
313/* Receive queue configuration */
314struct rq_cfg_msg {
315 u8 msg;
316 u8 qs_num;
317 u8 rq_num;
318 u64 cfg;
319};
320
321/* Send queue configuration */
322struct sq_cfg_msg {
323 u8 msg;
324 u8 qs_num;
325 u8 sq_num;
326 u64 cfg;
327};
328
329/* Set VF's MAC address */
330struct set_mac_msg {
331 u8 msg;
332 u8 vf_id;
333 u64 addr;
334};
335
336/* Set Maximum frame size */
337struct set_frs_msg {
338 u8 msg;
339 u8 vf_id;
340 u16 max_frs;
341};
342
343/* Set CPI algorithm type */
344struct cpi_cfg_msg {
345 u8 msg;
346 u8 vf_id;
347 u8 rq_cnt;
348 u8 cpi_alg;
349};
350
351/* Get RSS table size */
352struct rss_sz_msg {
353 u8 msg;
354 u8 vf_id;
355 u16 ind_tbl_size;
356};
357
358/* Set RSS configuration */
359struct rss_cfg_msg {
360 u8 msg;
361 u8 vf_id;
362 u8 hash_bits;
363 u8 tbl_len;
364 u8 tbl_offset;
365#define RSS_IND_TBL_LEN_PER_MBX_MSG 8
366 u8 ind_tbl[RSS_IND_TBL_LEN_PER_MBX_MSG];
367};
368
369struct bgx_stats_msg {
370 u8 msg;
371 u8 vf_id;
372 u8 rx;
373 u8 idx;
374 u64 stats;
375};
376
377/* Physical interface link status */
378struct bgx_link_status {
379 u8 msg;
380 u8 link_up;
381 u8 duplex;
382 u32 speed;
383};
384
385/* 128 bit shared memory between PF and each VF */
386union nic_mbx {
387 struct { u8 msg; } msg;
388 struct nic_cfg_msg nic_cfg;
389 struct qs_cfg_msg qs;
390 struct rq_cfg_msg rq;
391 struct sq_cfg_msg sq;
392 struct set_mac_msg mac;
393 struct set_frs_msg frs;
394 struct cpi_cfg_msg cpi_cfg;
395 struct rss_sz_msg rss_size;
396 struct rss_cfg_msg rss_cfg;
397 struct bgx_stats_msg bgx_stats;
398 struct bgx_link_status link_status;
399};
400
401int nicvf_set_real_num_queues(struct net_device *netdev,
402 int tx_queues, int rx_queues);
403int nicvf_open(struct net_device *netdev);
404int nicvf_stop(struct net_device *netdev);
405int nicvf_send_msg_to_pf(struct nicvf *vf, union nic_mbx *mbx);
406void nicvf_config_cpi(struct nicvf *nic);
407void nicvf_config_rss(struct nicvf *nic);
408void nicvf_set_rss_key(struct nicvf *nic);
409void nicvf_free_skb(struct nicvf *nic, struct sk_buff *skb);
410void nicvf_set_ethtool_ops(struct net_device *netdev);
411void nicvf_update_stats(struct nicvf *nic);
412void nicvf_update_lmac_stats(struct nicvf *nic);
413
414#endif /* NIC_H */