/*1* linux/drivers/char/hpilo.h2*3* Copyright (C) 2008 Hewlett-Packard Development Company, L.P.4* David Altobelli <[email protected]>5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License version 2 as8* published by the Free Software Foundation.9*/10#ifndef __HPILO_H11#define __HPILO_H1213#define ILO_NAME "hpilo"1415/* max number of open channel control blocks per device, hw limited to 32 */16#define MAX_CCB 817/* max number of supported devices */18#define MAX_ILO_DEV 119/* max number of files */20#define MAX_OPEN (MAX_CCB * MAX_ILO_DEV)21/* total wait time in usec */22#define MAX_WAIT_TIME 1000023/* per spin wait time in usec */24#define WAIT_TIME 1025/* spin counter for open/close delay */26#define MAX_WAIT (MAX_WAIT_TIME / WAIT_TIME)2728/*29* Per device, used to track global memory allocations.30*/31struct ilo_hwinfo {32/* mmio registers on device */33char __iomem *mmio_vaddr;3435/* doorbell registers on device */36char __iomem *db_vaddr;3738/* shared memory on device used for channel control blocks */39char __iomem *ram_vaddr;4041/* files corresponding to this device */42struct ccb_data *ccb_alloc[MAX_CCB];4344struct pci_dev *ilo_dev;4546/*47* open_lock serializes ccb_cnt during open and close48* [ irq disabled ]49* -> alloc_lock used when adding/removing/searching ccb_alloc,50* which represents all ccbs open on the device51* --> fifo_lock controls access to fifo queues shared with hw52*53* Locks must be taken in this order, but open_lock and alloc_lock54* are optional, they do not need to be held in order to take a55* lower level lock.56*/57spinlock_t open_lock;58spinlock_t alloc_lock;59spinlock_t fifo_lock;6061struct cdev cdev;62};6364/* offset from mmio_vaddr for enabling doorbell interrupts */65#define DB_IRQ 0xB266/* offset from mmio_vaddr for outbound communications */67#define DB_OUT 0xD468/* DB_OUT reset bit */69#define DB_RESET 267071/*72* Channel control block. Used to manage hardware queues.73* The format must match hw's version. The hw ccb is 128 bytes,74* but the context area shouldn't be touched by the driver.75*/76#define ILOSW_CCB_SZ 6477#define ILOHW_CCB_SZ 12878struct ccb {79union {80char *send_fifobar;81u64 send_fifobar_pa;82} ccb_u1;83union {84char *send_desc;85u64 send_desc_pa;86} ccb_u2;87u64 send_ctrl;8889union {90char *recv_fifobar;91u64 recv_fifobar_pa;92} ccb_u3;93union {94char *recv_desc;95u64 recv_desc_pa;96} ccb_u4;97u64 recv_ctrl;9899union {100char __iomem *db_base;101u64 padding5;102} ccb_u5;103104u64 channel;105106/* unused context area (64 bytes) */107};108109/* ccb queue parameters */110#define SENDQ 1111#define RECVQ 2112#define NR_QENTRY 4113#define L2_QENTRY_SZ 12114115/* ccb ctrl bitfields */116#define CTRL_BITPOS_L2SZ 0117#define CTRL_BITPOS_FIFOINDEXMASK 4118#define CTRL_BITPOS_DESCLIMIT 18119#define CTRL_BITPOS_A 30120#define CTRL_BITPOS_G 31121122/* ccb doorbell macros */123#define L2_DB_SIZE 14124#define ONE_DB_SIZE (1 << L2_DB_SIZE)125126/*127* Per fd structure used to track the ccb allocated to that dev file.128*/129struct ccb_data {130/* software version of ccb, using virtual addrs */131struct ccb driver_ccb;132133/* hardware version of ccb, using physical addrs */134struct ccb ilo_ccb;135136/* hardware ccb is written to this shared mapped device memory */137struct ccb __iomem *mapped_ccb;138139/* dma'able memory used for send/recv queues */140void *dma_va;141dma_addr_t dma_pa;142size_t dma_size;143144/* pointer to hardware device info */145struct ilo_hwinfo *ilo_hw;146147/* queue for this ccb to wait for recv data */148wait_queue_head_t ccb_waitq;149150/* usage count, to allow for shared ccb's */151int ccb_cnt;152153/* open wanted exclusive access to this ccb */154int ccb_excl;155};156157/*158* FIFO queue structure, shared with hw.159*/160#define ILO_START_ALIGN 4096161#define ILO_CACHE_SZ 128162struct fifo {163u64 nrents; /* user requested number of fifo entries */164u64 imask; /* mask to extract valid fifo index */165u64 merge; /* O/C bits to merge in during enqueue operation */166u64 reset; /* set to non-zero when the target device resets */167u8 pad_0[ILO_CACHE_SZ - (sizeof(u64) * 4)];168169u64 head;170u8 pad_1[ILO_CACHE_SZ - (sizeof(u64))];171172u64 tail;173u8 pad_2[ILO_CACHE_SZ - (sizeof(u64))];174175u64 fifobar[1];176};177178/* convert between struct fifo, and the fifobar, which is saved in the ccb */179#define FIFOHANDLESIZE (sizeof(struct fifo) - sizeof(u64))180#define FIFOBARTOHANDLE(_fifo) \181((struct fifo *)(((char *)(_fifo)) - FIFOHANDLESIZE))182183/* the number of qwords to consume from the entry descriptor */184#define ENTRY_BITPOS_QWORDS 0185/* descriptor index number (within a specified queue) */186#define ENTRY_BITPOS_DESCRIPTOR 10187/* state bit, fifo entry consumed by consumer */188#define ENTRY_BITPOS_C 22189/* state bit, fifo entry is occupied */190#define ENTRY_BITPOS_O 23191192#define ENTRY_BITS_QWORDS 10193#define ENTRY_BITS_DESCRIPTOR 12194#define ENTRY_BITS_C 1195#define ENTRY_BITS_O 1196#define ENTRY_BITS_TOTAL \197(ENTRY_BITS_C + ENTRY_BITS_O + \198ENTRY_BITS_QWORDS + ENTRY_BITS_DESCRIPTOR)199200/* extract various entry fields */201#define ENTRY_MASK ((1 << ENTRY_BITS_TOTAL) - 1)202#define ENTRY_MASK_C (((1 << ENTRY_BITS_C) - 1) << ENTRY_BITPOS_C)203#define ENTRY_MASK_O (((1 << ENTRY_BITS_O) - 1) << ENTRY_BITPOS_O)204#define ENTRY_MASK_QWORDS \205(((1 << ENTRY_BITS_QWORDS) - 1) << ENTRY_BITPOS_QWORDS)206#define ENTRY_MASK_DESCRIPTOR \207(((1 << ENTRY_BITS_DESCRIPTOR) - 1) << ENTRY_BITPOS_DESCRIPTOR)208209#define ENTRY_MASK_NOSTATE (ENTRY_MASK >> (ENTRY_BITS_C + ENTRY_BITS_O))210211#endif /* __HPILO_H */212213214