blob: 71fa1c4543662eb4cf1ea80a11c527889ab71d1b [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_DEVICES_BLOCK_DRIVERS_FTL_NAND_DRIVER_H_
#define SRC_DEVICES_BLOCK_DRIVERS_FTL_NAND_DRIVER_H_
#include <fuchsia/hardware/badblock/c/banjo.h>
#include <fuchsia/hardware/nand/c/banjo.h>
#include <inttypes.h>
#include <lib/ftl/ndm-driver.h>
#include <zircon/compiler.h>
#include <zircon/types.h>
#include <memory>
namespace ftl {
struct OperationCounters {
void Reset() { *this = OperationCounters(); }
constexpr unsigned int GetSum() const { return page_read + page_write + block_erase; }
unsigned int page_read = 0;
unsigned int page_write = 0;
unsigned int block_erase = 0;
};
// Implementation of the FTL library's driver interface in terms of a device implementing Fuchsia's
// NAND protocol.
class NandDriver : public ftl::NdmBaseDriver {
public:
static std::unique_ptr<NandDriver> Create(const nand_protocol_t* parent,
const bad_block_protocol_t* bad_block);
static std::unique_ptr<NandDriver> CreateWithCounters(const nand_protocol_t* parent,
const bad_block_protocol_t* bad_block,
OperationCounters* counters);
virtual const nand_info_t& info() const = 0;
// Cleans all non bad blocks in a given block range. Erase failures are logged amd deemed non
// fatal.
virtual void TryEraseRange(uint32_t start_block, uint32_t end_block) = 0;
protected:
NandDriver(FtlLogger logger) : NdmBaseDriver(logger) {}
};
} // namespace ftl.
#endif // SRC_DEVICES_BLOCK_DRIVERS_FTL_NAND_DRIVER_H_