16733b39aSJayamohan Kallickal /** 2c4f39bdaSKetan Mukadam * Copyright (C) 2005 - 2015 Emulex 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: 114627de93SMinh Tran * linux-drivers@avagotech.com 126733b39aSJayamohan Kallickal * 13c4f39bdaSKetan Mukadam * Emulex 14255fa9a3SJayamohan Kallickal * 3333 Susan Street 15255fa9a3SJayamohan Kallickal * Costa Mesa, CA 92626 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> 23511cbce2SChristoph Hellwig #include <linux/irq_poll.h> 246733b39aSJayamohan Kallickal #define FW_VER_LEN 32 25bfead3b2SJayamohan Kallickal #define MCC_Q_LEN 128 26bfead3b2SJayamohan Kallickal #define MCC_CQ_LEN 256 27756d29c8SJayamohan Kallickal #define MAX_MCC_CMD 16 28f98c96b0SJayamohan Kallickal /* BladeEngine Generation numbers */ 29f98c96b0SJayamohan Kallickal #define BE_GEN2 2 30f98c96b0SJayamohan Kallickal #define BE_GEN3 3 31139a1b1eSJohn Soni Jose #define BE_GEN4 4 326733b39aSJayamohan Kallickal struct be_dma_mem { 336733b39aSJayamohan Kallickal void *va; 346733b39aSJayamohan Kallickal dma_addr_t dma; 356733b39aSJayamohan Kallickal u32 size; 366733b39aSJayamohan Kallickal }; 376733b39aSJayamohan Kallickal 386733b39aSJayamohan Kallickal struct be_queue_info { 396733b39aSJayamohan Kallickal struct be_dma_mem dma_mem; 406733b39aSJayamohan Kallickal u16 len; 416733b39aSJayamohan Kallickal u16 entry_size; /* Size of an element in the queue */ 426733b39aSJayamohan Kallickal u16 id; 436733b39aSJayamohan Kallickal u16 tail, head; 446733b39aSJayamohan Kallickal bool created; 45090e2184SJitendra Bhivare u16 used; /* Number of valid elements in the queue */ 466733b39aSJayamohan Kallickal }; 476733b39aSJayamohan Kallickal 486733b39aSJayamohan Kallickal static inline u32 MODULO(u16 val, u16 limit) 496733b39aSJayamohan Kallickal { 506733b39aSJayamohan Kallickal WARN_ON(limit & (limit - 1)); 516733b39aSJayamohan Kallickal return val & (limit - 1); 526733b39aSJayamohan Kallickal } 536733b39aSJayamohan Kallickal 546733b39aSJayamohan Kallickal static inline void index_inc(u16 *index, u16 limit) 556733b39aSJayamohan Kallickal { 566733b39aSJayamohan Kallickal *index = MODULO((*index + 1), limit); 576733b39aSJayamohan Kallickal } 586733b39aSJayamohan Kallickal 596733b39aSJayamohan Kallickal static inline void *queue_head_node(struct be_queue_info *q) 606733b39aSJayamohan Kallickal { 616733b39aSJayamohan Kallickal return q->dma_mem.va + q->head * q->entry_size; 626733b39aSJayamohan Kallickal } 636733b39aSJayamohan Kallickal 64756d29c8SJayamohan Kallickal static inline void *queue_get_wrb(struct be_queue_info *q, unsigned int wrb_num) 65756d29c8SJayamohan Kallickal { 66756d29c8SJayamohan Kallickal return q->dma_mem.va + wrb_num * q->entry_size; 67756d29c8SJayamohan Kallickal } 68756d29c8SJayamohan Kallickal 696733b39aSJayamohan Kallickal static inline void *queue_tail_node(struct be_queue_info *q) 706733b39aSJayamohan Kallickal { 716733b39aSJayamohan Kallickal return q->dma_mem.va + q->tail * q->entry_size; 726733b39aSJayamohan Kallickal } 736733b39aSJayamohan Kallickal 746733b39aSJayamohan Kallickal static inline void queue_head_inc(struct be_queue_info *q) 756733b39aSJayamohan Kallickal { 766733b39aSJayamohan Kallickal index_inc(&q->head, q->len); 776733b39aSJayamohan Kallickal } 786733b39aSJayamohan Kallickal 796733b39aSJayamohan Kallickal static inline void queue_tail_inc(struct be_queue_info *q) 806733b39aSJayamohan Kallickal { 816733b39aSJayamohan Kallickal index_inc(&q->tail, q->len); 826733b39aSJayamohan Kallickal } 836733b39aSJayamohan Kallickal 846733b39aSJayamohan Kallickal /*ISCSI */ 856733b39aSJayamohan Kallickal 8673af08e1SJayamohan Kallickal struct be_aic_obj { /* Adaptive interrupt coalescing (AIC) info */ 8773af08e1SJayamohan Kallickal bool enable; 8873af08e1SJayamohan Kallickal u32 min_eqd; /* in usecs */ 8973af08e1SJayamohan Kallickal u32 max_eqd; /* in usecs */ 9073af08e1SJayamohan Kallickal u32 prev_eqd; /* in usecs */ 9173af08e1SJayamohan Kallickal u32 et_eqd; /* configured val when aic is off */ 9273af08e1SJayamohan Kallickal ulong jiffs; 9373af08e1SJayamohan Kallickal u64 eq_prev; /* Used to calculate eqe */ 9473af08e1SJayamohan Kallickal }; 9573af08e1SJayamohan Kallickal 966733b39aSJayamohan Kallickal struct be_eq_obj { 9772fb46a9SJohn Soni Jose bool todo_mcc_cq; 9872fb46a9SJohn Soni Jose bool todo_cq; 9973af08e1SJayamohan Kallickal u32 cq_count; 1006733b39aSJayamohan Kallickal struct be_queue_info q; 101bfead3b2SJayamohan Kallickal struct beiscsi_hba *phba; 102bfead3b2SJayamohan Kallickal struct be_queue_info *cq; 103*a3095016SJitendra Bhivare struct work_struct mcc_work; /* Work Item */ 104511cbce2SChristoph Hellwig struct irq_poll iopoll; 1056733b39aSJayamohan Kallickal }; 1066733b39aSJayamohan Kallickal 1076733b39aSJayamohan Kallickal struct be_mcc_obj { 108bfead3b2SJayamohan Kallickal struct be_queue_info q; 109bfead3b2SJayamohan Kallickal struct be_queue_info cq; 1106733b39aSJayamohan Kallickal }; 1116733b39aSJayamohan Kallickal 1121957aa7fSJayamohan Kallickal struct beiscsi_mcc_tag_state { 113cdde6682SJitendra Bhivare unsigned long tag_state; 114cdde6682SJitendra Bhivare #define MCC_TAG_STATE_RUNNING 1 115cdde6682SJitendra Bhivare #define MCC_TAG_STATE_TIMEOUT 2 1161957aa7fSJayamohan Kallickal struct be_dma_mem tag_mem_state; 1171957aa7fSJayamohan Kallickal }; 1181957aa7fSJayamohan Kallickal 1196733b39aSJayamohan Kallickal struct be_ctrl_info { 1206733b39aSJayamohan Kallickal u8 __iomem *csr; 1216733b39aSJayamohan Kallickal u8 __iomem *db; /* Door Bell */ 1226733b39aSJayamohan Kallickal u8 __iomem *pcicfg; /* PCI config space */ 1236733b39aSJayamohan Kallickal struct pci_dev *pdev; 1246733b39aSJayamohan Kallickal 1256733b39aSJayamohan Kallickal /* Mbox used for cmd request/response */ 126c03a50f7SJitendra Bhivare struct mutex mbox_lock; /* For serializing mbox cmds to BE card */ 1276733b39aSJayamohan Kallickal struct be_dma_mem mbox_mem; 1286733b39aSJayamohan Kallickal /* Mbox mem is adjusted to align to 16 bytes. The allocated addr 1296733b39aSJayamohan Kallickal * is stored for freeing purpose */ 1306733b39aSJayamohan Kallickal struct be_dma_mem mbox_mem_alloced; 1316733b39aSJayamohan Kallickal 1326733b39aSJayamohan Kallickal /* MCC Rings */ 1336733b39aSJayamohan Kallickal struct be_mcc_obj mcc_obj; 1346733b39aSJayamohan Kallickal spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */ 1356733b39aSJayamohan Kallickal 136756d29c8SJayamohan Kallickal wait_queue_head_t mcc_wait[MAX_MCC_CMD + 1]; 137756d29c8SJayamohan Kallickal unsigned int mcc_tag[MAX_MCC_CMD]; 13867296ad9SJitendra Bhivare unsigned int mcc_tag_status[MAX_MCC_CMD + 1]; 139756d29c8SJayamohan Kallickal unsigned short mcc_alloc_index; 140756d29c8SJayamohan Kallickal unsigned short mcc_free_index; 141756d29c8SJayamohan Kallickal unsigned int mcc_tag_available; 1421957aa7fSJayamohan Kallickal 1431957aa7fSJayamohan Kallickal struct beiscsi_mcc_tag_state ptag_state[MAX_MCC_CMD + 1]; 1446733b39aSJayamohan Kallickal }; 1456733b39aSJayamohan Kallickal 1466733b39aSJayamohan Kallickal #include "be_cmds.h" 1476733b39aSJayamohan Kallickal 14867296ad9SJitendra Bhivare /* WRB index mask for MCC_Q_LEN queue entries */ 14967296ad9SJitendra Bhivare #define MCC_Q_WRB_IDX_MASK CQE_STATUS_WRB_MASK 15067296ad9SJitendra Bhivare #define MCC_Q_WRB_IDX_SHIFT CQE_STATUS_WRB_SHIFT 15167296ad9SJitendra Bhivare /* TAG is from 1...MAX_MCC_CMD, MASK includes MAX_MCC_CMD */ 15267296ad9SJitendra Bhivare #define MCC_Q_CMD_TAG_MASK ((MAX_MCC_CMD << 1) - 1) 15367296ad9SJitendra Bhivare 1546733b39aSJayamohan Kallickal #define PAGE_SHIFT_4K 12 1556733b39aSJayamohan Kallickal #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K) 15692665a66SJayamohan Kallickal #define mcc_timeout 120000 /* 12s timeout */ 1579343be74SJayamohan Kallickal #define BEISCSI_LOGOUT_SYNC_DELAY 250 1586733b39aSJayamohan Kallickal 1596733b39aSJayamohan Kallickal /* Returns number of pages spanned by the data starting at the given addr */ 1606733b39aSJayamohan Kallickal #define PAGES_4K_SPANNED(_address, size) \ 1616733b39aSJayamohan Kallickal ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \ 1626733b39aSJayamohan Kallickal (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K)) 1636733b39aSJayamohan Kallickal 1646733b39aSJayamohan Kallickal /* Returns bit offset within a DWORD of a bitfield */ 1656733b39aSJayamohan Kallickal #define AMAP_BIT_OFFSET(_struct, field) \ 1666733b39aSJayamohan Kallickal (((size_t)&(((_struct *)0)->field))%32) 1676733b39aSJayamohan Kallickal 1686733b39aSJayamohan Kallickal /* Returns the bit mask of the field that is NOT shifted into location. */ 1696733b39aSJayamohan Kallickal static inline u32 amap_mask(u32 bitsize) 1706733b39aSJayamohan Kallickal { 1716733b39aSJayamohan Kallickal return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1); 1726733b39aSJayamohan Kallickal } 1736733b39aSJayamohan Kallickal 1746733b39aSJayamohan Kallickal static inline void amap_set(void *ptr, u32 dw_offset, u32 mask, 1756733b39aSJayamohan Kallickal u32 offset, u32 value) 1766733b39aSJayamohan Kallickal { 1776733b39aSJayamohan Kallickal u32 *dw = (u32 *) ptr + dw_offset; 1786733b39aSJayamohan Kallickal *dw &= ~(mask << offset); 1796733b39aSJayamohan Kallickal *dw |= (mask & value) << offset; 1806733b39aSJayamohan Kallickal } 1816733b39aSJayamohan Kallickal 1826733b39aSJayamohan Kallickal #define AMAP_SET_BITS(_struct, field, ptr, val) \ 1836733b39aSJayamohan Kallickal amap_set(ptr, \ 1846733b39aSJayamohan Kallickal offsetof(_struct, field)/32, \ 1856733b39aSJayamohan Kallickal amap_mask(sizeof(((_struct *)0)->field)), \ 1866733b39aSJayamohan Kallickal AMAP_BIT_OFFSET(_struct, field), \ 1876733b39aSJayamohan Kallickal val) 1886733b39aSJayamohan Kallickal 1896733b39aSJayamohan Kallickal static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset) 1906733b39aSJayamohan Kallickal { 1916733b39aSJayamohan Kallickal u32 *dw = ptr; 1926733b39aSJayamohan Kallickal return mask & (*(dw + dw_offset) >> offset); 1936733b39aSJayamohan Kallickal } 1946733b39aSJayamohan Kallickal 1956733b39aSJayamohan Kallickal #define AMAP_GET_BITS(_struct, field, ptr) \ 1966733b39aSJayamohan Kallickal amap_get(ptr, \ 1976733b39aSJayamohan Kallickal offsetof(_struct, field)/32, \ 1986733b39aSJayamohan Kallickal amap_mask(sizeof(((_struct *)0)->field)), \ 1996733b39aSJayamohan Kallickal AMAP_BIT_OFFSET(_struct, field)) 2006733b39aSJayamohan Kallickal 2016733b39aSJayamohan Kallickal #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len) 2026733b39aSJayamohan Kallickal #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len) 2036733b39aSJayamohan Kallickal static inline void swap_dws(void *wrb, int len) 2046733b39aSJayamohan Kallickal { 2056733b39aSJayamohan Kallickal #ifdef __BIG_ENDIAN 2066733b39aSJayamohan Kallickal u32 *dw = wrb; 2076733b39aSJayamohan Kallickal WARN_ON(len % 4); 2086733b39aSJayamohan Kallickal do { 2096733b39aSJayamohan Kallickal *dw = cpu_to_le32(*dw); 2106733b39aSJayamohan Kallickal dw++; 2116733b39aSJayamohan Kallickal len -= 4; 2126733b39aSJayamohan Kallickal } while (len); 2136733b39aSJayamohan Kallickal #endif /* __BIG_ENDIAN */ 2146733b39aSJayamohan Kallickal } 2156733b39aSJayamohan Kallickal #endif /* BEISCSI_H */ 216