/*
* CXL Flash Device Driver
*
* Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
* Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
*
* Copyright (C) 2015 IBM Corporation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/syscalls.h>
#include <asm/unaligned.h>
#include <asm/bitsperlong.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_host.h>
#include <uapi/scsi/cxlflash_ioctl.h>
#include "sislite.h"
#include "common.h"
#include "vlun.h"
#include "superpipe.h"
/**
* marshal_virt_to_resize() - translate uvirtual to resize structure
* @virt: Source structure from which to translate/copy.
* @resize: Destination structure for the translate/copy.
*/
static void marshal_virt_to_resize(struct dk_cxlflash_uvirtual *virt,
struct dk_cxlflash_resize *resize)
{
resize->hdr = virt->hdr;
resize->context_id = virt->context_id;
resize->rsrc_handle = virt->rsrc_handle;
resize->req_size = virt->lun_size;
resize->last_lba = virt->last_lba;
}
/**
* marshal_clone_to_rele() - translate clone to release structure
* @clone: Source structure from which to translate/copy.
* @rele: Destination structure for the translate/copy.
*/
static void marshal_clone_to_rele(struct dk_cxlflash_clone *clone,
struct dk_cxlflash_release *release)
{
release->hdr = clone->hdr;
release->context_id = clone->context_id_dst;
}
/**
* ba_init() - initializes a block allocator
* @ba_lun: Block allocator to initialize.
*
* Return: 0 on success, -errno on failure
*/
static int ba_init(struct ba_lun *ba_lun)
{
struct ba_lun_info *bali = NULL;
int lun_size_au = 0, i = 0;
int last_word_underflow = 0;
u64 *lam;
pr_debug("%s: Initializing LUN: lun_id=%016llx "
"ba_lun->lsize=%lx ba_lun->au_size=%lX\n",
__func__, ba_lun->lun_id, ba_lun->lsize, ba_lun->au_size);
/* Calculate bit map size */
lun_size_au = ba_lun->lsize / ba_lun->au_size;
if (lun_size_au == 0) {
pr_debug("%s: Requested LUN size of 0!\n", __func__);
return -EINVAL;
}
/* Allocate lun information container */
bali = kzalloc(sizeof(struct