ena_com.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. /*
  2. * Copyright 2015 Amazon.com, Inc. or its affiliates.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef ENA_COM
  33. #define ENA_COM
  34. #include <linux/compiler.h>
  35. #include <linux/delay.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/gfp.h>
  38. #include <linux/io.h>
  39. #include <linux/prefetch.h>
  40. #include <linux/sched.h>
  41. #include <linux/sizes.h>
  42. #include <linux/spinlock.h>
  43. #include <linux/types.h>
  44. #include <linux/wait.h>
  45. #include <linux/netdevice.h>
  46. #include "ena_common_defs.h"
  47. #include "ena_admin_defs.h"
  48. #include "ena_eth_io_defs.h"
  49. #include "ena_regs_defs.h"
  50. #undef pr_fmt
  51. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  52. #define ENA_MAX_NUM_IO_QUEUES 128U
  53. /* We need to queues for each IO (on for Tx and one for Rx) */
  54. #define ENA_TOTAL_NUM_QUEUES (2 * (ENA_MAX_NUM_IO_QUEUES))
  55. #define ENA_MAX_HANDLERS 256
  56. #define ENA_MAX_PHYS_ADDR_SIZE_BITS 48
  57. /* Unit in usec */
  58. #define ENA_REG_READ_TIMEOUT 200000
  59. #define ADMIN_SQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aq_entry))
  60. #define ADMIN_CQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_acq_entry))
  61. #define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry))
  62. /*****************************************************************************/
  63. /*****************************************************************************/
  64. /* ENA adaptive interrupt moderation settings */
  65. #define ENA_INTR_INITIAL_TX_INTERVAL_USECS 196
  66. #define ENA_INTR_INITIAL_RX_INTERVAL_USECS 0
  67. #define ENA_DEFAULT_INTR_DELAY_RESOLUTION 1
  68. #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
  69. #define ENA_FEATURE_MAX_QUEUE_EXT_VER 1
  70. struct ena_llq_configurations {
  71. enum ena_admin_llq_header_location llq_header_location;
  72. enum ena_admin_llq_ring_entry_size llq_ring_entry_size;
  73. enum ena_admin_llq_stride_ctrl llq_stride_ctrl;
  74. enum ena_admin_llq_num_descs_before_header llq_num_decs_before_header;
  75. u16 llq_ring_entry_size_value;
  76. };
  77. enum queue_direction {
  78. ENA_COM_IO_QUEUE_DIRECTION_TX,
  79. ENA_COM_IO_QUEUE_DIRECTION_RX
  80. };
  81. struct ena_com_buf {
  82. dma_addr_t paddr; /**< Buffer physical address */
  83. u16 len; /**< Buffer length in bytes */
  84. };
  85. struct ena_com_rx_buf_info {
  86. u16 len;
  87. u16 req_id;
  88. };
  89. struct ena_com_io_desc_addr {
  90. u8 __iomem *pbuf_dev_addr; /* LLQ address */
  91. u8 *virt_addr;
  92. dma_addr_t phys_addr;
  93. };
  94. struct ena_com_tx_meta {
  95. u16 mss;
  96. u16 l3_hdr_len;
  97. u16 l3_hdr_offset;
  98. u16 l4_hdr_len; /* In words */
  99. };
  100. struct ena_com_llq_info {
  101. u16 header_location_ctrl;
  102. u16 desc_stride_ctrl;
  103. u16 desc_list_entry_size_ctrl;
  104. u16 desc_list_entry_size;
  105. u16 descs_num_before_header;
  106. u16 descs_per_entry;
  107. u16 max_entries_in_tx_burst;
  108. };
  109. struct ena_com_io_cq {
  110. struct ena_com_io_desc_addr cdesc_addr;
  111. /* Interrupt unmask register */
  112. u32 __iomem *unmask_reg;
  113. /* The completion queue head doorbell register */
  114. u32 __iomem *cq_head_db_reg;
  115. /* numa configuration register (for TPH) */
  116. u32 __iomem *numa_node_cfg_reg;
  117. /* The value to write to the above register to unmask
  118. * the interrupt of this queue
  119. */
  120. u32 msix_vector;
  121. enum queue_direction direction;
  122. /* holds the number of cdesc of the current packet */
  123. u16 cur_rx_pkt_cdesc_count;
  124. /* save the firt cdesc idx of the current packet */
  125. u16 cur_rx_pkt_cdesc_start_idx;
  126. u16 q_depth;
  127. /* Caller qid */
  128. u16 qid;
  129. /* Device queue index */
  130. u16 idx;
  131. u16 head;
  132. u16 last_head_update;
  133. u8 phase;
  134. u8 cdesc_entry_size_in_bytes;
  135. } ____cacheline_aligned;
  136. struct ena_com_io_bounce_buffer_control {
  137. u8 *base_buffer;
  138. u16 next_to_use;
  139. u16 buffer_size;
  140. u16 buffers_num; /* Must be a power of 2 */
  141. };
  142. /* This struct is to keep tracking the current location of the next llq entry */
  143. struct ena_com_llq_pkt_ctrl {
  144. u8 *curr_bounce_buf;
  145. u16 idx;
  146. u16 descs_left_in_line;
  147. };
  148. struct ena_com_io_sq {
  149. struct ena_com_io_desc_addr desc_addr;
  150. u32 __iomem *db_addr;
  151. u8 __iomem *header_addr;
  152. enum queue_direction direction;
  153. enum ena_admin_placement_policy_type mem_queue_type;
  154. u32 msix_vector;
  155. struct ena_com_tx_meta cached_tx_meta;
  156. struct ena_com_llq_info llq_info;
  157. struct ena_com_llq_pkt_ctrl llq_buf_ctrl;
  158. struct ena_com_io_bounce_buffer_control bounce_buf_ctrl;
  159. u16 q_depth;
  160. u16 qid;
  161. u16 idx;
  162. u16 tail;
  163. u16 next_to_comp;
  164. u16 llq_last_copy_tail;
  165. u32 tx_max_header_size;
  166. u8 phase;
  167. u8 desc_entry_size;
  168. u8 dma_addr_bits;
  169. u16 entries_in_tx_burst_left;
  170. } ____cacheline_aligned;
  171. struct ena_com_admin_cq {
  172. struct ena_admin_acq_entry *entries;
  173. dma_addr_t dma_addr;
  174. u16 head;
  175. u8 phase;
  176. };
  177. struct ena_com_admin_sq {
  178. struct ena_admin_aq_entry *entries;
  179. dma_addr_t dma_addr;
  180. u32 __iomem *db_addr;
  181. u16 head;
  182. u16 tail;
  183. u8 phase;
  184. };
  185. struct ena_com_stats_admin {
  186. u32 aborted_cmd;
  187. u32 submitted_cmd;
  188. u32 completed_cmd;
  189. u32 out_of_space;
  190. u32 no_completion;
  191. };
  192. struct ena_com_admin_queue {
  193. void *q_dmadev;
  194. spinlock_t q_lock; /* spinlock for the admin queue */
  195. struct ena_comp_ctx *comp_ctx;
  196. u32 completion_timeout;
  197. u16 q_depth;
  198. struct ena_com_admin_cq cq;
  199. struct ena_com_admin_sq sq;
  200. /* Indicate if the admin queue should poll for completion */
  201. bool polling;
  202. /* Define if fallback to polling mode should occur */
  203. bool auto_polling;
  204. u16 curr_cmd_id;
  205. /* Indicate that the ena was initialized and can
  206. * process new admin commands
  207. */
  208. bool running_state;
  209. /* Count the number of outstanding admin commands */
  210. atomic_t outstanding_cmds;
  211. struct ena_com_stats_admin stats;
  212. };
  213. struct ena_aenq_handlers;
  214. struct ena_com_aenq {
  215. u16 head;
  216. u8 phase;
  217. struct ena_admin_aenq_entry *entries;
  218. dma_addr_t dma_addr;
  219. u16 q_depth;
  220. struct ena_aenq_handlers *aenq_handlers;
  221. };
  222. struct ena_com_mmio_read {
  223. struct ena_admin_ena_mmio_req_read_less_resp *read_resp;
  224. dma_addr_t read_resp_dma_addr;
  225. u32 reg_read_to; /* in us */
  226. u16 seq_num;
  227. bool readless_supported;
  228. /* spin lock to ensure a single outstanding read */
  229. spinlock_t lock;
  230. };
  231. struct ena_rss {
  232. /* Indirect table */
  233. u16 *host_rss_ind_tbl;
  234. struct ena_admin_rss_ind_table_entry *rss_ind_tbl;
  235. dma_addr_t rss_ind_tbl_dma_addr;
  236. u16 tbl_log_size;
  237. /* Hash key */
  238. enum ena_admin_hash_functions hash_func;
  239. struct ena_admin_feature_rss_flow_hash_control *hash_key;
  240. dma_addr_t hash_key_dma_addr;
  241. u32 hash_init_val;
  242. /* Flow Control */
  243. struct ena_admin_feature_rss_hash_control *hash_ctrl;
  244. dma_addr_t hash_ctrl_dma_addr;
  245. };
  246. struct ena_host_attribute {
  247. /* Debug area */
  248. u8 *debug_area_virt_addr;
  249. dma_addr_t debug_area_dma_addr;
  250. u32 debug_area_size;
  251. /* Host information */
  252. struct ena_admin_host_info *host_info;
  253. dma_addr_t host_info_dma_addr;
  254. };
  255. /* Each ena_dev is a PCI function. */
  256. struct ena_com_dev {
  257. struct ena_com_admin_queue admin_queue;
  258. struct ena_com_aenq aenq;
  259. struct ena_com_io_cq io_cq_queues[ENA_TOTAL_NUM_QUEUES];
  260. struct ena_com_io_sq io_sq_queues[ENA_TOTAL_NUM_QUEUES];
  261. u8 __iomem *reg_bar;
  262. void __iomem *mem_bar;
  263. void *dmadev;
  264. enum ena_admin_placement_policy_type tx_mem_queue_type;
  265. u32 tx_max_header_size;
  266. u16 stats_func; /* Selected function for extended statistic dump */
  267. u16 stats_queue; /* Selected queue for extended statistic dump */
  268. struct ena_com_mmio_read mmio_read;
  269. struct ena_rss rss;
  270. u32 supported_features;
  271. u32 dma_addr_bits;
  272. struct ena_host_attribute host_attr;
  273. bool adaptive_coalescing;
  274. u16 intr_delay_resolution;
  275. /* interrupt moderation intervals are in usec divided by
  276. * intr_delay_resolution, which is supplied by the device.
  277. */
  278. u32 intr_moder_tx_interval;
  279. u32 intr_moder_rx_interval;
  280. struct ena_intr_moder_entry *intr_moder_tbl;
  281. struct ena_com_llq_info llq_info;
  282. };
  283. struct ena_com_dev_get_features_ctx {
  284. struct ena_admin_queue_feature_desc max_queues;
  285. struct ena_admin_queue_ext_feature_desc max_queue_ext;
  286. struct ena_admin_device_attr_feature_desc dev_attr;
  287. struct ena_admin_feature_aenq_desc aenq;
  288. struct ena_admin_feature_offload_desc offload;
  289. struct ena_admin_ena_hw_hints hw_hints;
  290. struct ena_admin_feature_llq_desc llq;
  291. };
  292. struct ena_com_create_io_ctx {
  293. enum ena_admin_placement_policy_type mem_queue_type;
  294. enum queue_direction direction;
  295. int numa_node;
  296. u32 msix_vector;
  297. u16 queue_size;
  298. u16 qid;
  299. };
  300. typedef void (*ena_aenq_handler)(void *data,
  301. struct ena_admin_aenq_entry *aenq_e);
  302. /* Holds aenq handlers. Indexed by AENQ event group */
  303. struct ena_aenq_handlers {
  304. ena_aenq_handler handlers[ENA_MAX_HANDLERS];
  305. ena_aenq_handler unimplemented_handler;
  306. };
  307. /*****************************************************************************/
  308. /*****************************************************************************/
  309. /* ena_com_mmio_reg_read_request_init - Init the mmio reg read mechanism
  310. * @ena_dev: ENA communication layer struct
  311. *
  312. * Initialize the register read mechanism.
  313. *
  314. * @note: This method must be the first stage in the initialization sequence.
  315. *
  316. * @return - 0 on success, negative value on failure.
  317. */
  318. int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev);
  319. /* ena_com_set_mmio_read_mode - Enable/disable the mmio reg read mechanism
  320. * @ena_dev: ENA communication layer struct
  321. * @readless_supported: readless mode (enable/disable)
  322. */
  323. void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev,
  324. bool readless_supported);
  325. /* ena_com_mmio_reg_read_request_write_dev_addr - Write the mmio reg read return
  326. * value physical address.
  327. * @ena_dev: ENA communication layer struct
  328. */
  329. void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev);
  330. /* ena_com_mmio_reg_read_request_destroy - Destroy the mmio reg read mechanism
  331. * @ena_dev: ENA communication layer struct
  332. */
  333. void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev);
  334. /* ena_com_admin_init - Init the admin and the async queues
  335. * @ena_dev: ENA communication layer struct
  336. * @aenq_handlers: Those handlers to be called upon event.
  337. *
  338. * Initialize the admin submission and completion queues.
  339. * Initialize the asynchronous events notification queues.
  340. *
  341. * @return - 0 on success, negative value on failure.
  342. */
  343. int ena_com_admin_init(struct ena_com_dev *ena_dev,
  344. struct ena_aenq_handlers *aenq_handlers);
  345. /* ena_com_admin_destroy - Destroy the admin and the async events queues.
  346. * @ena_dev: ENA communication layer struct
  347. *
  348. * @note: Before calling this method, the caller must validate that the device
  349. * won't send any additional admin completions/aenq.
  350. * To achieve that, a FLR is recommended.
  351. */
  352. void ena_com_admin_destroy(struct ena_com_dev *ena_dev);
  353. /* ena_com_dev_reset - Perform device FLR to the device.
  354. * @ena_dev: ENA communication layer struct
  355. * @reset_reason: Specify what is the trigger for the reset in case of an error.
  356. *
  357. * @return - 0 on success, negative value on failure.
  358. */
  359. int ena_com_dev_reset(struct ena_com_dev *ena_dev,
  360. enum ena_regs_reset_reason_types reset_reason);
  361. /* ena_com_create_io_queue - Create io queue.
  362. * @ena_dev: ENA communication layer struct
  363. * @ctx - create context structure
  364. *
  365. * Create the submission and the completion queues.
  366. *
  367. * @return - 0 on success, negative value on failure.
  368. */
  369. int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
  370. struct ena_com_create_io_ctx *ctx);
  371. /* ena_com_destroy_io_queue - Destroy IO queue with the queue id - qid.
  372. * @ena_dev: ENA communication layer struct
  373. * @qid - the caller virtual queue id.
  374. */
  375. void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid);
  376. /* ena_com_get_io_handlers - Return the io queue handlers
  377. * @ena_dev: ENA communication layer struct
  378. * @qid - the caller virtual queue id.
  379. * @io_sq - IO submission queue handler
  380. * @io_cq - IO completion queue handler.
  381. *
  382. * @return - 0 on success, negative value on failure.
  383. */
  384. int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid,
  385. struct ena_com_io_sq **io_sq,
  386. struct ena_com_io_cq **io_cq);
  387. /* ena_com_admin_aenq_enable - ENAble asynchronous event notifications
  388. * @ena_dev: ENA communication layer struct
  389. *
  390. * After this method, aenq event can be received via AENQ.
  391. */
  392. void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev);
  393. /* ena_com_set_admin_running_state - Set the state of the admin queue
  394. * @ena_dev: ENA communication layer struct
  395. *
  396. * Change the state of the admin queue (enable/disable)
  397. */
  398. void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state);
  399. /* ena_com_get_admin_running_state - Get the admin queue state
  400. * @ena_dev: ENA communication layer struct
  401. *
  402. * Retrieve the state of the admin queue (enable/disable)
  403. *
  404. * @return - current polling mode (enable/disable)
  405. */
  406. bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev);
  407. /* ena_com_set_admin_polling_mode - Set the admin completion queue polling mode
  408. * @ena_dev: ENA communication layer struct
  409. * @polling: ENAble/Disable polling mode
  410. *
  411. * Set the admin completion mode.
  412. */
  413. void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling);
  414. /* ena_com_set_admin_polling_mode - Get the admin completion queue polling mode
  415. * @ena_dev: ENA communication layer struct
  416. *
  417. * Get the admin completion mode.
  418. * If polling mode is on, ena_com_execute_admin_command will perform a
  419. * polling on the admin completion queue for the commands completion,
  420. * otherwise it will wait on wait event.
  421. *
  422. * @return state
  423. */
  424. bool ena_com_get_ena_admin_polling_mode(struct ena_com_dev *ena_dev);
  425. /* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode
  426. * @ena_dev: ENA communication layer struct
  427. * @polling: Enable/Disable polling mode
  428. *
  429. * Set the autopolling mode.
  430. * If autopolling is on:
  431. * In case of missing interrupt when data is available switch to polling.
  432. */
  433. void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev,
  434. bool polling);
  435. /* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler
  436. * @ena_dev: ENA communication layer struct
  437. *
  438. * This method go over the admin completion queue and wake up all the pending
  439. * threads that wait on the commands wait event.
  440. *
  441. * @note: Should be called after MSI-X interrupt.
  442. */
  443. void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev);
  444. /* ena_com_aenq_intr_handler - AENQ interrupt handler
  445. * @ena_dev: ENA communication layer struct
  446. *
  447. * This method go over the async event notification queue and call the proper
  448. * aenq handler.
  449. */
  450. void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data);
  451. /* ena_com_abort_admin_commands - Abort all the outstanding admin commands.
  452. * @ena_dev: ENA communication layer struct
  453. *
  454. * This method aborts all the outstanding admin commands.
  455. * The caller should then call ena_com_wait_for_abort_completion to make sure
  456. * all the commands were completed.
  457. */
  458. void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev);
  459. /* ena_com_wait_for_abort_completion - Wait for admin commands abort.
  460. * @ena_dev: ENA communication layer struct
  461. *
  462. * This method wait until all the outstanding admin commands will be completed.
  463. */
  464. void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev);
  465. /* ena_com_validate_version - Validate the device parameters
  466. * @ena_dev: ENA communication layer struct
  467. *
  468. * This method validate the device parameters are the same as the saved
  469. * parameters in ena_dev.
  470. * This method is useful after device reset, to validate the device mac address
  471. * and the device offloads are the same as before the reset.
  472. *
  473. * @return - 0 on success negative value otherwise.
  474. */
  475. int ena_com_validate_version(struct ena_com_dev *ena_dev);
  476. /* ena_com_get_link_params - Retrieve physical link parameters.
  477. * @ena_dev: ENA communication layer struct
  478. * @resp: Link parameters
  479. *
  480. * Retrieve the physical link parameters,
  481. * like speed, auto-negotiation and full duplex support.
  482. *
  483. * @return - 0 on Success negative value otherwise.
  484. */
  485. int ena_com_get_link_params(struct ena_com_dev *ena_dev,
  486. struct ena_admin_get_feat_resp *resp);
  487. /* ena_com_get_dma_width - Retrieve physical dma address width the device
  488. * supports.
  489. * @ena_dev: ENA communication layer struct
  490. *
  491. * Retrieve the maximum physical address bits the device can handle.
  492. *
  493. * @return: > 0 on Success and negative value otherwise.
  494. */
  495. int ena_com_get_dma_width(struct ena_com_dev *ena_dev);
  496. /* ena_com_set_aenq_config - Set aenq groups configurations
  497. * @ena_dev: ENA communication layer struct
  498. * @groups flag: bit fields flags of enum ena_admin_aenq_group.
  499. *
  500. * Configure which aenq event group the driver would like to receive.
  501. *
  502. * @return: 0 on Success and negative value otherwise.
  503. */
  504. int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag);
  505. /* ena_com_get_dev_attr_feat - Get device features
  506. * @ena_dev: ENA communication layer struct
  507. * @get_feat_ctx: returned context that contain the get features.
  508. *
  509. * @return: 0 on Success and negative value otherwise.
  510. */
  511. int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
  512. struct ena_com_dev_get_features_ctx *get_feat_ctx);
  513. /* ena_com_get_dev_basic_stats - Get device basic statistics
  514. * @ena_dev: ENA communication layer struct
  515. * @stats: stats return value
  516. *
  517. * @return: 0 on Success and negative value otherwise.
  518. */
  519. int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
  520. struct ena_admin_basic_stats *stats);
  521. /* ena_com_set_dev_mtu - Configure the device mtu.
  522. * @ena_dev: ENA communication layer struct
  523. * @mtu: mtu value
  524. *
  525. * @return: 0 on Success and negative value otherwise.
  526. */
  527. int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu);
  528. /* ena_com_get_offload_settings - Retrieve the device offloads capabilities
  529. * @ena_dev: ENA communication layer struct
  530. * @offlad: offload return value
  531. *
  532. * @return: 0 on Success and negative value otherwise.
  533. */
  534. int ena_com_get_offload_settings(struct ena_com_dev *ena_dev,
  535. struct ena_admin_feature_offload_desc *offload);
  536. /* ena_com_rss_init - Init RSS
  537. * @ena_dev: ENA communication layer struct
  538. * @log_size: indirection log size
  539. *
  540. * Allocate RSS/RFS resources.
  541. * The caller then can configure rss using ena_com_set_hash_function,
  542. * ena_com_set_hash_ctrl and ena_com_indirect_table_set.
  543. *
  544. * @return: 0 on Success and negative value otherwise.
  545. */
  546. int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size);
  547. /* ena_com_rss_destroy - Destroy rss
  548. * @ena_dev: ENA communication layer struct
  549. *
  550. * Free all the RSS/RFS resources.
  551. */
  552. void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
  553. /* ena_com_get_current_hash_function - Get RSS hash function
  554. * @ena_dev: ENA communication layer struct
  555. *
  556. * Return the current hash function.
  557. * @return: 0 or one of the ena_admin_hash_functions values.
  558. */
  559. int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev);
  560. /* ena_com_fill_hash_function - Fill RSS hash function
  561. * @ena_dev: ENA communication layer struct
  562. * @func: The hash function (Toeplitz or crc)
  563. * @key: Hash key (for toeplitz hash)
  564. * @key_len: key length (max length 10 DW)
  565. * @init_val: initial value for the hash function
  566. *
  567. * Fill the ena_dev resources with the desire hash function, hash key, key_len
  568. * and key initial value (if needed by the hash function).
  569. * To flush the key into the device the caller should call
  570. * ena_com_set_hash_function.
  571. *
  572. * @return: 0 on Success and negative value otherwise.
  573. */
  574. int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
  575. enum ena_admin_hash_functions func,
  576. const u8 *key, u16 key_len, u32 init_val);
  577. /* ena_com_set_hash_function - Flush the hash function and it dependencies to
  578. * the device.
  579. * @ena_dev: ENA communication layer struct
  580. *
  581. * Flush the hash function and it dependencies (key, key length and
  582. * initial value) if needed.
  583. *
  584. * @note: Prior to this method the caller should call ena_com_fill_hash_function
  585. *
  586. * @return: 0 on Success and negative value otherwise.
  587. */
  588. int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
  589. /* ena_com_get_hash_function - Retrieve the hash function and the hash key
  590. * from the device.
  591. * @ena_dev: ENA communication layer struct
  592. * @func: hash function
  593. * @key: hash key
  594. *
  595. * Retrieve the hash function and the hash key from the device.
  596. *
  597. * @note: If the caller called ena_com_fill_hash_function but didn't flash
  598. * it to the device, the new configuration will be lost.
  599. *
  600. * @return: 0 on Success and negative value otherwise.
  601. */
  602. int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
  603. enum ena_admin_hash_functions *func,
  604. u8 *key);
  605. /* ena_com_fill_hash_ctrl - Fill RSS hash control
  606. * @ena_dev: ENA communication layer struct.
  607. * @proto: The protocol to configure.
  608. * @hash_fields: bit mask of ena_admin_flow_hash_fields
  609. *
  610. * Fill the ena_dev resources with the desire hash control (the ethernet
  611. * fields that take part of the hash) for a specific protocol.
  612. * To flush the hash control to the device, the caller should call
  613. * ena_com_set_hash_ctrl.
  614. *
  615. * @return: 0 on Success and negative value otherwise.
  616. */
  617. int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev,
  618. enum ena_admin_flow_hash_proto proto,
  619. u16 hash_fields);
  620. /* ena_com_set_hash_ctrl - Flush the hash control resources to the device.
  621. * @ena_dev: ENA communication layer struct
  622. *
  623. * Flush the hash control (the ethernet fields that take part of the hash)
  624. *
  625. * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl.
  626. *
  627. * @return: 0 on Success and negative value otherwise.
  628. */
  629. int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev);
  630. /* ena_com_get_hash_ctrl - Retrieve the hash control from the device.
  631. * @ena_dev: ENA communication layer struct
  632. * @proto: The protocol to retrieve.
  633. * @fields: bit mask of ena_admin_flow_hash_fields.
  634. *
  635. * Retrieve the hash control from the device.
  636. *
  637. * @note, If the caller called ena_com_fill_hash_ctrl but didn't flash
  638. * it to the device, the new configuration will be lost.
  639. *
  640. * @return: 0 on Success and negative value otherwise.
  641. */
  642. int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev,
  643. enum ena_admin_flow_hash_proto proto,
  644. u16 *fields);
  645. /* ena_com_set_default_hash_ctrl - Set the hash control to a default
  646. * configuration.
  647. * @ena_dev: ENA communication layer struct
  648. *
  649. * Fill the ena_dev resources with the default hash control configuration.
  650. * To flush the hash control to the device, the caller should call
  651. * ena_com_set_hash_ctrl.
  652. *
  653. * @return: 0 on Success and negative value otherwise.
  654. */
  655. int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev);
  656. /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS
  657. * indirection table
  658. * @ena_dev: ENA communication layer struct.
  659. * @entry_idx - indirection table entry.
  660. * @entry_value - redirection value
  661. *
  662. * Fill a single entry of the RSS indirection table in the ena_dev resources.
  663. * To flush the indirection table to the device, the called should call
  664. * ena_com_indirect_table_set.
  665. *
  666. * @return: 0 on Success and negative value otherwise.
  667. */
  668. int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev,
  669. u16 entry_idx, u16 entry_value);
  670. /* ena_com_indirect_table_set - Flush the indirection table to the device.
  671. * @ena_dev: ENA communication layer struct
  672. *
  673. * Flush the indirection hash control to the device.
  674. * Prior to this method the caller should call ena_com_indirect_table_fill_entry
  675. *
  676. * @return: 0 on Success and negative value otherwise.
  677. */
  678. int ena_com_indirect_table_set(struct ena_com_dev *ena_dev);
  679. /* ena_com_indirect_table_get - Retrieve the indirection table from the device.
  680. * @ena_dev: ENA communication layer struct
  681. * @ind_tbl: indirection table
  682. *
  683. * Retrieve the RSS indirection table from the device.
  684. *
  685. * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flash
  686. * it to the device, the new configuration will be lost.
  687. *
  688. * @return: 0 on Success and negative value otherwise.
  689. */
  690. int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl);
  691. /* ena_com_allocate_host_info - Allocate host info resources.
  692. * @ena_dev: ENA communication layer struct
  693. *
  694. * @return: 0 on Success and negative value otherwise.
  695. */
  696. int ena_com_allocate_host_info(struct ena_com_dev *ena_dev);
  697. /* ena_com_allocate_debug_area - Allocate debug area.
  698. * @ena_dev: ENA communication layer struct
  699. * @debug_area_size - debug area size.
  700. *
  701. * @return: 0 on Success and negative value otherwise.
  702. */
  703. int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
  704. u32 debug_area_size);
  705. /* ena_com_delete_debug_area - Free the debug area resources.
  706. * @ena_dev: ENA communication layer struct
  707. *
  708. * Free the allocate debug area.
  709. */
  710. void ena_com_delete_debug_area(struct ena_com_dev *ena_dev);
  711. /* ena_com_delete_host_info - Free the host info resources.
  712. * @ena_dev: ENA communication layer struct
  713. *
  714. * Free the allocate host info.
  715. */
  716. void ena_com_delete_host_info(struct ena_com_dev *ena_dev);
  717. /* ena_com_set_host_attributes - Update the device with the host
  718. * attributes (debug area and host info) base address.
  719. * @ena_dev: ENA communication layer struct
  720. *
  721. * @return: 0 on Success and negative value otherwise.
  722. */
  723. int ena_com_set_host_attributes(struct ena_com_dev *ena_dev);
  724. /* ena_com_create_io_cq - Create io completion queue.
  725. * @ena_dev: ENA communication layer struct
  726. * @io_cq - io completion queue handler
  727. * Create IO completion queue.
  728. *
  729. * @return - 0 on success, negative value on failure.
  730. */
  731. int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
  732. struct ena_com_io_cq *io_cq);
  733. /* ena_com_destroy_io_cq - Destroy io completion queue.
  734. * @ena_dev: ENA communication layer struct
  735. * @io_cq - io completion queue handler
  736. * Destroy IO completion queue.
  737. *
  738. * @return - 0 on success, negative value on failure.
  739. */
  740. int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
  741. struct ena_com_io_cq *io_cq);
  742. /* ena_com_execute_admin_command - Execute admin command
  743. * @admin_queue: admin queue.
  744. * @cmd: the admin command to execute.
  745. * @cmd_size: the command size.
  746. * @cmd_completion: command completion return value.
  747. * @cmd_comp_size: command completion size.
  748. * Submit an admin command and then wait until the device will return a
  749. * completion.
  750. * The completion will be copyed into cmd_comp.
  751. *
  752. * @return - 0 on success, negative value on failure.
  753. */
  754. int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue,
  755. struct ena_admin_aq_entry *cmd,
  756. size_t cmd_size,
  757. struct ena_admin_acq_entry *cmd_comp,
  758. size_t cmd_comp_size);
  759. /* ena_com_init_interrupt_moderation - Init interrupt moderation
  760. * @ena_dev: ENA communication layer struct
  761. *
  762. * @return - 0 on success, negative value on failure.
  763. */
  764. int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev);
  765. /* ena_com_interrupt_moderation_supported - Return if interrupt moderation
  766. * capability is supported by the device.
  767. *
  768. * @return - supported or not.
  769. */
  770. bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev);
  771. /* ena_com_update_nonadaptive_moderation_interval_tx - Update the
  772. * non-adaptive interval in Tx direction.
  773. * @ena_dev: ENA communication layer struct
  774. * @tx_coalesce_usecs: Interval in usec.
  775. *
  776. * @return - 0 on success, negative value on failure.
  777. */
  778. int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
  779. u32 tx_coalesce_usecs);
  780. /* ena_com_update_nonadaptive_moderation_interval_rx - Update the
  781. * non-adaptive interval in Rx direction.
  782. * @ena_dev: ENA communication layer struct
  783. * @rx_coalesce_usecs: Interval in usec.
  784. *
  785. * @return - 0 on success, negative value on failure.
  786. */
  787. int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
  788. u32 rx_coalesce_usecs);
  789. /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the
  790. * non-adaptive interval in Tx direction.
  791. * @ena_dev: ENA communication layer struct
  792. *
  793. * @return - interval in usec
  794. */
  795. unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev);
  796. /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the
  797. * non-adaptive interval in Rx direction.
  798. * @ena_dev: ENA communication layer struct
  799. *
  800. * @return - interval in usec
  801. */
  802. unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev);
  803. /* ena_com_config_dev_mode - Configure the placement policy of the device.
  804. * @ena_dev: ENA communication layer struct
  805. * @llq_features: LLQ feature descriptor, retrieve via
  806. * ena_com_get_dev_attr_feat.
  807. * @ena_llq_config: The default driver LLQ parameters configurations
  808. */
  809. int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
  810. struct ena_admin_feature_llq_desc *llq_features,
  811. struct ena_llq_configurations *llq_default_config);
  812. static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev)
  813. {
  814. return ena_dev->adaptive_coalescing;
  815. }
  816. static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev)
  817. {
  818. ena_dev->adaptive_coalescing = true;
  819. }
  820. static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev)
  821. {
  822. ena_dev->adaptive_coalescing = false;
  823. }
  824. /* ena_com_update_intr_reg - Prepare interrupt register
  825. * @intr_reg: interrupt register to update.
  826. * @rx_delay_interval: Rx interval in usecs
  827. * @tx_delay_interval: Tx interval in usecs
  828. * @unmask: unask enable/disable
  829. *
  830. * Prepare interrupt update register with the supplied parameters.
  831. */
  832. static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg,
  833. u32 rx_delay_interval,
  834. u32 tx_delay_interval,
  835. bool unmask)
  836. {
  837. intr_reg->intr_control = 0;
  838. intr_reg->intr_control |= rx_delay_interval &
  839. ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK;
  840. intr_reg->intr_control |=
  841. (tx_delay_interval << ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT)
  842. & ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK;
  843. if (unmask)
  844. intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK;
  845. }
  846. static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl)
  847. {
  848. u16 size, buffers_num;
  849. u8 *buf;
  850. size = bounce_buf_ctrl->buffer_size;
  851. buffers_num = bounce_buf_ctrl->buffers_num;
  852. buf = bounce_buf_ctrl->base_buffer +
  853. (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size;
  854. prefetchw(bounce_buf_ctrl->base_buffer +
  855. (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size);
  856. return buf;
  857. }
  858. #endif /* !(ENA_COM) */