16733b39aSJayamohan Kallickal /** 26733b39aSJayamohan Kallickal * Copyright (C) 2005 - 2009 ServerEngines 36733b39aSJayamohan Kallickal * All rights reserved. 46733b39aSJayamohan Kallickal * 56733b39aSJayamohan Kallickal * This program is free software; you can redistribute it and/or 66733b39aSJayamohan Kallickal * modify it under the terms of the GNU General Public License version 2 76733b39aSJayamohan Kallickal * as published by the Free Software Foundation. The full GNU General 86733b39aSJayamohan Kallickal * Public License is included in this distribution in the file called COPYING. 96733b39aSJayamohan Kallickal * 106733b39aSJayamohan Kallickal * Contact Information: 116733b39aSJayamohan Kallickal * linux-drivers@serverengines.com 126733b39aSJayamohan Kallickal * 136733b39aSJayamohan Kallickal * ServerEngines 146733b39aSJayamohan Kallickal * 209 N. Fair Oaks Ave 156733b39aSJayamohan Kallickal * Sunnyvale, CA 94085 166733b39aSJayamohan Kallickal */ 176733b39aSJayamohan Kallickal 186733b39aSJayamohan Kallickal #ifndef BEISCSI_H 196733b39aSJayamohan Kallickal #define BEISCSI_H 206733b39aSJayamohan Kallickal 216733b39aSJayamohan Kallickal #include <linux/pci.h> 226733b39aSJayamohan Kallickal #include <linux/if_vlan.h> 23*bfead3b2SJayamohan Kallickal #include <linux/blk-iopoll.h> 246733b39aSJayamohan Kallickal #define FW_VER_LEN 32 25*bfead3b2SJayamohan Kallickal #define MCC_Q_LEN 128 26*bfead3b2SJayamohan Kallickal #define MCC_CQ_LEN 256 276733b39aSJayamohan Kallickal 286733b39aSJayamohan Kallickal struct be_dma_mem { 296733b39aSJayamohan Kallickal void *va; 306733b39aSJayamohan Kallickal dma_addr_t dma; 316733b39aSJayamohan Kallickal u32 size; 326733b39aSJayamohan Kallickal }; 336733b39aSJayamohan Kallickal 346733b39aSJayamohan Kallickal struct be_queue_info { 356733b39aSJayamohan Kallickal struct be_dma_mem dma_mem; 366733b39aSJayamohan Kallickal u16 len; 376733b39aSJayamohan Kallickal u16 entry_size; /* Size of an element in the queue */ 386733b39aSJayamohan Kallickal u16 id; 396733b39aSJayamohan Kallickal u16 tail, head; 406733b39aSJayamohan Kallickal bool created; 416733b39aSJayamohan Kallickal atomic_t used; /* Number of valid elements in the queue */ 426733b39aSJayamohan Kallickal }; 436733b39aSJayamohan Kallickal 446733b39aSJayamohan Kallickal static inline u32 MODULO(u16 val, u16 limit) 456733b39aSJayamohan Kallickal { 466733b39aSJayamohan Kallickal WARN_ON(limit & (limit - 1)); 476733b39aSJayamohan Kallickal return val & (limit - 1); 486733b39aSJayamohan Kallickal } 496733b39aSJayamohan Kallickal 506733b39aSJayamohan Kallickal static inline void index_inc(u16 *index, u16 limit) 516733b39aSJayamohan Kallickal { 526733b39aSJayamohan Kallickal *index = MODULO((*index + 1), limit); 536733b39aSJayamohan Kallickal } 546733b39aSJayamohan Kallickal 556733b39aSJayamohan Kallickal static inline void *queue_head_node(struct be_queue_info *q) 566733b39aSJayamohan Kallickal { 576733b39aSJayamohan Kallickal return q->dma_mem.va + q->head * q->entry_size; 586733b39aSJayamohan Kallickal } 596733b39aSJayamohan Kallickal 606733b39aSJayamohan Kallickal static inline void *queue_tail_node(struct be_queue_info *q) 616733b39aSJayamohan Kallickal { 626733b39aSJayamohan Kallickal return q->dma_mem.va + q->tail * q->entry_size; 636733b39aSJayamohan Kallickal } 646733b39aSJayamohan Kallickal 656733b39aSJayamohan Kallickal static inline void queue_head_inc(struct be_queue_info *q) 666733b39aSJayamohan Kallickal { 676733b39aSJayamohan Kallickal index_inc(&q->head, q->len); 686733b39aSJayamohan Kallickal } 696733b39aSJayamohan Kallickal 706733b39aSJayamohan Kallickal static inline void queue_tail_inc(struct be_queue_info *q) 716733b39aSJayamohan Kallickal { 726733b39aSJayamohan Kallickal index_inc(&q->tail, q->len); 736733b39aSJayamohan Kallickal } 746733b39aSJayamohan Kallickal 756733b39aSJayamohan Kallickal /*ISCSI */ 766733b39aSJayamohan Kallickal 776733b39aSJayamohan Kallickal struct be_eq_obj { 786733b39aSJayamohan Kallickal struct be_queue_info q; 79*bfead3b2SJayamohan Kallickal struct beiscsi_hba *phba; 80*bfead3b2SJayamohan Kallickal struct be_queue_info *cq; 81*bfead3b2SJayamohan Kallickal struct blk_iopoll iopoll; 826733b39aSJayamohan Kallickal }; 836733b39aSJayamohan Kallickal 846733b39aSJayamohan Kallickal struct be_mcc_obj { 85*bfead3b2SJayamohan Kallickal struct be_queue_info q; 86*bfead3b2SJayamohan Kallickal struct be_queue_info cq; 876733b39aSJayamohan Kallickal }; 886733b39aSJayamohan Kallickal 896733b39aSJayamohan Kallickal struct be_ctrl_info { 906733b39aSJayamohan Kallickal u8 __iomem *csr; 916733b39aSJayamohan Kallickal u8 __iomem *db; /* Door Bell */ 926733b39aSJayamohan Kallickal u8 __iomem *pcicfg; /* PCI config space */ 936733b39aSJayamohan Kallickal struct pci_dev *pdev; 946733b39aSJayamohan Kallickal 956733b39aSJayamohan Kallickal /* Mbox used for cmd request/response */ 966733b39aSJayamohan Kallickal spinlock_t mbox_lock; /* For serializing mbox cmds to BE card */ 976733b39aSJayamohan Kallickal struct be_dma_mem mbox_mem; 986733b39aSJayamohan Kallickal /* Mbox mem is adjusted to align to 16 bytes. The allocated addr 996733b39aSJayamohan Kallickal * is stored for freeing purpose */ 1006733b39aSJayamohan Kallickal struct be_dma_mem mbox_mem_alloced; 1016733b39aSJayamohan Kallickal 1026733b39aSJayamohan Kallickal /* MCC Rings */ 1036733b39aSJayamohan Kallickal struct be_mcc_obj mcc_obj; 1046733b39aSJayamohan Kallickal spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */ 1056733b39aSJayamohan Kallickal spinlock_t mcc_cq_lock; 1066733b39aSJayamohan Kallickal 1076733b39aSJayamohan Kallickal /* MCC Async callback */ 1086733b39aSJayamohan Kallickal void (*async_cb) (void *adapter, bool link_up); 1096733b39aSJayamohan Kallickal void *adapter_ctxt; 1106733b39aSJayamohan Kallickal }; 1116733b39aSJayamohan Kallickal 1126733b39aSJayamohan Kallickal #include "be_cmds.h" 1136733b39aSJayamohan Kallickal 1146733b39aSJayamohan Kallickal #define PAGE_SHIFT_4K 12 1156733b39aSJayamohan Kallickal #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K) 1166733b39aSJayamohan Kallickal 1176733b39aSJayamohan Kallickal /* Returns number of pages spanned by the data starting at the given addr */ 1186733b39aSJayamohan Kallickal #define PAGES_4K_SPANNED(_address, size) \ 1196733b39aSJayamohan Kallickal ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \ 1206733b39aSJayamohan Kallickal (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K)) 1216733b39aSJayamohan Kallickal 1226733b39aSJayamohan Kallickal /* Byte offset into the page corresponding to given address */ 1236733b39aSJayamohan Kallickal #define OFFSET_IN_PAGE(addr) \ 1246733b39aSJayamohan Kallickal ((size_t)(addr) & (PAGE_SIZE_4K-1)) 1256733b39aSJayamohan Kallickal 1266733b39aSJayamohan Kallickal /* Returns bit offset within a DWORD of a bitfield */ 1276733b39aSJayamohan Kallickal #define AMAP_BIT_OFFSET(_struct, field) \ 1286733b39aSJayamohan Kallickal (((size_t)&(((_struct *)0)->field))%32) 1296733b39aSJayamohan Kallickal 1306733b39aSJayamohan Kallickal /* Returns the bit mask of the field that is NOT shifted into location. */ 1316733b39aSJayamohan Kallickal static inline u32 amap_mask(u32 bitsize) 1326733b39aSJayamohan Kallickal { 1336733b39aSJayamohan Kallickal return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1); 1346733b39aSJayamohan Kallickal } 1356733b39aSJayamohan Kallickal 1366733b39aSJayamohan Kallickal static inline void amap_set(void *ptr, u32 dw_offset, u32 mask, 1376733b39aSJayamohan Kallickal u32 offset, u32 value) 1386733b39aSJayamohan Kallickal { 1396733b39aSJayamohan Kallickal u32 *dw = (u32 *) ptr + dw_offset; 1406733b39aSJayamohan Kallickal *dw &= ~(mask << offset); 1416733b39aSJayamohan Kallickal *dw |= (mask & value) << offset; 1426733b39aSJayamohan Kallickal } 1436733b39aSJayamohan Kallickal 1446733b39aSJayamohan Kallickal #define AMAP_SET_BITS(_struct, field, ptr, val) \ 1456733b39aSJayamohan Kallickal amap_set(ptr, \ 1466733b39aSJayamohan Kallickal offsetof(_struct, field)/32, \ 1476733b39aSJayamohan Kallickal amap_mask(sizeof(((_struct *)0)->field)), \ 1486733b39aSJayamohan Kallickal AMAP_BIT_OFFSET(_struct, field), \ 1496733b39aSJayamohan Kallickal val) 1506733b39aSJayamohan Kallickal 1516733b39aSJayamohan Kallickal static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset) 1526733b39aSJayamohan Kallickal { 1536733b39aSJayamohan Kallickal u32 *dw = ptr; 1546733b39aSJayamohan Kallickal return mask & (*(dw + dw_offset) >> offset); 1556733b39aSJayamohan Kallickal } 1566733b39aSJayamohan Kallickal 1576733b39aSJayamohan Kallickal #define AMAP_GET_BITS(_struct, field, ptr) \ 1586733b39aSJayamohan Kallickal amap_get(ptr, \ 1596733b39aSJayamohan Kallickal offsetof(_struct, field)/32, \ 1606733b39aSJayamohan Kallickal amap_mask(sizeof(((_struct *)0)->field)), \ 1616733b39aSJayamohan Kallickal AMAP_BIT_OFFSET(_struct, field)) 1626733b39aSJayamohan Kallickal 1636733b39aSJayamohan Kallickal #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len) 1646733b39aSJayamohan Kallickal #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len) 1656733b39aSJayamohan Kallickal static inline void swap_dws(void *wrb, int len) 1666733b39aSJayamohan Kallickal { 1676733b39aSJayamohan Kallickal #ifdef __BIG_ENDIAN 1686733b39aSJayamohan Kallickal u32 *dw = wrb; 1696733b39aSJayamohan Kallickal WARN_ON(len % 4); 1706733b39aSJayamohan Kallickal do { 1716733b39aSJayamohan Kallickal *dw = cpu_to_le32(*dw); 1726733b39aSJayamohan Kallickal dw++; 1736733b39aSJayamohan Kallickal len -= 4; 1746733b39aSJayamohan Kallickal } while (len); 1756733b39aSJayamohan Kallickal #endif /* __BIG_ENDIAN */ 1766733b39aSJayamohan Kallickal } 1776733b39aSJayamohan Kallickal #endif /* BEISCSI_H */ 178