LCOV - code coverage report
Current view: top level - drivers/net/gve/base - gve_adminq.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 438 0.0 %
Date: 2024-01-22 15:35:40 Functions: 0 30 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 316 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: MIT
       2                 :            :  * Google Virtual Ethernet (gve) driver
       3                 :            :  * Copyright (C) 2015-2022 Google, Inc.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "../gve_ethdev.h"
       7                 :            : #include "gve_adminq.h"
       8                 :            : #include "gve_register.h"
       9                 :            : 
      10                 :            : #define GVE_MAX_ADMINQ_RELEASE_CHECK    500
      11                 :            : #define GVE_ADMINQ_SLEEP_LEN            20
      12                 :            : #define GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK      100
      13                 :            : 
      14                 :            : #define GVE_DEVICE_OPTION_ERROR_FMT "%s option error:\n Expected: length=%d, feature_mask=%x.\n Actual: length=%d, feature_mask=%x."
      15                 :            : 
      16                 :            : #define GVE_DEVICE_OPTION_TOO_BIG_FMT "Length of %s option larger than expected. Possible older version of guest driver."
      17                 :            : 
      18                 :            : static
      19                 :            : struct gve_device_option *gve_get_next_option(struct gve_device_descriptor *descriptor,
      20                 :            :                                               struct gve_device_option *option)
      21                 :            : {
      22                 :            :         uintptr_t option_end, descriptor_end;
      23                 :            : 
      24         [ #  # ]:          0 :         option_end = (uintptr_t)option + sizeof(*option) + be16_to_cpu(option->option_length);
      25         [ #  # ]:          0 :         descriptor_end = (uintptr_t)descriptor + be16_to_cpu(descriptor->total_length);
      26                 :            : 
      27         [ #  # ]:          0 :         return option_end > descriptor_end ? NULL : (struct gve_device_option *)option_end;
      28                 :            : }
      29                 :            : 
      30                 :            : static
      31                 :          0 : void gve_parse_device_option(struct gve_priv *priv,
      32                 :            :                              struct gve_device_option *option,
      33                 :            :                              struct gve_device_option_gqi_rda **dev_op_gqi_rda,
      34                 :            :                              struct gve_device_option_gqi_qpl **dev_op_gqi_qpl,
      35                 :            :                              struct gve_device_option_dqo_rda **dev_op_dqo_rda,
      36                 :            :                              struct gve_device_option_jumbo_frames **dev_op_jumbo_frames)
      37                 :            : {
      38         [ #  # ]:          0 :         u32 req_feat_mask = be32_to_cpu(option->required_features_mask);
      39         [ #  # ]:          0 :         u16 option_length = be16_to_cpu(option->option_length);
      40         [ #  # ]:          0 :         u16 option_id = be16_to_cpu(option->option_id);
      41                 :            : 
      42                 :            :         /* If the length or feature mask doesn't match, continue without
      43                 :            :          * enabling the feature.
      44                 :            :          */
      45   [ #  #  #  #  :          0 :         switch (option_id) {
                   #  # ]
      46                 :          0 :         case GVE_DEV_OPT_ID_GQI_RAW_ADDRESSING:
      47                 :          0 :                 if (option_length != GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING ||
      48         [ #  # ]:          0 :                     req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RAW_ADDRESSING) {
      49                 :          0 :                         PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
      50                 :            :                                     "Raw Addressing",
      51                 :            :                                     GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING,
      52                 :            :                                     GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RAW_ADDRESSING,
      53                 :            :                                     option_length, req_feat_mask);
      54                 :          0 :                         break;
      55                 :            :                 }
      56                 :            : 
      57                 :          0 :                 PMD_DRV_LOG(INFO, "Gqi raw addressing device option enabled.");
      58                 :          0 :                 priv->queue_format = GVE_GQI_RDA_FORMAT;
      59                 :          0 :                 break;
      60                 :          0 :         case GVE_DEV_OPT_ID_GQI_RDA:
      61                 :          0 :                 if (option_length < sizeof(**dev_op_gqi_rda) ||
      62         [ #  # ]:          0 :                     req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RDA) {
      63                 :          0 :                         PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
      64                 :            :                                     "GQI RDA", (int)sizeof(**dev_op_gqi_rda),
      65                 :            :                                     GVE_DEV_OPT_REQ_FEAT_MASK_GQI_RDA,
      66                 :            :                                     option_length, req_feat_mask);
      67                 :          0 :                         break;
      68                 :            :                 }
      69                 :            : 
      70         [ #  # ]:          0 :                 if (option_length > sizeof(**dev_op_gqi_rda)) {
      71                 :          0 :                         PMD_DRV_LOG(WARNING,
      72                 :            :                                     GVE_DEVICE_OPTION_TOO_BIG_FMT, "GQI RDA");
      73                 :            :                 }
      74                 :          0 :                 *dev_op_gqi_rda = RTE_PTR_ADD(option, sizeof(*option));
      75                 :          0 :                 break;
      76                 :          0 :         case GVE_DEV_OPT_ID_GQI_QPL:
      77                 :          0 :                 if (option_length < sizeof(**dev_op_gqi_qpl) ||
      78         [ #  # ]:          0 :                     req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_GQI_QPL) {
      79                 :          0 :                         PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
      80                 :            :                                     "GQI QPL", (int)sizeof(**dev_op_gqi_qpl),
      81                 :            :                                     GVE_DEV_OPT_REQ_FEAT_MASK_GQI_QPL,
      82                 :            :                                     option_length, req_feat_mask);
      83                 :          0 :                         break;
      84                 :            :                 }
      85                 :            : 
      86         [ #  # ]:          0 :                 if (option_length > sizeof(**dev_op_gqi_qpl)) {
      87                 :          0 :                         PMD_DRV_LOG(WARNING,
      88                 :            :                                     GVE_DEVICE_OPTION_TOO_BIG_FMT, "GQI QPL");
      89                 :            :                 }
      90                 :          0 :                 *dev_op_gqi_qpl = RTE_PTR_ADD(option, sizeof(*option));
      91                 :          0 :                 break;
      92                 :          0 :         case GVE_DEV_OPT_ID_DQO_RDA:
      93                 :          0 :                 if (option_length < sizeof(**dev_op_dqo_rda) ||
      94         [ #  # ]:          0 :                     req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_DQO_RDA) {
      95                 :          0 :                         PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
      96                 :            :                                     "DQO RDA", (int)sizeof(**dev_op_dqo_rda),
      97                 :            :                                     GVE_DEV_OPT_REQ_FEAT_MASK_DQO_RDA,
      98                 :            :                                     option_length, req_feat_mask);
      99                 :          0 :                         break;
     100                 :            :                 }
     101                 :            : 
     102         [ #  # ]:          0 :                 if (option_length > sizeof(**dev_op_dqo_rda)) {
     103                 :          0 :                         PMD_DRV_LOG(WARNING,
     104                 :            :                                     GVE_DEVICE_OPTION_TOO_BIG_FMT, "DQO RDA");
     105                 :            :                 }
     106                 :          0 :                 *dev_op_dqo_rda = RTE_PTR_ADD(option, sizeof(*option));
     107                 :          0 :                 break;
     108                 :          0 :         case GVE_DEV_OPT_ID_JUMBO_FRAMES:
     109                 :          0 :                 if (option_length < sizeof(**dev_op_jumbo_frames) ||
     110         [ #  # ]:          0 :                     req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_JUMBO_FRAMES) {
     111                 :          0 :                         PMD_DRV_LOG(WARNING, GVE_DEVICE_OPTION_ERROR_FMT,
     112                 :            :                                     "Jumbo Frames",
     113                 :            :                                     (int)sizeof(**dev_op_jumbo_frames),
     114                 :            :                                     GVE_DEV_OPT_REQ_FEAT_MASK_JUMBO_FRAMES,
     115                 :            :                                     option_length, req_feat_mask);
     116                 :          0 :                         break;
     117                 :            :                 }
     118                 :            : 
     119         [ #  # ]:          0 :                 if (option_length > sizeof(**dev_op_jumbo_frames)) {
     120                 :          0 :                         PMD_DRV_LOG(WARNING,
     121                 :            :                                     GVE_DEVICE_OPTION_TOO_BIG_FMT,
     122                 :            :                                     "Jumbo Frames");
     123                 :            :                 }
     124                 :          0 :                 *dev_op_jumbo_frames = RTE_PTR_ADD(option, sizeof(*option));
     125                 :          0 :                 break;
     126                 :          0 :         default:
     127                 :            :                 /* If we don't recognize the option just continue
     128                 :            :                  * without doing anything.
     129                 :            :                  */
     130                 :          0 :                 PMD_DRV_LOG(DEBUG, "Unrecognized device option 0x%hx not enabled.",
     131                 :            :                             option_id);
     132                 :            :         }
     133                 :          0 : }
     134                 :            : 
     135                 :            : /* Process all device options for a given describe device call. */
     136                 :            : static int
     137                 :          0 : gve_process_device_options(struct gve_priv *priv,
     138                 :            :                            struct gve_device_descriptor *descriptor,
     139                 :            :                            struct gve_device_option_gqi_rda **dev_op_gqi_rda,
     140                 :            :                            struct gve_device_option_gqi_qpl **dev_op_gqi_qpl,
     141                 :            :                            struct gve_device_option_dqo_rda **dev_op_dqo_rda,
     142                 :            :                            struct gve_device_option_jumbo_frames **dev_op_jumbo_frames)
     143                 :            : {
     144         [ #  # ]:          0 :         const int num_options = be16_to_cpu(descriptor->num_device_options);
     145                 :            :         struct gve_device_option *dev_opt;
     146                 :            :         int i;
     147                 :            : 
     148                 :            :         /* The options struct directly follows the device descriptor. */
     149                 :          0 :         dev_opt = RTE_PTR_ADD(descriptor, sizeof(*descriptor));
     150         [ #  # ]:          0 :         for (i = 0; i < num_options; i++) {
     151                 :            :                 struct gve_device_option *next_opt;
     152                 :            : 
     153                 :            :                 next_opt = gve_get_next_option(descriptor, dev_opt);
     154         [ #  # ]:          0 :                 if (!next_opt) {
     155                 :          0 :                         PMD_DRV_LOG(ERR,
     156                 :            :                                     "options exceed device_descriptor's total length.");
     157                 :          0 :                         return -EINVAL;
     158                 :            :                 }
     159                 :            : 
     160                 :          0 :                 gve_parse_device_option(priv, dev_opt,
     161                 :            :                                         dev_op_gqi_rda, dev_op_gqi_qpl,
     162                 :            :                                         dev_op_dqo_rda, dev_op_jumbo_frames);
     163                 :            :                 dev_opt = next_opt;
     164                 :            :         }
     165                 :            : 
     166                 :            :         return 0;
     167                 :            : }
     168                 :            : 
     169                 :          0 : int gve_adminq_alloc(struct gve_priv *priv)
     170                 :            : {
     171                 :          0 :         priv->adminq = gve_alloc_dma_mem(&priv->adminq_dma_mem, PAGE_SIZE);
     172         [ #  # ]:          0 :         if (unlikely(!priv->adminq))
     173                 :            :                 return -ENOMEM;
     174                 :            : 
     175                 :          0 :         priv->adminq_mask = (PAGE_SIZE / sizeof(union gve_adminq_command)) - 1;
     176                 :          0 :         priv->adminq_prod_cnt = 0;
     177                 :          0 :         priv->adminq_cmd_fail = 0;
     178                 :          0 :         priv->adminq_timeouts = 0;
     179                 :          0 :         priv->adminq_describe_device_cnt = 0;
     180                 :          0 :         priv->adminq_cfg_device_resources_cnt = 0;
     181                 :          0 :         priv->adminq_register_page_list_cnt = 0;
     182                 :          0 :         priv->adminq_unregister_page_list_cnt = 0;
     183                 :          0 :         priv->adminq_create_tx_queue_cnt = 0;
     184                 :          0 :         priv->adminq_create_rx_queue_cnt = 0;
     185                 :          0 :         priv->adminq_destroy_tx_queue_cnt = 0;
     186                 :          0 :         priv->adminq_destroy_rx_queue_cnt = 0;
     187                 :          0 :         priv->adminq_dcfg_device_resources_cnt = 0;
     188                 :          0 :         priv->adminq_set_driver_parameter_cnt = 0;
     189                 :          0 :         priv->adminq_report_stats_cnt = 0;
     190                 :          0 :         priv->adminq_report_link_speed_cnt = 0;
     191                 :          0 :         priv->adminq_get_ptype_map_cnt = 0;
     192                 :            : 
     193                 :            :         /* Setup Admin queue with the device */
     194                 :          0 :         iowrite32be(priv->adminq_dma_mem.pa / PAGE_SIZE,
     195         [ #  # ]:          0 :                     &priv->reg_bar0->adminq_pfn);
     196                 :            : 
     197                 :            :         gve_set_admin_queue_ok(priv);
     198                 :          0 :         return 0;
     199                 :            : }
     200                 :            : 
     201                 :          0 : void gve_adminq_release(struct gve_priv *priv)
     202                 :            : {
     203                 :            :         int i = 0;
     204                 :            : 
     205                 :            :         /* Tell the device the adminq is leaving */
     206                 :          0 :         iowrite32be(0x0, &priv->reg_bar0->adminq_pfn);
     207         [ #  # ]:          0 :         while (ioread32be(&priv->reg_bar0->adminq_pfn)) {
     208                 :            :                 /* If this is reached the device is unrecoverable and still
     209                 :            :                  * holding memory. Continue looping to avoid memory corruption,
     210                 :            :                  * but WARN so it is visible what is going on.
     211                 :            :                  */
     212         [ #  # ]:          0 :                 if (i == GVE_MAX_ADMINQ_RELEASE_CHECK)
     213                 :          0 :                         PMD_DRV_LOG(WARNING, "Unrecoverable platform error!");
     214                 :          0 :                 i++;
     215                 :            :                 msleep(GVE_ADMINQ_SLEEP_LEN);
     216                 :            :         }
     217                 :            :         gve_clear_device_rings_ok(priv);
     218                 :            :         gve_clear_device_resources_ok(priv);
     219                 :            :         gve_clear_admin_queue_ok(priv);
     220                 :          0 : }
     221                 :            : 
     222         [ #  # ]:          0 : void gve_adminq_free(struct gve_priv *priv)
     223                 :            : {
     224         [ #  # ]:          0 :         if (!gve_get_admin_queue_ok(priv))
     225                 :            :                 return;
     226                 :          0 :         gve_adminq_release(priv);
     227                 :          0 :         gve_free_dma_mem(&priv->adminq_dma_mem);
     228                 :            :         gve_clear_admin_queue_ok(priv);
     229                 :            : }
     230                 :            : 
     231                 :            : static void gve_adminq_kick_cmd(struct gve_priv *priv, u32 prod_cnt)
     232                 :            : {
     233                 :          0 :         iowrite32be(prod_cnt, &priv->reg_bar0->adminq_doorbell);
     234                 :          0 : }
     235                 :            : 
     236                 :            : static bool gve_adminq_wait_for_cmd(struct gve_priv *priv, u32 prod_cnt)
     237                 :            : {
     238                 :            :         int i;
     239                 :            : 
     240         [ #  # ]:          0 :         for (i = 0; i < GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK; i++) {
     241         [ #  # ]:          0 :                 if (ioread32be(&priv->reg_bar0->adminq_event_counter)
     242                 :            :                     == prod_cnt)
     243                 :            :                         return true;
     244                 :            :                 msleep(GVE_ADMINQ_SLEEP_LEN);
     245                 :            :         }
     246                 :            : 
     247                 :            :         return false;
     248                 :            : }
     249                 :            : 
     250                 :          0 : static int gve_adminq_parse_err(struct gve_priv *priv, u32 status)
     251                 :            : {
     252         [ #  # ]:          0 :         if (status != GVE_ADMINQ_COMMAND_PASSED &&
     253                 :            :             status != GVE_ADMINQ_COMMAND_UNSET) {
     254                 :          0 :                 PMD_DRV_LOG(ERR, "AQ command failed with status %d", status);
     255                 :          0 :                 priv->adminq_cmd_fail++;
     256                 :            :         }
     257   [ #  #  #  #  :          0 :         switch (status) {
             #  #  #  #  
                      # ]
     258                 :            :         case GVE_ADMINQ_COMMAND_PASSED:
     259                 :            :                 return 0;
     260                 :          0 :         case GVE_ADMINQ_COMMAND_UNSET:
     261                 :          0 :                 PMD_DRV_LOG(ERR, "parse_aq_err: err and status both unset, this should not be possible.");
     262                 :          0 :                 return -EINVAL;
     263                 :          0 :         case GVE_ADMINQ_COMMAND_ERROR_ABORTED:
     264                 :            :         case GVE_ADMINQ_COMMAND_ERROR_CANCELLED:
     265                 :            :         case GVE_ADMINQ_COMMAND_ERROR_DATALOSS:
     266                 :            :         case GVE_ADMINQ_COMMAND_ERROR_FAILED_PRECONDITION:
     267                 :            :         case GVE_ADMINQ_COMMAND_ERROR_UNAVAILABLE:
     268                 :          0 :                 return -EAGAIN;
     269                 :          0 :         case GVE_ADMINQ_COMMAND_ERROR_ALREADY_EXISTS:
     270                 :            :         case GVE_ADMINQ_COMMAND_ERROR_INTERNAL_ERROR:
     271                 :            :         case GVE_ADMINQ_COMMAND_ERROR_INVALID_ARGUMENT:
     272                 :            :         case GVE_ADMINQ_COMMAND_ERROR_NOT_FOUND:
     273                 :            :         case GVE_ADMINQ_COMMAND_ERROR_OUT_OF_RANGE:
     274                 :            :         case GVE_ADMINQ_COMMAND_ERROR_UNKNOWN_ERROR:
     275                 :          0 :                 return -EINVAL;
     276                 :          0 :         case GVE_ADMINQ_COMMAND_ERROR_DEADLINE_EXCEEDED:
     277                 :          0 :                 return -ETIMEDOUT;
     278                 :          0 :         case GVE_ADMINQ_COMMAND_ERROR_PERMISSION_DENIED:
     279                 :            :         case GVE_ADMINQ_COMMAND_ERROR_UNAUTHENTICATED:
     280                 :          0 :                 return -EACCES;
     281                 :          0 :         case GVE_ADMINQ_COMMAND_ERROR_RESOURCE_EXHAUSTED:
     282                 :          0 :                 return -ENOMEM;
     283                 :          0 :         case GVE_ADMINQ_COMMAND_ERROR_UNIMPLEMENTED:
     284                 :          0 :                 return -ENOTSUP;
     285                 :          0 :         default:
     286                 :          0 :                 PMD_DRV_LOG(ERR, "parse_aq_err: unknown status code %d",
     287                 :            :                             status);
     288                 :          0 :                 return -EINVAL;
     289                 :            :         }
     290                 :            : }
     291                 :            : 
     292                 :            : /* Flushes all AQ commands currently queued and waits for them to complete.
     293                 :            :  * If there are failures, it will return the first error.
     294                 :            :  */
     295                 :          0 : static int gve_adminq_kick_and_wait(struct gve_priv *priv)
     296                 :            : {
     297                 :            :         u32 tail, head;
     298                 :            :         u32 i;
     299                 :            : 
     300                 :          0 :         tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
     301         [ #  # ]:          0 :         head = priv->adminq_prod_cnt;
     302                 :            : 
     303                 :            :         gve_adminq_kick_cmd(priv, head);
     304         [ #  # ]:          0 :         if (!gve_adminq_wait_for_cmd(priv, head)) {
     305                 :          0 :                 PMD_DRV_LOG(ERR, "AQ commands timed out, need to reset AQ");
     306                 :          0 :                 priv->adminq_timeouts++;
     307                 :          0 :                 return -ENOTRECOVERABLE;
     308                 :            :         }
     309                 :            : 
     310         [ #  # ]:          0 :         for (i = tail; i < head; i++) {
     311                 :            :                 union gve_adminq_command *cmd;
     312                 :            :                 u32 status, err;
     313                 :            : 
     314                 :          0 :                 cmd = &priv->adminq[i & priv->adminq_mask];
     315                 :            :                 status = be32_to_cpu(READ_ONCE32(cmd->status));
     316                 :          0 :                 err = gve_adminq_parse_err(priv, status);
     317         [ #  # ]:          0 :                 if (err)
     318                 :            :                         /* Return the first error if we failed. */
     319                 :          0 :                         return err;
     320                 :            :         }
     321                 :            : 
     322                 :            :         return 0;
     323                 :            : }
     324                 :            : 
     325                 :            : /* This function is not threadsafe - the caller is responsible for any
     326                 :            :  * necessary locks.
     327                 :            :  */
     328                 :          0 : static int gve_adminq_issue_cmd(struct gve_priv *priv,
     329                 :            :                                 union gve_adminq_command *cmd_orig)
     330                 :            : {
     331                 :            :         union gve_adminq_command *cmd;
     332                 :            :         u32 opcode;
     333                 :            :         u32 tail;
     334                 :            : 
     335                 :          0 :         tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
     336                 :            : 
     337                 :            :         /* Check if next command will overflow the buffer. */
     338                 :          0 :         if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) ==
     339         [ #  # ]:          0 :             (tail & priv->adminq_mask)) {
     340                 :            :                 int err;
     341                 :            : 
     342                 :            :                 /* Flush existing commands to make room. */
     343                 :          0 :                 err = gve_adminq_kick_and_wait(priv);
     344         [ #  # ]:          0 :                 if (err)
     345                 :            :                         return err;
     346                 :            : 
     347                 :            :                 /* Retry. */
     348                 :          0 :                 tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
     349                 :          0 :                 if (((priv->adminq_prod_cnt + 1) & priv->adminq_mask) ==
     350         [ #  # ]:          0 :                     (tail & priv->adminq_mask)) {
     351                 :            :                         /* This should never happen. We just flushed the
     352                 :            :                          * command queue so there should be enough space.
     353                 :            :                          */
     354                 :            :                         return -ENOMEM;
     355                 :            :                 }
     356                 :            :         }
     357                 :            : 
     358                 :          0 :         cmd = &priv->adminq[priv->adminq_prod_cnt & priv->adminq_mask];
     359                 :          0 :         priv->adminq_prod_cnt++;
     360                 :            : 
     361                 :            :         memcpy(cmd, cmd_orig, sizeof(*cmd_orig));
     362                 :            :         opcode = be32_to_cpu(READ_ONCE32(cmd->opcode));
     363                 :            : 
     364   [ #  #  #  #  :          0 :         switch (opcode) {
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
     365                 :          0 :         case GVE_ADMINQ_DESCRIBE_DEVICE:
     366                 :          0 :                 priv->adminq_describe_device_cnt++;
     367                 :          0 :                 break;
     368                 :          0 :         case GVE_ADMINQ_CONFIGURE_DEVICE_RESOURCES:
     369                 :          0 :                 priv->adminq_cfg_device_resources_cnt++;
     370                 :          0 :                 break;
     371                 :          0 :         case GVE_ADMINQ_REGISTER_PAGE_LIST:
     372                 :          0 :                 priv->adminq_register_page_list_cnt++;
     373                 :          0 :                 break;
     374                 :          0 :         case GVE_ADMINQ_UNREGISTER_PAGE_LIST:
     375                 :          0 :                 priv->adminq_unregister_page_list_cnt++;
     376                 :          0 :                 break;
     377                 :          0 :         case GVE_ADMINQ_CREATE_TX_QUEUE:
     378                 :          0 :                 priv->adminq_create_tx_queue_cnt++;
     379                 :          0 :                 break;
     380                 :          0 :         case GVE_ADMINQ_CREATE_RX_QUEUE:
     381                 :          0 :                 priv->adminq_create_rx_queue_cnt++;
     382                 :          0 :                 break;
     383                 :          0 :         case GVE_ADMINQ_DESTROY_TX_QUEUE:
     384                 :          0 :                 priv->adminq_destroy_tx_queue_cnt++;
     385                 :          0 :                 break;
     386                 :          0 :         case GVE_ADMINQ_DESTROY_RX_QUEUE:
     387                 :          0 :                 priv->adminq_destroy_rx_queue_cnt++;
     388                 :          0 :                 break;
     389                 :          0 :         case GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES:
     390                 :          0 :                 priv->adminq_dcfg_device_resources_cnt++;
     391                 :          0 :                 break;
     392                 :          0 :         case GVE_ADMINQ_SET_DRIVER_PARAMETER:
     393                 :          0 :                 priv->adminq_set_driver_parameter_cnt++;
     394                 :          0 :                 break;
     395                 :          0 :         case GVE_ADMINQ_REPORT_STATS:
     396                 :          0 :                 priv->adminq_report_stats_cnt++;
     397                 :          0 :                 break;
     398                 :          0 :         case GVE_ADMINQ_REPORT_LINK_SPEED:
     399                 :          0 :                 priv->adminq_report_link_speed_cnt++;
     400                 :          0 :                 break;
     401                 :          0 :         case GVE_ADMINQ_GET_PTYPE_MAP:
     402                 :          0 :                 priv->adminq_get_ptype_map_cnt++;
     403                 :          0 :                 break;
     404                 :          0 :         case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
     405                 :          0 :                 priv->adminq_verify_driver_compatibility_cnt++;
     406                 :          0 :                 break;
     407                 :          0 :         default:
     408                 :          0 :                 PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
     409                 :            :         }
     410                 :            : 
     411                 :            :         return 0;
     412                 :            : }
     413                 :            : 
     414                 :            : /* This function is not threadsafe - the caller is responsible for any
     415                 :            :  * necessary locks.
     416                 :            :  * The caller is also responsible for making sure there are no commands
     417                 :            :  * waiting to be executed.
     418                 :            :  */
     419                 :          0 : static int gve_adminq_execute_cmd(struct gve_priv *priv,
     420                 :            :                                   union gve_adminq_command *cmd_orig)
     421                 :            : {
     422                 :            :         u32 tail, head;
     423                 :            :         int err;
     424                 :            : 
     425                 :          0 :         tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
     426                 :          0 :         head = priv->adminq_prod_cnt;
     427         [ #  # ]:          0 :         if (tail != head)
     428                 :            :                 /* This is not a valid path */
     429                 :            :                 return -EINVAL;
     430                 :            : 
     431                 :          0 :         err = gve_adminq_issue_cmd(priv, cmd_orig);
     432         [ #  # ]:          0 :         if (err)
     433                 :            :                 return err;
     434                 :            : 
     435                 :          0 :         return gve_adminq_kick_and_wait(priv);
     436                 :            : }
     437                 :            : 
     438                 :            : /* The device specifies that the management vector can either be the first irq
     439                 :            :  * or the last irq. ntfy_blk_msix_base_idx indicates the first irq assigned to
     440                 :            :  * the ntfy blks. It if is 0 then the management vector is last, if it is 1 then
     441                 :            :  * the management vector is first.
     442                 :            :  *
     443                 :            :  * gve arranges the msix vectors so that the management vector is last.
     444                 :            :  */
     445                 :            : #define GVE_NTFY_BLK_BASE_MSIX_IDX      0
     446         [ #  # ]:          0 : int gve_adminq_configure_device_resources(struct gve_priv *priv,
     447                 :            :                                           dma_addr_t counter_array_bus_addr,
     448                 :            :                                           u32 num_counters,
     449                 :            :                                           dma_addr_t db_array_bus_addr,
     450                 :            :                                           u32 num_ntfy_blks)
     451                 :            : {
     452                 :            :         union gve_adminq_command cmd;
     453                 :            : 
     454                 :            :         memset(&cmd, 0, sizeof(cmd));
     455                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_CONFIGURE_DEVICE_RESOURCES);
     456                 :          0 :         cmd.configure_device_resources =
     457                 :            :                 (struct gve_adminq_configure_device_resources) {
     458         [ #  # ]:          0 :                 .counter_array = cpu_to_be64(counter_array_bus_addr),
     459         [ #  # ]:          0 :                 .num_counters = cpu_to_be32(num_counters),
     460         [ #  # ]:          0 :                 .irq_db_addr = cpu_to_be64(db_array_bus_addr),
     461         [ #  # ]:          0 :                 .num_irq_dbs = cpu_to_be32(num_ntfy_blks),
     462                 :            :                 .irq_db_stride = cpu_to_be32(sizeof(*priv->irq_dbs)),
     463                 :            :                 .ntfy_blk_msix_base_idx =
     464                 :            :                                         cpu_to_be32(GVE_NTFY_BLK_BASE_MSIX_IDX),
     465                 :          0 :                 .queue_format = priv->queue_format,
     466                 :            :         };
     467                 :            : 
     468                 :          0 :         return gve_adminq_execute_cmd(priv, &cmd);
     469                 :            : }
     470                 :            : 
     471         [ #  # ]:          0 : int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
     472                 :            :                                            u64 driver_info_len,
     473                 :            :                                            dma_addr_t driver_info_addr)
     474                 :            : {
     475                 :            :         union gve_adminq_command cmd;
     476                 :            : 
     477                 :            :         memset(&cmd, 0, sizeof(cmd));
     478                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
     479                 :          0 :         cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
     480         [ #  # ]:          0 :                 .driver_info_len = cpu_to_be64(driver_info_len),
     481         [ #  # ]:          0 :                 .driver_info_addr = cpu_to_be64(driver_info_addr),
     482                 :            :         };
     483                 :            : 
     484                 :          0 :         return gve_adminq_execute_cmd(priv, &cmd);
     485                 :            : }
     486                 :            : 
     487                 :          0 : int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
     488                 :            : {
     489                 :            :         union gve_adminq_command cmd;
     490                 :            : 
     491                 :            :         memset(&cmd, 0, sizeof(cmd));
     492                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES);
     493                 :            : 
     494                 :          0 :         return gve_adminq_execute_cmd(priv, &cmd);
     495                 :            : }
     496                 :            : 
     497                 :          0 : static int gve_adminq_create_tx_queue(struct gve_priv *priv, u32 queue_index)
     498                 :            : {
     499         [ #  # ]:          0 :         struct gve_tx_queue *txq = priv->txqs[queue_index];
     500                 :            :         union gve_adminq_command cmd;
     501                 :            : 
     502                 :            :         memset(&cmd, 0, sizeof(cmd));
     503                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_CREATE_TX_QUEUE);
     504         [ #  # ]:          0 :         cmd.create_tx_queue = (struct gve_adminq_create_tx_queue) {
     505         [ #  # ]:          0 :                 .queue_id = cpu_to_be32(queue_index),
     506                 :            :                 .queue_resources_addr =
     507         [ #  # ]:          0 :                         cpu_to_be64(txq->qres_mz->iova),
     508         [ #  # ]:          0 :                 .tx_ring_addr = cpu_to_be64(txq->tx_ring_phys_addr),
     509         [ #  # ]:          0 :                 .ntfy_id = cpu_to_be32(txq->ntfy_id),
     510                 :            :         };
     511                 :            : 
     512         [ #  # ]:          0 :         if (gve_is_gqi(priv)) {
     513                 :            :                 u32 qpl_id = priv->queue_format == GVE_GQI_RDA_FORMAT ?
     514         [ #  # ]:          0 :                         GVE_RAW_ADDRESSING_QPL_ID : txq->qpl->id;
     515                 :            : 
     516         [ #  # ]:          0 :                 cmd.create_tx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
     517                 :            :         } else {
     518                 :          0 :                 cmd.create_tx_queue.tx_ring_size =
     519         [ #  # ]:          0 :                         cpu_to_be16(txq->nb_tx_desc);
     520                 :          0 :                 cmd.create_tx_queue.tx_comp_ring_addr =
     521         [ #  # ]:          0 :                         cpu_to_be64(txq->compl_ring_phys_addr);
     522                 :          0 :                 cmd.create_tx_queue.tx_comp_ring_size =
     523         [ #  # ]:          0 :                         cpu_to_be16(txq->sw_size);
     524                 :            :         }
     525                 :            : 
     526                 :          0 :         return gve_adminq_issue_cmd(priv, &cmd);
     527                 :            : }
     528                 :            : 
     529                 :          0 : int gve_adminq_create_tx_queues(struct gve_priv *priv, u32 num_queues)
     530                 :            : {
     531                 :            :         int err;
     532                 :            :         u32 i;
     533                 :            : 
     534         [ #  # ]:          0 :         for (i = 0; i < num_queues; i++) {
     535                 :          0 :                 err = gve_adminq_create_tx_queue(priv, i);
     536         [ #  # ]:          0 :                 if (err)
     537                 :          0 :                         return err;
     538                 :            :         }
     539                 :            : 
     540                 :          0 :         return gve_adminq_kick_and_wait(priv);
     541                 :            : }
     542                 :            : 
     543                 :          0 : static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
     544                 :            : {
     545         [ #  # ]:          0 :         struct gve_rx_queue *rxq = priv->rxqs[queue_index];
     546                 :            :         union gve_adminq_command cmd;
     547                 :            : 
     548                 :            :         memset(&cmd, 0, sizeof(cmd));
     549                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_CREATE_RX_QUEUE);
     550         [ #  # ]:          0 :         cmd.create_rx_queue = (struct gve_adminq_create_rx_queue) {
     551         [ #  # ]:          0 :                 .queue_id = cpu_to_be32(queue_index),
     552         [ #  # ]:          0 :                 .ntfy_id = cpu_to_be32(rxq->ntfy_id),
     553         [ #  # ]:          0 :                 .queue_resources_addr = cpu_to_be64(rxq->qres_mz->iova),
     554                 :            :         };
     555                 :            : 
     556         [ #  # ]:          0 :         if (gve_is_gqi(priv)) {
     557                 :            :                 u32 qpl_id = priv->queue_format == GVE_GQI_RDA_FORMAT ?
     558         [ #  # ]:          0 :                         GVE_RAW_ADDRESSING_QPL_ID : rxq->qpl->id;
     559                 :            : 
     560                 :          0 :                 cmd.create_rx_queue.rx_desc_ring_addr =
     561         [ #  # ]:          0 :                         cpu_to_be64(rxq->mz->iova),
     562                 :          0 :                 cmd.create_rx_queue.rx_data_ring_addr =
     563         [ #  # ]:          0 :                         cpu_to_be64(rxq->data_mz->iova),
     564         [ #  # ]:          0 :                 cmd.create_rx_queue.index = cpu_to_be32(queue_index);
     565         [ #  # ]:          0 :                 cmd.create_rx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
     566         [ #  # ]:          0 :                 cmd.create_rx_queue.packet_buffer_size = cpu_to_be16(rxq->rx_buf_len);
     567                 :            :         } else {
     568                 :          0 :                 cmd.create_rx_queue.rx_ring_size =
     569         [ #  # ]:          0 :                         cpu_to_be16(rxq->nb_rx_desc);
     570                 :          0 :                 cmd.create_rx_queue.rx_desc_ring_addr =
     571         [ #  # ]:          0 :                         cpu_to_be64(rxq->compl_ring_phys_addr);
     572                 :          0 :                 cmd.create_rx_queue.rx_data_ring_addr =
     573         [ #  # ]:          0 :                         cpu_to_be64(rxq->rx_ring_phys_addr);
     574                 :          0 :                 cmd.create_rx_queue.packet_buffer_size =
     575         [ #  # ]:          0 :                         cpu_to_be16(rxq->rx_buf_len);
     576                 :          0 :                 cmd.create_rx_queue.rx_buff_ring_size =
     577         [ #  # ]:          0 :                         cpu_to_be16(rxq->nb_rx_desc);
     578                 :          0 :                 cmd.create_rx_queue.enable_rsc = !!(priv->enable_rsc);
     579                 :            :         }
     580                 :            : 
     581                 :          0 :         return gve_adminq_issue_cmd(priv, &cmd);
     582                 :            : }
     583                 :            : 
     584                 :          0 : int gve_adminq_create_rx_queues(struct gve_priv *priv, u32 num_queues)
     585                 :            : {
     586                 :            :         int err;
     587                 :            :         u32 i;
     588                 :            : 
     589         [ #  # ]:          0 :         for (i = 0; i < num_queues; i++) {
     590                 :          0 :                 err = gve_adminq_create_rx_queue(priv, i);
     591         [ #  # ]:          0 :                 if (err)
     592                 :          0 :                         return err;
     593                 :            :         }
     594                 :            : 
     595                 :          0 :         return gve_adminq_kick_and_wait(priv);
     596                 :            : }
     597                 :            : 
     598         [ #  # ]:          0 : static int gve_adminq_destroy_tx_queue(struct gve_priv *priv, u32 queue_index)
     599                 :            : {
     600                 :            :         union gve_adminq_command cmd;
     601                 :            :         int err;
     602                 :            : 
     603                 :            :         memset(&cmd, 0, sizeof(cmd));
     604                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESTROY_TX_QUEUE);
     605                 :          0 :         cmd.destroy_tx_queue = (struct gve_adminq_destroy_tx_queue) {
     606         [ #  # ]:          0 :                 .queue_id = cpu_to_be32(queue_index),
     607                 :            :         };
     608                 :            : 
     609                 :          0 :         err = gve_adminq_issue_cmd(priv, &cmd);
     610         [ #  # ]:          0 :         if (err)
     611                 :          0 :                 return err;
     612                 :            : 
     613                 :            :         return 0;
     614                 :            : }
     615                 :            : 
     616                 :          0 : int gve_adminq_destroy_tx_queues(struct gve_priv *priv, u32 num_queues)
     617                 :            : {
     618                 :            :         int err;
     619                 :            :         u32 i;
     620                 :            : 
     621         [ #  # ]:          0 :         for (i = 0; i < num_queues; i++) {
     622                 :          0 :                 err = gve_adminq_destroy_tx_queue(priv, i);
     623         [ #  # ]:          0 :                 if (err)
     624                 :          0 :                         return err;
     625                 :            :         }
     626                 :            : 
     627                 :          0 :         return gve_adminq_kick_and_wait(priv);
     628                 :            : }
     629                 :            : 
     630         [ #  # ]:          0 : static int gve_adminq_destroy_rx_queue(struct gve_priv *priv, u32 queue_index)
     631                 :            : {
     632                 :            :         union gve_adminq_command cmd;
     633                 :            :         int err;
     634                 :            : 
     635                 :            :         memset(&cmd, 0, sizeof(cmd));
     636                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESTROY_RX_QUEUE);
     637                 :          0 :         cmd.destroy_rx_queue = (struct gve_adminq_destroy_rx_queue) {
     638         [ #  # ]:          0 :                 .queue_id = cpu_to_be32(queue_index),
     639                 :            :         };
     640                 :            : 
     641                 :          0 :         err = gve_adminq_issue_cmd(priv, &cmd);
     642         [ #  # ]:          0 :         if (err)
     643                 :          0 :                 return err;
     644                 :            : 
     645                 :            :         return 0;
     646                 :            : }
     647                 :            : 
     648                 :          0 : int gve_adminq_destroy_rx_queues(struct gve_priv *priv, u32 num_queues)
     649                 :            : {
     650                 :            :         int err;
     651                 :            :         u32 i;
     652                 :            : 
     653         [ #  # ]:          0 :         for (i = 0; i < num_queues; i++) {
     654                 :          0 :                 err = gve_adminq_destroy_rx_queue(priv, i);
     655         [ #  # ]:          0 :                 if (err)
     656                 :          0 :                         return err;
     657                 :            :         }
     658                 :            : 
     659                 :          0 :         return gve_adminq_kick_and_wait(priv);
     660                 :            : }
     661                 :            : 
     662                 :          0 : static int gve_set_desc_cnt(struct gve_priv *priv,
     663                 :            :                             struct gve_device_descriptor *descriptor)
     664                 :            : {
     665         [ #  # ]:          0 :         priv->tx_desc_cnt = be16_to_cpu(descriptor->tx_queue_entries);
     666         [ #  # ]:          0 :         if (priv->tx_desc_cnt * sizeof(priv->txqs[0]->tx_desc_ring[0])
     667                 :            :             < PAGE_SIZE) {
     668                 :          0 :                 PMD_DRV_LOG(ERR, "Tx desc count %d too low", priv->tx_desc_cnt);
     669                 :          0 :                 return -EINVAL;
     670                 :            :         }
     671         [ #  # ]:          0 :         priv->rx_desc_cnt = be16_to_cpu(descriptor->rx_queue_entries);
     672         [ #  # ]:          0 :         if (priv->rx_desc_cnt * sizeof(priv->rxqs[0]->rx_desc_ring[0])
     673                 :            :             < PAGE_SIZE) {
     674                 :          0 :                 PMD_DRV_LOG(ERR, "Rx desc count %d too low", priv->rx_desc_cnt);
     675                 :          0 :                 return -EINVAL;
     676                 :            :         }
     677                 :            :         return 0;
     678                 :            : }
     679                 :            : 
     680                 :            : static int
     681                 :          0 : gve_set_desc_cnt_dqo(struct gve_priv *priv,
     682                 :            :                      const struct gve_device_descriptor *descriptor,
     683                 :            :                      const struct gve_device_option_dqo_rda *dev_op_dqo_rda)
     684                 :            : {
     685         [ #  # ]:          0 :         priv->tx_desc_cnt = be16_to_cpu(descriptor->tx_queue_entries);
     686         [ #  # ]:          0 :         priv->tx_compq_size = be16_to_cpu(dev_op_dqo_rda->tx_comp_ring_entries);
     687         [ #  # ]:          0 :         priv->rx_desc_cnt = be16_to_cpu(descriptor->rx_queue_entries);
     688         [ #  # ]:          0 :         priv->rx_bufq_size = be16_to_cpu(dev_op_dqo_rda->rx_buff_ring_entries);
     689                 :            : 
     690                 :          0 :         return 0;
     691                 :            : }
     692                 :            : 
     693                 :          0 : static void gve_enable_supported_features(struct gve_priv *priv,
     694                 :            :                                           u32 supported_features_mask,
     695                 :            :                                           const struct gve_device_option_jumbo_frames
     696                 :            :                                                   *dev_op_jumbo_frames)
     697                 :            : {
     698                 :            :         /* Before control reaches this point, the page-size-capped max MTU from
     699                 :            :          * the gve_device_descriptor field has already been stored in
     700                 :            :          * priv->dev->max_mtu. We overwrite it with the true max MTU below.
     701                 :            :          */
     702         [ #  # ]:          0 :         if (dev_op_jumbo_frames &&
     703         [ #  # ]:          0 :             (supported_features_mask & GVE_SUP_JUMBO_FRAMES_MASK)) {
     704                 :          0 :                 PMD_DRV_LOG(INFO, "JUMBO FRAMES device option enabled.");
     705         [ #  # ]:          0 :                 priv->max_mtu = be16_to_cpu(dev_op_jumbo_frames->max_mtu);
     706                 :            :         }
     707                 :          0 : }
     708                 :            : 
     709                 :          0 : int gve_adminq_describe_device(struct gve_priv *priv)
     710                 :            : {
     711                 :          0 :         struct gve_device_option_jumbo_frames *dev_op_jumbo_frames = NULL;
     712                 :          0 :         struct gve_device_option_gqi_rda *dev_op_gqi_rda = NULL;
     713                 :          0 :         struct gve_device_option_gqi_qpl *dev_op_gqi_qpl = NULL;
     714                 :          0 :         struct gve_device_option_dqo_rda *dev_op_dqo_rda = NULL;
     715                 :            :         struct gve_device_descriptor *descriptor;
     716                 :            :         struct gve_dma_mem descriptor_dma_mem;
     717                 :            :         u32 supported_features_mask = 0;
     718                 :            :         union gve_adminq_command cmd;
     719                 :            :         int err = 0;
     720                 :            :         u16 mtu;
     721                 :            : 
     722                 :            :         memset(&cmd, 0, sizeof(cmd));
     723                 :          0 :         descriptor = gve_alloc_dma_mem(&descriptor_dma_mem, PAGE_SIZE);
     724         [ #  # ]:          0 :         if (!descriptor)
     725                 :            :                 return -ENOMEM;
     726                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESCRIBE_DEVICE);
     727                 :          0 :         cmd.describe_device.device_descriptor_addr =
     728         [ #  # ]:          0 :                                         cpu_to_be64(descriptor_dma_mem.pa);
     729                 :          0 :         cmd.describe_device.device_descriptor_version =
     730                 :            :                         cpu_to_be32(GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION);
     731                 :          0 :         cmd.describe_device.available_length = cpu_to_be32(PAGE_SIZE);
     732                 :            : 
     733                 :          0 :         err = gve_adminq_execute_cmd(priv, &cmd);
     734         [ #  # ]:          0 :         if (err)
     735                 :          0 :                 goto free_device_descriptor;
     736                 :            : 
     737                 :          0 :         err = gve_process_device_options(priv, descriptor, &dev_op_gqi_rda,
     738                 :            :                                          &dev_op_gqi_qpl, &dev_op_dqo_rda,
     739                 :            :                                          &dev_op_jumbo_frames);
     740         [ #  # ]:          0 :         if (err)
     741                 :          0 :                 goto free_device_descriptor;
     742                 :            : 
     743                 :            :         /* If the GQI_RAW_ADDRESSING option is not enabled and the queue format
     744                 :            :          * is not set to GqiRda, choose the queue format in a priority order:
     745                 :            :          * DqoRda, GqiRda, GqiQpl. Use GqiQpl as default.
     746                 :            :          */
     747         [ #  # ]:          0 :         if (dev_op_dqo_rda) {
     748                 :          0 :                 priv->queue_format = GVE_DQO_RDA_FORMAT;
     749                 :          0 :                 PMD_DRV_LOG(INFO, "Driver is running with DQO RDA queue format.");
     750                 :            :                 supported_features_mask =
     751         [ #  # ]:          0 :                         be32_to_cpu(dev_op_dqo_rda->supported_features_mask);
     752         [ #  # ]:          0 :         } else if (dev_op_gqi_rda) {
     753                 :          0 :                 priv->queue_format = GVE_GQI_RDA_FORMAT;
     754                 :          0 :                 PMD_DRV_LOG(INFO, "Driver is running with GQI RDA queue format.");
     755                 :            :                 supported_features_mask =
     756         [ #  # ]:          0 :                         be32_to_cpu(dev_op_gqi_rda->supported_features_mask);
     757         [ #  # ]:          0 :         } else if (priv->queue_format == GVE_GQI_RDA_FORMAT) {
     758                 :          0 :                 PMD_DRV_LOG(INFO, "Driver is running with GQI RDA queue format.");
     759                 :            :         } else {
     760                 :          0 :                 priv->queue_format = GVE_GQI_QPL_FORMAT;
     761         [ #  # ]:          0 :                 if (dev_op_gqi_qpl)
     762                 :            :                         supported_features_mask =
     763         [ #  # ]:          0 :                                 be32_to_cpu(dev_op_gqi_qpl->supported_features_mask);
     764                 :          0 :                 PMD_DRV_LOG(INFO, "Driver is running with GQI QPL queue format.");
     765                 :            :         }
     766         [ #  # ]:          0 :         if (gve_is_gqi(priv)) {
     767                 :          0 :                 err = gve_set_desc_cnt(priv, descriptor);
     768                 :            :         } else {
     769                 :            :                 /* DQO supports LRO. */
     770                 :          0 :                 err = gve_set_desc_cnt_dqo(priv, descriptor, dev_op_dqo_rda);
     771                 :            :         }
     772         [ #  # ]:          0 :         if (err)
     773                 :          0 :                 goto free_device_descriptor;
     774                 :            : 
     775                 :          0 :         priv->max_registered_pages =
     776         [ #  # ]:          0 :                                 be64_to_cpu(descriptor->max_registered_pages);
     777         [ #  # ]:          0 :         mtu = be16_to_cpu(descriptor->mtu);
     778         [ #  # ]:          0 :         if (mtu < ETH_MIN_MTU) {
     779                 :          0 :                 PMD_DRV_LOG(ERR, "MTU %d below minimum MTU", mtu);
     780                 :            :                 err = -EINVAL;
     781                 :          0 :                 goto free_device_descriptor;
     782                 :            :         }
     783                 :          0 :         priv->max_mtu = mtu;
     784         [ #  # ]:          0 :         priv->num_event_counters = be16_to_cpu(descriptor->counters);
     785         [ #  # ]:          0 :         rte_memcpy(priv->dev_addr.addr_bytes, descriptor->mac, ETH_ALEN);
     786                 :          0 :         PMD_DRV_LOG(INFO, "MAC addr: " RTE_ETHER_ADDR_PRT_FMT,
     787                 :            :                     RTE_ETHER_ADDR_BYTES(&priv->dev_addr));
     788         [ #  # ]:          0 :         priv->tx_pages_per_qpl = be16_to_cpu(descriptor->tx_pages_per_qpl);
     789   [ #  #  #  # ]:          0 :         priv->rx_data_slot_cnt = be16_to_cpu(descriptor->rx_pages_per_qpl);
     790                 :            : 
     791   [ #  #  #  # ]:          0 :         if (gve_is_gqi(priv) && priv->rx_data_slot_cnt < priv->rx_desc_cnt) {
     792                 :          0 :                 PMD_DRV_LOG(ERR,
     793                 :            :                             "rx_data_slot_cnt cannot be smaller than rx_desc_cnt, setting rx_desc_cnt down to %d",
     794                 :            :                             priv->rx_data_slot_cnt);
     795                 :          0 :                 priv->rx_desc_cnt = priv->rx_data_slot_cnt;
     796                 :            :         }
     797         [ #  # ]:          0 :         priv->default_num_queues = be16_to_cpu(descriptor->default_num_queues);
     798                 :            : 
     799                 :          0 :         gve_enable_supported_features(priv, supported_features_mask,
     800                 :            :                                       dev_op_jumbo_frames);
     801                 :            : 
     802                 :          0 : free_device_descriptor:
     803                 :          0 :         gve_free_dma_mem(&descriptor_dma_mem);
     804                 :          0 :         return err;
     805                 :            : }
     806                 :            : 
     807                 :          0 : int gve_adminq_register_page_list(struct gve_priv *priv,
     808                 :            :                                   struct gve_queue_page_list *qpl)
     809                 :            : {
     810                 :            :         struct gve_dma_mem page_list_dma_mem;
     811                 :          0 :         u32 num_entries = qpl->num_entries;
     812                 :          0 :         u32 size = num_entries * sizeof(qpl->page_buses[0]);
     813                 :            :         union gve_adminq_command cmd;
     814                 :            :         __be64 *page_list;
     815                 :            :         int err;
     816                 :            :         u32 i;
     817                 :            : 
     818                 :            :         memset(&cmd, 0, sizeof(cmd));
     819                 :          0 :         page_list = gve_alloc_dma_mem(&page_list_dma_mem, size);
     820         [ #  # ]:          0 :         if (!page_list)
     821                 :            :                 return -ENOMEM;
     822                 :            : 
     823         [ #  # ]:          0 :         for (i = 0; i < num_entries; i++)
     824         [ #  # ]:          0 :                 page_list[i] = cpu_to_be64(qpl->page_buses[i]);
     825                 :            : 
     826                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_REGISTER_PAGE_LIST);
     827                 :          0 :         cmd.reg_page_list = (struct gve_adminq_register_page_list) {
     828         [ #  # ]:          0 :                 .page_list_id = cpu_to_be32(qpl->id),
     829         [ #  # ]:          0 :                 .num_pages = cpu_to_be32(num_entries),
     830         [ #  # ]:          0 :                 .page_address_list_addr = cpu_to_be64(page_list_dma_mem.pa),
     831                 :            :         };
     832                 :            : 
     833                 :          0 :         err = gve_adminq_execute_cmd(priv, &cmd);
     834                 :          0 :         gve_free_dma_mem(&page_list_dma_mem);
     835                 :          0 :         return err;
     836                 :            : }
     837                 :            : 
     838         [ #  # ]:          0 : int gve_adminq_unregister_page_list(struct gve_priv *priv, u32 page_list_id)
     839                 :            : {
     840                 :            :         union gve_adminq_command cmd;
     841                 :            : 
     842                 :            :         memset(&cmd, 0, sizeof(cmd));
     843                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_UNREGISTER_PAGE_LIST);
     844                 :          0 :         cmd.unreg_page_list = (struct gve_adminq_unregister_page_list) {
     845         [ #  # ]:          0 :                 .page_list_id = cpu_to_be32(page_list_id),
     846                 :            :         };
     847                 :            : 
     848                 :          0 :         return gve_adminq_execute_cmd(priv, &cmd);
     849                 :            : }
     850                 :            : 
     851         [ #  # ]:          0 : int gve_adminq_set_mtu(struct gve_priv *priv, u64 mtu)
     852                 :            : {
     853                 :            :         union gve_adminq_command cmd;
     854                 :            : 
     855                 :            :         memset(&cmd, 0, sizeof(cmd));
     856                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_SET_DRIVER_PARAMETER);
     857                 :          0 :         cmd.set_driver_param = (struct gve_adminq_set_driver_parameter) {
     858                 :            :                 .parameter_type = cpu_to_be32(GVE_SET_PARAM_MTU),
     859         [ #  # ]:          0 :                 .parameter_value = cpu_to_be64(mtu),
     860                 :            :         };
     861                 :            : 
     862                 :          0 :         return gve_adminq_execute_cmd(priv, &cmd);
     863                 :            : }
     864                 :            : 
     865         [ #  # ]:          0 : int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len,
     866                 :            :                             dma_addr_t stats_report_addr, u64 interval)
     867                 :            : {
     868                 :            :         union gve_adminq_command cmd;
     869                 :            : 
     870                 :            :         memset(&cmd, 0, sizeof(cmd));
     871                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_REPORT_STATS);
     872                 :          0 :         cmd.report_stats = (struct gve_adminq_report_stats) {
     873         [ #  # ]:          0 :                 .stats_report_len = cpu_to_be64(stats_report_len),
     874         [ #  # ]:          0 :                 .stats_report_addr = cpu_to_be64(stats_report_addr),
     875         [ #  # ]:          0 :                 .interval = cpu_to_be64(interval),
     876                 :            :         };
     877                 :            : 
     878                 :          0 :         return gve_adminq_execute_cmd(priv, &cmd);
     879                 :            : }
     880                 :            : 
     881                 :          0 : int gve_adminq_report_link_speed(struct gve_priv *priv)
     882                 :            : {
     883                 :            :         struct gve_dma_mem link_speed_region_dma_mem;
     884                 :            :         union gve_adminq_command gvnic_cmd;
     885                 :            :         u64 *link_speed_region;
     886                 :            :         int err;
     887                 :            : 
     888                 :          0 :         link_speed_region = gve_alloc_dma_mem(&link_speed_region_dma_mem,
     889                 :            :                                               sizeof(*link_speed_region));
     890                 :            : 
     891         [ #  # ]:          0 :         if (!link_speed_region)
     892                 :            :                 return -ENOMEM;
     893                 :            : 
     894                 :            :         memset(&gvnic_cmd, 0, sizeof(gvnic_cmd));
     895                 :          0 :         gvnic_cmd.opcode = cpu_to_be32(GVE_ADMINQ_REPORT_LINK_SPEED);
     896                 :          0 :         gvnic_cmd.report_link_speed.link_speed_address =
     897         [ #  # ]:          0 :                 cpu_to_be64(link_speed_region_dma_mem.pa);
     898                 :            : 
     899                 :          0 :         err = gve_adminq_execute_cmd(priv, &gvnic_cmd);
     900                 :            : 
     901         [ #  # ]:          0 :         priv->link_speed = be64_to_cpu(*link_speed_region);
     902                 :          0 :         gve_free_dma_mem(&link_speed_region_dma_mem);
     903                 :          0 :         return err;
     904                 :            : }
     905                 :            : 
     906                 :          0 : int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
     907                 :            :                                  struct gve_ptype_lut *ptype_lut)
     908                 :            : {
     909                 :            :         struct gve_dma_mem ptype_map_dma_mem;
     910                 :            :         struct gve_ptype_map *ptype_map;
     911                 :            :         union gve_adminq_command cmd;
     912                 :            :         int err = 0;
     913                 :            :         int i;
     914                 :            : 
     915                 :            :         memset(&cmd, 0, sizeof(cmd));
     916                 :          0 :         ptype_map = gve_alloc_dma_mem(&ptype_map_dma_mem, sizeof(*ptype_map));
     917         [ #  # ]:          0 :         if (!ptype_map)
     918                 :            :                 return -ENOMEM;
     919                 :            : 
     920                 :          0 :         cmd.opcode = cpu_to_be32(GVE_ADMINQ_GET_PTYPE_MAP);
     921                 :          0 :         cmd.get_ptype_map = (struct gve_adminq_get_ptype_map) {
     922                 :            :                 .ptype_map_len = cpu_to_be64(sizeof(*ptype_map)),
     923         [ #  # ]:          0 :                 .ptype_map_addr = cpu_to_be64(ptype_map_dma_mem.pa),
     924                 :            :         };
     925                 :            : 
     926                 :          0 :         err = gve_adminq_execute_cmd(priv, &cmd);
     927         [ #  # ]:          0 :         if (err)
     928                 :          0 :                 goto err;
     929                 :            : 
     930                 :            :         /* Populate ptype_lut. */
     931         [ #  # ]:          0 :         for (i = 0; i < GVE_NUM_PTYPES; i++) {
     932                 :          0 :                 ptype_lut->ptypes[i].l3_type =
     933                 :          0 :                         ptype_map->ptypes[i].l3_type;
     934                 :          0 :                 ptype_lut->ptypes[i].l4_type =
     935                 :          0 :                         ptype_map->ptypes[i].l4_type;
     936                 :            :         }
     937                 :          0 : err:
     938                 :          0 :         gve_free_dma_mem(&ptype_map_dma_mem);
     939                 :          0 :         return err;
     940                 :            : }

Generated by: LCOV version 1.14