PageRenderTime 29ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/ethernet/netronome/nfp/nfp_net.h

https://github.com/mturquette/linux
C Header | 760 lines | 395 code | 112 blank | 253 comment | 14 complexity | ebb217c95994e63ab537a8f947d5bc5d MD5 | raw file
  1. /*
  2. * Copyright (C) 2015 Netronome Systems, Inc.
  3. *
  4. * This software is dual licensed under the GNU General License Version 2,
  5. * June 1991 as shown in the file COPYING in the top-level directory of this
  6. * source tree or the BSD 2-Clause License provided below. You have the
  7. * option to license this software under the complete terms of either license.
  8. *
  9. * The BSD 2-Clause License:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. /*
  34. * nfp_net.h
  35. * Declarations for Netronome network device driver.
  36. * Authors: Jakub Kicinski <jakub.kicinski@netronome.com>
  37. * Jason McMullan <jason.mcmullan@netronome.com>
  38. * Rolf Neugebauer <rolf.neugebauer@netronome.com>
  39. */
  40. #ifndef _NFP_NET_H_
  41. #define _NFP_NET_H_
  42. #include <linux/interrupt.h>
  43. #include <linux/netdevice.h>
  44. #include <linux/pci.h>
  45. #include <linux/io-64-nonatomic-hi-lo.h>
  46. #include "nfp_net_ctrl.h"
  47. #define nn_err(nn, fmt, args...) netdev_err((nn)->netdev, fmt, ## args)
  48. #define nn_warn(nn, fmt, args...) netdev_warn((nn)->netdev, fmt, ## args)
  49. #define nn_info(nn, fmt, args...) netdev_info((nn)->netdev, fmt, ## args)
  50. #define nn_dbg(nn, fmt, args...) netdev_dbg((nn)->netdev, fmt, ## args)
  51. #define nn_warn_ratelimit(nn, fmt, args...) \
  52. do { \
  53. if (unlikely(net_ratelimit())) \
  54. netdev_warn((nn)->netdev, fmt, ## args); \
  55. } while (0)
  56. /* Max time to wait for NFP to respond on updates (in seconds) */
  57. #define NFP_NET_POLL_TIMEOUT 5
  58. /* Bar allocation */
  59. #define NFP_NET_CRTL_BAR 0
  60. #define NFP_NET_Q0_BAR 2
  61. #define NFP_NET_Q1_BAR 4 /* OBSOLETE */
  62. /* Max bits in DMA address */
  63. #define NFP_NET_MAX_DMA_BITS 40
  64. /* Default size for MTU and freelist buffer sizes */
  65. #define NFP_NET_DEFAULT_MTU 1500
  66. #define NFP_NET_DEFAULT_RX_BUFSZ 2048
  67. /* Maximum number of bytes prepended to a packet */
  68. #define NFP_NET_MAX_PREPEND 64
  69. /* Interrupt definitions */
  70. #define NFP_NET_NON_Q_VECTORS 2
  71. #define NFP_NET_IRQ_LSC_IDX 0
  72. #define NFP_NET_IRQ_EXN_IDX 1
  73. /* Queue/Ring definitions */
  74. #define NFP_NET_MAX_TX_RINGS 64 /* Max. # of Tx rings per device */
  75. #define NFP_NET_MAX_RX_RINGS 64 /* Max. # of Rx rings per device */
  76. #define NFP_NET_MIN_TX_DESCS 256 /* Min. # of Tx descs per ring */
  77. #define NFP_NET_MIN_RX_DESCS 256 /* Min. # of Rx descs per ring */
  78. #define NFP_NET_MAX_TX_DESCS (256 * 1024) /* Max. # of Tx descs per ring */
  79. #define NFP_NET_MAX_RX_DESCS (256 * 1024) /* Max. # of Rx descs per ring */
  80. #define NFP_NET_TX_DESCS_DEFAULT 4096 /* Default # of Tx descs per ring */
  81. #define NFP_NET_RX_DESCS_DEFAULT 4096 /* Default # of Rx descs per ring */
  82. #define NFP_NET_FL_BATCH 16 /* Add freelist in this Batch size */
  83. /* Offload definitions */
  84. #define NFP_NET_N_VXLAN_PORTS (NFP_NET_CFG_VXLAN_SZ / sizeof(__be16))
  85. /* Forward declarations */
  86. struct nfp_net;
  87. struct nfp_net_r_vector;
  88. /* Convenience macro for writing dma address into RX/TX descriptors */
  89. #define nfp_desc_set_dma_addr(desc, dma_addr) \
  90. do { \
  91. __typeof(desc) __d = (desc); \
  92. dma_addr_t __addr = (dma_addr); \
  93. \
  94. __d->dma_addr_lo = cpu_to_le32(lower_32_bits(__addr)); \
  95. __d->dma_addr_hi = upper_32_bits(__addr) & 0xff; \
  96. } while (0)
  97. /* TX descriptor format */
  98. #define PCIE_DESC_TX_EOP BIT(7)
  99. #define PCIE_DESC_TX_OFFSET_MASK GENMASK(6, 0)
  100. #define PCIE_DESC_TX_MSS_MASK GENMASK(13, 0)
  101. /* Flags in the host TX descriptor */
  102. #define PCIE_DESC_TX_CSUM BIT(7)
  103. #define PCIE_DESC_TX_IP4_CSUM BIT(6)
  104. #define PCIE_DESC_TX_TCP_CSUM BIT(5)
  105. #define PCIE_DESC_TX_UDP_CSUM BIT(4)
  106. #define PCIE_DESC_TX_VLAN BIT(3)
  107. #define PCIE_DESC_TX_LSO BIT(2)
  108. #define PCIE_DESC_TX_ENCAP BIT(1)
  109. #define PCIE_DESC_TX_O_IP4_CSUM BIT(0)
  110. struct nfp_net_tx_desc {
  111. union {
  112. struct {
  113. u8 dma_addr_hi; /* High bits of host buf address */
  114. __le16 dma_len; /* Length to DMA for this desc */
  115. u8 offset_eop; /* Offset in buf where pkt starts +
  116. * highest bit is eop flag.
  117. */
  118. __le32 dma_addr_lo; /* Low 32bit of host buf addr */
  119. __le16 mss; /* MSS to be used for LSO */
  120. u8 l4_offset; /* LSO, where the L4 data starts */
  121. u8 flags; /* TX Flags, see @PCIE_DESC_TX_* */
  122. __le16 vlan; /* VLAN tag to add if indicated */
  123. __le16 data_len; /* Length of frame + meta data */
  124. } __packed;
  125. __le32 vals[4];
  126. };
  127. };
  128. /**
  129. * struct nfp_net_tx_buf - software TX buffer descriptor
  130. * @skb: sk_buff associated with this buffer
  131. * @dma_addr: DMA mapping address of the buffer
  132. * @fidx: Fragment index (-1 for the head and [0..nr_frags-1] for frags)
  133. * @pkt_cnt: Number of packets to be produced out of the skb associated
  134. * with this buffer (valid only on the head's buffer).
  135. * Will be 1 for all non-TSO packets.
  136. * @real_len: Number of bytes which to be produced out of the skb (valid only
  137. * on the head's buffer). Equal to skb->len for non-TSO packets.
  138. */
  139. struct nfp_net_tx_buf {
  140. struct sk_buff *skb;
  141. dma_addr_t dma_addr;
  142. short int fidx;
  143. u16 pkt_cnt;
  144. u32 real_len;
  145. };
  146. /**
  147. * struct nfp_net_tx_ring - TX ring structure
  148. * @r_vec: Back pointer to ring vector structure
  149. * @idx: Ring index from Linux's perspective
  150. * @qcidx: Queue Controller Peripheral (QCP) queue index for the TX queue
  151. * @qcp_q: Pointer to base of the QCP TX queue
  152. * @cnt: Size of the queue in number of descriptors
  153. * @wr_p: TX ring write pointer (free running)
  154. * @rd_p: TX ring read pointer (free running)
  155. * @qcp_rd_p: Local copy of QCP TX queue read pointer
  156. * @wr_ptr_add: Accumulated number of buffers to add to QCP write pointer
  157. * (used for .xmit_more delayed kick)
  158. * @txbufs: Array of transmitted TX buffers, to free on transmit
  159. * @txds: Virtual address of TX ring in host memory
  160. * @dma: DMA address of the TX ring
  161. * @size: Size, in bytes, of the TX ring (needed to free)
  162. */
  163. struct nfp_net_tx_ring {
  164. struct nfp_net_r_vector *r_vec;
  165. u32 idx;
  166. int qcidx;
  167. u8 __iomem *qcp_q;
  168. u32 cnt;
  169. u32 wr_p;
  170. u32 rd_p;
  171. u32 qcp_rd_p;
  172. u32 wr_ptr_add;
  173. struct nfp_net_tx_buf *txbufs;
  174. struct nfp_net_tx_desc *txds;
  175. dma_addr_t dma;
  176. unsigned int size;
  177. } ____cacheline_aligned;
  178. /* RX and freelist descriptor format */
  179. #define PCIE_DESC_RX_DD BIT(7)
  180. #define PCIE_DESC_RX_META_LEN_MASK GENMASK(6, 0)
  181. /* Flags in the RX descriptor */
  182. #define PCIE_DESC_RX_RSS cpu_to_le16(BIT(15))
  183. #define PCIE_DESC_RX_I_IP4_CSUM cpu_to_le16(BIT(14))
  184. #define PCIE_DESC_RX_I_IP4_CSUM_OK cpu_to_le16(BIT(13))
  185. #define PCIE_DESC_RX_I_TCP_CSUM cpu_to_le16(BIT(12))
  186. #define PCIE_DESC_RX_I_TCP_CSUM_OK cpu_to_le16(BIT(11))
  187. #define PCIE_DESC_RX_I_UDP_CSUM cpu_to_le16(BIT(10))
  188. #define PCIE_DESC_RX_I_UDP_CSUM_OK cpu_to_le16(BIT(9))
  189. #define PCIE_DESC_RX_SPARE cpu_to_le16(BIT(8))
  190. #define PCIE_DESC_RX_EOP cpu_to_le16(BIT(7))
  191. #define PCIE_DESC_RX_IP4_CSUM cpu_to_le16(BIT(6))
  192. #define PCIE_DESC_RX_IP4_CSUM_OK cpu_to_le16(BIT(5))
  193. #define PCIE_DESC_RX_TCP_CSUM cpu_to_le16(BIT(4))
  194. #define PCIE_DESC_RX_TCP_CSUM_OK cpu_to_le16(BIT(3))
  195. #define PCIE_DESC_RX_UDP_CSUM cpu_to_le16(BIT(2))
  196. #define PCIE_DESC_RX_UDP_CSUM_OK cpu_to_le16(BIT(1))
  197. #define PCIE_DESC_RX_VLAN cpu_to_le16(BIT(0))
  198. #define PCIE_DESC_RX_CSUM_ALL (PCIE_DESC_RX_IP4_CSUM | \
  199. PCIE_DESC_RX_TCP_CSUM | \
  200. PCIE_DESC_RX_UDP_CSUM | \
  201. PCIE_DESC_RX_I_IP4_CSUM | \
  202. PCIE_DESC_RX_I_TCP_CSUM | \
  203. PCIE_DESC_RX_I_UDP_CSUM)
  204. #define PCIE_DESC_RX_CSUM_OK_SHIFT 1
  205. #define __PCIE_DESC_RX_CSUM_ALL le16_to_cpu(PCIE_DESC_RX_CSUM_ALL)
  206. #define __PCIE_DESC_RX_CSUM_ALL_OK (__PCIE_DESC_RX_CSUM_ALL >> \
  207. PCIE_DESC_RX_CSUM_OK_SHIFT)
  208. struct nfp_net_rx_desc {
  209. union {
  210. struct {
  211. u8 dma_addr_hi; /* High bits of the buf address */
  212. __le16 reserved; /* Must be zero */
  213. u8 meta_len_dd; /* Must be zero */
  214. __le32 dma_addr_lo; /* Low bits of the buffer address */
  215. } __packed fld;
  216. struct {
  217. __le16 data_len; /* Length of the frame + meta data */
  218. u8 reserved;
  219. u8 meta_len_dd; /* Length of meta data prepended +
  220. * descriptor done flag.
  221. */
  222. __le16 flags; /* RX flags. See @PCIE_DESC_RX_* */
  223. __le16 vlan; /* VLAN if stripped */
  224. } __packed rxd;
  225. __le32 vals[2];
  226. };
  227. };
  228. struct nfp_net_rx_hash {
  229. __be32 hash_type;
  230. __be32 hash;
  231. };
  232. /**
  233. * struct nfp_net_rx_buf - software RX buffer descriptor
  234. * @skb: sk_buff associated with this buffer
  235. * @dma_addr: DMA mapping address of the buffer
  236. */
  237. struct nfp_net_rx_buf {
  238. struct sk_buff *skb;
  239. dma_addr_t dma_addr;
  240. };
  241. /**
  242. * struct nfp_net_rx_ring - RX ring structure
  243. * @r_vec: Back pointer to ring vector structure
  244. * @cnt: Size of the queue in number of descriptors
  245. * @wr_p: FL/RX ring write pointer (free running)
  246. * @rd_p: FL/RX ring read pointer (free running)
  247. * @idx: Ring index from Linux's perspective
  248. * @fl_qcidx: Queue Controller Peripheral (QCP) queue index for the freelist
  249. * @rx_qcidx: Queue Controller Peripheral (QCP) queue index for the RX queue
  250. * @qcp_fl: Pointer to base of the QCP freelist queue
  251. * @qcp_rx: Pointer to base of the QCP RX queue
  252. * @wr_ptr_add: Accumulated number of buffers to add to QCP write pointer
  253. * (used for free list batching)
  254. * @rxbufs: Array of transmitted FL/RX buffers
  255. * @rxds: Virtual address of FL/RX ring in host memory
  256. * @dma: DMA address of the FL/RX ring
  257. * @size: Size, in bytes, of the FL/RX ring (needed to free)
  258. * @bufsz: Buffer allocation size for convenience of management routines
  259. * (NOTE: this is in second cache line, do not use on fast path!)
  260. */
  261. struct nfp_net_rx_ring {
  262. struct nfp_net_r_vector *r_vec;
  263. u32 cnt;
  264. u32 wr_p;
  265. u32 rd_p;
  266. u16 idx;
  267. u16 wr_ptr_add;
  268. int fl_qcidx;
  269. int rx_qcidx;
  270. u8 __iomem *qcp_fl;
  271. u8 __iomem *qcp_rx;
  272. struct nfp_net_rx_buf *rxbufs;
  273. struct nfp_net_rx_desc *rxds;
  274. dma_addr_t dma;
  275. unsigned int size;
  276. unsigned int bufsz;
  277. } ____cacheline_aligned;
  278. /**
  279. * struct nfp_net_r_vector - Per ring interrupt vector configuration
  280. * @nfp_net: Backpointer to nfp_net structure
  281. * @napi: NAPI structure for this ring vec
  282. * @tx_ring: Pointer to TX ring
  283. * @rx_ring: Pointer to RX ring
  284. * @irq_idx: Index into MSI-X table
  285. * @rx_sync: Seqlock for atomic updates of RX stats
  286. * @rx_pkts: Number of received packets
  287. * @rx_bytes: Number of received bytes
  288. * @rx_drops: Number of packets dropped on RX due to lack of resources
  289. * @hw_csum_rx_ok: Counter of packets where the HW checksum was OK
  290. * @hw_csum_rx_inner_ok: Counter of packets where the inner HW checksum was OK
  291. * @hw_csum_rx_error: Counter of packets with bad checksums
  292. * @tx_sync: Seqlock for atomic updates of TX stats
  293. * @tx_pkts: Number of Transmitted packets
  294. * @tx_bytes: Number of Transmitted bytes
  295. * @hw_csum_tx: Counter of packets with TX checksum offload requested
  296. * @hw_csum_tx_inner: Counter of inner TX checksum offload requests
  297. * @tx_gather: Counter of packets with Gather DMA
  298. * @tx_lso: Counter of LSO packets sent
  299. * @tx_errors: How many TX errors were encountered
  300. * @tx_busy: How often was TX busy (no space)?
  301. * @handler: Interrupt handler for this ring vector
  302. * @name: Name of the interrupt vector
  303. * @affinity_mask: SMP affinity mask for this vector
  304. *
  305. * This structure ties RX and TX rings to interrupt vectors and a NAPI
  306. * context. This currently only supports one RX and TX ring per
  307. * interrupt vector but might be extended in the future to allow
  308. * association of multiple rings per vector.
  309. */
  310. struct nfp_net_r_vector {
  311. struct nfp_net *nfp_net;
  312. struct napi_struct napi;
  313. struct nfp_net_tx_ring *tx_ring;
  314. struct nfp_net_rx_ring *rx_ring;
  315. int irq_idx;
  316. struct u64_stats_sync rx_sync;
  317. u64 rx_pkts;
  318. u64 rx_bytes;
  319. u64 rx_drops;
  320. u64 hw_csum_rx_ok;
  321. u64 hw_csum_rx_inner_ok;
  322. u64 hw_csum_rx_error;
  323. struct u64_stats_sync tx_sync;
  324. u64 tx_pkts;
  325. u64 tx_bytes;
  326. u64 hw_csum_tx;
  327. u64 hw_csum_tx_inner;
  328. u64 tx_gather;
  329. u64 tx_lso;
  330. u64 tx_errors;
  331. u64 tx_busy;
  332. irq_handler_t handler;
  333. char name[IFNAMSIZ + 8];
  334. cpumask_t affinity_mask;
  335. } ____cacheline_aligned;
  336. /* Firmware version as it is written in the 32bit value in the BAR */
  337. struct nfp_net_fw_version {
  338. u8 minor;
  339. u8 major;
  340. u8 class;
  341. u8 resv;
  342. } __packed;
  343. static inline bool nfp_net_fw_ver_eq(struct nfp_net_fw_version *fw_ver,
  344. u8 resv, u8 class, u8 major, u8 minor)
  345. {
  346. return fw_ver->resv == resv &&
  347. fw_ver->class == class &&
  348. fw_ver->major == major &&
  349. fw_ver->minor == minor;
  350. }
  351. /**
  352. * struct nfp_net - NFP network device structure
  353. * @pdev: Backpointer to PCI device
  354. * @netdev: Backpointer to net_device structure
  355. * @nfp_fallback: Is the driver used in fallback mode?
  356. * @is_vf: Is the driver attached to a VF?
  357. * @is_nfp3200: Is the driver for a NFP-3200 card?
  358. * @fw_loaded: Is the firmware loaded?
  359. * @ctrl: Local copy of the control register/word.
  360. * @fl_bufsz: Currently configured size of the freelist buffers
  361. * @rx_offset: Offset in the RX buffers where packet data starts
  362. * @cpp: Pointer to the CPP handle
  363. * @nfp_dev_cpp: Pointer to the NFP Device handle
  364. * @ctrl_area: Pointer to the CPP area for the control BAR
  365. * @tx_area: Pointer to the CPP area for the TX queues
  366. * @rx_area: Pointer to the CPP area for the FL/RX queues
  367. * @fw_ver: Firmware version
  368. * @cap: Capabilities advertised by the Firmware
  369. * @max_mtu: Maximum support MTU advertised by the Firmware
  370. * @rss_cfg: RSS configuration
  371. * @rss_key: RSS secret key
  372. * @rss_itbl: RSS indirection table
  373. * @max_tx_rings: Maximum number of TX rings supported by the Firmware
  374. * @max_rx_rings: Maximum number of RX rings supported by the Firmware
  375. * @num_tx_rings: Currently configured number of TX rings
  376. * @num_rx_rings: Currently configured number of RX rings
  377. * @txd_cnt: Size of the TX ring in number of descriptors
  378. * @rxd_cnt: Size of the RX ring in number of descriptors
  379. * @tx_rings: Array of pre-allocated TX ring structures
  380. * @rx_rings: Array of pre-allocated RX ring structures
  381. * @num_irqs: Number of allocated interrupt vectors
  382. * @num_r_vecs: Number of used ring vectors
  383. * @r_vecs: Pre-allocated array of ring vectors
  384. * @irq_entries: Pre-allocated array of MSI-X entries
  385. * @lsc_handler: Handler for Link State Change interrupt
  386. * @lsc_name: Name for Link State Change interrupt
  387. * @exn_handler: Handler for Exception interrupt
  388. * @exn_name: Name for Exception interrupt
  389. * @shared_handler: Handler for shared interrupts
  390. * @shared_name: Name for shared interrupt
  391. * @me_freq_mhz: ME clock_freq (MHz)
  392. * @reconfig_lock: Protects HW reconfiguration request regs/machinery
  393. * @reconfig_posted: Pending reconfig bits coming from async sources
  394. * @reconfig_timer_active: Timer for reading reconfiguration results is pending
  395. * @reconfig_sync_present: Some thread is performing synchronous reconfig
  396. * @reconfig_timer: Timer for async reading of reconfig results
  397. * @link_up: Is the link up?
  398. * @link_status_lock: Protects @link_up and ensures atomicity with BAR reading
  399. * @rx_coalesce_usecs: RX interrupt moderation usecs delay parameter
  400. * @rx_coalesce_max_frames: RX interrupt moderation frame count parameter
  401. * @tx_coalesce_usecs: TX interrupt moderation usecs delay parameter
  402. * @tx_coalesce_max_frames: TX interrupt moderation frame count parameter
  403. * @vxlan_ports: VXLAN ports for RX inner csum offload communicated to HW
  404. * @vxlan_usecnt: IPv4/IPv6 VXLAN port use counts
  405. * @qcp_cfg: Pointer to QCP queue used for configuration notification
  406. * @ctrl_bar: Pointer to mapped control BAR
  407. * @tx_bar: Pointer to mapped TX queues
  408. * @rx_bar: Pointer to mapped FL/RX queues
  409. * @debugfs_dir: Device directory in debugfs
  410. */
  411. struct nfp_net {
  412. struct pci_dev *pdev;
  413. struct net_device *netdev;
  414. unsigned nfp_fallback:1;
  415. unsigned is_vf:1;
  416. unsigned is_nfp3200:1;
  417. unsigned fw_loaded:1;
  418. u32 ctrl;
  419. u32 fl_bufsz;
  420. u32 rx_offset;
  421. struct nfp_net_tx_ring *tx_rings;
  422. struct nfp_net_rx_ring *rx_rings;
  423. #ifdef CONFIG_PCI_IOV
  424. unsigned int num_vfs;
  425. struct vf_data_storage *vfinfo;
  426. int vf_rate_link_speed;
  427. #endif
  428. struct nfp_cpp *cpp;
  429. struct platform_device *nfp_dev_cpp;
  430. struct nfp_cpp_area *ctrl_area;
  431. struct nfp_cpp_area *tx_area;
  432. struct nfp_cpp_area *rx_area;
  433. struct nfp_net_fw_version fw_ver;
  434. u32 cap;
  435. u32 max_mtu;
  436. u32 rss_cfg;
  437. u8 rss_key[NFP_NET_CFG_RSS_KEY_SZ];
  438. u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ];
  439. int max_tx_rings;
  440. int max_rx_rings;
  441. int num_tx_rings;
  442. int num_rx_rings;
  443. int stride_tx;
  444. int stride_rx;
  445. int txd_cnt;
  446. int rxd_cnt;
  447. u8 num_irqs;
  448. u8 num_r_vecs;
  449. struct nfp_net_r_vector r_vecs[NFP_NET_MAX_TX_RINGS];
  450. struct msix_entry irq_entries[NFP_NET_NON_Q_VECTORS +
  451. NFP_NET_MAX_TX_RINGS];
  452. irq_handler_t lsc_handler;
  453. char lsc_name[IFNAMSIZ + 8];
  454. irq_handler_t exn_handler;
  455. char exn_name[IFNAMSIZ + 8];
  456. irq_handler_t shared_handler;
  457. char shared_name[IFNAMSIZ + 8];
  458. u32 me_freq_mhz;
  459. bool link_up;
  460. spinlock_t link_status_lock;
  461. spinlock_t reconfig_lock;
  462. u32 reconfig_posted;
  463. bool reconfig_timer_active;
  464. bool reconfig_sync_present;
  465. struct timer_list reconfig_timer;
  466. u32 rx_coalesce_usecs;
  467. u32 rx_coalesce_max_frames;
  468. u32 tx_coalesce_usecs;
  469. u32 tx_coalesce_max_frames;
  470. __be16 vxlan_ports[NFP_NET_N_VXLAN_PORTS];
  471. u8 vxlan_usecnt[NFP_NET_N_VXLAN_PORTS];
  472. u8 __iomem *qcp_cfg;
  473. u8 __iomem *ctrl_bar;
  474. u8 __iomem *q_bar;
  475. u8 __iomem *tx_bar;
  476. u8 __iomem *rx_bar;
  477. struct dentry *debugfs_dir;
  478. };
  479. /* Functions to read/write from/to a BAR
  480. * Performs any endian conversion necessary.
  481. */
  482. static inline void nn_writeb(struct nfp_net *nn, int off, u8 val)
  483. {
  484. writeb(val, nn->ctrl_bar + off);
  485. }
  486. /* NFP-3200 can't handle 16-bit accesses too well - hence no readw/writew */
  487. static inline u32 nn_readl(struct nfp_net *nn, int off)
  488. {
  489. return readl(nn->ctrl_bar + off);
  490. }
  491. static inline void nn_writel(struct nfp_net *nn, int off, u32 val)
  492. {
  493. writel(val, nn->ctrl_bar + off);
  494. }
  495. static inline u64 nn_readq(struct nfp_net *nn, int off)
  496. {
  497. return readq(nn->ctrl_bar + off);
  498. }
  499. static inline void nn_writeq(struct nfp_net *nn, int off, u64 val)
  500. {
  501. writeq(val, nn->ctrl_bar + off);
  502. }
  503. /* Flush posted PCI writes by reading something without side effects */
  504. static inline void nn_pci_flush(struct nfp_net *nn)
  505. {
  506. nn_readl(nn, NFP_NET_CFG_VERSION);
  507. }
  508. /* Queue Controller Peripheral access functions and definitions.
  509. *
  510. * Some of the BARs of the NFP are mapped to portions of the Queue
  511. * Controller Peripheral (QCP) address space on the NFP. A QCP queue
  512. * has a read and a write pointer (as well as a size and flags,
  513. * indicating overflow etc). The QCP offers a number of different
  514. * operation on queue pointers, but here we only offer function to
  515. * either add to a pointer or to read the pointer value.
  516. */
  517. #define NFP_QCP_QUEUE_ADDR_SZ 0x800
  518. #define NFP_QCP_QUEUE_OFF(_x) ((_x) * NFP_QCP_QUEUE_ADDR_SZ)
  519. #define NFP_QCP_QUEUE_ADD_RPTR 0x0000
  520. #define NFP_QCP_QUEUE_ADD_WPTR 0x0004
  521. #define NFP_QCP_QUEUE_STS_LO 0x0008
  522. #define NFP_QCP_QUEUE_STS_LO_READPTR_mask 0x3ffff
  523. #define NFP_QCP_QUEUE_STS_HI 0x000c
  524. #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask 0x3ffff
  525. /* The offset of a QCP queues in the PCIe Target (same on NFP3200 and NFP6000 */
  526. #define NFP_PCIE_QUEUE(_q) (0x80000 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff)))
  527. /* nfp_qcp_ptr - Read or Write Pointer of a queue */
  528. enum nfp_qcp_ptr {
  529. NFP_QCP_READ_PTR = 0,
  530. NFP_QCP_WRITE_PTR
  531. };
  532. /* There appear to be an *undocumented* upper limit on the value which
  533. * one can add to a queue and that value is either 0x3f or 0x7f. We
  534. * go with 0x3f as a conservative measure.
  535. */
  536. #define NFP_QCP_MAX_ADD 0x3f
  537. static inline void _nfp_qcp_ptr_add(u8 __iomem *q,
  538. enum nfp_qcp_ptr ptr, u32 val)
  539. {
  540. u32 off;
  541. if (ptr == NFP_QCP_READ_PTR)
  542. off = NFP_QCP_QUEUE_ADD_RPTR;
  543. else
  544. off = NFP_QCP_QUEUE_ADD_WPTR;
  545. while (val > NFP_QCP_MAX_ADD) {
  546. writel(NFP_QCP_MAX_ADD, q + off);
  547. val -= NFP_QCP_MAX_ADD;
  548. }
  549. writel(val, q + off);
  550. }
  551. /**
  552. * nfp_qcp_rd_ptr_add() - Add the value to the read pointer of a queue
  553. *
  554. * @q: Base address for queue structure
  555. * @val: Value to add to the queue pointer
  556. *
  557. * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed.
  558. */
  559. static inline void nfp_qcp_rd_ptr_add(u8 __iomem *q, u32 val)
  560. {
  561. _nfp_qcp_ptr_add(q, NFP_QCP_READ_PTR, val);
  562. }
  563. /**
  564. * nfp_qcp_wr_ptr_add() - Add the value to the write pointer of a queue
  565. *
  566. * @q: Base address for queue structure
  567. * @val: Value to add to the queue pointer
  568. *
  569. * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed.
  570. */
  571. static inline void nfp_qcp_wr_ptr_add(u8 __iomem *q, u32 val)
  572. {
  573. _nfp_qcp_ptr_add(q, NFP_QCP_WRITE_PTR, val);
  574. }
  575. static inline u32 _nfp_qcp_read(u8 __iomem *q, enum nfp_qcp_ptr ptr)
  576. {
  577. u32 off;
  578. u32 val;
  579. if (ptr == NFP_QCP_READ_PTR)
  580. off = NFP_QCP_QUEUE_STS_LO;
  581. else
  582. off = NFP_QCP_QUEUE_STS_HI;
  583. val = readl(q + off);
  584. if (ptr == NFP_QCP_READ_PTR)
  585. return val & NFP_QCP_QUEUE_STS_LO_READPTR_mask;
  586. else
  587. return val & NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask;
  588. }
  589. /**
  590. * nfp_qcp_rd_ptr_read() - Read the current read pointer value for a queue
  591. * @q: Base address for queue structure
  592. *
  593. * Return: Value read.
  594. */
  595. static inline u32 nfp_qcp_rd_ptr_read(u8 __iomem *q)
  596. {
  597. return _nfp_qcp_read(q, NFP_QCP_READ_PTR);
  598. }
  599. /**
  600. * nfp_qcp_wr_ptr_read() - Read the current write pointer value for a queue
  601. * @q: Base address for queue structure
  602. *
  603. * Return: Value read.
  604. */
  605. static inline u32 nfp_qcp_wr_ptr_read(u8 __iomem *q)
  606. {
  607. return _nfp_qcp_read(q, NFP_QCP_WRITE_PTR);
  608. }
  609. /* Globals */
  610. extern const char nfp_net_driver_name[];
  611. extern const char nfp_net_driver_version[];
  612. /* Prototypes */
  613. void nfp_net_get_fw_version(struct nfp_net_fw_version *fw_ver,
  614. void __iomem *ctrl_bar);
  615. struct nfp_net *nfp_net_netdev_alloc(struct pci_dev *pdev,
  616. int max_tx_rings, int max_rx_rings);
  617. void nfp_net_netdev_free(struct nfp_net *nn);
  618. int nfp_net_netdev_init(struct net_device *netdev);
  619. void nfp_net_netdev_clean(struct net_device *netdev);
  620. void nfp_net_set_ethtool_ops(struct net_device *netdev);
  621. void nfp_net_info(struct nfp_net *nn);
  622. int nfp_net_reconfig(struct nfp_net *nn, u32 update);
  623. void nfp_net_rss_write_itbl(struct nfp_net *nn);
  624. void nfp_net_rss_write_key(struct nfp_net *nn);
  625. void nfp_net_coalesce_write_cfg(struct nfp_net *nn);
  626. int nfp_net_irqs_alloc(struct nfp_net *nn);
  627. void nfp_net_irqs_disable(struct nfp_net *nn);
  628. int nfp_net_set_ring_size(struct nfp_net *nn, u32 rxd_cnt, u32 txd_cnt);
  629. #ifdef CONFIG_NFP_NET_DEBUG
  630. void nfp_net_debugfs_create(void);
  631. void nfp_net_debugfs_destroy(void);
  632. void nfp_net_debugfs_adapter_add(struct nfp_net *nn);
  633. void nfp_net_debugfs_adapter_del(struct nfp_net *nn);
  634. #else
  635. static inline void nfp_net_debugfs_create(void)
  636. {
  637. }
  638. static inline void nfp_net_debugfs_destroy(void)
  639. {
  640. }
  641. static inline void nfp_net_debugfs_adapter_add(struct nfp_net *nn)
  642. {
  643. }
  644. static inline void nfp_net_debugfs_adapter_del(struct nfp_net *nn)
  645. {
  646. }
  647. #endif /* CONFIG_NFP_NET_DEBUG */
  648. #endif /* _NFP_NET_H_ */