Jeff Kirsher | ae06c70 | 2018-03-22 10:08:48 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jeff Kirsher | 51dce24 | 2018-04-26 08:08:09 -0700 | [diff] [blame^] | 2 | /* Copyright(c) 2013 - 2018 Intel Corporation. */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 3 | |
| 4 | #ifndef _I40E_ADMINQ_H_ |
| 5 | #define _I40E_ADMINQ_H_ |
| 6 | |
| 7 | #include "i40e_osdep.h" |
Shannon Nelson | bf848f3 | 2014-11-13 08:23:22 +0000 | [diff] [blame] | 8 | #include "i40e_status.h" |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 9 | #include "i40e_adminq_cmd.h" |
| 10 | |
| 11 | #define I40E_ADMINQ_DESC(R, i) \ |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 12 | (&(((struct i40e_aq_desc *)((R).desc_buf.va))[i])) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 13 | |
| 14 | #define I40E_ADMINQ_DESC_ALIGNMENT 4096 |
| 15 | |
| 16 | struct i40e_adminq_ring { |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 17 | struct i40e_virt_mem dma_head; /* space for dma structures */ |
| 18 | struct i40e_dma_mem desc_buf; /* descriptor ring memory */ |
| 19 | struct i40e_virt_mem cmd_buf; /* command buffer memory */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 20 | |
| 21 | union { |
| 22 | struct i40e_dma_mem *asq_bi; |
| 23 | struct i40e_dma_mem *arq_bi; |
| 24 | } r; |
| 25 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 26 | u16 count; /* Number of descriptors */ |
| 27 | u16 rx_buf_len; /* Admin Receive Queue buffer length */ |
| 28 | |
| 29 | /* used for interrupt processing */ |
| 30 | u16 next_to_use; |
| 31 | u16 next_to_clean; |
| 32 | |
| 33 | /* used for queue tracking */ |
| 34 | u32 head; |
| 35 | u32 tail; |
Shannon Nelson | 17e6a84 | 2013-11-16 10:00:36 +0000 | [diff] [blame] | 36 | u32 len; |
Shannon Nelson | 87dc346 | 2014-06-04 20:41:17 +0000 | [diff] [blame] | 37 | u32 bah; |
| 38 | u32 bal; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | /* ASQ transaction details */ |
| 42 | struct i40e_asq_cmd_details { |
| 43 | void *callback; /* cast from type I40E_ADMINQ_CALLBACK */ |
| 44 | u64 cookie; |
| 45 | u16 flags_ena; |
| 46 | u16 flags_dis; |
| 47 | bool async; |
| 48 | bool postpone; |
Shannon Nelson | 87db27a | 2015-08-27 11:42:42 -0400 | [diff] [blame] | 49 | struct i40e_aq_desc *wb_desc; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | #define I40E_ADMINQ_DETAILS(R, i) \ |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 53 | (&(((struct i40e_asq_cmd_details *)((R).cmd_buf.va))[i])) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 54 | |
| 55 | /* ARQ event information */ |
| 56 | struct i40e_arq_event_info { |
| 57 | struct i40e_aq_desc desc; |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 58 | u16 msg_len; |
| 59 | u16 buf_len; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 60 | u8 *msg_buf; |
| 61 | }; |
| 62 | |
| 63 | /* Admin Queue information */ |
| 64 | struct i40e_adminq_info { |
| 65 | struct i40e_adminq_ring arq; /* receive queue */ |
| 66 | struct i40e_adminq_ring asq; /* send queue */ |
Kamil Krawczyk | 09c4e56 | 2014-06-04 20:41:43 +0000 | [diff] [blame] | 67 | u32 asq_cmd_timeout; /* send queue cmd write back timeout*/ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 68 | u16 num_arq_entries; /* receive queue depth */ |
| 69 | u16 num_asq_entries; /* send queue depth */ |
| 70 | u16 arq_buf_size; /* receive queue buffer size */ |
| 71 | u16 asq_buf_size; /* send queue buffer size */ |
| 72 | u16 fw_maj_ver; /* firmware major version */ |
| 73 | u16 fw_min_ver; /* firmware minor version */ |
Shannon Nelson | 7edf810 | 2015-02-24 06:58:41 +0000 | [diff] [blame] | 74 | u32 fw_build; /* firmware build number */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 75 | u16 api_maj_ver; /* api major version */ |
| 76 | u16 api_min_ver; /* api minor version */ |
| 77 | |
| 78 | struct mutex asq_mutex; /* Send queue lock */ |
| 79 | struct mutex arq_mutex; /* Receive queue lock */ |
| 80 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 81 | /* last status values on send and receive queues */ |
| 82 | enum i40e_admin_queue_err asq_last_status; |
| 83 | enum i40e_admin_queue_err arq_last_status; |
| 84 | }; |
| 85 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 86 | /** |
| 87 | * i40e_aq_rc_to_posix - convert errors to user-land codes |
Shannon Nelson | 1fa89a4 | 2015-07-23 16:54:30 -0400 | [diff] [blame] | 88 | * aq_ret: AdminQ handler error code can override aq_rc |
| 89 | * aq_rc: AdminQ firmware error code to convert |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 90 | **/ |
Shannon Nelson | 1fa89a4 | 2015-07-23 16:54:30 -0400 | [diff] [blame] | 91 | static inline int i40e_aq_rc_to_posix(int aq_ret, int aq_rc) |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 92 | { |
| 93 | int aq_to_posix[] = { |
| 94 | 0, /* I40E_AQ_RC_OK */ |
| 95 | -EPERM, /* I40E_AQ_RC_EPERM */ |
| 96 | -ENOENT, /* I40E_AQ_RC_ENOENT */ |
| 97 | -ESRCH, /* I40E_AQ_RC_ESRCH */ |
| 98 | -EINTR, /* I40E_AQ_RC_EINTR */ |
| 99 | -EIO, /* I40E_AQ_RC_EIO */ |
| 100 | -ENXIO, /* I40E_AQ_RC_ENXIO */ |
| 101 | -E2BIG, /* I40E_AQ_RC_E2BIG */ |
| 102 | -EAGAIN, /* I40E_AQ_RC_EAGAIN */ |
| 103 | -ENOMEM, /* I40E_AQ_RC_ENOMEM */ |
| 104 | -EACCES, /* I40E_AQ_RC_EACCES */ |
| 105 | -EFAULT, /* I40E_AQ_RC_EFAULT */ |
| 106 | -EBUSY, /* I40E_AQ_RC_EBUSY */ |
| 107 | -EEXIST, /* I40E_AQ_RC_EEXIST */ |
| 108 | -EINVAL, /* I40E_AQ_RC_EINVAL */ |
| 109 | -ENOTTY, /* I40E_AQ_RC_ENOTTY */ |
| 110 | -ENOSPC, /* I40E_AQ_RC_ENOSPC */ |
| 111 | -ENOSYS, /* I40E_AQ_RC_ENOSYS */ |
| 112 | -ERANGE, /* I40E_AQ_RC_ERANGE */ |
| 113 | -EPIPE, /* I40E_AQ_RC_EFLUSHED */ |
| 114 | -ESPIPE, /* I40E_AQ_RC_BAD_ADDR */ |
| 115 | -EROFS, /* I40E_AQ_RC_EMODE */ |
| 116 | -EFBIG, /* I40E_AQ_RC_EFBIG */ |
| 117 | }; |
| 118 | |
Shannon Nelson | bf848f3 | 2014-11-13 08:23:22 +0000 | [diff] [blame] | 119 | /* aq_rc is invalid if AQ timed out */ |
| 120 | if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT) |
| 121 | return -EAGAIN; |
| 122 | |
Shannon Nelson | df08fd4 | 2015-08-26 15:14:11 -0400 | [diff] [blame] | 123 | if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0])))) |
Shannon Nelson | 43477d2 | 2014-11-13 08:23:16 +0000 | [diff] [blame] | 124 | return -ERANGE; |
Shannon Nelson | 1fa89a4 | 2015-07-23 16:54:30 -0400 | [diff] [blame] | 125 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 126 | return aq_to_posix[aq_rc]; |
| 127 | } |
| 128 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 129 | /* general information */ |
| 130 | #define I40E_AQ_LARGE_BUF 512 |
Jacob Keller | 9e3f23f | 2017-04-13 04:45:49 -0400 | [diff] [blame] | 131 | #define I40E_ASQ_CMD_TIMEOUT 250000 /* usecs */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 132 | |
| 133 | void i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc, |
| 134 | u16 opcode); |
| 135 | |
| 136 | #endif /* _I40E_ADMINQ_H_ */ |