18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * linux/drivers/char/hpilo.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. 68c2ecf20Sopenharmony_ci * David Altobelli <david.altobelli@hp.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#ifndef __HPILO_H 98c2ecf20Sopenharmony_ci#define __HPILO_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define ILO_NAME "hpilo" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* max number of open channel control blocks per device, hw limited to 32 */ 148c2ecf20Sopenharmony_ci#define MAX_CCB 24 158c2ecf20Sopenharmony_ci/* min number of open channel control blocks per device, hw limited to 32 */ 168c2ecf20Sopenharmony_ci#define MIN_CCB 8 178c2ecf20Sopenharmony_ci/* max number of supported devices */ 188c2ecf20Sopenharmony_ci#define MAX_ILO_DEV 1 198c2ecf20Sopenharmony_ci/* max number of files */ 208c2ecf20Sopenharmony_ci#define MAX_OPEN (MAX_CCB * MAX_ILO_DEV) 218c2ecf20Sopenharmony_ci/* total wait time in usec */ 228c2ecf20Sopenharmony_ci#define MAX_WAIT_TIME 10000 238c2ecf20Sopenharmony_ci/* per spin wait time in usec */ 248c2ecf20Sopenharmony_ci#define WAIT_TIME 10 258c2ecf20Sopenharmony_ci/* spin counter for open/close delay */ 268c2ecf20Sopenharmony_ci#define MAX_WAIT (MAX_WAIT_TIME / WAIT_TIME) 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * Per device, used to track global memory allocations. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_cistruct ilo_hwinfo { 328c2ecf20Sopenharmony_ci /* mmio registers on device */ 338c2ecf20Sopenharmony_ci char __iomem *mmio_vaddr; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci /* doorbell registers on device */ 368c2ecf20Sopenharmony_ci char __iomem *db_vaddr; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci /* shared memory on device used for channel control blocks */ 398c2ecf20Sopenharmony_ci char __iomem *ram_vaddr; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci /* files corresponding to this device */ 428c2ecf20Sopenharmony_ci struct ccb_data *ccb_alloc[MAX_CCB]; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci struct pci_dev *ilo_dev; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci /* 478c2ecf20Sopenharmony_ci * open_lock serializes ccb_cnt during open and close 488c2ecf20Sopenharmony_ci * [ irq disabled ] 498c2ecf20Sopenharmony_ci * -> alloc_lock used when adding/removing/searching ccb_alloc, 508c2ecf20Sopenharmony_ci * which represents all ccbs open on the device 518c2ecf20Sopenharmony_ci * --> fifo_lock controls access to fifo queues shared with hw 528c2ecf20Sopenharmony_ci * 538c2ecf20Sopenharmony_ci * Locks must be taken in this order, but open_lock and alloc_lock 548c2ecf20Sopenharmony_ci * are optional, they do not need to be held in order to take a 558c2ecf20Sopenharmony_ci * lower level lock. 568c2ecf20Sopenharmony_ci */ 578c2ecf20Sopenharmony_ci spinlock_t open_lock; 588c2ecf20Sopenharmony_ci spinlock_t alloc_lock; 598c2ecf20Sopenharmony_ci spinlock_t fifo_lock; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci struct cdev cdev; 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* offset from mmio_vaddr for enabling doorbell interrupts */ 658c2ecf20Sopenharmony_ci#define DB_IRQ 0xB2 668c2ecf20Sopenharmony_ci/* offset from mmio_vaddr for outbound communications */ 678c2ecf20Sopenharmony_ci#define DB_OUT 0xD4 688c2ecf20Sopenharmony_ci/* DB_OUT reset bit */ 698c2ecf20Sopenharmony_ci#define DB_RESET 26 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/* 728c2ecf20Sopenharmony_ci * Channel control block. Used to manage hardware queues. 738c2ecf20Sopenharmony_ci * The format must match hw's version. The hw ccb is 128 bytes, 748c2ecf20Sopenharmony_ci * but the context area shouldn't be touched by the driver. 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_ci#define ILOSW_CCB_SZ 64 778c2ecf20Sopenharmony_ci#define ILOHW_CCB_SZ 128 788c2ecf20Sopenharmony_cistruct ccb { 798c2ecf20Sopenharmony_ci union { 808c2ecf20Sopenharmony_ci char *send_fifobar; 818c2ecf20Sopenharmony_ci u64 send_fifobar_pa; 828c2ecf20Sopenharmony_ci } ccb_u1; 838c2ecf20Sopenharmony_ci union { 848c2ecf20Sopenharmony_ci char *send_desc; 858c2ecf20Sopenharmony_ci u64 send_desc_pa; 868c2ecf20Sopenharmony_ci } ccb_u2; 878c2ecf20Sopenharmony_ci u64 send_ctrl; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci union { 908c2ecf20Sopenharmony_ci char *recv_fifobar; 918c2ecf20Sopenharmony_ci u64 recv_fifobar_pa; 928c2ecf20Sopenharmony_ci } ccb_u3; 938c2ecf20Sopenharmony_ci union { 948c2ecf20Sopenharmony_ci char *recv_desc; 958c2ecf20Sopenharmony_ci u64 recv_desc_pa; 968c2ecf20Sopenharmony_ci } ccb_u4; 978c2ecf20Sopenharmony_ci u64 recv_ctrl; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci union { 1008c2ecf20Sopenharmony_ci char __iomem *db_base; 1018c2ecf20Sopenharmony_ci u64 padding5; 1028c2ecf20Sopenharmony_ci } ccb_u5; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci u64 channel; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci /* unused context area (64 bytes) */ 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* ccb queue parameters */ 1108c2ecf20Sopenharmony_ci#define SENDQ 1 1118c2ecf20Sopenharmony_ci#define RECVQ 2 1128c2ecf20Sopenharmony_ci#define NR_QENTRY 4 1138c2ecf20Sopenharmony_ci#define L2_QENTRY_SZ 12 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* ccb ctrl bitfields */ 1168c2ecf20Sopenharmony_ci#define CTRL_BITPOS_L2SZ 0 1178c2ecf20Sopenharmony_ci#define CTRL_BITPOS_FIFOINDEXMASK 4 1188c2ecf20Sopenharmony_ci#define CTRL_BITPOS_DESCLIMIT 18 1198c2ecf20Sopenharmony_ci#define CTRL_BITPOS_A 30 1208c2ecf20Sopenharmony_ci#define CTRL_BITPOS_G 31 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* ccb doorbell macros */ 1238c2ecf20Sopenharmony_ci#define L2_DB_SIZE 14 1248c2ecf20Sopenharmony_ci#define ONE_DB_SIZE (1 << L2_DB_SIZE) 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci/* 1278c2ecf20Sopenharmony_ci * Per fd structure used to track the ccb allocated to that dev file. 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_cistruct ccb_data { 1308c2ecf20Sopenharmony_ci /* software version of ccb, using virtual addrs */ 1318c2ecf20Sopenharmony_ci struct ccb driver_ccb; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* hardware version of ccb, using physical addrs */ 1348c2ecf20Sopenharmony_ci struct ccb ilo_ccb; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci /* hardware ccb is written to this shared mapped device memory */ 1378c2ecf20Sopenharmony_ci struct ccb __iomem *mapped_ccb; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci /* dma'able memory used for send/recv queues */ 1408c2ecf20Sopenharmony_ci void *dma_va; 1418c2ecf20Sopenharmony_ci dma_addr_t dma_pa; 1428c2ecf20Sopenharmony_ci size_t dma_size; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci /* pointer to hardware device info */ 1458c2ecf20Sopenharmony_ci struct ilo_hwinfo *ilo_hw; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci /* queue for this ccb to wait for recv data */ 1488c2ecf20Sopenharmony_ci wait_queue_head_t ccb_waitq; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci /* usage count, to allow for shared ccb's */ 1518c2ecf20Sopenharmony_ci int ccb_cnt; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci /* open wanted exclusive access to this ccb */ 1548c2ecf20Sopenharmony_ci int ccb_excl; 1558c2ecf20Sopenharmony_ci}; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci/* 1588c2ecf20Sopenharmony_ci * FIFO queue structure, shared with hw. 1598c2ecf20Sopenharmony_ci */ 1608c2ecf20Sopenharmony_ci#define ILO_START_ALIGN 4096 1618c2ecf20Sopenharmony_ci#define ILO_CACHE_SZ 128 1628c2ecf20Sopenharmony_cistruct fifo { 1638c2ecf20Sopenharmony_ci u64 nrents; /* user requested number of fifo entries */ 1648c2ecf20Sopenharmony_ci u64 imask; /* mask to extract valid fifo index */ 1658c2ecf20Sopenharmony_ci u64 merge; /* O/C bits to merge in during enqueue operation */ 1668c2ecf20Sopenharmony_ci u64 reset; /* set to non-zero when the target device resets */ 1678c2ecf20Sopenharmony_ci u8 pad_0[ILO_CACHE_SZ - (sizeof(u64) * 4)]; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci u64 head; 1708c2ecf20Sopenharmony_ci u8 pad_1[ILO_CACHE_SZ - (sizeof(u64))]; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci u64 tail; 1738c2ecf20Sopenharmony_ci u8 pad_2[ILO_CACHE_SZ - (sizeof(u64))]; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci u64 fifobar[]; 1768c2ecf20Sopenharmony_ci}; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci/* convert between struct fifo, and the fifobar, which is saved in the ccb */ 1798c2ecf20Sopenharmony_ci#define FIFOHANDLESIZE (sizeof(struct fifo)) 1808c2ecf20Sopenharmony_ci#define FIFOBARTOHANDLE(_fifo) \ 1818c2ecf20Sopenharmony_ci ((struct fifo *)(((char *)(_fifo)) - FIFOHANDLESIZE)) 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci/* the number of qwords to consume from the entry descriptor */ 1848c2ecf20Sopenharmony_ci#define ENTRY_BITPOS_QWORDS 0 1858c2ecf20Sopenharmony_ci/* descriptor index number (within a specified queue) */ 1868c2ecf20Sopenharmony_ci#define ENTRY_BITPOS_DESCRIPTOR 10 1878c2ecf20Sopenharmony_ci/* state bit, fifo entry consumed by consumer */ 1888c2ecf20Sopenharmony_ci#define ENTRY_BITPOS_C 22 1898c2ecf20Sopenharmony_ci/* state bit, fifo entry is occupied */ 1908c2ecf20Sopenharmony_ci#define ENTRY_BITPOS_O 23 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci#define ENTRY_BITS_QWORDS 10 1938c2ecf20Sopenharmony_ci#define ENTRY_BITS_DESCRIPTOR 12 1948c2ecf20Sopenharmony_ci#define ENTRY_BITS_C 1 1958c2ecf20Sopenharmony_ci#define ENTRY_BITS_O 1 1968c2ecf20Sopenharmony_ci#define ENTRY_BITS_TOTAL \ 1978c2ecf20Sopenharmony_ci (ENTRY_BITS_C + ENTRY_BITS_O + \ 1988c2ecf20Sopenharmony_ci ENTRY_BITS_QWORDS + ENTRY_BITS_DESCRIPTOR) 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/* extract various entry fields */ 2018c2ecf20Sopenharmony_ci#define ENTRY_MASK ((1 << ENTRY_BITS_TOTAL) - 1) 2028c2ecf20Sopenharmony_ci#define ENTRY_MASK_C (((1 << ENTRY_BITS_C) - 1) << ENTRY_BITPOS_C) 2038c2ecf20Sopenharmony_ci#define ENTRY_MASK_O (((1 << ENTRY_BITS_O) - 1) << ENTRY_BITPOS_O) 2048c2ecf20Sopenharmony_ci#define ENTRY_MASK_QWORDS \ 2058c2ecf20Sopenharmony_ci (((1 << ENTRY_BITS_QWORDS) - 1) << ENTRY_BITPOS_QWORDS) 2068c2ecf20Sopenharmony_ci#define ENTRY_MASK_DESCRIPTOR \ 2078c2ecf20Sopenharmony_ci (((1 << ENTRY_BITS_DESCRIPTOR) - 1) << ENTRY_BITPOS_DESCRIPTOR) 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci#define ENTRY_MASK_NOSTATE (ENTRY_MASK >> (ENTRY_BITS_C + ENTRY_BITS_O)) 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci#endif /* __HPILO_H */ 212