// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
 /*
- * Copyright (C) 2012-2014, 2018-2023 Intel Corporation
+ * Copyright (C) 2012-2014, 2018-2024 Intel Corporation
  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
  * Copyright (C) 2016-2017 Intel Deutschland GmbH
  */
                              struct ieee80211_vif *vif,
                              struct iwl_mvm *mvm, u32 gtk_cipher)
 {
-       int i;
+       int i, j;
        struct ieee80211_key_conf *key;
        struct {
                struct ieee80211_key_conf conf;
                key = ieee80211_gtk_rekey_add(vif, &conf.conf);
                if (IS_ERR(key))
                        return false;
-               iwl_mvm_set_key_rx_seq_idx(key, status, i);
+
+               for (j = 0; j < ARRAY_SIZE(status->gtk_seq); j++) {
+                       if (!status->gtk_seq[j].valid ||
+                           status->gtk_seq[j].key_id != key->keyidx)
+                               continue;
+                       iwl_mvm_set_key_rx_seq_idx(key, status, j);
+                       break;
+               }
+               WARN_ON(j == ARRAY_SIZE(status->gtk_seq));
        }
 
        return true;