return 0;
 }
 
+static void bnxt_free_one_ctx_mem(struct bnxt *bp,
+                                 struct bnxt_ctx_mem_type *ctxm, bool force);
+
 #define BNXT_CTX_INIT_VALID(flags)     \
        (!!((flags) &                   \
            FUNC_BACKING_STORE_QCAPS_V2_RESP_FLAGS_ENABLE_CTX_KIND_INIT))
        for (type = 0; type < BNXT_CTX_V2_MAX; ) {
                struct bnxt_ctx_mem_type *ctxm = &ctx->ctx_arr[type];
                u8 init_val, init_off, i;
+               u32 max_entries;
+               u16 entry_size;
                __le32 *p;
                u32 flags;
 
                        goto ctx_done;
                flags = le32_to_cpu(resp->flags);
                type = le16_to_cpu(resp->next_valid_type);
-               if (!(flags & FUNC_BACKING_STORE_QCAPS_V2_RESP_FLAGS_TYPE_VALID))
+               if (!(flags & BNXT_CTX_MEM_TYPE_VALID)) {
+                       bnxt_free_one_ctx_mem(bp, ctxm, true);
                        continue;
-
+               }
+               entry_size = le16_to_cpu(resp->entry_size);
+               max_entries = le32_to_cpu(resp->max_num_entries);
+               if (ctxm->mem_valid) {
+                       if (!(flags & BNXT_CTX_MEM_PERSIST) ||
+                           ctxm->entry_size != entry_size ||
+                           ctxm->max_entries != max_entries)
+                               bnxt_free_one_ctx_mem(bp, ctxm, true);
+                       else
+                               continue;
+               }
                ctxm->type = le16_to_cpu(resp->type);
-               ctxm->entry_size = le16_to_cpu(resp->entry_size);
+               ctxm->entry_size = entry_size;
                ctxm->flags = flags;
                ctxm->instance_bmap = le32_to_cpu(resp->instance_bit_map);
                ctxm->entry_multiple = resp->entry_multiple;
-               ctxm->max_entries = le32_to_cpu(resp->max_num_entries);
+               ctxm->max_entries = max_entries;
                ctxm->min_entries = le32_to_cpu(resp->min_num_entries);
                init_val = resp->ctx_init_value;
                init_off = resp->ctx_init_offset;
        hwrm_req_hold(bp, req);
        req->type = cpu_to_le16(ctxm->type);
        req->entry_size = cpu_to_le16(ctxm->entry_size);
+       if ((ctxm->flags & BNXT_CTX_MEM_PERSIST) &&
+           bnxt_bs_trace_avail(bp, ctxm->type)) {
+               struct bnxt_bs_trace_info *bs_trace;
+               u32 enables;
+
+               enables = FUNC_BACKING_STORE_CFG_V2_REQ_ENABLES_NEXT_BS_OFFSET;
+               req->enables = cpu_to_le32(enables);
+               bs_trace = &bp->bs_trace[bnxt_bstore_to_trace[ctxm->type]];
+               req->next_bs_offset = cpu_to_le32(bs_trace->last_offset);
+       }
        req->subtype_valid_cnt = ctxm->split_entry_cnt;
        for (i = 0, p = &req->split_entry_0; i < ctxm->split_entry_cnt; i++)
                p[i] = cpu_to_le32(ctxm->split[i]);
                ctxm->pg_info = NULL;
                ctxm->mem_valid = 0;
        }
+       memset(ctxm, 0, sizeof(*ctxm));
 }
 
 void bnxt_free_ctx_mem(struct bnxt *bp, bool force)
                        set_bit(BNXT_STATE_FW_RESET_DET, &bp->state);
                        if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
                                bnxt_ulp_irq_stop(bp);
-                       bnxt_free_ctx_mem(bp, true);
+                       bnxt_free_ctx_mem(bp, false);
                        bnxt_dcb_free(bp);
                        rc = bnxt_fw_init_one(bp);
                        if (rc) {
        bnxt_hwrm_func_drv_unrgtr(bp);
        if (pci_is_enabled(bp->pdev))
                pci_disable_device(bp->pdev);
-       bnxt_free_ctx_mem(bp, true);
+       bnxt_free_ctx_mem(bp, false);
 }
 
 static bool is_bnxt_fw_ok(struct bnxt *bp)
        }
        bnxt_hwrm_func_drv_unrgtr(bp);
        pci_disable_device(bp->pdev);
-       bnxt_free_ctx_mem(bp, true);
+       bnxt_free_ctx_mem(bp, false);
        rtnl_unlock();
        return rc;
 }
 
        if (pci_is_enabled(pdev))
                pci_disable_device(pdev);
-       bnxt_free_ctx_mem(bp, true);
+       bnxt_free_ctx_mem(bp, false);
        rtnl_unlock();
 
        /* Request a slot slot reset. */