Add iecm and idpf
Subsystems (4)
cover Add iecm and idpf
This series introduces both the Intel Ethernet Common Module and the Intel Data Plane Function. This also adds extended features and functionality to virtchnl with virtchnl_2.h.
The format of the series generally follows the flow of driver init to interface open. We go from probe into a hard reset followed by an init task. From there the rest of the netdev_ops and data path are added. Then lastly advanced features and idpf are introduced.
Currently this common layer (iecm) is initially only being used by only the idpf driver (PF driver for SmartNIC). However, the plan is to eventually switch our iavf driver along with future drivers to use this common module. The hope is to better enable code sharing going forward as well as support other developers writing drivers for our hardware
Alan Brady (17):
virtchnl: Add new virtchnl2 ops
iecm: add basic module init and documentation
iecm: add probe and remove
iecm: add api_init and controlq init
iecm: add vport alloc and virtchnl messages
iecm: add virtchnl messages for queues
iecm: finish virtchnl messages
iecm: add interrupts and configure netdev
iecm: alloc vport TX resources
iecm: alloc vport RX resources
iecm: add start_xmit and set_rx_mode
iecm: finish netdev_ops
iecm: implement splitq napi_poll
iecm: implement singleq napi_poll
iecm: implement ethtool callbacks
iecm: implement cloud filters
idpf: introduce idpf driver
Haiyue Wang (2):
iecm: implement flow director
iecm: add advanced rss
.../device_drivers/ethernet/intel/idpf.rst | 47 + .../device_drivers/ethernet/intel/iecm.rst | 93 + MAINTAINERS | 1 + drivers/net/ethernet/intel/Kconfig | 31 + drivers/net/ethernet/intel/Makefile | 2 + drivers/net/ethernet/intel/idpf/Makefile | 15 + drivers/net/ethernet/intel/idpf/idpf_dev.h | 17 + drivers/net/ethernet/intel/idpf/idpf_devids.h | 10 + drivers/net/ethernet/intel/idpf/idpf_main.c | 140 + drivers/net/ethernet/intel/idpf/idpf_reg.c | 130 + drivers/net/ethernet/intel/iecm/Makefile | 21 + .../net/ethernet/intel/iecm/iecm_controlq.c | 649 ++ .../ethernet/intel/iecm/iecm_controlq_setup.c | 175 + .../net/ethernet/intel/iecm/iecm_ethtool.c | 1332 ++++ drivers/net/ethernet/intel/iecm/iecm_lib.c | 5717 +++++++++++++++++ drivers/net/ethernet/intel/iecm/iecm_main.c | 40 + .../ethernet/intel/iecm/iecm_singleq_txrx.c | 1229 ++++ drivers/net/ethernet/intel/iecm/iecm_txrx.c | 4577 +++++++++++++ .../net/ethernet/intel/iecm/iecm_virtchnl.c | 4240 ++++++++++++ drivers/net/ethernet/intel/include/iecm.h | 973 +++ .../ethernet/intel/include/iecm_controlq.h | 117 + .../intel/include/iecm_controlq_api.h | 185 + .../ethernet/intel/include/iecm_lan_pf_regs.h | 131 + .../ethernet/intel/include/iecm_lan_txrx.h | 394 ++ drivers/net/ethernet/intel/include/iecm_mem.h | 20 + .../net/ethernet/intel/include/iecm_txrx.h | 733 +++ include/linux/avf/virtchnl.h | 1507 ++++- include/linux/avf/virtchnl_2.h | 1243 ++++ include/linux/avf/virtchnl_lan_desc.h | 603 ++ 29 files changed, 24255 insertions(+), 117 deletions(-) create mode 100644 Documentation/networking/device_drivers/ethernet/intel/idpf.rst create mode 100644 Documentation/networking/device_drivers/ethernet/intel/iecm.rst create mode 100644 drivers/net/ethernet/intel/idpf/Makefile create mode 100644 drivers/net/ethernet/intel/idpf/idpf_dev.h create mode 100644 drivers/net/ethernet/intel/idpf/idpf_devids.h create mode 100644 drivers/net/ethernet/intel/idpf/idpf_main.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_reg.c create mode 100644 drivers/net/ethernet/intel/iecm/Makefile create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_ethtool.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_lib.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_main.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_singleq_txrx.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_txrx.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c create mode 100644 drivers/net/ethernet/intel/include/iecm.h create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq_api.h create mode 100644 drivers/net/ethernet/intel/include/iecm_lan_pf_regs.h create mode 100644 drivers/net/ethernet/intel/include/iecm_lan_txrx.h create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h create mode 100644 drivers/net/ethernet/intel/include/iecm_txrx.h create mode 100644 include/linux/avf/virtchnl_2.h create mode 100644 include/linux/avf/virtchnl_lan_desc.h
Signature · 1 line
2.33.0
PATCH 1/19 virtchnl: Add new virtchnl2 ops
This extends the virtchnl interface to add new virtchnl ops and defines needed to implement virtchnl 2.0.
--- MAINTAINERS | 1 + include/linux/avf/virtchnl.h | 1507 +++++++++++++++++++++++-- include/linux/avf/virtchnl_2.h | 1243 ++++++++++++++++++++ include/linux/avf/virtchnl_lan_desc.h | 603 ++++++++++ 4 files changed, 3237 insertions(+), 117 deletions(-) create mode 100644 include/linux/avf/virtchnl_2.h create mode 100644 include/linux/avf/virtchnl_lan_desc.h
MAINTAINERS +1 -0
@@ -9602,6 +9602,7 @@ F: Documentation/networking/device_drivers/ethernet/intel/ F: drivers/net/ethernet/intel/ F: drivers/net/ethernet/intel/*/ F: include/linux/avf/virtchnl.h +F: include/linux/avf/virtchnl_2.h F: include/linux/net/intel/iidc.h INTEL ETHERNET PROTOCOL DRIVER FOR RDMA
include/linux/avf/virtchnl.h +1390 -117
1,905 lines not on this page · raw message
include/linux/avf/virtchnl_2.h new file +1243 -0
1,088 lines not on this page · raw message
include/linux/avf/virtchnl_lan_desc.h new file +603 -0
603 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.33.0
Part of the diff is not shown here. View the raw message.
Brady
PATCH 1/19 virtchnl: Add new virtchnl2 ops
Quoted 115 lines
-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 3:48 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired-
lan at lists.osuosl.org; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 01/19] virtchnl: Add new virtchnl2 opsFrom: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:51 -0800MAINTAINERS F:
Quoted 22 lines
This extends the virtchnl interface to add new virtchnl ops and defines needed to implement virtchnl 2.0.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- MAINTAINERS | 1 + include/linux/avf/virtchnl.h | 1507 +++++++++++++++++++++++-- include/linux/avf/virtchnl_2.h | 1243 ++++++++++++++++++++ include/linux/avf/virtchnl_lan_desc.h | 603 ++++++++++ 4 files changed, 3237 insertions(+), 117 deletions(-) create mode100644
include/linux/avf/virtchnl_2.hcreate mode 100644include/linux/avf/virtchnl_lan_desc.hMAINTAINERS index renamed from MAINTAINERS +0
-0
0d7883977e9b..5685d64afd76100644MAINTAINERS +0
-0@@ -9602,6 +9602,7 @@ F:
Documentation/networking/device_drivers/ethernet/intel/Quoted 42 lines
MAINTAINERS +1
-0F: drivers/net/ethernet/intel/ F: drivers/net/ethernet/intel/*/ F: include/linux/avf/virtchnl.h +F: include/linux/avf/virtchnl_2.h F: include/linux/net/intel/iidc.h INTEL ETHERNET PROTOCOL DRIVER FOR RDMA diff --git
a/include/linux/avf/virtchnl.hb/include/linux/avf/virtchnl.hindex2ce27e8e4f19..aee5e2677e1c100644include/linux/avf/virtchnl.h +5
-2@@ -14,8 +14,9 @@#define _VIRTCHNL_H_/* Description: -* This header file describes the VF-PF communication protocol used -* by the drivers for all devices starting from our 40G product line +* This header file describes the Virtual Function (VF) - Physical +Function +* (PF) communication protocol used by the drivers for all devices +starting +* from our 40G product line * * Admin queue buffer usage: * desc->opcode is always aqc_opc_send_msg_to_pf @@ -29,8 +30,8 @@ * have a maximum of sixteen queues for all of its VSIs. * * The PF is required to return a status code in v_retval for all messages
- * exceptRESET_VF, which does not require any response. The return value
- * is ofstatus_codetype, defined in the sharedtype.h.
+ * exceptRESET_VF, which does not require any response. The returned
+ value
+ * is ofvirtchnl_status_codetype, defined here.
*
* In general, VF driver initialization should roughly follow the order of
* these opcodes. The VF driver must first validate the API version
of the @@ -45,7 +46,21 @@
* value in current and future projects
*/include/linux/avf/virtchnl.h
Quoted 10 lines
include/linux/avf/virtchnl.h +9
-1-/* Error Codes */ +/* These macros are used to generate compilation errors if a +structure/union +* is not exactly the correct length. It gives a divide by zero error +if the +* structure/union is not of the correct size, otherwise it creates +an enum +* that is never used. +*/ +#define VIRTCHNL_CHECK_STRUCT_LEN (n,X ) enumvirtchnl_static_assert_enum_##X \
include/linux/avf/virtchnl.h
Quoted 2 lines
include/linux/avf/virtchnl.h +2
-0+ { virtchnl_static_assert_##X = (n) / ((sizeof(struct X) == (n)) ? 1 +: 0) } #define VIRTCHNL_CHECK_UNION_LEN(n, X) enumvirtchnl_static_asset_enum_##X \
Quoted 22 lines
include/linux/avf/virtchnl.h +13
-0+ { virtchnl_static_assert_##X = (n) / ((sizeof(union X) == (n)) ? 1 : +0) } + +/* Error Codes +* Note that many older versions of various iAVF drivers convert the +reported +* status code directly into an iavf_status enumeration. For this +reason, it +* is important that the values of these enumerations line up. +*/ enum virtchnl_status_code {VIRTCHNL_STATUS_SUCCESS =0 ,VIRTCHNL_STATUS_ERR_PARAM =-5 ,@@ -92,6 +107,9 @@ enum virtchnl_rx_hsplit { VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8, }; +enum virtchnl_bw_limit_type { +VIRTCHNL_BW_SHAPER =0 , +};/* END GENERIC DEFINES */
Quoted 11 lines
include/linux/avf/virtchnl.h enum virtchnl_ops { · line 157
Quoted 7 lines
include/linux/avf/virtchnl.h +0
-0/* Opcodes for VF-PF communication. These are placed in the v_opcode field @@ -136,11 +154,14 @@ enum
virtchnl_ops{include/linux/avf/virtchnl.h +1
-1VIRTCHNL_OP_DISABLE_CHANNELS =31 ,VIRTCHNL_OP_ADD_CLOUD_FILTER =32 , VIRTCHNL_OP_DEL_CLOUD_FILTER = 33, -/* opcode 34 - 44 are reserved */ +/* opcode 34 is reserved */ Here's a gap between 34 and 38. If you decided to comment gaps, it should be mentioned as well.
Will fix
Quoted 230 lines
Quoted 53 lines
include/linux/avf/virtchnl.h +42
-0+/* opcodes 38, 39, 40, 41, 42 and 43 are reserved */ +VIRTCHNL_OP_GET_SUPPORTED_RXDIDS =44 ,VIRTCHNL_OP_ADD_RSS_CFG =45 ,VIRTCHNL_OP_DEL_RSS_CFG =46 ,VIRTCHNL_OP_ADD_FDIR_FILTER =47 ,VIRTCHNL_OP_DEL_FDIR_FILTER =48 , +VIRTCHNL_OP_GET_MAX_RSS_QREGION =50 ,VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS =51 ,VIRTCHNL_OP_ADD_VLAN_V2 =52 , VIRTCHNL_OP_DEL_VLAN_V2 = 53,@@ -148,31 +169,206 @@ enum virtchnl_ops {VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 =55 ,VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 =56 ,VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 =57 , +VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 =58 , +VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 =59 , +VIRTCHNL_OP_1588_PTP_GET_CAPS =60 , +VIRTCHNL_OP_1588_PTP_GET_TIME =61 , +VIRTCHNL_OP_1588_PTP_SET_TIME =62 , +VIRTCHNL_OP_1588_PTP_ADJ_TIME =63 , +VIRTCHNL_OP_1588_PTP_ADJ_FREQ =64 , +VIRTCHNL_OP_1588_PTP_TX_TIMESTAMP =65 , +VIRTCHNL_OP_GET_QOS_CAPS =66 , +VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP =67 , +VIRTCHNL_OP_1588_PTP_GET_PIN_CFGS =68 , +VIRTCHNL_OP_1588_PTP_SET_PIN_CFG =69 , +VIRTCHNL_OP_1588_PTP_EXT_TIMESTAMP =70 , +VIRTCHNL_OP_ENABLE_QUEUES_V2 =107 , +VIRTCHNL_OP_DISABLE_QUEUES_V2 =108 , +VIRTCHNL_OP_MAP_QUEUE_VECTOR =111 , +/* New major set of opcodes introduced and so leaving room for +* old misc opcodes to be added in future. Also these opcodes may only +* be used if both the PF and VF have successfully negotiated the +* VIRTCHNL version as 2.0 during VIRTCHNL_OP_VERSION exchange. +*/ +VIRTCHNL2_OP_GET_CAPS =500 , +VIRTCHNL2_OP_CREATE_VPORT =501 , +VIRTCHNL2_OP_DESTROY_VPORT =502 , +VIRTCHNL2_OP_ENABLE_VPORT =503 , +VIRTCHNL2_OP_DISABLE_VPORT =504 , +VIRTCHNL2_OP_CONFIG_TX_QUEUES =505 , +VIRTCHNL2_OP_CONFIG_RX_QUEUES =506 , +VIRTCHNL2_OP_ENABLE_QUEUES =507 , +VIRTCHNL2_OP_DISABLE_QUEUES =508 , +VIRTCHNL2_OP_ADD_QUEUES =509 , +VIRTCHNL2_OP_DEL_QUEUES =510 , +VIRTCHNL2_OP_MAP_QUEUE_VECTOR =511 , +VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR =512 , +VIRTCHNL2_OP_GET_RSS_KEY =513 , +VIRTCHNL2_OP_SET_RSS_KEY =514 , +VIRTCHNL2_OP_GET_RSS_LUT =515 , +VIRTCHNL2_OP_SET_RSS_LUT =516 , + VIRTCHNL2_OP_GET_RSS_HASH = 517,include/linux/avf/virtchnl.h enum virtchnl_ops { · line 220
Quoted 10 lines
include/linux/avf/virtchnl.h +10
-0+VIRTCHNL2_OP_SET_RSS_HASH =518 , +VIRTCHNL2_OP_SET_SRIOV_VFS =519 , +VIRTCHNL2_OP_ALLOC_VECTORS =520 , +VIRTCHNL2_OP_DEALLOC_VECTORS =521 , +VIRTCHNL2_OP_EVENT =522 , +VIRTCHNL2_OP_GET_STATS =523 , +VIRTCHNL2_OP_RESET_VF =524 , +/* opcode 525 is reserved */ +VIRTCHNL2_OP_GET_PTYPE_INFO =526 , +/* opcode 527 and 528 are reserved for VIRTCHNL2_OP_GET_PTYPE_ID and
Quoted 7 lines
include/linux/avf/virtchnl.h +3
-1+* VIRTCHNL2_OP_GET_PTYPE_INFO_RAW +*/ +/* opcodes 529, 530, and 531 are reserved */ VIRTCHNL_OP_MAX, }; -/* These macros are used to generate compilation errors if a Quoted 8 lines
structure/union
- * is not exactly the correct length. It gives a divide by zero error if the
- * structure/union is not of the correct size, otherwise it creates an enum
- * that is never used.
- */
-#defineVIRTCHNL_CHECK_STRUCT_LEN(n, X)enumvirtchnl_static_assert_enum_##X \
include/linux/avf/virtchnl.h
Quoted 2 lines
include/linux/avf/virtchnl.h +0
-2- { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) } -#define VIRTCHNL_CHECK_UNION_LEN (n,X ) enumvirtchnl_static_asset_enum_##X \
Quoted 123 lines
include/linux/avf/virtchnl.h +111
-12- { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) } - -/* Virtual channel message descriptor. This overlays the admin queue -* descriptor. All other data is passed in external buffers. -*/ - -struct virtchnl_msg { -u8 pad[8 ];/* AQ flags/opcode/len/retval fields */ -enum virtchnl_ops v_opcode;/* avoid confusion with desc->opcode */ -enum virtchnl_status_code v_retval;/* ditto for desc->retval */ -u32 vfid;/* used by PF when sending to VF */ -}; +static inline const char *virtchnl_op_str (enum virtchnl_ops v_opcode) +{ +switch (v_opcode) { +case VIRTCHNL_OP_UNKNOWN : +return "VIRTCHNL_OP_UNKNOWN" ; +case VIRTCHNL_OP_VERSION : +return "VIRTCHNL_OP_VERSION" ; +case VIRTCHNL_OP_RESET_VF : +return "VIRTCHNL_OP_RESET_VF" ; +case VIRTCHNL_OP_GET_VF_RESOURCES : +return "VIRTCHNL_OP_GET_VF_RESOURCES" ; +case VIRTCHNL_OP_CONFIG_TX_QUEUE : +return "VIRTCHNL_OP_CONFIG_TX_QUEUE" ; +case VIRTCHNL_OP_CONFIG_RX_QUEUE : +return "VIRTCHNL_OP_CONFIG_RX_QUEUE" ; +case VIRTCHNL_OP_CONFIG_VSI_QUEUES : +return "VIRTCHNL_OP_CONFIG_VSI_QUEUES" ; +case VIRTCHNL_OP_CONFIG_IRQ_MAP : +return "VIRTCHNL_OP_CONFIG_IRQ_MAP" ; +case VIRTCHNL_OP_ENABLE_QUEUES : +return "VIRTCHNL_OP_ENABLE_QUEUES" ; +case VIRTCHNL_OP_DISABLE_QUEUES : +return "VIRTCHNL_OP_DISABLE_QUEUES" ; +case VIRTCHNL_OP_ADD_ETH_ADDR : +return "VIRTCHNL_OP_ADD_ETH_ADDR" ; +case VIRTCHNL_OP_DEL_ETH_ADDR : +return "VIRTCHNL_OP_DEL_ETH_ADDR" ; +case VIRTCHNL_OP_ADD_VLAN : +return "VIRTCHNL_OP_ADD_VLAN" ; +case VIRTCHNL_OP_DEL_VLAN : +return "VIRTCHNL_OP_DEL_VLAN" ; +case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE : +return "VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE" ; +case VIRTCHNL_OP_GET_STATS : +return "VIRTCHNL_OP_GET_STATS" ; +case VIRTCHNL_OP_RSVD : +return "VIRTCHNL_OP_RSVD" ; +case VIRTCHNL_OP_EVENT : +return "VIRTCHNL_OP_EVENT" ; +case VIRTCHNL_OP_CONFIG_RSS_KEY : +return "VIRTCHNL_OP_CONFIG_RSS_KEY" ; +case VIRTCHNL_OP_CONFIG_RSS_LUT : +return "VIRTCHNL_OP_CONFIG_RSS_LUT" ; +case VIRTCHNL_OP_GET_RSS_HENA_CAPS : +return "VIRTCHNL_OP_GET_RSS_HENA_CAPS" ; +case VIRTCHNL_OP_SET_RSS_HENA : +return "VIRTCHNL_OP_SET_RSS_HENA" ; +case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING : +return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING" ; +case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING : +return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING" ; +case VIRTCHNL_OP_REQUEST_QUEUES : +return "VIRTCHNL_OP_REQUEST_QUEUES" ; +case VIRTCHNL_OP_ENABLE_CHANNELS : +return "VIRTCHNL_OP_ENABLE_CHANNELS" ; +case VIRTCHNL_OP_DISABLE_CHANNELS : +return "VIRTCHNL_OP_DISABLE_CHANNELS" ; +case VIRTCHNL_OP_ADD_CLOUD_FILTER : +return "VIRTCHNL_OP_ADD_CLOUD_FILTER" ; +case VIRTCHNL_OP_DEL_CLOUD_FILTER : +return "VIRTCHNL_OP_DEL_CLOUD_FILTER" ; +case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS : +return "VIRTCHNL_OP_GET_SUPPORTED_RXDIDS" ; +case VIRTCHNL_OP_ADD_RSS_CFG : +return "VIRTCHNL_OP_ADD_RSS_CFG" ; +case VIRTCHNL_OP_DEL_RSS_CFG : +return "VIRTCHNL_OP_DEL_RSS_CFG" ; +case VIRTCHNL_OP_ADD_FDIR_FILTER : +return "VIRTCHNL_OP_ADD_FDIR_FILTER" ; +case VIRTCHNL_OP_DEL_FDIR_FILTER : +return "VIRTCHNL_OP_DEL_FDIR_FILTER" ; +case VIRTCHNL_OP_GET_MAX_RSS_QREGION : +return "VIRTCHNL_OP_GET_MAX_RSS_QREGION" ; +case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS : +return "VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS" ; +case VIRTCHNL_OP_ADD_VLAN_V2 : +return "VIRTCHNL_OP_ADD_VLAN_V2" ; +case VIRTCHNL_OP_DEL_VLAN_V2 : +return "VIRTCHNL_OP_DEL_VLAN_V2" ; +case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 : +return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2" ; +case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 : +return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2" ; +case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 : +return "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2" ; +case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 : +return "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2" ; +case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 : +return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2" ; +case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 : +return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2" ; +case VIRTCHNL_OP_1588_PTP_GET_CAPS : +return "VIRTCHNL_OP_1588_PTP_GET_CAPS" ; +case VIRTCHNL_OP_1588_PTP_GET_TIME : +return "VIRTCHNL_OP_1588_PTP_GET_TIME" ; +case VIRTCHNL_OP_1588_PTP_SET_TIME : +return "VIRTCHNL_OP_1588_PTP_SET_TIME" ; +case VIRTCHNL_OP_1588_PTP_ADJ_TIME : +return "VIRTCHNL_OP_1588_PTP_ADJ_TIME" ; +case VIRTCHNL_OP_1588_PTP_ADJ_FREQ : +return "VIRTCHNL_OP_1588_PTP_ADJ_FREQ" ; +case VIRTCHNL_OP_1588_PTP_TX_TIMESTAMP : +return "VIRTCHNL_OP_1588_PTP_TX_TIMESTAMP" ; +case VIRTCHNL_OP_1588_PTP_GET_PIN_CFGS : +return "VIRTCHNL_OP_1588_PTP_GET_PIN_CFGS" ; +case VIRTCHNL_OP_1588_PTP_SET_PIN_CFG : +return "VIRTCHNL_OP_1588_PTP_SET_PIN_CFG" ; +case VIRTCHNL_OP_1588_PTP_EXT_TIMESTAMP : +return "VIRTCHNL_OP_1588_PTP_EXT_TIMESTAMP" ; +case VIRTCHNL_OP_ENABLE_QUEUES_V2 : +return "VIRTCHNL_OP_ENABLE_QUEUES_V2" ;include/linux/avf/virtchnl.h enum virtchnl_ops { · line 347
Quoted 10 lines
include/linux/avf/virtchnl.h +10
-0+case VIRTCHNL_OP_DISABLE_QUEUES_V2 : +return "VIRTCHNL_OP_DISABLE_QUEUES_V2" ; +case VIRTCHNL_OP_MAP_QUEUE_VECTOR : +return "VIRTCHNL_OP_MAP_QUEUE_VECTOR" ; +case VIRTCHNL_OP_MAX : +return "VIRTCHNL_OP_MAX" ; +default : +return "Unsupported (update virtchnl.h)" ; + } +}This static inline will result in bloated functions and text (code). As it's far from hotpath, it should be moved into a C file.
Moreover, all those could be defined in an array to reduce text size even more and compressed via definition.#define VIRTCHNL_OP_STR(op) \ [VIRTCHNL_OP_##op] = "VIRTCHNL_OP_" #opstatic const char * const virtchnl_op_strings[] = { VIRTCHNL_OP_STR(UNKNOWN), ... };
Quoted 5 lines
const char *virtchnl_op_str(enum virtchnl_ops v_opcode) {
/* Will be NULL for not defined codes */
return virtchnl_op_strings[v_opcode] ? :
"Unsupported (update virtchnl.h)"; }I'm concerned about adding a C file and the complexity that will add but we will take a look.
Quoted 56 lines
Quoted 15 lines
include/linux/avf/virtchnl.h +13
-1-VIRTCHNL_CHECK_STRUCT_LEN (20 , virtchnl_msg); +static inline const char *virtchnl_stat_str (enum virtchnl_status_code +v_status) { +switch (v_status) { +case VIRTCHNL_STATUS_SUCCESS : +return "VIRTCHNL_STATUS_SUCCESS" ; +case VIRTCHNL_STATUS_ERR_PARAM : +return "VIRTCHNL_STATUS_ERR_PARAM" ; +case VIRTCHNL_STATUS_ERR_NO_MEMORY : +return "VIRTCHNL_STATUS_ERR_NO_MEMORY" ; +case VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH : +return "VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH" ; +case VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR : +return "VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR" ;include/linux/avf/virtchnl.h enum virtchnl_ops { · line 371
Quoted 10 lines
include/linux/avf/virtchnl.h +10
-0+case VIRTCHNL_STATUS_ERR_INVALID_VF_ID : +return "VIRTCHNL_STATUS_ERR_INVALID_VF_ID" ; +case VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR : +return "VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR" ; +case VIRTCHNL_STATUS_ERR_NOT_SUPPORTED : +return "VIRTCHNL_STATUS_ERR_NOT_SUPPORTED" ; +default : +return "Unknown status code (update virtchnl.h)" ; + } +}Same here.
Quoted 3 lines
/* Message descriptions and data structures. */
--- 8< ---
include/linux/avf/virtchnl.h VIRTCHNL_CHECK_STRUCT_LEN(6,
Quoted 1 line
include/linux/avf/virtchnl.h +0
-0@@ -538,17 +851,17 @@ VIRTCHNL_CHECK_STRUCT_LEN(6,
virtchnl_vlan_filter_list);Quoted 20 lines
include/linux/avf/virtchnl.h +6
-11*/ enum virtchnl_vlan_support {VIRTCHNL_VLAN_UNSUPPORTED =0 , -VIRTCHNL_VLAN_ETHERTYPE_8100 =BIT (0 ), -VIRTCHNL_VLAN_ETHERTYPE_88A8 =BIT (1 ), -VIRTCHNL_VLAN_ETHERTYPE_9100 =BIT (2 ), -VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 =BIT (8 ), -VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 =BIT (9 ), -VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 =BIT (10 ), -VIRTCHNL_VLAN_PRIO =BIT (24 ), -VIRTCHNL_VLAN_FILTER_MASK =BIT (28 ), -VIRTCHNL_VLAN_ETHERTYPE_AND =BIT (29 ), -VIRTCHNL_VLAN_ETHERTYPE_XOR =BIT (30 ), -VIRTCHNL_VLAN_TOGGLE =BIT (31 ), +VIRTCHNL_VLAN_ETHERTYPE_8100 =0x00000001 , +VIRTCHNL_VLAN_ETHERTYPE_88A8 =0x00000002 , +VIRTCHNL_VLAN_ETHERTYPE_9100 =0x00000004 , +VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 =0x00000100 , +VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 =0x00000200 , +VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 =0x00000400 ,
Quoted 9 lines
include/linux/avf/virtchnl.h VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list); · line 864
Quoted 5 lines
include/linux/avf/virtchnl.h +5
-0+VIRTCHNL_VLAN_PRIO =0x01000000 , +VIRTCHNL_VLAN_FILTER_MASK =0x10000000 , +VIRTCHNL_VLAN_ETHERTYPE_AND =0x20000000 , +VIRTCHNL_VLAN_ETHERTYPE_XOR =0x40000000 , +VIRTCHNL_VLAN_TOGGLE =0x80000000 Any particular reason for reverting this? Upstream maintainers would most likely ask the same.
Unintentional, will fix.
Quoted 88 lines
Quoted 4 lines
include/linux/avf/virtchnl.h +0
-0};/* This structure is used as part of the
VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS--- 8< ---
Quoted 50 lines
include/linux/avf/virtchnl.h +50
-0+ +static inline const char *virtchnl2_op_str (enum virtchnl_ops +v_opcode) { +switch (v_opcode) { +case VIRTCHNL2_OP_GET_CAPS : +return "VIRTCHNL2_OP_GET_CAPS" ; +case VIRTCHNL2_OP_CREATE_VPORT : +return "VIRTCHNL2_OP_CREATE_VPORT" ; +case VIRTCHNL2_OP_DESTROY_VPORT : +return "VIRTCHNL2_OP_DESTROY_VPORT" ; +case VIRTCHNL2_OP_ENABLE_VPORT : +return "VIRTCHNL2_OP_ENABLE_VPORT" ; +case VIRTCHNL2_OP_DISABLE_VPORT : +return "VIRTCHNL2_OP_DISABLE_VPORT" ; +case VIRTCHNL2_OP_CONFIG_TX_QUEUES : +return "VIRTCHNL2_OP_CONFIG_TX_QUEUES" ; +case VIRTCHNL2_OP_CONFIG_RX_QUEUES : +return "VIRTCHNL2_OP_CONFIG_RX_QUEUES" ; +case VIRTCHNL2_OP_ENABLE_QUEUES : +return "VIRTCHNL2_OP_ENABLE_QUEUES" ; +case VIRTCHNL2_OP_DISABLE_QUEUES : +return "VIRTCHNL2_OP_DISABLE_QUEUES" ; +case VIRTCHNL2_OP_ADD_QUEUES : +return "VIRTCHNL2_OP_ADD_QUEUES" ; +case VIRTCHNL2_OP_DEL_QUEUES : +return "VIRTCHNL2_OP_DEL_QUEUES" ; +case VIRTCHNL2_OP_MAP_QUEUE_VECTOR : +return "VIRTCHNL2_OP_MAP_QUEUE_VECTOR" ; +case VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR : +return "VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR" ; +case VIRTCHNL2_OP_GET_RSS_KEY : +return "VIRTCHNL2_OP_GET_RSS_KEY" ; +case VIRTCHNL2_OP_SET_RSS_KEY : +return "VIRTCHNL2_OP_SET_RSS_KEY" ; +case VIRTCHNL2_OP_GET_RSS_LUT : +return "VIRTCHNL2_OP_GET_RSS_LUT" ; +case VIRTCHNL2_OP_SET_RSS_LUT : +return "VIRTCHNL2_OP_SET_RSS_LUT" ; +case VIRTCHNL2_OP_GET_RSS_HASH : +return "VIRTCHNL2_OP_GET_RSS_HASH" ; +case VIRTCHNL2_OP_SET_RSS_HASH : +return "VIRTCHNL2_OP_SET_RSS_HASH" ; +case VIRTCHNL2_OP_SET_SRIOV_VFS : +return "VIRTCHNL2_OP_SET_SRIOV_VFS" ; +case VIRTCHNL2_OP_ALLOC_VECTORS : +return "VIRTCHNL2_OP_ALLOC_VECTORS" ; +case VIRTCHNL2_OP_DEALLOC_VECTORS : +return "VIRTCHNL2_OP_DEALLOC_VECTORS" ; +case VIRTCHNL2_OP_GET_PTYPE_INFO : +return "VIRTCHNL2_OP_GET_PTYPE_INFO" ;include/linux/avf/virtchnl.h
Quoted 10 lines
include/linux/avf/virtchnl.h +10
-0+case VIRTCHNL2_OP_GET_STATS : +return "VIRTCHNL2_OP_GET_STATS" ; +case VIRTCHNL2_OP_EVENT : +return "VIRTCHNL2_OP_EVENT" ; +case VIRTCHNL2_OP_RESET_VF : +return "VIRTCHNL2_OP_RESET_VF" ; +default : +return virtchnl_op_str (v_opcode); + } +}Same here (array + compression). Since v2 ops start from 500, array indexes can be shifted by this value.
include/linux/avf/virtchnl.h
Quoted 9 lines
include/linux/avf/virtchnl.h +9
-0+ +/** +* virtchnl2_vc_validate_vf_msg +* @ver: Virtchnl version info +* @v_opcode: Opcode for the message +* @msg: pointer to the msg buffer +* @msglen: msg length +* +* validate msg format against struct for each opcode */ --- 8< ---
Quoted 2 lines
--
2.33.0Thanks,
Al
PATCH 2/19 iecm: add basic module init and documentation
In reply to Alan BradyThis adds the basics needed to make a kernel module and documentation needed to use iecm module.
--- .../device_drivers/ethernet/intel/iecm.rst | 93 +++++++++++++++++++ drivers/net/ethernet/intel/Kconfig | 15 +++ drivers/net/ethernet/intel/Makefile | 1 + drivers/net/ethernet/intel/iecm/Makefile | 13 +++ drivers/net/ethernet/intel/iecm/iecm_main.c | 40 ++++++++ drivers/net/ethernet/intel/include/iecm.h | 10 ++ 6 files changed, 172 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/intel/iecm.rst create mode 100644 drivers/net/ethernet/intel/iecm/Makefile create mode 100644 drivers/net/ethernet/intel/iecm/iecm_main.c create mode 100644 drivers/net/ethernet/intel/include/iecm.h
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +93 -0
@@ -0,0 +1,93 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================== +Intel Ethernet Common Module +======================== + +The Intel Ethernet Common Module is meant to serve as an abstraction layer +between device specific implementation details and common net device driver +flows. This library provides several function hooks which allow a device driver +to specify register addresses, control queue communications, and other device +specific functionality. Some functions are required to be implemented while +others have a default implementation that is used when none is supplied by the +device driver. Doing this, a device driver can be written to take advantage +of existing code while also giving the flexibility to implement device specific +features. + +The common use case for this library is for a network device driver that wants +specify its own device specific details but also leverage the more common +code flows found in network device drivers. + +Sections in this document: + Entry Point + Exit Point + Register Operations API + Virtchnl Operations API + +Entry Point +~~~~~~~~~~~ +The primary entry point to the library is the iecm_probe function. Prior to +calling this, device drivers must have allocated an iecm_adapter struct and +initialized it with the required API functions. The adapter struct, along with +the pci_dev struct and the pci_device_id struct, is provided to iecm_probe +which finalizes device initialization and prepares the device for open. + +The iecm_dev_ops struct within the iecm_adapter struct is the primary vehicle +for passing information from device drivers to the common module. A dependent +module must define and assign a reg_ops_init function which will assign the +respective function pointers to initialize register values (see iecm_reg_ops +struct). These are required to be provided by the dependent device driver as +no suitable default can be assumed for register addresses. + +The vc_ops_init function pointer and the related iecm_virtchnl_ops struct are +optional and should only be necessary for device drivers which use a different +method/timing for communicating across a mailbox to the hardware. Within iecm +is a default interface provided in the case where one is not provided by the +device driver. + +Exit Point +~~~~~~~~~~ +When the device driver is being prepared to be removed through the pci_driver +remove callback, it is required for the device driver to call iecm_remove with +the pci_dev struct provided. This is required to ensure all resources are +properly freed and returned to the operating system. + +Register Operations API +~~~~~~~~~~~~~~~~~~~~~~~ +iecm_reg_ops contains three different function pointers relating to initializing +registers for the specific net device using the library. + +ctlq_reg_init relates specifically to setting up registers related to control +queue/mailbox communications. Registers that should be defined include: head, +tail, len, bah, bal, len_mask, len_ena_mask, and head_mask. + +vportq_reg_init relates to setting up queue registers. The tail registers to +be assigned to the iecm_queue struct for each RX/TX queue. + +intr_reg_init relates to any registers needed to setup interrupts. These +include registers needed to enable the interrupt and change ITR settings. + +If the initialization function finds that one or more required function +pointers were not provided, an error will be issued and the device will be +inoperable. + + +Virtchnl Operations API +~~~~~~~~~~~~~~~~~~~~~~~ +The virtchnl is a conduit between driver and hardware that allows device +drivers to send and receive control messages to/from hardware. This is +optional to be specified as there is a general interface that can be assumed +when using this library. However, if a device deviates in some way to +communicate across the mailbox correctly, this interface is provided to allow +that. + +If vc_ops_init is set in the dev_ops field of the iecm_adapter struct, then it +is assumed the device driver is using providing it's own interface to do +virtchnl communications. While providing vc_ops_init is optional, if it is +provided, it is required that the device driver provide function pointers for +those functions in vc_ops, with exception for the enable_vport, disable_vport, +and destroy_vport functions which may not be required for all devices. + +If the initialization function finds that vc_ops_init was defined but one or +more required function pointers were not provided, an error will be issued and +the device will be inoperable.
drivers/net/ethernet/intel/Kconfig +15 -0
@@ -372,4 +372,19 @@ config IGC To compile this driver as a module, choose M here. The module will be called igc. +config IECM + tristate "Intel(R) Ethernet Common Module Support" + default n + depends on PCI_MSI + select DIMLIB + help + This supplies needed functions to device specific device drivers + implementing common module. + + More specific information on configuring the driver is in + <file:Documentation/networking/device_drivers/ethernet/intel/iecm.rst>. + + To compile this as a module, choose M here. The module will be called + iecm. + endif # NET_VENDOR_INTEL
drivers/net/ethernet/intel/Makefile +1 -0
@@ -16,3 +16,4 @@ obj-$(CONFIG_IXGB) += ixgb/ obj-$(CONFIG_IAVF) += iavf/ obj-$(CONFIG_FM10K) += fm10k/ obj-$(CONFIG_ICE) += ice/ +obj-$(CONFIG_IECM) += iecm/
drivers/net/ethernet/intel/iecm/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2019 Intel Corporation + +# +# Makefile for the Intel(R) Data Plane Function Linux Driver +# + +obj-$(CONFIG_IECM) += iecm.o + +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include + +iecm-y := \ + iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_main.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include "iecm.h" + +#define DRV_SUMMARY "Intel(R) Ethernet Common Module" +static const char iecm_driver_string[] =DRV_SUMMARY ; +static const char iecm_copyright[] ="Copyright (c) 2020, Intel Corporation." ; + +MODULE_DESCRIPTION (DRV_SUMMARY ); +MODULE_LICENSE ("GPL v2" ); + +/** +* iecm_module_init - Driver registration routine +* +* iecm_module_init is the first routine called when the driver is +* loaded. All it does is register with the PCI subsystem. +*/ +static int __init iecm_module_init (void ) +{ +pr_info ("%s - version %d\n" , iecm_driver_string,LINUX_VERSION_CODE ); +pr_info ("%s\n" , iecm_copyright); + +return 0 ; +} +module_init (iecm_module_init); + +/** +* iecm_module_exit - Driver exit cleanup routine +* +* iecm_module_exit is called just before the driver is removed +* from memory. +*/ +static void __exit iecm_module_exit(void) +{ +pr_info ("module unloaded\n" ); +} +module_exit (iecm_module_exit);
drivers/net/ethernet/intel/include/iecm.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_H_ +#define _IECM_H_ + +#include <linux/etherdevice.h> +#include <linux/version.h> + +#endif /* !_IECM_H_ */
Signature · 1 line
2.33.0
PATCH 2/19 iecm: add basic module init and documentation
From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:52 -0800
Quoted 125 lines
This adds the basics needed to make a kernel module and documentation needed to use iecm module.
Signed-off-by Alan Brady <[email protected]>Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>--- .../device_drivers/ethernet/intel/iecm.rst | 93 +++++++++++++++++++ drivers/net/ethernet/intel/Kconfig | 15 +++ drivers/net/ethernet/intel/Makefile | 1 + drivers/net/ethernet/intel/iecm/Makefile | 13 +++ drivers/net/ethernet/intel/iecm/iecm_main.c | 40 ++++++++ drivers/net/ethernet/intel/include/iecm.h | 10 ++ 6 files changed, 172 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/intel/iecm.rst create mode 100644 drivers/net/ethernet/intel/iecm/Makefile create mode 100644 drivers/net/ethernet/intel/iecm/iecm_main.c create mode 100644 drivers/net/ethernet/intel/include/iecm.hDocumentation/networking/device_drivers/ethernet/intel/iecm.rst new file +93
-0@@ -0,0 +1,93 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================== +Intel Ethernet Common Module +======================== + +The Intel Ethernet Common Module is meant to serve as an abstraction layer +between device specific implementation details and common net device driver +flows. This library provides several function hooks which allow a device driver +to specify register addresses, control queue communications, and other device +specific functionality. Some functions are required to be implemented while +others have a default implementation that is used when none is supplied by the +device driver. Doing this, a device driver can be written to take advantage +of existing code while also giving the flexibility to implement device specific +features. + +The common use case for this library is for a network device driver that wants +specify its own device specific details but also leverage the more common +code flows found in network device drivers. + +Sections in this document: + Entry Point + Exit Point + Register Operations API + Virtchnl Operations API + +Entry Point +~~~~~~~~~~~ +The primary entry point to the library is the iecm_probe function. Prior to +calling this, device drivers must have allocated an iecm_adapter struct and +initialized it with the required API functions. The adapter struct, along with +the pci_dev struct and the pci_device_id struct, is provided to iecm_probe +which finalizes device initialization and prepares the device for open. + +The iecm_dev_ops struct within the iecm_adapter struct is the primary vehicle +for passing information from device drivers to the common module. A dependent +module must define and assign a reg_ops_init function which will assign the +respective function pointers to initialize register values (see iecm_reg_ops +struct). These are required to be provided by the dependent device driver as +no suitable default can be assumed for register addresses. + +The vc_ops_init function pointer and the related iecm_virtchnl_ops struct are +optional and should only be necessary for device drivers which use a different +method/timing for communicating across a mailbox to the hardware. Within iecm +is a default interface provided in the case where one is not provided by the +device driver. + +Exit Point +~~~~~~~~~~ +When the device driver is being prepared to be removed through the pci_driver +remove callback, it is required for the device driver to call iecm_remove with +the pci_dev struct provided. This is required to ensure all resources are +properly freed and returned to the operating system. + +Register Operations API +~~~~~~~~~~~~~~~~~~~~~~~ +iecm_reg_ops contains three different function pointers relating to initializing +registers for the specific net device using the library. + +ctlq_reg_init relates specifically to setting up registers related to control +queue/mailbox communications. Registers that should be defined include: head, +tail, len, bah, bal, len_mask, len_ena_mask, and head_mask. + +vportq_reg_init relates to setting up queue registers. The tail registers to +be assigned to the iecm_queue struct for each RX/TX queue. + +intr_reg_init relates to any registers needed to setup interrupts. These +include registers needed to enable the interrupt and change ITR settings. + +If the initialization function finds that one or more required function +pointers were not provided, an error will be issued and the device will be +inoperable. + + +Virtchnl Operations API +~~~~~~~~~~~~~~~~~~~~~~~ +The virtchnl is a conduit between driver and hardware that allows device +drivers to send and receive control messages to/from hardware. This is +optional to be specified as there is a general interface that can be assumed +when using this library. However, if a device deviates in some way to +communicate across the mailbox correctly, this interface is provided to allow +that. + +If vc_ops_init is set in the dev_ops field of the iecm_adapter struct, then it +is assumed the device driver is using providing it's own interface to do +virtchnl communications. While providing vc_ops_init is optional, if it is +provided, it is required that the device driver provide function pointers for +those functions in vc_ops, with exception for the enable_vport, disable_vport, +and destroy_vport functions which may not be required for all devices. + +If the initialization function finds that vc_ops_init was defined but one or +more required function pointers were not provided, an error will be issued and +the device will be inoperable.drivers/net/ethernet/intel/Kconfig +0
-0
drivers/net/ethernet/intel/Kconfig config IGC · line 381
Quoted 10 lines
drivers/net/ethernet/intel/Kconfig +7
-0@@ -372,4 +372,19 @@ config IGC To compile this driver as a module, choose M here. The module will be called igc. +config IECM + tristate "Intel(R) Ethernet Common Module Support" + default n + depends on PCI_MSI + select DIMLIB + help + This supplies needed functions to device specific device drivers
One Tab + two spaces instead of 6 spaces. And one Tab is 8 cols in the kernel.
Quoted 24 lines
drivers/net/ethernet/intel/Kconfig +8
-0+ implementing common module. + + More specific information on configuring the driver is in + <file:Documentation/networking/device_drivers/ethernet/intel/iecm.rst>. + + To compile this as a module, choose M here. The module will be called + iecm. + endif # NET_VENDOR_INTELdrivers/net/ethernet/intel/Makefile +1
-0@@ -16,3 +16,4 @@ obj-$(CONFIG_IXGB) += ixgb/ obj-$(CONFIG_IAVF) += iavf/ obj-$(CONFIG_FM10K) += fm10k/ obj-$(CONFIG_ICE) += ice/ +obj-$(CONFIG_IECM) += iecm/drivers/net/ethernet/intel/iecm/Makefile new file +0
-0
drivers/net/ethernet/intel/iecm/Makefile line 10
Quoted 10 lines
drivers/net/ethernet/intel/iecm/Makefile new file +10
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2019 Intel Corporation + +# +# Makefile for the Intel(R) Data Plane Function Linux Driver +# + +obj-$(CONFIG_IECM) += iecm.o + +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include
Common includes are usually being added to include/linux/. Files outside include directories are usually considered "private", i.e. used only inside a particular folder.
Quoted 9 lines
drivers/net/ethernet/intel/iecm/Makefile new file +3
-0+ +iecm-y := \ + iecm_main.odrivers/net/ethernet/intel/iecm/iecm_main.c new file +0
-0
drivers/net/ethernet/intel/iecm/iecm_main.c line 6
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +6
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include "iecm.h"
Quotes are used for local includes. For includes from the search directories please use <>.
drivers/net/ethernet/intel/iecm/iecm_main.c line 13
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +7
-0+ +#define DRV_SUMMARY "Intel(R) Ethernet Common Module" +static const char iecm_driver_string[] =DRV_SUMMARY ; +static const char iecm_copyright[] ="Copyright (c) 2020, Intel Corporation." ; + +MODULE_DESCRIPTION (DRV_SUMMARY ); +MODULE_LICENSE ("GPL v2" );
"GPL v2" is a deprecated identifier and is not recommended for new modules. Just "GPL" is enough and means exactly the same.
Quoted 45 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +27
-0+ +/** +* iecm_module_init - Driver registration routine +* +* iecm_module_init is the first routine called when the driver is +* loaded. All it does is register with the PCI subsystem. +*/ +static int __init iecm_module_init (void ) +{ +pr_info ("%s - version %d\n" , iecm_driver_string,LINUX_VERSION_CODE ); +pr_info ("%s\n" , iecm_copyright); + +return 0 ; +} +module_init (iecm_module_init); + +/** +* iecm_module_exit - Driver exit cleanup routine +* +* iecm_module_exit is called just before the driver is removed +* from memory. +*/ +static void __exit iecm_module_exit(void) +{ +pr_info ("module unloaded\n" ); +} +module_exit (iecm_module_exit);drivers/net/ethernet/intel/include/iecm.h new file +10
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_H_ +#define _IECM_H_ + +#include <linux/etherdevice.h> +#include <linux/version.h> + +#endif /* !_IECM_H_ */ Signature · 1 line
2.33.0
Thanks,
Al
Brady
PATCH 2/19 iecm: add basic module init and documentation
Quoted 153 lines
-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 3:56 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired-
lan at lists.osuosl.org; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 02/19] iecm: add basic module init and documentationFrom: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:52 -0800Quoted 35 lines
This adds the basics needed to make a kernel module and documentation needed to use iecm module.
Signed-off-by Alan Brady <[email protected]>Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>--- .../device_drivers/ethernet/intel/iecm.rst | 93 +++++++++++++++++++ drivers/net/ethernet/intel/Kconfig | 15 +++ drivers/net/ethernet/intel/Makefile | 1 + drivers/net/ethernet/intel/iecm/Makefile | 13 +++ drivers/net/ethernet/intel/iecm/iecm_main.c | 40 ++++++++ drivers/net/ethernet/intel/include/iecm.h | 10 ++ 6 files changed, 172 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/intel/iecm.rst create mode 100644 drivers/net/ethernet/intel/iecm/Makefile create mode 100644 drivers/net/ethernet/intel/iecm/iecm_main.c create mode 100644 drivers/net/ethernet/intel/include/iecm.hdiff --git
a/Documentation/networking/device_drivers/ethernet/intel/iecm.rstb/Documentation/networking/device_drivers/ethernet/intel/iecm.rstnew file mode 100644
index 000000000000..5634e3e65c74Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +5
-0@@ -0,0 +1,93 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================== +Intel Ethernet Common Module +========================Documentation/networking/device_drivers/ethernet/intel/iecm.rst line 15
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +10
-0+ +The Intel Ethernet Common Module is meant to serve as an abstraction +layer between device specific implementation details and common net +device driver flows. This library provides several function hooks +which allow a device driver to specify register addresses, control +queue communications, and other device specific functionality. Some +functions are required to be implemented while others have a default +implementation that is used when none is supplied by the device +driver. Doing this, a device driver can be written to take advantage +of existing code while also giving the flexibility to implement device specificfeatures.
Quoted 8 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +8
-0+ +The common use case for this library is for a network device driver +that wants specify its own device specific details but also leverage +the more common code flows found in network device drivers. + +Sections in this document: + Entry Point + Exit PointDocumentation/networking/device_drivers/ethernet/intel/iecm.rst
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +10
-0+ Register Operations API + Virtchnl Operations API + +Entry Point +~~~~~~~~~~~ +The primary entry point to the library is the iecm_probe function. +Prior to calling this, device drivers must have allocated an +iecm_adapter struct and initialized it with the required API +functions. The adapter struct, along with the pci_dev struct and the +pci_device_id struct, is provided to iecm_probe which finalizes deviceinitialization and prepares the device for open.
Documentation/networking/device_drivers/ethernet/intel/iecm.rst line 40
Quoted 7 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +7
-0+ +The iecm_dev_ops struct within the iecm_adapter struct is the primary +vehicle for passing information from device drivers to the common +module. A dependent module must define and assign a reg_ops_init +function which will assign the respective function pointers to +initialize register values (see iecm_reg_ops struct). These are +required to be provided by the dependent device driver as no suitable defaultcan be assumed for register addresses.
Documentation/networking/device_drivers/ethernet/intel/iecm.rst line 53
Quoted 13 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +13
-0+ +The vc_ops_init function pointer and the related iecm_virtchnl_ops +struct are optional and should only be necessary for device drivers +which use a different method/timing for communicating across a +mailbox to the hardware. Within iecm is a default interface provided +in the case where one is not provided by the device driver. + +Exit Point +~~~~~~~~~~ +When the device driver is being prepared to be removed through the +pci_driver remove callback, it is required for the device driver to +call iecm_remove with the pci_dev struct provided. This is required +to ensure all resources are properly freed and returned to the operatingsystem.
Documentation/networking/device_drivers/ethernet/intel/iecm.rst line 62
Quoted 9 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +9
-0+ +Register Operations API +~~~~~~~~~~~~~~~~~~~~~~~ +iecm_reg_ops contains three different function pointers relating to +initializing registers for the specific net device using the library. + +ctlq_reg_init relates specifically to setting up registers related to +control queue/mailbox communications. Registers that should be +defined include: head, tail, len, bah, bal, len_mask, len_ena_mask, and
head_mask.Documentation/networking/device_drivers/ethernet/intel/iecm.rst line 68
Quoted 6 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +6
-0+ +vportq_reg_init relates to setting up queue registers. The tail +registers to be assigned to the iecm_queue struct for each RX/TX queue. + +intr_reg_init relates to any registers needed to setup interrupts. +These include registers needed to enable the interrupt and change ITRsettings.
Quoted 11 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +11
-0+ +If the initialization function finds that one or more required +function pointers were not provided, an error will be issued and the +device will be inoperable. + + +Virtchnl Operations API +~~~~~~~~~~~~~~~~~~~~~~~ +The virtchnl is a conduit between driver and hardware that allows +device drivers to send and receive control messages to/from hardware. +This is optional to be specified as there is a general interface thatDocumentation/networking/device_drivers/ethernet/intel/iecm.rst line 89
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +10
-0+can be assumed when using this library. However, if a device +deviates in some way to communicate across the mailbox correctly, +this interface is provided to allow that. + +If vc_ops_init is set in the dev_ops field of the iecm_adapter +struct, then it is assumed the device driver is using providing it's +own interface to do virtchnl communications. While providing +vc_ops_init is optional, if it is provided, it is required that the +device driver provide function pointers for those functions in +vc_ops, with exception for the enable_vport, disable_vport, and
destroy_vportfunctions which may not be required for all devices.Quoted 13 lines
Documentation/networking/device_drivers/ethernet/intel/iecm.rst new file +4
-0+ +If the initialization function finds that vc_ops_init was defined but +one or more required function pointers were not provided, an error +will be issued and the device will be inoperable.drivers/net/ethernet/intel/Kconfig +0
-0@@ -372,4 +372,19 @@ config IGC To compile this driver as a module, choose M here. The module will be called igc.
Quoted 11 lines
drivers/net/ethernet/intel/Kconfig config IGC
Quoted 8 lines
drivers/net/ethernet/intel/Kconfig +8
-0+config IECM + tristate "Intel(R) Ethernet Common Module Support" + default n + depends on PCI_MSI + select DIMLIB + help + This supplies needed functions to device specific device +driversOne Tab + two spaces instead of 6 spaces. And one Tab is 8 cols in the kernel.
Will fix
Quoted 32 lines
drivers/net/ethernet/intel/Kconfig config IGC · line 386
Quoted 4 lines
drivers/net/ethernet/intel/Kconfig +4
-0+ implementing common module. + + More specific information on configuring the driver is in +<file:Documentation/networking/device_drivers/ethernet/intel/iecm.rst>.
Quoted 27 lines
drivers/net/ethernet/intel/Kconfig +4
-0+ + To compile this as a module, choose M here. The module will be called + iecm. + endif # NET_VENDOR_INTELdrivers/net/ethernet/intel/Makefile +1
-0@@ -16,3 +16,4 @@ obj-$(CONFIG_IXGB) += ixgb/ obj-$(CONFIG_IAVF) += iavf/ obj-$(CONFIG_FM10K) += fm10k/ obj-$(CONFIG_ICE) += ice/ +obj-$(CONFIG_IECM) += iecm/drivers/net/ethernet/intel/iecm/Makefile new file +5
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only # Copyright (C) 2019 Intel +Corporation + +# +# Makefile for the Intel(R) Data Plane Function Linux Driver #
Quoted 9 lines
drivers/net/ethernet/intel/iecm/Makefile line 10
Quoted 4 lines
drivers/net/ethernet/intel/iecm/Makefile new file +4
-0+ +obj-$(CONFIG_IECM) += iecm.o + +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/includeCommon includes are usually being added to
include/linux/. Files outside include directories are usually considered "private", i.e.
used only inside a particular folder.
Will fix.
Quoted 20 lines
Quoted 10 lines
drivers/net/ethernet/intel/iecm/Makefile new file +3
-0+ +iecm-y := \ + iecm_main.odrivers/net/ethernet/intel/iecm/iecm_main.c new file +0
-0drivers/net/ethernet/intel/iecm/iecm_main.c line 6
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +6
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include "iecm.h" Quotes are used for local includes. For includes from the search directories please use <>.
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_main.c line 13
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +7
-0+ +#define DRV_SUMMARY "Intel(R) Ethernet Common Module" +static const char iecm_driver_string[] =DRV_SUMMARY ;static const +char iecm_copyright[] ="Copyright (c) 2020, Intel Corporation." ; + +MODULE_DESCRIPTION (DRV_SUMMARY ); +MODULE_LICENSE ("GPL v2" );"GPL v2" is a deprecated identifier and is not recommended for new modules. Just "GPL" is enough and means exactly the same.
Will fix
Quoted 48 lines
drivers/net/ethernet/intel/iecm/iecm_main.c
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +9
-0+ +/** +* iecm_module_init - Driver registration routine +* +* iecm_module_init is the first routine called when the driver is +* loaded. All it does is register with the PCI subsystem. +*/ +static int __init iecm_module_init (void ) { + pr_info("%s - version %d\n", iecm_driver_string,
LINUX_VERSION_CODE);Quoted 34 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +16
-0+pr_info ("%s\n" , iecm_copyright); + +return 0 ; +} +module_init (iecm_module_init); + +/** +* iecm_module_exit - Driver exit cleanup routine +* +* iecm_module_exit is called just before the driver is removed +* from memory. +*/ +static void __exit iecm_module_exit(void) { +pr_info ("module unloaded\n" ); +} +module_exit (iecm_module_exit);drivers/net/ethernet/intel/include/iecm.h new file +10
-1@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_H_ +#define _IECM_H_ + +#include <linux/etherdevice.h> +#include <linux/version.h> + +#endif /* !_IECM_H_ */ --Quoted 1 line
2.33.0
Thanks,
Al
PATCH 2/19 iecm: add basic module init and documentation
In reply to Alan BradyQuoted 4 lines · Alan Brady
This adds the basics needed to make a kernel module and documentation needed to use iecm module.
[ snip ]
drivers/net/ethernet/intel/iecm/Makefile line 5
Quoted 11 lines
drivers/net/ethernet/intel/iecm/Makefile new file +5
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2019 Intel Corporation + +# +# Makefile for the Intel(R) Data Plane Function Linux Driver
Maybe the iecm here rather than idpf?
Quoted 14 lines
drivers/net/ethernet/intel/iecm/Makefile new file +8
-0+# + +obj-$(CONFIG_IECM) += iecm.o + +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include + +iecm-y := \ + iecm_main.odrivers/net/ethernet/intel/iecm/iecm_main.c new file +0
-0
drivers/net/ethernet/intel/iecm/iecm_main.c line 10
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +10
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include "iecm.h" + +#define DRV_SUMMARY "Intel(R) Ethernet Common Module" +static const char iecm_driver_string[] =DRV_SUMMARY ; +static const char iecm_copyright[] ="Copyright (c) 2020, Intel Corporation." ;
Do you want this copyright string "2020" to match the top of the file "2019"?
Quoted 53 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +30
-0+ +MODULE_DESCRIPTION (DRV_SUMMARY ); +MODULE_LICENSE ("GPL v2" ); + +/** +* iecm_module_init - Driver registration routine +* +* iecm_module_init is the first routine called when the driver is +* loaded. All it does is register with the PCI subsystem. +*/ +static int __init iecm_module_init (void ) +{ +pr_info ("%s - version %d\n" , iecm_driver_string,LINUX_VERSION_CODE ); +pr_info ("%s\n" , iecm_copyright); + +return 0 ; +} +module_init (iecm_module_init); + +/** +* iecm_module_exit - Driver exit cleanup routine +* +* iecm_module_exit is called just before the driver is removed +* from memory. +*/ +static void __exit iecm_module_exit(void) +{ +pr_info ("module unloaded\n" ); +} +module_exit (iecm_module_exit);drivers/net/ethernet/intel/include/iecm.h new file +10
-1@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_H_ +#define _IECM_H_ + +#include <linux/etherdevice.h> +#include <linux/version.h> + +#endif /* !_IECM_H_ */ --2.33.0
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Brady
PATCH 2/19 iecm: add basic module init and documentation
Quoted 19 lines
-----Original Message-----
From: Shannon Nelson <[email protected]>
Sent: Tuesday, February 1, 2022 11:45 AM
To: Brady, Alan <[email protected]>
Cc: Intel Wired LAN <[email protected]>; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 02/19] iecm: add basic module init and documentationQuoted 4 lines · Alan Brady
This adds the basics needed to make a kernel module and documentation needed to use iecm module.
[ snip ]
Quoted 15 lines
drivers/net/ethernet/intel/iecm/Makefile line 5
Quoted 12 lines
drivers/net/ethernet/intel/iecm/Makefile new file +5
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only # Copyright (C) 2019 Intel +Corporation + +# +# Makefile for the Intel(R) Data Plane Function Linux DriverMaybe the iecm here rather than idpf?
Woops. Thanks, will fix.
Quoted 20 lines
Quoted 20 lines
drivers/net/ethernet/intel/iecm/Makefile new file +8
-0+# + +obj-$(CONFIG_IECM) += iecm.o + +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include + +iecm-y := \ + iecm_main.odrivers/net/ethernet/intel/iecm/iecm_main.c new file +5
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_main.c
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +5
-0+#include "iecm.h" + +#define DRV_SUMMARY "Intel(R) Ethernet Common Module" +static const char iecm_driver_string[] =DRV_SUMMARY ;static const +char iecm_copyright[] ="Copyright (c) 2020, Intel Corporation." ;Do you want this copyright string "2020" to match the top of the file "2019"?
Hmm yes we should probably fix that. Thanks!
Quoted 53 lines
drivers/net/ethernet/intel/iecm/iecm_main.c
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +12
-0+ +MODULE_DESCRIPTION (DRV_SUMMARY ); +MODULE_LICENSE ("GPL v2" ); + +/** +* iecm_module_init - Driver registration routine +* +* iecm_module_init is the first routine called when the driver is +* loaded. All it does is register with the PCI subsystem. +*/ +static int __init iecm_module_init (void ) { + pr_info("%s - version %d\n", iecm_driver_string,
LINUX_VERSION_CODE);Quoted 40 lines
drivers/net/ethernet/intel/iecm/iecm_main.c new file +16
-0+pr_info ("%s\n" , iecm_copyright); + +return 0 ; +} +module_init (iecm_module_init); + +/** +* iecm_module_exit - Driver exit cleanup routine +* +* iecm_module_exit is called just before the driver is removed +* from memory. +*/ +static void __exit iecm_module_exit(void) { +pr_info ("module unloaded\n" ); +} +module_exit (iecm_module_exit);drivers/net/ethernet/intel/include/iecm.h new file +10
-1@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_H_ +#define _IECM_H_ + +#include <linux/etherdevice.h> +#include <linux/version.h> + +#endif /* !_IECM_H_ */ --2.33.0
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
PATCH 3/19 iecm: add probe and remove
In reply to Alan BradyThis adds everything we need in probe and remove as well as a few stubs which will kick off the next step in the init process of device driver coming up.
--- drivers/net/ethernet/intel/iecm/Makefile | 1 + drivers/net/ethernet/intel/iecm/iecm_lib.c | 231 ++++++++++++++++++ drivers/net/ethernet/intel/include/iecm.h | 178 +++++++++++++- .../net/ethernet/intel/include/iecm_txrx.h | 33 +++ 4 files changed, 442 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_lib.c create mode 100644 drivers/net/ethernet/intel/include/iecm_txrx.h
drivers/net/ethernet/intel/iecm/Makefile +1 -0
@@ -10,4 +10,5 @@ obj-$(CONFIG_IECM) += iecm.o ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include iecm-y := \ + iecm_lib.o \ iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +231 -0
231 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm.h +177 -1
184 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm_txrx.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_TXRX_H_ +#define _IECM_TXRX_H_ + +#define IECM_LARGE_MAX_Q 256 +#define IECM_MAX_Q 16 +/* Mailbox Queue */ +#define IECM_MAX_NONQ 1 +#define IECM_MAX_TXQ_DESC 4096 +#define IECM_MAX_RXQ_DESC 4096 +#define IECM_MIN_TXQ_DESC 32 +#define IECM_MIN_TXQ_COMPLQ_DESC 64 +#define IECM_MIN_RXQ_DESC 32 +#define IECM_REQ_DESC_MULTIPLE 32 +#define IECM_REQ_SPLITQ_RXQ_DESC_MULTIPLE 64 +#define IECM_MIN_TX_DESC_NEEDED (MAX_SKB_FRAGS + 6) +#define IECM_TX_WAKE_THRESH ((s16)IECM_MIN_TX_DESC_NEEDED * 2) + +#define IECM_DFLT_SINGLEQ_TX_Q_GROUPS 1 +#define IECM_DFLT_SINGLEQ_RX_Q_GROUPS 1 +#define IECM_DFLT_SINGLEQ_TXQ_PER_GROUP 4 +#define IECM_DFLT_SINGLEQ_RXQ_PER_GROUP 4 + +#define IECM_COMPLQ_PER_GROUP 1 +#define IECM_MAX_BUFQS_PER_RXQ_GRP 2 + +#define IECM_DFLT_SPLITQ_TX_Q_GROUPS 4 +#define IECM_DFLT_SPLITQ_RX_Q_GROUPS 4 +#define IECM_DFLT_SPLITQ_TXQ_PER_GROUP 1 +#define IECM_DFLT_SPLITQ_RXQ_PER_GROUP 1 +#endif /* !_IECM_TXRX_H_ */
Signature · 1 line
2.33.0
PATCH 3/19 iecm: add probe and remove
Quoted 130 lines · Alan Brady
This adds everything we need in probe and remove as well as a few stubs which will kick off the next step in the init process of device driver coming up.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 1 + drivers/net/ethernet/intel/iecm/iecm_lib.c | 231 ++++++++++++++++++ drivers/net/ethernet/intel/include/iecm.h | 178 +++++++++++++- .../net/ethernet/intel/include/iecm_txrx.h | 33 +++ 4 files changed, 442 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_lib.c create mode 100644 drivers/net/ethernet/intel/include/iecm_txrx.hdrivers/net/ethernet/intel/iecm/Makefile +1
-0@@ -10,4 +10,5 @@ obj-$(CONFIG_IECM) += iecm.o ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include iecm-y := \ + iecm_lib.o \ iecm_main.odrivers/net/ethernet/intel/iecm/iecm_lib.c new file +95
-0@@ -0,0 +1,231 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include "iecm.h" + +/** +* iecm_statistics_task - Delayed task to get statistics over mailbox +* @work: work_struct handle to our data +*/ +static void iecm_statistics_task (struct work_struct *work) +{ +/* stub */ +} + +/** +* iecm_service_task - Delayed task for handling mailbox responses +* @work: work_struct handle to our data +* +*/ +static void iecm_service_task (struct work_struct *work) +{ +/* stub */ +} + +/** +* iecm_init_task - Delayed initialization task +* @work: work_struct handle to our data +* +* Init task finishes up pending work started in probe. Due to the asynchronous +* nature in which the device communicates with hardware, we may have to wait +* several milliseconds to get a response. Instead of busy polling in probe, +* pulling it out into a delayed work task prevents us from bogging down the +* whole system waiting for a response from hardware. +*/ +static void iecm_init_task (struct work_struct *work) +{ +/* stub */ +} + +/** +* iecm_deinit_task - Device deinit routine +* @adapter: Driver specific private structue +* +* Extended remove logic which will be used for +* hard reset as well +*/ +static void iecm_deinit_task (struct iecm_adapter *adapter) +{ +/* stub */ +} + +/** +* iecm_vc_event_task - Handle virtchannel event logic +* @work: work queue struct +*/ +static void iecm_vc_event_task (struct work_struct *work) +{ +/* stub */ +} + +/** +* iecm_probe - Device initialization routine +* @pdev: PCI device information struct +* @ent: entry in iecm_pci_tbl +* @adapter: driver specific private structure +* +* Returns 0 on success, negative on failure +*/ +int iecm_probe (struct pci_dev *pdev, +const struct pci_device_id __always_unused *ent, +struct iecm_adapter *adapter) +{ +int err; + + adapter->pdev = pdev; + + err =pcim_enable_device (pdev); +if (err) +return err; + + err =pcim_iomap_regions (pdev,BIT (IECM_BAR0 ),pci_name (pdev)); +if (err) { +dev_err (&pdev->dev,"BAR0 I/O map error %d\n" , err); +return err; + } + +/* set up for high or low dma */ + err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 )); +if (err) + err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); +if (err) { +dev_err (&pdev->dev,"DMA configuration failed: 0x%x\n" , err); +return err;
drivers/net/ethernet/intel/iecm/iecm_lib.c line 105
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +10
-0+ } + +pci_enable_pcie_error_reporting (pdev); +pci_set_master (pdev); +pci_set_drvdata (pdev, adapter); + + adapter->init_wq = +alloc_workqueue ("%s" ,WQ_MEM_RECLAIM ,0 ,KBUILD_MODNAME ); +if (!adapter->init_wq) { +dev_err (&pdev->dev,"Failed to allocate workqueue\n" );
checkpatch usually complains about these kinds of messages, but if you're going to put them in anyway, you might make them more useful and add a bit to each that can tell you which is the one that broke. For example, in this one, you might write it as
"Failed to allocate init workqueue"
Quoted 23 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +23
-0+ err = -ENOMEM ; + goto err_wq_alloc; + } + + adapter->serv_wq = +alloc_workqueue ("%s" ,WQ_MEM_RECLAIM ,0 ,KBUILD_MODNAME ); +if (!adapter->serv_wq) { +dev_err (&pdev->dev,"Failed to allocate workqueue\n" ); + err = -ENOMEM ; + goto err_mbx_wq_alloc; + } + + adapter->stats_wq = +alloc_workqueue ("%s" ,WQ_MEM_RECLAIM ,0 ,KBUILD_MODNAME ); +if (!adapter->stats_wq) { +dev_err (&pdev->dev,"Failed to allocate workqueue\n" ); + err = -ENOMEM ; + goto err_stats_wq_alloc; + } + adapter->vc_event_wq = +alloc_workqueue ("%s" ,WQ_MEM_RECLAIM ,0 ,KBUILD_MODNAME ); +if (!adapter->vc_event_wq) { +dev_err (&pdev->dev,"Failed to allocate workqueue\n" );
drivers/net/ethernet/intel/iecm/iecm_lib.c line 138
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +10
-0+ err = -ENOMEM ; + goto err_vc_event_wq_alloc; + } + +/* setup msglvl */ + adapter->msg_enable =netif_msg_init (-1 ,IECM_AVAIL_NETIF_M ); + + adapter->vports =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (*adapter->vports),GFP_KERNEL ); +if (!adapter->vports) {
With error messages on all the above allocations, is there any reason they aren't here and in the next one?
Quoted 76 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +76
-0+ err = -ENOMEM ; + goto err_vport_alloc; + } + + adapter->netdevs =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (struct net_device *),GFP_KERNEL ); +if (!adapter->netdevs) { + err = -ENOMEM ; + goto err_netdev_alloc; + } + +mutex_init (&adapter->sw_mutex); +mutex_init (&adapter->reset_lock); +init_waitqueue_head (&adapter->vchnl_wq); +init_waitqueue_head (&adapter->sw_marker_wq); + +spin_lock_init (&adapter->cloud_filter_list_lock); +spin_lock_init (&adapter->mac_filter_list_lock); +spin_lock_init (&adapter->vlan_list_lock); +spin_lock_init (&adapter->adv_rss_list_lock); +spin_lock_init (&adapter->fdir_fltr_list_lock); +INIT_LIST_HEAD (&adapter->config_data.mac_filter_list); +INIT_LIST_HEAD (&adapter->config_data.vlan_filter_list); +INIT_LIST_HEAD (&adapter->config_data.adv_rss_list); + +INIT_DELAYED_WORK (&adapter->stats_task, iecm_statistics_task); +INIT_DELAYED_WORK (&adapter->serv_task, iecm_service_task); +INIT_DELAYED_WORK (&adapter->init_task, iecm_init_task); +INIT_DELAYED_WORK (&adapter->vc_event_task, iecm_vc_event_task); + +set_bit (__IECM_HR_DRV_LOAD, adapter->flags); +queue_delayed_work (adapter->vc_event_wq, &adapter->vc_event_task, +msecs_to_jiffies (10 * (pdev->devfn &0x07 ))); + +return 0 ; +err_netdev_alloc: +kfree (adapter->vports); +err_vport_alloc: +destroy_workqueue (adapter->vc_event_wq); +err_vc_event_wq_alloc: +destroy_workqueue (adapter->stats_wq); +err_stats_wq_alloc: +destroy_workqueue (adapter->serv_wq); +err_mbx_wq_alloc: +destroy_workqueue (adapter->init_wq); +err_wq_alloc: +pci_disable_pcie_error_reporting (pdev); +return err; +} +EXPORT_SYMBOL (iecm_probe); + +/** +* iecm_del_user_cfg_data - delete all user configuration data +* @adapter: Driver specific private structue +*/ +static void iecm_del_user_cfg_data (struct iecm_adapter *adapter) +{ +/* stub */ +} + +/** +* iecm_remove - Device removal routine +* @pdev: PCI device information struct +*/ +void iecm_remove (struct pci_dev *pdev) +{ +struct iecm_adapter *adapter =pci_get_drvdata (pdev); + +if (!adapter) +return ; +/* Wait until vc_event_task is done to consider if any hard reset is +* in progress else we may go ahead and release the resources but the +* thread doing the hard reset might continue the init path and +* end up in bad state. +*/ +cancel_delayed_work_sync (&adapter->vc_event_task);
drivers/net/ethernet/intel/iecm/iecm_lib.c line 224
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +10
-0+iecm_deinit_task (adapter); +iecm_del_user_cfg_data (adapter); +msleep (20 ); +destroy_workqueue (adapter->serv_wq); +destroy_workqueue (adapter->vc_event_wq); +destroy_workqueue (adapter->stats_wq); +destroy_workqueue (adapter->init_wq); +kfree (adapter->vports); +kfree (adapter->netdevs); +kfree (adapter->vlan_caps);
Where did vlan_caps get allocated?
Quoted 242 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +7
-0+mutex_destroy (&adapter->sw_mutex); +mutex_destroy (&adapter->reset_lock); +pci_disable_pcie_error_reporting (pdev); +pcim_iounmap_regions (pdev,BIT (IECM_BAR0 )); +pci_disable_device (pdev); +} +EXPORT_SYMBOL (iecm_remove);drivers/net/ethernet/intel/include/iecm.h +177
-1@@ -4,7 +4,183 @@#ifndef _IECM_H_#define _IECM_H_ -#include <linux/etherdevice.h> +#include <linux/aer.h> +#include <linux/pci.h> +#include <linux/netdevice.h> +#include <linux/ethtool.h> #include <linux/version.h> +#include <linux/dim.h> +#include "iecm_txrx.h" + +#define IECM_BAR0 0 +#define IECM_NO_FREE_SLOT 0xffff + +#define IECM_MAX_NUM_VPORTS 1 + +/* available message levels */ +#define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK) + +enum iecm_state { + __IECM_STARTUP, + __IECM_VER_CHECK, + __IECM_GET_CAPS, + __IECM_GET_DFLT_VPORT_PARAMS, + __IECM_INIT_SW, + __IECM_DOWN, + __IECM_UP, + __IECM_STATE_LAST/* this member MUST be last */ +}; + +enum iecm_flags { +/* Soft reset causes */ + __IECM_SR_Q_CHANGE,/* Soft reset to do queue change */ + __IECM_SR_Q_DESC_CHANGE, + __IECM_SR_Q_SCH_CHANGE,/* Scheduling mode change in queue context */ + __IECM_SR_MTU_CHANGE, + __IECM_SR_TC_CHANGE, + __IECM_SR_RSC_CHANGE, + __IECM_SR_HSPLIT_CHANGE, +/* Hard reset causes */ + __IECM_HR_FUNC_RESET,/* Hard reset when txrx timeout */ + __IECM_HR_CORE_RESET,/* when reset event is received on virtchannel */ + __IECM_HR_DRV_LOAD,/* Set on driver load for a clean HW */ +/* Reset in progress */ + __IECM_HR_RESET_IN_PROG, +/* Resources release in progress*/ + __IECM_REL_RES_IN_PROG, +/* Generic bits to share a message */ + __IECM_DEL_QUEUES, + __IECM_UP_REQUESTED,/* Set if open to be called explicitly by driver */ +/* Mailbox interrupt event */ + __IECM_MB_INTR_MODE, + __IECM_MB_INTR_TRIGGER, +/* Stats message pending on mailbox */ + __IECM_MB_STATS_PENDING, +/* Device specific bits */ +/* Request split queue model when creating vport */ + __IECM_REQ_TX_SPLITQ, + __IECM_REQ_RX_SPLITQ, +/* Asynchronous add/del ether address in flight */ + __IECM_ADD_ETH_REQ, + __IECM_DEL_ETH_REQ, +/* Virtchnl message buffer received needs to be processed */ + __IECM_VC_MSG_PENDING, +/* To process software marker packets */ + __IECM_SW_MARKER, +/* must be last */ + __IECM_FLAGS_NBITS, +}; + +struct iecm_reset_reg { +u32 rstat; +u32 rstat_m; +}; + +/* stub */ +struct iecm_vport { +}; + +enum iecm_user_flags { + __IECM_PRIV_FLAGS_HDR_SPLIT =0 , + __IECM_PROMISC_UC =32 , + __IECM_PROMISC_MC, + __IECM_USER_FLAGS_NBITS, +}; + +/* User defined configuration values */ +struct iecm_user_config_data { +u32 num_req_tx_qs;/* user requested TX queues through ethtool */ +u32 num_req_rx_qs;/* user requested RX queues through ethtool */ +u32 num_req_txq_desc; +u32 num_req_rxq_desc; +u16 vlan_ethertype; +void *req_qs_chunks; + DECLARE_BITMAP(user_flags, __IECM_USER_FLAGS_NBITS); + DECLARE_BITMAP(etf_qenable, IECM_LARGE_MAX_Q); +struct list_head mac_filter_list; +struct list_head vlan_filter_list; +struct list_head adv_rss_list; +}; + +struct iecm_rss_data { +u64 rss_hash; +u16 rss_key_size; +u8 *rss_key; +u16 rss_lut_size; +u32 *rss_lut; +}; + +struct iecm_adapter { +struct pci_dev *pdev; +const char *drv_name; +const char *drv_ver; +u32 virt_ver_maj; +u32 virt_ver_min; + +u32 tx_timeout_count; +u32 msg_enable; +enum iecm_state state; + DECLARE_BITMAP(flags, __IECM_FLAGS_NBITS); +struct mutex reset_lock;/* lock to protect reset flows */ +struct iecm_reset_reg reset_reg; + +u16 num_req_msix; +u16 num_msix_entries; +struct msix_entry *msix_entries; +struct virtchnl2_alloc_vectors *req_vec_chunks; + +/* vport structs */ +struct iecm_vport **vports;/* vports created by the driver */ +struct net_device **netdevs;/* associated vport netdevs */ +u16 num_alloc_vport; +u16 next_vport;/* Next free slot in pf->vport[] - 0-based! */ + +struct delayed_work init_task;/* delayed init task */ +struct workqueue_struct *init_wq; +u32 mb_wait_count; +struct delayed_work serv_task;/* delayed service task */ +struct workqueue_struct *serv_wq; +struct delayed_work stats_task;/* delayed statistics task */ +struct workqueue_struct *stats_wq; +struct delayed_work vc_event_task;/* delayed virtchannel event task */ +struct workqueue_struct *vc_event_wq; +/* Store the resources data received from control plane */ +void **vport_params_reqd; +void **vport_params_recvd; +/* User set parameters */ +struct iecm_user_config_data config_data; +void *caps; +struct virtchnl_vlan_caps *vlan_caps; + +wait_queue_head_t vchnl_wq; +wait_queue_head_t sw_marker_wq; +struct iecm_rss_data rss_data; +s32 link_speed; +/* This is only populated if the VIRTCHNL_VF_CAP_ADV_LINK_SPEED is set +* in vf_res->vf_cap_flags. This field should be used going forward and +* the enum virtchnl_link_speed above should be considered the legacy +* way of storing/communicating link speeds. +*/ +u32 link_speed_mbps; +bool link_up; +int num_vfs; + +struct mutex sw_mutex;/* lock to protect vport alloc flow */ +/* lock to protect cloud filters*/ +spinlock_t cloud_filter_list_lock; +/* lock to protect mac filters */ +spinlock_t mac_filter_list_lock; +/* lock to protect vlan filters */ +spinlock_t vlan_list_lock; +/* lock to protect advanced RSS filters */ +spinlock_t adv_rss_list_lock; +/* lock to protect the Flow Director filters */ +spinlock_t fdir_fltr_list_lock; +}; + +int iecm_probe (struct pci_dev *pdev, +const struct pci_device_id __always_unused *ent, +struct iecm_adapter *adapter); +void iecm_remove (struct pci_dev *pdev);#endif /* !_IECM_H_ */ drivers/net/ethernet/intel/include/iecm_txrx.h new file +33
-1@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_TXRX_H_ +#define _IECM_TXRX_H_ + +#define IECM_LARGE_MAX_Q 256 +#define IECM_MAX_Q 16 +/* Mailbox Queue */ +#define IECM_MAX_NONQ 1 +#define IECM_MAX_TXQ_DESC 4096 +#define IECM_MAX_RXQ_DESC 4096 +#define IECM_MIN_TXQ_DESC 32 +#define IECM_MIN_TXQ_COMPLQ_DESC 64 +#define IECM_MIN_RXQ_DESC 32 +#define IECM_REQ_DESC_MULTIPLE 32 +#define IECM_REQ_SPLITQ_RXQ_DESC_MULTIPLE 64 +#define IECM_MIN_TX_DESC_NEEDED (MAX_SKB_FRAGS + 6) +#define IECM_TX_WAKE_THRESH ((s16)IECM_MIN_TX_DESC_NEEDED * 2) + +#define IECM_DFLT_SINGLEQ_TX_Q_GROUPS 1 +#define IECM_DFLT_SINGLEQ_RX_Q_GROUPS 1 +#define IECM_DFLT_SINGLEQ_TXQ_PER_GROUP 4 +#define IECM_DFLT_SINGLEQ_RXQ_PER_GROUP 4 + +#define IECM_COMPLQ_PER_GROUP 1 +#define IECM_MAX_BUFQS_PER_RXQ_GRP 2 + +#define IECM_DFLT_SPLITQ_TX_Q_GROUPS 4 +#define IECM_DFLT_SPLITQ_RX_Q_GROUPS 4 +#define IECM_DFLT_SPLITQ_TXQ_PER_GROUP 1 +#define IECM_DFLT_SPLITQ_RXQ_PER_GROUP 1 +#endif /* !_IECM_TXRX_H_ */ --2.33.0
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Brady
PATCH 3/19 iecm: add probe and remove
Quoted 153 lines
-----Original Message-----
From: Shannon Nelson <[email protected]>
Sent: Tuesday, February 1, 2022 12:02 PM
To: Brady, Alan <[email protected]>
Cc: Intel Wired LAN <[email protected]>; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 03/19] iecm: add probe and removeQuoted 5 lines · Alan Brady
This adds everything we need in probe and remove as well as a few stubs which will kick off the next step in the init process of device driver coming up.
Quoted 8 lines
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 1 + drivers/net/ethernet/intel/iecm/iecm_lib.c | 231++++++++++++++++++
Quoted 44 lines
drivers/net/ethernet/intel/include/iecm.h | 178 +++++++++++++- .../net/ethernet/intel/include/iecm_txrx.h | 33 +++ 4 files changed, 442 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_lib.c create mode 100644 drivers/net/ethernet/intel/include/iecm_txrx.hdrivers/net/ethernet/intel/iecm/Makefile +1
-1@@ -10,4 +10,5 @@ obj-$(CONFIG_IECM) += iecm.o ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include iecm-y := \ + iecm_lib.o \ iecm_main.odrivers/net/ethernet/intel/iecm/iecm_lib.c new file +20
-0@@ -0,0 +1,231 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include "iecm.h" + +/** +* iecm_statistics_task - Delayed task to get statistics over mailbox +* @work: work_struct handle to our data */ static void +iecm_statistics_task (struct work_struct *work) { +/* stub */ +} + +/** +* iecm_service_task - Delayed task for handling mailbox responses +* @work: work_struct handle to our data +* +*/ +static void iecm_service_task (struct work_struct *work) {drivers/net/ethernet/intel/iecm/iecm_lib.c line 30
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +10
-0+/* stub */ +} + +/** +* iecm_init_task - Delayed initialization task +* @work: work_struct handle to our data +* +* Init task finishes up pending work started in probe. Due to the +asynchronous +* nature in which the device communicates with hardware, we may have
Quoted 46 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +46
-0+to wait +* several milliseconds to get a response. Instead of busy polling +in probe, +* pulling it out into a delayed work task prevents us from bogging +down the +* whole system waiting for a response from hardware. +*/ +static void iecm_init_task (struct work_struct *work) { +/* stub */ +} + +/** +* iecm_deinit_task - Device deinit routine +* @adapter: Driver specific private structue +* +* Extended remove logic which will be used for +* hard reset as well +*/ +static void iecm_deinit_task (struct iecm_adapter *adapter) { +/* stub */ +} + +/** +* iecm_vc_event_task - Handle virtchannel event logic +* @work: work queue struct +*/ +static void iecm_vc_event_task (struct work_struct *work) { +/* stub */ +} + +/** +* iecm_probe - Device initialization routine +* @pdev: PCI device information struct +* @ent: entry in iecm_pci_tbl +* @adapter: driver specific private structure +* +* Returns 0 on success, negative on failure */ int +iecm_probe (struct pci_dev *pdev, +const struct pci_device_id __always_unused *ent, +struct iecm_adapter *adapter) { +int err; + + adapter->pdev = pdev; + + err =pcim_enable_device (pdev); +if (err)drivers/net/ethernet/intel/iecm/iecm_lib.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +10
-0+return err; + + err =pcim_iomap_regions (pdev,BIT (IECM_BAR0 ),pci_name (pdev)); +if (err) { +dev_err (&pdev->dev,"BAR0 I/O map error %d\n" , err); +return err; + } + +/* set up for high or low dma */ + err = dma_set_mask_and_coherent(&pdev->dev,
DMA_BIT_MASK(64));drivers/net/ethernet/intel/iecm/iecm_lib.c line 88
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +2
-0+if (err) + err = dma_set_mask_and_coherent(&pdev->dev,
DMA_BIT_MASK(32));drivers/net/ethernet/intel/iecm/iecm_lib.c
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +11
-0+if (err) { +dev_err (&pdev->dev,"DMA configuration failed: 0x%x\n" , err); +return err; + } + +pci_enable_pcie_error_reporting (pdev); +pci_set_master (pdev); +pci_set_drvdata (pdev, adapter); + + adapter->init_wq = + alloc_workqueue("%s", WQ_MEM_RECLAIM, 0,
KBUILD_MODNAME);
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c line 101
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +2
-0+if (!adapter->init_wq) { +dev_err (&pdev->dev,"Failed to allocate workqueue\n" );checkpatch usually complains about these kinds of messages, but if you're going to put them in anyway, you might make them more useful and add a bit to each that can tell you which is the one that broke. For example, in this one, you might write it as "Failed to allocate init workqueue"
I agree it seems excessive, will remove.
Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +6
-0+ err = -ENOMEM ; + goto err_wq_alloc; + } + + adapter->serv_wq = + alloc_workqueue("%s", WQ_MEM_RECLAIM, 0,
KBUILD_MODNAME);drivers/net/ethernet/intel/iecm/iecm_lib.c
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +8
-0+if (!adapter->serv_wq) { +dev_err (&pdev->dev,"Failed to allocate workqueue\n" ); + err = -ENOMEM ; + goto err_mbx_wq_alloc; + } + + adapter->stats_wq = + alloc_workqueue("%s", WQ_MEM_RECLAIM, 0,
KBUILD_MODNAME);drivers/net/ethernet/intel/iecm/iecm_lib.c
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +7
-0+if (!adapter->stats_wq) { +dev_err (&pdev->dev,"Failed to allocate workqueue\n" ); + err = -ENOMEM ; + goto err_stats_wq_alloc; + } + adapter->vc_event_wq = + alloc_workqueue("%s", WQ_MEM_RECLAIM, 0,
KBUILD_MODNAME);
Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c line 138
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +12
-0+if (!adapter->vc_event_wq) { +dev_err (&pdev->dev,"Failed to allocate workqueue\n" ); + err = -ENOMEM ; + goto err_vc_event_wq_alloc; + } + +/* setup msglvl */ + adapter->msg_enable =netif_msg_init (-1 ,IECM_AVAIL_NETIF_M ); + + adapter->vports =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (*adapter->vports),GFP_KERNEL ); +if (!adapter->vports) {With error messages on all the above allocations, is there any reason they aren't here and in the next one?
Probably not a good reason no. Will fix.
Quoted 87 lines
Quoted 61 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +33
-0+ err = -ENOMEM ; + goto err_vport_alloc; + } + + adapter->netdevs =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (struct net_device *),GFP_KERNEL ); +if (!adapter->netdevs) { + err = -ENOMEM ; + goto err_netdev_alloc; + } + +mutex_init (&adapter->sw_mutex); +mutex_init (&adapter->reset_lock); +init_waitqueue_head (&adapter->vchnl_wq); +init_waitqueue_head (&adapter->sw_marker_wq); + +spin_lock_init (&adapter->cloud_filter_list_lock); +spin_lock_init (&adapter->mac_filter_list_lock); +spin_lock_init (&adapter->vlan_list_lock); +spin_lock_init (&adapter->adv_rss_list_lock); +spin_lock_init (&adapter->fdir_fltr_list_lock); +INIT_LIST_HEAD (&adapter->config_data.mac_filter_list); +INIT_LIST_HEAD (&adapter->config_data.vlan_filter_list); +INIT_LIST_HEAD (&adapter->config_data.adv_rss_list); + +INIT_DELAYED_WORK (&adapter->stats_task, iecm_statistics_task); +INIT_DELAYED_WORK (&adapter->serv_task, iecm_service_task); +INIT_DELAYED_WORK (&adapter->init_task, iecm_init_task); +INIT_DELAYED_WORK (&adapter->vc_event_task, + iecm_vc_event_task); + +set_bit (__IECM_HR_DRV_LOAD, adapter->flags); + queue_delayed_work(adapter->vc_event_wq, &adapter-
vc_event_task,drivers/net/ethernet/intel/iecm/iecm_lib.c new file +27
-0+msecs_to_jiffies (10 * (pdev->devfn & + 0x07))); + +return 0 ; +err_netdev_alloc: +kfree (adapter->vports); +err_vport_alloc: +destroy_workqueue (adapter->vc_event_wq); +err_vc_event_wq_alloc: +destroy_workqueue (adapter->stats_wq); +err_stats_wq_alloc: +destroy_workqueue (adapter->serv_wq); +err_mbx_wq_alloc: +destroy_workqueue (adapter->init_wq); +err_wq_alloc: +pci_disable_pcie_error_reporting (pdev); +return err; +} +EXPORT_SYMBOL (iecm_probe); + +/** +* iecm_del_user_cfg_data - delete all user configuration data +* @adapter: Driver specific private structue */ static void +iecm_del_user_cfg_data (struct iecm_adapter *adapter) { +/* stub */ +} +drivers/net/ethernet/intel/iecm/iecm_lib.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +10
-0+/** +* iecm_remove - Device removal routine +* @pdev: PCI device information struct */ void iecm_remove (struct +pci_dev *pdev) { +struct iecm_adapter *adapter =pci_get_drvdata (pdev); + +if (!adapter) +return ; +/* Wait until vc_event_task is done to consider if any hard reset is +* in progress else we may go ahead and release the resources but the
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +4
-0+* thread doing the hard reset might continue the init path and +* end up in bad state. +*/ +cancel_delayed_work_sync (&adapter->vc_event_task);drivers/net/ethernet/intel/iecm/iecm_lib.c line 224
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +10
-0+iecm_deinit_task (adapter); +iecm_del_user_cfg_data (adapter); +msleep (20 ); +destroy_workqueue (adapter->serv_wq); +destroy_workqueue (adapter->vc_event_wq); +destroy_workqueue (adapter->stats_wq); +destroy_workqueue (adapter->init_wq); +kfree (adapter->vports); +kfree (adapter->netdevs); +kfree (adapter->vlan_caps);
Quoted 2 lines
Where did
vlan_capsget allocated?
This probably leaked into this patch as I was breaking down the code into patches. i.e. it doesn't get allocated until a later patch. Will fix. Thanks!
Quoted 252 lines
Quoted 23 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c new file +7
-0+mutex_destroy (&adapter->sw_mutex); +mutex_destroy (&adapter->reset_lock); +pci_disable_pcie_error_reporting (pdev); +pcim_iounmap_regions (pdev,BIT (IECM_BAR0 )); +pci_disable_device (pdev); +} +EXPORT_SYMBOL (iecm_remove);drivers/net/ethernet/intel/include/iecm.h +5
-1@@ -4,7 +4,183 @@#ifndef _IECM_H_#define _IECM_H_ -#include <linux/etherdevice.h> +#include <linux/aer.h> +#include <linux/pci.h> +#include <linux/netdevice.h> +#include <linux/ethtool.h> #include <linux/version.h> +#include <linux/dim.h> drivers/net/ethernet/intel/include/iecm.h line 22
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +9
-0+#include "iecm_txrx.h" + +#define IECM_BAR0 0 +#define IECM_NO_FREE_SLOT 0xffff + +#define IECM_MAX_NUM_VPORTS 1 + +/* available message levels */ +#define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE|
Quoted 7 lines
drivers/net/ethernet/intel/include/iecm.h +7
-0+NETIF_MSG_LINK) + +enum iecm_state { + __IECM_STARTUP, + __IECM_VER_CHECK, + __IECM_GET_CAPS, + __IECM_GET_DFLT_VPORT_PARAMS,drivers/net/ethernet/intel/include/iecm.h
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +10
-0+ __IECM_INIT_SW, + __IECM_DOWN, + __IECM_UP, + __IECM_STATE_LAST /* this member MUST be last */ }; + +enum iecm_flags { +/* Soft reset causes */ + __IECM_SR_Q_CHANGE,/* Soft reset to do queue change */ + __IECM_SR_Q_DESC_CHANGE, + __IECM_SR_Q_SCH_CHANGE,/* Scheduling mode change in queue context */
drivers/net/ethernet/intel/include/iecm.h
Quoted 7 lines
drivers/net/ethernet/intel/include/iecm.h +7
-0+ __IECM_SR_MTU_CHANGE, + __IECM_SR_TC_CHANGE, + __IECM_SR_RSC_CHANGE, + __IECM_SR_HSPLIT_CHANGE, +/* Hard reset causes */ + __IECM_HR_FUNC_RESET,/* Hard reset when txrx timeout */ + __IECM_HR_CORE_RESET, /* when reset event is received onvirtchannel */
drivers/net/ethernet/intel/include/iecm.h
Quoted 8 lines
drivers/net/ethernet/intel/include/iecm.h +8
-0+ __IECM_HR_DRV_LOAD,/* Set on driver load for a clean HW */ +/* Reset in progress */ + __IECM_HR_RESET_IN_PROG, +/* Resources release in progress*/ + __IECM_REL_RES_IN_PROG, +/* Generic bits to share a message */ + __IECM_DEL_QUEUES, + __IECM_UP_REQUESTED, /* Set if open to be called explicitly bydriver */
Quoted 29 lines
drivers/net/ethernet/intel/include/iecm.h +29
-0+/* Mailbox interrupt event */ + __IECM_MB_INTR_MODE, + __IECM_MB_INTR_TRIGGER, +/* Stats message pending on mailbox */ + __IECM_MB_STATS_PENDING, +/* Device specific bits */ +/* Request split queue model when creating vport */ + __IECM_REQ_TX_SPLITQ, + __IECM_REQ_RX_SPLITQ, +/* Asynchronous add/del ether address in flight */ + __IECM_ADD_ETH_REQ, + __IECM_DEL_ETH_REQ, +/* Virtchnl message buffer received needs to be processed */ + __IECM_VC_MSG_PENDING, +/* To process software marker packets */ + __IECM_SW_MARKER, +/* must be last */ + __IECM_FLAGS_NBITS, +}; + +struct iecm_reset_reg { +u32 rstat; +u32 rstat_m; +}; + +/* stub */ +struct iecm_vport { +}; +drivers/net/ethernet/intel/include/iecm.h
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +10
-0+enum iecm_user_flags { + __IECM_PRIV_FLAGS_HDR_SPLIT =0 , + __IECM_PROMISC_UC =32 , + __IECM_PROMISC_MC, + __IECM_USER_FLAGS_NBITS, +}; + +/* User defined configuration values */ struct iecm_user_config_data +{ +u32 num_req_tx_qs;/* user requested TX queues through ethtool */
drivers/net/ethernet/intel/include/iecm.h line 94
Quoted 1 line
drivers/net/ethernet/intel/include/iecm.h +1
-0+u32 num_req_rx_qs;/* user requested RX queues through ethtool */
Quoted 41 lines
drivers/net/ethernet/intel/include/iecm.h +41
-0+u32 num_req_txq_desc; +u32 num_req_rxq_desc; +u16 vlan_ethertype; +void *req_qs_chunks; +DECLARE_BITMAP (user_flags, __IECM_USER_FLAGS_NBITS); +DECLARE_BITMAP (etf_qenable,IECM_LARGE_MAX_Q ); +struct list_head mac_filter_list; +struct list_head vlan_filter_list; +struct list_head adv_rss_list; }; + +struct iecm_rss_data { +u64 rss_hash; +u16 rss_key_size; +u8 *rss_key; +u16 rss_lut_size; +u32 *rss_lut; +}; + +struct iecm_adapter { +struct pci_dev *pdev; +const char *drv_name; +const char *drv_ver; +u32 virt_ver_maj; +u32 virt_ver_min; + +u32 tx_timeout_count; +u32 msg_enable; +enum iecm_state state; + DECLARE_BITMAP(flags, __IECM_FLAGS_NBITS); +struct mutex reset_lock;/* lock to protect reset flows */ +struct iecm_reset_reg reset_reg; + +u16 num_req_msix; +u16 num_msix_entries; +struct msix_entry *msix_entries; +struct virtchnl2_alloc_vectors *req_vec_chunks; + +/* vport structs */ +struct iecm_vport **vports;/* vports created by the driver */ +struct net_device **netdevs;/* associated vport netdevs */ +u16 num_alloc_vport;drivers/net/ethernet/intel/include/iecm.h
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +10
-0+u16 next_vport;/* Next free slot in pf->vport[] - 0-based! */ + +struct delayed_work init_task;/* delayed init task */ +struct workqueue_struct *init_wq; +u32 mb_wait_count; +struct delayed_work serv_task;/* delayed service task */ +struct workqueue_struct *serv_wq; +struct delayed_work stats_task;/* delayed statistics task */ +struct workqueue_struct *stats_wq; +struct delayed_work vc_event_task;/* delayed virtchannel event task */
Quoted 4 lines
drivers/net/ethernet/intel/include/iecm.h +4
-0+struct workqueue_struct *vc_event_wq; +/* Store the resources data received from control plane */ +void **vport_params_reqd; +void **vport_params_recvd;drivers/net/ethernet/intel/include/iecm.h
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +10
-0+/* User set parameters */ +struct iecm_user_config_data config_data; +void *caps; +struct virtchnl_vlan_caps *vlan_caps; + +wait_queue_head_t vchnl_wq; +wait_queue_head_t sw_marker_wq; +struct iecm_rss_data rss_data; +s32 link_speed; +/* This is only populated if the
VIRTCHNL_VF_CAP_ADV_LINK_SPEEDis setdrivers/net/ethernet/intel/include/iecm.h line 160
Quoted 1 line
drivers/net/ethernet/intel/include/iecm.h +1
-0+* in vf_res->vf_cap_flags. This field should be used going forward and
drivers/net/ethernet/intel/include/iecm.h line 161
Quoted 1 line
drivers/net/ethernet/intel/include/iecm.h +1
-0+* the enum virtchnl_link_speed above should be considered the legacy
Quoted 70 lines
drivers/net/ethernet/intel/include/iecm.h +22
-0+* way of storing/communicating link speeds. +*/ +u32 link_speed_mbps; +bool link_up; +int num_vfs; + +struct mutex sw_mutex;/* lock to protect vport alloc flow */ +/* lock to protect cloud filters*/ +spinlock_t cloud_filter_list_lock; +/* lock to protect mac filters */ +spinlock_t mac_filter_list_lock; +/* lock to protect vlan filters */ +spinlock_t vlan_list_lock; +/* lock to protect advanced RSS filters */ +spinlock_t adv_rss_list_lock; +/* lock to protect the Flow Director filters */ + spinlock_t fdir_fltr_list_lock; }; + +int iecm_probe (struct pci_dev *pdev, +const struct pci_device_id __always_unused *ent, +struct iecm_adapter *adapter);void iecm_remove (struct +pci_dev *pdev);#endif /* !_IECM_H_ */ drivers/net/ethernet/intel/include/iecm_txrx.h new file +33
-1@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_TXRX_H_ +#define _IECM_TXRX_H_ + +#define IECM_LARGE_MAX_Q 256 +#define IECM_MAX_Q 16 +/* Mailbox Queue */ +#define IECM_MAX_NONQ 1 +#define IECM_MAX_TXQ_DESC 4096 +#define IECM_MAX_RXQ_DESC 4096 +#define IECM_MIN_TXQ_DESC 32 +#define IECM_MIN_TXQ_COMPLQ_DESC 64 +#define IECM_MIN_RXQ_DESC 32 +#define IECM_REQ_DESC_MULTIPLE 32 +#define IECM_REQ_SPLITQ_RXQ_DESC_MULTIPLE 64 +#define IECM_MIN_TX_DESC_NEEDED (MAX_SKB_FRAGS + 6) #define +IECM_TX_WAKE_THRESH ((s16)IECM_MIN_TX_DESC_NEEDED * 2) + +#define IECM_DFLT_SINGLEQ_TX_Q_GROUPS 1 +#define IECM_DFLT_SINGLEQ_RX_Q_GROUPS 1 +#define IECM_DFLT_SINGLEQ_TXQ_PER_GROUP 4 +#define IECM_DFLT_SINGLEQ_RXQ_PER_GROUP 4 + +#define IECM_COMPLQ_PER_GROUP 1 +#define IECM_MAX_BUFQS_PER_RXQ_GRP 2 + +#define IECM_DFLT_SPLITQ_TX_Q_GROUPS 4 +#define IECM_DFLT_SPLITQ_RX_Q_GROUPS 4 +#define IECM_DFLT_SPLITQ_TXQ_PER_GROUP 1 +#define IECM_DFLT_SPLITQ_RXQ_PER_GROUP 1 +#endif /* !_IECM_TXRX_H_ */ --2.33.0
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
PATCH 4/19 iecm: add api_init and controlq init
In reply to Alan BradyInitializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.
At the end of probe we kicked off a hard reset and this implements what's needed to handle that reset and continue init.
--- drivers/net/ethernet/intel/iecm/Makefile | 3 + .../net/ethernet/intel/iecm/iecm_controlq.c | 649 ++++++++++++++++++ .../ethernet/intel/iecm/iecm_controlq_setup.c | 175 +++++ drivers/net/ethernet/intel/iecm/iecm_lib.c | 191 +++++- .../net/ethernet/intel/iecm/iecm_virtchnl.c | 172 +++++ drivers/net/ethernet/intel/include/iecm.h | 52 ++ .../ethernet/intel/include/iecm_controlq.h | 117 ++++ .../intel/include/iecm_controlq_api.h | 185 +++++ drivers/net/ethernet/intel/include/iecm_mem.h | 20 + 9 files changed, 1563 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq_api.h create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h
drivers/net/ethernet/intel/iecm/Makefile +3 -0
@@ -11,4 +11,7 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include iecm-y := \ iecm_lib.o \ + iecm_virtchnl.o \ + iecm_controlq.o \ + iecm_controlq_setup.o \ iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +649 -0
649 lines not on this page · raw message
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +175 -0
175 lines not on this page · raw message
drivers/net/ethernet/intel/iecm/iecm_lib.c +190 -1
253 lines not on this page · raw message
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +172 -0
172 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm.h +52 -0
93 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm_controlq.h new file +117 -0
117 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +185 -0
185 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm_mem.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_MEM_H_ +#define _IECM_MEM_H_ + +#include <linux/io.h> + +struct iecm_dma_mem { +void *va; +dma_addr_t pa; +size_t size; +}; + +#define wr32 (a, reg, value) writel((value), ((a)->hw_addr + (reg))) +#define rd32 (a, reg) readl((a)->hw_addr + (reg)) +#define wr64 (a, reg, value) writeq((value), ((a)->hw_addr + (reg))) +#define rd64 (a, reg) readq((a)->hw_addr + (reg)) + +#endif /* _IECM_MEM_H_ */
Signature · 1 line
2.33.0
PATCH 4/19 iecm: add api_init and controlq init
From: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:54 -0800
Quoted 22 lines
Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.
At the end of probe we kicked off a hard reset and this implements what's needed to handle that reset and continue init.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 3 + .../net/ethernet/intel/iecm/iecm_controlq.c | 649 ++++++++++++++++++ .../ethernet/intel/iecm/iecm_controlq_setup.c | 175 +++++ drivers/net/ethernet/intel/iecm/iecm_lib.c | 191 +++++- .../net/ethernet/intel/iecm/iecm_virtchnl.c | 172 +++++ drivers/net/ethernet/intel/include/iecm.h | 52 ++ .../ethernet/intel/include/iecm_controlq.h | 117 ++++ .../intel/include/iecm_controlq_api.h | 185 +++++
Quoted 9 lines
drivers/net/ethernet/intel/include/iecm_mem.h | 20 + 9 files changed, 1563 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq_api.h create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h
--- 8< ---
Quoted 50 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +44
-0@@ -0,0 +1,185 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020, Intel Corporation. */ + +#ifndef _IECM_CONTROLQ_API_H_ +#define _IECM_CONTROLQ_API_H_ + +#include "iecm_mem.h" + +struct iecm_hw; + +/* Used for queue init, response and events */ +enum iecm_ctlq_type { + IECM_CTLQ_TYPE_MAILBOX_TX = 0, + IECM_CTLQ_TYPE_MAILBOX_RX = 1, + IECM_CTLQ_TYPE_CONFIG_TX = 2, + IECM_CTLQ_TYPE_CONFIG_RX = 3, + IECM_CTLQ_TYPE_EVENT_RX = 4, + IECM_CTLQ_TYPE_RDMA_TX = 5, + IECM_CTLQ_TYPE_RDMA_RX = 6, + IECM_CTLQ_TYPE_RDMA_COMPL = 7 +}; + +/* Generic Control Queue Structures */ +struct iecm_ctlq_reg { + /* used for queue tracking */ + u32 head; + u32 tail; + /* Below applies only to default mb (if present) */ + u32 len; + u32 bah; + u32 bal; + u32 len_mask; + u32 len_ena_mask; + u32 head_mask; +}; + +/* Generic queue msg structure */ +struct iecm_ctlq_msg { + u16 vmvf_type; /* represents the source of the message on recv */ +#define IECM_VMVF_TYPE_VF 0 +#define IECM_VMVF_TYPE_VM 1 +#define IECM_VMVF_TYPE_PF 2 + u16 opcode; + u16 data_len; /* data_len = 0 when no payload is attached */
drivers/net/ethernet/intel/include/iecm_controlq_api.h line 54
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +10
-0+union { +u16 func_id;/* when sending a message */ +u16 status;/* when receiving a message */ + }; +union { +struct { +u32 chnl_retval; +u32 chnl_opcode; + } mbx; + } cookie;
One field union? If it will be expanded later, please unionize it only then.
Quoted 121 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +121
-0+union { +#define IECM_DIRECT_CTX_SIZE 16 +#define IECM_INDIRECT_CTX_SIZE 8 +/* 16 bytes of context can be provided or 8 bytes of context +* plus the address of a DMA buffer +*/ +u8 direct[IECM_DIRECT_CTX_SIZE ]; +struct { +u8 context[IECM_INDIRECT_CTX_SIZE ]; +struct iecm_dma_mem *payload; + } indirect; + } ctx; +}; + +/* Generic queue info structures */ +/* MB, CONFIG and EVENT q do not have extended info */ +struct iecm_ctlq_create_info { +enum iecm_ctlq_type type; +int id;/* absolute queue offset passed as input +* -1 for default mailbox if present +*/ +u16 len;/* Queue length passed as input */ +u16 buf_size;/* buffer size passed as input */ +u64 base_address;/* output, HPA of the Queue start */ +struct iecm_ctlq_reg reg;/* registers accessed by ctlqs */ + +int ext_info_size; +void *ext_info;/* Specific to q type */ +}; + +/* Control Queue information */ +struct iecm_ctlq_info { +struct list_head cq_list; + +enum iecm_ctlq_type cq_type; +int q_id; +/* control queue lock */ +struct mutex cq_lock; + +/* used for interrupt processing */ +u16 next_to_use; +u16 next_to_clean; +u16 next_to_post;/* starting descriptor to post buffers +* to after recev +*/ + +struct iecm_dma_mem desc_ring;/* descriptor ring memory +* iecm_dma_mem is defined in OSdep.h +*/ +union { +struct iecm_dma_mem **rx_buff; +struct iecm_ctlq_msg **tx_msg; + } bi; + +u16 buf_size;/* queue buffer size */ +u16 ring_size;/* Number of descriptors */ +struct iecm_ctlq_reg reg;/* registers accessed by ctlqs */ +}; + +/* PF/VF mailbox commands */ +enum iecm_mbx_opc { +/* iecm_mbq_opc_send_msg_to_pf: +* usage: used by PF or VF to send a message to its CPF +* target: RX queue and function ID of parent PF taken from HW +*/ + iecm_mbq_opc_send_msg_to_pf =0x0801 , + +/* iecm_mbq_opc_send_msg_to_vf: +* usage: used by PF to send message to a VF +* target: VF control queue ID must be specified in descriptor +*/ + iecm_mbq_opc_send_msg_to_vf =0x0802 , + +/* iecm_mbq_opc_send_msg_to_peer_pf: +* usage: used by any function to send message to any peer PF +* target: RX queue and host of parent PF taken from HW +*/ + iecm_mbq_opc_send_msg_to_peer_pf =0x0803 , + +/* iecm_mbq_opc_send_msg_to_peer_drv: +* usage: used by any function to send message to any peer driver +* target: RX queue and target host must be specific in descriptor +*/ + iecm_mbq_opc_send_msg_to_peer_drv =0x0804 , +}; + +/* API support for control queue management */ + +/* Will init all required q including default mb. "q_info" is an array of +* create_info structs equal to the number of control queues to be created. +*/ +int iecm_ctlq_init (struct iecm_hw *hw,u8 num_q, +struct iecm_ctlq_create_info *q_info); + +/* Allocate and initialize a single control queue, which will be added to the +* control queue list; returns a handle to the created control queue +*/ +int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq); + +/* Deinitialize and deallocate a single control queue */ +void iecm_ctlq_remove (struct iecm_hw *hw, +struct iecm_ctlq_info *cq); + +/* Sends messages to HW and will also free the buffer*/ +int iecm_ctlq_send (struct iecm_hw *hw, +struct iecm_ctlq_info *cq, +u16 num_q_msg, +struct iecm_ctlq_msg q_msg[]); + +/* Receives messages and called by interrupt handler/polling +* initiated by app/process. Also caller is supposed to free the buffers +*/ +int iecm_ctlq_recv (struct iecm_ctlq_info *cq,u16 *num_q_msg, +struct iecm_ctlq_msg *q_msg); + +/* Reclaims send descriptors on HW write back */ +int iecm_ctlq_clean_sq (struct iecm_ctlq_info *cq,u16 *clean_count, +struct iecm_ctlq_msg *msg_status[]); +
drivers/net/ethernet/intel/include/iecm_controlq_api.h line 185
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +10
-0+/* Indicate RX buffers are done being processed */ +int iecm_ctlq_post_rx_buffs (struct iecm_hw *hw, +struct iecm_ctlq_info *cq, +u16 *buff_count, +struct iecm_dma_mem **buffs); + +/* Will destroy all q including the default mb */ +int iecm_ctlq_deinit (struct iecm_hw *hw); + +#endif /* _IECM_CONTROLQ_API_H_ */
--- 8< ---
Quoted 2 lines
Signature · 1 line
2.33.0
Thanks,
Al
Brady
PATCH 4/19 iecm: add api_init and controlq init
Quoted 102 lines
-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 4:09 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired-
lan at lists.osuosl.org; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 04/19] iecm: addapi_initand controlq initFrom: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:54 -0800Quoted 24 lines
Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.
At the end of probe we kicked off a hard reset and this implements what's needed to handle that reset and continue init.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 3 + .../net/ethernet/intel/iecm/iecm_controlq.c | 649 ++++++++++++++++++ .../ethernet/intel/iecm/iecm_controlq_setup.c | 175 +++++ drivers/net/ethernet/intel/iecm/iecm_lib.c | 191 +++++- .../net/ethernet/intel/iecm/iecm_virtchnl.c | 172 +++++ drivers/net/ethernet/intel/include/iecm.h | 52 ++ .../ethernet/intel/include/iecm_controlq.h | 117 ++++ .../intel/include/iecm_controlq_api.h | 185 +++++ drivers/net/ethernet/intel/include/iecm_mem.h | 20 + 9 files changed, 1563 insertions(+), 1 deletion(-) create modeQuoted 9 lines
100644
drivers/net/ethernet/intel/iecm/iecm_controlq.ccreate mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq_api.h create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h--- 8< ---
Quoted 52 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +45
-0@@ -0,0 +1,185 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020, Intel Corporation. */ + +#ifndef _IECM_CONTROLQ_API_H_ +#define _IECM_CONTROLQ_API_H_ + +#include "iecm_mem.h" + +struct iecm_hw; + +/* Used for queue init, response and events */ enum iecm_ctlq_type { + IECM_CTLQ_TYPE_MAILBOX_TX = 0, + IECM_CTLQ_TYPE_MAILBOX_RX = 1, + IECM_CTLQ_TYPE_CONFIG_TX = 2, + IECM_CTLQ_TYPE_CONFIG_RX = 3, + IECM_CTLQ_TYPE_EVENT_RX = 4, + IECM_CTLQ_TYPE_RDMA_TX = 5, + IECM_CTLQ_TYPE_RDMA_RX = 6, + IECM_CTLQ_TYPE_RDMA_COMPL = 7 +}; + +/* Generic Control Queue Structures */ struct iecm_ctlq_reg { + /* used for queue tracking */ + u32 head; + u32 tail; + /* Below applies only to default mb (if present) */ + u32 len; + u32 bah; + u32 bal; + u32 len_mask; + u32 len_ena_mask; + u32 head_mask; +}; + +/* Generic queue msg structure */ +struct iecm_ctlq_msg { + u16 vmvf_type; /* represents the source of the message on recv */ +#define IECM_VMVF_TYPE_VF 0 #define IECM_VMVF_TYPE_VM 1 #define +IECM_VMVF_TYPE_PF 2 + u16 opcode; + u16 data_len; /* data_len = 0 when no payload is attached */ + union { + u16 func_id; /* when sending a message */ + u16 status; /* when receiving a message */ + };
Quoted 9 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h line 54
Quoted 6 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +6
-0+union { +struct { +u32 chnl_retval; +u32 chnl_opcode; + } mbx; + } cookie;One field union? If it will be expanded later, please unionize it only then.
Will fix
Quoted 140 lines
Quoted 37 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +37
-0+union { +#define IECM_DIRECT_CTX_SIZE 16 +#define IECM_INDIRECT_CTX_SIZE 8 +/* 16 bytes of context can be provided or 8 bytes of context +* plus the address of a DMA buffer +*/ +u8 direct[IECM_DIRECT_CTX_SIZE ]; +struct { +u8 context[IECM_INDIRECT_CTX_SIZE ]; +struct iecm_dma_mem *payload; + } indirect; + } ctx; +}; + +/* Generic queue info structures */ +/* MB, CONFIG and EVENT q do not have extended info */ struct +iecm_ctlq_create_info { +enum iecm_ctlq_type type; +int id;/* absolute queue offset passed as input +* -1 for default mailbox if present +*/ +u16 len;/* Queue length passed as input */ +u16 buf_size;/* buffer size passed as input */ +u64 base_address;/* output, HPA of the Queue start */ +struct iecm_ctlq_reg reg;/* registers accessed by ctlqs */ + +int ext_info_size; +void *ext_info;/* Specific to q type */ }; + +/* Control Queue information */ +struct iecm_ctlq_info { +struct list_head cq_list; + +enum iecm_ctlq_type cq_type; +int q_id; +/* control queue lock */ +struct mutex cq_lock;drivers/net/ethernet/intel/include/iecm_controlq_api.h
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +10
-0+ +/* used for interrupt processing */ +u16 next_to_use; +u16 next_to_clean; +u16 next_to_post;/* starting descriptor to post buffers +* to after recev +*/ + +struct iecm_dma_mem desc_ring;/* descriptor ring memory +* iecm_dma_mem is defined in
OSdep.hQuoted 74 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +74
-0+*/ +union { +struct iecm_dma_mem **rx_buff; +struct iecm_ctlq_msg **tx_msg; + } bi; + +u16 buf_size;/* queue buffer size */ +u16 ring_size;/* Number of descriptors */ +struct iecm_ctlq_reg reg;/* registers accessed by ctlqs */ +}; + +/* PF/VF mailbox commands */ +enum iecm_mbx_opc { +/* iecm_mbq_opc_send_msg_to_pf: +* usage: used by PF or VF to send a message to its CPF +* target: RX queue and function ID of parent PF taken from HW +*/ + iecm_mbq_opc_send_msg_to_pf =0x0801 , + +/* iecm_mbq_opc_send_msg_to_vf: +* usage: used by PF to send message to a VF +* target: VF control queue ID must be specified in descriptor +*/ + iecm_mbq_opc_send_msg_to_vf =0x0802 , + +/* iecm_mbq_opc_send_msg_to_peer_pf: +* usage: used by any function to send message to any peer PF +* target: RX queue and host of parent PF taken from HW +*/ + iecm_mbq_opc_send_msg_to_peer_pf =0x0803 , + +/* iecm_mbq_opc_send_msg_to_peer_drv: +* usage: used by any function to send message to any peer driver +* target: RX queue and target host must be specific in descriptor +*/ + iecm_mbq_opc_send_msg_to_peer_drv =0x0804 , +}; + +/* API support for control queue management */ + +/* Will init all required q including default mb. "q_info" is an +array of +* create_info structs equal to the number of control queues to be created. +*/ +int iecm_ctlq_init (struct iecm_hw *hw,u8 num_q, +struct iecm_ctlq_create_info *q_info); + +/* Allocate and initialize a single control queue, which will be +added to the +* control queue list; returns a handle to the created control queue +*/ int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq); + +/* Deinitialize and deallocate a single control queue */ void +iecm_ctlq_remove (struct iecm_hw *hw, +struct iecm_ctlq_info *cq); + +/* Sends messages to HW and will also free the buffer*/ int +iecm_ctlq_send (struct iecm_hw *hw, +struct iecm_ctlq_info *cq, +u16 num_q_msg, +struct iecm_ctlq_msg q_msg[]); + +/* Receives messages and called by interrupt handler/polling +* initiated by app/process. Also caller is supposed to free the +buffers */ int iecm_ctlq_recv (struct iecm_ctlq_info *cq,u16 +*num_q_msg, +struct iecm_ctlq_msg *q_msg); + +/* Reclaims send descriptors on HW write back */ int +iecm_ctlq_clean_sq (struct iecm_ctlq_info *cq,u16 *clean_count, +struct iecm_ctlq_msg *msg_status[]); +drivers/net/ethernet/intel/include/iecm_controlq_api.h line 185
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +10
-0+/* Indicate RX buffers are done being processed */ int +iecm_ctlq_post_rx_buffs (struct iecm_hw *hw, +struct iecm_ctlq_info *cq, +u16 *buff_count, +struct iecm_dma_mem **buffs); + +/* Will destroy all q including the default mb */ int +iecm_ctlq_deinit (struct iecm_hw *hw); + +#endif /* _IECM_CONTROLQ_API_H_ */ --- 8< ---
Quoted 2 lines
--
2.33.0Thanks,
Al
PATCH 4/19 iecm: add api_init and controlq init
In reply to Alan BradyQuoted 117 lines · Alan Brady
Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.
At the end of probe we kicked off a hard reset and this implements what's needed to handle that reset and continue init.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 3 + .../net/ethernet/intel/iecm/iecm_controlq.c | 649 ++++++++++++++++++ .../ethernet/intel/iecm/iecm_controlq_setup.c | 175 +++++ drivers/net/ethernet/intel/iecm/iecm_lib.c | 191 +++++- .../net/ethernet/intel/iecm/iecm_virtchnl.c | 172 +++++ drivers/net/ethernet/intel/include/iecm.h | 52 ++ .../ethernet/intel/include/iecm_controlq.h | 117 ++++ .../intel/include/iecm_controlq_api.h | 185 +++++ drivers/net/ethernet/intel/include/iecm_mem.h | 20 + 9 files changed, 1563 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq_api.h create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.hdrivers/net/ethernet/intel/iecm/Makefile +3
-0@@ -11,4 +11,7 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include iecm-y := \ iecm_lib.o \ + iecm_virtchnl.o \ + iecm_controlq.o \ + iecm_controlq_setup.o \ iecm_main.odrivers/net/ethernet/intel/iecm/iecm_controlq.c new file +67
-0@@ -0,0 +1,649 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2020, Intel Corporation. */ + +#include "iecm_controlq.h" + +/** +* iecm_ctlq_setup_regs - initialize control queue registers +* @cq: pointer to the specific control queue +* @q_create_info: structs containing info for each queue to be initialized +*/ +static void +iecm_ctlq_setup_regs (struct iecm_ctlq_info *cq, +struct iecm_ctlq_create_info *q_create_info) +{ +/* set head and tail registers in our local struct */ + cq->reg.head = q_create_info->reg.head; + cq->reg.tail = q_create_info->reg.tail; + cq->reg.len = q_create_info->reg.len; + cq->reg.bah = q_create_info->reg.bah; + cq->reg.bal = q_create_info->reg.bal; + cq->reg.len_mask = q_create_info->reg.len_mask; + cq->reg.len_ena_mask = q_create_info->reg.len_ena_mask; + cq->reg.head_mask = q_create_info->reg.head_mask; +} + +/** +* iecm_ctlq_init_regs - Initialize control queue registers +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* @is_rxq: true if receive control queue, false otherwise +* +* Initialize registers. The caller is expected to have already initialized the +* descriptor ring memory and buffer memory +*/ +static void iecm_ctlq_init_regs (struct iecm_hw *hw,struct iecm_ctlq_info *cq, +bool is_rxq) +{ +/* Update tail to post pre-allocated buffers for rx queues */ +if (is_rxq) +wr32 (hw, cq->reg.tail, (u32)(cq->ring_size -1 )); + +/* For non-Mailbox control queues only TAIL need to be set */ +if (cq->q_id !=-1 ) +return ; + +/* Clear Head for both send or receive */ +wr32 (hw, cq->reg.head,0 ); + +/* set starting point */ +wr32 (hw, cq->reg.bal,lower_32_bits (cq->desc_ring.pa)); +wr32 (hw, cq->reg.bah,upper_32_bits (cq->desc_ring.pa)); +wr32 (hw, cq->reg.len, (cq->ring_size | cq->reg.len_ena_mask)); +} + +/** +* iecm_ctlq_init_rxq_bufs - populate receive queue descriptors with buf +* @cq: pointer to the specific Control queue +* +* Record the address of the receive queue DMA buffers in the descriptors. +* The buffers must have been previously allocated. +*/ +static void iecm_ctlq_init_rxq_bufs (struct iecm_ctlq_info *cq) +{ +int i =0 ; + +for (i =0 ; i < cq->ring_size; i++) { +struct iecm_ctlq_desc *desc =IECM_CTLQ_DESC (cq, i);
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 77
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+struct iecm_dma_mem *bi = cq->bi.rx_buff[i]; + +/* No buffer to post to descriptor, continue */ +if (!bi) +continue ; + + desc->flags = +cpu_to_le16 (IECM_CTLQ_FLAG_BUF |IECM_CTLQ_FLAG_RD ); + desc->opcode =0 ; + desc->datalen = (__le16 )cpu_to_le16 (bi->size);
Why the typecast to __le16, aren't we there already with the cpu_to_le16()?
Quoted 54 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +54
-0+ desc->ret_val =0 ; + desc->cookie_high =0 ; + desc->cookie_low =0 ; + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (bi->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (bi->pa)); + desc->params.indirect.param0 =0 ; + desc->params.indirect.param1 =0 ; + } +} + +/** +* iecm_ctlq_shutdown - shutdown the CQ +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* The main shutdown routine for any controq queue +*/ +static void iecm_ctlq_shutdown (struct iecm_hw *hw,struct iecm_ctlq_info *cq) +{ +mutex_lock (&cq->cq_lock); + +if (!cq->ring_size) + goto shutdown_sq_out; + +/* free ring buffers and the ring itself */ +iecm_ctlq_dealloc_ring_res (hw, cq); + +/* Set ring_size to 0 to indicate uninitialized queue */ + cq->ring_size =0 ; + +shutdown_sq_out: +mutex_unlock (&cq->cq_lock); +mutex_destroy (&cq->cq_lock); +} + +/** +* iecm_ctlq_add - add one control queue +* @hw: pointer to hardware struct +* @qinfo: info for queue to be created +* @cq_out: (output) double pointer to control queue to be created +* +* Allocate and initialize a control queue and add it to the control queue list. +* The cq parameter will be allocated/initialized and passed back to the caller +* if no errors occur. +* +* Note: iecm_ctlq_init must be called prior to any calls to iecm_ctlq_add +*/ +int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq_out) +{ +bool is_rxq = false;
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 141
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+int status =0 ; + +if (!qinfo->len || !qinfo->buf_size || + qinfo->len >IECM_CTLQ_MAX_RING_SIZE || + qinfo->buf_size >IECM_CTLQ_MAX_BUF_LEN ) +return -EINVAL ; + + *cq_out =kcalloc (1 ,sizeof (struct iecm_ctlq_info ),GFP_KERNEL ); +if (!(*cq_out)) +return -ENOMEM ;
You might keep this as a local variable until you get to a successful end, then set *cq_out when done.
Else, you need to be sure to clear it back to NULL on error return to be sure no one uses a bogus value.
Quoted 43 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +43
-0+ + (*cq_out)->cq_type = qinfo->type; + (*cq_out)->q_id = qinfo->id; + (*cq_out)->buf_size = qinfo->buf_size; + (*cq_out)->ring_size = qinfo->len; + + (*cq_out)->next_to_use =0 ; + (*cq_out)->next_to_clean =0 ; + (*cq_out)->next_to_post = (*cq_out)->ring_size -1 ; + +switch (qinfo->type) { +case IECM_CTLQ_TYPE_MAILBOX_RX : + is_rxq = true; + fallthrough; +case IECM_CTLQ_TYPE_MAILBOX_TX : + status =iecm_ctlq_alloc_ring_res (hw, *cq_out); +break ; +default : + status = -EBADR ; +break ; + } + +if (status) + goto init_free_q; + +if (is_rxq) { +iecm_ctlq_init_rxq_bufs (*cq_out); + }else { +/* Allocate the array of msg pointers for TX queues */ + (*cq_out)->bi.tx_msg =kcalloc (qinfo->len, +sizeof (struct iecm_ctlq_msg *), +GFP_KERNEL ); +if (!(*cq_out)->bi.tx_msg) { + status = -ENOMEM ; + goto init_dealloc_q_mem; + } + } + +iecm_ctlq_setup_regs (*cq_out, qinfo); + +iecm_ctlq_init_regs (hw, *cq_out, is_rxq); + +mutex_init (&(*cq_out)->cq_lock);
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 194
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ +list_add (&(*cq_out)->cq_list, &hw->cq_list_head); + +return status; + +init_dealloc_q_mem: +/* free ring buffers and the ring itself */ +iecm_ctlq_dealloc_ring_res (hw, *cq_out); +init_free_q: +kfree (*cq_out);
Probably should clear this back to NULL.
Quoted 40 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +40
-0+ +return status; +} + +/** +* iecm_ctlq_remove - deallocate and remove specified control queue +* @hw: pointer to hardware struct +* @cq: pointer to control queue to be removed +*/ +void iecm_ctlq_remove (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{ +list_del (&cq->cq_list); +iecm_ctlq_shutdown (hw, cq); +kfree (cq); +} + +/** +* iecm_ctlq_init - main initialization routine for all control queues +* @hw: pointer to hardware struct +* @num_q: number of queues to initialize +* @q_info: array of structs containing info for each queue to be initialized +* +* This initializes any number and any type of control queues. This is an all +* or nothing routine; if one fails, all previously allocated queues will be +* destroyed. This must be called prior to using the individual add/remove +* APIs. +*/ +int iecm_ctlq_init (struct iecm_hw *hw,u8 num_q, +struct iecm_ctlq_create_info *q_info) +{ +struct iecm_ctlq_info *cq =NULL , *tmp =NULL ; +int ret_code =0 ; +int i =0 ; + +INIT_LIST_HEAD (&hw->cq_list_head); + +for (i =0 ; i < num_q; i++) { +struct iecm_ctlq_create_info *qinfo = q_info + i; +
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 244
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ ret_code =iecm_ctlq_add (hw, qinfo, &cq); +if (ret_code) + goto init_destroy_qs; + } + +return ret_code; + +init_destroy_qs: +list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) +iecm_ctlq_remove (hw, cq);
This could call iecm_ctlq_deinit() rather than repeat the same code.
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +7
-0+ +return ret_code; +} + +/** +* iecm_ctlq_deinit - destroy all control queues +* @hw: pointer to hw struct
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 261
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+*/ +int iecm_ctlq_deinit (struct iecm_hw *hw) +{ +struct iecm_ctlq_info *cq =NULL , *tmp =NULL ; +int ret_code =0 ; + +list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) +iecm_ctlq_remove (hw, cq); + +return ret_code;
Why is there a return code here when there is never an error?
Quoted 88 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +88
-0+} + +/** +* iecm_ctlq_send - send command to Control Queue (CTQ) +* @hw: pointer to hw struct +* @cq: handle to control queue struct to send on +* @num_q_msg: number of messages to send on control queue +* @q_msg: pointer to array of queue messages to be sent +* +* The caller is expected to allocate DMAable buffers and pass them to the +* send routine via the q_msg struct / control queue specific data struct. +* The control queue will hold a reference to each send message until +* the completion for that message has been cleaned. +*/ +int iecm_ctlq_send (struct iecm_hw *hw,struct iecm_ctlq_info *cq, +u16 num_q_msg,struct iecm_ctlq_msg q_msg[]) +{ +struct iecm_ctlq_desc *desc; +int num_desc_avail =0 ; +int status =0 ; +int i =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ; + +mutex_lock (&cq->cq_lock); + +/* Ensure there are enough descriptors to send all messages */ + num_desc_avail =IECM_CTLQ_DESC_UNUSED (cq); +if (num_desc_avail ==0 || num_desc_avail < num_q_msg) { + status = -ENOSPC ; + goto sq_send_command_out; + } + +for (i =0 ; i < num_q_msg; i++) { +struct iecm_ctlq_msg *msg = &q_msg[i]; +u64 msg_cookie; + + desc =IECM_CTLQ_DESC (cq, cq->next_to_use); + + desc->opcode =cpu_to_le16 (msg->opcode); + desc->pfid_vfid =cpu_to_le16 (msg->func_id); + + msg_cookie = *(u64 *)&msg->cookie; + desc->cookie_high = +cpu_to_le32 (upper_32_bits (msg_cookie)); + desc->cookie_low = +cpu_to_le32 (lower_32_bits (msg_cookie)); + +if (msg->data_len) { +struct iecm_dma_mem *buff = msg->ctx.indirect.payload; + + desc->datalen =cpu_to_le16 (msg->data_len); + desc->flags |=cpu_to_le16 (IECM_CTLQ_FLAG_BUF ); + desc->flags |=cpu_to_le16 (IECM_CTLQ_FLAG_RD ); + +/* Update the address values in the desc with the pa +* value for respective buffer +*/ + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (buff->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (buff->pa)); + +memcpy (&desc->params, msg->ctx.indirect.context, +IECM_INDIRECT_CTX_SIZE ); + }else { +memcpy (&desc->params, msg->ctx.direct, +IECM_DIRECT_CTX_SIZE ); + } + +/* Store buffer info */ + cq->bi.tx_msg[cq->next_to_use] = msg; + + (cq->next_to_use)++; +if (cq->next_to_use == cq->ring_size) + cq->next_to_use =0 ; + } + +/* Force memory write to complete before letting hardware +* know that there are new descriptors to fetch. +*/ +dma_wmb (); + +wr32 (hw, cq->reg.tail, cq->next_to_use); + +sq_send_command_out: +mutex_unlock (&cq->cq_lock);
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 359
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ +return status; +} + +/** +* iecm_ctlq_clean_sq - reclaim send descriptors on HW write back for the +* requested queue +* @cq: pointer to the specific Control queue +* @clean_count: (input|output) number of descriptors to clean as input, and +* number of descriptors actually cleaned as output
Rather than two meanings for one parameter, can the number cleaned be a positive return value?
Quoted 32 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +32
-0+* @msg_status: (output) pointer to msg pointer array to be populated; needs +* to be allocated by caller +* +* Returns an array of message pointers associated with the cleaned +* descriptors. The pointers are to the original ctlq_msgs sent on the cleaned +* descriptors. The status will be returned for each; any messages that failed +* to send will have a non-zero status. The caller is expected to free original +* ctlq_msgs and free or reuse the DMA buffers. +*/ +int iecm_ctlq_clean_sq (struct iecm_ctlq_info *cq,u16 *clean_count, +struct iecm_ctlq_msg *msg_status[]) +{ +struct iecm_ctlq_desc *desc; +u16 i =0 , num_to_clean; +u16 ntc, desc_err; +int ret =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ; + +if (*clean_count ==0 ) +return 0 ; +if (*clean_count > cq->ring_size) +return -EBADR ; + +mutex_lock (&cq->cq_lock); + + ntc = cq->next_to_clean; + + num_to_clean = *clean_count; + +for (i =0 ; i < num_to_clean; i++) {
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 401
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+/* Fetch next descriptor and check if marked as done */ + desc =IECM_CTLQ_DESC (cq, ntc); +if (!(le16_to_cpu (desc->flags) &IECM_CTLQ_FLAG_DD )) +break ; + + desc_err =le16_to_cpu (desc->ret_val); +if (desc_err) { +/* strip off FW internal code */ + desc_err &=0xff ; + }
Why not simply
desc_err = le16_to_cpu(desc->ret_val) & 0xff;
Quoted 20 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +20
-0+ + msg_status[i] = cq->bi.tx_msg[ntc]; + msg_status[i]->status = desc_err; + + cq->bi.tx_msg[ntc] =NULL ; + +/* Zero out any stale data */ +memset (desc,0 ,sizeof (*desc)); + + ntc++; +if (ntc == cq->ring_size) + ntc =0 ; + } + + cq->next_to_clean = ntc; + +mutex_unlock (&cq->cq_lock); + +/* Return number of descriptors actually cleaned */ + *clean_count = i;
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 431
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ +return ret; +} + +/** +* iecm_ctlq_post_rx_buffs - post buffers to descriptor ring +* @hw: pointer to hw struct +* @cq: pointer to control queue handle +* @buff_count: (input|output) input is number of buffers caller is trying to +* return; output is number of buffers that were not posted
Same comment.
And the return would make more sense if consistent with the previous function where the return is how many were successful.
Quoted 131 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +131
-0+* @buffs: array of pointers to dma mem structs to be given to hardware +* +* Caller uses this function to return DMA buffers to the descriptor ring after +* consuming them; buff_count will be the number of buffers. +* +* Note: this function needs to be called after a receive call even +* if there are no DMA buffers to be returned, i.e. buff_count = 0, +* buffs = NULL to support direct commands +*/ +int iecm_ctlq_post_rx_buffs (struct iecm_hw *hw,struct iecm_ctlq_info *cq, +u16 *buff_count,struct iecm_dma_mem **buffs) +{ +struct iecm_ctlq_desc *desc; +u16 ntp = cq->next_to_post; +bool buffs_avail = false; +u16 tbp = ntp +1 ; +int status =0 ; +int i =0 ; + +if (*buff_count > cq->ring_size) +return -EBADR ; + +if (*buff_count >0 ) + buffs_avail = true; + +mutex_lock (&cq->cq_lock); + +if (tbp >= cq->ring_size) + tbp =0 ; + +if (tbp == cq->next_to_clean) +/* Nothing to do */ + goto post_buffs_out; + +/* Post buffers for as many as provided or up until the last one used */ +while (ntp != cq->next_to_clean) { + desc =IECM_CTLQ_DESC (cq, ntp); + +if (cq->bi.rx_buff[ntp]) + goto fill_desc; +if (!buffs_avail) { +/* If the caller hasn't given us any buffers or +* there are none left, search the ring itself +* for an available buffer to move to this +* entry starting at the next entry in the ring +*/ + tbp = ntp +1 ; + +/* Wrap ring if necessary */ +if (tbp >= cq->ring_size) + tbp =0 ; + +while (tbp != cq->next_to_clean) { +if (cq->bi.rx_buff[tbp]) { + cq->bi.rx_buff[ntp] = + cq->bi.rx_buff[tbp]; + cq->bi.rx_buff[tbp] =NULL ; + +/* Found a buffer, no need to +* search anymore +*/ +break ; + } + +/* Wrap ring if necessary */ + tbp++; +if (tbp >= cq->ring_size) + tbp =0 ; + } + +if (tbp == cq->next_to_clean) + goto post_buffs_out; + }else { +/* Give back pointer to DMA buffer */ + cq->bi.rx_buff[ntp] = buffs[i]; + i++; + +if (i >= *buff_count) + buffs_avail = false; + } + +fill_desc: + desc->flags = +cpu_to_le16 (IECM_CTLQ_FLAG_BUF |IECM_CTLQ_FLAG_RD ); + +/* Post buffers to descriptor */ + desc->datalen =cpu_to_le16 (cq->bi.rx_buff[ntp]->size); + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (cq->bi.rx_buff[ntp]->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (cq->bi.rx_buff[ntp]->pa)); + + ntp++; +if (ntp == cq->ring_size) + ntp =0 ; + } + +post_buffs_out: +/* Only update tail if buffers were actually posted */ +if (cq->next_to_post != ntp) { +if (ntp) +/* Update next_to_post to ntp - 1 since current ntp +* will not have a buffer +*/ + cq->next_to_post = ntp -1 ; +else +/* Wrap to end of end ring since current ntp is 0 */ + cq->next_to_post = cq->ring_size -1 ; + +wr32 (hw, cq->reg.tail, cq->next_to_post); + } + +mutex_unlock (&cq->cq_lock); + +/* return the number of buffers that were not posted */ + *buff_count = *buff_count - i; + +return status; +} + +/** +* iecm_ctlq_recv - receive control queue message call back +* @cq: pointer to control queue handle to receive on +* @num_q_msg: (input|output) input number of messages that should be received; +* output number of messages actually received +* @q_msg: (output) array of received control queue messages on this q; +* needs to be pre-allocated by caller for as many messages as requested +* +* Called by interrupt handler or polling mechanism. Caller is expected +* to free buffers +*/
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 572
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+int iecm_ctlq_recv (struct iecm_ctlq_info *cq,u16 *num_q_msg, +struct iecm_ctlq_msg *q_msg) +{ +u16 num_to_clean, ntc, ret_val, flags; +struct iecm_ctlq_desc *desc; +int ret_code =0 ; +u16 i =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ;
Should *num_q_msgs get set to 0 here since none were received?
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 577
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +5
-0+ +if (*num_q_msg ==0 ) +return 0 ; +else if (*num_q_msg > cq->ring_size) +return -EBADR ;
Again, set *num_q_msgs to 0?
Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +17
-0+ +/* take the lock before we start messing with the ring */ +mutex_lock (&cq->cq_lock); + + ntc = cq->next_to_clean; + + num_to_clean = *num_q_msg; + +for (i =0 ; i < num_to_clean; i++) { +u64 msg_cookie; + +/* Fetch next descriptor and check if marked as done */ + desc =IECM_CTLQ_DESC (cq, ntc); + flags =le16_to_cpu (desc->flags); + +if (!(flags &IECM_CTLQ_FLAG_DD )) +break ;
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 604
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ + ret_val =le16_to_cpu (desc->ret_val); + + q_msg[i].vmvf_type = (flags & + (IECM_CTLQ_FLAG_FTYPE_VM | +IECM_CTLQ_FLAG_FTYPE_PF )) >> +IECM_CTLQ_FLAG_FTYPE_S ; + +if (flags &IECM_CTLQ_FLAG_ERR ) + ret_code = -EBADMSG ;
So you might return -EBADMSG, even if you've cleaned many messages? Will this be reflected in ret_val and does the caller then need to hunt down the bad q_msg[].status?
How these work together should probably be clearly explained in the function header.
Quoted 1,119 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +45
-0+ + msg_cookie = (u64 )le32_to_cpu (desc->cookie_high) <<32 ; + msg_cookie |= (u64 )le32_to_cpu (desc->cookie_low); +memcpy (&q_msg[i].cookie, &msg_cookie,sizeof (u64)); + + q_msg[i].opcode =le16_to_cpu (desc->opcode); + q_msg[i].data_len =le16_to_cpu (desc->datalen); + q_msg[i].status = ret_val; + +if (desc->datalen) { +memcpy (q_msg[i].ctx.indirect.context, + &desc->params.indirect,IECM_INDIRECT_CTX_SIZE ); + +/* Assign pointer to dma buffer to ctlq_msg array +* to be given to upper layer +*/ + q_msg[i].ctx.indirect.payload = cq->bi.rx_buff[ntc]; + +/* Zero out pointer to DMA buffer info; +* will be repopulated by post buffers API +*/ + cq->bi.rx_buff[ntc] =NULL ; + }else { +memcpy (q_msg[i].ctx.direct, desc->params.raw, +IECM_DIRECT_CTX_SIZE ); + } + +/* Zero out stale data in descriptor */ +memset (desc,0 ,sizeof (struct iecm_ctlq_desc )); + + ntc++; +if (ntc == cq->ring_size) + ntc =0 ; + }; + + cq->next_to_clean = ntc; + +mutex_unlock (&cq->cq_lock); + + *num_q_msg = i; +if (*num_q_msg ==0 ) + ret_code = -ENOMSG ; + +return ret_code; +}drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +175
-0@@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2020, Intel Corporation. */ + +#include "iecm_controlq.h" + +/** +* iecm_ctlq_alloc_desc_ring - Allocate Control Queue (CQ) rings +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +*/ +static int +iecm_ctlq_alloc_desc_ring (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{ +size_t size = cq->ring_size *sizeof (struct iecm_ctlq_desc ); + + cq->desc_ring.va =iecm_alloc_dma_mem (hw, &cq->desc_ring, size); +if (!cq->desc_ring.va) +return -ENOMEM ; + +return 0 ; +} + +/** +* iecm_ctlq_alloc_bufs - Allocate Control Queue (CQ) buffers +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Allocate the buffer head for all control queues, and if it's a receive +* queue, allocate DMA buffers +*/ +static int iecm_ctlq_alloc_bufs (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{ +int i =0 ; + +/* Do not allocate DMA buffers for transmit queues */ +if (cq->cq_type ==IECM_CTLQ_TYPE_MAILBOX_TX ) +return 0 ; + +/* We'll be allocating the buffer info memory first, then we can +* allocate the mapped buffers for the event processing +*/ + cq->bi.rx_buff =kcalloc (cq->ring_size,sizeof (struct iecm_dma_mem *), +GFP_KERNEL ); +if (!cq->bi.rx_buff) +return -ENOMEM ; + +/* allocate the mapped buffers (except for the last one) */ +for (i =0 ; i < cq->ring_size -1 ; i++) { +struct iecm_dma_mem *bi; +int num =1 ;/* number of iecm_dma_mem to be allocated */ + + cq->bi.rx_buff[i] =kcalloc (num,sizeof (struct iecm_dma_mem ), +GFP_KERNEL ); +if (!cq->bi.rx_buff[i]) + goto unwind_alloc_cq_bufs; + + bi = cq->bi.rx_buff[i]; + + bi->va =iecm_alloc_dma_mem (hw, bi, cq->buf_size); +if (!bi->va) { +/* unwind will not free the failed entry */ +kfree (cq->bi.rx_buff[i]); + goto unwind_alloc_cq_bufs; + } + } + +return 0 ; + +unwind_alloc_cq_bufs: +/* don't try to free the one that failed... */ + i--; +for (; i >=0 ; i--) { +iecm_free_dma_mem (hw, cq->bi.rx_buff[i]); +kfree (cq->bi.rx_buff[i]); + } +kfree (cq->bi.rx_buff); + +return -ENOMEM ; +} + +/** +* iecm_ctlq_free_desc_ring - Free Control Queue (CQ) rings +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* This assumes the posted send buffers have already been cleaned +* and de-allocated +*/ +static void iecm_ctlq_free_desc_ring (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{ +iecm_free_dma_mem (hw, &cq->desc_ring); +} + +/** +* iecm_ctlq_free_bufs - Free CQ buffer info elements +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Free the DMA buffers for RX queues, and DMA buffer header for both RX and TX +* queues. The upper layers are expected to manage freeing of TX DMA buffers +*/ +static void iecm_ctlq_free_bufs (struct iecm_hw *hw,struct iecm_ctlq_info *cq) +{ +void *bi; + +if (cq->cq_type ==IECM_CTLQ_TYPE_MAILBOX_RX ) { +int i; + +/* free DMA buffers for rx queues*/ +for (i =0 ; i < cq->ring_size; i++) { +if (cq->bi.rx_buff[i]) { +iecm_free_dma_mem (hw, cq->bi.rx_buff[i]); +kfree (cq->bi.rx_buff[i]); + } + } + + bi = (void *)cq->bi.rx_buff; + }else { + bi = (void *)cq->bi.tx_msg; + } + +/* free the buffer header */ +kfree (bi); +} + +/** +* iecm_ctlq_dealloc_ring_res - Free memory allocated for control queue +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Free the memory used by the ring, buffers and other related structures +*/ +void iecm_ctlq_dealloc_ring_res (struct iecm_hw *hw,struct iecm_ctlq_info *cq) +{ +/* free ring buffers and the ring itself */ +iecm_ctlq_free_bufs (hw, cq); +iecm_ctlq_free_desc_ring (hw, cq); +} + +/** +* iecm_ctlq_alloc_ring_res - allocate memory for descriptor ring and bufs +* @hw: pointer to hw struct +* @cq: pointer to control queue struct +* +* Do *NOT* hold the lock when calling this as the memory allocation routines +* called are not going to be atomic context safe +*/ +int iecm_ctlq_alloc_ring_res (struct iecm_hw *hw,struct iecm_ctlq_info *cq) +{ +int ret_code; + +/* verify input for valid configuration */ +if (!cq->ring_size || !cq->buf_size) +return -EINVAL ; + +/* allocate the ring memory */ + ret_code =iecm_ctlq_alloc_desc_ring (hw, cq); +if (ret_code) +return ret_code; + +/* allocate buffers in the rings */ + ret_code =iecm_ctlq_alloc_bufs (hw, cq); +if (ret_code) + goto iecm_init_cq_free_ring; + +/* success! */ +return 0 ; + +iecm_init_cq_free_ring: +iecm_free_dma_mem (hw, &cq->desc_ring); +return ret_code; +}drivers/net/ethernet/intel/iecm/iecm_lib.c +190
-1@@ -5,6 +5,25 @@#include "iecm.h" +/** +* iecm_cfg_hw - Initialize HW struct +* @adapter: adapter to setup hw struct for +* +* Returns 0 on success, negative on failure +*/ +static int iecm_cfg_hw (struct iecm_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct iecm_hw *hw = &adapter->hw; + + hw->hw_addr =pcim_iomap_table (pdev)[IECM_BAR0 ]; +if (!hw->hw_addr) +return -EIO ; + hw->back = adapter; + +return 0 ; +} +/** * iecm_statistics_task - Delayed task to get statistics over mailbox * @work: work_struct handle to our data @@ -39,6 +58,32 @@ static void iecm_init_task(struct work_struct *work)/* stub */ } +/** +* iecm_api_init - Initialize and verify device API +* @adapter: driver specific private structure +* +* Returns 0 on success, negative on failure +*/ +static int iecm_api_init (struct iecm_adapter *adapter) +{ +struct iecm_reg_ops *reg_ops = &adapter->dev_ops.reg_ops; +struct pci_dev *pdev = adapter->pdev; + +if (!adapter->dev_ops.reg_ops_init) { +dev_err (&pdev->dev,"Invalid device, register API init not defined\n" ); +return -EINVAL ; + } + adapter->dev_ops.reg_ops_init (adapter); +if (!(reg_ops->ctlq_reg_init && reg_ops->intr_reg_init && + reg_ops->mb_intr_reg_init && reg_ops->reset_reg_init && + reg_ops->trigger_reset)) { +dev_err (&pdev->dev,"Invalid device, missing one or more register functions\n" ); +return -EINVAL ; + } + +return 0 ; +} +/** * iecm_deinit_task - Device deinit routine * @adapter: Driver specific private structue @@ -51,13 +96,108 @@ static void iecm_deinit_task(struct iecm_adapter *adapter)/* stub */ } +/** +* iecm_check_reset_complete - check that reset is complete +* @hw: pointer to hw struct +* @reset_reg: struct with reset registers +* +* Returns 0 if device is ready to use, or -EBUSY if it's in reset. +**/ +static int iecm_check_reset_complete (struct iecm_hw *hw, +struct iecm_reset_reg *reset_reg) +{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; +int i; + +for (i =0 ; i <2000 ; i++) { +u32 reg_val =rd32 (hw, reset_reg->rstat); + +/* 0xFFFFFFFF might be read if other side hasn't cleared the +* register for us yet and 0xFFFFFFFF is not a valid value for +* the register, so treat that as invalid. +*/ +if (reg_val !=0xFFFFFFFF && (reg_val & reset_reg->rstat_m)) +return 0 ; +usleep_range (5000 ,10000 ); + } + +dev_warn (&adapter->pdev->dev,"Device reset timeout!\n" ); +return -EBUSY ; +} + +/** +* iecm_init_hard_reset - Initiate a hardware reset +* @adapter: Driver specific private structure +* +* Deallocate the vports and all the resources associated with them and +* reallocate. Also reinitialize the mailbox. Return 0 on success, +* negative on failure. +*/ +static int iecm_init_hard_reset (struct iecm_adapter *adapter) +{ +int err =0 ; + +mutex_lock (&adapter->reset_lock); + +/* Prepare for reset */ +if (test_and_clear_bit (__IECM_HR_DRV_LOAD, adapter->flags)) { + adapter->dev_ops.reg_ops.trigger_reset (adapter, + __IECM_HR_DRV_LOAD); + }else if (test_and_clear_bit (__IECM_HR_FUNC_RESET, adapter->flags)) { +bool is_reset =iecm_is_reset_detected (adapter); + +if (adapter->state == __IECM_UP) +set_bit (__IECM_UP_REQUESTED, adapter->flags); +iecm_deinit_task (adapter); +if (!is_reset) + adapter->dev_ops.reg_ops.trigger_reset (adapter, + __IECM_HR_FUNC_RESET); +iecm_deinit_dflt_mbx (adapter); + }else if (test_and_clear_bit (__IECM_HR_CORE_RESET, adapter->flags)) { +if (adapter->state == __IECM_UP) +set_bit (__IECM_UP_REQUESTED, adapter->flags); +iecm_deinit_task (adapter); + }else { +dev_err (&adapter->pdev->dev,"Unhandled hard reset cause\n" ); + err = -EBADRQC ; + goto handle_err; + } + +/* Wait for reset to complete */ + err =iecm_check_reset_complete (&adapter->hw, &adapter->reset_reg); +if (err) { +dev_err (&adapter->pdev->dev,"The driver was unable to contact the device's firmware. Check that the FW is running. Driver state=%u\n" , + adapter->state); + goto handle_err; + } + +/* Reset is complete and so start building the driver resources again */ + err =iecm_init_dflt_mbx (adapter); +if (err) { +dev_err (&adapter->pdev->dev,"Failed to initialize default mailbox: %d\n" , + err); + } +handle_err: +mutex_unlock (&adapter->reset_lock); +return err; +} +/** * iecm_vc_event_task - Handle virtchannel event logic * @work: work queue struct */ static void iecm_vc_event_task (struct work_struct *work) { -/* stub */ +struct iecm_adapter *adapter =container_of (work, + struct iecm_adapter, + vc_event_task.work); + +if (test_bit (__IECM_HR_CORE_RESET, adapter->flags) || +test_bit (__IECM_HR_FUNC_RESET, adapter->flags) || +test_bit (__IECM_HR_DRV_LOAD, adapter->flags)) { +set_bit (__IECM_HR_RESET_IN_PROG, adapter->flags); +iecm_init_hard_reset (adapter); + } }/** @@ -75,6 +215,11 @@ int iecm_probe(struct pci_dev *pdev,int err; adapter->pdev = pdev; + err =iecm_api_init (adapter); +if (err) { +dev_err (&pdev->dev,"Device API is incorrectly configured\n" ); +return err; + } err =pcim_enable_device (pdev);if (err)@@ -147,6 +292,20 @@ int iecm_probe(struct pci_dev *pdev, goto err_netdev_alloc; } + err =iecm_vport_params_buf_alloc (adapter); +if (err) { +dev_err (&pdev->dev,"Failed to alloc vport params buffer: %d\n" , + err); + goto err_mb_res; + } + + err =iecm_cfg_hw (adapter); +if (err) { +dev_err (&pdev->dev,"Failed to configure HW structure for adapter: %d\n" , + err); + goto err_cfg_hw; + } +mutex_init (&adapter->sw_mutex);mutex_init (&adapter->reset_lock);init_waitqueue_head (&adapter->vchnl_wq);@@ -166,11 +325,16 @@ int iecm_probe(struct pci_dev *pdev,INIT_DELAYED_WORK (&adapter->init_task, iecm_init_task);INIT_DELAYED_WORK (&adapter->vc_event_task, iecm_vc_event_task); + adapter->dev_ops.reg_ops.reset_reg_init (&adapter->reset_reg);set_bit (__IECM_HR_DRV_LOAD, adapter->flags);queue_delayed_work (adapter->vc_event_wq, &adapter->vc_event_task,msecs_to_jiffies (10 * (pdev->devfn &0x07 )));return 0 ; +err_cfg_hw: +iecm_vport_params_buf_rel (adapter); +err_mb_res: +kfree (adapter->netdevs); err_netdev_alloc:kfree (adapter->vports); err_vport_alloc:@@ -214,6 +378,7 @@ void iecm_remove(struct pci_dev *pdev)cancel_delayed_work_sync (&adapter->vc_event_task);iecm_deinit_task (adapter);iecm_del_user_cfg_data (adapter); +iecm_deinit_dflt_mbx (adapter);msleep (20 );destroy_workqueue (adapter->serv_wq);destroy_workqueue (adapter->vc_event_wq);@@ -222,6 +387,7 @@ void iecm_remove(struct pci_dev *pdev)kfree (adapter->vports);kfree (adapter->netdevs);kfree (adapter->vlan_caps); +iecm_vport_params_buf_rel (adapter);mutex_destroy (&adapter->sw_mutex);mutex_destroy (&adapter->reset_lock);pci_disable_pcie_error_reporting (pdev);@@ -229,3 +395,26 @@ void iecm_remove(struct pci_dev *pdev)pci_disable_device (pdev); }EXPORT_SYMBOL (iecm_remove); + +void *iecm_alloc_dma_mem (struct iecm_hw *hw,struct iecm_dma_mem *mem,u64 size) +{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; +size_t sz =ALIGN (size,4096 ); + + mem->va =dma_alloc_coherent (&adapter->pdev->dev, sz, + &mem->pa,GFP_KERNEL | __GFP_ZERO); + mem->size = size; + +return mem->va; +} + +void iecm_free_dma_mem (struct iecm_hw *hw,struct iecm_dma_mem *mem) +{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; + +dma_free_coherent (&adapter->pdev->dev, mem->size, + mem->va, mem->pa); + mem->size =0 ; + mem->va =NULL ; + mem->pa =0 ; +}drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +172
-0@@ -0,0 +1,172 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#include "iecm.h" + +/** +* iecm_mb_clean - Reclaim the send mailbox queue entries +* @adapter: Driver specific private structure +* +* Reclaim the send mailbox queue entries to be used to send further messages +* +* Returns 0 on success, negative on failure +*/ +static int iecm_mb_clean (struct iecm_adapter *adapter) +{ +u16 i, num_q_msg =IECM_DFLT_MBX_Q_LEN ; +struct iecm_ctlq_msg **q_msg; +struct iecm_dma_mem *dma_mem; +int err =0 ; + + q_msg =kcalloc (num_q_msg,sizeof (struct iecm_ctlq_msg *),GFP_KERNEL ); +if (!q_msg) +return -ENOMEM ; + + err =iecm_ctlq_clean_sq (adapter->hw.asq, &num_q_msg, q_msg); +if (err) + goto error; + +for (i =0 ; i < num_q_msg; i++) { + dma_mem = q_msg[i]->ctx.indirect.payload; +if (dma_mem) +dmam_free_coherent (&adapter->pdev->dev, dma_mem->size, + dma_mem->va, dma_mem->pa); +kfree (q_msg[i]); +kfree (dma_mem); + } +error: +kfree (q_msg); +return err; +} + +/** +* iecm_find_ctlq - Given a type and id, find ctlq info +* @hw: hardware struct +* @type: type of ctrlq to find +* @id: ctlq id to find +* +* Returns pointer to found ctlq info struct, NULL otherwise. +*/ +static struct iecm_ctlq_info *iecm_find_ctlq (struct iecm_hw *hw, +enum iecm_ctlq_type type,int id) +{ +struct iecm_ctlq_info *cq, *tmp; + +list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) { +if (cq->q_id == id && cq->cq_type == type) +return cq; + } + +return NULL ; +} + +/** +* iecm_init_dflt_mbx - Setup default mailbox parameters and make request +* @adapter: adapter info struct +* +* Returns 0 on success, negative otherwise +*/ +int iecm_init_dflt_mbx (struct iecm_adapter *adapter) +{ +struct iecm_ctlq_create_info ctlq_info[] = { + { + .type =IECM_CTLQ_TYPE_MAILBOX_TX , + .id =IECM_DFLT_MBX_ID , + .len =IECM_DFLT_MBX_Q_LEN , + .buf_size =IECM_DFLT_MBX_BUF_SIZE + }, + { + .type =IECM_CTLQ_TYPE_MAILBOX_RX , + .id =IECM_DFLT_MBX_ID , + .len =IECM_DFLT_MBX_Q_LEN , + .buf_size =IECM_DFLT_MBX_BUF_SIZE + } + }; +struct iecm_hw *hw = &adapter->hw; +int err; + + adapter->dev_ops.reg_ops.ctlq_reg_init (ctlq_info); + +#define NUM_Q 2 + err =iecm_ctlq_init (hw,NUM_Q , ctlq_info); +if (err) +return err; + + hw->asq =iecm_find_ctlq (hw,IECM_CTLQ_TYPE_MAILBOX_TX , +IECM_DFLT_MBX_ID ); + hw->arq =iecm_find_ctlq (hw,IECM_CTLQ_TYPE_MAILBOX_RX , +IECM_DFLT_MBX_ID ); + +if (!hw->asq || !hw->arq) { +iecm_ctlq_deinit (hw); +return -ENOENT ; + } + adapter->state = __IECM_STARTUP; +/* Skew the delay for init tasks for each function based on fn number +* to prevent every function from making the same call simulatenously. +*/ +queue_delayed_work (adapter->init_wq, &adapter->init_task, +msecs_to_jiffies (5 * (adapter->pdev->devfn &0x07 ))); +return 0 ; +} + +/** +* iecm_deinit_dflt_mbx - Free up ctlqs setup +* @adapter: Driver specific private data structure +*/ +void iecm_deinit_dflt_mbx (struct iecm_adapter *adapter) +{ +if (adapter->hw.arq && adapter->hw.asq) { +iecm_mb_clean (adapter); +iecm_ctlq_deinit (&adapter->hw); + } + adapter->hw.arq =NULL ; + adapter->hw.asq =NULL ; +} + +/** +* iecm_vport_params_buf_alloc - Allocate memory for MailBox resources +* @adapter: Driver specific private data structure +* +* Will alloc memory to hold the vport parameters received on MailBox +*/ +int iecm_vport_params_buf_alloc (struct iecm_adapter *adapter) +{ + adapter->vport_params_reqd =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (*adapter->vport_params_reqd), +GFP_KERNEL ); +if (!adapter->vport_params_reqd) +return -ENOMEM ; + + adapter->vport_params_recvd =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (*adapter->vport_params_recvd), +GFP_KERNEL ); +if (!adapter->vport_params_recvd) { +kfree (adapter->vport_params_reqd); +return -ENOMEM ; + } + +return 0 ; +} + +/** +* iecm_vport_params_buf_rel - Release memory for MailBox resources +* @adapter: Driver specific private data structure +* +* Will release memory to hold the vport parameters received on MailBox +*/ +void iecm_vport_params_buf_rel (struct iecm_adapter *adapter) +{ +int i =0 ; + +for (i =0 ; i <IECM_MAX_NUM_VPORTS ; i++) { +kfree (adapter->vport_params_recvd[i]); +kfree (adapter->vport_params_reqd[i]); + } + +kfree (adapter->vport_params_recvd); +kfree (adapter->vport_params_reqd); + +kfree (adapter->caps); +kfree (adapter->config_data.req_qs_chunks); +}drivers/net/ethernet/intel/include/iecm.h +52
-0@@ -12,15 +12,33 @@#include <linux/dim.h> #include "iecm_txrx.h" +#include "iecm_controlq.h" #define IECM_BAR0 0#define IECM_NO_FREE_SLOT 0xffff +/* Default Mailbox settings */ +#define IECM_DFLT_MBX_BUF_SIZE (4 * 1024) +#define IECM_NUM_QCTX_PER_MSG 3 +#define IECM_NUM_FILTERS_PER_MSG 20 +#define IECM_VLANS_PER_MSG \ + ((IECM_DFLT_MBX_BUF_SIZE - sizeof(struct virtchnl_vlan_filter_list)) \ + / sizeof(u16)) +#define IECM_DFLT_MBX_Q_LEN 64 +#define IECM_DFLT_MBX_ID -1 +/* maximum number of times to try before resetting mailbox */ +#define IECM_MB_MAX_ERR 20 +#define IECM_NUM_CHUNKS_PER_MSG (a, b) ((IECM_DFLT_MBX_BUF_SIZE - (a)) / (b)) +#define IECM_MAX_NUM_VPORTS 1/* available message levels */ #define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK) +/* Forward declaration */ +struct iecm_adapter ; +struct iecm_vport ; +enum iecm_state { __IECM_STARTUP, __IECM_VER_CHECK,@@ -77,6 +95,22 @@ struct iecm_reset_reg {u32 rstat_m; }; +/* product specific register API */ +struct iecm_reg_ops { +void (*ctlq_reg_init)(struct iecm_ctlq_create_info *cq); +int (*intr_reg_init)(struct iecm_vport *vport); +void (*mb_intr_reg_init)(struct iecm_adapter *adapter); +void (*reset_reg_init)(struct iecm_reset_reg *reset_reg); +void (*trigger_reset)(struct iecm_adapter *adapter, +enum iecm_flags trig_cause); +}; + +struct iecm_dev_ops { +void (*reg_ops_init)(struct iecm_adapter *adapter); +void (*crc_enable)(u64 *td_cmd); +struct iecm_reg_ops reg_ops; +}; +/* stub */ struct iecm_vport { };@@ -124,6 +158,7 @@ struct iecm_adapter {DECLARE_BITMAP (flags, __IECM_FLAGS_NBITS);struct mutex reset_lock;/* lock to protect reset flows */ struct iecm_reset_reg reset_reg; +struct iecm_hw hw;u16 num_req_msix;u16 num_msix_entries;@@ -156,6 +191,7 @@ struct iecm_adapter {wait_queue_head_t vchnl_wq;wait_queue_head_t sw_marker_wq;struct iecm_rss_data rss_data; +struct iecm_dev_ops dev_ops;s32 link_speed;/* This is only populated if the VIRTCHNL_VF_CAP_ADV_LINK_SPEED is set * in vf_res->vf_cap_flags. This field should be used going forward and @@ -179,8 +215,24 @@ struct iecm_adapter { spinlock_t fdir_fltr_list_lock; }; +/** +* iecm_is_reset_detected - check if we were reset at some point +* @adapter: driver specific private structure +* +* Returns true if we are either in reset currently or were previously reset. +*/ +static inline bool iecm_is_reset_detected (struct iecm_adapter *adapter) +{ +return !(rd32 (&adapter->hw, adapter->hw.arq->reg.len) & + adapter->hw.arq->reg.len_ena_mask); +} +int iecm_probe (struct pci_dev *pdev,const struct pci_device_id __always_unused *ent,struct iecm_adapter *adapter);void iecm_remove (struct pci_dev *pdev); +int iecm_init_dflt_mbx (struct iecm_adapter *adapter); +void iecm_deinit_dflt_mbx (struct iecm_adapter *adapter); +int iecm_vport_params_buf_alloc (struct iecm_adapter *adapter); +void iecm_vport_params_buf_rel (struct iecm_adapter *adapter);#endif /* !_IECM_H_ */ drivers/net/ethernet/intel/include/iecm_controlq.h new file +117
-0@@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020, Intel Corporation. */ + +#ifndef _IECM_CONTROLQ_H_ +#define _IECM_CONTROLQ_H_ + +#include <linux/slab.h> + +#include "iecm_controlq_api.h" + +/* Maximum buffer lengths for all control queue types */ +#define IECM_CTLQ_MAX_RING_SIZE 1024 +#define IECM_CTLQ_MAX_BUF_LEN 4096 + +#define IECM_CTLQ_DESC (R , i) \ + (&(((struct iecm_ctlq_desc *)((R)->desc_ring.va))[i])) + +#define IECM_CTLQ_DESC_UNUSED (R ) \ + ((u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->ring_size) + \ + (R)->next_to_clean - (R)->next_to_use - 1)) + +/* Control Queue default settings */ +#define IECM_CTRL_SQ_CMD_TIMEOUT 250/* msecs */ + +struct iecm_ctlq_desc { +__le16 flags; +__le16 opcode; +__le16 datalen;/* 0 for direct commands */ +union { +__le16 ret_val; +__le16 pfid_vfid; +#define IECM_CTLQ_DESC_VF_ID_S 0 +#define IECM_CTLQ_DESC_VF_ID_M (0x7FF << IECM_CTLQ_DESC_VF_ID_S) +#define IECM_CTLQ_DESC_PF_ID_S 11 +#define IECM_CTLQ_DESC_PF_ID_M (0x1F << IECM_CTLQ_DESC_PF_ID_S) + }; +__le32 cookie_high; +__le32 cookie_low; +union { +struct { +__le32 param0; +__le32 param1; +__le32 param2; +__le32 param3; + } direct; +struct { +__le32 param0; +__le32 param1; +__le32 addr_high; +__le32 addr_low; + } indirect; +u8 raw[16 ]; + } params; +}; + +/* Flags sub-structure +* |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |10 |11 |12 |13 |14 |15 | +* |DD |CMP|ERR| * RSV * |FTYPE | *RSV* |RD |VFC|BUF| * RSV * | +*/ +/* command flags and offsets */ +#define IECM_CTLQ_FLAG_DD_S 0 +#define IECM_CTLQ_FLAG_CMP_S 1 +#define IECM_CTLQ_FLAG_ERR_S 2 +#define IECM_CTLQ_FLAG_FTYPE_S 6 +#define IECM_CTLQ_FLAG_RD_S 10 +#define IECM_CTLQ_FLAG_VFC_S 11 +#define IECM_CTLQ_FLAG_BUF_S 12 + +#define IECM_CTLQ_FLAG_DD BIT(IECM_CTLQ_FLAG_DD_S)/* 0x1 */ +#define IECM_CTLQ_FLAG_CMP BIT(IECM_CTLQ_FLAG_CMP_S)/* 0x2 */ +#define IECM_CTLQ_FLAG_ERR BIT(IECM_CTLQ_FLAG_ERR_S)/* 0x4 */ +#define IECM_CTLQ_FLAG_FTYPE_VM BIT(IECM_CTLQ_FLAG_FTYPE_S)/* 0x40 */ +#define IECM_CTLQ_FLAG_FTYPE_PF BIT(IECM_CTLQ_FLAG_FTYPE_S + 1)/* 0x80 */ +#define IECM_CTLQ_FLAG_RD BIT(IECM_CTLQ_FLAG_RD_S)/* 0x400 */ +#define IECM_CTLQ_FLAG_VFC BIT(IECM_CTLQ_FLAG_VFC_S)/* 0x800 */ +#define IECM_CTLQ_FLAG_BUF BIT(IECM_CTLQ_FLAG_BUF_S)/* 0x1000 */ + +struct iecm_mbxq_desc { +u8 pad[8 ];/* CTLQ flags/opcode/len/retval fields */ +u32 chnl_opcode;/* avoid confusion with desc->opcode */ +u32 chnl_retval;/* ditto for desc->retval */ +u32 pf_vf_id;/* used by CP when sending to PF */ +}; + +/* Define the APF hardware struct to replace other control structs as needed +* Align to ctlq_hw_info +*/ +struct iecm_hw { +u8 __iomem *hw_addr; +u64 hw_addr_len; +void *back; + +/* control queue - send and receive */ +struct iecm_ctlq_info *asq; +struct iecm_ctlq_info *arq; + +/* pci info */ +u16 device_id; +u16 vendor_id; +u16 subsystem_device_id; +u16 subsystem_vendor_id; +u8 revision_id; +bool adapter_stopped; + +struct list_head cq_list_head; +}; + +int iecm_ctlq_alloc_ring_res (struct iecm_hw *hw, +struct iecm_ctlq_info *cq); + +void iecm_ctlq_dealloc_ring_res (struct iecm_hw *hw,struct iecm_ctlq_info *cq); + +/* prototype for functions used for dynamic memory allocation */ +void *iecm_alloc_dma_mem (struct iecm_hw *hw,struct iecm_dma_mem *mem, +u64 size); +void iecm_free_dma_mem (struct iecm_hw *hw,struct iecm_dma_mem *mem); +#endif /* _IECM_CONTROLQ_H_ */ drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +185
-0@@ -0,0 +1,185 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020, Intel Corporation. */ + +#ifndef _IECM_CONTROLQ_API_H_ +#define _IECM_CONTROLQ_API_H_ + +#include "iecm_mem.h" + +struct iecm_hw ; + +/* Used for queue init, response and events */ +enum iecm_ctlq_type { +IECM_CTLQ_TYPE_MAILBOX_TX =0 , +IECM_CTLQ_TYPE_MAILBOX_RX =1 , +IECM_CTLQ_TYPE_CONFIG_TX =2 , +IECM_CTLQ_TYPE_CONFIG_RX =3 , +IECM_CTLQ_TYPE_EVENT_RX =4 , +IECM_CTLQ_TYPE_RDMA_TX =5 , +IECM_CTLQ_TYPE_RDMA_RX =6 , +IECM_CTLQ_TYPE_RDMA_COMPL =7 +}; + +/* Generic Control Queue Structures */ +struct iecm_ctlq_reg { +/* used for queue tracking */ +u32 head; +u32 tail; +/* Below applies only to default mb (if present) */ +u32 len; +u32 bah; +u32 bal; +u32 len_mask; +u32 len_ena_mask; +u32 head_mask; +}; + +/* Generic queue msg structure */ +struct iecm_ctlq_msg { +u16 vmvf_type;/* represents the source of the message on recv */ +#define IECM_VMVF_TYPE_VF 0 +#define IECM_VMVF_TYPE_VM 1 +#define IECM_VMVF_TYPE_PF 2 +u16 opcode; +u16 data_len;/* data_len = 0 when no payload is attached */ +union { +u16 func_id;/* when sending a message */ +u16 status;/* when receiving a message */ + }; +union { +struct { +u32 chnl_retval; +u32 chnl_opcode; + } mbx; + } cookie; +union { +#define IECM_DIRECT_CTX_SIZE 16 +#define IECM_INDIRECT_CTX_SIZE 8 +/* 16 bytes of context can be provided or 8 bytes of context +* plus the address of a DMA buffer +*/ +u8 direct[IECM_DIRECT_CTX_SIZE ]; +struct { +u8 context[IECM_INDIRECT_CTX_SIZE ]; +struct iecm_dma_mem *payload; + } indirect; + } ctx; +}; + +/* Generic queue info structures */ +/* MB, CONFIG and EVENT q do not have extended info */ +struct iecm_ctlq_create_info { +enum iecm_ctlq_type type; +int id;/* absolute queue offset passed as input +* -1 for default mailbox if present +*/ +u16 len;/* Queue length passed as input */ +u16 buf_size;/* buffer size passed as input */ +u64 base_address;/* output, HPA of the Queue start */ +struct iecm_ctlq_reg reg;/* registers accessed by ctlqs */ + +int ext_info_size; +void *ext_info;/* Specific to q type */ +}; + +/* Control Queue information */ +struct iecm_ctlq_info { +struct list_head cq_list; + +enum iecm_ctlq_type cq_type; +int q_id; +/* control queue lock */ +struct mutex cq_lock; + +/* used for interrupt processing */ +u16 next_to_use; +u16 next_to_clean; +u16 next_to_post;/* starting descriptor to post buffers +* to after recev +*/ + +struct iecm_dma_mem desc_ring;/* descriptor ring memory +* iecm_dma_mem is defined in OSdep.h +*/ +union { +struct iecm_dma_mem **rx_buff; +struct iecm_ctlq_msg **tx_msg; + } bi; + +u16 buf_size;/* queue buffer size */ +u16 ring_size;/* Number of descriptors */ +struct iecm_ctlq_reg reg;/* registers accessed by ctlqs */ +}; + +/* PF/VF mailbox commands */ +enum iecm_mbx_opc { +/* iecm_mbq_opc_send_msg_to_pf: +* usage: used by PF or VF to send a message to its CPF +* target: RX queue and function ID of parent PF taken from HW +*/ + iecm_mbq_opc_send_msg_to_pf =0x0801 , + +/* iecm_mbq_opc_send_msg_to_vf: +* usage: used by PF to send message to a VF +* target: VF control queue ID must be specified in descriptor +*/ + iecm_mbq_opc_send_msg_to_vf =0x0802 , + +/* iecm_mbq_opc_send_msg_to_peer_pf: +* usage: used by any function to send message to any peer PF +* target: RX queue and host of parent PF taken from HW +*/ + iecm_mbq_opc_send_msg_to_peer_pf =0x0803 , + +/* iecm_mbq_opc_send_msg_to_peer_drv: +* usage: used by any function to send message to any peer driver +* target: RX queue and target host must be specific in descriptor +*/ + iecm_mbq_opc_send_msg_to_peer_drv =0x0804 , +}; + +/* API support for control queue management */ + +/* Will init all required q including default mb. "q_info" is an array of +* create_info structs equal to the number of control queues to be created. +*/ +int iecm_ctlq_init (struct iecm_hw *hw,u8 num_q, +struct iecm_ctlq_create_info *q_info); + +/* Allocate and initialize a single control queue, which will be added to the +* control queue list; returns a handle to the created control queue +*/ +int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq); + +/* Deinitialize and deallocate a single control queue */ +void iecm_ctlq_remove (struct iecm_hw *hw, +struct iecm_ctlq_info *cq); + +/* Sends messages to HW and will also free the buffer*/ +int iecm_ctlq_send (struct iecm_hw *hw, +struct iecm_ctlq_info *cq, +u16 num_q_msg, +struct iecm_ctlq_msg q_msg[]); + +/* Receives messages and called by interrupt handler/polling +* initiated by app/process. Also caller is supposed to free the buffers +*/ +int iecm_ctlq_recv (struct iecm_ctlq_info *cq,u16 *num_q_msg, +struct iecm_ctlq_msg *q_msg); + +/* Reclaims send descriptors on HW write back */ +int iecm_ctlq_clean_sq (struct iecm_ctlq_info *cq,u16 *clean_count, +struct iecm_ctlq_msg *msg_status[]); + +/* Indicate RX buffers are done being processed */ +int iecm_ctlq_post_rx_buffs (struct iecm_hw *hw, +struct iecm_ctlq_info *cq, +u16 *buff_count, +struct iecm_dma_mem **buffs); + +/* Will destroy all q including the default mb */ +int iecm_ctlq_deinit (struct iecm_hw *hw); + +#endif /* _IECM_CONTROLQ_API_H_ */ drivers/net/ethernet/intel/include/iecm_mem.h new file +20
-1@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_MEM_H_ +#define _IECM_MEM_H_ + +#include <linux/io.h> + +struct iecm_dma_mem { +void *va; +dma_addr_t pa; +size_t size; +}; + +#define wr32 (a, reg, value) writel((value), ((a)->hw_addr + (reg))) +#define rd32 (a, reg) readl((a)->hw_addr + (reg)) +#define wr64 (a, reg, value) writeq((value), ((a)->hw_addr + (reg))) +#define rd64 (a, reg) readq((a)->hw_addr + (reg)) + +#endif /* _IECM_MEM_H_ */ --2.33.0
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Brady
PATCH 4/19 iecm: add api_init and controlq init
Quoted 147 lines
-----Original Message-----
From: Shannon Nelson <[email protected]>
Sent: Tuesday, February 1, 2022 1:27 PM
To: Brady, Alan <[email protected]>
Cc: Intel Wired LAN <[email protected]>; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 04/19] iecm: addapi_initand controlq initQuoted 9 lines · Alan Brady
Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.
At the end of probe we kicked off a hard reset and this implements what's needed to handle that reset and continue init.
Quoted 8 lines
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 3 + .../net/ethernet/intel/iecm/iecm_controlq.c | 649++++++++++++++++++
Quoted 10 lines
.../ethernet/intel/iecm/iecm_controlq_setup.c | 175 +++++ drivers/net/ethernet/intel/iecm/iecm_lib.c | 191 +++++- .../net/ethernet/intel/iecm/iecm_virtchnl.c | 172 +++++ drivers/net/ethernet/intel/include/iecm.h | 52 ++ .../ethernet/intel/include/iecm_controlq.h | 117 ++++ .../intel/include/iecm_controlq_api.h | 185 +++++ drivers/net/ethernet/intel/include/iecm_mem.h | 20 + 9 files changed, 1563 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c create mode 100644
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.cQuoted 3 lines
create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h create mode 100644
drivers/net/ethernet/intel/include/iecm_controlq_api.hReview
Quoted 3 lines
create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h(quoted diff) +0
-0b/drivers/net/ethernet/intel/iecm/Makefile
drivers/net/ethernet/intel/iecm/Makefile ccflags-y += -
Quoted 4 lines
index
4f497723419d..db8fecb075a6100644drivers/net/ethernet/intel/iecm/Makefile +0
-0@@ -11,4 +11,7 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include
Review
Quoted 8 lines
drivers/net/ethernet/intel/iecm/Makefile +3
-0iecm-y := \ iecm_lib.o \ + iecm_virtchnl.o \ + iecm_controlq.o \ + iecm_controlq_setup.o \ iecm_main.o(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_controlq.cQuoted 5 lines
new file mode 100644
index 000000000000..f9682a7b3e44drivers/net/ethernet/intel/iecm/iecm_controlq.c line 9
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +9
-0@@ -0,0 +1,649 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2020, Intel Corporation. */ + +#include "iecm_controlq.h" + +/** +* iecm_ctlq_setup_regs - initialize control queue registers +* @cq: pointer to the specific control queue +* @q_create_info: structs containing info for each queue to be initialized
Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +16
-0+*/ +static void +iecm_ctlq_setup_regs (struct iecm_ctlq_info *cq, +struct iecm_ctlq_create_info *q_create_info) +{ +/* set head and tail registers in our local struct */ + cq->reg.head = q_create_info->reg.head; + cq->reg.tail = q_create_info->reg.tail; + cq->reg.len = q_create_info->reg.len; + cq->reg.bah = q_create_info->reg.bah; + cq->reg.bal = q_create_info->reg.bal; + cq->reg.len_mask = q_create_info->reg.len_mask; + cq->reg.len_ena_mask = q_create_info->reg.len_ena_mask; + cq->reg.head_mask = q_create_info->reg.head_mask; +} +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+/** +* iecm_ctlq_init_regs - Initialize control queue registers +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* @is_rxq: true if receive control queue, false otherwise +* +* Initialize registers. The caller is expected to have already initialized the +* descriptor ring memory and buffer memory +*/ +static void iecm_ctlq_init_regs(struct iecm_hw *hw, struct
iecm_ctlq_info*cq,Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +14
-0+ bool is_rxq) +{ +/* Update tail to post pre-allocated buffers for rx queues */ +if (is_rxq) +wr32 (hw, cq->reg.tail, (u32)(cq->ring_size -1 )); + +/* For non-Mailbox control queues only TAIL need to be set */ +if (cq->q_id !=-1 ) +return ; + +/* Clear Head for both send or receive */ +wr32 (hw, cq->reg.head,0 ); + +/* set starting point */ drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+wr32 (hw, cq->reg.bal,lower_32_bits (cq->desc_ring.pa)); +wr32 (hw, cq->reg.bah,upper_32_bits (cq->desc_ring.pa)); +wr32 (hw, cq->reg.len, (cq->ring_size | cq->reg.len_ena_mask)); +} + +/** +* iecm_ctlq_init_rxq_bufs - populate receive queue descriptors with buf +* @cq: pointer to the specific Control queue +* +* Record the address of the receive queue DMA buffers in the descriptors.
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+* The buffers must have been previously allocated. +*/ +static void iecm_ctlq_init_rxq_bufs (struct iecm_ctlq_info *cq) +{ +int i =0 ; +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+for (i =0 ; i < cq->ring_size; i++) { +struct iecm_ctlq_desc *desc =IECM_CTLQ_DESC (cq, i); +struct iecm_dma_mem *bi = cq->bi.rx_buff[i]; + +/* No buffer to post to descriptor, continue */ +if (!bi) +continue ; + + desc->flags = + cpu_to_le16(IECM_CTLQ_FLAG_BUF |
IECM_CTLQ_FLAG_RD);
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 77
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+ desc->opcode =0 ; + desc->datalen = (__le16 )cpu_to_le16 (bi->size);Why the typecast to
__le16, aren't we there already with thecpu_to_le16()?
Yeah this is weird. Will fix.
Quoted 65 lines
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ desc->ret_val =0 ; + desc->cookie_high =0 ; + desc->cookie_low =0 ; + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (bi->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (bi->pa)); + desc->params.indirect.param0 =0 ; + desc->params.indirect.param1 =0 ; + }drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+} + +/** +* iecm_ctlq_shutdown - shutdown the CQ +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* The main shutdown routine for any controq queue +*/ +static void iecm_ctlq_shutdown(struct iecm_hw *hw, struct
iecm_ctlq_info*cq)Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +14
-0+{ +mutex_lock (&cq->cq_lock); + +if (!cq->ring_size) + goto shutdown_sq_out; + +/* free ring buffers and the ring itself */ +iecm_ctlq_dealloc_ring_res (hw, cq); + +/* Set ring_size to 0 to indicate uninitialized queue */ + cq->ring_size =0 ; + +shutdown_sq_out: +mutex_unlock (&cq->cq_lock);drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+mutex_destroy (&cq->cq_lock); +} + +/** +* iecm_ctlq_add - add one control queue +* @hw: pointer to hardware struct +* @qinfo: info for queue to be created +* @cq_out: (output) double pointer to control queue to be created +* +* Allocate and initialize a control queue and add it to the control queue list.
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 122
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* The cq parameter will be allocated/initialized and passed back to the caller
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +3
-0+* if no errors occur. +* +* Note: iecm_ctlq_init must be called prior to any calls to
iecm_ctlq_addQuoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +13
-0+*/ +int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq_out) +{ +bool is_rxq = false; +int status =0 ; + +if (!qinfo->len || !qinfo->buf_size || + qinfo->len >IECM_CTLQ_MAX_RING_SIZE || + qinfo->buf_size >IECM_CTLQ_MAX_BUF_LEN ) +return -EINVAL ; +
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 141
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +3
-0+ *cq_out =kcalloc (1 ,sizeof (struct iecm_ctlq_info ),GFP_KERNEL ); +if (!(*cq_out)) +return -ENOMEM ;You might keep this as a local variable until you get to a successful end, then set
*cq_outwhen done.
Else, you need to be sure to clear it back to NULL on error return to be sure no one uses a bogus value.
This one I'm not sure I follow. If it's NULL we fall into the if(!*cq_out) and don't need to set it to NULL (it already is?). If it's not NULL then we go on to use it like a valid memory address so I hope it's valid.
Quoted 47 lines
Quoted 47 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +47
-0+ + (*cq_out)->cq_type = qinfo->type; + (*cq_out)->q_id = qinfo->id; + (*cq_out)->buf_size = qinfo->buf_size; + (*cq_out)->ring_size = qinfo->len; + + (*cq_out)->next_to_use =0 ; + (*cq_out)->next_to_clean =0 ; + (*cq_out)->next_to_post = (*cq_out)->ring_size -1 ; + +switch (qinfo->type) { +case IECM_CTLQ_TYPE_MAILBOX_RX : + is_rxq = true; + fallthrough; +case IECM_CTLQ_TYPE_MAILBOX_TX : + status =iecm_ctlq_alloc_ring_res (hw, *cq_out); +break ; +default : + status = -EBADR ; +break ; + } + +if (status) + goto init_free_q; + +if (is_rxq) { +iecm_ctlq_init_rxq_bufs (*cq_out); + }else { +/* Allocate the array of msg pointers for TX queues */ + (*cq_out)->bi.tx_msg =kcalloc (qinfo->len, +sizeof (struct iecm_ctlq_msg *), +GFP_KERNEL ); +if (!(*cq_out)->bi.tx_msg) { + status = -ENOMEM ; + goto init_dealloc_q_mem; + } + } + +iecm_ctlq_setup_regs (*cq_out, qinfo); + +iecm_ctlq_init_regs (hw, *cq_out, is_rxq); + +mutex_init (&(*cq_out)->cq_lock); + +list_add (&(*cq_out)->cq_list, &hw->cq_list_head); + +return status;
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 194
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+ +init_dealloc_q_mem: +/* free ring buffers and the ring itself */ +iecm_ctlq_dealloc_ring_res (hw, *cq_out); +init_free_q: +kfree (*cq_out);Probably should clear this back to NULL.
Will fix.
Quoted 47 lines
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +12
-0+ +return status; +} + +/** +* iecm_ctlq_remove - deallocate and remove specified control queue +* @hw: pointer to hardware struct +* @cq: pointer to control queue to be removed +*/ +void iecm_ctlq_remove (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+list_del (&cq->cq_list); +iecm_ctlq_shutdown (hw, cq); +kfree (cq); +} + +/** +* iecm_ctlq_init - main initialization routine for all control queues +* @hw: pointer to hardware struct +* @num_q: number of queues to initialize +* @q_info: array of structs containing info for each queue to be initialized
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 218
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+* +* This initializes any number and any type of control queues. This is an all
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 220
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+* or nothing routine; if one fails, all previously allocated queues will be +* destroyed. This must be called prior to using the individual add/remove
Quoted 18 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +18
-0+* APIs. +*/ +int iecm_ctlq_init (struct iecm_hw *hw,u8 num_q, +struct iecm_ctlq_create_info *q_info) +{ +struct iecm_ctlq_info *cq =NULL , *tmp =NULL ; +int ret_code =0 ; +int i =0 ; + +INIT_LIST_HEAD (&hw->cq_list_head); + +for (i =0 ; i < num_q; i++) { +struct iecm_ctlq_create_info *qinfo = q_info + i; + + ret_code =iecm_ctlq_add (hw, qinfo, &cq); +if (ret_code) + goto init_destroy_qs; + }
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 244
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+ +return ret_code; + +init_destroy_qs: +list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) +iecm_ctlq_remove (hw, cq);This could call
iecm_ctlq_deinit()rather than repeat the same code.
Seems fair, will fix.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +11
-0+ +return ret_code; +} + +/** +* iecm_ctlq_deinit - destroy all control queues +* @hw: pointer to hw struct +*/ +int iecm_ctlq_deinit (struct iecm_hw *hw) +{ +struct iecm_ctlq_info *cq =NULL , *tmp =NULL ;
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 246
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+int ret_code =0 ; + +list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) +iecm_ctlq_remove (hw, cq); + +return ret_code;Why is there a return code here when there is never an error?
Yeah this is weird, will fix.
Quoted 96 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+} + +/** +* iecm_ctlq_send - send command to Control Queue (CTQ) +* @hw: pointer to hw struct +* @cq: handle to control queue struct to send on +* @num_q_msg: number of messages to send on control queue +* @q_msg: pointer to array of queue messages to be sent +* +* The caller is expected to allocate DMAable buffers and pass them to the
Quoted 74 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +74
-0+* send routine via the q_msg struct / control queue specific data struct. +* The control queue will hold a reference to each send message until +* the completion for that message has been cleaned. +*/ +int iecm_ctlq_send (struct iecm_hw *hw,struct iecm_ctlq_info *cq, +u16 num_q_msg,struct iecm_ctlq_msg q_msg[]) +{ +struct iecm_ctlq_desc *desc; +int num_desc_avail =0 ; +int status =0 ; +int i =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ; + +mutex_lock (&cq->cq_lock); + +/* Ensure there are enough descriptors to send all messages */ + num_desc_avail =IECM_CTLQ_DESC_UNUSED (cq); +if (num_desc_avail ==0 || num_desc_avail < num_q_msg) { + status = -ENOSPC ; + goto sq_send_command_out; + } + +for (i =0 ; i < num_q_msg; i++) { +struct iecm_ctlq_msg *msg = &q_msg[i]; +u64 msg_cookie; + + desc =IECM_CTLQ_DESC (cq, cq->next_to_use); + + desc->opcode =cpu_to_le16 (msg->opcode); + desc->pfid_vfid =cpu_to_le16 (msg->func_id); + + msg_cookie = *(u64 *)&msg->cookie; + desc->cookie_high = +cpu_to_le32 (upper_32_bits (msg_cookie)); + desc->cookie_low = +cpu_to_le32 (lower_32_bits (msg_cookie)); + +if (msg->data_len) { +struct iecm_dma_mem *buff = msg->ctx.indirect.payload; + + desc->datalen =cpu_to_le16 (msg->data_len); + desc->flags |=cpu_to_le16 (IECM_CTLQ_FLAG_BUF ); + desc->flags |=cpu_to_le16 (IECM_CTLQ_FLAG_RD ); + +/* Update the address values in the desc with the pa +* value for respective buffer +*/ + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (buff->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (buff->pa)); + +memcpy (&desc->params, msg->ctx.indirect.context, +IECM_INDIRECT_CTX_SIZE ); + }else { +memcpy (&desc->params, msg->ctx.direct, +IECM_DIRECT_CTX_SIZE ); + } + +/* Store buffer info */ + cq->bi.tx_msg[cq->next_to_use] = msg; + + (cq->next_to_use)++; +if (cq->next_to_use == cq->ring_size) + cq->next_to_use =0 ; + } + +/* Force memory write to complete before letting hardware +* know that there are new descriptors to fetch. +*/ +dma_wmb (); +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+wr32 (hw, cq->reg.tail, cq->next_to_use); + +sq_send_command_out: +mutex_unlock (&cq->cq_lock); + +return status; +} + +/** +* iecm_ctlq_clean_sq - reclaim send descriptors on HW write back for the
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +3
-0+* requested queue +* @cq: pointer to the specific Control queue +* @clean_count: (input|output) number of descriptors to clean as input, and
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 359
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* number of descriptors actually cleaned as output Rather than two meanings for one parameter, can the number cleaned be a positive return value?
That seems fair. Will check.
Quoted 48 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 360
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* @msg_status: (output) pointer to msg pointer array to be populated; needs
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +4
-0+* to be allocated by caller +* +* Returns an array of message pointers associated with the cleaned +* descriptors. The pointers are to the original ctlq_msgs sent on the cleaned
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 365
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* descriptors. The status will be returned for each; any messages that failed
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 366
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* to send will have a non-zero status. The caller is expected to free original
Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +25
-0+* ctlq_msgs and free or reuse the DMA buffers. +*/ +int iecm_ctlq_clean_sq (struct iecm_ctlq_info *cq,u16 *clean_count, +struct iecm_ctlq_msg *msg_status[]) +{ +struct iecm_ctlq_desc *desc; +u16 i =0 , num_to_clean; +u16 ntc, desc_err; +int ret =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ; + +if (*clean_count ==0 ) +return 0 ; +if (*clean_count > cq->ring_size) +return -EBADR ; + +mutex_lock (&cq->cq_lock); + + ntc = cq->next_to_clean; + + num_to_clean = *clean_count; + +for (i =0 ; i < num_to_clean; i++) {drivers/net/ethernet/intel/iecm/iecm_controlq.c line 401
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+/* Fetch next descriptor and check if marked as done */ + desc =IECM_CTLQ_DESC (cq, ntc); +if (!(le16_to_cpu (desc->flags) &IECM_CTLQ_FLAG_DD )) +break ; + + desc_err =le16_to_cpu (desc->ret_val); +if (desc_err) { +/* strip off FW internal code */ + desc_err &=0xff ; + }Why not simply
Quoted 2 lines
desc_err = le16_to_cpu(desc->ret_val) & 0xff;
Will fix.
Quoted 30 lines
Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +19
-0+ + msg_status[i] = cq->bi.tx_msg[ntc]; + msg_status[i]->status = desc_err; + + cq->bi.tx_msg[ntc] =NULL ; + +/* Zero out any stale data */ +memset (desc,0 ,sizeof (*desc)); + + ntc++; +if (ntc == cq->ring_size) + ntc =0 ; + } + + cq->next_to_clean = ntc; + +mutex_unlock (&cq->cq_lock); + +/* Return number of descriptors actually cleaned */ drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ *clean_count = i; + +return ret; +} + +/** +* iecm_ctlq_post_rx_buffs - post buffers to descriptor ring +* @hw: pointer to hw struct +* @cq: pointer to control queue handle +* @buff_count: (input|output) input is number of buffers caller is trying to
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 431
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* return; output is number of buffers that were not posted Same comment.
And the return would make more sense if consistent with the previous function where the return is how many were successful.
Yeah this seems more sane, need a little time to see what the refactor looks like.
Quoted 142 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 432
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* @buffs: array of pointers to dma mem structs to be given to hardware
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 434
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+* +* Caller uses this function to return DMA buffers to the descriptor ring after
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +7
-0+* consuming them; buff_count will be the number of buffers. +* +* Note: this function needs to be called after a receive call even +* if there are no DMA buffers to be returned, i.e. buff_count = 0, +* buffs = NULL to support direct commands +*/ +int iecm_ctlq_post_rx_buffs(struct iecm_hw *hw, struct iecm_ctlq_info*cq,
Quoted 15 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +15
-0+ u16 *buff_count, struct iecm_dma_mem **buffs) +{ + struct iecm_ctlq_desc *desc; +u16 ntp = cq->next_to_post; +bool buffs_avail = false; +u16 tbp = ntp +1 ; +int status =0 ; +int i =0 ; + +if (*buff_count > cq->ring_size) +return -EBADR ; + +if (*buff_count >0 ) + buffs_avail = true; +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+mutex_lock (&cq->cq_lock); + +if (tbp >= cq->ring_size) + tbp =0 ; + +if (tbp == cq->next_to_clean) +/* Nothing to do */ + goto post_buffs_out; + +/* Post buffers for as many as provided or up until the last one used */
Quoted 39 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +39
-0+while (ntp != cq->next_to_clean) { + desc =IECM_CTLQ_DESC (cq, ntp); + +if (cq->bi.rx_buff[ntp]) + goto fill_desc; +if (!buffs_avail) { +/* If the caller hasn't given us any buffers or +* there are none left, search the ring itself +* for an available buffer to move to this +* entry starting at the next entry in the ring +*/ + tbp = ntp +1 ; + +/* Wrap ring if necessary */ +if (tbp >= cq->ring_size) + tbp =0 ; + +while (tbp != cq->next_to_clean) { +if (cq->bi.rx_buff[tbp]) { + cq->bi.rx_buff[ntp] = + cq->bi.rx_buff[tbp]; + cq->bi.rx_buff[tbp] =NULL ; + +/* Found a buffer, no need to +* search anymore +*/ +break ; + } + +/* Wrap ring if necessary */ + tbp++; +if (tbp >= cq->ring_size) + tbp =0 ; + } + +if (tbp == cq->next_to_clean) + goto post_buffs_out; + }else { +/* Give back pointer to DMA buffer */ drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ cq->bi.rx_buff[ntp] = buffs[i]; + i++; + +if (i >= *buff_count) + buffs_avail = false; + } + +fill_desc: + desc->flags = + cpu_to_le16(IECM_CTLQ_FLAG_BUF |
IECM_CTLQ_FLAG_RD);Quoted 30 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +30
-0+ +/* Post buffers to descriptor */ + desc->datalen =cpu_to_le16 (cq->bi.rx_buff[ntp]->size); + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (cq->bi.rx_buff[ntp]->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (cq->bi.rx_buff[ntp]->pa)); + + ntp++; +if (ntp == cq->ring_size) + ntp =0 ; + } + +post_buffs_out: +/* Only update tail if buffers were actually posted */ +if (cq->next_to_post != ntp) { +if (ntp) +/* Update next_to_post to ntp - 1 since current ntp +* will not have a buffer +*/ + cq->next_to_post = ntp -1 ; +else +/* Wrap to end of end ring since current ntp is 0 */ + cq->next_to_post = cq->ring_size -1 ; + +wr32 (hw, cq->reg.tail, cq->next_to_post); + } + +mutex_unlock (&cq->cq_lock); +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+/* return the number of buffers that were not posted */ + *buff_count = *buff_count - i; + +return status; +} + +/** +* iecm_ctlq_recv - receive control queue message call back +* @cq: pointer to control queue handle to receive on +* @num_q_msg: (input|output) input number of messages that should be received;
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 557
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+* output number of messages actually received +* @q_msg: (output) array of received control queue messages on this q;
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +9
-0+* needs to be pre-allocated by caller for as many messages as requested +* +* Called by interrupt handler or polling mechanism. Caller is expected +* to free buffers +*/ +int iecm_ctlq_recv (struct iecm_ctlq_info *cq,u16 *num_q_msg, +struct iecm_ctlq_msg *q_msg) +{ +u16 num_to_clean, ntc, ret_val, flags;
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 572
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+struct iecm_ctlq_desc *desc; +int ret_code =0 ; +u16 i =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ;Should
*num_q_msgsget set to 0 here since none were received?
Based on the function description it does indeed sound like we should be.
Quoted 33 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 577
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +5
-0+ +if (*num_q_msg ==0 ) +return 0 ; +else if (*num_q_msg > cq->ring_size) +return -EBADR ;Again, set
*num_q_msgsto 0?Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +25
-0+ +/* take the lock before we start messing with the ring */ +mutex_lock (&cq->cq_lock); + + ntc = cq->next_to_clean; + + num_to_clean = *num_q_msg; + +for (i =0 ; i < num_to_clean; i++) { +u64 msg_cookie; + +/* Fetch next descriptor and check if marked as done */ + desc =IECM_CTLQ_DESC (cq, ntc); + flags =le16_to_cpu (desc->flags); + +if (!(flags &IECM_CTLQ_FLAG_DD )) +break ; + + ret_val =le16_to_cpu (desc->ret_val); + + q_msg[i].vmvf_type = (flags & + (IECM_CTLQ_FLAG_FTYPE_VM | +IECM_CTLQ_FLAG_FTYPE_PF )) >> +IECM_CTLQ_FLAG_FTYPE_S ; +
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 604
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+if (flags &IECM_CTLQ_FLAG_ERR ) + ret_code = -EBADMSG ;So you might return
-EBADMSG, even if you've cleaned many messages? Will this be reflected inret_valand does the caller then need to hunt down the bad q_msg[].status?
How these work together should probably be clearly explained in the function header.
I'll need some time to look at this, but it does seem suspect.
Quoted 1,185 lines
Review
Quoted 46 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +45
-0+ + msg_cookie = (u64 )le32_to_cpu (desc->cookie_high) <<32 ; + msg_cookie |= (u64 )le32_to_cpu (desc->cookie_low); +memcpy (&q_msg[i].cookie, &msg_cookie,sizeof (u64)); + + q_msg[i].opcode =le16_to_cpu (desc->opcode); + q_msg[i].data_len =le16_to_cpu (desc->datalen); + q_msg[i].status = ret_val; + +if (desc->datalen) { +memcpy (q_msg[i].ctx.indirect.context, + &desc->params.indirect,IECM_INDIRECT_CTX_SIZE ); + +/* Assign pointer to dma buffer to ctlq_msg array +* to be given to upper layer +*/ + q_msg[i].ctx.indirect.payload = cq->bi.rx_buff[ntc]; + +/* Zero out pointer to DMA buffer info; +* will be repopulated by post buffers API +*/ + cq->bi.rx_buff[ntc] =NULL ; + }else { +memcpy (q_msg[i].ctx.direct, desc->params.raw, +IECM_DIRECT_CTX_SIZE ); + } + +/* Zero out stale data in descriptor */ +memset (desc,0 ,sizeof (struct iecm_ctlq_desc )); + + ntc++; +if (ntc == cq->ring_size) + ntc =0 ; + }; + + cq->next_to_clean = ntc; + +mutex_unlock (&cq->cq_lock); + + *num_q_msg = i; +if (*num_q_msg ==0 ) + ret_code = -ENOMSG ; + +return ret_code; +}(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_controlq_setup.cQuoted 12 lines
new file mode 100644
index 000000000000..a36fc88d6bb5drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +7
-0@@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2020, Intel Corporation. */ + +#include "iecm_controlq.h" + +/** +* iecm_ctlq_alloc_desc_ring - Allocate Control Queue (CQ) rings drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c line 17
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +10
-0+* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +*/ +static int +iecm_ctlq_alloc_desc_ring (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{ +size_t size = cq->ring_size *sizeof (struct iecm_ctlq_desc ); + + cq->desc_ring.va = iecm_alloc_dma_mem(hw, &cq->desc_ring,size);
Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +17
-0+if (!cq->desc_ring.va) +return -ENOMEM ; + +return 0 ; +} + +/** +* iecm_ctlq_alloc_bufs - Allocate Control Queue (CQ) buffers +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Allocate the buffer head for all control queues, and if it's a receive +* queue, allocate DMA buffers +*/ +static int iecm_ctlq_alloc_bufs (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +10
-0+int i =0 ; + +/* Do not allocate DMA buffers for transmit queues */ +if (cq->cq_type ==IECM_CTLQ_TYPE_MAILBOX_TX ) +return 0 ; + +/* We'll be allocating the buffer info memory first, then we can +* allocate the mapped buffers for the event processing +*/ + cq->bi.rx_buff = kcalloc(cq->ring_size, sizeof(struct iecm_dma_mem*),
Quoted 48 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +48
-0+ GFP_KERNEL); +if (!cq->bi.rx_buff) +return -ENOMEM ; + +/* allocate the mapped buffers (except for the last one) */ +for (i =0 ; i < cq->ring_size -1 ; i++) { +struct iecm_dma_mem *bi; +int num =1 ;/* number of iecm_dma_mem to be allocated */ + + cq->bi.rx_buff[i] =kcalloc (num,sizeof (struct iecm_dma_mem ), +GFP_KERNEL ); +if (!cq->bi.rx_buff[i]) + goto unwind_alloc_cq_bufs; + + bi = cq->bi.rx_buff[i]; + + bi->va =iecm_alloc_dma_mem (hw, bi, cq->buf_size); +if (!bi->va) { +/* unwind will not free the failed entry */ +kfree (cq->bi.rx_buff[i]); + goto unwind_alloc_cq_bufs; + } + } + +return 0 ; + +unwind_alloc_cq_bufs: +/* don't try to free the one that failed... */ + i--; +for (; i >=0 ; i--) { +iecm_free_dma_mem (hw, cq->bi.rx_buff[i]); +kfree (cq->bi.rx_buff[i]); + } +kfree (cq->bi.rx_buff); + +return -ENOMEM ; +} + +/** +* iecm_ctlq_free_desc_ring - Free Control Queue (CQ) rings +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* This assumes the posted send buffers have already been cleaned +* and de-allocated +*/ +static void iecm_ctlq_free_desc_ring (struct iecm_hw *hw, +struct iecm_ctlq_info *cq)drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +10
-0+{ +iecm_free_dma_mem (hw, &cq->desc_ring); +} + +/** +* iecm_ctlq_free_bufs - Free CQ buffer info elements +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Free the DMA buffers for RX queues, and DMA buffer header for both RX and TX
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c line 103
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +1
-0+* queues. The upper layers are expected to manage freeing of TX DMA buffers
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c line 105
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +2
-0+*/ +static void iecm_ctlq_free_bufs(struct iecm_hw *hw, struct
iecm_ctlq_info*cq)Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +19
-0+{ +void *bi; + +if (cq->cq_type ==IECM_CTLQ_TYPE_MAILBOX_RX ) { +int i; + +/* free DMA buffers for rx queues*/ +for (i =0 ; i < cq->ring_size; i++) { +if (cq->bi.rx_buff[i]) { +iecm_free_dma_mem (hw, cq->bi.rx_buff[i]); +kfree (cq->bi.rx_buff[i]); + } + } + + bi = (void *)cq->bi.rx_buff; + }else { + bi = (void *)cq->bi.tx_msg; + } +drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +10
-0+/* free the buffer header */ +kfree (bi); +} + +/** +* iecm_ctlq_dealloc_ring_res - Free memory allocated for control queue +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Free the memory used by the ring, buffers and other related structures
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c line 136
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +2
-0+*/ +void iecm_ctlq_dealloc_ring_res(struct iecm_hw *hw, struct
iecm_ctlq_info*cq)drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +8
-0+{ +/* free ring buffers and the ring itself */ +iecm_ctlq_free_bufs (hw, cq); +iecm_ctlq_free_desc_ring (hw, cq); +} + +/** +* iecm_ctlq_alloc_ring_res - allocate memory for descriptor ring and bufs
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +4
-0+* @hw: pointer to hw struct +* @cq: pointer to control queue struct +* +* Do *NOT* hold the lock when calling this as the memory allocation routines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +3
-0+* called are not going to be atomic context safe +*/ +int iecm_ctlq_alloc_ring_res(struct iecm_hw *hw, struct iecm_ctlq_info*cq)
Review
Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +24
-0+{ +int ret_code; + +/* verify input for valid configuration */ +if (!cq->ring_size || !cq->buf_size) +return -EINVAL ; + +/* allocate the ring memory */ + ret_code =iecm_ctlq_alloc_desc_ring (hw, cq); +if (ret_code) +return ret_code; + +/* allocate buffers in the rings */ + ret_code =iecm_ctlq_alloc_bufs (hw, cq); +if (ret_code) + goto iecm_init_cq_free_ring; + +/* success! */ +return 0 ; + +iecm_init_cq_free_ring: +iecm_free_dma_mem (hw, &cq->desc_ring); +return ret_code; +}(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_lib.cdrivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct
Quoted 30 lines
index
e6d0b418a27f..64cdbce2c842100644drivers/net/ethernet/intel/iecm/iecm_lib.c +19
-0@@ -5,6 +5,25 @@#include "iecm.h" +/** +* iecm_cfg_hw - Initialize HW struct +* @adapter: adapter to setup hw struct for +* +* Returns 0 on success, negative on failure +*/ +static int iecm_cfg_hw (struct iecm_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct iecm_hw *hw = &adapter->hw; + + hw->hw_addr =pcim_iomap_table (pdev)[IECM_BAR0 ]; +if (!hw->hw_addr) +return -EIO ; + hw->back = adapter; + +return 0 ; +} +/** * iecm_statistics_task - Delayed task to get statistics over mailbox * @work: work_struct handle to our data @@ -39,6 +58,32 @@ static void iecm_init_task(struct work_struct*work)
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3
-0/* stub */ } +/** +* iecm_api_init - Initialize and verify device API +* @adapter: driver specific private structure drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct *work)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10
-0+* +* Returns 0 on success, negative on failure +*/ +static int iecm_api_init (struct iecm_adapter *adapter) +{ +struct iecm_reg_ops *reg_ops = &adapter->dev_ops.reg_ops; +struct pci_dev *pdev = adapter->pdev; + +if (!adapter->dev_ops.reg_ops_init) { + dev_err(&pdev->dev, "Invalid device, register API init notdefined\n");
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct *work)
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7
-0+return -EINVAL ; + } + adapter->dev_ops.reg_ops_init (adapter); +if (!(reg_ops->ctlq_reg_init && reg_ops->intr_reg_init && + reg_ops->mb_intr_reg_init && reg_ops->reset_reg_init && + reg_ops->trigger_reset)) { + dev_err(&pdev->dev, "Invalid device, missing one or moreregister functions\n");
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6
-0+return -EINVAL ; + } + +return 0 ; +} +/** * iecm_deinit_task - Device deinit routine * @adapter: Driver specific private structue @@ -51,13 +96,108 @@ static void iecm_deinit_task(struct
iecm_adapter*adapter)Quoted 58 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +54
-0/* stub */ } +/** +* iecm_check_reset_complete - check that reset is complete +* @hw: pointer to hw struct +* @reset_reg: struct with reset registers +* +* Returns 0 if device is ready to use, or -EBUSY if it's in reset. +**/ +static int iecm_check_reset_complete (struct iecm_hw *hw, +struct iecm_reset_reg *reset_reg) +{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; +int i; + +for (i =0 ; i <2000 ; i++) { +u32 reg_val =rd32 (hw, reset_reg->rstat); + +/* 0xFFFFFFFF might be read if other side hasn't cleared the +* register for us yet and 0xFFFFFFFF is not a valid value for +* the register, so treat that as invalid. +*/ +if (reg_val !=0xFFFFFFFF && (reg_val & reset_reg->rstat_m)) +return 0 ; +usleep_range (5000 ,10000 ); + } + +dev_warn (&adapter->pdev->dev,"Device reset timeout!\n" ); +return -EBUSY ; +} + +/** +* iecm_init_hard_reset - Initiate a hardware reset +* @adapter: Driver specific private structure +* +* Deallocate the vports and all the resources associated with them and +* reallocate. Also reinitialize the mailbox. Return 0 on success, +* negative on failure. +*/ +static int iecm_init_hard_reset (struct iecm_adapter *adapter) +{ +int err =0 ; + +mutex_lock (&adapter->reset_lock); + +/* Prepare for reset */ +if (test_and_clear_bit (__IECM_HR_DRV_LOAD, adapter->flags)) { + adapter->dev_ops.reg_ops.trigger_reset (adapter, + __IECM_HR_DRV_LOAD); + }else if (test_and_clear_bit (__IECM_HR_FUNC_RESET, adapter- flags)) { +bool is_reset =iecm_is_reset_detected (adapter); + +if (adapter->state == __IECM_UP) +set_bit (__IECM_UP_REQUESTED, adapter->flags); +iecm_deinit_task (adapter); +if (!is_reset)drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9
-0+ adapter->dev_ops.reg_ops.trigger_reset (adapter, + __IECM_HR_FUNC_RESET); +iecm_deinit_dflt_mbx (adapter); + }else if (test_and_clear_bit (__IECM_HR_CORE_RESET, adapter- flags)) { +if (adapter->state == __IECM_UP) +set_bit (__IECM_UP_REQUESTED, adapter->flags); +iecm_deinit_task (adapter); + }else { + dev_err(&adapter->pdev->dev, "Unhandled hard resetcause\n");
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter *adapter)
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8
-0+ err = -EBADRQC ; + goto handle_err; + } + +/* Wait for reset to complete */ + err =iecm_check_reset_complete (&adapter->hw, &adapter- reset_reg); +if (err) { + dev_err(&adapter->pdev->dev, "The driver was unable tocontact the device's firmware. Check that the FW is running. Driver state=%u\n",
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter *adapter)
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5
-0+ adapter->state); + goto handle_err; + } + +/* Reset is complete and so start building the driver resources again */
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter *adapter)
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3
-0+ err =iecm_init_dflt_mbx (adapter); +if (err) { + dev_err(&adapter->pdev->dev, "Failed to initialize defaultmailbox: %d\n",
Quoted 40 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +17
-1+ err); + } +handle_err: +mutex_unlock (&adapter->reset_lock); +return err; +} +/** * iecm_vc_event_task - Handle virtchannel event logic * @work: work queue struct */ static void iecm_vc_event_task (struct work_struct *work) { -/* stub */ +struct iecm_adapter *adapter =container_of (work, + struct iecm_adapter, + vc_event_task.work); + +if (test_bit (__IECM_HR_CORE_RESET, adapter->flags) || +test_bit (__IECM_HR_FUNC_RESET, adapter->flags) || +test_bit (__IECM_HR_DRV_LOAD, adapter->flags)) { +set_bit (__IECM_HR_RESET_IN_PROG, adapter->flags); +iecm_init_hard_reset (adapter); + }}
/**
drivers/net/ethernet/intel/iecm/iecm_lib.c +5
-0@@ -75,6 +215,11 @@ int iecm_probe(struct pci_dev *pdev,int err; adapter->pdev = pdev; + err =iecm_api_init (adapter); +if (err) { +dev_err (&pdev->dev,"Device API is incorrectly configured\n" ); +return err; + } err =pcim_enable_device (pdev);if (err)drivers/net/ethernet/intel/iecm/iecm_lib.c int iecm_probe(struct pci_dev *pdev, · line 297
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3
-0@@ -147,6 +292,20 @@ int iecm_probe(struct pci_dev *pdev, goto err_netdev_alloc; } + err =iecm_vport_params_buf_alloc (adapter); +if (err) { + dev_err(&pdev->dev, "Failed to alloc vport params buffer:%d\n",
drivers/net/ethernet/intel/iecm/iecm_lib.c int iecm_probe(struct pci_dev *pdev,
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7
-0+ err); + goto err_mb_res; + } + + err =iecm_cfg_hw (adapter); +if (err) { + dev_err(&pdev->dev, "Failed to configure HW structure foradapter: %d\n",
drivers/net/ethernet/intel/iecm/iecm_lib.c int iecm_probe(struct pci_dev *pdev, · line 326
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4
-0+ err); + goto err_cfg_hw; + } +mutex_init (&adapter->sw_mutex);mutex_init (&adapter->reset_lock);init_waitqueue_head (&adapter->vchnl_wq);@@ -166,11 +325,16 @@ int iecm_probe(struct pci_dev *pdev,INIT_DELAYED_WORK (&adapter->init_task, iecm_init_task); INIT_DELAYED_WORK(&adapter->vc_event_task,
iecm_vc_event_task);Quoted 32 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7
-0+ adapter->dev_ops.reg_ops.reset_reg_init (&adapter->reset_reg);set_bit (__IECM_HR_DRV_LOAD, adapter->flags);queue_delayed_work (adapter->vc_event_wq, &adapter- vc_event_task,msecs_to_jiffies (10 * (pdev->devfn &0x07 )));return 0 ; +err_cfg_hw: +iecm_vport_params_buf_rel (adapter); +err_mb_res: +kfree (adapter->netdevs); err_netdev_alloc:kfree (adapter->vports); err_vport_alloc:@@ -214,6 +378,7 @@ void iecm_remove(struct pci_dev *pdev)cancel_delayed_work_sync (&adapter->vc_event_task);iecm_deinit_task (adapter);iecm_del_user_cfg_data (adapter); +iecm_deinit_dflt_mbx (adapter);msleep (20 );destroy_workqueue (adapter->serv_wq);destroy_workqueue (adapter->vc_event_wq);@@ -222,6 +387,7 @@ void iecm_remove(struct pci_dev *pdev)kfree (adapter->vports);kfree (adapter->netdevs);kfree (adapter->vlan_caps); +iecm_vport_params_buf_rel (adapter);mutex_destroy (&adapter->sw_mutex);mutex_destroy (&adapter->reset_lock);pci_disable_pcie_error_reporting (pdev);drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_remove(struct pci_dev *pdev) · line 399
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2
-0@@ -229,3 +395,26 @@ void iecm_remove(struct pci_dev *pdev)pci_disable_device (pdev); }EXPORT_SYMBOL (iecm_remove); + +void *iecm_alloc_dma_mem(struct iecm_hw *hw, struct
iecm_dma_mem*mem, u64 size)drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_remove(struct pci_dev *pdev)
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +12
-0+{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; +size_t sz =ALIGN (size,4096 ); + + mem->va =dma_alloc_coherent (&adapter->pdev->dev, sz, + &mem->pa,GFP_KERNEL | __GFP_ZERO); + mem->size = size; + +return mem->va; +} + +void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem*mem)
Review
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9
-0+{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; + +dma_free_coherent (&adapter->pdev->dev, mem->size, + mem->va, mem->pa); + mem->size =0 ; + mem->va =NULL ; + mem->pa =0 ; +}(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_virtchnl.cQuoted 5 lines
new file mode 100644
index 000000000000..b8f54b8c700adrivers/net/ethernet/intel/iecm/iecm_virtchnl.c line 10
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0@@ -0,0 +1,172 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#include "iecm.h" + +/** +* iecm_mb_clean - Reclaim the send mailbox queue entries +* @adapter: Driver specific private structure +* +* Reclaim the send mailbox queue entries to be used to send further messages
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +11
-0+* +* Returns 0 on success, negative on failure +*/ +static int iecm_mb_clean (struct iecm_adapter *adapter) +{ +u16 i, num_q_msg =IECM_DFLT_MBX_Q_LEN ; +struct iecm_ctlq_msg **q_msg; +struct iecm_dma_mem *dma_mem; +int err =0 ; + + q_msg = kcalloc(num_q_msg, sizeof(struct iecm_ctlq_msg *),
GFP_KERNEL);Quoted 34 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +11
-0+if (!q_msg) +return -ENOMEM ; + + err =iecm_ctlq_clean_sq (adapter->hw.asq, &num_q_msg, q_msg); +if (err) + goto error; + +for (i =0 ; i < num_q_msg; i++) { + dma_mem = q_msg[i]->ctx.indirect.payload; +if (dma_mem) + dmam_free_coherent(&adapter->pdev->dev, dma_mem-size,
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +22
-0+ dma_mem->va, dma_mem->pa); +kfree (q_msg[i]); +kfree (dma_mem); + } +error: +kfree (q_msg); +return err; +} + +/** +* iecm_find_ctlq - Given a type and id, find ctlq info +* @hw: hardware struct +* @type: type of ctrlq to find +* @id: ctlq id to find +* +* Returns pointer to found ctlq info struct, NULL otherwise. +*/ +static struct iecm_ctlq_info *iecm_find_ctlq (struct iecm_hw *hw, +enum iecm_ctlq_type type,int id) +{ +struct iecm_ctlq_info *cq, *tmp; +drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0+list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) { +if (cq->q_id == id && cq->cq_type == type) +return cq; + } + +return NULL ; +} + +/** +* iecm_init_dflt_mbx - Setup default mailbox parameters and make request
Quoted 31 lines
+ * @adapter: adapter info struct
+ *
+ * Returns 0 on success, negative otherwise
+ */drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +27
-0+int iecm_init_dflt_mbx (struct iecm_adapter *adapter) +{ +struct iecm_ctlq_create_info ctlq_info[] = { + { + .type =IECM_CTLQ_TYPE_MAILBOX_TX , + .id =IECM_DFLT_MBX_ID , + .len =IECM_DFLT_MBX_Q_LEN , + .buf_size =IECM_DFLT_MBX_BUF_SIZE + }, + { + .type =IECM_CTLQ_TYPE_MAILBOX_RX , + .id =IECM_DFLT_MBX_ID , + .len =IECM_DFLT_MBX_Q_LEN , + .buf_size =IECM_DFLT_MBX_BUF_SIZE + } + }; +struct iecm_hw *hw = &adapter->hw; +int err; + + adapter->dev_ops.reg_ops.ctlq_reg_init (ctlq_info); + +#define NUM_Q 2 + err =iecm_ctlq_init (hw,NUM_Q , ctlq_info); +if (err) +return err; + + hw->asq = iecm_find_ctlq(hw, IECM_CTLQ_TYPE_MAILBOX_TX,drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0+ IECM_DFLT_MBX_ID); + hw->arq =iecm_find_ctlq (hw,IECM_CTLQ_TYPE_MAILBOX_RX , +IECM_DFLT_MBX_ID ); + +if (!hw->asq || !hw->arq) { +iecm_ctlq_deinit (hw); +return -ENOENT ; + } + adapter->state = __IECM_STARTUP; +/* Skew the delay for init tasks for each function based on fn number
Quoted 1 line
+ * to prevent every function from making the same call
simulatenously.
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +12
-0+*/ +queue_delayed_work (adapter->init_wq, &adapter->init_task, +msecs_to_jiffies (5 * (adapter->pdev->devfn &0x07 ))); +return 0 ; +} + +/** +* iecm_deinit_dflt_mbx - Free up ctlqs setup +* @adapter: Driver specific private data structure +*/ +void iecm_deinit_dflt_mbx (struct iecm_adapter *adapter) +{drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0+if (adapter->hw.arq && adapter->hw.asq) { +iecm_mb_clean (adapter); +iecm_ctlq_deinit (&adapter->hw); + } + adapter->hw.arq =NULL ; + adapter->hw.asq =NULL ; +} + +/** +* iecm_vport_params_buf_alloc - Allocate memory for MailBox resources
Quoted 18 lines
+ * @adapter: Driver specific private data structure
+ *
+ * Will alloc memory to hold the vport parameters received on MailBox
+ */drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +14
-0+int iecm_vport_params_buf_alloc (struct iecm_adapter *adapter) +{ + adapter->vport_params_reqd =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (*adapter->vport_params_reqd), +GFP_KERNEL ); +if (!adapter->vport_params_reqd) +return -ENOMEM ; + + adapter->vport_params_recvd =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (*adapter->vport_params_recvd), +GFP_KERNEL ); +if (!adapter->vport_params_recvd) { +kfree (adapter->vport_params_reqd); +return -ENOMEM ;drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0+ } + +return 0 ; +} + +/** +* iecm_vport_params_buf_rel - Release memory for MailBox resources +* @adapter: Driver specific private data structure +* +* Will release memory to hold the vport parameters received on MailBox
Review
Quoted 17 lines
+ */
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +15
-0+void iecm_vport_params_buf_rel (struct iecm_adapter *adapter) +{ +int i =0 ; + +for (i =0 ; i <IECM_MAX_NUM_VPORTS ; i++) { +kfree (adapter->vport_params_recvd[i]); +kfree (adapter->vport_params_reqd[i]); + } + +kfree (adapter->vport_params_recvd); +kfree (adapter->vport_params_reqd); + +kfree (adapter->caps); +kfree (adapter->config_data.req_qs_chunks); +}(quoted diff) +0
-0
b/drivers/net/ethernet/intel/include/iecm.hQuoted 8 lines
index
e19e014e9817..ca9029224e06100644drivers/net/ethernet/intel/include/iecm.h +1
-0@@ -12,15 +12,33 @@#include <linux/dim.h> #include "iecm_txrx.h" +#include "iecm_controlq.h" drivers/net/ethernet/intel/include/iecm.h line 25
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +6
-0#define IECM_BAR0 0#define IECM_NO_FREE_SLOT 0xffff +/* Default Mailbox settings */ +#define IECM_DFLT_MBX_BUF_SIZE (4 * 1024) +#define IECM_NUM_QCTX_PER_MSG 3 +#define IECM_NUM_FILTERS_PER_MSG 20 +#define IECM_VLANS_PER_MSG \ + ((IECM_DFLT_MBX_BUF_SIZE - sizeof(struct
virtchnl_vlan_filter_list)) \drivers/net/ethernet/intel/include/iecm.h
Quoted 6 lines
drivers/net/ethernet/intel/include/iecm.h +6
-0+ / sizeof(u16)) +#define IECM_DFLT_MBX_Q_LEN 64 +#define IECM_DFLT_MBX_ID -1 +/* maximum number of times to try before resetting mailbox */ +#define IECM_MB_MAX_ERR 20 +#define IECM_NUM_CHUNKS_PER_MSG (a, b)((
IECM_DFLT_MBX_BUF_SIZE- (a)) / (b))drivers/net/ethernet/intel/include/iecm.h
Quoted 5 lines
drivers/net/ethernet/intel/include/iecm.h +1
-0+#define IECM_MAX_NUM_VPORTS 1/* available message levels */ #define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE |
NETIF_MSG_LINK)Quoted 40 lines
drivers/net/ethernet/intel/include/iecm.h +21
-0+/* Forward declaration */ +struct iecm_adapter ; +struct iecm_vport ; +enum iecm_state { __IECM_STARTUP, __IECM_VER_CHECK,@@ -77,6 +95,22 @@ struct iecm_reset_reg {u32 rstat_m; }; +/* product specific register API */ +struct iecm_reg_ops { +void (*ctlq_reg_init)(struct iecm_ctlq_create_info *cq); +int (*intr_reg_init)(struct iecm_vport *vport); +void (*mb_intr_reg_init)(struct iecm_adapter *adapter); +void (*reset_reg_init)(struct iecm_reset_reg *reset_reg); +void (*trigger_reset)(struct iecm_adapter *adapter, +enum iecm_flags trig_cause); +}; + +struct iecm_dev_ops { +void (*reg_ops_init)(struct iecm_adapter *adapter); +void (*crc_enable)(u64 *td_cmd); +struct iecm_reg_ops reg_ops; +}; +/* stub */ struct iecm_vport { };@@ -124,6 +158,7 @@ struct iecm_adapter {DECLARE_BITMAP (flags, __IECM_FLAGS_NBITS);struct mutex reset_lock;/* lock to protect reset flows */ struct iecm_reset_reg reset_reg; +struct iecm_hw hw;u16 num_req_msix;u16 num_msix_entries;drivers/net/ethernet/intel/include/iecm.h struct iecm_adapter { · line 196
Quoted 6 lines
drivers/net/ethernet/intel/include/iecm.h +1
-0@@ -156,6 +191,7 @@ struct iecm_adapter {wait_queue_head_t vchnl_wq;wait_queue_head_t sw_marker_wq;struct iecm_rss_data rss_data; +struct iecm_dev_ops dev_ops;s32 link_speed;/* This is only populated if the VIRTCHNL_VF_CAP_ADV_LINK_SPEED is set
drivers/net/ethernet/intel/include/iecm.h struct iecm_adapter { · line 197
Quoted 1 line
drivers/net/ethernet/intel/include/iecm.h +0
-0* in vf_res->vf_cap_flags. This field should be used going forward and
drivers/net/ethernet/intel/include/iecm.h struct iecm_adapter { · line 222
Quoted 9 lines
drivers/net/ethernet/intel/include/iecm.h +5
-0@@ -179,8 +215,24 @@ struct iecm_adapter {spinlock_t fdir_fltr_list_lock; }; +/** +* iecm_is_reset_detected - check if we were reset at some point +* @adapter: driver specific private structure +* +* Returns true if we are either in reset currently or were previously reset.
Review
Quoted 17 lines
drivers/net/ethernet/intel/include/iecm.h +11
-0+*/ +static inline bool iecm_is_reset_detected (struct iecm_adapter *adapter) +{ +return !(rd32 (&adapter->hw, adapter->hw.arq->reg.len) & + adapter->hw.arq->reg.len_ena_mask); +} +int iecm_probe (struct pci_dev *pdev,const struct pci_device_id __always_unused *ent,struct iecm_adapter *adapter);void iecm_remove (struct pci_dev *pdev); +int iecm_init_dflt_mbx (struct iecm_adapter *adapter); +void iecm_deinit_dflt_mbx (struct iecm_adapter *adapter); +int iecm_vport_params_buf_alloc (struct iecm_adapter *adapter); +void iecm_vport_params_buf_rel (struct iecm_adapter *adapter);#endif /* !_IECM_H_ */ (quoted diff) +0
-0
b/drivers/net/ethernet/intel/include/iecm_controlq.hQuoted 14 lines
new file mode 100644
index 000000000000..f2539baa2ce1drivers/net/ethernet/intel/include/iecm_controlq.h new file +9
-0@@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020, Intel Corporation. */ + +#ifndef _IECM_CONTROLQ_H_ +#define _IECM_CONTROLQ_H_ + +#include <linux/slab.h> + +#include "iecm_controlq_api.h" drivers/net/ethernet/intel/include/iecm_controlq.h line 19
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +10
-0+ +/* Maximum buffer lengths for all control queue types */ +#define IECM_CTLQ_MAX_RING_SIZE 1024 +#define IECM_CTLQ_MAX_BUF_LEN 4096 + +#define IECM_CTLQ_DESC (R , i) \ + (&(((struct iecm_ctlq_desc *)((R)->desc_ring.va))[i])) + +#define IECM_CTLQ_DESC_UNUSED (R ) \ + ((u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->ring_size)+ \
Quoted 4 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +4
-0+ (R)->next_to_clean - (R)->next_to_use - 1)) + +/* Control Queue default settings */ +#define IECM_CTRL_SQ_CMD_TIMEOUT 250/* msecs */ drivers/net/ethernet/intel/include/iecm_controlq.h
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +10
-0+ +struct iecm_ctlq_desc { +__le16 flags; +__le16 opcode; +__le16 datalen;/* 0 for direct commands */ +union { +__le16 ret_val; +__le16 pfid_vfid; +#define IECM_CTLQ_DESC_VF_ID_S 0 +#define IECM_CTLQ_DESC_VF_ID_M (0x7FF <<
IECM_CTLQ_DESC_VF_ID_S)drivers/net/ethernet/intel/include/iecm_controlq.h line 35
Quoted 2 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +2
-0+#define IECM_CTLQ_DESC_PF_ID_S 11 +#define IECM_CTLQ_DESC_PF_ID_M (0x1F <<
IECM_CTLQ_DESC_PF_ID_S)Quoted 24 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +24
-0+ }; +__le32 cookie_high; +__le32 cookie_low; +union { +struct { +__le32 param0; +__le32 param1; +__le32 param2; +__le32 param3; + } direct; +struct { +__le32 param0; +__le32 param1; +__le32 addr_high; +__le32 addr_low; + } indirect; +u8 raw[16 ]; + } params; +}; + +/* Flags sub-structure +* |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |10 |11 |12 |13 |14 |15 | +* |DD |CMP|ERR| * RSV * |FTYPE | *RSV* |RD |VFC|BUF| * RSV * | +*/ drivers/net/ethernet/intel/include/iecm_controlq.h
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +10
-0+/* command flags and offsets */ +#define IECM_CTLQ_FLAG_DD_S 0 +#define IECM_CTLQ_FLAG_CMP_S 1 +#define IECM_CTLQ_FLAG_ERR_S 2 +#define IECM_CTLQ_FLAG_FTYPE_S 6 +#define IECM_CTLQ_FLAG_RD_S 10 +#define IECM_CTLQ_FLAG_VFC_S 11 +#define IECM_CTLQ_FLAG_BUF_S 12 + +#define IECM_CTLQ_FLAG_DD BIT(IECM_CTLQ_FLAG_DD_S)/*
0x1*/drivers/net/ethernet/intel/include/iecm_controlq.h line 70
Quoted 1 line
drivers/net/ethernet/intel/include/iecm_controlq.h new file +1
-0+#define IECM_CTLQ_FLAG_CMP BIT(IECM_CTLQ_FLAG_CMP_S)/*
0x2*/drivers/net/ethernet/intel/include/iecm_controlq.h line 71
Quoted 1 line
drivers/net/ethernet/intel/include/iecm_controlq.h new file +1
-0+#define IECM_CTLQ_FLAG_ERR BIT(IECM_CTLQ_FLAG_ERR_S)/*
0x4*/drivers/net/ethernet/intel/include/iecm_controlq.h line 72
Quoted 1 line
drivers/net/ethernet/intel/include/iecm_controlq.h new file +1
-0+#define IECM_CTLQ_FLAG_FTYPE_VM
BIT(IECM_CTLQ_FLAG_FTYPE_S)/*0x40*/drivers/net/ethernet/intel/include/iecm_controlq.h line 73
Quoted 1 line
drivers/net/ethernet/intel/include/iecm_controlq.h new file +1
-0+#define IECM_CTLQ_FLAG_FTYPE_PF BIT(IECM_CTLQ_FLAG_FTYPE_S+ 1) /*
0x80*/drivers/net/ethernet/intel/include/iecm_controlq.h line 74
Quoted 1 line
drivers/net/ethernet/intel/include/iecm_controlq.h new file +1
-0+#define IECM_CTLQ_FLAG_RD BIT(IECM_CTLQ_FLAG_RD_S)/*
0x400*/drivers/net/ethernet/intel/include/iecm_controlq.h line 75
Quoted 1 line
drivers/net/ethernet/intel/include/iecm_controlq.h new file +1
-0+#define IECM_CTLQ_FLAG_VFC BIT(IECM_CTLQ_FLAG_VFC_S)/*
0x800*/drivers/net/ethernet/intel/include/iecm_controlq.h line 76
Quoted 1 line
drivers/net/ethernet/intel/include/iecm_controlq.h new file +1
-0+#define IECM_CTLQ_FLAG_BUF BIT(IECM_CTLQ_FLAG_BUF_S)/*
0x1000*/drivers/net/ethernet/intel/include/iecm_controlq.h
Quoted 9 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +9
-0+ +struct iecm_mbxq_desc { +u8 pad[8 ];/* CTLQ flags/opcode/len/retval fields */ +u32 chnl_opcode;/* avoid confusion with desc->opcode */ +u32 chnl_retval;/* ditto for desc->retval */ +u32 pf_vf_id;/* used by CP when sending to PF */ +}; + +/* Define the APF hardware struct to replace other control structs as needed
Quoted 16 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +16
-0+* Align to ctlq_hw_info +*/ +struct iecm_hw { +u8 __iomem *hw_addr; +u64 hw_addr_len; +void *back; + +/* control queue - send and receive */ +struct iecm_ctlq_info *asq; +struct iecm_ctlq_info *arq; + +/* pci info */ +u16 device_id; +u16 vendor_id; +u16 subsystem_device_id; +u16 subsystem_vendor_id;drivers/net/ethernet/intel/include/iecm_controlq.h
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +10
-0+u8 revision_id; +bool adapter_stopped; + +struct list_head cq_list_head; +}; + +int iecm_ctlq_alloc_ring_res (struct iecm_hw *hw, +struct iecm_ctlq_info *cq); + +void iecm_ctlq_dealloc_ring_res(struct iecm_hw *hw, struct
iecm_ctlq_info*cq);drivers/net/ethernet/intel/include/iecm_controlq.h
Quoted 3 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +3
-0+ +/* prototype for functions used for dynamic memory allocation */ +void *iecm_alloc_dma_mem(struct iecm_hw *hw, struct
iecm_dma_mem*mem,drivers/net/ethernet/intel/include/iecm_controlq.h line 116
Quoted 2 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +2
-0+ u64 size); +void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem*mem);
Review
Quoted 2 lines
drivers/net/ethernet/intel/include/iecm_controlq.h new file +1
-0+#endif /* _IECM_CONTROLQ_H_ */ (quoted diff) +0
-0
b/drivers/net/ethernet/intel/include/iecm_controlq_api.hQuoted 139 lines
new file mode 100644
index 000000000000..5f624f005d33drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +134
-0@@ -0,0 +1,185 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2020, Intel Corporation. */ + +#ifndef _IECM_CONTROLQ_API_H_ +#define _IECM_CONTROLQ_API_H_ + +#include "iecm_mem.h" + +struct iecm_hw ; + +/* Used for queue init, response and events */ +enum iecm_ctlq_type { +IECM_CTLQ_TYPE_MAILBOX_TX =0 , +IECM_CTLQ_TYPE_MAILBOX_RX =1 , +IECM_CTLQ_TYPE_CONFIG_TX =2 , +IECM_CTLQ_TYPE_CONFIG_RX =3 , +IECM_CTLQ_TYPE_EVENT_RX =4 , +IECM_CTLQ_TYPE_RDMA_TX =5 , +IECM_CTLQ_TYPE_RDMA_RX =6 , +IECM_CTLQ_TYPE_RDMA_COMPL =7 +}; + +/* Generic Control Queue Structures */ +struct iecm_ctlq_reg { +/* used for queue tracking */ +u32 head; +u32 tail; +/* Below applies only to default mb (if present) */ +u32 len; +u32 bah; +u32 bal; +u32 len_mask; +u32 len_ena_mask; +u32 head_mask; +}; + +/* Generic queue msg structure */ +struct iecm_ctlq_msg { +u16 vmvf_type;/* represents the source of the message on recv */ +#define IECM_VMVF_TYPE_VF 0 +#define IECM_VMVF_TYPE_VM 1 +#define IECM_VMVF_TYPE_PF 2 +u16 opcode; +u16 data_len;/* data_len = 0 when no payload is attached */ +union { +u16 func_id;/* when sending a message */ +u16 status;/* when receiving a message */ + }; +union { +struct { +u32 chnl_retval; +u32 chnl_opcode; + } mbx; + } cookie; +union { +#define IECM_DIRECT_CTX_SIZE 16 +#define IECM_INDIRECT_CTX_SIZE 8 +/* 16 bytes of context can be provided or 8 bytes of context +* plus the address of a DMA buffer +*/ +u8 direct[IECM_DIRECT_CTX_SIZE ]; +struct { +u8 context[IECM_INDIRECT_CTX_SIZE ]; +struct iecm_dma_mem *payload; + } indirect; + } ctx; +}; + +/* Generic queue info structures */ +/* MB, CONFIG and EVENT q do not have extended info */ +struct iecm_ctlq_create_info { +enum iecm_ctlq_type type; +int id;/* absolute queue offset passed as input +* -1 for default mailbox if present +*/ +u16 len;/* Queue length passed as input */ +u16 buf_size;/* buffer size passed as input */ +u64 base_address;/* output, HPA of the Queue start */ +struct iecm_ctlq_reg reg;/* registers accessed by ctlqs */ + +int ext_info_size; +void *ext_info;/* Specific to q type */ +}; + +/* Control Queue information */ +struct iecm_ctlq_info { +struct list_head cq_list; + +enum iecm_ctlq_type cq_type; +int q_id; +/* control queue lock */ +struct mutex cq_lock; + +/* used for interrupt processing */ +u16 next_to_use; +u16 next_to_clean; +u16 next_to_post;/* starting descriptor to post buffers +* to after recev +*/ + +struct iecm_dma_mem desc_ring;/* descriptor ring memory +* iecm_dma_mem is defined in OSdep.h +*/ +union { +struct iecm_dma_mem **rx_buff; +struct iecm_ctlq_msg **tx_msg; + } bi; + +u16 buf_size;/* queue buffer size */ +u16 ring_size;/* Number of descriptors */ +struct iecm_ctlq_reg reg;/* registers accessed by ctlqs */ +}; + +/* PF/VF mailbox commands */ +enum iecm_mbx_opc { +/* iecm_mbq_opc_send_msg_to_pf: +* usage: used by PF or VF to send a message to its CPF +* target: RX queue and function ID of parent PF taken from HW +*/ + iecm_mbq_opc_send_msg_to_pf =0x0801 , + +/* iecm_mbq_opc_send_msg_to_vf: +* usage: used by PF to send message to a VF +* target: VF control queue ID must be specified in descriptor +*/ + iecm_mbq_opc_send_msg_to_vf =0x0802 , + +/* iecm_mbq_opc_send_msg_to_peer_pf: +* usage: used by any function to send message to any peer PF +* target: RX queue and host of parent PF taken from HW +*/ + iecm_mbq_opc_send_msg_to_peer_pf =0x0803 , + +/* iecm_mbq_opc_send_msg_to_peer_drv: drivers/net/ethernet/intel/include/iecm_controlq_api.h line 144
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +10
-0+* usage: used by any function to send message to any peer driver +* target: RX queue and target host must be specific in descriptor +*/ + iecm_mbq_opc_send_msg_to_peer_drv = 0x0804, +}; + +/* API support for control queue management */ + +/* Will init all required q including default mb. "q_info" is an array of +* create_info structs equal to the number of control queues to be created.
drivers/net/ethernet/intel/include/iecm_controlq_api.h
Quoted 5 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +5
-0+*/ +int iecm_ctlq_init (struct iecm_hw *hw,u8 num_q, +struct iecm_ctlq_create_info *q_info); + +/* Allocate and initialize a single control queue, which will be added to the
Review
Quoted 37 lines
drivers/net/ethernet/intel/include/iecm_controlq_api.h new file +36
-0+* control queue list; returns a handle to the created control queue +*/ +int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq); + +/* Deinitialize and deallocate a single control queue */ +void iecm_ctlq_remove (struct iecm_hw *hw, +struct iecm_ctlq_info *cq); + +/* Sends messages to HW and will also free the buffer*/ +int iecm_ctlq_send (struct iecm_hw *hw, +struct iecm_ctlq_info *cq, +u16 num_q_msg, +struct iecm_ctlq_msg q_msg[]); + +/* Receives messages and called by interrupt handler/polling +* initiated by app/process. Also caller is supposed to free the buffers +*/ +int iecm_ctlq_recv (struct iecm_ctlq_info *cq,u16 *num_q_msg, +struct iecm_ctlq_msg *q_msg); + +/* Reclaims send descriptors on HW write back */ +int iecm_ctlq_clean_sq (struct iecm_ctlq_info *cq,u16 *clean_count, +struct iecm_ctlq_msg *msg_status[]); + +/* Indicate RX buffers are done being processed */ +int iecm_ctlq_post_rx_buffs (struct iecm_hw *hw, +struct iecm_ctlq_info *cq, +u16 *buff_count, +struct iecm_dma_mem **buffs); + +/* Will destroy all q including the default mb */ +int iecm_ctlq_deinit (struct iecm_hw *hw); + +#endif /* _IECM_CONTROLQ_API_H_ */ (quoted diff) +0
-0
b/drivers/net/ethernet/intel/include/iecm_mem.hQuoted 32 lines
new file mode 100644
index 000000000000..064dd6e10c24drivers/net/ethernet/intel/include/iecm_mem.h new file +20
-1@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2019 Intel Corporation */ + +#ifndef _IECM_MEM_H_ +#define _IECM_MEM_H_ + +#include <linux/io.h> + +struct iecm_dma_mem { +void *va; +dma_addr_t pa; +size_t size; +}; + +#define wr32 (a, reg, value) writel((value), ((a)->hw_addr + (reg))) +#define rd32 (a, reg) readl((a)->hw_addr + (reg)) +#define wr64 (a, reg, value) writeq((value), ((a)->hw_addr + (reg))) +#define rd64 (a, reg) readq((a)->hw_addr + (reg)) + +#endif /* _IECM_MEM_H_ */ --2.33.0
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Brady
PATCH 4/19 iecm: add api_init and controlq init
Quoted 25 lines
-----Original Message-----
From: Brady, Alan
Sent: Wednesday, February 2, 2022 7:25 PM
To: Shannon Nelson <[email protected]>
Cc: Intel Wired LAN <[email protected]>; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: RE: [Intel-wired-lan] [PATCH net-next 04/19] iecm: addapi_initand controlq initQuoted 6 lines
-----Original Message-----
From: Shannon Nelson <[email protected]>
Sent: Tuesday, February 1, 2022 1:27 PM
To: Brady, Alan <[email protected]>
Cc: Intel Wired LAN <[email protected]>; Burra, Phani R <[email protected]>; Chittim, MadhuQuoted 2 lines
Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 04/19] iecm: addapi_initand
Quoted 5 lines
controlq init
Quoted 1 line · Alan Brady
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.
At the end of probe we kicked off a hard reset and this implements
what's
Quoted 8 lines
Quoted 8 lines
needed to handle that reset and continue init.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>---
<snip/>
Quoted 54 lines
Quoted 7 lines
Quoted 7 lines
+/**
+ *iecm_ctlq_add- add one control queue
+ * @hw: pointer to hardware struct
+ * @qinfo: info for queue to be created
+ * @cq_out: (output) double pointer to control queue to be created
+ *
+ * Allocate and initialize a control queue and add it to the controlqueue
Quoted 20 lines
list.
Quoted 1 line
+ * The cq parameter will be allocated/initialized and passed back to the
caller
Quoted 3 lines
+ * if no errors occur.
+ *
+ * Note:iecm_ctlq_initmust be called prior to any calls to
iecm_ctlq_addQuoted 13 lines
+ */
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +12
-0+int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq_out) +{ +bool is_rxq = false; +int status =0 ; + +if (!qinfo->len || !qinfo->buf_size || + qinfo->len >IECM_CTLQ_MAX_RING_SIZE || + qinfo->buf_size >IECM_CTLQ_MAX_BUF_LEN ) +return -EINVAL ; +Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 141
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +3
-0+ *cq_out =kcalloc (1 ,sizeof (struct iecm_ctlq_info ),GFP_KERNEL ); +if (!(*cq_out)) +return -ENOMEM ;You might keep this as a local variable until you get to a successful end, then set
*cq_outwhen done.
Else, you need to be sure to clear it back to NULL on error return to be sure no one uses a bogus value.This one I'm not sure I follow. If it's NULL we fall into the
if(!*cq_out)and don't need to set it to NULL (it already is?). If it's not NULL then we go on to use it like a valid memory address so I hope it's valid.Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +12
-0+ + (*cq_out)->cq_type = qinfo->type; + (*cq_out)->q_id = qinfo->id; + (*cq_out)->buf_size = qinfo->buf_size; + (*cq_out)->ring_size = qinfo->len; + + (*cq_out)->next_to_use =0 ; + (*cq_out)->next_to_clean =0 ; + (*cq_out)->next_to_post = (*cq_out)->ring_size -1 ; + +switch (qinfo->type) { +case IECM_CTLQ_TYPE_MAILBOX_RX :
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 161
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +8
-0+ is_rxq = true; + fallthrough; +case IECM_CTLQ_TYPE_MAILBOX_TX : + status =iecm_ctlq_alloc_ring_res (hw, *cq_out); +break ; +default : + status = -EBADR ; +break ;
Ah wait I think I understand, if we end up in error state later in the function like here we probably shouldn't be giving the memory back to the caller. Will fix.
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +25
-0+ } + +if (status) + goto init_free_q; + +if (is_rxq) { +iecm_ctlq_init_rxq_bufs (*cq_out); + }else { +/* Allocate the array of msg pointers for TX queues */ + (*cq_out)->bi.tx_msg =kcalloc (qinfo->len, +sizeof (struct iecm_ctlq_msg *), +GFP_KERNEL ); +if (!(*cq_out)->bi.tx_msg) { + status = -ENOMEM ; + goto init_dealloc_q_mem; + } + } + +iecm_ctlq_setup_regs (*cq_out, qinfo); + +iecm_ctlq_init_regs (hw, *cq_out, is_rxq); + +mutex_init (&(*cq_out)->cq_lock); + +list_add (&(*cq_out)->cq_list, &hw->cq_list_head);
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 194
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +8
-0+ +return status; + +init_dealloc_q_mem: +/* free ring buffers and the ring itself */ +iecm_ctlq_dealloc_ring_res (hw, *cq_out); +init_free_q: +kfree (*cq_out);
.
Quoted 8 lines
Quoted 1 line
Will fix.
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 198
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +4
-0+ +return status; +} +
<snip/>
PATCH 4/19 iecm: add api_init and controlq init
Quoted 100 lines · Alan
Quoted 26 lines
-----Original Message-----
From: Brady, Alan
Sent: Wednesday, February 2, 2022 7:25 PM
To: Shannon Nelson <[email protected]>
Cc: Intel Wired LAN <[email protected]>; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: RE: [Intel-wired-lan] [PATCH net-next 04/19] iecm: addapi_initand controlq initQuoted 6 lines
-----Original Message-----
From: Shannon Nelson <[email protected]>
Sent: Tuesday, February 1, 2022 1:27 PM
To: Brady, Alan <[email protected]>
Cc: Intel Wired LAN <[email protected]>; Burra, Phani R <[email protected]>; Chittim, MadhuQuoted 2 lines
Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 04/19] iecm: addapi_initand
Quoted 5 lines
controlq init
Quoted 1 line · Alan Brady
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.
At the end of probe we kicked off a hard reset and this implements
what's
Quoted 8 lines
Quoted 8 lines
needed to handle that reset and continue init.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>---
<snip/>
Quoted 56 lines
Quoted 7 lines
Quoted 7 lines
+/**
+ *iecm_ctlq_add- add one control queue
+ * @hw: pointer to hardware struct
+ * @qinfo: info for queue to be created
+ * @cq_out: (output) double pointer to control queue to be created
+ *
+ * Allocate and initialize a control queue and add it to the controlqueue
Quoted 20 lines
list.
Quoted 1 line
+ * The cq parameter will be allocated/initialized and passed back to the
caller
Quoted 3 lines
+ * if no errors occur.
+ *
+ * Note:iecm_ctlq_initmust be called prior to any calls to
iecm_ctlq_addQuoted 13 lines
+ */
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +12
-0+int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq_out) +{ +bool is_rxq = false; +int status =0 ; + +if (!qinfo->len || !qinfo->buf_size || + qinfo->len >IECM_CTLQ_MAX_RING_SIZE || + qinfo->buf_size >IECM_CTLQ_MAX_BUF_LEN ) +return -EINVAL ; +Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 141
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +3
-0+ *cq_out =kcalloc (1 ,sizeof (struct iecm_ctlq_info ),GFP_KERNEL ); +if (!(*cq_out)) +return -ENOMEM ;You might keep this as a local variable until you get to a successful end, then set
*cq_outwhen done.
Else, you need to be sure to clear it back to NULL on error return to be sure no one uses a bogus value.This one I'm not sure I follow. If it's NULL we fall into the
if(!*cq_out)and don't need to set it to NULL (it already is?). If it's not NULL then we go on to use it like a valid memory address so I hope it's valid.Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +14
-0+ + (*cq_out)->cq_type = qinfo->type; + (*cq_out)->q_id = qinfo->id; + (*cq_out)->buf_size = qinfo->buf_size; + (*cq_out)->ring_size = qinfo->len; + + (*cq_out)->next_to_use =0 ; + (*cq_out)->next_to_clean =0 ; + (*cq_out)->next_to_post = (*cq_out)->ring_size -1 ; + +switch (qinfo->type) { +case IECM_CTLQ_TYPE_MAILBOX_RX : + is_rxq = true; + fallthrough;
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 161
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+case IECM_CTLQ_TYPE_MAILBOX_TX : + status =iecm_ctlq_alloc_ring_res (hw, *cq_out); +break ; +default : + status = -EBADR ; +break ;Ah wait I think I understand, if we end up in error state later in the function like here we probably shouldn't be giving the memory back to the caller. Will fix.
Right. If you store the pointer in a local variable first, then you can do the final assignment to *cq_out at the end once you know that all is done and safe.
Some folks might thinik that at the end they could just set *cq_out back to NULL if there was an error, but I think it is safer and less of a surprise to leave the caller's data alone until we have a happy answer.
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +18
-0+ } + +if (status) + goto init_free_q; + +if (is_rxq) { +iecm_ctlq_init_rxq_bufs (*cq_out); + }else { +/* Allocate the array of msg pointers for TX queues */ + (*cq_out)->bi.tx_msg =kcalloc (qinfo->len, +sizeof (struct iecm_ctlq_msg *), +GFP_KERNEL ); +if (!(*cq_out)->bi.tx_msg) { + status = -ENOMEM ; + goto init_dealloc_q_mem; + } + } +
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 187
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +8
-0+iecm_ctlq_setup_regs (*cq_out, qinfo); + +iecm_ctlq_init_regs (hw, *cq_out, is_rxq); + +mutex_init (&(*cq_out)->cq_lock); + +list_add (&(*cq_out)->cq_list, &hw->cq_list_head); +
Here you can set *cq_out = local_ptr;
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 194
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +7
-0+return status; + +init_dealloc_q_mem: +/* free ring buffers and the ring itself */ +iecm_ctlq_dealloc_ring_res (hw, *cq_out); +init_free_q: +kfree (*cq_out);
Here you would kfree() your local pointer
sln
Quoted 11 lines
.
Quoted 8 lines
Quoted 1 line
Will fix.
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 198
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +4
-0+ +return status; +} +<snip/>
PATCH 4/19 iecm: add api_init and controlq init
In reply to BradyFrom: Alan Brady <[email protected]>
Date: Thu, 3 Feb 2022 03:24:57 +0000
Quoted 1 line
In-Reply-To: <CO1PR11MB518657515DD2AEBF539B9B768F289@CO1PR11MB5186.namprd11.prod.outlook.com>
Hmm, I wouldn't use Outlook for replying to patches discussion. Apart from breaking the original code formatting, messages with Outlook in X-mailer often get rejected from upstream vger.kernel.org mailing lists.
Quoted 231 lines
Quoted 147 lines
-----Original Message-----
From: Shannon Nelson <[email protected]>
Sent: Tuesday, February 1, 2022 1:27 PM
To: Brady, Alan <[email protected]>
Cc: Intel Wired LAN <[email protected]>; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 04/19] iecm: addapi_initand controlq initQuoted 9 lines · Alan Brady
Initializing device registers is offloaded into function pointers given to iecm from the dependent device driver for a given device, as offsets can vary wildly. This also adds everything needed to setup and use a controlq which uses some of those registers.
At the end of probe we kicked off a hard reset and this implements what's needed to handle that reset and continue init.
Quoted 8 lines
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 3 + .../net/ethernet/intel/iecm/iecm_controlq.c | 649++++++++++++++++++
Quoted 10 lines
.../ethernet/intel/iecm/iecm_controlq_setup.c | 175 +++++ drivers/net/ethernet/intel/iecm/iecm_lib.c | 191 +++++- .../net/ethernet/intel/iecm/iecm_virtchnl.c | 172 +++++ drivers/net/ethernet/intel/include/iecm.h | 52 ++ .../ethernet/intel/include/iecm_controlq.h | 117 ++++ .../intel/include/iecm_controlq_api.h | 185 +++++ drivers/net/ethernet/intel/include/iecm_mem.h | 20 + 9 files changed, 1563 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_controlq.c create mode 100644
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.cQuoted 3 lines
create mode 100644 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c create mode 100644 drivers/net/ethernet/intel/include/iecm_controlq.h create mode 100644
drivers/net/ethernet/intel/include/iecm_controlq_api.hReview
Quoted 3 lines
create mode 100644 drivers/net/ethernet/intel/include/iecm_mem.h(quoted diff) +0
-0b/drivers/net/ethernet/intel/iecm/Makefile
drivers/net/ethernet/intel/iecm/Makefile ccflags-y += -
Quoted 4 lines
index
4f497723419d..db8fecb075a6100644drivers/net/ethernet/intel/iecm/Makefile +0
-0@@ -11,4 +11,7 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include
Review
Quoted 8 lines
drivers/net/ethernet/intel/iecm/Makefile +3
-0iecm-y := \ iecm_lib.o \ + iecm_virtchnl.o \ + iecm_controlq.o \ + iecm_controlq_setup.o \ iecm_main.o(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_controlq.cQuoted 5 lines
new file mode 100644
index 000000000000..f9682a7b3e44drivers/net/ethernet/intel/iecm/iecm_controlq.c line 9
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +9
-0@@ -0,0 +1,649 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2020, Intel Corporation. */ + +#include "iecm_controlq.h" + +/** +* iecm_ctlq_setup_regs - initialize control queue registers +* @cq: pointer to the specific control queue +* @q_create_info: structs containing info for each queue to be initialized
Quoted 16 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +16
-0+*/ +static void +iecm_ctlq_setup_regs (struct iecm_ctlq_info *cq, +struct iecm_ctlq_create_info *q_create_info) +{ +/* set head and tail registers in our local struct */ + cq->reg.head = q_create_info->reg.head; + cq->reg.tail = q_create_info->reg.tail; + cq->reg.len = q_create_info->reg.len; + cq->reg.bah = q_create_info->reg.bah; + cq->reg.bal = q_create_info->reg.bal; + cq->reg.len_mask = q_create_info->reg.len_mask; + cq->reg.len_ena_mask = q_create_info->reg.len_ena_mask; + cq->reg.head_mask = q_create_info->reg.head_mask; +} +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+/** +* iecm_ctlq_init_regs - Initialize control queue registers +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* @is_rxq: true if receive control queue, false otherwise +* +* Initialize registers. The caller is expected to have already initialized the +* descriptor ring memory and buffer memory +*/ +static void iecm_ctlq_init_regs(struct iecm_hw *hw, struct
iecm_ctlq_info*cq,Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +14
-0+ bool is_rxq) +{ +/* Update tail to post pre-allocated buffers for rx queues */ +if (is_rxq) +wr32 (hw, cq->reg.tail, (u32)(cq->ring_size -1 )); + +/* For non-Mailbox control queues only TAIL need to be set */ +if (cq->q_id !=-1 ) +return ; + +/* Clear Head for both send or receive */ +wr32 (hw, cq->reg.head,0 ); + +/* set starting point */ drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+wr32 (hw, cq->reg.bal,lower_32_bits (cq->desc_ring.pa)); +wr32 (hw, cq->reg.bah,upper_32_bits (cq->desc_ring.pa)); +wr32 (hw, cq->reg.len, (cq->ring_size | cq->reg.len_ena_mask)); +} + +/** +* iecm_ctlq_init_rxq_bufs - populate receive queue descriptors with buf +* @cq: pointer to the specific Control queue +* +* Record the address of the receive queue DMA buffers in the descriptors.
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+* The buffers must have been previously allocated. +*/ +static void iecm_ctlq_init_rxq_bufs (struct iecm_ctlq_info *cq) +{ +int i =0 ; +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+for (i =0 ; i < cq->ring_size; i++) { +struct iecm_ctlq_desc *desc =IECM_CTLQ_DESC (cq, i); +struct iecm_dma_mem *bi = cq->bi.rx_buff[i]; + +/* No buffer to post to descriptor, continue */ +if (!bi) +continue ; + + desc->flags = + cpu_to_le16(IECM_CTLQ_FLAG_BUF |
IECM_CTLQ_FLAG_RD);Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 77
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+ desc->opcode =0 ; + desc->datalen = (__le16 )cpu_to_le16 (bi->size);Why the typecast to
__le16, aren't we there already with thecpu_to_le16()?Yeah this is weird. Will fix.
Quoted 65 lines
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ desc->ret_val =0 ; + desc->cookie_high =0 ; + desc->cookie_low =0 ; + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (bi->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (bi->pa)); + desc->params.indirect.param0 =0 ; + desc->params.indirect.param1 =0 ; + }drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+} + +/** +* iecm_ctlq_shutdown - shutdown the CQ +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* The main shutdown routine for any controq queue +*/ +static void iecm_ctlq_shutdown(struct iecm_hw *hw, struct
iecm_ctlq_info*cq)Quoted 14 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +14
-0+{ +mutex_lock (&cq->cq_lock); + +if (!cq->ring_size) + goto shutdown_sq_out; + +/* free ring buffers and the ring itself */ +iecm_ctlq_dealloc_ring_res (hw, cq); + +/* Set ring_size to 0 to indicate uninitialized queue */ + cq->ring_size =0 ; + +shutdown_sq_out: +mutex_unlock (&cq->cq_lock);drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+mutex_destroy (&cq->cq_lock); +} + +/** +* iecm_ctlq_add - add one control queue +* @hw: pointer to hardware struct +* @qinfo: info for queue to be created +* @cq_out: (output) double pointer to control queue to be created +* +* Allocate and initialize a control queue and add it to the control queue list.
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 122
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* The cq parameter will be allocated/initialized and passed back to the caller
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +3
-0+* if no errors occur. +* +* Note: iecm_ctlq_init must be called prior to any calls to
iecm_ctlq_addQuoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +13
-0+*/ +int iecm_ctlq_add (struct iecm_hw *hw, +struct iecm_ctlq_create_info *qinfo, +struct iecm_ctlq_info **cq_out) +{ +bool is_rxq = false; +int status =0 ; + +if (!qinfo->len || !qinfo->buf_size || + qinfo->len >IECM_CTLQ_MAX_RING_SIZE || + qinfo->buf_size >IECM_CTLQ_MAX_BUF_LEN ) +return -EINVAL ; +Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 141
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +3
-0+ *cq_out =kcalloc (1 ,sizeof (struct iecm_ctlq_info ),GFP_KERNEL ); +if (!(*cq_out)) +return -ENOMEM ;You might keep this as a local variable until you get to a successful end, then set
*cq_outwhen done.
Else, you need to be sure to clear it back to NULL on error return to be sure no one uses a bogus value.
Quoted 1 line
This one I'm not sure I follow. If it's NULL we fall into the
if(!*cq_out)and don't need to set it to NULL (it already is?). If it's not NULL then we go on to use it like a valid memory address so I hope it's valid.
Please also fix
kcalloc(1, sizeof(struct iecm_ctlq_info), GFP_KERNEL)
to
kzalloc(sizeof(**cq_out), GFP_KERNEL)
while at it.
kcalloc(1) is excessive and it's preferred to take sizeof(*variable) you assign to exclude type mismatches. checkpatch should've complained on both of these.
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 150
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +9
-0+ + (*cq_out)->cq_type = qinfo->type; + (*cq_out)->q_id = qinfo->id; + (*cq_out)->buf_size = qinfo->buf_size; + (*cq_out)->ring_size = qinfo->len; + + (*cq_out)->next_to_use =0 ; + (*cq_out)->next_to_clean =0 ; + (*cq_out)->next_to_post = (*cq_out)->ring_size -1 ;
I would follow Shannon's advice to create a local variable. All those look like an unneeded complication.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +13
-0+ +switch (qinfo->type) { +case IECM_CTLQ_TYPE_MAILBOX_RX : + is_rxq = true; + fallthrough; +case IECM_CTLQ_TYPE_MAILBOX_TX : + status =iecm_ctlq_alloc_ring_res (hw, *cq_out); +break ; +default : + status = -EBADR ; +break ; + } +
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 171
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +8
-0+if (status) + goto init_free_q; + +if (is_rxq) { +iecm_ctlq_init_rxq_bufs (*cq_out); + }else { +/* Allocate the array of msg pointers for TX queues */ + (*cq_out)->bi.tx_msg = kcalloc(qinfo->len,
This kcalloc() is okay since we're allocating an array indeed.
Quoted 1,691 lines
Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +17
-0+sizeof (struct iecm_ctlq_msg *), + GFP_KERNEL); +if (!(*cq_out)->bi.tx_msg) { + status = -ENOMEM ; + goto init_dealloc_q_mem; + } + } + +iecm_ctlq_setup_regs (*cq_out, qinfo); + +iecm_ctlq_init_regs (hw, *cq_out, is_rxq); + +mutex_init (&(*cq_out)->cq_lock); + +list_add (&(*cq_out)->cq_list, &hw->cq_list_head); + +return status;Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 194
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+ +init_dealloc_q_mem: +/* free ring buffers and the ring itself */ +iecm_ctlq_dealloc_ring_res (hw, *cq_out); +init_free_q: +kfree (*cq_out);Probably should clear this back to NULL.
Will fix.
Quoted 47 lines
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +12
-0+ +return status; +} + +/** +* iecm_ctlq_remove - deallocate and remove specified control queue +* @hw: pointer to hardware struct +* @cq: pointer to control queue to be removed +*/ +void iecm_ctlq_remove (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+list_del (&cq->cq_list); +iecm_ctlq_shutdown (hw, cq); +kfree (cq); +} + +/** +* iecm_ctlq_init - main initialization routine for all control queues +* @hw: pointer to hardware struct +* @num_q: number of queues to initialize +* @q_info: array of structs containing info for each queue to be initialized
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 218
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+* +* This initializes any number and any type of control queues. This is an all
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 220
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+* or nothing routine; if one fails, all previously allocated queues will be +* destroyed. This must be called prior to using the individual add/remove
Quoted 18 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +18
-0+* APIs. +*/ +int iecm_ctlq_init (struct iecm_hw *hw,u8 num_q, +struct iecm_ctlq_create_info *q_info) +{ +struct iecm_ctlq_info *cq =NULL , *tmp =NULL ; +int ret_code =0 ; +int i =0 ; + +INIT_LIST_HEAD (&hw->cq_list_head); + +for (i =0 ; i < num_q; i++) { +struct iecm_ctlq_create_info *qinfo = q_info + i; + + ret_code =iecm_ctlq_add (hw, qinfo, &cq); +if (ret_code) + goto init_destroy_qs; + }Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 244
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+ +return ret_code; + +init_destroy_qs: +list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) +iecm_ctlq_remove (hw, cq);This could call
iecm_ctlq_deinit()rather than repeat the same code.Seems fair, will fix.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +11
-0+ +return ret_code; +} + +/** +* iecm_ctlq_deinit - destroy all control queues +* @hw: pointer to hw struct +*/ +int iecm_ctlq_deinit (struct iecm_hw *hw) +{ +struct iecm_ctlq_info *cq =NULL , *tmp =NULL ;Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 246
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+int ret_code =0 ; + +list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) +iecm_ctlq_remove (hw, cq); + +return ret_code;Why is there a return code here when there is never an error?
Yeah this is weird, will fix.
Quoted 96 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+} + +/** +* iecm_ctlq_send - send command to Control Queue (CTQ) +* @hw: pointer to hw struct +* @cq: handle to control queue struct to send on +* @num_q_msg: number of messages to send on control queue +* @q_msg: pointer to array of queue messages to be sent +* +* The caller is expected to allocate DMAable buffers and pass them to the
Quoted 74 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +74
-0+* send routine via the q_msg struct / control queue specific data struct. +* The control queue will hold a reference to each send message until +* the completion for that message has been cleaned. +*/ +int iecm_ctlq_send (struct iecm_hw *hw,struct iecm_ctlq_info *cq, +u16 num_q_msg,struct iecm_ctlq_msg q_msg[]) +{ +struct iecm_ctlq_desc *desc; +int num_desc_avail =0 ; +int status =0 ; +int i =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ; + +mutex_lock (&cq->cq_lock); + +/* Ensure there are enough descriptors to send all messages */ + num_desc_avail =IECM_CTLQ_DESC_UNUSED (cq); +if (num_desc_avail ==0 || num_desc_avail < num_q_msg) { + status = -ENOSPC ; + goto sq_send_command_out; + } + +for (i =0 ; i < num_q_msg; i++) { +struct iecm_ctlq_msg *msg = &q_msg[i]; +u64 msg_cookie; + + desc =IECM_CTLQ_DESC (cq, cq->next_to_use); + + desc->opcode =cpu_to_le16 (msg->opcode); + desc->pfid_vfid =cpu_to_le16 (msg->func_id); + + msg_cookie = *(u64 *)&msg->cookie; + desc->cookie_high = +cpu_to_le32 (upper_32_bits (msg_cookie)); + desc->cookie_low = +cpu_to_le32 (lower_32_bits (msg_cookie)); + +if (msg->data_len) { +struct iecm_dma_mem *buff = msg->ctx.indirect.payload; + + desc->datalen =cpu_to_le16 (msg->data_len); + desc->flags |=cpu_to_le16 (IECM_CTLQ_FLAG_BUF ); + desc->flags |=cpu_to_le16 (IECM_CTLQ_FLAG_RD ); + +/* Update the address values in the desc with the pa +* value for respective buffer +*/ + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (buff->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (buff->pa)); + +memcpy (&desc->params, msg->ctx.indirect.context, +IECM_INDIRECT_CTX_SIZE ); + }else { +memcpy (&desc->params, msg->ctx.direct, +IECM_DIRECT_CTX_SIZE ); + } + +/* Store buffer info */ + cq->bi.tx_msg[cq->next_to_use] = msg; + + (cq->next_to_use)++; +if (cq->next_to_use == cq->ring_size) + cq->next_to_use =0 ; + } + +/* Force memory write to complete before letting hardware +* know that there are new descriptors to fetch. +*/ +dma_wmb (); +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+wr32 (hw, cq->reg.tail, cq->next_to_use); + +sq_send_command_out: +mutex_unlock (&cq->cq_lock); + +return status; +} + +/** +* iecm_ctlq_clean_sq - reclaim send descriptors on HW write back for the
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +3
-0+* requested queue +* @cq: pointer to the specific Control queue +* @clean_count: (input|output) number of descriptors to clean as input, and
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 359
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* number of descriptors actually cleaned as output Rather than two meanings for one parameter, can the number cleaned be a positive return value?
That seems fair. Will check.
Quoted 48 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 360
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* @msg_status: (output) pointer to msg pointer array to be populated; needs
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +4
-0+* to be allocated by caller +* +* Returns an array of message pointers associated with the cleaned +* descriptors. The pointers are to the original ctlq_msgs sent on the cleaned
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 365
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* descriptors. The status will be returned for each; any messages that failed
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 366
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* to send will have a non-zero status. The caller is expected to free original
Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +25
-0+* ctlq_msgs and free or reuse the DMA buffers. +*/ +int iecm_ctlq_clean_sq (struct iecm_ctlq_info *cq,u16 *clean_count, +struct iecm_ctlq_msg *msg_status[]) +{ +struct iecm_ctlq_desc *desc; +u16 i =0 , num_to_clean; +u16 ntc, desc_err; +int ret =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ; + +if (*clean_count ==0 ) +return 0 ; +if (*clean_count > cq->ring_size) +return -EBADR ; + +mutex_lock (&cq->cq_lock); + + ntc = cq->next_to_clean; + + num_to_clean = *clean_count; + +for (i =0 ; i < num_to_clean; i++) {drivers/net/ethernet/intel/iecm/iecm_controlq.c line 401
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+/* Fetch next descriptor and check if marked as done */ + desc =IECM_CTLQ_DESC (cq, ntc); +if (!(le16_to_cpu (desc->flags) &IECM_CTLQ_FLAG_DD )) +break ; + + desc_err =le16_to_cpu (desc->ret_val); +if (desc_err) { +/* strip off FW internal code */ + desc_err &=0xff ; + }Why not simply
Quoted 2 lines
desc_err = le16_to_cpu(desc->ret_val) & 0xff;Will fix.
Quoted 30 lines
Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +19
-0+ + msg_status[i] = cq->bi.tx_msg[ntc]; + msg_status[i]->status = desc_err; + + cq->bi.tx_msg[ntc] =NULL ; + +/* Zero out any stale data */ +memset (desc,0 ,sizeof (*desc)); + + ntc++; +if (ntc == cq->ring_size) + ntc =0 ; + } + + cq->next_to_clean = ntc; + +mutex_unlock (&cq->cq_lock); + +/* Return number of descriptors actually cleaned */ drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ *clean_count = i; + +return ret; +} + +/** +* iecm_ctlq_post_rx_buffs - post buffers to descriptor ring +* @hw: pointer to hw struct +* @cq: pointer to control queue handle +* @buff_count: (input|output) input is number of buffers caller is trying to
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 431
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* return; output is number of buffers that were not posted Same comment.
And the return would make more sense if consistent with the previous function where the return is how many were successful.Yeah this seems more sane, need a little time to see what the refactor looks like.
Quoted 142 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 432
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +1
-0+* @buffs: array of pointers to dma mem structs to be given to hardware
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 434
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+* +* Caller uses this function to return DMA buffers to the descriptor ring after
drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +7
-0+* consuming them; buff_count will be the number of buffers. +* +* Note: this function needs to be called after a receive call even +* if there are no DMA buffers to be returned, i.e. buff_count = 0, +* buffs = NULL to support direct commands +*/ +int iecm_ctlq_post_rx_buffs(struct iecm_hw *hw, struct iecm_ctlq_info*cq,
Quoted 15 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +15
-0+ u16 *buff_count, struct iecm_dma_mem **buffs) +{ + struct iecm_ctlq_desc *desc; +u16 ntp = cq->next_to_post; +bool buffs_avail = false; +u16 tbp = ntp +1 ; +int status =0 ; +int i =0 ; + +if (*buff_count > cq->ring_size) +return -EBADR ; + +if (*buff_count >0 ) + buffs_avail = true; +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+mutex_lock (&cq->cq_lock); + +if (tbp >= cq->ring_size) + tbp =0 ; + +if (tbp == cq->next_to_clean) +/* Nothing to do */ + goto post_buffs_out; + +/* Post buffers for as many as provided or up until the last one used */
Quoted 39 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +39
-0+while (ntp != cq->next_to_clean) { + desc =IECM_CTLQ_DESC (cq, ntp); + +if (cq->bi.rx_buff[ntp]) + goto fill_desc; +if (!buffs_avail) { +/* If the caller hasn't given us any buffers or +* there are none left, search the ring itself +* for an available buffer to move to this +* entry starting at the next entry in the ring +*/ + tbp = ntp +1 ; + +/* Wrap ring if necessary */ +if (tbp >= cq->ring_size) + tbp =0 ; + +while (tbp != cq->next_to_clean) { +if (cq->bi.rx_buff[tbp]) { + cq->bi.rx_buff[ntp] = + cq->bi.rx_buff[tbp]; + cq->bi.rx_buff[tbp] =NULL ; + +/* Found a buffer, no need to +* search anymore +*/ +break ; + } + +/* Wrap ring if necessary */ + tbp++; +if (tbp >= cq->ring_size) + tbp =0 ; + } + +if (tbp == cq->next_to_clean) + goto post_buffs_out; + }else { +/* Give back pointer to DMA buffer */ drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+ cq->bi.rx_buff[ntp] = buffs[i]; + i++; + +if (i >= *buff_count) + buffs_avail = false; + } + +fill_desc: + desc->flags = + cpu_to_le16(IECM_CTLQ_FLAG_BUF |
IECM_CTLQ_FLAG_RD);Quoted 30 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +30
-0+ +/* Post buffers to descriptor */ + desc->datalen =cpu_to_le16 (cq->bi.rx_buff[ntp]->size); + desc->params.indirect.addr_high = +cpu_to_le32 (upper_32_bits (cq->bi.rx_buff[ntp]->pa)); + desc->params.indirect.addr_low = +cpu_to_le32 (lower_32_bits (cq->bi.rx_buff[ntp]->pa)); + + ntp++; +if (ntp == cq->ring_size) + ntp =0 ; + } + +post_buffs_out: +/* Only update tail if buffers were actually posted */ +if (cq->next_to_post != ntp) { +if (ntp) +/* Update next_to_post to ntp - 1 since current ntp +* will not have a buffer +*/ + cq->next_to_post = ntp -1 ; +else +/* Wrap to end of end ring since current ntp is 0 */ + cq->next_to_post = cq->ring_size -1 ; + +wr32 (hw, cq->reg.tail, cq->next_to_post); + } + +mutex_unlock (&cq->cq_lock); +drivers/net/ethernet/intel/iecm/iecm_controlq.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +10
-0+/* return the number of buffers that were not posted */ + *buff_count = *buff_count - i; + +return status; +} + +/** +* iecm_ctlq_recv - receive control queue message call back +* @cq: pointer to control queue handle to receive on +* @num_q_msg: (input|output) input number of messages that should be received;
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 557
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+* output number of messages actually received +* @q_msg: (output) array of received control queue messages on this q;
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +9
-0+* needs to be pre-allocated by caller for as many messages as requested +* +* Called by interrupt handler or polling mechanism. Caller is expected +* to free buffers +*/ +int iecm_ctlq_recv (struct iecm_ctlq_info *cq,u16 *num_q_msg, +struct iecm_ctlq_msg *q_msg) +{ +u16 num_to_clean, ntc, ret_val, flags;Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 572
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +6
-0+struct iecm_ctlq_desc *desc; +int ret_code =0 ; +u16 i =0 ; + +if (!cq || !cq->ring_size) +return -ENOBUFS ;Should
*num_q_msgsget set to 0 here since none were received?Based on the function description it does indeed sound like we should be.
Quoted 33 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 577
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +5
-0+ +if (*num_q_msg ==0 ) +return 0 ; +else if (*num_q_msg > cq->ring_size) +return -EBADR ;Again, set
*num_q_msgsto 0?Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +25
-0+ +/* take the lock before we start messing with the ring */ +mutex_lock (&cq->cq_lock); + + ntc = cq->next_to_clean; + + num_to_clean = *num_q_msg; + +for (i =0 ; i < num_to_clean; i++) { +u64 msg_cookie; + +/* Fetch next descriptor and check if marked as done */ + desc =IECM_CTLQ_DESC (cq, ntc); + flags =le16_to_cpu (desc->flags); + +if (!(flags &IECM_CTLQ_FLAG_DD )) +break ; + + ret_val =le16_to_cpu (desc->ret_val); + + q_msg[i].vmvf_type = (flags & + (IECM_CTLQ_FLAG_FTYPE_VM | +IECM_CTLQ_FLAG_FTYPE_PF )) >> +IECM_CTLQ_FLAG_FTYPE_S ; +Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c line 604
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +2
-0+if (flags &IECM_CTLQ_FLAG_ERR ) + ret_code = -EBADMSG ;So you might return
-EBADMSG, even if you've cleaned many messages? Will this be reflected inret_valand does the caller then need to hunt down the bad q_msg[].status?
How these work together should probably be clearly explained in the function header.I'll need some time to look at this, but it does seem suspect.
Quoted 1,181 lines
Review
Quoted 46 lines
drivers/net/ethernet/intel/iecm/iecm_controlq.c new file +45
-0+ + msg_cookie = (u64 )le32_to_cpu (desc->cookie_high) <<32 ; + msg_cookie |= (u64 )le32_to_cpu (desc->cookie_low); +memcpy (&q_msg[i].cookie, &msg_cookie,sizeof (u64)); + + q_msg[i].opcode =le16_to_cpu (desc->opcode); + q_msg[i].data_len =le16_to_cpu (desc->datalen); + q_msg[i].status = ret_val; + +if (desc->datalen) { +memcpy (q_msg[i].ctx.indirect.context, + &desc->params.indirect,IECM_INDIRECT_CTX_SIZE ); + +/* Assign pointer to dma buffer to ctlq_msg array +* to be given to upper layer +*/ + q_msg[i].ctx.indirect.payload = cq->bi.rx_buff[ntc]; + +/* Zero out pointer to DMA buffer info; +* will be repopulated by post buffers API +*/ + cq->bi.rx_buff[ntc] =NULL ; + }else { +memcpy (q_msg[i].ctx.direct, desc->params.raw, +IECM_DIRECT_CTX_SIZE ); + } + +/* Zero out stale data in descriptor */ +memset (desc,0 ,sizeof (struct iecm_ctlq_desc )); + + ntc++; +if (ntc == cq->ring_size) + ntc =0 ; + }; + + cq->next_to_clean = ntc; + +mutex_unlock (&cq->cq_lock); + + *num_q_msg = i; +if (*num_q_msg ==0 ) + ret_code = -ENOMSG ; + +return ret_code; +}(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_controlq_setup.cQuoted 12 lines
new file mode 100644
index 000000000000..a36fc88d6bb5drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +7
-0@@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2020, Intel Corporation. */ + +#include "iecm_controlq.h" + +/** +* iecm_ctlq_alloc_desc_ring - Allocate Control Queue (CQ) rings drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c line 17
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +10
-0+* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +*/ +static int +iecm_ctlq_alloc_desc_ring (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{ +size_t size = cq->ring_size *sizeof (struct iecm_ctlq_desc ); + + cq->desc_ring.va = iecm_alloc_dma_mem(hw, &cq->desc_ring,size);
Quoted 17 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +17
-0+if (!cq->desc_ring.va) +return -ENOMEM ; + +return 0 ; +} + +/** +* iecm_ctlq_alloc_bufs - Allocate Control Queue (CQ) buffers +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Allocate the buffer head for all control queues, and if it's a receive +* queue, allocate DMA buffers +*/ +static int iecm_ctlq_alloc_bufs (struct iecm_hw *hw, +struct iecm_ctlq_info *cq) +{drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +10
-0+int i =0 ; + +/* Do not allocate DMA buffers for transmit queues */ +if (cq->cq_type ==IECM_CTLQ_TYPE_MAILBOX_TX ) +return 0 ; + +/* We'll be allocating the buffer info memory first, then we can +* allocate the mapped buffers for the event processing +*/ + cq->bi.rx_buff = kcalloc(cq->ring_size, sizeof(struct iecm_dma_mem*),
Quoted 48 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +48
-0+ GFP_KERNEL); +if (!cq->bi.rx_buff) +return -ENOMEM ; + +/* allocate the mapped buffers (except for the last one) */ +for (i =0 ; i < cq->ring_size -1 ; i++) { +struct iecm_dma_mem *bi; +int num =1 ;/* number of iecm_dma_mem to be allocated */ + + cq->bi.rx_buff[i] =kcalloc (num,sizeof (struct iecm_dma_mem ), +GFP_KERNEL ); +if (!cq->bi.rx_buff[i]) + goto unwind_alloc_cq_bufs; + + bi = cq->bi.rx_buff[i]; + + bi->va =iecm_alloc_dma_mem (hw, bi, cq->buf_size); +if (!bi->va) { +/* unwind will not free the failed entry */ +kfree (cq->bi.rx_buff[i]); + goto unwind_alloc_cq_bufs; + } + } + +return 0 ; + +unwind_alloc_cq_bufs: +/* don't try to free the one that failed... */ + i--; +for (; i >=0 ; i--) { +iecm_free_dma_mem (hw, cq->bi.rx_buff[i]); +kfree (cq->bi.rx_buff[i]); + } +kfree (cq->bi.rx_buff); + +return -ENOMEM ; +} + +/** +* iecm_ctlq_free_desc_ring - Free Control Queue (CQ) rings +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* This assumes the posted send buffers have already been cleaned +* and de-allocated +*/ +static void iecm_ctlq_free_desc_ring (struct iecm_hw *hw, +struct iecm_ctlq_info *cq)drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +10
-0+{ +iecm_free_dma_mem (hw, &cq->desc_ring); +} + +/** +* iecm_ctlq_free_bufs - Free CQ buffer info elements +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Free the DMA buffers for RX queues, and DMA buffer header for both RX and TX
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c line 103
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +1
-0+* queues. The upper layers are expected to manage freeing of TX DMA buffers
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c line 105
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +2
-0+*/ +static void iecm_ctlq_free_bufs(struct iecm_hw *hw, struct
iecm_ctlq_info*cq)Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +19
-0+{ +void *bi; + +if (cq->cq_type ==IECM_CTLQ_TYPE_MAILBOX_RX ) { +int i; + +/* free DMA buffers for rx queues*/ +for (i =0 ; i < cq->ring_size; i++) { +if (cq->bi.rx_buff[i]) { +iecm_free_dma_mem (hw, cq->bi.rx_buff[i]); +kfree (cq->bi.rx_buff[i]); + } + } + + bi = (void *)cq->bi.rx_buff; + }else { + bi = (void *)cq->bi.tx_msg; + } +drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +10
-0+/* free the buffer header */ +kfree (bi); +} + +/** +* iecm_ctlq_dealloc_ring_res - Free memory allocated for control queue +* @hw: pointer to hw struct +* @cq: pointer to the specific Control queue +* +* Free the memory used by the ring, buffers and other related structures
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c line 136
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +2
-0+*/ +void iecm_ctlq_dealloc_ring_res(struct iecm_hw *hw, struct
iecm_ctlq_info*cq)drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +8
-0+{ +/* free ring buffers and the ring itself */ +iecm_ctlq_free_bufs (hw, cq); +iecm_ctlq_free_desc_ring (hw, cq); +} + +/** +* iecm_ctlq_alloc_ring_res - allocate memory for descriptor ring and bufs
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +4
-0+* @hw: pointer to hw struct +* @cq: pointer to control queue struct +* +* Do *NOT* hold the lock when calling this as the memory allocation routines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +3
-0+* called are not going to be atomic context safe +*/ +int iecm_ctlq_alloc_ring_res(struct iecm_hw *hw, struct iecm_ctlq_info*cq)
Review
Quoted 25 lines
drivers/net/ethernet/intel/iecm/iecm_controlq_setup.c new file +24
-0+{ +int ret_code; + +/* verify input for valid configuration */ +if (!cq->ring_size || !cq->buf_size) +return -EINVAL ; + +/* allocate the ring memory */ + ret_code =iecm_ctlq_alloc_desc_ring (hw, cq); +if (ret_code) +return ret_code; + +/* allocate buffers in the rings */ + ret_code =iecm_ctlq_alloc_bufs (hw, cq); +if (ret_code) + goto iecm_init_cq_free_ring; + +/* success! */ +return 0 ; + +iecm_init_cq_free_ring: +iecm_free_dma_mem (hw, &cq->desc_ring); +return ret_code; +}(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_lib.cdrivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct
Quoted 30 lines
index
e6d0b418a27f..64cdbce2c842100644drivers/net/ethernet/intel/iecm/iecm_lib.c +19
-0@@ -5,6 +5,25 @@#include "iecm.h" +/** +* iecm_cfg_hw - Initialize HW struct +* @adapter: adapter to setup hw struct for +* +* Returns 0 on success, negative on failure +*/ +static int iecm_cfg_hw (struct iecm_adapter *adapter) +{ +struct pci_dev *pdev = adapter->pdev; +struct iecm_hw *hw = &adapter->hw; + + hw->hw_addr =pcim_iomap_table (pdev)[IECM_BAR0 ]; +if (!hw->hw_addr) +return -EIO ; + hw->back = adapter; + +return 0 ; +} +/** * iecm_statistics_task - Delayed task to get statistics over mailbox * @work: work_struct handle to our data @@ -39,6 +58,32 @@ static void iecm_init_task(struct work_struct*work)
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3
-0/* stub */ } +/** +* iecm_api_init - Initialize and verify device API +* @adapter: driver specific private structure drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct *work)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10
-0+* +* Returns 0 on success, negative on failure +*/ +static int iecm_api_init (struct iecm_adapter *adapter) +{ +struct iecm_reg_ops *reg_ops = &adapter->dev_ops.reg_ops; +struct pci_dev *pdev = adapter->pdev; + +if (!adapter->dev_ops.reg_ops_init) { + dev_err(&pdev->dev, "Invalid device, register API init notdefined\n");
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_init_task(struct work_struct *work)
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7
-0+return -EINVAL ; + } + adapter->dev_ops.reg_ops_init (adapter); +if (!(reg_ops->ctlq_reg_init && reg_ops->intr_reg_init && + reg_ops->mb_intr_reg_init && reg_ops->reset_reg_init && + reg_ops->trigger_reset)) { + dev_err(&pdev->dev, "Invalid device, missing one or moreregister functions\n");
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6
-0+return -EINVAL ; + } + +return 0 ; +} +/** * iecm_deinit_task - Device deinit routine * @adapter: Driver specific private structue @@ -51,13 +96,108 @@ static void iecm_deinit_task(struct
iecm_adapter*adapter)Quoted 58 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +54
-0/* stub */ } +/** +* iecm_check_reset_complete - check that reset is complete +* @hw: pointer to hw struct +* @reset_reg: struct with reset registers +* +* Returns 0 if device is ready to use, or -EBUSY if it's in reset. +**/ +static int iecm_check_reset_complete (struct iecm_hw *hw, +struct iecm_reset_reg *reset_reg) +{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; +int i; + +for (i =0 ; i <2000 ; i++) { +u32 reg_val =rd32 (hw, reset_reg->rstat); + +/* 0xFFFFFFFF might be read if other side hasn't cleared the +* register for us yet and 0xFFFFFFFF is not a valid value for +* the register, so treat that as invalid. +*/ +if (reg_val !=0xFFFFFFFF && (reg_val & reset_reg->rstat_m)) +return 0 ; +usleep_range (5000 ,10000 ); + } + +dev_warn (&adapter->pdev->dev,"Device reset timeout!\n" ); +return -EBUSY ; +} + +/** +* iecm_init_hard_reset - Initiate a hardware reset +* @adapter: Driver specific private structure +* +* Deallocate the vports and all the resources associated with them and +* reallocate. Also reinitialize the mailbox. Return 0 on success, +* negative on failure. +*/ +static int iecm_init_hard_reset (struct iecm_adapter *adapter) +{ +int err =0 ; + +mutex_lock (&adapter->reset_lock); + +/* Prepare for reset */ +if (test_and_clear_bit (__IECM_HR_DRV_LOAD, adapter->flags)) { + adapter->dev_ops.reg_ops.trigger_reset (adapter, + __IECM_HR_DRV_LOAD); + }else if (test_and_clear_bit (__IECM_HR_FUNC_RESET, adapter- flags)) { +bool is_reset =iecm_is_reset_detected (adapter); + +if (adapter->state == __IECM_UP) +set_bit (__IECM_UP_REQUESTED, adapter->flags); +iecm_deinit_task (adapter); +if (!is_reset)drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9
-0+ adapter->dev_ops.reg_ops.trigger_reset (adapter, + __IECM_HR_FUNC_RESET); +iecm_deinit_dflt_mbx (adapter); + }else if (test_and_clear_bit (__IECM_HR_CORE_RESET, adapter- flags)) { +if (adapter->state == __IECM_UP) +set_bit (__IECM_UP_REQUESTED, adapter->flags); +iecm_deinit_task (adapter); + }else { + dev_err(&adapter->pdev->dev, "Unhandled hard resetcause\n");
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter *adapter)
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +8
-0+ err = -EBADRQC ; + goto handle_err; + } + +/* Wait for reset to complete */ + err =iecm_check_reset_complete (&adapter->hw, &adapter- reset_reg); +if (err) { + dev_err(&adapter->pdev->dev, "The driver was unable tocontact the device's firmware. Check that the FW is running. Driver state=%u\n",
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter *adapter)
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5
-0+ adapter->state); + goto handle_err; + } + +/* Reset is complete and so start building the driver resources again */
drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_deinit_task(struct iecm_adapter *adapter)
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3
-0+ err =iecm_init_dflt_mbx (adapter); +if (err) { + dev_err(&adapter->pdev->dev, "Failed to initialize defaultmailbox: %d\n",
Quoted 40 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +17
-1+ err); + } +handle_err: +mutex_unlock (&adapter->reset_lock); +return err; +} +/** * iecm_vc_event_task - Handle virtchannel event logic * @work: work queue struct */ static void iecm_vc_event_task (struct work_struct *work) { -/* stub */ +struct iecm_adapter *adapter =container_of (work, + struct iecm_adapter, + vc_event_task.work); + +if (test_bit (__IECM_HR_CORE_RESET, adapter->flags) || +test_bit (__IECM_HR_FUNC_RESET, adapter->flags) || +test_bit (__IECM_HR_DRV_LOAD, adapter->flags)) { +set_bit (__IECM_HR_RESET_IN_PROG, adapter->flags); +iecm_init_hard_reset (adapter); + }}
/**
drivers/net/ethernet/intel/iecm/iecm_lib.c +5
-0@@ -75,6 +215,11 @@ int iecm_probe(struct pci_dev *pdev,int err; adapter->pdev = pdev; + err =iecm_api_init (adapter); +if (err) { +dev_err (&pdev->dev,"Device API is incorrectly configured\n" ); +return err; + } err =pcim_enable_device (pdev);if (err)drivers/net/ethernet/intel/iecm/iecm_lib.c int iecm_probe(struct pci_dev *pdev, · line 297
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +3
-0@@ -147,6 +292,20 @@ int iecm_probe(struct pci_dev *pdev, goto err_netdev_alloc; } + err =iecm_vport_params_buf_alloc (adapter); +if (err) { + dev_err(&pdev->dev, "Failed to alloc vport params buffer:%d\n",
drivers/net/ethernet/intel/iecm/iecm_lib.c int iecm_probe(struct pci_dev *pdev,
Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7
-0+ err); + goto err_mb_res; + } + + err =iecm_cfg_hw (adapter); +if (err) { + dev_err(&pdev->dev, "Failed to configure HW structure foradapter: %d\n",
drivers/net/ethernet/intel/iecm/iecm_lib.c int iecm_probe(struct pci_dev *pdev, · line 326
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +4
-0+ err); + goto err_cfg_hw; + } +mutex_init (&adapter->sw_mutex);mutex_init (&adapter->reset_lock);init_waitqueue_head (&adapter->vchnl_wq);@@ -166,11 +325,16 @@ int iecm_probe(struct pci_dev *pdev,INIT_DELAYED_WORK (&adapter->init_task, iecm_init_task); INIT_DELAYED_WORK(&adapter->vc_event_task,
iecm_vc_event_task);Quoted 32 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +7
-0+ adapter->dev_ops.reg_ops.reset_reg_init (&adapter->reset_reg);set_bit (__IECM_HR_DRV_LOAD, adapter->flags);queue_delayed_work (adapter->vc_event_wq, &adapter- vc_event_task,msecs_to_jiffies (10 * (pdev->devfn &0x07 )));return 0 ; +err_cfg_hw: +iecm_vport_params_buf_rel (adapter); +err_mb_res: +kfree (adapter->netdevs); err_netdev_alloc:kfree (adapter->vports); err_vport_alloc:@@ -214,6 +378,7 @@ void iecm_remove(struct pci_dev *pdev)cancel_delayed_work_sync (&adapter->vc_event_task);iecm_deinit_task (adapter);iecm_del_user_cfg_data (adapter); +iecm_deinit_dflt_mbx (adapter);msleep (20 );destroy_workqueue (adapter->serv_wq);destroy_workqueue (adapter->vc_event_wq);@@ -222,6 +387,7 @@ void iecm_remove(struct pci_dev *pdev)kfree (adapter->vports);kfree (adapter->netdevs);kfree (adapter->vlan_caps); +iecm_vport_params_buf_rel (adapter);mutex_destroy (&adapter->sw_mutex);mutex_destroy (&adapter->reset_lock);pci_disable_pcie_error_reporting (pdev);drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_remove(struct pci_dev *pdev) · line 399
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +2
-0@@ -229,3 +395,26 @@ void iecm_remove(struct pci_dev *pdev)pci_disable_device (pdev); }EXPORT_SYMBOL (iecm_remove); + +void *iecm_alloc_dma_mem(struct iecm_hw *hw, struct
iecm_dma_mem*mem, u64 size)drivers/net/ethernet/intel/iecm/iecm_lib.c void iecm_remove(struct pci_dev *pdev)
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +12
-0+{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; +size_t sz =ALIGN (size,4096 ); + + mem->va =dma_alloc_coherent (&adapter->pdev->dev, sz, + &mem->pa,GFP_KERNEL | __GFP_ZERO); + mem->size = size; + +return mem->va; +} + +void iecm_free_dma_mem(struct iecm_hw *hw, struct iecm_dma_mem*mem)
Review
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +9
-0+{ +struct iecm_adapter *adapter = (struct iecm_adapter *)hw->back; + +dma_free_coherent (&adapter->pdev->dev, mem->size, + mem->va, mem->pa); + mem->size =0 ; + mem->va =NULL ; + mem->pa =0 ; +}(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_virtchnl.cQuoted 5 lines
new file mode 100644
index 000000000000..b8f54b8c700adrivers/net/ethernet/intel/iecm/iecm_virtchnl.c line 10
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0@@ -0,0 +1,172 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#include "iecm.h" + +/** +* iecm_mb_clean - Reclaim the send mailbox queue entries +* @adapter: Driver specific private structure +* +* Reclaim the send mailbox queue entries to be used to send further messages
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +11
-0+* +* Returns 0 on success, negative on failure +*/ +static int iecm_mb_clean (struct iecm_adapter *adapter) +{ +u16 i, num_q_msg =IECM_DFLT_MBX_Q_LEN ; +struct iecm_ctlq_msg **q_msg; +struct iecm_dma_mem *dma_mem; +int err =0 ; + + q_msg = kcalloc(num_q_msg, sizeof(struct iecm_ctlq_msg *),
GFP_KERNEL);Quoted 34 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +11
-0+if (!q_msg) +return -ENOMEM ; + + err =iecm_ctlq_clean_sq (adapter->hw.asq, &num_q_msg, q_msg); +if (err) + goto error; + +for (i =0 ; i < num_q_msg; i++) { + dma_mem = q_msg[i]->ctx.indirect.payload; +if (dma_mem) + dmam_free_coherent(&adapter->pdev->dev, dma_mem-size,
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +22
-0+ dma_mem->va, dma_mem->pa); +kfree (q_msg[i]); +kfree (dma_mem); + } +error: +kfree (q_msg); +return err; +} + +/** +* iecm_find_ctlq - Given a type and id, find ctlq info +* @hw: hardware struct +* @type: type of ctrlq to find +* @id: ctlq id to find +* +* Returns pointer to found ctlq info struct, NULL otherwise. +*/ +static struct iecm_ctlq_info *iecm_find_ctlq (struct iecm_hw *hw, +enum iecm_ctlq_type type,int id) +{ +struct iecm_ctlq_info *cq, *tmp; +drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0+list_for_each_entry_safe (cq, tmp, &hw->cq_list_head, cq_list) { +if (cq->q_id == id && cq->cq_type == type) +return cq; + } + +return NULL ; +} + +/** +* iecm_init_dflt_mbx - Setup default mailbox parameters and make request
Quoted 31 lines
+ * @adapter: adapter info struct
+ *
+ * Returns 0 on success, negative otherwise
+ */drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +27
-0+int iecm_init_dflt_mbx (struct iecm_adapter *adapter) +{ +struct iecm_ctlq_create_info ctlq_info[] = { + { + .type =IECM_CTLQ_TYPE_MAILBOX_TX , + .id =IECM_DFLT_MBX_ID , + .len =IECM_DFLT_MBX_Q_LEN , + .buf_size =IECM_DFLT_MBX_BUF_SIZE + }, + { + .type =IECM_CTLQ_TYPE_MAILBOX_RX , + .id =IECM_DFLT_MBX_ID , + .len =IECM_DFLT_MBX_Q_LEN , + .buf_size =IECM_DFLT_MBX_BUF_SIZE + } + }; +struct iecm_hw *hw = &adapter->hw; +int err; + + adapter->dev_ops.reg_ops.ctlq_reg_init (ctlq_info); + +#define NUM_Q 2 + err =iecm_ctlq_init (hw,NUM_Q , ctlq_info); +if (err) +return err; + + hw->asq = iecm_find_ctlq(hw, IECM_CTLQ_TYPE_MAILBOX_TX,drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0+ IECM_DFLT_MBX_ID); + hw->arq =iecm_find_ctlq (hw,IECM_CTLQ_TYPE_MAILBOX_RX , +IECM_DFLT_MBX_ID ); + +if (!hw->asq || !hw->arq) { +iecm_ctlq_deinit (hw); +return -ENOENT ; + } + adapter->state = __IECM_STARTUP; +/* Skew the delay for init tasks for each function based on fn number
Quoted 1 line
+ * to prevent every function from making the same call
simulatenously.
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +12
-0+*/ +queue_delayed_work (adapter->init_wq, &adapter->init_task, +msecs_to_jiffies (5 * (adapter->pdev->devfn &0x07 ))); +return 0 ; +} + +/** +* iecm_deinit_dflt_mbx - Free up ctlqs setup +* @adapter: Driver specific private data structure +*/ +void iecm_deinit_dflt_mbx (struct iecm_adapter *adapter) +{drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0+if (adapter->hw.arq && adapter->hw.asq) { +iecm_mb_clean (adapter); +iecm_ctlq_deinit (&adapter->hw); + } + adapter->hw.arq =NULL ; + adapter->hw.asq =NULL ; +} + +/** +* iecm_vport_params_buf_alloc - Allocate memory for MailBox resources
Quoted 18 lines
+ * @adapter: Driver specific private data structure
+ *
+ * Will alloc memory to hold the vport parameters received on MailBox
+ */drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +14
-0+int iecm_vport_params_buf_alloc (struct iecm_adapter *adapter) +{ + adapter->vport_params_reqd =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (*adapter->vport_params_reqd), +GFP_KERNEL ); +if (!adapter->vport_params_reqd) +return -ENOMEM ; + + adapter->vport_params_recvd =kcalloc (IECM_MAX_NUM_VPORTS , +sizeof (*adapter->vport_params_recvd), +GFP_KERNEL ); +if (!adapter->vport_params_recvd) { +kfree (adapter->vport_params_reqd); +return -ENOMEM ;drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +10
-0+ } + +return 0 ; +} + +/** +* iecm_vport_params_buf_rel - Release memory for MailBox resources +* @adapter: Driver specific private data structure +* +* Will release memory to hold the vport parameters received on MailBox
Review
Quoted 17 lines
+ */
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c new file +15
-0+void iecm_vport_params_buf_rel (struct iecm_adapter *adapter) +{ +int i =0 ; + +for (i =0 ; i <IECM_MAX_NUM_VPORTS ; i++) { +kfree (adapter->vport_params_recvd[i]); +kfree (adapter->vport_params_reqd[i]); + } + +kfree (adapter->vport_params_recvd); +kfree (adapter->vport_params_reqd); + +kfree (adapter->caps); +kfree (adapter->config_data.req_qs_chunks); +}(quoted diff) +0
-0
b/drivers/net/ethernet/intel/include/iecm.hQuoted 8 lines
index
e19e014e9817..ca9029224e06100644drivers/net/ethernet/intel/include/iecm.h +1
-0@@ -12,15 +12,33 @@#include <linux/dim.h> #include "iecm_txrx.h" +#include "iecm_controlq.h" drivers/net/ethernet/intel/include/iecm.h line 25
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +6
-0#define IECM_BAR0 0#define IECM_NO_FREE_SLOT 0xffff +/* Default Mailbox settings */ +#define IECM_DFLT_MBX_BUF_SIZE (4 * 1024) +#define IECM_NUM_QCTX_PER_MSG 3 +#define IECM_NUM_FILTERS_PER_MSG 20 +#define IECM_VLANS_PER_MSG \ + ((IECM_DFLT_MBX_BUF_SIZE - sizeof(struct
virtchnl_vlan_filter_list)) \drivers/net/ethernet/intel/include/iecm.h
Quoted 6 lines
drivers/net/ethernet/intel/include/iecm.h +6
-0+ / sizeof(u16)) +#define IECM_DFLT_MBX_Q_LEN 64 +#define IECM_DFLT_MBX_ID -1 +/* maximum number of times to try before resetting mailbox */ +#define IECM_MB_MAX_ERR 20 +#define IECM_NUM_CHUNKS_PER_MSG (a, b)((
IECM_DFLT_MBX_BUF_SIZE- (a)) / (b))444 lines not shown · raw message
Quoted 4 lines
4 lines not shown · raw message
2 lines not shown · raw message
Part of this message is not shown here. View the raw message.
PATCH 5/19 iecm: add vport alloc and virtchnl messages
In reply to Alan BradyAfter handling hard reset, we end up in init task. This starts by allocating and setting up a vport. To do that we need implement virtchnl messages.
The virtchnl messages are also offloaded into function pointers so that a device driver may override them. Here a default implementation is provided for devices using virtchnl 2.0 but there exists the flexibility add virtchnl 1.1 support through function pointers.
--- drivers/net/ethernet/intel/iecm/Makefile | 4 +- drivers/net/ethernet/intel/iecm/iecm_lib.c | 167 ++- drivers/net/ethernet/intel/iecm/iecm_txrx.c | 22 + .../net/ethernet/intel/iecm/iecm_virtchnl.c | 1299 +++++++++++++++++ drivers/net/ethernet/intel/include/iecm.h | 316 +++- .../net/ethernet/intel/include/iecm_txrx.h | 94 ++ 6 files changed, 1898 insertions(+), 4 deletions(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_txrx.c
drivers/net/ethernet/intel/iecm/Makefile +3 -1
@@ -7,11 +7,13 @@ obj-$(CONFIG_IECM) += iecm.o -ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include \ + -I$(srctree)/include/linux/avf iecm-y := \ iecm_lib.o \ iecm_virtchnl.o \ + iecm_txrx.o \ iecm_controlq.o \ iecm_controlq_setup.o \ iecm_main.o
drivers/net/ethernet/intel/iecm/iecm_lib.c +165 -2
197 lines not on this page · raw message
drivers/net/ethernet/intel/iecm/iecm_txrx.c new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#include "iecm.h" + +/** +* iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler +* @irq: interrupt number +* @data: pointer to a q_vector +* +*/ +irqreturn_t +iecm_vport_intr_clean_queues (int __always_unused irq,void *data) +{ +struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data; + + q_vector->total_events++; +napi_schedule (&q_vector->napi); + +return IRQ_HANDLED ; +} +
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1299 -0
1,314 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm.h +315 -1
379 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm_txrx.h +94 -0
98 lines not on this page · raw message
Signature · 1 line
2.33.0
kernel test robot
build bot[Intel-wired-lan] [PATCH net-next 05/19] iecm: add vport alloc and virtchnl messages
Thank you for the patch! Perhaps something to improve:
Hi Alan,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-idpf/20220128-085513 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e2cf07654efb0fd7bbcb475c6f74be7b5755a8fd config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220128/202201281200.CI9u45bS-lkp at intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/1233d9631b312eea5aebbce63590e27f9993bacc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-085513 git checkout 1233d9631b312eea5aebbce63590e27f9993bacc
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/net/ethernet/intel/iecm/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c: In function 'iecm_vport_queue_ids_init':
>> drivers/net/ethernet/intel/iecm/iecm_virtchnl.c:1396:1: warning: the frame size of 1052 bytes is larger than 1024 bytes [-Wframe-larger-than=]
1396 | }
| ^vim +1396 drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
1322
1323 /**
1324 * iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters
1325 * @vport: virtual port for which the queues ids are initialized
1326 *
1327 * Will initialize all queue ids with ids received as mailbox parameters.
1328 * Returns 0 on success, negative if all the queues are not initialized.
1329 */
1330 static int iecm_vport_queue_ids_init(struct iecm_vport *vport)
1331 {
1332 struct virtchnl2_create_vport *vport_params;
1333 struct virtchnl2_queue_reg_chunks *chunks;
1334 /* We may never deal with more than 256 same type of queues */
1335 #define IECM_MAX_QIDS 256
1336 u32 qids[IECM_MAX_QIDS];
1337 int num_ids;
1338 u16 q_type;
1339
1340 if (vport->adapter->config_data.req_qs_chunks) {
1341 struct virtchnl2_add_queues *vc_aq =
1342 (struct virtchnl2_add_queues *)
1343 vport->adapter->config_data.req_qs_chunks;
1344 chunks = &vc_aq->chunks;
1345 } else {
1346 vport_params = (struct virtchnl2_create_vport *)
1347 vport->adapter->vport_params_recvd[0];
1348 chunks = &vport_params->chunks;
1349 }
1350
1351 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,
1352 VIRTCHNL2_QUEUE_TYPE_TX,
1353 chunks);
1354 if (num_ids != vport->num_txq)
1355 return -EINVAL;
1356 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1357 VIRTCHNL2_QUEUE_TYPE_TX);
1358 if (num_ids != vport->num_txq)
1359 return -EINVAL;
1360 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,
1361 VIRTCHNL2_QUEUE_TYPE_RX,
1362 chunks);
1363 if (num_ids != vport->num_rxq)
1364 return -EINVAL;
1365 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1366 VIRTCHNL2_QUEUE_TYPE_RX);
1367 if (num_ids != vport->num_rxq)
1368 return -EINVAL;
1369
1370 if (iecm_is_queue_model_split(vport->txq_model)) {
1371 q_type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
1372 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS, q_type,
1373 chunks);
1374 if (num_ids != vport->num_complq)
1375 return -EINVAL;
1376 num_ids = __iecm_vport_queue_ids_init(vport, qids,
1377 num_ids,
1378 q_type);
1379 if (num_ids != vport->num_complq)
1380 return -EINVAL;
1381 }
1382
1383 if (iecm_is_queue_model_split(vport->rxq_model)) {
1384 q_type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
1385 num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS, q_type,
1386 chunks);
1387 if (num_ids != vport->num_bufq)
1388 return -EINVAL;
1389 num_ids = __iecm_vport_queue_ids_init(vport, qids, num_ids,
1390 q_type);
1391 if (num_ids != vport->num_bufq)
1392 return -EINVAL;
1393 }
1394
1395 return 0;
> 1396 }
1397
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org
PATCH 5/19 iecm: add vport alloc and virtchnl messages
From: kernel test robot <[email protected]>
Date: Fri, 28 Jan 2022 12:19:10 +0800
Quoted 32 lines
Hi Alan,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-idpf/20220128-085513 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git e2cf07654efb0fd7bbcb475c6f74be7b5755a8fd config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220128/202201281200.CI9u45bS-lkp at intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/1233d9631b312eea5aebbce63590e27f9993bacc
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-085513 git checkout1233d9631b312eea5aebbce63590e27f9993bacc
# save the config file to linux build tree
mkdirbuild_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bashdrivers/net/ethernet/intel/iecm/If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All warnings (new ones prefixed by >>):
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c: In function 'iecm_vport_queue_ids_init':Quoted 1 line
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c:1396:1: warning: the frame size of 1052 bytes is larger than 1024 bytes [-Wframe-larger-than=]1396 | } | ^vim +1396
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 15 lines
1322
1323 /**
1324 *iecm_vport_queue_ids_init- Initialize queue ids from Mailbox parameters
1325 * @vport: virtual port for which the queues ids are initialized
1326 *
1327 * Will initialize all queue ids with ids received as mailbox parameters.
1328 * Returns 0 on success, negative if all the queues are not initialized.
1329 */
1330 static intiecm_vport_queue_ids_init(struct iecm_vport *vport)
1331 {
1332 structvirtchnl2_create_vport*vport_params;
1333 structvirtchnl2_queue_reg_chunks*chunks;
1334 /* We may never deal with more than 256 same type of queues */
1335 #defineIECM_MAX_QIDS256
1336 u32 qids[IECM_MAX_QIDS];
I'll elaborate on this warning a bit: you declare 4 * 256 = 1 Kb array directly on the stack here.
1 Kb is a limit inside the kernel, it won't cause any issues since stacks on x86 are huge, but raises such warnings and we should listen to them, especially given that compile tests are now being done with -Werror.
Just use kzalloc(array_size(IECM_MAX_QIDS, sizeof(u32))) + kfree() here to avoid that.
Quoted 59 lines
1337 int
num_ids;
1338 u16q_type;
1339
1340 if (vport->adapter->config_data.req_qs_chunks) {
1341 structvirtchnl2_add_queues*vc_aq=
1342 (structvirtchnl2_add_queues*)
1343vport->adapter->config_data.req_qs_chunks;
1344 chunks =&vc_aq->chunks;
1345 } else {
1346vport_params= (structvirtchnl2_create_vport*)
1347 vport->adapter->vport_params_recvd[0];
1348 chunks =&vport_params->chunks;
1349 }
1350
1351num_ids= iecm_vport_get_queue_ids(qids,IECM_MAX_QIDS,
1352VIRTCHNL2_QUEUE_TYPE_TX,
1353 chunks);
1354 if (num_ids!=vport->num_txq)
1355 return-EINVAL;
1356num_ids= __iecm_vport_queue_ids_init(vport, qids,num_ids,
1357VIRTCHNL2_QUEUE_TYPE_TX);
1358 if (num_ids!=vport->num_txq)
1359 return-EINVAL;
1360num_ids= iecm_vport_get_queue_ids(qids,IECM_MAX_QIDS,
1361VIRTCHNL2_QUEUE_TYPE_RX,
1362 chunks);
1363 if (num_ids!=vport->num_rxq)
1364 return-EINVAL;
1365num_ids= __iecm_vport_queue_ids_init(vport, qids,num_ids,
1366VIRTCHNL2_QUEUE_TYPE_RX);
1367 if (num_ids!=vport->num_rxq)
1368 return-EINVAL;
1369
1370 if (iecm_is_queue_model_split(vport->txq_model)) {
1371q_type=VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION;
1372num_ids= iecm_vport_get_queue_ids(qids,IECM_MAX_QIDS,q_type,
1373 chunks);
1374 if (num_ids!=vport->num_complq)
1375 return-EINVAL;
1376num_ids= __iecm_vport_queue_ids_init(vport, qids,
1377num_ids,
1378q_type);
1379 if (num_ids!=vport->num_complq)
1380 return-EINVAL;
1381 }
1382
1383 if (iecm_is_queue_model_split(vport->rxq_model)) {
1384q_type=VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
1385num_ids= iecm_vport_get_queue_ids(qids,IECM_MAX_QIDS,q_type,
1386 chunks);
1387 if (num_ids!=vport->num_bufq)
1388 return-EINVAL;
1389num_ids= __iecm_vport_queue_ids_init(vport, qids,num_ids,
1390q_type);
1391 if (num_ids!=vport->num_bufq)
1392 return-EINVAL;
1393 }
1394
1395 return 0;
Quoted 6 lines
Quoted 1 line
1396 }
1397
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org
Thanks,
Al
Brady
PATCH 5/19 iecm: add vport alloc and virtchnl messages
Quoted 77 lines
-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 4:40 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired- lan at lists.osuosl.org; lkp <[email protected]>; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; kbuild-all at lists.01.org; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 05/19] iecm: add vport alloc and virtchnl messagesFrom: kernel test robot <[email protected]>
Date: Fri, 28 Jan 2022 12:19:10 +0800Quoted 7 lines
Hi Alan,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Alan-Brady/Add-iecm-and-
idpf/20220128-085513
Quoted 1 line
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
e2cf07654efb0fd7bbcb475c6f74be7b5755a8fdQuoted 6 lines
config: i386-allyesconfig
(https://download.01.org/0day-ci/archive/20220128/202201281200.CI9u45b
S-lkp at intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build):# https://github.com/0day-ci/linux/commit/1233d9631b312eea5aebbce63590e27f9993bacc
Quoted 2 lines
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alan-Brady/Add-iecm-and-idpf/20220128-085513
Quoted 6 lines
git checkout
1233d9631b312eea5aebbce63590e27f9993bacc# save the config file to linux build tree mkdirbuild_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bashdrivers/net/ethernet/intel/iecm/Quoted 6 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All warnings (new ones prefixed by >>):
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c: In function'
iecm_vport_queue_ids_init':Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c:1396:1: warning:
the frame size of 1052 bytes is larger than 1024 bytes [-Wframe-larger-than=]1396 | } | ^Quoted 5 lines
vim +1396
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c1322
1323 /**
1324 *iecm_vport_queue_ids_init- Initialize queue ids from Mailboxparameters
Quoted 10 lines
1325 * @vport: virtual port for which the queues ids are initialized
1326 *
1327 * Will initialize all queue ids with ids received as mailbox parameters.
1328 * Returns 0 on success, negative if all the queues are not initialized.
1329 */
1330 static intiecm_vport_queue_ids_init(struct iecm_vport *vport)
1331 {
1332 structvirtchnl2_create_vport*vport_params;
1333 structvirtchnl2_queue_reg_chunks*chunks;
1334 /* We may never deal with more than 256 same type of queues*/
Quoted 2 lines
1335 #define IECM_MAX_QIDS 256 1336 u32 qids[IECM_MAX_QIDS];I'll elaborate on this warning a bit: you declare 4 * 256 = 1 Kb array directly on the stack here.
Quoted 7 lines
1 Kb is a limit inside the kernel, it won't cause any issues since stacks on x86 are huge, but raises such warnings and we should listen to them, especially given that compile tests are now being done with -Werror.
Just use
kzalloc(array_size(IECM_MAX_QIDS, sizeof(u32)))+kfree()here to avoid that.
Will fix
Quoted 76 lines
Quoted 9 lines
1337 int
num_ids;
1338 u16q_type;
1339
1340 if (vport->adapter->config_data.req_qs_chunks) {
1341 structvirtchnl2_add_queues*vc_aq=
1342 (structvirtchnl2_add_queues*)
1343vport->adapter->config_data.req_qs_chunks;
1344 chunks =&vc_aq->chunks;
1345 } else {Quoted 8 lines
1346
vport_params= (structvirtchnl2_create_vport*)
1347 vport->adapter-
vport_params_recvd[0];
1348 chunks =&vport_params->chunks;
1349 }
1350
1351num_ids= iecm_vport_get_queue_ids(qids,IECM_MAX_QIDS,
1352
VIRTCHNL2_QUEUE_TYPE_TX,Quoted 5 lines
1353 chunks);
1354 if (num_ids!=vport->num_txq)
1355 return-EINVAL;
1356num_ids= __iecm_vport_queue_ids_init(vport, qids,num_ids,
1357
VIRTCHNL2_QUEUE_TYPE_TX);Quoted 4 lines
1358 if (
num_ids!=vport->num_txq)
1359 return-EINVAL;
1360num_ids= iecm_vport_get_queue_ids(qids,IECM_MAX_QIDS,
1361
VIRTCHNL2_QUEUE_TYPE_RX,Quoted 5 lines
1362 chunks);
1363 if (num_ids!=vport->num_rxq)
1364 return-EINVAL;
1365num_ids= __iecm_vport_queue_ids_init(vport, qids,num_ids,
1366
VIRTCHNL2_QUEUE_TYPE_RX);Quoted 6 lines
1367 if (num_ids != vport->num_rxq) 1368 return -EINVAL; 1369 1370 if (iecm_is_queue_model_split(vport->txq_model)) { 1371 q_type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION; 1372 num_ids = iecm_vport_get_queue_ids(qids,
IECM_MAX_QIDS,q_type,Quoted 5 lines
1373 chunks);
1374 if (num_ids!=vport->num_complq)
1375 return-EINVAL;
1376num_ids= __iecm_vport_queue_ids_init(vport, qids,
1377num_ids,Quoted 8 lines
1378
q_type);
1379 if (num_ids!=vport->num_complq)
1380 return-EINVAL;
1381 }
1382
1383 if (iecm_is_queue_model_split(vport->rxq_model)) {
1384q_type=VIRTCHNL2_QUEUE_TYPE_RX_BUFFER;
1385num_ids= iecm_vport_get_queue_ids(qids,
IECM_MAX_QIDS,q_type,Quoted 4 lines
1386 chunks);
1387 if (num_ids!=vport->num_bufq)
1388 return-EINVAL;
1389num_ids= __iecm_vport_queue_ids_init(vport, qids,
num_ids,Quoted 6 lines
1390
q_type);
1391 if (num_ids!=vport->num_bufq)
1392 return-EINVAL;
1393 }
1394
1395 return 0;Quoted 6 lines
Quoted 1 line
1396 }
1397
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.orgThanks,
Al
PATCH 5/19 iecm: add vport alloc and virtchnl messages
In reply to Alan BradyFrom: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:55 -0800
Quoted 68 lines
After handling hard reset, we end up in init task. This starts by allocating and setting up a vport. To do that we need implement virtchnl messages.
The virtchnl messages are also offloaded into function pointers so that a device driver may override them. Here a default implementation is provided for devices using virtchnl 2.0 but there exists the flexibility add virtchnl 1.1 support through function pointers.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 4 +- drivers/net/ethernet/intel/iecm/iecm_lib.c | 167 ++- drivers/net/ethernet/intel/iecm/iecm_txrx.c | 22 + .../net/ethernet/intel/iecm/iecm_virtchnl.c | 1299 +++++++++++++++++ drivers/net/ethernet/intel/include/iecm.h | 316 +++- .../net/ethernet/intel/include/iecm_txrx.h | 94 ++ 6 files changed, 1898 insertions(+), 4 deletions(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_txrx.cdrivers/net/ethernet/intel/iecm/Makefile +3
-1@@ -7,11 +7,13 @@ obj-$(CONFIG_IECM) += iecm.o -ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include \ + -I$(srctree)/include/linux/avf iecm-y := \ iecm_lib.o \ iecm_virtchnl.o \ + iecm_txrx.o \ iecm_controlq.o \ iecm_controlq_setup.o \ iecm_main.odrivers/net/ethernet/intel/iecm/iecm_lib.c +10
-0@@ -5,6 +5,11 @@#include "iecm.h" +const char *const iecm_vport_vc_state_str[] = { +IECM_FOREACH_VPORT_VC_STATE (IECM_GEN_STRING ) +}; +EXPORT_SYMBOL (iecm_vport_vc_state_str); +/** * iecm_cfg_hw - Initialize HW struct * @adapter: adapter to setup hw struct for @@ -24,6 +29,113 @@ static int iecm_cfg_hw(struct iecm_adapter *adapter)return 0 ; } +/** +* iecm_get_free_slot - get the next non-NULL location index in array +* @array: array to search +* @size: size of the array +* @curr: last known occupied index to be used as a search hint
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_cfg_hw(struct iecm_adapter *adapter) · line 46
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10
-0+* +* void * is being used to keep the functionality generic. This lets us use this +* function on any array of pointers. +*/ +static int iecm_get_free_slot (void *array,int size,int curr) +{ +int **tmp_array = (int **)array; +int next; + +if (curr < (size -1 ) && !tmp_array[curr +1 ]) {
Redundant braces around size - 1.
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_cfg_hw(struct iecm_adapter *adapter) · line 57
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11
-0+ next = curr +1 ; + }else { +int i =0 ; + +while ((i < size) && (tmp_array[i])) + i++; +if (i == size) + next =IECM_NO_FREE_SLOT ; +else + next = i; + }
One indent level is redundant here. First condition is an oneliner:
if (curr < (size - 1) && !tmp_array[curr + 1]) {
return curr + 1;
while ((i < size) && (tmp_array[i])) {
...Quoted 123 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +108
-1+return next; +} + +/** +* iecm_vport_rel - Delete a vport and free its resources +* @vport: the vport being removed +*/ +static void iecm_vport_rel (struct iecm_vport *vport) +{ +mutex_destroy (&vport->stop_mutex); +kfree (vport); +} + +/** +* iecm_vport_rel_all - Delete all vports +* @adapter: adapter from which all vports are being removed +*/ +static void iecm_vport_rel_all (struct iecm_adapter *adapter) +{ +int i; + +if (!adapter->vports) +return ; + +for (i =0 ; i < adapter->num_alloc_vport; i++) { +if (!adapter->vports[i]) +continue ; + +iecm_vport_rel (adapter->vports[i]); + adapter->vports[i] =NULL ; + adapter->next_vport =0 ; + } + adapter->num_alloc_vport =0 ; +} + +/** +* iecm_vport_alloc - Allocates the next available struct vport in the adapter +* @adapter: board private structure +* @vport_id: vport identifier +* +* returns a pointer to a vport on success, NULL on failure. +*/ +static struct iecm_vport * +iecm_vport_alloc (struct iecm_adapter *adapter,int vport_id) +{ +struct iecm_vport *vport =NULL ; + +if (adapter->next_vport ==IECM_NO_FREE_SLOT ) +return vport; + +/* Need to protect the allocation of the vports at the adapter level */ +mutex_lock (&adapter->sw_mutex); + + vport =kzalloc (sizeof (*vport),GFP_KERNEL ); +if (!vport) + goto unlock_adapter; + + vport->adapter = adapter; + vport->idx = adapter->next_vport; + vport->compln_clean_budget =IECM_TX_COMPLQ_CLEAN_BUDGET ; + adapter->num_alloc_vport++; + +/* Setup default MSIX irq handler for the vport */ + vport->irq_q_handler = iecm_vport_intr_clean_queues; + vport->q_vector_base =IECM_NONQ_VEC ; + +mutex_init (&vport->stop_mutex); + +/* fill vport slot in the adapter struct */ + adapter->vports[adapter->next_vport] = vport; + +/* prepare adapter->next_vport for next use */ + adapter->next_vport =iecm_get_free_slot (adapter->vports, + adapter->num_alloc_vport, + adapter->next_vport); + +unlock_adapter: +mutex_unlock (&adapter->sw_mutex); +return vport; +} +/** * iecm_statistics_task - Delayed task to get statistics over mailbox * @work: work_struct handle to our data @@ -55,7 +167,25 @@ static void iecm_service_task(struct work_struct *work)*/ static void iecm_init_task (struct work_struct *work) { -/* stub */ +struct iecm_adapter *adapter =container_of (work, + struct iecm_adapter, + init_task.work); +struct iecm_vport *vport; +struct pci_dev *pdev; +int vport_id, err; + + err = adapter->dev_ops.vc_ops.core_init (adapter, &vport_id); +if (err) +return ; + + pdev = adapter->pdev; + vport =iecm_vport_alloc (adapter, vport_id); +if (!vport) { + err = -EFAULT ; +dev_err (&pdev->dev,"failed to allocate vport: %d\n" , + err); +return ; + } }/** @@ -81,6 +211,31 @@ static int iecm_api_init(struct iecm_adapter *adapter)return -EINVAL ; } +if (adapter->dev_ops.vc_ops_init) { +struct iecm_virtchnl_ops *vc_ops; + + adapter->dev_ops.vc_ops_init (adapter); + vc_ops = &adapter->dev_ops.vc_ops; + if (!(vc_ops->core_init && + vc_ops->vport_init && + vc_ops->vport_queue_ids_init &&
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 231
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10
-0+ vc_ops->get_caps && + vc_ops->config_queues && + vc_ops->enable_queues && + vc_ops->disable_queues && + vc_ops->irq_map_unmap && + vc_ops->get_set_rss_lut && + vc_ops->get_set_rss_hash && + vc_ops->adjust_qs && + vc_ops->get_ptype && + vc_ops->init_max_queues)) {
if (!op1 ||
!op2 ||!opn) would look more natural and more readable here.
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 237
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6
-0+dev_err (&pdev->dev,"Invalid device, missing one or more virtchnl functions\n" ); +return -EINVAL ; + } + }else { +iecm_vc_ops_init (adapter); + }
'else' path is a two-liner allowing to save one indent level:
if (!adapter->dev_ops.vc_ops_init) {
iecm_vc_ops_init(adapter);
return 0;
}
adapter->dev_ops.vc_ops_init(adapter);
vc_ops = &adapter->dev_ops.vc_ops;
if (!(vc_ops->core_init &&
...Quoted 291 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10
-1+return 0 ; }@@ -93,7 +248,15 @@ static int iecm_api_init(struct iecm_adapter *adapter)*/ static void iecm_deinit_task (struct iecm_adapter *adapter) { -/* stub */ +set_bit (__IECM_REL_RES_IN_PROG, adapter->flags); +/* Wait until the init_task is done else this thread might release +* the resources first and the other thread might end up in a bad state +*/ +cancel_delayed_work_sync (&adapter->init_task); +iecm_vport_rel_all (adapter); + +cancel_delayed_work_sync (&adapter->serv_task); +cancel_delayed_work_sync (&adapter->stats_task); }/** drivers/net/ethernet/intel/iecm/iecm_txrx.c new file +22
-0@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#include "iecm.h" + +/** +* iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler +* @irq: interrupt number +* @data: pointer to a q_vector +* +*/ +irqreturn_t +iecm_vport_intr_clean_queues (int __always_unused irq,void *data) +{ +struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data; + + q_vector->total_events++; +napi_schedule (&q_vector->napi); + +return IRQ_HANDLED ; +} +drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +227
-0@@ -3,6 +3,74 @@#include "iecm.h" +/** +* iecm_recv_event_msg - Receive virtchnl event message +* @vport: virtual port structure +* +* Receive virtchnl event message +*/ +static void iecm_recv_event_msg (struct iecm_vport *vport) +{ +struct iecm_adapter *adapter = vport->adapter; +struct virtchnl_pf_event *vpe; +struct virtchnl2_event *v2e; +bool link_status; +u32 event; + +if (adapter->virt_ver_maj <VIRTCHNL_VERSION_MAJOR_2 ) { + vpe = (struct virtchnl_pf_event *)adapter->vc_msg; + event = vpe->event; + }else { + v2e = (struct virtchnl2_event *)adapter->vc_msg; + event =le32_to_cpu (v2e->event); + } + +switch (event) { +case VIRTCHNL2_EVENT_LINK_CHANGE : +if (adapter->virt_ver_maj <VIRTCHNL_VERSION_MAJOR_2 ) { +if (iecm_is_cap_ena (adapter,IECM_OTHER_CAPS , +VIRTCHNL2_CAP_LINK_SPEED )) { + adapter->link_speed_mbps = + vpe->event_data.link_event_adv.link_speed; + link_status = + vpe->event_data.link_event_adv.link_status; + }else { + adapter->link_speed = + vpe->event_data.link_event.link_speed; + link_status = + vpe->event_data.link_event.link_status; + } + }else { + adapter->link_speed_mbps =le32_to_cpu (v2e->link_speed); + link_status = v2e->link_status; + } +if (adapter->link_up != link_status) { + adapter->link_up = link_status; +if (adapter->state == __IECM_UP) { +if (adapter->link_up) { +netif_tx_start_all_queues (vport->netdev); +netif_carrier_on (vport->netdev); + }else { +netif_tx_stop_all_queues (vport->netdev); +netif_carrier_off (vport->netdev); + } + } + } +break ; +case VIRTCHNL_EVENT_RESET_IMPENDING : +set_bit (__IECM_HR_CORE_RESET, adapter->flags); +queue_delayed_work (adapter->vc_event_wq, + &adapter->vc_event_task, +msecs_to_jiffies (10 )); +break ; +default : +dev_err (&vport->adapter->pdev->dev, +"Unknown event %d from PF\n" , event); +break ; + } +clear_bit (__IECM_VC_MSG_PENDING, adapter->flags); +} +/** * iecm_mb_clean - Reclaim the send mailbox queue entries * @adapter: Driver specific private structure @@ -39,6 +107,865 @@ static int iecm_mb_clean(struct iecm_adapter *adapter)return err; } +/** +* iecm_send_mb_msg - Send message over mailbox +* @adapter: Driver specific private structure +* @op: virtchnl opcode +* @msg_size: size of the payload +* @msg: pointer to buffer holding the payload +* +* Will prepare the control queue message and initiates the send api +* +* Returns 0 on success, negative on failure +*/ +int iecm_send_mb_msg (struct iecm_adapter *adapter,enum virtchnl_ops op, +u16 msg_size,u8 *msg) +{ +struct iecm_ctlq_msg *ctlq_msg; +struct iecm_dma_mem *dma_mem; +int err =0 ; + +if (iecm_is_reset_detected (adapter)) +return -EBUSY ; + + err =iecm_mb_clean (adapter); +if (err) +return err; + + ctlq_msg =kzalloc (sizeof (*ctlq_msg),GFP_KERNEL ); +if (!ctlq_msg) +return -ENOMEM ; + + dma_mem =kzalloc (sizeof (*dma_mem),GFP_KERNEL ); +if (!dma_mem) { + err = -ENOMEM ; + goto dma_mem_error; + } + +memset (ctlq_msg,0 ,sizeof (struct iecm_ctlq_msg )); + ctlq_msg->opcode = iecm_mbq_opc_send_msg_to_pf; + ctlq_msg->func_id =0 ; + ctlq_msg->data_len = msg_size; + ctlq_msg->cookie.mbx.chnl_opcode = op; + ctlq_msg->cookie.mbx.chnl_retval =VIRTCHNL_STATUS_SUCCESS ; + dma_mem->size =IECM_DFLT_MBX_BUF_SIZE ; + dma_mem->va =dmam_alloc_coherent (&adapter->pdev->dev, dma_mem->size, + &dma_mem->pa,GFP_KERNEL ); +if (!dma_mem->va) { + err = -ENOMEM ; + goto dma_alloc_error; + } +memcpy (dma_mem->va, msg, msg_size); + ctlq_msg->ctx.indirect.payload = dma_mem; + + err =iecm_ctlq_send (&adapter->hw, adapter->hw.asq,1 , ctlq_msg); +if (err) + goto send_error; + +return 0 ; +send_error: +dmam_free_coherent (&adapter->pdev->dev, dma_mem->size, dma_mem->va, + dma_mem->pa); +dma_alloc_error: +kfree (dma_mem); +dma_mem_error: +kfree (ctlq_msg); +return err; +} +EXPORT_SYMBOL (iecm_send_mb_msg); + +/** +* iecm_set_msg_pending_bit - Wait for clear and set msg pending +* @adapter: driver specific private structure +* +* If clear sets msg pending bit, otherwise waits for it to clear before +* setting it again. Returns 0 on success, negative on failure. +*/ +static int iecm_set_msg_pending_bit (struct iecm_adapter *adapter) +{ +unsigned int retries =100 ; + +/* If msg pending bit already set, there's a message waiting to be +* parsed and we must wait for it to be cleared before copying a new +* message into the vc_msg buffer or else we'll stomp all over the +* previous message. +*/ +while (retries) { +if (!test_and_set_bit (__IECM_VC_MSG_PENDING, + adapter->flags)) +break ; +msleep (20 ); + retries--; + } +return retries ?0 : -ETIMEDOUT ; +} + +/** +* iecm_set_msg_pending - Wait for msg pending bit and copy msg to buf +* @adapter: driver specific private structure +* @ctlq_msg: msg to copy from +* @err_enum: err bit to set on error +* +* Copies payload from ctlq_msg into vc_msg buf in adapter and sets msg pending +* bit. Returns 0 on success, negative on failure. +*/ +int iecm_set_msg_pending (struct iecm_adapter *adapter, +struct iecm_ctlq_msg *ctlq_msg, +enum iecm_vport_vc_state err_enum) +{ +if (ctlq_msg->cookie.mbx.chnl_retval) { +set_bit (err_enum, adapter->vc_state); +return -EINVAL ; + } + +if (iecm_set_msg_pending_bit (adapter)) { +set_bit (err_enum, adapter->vc_state); +dev_info (&adapter->pdev->dev,"Timed out setting msg pending\n" ); +return -ETIMEDOUT ; + } + +memcpy (adapter->vc_msg, ctlq_msg->ctx.indirect.payload->va, +min_t (int, ctlq_msg->ctx.indirect.payload->size, +IECM_DFLT_MBX_BUF_SIZE )); +return 0 ; +} +EXPORT_SYMBOL (iecm_set_msg_pending); + +/** +* iecm_recv_mb_msg - Receive message over mailbox +* @adapter: Driver specific private structure +* @op: virtchannel operation code +* @msg: Received message holding buffer +* @msg_size: message size +* +* Will receive control queue message and posts the receive buffer. Returns 0 +* on success and negative on failure. +*/ +int iecm_recv_mb_msg (struct iecm_adapter *adapter,enum virtchnl_ops op, +void *msg,int msg_size) +{ +struct iecm_ctlq_msg ctlq_msg; +struct iecm_dma_mem *dma_mem; +struct iecm_vport *vport; +bool work_done = false; +int num_retry =2000 ; +int payload_size =0 ; +u16 num_q_msg; +int err =0 ; + + vport = adapter->vports[0 ]; +while (1 ) { +/* Try to get one message */ + num_q_msg =1 ; + dma_mem =NULL ; + err =iecm_ctlq_recv (adapter->hw.arq, &num_q_msg, &ctlq_msg); +/* If no message then decide if we have to retry based on +* opcode +*/ +if (err || !num_q_msg) { +/* Increasing num_retry to consider the delayed +* responses because of large number of VF's mailbox +* messages. If the mailbox message is received from
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 278
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+* the other side, we come out of the sleep cycle +* immediately else we wait for more time. +*/ +if (op && num_retry-- && + !test_bit (__IECM_REL_RES_IN_PROG, adapter->flags)) { +msleep (20 ); +continue ; + }else { +break ; + }
Since if-condition always ends with a 'continue', 'else' is reduntant here.
Quoted 675 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +675
-0+ } + +/* If we are here a message is received. Check if we are looking +* for a specific message based on opcode. If it is different +* ignore and post buffers +*/ +if (op && ctlq_msg.cookie.mbx.chnl_opcode != op) + goto post_buffs; + +if (ctlq_msg.data_len) + payload_size = ctlq_msg.ctx.indirect.payload->size; + +/* All conditions are met. Either a message requested is +* received or we received a message to be processed +*/ +switch (ctlq_msg.cookie.mbx.chnl_opcode) { +case VIRTCHNL_OP_VERSION : +case VIRTCHNL2_OP_GET_CAPS : +case VIRTCHNL2_OP_CREATE_VPORT : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_info (&adapter->pdev->dev,"Failure initializing, vc op: %u retval: %u\n" , + ctlq_msg.cookie.mbx.chnl_opcode, + ctlq_msg.cookie.mbx.chnl_retval); + err = -EBADMSG ; + }else if (msg) { +memcpy (msg, ctlq_msg.ctx.indirect.payload->va, +min_t (int, + payload_size, msg_size)); + } + work_done = true; +break ; +case VIRTCHNL2_OP_ENABLE_VPORT : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_ENA_VPORT_ERR , + adapter->vc_state); +set_bit (IECM_VC_ENA_VPORT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DISABLE_VPORT : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DIS_VPORT_ERR , + adapter->vc_state); +set_bit (IECM_VC_DIS_VPORT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DESTROY_VPORT : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DESTROY_VPORT_ERR , + adapter->vc_state); +set_bit (IECM_VC_DESTROY_VPORT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_CONFIG_TX_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_CONFIG_TXQ_ERR , + adapter->vc_state); +set_bit (IECM_VC_CONFIG_TXQ , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_CONFIG_RX_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_CONFIG_RXQ_ERR , + adapter->vc_state); +set_bit (IECM_VC_CONFIG_RXQ , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_ENABLE_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_ENA_QUEUES_ERR , + adapter->vc_state); +set_bit (IECM_VC_ENA_QUEUES , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DISABLE_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DIS_QUEUES_ERR , + adapter->vc_state); +set_bit (IECM_VC_DIS_QUEUES , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_ADD_QUEUES : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_ADD_QUEUES_ERR ); +set_bit (IECM_VC_ADD_QUEUES , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DEL_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DEL_QUEUES_ERR , + adapter->vc_state); +set_bit (IECM_VC_DEL_QUEUES , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_MAP_QUEUE_VECTOR : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_MAP_IRQ_ERR , + adapter->vc_state); +set_bit (IECM_VC_MAP_IRQ , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_UNMAP_IRQ_ERR , + adapter->vc_state); +set_bit (IECM_VC_UNMAP_IRQ , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_STATS : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_STATS_ERR ); +set_bit (IECM_VC_GET_STATS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_RSS_HASH : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_RSS_HASH_ERR ); +set_bit (IECM_VC_GET_RSS_HASH , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_SET_RSS_HASH : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_SET_RSS_HASH_ERR , + adapter->vc_state); +set_bit (IECM_VC_SET_RSS_HASH , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_RSS_LUT : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_RSS_LUT_ERR ); +set_bit (IECM_VC_GET_RSS_LUT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_SET_RSS_LUT : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_SET_RSS_LUT_ERR , + adapter->vc_state); +set_bit (IECM_VC_SET_RSS_LUT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_RSS_KEY : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_RSS_KEY_ERR ); +set_bit (IECM_VC_GET_RSS_KEY , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_SET_RSS_KEY : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_SET_RSS_KEY_ERR , + adapter->vc_state); +set_bit (IECM_VC_SET_RSS_KEY , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_ALLOC_VECTORS : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_ALLOC_VECTORS_ERR ); +set_bit (IECM_VC_ALLOC_VECTORS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DEALLOC_VECTORS : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DEALLOC_VECTORS_ERR , + adapter->vc_state); +set_bit (IECM_VC_DEALLOC_VECTORS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_PTYPE_INFO : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_PTYPE_INFO_ERR ); +set_bit (IECM_VC_GET_PTYPE_INFO , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_EVENT : +case VIRTCHNL_OP_EVENT : +if (iecm_set_msg_pending_bit (adapter)) { +dev_info (&adapter->pdev->dev,"Timed out setting msg pending\n" ); + }else { +memcpy (adapter->vc_msg, + ctlq_msg.ctx.indirect.payload->va, +min_t (int, payload_size, +IECM_DFLT_MBX_BUF_SIZE )); +iecm_recv_event_msg (vport); + } +break ; +case VIRTCHNL_OP_ADD_ETH_ADDR : +if (test_and_clear_bit (__IECM_ADD_ETH_REQ, adapter->flags)) { +/* Message was sent asynchronously. We don't +* normally print errors here, instead +* preferring to handle errors in the function +* calling wait_for_event. However, we will +* have lost the context in which we sent the +* message if asynchronous. We can't really do +* anything about at it this point, but we +* should at a minimum indicate that it looks +* like something went wrong. Also don't bother +* setting ERR bit or waking vchnl_wq since no +* one will be waiting to read the async +* message. +*/ +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to add MAC address: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); + } +break ; + } +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_ADD_ETH_ADDR_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_ADD_ETH_ADDR , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DEL_ETH_ADDR : +if (test_and_clear_bit (__IECM_DEL_ETH_REQ, adapter->flags)) { +/* Message was sent asynchronously. We don't +* normally print errors here, instead +* preferring to handle errors in the function +* calling wait_for_event. However, we will +* have lost the context in which we sent the +* message if asynchronous. We can't really do +* anything about at it this point, but we +* should at a minimum indicate that it looks +* like something went wrong. Also don't bother +* setting ERR bit or waking vchnl_wq since no +* one will be waiting to read the async +* message. +*/ +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to delete MAC address: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); + } +break ; + } +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_DEL_ETH_ADDR_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_DEL_ETH_ADDR , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_OFFLOAD_VLAN_V2_CAPS_ERR , adapter->vc_state); + }else { +memcpy (adapter->vc_msg, + ctlq_msg.ctx.indirect.payload->va, +min_t (int, payload_size, +IECM_DFLT_MBX_BUF_SIZE )); + } +set_bit (IECM_VC_OFFLOAD_VLAN_V2_CAPS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ADD_VLAN_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to add vlan filter: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); + } +break ; +case VIRTCHNL_OP_DEL_VLAN_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to delete vlan filter: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); + } +break ; +case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_INSERTION_ENA_VLAN_V2_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_INSERTION_ENA_VLAN_V2 , + adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_INSERTION_DIS_VLAN_V2_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_INSERTION_DIS_VLAN_V2 , + adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_STRIPPING_ENA_VLAN_V2_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_STRIPPING_ENA_VLAN_V2 , + adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_STRIPPING_DIS_VLAN_V2_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_STRIPPING_DIS_VLAN_V2 , + adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE : +/* This message can only be sent asynchronously. As +* such we'll have lost the context in which it was +* called and thus can only really report if it looks +* like an error occurred. Don't bother setting ERR bit +* or waking chnl_wq since no will be waiting to +* reading message. +*/ +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to set promiscuous mode: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); + } +break ; +case VIRTCHNL_OP_ADD_CLOUD_FILTER : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to add cloud filter: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_ADD_CLOUD_FILTER_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_ADD_CLOUD_FILTER , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DEL_CLOUD_FILTER : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to delete cloud filter: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_DEL_CLOUD_FILTER_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_DEL_CLOUD_FILTER , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ADD_RSS_CFG : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to add RSS configuration: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_ADD_RSS_CFG_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_ADD_RSS_CFG , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DEL_RSS_CFG : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to delete RSS configuration: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_DEL_RSS_CFG_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_DEL_RSS_CFG , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ADD_FDIR_FILTER : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_ADD_FDIR_FILTER_ERR ); +set_bit (IECM_VC_ADD_FDIR_FILTER , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DEL_FDIR_FILTER : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_DEL_FDIR_FILTER_ERR ); +set_bit (IECM_VC_DEL_FDIR_FILTER , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ENABLE_CHANNELS : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to enable channels: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_ENA_CHANNELS_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_ENA_CHANNELS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DISABLE_CHANNELS : +if (ctlq_msg.cookie.mbx.chnl_retval) { +dev_err (&adapter->pdev->dev,"Failed to disable channels: %d\n" , + ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_DIS_CHANNELS_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_DIS_CHANNELS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +default : +if (adapter->dev_ops.vc_ops.recv_mbx_msg) + err = + adapter->dev_ops.vc_ops.recv_mbx_msg (adapter, + msg, + msg_size, + &ctlq_msg, + &work_done); +else +dev_warn (&adapter->pdev->dev, +"Unhandled virtchnl response %d\n" , + ctlq_msg.cookie.mbx.chnl_opcode); +break ; + }/* switch v_opcode */ +post_buffs: +if (ctlq_msg.data_len) + dma_mem = ctlq_msg.ctx.indirect.payload; +else + num_q_msg =0 ; + + err =iecm_ctlq_post_rx_buffs (&adapter->hw, adapter->hw.arq, + &num_q_msg, &dma_mem); +/* If post failed clear the only buffer we supplied */ +if (err && dma_mem) +dmam_free_coherent (&adapter->pdev->dev, dma_mem->size, + dma_mem->va, dma_mem->pa); +/* Applies only if we are looking for a specific opcode */ +if (work_done) +break ; + } + +return err; +} +EXPORT_SYMBOL (iecm_recv_mb_msg); + +/** +* iecm_send_ver_msg - send virtchnl version message +* @adapter: Driver specific private structure +* +* Send virtchnl version message. Returns 0 on success, negative on failure. +*/ +static int iecm_send_ver_msg (struct iecm_adapter *adapter) +{ +struct virtchnl_version_info vvi; + +if (adapter->virt_ver_maj) { + vvi.major = adapter->virt_ver_maj; + vvi.minor = adapter->virt_ver_min; + }else { + vvi.major =IECM_VIRTCHNL_VERSION_MAJOR ; + vvi.minor =IECM_VIRTCHNL_VERSION_MINOR ; + } + +return iecm_send_mb_msg (adapter,VIRTCHNL_OP_VERSION ,sizeof (vvi), + (u8 *)&vvi); +} + +/** +* iecm_recv_ver_msg - Receive virtchnl version message +* @adapter: Driver specific private structure +* +* Receive virtchnl version message. Returns 0 on success, -EAGAIN if we need +* to send version message again, otherwise negative on failure. +*/ +static int iecm_recv_ver_msg (struct iecm_adapter *adapter) +{ +struct virtchnl_version_info vvi; +int err =0 ; + + err =iecm_recv_mb_msg (adapter,VIRTCHNL_OP_VERSION , &vvi,sizeof (vvi)); +if (err) +return err; + +if (vvi.major >IECM_VIRTCHNL_VERSION_MAJOR ) { +dev_warn (&adapter->pdev->dev,"Virtchnl major version greater than supported\n" ); +return -EINVAL ; + } +if (vvi.major ==IECM_VIRTCHNL_VERSION_MAJOR && + vvi.minor >IECM_VIRTCHNL_VERSION_MINOR ) +dev_warn (&adapter->pdev->dev,"Virtchnl minor version not matched\n" ); + +/* If we have a mismatch, resend version to update receiver on what +* version we will use. +*/ +if (!adapter->virt_ver_maj && + vvi.major !=IECM_VIRTCHNL_VERSION_MAJOR && + vvi.minor !=IECM_VIRTCHNL_VERSION_MINOR ) + err = -EAGAIN ; + + adapter->virt_ver_maj = vvi.major; + adapter->virt_ver_min = vvi.minor; + +return err; +} + +/** +* iecm_send_get_caps_msg - Send virtchnl get capabilities message +* @adapter: Driver specific private structure +* +* Send virtchl get capabilities message. Returns 0 on success, negative on +* failure. +*/ +int iecm_send_get_caps_msg (struct iecm_adapter *adapter) +{ +struct virtchnl2_get_capabilities caps = {0 }; +int buf_size; + + buf_size =sizeof (struct virtchnl2_get_capabilities ); + adapter->caps =kzalloc (buf_size,GFP_KERNEL ); +if (!adapter->caps) +return -ENOMEM ; + + caps.csum_caps = +cpu_to_le32 (VIRTCHNL2_CAP_TX_CSUM_L3_IPV4 | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP | +VIRTCHNL2_CAP_TX_CSUM_GENERIC | +VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP | +VIRTCHNL2_CAP_RX_CSUM_GENERIC ); + + caps.seg_caps = +cpu_to_le32 (VIRTCHNL2_CAP_SEG_IPV4_TCP | +VIRTCHNL2_CAP_SEG_IPV4_UDP | +VIRTCHNL2_CAP_SEG_IPV4_SCTP | +VIRTCHNL2_CAP_SEG_IPV6_TCP | +VIRTCHNL2_CAP_SEG_IPV6_UDP | +VIRTCHNL2_CAP_SEG_IPV6_SCTP | +VIRTCHNL2_CAP_SEG_GENERIC ); + + caps.rss_caps = +cpu_to_le64 (VIRTCHNL2_CAP_RSS_IPV4_TCP | +VIRTCHNL2_CAP_RSS_IPV4_UDP | +VIRTCHNL2_CAP_RSS_IPV4_SCTP | +VIRTCHNL2_CAP_RSS_IPV4_OTHER | +VIRTCHNL2_CAP_RSS_IPV6_TCP | +VIRTCHNL2_CAP_RSS_IPV6_UDP | +VIRTCHNL2_CAP_RSS_IPV6_SCTP | +VIRTCHNL2_CAP_RSS_IPV6_OTHER | +VIRTCHNL2_CAP_RSS_IPV4_AH | +VIRTCHNL2_CAP_RSS_IPV4_ESP | +VIRTCHNL2_CAP_RSS_IPV4_AH_ESP | +VIRTCHNL2_CAP_RSS_IPV6_AH | +VIRTCHNL2_CAP_RSS_IPV6_ESP | +VIRTCHNL2_CAP_RSS_IPV6_AH_ESP ); + + caps.hsplit_caps = +cpu_to_le32 (VIRTCHNL2_CAP_RX_HSPLIT_AT_L2 | +VIRTCHNL2_CAP_RX_HSPLIT_AT_L3 | +VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 | +VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6 ); + + caps.rsc_caps = +cpu_to_le32 (VIRTCHNL2_CAP_RSC_IPV4_TCP | +VIRTCHNL2_CAP_RSC_IPV4_SCTP | +VIRTCHNL2_CAP_RSC_IPV6_TCP | +VIRTCHNL2_CAP_RSC_IPV6_SCTP ); + + caps.other_caps = +cpu_to_le64 (VIRTCHNL2_CAP_RDMA | +VIRTCHNL2_CAP_SRIOV | +VIRTCHNL2_CAP_MACFILTER | +VIRTCHNL2_CAP_FLOW_DIRECTOR | +VIRTCHNL2_CAP_SPLITQ_QSCHED | +VIRTCHNL2_CAP_CRC | +VIRTCHNL2_CAP_ADQ | +VIRTCHNL2_CAP_WB_ON_ITR | +VIRTCHNL2_CAP_PROMISC | +VIRTCHNL2_CAP_INLINE_IPSEC | +VIRTCHNL2_CAP_VLAN | +VIRTCHNL2_CAP_RX_FLEX_DESC ); + +return iecm_send_mb_msg (adapter,VIRTCHNL2_OP_GET_CAPS ,sizeof (caps), + (u8 *)&caps); +} +EXPORT_SYMBOL (iecm_send_get_caps_msg); + +/** +* iecm_recv_get_caps_msg - Receive virtchnl get capabilities message +* @adapter: Driver specific private structure +* +* Receive virtchnl get capabilities message. Returns 0 on succes, negative on +* failure. +*/ +static int iecm_recv_get_caps_msg (struct iecm_adapter *adapter) +{ +return iecm_recv_mb_msg (adapter,VIRTCHNL2_OP_GET_CAPS , adapter->caps, +sizeof (struct virtchnl2_get_capabilities )); +} + +/** +* iecm_send_create_vport_msg - Send virtchnl create vport message +* @adapter: Driver specific private structure +* +* send virtchnl creae vport message +* +* Returns 0 on success, negative on failure +*/ +static int iecm_send_create_vport_msg (struct iecm_adapter *adapter) +{ +/* stub */ +return 0 ; +} + +/** +* iecm_recv_create_vport_msg - Receive virtchnl create vport message +* @adapter: Driver specific private structure +* @vport_id: Virtual port identifier +* +* Receive virtchnl create vport message. Returns 0 on success, negative on +* failure. +*/ +static int iecm_recv_create_vport_msg (struct iecm_adapter *adapter, +int *vport_id) +{ +/* stub */ +return 0 ; +} + +/** +* __iecm_wait_for_event - wrapper function for wait on virtchannel response +* @adapter: Driver private data structure +* @state: check on state upon timeout +* @err_check: check if this specific error bit is set +* @timeout: Max time to wait +* +* Checks if state is set upon expiry of timeout. Returns 0 on success, +* negative on failure. +*/ +static int __iecm_wait_for_event (struct iecm_adapter *adapter, +enum iecm_vport_vc_state state, +enum iecm_vport_vc_state err_check, +int timeout) +{ +int event; + + event =wait_event_timeout (adapter->vchnl_wq, +test_and_clear_bit (state, adapter->vc_state), +msecs_to_jiffies (timeout)); +if (event) { +if (test_and_clear_bit (err_check, adapter->vc_state)) { +dev_err (&adapter->pdev->dev,"VC response error %s\n" , + iecm_vport_vc_state_str[err_check]); +return -EINVAL ; + } +return 0 ; + } + +/* Timeout occurred */ +dev_err (&adapter->pdev->dev,"VC timeout, state = %s\n" , + iecm_vport_vc_state_str[state]); +return -ETIMEDOUT ; +} + +/** +* iecm_min_wait_for_event - wait for virtchannel response +* @adapter: Driver private data structure +* @state: check on state upon timeout +* @err_check: check if this specific error bit is set +* +* Returns 0 on success, negative on failure. +*/ +int iecm_min_wait_for_event (struct iecm_adapter *adapter, +enum iecm_vport_vc_state state, +enum iecm_vport_vc_state err_check) +{ +int timeout =2000 ; + +return __iecm_wait_for_event (adapter, state, err_check, timeout); +} +EXPORT_SYMBOL (iecm_min_wait_for_event); + +/** +* iecm_wait_for_event - wait for virtchannel response +* @adapter: Driver private data structure +* @state: check on state upon timeout after 500ms +* @err_check: check if this specific error bit is set +* +* Returns 0 on success, negative on failure. +*/ +int iecm_wait_for_event(struct iecm_adapter *adapter, + enum iecm_vport_vc_state state,
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 963
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ enum iecm_vport_vc_state err_check) +{ +/* Increasing the timeout in __IECM_INIT_SW flow to consider large +* number of VF's mailbox message responses. When a message is received +* on mailbox, this thread is wake up by the iecm_recv_mb_msg before the +* timeout expires. Only in the error case i.e. if no message is +* received on mailbox, we wait for the complete timeout which is +* less likely to happen. +*/ +int timeout =60000 ;
If you make a definition from it, it would be easier to find it later in case of adjustments needed.
Quoted 660 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +377
-0+ +return __iecm_wait_for_event (adapter, state, err_check, timeout); +} +EXPORT_SYMBOL (iecm_wait_for_event); +/** * iecm_find_ctlq - Given a type and id, find ctlq info * @hw: hardware struct @@ -170,3 +1097,375 @@ void iecm_vport_params_buf_rel(struct iecm_adapter *adapter)kfree (adapter->caps);kfree (adapter->config_data.req_qs_chunks); } + +/** +* iecm_vc_core_init - Initialize mailbox and get resources +* @adapter: Driver specific private structure +* @vport_id: Virtual port identifier +* +* Will check if HW is ready with reset complete. Initializes the mailbox and +* communicate with master to get all the default vport parameters. Returns 0 +* on success, -EAGAIN function will get called again, otherwise negative on +* failure. +*/ +int iecm_vc_core_init (struct iecm_adapter *adapter,int *vport_id) +{ +int err; + +switch (adapter->state) { +case __IECM_STARTUP: +if (iecm_send_ver_msg (adapter)) + goto init_failed; + adapter->state = __IECM_VER_CHECK; + goto restart; +case __IECM_VER_CHECK: + err =iecm_recv_ver_msg (adapter); +if (err == -EAGAIN ) { + adapter->state = __IECM_STARTUP; + goto restart; + }else if (err) { + goto init_failed; + } + adapter->state = __IECM_GET_CAPS; +if (adapter->dev_ops.vc_ops.get_caps (adapter)) + goto init_failed; + goto restart; +case __IECM_GET_CAPS: +if (iecm_recv_get_caps_msg (adapter)) + goto init_failed; +if (iecm_send_create_vport_msg (adapter)) + goto init_failed; + adapter->state = __IECM_GET_DFLT_VPORT_PARAMS; + goto restart; +case __IECM_GET_DFLT_VPORT_PARAMS: +if (iecm_recv_create_vport_msg (adapter, vport_id)) + goto init_failed; + adapter->state = __IECM_INIT_SW; +break ; +case __IECM_INIT_SW: +break ; +default : +dev_err (&adapter->pdev->dev,"Device is in bad state: %d\n" , + adapter->state); + goto init_failed; + } + +return 0 ; +restart: +queue_delayed_work (adapter->init_wq, &adapter->init_task, +msecs_to_jiffies (30 )); +/* Not an error. Using try again to continue with state machine */ +return -EAGAIN ; +init_failed: +if (++adapter->mb_wait_count >IECM_MB_MAX_ERR ) { +dev_err (&adapter->pdev->dev,"Failed to establish mailbox communications with hardware\n" ); +return -EFAULT ; + } + adapter->state = __IECM_STARTUP; +/* If it reaches here, it is possible that mailbox queue initialization +* register writes might not have taken effect. Retry to initialize +* the mailbox again +*/ +iecm_deinit_dflt_mbx (adapter); +set_bit (__IECM_HR_DRV_LOAD, adapter->flags); +queue_delayed_work (adapter->vc_event_wq, &adapter->vc_event_task, +msecs_to_jiffies (20 )); +return -EAGAIN ; +} +EXPORT_SYMBOL (iecm_vc_core_init); + +/** +* iecm_vport_init - Initialize virtual port +* @vport: virtual port to be initialized +* @vport_id: Unique identification number of vport +* +* Will initialize vport with the info received through MB earlier +*/ +static void iecm_vport_init (struct iecm_vport *vport, +__always_unused int vport_id) +{ +struct virtchnl2_create_vport *vport_msg; +u16 rx_itr[] = {2 ,8 ,32 ,96 ,128 }; +u16 tx_itr[] = {2 ,8 ,64 ,128 ,256 }; + + vport_msg = (struct virtchnl2_create_vport *) + vport->adapter->vport_params_recvd[0 ]; + vport->txq_model =le16_to_cpu (vport_msg->txq_model); + vport->rxq_model =le16_to_cpu (vport_msg->rxq_model); + vport->vport_type =le16_to_cpu (vport_msg->vport_type); + vport->vport_id =le32_to_cpu (vport_msg->vport_id); + vport->adapter->rss_data.rss_key_size = +min_t (u16,NETDEV_RSS_KEY_LEN , +le16_to_cpu (vport_msg->rss_key_size)); + vport->adapter->rss_data.rss_lut_size = +le16_to_cpu (vport_msg->rss_lut_size); +ether_addr_copy (vport->default_mac_addr, vport_msg->default_mac_addr); + vport->max_mtu =IECM_MAX_MTU ; + +if (iecm_is_queue_model_split (vport->rxq_model)) { + vport->num_bufqs_per_qgrp =IECM_MAX_BUFQS_PER_RXQ_GRP ; +/* Bufq[0] default buffer size is 4K +* Bufq[1] default buffer size is 2K +*/ + vport->bufq_size[0 ] =IECM_RX_BUF_4096 ; + vport->bufq_size[1 ] =IECM_RX_BUF_2048 ; + }else { + vport->num_bufqs_per_qgrp =0 ; + vport->bufq_size[0 ] =IECM_RX_BUF_2048 ; + } + +/*Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */ +memcpy (vport->rx_itr_profile, rx_itr,IECM_DIM_PROFILE_SLOTS ); +memcpy (vport->tx_itr_profile, tx_itr,IECM_DIM_PROFILE_SLOTS ); +} + +/** +* iecm_get_vec_ids - Initialize vector id from Mailbox parameters +* @adapter: adapter structure to get the mailbox vector id +* @vecids: Array of vector ids +* @num_vecids: number of vector ids +* @chunks: vector ids received over mailbox +* +* Will initialize the mailbox vector id which is received from the +* get capabilities and data queue vector ids with ids received as +* mailbox parameters. +* Returns number of ids filled +*/ +int iecm_get_vec_ids (struct iecm_adapter *adapter, +u16 *vecids,int num_vecids, +struct virtchnl2_vector_chunks *chunks) +{ +u16 num_chunks =le16_to_cpu (chunks->num_vchunks); +u16 start_vecid, num_vec; +int num_vecid_filled =0 ; +int i, j; + + vecids[num_vecid_filled] = adapter->mb_vector.v_idx; + num_vecid_filled++; + +for (j =0 ; j < num_chunks; j++) { +struct virtchnl2_vector_chunk *chunk = &chunks->vchunks[j]; + + num_vec =le16_to_cpu (chunk->num_vectors); + start_vecid =le16_to_cpu (chunk->start_vector_id); +for (i =0 ; i < num_vec; i++) { +if ((num_vecid_filled + i) < num_vecids) { + vecids[num_vecid_filled + i] = start_vecid; + start_vecid++; + }else { +break ; + } + } + num_vecid_filled = num_vecid_filled + i; + } + +return num_vecid_filled; +} + +/** +* iecm_vport_get_queue_ids - Initialize queue id from Mailbox parameters +* @qids: Array of queue ids +* @num_qids: number of queue ids +* @q_type: queue model +* @chunks: queue ids received over mailbox +* +* Will initialize all queue ids with ids received as mailbox parameters +* Returns number of ids filled +*/ +static int +iecm_vport_get_queue_ids (u32 *qids,int num_qids,u16 q_type, +struct virtchnl2_queue_reg_chunks *chunks) +{ +u16 num_chunks =le16_to_cpu (chunks->num_chunks); +u32 num_q_id_filled =0 , i; +u32 start_q_id, num_q; + +while (num_chunks) { +struct virtchnl2_queue_reg_chunk *chunk = &chunks->chunks[num_chunks -1 ]; + +if (le32_to_cpu (chunk->type) == q_type) { + num_q =le32_to_cpu (chunk->num_queues); + start_q_id =le32_to_cpu (chunk->start_queue_id); +for (i =0 ; i < num_q; i++) { +if ((num_q_id_filled + i) < num_qids) { + qids[num_q_id_filled + i] = start_q_id; + start_q_id++; + }else { +break ; + } + } + num_q_id_filled = num_q_id_filled + i; + } + num_chunks--; + } + +return num_q_id_filled; +} + +/** +* __iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters +* @vport: virtual port for which the queues ids are initialized +* @qids: queue ids +* @num_qids: number of queue ids +* @q_type: type of queue +* +* Will initialize all queue ids with ids received as mailbox +* parameters. Returns number of queue ids initialized. +*/ +static int +__iecm_vport_queue_ids_init (struct iecm_vport *vport,u32 *qids, +int num_qids,u32 q_type) +{ +/* stub */ +return 0 ; +} + +/** +* iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters +* @vport: virtual port for which the queues ids are initialized +* +* Will initialize all queue ids with ids received as mailbox parameters. +* Returns 0 on success, negative if all the queues are not initialized. +*/ +static int iecm_vport_queue_ids_init (struct iecm_vport *vport) +{ +struct virtchnl2_create_vport *vport_params; +struct virtchnl2_queue_reg_chunks *chunks; +/* We may never deal with more than 256 same type of queues */ +#define IECM_MAX_QIDS 256 +u32 qids[IECM_MAX_QIDS ]; +int num_ids; +u16 q_type; + +if (vport->adapter->config_data.req_qs_chunks) { +struct virtchnl2_add_queues *vc_aq = + (struct virtchnl2_add_queues *) + vport->adapter->config_data.req_qs_chunks; + chunks = &vc_aq->chunks; + }else { + vport_params = (struct virtchnl2_create_vport *) + vport->adapter->vport_params_recvd[0 ]; + chunks = &vport_params->chunks; + } + + num_ids =iecm_vport_get_queue_ids (qids,IECM_MAX_QIDS , +VIRTCHNL2_QUEUE_TYPE_TX , + chunks); +if (num_ids != vport->num_txq) +return -EINVAL ; + num_ids =__iecm_vport_queue_ids_init (vport, qids, num_ids, +VIRTCHNL2_QUEUE_TYPE_TX ); +if (num_ids != vport->num_txq) +return -EINVAL ; + num_ids =iecm_vport_get_queue_ids (qids,IECM_MAX_QIDS , +VIRTCHNL2_QUEUE_TYPE_RX , + chunks); +if (num_ids != vport->num_rxq) +return -EINVAL ; + num_ids =__iecm_vport_queue_ids_init (vport, qids, num_ids, +VIRTCHNL2_QUEUE_TYPE_RX ); +if (num_ids != vport->num_rxq) +return -EINVAL ; + +if (iecm_is_queue_model_split (vport->txq_model)) { + q_type =VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION ; + num_ids =iecm_vport_get_queue_ids (qids,IECM_MAX_QIDS , q_type, + chunks); +if (num_ids != vport->num_complq) +return -EINVAL ; + num_ids =__iecm_vport_queue_ids_init (vport, qids, + num_ids, + q_type); +if (num_ids != vport->num_complq) +return -EINVAL ; + } + +if (iecm_is_queue_model_split (vport->rxq_model)) { + q_type =VIRTCHNL2_QUEUE_TYPE_RX_BUFFER ; + num_ids =iecm_vport_get_queue_ids (qids,IECM_MAX_QIDS , q_type, + chunks); +if (num_ids != vport->num_bufq) +return -EINVAL ; + num_ids =__iecm_vport_queue_ids_init (vport, qids, num_ids, + q_type); +if (num_ids != vport->num_bufq) +return -EINVAL ; + } + +return 0 ; +} + +/** +* iecm_is_capability_ena - Default implementation of capability checking +* @adapter: Private data struct +* @all: all or one flag +* @field: caps field to check for flags +* @flag: flag to check +* +* Return true if all capabilities are supported, false otherwise +*/ +static bool iecm_is_capability_ena (struct iecm_adapter *adapter,bool all, +enum iecm_cap_field field,u64 flag) +{ +u8 *caps = (u8 *)adapter->caps; +u32 *cap_field; + +if (field ==IECM_BASE_CAPS ) +return false; +if (field >=IECM_CAP_FIELD_LAST ) { +dev_err (&adapter->pdev->dev,"Bad capability field: %d\n" , + field); +return false; + } + cap_field = (u32 *)(caps + field); + +if (all) +return (*cap_field & flag) == flag; +else +return !!(*cap_field & flag); +} + +/** +* iecm_vc_ops_init - Initialize virtchnl common api +* @adapter: Driver specific private structure +* +* Initialize the function pointers with the extended feature set functions +* as APF will deal only with new set of opcodes. +*/ +void iecm_vc_ops_init (struct iecm_adapter *adapter) +{ +struct iecm_virtchnl_ops *vc_ops = &adapter->dev_ops.vc_ops; + + vc_ops->core_init = iecm_vc_core_init; + vc_ops->vport_init = iecm_vport_init; + vc_ops->vport_queue_ids_init = iecm_vport_queue_ids_init; + vc_ops->get_caps = iecm_send_get_caps_msg; + vc_ops->is_cap_ena = iecm_is_capability_ena; + vc_ops->get_reserved_vecs =NULL ; + vc_ops->config_queues =NULL ; + vc_ops->enable_queues =NULL ; + vc_ops->disable_queues =NULL ; + vc_ops->add_queues =NULL ; + vc_ops->delete_queues =NULL ; + vc_ops->irq_map_unmap =NULL ; + vc_ops->enable_vport =NULL ; + vc_ops->disable_vport =NULL ; + vc_ops->destroy_vport =NULL ; + vc_ops->get_ptype =NULL ; + vc_ops->get_set_rss_key =NULL ; + vc_ops->get_set_rss_lut =NULL ; + vc_ops->get_set_rss_hash =NULL ; + vc_ops->adjust_qs =NULL ; + vc_ops->add_del_vlans =NULL ; + vc_ops->strip_vlan_msg =NULL ; + vc_ops->insert_vlan_msg =NULL ; + vc_ops->init_max_queues =NULL ; + vc_ops->get_max_tx_bufs =NULL ; + vc_ops->vportq_reg_init =NULL ; + vc_ops->alloc_vectors =NULL ; + vc_ops->dealloc_vectors =NULL ; + vc_ops->get_supported_desc_ids =NULL ; + vc_ops->get_stats_msg =NULL ; + vc_ops->recv_mbx_msg =NULL ; +} +EXPORT_SYMBOL (iecm_vc_ops_init);drivers/net/ethernet/intel/include/iecm.h +231
-1@@ -7,10 +7,13 @@#include <linux/aer.h> #include <linux/pci.h> #include <linux/netdevice.h> +#include <linux/etherdevice.h> #include <linux/ethtool.h> +#include <net/tcp.h> #include <linux/version.h> #include <linux/dim.h> +#include "virtchnl_2.h" #include "iecm_txrx.h" #include "iecm_controlq.h" @@ -35,10 +38,34 @@/* available message levels */ #define IECM_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK) +#define IECM_VIRTCHNL_VERSION_MAJOR VIRTCHNL_VERSION_MAJOR_2 +#define IECM_VIRTCHNL_VERSION_MINOR VIRTCHNL_VERSION_MINOR_0 +/* Forward declaration */ struct iecm_adapter ;struct iecm_vport ; +struct iecm_mac_filter { +struct list_head list; +u8 macaddr[ETH_ALEN ]; +bool remove;/* filter needs to be removed */ +bool add;/* filter needs to be added */ +}; + +#define IECM_VLAN (vid, tpid) ((struct iecm_vlan){ vid, tpid }) + +struct iecm_vlan { +u16 vid; +u16 tpid; +}; + +struct iecm_vlan_filter { +struct list_head list; +struct iecm_vlan vlan; +bool remove;/* filter needs to be removed */ +bool add;/* filter needs to be added */ +}; +enum iecm_state { __IECM_STARTUP, __IECM_VER_CHECK,@@ -90,6 +117,24 @@ enum iecm_flags { __IECM_FLAGS_NBITS, }; +/* enum used to distinquish which capability field to check */ +enum iecm_cap_field { +IECM_BASE_CAPS =-1 , +IECM_CSUM_CAPS = offsetof(struct virtchnl2_get_capabilities , + csum_caps), +IECM_SEG_CAPS = offsetof(struct virtchnl2_get_capabilities , + seg_caps), +IECM_RSS_CAPS = offsetof(struct virtchnl2_get_capabilities , + rss_caps), +IECM_HSPLIT_CAPS = offsetof(struct virtchnl2_get_capabilities , + hsplit_caps), +IECM_RSC_CAPS = offsetof(struct virtchnl2_get_capabilities , + rsc_caps), +IECM_OTHER_CAPS = offsetof(struct virtchnl2_get_capabilities , + other_caps), +IECM_CAP_FIELD_LAST , +}; +struct iecm_reset_reg {u32 rstat;u32 rstat_m;@@ -105,14 +150,229 @@ struct iecm_reg_ops { enum iecm_flags trig_cause); }; +struct iecm_virtchnl_ops { +int (*core_init)(struct iecm_adapter *adapter,int *vport_id); +void (*vport_init)(struct iecm_vport *vport,int vport_id); +int (*vport_queue_ids_init)(struct iecm_vport *vport); +int (*get_caps)(struct iecm_adapter *adapter); +int (*config_queues)(struct iecm_vport *vport); +int (*enable_queues)(struct iecm_vport *vport); +int (*disable_queues)(struct iecm_vport *vport); +int (*add_queues)(struct iecm_vport *vport,u16 num_tx_q, +u16 num_complq,u16 num_rx_q, +u16 num_rx_bufq); +int (*delete_queues)(struct iecm_vport *vport); +int (*irq_map_unmap)(struct iecm_vport *vport,bool map); +int (*enable_vport)(struct iecm_vport *vport); +int (*disable_vport)(struct iecm_vport *vport); +int (*destroy_vport)(struct iecm_vport *vport); +int (*get_ptype)(struct iecm_vport *vport); +int (*get_set_rss_key)(struct iecm_vport *vport,bool get); +int (*get_set_rss_lut)(struct iecm_vport *vport,bool get); +int (*get_set_rss_hash)(struct iecm_vport *vport,bool get); +void (*adjust_qs)(struct iecm_vport *vport); +int (*recv_mbx_msg)(struct iecm_adapter *adapter, +void *msg,int msg_size, +struct iecm_ctlq_msg *ctlq_msg,bool *work_done); +bool (*is_cap_ena)(struct iecm_adapter *adapter,bool all, +enum iecm_cap_field field,u64 flag); +u16 (*get_reserved_vecs)(struct iecm_adapter *adapter); +void (*add_del_vlans)(struct iecm_vport *vport,bool add); +int (*strip_vlan_msg)(struct iecm_vport *vport,bool ena); +int (*insert_vlan_msg)(struct iecm_vport *vport,bool ena); +void (*init_max_queues)(struct iecm_adapter *adapter); +unsigned int (*get_max_tx_bufs)(struct iecm_adapter *adapter); +int (*vportq_reg_init)(struct iecm_vport *vport); +int (*alloc_vectors)(struct iecm_adapter *adapter,u16 num_vectors); +int (*dealloc_vectors)(struct iecm_adapter *adapter); +int (*get_supported_desc_ids)(struct iecm_vport *vport); +int (*get_stats_msg)(struct iecm_vport *vport); +}; +struct iecm_dev_ops {void (*reg_ops_init)(struct iecm_adapter *adapter); +void (*vc_ops_init)(struct iecm_adapter *adapter);void (*crc_enable)(u64 *td_cmd);struct iecm_reg_ops reg_ops; +struct iecm_virtchnl_ops vc_ops; +}; + +/* These macros allow us to generate an enum and a matching char * array of +* stringified enums that are always in sync. Checkpatch issues a bogus warning +* about this being a complex macro; but it's wrong, these are never used as a +* statement and instead only used to define the enum and array. +*/ +#define IECM_FOREACH_VPORT_VC_STATE (STATE ) \ + STATE(IECM_VC_ENA_VPORT) \ + STATE(IECM_VC_ENA_VPORT_ERR) \ + STATE(IECM_VC_DIS_VPORT) \ + STATE(IECM_VC_DIS_VPORT_ERR) \ + STATE(IECM_VC_DESTROY_VPORT) \ + STATE(IECM_VC_DESTROY_VPORT_ERR) \ + STATE(IECM_VC_CONFIG_TXQ) \ + STATE(IECM_VC_CONFIG_TXQ_ERR) \ + STATE(IECM_VC_CONFIG_RXQ) \ + STATE(IECM_VC_CONFIG_RXQ_ERR) \ + STATE(IECM_VC_CONFIG_Q) \ + STATE(IECM_VC_CONFIG_Q_ERR) \ + STATE(IECM_VC_ENA_QUEUES) \ + STATE(IECM_VC_ENA_QUEUES_ERR) \ + STATE(IECM_VC_DIS_QUEUES) \ + STATE(IECM_VC_DIS_QUEUES_ERR) \ + STATE(IECM_VC_ENA_CHANNELS) \ + STATE(IECM_VC_ENA_CHANNELS_ERR) \ + STATE(IECM_VC_DIS_CHANNELS) \ + STATE(IECM_VC_DIS_CHANNELS_ERR) \ + STATE(IECM_VC_MAP_IRQ) \ + STATE(IECM_VC_MAP_IRQ_ERR) \ + STATE(IECM_VC_UNMAP_IRQ) \ + STATE(IECM_VC_UNMAP_IRQ_ERR) \ + STATE(IECM_VC_ADD_QUEUES) \ + STATE(IECM_VC_ADD_QUEUES_ERR) \ + STATE(IECM_VC_DEL_QUEUES) \ + STATE(IECM_VC_REQUEST_QUEUES) \ + STATE(IECM_VC_REQUEST_QUEUES_ERR) \ + STATE(IECM_VC_DEL_QUEUES_ERR) \ + STATE(IECM_VC_ALLOC_VECTORS) \ + STATE(IECM_VC_ALLOC_VECTORS_ERR) \ + STATE(IECM_VC_DEALLOC_VECTORS) \ + STATE(IECM_VC_DEALLOC_VECTORS_ERR) \ + STATE(IECM_VC_SET_SRIOV_VFS) \ + STATE(IECM_VC_SET_SRIOV_VFS_ERR) \ + STATE(IECM_VC_GET_RSS_HASH) \ + STATE(IECM_VC_GET_RSS_HASH_ERR) \ + STATE(IECM_VC_SET_RSS_HASH) \ + STATE(IECM_VC_SET_RSS_HASH_ERR) \ + STATE(IECM_VC_GET_RSS_LUT) \ + STATE(IECM_VC_GET_RSS_LUT_ERR) \ + STATE(IECM_VC_SET_RSS_LUT) \ + STATE(IECM_VC_SET_RSS_LUT_ERR) \ + STATE(IECM_VC_GET_RSS_KEY) \ + STATE(IECM_VC_GET_RSS_KEY_ERR) \ + STATE(IECM_VC_SET_RSS_KEY) \ + STATE(IECM_VC_SET_RSS_KEY_ERR) \ + STATE(IECM_VC_GET_STATS) \ + STATE(IECM_VC_GET_STATS_ERR) \ + STATE(IECM_VC_ENA_STRIP_VLAN_TAG) \ + STATE(IECM_VC_ENA_STRIP_VLAN_TAG_ERR) \ + STATE(IECM_VC_DIS_STRIP_VLAN_TAG) \ + STATE(IECM_VC_DIS_STRIP_VLAN_TAG_ERR) \ + STATE(IECM_VC_IWARP_IRQ_MAP) \ + STATE(IECM_VC_IWARP_IRQ_MAP_ERR) \ + STATE(IECM_VC_ADD_ETH_ADDR) \ + STATE(IECM_VC_ADD_ETH_ADDR_ERR) \ + STATE(IECM_VC_DEL_ETH_ADDR) \ + STATE(IECM_VC_DEL_ETH_ADDR_ERR) \ + STATE(IECM_VC_PROMISC) \ + STATE(IECM_VC_ADD_CLOUD_FILTER) \ + STATE(IECM_VC_ADD_CLOUD_FILTER_ERR) \ + STATE(IECM_VC_DEL_CLOUD_FILTER) \ + STATE(IECM_VC_DEL_CLOUD_FILTER_ERR) \ + STATE(IECM_VC_ADD_RSS_CFG) \ + STATE(IECM_VC_ADD_RSS_CFG_ERR) \ + STATE(IECM_VC_DEL_RSS_CFG) \ + STATE(IECM_VC_DEL_RSS_CFG_ERR) \ + STATE(IECM_VC_ADD_FDIR_FILTER) \ + STATE(IECM_VC_ADD_FDIR_FILTER_ERR) \ + STATE(IECM_VC_DEL_FDIR_FILTER) \ + STATE(IECM_VC_DEL_FDIR_FILTER_ERR) \ + STATE(IECM_VC_OFFLOAD_VLAN_V2_CAPS) \ + STATE(IECM_VC_OFFLOAD_VLAN_V2_CAPS_ERR) \ + STATE(IECM_VC_INSERTION_ENA_VLAN_V2) \ + STATE(IECM_VC_INSERTION_ENA_VLAN_V2_ERR)\ + STATE(IECM_VC_INSERTION_DIS_VLAN_V2) \ + STATE(IECM_VC_INSERTION_DIS_VLAN_V2_ERR)\ + STATE(IECM_VC_STRIPPING_ENA_VLAN_V2) \ + STATE(IECM_VC_STRIPPING_ENA_VLAN_V2_ERR)\ + STATE(IECM_VC_STRIPPING_DIS_VLAN_V2) \ + STATE(IECM_VC_STRIPPING_DIS_VLAN_V2_ERR)\ + STATE(IECM_VC_GET_SUPPORTED_RXDIDS) \ + STATE(IECM_VC_GET_SUPPORTED_RXDIDS_ERR) \ + STATE(IECM_VC_GET_PTYPE_INFO) \ + STATE(IECM_VC_GET_PTYPE_INFO_ERR) \ + STATE(IECM_VC_NBITS) + +#define IECM_GEN_ENUM (ENUM ) ENUM, +#define IECM_GEN_STRING (STRING ) #STRING, + +enum iecm_vport_vc_state { + IECM_FOREACH_VPORT_VC_STATE(IECM_GEN_ENUM) +}; + +extern const char *const iecm_vport_vc_state_str[]; + +enum iecm_vport_flags { + __IECM_VPORT_INIT_PROMISC, + __IECM_VPORT_FLAGS_NBITS, +}; + +struct iecm_port_stats { +struct u64_stats_sync stats_sync; +u64 rx_hw_csum_err; +u64 rx_hsplit; +u64 rx_hsplit_hbo; +u64 tx_linearize; +u64 rx_bad_descs; +struct virtchnl2_vport_stats vport_stats; +struct virtchnl_eth_stats eth_stats; }; -/* stub */ struct iecm_vport { +/* TX */ +int num_txq; +int num_complq; +/* It makes more sense for descriptor count to be part of only idpf +* queue structure. But when user changes the count via ethtool, driver +* has to store that value somewhere other than queue structure as the +* queues will be freed and allocated again. +*/ +int txq_desc_count; +int complq_desc_count; +int compln_clean_budget; +int num_txq_grp; +struct iecm_txq_group *txq_grps; +u32 txq_model; +/* Used only in hotpath to get to the right queue very fast */ +struct iecm_queue **txqs; + DECLARE_BITMAP(flags, __IECM_VPORT_FLAGS_NBITS); + +/* RX */ +int num_rxq; +int num_bufq; +int rxq_desc_count; +u8 num_bufqs_per_qgrp; +int bufq_desc_count[IECM_MAX_BUFQS_PER_RXQ_GRP ]; +u32 bufq_size[IECM_MAX_BUFQS_PER_RXQ_GRP ];
drivers/net/ethernet/intel/include/iecm.h struct iecm_reg_ops { · line 355
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm.h +10
-0+int num_rxq_grp; +struct iecm_rxq_group *rxq_grps; +u32 rxq_model; + +struct iecm_adapter *adapter; +struct net_device *netdev; +u16 vport_type; +u16 vport_id; +u16 idx;/* software index in adapter vports struct */ +bool base_rxd;
Bools are not really advised to use inside structures since they may have different sizes and alignments. There's a 2-byte hole here, so u8 or u16 for base_rxd would do the job.
Quoted 179 lines
drivers/net/ethernet/intel/include/iecm.h +74
-0+ +/* handler for hard interrupt */ +irqreturn_t (*irq_q_handler)(int irq,void *data); +struct iecm_q_vector *q_vectors;/* q vector array */ +u16 num_q_vectors; +u16 q_vector_base; +u16 max_mtu; +u8 default_mac_addr[ETH_ALEN ]; +u16 qset_handle; +/* ITR profiles for the DIM algorithm */ +#define IECM_DIM_PROFILE_SLOTS 5 +u16 rx_itr_profile[IECM_DIM_PROFILE_SLOTS ]; +u16 tx_itr_profile[IECM_DIM_PROFILE_SLOTS ]; +struct rtnl_link_stats64 netstats; +struct iecm_port_stats port_stats; + +/* lock to protect against multiple stop threads, which can happen when +* the driver is in a namespace in a system that is being shutdown +*/ +struct mutex stop_mutex; };enum iecm_user_flags {@@ -164,6 +424,7 @@ struct iecm_adapter {u16 num_msix_entries;struct msix_entry *msix_entries;struct virtchnl2_alloc_vectors *req_vec_chunks; +struct iecm_q_vector mb_vector;/* vport structs */ struct iecm_vport **vports;/* vports created by the driver */ @@ -190,6 +451,8 @@ struct iecm_adapter {wait_queue_head_t vchnl_wq;wait_queue_head_t sw_marker_wq; +DECLARE_BITMAP (vc_state,IECM_VC_NBITS ); +char vc_msg[IECM_DFLT_MBX_BUF_SIZE ];struct iecm_rss_data rss_data;struct iecm_dev_ops dev_ops;s32 link_speed;@@ -215,6 +478,38 @@ struct iecm_adapter {spinlock_t fdir_fltr_list_lock; }; +/** +* iecm_is_queue_model_split - check if queue model is split +* @q_model: queue model single or split +* +* Returns true if queue model is split else false +*/ +static inline int iecm_is_queue_model_split (u16 q_model) +{ +return (q_model ==VIRTCHNL2_QUEUE_MODEL_SPLIT ); +} + +#define iecm_is_cap_ena (adapter, field, flag) \ + __iecm_is_cap_ena(adapter, false, field, flag) +#define iecm_is_cap_ena_all (adapter, field, flag) \ + __iecm_is_cap_ena(adapter, true, field, flag) +/** +* __iecm_is_cap_ena - Determine if HW capability is supported +* @adapter: private data struct +* @all: all or one flag +* @field: cap field to check +* @flag: Feature flag to check +* +* iecm_is_cap_ena_all is used to check if all the capability bits are set +* ('AND' operation) where as iecm_is_cap_ena is used to check if +* any one of the capability bits is set ('OR' operation) +*/ +static inline bool __iecm_is_cap_ena (struct iecm_adapter *adapter,bool all, +enum iecm_cap_field field,u64 flag) +{ +return adapter->dev_ops.vc_ops.is_cap_ena (adapter, all, field, flag); +} +/** * iecm_is_reset_detected - check if we were reset at some point * @adapter: driver specific private structure @@ -233,6 +528,25 @@ int iecm_probe(struct pci_dev *pdev,void iecm_remove (struct pci_dev *pdev);int iecm_init_dflt_mbx (struct iecm_adapter *adapter);void iecm_deinit_dflt_mbx (struct iecm_adapter *adapter); +void iecm_vc_ops_init (struct iecm_adapter *adapter); +int iecm_vc_core_init (struct iecm_adapter *adapter,int *vport_id); +int iecm_wait_for_event (struct iecm_adapter *adapter, +enum iecm_vport_vc_state state, +enum iecm_vport_vc_state err_check); +int iecm_min_wait_for_event (struct iecm_adapter *adapter, +enum iecm_vport_vc_state state, +enum iecm_vport_vc_state err_check); +int iecm_send_get_caps_msg (struct iecm_adapter *adapter);int iecm_vport_params_buf_alloc (struct iecm_adapter *adapter);void iecm_vport_params_buf_rel (struct iecm_adapter *adapter); +int iecm_get_vec_ids (struct iecm_adapter *adapter, +u16 *vecids,int num_vecids, +struct virtchnl2_vector_chunks *chunks); +int iecm_recv_mb_msg (struct iecm_adapter *adapter,enum virtchnl_ops op, +void *msg,int msg_size); +int iecm_send_mb_msg (struct iecm_adapter *adapter,enum virtchnl_ops op, +u16 msg_size,u8 *msg); +int iecm_set_msg_pending (struct iecm_adapter *adapter, +struct iecm_ctlq_msg *ctlq_msg, +enum iecm_vport_vc_state err_enum);#endif /* !_IECM_H_ */ drivers/net/ethernet/intel/include/iecm_txrx.h +66
-0@@ -30,4 +30,98 @@#define IECM_DFLT_SPLITQ_RX_Q_GROUPS 4#define IECM_DFLT_SPLITQ_TXQ_PER_GROUP 1#define IECM_DFLT_SPLITQ_RXQ_PER_GROUP 1 + +/* Default vector sharing */ +#define IECM_NONQ_VEC 1 +#define IECM_MAX_Q_VEC 4/* For Tx Completion queue and Rx queue */ +#define IECM_MIN_Q_VEC 1 +#define IECM_MAX_RDMA_VEC 2/* To share with RDMA */ +#define IECM_MIN_RDMA_VEC 1/* Minimum vectors to be shared with RDMA */ +#define IECM_MIN_VEC 3/* One for mailbox, one for data queues, one +* for RDMA +*/ + +#define IECM_DFLT_TX_Q_DESC_COUNT 512 +#define IECM_DFLT_TX_COMPLQ_DESC_COUNT 512 +#define IECM_DFLT_RX_Q_DESC_COUNT 512 +/* IMPORTANT: We absolutely _cannot_ have more buffers in the system than a +* given RX completion queue has descriptors. This includes _ALL_ buffer +* queues. E.g.: If you have two buffer queues of 512 descriptors and buffers, +* you have a total of 1024 buffers so your RX queue _must_ have at least that +* many descriptors. This macro divides a given number of RX descriptors by +* number of buffer queues to calculate how many descriptors each buffer queue +* can have without overrunning the RX queue. +* +* If you give hardware more buffers than completion descriptors what will +* happen is that if hardware gets a chance to post more than ring wrap of +* descriptors before SW gets an interrupt and overwrites SW head, the gen bit +* in the descriptor will be wrong. Any overwritten descriptors' buffers will +* be gone forever and SW has no reasonable way to tell that this has happened. +* From SW perspective, when we finally get an interrupt, it looks like we're +* still waiting for descriptor to be done, stalling forever. +*/ +#define IECM_RX_BUFQ_DESC_COUNT (RXD ,NUM_BUFQ ) ((RXD) / (NUM_BUFQ)) + +#define IECM_RX_BUFQ_WORKING_SET (R ) ((R)->desc_count - 1) +#define IECM_RX_BUFQ_NON_WORKING_SET (R ) ((R)->desc_count - \ + IECM_RX_BUFQ_WORKING_SET(R)) + +#define IECM_RX_HDR_SIZE 256 +#define IECM_RX_BUF_2048 2048 +#define IECM_RX_BUF_4096 4096 +#define IECM_RX_BUF_STRIDE 64 +#define IECM_LOW_WATERMARK 64 +#define IECM_HDR_BUF_SIZE 256 +#define IECM_PACKET_HDR_PAD \ + (ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2)) +#define IECM_MAX_RXBUFFER 9728 +#define IECM_MAX_MTU \ + (IECM_MAX_RXBUFFER - IECM_PACKET_HDR_PAD) +#define IECM_INT_NAME_STR_LEN (IFNAMSIZ + 16) + +#define IECM_TX_COMPLQ_CLEAN_BUDGET 256 + +struct iecm_intr_reg { +u32 dyn_ctl; +u32 dyn_ctl_intena_m; +u32 dyn_ctl_clrpba_m; +u32 dyn_ctl_itridx_s; +u32 dyn_ctl_itridx_m; +u32 dyn_ctl_intrvl_s; +u32 rx_itr; +u32 tx_itr; +u32 icr_ena; +u32 icr_ena_ctlq_m; +}; + +struct iecm_q_vector { +struct iecm_vport *vport;
drivers/net/ethernet/intel/include/iecm_txrx.h line 108
Quoted 10 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +10
-0+cpumask_t affinity_mask; +struct napi_struct napi; +u16 v_idx;/* index in the vport->q_vector array */ +struct iecm_intr_reg intr_reg; + +int num_txq; +struct iecm_queue **tx; +struct dim tx_dim;/* data for net_dim algorithm */ +u16 tx_itr_value; +bool tx_intr_mode;
Same here.
drivers/net/ethernet/intel/include/iecm_txrx.h line 115
Quoted 7 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +7
-0+u32 tx_itr_idx; + +int num_rxq; +struct iecm_queue **rx; +struct dim rx_dim;/* data for net_dim algorithm */ +u16 rx_itr_value; +bool rx_intr_mode;
...here as well, and most likely in more places I overlooked.
Quoted 14 lines
drivers/net/ethernet/intel/include/iecm_txrx.h +11
-0+u32 rx_itr_idx; + +int num_bufq; +struct iecm_queue **bufq; + +u16 total_events;/* net_dim(): number of interrupts processed */ + char name[IECM_INT_NAME_STR_LEN]; +}; + +irqreturn_t +iecm_vport_intr_clean_queues (int __always_unused irq,void *data);#endif /* !_IECM_TXRX_H_ */ Signature · 1 line
2.33.0
Thanks,
Al
Brady
PATCH 5/19 iecm: add vport alloc and virtchnl messages
Quoted 88 lines
-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 4:33 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired-
lan at lists.osuosl.org; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 05/19] iecm: add vport alloc and virtchnl messagesFrom: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:55 -0800Quoted 24 lines
After handling hard reset, we end up in init task. This starts by allocating and setting up a vport. To do that we need implement virtchnl messages.
The virtchnl messages are also offloaded into function pointers so that a device driver may override them. Here a default implementation is provided for devices using virtchnl 2.0 but there exists the flexibility add virtchnl 1.1 support through function pointers.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 4 +- drivers/net/ethernet/intel/iecm/iecm_lib.c | 167 ++- drivers/net/ethernet/intel/iecm/iecm_txrx.c | 22 + .../net/ethernet/intel/iecm/iecm_virtchnl.c | 1299 +++++++++++++++++ drivers/net/ethernet/intel/include/iecm.h | 316 +++- .../net/ethernet/intel/include/iecm_txrx.h | 94 ++ 6 files changed, 1898 insertions(+), 4 deletions(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_txrx.cReview
Quoted 1 line
(quoted diff) +0
-0b/drivers/net/ethernet/intel/iecm/Makefile
Review
Quoted 19 lines
index
db8fecb075a6..fcb49402334f100644drivers/net/ethernet/intel/iecm/Makefile +3
-1@@ -7,11 +7,13 @@ obj-$(CONFIG_IECM) += iecm.o -ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include \ + -I$(srctree)/include/linux/avf iecm-y := \ iecm_lib.o \ iecm_virtchnl.o \ + iecm_txrx.o \ iecm_controlq.o \ iecm_controlq_setup.o \ iecm_main.o(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_lib.cQuoted 28 lines
index
64cdbce2c842..e2e523f0700e100644drivers/net/ethernet/intel/iecm/iecm_lib.c +14
-0@@ -5,6 +5,11 @@#include "iecm.h" +const char *const iecm_vport_vc_state_str[] = { +IECM_FOREACH_VPORT_VC_STATE (IECM_GEN_STRING ) +}; +EXPORT_SYMBOL (iecm_vport_vc_state_str); +/** * iecm_cfg_hw - Initialize HW struct * @adapter: adapter to setup hw struct for @@ -24,6 +29,113 @@ static int iecm_cfg_hw(struct iecm_adapter *adapter)return 0 ; } +/** +* iecm_get_free_slot - get the next non-NULL location index in array +* @array: array to search +* @size: size of the array +* @curr: last known occupied index to be used as a search hint +* +* void * is being used to keep the functionality generic. This lets us use this +* function on any array of pointers. +*/
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_cfg_hw(struct iecm_adapter *adapter) · line 46
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6
-0+static int iecm_get_free_slot (void *array,int size,int curr) +{ +int **tmp_array = (int **)array; +int next; + +if (curr < (size -1 ) && !tmp_array[curr +1 ]) {Redundant braces around
size - 1.
Will fix
Quoted 158 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_cfg_hw(struct iecm_adapter *adapter) · line 57
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11
-0+ next = curr +1 ; + }else { +int i =0 ; + +while ((i < size) && (tmp_array[i])) + i++; +if (i == size) + next =IECM_NO_FREE_SLOT ; +else + next = i; + }One indent level is redundant here. First condition is an oneliner:
if (curr < (size - 1) && !tmp_array[curr + 1]) { return curr + 1; while ((i < size) && (tmp_array[i])) { ...drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_service_task(struct work_struct
Quoted 85 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +81
-0+return next; +} + +/** +* iecm_vport_rel - Delete a vport and free its resources +* @vport: the vport being removed +*/ +static void iecm_vport_rel (struct iecm_vport *vport) +{ +mutex_destroy (&vport->stop_mutex); +kfree (vport); +} + +/** +* iecm_vport_rel_all - Delete all vports +* @adapter: adapter from which all vports are being removed +*/ +static void iecm_vport_rel_all (struct iecm_adapter *adapter) +{ +int i; + +if (!adapter->vports) +return ; + +for (i =0 ; i < adapter->num_alloc_vport; i++) { +if (!adapter->vports[i]) +continue ; + +iecm_vport_rel (adapter->vports[i]); + adapter->vports[i] =NULL ; + adapter->next_vport =0 ; + } + adapter->num_alloc_vport =0 ; +} + +/** +* iecm_vport_alloc - Allocates the next available struct vport in the adapter +* @adapter: board private structure +* @vport_id: vport identifier +* +* returns a pointer to a vport on success, NULL on failure. +*/ +static struct iecm_vport * +iecm_vport_alloc (struct iecm_adapter *adapter,int vport_id) +{ +struct iecm_vport *vport =NULL ; + +if (adapter->next_vport ==IECM_NO_FREE_SLOT ) +return vport; + +/* Need to protect the allocation of the vports at the adapter level */ +mutex_lock (&adapter->sw_mutex); + + vport =kzalloc (sizeof (*vport),GFP_KERNEL ); +if (!vport) + goto unlock_adapter; + + vport->adapter = adapter; + vport->idx = adapter->next_vport; + vport->compln_clean_budget =IECM_TX_COMPLQ_CLEAN_BUDGET ; + adapter->num_alloc_vport++; + +/* Setup default MSIX irq handler for the vport */ + vport->irq_q_handler = iecm_vport_intr_clean_queues; + vport->q_vector_base =IECM_NONQ_VEC ; + +mutex_init (&vport->stop_mutex); + +/* fill vport slot in the adapter struct */ + adapter->vports[adapter->next_vport] = vport; + +/* prepare adapter->next_vport for next use */ + adapter->next_vport =iecm_get_free_slot (adapter->vports, + adapter->num_alloc_vport, + adapter->next_vport); + +unlock_adapter: +mutex_unlock (&adapter->sw_mutex); +return vport; +} +/** * iecm_statistics_task - Delayed task to get statistics over mailbox * @work: work_struct handle to our data @@ -55,7 +167,25 @@ static void iecm_service_task(struct work_struct*work)
Quoted 38 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +27
-1*/ static void iecm_init_task (struct work_struct *work) { -/* stub */ +struct iecm_adapter *adapter =container_of (work, + struct iecm_adapter, + init_task.work); +struct iecm_vport *vport; +struct pci_dev *pdev; +int vport_id, err; + + err = adapter->dev_ops.vc_ops.core_init (adapter, &vport_id); +if (err) +return ; + + pdev = adapter->pdev; + vport =iecm_vport_alloc (adapter, vport_id); +if (!vport) { + err = -EFAULT ; +dev_err (&pdev->dev,"failed to allocate vport: %d\n" , + err); +return ; + } }/** @@ -81,6 +211,31 @@ static int iecm_api_init(struct iecm_adapter *adapter)return -EINVAL ; } +if (adapter->dev_ops.vc_ops_init) { +struct iecm_virtchnl_ops *vc_ops; + + adapter->dev_ops.vc_ops_init (adapter); + vc_ops = &adapter->dev_ops.vc_ops; + if (!(vc_ops->core_init && + vc_ops->vport_init && + vc_ops->vport_queue_ids_init &&drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 231
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10
-0+ vc_ops->get_caps && + vc_ops->config_queues && + vc_ops->enable_queues && + vc_ops->disable_queues && + vc_ops->irq_map_unmap && + vc_ops->get_set_rss_lut && + vc_ops->get_set_rss_hash && + vc_ops->adjust_qs && + vc_ops->get_ptype && + vc_ops->init_max_queues)) {if (!op1 || !op2 ||
Quoted 2 lines
!opn) would look more natural and more readable here.
I'm not sure I understand this comment. Adding an extra symbol for '!' seems worse.
Quoted 328 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 232
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_lib.c +1
-0+ dev_err(&pdev->dev, "Invalid device, missing one ormore virtchnl functions\n");
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 237
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5
-0+return -EINVAL ; + } + }else { +iecm_vc_ops_init (adapter); + }'else' path is a two-liner allowing to save one indent level:
if (!adapter->dev_ops.vc_ops_init) { iecm_vc_ops_init(adapter); return 0; } adapter->dev_ops.vc_ops_init(adapter); vc_ops = &adapter->dev_ops.vc_ops; if (!(vc_ops->core_init && ...Review
Quoted 22 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10
-1+return 0 ; }@@ -93,7 +248,15 @@ static int iecm_api_init(struct iecm_adapter *adapter)*/ static void iecm_deinit_task (struct iecm_adapter *adapter) { -/* stub */ +set_bit (__IECM_REL_RES_IN_PROG, adapter->flags); +/* Wait until the init_task is done else this thread might release +* the resources first and the other thread might end up in a bad state +*/ +cancel_delayed_work_sync (&adapter->init_task); +iecm_vport_rel_all (adapter); + +cancel_delayed_work_sync (&adapter->serv_task); +cancel_delayed_work_sync (&adapter->stats_task); }/** (quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_txrx.cReview
Quoted 28 lines
new file mode 100644
index 000000000000..2f5c16a28266drivers/net/ethernet/intel/iecm/iecm_txrx.c new file +22
-0@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2019 Intel Corporation */ + +#include "iecm.h" + +/** +* iecm_vport_intr_clean_queues - MSIX mode Interrupt Handler +* @irq: interrupt number +* @data: pointer to a q_vector +* +*/ +irqreturn_t +iecm_vport_intr_clean_queues (int __always_unused irq,void *data) +{ +struct iecm_q_vector *q_vector = (struct iecm_q_vector *)data; + + q_vector->total_events++; +napi_schedule (&q_vector->napi); + +return IRQ_HANDLED ; +} +(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_virtchnl.cdrivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter
Quoted 82 lines
index
b8f54b8c700a..aae06064d706100644drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +68
-0@@ -3,6 +3,74 @@#include "iecm.h" +/** +* iecm_recv_event_msg - Receive virtchnl event message +* @vport: virtual port structure +* +* Receive virtchnl event message +*/ +static void iecm_recv_event_msg (struct iecm_vport *vport) +{ +struct iecm_adapter *adapter = vport->adapter; +struct virtchnl_pf_event *vpe; +struct virtchnl2_event *v2e; +bool link_status; +u32 event; + +if (adapter->virt_ver_maj <VIRTCHNL_VERSION_MAJOR_2 ) { + vpe = (struct virtchnl_pf_event *)adapter->vc_msg; + event = vpe->event; + }else { + v2e = (struct virtchnl2_event *)adapter->vc_msg; + event =le32_to_cpu (v2e->event); + } + +switch (event) { +case VIRTCHNL2_EVENT_LINK_CHANGE : +if (adapter->virt_ver_maj <VIRTCHNL_VERSION_MAJOR_2 ) { +if (iecm_is_cap_ena (adapter,IECM_OTHER_CAPS , +VIRTCHNL2_CAP_LINK_SPEED )) { + adapter->link_speed_mbps = + vpe->event_data.link_event_adv.link_speed; + link_status = + vpe->event_data.link_event_adv.link_status; + }else { + adapter->link_speed = + vpe->event_data.link_event.link_speed; + link_status = + vpe->event_data.link_event.link_status; + } + }else { + adapter->link_speed_mbps =le32_to_cpu (v2e- link_speed); + link_status = v2e->link_status; + } +if (adapter->link_up != link_status) { + adapter->link_up = link_status; +if (adapter->state == __IECM_UP) { +if (adapter->link_up) { +netif_tx_start_all_queues (vport- netdev); +netif_carrier_on (vport->netdev); + }else { +netif_tx_stop_all_queues (vport- netdev); +netif_carrier_off (vport->netdev); + } + } + } +break ; +case VIRTCHNL_EVENT_RESET_IMPENDING : +set_bit (__IECM_HR_CORE_RESET, adapter->flags); +queue_delayed_work (adapter->vc_event_wq, + &adapter->vc_event_task, +msecs_to_jiffies (10 )); +break ; +default : +dev_err (&vport->adapter->pdev->dev, +"Unknown event %d from PF\n" , event); +break ; + } +clear_bit (__IECM_VC_MSG_PENDING, adapter->flags); +} +/**
*iecm_mb_clean- Reclaim the send mailbox queue entries
* @adapter: Driver specific private structuredrivers/net/ethernet/intel/iecm/iecm_virtchnl.c +0
-0@@ -39,6 +107,865 @@ static int iecm_mb_clean(struct iecm_adapter*adapter)
Quoted 36 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +33
-0return err; } +/** +* iecm_send_mb_msg - Send message over mailbox +* @adapter: Driver specific private structure +* @op: virtchnl opcode +* @msg_size: size of the payload +* @msg: pointer to buffer holding the payload +* +* Will prepare the control queue message and initiates the send api +* +* Returns 0 on success, negative on failure +*/ +int iecm_send_mb_msg (struct iecm_adapter *adapter,enum virtchnl_ops op, +u16 msg_size,u8 *msg) +{ +struct iecm_ctlq_msg *ctlq_msg; +struct iecm_dma_mem *dma_mem; +int err =0 ; + +if (iecm_is_reset_detected (adapter)) +return -EBUSY ; + + err =iecm_mb_clean (adapter); +if (err) +return err; + + ctlq_msg =kzalloc (sizeof (*ctlq_msg),GFP_KERNEL ); +if (!ctlq_msg) +return -ENOMEM ; + + dma_mem =kzalloc (sizeof (*dma_mem),GFP_KERNEL ); +if (!dma_mem) { + err = -ENOMEM ; + goto dma_mem_error;drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ } + +memset (ctlq_msg,0 ,sizeof (struct iecm_ctlq_msg )); + ctlq_msg->opcode = iecm_mbq_opc_send_msg_to_pf; + ctlq_msg->func_id =0 ; + ctlq_msg->data_len = msg_size; + ctlq_msg->cookie.mbx.chnl_opcode = op; + ctlq_msg->cookie.mbx.chnl_retval =VIRTCHNL_STATUS_SUCCESS ; + dma_mem->size =IECM_DFLT_MBX_BUF_SIZE ; + dma_mem->va = dmam_alloc_coherent(&adapter->pdev->dev,
dma_mem->size,Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+ &dma_mem->pa, GFP_KERNEL); +if (!dma_mem->va) { + err = -ENOMEM ; + goto dma_alloc_error; + }drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+memcpy (dma_mem->va, msg, msg_size); + ctlq_msg->ctx.indirect.payload = dma_mem; + + err =iecm_ctlq_send (&adapter->hw, adapter->hw.asq,1 , ctlq_msg); +if (err) + goto send_error; + +return 0 ; +send_error: + dmam_free_coherent(&adapter->pdev->dev, dma_mem->size,
dma_mem->va,Quoted 32 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +32
-0+ dma_mem->pa); +dma_alloc_error: +kfree (dma_mem); +dma_mem_error: +kfree (ctlq_msg); +return err; +} +EXPORT_SYMBOL (iecm_send_mb_msg); + +/** +* iecm_set_msg_pending_bit - Wait for clear and set msg pending +* @adapter: driver specific private structure +* +* If clear sets msg pending bit, otherwise waits for it to clear before +* setting it again. Returns 0 on success, negative on failure. +*/ +static int iecm_set_msg_pending_bit (struct iecm_adapter *adapter) +{ +unsigned int retries =100 ; + +/* If msg pending bit already set, there's a message waiting to be +* parsed and we must wait for it to be cleared before copying a new +* message into the vc_msg buffer or else we'll stomp all over the +* previous message. +*/ +while (retries) { +if (!test_and_set_bit (__IECM_VC_MSG_PENDING, + adapter->flags)) +break ; +msleep (20 ); + retries--; + }drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+return retries ?0 : -ETIMEDOUT ; +} + +/** +* iecm_set_msg_pending - Wait for msg pending bit and copy msg to buf +* @adapter: driver specific private structure +* @ctlq_msg: msg to copy from +* @err_enum: err bit to set on error +* +* Copies payload from ctlq_msg into vc_msg buf in adapter and sets msg pending
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4
-0+* bit. Returns 0 on success, negative on failure. +*/ +int iecm_set_msg_pending(struct iecm_adapter *adapter, + struct iecm_ctlq_msg *ctlq_msg,drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ enum iecm_vport_vc_state err_enum) +{ +if (ctlq_msg->cookie.mbx.chnl_retval) { +set_bit (err_enum, adapter->vc_state); +return -EINVAL ; + } + +if (iecm_set_msg_pending_bit (adapter)) { +set_bit (err_enum, adapter->vc_state); + dev_info(&adapter->pdev->dev, "Timed out setting msgpending\n");
Quoted 28 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +28
-0+return -ETIMEDOUT ; + } + +memcpy (adapter->vc_msg, ctlq_msg->ctx.indirect.payload->va, +min_t (int, ctlq_msg->ctx.indirect.payload->size, +IECM_DFLT_MBX_BUF_SIZE )); +return 0 ; +} +EXPORT_SYMBOL (iecm_set_msg_pending); + +/** +* iecm_recv_mb_msg - Receive message over mailbox +* @adapter: Driver specific private structure +* @op: virtchannel operation code +* @msg: Received message holding buffer +* @msg_size: message size +* +* Will receive control queue message and posts the receive buffer. Returns 0 +* on success and negative on failure. +*/ +int iecm_recv_mb_msg (struct iecm_adapter *adapter,enum virtchnl_ops op, +void *msg,int msg_size) +{ +struct iecm_ctlq_msg ctlq_msg; +struct iecm_dma_mem *dma_mem; +struct iecm_vport *vport; +bool work_done = false; +int num_retry =2000 ;drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+int payload_size =0 ; +u16 num_q_msg; +int err =0 ; + + vport = adapter->vports[0 ]; +while (1 ) { +/* Try to get one message */ + num_q_msg =1 ; + dma_mem =NULL ; + err = iecm_ctlq_recv(adapter->hw.arq, &num_q_msg,
&ctlq_msg);Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12
-0+/* If no message then decide if we have to retry based on +* opcode +*/ +if (err || !num_q_msg) { +/* Increasing num_retry to consider the delayed +* responses because of large number of VF's mailbox +* messages. If the mailbox message is received from +* the other side, we come out of the sleep cycle +* immediately else we wait for more time. +*/ +if (op && num_retry-- && + !test_bit (__IECM_REL_RES_IN_PROG, adapter- flags)) {
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 278
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+msleep (20 ); +continue ; + }else { +break ; + }Since if-condition always ends with a 'continue', 'else' is reduntant here.
Will fix
Quoted 728 lines
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11
-0+ } + +/* If we are here a message is received. Check if we are looking +* for a specific message based on opcode. If it is different +* ignore and post buffers +*/ +if (op && ctlq_msg.cookie.mbx.chnl_opcode != op) + goto post_buffs; + +if (ctlq_msg.data_len) + payload_size = ctlq_msg.ctx.indirect.payload->size;drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ +/* All conditions are met. Either a message requested is +* received or we received a message to be processed +*/ +switch (ctlq_msg.cookie.mbx.chnl_opcode) { +case VIRTCHNL_OP_VERSION : +case VIRTCHNL2_OP_GET_CAPS : +case VIRTCHNL2_OP_CREATE_VPORT : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_info(&adapter->pdev->dev, "Failureinitializing, vc op: %u retval: %u\n",
Quoted 153 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +135
-0+ ctlq_msg.cookie.mbx.chnl_opcode, + ctlq_msg.cookie.mbx.chnl_retval); + err = -EBADMSG ; + }else if (msg) { +memcpy (msg, ctlq_msg.ctx.indirect.payload- va, +min_t (int, + payload_size, msg_size)); + } + work_done = true; +break ; +case VIRTCHNL2_OP_ENABLE_VPORT : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_ENA_VPORT_ERR , + adapter->vc_state); +set_bit (IECM_VC_ENA_VPORT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DISABLE_VPORT : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DIS_VPORT_ERR , + adapter->vc_state); +set_bit (IECM_VC_DIS_VPORT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DESTROY_VPORT : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DESTROY_VPORT_ERR , + adapter->vc_state); +set_bit (IECM_VC_DESTROY_VPORT , adapter- vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_CONFIG_TX_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_CONFIG_TXQ_ERR , + adapter->vc_state); +set_bit (IECM_VC_CONFIG_TXQ , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_CONFIG_RX_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_CONFIG_RXQ_ERR , + adapter->vc_state); +set_bit (IECM_VC_CONFIG_RXQ , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_ENABLE_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_ENA_QUEUES_ERR , + adapter->vc_state); +set_bit (IECM_VC_ENA_QUEUES , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DISABLE_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DIS_QUEUES_ERR , + adapter->vc_state); +set_bit (IECM_VC_DIS_QUEUES , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_ADD_QUEUES : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_ADD_QUEUES_ERR ); +set_bit (IECM_VC_ADD_QUEUES , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DEL_QUEUES : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DEL_QUEUES_ERR , + adapter->vc_state); +set_bit (IECM_VC_DEL_QUEUES , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_MAP_QUEUE_VECTOR : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_MAP_IRQ_ERR , + adapter->vc_state); +set_bit (IECM_VC_MAP_IRQ , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_UNMAP_IRQ_ERR , + adapter->vc_state); +set_bit (IECM_VC_UNMAP_IRQ , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_STATS : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_STATS_ERR ); +set_bit (IECM_VC_GET_STATS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_RSS_HASH : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_RSS_HASH_ERR ); +set_bit (IECM_VC_GET_RSS_HASH , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_SET_RSS_HASH : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_SET_RSS_HASH_ERR , + adapter->vc_state); +set_bit (IECM_VC_SET_RSS_HASH , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_RSS_LUT : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_RSS_LUT_ERR ); +set_bit (IECM_VC_GET_RSS_LUT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_SET_RSS_LUT : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_SET_RSS_LUT_ERR , + adapter->vc_state); +set_bit (IECM_VC_SET_RSS_LUT , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_RSS_KEY : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_RSS_KEY_ERR ); +set_bit (IECM_VC_GET_RSS_KEY , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_SET_RSS_KEY : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_SET_RSS_KEY_ERR , + adapter->vc_state); +set_bit (IECM_VC_SET_RSS_KEY , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_ALLOC_VECTORS : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_ALLOC_VECTORS_ERR ); + set_bit(IECM_VC_ALLOC_VECTORS, adapter-
vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7
-0+wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_DEALLOC_VECTORS : +if (ctlq_msg.cookie.mbx.chnl_retval) +set_bit (IECM_VC_DEALLOC_VECTORS_ERR , + adapter->vc_state); + set_bit(IECM_VC_DEALLOC_VECTORS, adapter-
vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_GET_PTYPE_INFO : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_GET_PTYPE_INFO_ERR ); + set_bit(IECM_VC_GET_PTYPE_INFO, adapter-
vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL2_OP_EVENT : +case VIRTCHNL_OP_EVENT : +if (iecm_set_msg_pending_bit (adapter)) { + dev_info(&adapter->pdev->dev, "Timed outsetting msg pending\n");
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ }else { +memcpy (adapter->vc_msg, + ctlq_msg.ctx.indirect.payload->va, +min_t (int, payload_size, +IECM_DFLT_MBX_BUF_SIZE )); +iecm_recv_event_msg (vport); + } +break ; +case VIRTCHNL_OP_ADD_ETH_ADDR : + if (test_and_clear_bit(__IECM_ADD_ETH_REQ,
adapter->flags)) {drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9
-0+/* Message was sent asynchronously. We don't +* normally print errors here, instead +* preferring to handle errors in the function +* calling wait_for_event. However, we will +* have lost the context in which we sent the +* message if asynchronous. We can't really do +* anything about at it this point, but we +* should at a minimum indicate that it looks +* like something went wrong. Also don't bother
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+* setting ERR bit or waking vchnl_wq since no +* one will be waiting to read the async +* message. +*/ +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failedto add MAC address: %d\n",
Quoted 1 line
+
ctlq_msg.cookie.mbx.chnl_retval);Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12
-0+ } +break ; + } +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_ADD_ETH_ADDR_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_ADD_ETH_ADDR , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DEL_ETH_ADDR : + if (test_and_clear_bit(__IECM_DEL_ETH_REQ, adapter-flags)) {
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9
-0+/* Message was sent asynchronously. We don't +* normally print errors here, instead +* preferring to handle errors in the function +* calling wait_for_event. However, we will +* have lost the context in which we sent the +* message if asynchronous. We can't really do +* anything about at it this point, but we +* should at a minimum indicate that it looks +* like something went wrong. Also don't bother
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+* setting ERR bit or waking vchnl_wq since no +* one will be waiting to read the async +* message. +*/ +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failedto delete MAC address: %d\n",
Quoted 1 line
+
ctlq_msg.cookie.mbx.chnl_retval);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +13
-0+ } +break ; + } +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit (IECM_VC_DEL_ETH_ADDR_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_DEL_ETH_ADDR , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit(IECM_VC_OFFLOAD_VLAN_V2_CAPS_ERR, adapter->vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 13 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7
-0+ }else { +memcpy (adapter->vc_msg, + ctlq_msg.ctx.indirect.payload->va, +min_t (int, payload_size, +IECM_DFLT_MBX_BUF_SIZE )); + } + set_bit(IECM_VC_OFFLOAD_VLAN_V2_CAPS, adapter-
vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ADD_VLAN_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed to addvlan filter: %d\n",
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+ ctlq_msg.cookie.mbx.chnl_retval); + } +break ; +case VIRTCHNL_OP_DEL_VLAN_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed todelete vlan filter: %d\n",
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+ ctlq_msg.cookie.mbx.chnl_retval); + } +break ; +case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit(IECM_VC_INSERTION_ENA_VLAN_V2_ERR,
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9
-0+ adapter->vc_state); + } +set_bit (IECM_VC_INSERTION_ENA_VLAN_V2 , + adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit(IECM_VC_INSERTION_DIS_VLAN_V2_ERR,
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 682
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9
-0+ adapter->vc_state); + } +set_bit (IECM_VC_INSERTION_DIS_VLAN_V2 , + adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit(IECM_VC_STRIPPING_ENA_VLAN_V2_ERR,
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 682
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +9
-0+ adapter->vc_state); + } +set_bit (IECM_VC_STRIPPING_ENA_VLAN_V2 , + adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 : +if (ctlq_msg.cookie.mbx.chnl_retval) { +set_bit(IECM_VC_STRIPPING_DIS_VLAN_V2_ERR,
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+ adapter->vc_state); + } +set_bit (IECM_VC_STRIPPING_DIS_VLAN_V2 , + adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ;drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE : +/* This message can only be sent asynchronously. As +* such we'll have lost the context in which it was +* called and thus can only really report if it looks +* like an error occurred. Don't bother setting ERR bit +* or waking chnl_wq since no will be waiting to +* reading message. +*/ +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed to setpromiscuous mode: %d\n",
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+ ctlq_msg.cookie.mbx.chnl_retval); + } +break ; +case VIRTCHNL_OP_ADD_CLOUD_FILTER : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed to addcloud filter: %d\n",
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+ ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_ADD_CLOUD_FILTER_ERR , + adapter->vc_state); + } + set_bit(IECM_VC_ADD_CLOUD_FILTER, adapter-
vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DEL_CLOUD_FILTER : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed todelete cloud filter: %d\n",
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+ ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_DEL_CLOUD_FILTER_ERR , + adapter->vc_state); + } + set_bit(IECM_VC_DEL_CLOUD_FILTER, adapter-
vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ADD_RSS_CFG : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed to addRSS configuration: %d\n",
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_ADD_RSS_CFG_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_ADD_RSS_CFG , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DEL_RSS_CFG : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed todelete RSS configuration: %d\n",
Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11
-0+ ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_DEL_RSS_CFG_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_DEL_RSS_CFG , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ADD_FDIR_FILTER : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_ADD_FDIR_FILTER_ERR ); + set_bit(IECM_VC_ADD_FDIR_FILTER, adapter-
vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DEL_FDIR_FILTER : +iecm_set_msg_pending (adapter, &ctlq_msg, +IECM_VC_DEL_FDIR_FILTER_ERR ); + set_bit(IECM_VC_DEL_FDIR_FILTER, adapter-
vc_state);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_ENABLE_CHANNELS : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed toenable channels: %d\n",
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_ENA_CHANNELS_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_ENA_CHANNELS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +case VIRTCHNL_OP_DISABLE_CHANNELS : +if (ctlq_msg.cookie.mbx.chnl_retval) { + dev_err(&adapter->pdev->dev, "Failed todisable channels: %d\n",
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +11
-0+ ctlq_msg.cookie.mbx.chnl_retval); +set_bit (IECM_VC_DIS_CHANNELS_ERR , + adapter->vc_state); + } +set_bit (IECM_VC_DIS_CHANNELS , adapter->vc_state); +wake_up (&adapter->vchnl_wq); +break ; +default : +if (adapter->dev_ops.vc_ops.recv_mbx_msg) + err = + adapter-dev_ops.vc_ops.recv_mbx_msg(adapter,
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 682
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4
-0+ msg, + msg_size, + &ctlq_msg, +
&work_done);Quoted 7 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +7
-0+else +dev_warn (&adapter->pdev->dev, +"Unhandled virtchnl response %d\n" , + ctlq_msg.cookie.mbx.chnl_opcode); +break ; + }/* switch v_opcode */ +post_buffs:drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+if (ctlq_msg.data_len) + dma_mem = ctlq_msg.ctx.indirect.payload; +else + num_q_msg =0 ; + + err =iecm_ctlq_post_rx_buffs (&adapter->hw, adapter->hw.arq, + &num_q_msg, &dma_mem); +/* If post failed clear the only buffer we supplied */ +if (err && dma_mem) + dmam_free_coherent(&adapter->pdev->dev,
dma_mem->size,Quoted 19 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +19
-0+ dma_mem->va, dma_mem->pa); +/* Applies only if we are looking for a specific opcode */ +if (work_done) +break ; + } + +return err; +} +EXPORT_SYMBOL (iecm_recv_mb_msg); + +/** +* iecm_send_ver_msg - send virtchnl version message +* @adapter: Driver specific private structure +* +* Send virtchnl version message. Returns 0 on success, negative on failure. +*/ +static int iecm_send_ver_msg (struct iecm_adapter *adapter) +{ +struct virtchnl_version_info vvi;drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ +if (adapter->virt_ver_maj) { + vvi.major = adapter->virt_ver_maj; + vvi.minor = adapter->virt_ver_min; + }else { + vvi.major =IECM_VIRTCHNL_VERSION_MAJOR ; + vvi.minor =IECM_VIRTCHNL_VERSION_MINOR ; + } + + return iecm_send_mb_msg(adapter, VIRTCHNL_OP_VERSION,sizeof(vvi),
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +8
-0+ (u8 *)&vvi); +} + +/** +* iecm_recv_ver_msg - Receive virtchnl version message +* @adapter: Driver specific private structure +* +* Receive virtchnl version message. Returns 0 on success, -EAGAIN if we need
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 8 lines
+ * to send version message again, otherwise negative on failure.
+ */drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +6
-0+static int iecm_recv_ver_msg (struct iecm_adapter *adapter) +{ +struct virtchnl_version_info vvi; +int err =0 ; + + err = iecm_recv_mb_msg(adapter, VIRTCHNL_OP_VERSION, &vvi,sizeof(vvi));
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+if (err) +return err; + +if (vvi.major >IECM_VIRTCHNL_VERSION_MAJOR ) { + dev_warn(&adapter->pdev->dev, "Virtchnl major versiongreater than supported\n");
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+return -EINVAL ; + } +if (vvi.major ==IECM_VIRTCHNL_VERSION_MAJOR && + vvi.minor >IECM_VIRTCHNL_VERSION_MINOR ) + dev_warn(&adapter->pdev->dev, "Virtchnl minor version notmatched\n");
Quoted 92 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +92
-0+ +/* If we have a mismatch, resend version to update receiver on what +* version we will use. +*/ +if (!adapter->virt_ver_maj && + vvi.major !=IECM_VIRTCHNL_VERSION_MAJOR && + vvi.minor !=IECM_VIRTCHNL_VERSION_MINOR ) + err = -EAGAIN ; + + adapter->virt_ver_maj = vvi.major; + adapter->virt_ver_min = vvi.minor; + +return err; +} + +/** +* iecm_send_get_caps_msg - Send virtchnl get capabilities message +* @adapter: Driver specific private structure +* +* Send virtchl get capabilities message. Returns 0 on success, negative on +* failure. +*/ +int iecm_send_get_caps_msg (struct iecm_adapter *adapter) +{ +struct virtchnl2_get_capabilities caps = {0 }; +int buf_size; + + buf_size =sizeof (struct virtchnl2_get_capabilities ); + adapter->caps =kzalloc (buf_size,GFP_KERNEL ); +if (!adapter->caps) +return -ENOMEM ; + + caps.csum_caps = +cpu_to_le32 (VIRTCHNL2_CAP_TX_CSUM_L3_IPV4 | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP | +VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP | +VIRTCHNL2_CAP_TX_CSUM_GENERIC | +VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP | +VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP | +VIRTCHNL2_CAP_RX_CSUM_GENERIC ); + + caps.seg_caps = +cpu_to_le32 (VIRTCHNL2_CAP_SEG_IPV4_TCP | +VIRTCHNL2_CAP_SEG_IPV4_UDP | +VIRTCHNL2_CAP_SEG_IPV4_SCTP | +VIRTCHNL2_CAP_SEG_IPV6_TCP | +VIRTCHNL2_CAP_SEG_IPV6_UDP | +VIRTCHNL2_CAP_SEG_IPV6_SCTP | +VIRTCHNL2_CAP_SEG_GENERIC ); + + caps.rss_caps = +cpu_to_le64 (VIRTCHNL2_CAP_RSS_IPV4_TCP | +VIRTCHNL2_CAP_RSS_IPV4_UDP | +VIRTCHNL2_CAP_RSS_IPV4_SCTP | +VIRTCHNL2_CAP_RSS_IPV4_OTHER | +VIRTCHNL2_CAP_RSS_IPV6_TCP | +VIRTCHNL2_CAP_RSS_IPV6_UDP | +VIRTCHNL2_CAP_RSS_IPV6_SCTP | +VIRTCHNL2_CAP_RSS_IPV6_OTHER | +VIRTCHNL2_CAP_RSS_IPV4_AH | +VIRTCHNL2_CAP_RSS_IPV4_ESP | +VIRTCHNL2_CAP_RSS_IPV4_AH_ESP | +VIRTCHNL2_CAP_RSS_IPV6_AH | +VIRTCHNL2_CAP_RSS_IPV6_ESP | +VIRTCHNL2_CAP_RSS_IPV6_AH_ESP ); + + caps.hsplit_caps = +cpu_to_le32 (VIRTCHNL2_CAP_RX_HSPLIT_AT_L2 | +VIRTCHNL2_CAP_RX_HSPLIT_AT_L3 | +VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 | +VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6 ); + + caps.rsc_caps = +cpu_to_le32 (VIRTCHNL2_CAP_RSC_IPV4_TCP | +VIRTCHNL2_CAP_RSC_IPV4_SCTP | +VIRTCHNL2_CAP_RSC_IPV6_TCP | +VIRTCHNL2_CAP_RSC_IPV6_SCTP ); + + caps.other_caps = + cpu_to_le64(VIRTCHNL2_CAP_RDMA | + VIRTCHNL2_CAP_SRIOV | + VIRTCHNL2_CAP_MACFILTER | + VIRTCHNL2_CAP_FLOW_DIRECTOR |drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+VIRTCHNL2_CAP_SPLITQ_QSCHED | +VIRTCHNL2_CAP_CRC | +VIRTCHNL2_CAP_ADQ | +VIRTCHNL2_CAP_WB_ON_ITR | +VIRTCHNL2_CAP_PROMISC | +VIRTCHNL2_CAP_INLINE_IPSEC | +VIRTCHNL2_CAP_VLAN | + VIRTCHNL2_CAP_RX_FLEX_DESC); + + return iecm_send_mb_msg(adapter, VIRTCHNL2_OP_GET_CAPS,sizeof(caps),
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4
-0+ (u8 *)&caps); +} +EXPORT_SYMBOL (iecm_send_get_caps_msg); +drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+/** +* iecm_recv_get_caps_msg - Receive virtchnl get capabilities message +* @adapter: Driver specific private structure +* +* Receive virtchnl get capabilities message. Returns 0 on succes, negative on +* failure. +*/ +static int iecm_recv_get_caps_msg (struct iecm_adapter *adapter) +{ + return iecm_recv_mb_msg(adapter, VIRTCHNL2_OP_GET_CAPS,
adapter->caps,Quoted 24 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +24
-0+ sizeof(struct virtchnl2_get_capabilities)); +} + +/** +* iecm_send_create_vport_msg - Send virtchnl create vport message +* @adapter: Driver specific private structure +* +* send virtchnl creae vport message +* +* Returns 0 on success, negative on failure +*/ +static int iecm_send_create_vport_msg (struct iecm_adapter *adapter) +{ +/* stub */ +return 0 ; +} + +/** +* iecm_recv_create_vport_msg - Receive virtchnl create vport message +* @adapter: Driver specific private structure +* @vport_id: Virtual port identifier +* +* Receive virtchnl create vport message. Returns 0 on success, negative on +* failure. drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+*/ +static int iecm_recv_create_vport_msg (struct iecm_adapter *adapter, +int *vport_id) +{ +/* stub */ +return 0 ; +} + +/** +* __iecm_wait_for_event - wrapper function for wait on virtchannel response
Quoted 11 lines
+ * @adapter: Driver private data structure
+ * @state: check on state upon timeout
+ * @err_check: check if this specific error bit is set
+ * @timeout: Max time to wait
+ *
+ * Checks if state is set upon expiry of timeout. Returns 0 on success,
+ * negative on failure.
+ */drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +3
-0+static int __iecm_wait_for_event(struct iecm_adapter *adapter, + enum iecm_vport_vc_state state, + enum iecm_vport_vc_state err_check,drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ int timeout) +{ +int event; + + event =wait_event_timeout (adapter->vchnl_wq, +test_and_clear_bit (state, adapter->vc_state), +msecs_to_jiffies (timeout)); +if (event) { +if (test_and_clear_bit (err_check, adapter->vc_state)) { + dev_err(&adapter->pdev->dev, "VC response error%s\n",
Quoted 34 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +34
-0+ iecm_vport_vc_state_str[err_check]); +return -EINVAL ; + } +return 0 ; + } + +/* Timeout occurred */ +dev_err (&adapter->pdev->dev,"VC timeout, state = %s\n" , + iecm_vport_vc_state_str[state]); +return -ETIMEDOUT ; +} + +/** +* iecm_min_wait_for_event - wait for virtchannel response +* @adapter: Driver private data structure +* @state: check on state upon timeout +* @err_check: check if this specific error bit is set +* +* Returns 0 on success, negative on failure. +*/ +int iecm_min_wait_for_event (struct iecm_adapter *adapter, +enum iecm_vport_vc_state state, +enum iecm_vport_vc_state err_check) +{ +int timeout =2000 ; + +return __iecm_wait_for_event (adapter, state, err_check, timeout); +} +EXPORT_SYMBOL (iecm_min_wait_for_event); + +/** +* iecm_wait_for_event - wait for virtchannel response +* @adapter: Driver private data structure +* @state: check on state upon timeout after 500ms drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+* @err_check: check if this specific error bit is set +* +* Returns 0 on success, negative on failure. +*/ +int iecm_wait_for_event (struct iecm_adapter *adapter, +enum iecm_vport_vc_state state, +enum iecm_vport_vc_state err_check) +{ +/* Increasing the timeout in __IECM_INIT_SW flow to consider large +* number of VF's mailbox message responses. When a message is received
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c
Quoted 1 line
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1
-0+* on mailbox, this thread is wake up by the iecm_recv_mb_msg before the
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c static int iecm_mb_clean(struct iecm_adapter *adapter) · line 963
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+* timeout expires. Only in the error case i.e. if no message is +* received on mailbox, we wait for the complete timeout which is +* less likely to happen. +*/ +int timeout =60000 ;If you make a definition from it, it would be easier to find it later in case of adjustments needed.
Will fix
Quoted 685 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vport_params_buf_rel(struct
Quoted 9 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +5
-0+ +return __iecm_wait_for_event (adapter, state, err_check, timeout); +} +EXPORT_SYMBOL (iecm_wait_for_event); +/** * iecm_find_ctlq - Given a type and id, find ctlq info * @hw: hardware struct @@ -170,3 +1097,375 @@ void iecm_vport_params_buf_rel(struct
iecm_adapter*adapter)drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vport_params_buf_rel(struct iecm_adapter *adapter)
Quoted 11 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +8
-0kfree (adapter->caps);kfree (adapter->config_data.req_qs_chunks); } + +/** +* iecm_vc_core_init - Initialize mailbox and get resources +* @adapter: Driver specific private structure +* @vport_id: Virtual port identifier +* +* Will check if HW is ready with reset complete. Initializes the mailbox and +* communicate with master to get all the default vport parameters. Returns 0
Quoted 44 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +44
-0+* on success, -EAGAIN function will get called again, otherwise negative on +* failure. +*/ +int iecm_vc_core_init (struct iecm_adapter *adapter,int *vport_id) +{ +int err; + +switch (adapter->state) { +case __IECM_STARTUP: +if (iecm_send_ver_msg (adapter)) + goto init_failed; + adapter->state = __IECM_VER_CHECK; + goto restart; +case __IECM_VER_CHECK: + err =iecm_recv_ver_msg (adapter); +if (err == -EAGAIN ) { + adapter->state = __IECM_STARTUP; + goto restart; + }else if (err) { + goto init_failed; + } + adapter->state = __IECM_GET_CAPS; +if (adapter->dev_ops.vc_ops.get_caps (adapter)) + goto init_failed; + goto restart; +case __IECM_GET_CAPS: +if (iecm_recv_get_caps_msg (adapter)) + goto init_failed; +if (iecm_send_create_vport_msg (adapter)) + goto init_failed; + adapter->state = __IECM_GET_DFLT_VPORT_PARAMS; + goto restart; +case __IECM_GET_DFLT_VPORT_PARAMS: +if (iecm_recv_create_vport_msg (adapter, vport_id)) + goto init_failed; + adapter->state = __IECM_INIT_SW; +break ; +case __IECM_INIT_SW: +break ; +default : +dev_err (&adapter->pdev->dev,"Device is in bad state: %d\n" , + adapter->state); + goto init_failed; + }drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vport_params_buf_rel(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ +return 0 ; +restart: +queue_delayed_work (adapter->init_wq, &adapter->init_task, +msecs_to_jiffies (30 )); +/* Not an error. Using try again to continue with state machine */ +return -EAGAIN ; +init_failed: +if (++adapter->mb_wait_count >IECM_MB_MAX_ERR ) { + dev_err(&adapter->pdev->dev, "Failed to establish mailboxcommunications with hardware\n");
Quoted 43 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+return -EFAULT ; + } + adapter->state = __IECM_STARTUP; +/* If it reaches here, it is possible that mailbox queue initialization +* register writes might not have taken effect. Retry to initialize +* the mailbox again +*/ +iecm_deinit_dflt_mbx (adapter); +set_bit (__IECM_HR_DRV_LOAD, adapter->flags); + queue_delayed_work(adapter->vc_event_wq, &adapter-
vc_event_task,drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +31
-0+ msecs_to_jiffies(20)); +return -EAGAIN ; +} +EXPORT_SYMBOL (iecm_vc_core_init); + +/** +* iecm_vport_init - Initialize virtual port +* @vport: virtual port to be initialized +* @vport_id: Unique identification number of vport +* +* Will initialize vport with the info received through MB earlier +*/ +static void iecm_vport_init (struct iecm_vport *vport, +__always_unused int vport_id) +{ +struct virtchnl2_create_vport *vport_msg; +u16 rx_itr[] = {2 ,8 ,32 ,96 ,128 }; +u16 tx_itr[] = {2 ,8 ,64 ,128 ,256 }; + + vport_msg = (struct virtchnl2_create_vport *) + vport->adapter->vport_params_recvd[0 ]; + vport->txq_model =le16_to_cpu (vport_msg->txq_model); + vport->rxq_model =le16_to_cpu (vport_msg->rxq_model); + vport->vport_type =le16_to_cpu (vport_msg->vport_type); + vport->vport_id =le32_to_cpu (vport_msg->vport_id); + vport->adapter->rss_data.rss_key_size = +min_t (u16,NETDEV_RSS_KEY_LEN , +le16_to_cpu (vport_msg->rss_key_size)); + vport->adapter->rss_data.rss_lut_size = +le16_to_cpu (vport_msg->rss_lut_size); + ether_addr_copy(vport->default_mac_addr, vport_msg-
default_mac_addr);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vport_params_buf_rel(struct iecm_adapter *adapter)
Quoted 4 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +4
-0+ vport->max_mtu =IECM_MAX_MTU ; + +if (iecm_is_queue_model_split (vport->rxq_model)) { + vport->num_bufqs_per_qgrp =
IECM_MAX_BUFQS_PER_RXQ_GRP;Quoted 91 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +78
-0+/* Bufq[0] default buffer size is 4K +* Bufq[1] default buffer size is 2K +*/ + vport->bufq_size[0 ] =IECM_RX_BUF_4096 ; + vport->bufq_size[1 ] =IECM_RX_BUF_2048 ; + }else { + vport->num_bufqs_per_qgrp =0 ; + vport->bufq_size[0 ] =IECM_RX_BUF_2048 ; + } + +/*Initialize Tx and Rx profiles for Dynamic Interrupt Moderation */ +memcpy (vport->rx_itr_profile, rx_itr,IECM_DIM_PROFILE_SLOTS ); +memcpy (vport->tx_itr_profile, tx_itr,IECM_DIM_PROFILE_SLOTS ); +} + +/** +* iecm_get_vec_ids - Initialize vector id from Mailbox parameters +* @adapter: adapter structure to get the mailbox vector id +* @vecids: Array of vector ids +* @num_vecids: number of vector ids +* @chunks: vector ids received over mailbox +* +* Will initialize the mailbox vector id which is received from the +* get capabilities and data queue vector ids with ids received as +* mailbox parameters. +* Returns number of ids filled +*/ +int iecm_get_vec_ids (struct iecm_adapter *adapter, +u16 *vecids,int num_vecids, +struct virtchnl2_vector_chunks *chunks) +{ +u16 num_chunks =le16_to_cpu (chunks->num_vchunks); +u16 start_vecid, num_vec; +int num_vecid_filled =0 ; +int i, j; + + vecids[num_vecid_filled] = adapter->mb_vector.v_idx; + num_vecid_filled++; + +for (j =0 ; j < num_chunks; j++) { +struct virtchnl2_vector_chunk *chunk = &chunks->vchunks[j]; + + num_vec =le16_to_cpu (chunk->num_vectors); + start_vecid =le16_to_cpu (chunk->start_vector_id); +for (i =0 ; i < num_vec; i++) { +if ((num_vecid_filled + i) < num_vecids) { + vecids[num_vecid_filled + i] = start_vecid; + start_vecid++; + }else { +break ; + } + } + num_vecid_filled = num_vecid_filled + i; + } + +return num_vecid_filled; +} + +/** +* iecm_vport_get_queue_ids - Initialize queue id from Mailbox parameters +* @qids: Array of queue ids +* @num_qids: number of queue ids +* @q_type: queue model +* @chunks: queue ids received over mailbox +* +* Will initialize all queue ids with ids received as mailbox parameters +* Returns number of ids filled +*/ +static int +iecm_vport_get_queue_ids (u32 *qids,int num_qids,u16 q_type, +struct virtchnl2_queue_reg_chunks *chunks) +{ +u16 num_chunks =le16_to_cpu (chunks->num_chunks); +u32 num_q_id_filled =0 , i; +u32 start_q_id, num_q; + +while (num_chunks) { + struct virtchnl2_queue_reg_chunk *chunk = &chunks-chunks[num_chunks - 1];
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +12
-0+ +if (le32_to_cpu (chunk->type) == q_type) { + num_q =le32_to_cpu (chunk->num_queues); + start_q_id =le32_to_cpu (chunk->start_queue_id); +for (i =0 ; i < num_q; i++) { +if ((num_q_id_filled + i) < num_qids) { + qids[num_q_id_filled + i] = start_q_id; + start_q_id++; + }else { +break ; + } + }drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vport_params_buf_rel(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+ num_q_id_filled = num_q_id_filled + i; + } + num_chunks--; + } + +return num_q_id_filled; +} + +/** +* __iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters
Quoted 56 lines
8 lines not shown · raw message
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +48
-0+static int +__iecm_vport_queue_ids_init (struct iecm_vport *vport,u32 *qids, +int num_qids,u32 q_type) +{ +/* stub */ +return 0 ; +} + +/** +* iecm_vport_queue_ids_init - Initialize queue ids from Mailbox parameters +* @vport: virtual port for which the queues ids are initialized +* +* Will initialize all queue ids with ids received as mailbox parameters. +* Returns 0 on success, negative if all the queues are not initialized. +*/ +static int iecm_vport_queue_ids_init (struct iecm_vport *vport) +{ +struct virtchnl2_create_vport *vport_params; +struct virtchnl2_queue_reg_chunks *chunks; +/* We may never deal with more than 256 same type of queues */ +#define IECM_MAX_QIDS 256 +u32 qids[IECM_MAX_QIDS ]; +int num_ids; +u16 q_type; + +if (vport->adapter->config_data.req_qs_chunks) { +struct virtchnl2_add_queues *vc_aq = + (struct virtchnl2_add_queues *) + vport->adapter->config_data.req_qs_chunks; + chunks = &vc_aq->chunks; + }else { + vport_params = (struct virtchnl2_create_vport *) + vport->adapter->vport_params_recvd[0 ]; + chunks = &vport_params->chunks; + } + + num_ids =iecm_vport_get_queue_ids (qids,IECM_MAX_QIDS , +VIRTCHNL2_QUEUE_TYPE_TX , + chunks); +if (num_ids != vport->num_txq) +return -EINVAL ; + num_ids =__iecm_vport_queue_ids_init (vport, qids, num_ids, +VIRTCHNL2_QUEUE_TYPE_TX ); +if (num_ids != vport->num_txq) +return -EINVAL ; + num_ids =iecm_vport_get_queue_ids (qids,IECM_MAX_QIDS , +VIRTCHNL2_QUEUE_TYPE_RX , + chunks);drivers/net/ethernet/intel/iecm/iecm_virtchnl.c void iecm_vport_params_buf_rel(struct iecm_adapter *adapter)
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +10
-0+if (num_ids != vport->num_rxq) +return -EINVAL ; + num_ids =__iecm_vport_queue_ids_init (vport, qids, num_ids, +VIRTCHNL2_QUEUE_TYPE_RX ); +if (num_ids != vport->num_rxq) +return -EINVAL ; + +if (iecm_is_queue_model_split (vport->txq_model)) { + q_type =VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION ; + num_ids = iecm_vport_get_queue_ids(qids, IECM_MAX_QIDS,392 lines not shown · raw message
Quoted 9 lines
7 lines not shown · raw message
232 lines not shown · raw message
Part of this message is not shown here. View the raw message.
PATCH 5/19 iecm: add vport alloc and virtchnl messages
From: Alan Brady <[email protected]>
Date: Wed, 2 Feb 2022 23:21:54 +0100
Quoted 260 lines
Quoted 88 lines
-----Original Message-----
From: Lobakin, Alexandr <[email protected]>
Sent: Friday, January 28, 2022 4:33 AM
To: Brady, Alan <[email protected]>
Cc: Lobakin, Alexandr <[email protected]>; intel-wired-
lan at lists.osuosl.org; Burra, Phani R <[email protected]>; Chittim, Madhu <[email protected]>; Linga, Pavan Kumar <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net-next 05/19] iecm: add vport alloc and virtchnl messagesFrom: Alan Brady <[email protected]>
Date: Thu, 27 Jan 2022 16:09:55 -0800Quoted 24 lines
After handling hard reset, we end up in init task. This starts by allocating and setting up a vport. To do that we need implement virtchnl messages.
The virtchnl messages are also offloaded into function pointers so that a device driver may override them. Here a default implementation is provided for devices using virtchnl 2.0 but there exists the flexibility add virtchnl 1.1 support through function pointers.
Signed-off-by Phani Burra <[email protected]>Signed-off-by Joshua Hay <[email protected]>Signed-off-by Madhu Chittim <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Alan Brady <[email protected]>--- drivers/net/ethernet/intel/iecm/Makefile | 4 +- drivers/net/ethernet/intel/iecm/iecm_lib.c | 167 ++- drivers/net/ethernet/intel/iecm/iecm_txrx.c | 22 + .../net/ethernet/intel/iecm/iecm_virtchnl.c | 1299 +++++++++++++++++ drivers/net/ethernet/intel/include/iecm.h | 316 +++- .../net/ethernet/intel/include/iecm_txrx.h | 94 ++ 6 files changed, 1898 insertions(+), 4 deletions(-) create mode 100644 drivers/net/ethernet/intel/iecm/iecm_txrx.cReview
Quoted 1 line
(quoted diff) +0
-0b/drivers/net/ethernet/intel/iecm/Makefile
Review
Quoted 19 lines
index
db8fecb075a6..fcb49402334f100644drivers/net/ethernet/intel/iecm/Makefile +3
-1@@ -7,11 +7,13 @@ obj-$(CONFIG_IECM) += iecm.o -ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include +ccflags-y += -I$(srctree)/drivers/net/ethernet/intel/include \ + -I$(srctree)/include/linux/avf iecm-y := \ iecm_lib.o \ iecm_virtchnl.o \ + iecm_txrx.o \ iecm_controlq.o \ iecm_controlq_setup.o \ iecm_main.o(quoted diff) +0
-0
b/drivers/net/ethernet/intel/iecm/iecm_lib.cQuoted 28 lines
index
64cdbce2c842..e2e523f0700e100644drivers/net/ethernet/intel/iecm/iecm_lib.c +14
-0@@ -5,6 +5,11 @@#include "iecm.h" +const char *const iecm_vport_vc_state_str[] = { +IECM_FOREACH_VPORT_VC_STATE (IECM_GEN_STRING ) +}; +EXPORT_SYMBOL (iecm_vport_vc_state_str); +/** * iecm_cfg_hw - Initialize HW struct * @adapter: adapter to setup hw struct for @@ -24,6 +29,113 @@ static int iecm_cfg_hw(struct iecm_adapter *adapter)return 0 ; } +/** +* iecm_get_free_slot - get the next non-NULL location index in array +* @array: array to search +* @size: size of the array +* @curr: last known occupied index to be used as a search hint +* +* void * is being used to keep the functionality generic. This lets us use this +* function on any array of pointers. +*/ Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_cfg_hw(struct iecm_adapter *adapter) · line 46
Quoted 6 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +6
-0+static int iecm_get_free_slot (void *array,int size,int curr) +{ +int **tmp_array = (int **)array; +int next; + +if (curr < (size -1 ) && !tmp_array[curr +1 ]) {Redundant braces around
size - 1.Will fix
Quoted 158 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_cfg_hw(struct iecm_adapter *adapter) · line 57
Quoted 12 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +11
-0+ next = curr +1 ; + }else { +int i =0 ; + +while ((i < size) && (tmp_array[i])) + i++; +if (i == size) + next =IECM_NO_FREE_SLOT ; +else + next = i; + }One indent level is redundant here. First condition is an oneliner:
if (curr < (size - 1) && !tmp_array[curr + 1]) { return curr + 1; while ((i < size) && (tmp_array[i])) { ...drivers/net/ethernet/intel/iecm/iecm_lib.c static void iecm_service_task(struct work_struct
Quoted 85 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +81
-0+return next; +} + +/** +* iecm_vport_rel - Delete a vport and free its resources +* @vport: the vport being removed +*/ +static void iecm_vport_rel (struct iecm_vport *vport) +{ +mutex_destroy (&vport->stop_mutex); +kfree (vport); +} + +/** +* iecm_vport_rel_all - Delete all vports +* @adapter: adapter from which all vports are being removed +*/ +static void iecm_vport_rel_all (struct iecm_adapter *adapter) +{ +int i; + +if (!adapter->vports) +return ; + +for (i =0 ; i < adapter->num_alloc_vport; i++) { +if (!adapter->vports[i]) +continue ; + +iecm_vport_rel (adapter->vports[i]); + adapter->vports[i] =NULL ; + adapter->next_vport =0 ; + } + adapter->num_alloc_vport =0 ; +} + +/** +* iecm_vport_alloc - Allocates the next available struct vport in the adapter +* @adapter: board private structure +* @vport_id: vport identifier +* +* returns a pointer to a vport on success, NULL on failure. +*/ +static struct iecm_vport * +iecm_vport_alloc (struct iecm_adapter *adapter,int vport_id) +{ +struct iecm_vport *vport =NULL ; + +if (adapter->next_vport ==IECM_NO_FREE_SLOT ) +return vport; + +/* Need to protect the allocation of the vports at the adapter level */ +mutex_lock (&adapter->sw_mutex); + + vport =kzalloc (sizeof (*vport),GFP_KERNEL ); +if (!vport) + goto unlock_adapter; + + vport->adapter = adapter; + vport->idx = adapter->next_vport; + vport->compln_clean_budget =IECM_TX_COMPLQ_CLEAN_BUDGET ; + adapter->num_alloc_vport++; + +/* Setup default MSIX irq handler for the vport */ + vport->irq_q_handler = iecm_vport_intr_clean_queues; + vport->q_vector_base =IECM_NONQ_VEC ; + +mutex_init (&vport->stop_mutex); + +/* fill vport slot in the adapter struct */ + adapter->vports[adapter->next_vport] = vport; + +/* prepare adapter->next_vport for next use */ + adapter->next_vport =iecm_get_free_slot (adapter->vports, + adapter->num_alloc_vport, + adapter->next_vport); + +unlock_adapter: +mutex_unlock (&adapter->sw_mutex); +return vport; +} +/** * iecm_statistics_task - Delayed task to get statistics over mailbox * @work: work_struct handle to our data @@ -55,7 +167,25 @@ static void iecm_service_task(struct work_struct*work)
Quoted 38 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +27
-1*/ static void iecm_init_task (struct work_struct *work) { -/* stub */ +struct iecm_adapter *adapter =container_of (work, + struct iecm_adapter, + init_task.work); +struct iecm_vport *vport; +struct pci_dev *pdev; +int vport_id, err; + + err = adapter->dev_ops.vc_ops.core_init (adapter, &vport_id); +if (err) +return ; + + pdev = adapter->pdev; + vport =iecm_vport_alloc (adapter, vport_id); +if (!vport) { + err = -EFAULT ; +dev_err (&pdev->dev,"failed to allocate vport: %d\n" , + err); +return ; + } }/** @@ -81,6 +211,31 @@ static int iecm_api_init(struct iecm_adapter *adapter)return -EINVAL ; } +if (adapter->dev_ops.vc_ops_init) { +struct iecm_virtchnl_ops *vc_ops; + + adapter->dev_ops.vc_ops_init (adapter); + vc_ops = &adapter->dev_ops.vc_ops; + if (!(vc_ops->core_init && + vc_ops->vport_init && + vc_ops->vport_queue_ids_init &&drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 231
Quoted 10 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +10
-0+ vc_ops->get_caps && + vc_ops->config_queues && + vc_ops->enable_queues && + vc_ops->disable_queues && + vc_ops->irq_map_unmap && + vc_ops->get_set_rss_lut && + vc_ops->get_set_rss_hash && + vc_ops->adjust_qs && + vc_ops->get_ptype && + vc_ops->init_max_queues)) {if (!op1 || !op2 ||Quoted 2 lines
!opn) would look more natural and more readable here.
Quoted 1 line
I'm not sure I understand this comment. Adding an extra symbol for '!' seems worse.
But now you have two extra spaces, one for leading '!' and another one for leading '('.
I just wrote how it's usually being done in the kernel code, e.g. [0].
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 232
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +1
-0+ dev_err(&pdev->dev, "Invalid device, missing one ormore virtchnl functions\n");
drivers/net/ethernet/intel/iecm/iecm_lib.c static int iecm_api_init(struct iecm_adapter *adapter) · line 237
Quoted 5 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +5
-0+return -EINVAL ; + } + }else { +iecm_vc_ops_init (adapter); + }
--- 8< ---
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
drivers/net/ethernet/intel/iecm/iecm_lib.c +0
-1--2.33.0
Thanks,
Al
[0] https://elixir.bootlin.com/linux/v5.17-rc2/source/net/mac80211/main.c#L552
Thanks,
Al
PATCH 6/19 iecm: add virtchnl messages for queues
In reply to Alan BradyThis continues adding virtchnl messages. This largely relates to adding messages needed to negotiate and setup traffic queues.
--- drivers/net/ethernet/intel/iecm/iecm_lib.c | 14 + drivers/net/ethernet/intel/iecm/iecm_txrx.c | 161 +++ .../net/ethernet/intel/iecm/iecm_virtchnl.c | 1127 ++++++++++++++++- drivers/net/ethernet/intel/include/iecm.h | 22 + .../net/ethernet/intel/include/iecm_txrx.h | 196 +++ 5 files changed, 1505 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/iecm/iecm_lib.c +14 -0
@@ -90,6 +90,20 @@ static void iecm_vport_rel_all(struct iecm_adapter *adapter) adapter->num_alloc_vport =0 ; } +/** +* iecm_vport_set_hsplit - enable or disable header split on a given vport +* @vport: virtual port +* @ena: flag controlling header split, On (true) or Off (false) +*/ +void iecm_vport_set_hsplit (struct iecm_vport *vport,bool ena) +{ +if (iecm_is_cap_ena_all (vport->adapter,IECM_HSPLIT_CAPS , +IECM_CAP_HSPLIT ) && +iecm_is_queue_model_split (vport->rxq_model)) +set_bit (__IECM_PRIV_FLAGS_HDR_SPLIT, + vport->adapter->config_data.user_flags); +} +/** * iecm_vport_alloc - Allocates the next available struct vport in the adapter * @adapter: board private structure
drivers/net/ethernet/intel/iecm/iecm_txrx.c +161 -0
164 lines not on this page · raw message
drivers/net/ethernet/intel/iecm/iecm_virtchnl.c +1112 -15
1,175 lines not on this page · raw message
drivers/net/ethernet/intel/include/iecm.h +22 -0
@@ -432,6 +432,8 @@ struct iecm_adapter {u16 num_alloc_vport;u16 next_vport;/* Next free slot in pf->vport[] - 0-based! */ +u16 max_queue_limit;/* Max number of queues user can request */ +struct delayed_work init_task;/* delayed init task */ struct workqueue_struct *init_wq;u32 mb_wait_count;
@@ -510,6 +512,12 @@ static inline bool __iecm_is_cap_ena(struct iecm_adapter *adapter, bool all,return adapter->dev_ops.vc_ops.is_cap_ena (adapter, all, field, flag); } +#define IECM_CAP_HSPLIT (\ + VIRTCHNL2_CAP_RX_HSPLIT_AT_L2 |\ + VIRTCHNL2_CAP_RX_HSPLIT_AT_L3 |\ + VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V4 |\ + VIRTCHNL2_CAP_RX_HSPLIT_AT_L4V6) +/** * iecm_is_reset_detected - check if we were reset at some point * @adapter: driver specific private structure
@@ -530,6 +538,8 @@ int iecm_init_dflt_mbx(struct iecm_adapter *adapter);void iecm_deinit_dflt_mbx (struct iecm_adapter *adapter);void iecm_vc_ops_init (struct iecm_adapter *adapter);int iecm_vc_core_init (struct iecm_adapter *adapter,int *vport_id); +int iecm_get_reg_intr_vecs (struct iecm_vport *vport, +struct iecm_vec_regs *reg_vals,int num_vecs);int iecm_wait_for_event (struct iecm_adapter *adapter,enum iecm_vport_vc_state state,enum iecm_vport_vc_state err_check);
@@ -537,6 +547,14 @@ int iecm_min_wait_for_event(struct iecm_adapter *adapter,enum iecm_vport_vc_state state, enum iecm_vport_vc_state err_check);int iecm_send_get_caps_msg (struct iecm_adapter *adapter); +int iecm_send_delete_queues_msg (struct iecm_vport *vport); +int iecm_send_add_queues_msg (struct iecm_vport *vport,u16 num_tx_q, +u16 num_complq,u16 num_rx_q,u16 num_rx_bufq); +int iecm_send_config_tx_queues_msg (struct iecm_vport *vport); +int iecm_send_config_rx_queues_msg (struct iecm_vport *vport); +int iecm_send_enable_vport_msg (struct iecm_vport *vport); +int iecm_send_disable_vport_msg (struct iecm_vport *vport); +int iecm_send_destroy_vport_msg (struct iecm_vport *vport);int iecm_vport_params_buf_alloc (struct iecm_adapter *adapter);void iecm_vport_params_buf_rel (struct iecm_adapter *adapter); int iecm_get_vec_ids(struct iecm_adapter *adapter,
@@ -546,7 +564,11 @@ int iecm_recv_mb_msg(struct iecm_adapter *adapter, enum virtchnl_ops op, void *msg, int msg_size);int iecm_send_mb_msg (struct iecm_adapter *adapter,enum virtchnl_ops op,u16 msg_size,u8 *msg); +void iecm_vport_set_hsplit (struct iecm_vport *vport,bool ena); +int iecm_send_enable_channels_msg (struct iecm_vport *vport); +int iecm_send_disable_channels_msg (struct iecm_vport *vport);int iecm_set_msg_pending (struct iecm_adapter *adapter,struct iecm_ctlq_msg *ctlq_msg,enum iecm_vport_vc_state err_enum); +int iecm_send_map_unmap_queue_vector_msg (struct iecm_vport *vport,bool map);#endif /* !_IECM_H_ */
drivers/net/ethernet/intel/include/iecm_txrx.h +196 -0
208 lines not on this page · raw message
Signature · 1 line
2.33.0