1266423Sjfv/****************************************************************************** 2266423Sjfv 3349163Serj Copyright (c) 2013-2019, Intel Corporation 4266423Sjfv All rights reserved. 5349163Serj 6266423Sjfv Redistribution and use in source and binary forms, with or without 7266423Sjfv modification, are permitted provided that the following conditions are met: 8266423Sjfv 9266423Sjfv 1. Redistributions of source code must retain the above copyright notice, 10266423Sjfv this list of conditions and the following disclaimer. 11266423Sjfv 12266423Sjfv 2. Redistributions in binary form must reproduce the above copyright 13266423Sjfv notice, this list of conditions and the following disclaimer in the 14266423Sjfv documentation and/or other materials provided with the distribution. 15266423Sjfv 16266423Sjfv 3. Neither the name of the Intel Corporation nor the names of its 17266423Sjfv contributors may be used to endorse or promote products derived from 18266423Sjfv this software without specific prior written permission. 19266423Sjfv 20266423Sjfv THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21266423Sjfv AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22266423Sjfv IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23266423Sjfv ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24266423Sjfv LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25266423Sjfv CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26266423Sjfv SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27266423Sjfv INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28266423Sjfv CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29266423Sjfv ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30266423Sjfv POSSIBILITY OF SUCH DAMAGE. 31266423Sjfv 32266423Sjfv******************************************************************************/ 33266423Sjfv/*$FreeBSD: stable/11/sys/dev/ixl/i40e_adminq.h 349163 2019-06-18 00:08:02Z erj $*/ 34266423Sjfv 35266423Sjfv#ifndef _I40E_ADMINQ_H_ 36266423Sjfv#define _I40E_ADMINQ_H_ 37266423Sjfv 38266423Sjfv#include "i40e_osdep.h" 39277082Sjfv#include "i40e_status.h" 40266423Sjfv#include "i40e_adminq_cmd.h" 41266423Sjfv 42266423Sjfv#define I40E_ADMINQ_DESC(R, i) \ 43266423Sjfv (&(((struct i40e_aq_desc *)((R).desc_buf.va))[i])) 44266423Sjfv 45266423Sjfv#define I40E_ADMINQ_DESC_ALIGNMENT 4096 46266423Sjfv 47266423Sjfvstruct i40e_adminq_ring { 48266423Sjfv struct i40e_virt_mem dma_head; /* space for dma structures */ 49266423Sjfv struct i40e_dma_mem desc_buf; /* descriptor ring memory */ 50266423Sjfv struct i40e_virt_mem cmd_buf; /* command buffer memory */ 51266423Sjfv 52266423Sjfv union { 53266423Sjfv struct i40e_dma_mem *asq_bi; 54266423Sjfv struct i40e_dma_mem *arq_bi; 55266423Sjfv } r; 56266423Sjfv 57266423Sjfv u16 count; /* Number of descriptors */ 58266423Sjfv u16 rx_buf_len; /* Admin Receive Queue buffer length */ 59266423Sjfv 60266423Sjfv /* used for interrupt processing */ 61266423Sjfv u16 next_to_use; 62266423Sjfv u16 next_to_clean; 63266423Sjfv 64266423Sjfv /* used for queue tracking */ 65266423Sjfv u32 head; 66266423Sjfv u32 tail; 67266423Sjfv u32 len; 68269198Sjfv u32 bah; 69269198Sjfv u32 bal; 70266423Sjfv}; 71266423Sjfv 72266423Sjfv/* ASQ transaction details */ 73266423Sjfvstruct i40e_asq_cmd_details { 74266423Sjfv void *callback; /* cast from type I40E_ADMINQ_CALLBACK */ 75266423Sjfv u64 cookie; 76266423Sjfv u16 flags_ena; 77266423Sjfv u16 flags_dis; 78266423Sjfv bool async; 79266423Sjfv bool postpone; 80284049Sjfv struct i40e_aq_desc *wb_desc; 81266423Sjfv}; 82266423Sjfv 83266423Sjfv#define I40E_ADMINQ_DETAILS(R, i) \ 84266423Sjfv (&(((struct i40e_asq_cmd_details *)((R).cmd_buf.va))[i])) 85266423Sjfv 86266423Sjfv/* ARQ event information */ 87266423Sjfvstruct i40e_arq_event_info { 88266423Sjfv struct i40e_aq_desc desc; 89270346Sjfv u16 msg_len; 90270346Sjfv u16 buf_len; 91266423Sjfv u8 *msg_buf; 92266423Sjfv}; 93266423Sjfv 94266423Sjfv/* Admin Queue information */ 95266423Sjfvstruct i40e_adminq_info { 96266423Sjfv struct i40e_adminq_ring arq; /* receive queue */ 97266423Sjfv struct i40e_adminq_ring asq; /* send queue */ 98269198Sjfv u32 asq_cmd_timeout; /* send queue cmd write back timeout*/ 99266423Sjfv u16 num_arq_entries; /* receive queue depth */ 100266423Sjfv u16 num_asq_entries; /* send queue depth */ 101266423Sjfv u16 arq_buf_size; /* receive queue buffer size */ 102266423Sjfv u16 asq_buf_size; /* send queue buffer size */ 103266423Sjfv u16 fw_maj_ver; /* firmware major version */ 104266423Sjfv u16 fw_min_ver; /* firmware minor version */ 105277082Sjfv u32 fw_build; /* firmware build number */ 106266423Sjfv u16 api_maj_ver; /* api major version */ 107266423Sjfv u16 api_min_ver; /* api minor version */ 108266423Sjfv 109266423Sjfv struct i40e_spinlock asq_spinlock; /* Send queue spinlock */ 110266423Sjfv struct i40e_spinlock arq_spinlock; /* Receive queue spinlock */ 111266423Sjfv 112266423Sjfv /* last status values on send and receive queues */ 113266423Sjfv enum i40e_admin_queue_err asq_last_status; 114266423Sjfv enum i40e_admin_queue_err arq_last_status; 115266423Sjfv}; 116266423Sjfv 117299547Serj/** 118299547Serj * i40e_aq_rc_to_posix - convert errors to user-land codes 119299547Serj * aq_ret: AdminQ handler error code can override aq_rc 120299547Serj * aq_rc: AdminQ firmware error code to convert 121299547Serj **/ 122299547Serjstatic INLINE int i40e_aq_rc_to_posix(int aq_ret, int aq_rc) 123299547Serj{ 124299547Serj int aq_to_posix[] = { 125299547Serj 0, /* I40E_AQ_RC_OK */ 126299547Serj -EPERM, /* I40E_AQ_RC_EPERM */ 127299547Serj -ENOENT, /* I40E_AQ_RC_ENOENT */ 128299547Serj -ESRCH, /* I40E_AQ_RC_ESRCH */ 129299547Serj -EINTR, /* I40E_AQ_RC_EINTR */ 130299547Serj -EIO, /* I40E_AQ_RC_EIO */ 131299547Serj -ENXIO, /* I40E_AQ_RC_ENXIO */ 132299547Serj -E2BIG, /* I40E_AQ_RC_E2BIG */ 133299547Serj -EAGAIN, /* I40E_AQ_RC_EAGAIN */ 134299547Serj -ENOMEM, /* I40E_AQ_RC_ENOMEM */ 135299547Serj -EACCES, /* I40E_AQ_RC_EACCES */ 136299547Serj -EFAULT, /* I40E_AQ_RC_EFAULT */ 137299547Serj -EBUSY, /* I40E_AQ_RC_EBUSY */ 138299547Serj -EEXIST, /* I40E_AQ_RC_EEXIST */ 139299547Serj -EINVAL, /* I40E_AQ_RC_EINVAL */ 140299547Serj -ENOTTY, /* I40E_AQ_RC_ENOTTY */ 141299547Serj -ENOSPC, /* I40E_AQ_RC_ENOSPC */ 142299547Serj -ENOSYS, /* I40E_AQ_RC_ENOSYS */ 143299547Serj -ERANGE, /* I40E_AQ_RC_ERANGE */ 144299547Serj -EPIPE, /* I40E_AQ_RC_EFLUSHED */ 145299547Serj -ESPIPE, /* I40E_AQ_RC_BAD_ADDR */ 146299547Serj -EROFS, /* I40E_AQ_RC_EMODE */ 147299547Serj -EFBIG, /* I40E_AQ_RC_EFBIG */ 148299547Serj }; 149299547Serj 150299547Serj /* aq_rc is invalid if AQ timed out */ 151299547Serj if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT) 152299547Serj return -EAGAIN; 153299547Serj 154299547Serj if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0])))) 155299547Serj return -ERANGE; 156299547Serj 157299547Serj return aq_to_posix[aq_rc]; 158299547Serj} 159299547Serj 160266423Sjfv/* general information */ 161299555Serj#define I40E_AQ_LARGE_BUF 512 162333343Serj#define I40E_ASQ_CMD_TIMEOUT 250000 /* usecs */ 163266423Sjfv 164266423Sjfvvoid i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc, 165266423Sjfv u16 opcode); 166266423Sjfv 167266423Sjfv#endif /* _I40E_ADMINQ_H_ */ 168