ionic_lif.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
  3. #ifndef _IONIC_LIF_H_
  4. #define _IONIC_LIF_H_
  5. #include <linux/ptp_clock_kernel.h>
  6. #include <linux/timecounter.h>
  7. #include <uapi/linux/net_tstamp.h>
  8. #include <linux/dim.h>
  9. #include <linux/pci.h>
  10. #include "ionic_rx_filter.h"
  11. #define IONIC_ADMINQ_LENGTH 16 /* must be a power of two */
  12. #define IONIC_NOTIFYQ_LENGTH 64 /* must be a power of two */
  13. #define ADD_ADDR true
  14. #define DEL_ADDR false
  15. #define CAN_SLEEP true
  16. #define CAN_NOT_SLEEP false
  17. #define IONIC_RX_COPYBREAK_DEFAULT 256
  18. #define IONIC_TX_BUDGET_DEFAULT 256
  19. struct ionic_tx_stats {
  20. u64 pkts;
  21. u64 bytes;
  22. u64 csum_none;
  23. u64 csum;
  24. u64 tso;
  25. u64 tso_bytes;
  26. u64 frags;
  27. u64 vlan_inserted;
  28. u64 clean;
  29. u64 linearize;
  30. u64 crc32_csum;
  31. u64 dma_map_err;
  32. u64 hwstamp_valid;
  33. u64 hwstamp_invalid;
  34. u64 xdp_frames;
  35. };
  36. struct ionic_rx_stats {
  37. u64 pkts;
  38. u64 bytes;
  39. u64 csum_none;
  40. u64 csum_complete;
  41. u64 dropped;
  42. u64 vlan_stripped;
  43. u64 csum_error;
  44. u64 dma_map_err;
  45. u64 alloc_err;
  46. u64 hwstamp_valid;
  47. u64 hwstamp_invalid;
  48. u64 xdp_drop;
  49. u64 xdp_aborted;
  50. u64 xdp_pass;
  51. u64 xdp_tx;
  52. u64 xdp_redirect;
  53. };
  54. #define IONIC_QCQ_F_INITED BIT(0)
  55. #define IONIC_QCQ_F_SG BIT(1)
  56. #define IONIC_QCQ_F_INTR BIT(2)
  57. #define IONIC_QCQ_F_TX_STATS BIT(3)
  58. #define IONIC_QCQ_F_RX_STATS BIT(4)
  59. #define IONIC_QCQ_F_NOTIFYQ BIT(5)
  60. #define IONIC_QCQ_F_CMB_RINGS BIT(6)
  61. struct ionic_qcq {
  62. void *q_base;
  63. dma_addr_t q_base_pa;
  64. u32 q_size;
  65. u32 cq_size;
  66. void *cq_base;
  67. dma_addr_t cq_base_pa;
  68. void *sg_base;
  69. dma_addr_t sg_base_pa;
  70. u32 sg_size;
  71. unsigned int flags;
  72. void __iomem *cmb_q_base;
  73. phys_addr_t cmb_q_base_pa;
  74. u32 cmb_q_size;
  75. u32 cmb_pgid;
  76. u32 cmb_order;
  77. struct dim dim;
  78. struct ionic_queue q;
  79. struct ionic_cq cq;
  80. struct napi_struct napi;
  81. struct ionic_intr_info intr;
  82. struct work_struct doorbell_napi_work;
  83. struct dentry *dentry;
  84. };
  85. #define q_to_qcq(q) container_of(q, struct ionic_qcq, q)
  86. #define q_to_tx_stats(q) (&(q)->lif->txqstats[(q)->index])
  87. #define q_to_rx_stats(q) (&(q)->lif->rxqstats[(q)->index])
  88. #define napi_to_qcq(napi) container_of(napi, struct ionic_qcq, napi)
  89. #define napi_to_cq(napi) (&napi_to_qcq(napi)->cq)
  90. enum ionic_deferred_work_type {
  91. IONIC_DW_TYPE_RX_MODE,
  92. IONIC_DW_TYPE_LINK_STATUS,
  93. IONIC_DW_TYPE_LIF_RESET,
  94. };
  95. struct ionic_deferred_work {
  96. struct list_head list;
  97. enum ionic_deferred_work_type type;
  98. union {
  99. u8 addr[ETH_ALEN];
  100. u8 fw_status;
  101. };
  102. };
  103. struct ionic_deferred {
  104. spinlock_t lock; /* lock for deferred work list */
  105. struct list_head list;
  106. struct work_struct work;
  107. };
  108. struct ionic_lif_sw_stats {
  109. u64 tx_packets;
  110. u64 tx_bytes;
  111. u64 rx_packets;
  112. u64 rx_bytes;
  113. u64 tx_tso;
  114. u64 tx_tso_bytes;
  115. u64 tx_csum_none;
  116. u64 tx_csum;
  117. u64 rx_csum_none;
  118. u64 rx_csum_complete;
  119. u64 rx_csum_error;
  120. u64 tx_hwstamp_valid;
  121. u64 tx_hwstamp_invalid;
  122. u64 rx_hwstamp_valid;
  123. u64 rx_hwstamp_invalid;
  124. u64 hw_tx_dropped;
  125. u64 hw_rx_dropped;
  126. u64 hw_rx_over_errors;
  127. u64 hw_rx_missed_errors;
  128. u64 hw_tx_aborted_errors;
  129. u64 xdp_drop;
  130. u64 xdp_aborted;
  131. u64 xdp_pass;
  132. u64 xdp_tx;
  133. u64 xdp_redirect;
  134. u64 xdp_frames;
  135. };
  136. enum ionic_lif_state_flags {
  137. IONIC_LIF_F_INITED,
  138. IONIC_LIF_F_UP,
  139. IONIC_LIF_F_LINK_CHECK_REQUESTED,
  140. IONIC_LIF_F_FILTER_SYNC_NEEDED,
  141. IONIC_LIF_F_FW_RESET,
  142. IONIC_LIF_F_FW_STOPPING,
  143. IONIC_LIF_F_SPLIT_INTR,
  144. IONIC_LIF_F_BROKEN,
  145. IONIC_LIF_F_TX_DIM_INTR,
  146. IONIC_LIF_F_RX_DIM_INTR,
  147. IONIC_LIF_F_CMB_TX_RINGS,
  148. IONIC_LIF_F_CMB_RX_RINGS,
  149. /* leave this as last */
  150. IONIC_LIF_F_STATE_SIZE
  151. };
  152. struct ionic_qtype_info {
  153. u8 version;
  154. u8 supported;
  155. u64 features;
  156. u16 desc_sz;
  157. u16 comp_sz;
  158. u16 sg_desc_sz;
  159. u16 max_sg_elems;
  160. u16 sg_desc_stride;
  161. };
  162. struct ionic_phc;
  163. #define IONIC_LIF_NAME_MAX_SZ 32
  164. struct ionic_lif {
  165. struct net_device *netdev;
  166. DECLARE_BITMAP(state, IONIC_LIF_F_STATE_SIZE);
  167. struct ionic *ionic;
  168. unsigned int index;
  169. unsigned int hw_index;
  170. struct mutex queue_lock; /* lock for queue structures */
  171. struct mutex config_lock; /* lock for config actions */
  172. spinlock_t adminq_lock; /* lock for AdminQ operations */
  173. struct ionic_qcq *adminqcq;
  174. struct ionic_qcq *notifyqcq;
  175. struct ionic_qcq **txqcqs;
  176. struct ionic_qcq *hwstamp_txq;
  177. struct ionic_tx_stats *txqstats;
  178. struct ionic_qcq **rxqcqs;
  179. struct ionic_qcq *hwstamp_rxq;
  180. struct ionic_rx_stats *rxqstats;
  181. struct ionic_deferred deferred;
  182. struct work_struct tx_timeout_work;
  183. u64 last_eid;
  184. unsigned int kern_pid;
  185. u64 __iomem *kern_dbpage;
  186. unsigned int neqs;
  187. unsigned int nxqs;
  188. unsigned int ntxq_descs;
  189. unsigned int nrxq_descs;
  190. u64 rxq_features;
  191. u64 hw_features;
  192. u16 rx_copybreak;
  193. u16 rx_mode;
  194. bool registered;
  195. bool doorbell_wa;
  196. u16 lif_type;
  197. unsigned int link_down_count;
  198. unsigned int nmcast;
  199. unsigned int nucast;
  200. unsigned int nvlans;
  201. unsigned int max_vlans;
  202. char name[IONIC_LIF_NAME_MAX_SZ];
  203. union ionic_lif_identity *identity;
  204. struct ionic_lif_info *info;
  205. dma_addr_t info_pa;
  206. u32 info_sz;
  207. struct ionic_qtype_info qtype_info[IONIC_QTYPE_MAX];
  208. u8 rss_hash_key[IONIC_RSS_HASH_KEY_SIZE];
  209. u8 *rss_ind_tbl;
  210. dma_addr_t rss_ind_tbl_pa;
  211. u32 rss_ind_tbl_sz;
  212. u16 rss_types;
  213. struct ionic_rx_filters rx_filters;
  214. u32 rx_coalesce_usecs; /* what the user asked for */
  215. u32 rx_coalesce_hw; /* what the hw is using */
  216. u32 tx_coalesce_usecs; /* what the user asked for */
  217. u32 tx_coalesce_hw; /* what the hw is using */
  218. unsigned int dbid_count;
  219. struct ionic_phc *phc;
  220. struct dentry *dentry;
  221. struct bpf_prog *xdp_prog;
  222. };
  223. struct ionic_phc {
  224. spinlock_t lock; /* lock for cc and tc */
  225. struct cyclecounter cc;
  226. struct timecounter tc;
  227. struct mutex config_lock; /* lock for ts_config */
  228. struct hwtstamp_config ts_config;
  229. u64 ts_config_rx_filt;
  230. u32 ts_config_tx_mode;
  231. u32 init_cc_mult;
  232. long aux_work_delay;
  233. struct ptp_clock_info ptp_info;
  234. struct ptp_clock *ptp;
  235. struct ionic_lif *lif;
  236. };
  237. struct ionic_queue_params {
  238. unsigned int nxqs;
  239. unsigned int ntxq_descs;
  240. unsigned int nrxq_descs;
  241. u64 rxq_features;
  242. struct bpf_prog *xdp_prog;
  243. bool intr_split;
  244. bool cmb_tx;
  245. bool cmb_rx;
  246. };
  247. static inline void ionic_init_queue_params(struct ionic_lif *lif,
  248. struct ionic_queue_params *qparam)
  249. {
  250. qparam->nxqs = lif->nxqs;
  251. qparam->ntxq_descs = lif->ntxq_descs;
  252. qparam->nrxq_descs = lif->nrxq_descs;
  253. qparam->rxq_features = lif->rxq_features;
  254. qparam->xdp_prog = lif->xdp_prog;
  255. qparam->intr_split = test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
  256. qparam->cmb_tx = test_bit(IONIC_LIF_F_CMB_TX_RINGS, lif->state);
  257. qparam->cmb_rx = test_bit(IONIC_LIF_F_CMB_RX_RINGS, lif->state);
  258. }
  259. static inline void ionic_set_queue_params(struct ionic_lif *lif,
  260. struct ionic_queue_params *qparam)
  261. {
  262. lif->nxqs = qparam->nxqs;
  263. lif->ntxq_descs = qparam->ntxq_descs;
  264. lif->nrxq_descs = qparam->nrxq_descs;
  265. lif->rxq_features = qparam->rxq_features;
  266. if (qparam->intr_split)
  267. set_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
  268. else
  269. clear_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
  270. if (qparam->cmb_tx)
  271. set_bit(IONIC_LIF_F_CMB_TX_RINGS, lif->state);
  272. else
  273. clear_bit(IONIC_LIF_F_CMB_TX_RINGS, lif->state);
  274. if (qparam->cmb_rx)
  275. set_bit(IONIC_LIF_F_CMB_RX_RINGS, lif->state);
  276. else
  277. clear_bit(IONIC_LIF_F_CMB_RX_RINGS, lif->state);
  278. }
  279. static inline u32 ionic_coal_usec_to_hw(struct ionic *ionic, u32 usecs)
  280. {
  281. u32 mult = le32_to_cpu(ionic->ident.dev.intr_coal_mult);
  282. u32 div = le32_to_cpu(ionic->ident.dev.intr_coal_div);
  283. /* Div-by-zero should never be an issue, but check anyway */
  284. if (!div || !mult)
  285. return 0;
  286. /* Round up in case usecs is close to the next hw unit */
  287. usecs += (div / mult) >> 1;
  288. /* Convert from usecs to device units */
  289. return (usecs * mult) / div;
  290. }
  291. static inline bool ionic_txq_hwstamp_enabled(struct ionic_queue *q)
  292. {
  293. return q->features & IONIC_TXQ_F_HWSTAMP;
  294. }
  295. void ionic_link_status_check_request(struct ionic_lif *lif, bool can_sleep);
  296. void ionic_get_stats64(struct net_device *netdev,
  297. struct rtnl_link_stats64 *ns);
  298. void ionic_lif_deferred_enqueue(struct ionic_lif *lif,
  299. struct ionic_deferred_work *work);
  300. int ionic_lif_alloc(struct ionic *ionic);
  301. int ionic_lif_init(struct ionic_lif *lif);
  302. void ionic_lif_free(struct ionic_lif *lif);
  303. void ionic_lif_deinit(struct ionic_lif *lif);
  304. int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr);
  305. int ionic_lif_addr_del(struct ionic_lif *lif, const u8 *addr);
  306. void ionic_stop_queues_reconfig(struct ionic_lif *lif);
  307. void ionic_txrx_free(struct ionic_lif *lif);
  308. void ionic_qcqs_free(struct ionic_lif *lif);
  309. int ionic_restart_lif(struct ionic_lif *lif);
  310. int ionic_lif_register(struct ionic_lif *lif);
  311. void ionic_lif_unregister(struct ionic_lif *lif);
  312. int ionic_lif_identify(struct ionic *ionic, u8 lif_type,
  313. union ionic_lif_identity *lif_ident);
  314. int ionic_lif_size(struct ionic *ionic);
  315. #if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
  316. void ionic_lif_hwstamp_replay(struct ionic_lif *lif);
  317. void ionic_lif_hwstamp_recreate_queues(struct ionic_lif *lif);
  318. int ionic_lif_hwstamp_set(struct ionic_lif *lif, struct ifreq *ifr);
  319. int ionic_lif_hwstamp_get(struct ionic_lif *lif, struct ifreq *ifr);
  320. ktime_t ionic_lif_phc_ktime(struct ionic_lif *lif, u64 counter);
  321. void ionic_lif_register_phc(struct ionic_lif *lif);
  322. void ionic_lif_unregister_phc(struct ionic_lif *lif);
  323. void ionic_lif_alloc_phc(struct ionic_lif *lif);
  324. void ionic_lif_free_phc(struct ionic_lif *lif);
  325. #else
  326. static inline void ionic_lif_hwstamp_replay(struct ionic_lif *lif) {}
  327. static inline void ionic_lif_hwstamp_recreate_queues(struct ionic_lif *lif) {}
  328. static inline int ionic_lif_hwstamp_set(struct ionic_lif *lif, struct ifreq *ifr)
  329. {
  330. return -EOPNOTSUPP;
  331. }
  332. static inline int ionic_lif_hwstamp_get(struct ionic_lif *lif, struct ifreq *ifr)
  333. {
  334. return -EOPNOTSUPP;
  335. }
  336. static inline ktime_t ionic_lif_phc_ktime(struct ionic_lif *lif, u64 counter)
  337. {
  338. return ns_to_ktime(0);
  339. }
  340. static inline void ionic_lif_register_phc(struct ionic_lif *lif) {}
  341. static inline void ionic_lif_unregister_phc(struct ionic_lif *lif) {}
  342. static inline void ionic_lif_alloc_phc(struct ionic_lif *lif) {}
  343. static inline void ionic_lif_free_phc(struct ionic_lif *lif) {}
  344. #endif
  345. int ionic_lif_create_hwstamp_txq(struct ionic_lif *lif);
  346. int ionic_lif_create_hwstamp_rxq(struct ionic_lif *lif);
  347. int ionic_lif_config_hwstamp_rxq_all(struct ionic_lif *lif, bool rx_all);
  348. int ionic_lif_set_hwstamp_txmode(struct ionic_lif *lif, u16 txstamp_mode);
  349. int ionic_lif_set_hwstamp_rxfilt(struct ionic_lif *lif, u64 pkt_class);
  350. int ionic_lif_rss_config(struct ionic_lif *lif, u16 types,
  351. const u8 *key, const u32 *indir);
  352. void ionic_lif_rx_mode(struct ionic_lif *lif);
  353. int ionic_reconfigure_queues(struct ionic_lif *lif,
  354. struct ionic_queue_params *qparam);
  355. #endif /* _IONIC_LIF_H_ */