nic.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  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. #ifndef NIC_H
  9. #define NIC_H
  10. #include <linux/netdevice.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/pci.h>
  13. #include "thunder_bgx.h"
  14. /* PCI device IDs */
  15. #define PCI_DEVICE_ID_THUNDER_NIC_PF 0xA01E
  16. #define PCI_DEVICE_ID_THUNDER_PASS1_NIC_VF 0x0011
  17. #define PCI_DEVICE_ID_THUNDER_NIC_VF 0xA034
  18. #define PCI_DEVICE_ID_THUNDER_BGX 0xA026
  19. /* Subsystem device IDs */
  20. #define PCI_SUBSYS_DEVID_88XX_NIC_PF 0xA11E
  21. #define PCI_SUBSYS_DEVID_81XX_NIC_PF 0xA21E
  22. #define PCI_SUBSYS_DEVID_83XX_NIC_PF 0xA31E
  23. #define PCI_SUBSYS_DEVID_88XX_PASS1_NIC_VF 0xA11E
  24. #define PCI_SUBSYS_DEVID_88XX_NIC_VF 0xA134
  25. #define PCI_SUBSYS_DEVID_81XX_NIC_VF 0xA234
  26. #define PCI_SUBSYS_DEVID_83XX_NIC_VF 0xA334
  27. /* PCI BAR nos */
  28. #define PCI_CFG_REG_BAR_NUM 0
  29. #define PCI_MSIX_REG_BAR_NUM 4
  30. /* NIC SRIOV VF count */
  31. #define MAX_NUM_VFS_SUPPORTED 128
  32. #define DEFAULT_NUM_VF_ENABLED 8
  33. #define NIC_TNS_BYPASS_MODE 0
  34. #define NIC_TNS_MODE 1
  35. /* NIC priv flags */
  36. #define NIC_SRIOV_ENABLED BIT(0)
  37. /* Min/Max packet size */
  38. #define NIC_HW_MIN_FRS 64
  39. #define NIC_HW_MAX_FRS 9190 /* Excluding L2 header and FCS */
  40. /* Max pkinds */
  41. #define NIC_MAX_PKIND 16
  42. /* Max when CPI_ALG is IP diffserv */
  43. #define NIC_MAX_CPI_PER_LMAC 64
  44. /* NIC VF Interrupts */
  45. #define NICVF_INTR_CQ 0
  46. #define NICVF_INTR_SQ 1
  47. #define NICVF_INTR_RBDR 2
  48. #define NICVF_INTR_PKT_DROP 3
  49. #define NICVF_INTR_TCP_TIMER 4
  50. #define NICVF_INTR_MBOX 5
  51. #define NICVF_INTR_QS_ERR 6
  52. #define NICVF_INTR_CQ_SHIFT 0
  53. #define NICVF_INTR_SQ_SHIFT 8
  54. #define NICVF_INTR_RBDR_SHIFT 16
  55. #define NICVF_INTR_PKT_DROP_SHIFT 20
  56. #define NICVF_INTR_TCP_TIMER_SHIFT 21
  57. #define NICVF_INTR_MBOX_SHIFT 22
  58. #define NICVF_INTR_QS_ERR_SHIFT 23
  59. #define NICVF_INTR_CQ_MASK (0xFF << NICVF_INTR_CQ_SHIFT)
  60. #define NICVF_INTR_SQ_MASK (0xFF << NICVF_INTR_SQ_SHIFT)
  61. #define NICVF_INTR_RBDR_MASK (0x03 << NICVF_INTR_RBDR_SHIFT)
  62. #define NICVF_INTR_PKT_DROP_MASK BIT(NICVF_INTR_PKT_DROP_SHIFT)
  63. #define NICVF_INTR_TCP_TIMER_MASK BIT(NICVF_INTR_TCP_TIMER_SHIFT)
  64. #define NICVF_INTR_MBOX_MASK BIT(NICVF_INTR_MBOX_SHIFT)
  65. #define NICVF_INTR_QS_ERR_MASK BIT(NICVF_INTR_QS_ERR_SHIFT)
  66. /* MSI-X interrupts */
  67. #define NIC_PF_MSIX_VECTORS 10
  68. #define NIC_VF_MSIX_VECTORS 20
  69. #define NIC_PF_INTR_ID_ECC0_SBE 0
  70. #define NIC_PF_INTR_ID_ECC0_DBE 1
  71. #define NIC_PF_INTR_ID_ECC1_SBE 2
  72. #define NIC_PF_INTR_ID_ECC1_DBE 3
  73. #define NIC_PF_INTR_ID_ECC2_SBE 4
  74. #define NIC_PF_INTR_ID_ECC2_DBE 5
  75. #define NIC_PF_INTR_ID_ECC3_SBE 6
  76. #define NIC_PF_INTR_ID_ECC3_DBE 7
  77. #define NIC_PF_INTR_ID_MBOX0 8
  78. #define NIC_PF_INTR_ID_MBOX1 9
  79. /* Minimum FIFO level before all packets for the CQ are dropped
  80. *
  81. * This value ensures that once a packet has been "accepted"
  82. * for reception it will not get dropped due to non-availability
  83. * of CQ descriptor. An errata in HW mandates this value to be
  84. * atleast 0x100.
  85. */
  86. #define NICPF_CQM_MIN_DROP_LEVEL 0x100
  87. /* Global timer for CQ timer thresh interrupts
  88. * Calculated for SCLK of 700Mhz
  89. * value written should be a 1/16th of what is expected
  90. *
  91. * 1 tick per 0.025usec
  92. */
  93. #define NICPF_CLK_PER_INT_TICK 1
  94. /* Time to wait before we decide that a SQ is stuck.
  95. *
  96. * Since both pkt rx and tx notifications are done with same CQ,
  97. * when packets are being received at very high rate (eg: L2 forwarding)
  98. * then freeing transmitted skbs will be delayed and watchdog
  99. * will kick in, resetting interface. Hence keeping this value high.
  100. */
  101. #define NICVF_TX_TIMEOUT (50 * HZ)
  102. struct nicvf_cq_poll {
  103. struct nicvf *nicvf;
  104. u8 cq_idx; /* Completion queue index */
  105. struct napi_struct napi;
  106. };
  107. #define NIC_MAX_RSS_HASH_BITS 8
  108. #define NIC_MAX_RSS_IDR_TBL_SIZE (1 << NIC_MAX_RSS_HASH_BITS)
  109. #define RSS_HASH_KEY_SIZE 5 /* 320 bit key */
  110. struct nicvf_rss_info {
  111. bool enable;
  112. #define RSS_L2_EXTENDED_HASH_ENA BIT(0)
  113. #define RSS_IP_HASH_ENA BIT(1)
  114. #define RSS_TCP_HASH_ENA BIT(2)
  115. #define RSS_TCP_SYN_DIS BIT(3)
  116. #define RSS_UDP_HASH_ENA BIT(4)
  117. #define RSS_L4_EXTENDED_HASH_ENA BIT(5)
  118. #define RSS_ROCE_ENA BIT(6)
  119. #define RSS_L3_BI_DIRECTION_ENA BIT(7)
  120. #define RSS_L4_BI_DIRECTION_ENA BIT(8)
  121. u64 cfg;
  122. u8 hash_bits;
  123. u16 rss_size;
  124. u8 ind_tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
  125. u64 key[RSS_HASH_KEY_SIZE];
  126. } ____cacheline_aligned_in_smp;
  127. struct nicvf_pfc {
  128. u8 autoneg;
  129. u8 fc_rx;
  130. u8 fc_tx;
  131. };
  132. enum rx_stats_reg_offset {
  133. RX_OCTS = 0x0,
  134. RX_UCAST = 0x1,
  135. RX_BCAST = 0x2,
  136. RX_MCAST = 0x3,
  137. RX_RED = 0x4,
  138. RX_RED_OCTS = 0x5,
  139. RX_ORUN = 0x6,
  140. RX_ORUN_OCTS = 0x7,
  141. RX_FCS = 0x8,
  142. RX_L2ERR = 0x9,
  143. RX_DRP_BCAST = 0xa,
  144. RX_DRP_MCAST = 0xb,
  145. RX_DRP_L3BCAST = 0xc,
  146. RX_DRP_L3MCAST = 0xd,
  147. RX_STATS_ENUM_LAST,
  148. };
  149. enum tx_stats_reg_offset {
  150. TX_OCTS = 0x0,
  151. TX_UCAST = 0x1,
  152. TX_BCAST = 0x2,
  153. TX_MCAST = 0x3,
  154. TX_DROP = 0x4,
  155. TX_STATS_ENUM_LAST,
  156. };
  157. struct nicvf_hw_stats {
  158. u64 rx_bytes;
  159. u64 rx_frames;
  160. u64 rx_ucast_frames;
  161. u64 rx_bcast_frames;
  162. u64 rx_mcast_frames;
  163. u64 rx_drops;
  164. u64 rx_drop_red;
  165. u64 rx_drop_red_bytes;
  166. u64 rx_drop_overrun;
  167. u64 rx_drop_overrun_bytes;
  168. u64 rx_drop_bcast;
  169. u64 rx_drop_mcast;
  170. u64 rx_drop_l3_bcast;
  171. u64 rx_drop_l3_mcast;
  172. u64 rx_fcs_errors;
  173. u64 rx_l2_errors;
  174. u64 tx_bytes;
  175. u64 tx_frames;
  176. u64 tx_ucast_frames;
  177. u64 tx_bcast_frames;
  178. u64 tx_mcast_frames;
  179. u64 tx_drops;
  180. };
  181. struct nicvf_drv_stats {
  182. /* CQE Rx errs */
  183. u64 rx_bgx_truncated_pkts;
  184. u64 rx_jabber_errs;
  185. u64 rx_fcs_errs;
  186. u64 rx_bgx_errs;
  187. u64 rx_prel2_errs;
  188. u64 rx_l2_hdr_malformed;
  189. u64 rx_oversize;
  190. u64 rx_undersize;
  191. u64 rx_l2_len_mismatch;
  192. u64 rx_l2_pclp;
  193. u64 rx_ip_ver_errs;
  194. u64 rx_ip_csum_errs;
  195. u64 rx_ip_hdr_malformed;
  196. u64 rx_ip_payload_malformed;
  197. u64 rx_ip_ttl_errs;
  198. u64 rx_l3_pclp;
  199. u64 rx_l4_malformed;
  200. u64 rx_l4_csum_errs;
  201. u64 rx_udp_len_errs;
  202. u64 rx_l4_port_errs;
  203. u64 rx_tcp_flag_errs;
  204. u64 rx_tcp_offset_errs;
  205. u64 rx_l4_pclp;
  206. u64 rx_truncated_pkts;
  207. /* CQE Tx errs */
  208. u64 tx_desc_fault;
  209. u64 tx_hdr_cons_err;
  210. u64 tx_subdesc_err;
  211. u64 tx_max_size_exceeded;
  212. u64 tx_imm_size_oflow;
  213. u64 tx_data_seq_err;
  214. u64 tx_mem_seq_err;
  215. u64 tx_lock_viol;
  216. u64 tx_data_fault;
  217. u64 tx_tstmp_conflict;
  218. u64 tx_tstmp_timeout;
  219. u64 tx_mem_fault;
  220. u64 tx_csum_overlap;
  221. u64 tx_csum_overflow;
  222. /* driver debug stats */
  223. u64 tx_tso;
  224. u64 tx_timeout;
  225. u64 txq_stop;
  226. u64 txq_wake;
  227. u64 rcv_buffer_alloc_failures;
  228. u64 page_alloc;
  229. struct u64_stats_sync syncp;
  230. };
  231. struct cavium_ptp;
  232. struct xcast_addr_list {
  233. int count;
  234. u64 mc[];
  235. };
  236. struct nicvf_work {
  237. struct delayed_work work;
  238. u8 mode;
  239. struct xcast_addr_list *mc;
  240. };
  241. struct nicvf {
  242. struct nicvf *pnicvf;
  243. struct net_device *netdev;
  244. struct pci_dev *pdev;
  245. void __iomem *reg_base;
  246. struct bpf_prog *xdp_prog;
  247. #define MAX_QUEUES_PER_QSET 8
  248. struct queue_set *qs;
  249. void *iommu_domain;
  250. u8 vf_id;
  251. u8 sqs_id;
  252. bool sqs_mode;
  253. bool hw_tso;
  254. bool t88;
  255. /* Receive buffer alloc */
  256. u32 rb_page_offset;
  257. u16 rb_pageref;
  258. bool rb_alloc_fail;
  259. bool rb_work_scheduled;
  260. struct page *rb_page;
  261. struct delayed_work rbdr_work;
  262. struct tasklet_struct rbdr_task;
  263. /* Secondary Qset */
  264. u8 sqs_count;
  265. #define MAX_SQS_PER_VF_SINGLE_NODE 5
  266. #define MAX_SQS_PER_VF 11
  267. struct nicvf *snicvf[MAX_SQS_PER_VF];
  268. /* Queue count */
  269. u8 rx_queues;
  270. u8 tx_queues;
  271. u8 xdp_tx_queues;
  272. u8 max_queues;
  273. u8 node;
  274. u8 cpi_alg;
  275. bool link_up;
  276. u8 mac_type;
  277. u8 duplex;
  278. u32 speed;
  279. bool tns_mode;
  280. bool loopback_supported;
  281. struct nicvf_rss_info rss_info;
  282. struct nicvf_pfc pfc;
  283. struct tasklet_struct qs_err_task;
  284. struct work_struct reset_task;
  285. struct nicvf_work rx_mode_work;
  286. /* spinlock to protect workqueue arguments from concurrent access */
  287. spinlock_t rx_mode_wq_lock;
  288. /* PTP timestamp */
  289. struct cavium_ptp *ptp_clock;
  290. /* Inbound timestamping is on */
  291. bool hw_rx_tstamp;
  292. /* When the packet that requires timestamping is sent, hardware inserts
  293. * two entries to the completion queue. First is the regular
  294. * CQE_TYPE_SEND entry that signals that the packet was sent.
  295. * The second is CQE_TYPE_SEND_PTP that contains the actual timestamp
  296. * for that packet.
  297. * `ptp_skb` is initialized in the handler for the CQE_TYPE_SEND
  298. * entry and is used and zeroed in the handler for the CQE_TYPE_SEND_PTP
  299. * entry.
  300. * So `ptp_skb` is used to hold the pointer to the packet between
  301. * the calls to CQE_TYPE_SEND and CQE_TYPE_SEND_PTP handlers.
  302. */
  303. struct sk_buff *ptp_skb;
  304. /* `tx_ptp_skbs` is set when the hardware is sending a packet that
  305. * requires timestamping. Cavium hardware can not process more than one
  306. * such packet at once so this is set each time the driver submits
  307. * a packet that requires timestamping to the send queue and clears
  308. * each time it receives the entry on the completion queue saying
  309. * that such packet was sent.
  310. * So `tx_ptp_skbs` prevents driver from submitting more than one
  311. * packet that requires timestamping to the hardware for transmitting.
  312. */
  313. atomic_t tx_ptp_skbs;
  314. /* Interrupt coalescing settings */
  315. u32 cq_coalesce_usecs;
  316. u32 msg_enable;
  317. /* Stats */
  318. struct nicvf_hw_stats hw_stats;
  319. struct nicvf_drv_stats __percpu *drv_stats;
  320. struct bgx_stats bgx_stats;
  321. /* Napi */
  322. struct nicvf_cq_poll *napi[8];
  323. /* MSI-X */
  324. u8 num_vec;
  325. char irq_name[NIC_VF_MSIX_VECTORS][IFNAMSIZ + 15];
  326. bool irq_allocated[NIC_VF_MSIX_VECTORS];
  327. cpumask_var_t affinity_mask[NIC_VF_MSIX_VECTORS];
  328. /* VF <-> PF mailbox communication */
  329. bool pf_acked;
  330. bool pf_nacked;
  331. bool set_mac_pending;
  332. } ____cacheline_aligned_in_smp;
  333. /* PF <--> VF Mailbox communication
  334. * Eight 64bit registers are shared between PF and VF.
  335. * Separate set for each VF.
  336. * Writing '1' into last register mbx7 means end of message.
  337. */
  338. /* PF <--> VF mailbox communication */
  339. #define NIC_PF_VF_MAILBOX_SIZE 2
  340. #define NIC_MBOX_MSG_TIMEOUT 2000 /* ms */
  341. /* Mailbox message types */
  342. #define NIC_MBOX_MSG_READY 0x01 /* Is PF ready to rcv msgs */
  343. #define NIC_MBOX_MSG_ACK 0x02 /* ACK the message received */
  344. #define NIC_MBOX_MSG_NACK 0x03 /* NACK the message received */
  345. #define NIC_MBOX_MSG_QS_CFG 0x04 /* Configure Qset */
  346. #define NIC_MBOX_MSG_RQ_CFG 0x05 /* Configure receive queue */
  347. #define NIC_MBOX_MSG_SQ_CFG 0x06 /* Configure Send queue */
  348. #define NIC_MBOX_MSG_RQ_DROP_CFG 0x07 /* Configure receive queue */
  349. #define NIC_MBOX_MSG_SET_MAC 0x08 /* Add MAC ID to DMAC filter */
  350. #define NIC_MBOX_MSG_SET_MAX_FRS 0x09 /* Set max frame size */
  351. #define NIC_MBOX_MSG_CPI_CFG 0x0A /* Config CPI, RSSI */
  352. #define NIC_MBOX_MSG_RSS_SIZE 0x0B /* Get RSS indir_tbl size */
  353. #define NIC_MBOX_MSG_RSS_CFG 0x0C /* Config RSS table */
  354. #define NIC_MBOX_MSG_RSS_CFG_CONT 0x0D /* RSS config continuation */
  355. #define NIC_MBOX_MSG_RQ_BP_CFG 0x0E /* RQ backpressure config */
  356. #define NIC_MBOX_MSG_RQ_SW_SYNC 0x0F /* Flush inflight pkts to RQ */
  357. #define NIC_MBOX_MSG_BGX_STATS 0x10 /* Get stats from BGX */
  358. #define NIC_MBOX_MSG_BGX_LINK_CHANGE 0x11 /* BGX:LMAC link status */
  359. #define NIC_MBOX_MSG_ALLOC_SQS 0x12 /* Allocate secondary Qset */
  360. #define NIC_MBOX_MSG_NICVF_PTR 0x13 /* Send nicvf ptr to PF */
  361. #define NIC_MBOX_MSG_PNICVF_PTR 0x14 /* Get primary qset nicvf ptr */
  362. #define NIC_MBOX_MSG_SNICVF_PTR 0x15 /* Send sqet nicvf ptr to PVF */
  363. #define NIC_MBOX_MSG_LOOPBACK 0x16 /* Set interface in loopback */
  364. #define NIC_MBOX_MSG_RESET_STAT_COUNTER 0x17 /* Reset statistics counters */
  365. #define NIC_MBOX_MSG_PFC 0x18 /* Pause frame control */
  366. #define NIC_MBOX_MSG_PTP_CFG 0x19 /* HW packet timestamp */
  367. #define NIC_MBOX_MSG_CFG_DONE 0xF0 /* VF configuration done */
  368. #define NIC_MBOX_MSG_SHUTDOWN 0xF1 /* VF is being shutdown */
  369. #define NIC_MBOX_MSG_RESET_XCAST 0xF2 /* Reset DCAM filtering mode */
  370. #define NIC_MBOX_MSG_ADD_MCAST 0xF3 /* Add MAC to DCAM filters */
  371. #define NIC_MBOX_MSG_SET_XCAST 0xF4 /* Set MCAST/BCAST RX mode */
  372. struct nic_cfg_msg {
  373. u8 msg;
  374. u8 vf_id;
  375. u8 node_id;
  376. u8 tns_mode:1;
  377. u8 sqs_mode:1;
  378. u8 loopback_supported:1;
  379. u8 mac_addr[ETH_ALEN];
  380. };
  381. /* Qset configuration */
  382. struct qs_cfg_msg {
  383. u8 msg;
  384. u8 num;
  385. u8 sqs_count;
  386. u64 cfg;
  387. };
  388. /* Receive queue configuration */
  389. struct rq_cfg_msg {
  390. u8 msg;
  391. u8 qs_num;
  392. u8 rq_num;
  393. u64 cfg;
  394. };
  395. /* Send queue configuration */
  396. struct sq_cfg_msg {
  397. u8 msg;
  398. u8 qs_num;
  399. u8 sq_num;
  400. bool sqs_mode;
  401. u64 cfg;
  402. };
  403. /* Set VF's MAC address */
  404. struct set_mac_msg {
  405. u8 msg;
  406. u8 vf_id;
  407. u8 mac_addr[ETH_ALEN];
  408. };
  409. /* Set Maximum frame size */
  410. struct set_frs_msg {
  411. u8 msg;
  412. u8 vf_id;
  413. u16 max_frs;
  414. };
  415. /* Set CPI algorithm type */
  416. struct cpi_cfg_msg {
  417. u8 msg;
  418. u8 vf_id;
  419. u8 rq_cnt;
  420. u8 cpi_alg;
  421. };
  422. /* Get RSS table size */
  423. struct rss_sz_msg {
  424. u8 msg;
  425. u8 vf_id;
  426. u16 ind_tbl_size;
  427. };
  428. /* Set RSS configuration */
  429. struct rss_cfg_msg {
  430. u8 msg;
  431. u8 vf_id;
  432. u8 hash_bits;
  433. u8 tbl_len;
  434. u8 tbl_offset;
  435. #define RSS_IND_TBL_LEN_PER_MBX_MSG 8
  436. u8 ind_tbl[RSS_IND_TBL_LEN_PER_MBX_MSG];
  437. };
  438. struct bgx_stats_msg {
  439. u8 msg;
  440. u8 vf_id;
  441. u8 rx;
  442. u8 idx;
  443. u64 stats;
  444. };
  445. /* Physical interface link status */
  446. struct bgx_link_status {
  447. u8 msg;
  448. u8 mac_type;
  449. u8 link_up;
  450. u8 duplex;
  451. u32 speed;
  452. };
  453. /* Get Extra Qset IDs */
  454. struct sqs_alloc {
  455. u8 msg;
  456. u8 vf_id;
  457. u8 qs_count;
  458. };
  459. struct nicvf_ptr {
  460. u8 msg;
  461. u8 vf_id;
  462. bool sqs_mode;
  463. u8 sqs_id;
  464. u64 nicvf;
  465. };
  466. /* Set interface in loopback mode */
  467. struct set_loopback {
  468. u8 msg;
  469. u8 vf_id;
  470. bool enable;
  471. };
  472. /* Reset statistics counters */
  473. struct reset_stat_cfg {
  474. u8 msg;
  475. /* Bitmap to select NIC_PF_VNIC(vf_id)_RX_STAT(0..13) */
  476. u16 rx_stat_mask;
  477. /* Bitmap to select NIC_PF_VNIC(vf_id)_TX_STAT(0..4) */
  478. u8 tx_stat_mask;
  479. /* Bitmap to select NIC_PF_QS(0..127)_RQ(0..7)_STAT(0..1)
  480. * bit14, bit15 NIC_PF_QS(vf_id)_RQ7_STAT(0..1)
  481. * bit12, bit13 NIC_PF_QS(vf_id)_RQ6_STAT(0..1)
  482. * ..
  483. * bit2, bit3 NIC_PF_QS(vf_id)_RQ1_STAT(0..1)
  484. * bit0, bit1 NIC_PF_QS(vf_id)_RQ0_STAT(0..1)
  485. */
  486. u16 rq_stat_mask;
  487. /* Bitmap to select NIC_PF_QS(0..127)_SQ(0..7)_STAT(0..1)
  488. * bit14, bit15 NIC_PF_QS(vf_id)_SQ7_STAT(0..1)
  489. * bit12, bit13 NIC_PF_QS(vf_id)_SQ6_STAT(0..1)
  490. * ..
  491. * bit2, bit3 NIC_PF_QS(vf_id)_SQ1_STAT(0..1)
  492. * bit0, bit1 NIC_PF_QS(vf_id)_SQ0_STAT(0..1)
  493. */
  494. u16 sq_stat_mask;
  495. };
  496. struct pfc {
  497. u8 msg;
  498. u8 get; /* Get or set PFC settings */
  499. u8 autoneg;
  500. u8 fc_rx;
  501. u8 fc_tx;
  502. };
  503. struct set_ptp {
  504. u8 msg;
  505. bool enable;
  506. };
  507. struct xcast {
  508. u8 msg;
  509. union {
  510. u8 mode;
  511. u64 mac;
  512. } data;
  513. };
  514. /* 128 bit shared memory between PF and each VF */
  515. union nic_mbx {
  516. struct { u8 msg; } msg;
  517. struct nic_cfg_msg nic_cfg;
  518. struct qs_cfg_msg qs;
  519. struct rq_cfg_msg rq;
  520. struct sq_cfg_msg sq;
  521. struct set_mac_msg mac;
  522. struct set_frs_msg frs;
  523. struct cpi_cfg_msg cpi_cfg;
  524. struct rss_sz_msg rss_size;
  525. struct rss_cfg_msg rss_cfg;
  526. struct bgx_stats_msg bgx_stats;
  527. struct bgx_link_status link_status;
  528. struct sqs_alloc sqs_alloc;
  529. struct nicvf_ptr nicvf;
  530. struct set_loopback lbk;
  531. struct reset_stat_cfg reset_stat;
  532. struct pfc pfc;
  533. struct set_ptp ptp;
  534. struct xcast xcast;
  535. };
  536. #define NIC_NODE_ID_MASK 0x03
  537. #define NIC_NODE_ID_SHIFT 44
  538. static inline int nic_get_node_id(struct pci_dev *pdev)
  539. {
  540. u64 addr = pci_resource_start(pdev, PCI_CFG_REG_BAR_NUM);
  541. return ((addr >> NIC_NODE_ID_SHIFT) & NIC_NODE_ID_MASK);
  542. }
  543. static inline bool pass1_silicon(struct pci_dev *pdev)
  544. {
  545. return (pdev->revision < 8) &&
  546. (pdev->subsystem_device == PCI_SUBSYS_DEVID_88XX_NIC_PF);
  547. }
  548. static inline bool pass2_silicon(struct pci_dev *pdev)
  549. {
  550. return (pdev->revision >= 8) &&
  551. (pdev->subsystem_device == PCI_SUBSYS_DEVID_88XX_NIC_PF);
  552. }
  553. int nicvf_set_real_num_queues(struct net_device *netdev,
  554. int tx_queues, int rx_queues);
  555. int nicvf_open(struct net_device *netdev);
  556. int nicvf_stop(struct net_device *netdev);
  557. int nicvf_send_msg_to_pf(struct nicvf *vf, union nic_mbx *mbx);
  558. void nicvf_config_rss(struct nicvf *nic);
  559. void nicvf_set_rss_key(struct nicvf *nic);
  560. void nicvf_set_ethtool_ops(struct net_device *netdev);
  561. void nicvf_update_stats(struct nicvf *nic);
  562. void nicvf_update_lmac_stats(struct nicvf *nic);
  563. #endif /* NIC_H */