| 1 | #include <drivers/nvme.h> |
| 2 | #include <log.h> |
| 3 | #include <math/div.h> |
| 4 | |
| 5 | #define NVME_CMD_TIMEOUT_MS 2000 // Normal command timeout |
| 6 | #define NVME_ADMIN_TIMEOUT_MS 5000 // Admin commands |
| 7 | #define NVME_RESET_TIMEOUT_MS 30000 // Controller reset or format NVM |
| 8 | #define THIS_QID(nvme) (1 + (smp_core_id() % (nvme->queue_count))) |
| 9 | |
| 10 | LOG_SITE_EXTERN(nvme); |
| 11 | LOG_HANDLE_EXTERN(nvme); |
| 12 | #define nvme_log(log_level, fmt, ...) \ |
| 13 | log(LOG_SITE(nvme), LOG_HANDLE(nvme), log_level, fmt, ##__VA_ARGS__) |
| 14 | |
| 15 | #define NVME_COMPLETION_PHASE(cpl) ((cpl)->status & 0x1) |
| 16 | #define NVME_COMPLETION_STATUS(cpl) (((cpl)->status >> 1) & 0x7FFF) |
| 17 | |
| 18 | #define NVME_DOORBELL_BASE 0x1000 |
| 19 | |
| 20 | #define NVME_OP_ADMIN_DELETE_IOSQ 0x0 |
| 21 | #define NVME_OP_ADMIN_CREATE_IOSQ 0x1 |
| 22 | |
| 23 | #define NVME_OP_ADMIN_GET_LOG_PG 0x2 |
| 24 | |
| 25 | #define NVME_OP_ADMIN_DELETE_IOCQ 0x4 |
| 26 | #define NVME_OP_ADMIN_CREATE_IOCQ 0x5 |
| 27 | |
| 28 | #define NVME_OP_ADMIN_IDENT 0x6 |
| 29 | #define NVME_OP_ADMIN_SET_FEATS 0x9 |
| 30 | #define NVME_OP_ADMIN_GET_FEATS 0x10 |
| 31 | |
| 32 | #define NVME_OP_IO_READ 0x02 |
| 33 | #define NVME_OP_IO_WRITE 0x01 |
| 34 | |
| 35 | #define NVME_STATUS_CONFLICTING_ATTRIBUTES 0x80 |
| 36 | #define NVME_STATUS_INVALID_PROT_INFO 0x81 |
| 37 | |
| 38 | bool nvme_read_sector_async(struct block_device *disk, |
| 39 | struct nvme_request *req); |
| 40 | |
| 41 | bool nvme_write_sector_async(struct block_device *disk, |
| 42 | struct nvme_request *req); |
| 43 | |
| 44 | static inline enum workqueue_error nvme_work_enqueue(struct nvme_device *dev, |
| 45 | struct work *work) { |
| 46 | return workqueue_enqueue(queue: dev->workqueue, work); |
| 47 | } |
| 48 | |