Path: blob/master/drivers/infiniband/hw/amso1100/c2.h
15112 views
/*1* Copyright (c) 2005 Ammasso, Inc. All rights reserved.2* Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*/3233#ifndef __C2_H34#define __C2_H3536#include <linux/netdevice.h>37#include <linux/spinlock.h>38#include <linux/kernel.h>39#include <linux/pci.h>40#include <linux/dma-mapping.h>41#include <linux/idr.h>4243#include "c2_provider.h"44#include "c2_mq.h"45#include "c2_status.h"4647#define DRV_NAME "c2"48#define DRV_VERSION "1.1"49#define PFX DRV_NAME ": "5051#define BAR_0 052#define BAR_2 253#define BAR_4 45455#define RX_BUF_SIZE (1536 + 8)56#define ETH_JUMBO_MTU 900057#define C2_MAGIC "CEPHEUS"58#define C2_VERSION 459#define C2_IVN (18 & 0x7fffffff)6061#define C2_REG0_SIZE (16 * 1024)62#define C2_REG2_SIZE (2 * 1024 * 1024)63#define C2_REG4_SIZE (256 * 1024 * 1024)64#define C2_NUM_TX_DESC 34165#define C2_NUM_RX_DESC 25666#define C2_PCI_REGS_OFFSET (0x10000)67#define C2_RXP_HRXDQ_OFFSET (((C2_REG4_SIZE)/2))68#define C2_RXP_HRXDQ_SIZE (4096)69#define C2_TXP_HTXDQ_OFFSET (((C2_REG4_SIZE)/2) + C2_RXP_HRXDQ_SIZE)70#define C2_TXP_HTXDQ_SIZE (4096)71#define C2_TX_TIMEOUT (6*HZ)7273/* CEPHEUS */74static const u8 c2_magic[] = {750x43, 0x45, 0x50, 0x48, 0x45, 0x55, 0x5376};7778enum adapter_pci_regs {79C2_REGS_MAGIC = 0x0000,80C2_REGS_VERS = 0x0008,81C2_REGS_IVN = 0x000C,82C2_REGS_PCI_WINSIZE = 0x0010,83C2_REGS_Q0_QSIZE = 0x0014,84C2_REGS_Q0_MSGSIZE = 0x0018,85C2_REGS_Q0_POOLSTART = 0x001C,86C2_REGS_Q0_SHARED = 0x0020,87C2_REGS_Q1_QSIZE = 0x0024,88C2_REGS_Q1_MSGSIZE = 0x0028,89C2_REGS_Q1_SHARED = 0x0030,90C2_REGS_Q2_QSIZE = 0x0034,91C2_REGS_Q2_MSGSIZE = 0x0038,92C2_REGS_Q2_SHARED = 0x0040,93C2_REGS_ENADDR = 0x004C,94C2_REGS_RDMA_ENADDR = 0x0054,95C2_REGS_HRX_CUR = 0x006C,96};9798struct c2_adapter_pci_regs {99char reg_magic[8];100u32 version;101u32 ivn;102u32 pci_window_size;103u32 q0_q_size;104u32 q0_msg_size;105u32 q0_pool_start;106u32 q0_shared;107u32 q1_q_size;108u32 q1_msg_size;109u32 q1_pool_start;110u32 q1_shared;111u32 q2_q_size;112u32 q2_msg_size;113u32 q2_pool_start;114u32 q2_shared;115u32 log_start;116u32 log_size;117u8 host_enaddr[8];118u8 rdma_enaddr[8];119u32 crash_entry;120u32 crash_ready[2];121u32 fw_txd_cur;122u32 fw_hrxd_cur;123u32 fw_rxd_cur;124};125126enum pci_regs {127C2_HISR = 0x0000,128C2_DISR = 0x0004,129C2_HIMR = 0x0008,130C2_DIMR = 0x000C,131C2_NISR0 = 0x0010,132C2_NISR1 = 0x0014,133C2_NIMR0 = 0x0018,134C2_NIMR1 = 0x001C,135C2_IDIS = 0x0020,136};137138enum {139C2_PCI_HRX_INT = 1 << 8,140C2_PCI_HTX_INT = 1 << 17,141C2_PCI_HRX_QUI = 1 << 31,142};143144/*145* Cepheus registers in BAR0.146*/147struct c2_pci_regs {148u32 hostisr;149u32 dmaisr;150u32 hostimr;151u32 dmaimr;152u32 netisr0;153u32 netisr1;154u32 netimr0;155u32 netimr1;156u32 int_disable;157};158159/* TXP flags */160enum c2_txp_flags {161TXP_HTXD_DONE = 0,162TXP_HTXD_READY = 1 << 0,163TXP_HTXD_UNINIT = 1 << 1,164};165166/* RXP flags */167enum c2_rxp_flags {168RXP_HRXD_UNINIT = 0,169RXP_HRXD_READY = 1 << 0,170RXP_HRXD_DONE = 1 << 1,171};172173/* RXP status */174enum c2_rxp_status {175RXP_HRXD_ZERO = 0,176RXP_HRXD_OK = 1 << 0,177RXP_HRXD_BUF_OV = 1 << 1,178};179180/* TXP descriptor fields */181enum txp_desc {182C2_TXP_FLAGS = 0x0000,183C2_TXP_LEN = 0x0002,184C2_TXP_ADDR = 0x0004,185};186187/* RXP descriptor fields */188enum rxp_desc {189C2_RXP_FLAGS = 0x0000,190C2_RXP_STATUS = 0x0002,191C2_RXP_COUNT = 0x0004,192C2_RXP_LEN = 0x0006,193C2_RXP_ADDR = 0x0008,194};195196struct c2_txp_desc {197u16 flags;198u16 len;199u64 addr;200} __attribute__ ((packed));201202struct c2_rxp_desc {203u16 flags;204u16 status;205u16 count;206u16 len;207u64 addr;208} __attribute__ ((packed));209210struct c2_rxp_hdr {211u16 flags;212u16 status;213u16 len;214u16 rsvd;215} __attribute__ ((packed));216217struct c2_tx_desc {218u32 len;219u32 status;220dma_addr_t next_offset;221};222223struct c2_rx_desc {224u32 len;225u32 status;226dma_addr_t next_offset;227};228229struct c2_alloc {230u32 last;231u32 max;232spinlock_t lock;233unsigned long *table;234};235236struct c2_array {237struct {238void **page;239int used;240} *page_list;241};242243/*244* The MQ shared pointer pool is organized as a linked list of245* chunks. Each chunk contains a linked list of free shared pointers246* that can be allocated to a given user mode client.247*248*/249struct sp_chunk {250struct sp_chunk *next;251dma_addr_t dma_addr;252DEFINE_DMA_UNMAP_ADDR(mapping);253u16 head;254u16 shared_ptr[0];255};256257struct c2_pd_table {258u32 last;259u32 max;260spinlock_t lock;261unsigned long *table;262};263264struct c2_qp_table {265struct idr idr;266spinlock_t lock;267int last;268};269270struct c2_element {271struct c2_element *next;272void *ht_desc; /* host descriptor */273void __iomem *hw_desc; /* hardware descriptor */274struct sk_buff *skb;275dma_addr_t mapaddr;276u32 maplen;277};278279struct c2_ring {280struct c2_element *to_clean;281struct c2_element *to_use;282struct c2_element *start;283unsigned long count;284};285286struct c2_dev {287struct ib_device ibdev;288void __iomem *regs;289void __iomem *mmio_txp_ring; /* remapped adapter memory for hw rings */290void __iomem *mmio_rxp_ring;291spinlock_t lock;292struct pci_dev *pcidev;293struct net_device *netdev;294struct net_device *pseudo_netdev;295unsigned int cur_tx;296unsigned int cur_rx;297u32 adapter_handle;298int device_cap_flags;299void __iomem *kva; /* KVA device memory */300unsigned long pa; /* PA device memory */301void **qptr_array;302303struct kmem_cache *host_msg_cache;304305struct list_head cca_link; /* adapter list */306struct list_head eh_wakeup_list; /* event wakeup list */307wait_queue_head_t req_vq_wo;308309/* Cached RNIC properties */310struct ib_device_attr props;311312struct c2_pd_table pd_table;313struct c2_qp_table qp_table;314int ports; /* num of GigE ports */315int devnum;316spinlock_t vqlock; /* sync vbs req MQ */317318/* Verbs Queues */319struct c2_mq req_vq; /* Verbs Request MQ */320struct c2_mq rep_vq; /* Verbs Reply MQ */321struct c2_mq aeq; /* Async Events MQ */322323/* Kernel client MQs */324struct sp_chunk *kern_mqsp_pool;325326/* Device updates these values when posting messages to a host327* target queue */328u16 req_vq_shared;329u16 rep_vq_shared;330u16 aeq_shared;331u16 irq_claimed;332333/*334* Shared host target pages for user-accessible MQs.335*/336int hthead; /* index of first free entry */337void *htpages; /* kernel vaddr */338int htlen; /* length of htpages memory */339void *htuva; /* user mapped vaddr */340spinlock_t htlock; /* serialize allocation */341342u64 adapter_hint_uva; /* access to the activity FIFO */343344// spinlock_t aeq_lock;345// spinlock_t rnic_lock;346347__be16 *hint_count;348dma_addr_t hint_count_dma;349u16 hints_read;350351int init; /* TRUE if it's ready */352char ae_cache_name[16];353char vq_cache_name[16];354};355356struct c2_port {357u32 msg_enable;358struct c2_dev *c2dev;359struct net_device *netdev;360361spinlock_t tx_lock;362u32 tx_avail;363struct c2_ring tx_ring;364struct c2_ring rx_ring;365366void *mem; /* PCI memory for host rings */367dma_addr_t dma;368unsigned long mem_size;369370u32 rx_buf_size;371};372373/*374* Activity FIFO registers in BAR0.375*/376#define PCI_BAR0_HOST_HINT 0x100377#define PCI_BAR0_ADAPTER_HINT 0x2000378379/*380* Ammasso PCI vendor id and Cepheus PCI device id.381*/382#define CQ_ARMED 0x01383#define CQ_WAIT_FOR_DMA 0x80384385/*386* The format of a hint is as follows:387* Lower 16 bits are the count of hints for the queue.388* Next 15 bits are the qp_index389* Upper most bit depends on who reads it:390* If read by producer, then it means Full (1) or Not-Full (0)391* If read by consumer, then it means Empty (1) or Not-Empty (0)392*/393#define C2_HINT_MAKE(q_index, hint_count) (((q_index) << 16) | hint_count)394#define C2_HINT_GET_INDEX(hint) (((hint) & 0x7FFF0000) >> 16)395#define C2_HINT_GET_COUNT(hint) ((hint) & 0x0000FFFF)396397398/*399* The following defines the offset in SDRAM for the c2_adapter_pci_regs_t400* struct.401*/402#define C2_ADAPTER_PCI_REGS_OFFSET 0x10000403404#ifndef readq405static inline u64 readq(const void __iomem * addr)406{407u64 ret = readl(addr + 4);408ret <<= 32;409ret |= readl(addr);410411return ret;412}413#endif414415#ifndef writeq416static inline void __raw_writeq(u64 val, void __iomem * addr)417{418__raw_writel((u32) (val), addr);419__raw_writel((u32) (val >> 32), (addr + 4));420}421#endif422423#define C2_SET_CUR_RX(c2dev, cur_rx) \424__raw_writel((__force u32) cpu_to_be32(cur_rx), c2dev->mmio_txp_ring + 4092)425426#define C2_GET_CUR_RX(c2dev) \427be32_to_cpu((__force __be32) readl(c2dev->mmio_txp_ring + 4092))428429static inline struct c2_dev *to_c2dev(struct ib_device *ibdev)430{431return container_of(ibdev, struct c2_dev, ibdev);432}433434static inline int c2_errno(void *reply)435{436switch (c2_wr_get_result(reply)) {437case C2_OK:438return 0;439case CCERR_NO_BUFS:440case CCERR_INSUFFICIENT_RESOURCES:441case CCERR_ZERO_RDMA_READ_RESOURCES:442return -ENOMEM;443case CCERR_MR_IN_USE:444case CCERR_QP_IN_USE:445return -EBUSY;446case CCERR_ADDR_IN_USE:447return -EADDRINUSE;448case CCERR_ADDR_NOT_AVAIL:449return -EADDRNOTAVAIL;450case CCERR_CONN_RESET:451return -ECONNRESET;452case CCERR_NOT_IMPLEMENTED:453case CCERR_INVALID_WQE:454return -ENOSYS;455case CCERR_QP_NOT_PRIVILEGED:456return -EPERM;457case CCERR_STACK_ERROR:458return -EPROTO;459case CCERR_ACCESS_VIOLATION:460case CCERR_BASE_AND_BOUNDS_VIOLATION:461return -EFAULT;462case CCERR_STAG_STATE_NOT_INVALID:463case CCERR_INVALID_ADDRESS:464case CCERR_INVALID_CQ:465case CCERR_INVALID_EP:466case CCERR_INVALID_MODIFIER:467case CCERR_INVALID_MTU:468case CCERR_INVALID_PD_ID:469case CCERR_INVALID_QP:470case CCERR_INVALID_RNIC:471case CCERR_INVALID_STAG:472return -EINVAL;473default:474return -EAGAIN;475}476}477478/* Device */479extern int c2_register_device(struct c2_dev *c2dev);480extern void c2_unregister_device(struct c2_dev *c2dev);481extern int c2_rnic_init(struct c2_dev *c2dev);482extern void c2_rnic_term(struct c2_dev *c2dev);483extern void c2_rnic_interrupt(struct c2_dev *c2dev);484extern int c2_del_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask);485extern int c2_add_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask);486487/* QPs */488extern int c2_alloc_qp(struct c2_dev *c2dev, struct c2_pd *pd,489struct ib_qp_init_attr *qp_attrs, struct c2_qp *qp);490extern void c2_free_qp(struct c2_dev *c2dev, struct c2_qp *qp);491extern struct ib_qp *c2_get_qp(struct ib_device *device, int qpn);492extern int c2_qp_modify(struct c2_dev *c2dev, struct c2_qp *qp,493struct ib_qp_attr *attr, int attr_mask);494extern int c2_qp_set_read_limits(struct c2_dev *c2dev, struct c2_qp *qp,495int ord, int ird);496extern int c2_post_send(struct ib_qp *ibqp, struct ib_send_wr *ib_wr,497struct ib_send_wr **bad_wr);498extern int c2_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *ib_wr,499struct ib_recv_wr **bad_wr);500extern void __devinit c2_init_qp_table(struct c2_dev *c2dev);501extern void __devexit c2_cleanup_qp_table(struct c2_dev *c2dev);502extern void c2_set_qp_state(struct c2_qp *, int);503extern struct c2_qp *c2_find_qpn(struct c2_dev *c2dev, int qpn);504505/* PDs */506extern int c2_pd_alloc(struct c2_dev *c2dev, int privileged, struct c2_pd *pd);507extern void c2_pd_free(struct c2_dev *c2dev, struct c2_pd *pd);508extern int __devinit c2_init_pd_table(struct c2_dev *c2dev);509extern void __devexit c2_cleanup_pd_table(struct c2_dev *c2dev);510511/* CQs */512extern int c2_init_cq(struct c2_dev *c2dev, int entries,513struct c2_ucontext *ctx, struct c2_cq *cq);514extern void c2_free_cq(struct c2_dev *c2dev, struct c2_cq *cq);515extern void c2_cq_event(struct c2_dev *c2dev, u32 mq_index);516extern void c2_cq_clean(struct c2_dev *c2dev, struct c2_qp *qp, u32 mq_index);517extern int c2_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);518extern int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);519520/* CM */521extern int c2_llp_connect(struct iw_cm_id *cm_id,522struct iw_cm_conn_param *iw_param);523extern int c2_llp_accept(struct iw_cm_id *cm_id,524struct iw_cm_conn_param *iw_param);525extern int c2_llp_reject(struct iw_cm_id *cm_id, const void *pdata,526u8 pdata_len);527extern int c2_llp_service_create(struct iw_cm_id *cm_id, int backlog);528extern int c2_llp_service_destroy(struct iw_cm_id *cm_id);529530/* MM */531extern int c2_nsmr_register_phys_kern(struct c2_dev *c2dev, u64 *addr_list,532int page_size, int pbl_depth, u32 length,533u32 off, u64 *va, enum c2_acf acf,534struct c2_mr *mr);535extern int c2_stag_dealloc(struct c2_dev *c2dev, u32 stag_index);536537/* AE */538extern void c2_ae_event(struct c2_dev *c2dev, u32 mq_index);539540/* MQSP Allocator */541extern int c2_init_mqsp_pool(struct c2_dev *c2dev, gfp_t gfp_mask,542struct sp_chunk **root);543extern void c2_free_mqsp_pool(struct c2_dev *c2dev, struct sp_chunk *root);544extern __be16 *c2_alloc_mqsp(struct c2_dev *c2dev, struct sp_chunk *head,545dma_addr_t *dma_addr, gfp_t gfp_mask);546extern void c2_free_mqsp(__be16* mqsp);547#endif548549550