cnic.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /* cnic.h: QLogic CNIC core network driver.
  2. *
  3. * Copyright (c) 2006-2014 Broadcom Corporation
  4. * Copyright (c) 2014 QLogic Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation.
  9. *
  10. */
  11. #ifndef CNIC_H
  12. #define CNIC_H
  13. #define HC_INDEX_ISCSI_EQ_CONS 6
  14. #define HC_INDEX_FCOE_EQ_CONS 3
  15. #define HC_SP_INDEX_ETH_ISCSI_CQ_CONS 5
  16. #define HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS 1
  17. #define KWQ_PAGE_CNT 4
  18. #define KCQ_PAGE_CNT 16
  19. #define KWQ_CID 24
  20. #define KCQ_CID 25
  21. /*
  22. * krnlq_context definition
  23. */
  24. #define L5_KRNLQ_FLAGS 0x00000000
  25. #define L5_KRNLQ_SIZE 0x00000000
  26. #define L5_KRNLQ_TYPE 0x00000000
  27. #define KRNLQ_FLAGS_PG_SZ (0xf<<0)
  28. #define KRNLQ_FLAGS_PG_SZ_256 (0<<0)
  29. #define KRNLQ_FLAGS_PG_SZ_512 (1<<0)
  30. #define KRNLQ_FLAGS_PG_SZ_1K (2<<0)
  31. #define KRNLQ_FLAGS_PG_SZ_2K (3<<0)
  32. #define KRNLQ_FLAGS_PG_SZ_4K (4<<0)
  33. #define KRNLQ_FLAGS_PG_SZ_8K (5<<0)
  34. #define KRNLQ_FLAGS_PG_SZ_16K (6<<0)
  35. #define KRNLQ_FLAGS_PG_SZ_32K (7<<0)
  36. #define KRNLQ_FLAGS_PG_SZ_64K (8<<0)
  37. #define KRNLQ_FLAGS_PG_SZ_128K (9<<0)
  38. #define KRNLQ_FLAGS_PG_SZ_256K (10<<0)
  39. #define KRNLQ_FLAGS_PG_SZ_512K (11<<0)
  40. #define KRNLQ_FLAGS_PG_SZ_1M (12<<0)
  41. #define KRNLQ_FLAGS_PG_SZ_2M (13<<0)
  42. #define KRNLQ_FLAGS_QE_SELF_SEQ (1<<15)
  43. #define KRNLQ_SIZE_TYPE_SIZE ((((0x28 + 0x1f) & ~0x1f) / 0x20) << 16)
  44. #define KRNLQ_TYPE_TYPE (0xf<<28)
  45. #define KRNLQ_TYPE_TYPE_EMPTY (0<<28)
  46. #define KRNLQ_TYPE_TYPE_KRNLQ (6<<28)
  47. #define L5_KRNLQ_HOST_QIDX 0x00000004
  48. #define L5_KRNLQ_HOST_FW_QIDX 0x00000008
  49. #define L5_KRNLQ_NX_QE_SELF_SEQ 0x0000000c
  50. #define L5_KRNLQ_QE_SELF_SEQ_MAX 0x0000000c
  51. #define L5_KRNLQ_NX_QE_HADDR_HI 0x00000010
  52. #define L5_KRNLQ_NX_QE_HADDR_LO 0x00000014
  53. #define L5_KRNLQ_PGTBL_PGIDX 0x00000018
  54. #define L5_KRNLQ_NX_PG_QIDX 0x00000018
  55. #define L5_KRNLQ_PGTBL_NPAGES 0x0000001c
  56. #define L5_KRNLQ_QIDX_INCR 0x0000001c
  57. #define L5_KRNLQ_PGTBL_HADDR_HI 0x00000020
  58. #define L5_KRNLQ_PGTBL_HADDR_LO 0x00000024
  59. #define BNX2_PG_CTX_MAP 0x1a0034
  60. #define BNX2_ISCSI_CTX_MAP 0x1a0074
  61. #define MAX_COMPLETED_KCQE 64
  62. #define MAX_CNIC_L5_CONTEXT 256
  63. #define MAX_CM_SK_TBL_SZ MAX_CNIC_L5_CONTEXT
  64. #define MAX_ISCSI_TBL_SZ 256
  65. #define CNIC_LOCAL_PORT_MIN 60000
  66. #define CNIC_LOCAL_PORT_MAX 61024
  67. #define CNIC_LOCAL_PORT_RANGE (CNIC_LOCAL_PORT_MAX - CNIC_LOCAL_PORT_MIN)
  68. #define KWQE_CNT (BNX2_PAGE_SIZE / sizeof(struct kwqe))
  69. #define KCQE_CNT (BNX2_PAGE_SIZE / sizeof(struct kcqe))
  70. #define MAX_KWQE_CNT (KWQE_CNT - 1)
  71. #define MAX_KCQE_CNT (KCQE_CNT - 1)
  72. #define MAX_KWQ_IDX ((KWQ_PAGE_CNT * KWQE_CNT) - 1)
  73. #define MAX_KCQ_IDX ((KCQ_PAGE_CNT * KCQE_CNT) - 1)
  74. #define KWQ_PG(x) (((x) & ~MAX_KWQE_CNT) >> (BNX2_PAGE_BITS - 5))
  75. #define KWQ_IDX(x) ((x) & MAX_KWQE_CNT)
  76. #define KCQ_PG(x) (((x) & ~MAX_KCQE_CNT) >> (BNX2_PAGE_BITS - 5))
  77. #define KCQ_IDX(x) ((x) & MAX_KCQE_CNT)
  78. #define BNX2X_NEXT_KCQE(x) (((x) & (MAX_KCQE_CNT - 1)) == \
  79. (MAX_KCQE_CNT - 1)) ? \
  80. (x) + 2 : (x) + 1
  81. #define BNX2X_KWQ_DATA_PG(cp, x) ((x) / (cp)->kwq_16_data_pp)
  82. #define BNX2X_KWQ_DATA_IDX(cp, x) ((x) % (cp)->kwq_16_data_pp)
  83. #define BNX2X_KWQ_DATA(cp, x) \
  84. &(cp)->kwq_16_data[BNX2X_KWQ_DATA_PG(cp, x)][BNX2X_KWQ_DATA_IDX(cp, x)]
  85. #define DEF_IPID_START 0x8000
  86. #define DEF_KA_TIMEOUT 10000
  87. #define DEF_KA_INTERVAL 300000
  88. #define DEF_KA_MAX_PROBE_COUNT 3
  89. #define DEF_TOS 0
  90. #define DEF_TTL 0xfe
  91. #define DEF_SND_SEQ_SCALE 0
  92. #define DEF_RCV_BUF 0xffff
  93. #define DEF_SND_BUF 0xffff
  94. #define DEF_SEED 0
  95. #define DEF_MAX_RT_TIME 500
  96. #define DEF_MAX_DA_COUNT 2
  97. #define DEF_SWS_TIMER 1000
  98. #define DEF_MAX_CWND 0xffff
  99. struct cnic_ctx {
  100. u32 cid;
  101. void *ctx;
  102. dma_addr_t mapping;
  103. };
  104. #define BNX2_MAX_CID 0x2000
  105. struct cnic_dma {
  106. int num_pages;
  107. void **pg_arr;
  108. dma_addr_t *pg_map_arr;
  109. int pgtbl_size;
  110. u32 *pgtbl;
  111. dma_addr_t pgtbl_map;
  112. };
  113. struct cnic_id_tbl {
  114. spinlock_t lock;
  115. u32 start;
  116. u32 max;
  117. u32 next;
  118. unsigned long *table;
  119. };
  120. #define CNIC_KWQ16_DATA_SIZE 128
  121. struct kwqe_16_data {
  122. u8 data[CNIC_KWQ16_DATA_SIZE];
  123. };
  124. struct cnic_iscsi {
  125. struct cnic_dma task_array_info;
  126. struct cnic_dma r2tq_info;
  127. struct cnic_dma hq_info;
  128. };
  129. struct cnic_context {
  130. u32 cid;
  131. struct kwqe_16_data *kwqe_data;
  132. dma_addr_t kwqe_data_mapping;
  133. wait_queue_head_t waitq;
  134. int wait_cond;
  135. unsigned long timestamp;
  136. unsigned long ctx_flags;
  137. #define CTX_FL_OFFLD_START 0
  138. #define CTX_FL_DELETE_WAIT 1
  139. #define CTX_FL_CID_ERROR 2
  140. u8 ulp_proto_id;
  141. union {
  142. struct cnic_iscsi *iscsi;
  143. } proto;
  144. };
  145. struct kcq_info {
  146. struct cnic_dma dma;
  147. struct kcqe **kcq;
  148. u16 *hw_prod_idx_ptr;
  149. u16 sw_prod_idx;
  150. u16 *status_idx_ptr;
  151. u32 io_addr;
  152. u16 (*next_idx)(u16);
  153. u16 (*hw_idx)(u16);
  154. };
  155. #define UIO_USE_TX_DOORBELL 0x017855DB
  156. struct cnic_uio_dev {
  157. struct uio_info cnic_uinfo;
  158. u32 uio_dev;
  159. int l2_ring_size;
  160. void *l2_ring;
  161. dma_addr_t l2_ring_map;
  162. int l2_buf_size;
  163. void *l2_buf;
  164. dma_addr_t l2_buf_map;
  165. struct cnic_dev *dev;
  166. struct pci_dev *pdev;
  167. struct list_head list;
  168. };
  169. struct cnic_local {
  170. spinlock_t cnic_ulp_lock;
  171. void *ulp_handle[MAX_CNIC_ULP_TYPE];
  172. unsigned long ulp_flags[MAX_CNIC_ULP_TYPE];
  173. #define ULP_F_INIT 0
  174. #define ULP_F_START 1
  175. #define ULP_F_CALL_PENDING 2
  176. struct cnic_ulp_ops __rcu *ulp_ops[MAX_CNIC_ULP_TYPE];
  177. unsigned long cnic_local_flags;
  178. #define CNIC_LCL_FL_KWQ_INIT 0x0
  179. #define CNIC_LCL_FL_L2_WAIT 0x1
  180. #define CNIC_LCL_FL_RINGS_INITED 0x2
  181. #define CNIC_LCL_FL_STOP_ISCSI 0x4
  182. struct cnic_dev *dev;
  183. struct cnic_eth_dev *ethdev;
  184. struct cnic_uio_dev *udev;
  185. int l2_rx_ring_size;
  186. int l2_single_buf_size;
  187. u16 *rx_cons_ptr;
  188. u16 *tx_cons_ptr;
  189. u16 rx_cons;
  190. u16 tx_cons;
  191. struct cnic_dma kwq_info;
  192. struct kwqe **kwq;
  193. struct cnic_dma kwq_16_data_info;
  194. u16 max_kwq_idx;
  195. u16 kwq_prod_idx;
  196. u32 kwq_io_addr;
  197. u16 *kwq_con_idx_ptr;
  198. u16 kwq_con_idx;
  199. struct kcq_info kcq1;
  200. struct kcq_info kcq2;
  201. union {
  202. void *gen;
  203. struct status_block_msix *bnx2;
  204. struct host_hc_status_block_e1x *bnx2x_e1x;
  205. /* index values - which counter to update */
  206. #define SM_RX_ID 0
  207. #define SM_TX_ID 1
  208. } status_blk;
  209. struct host_sp_status_block *bnx2x_def_status_blk;
  210. u32 status_blk_num;
  211. u32 bnx2x_igu_sb_id;
  212. u32 int_num;
  213. u32 last_status_idx;
  214. struct tasklet_struct cnic_irq_task;
  215. struct kcqe *completed_kcq[MAX_COMPLETED_KCQE];
  216. struct cnic_sock *csk_tbl;
  217. struct cnic_id_tbl csk_port_tbl;
  218. struct cnic_dma gbl_buf_info;
  219. struct cnic_iscsi *iscsi_tbl;
  220. struct cnic_context *ctx_tbl;
  221. struct cnic_id_tbl cid_tbl;
  222. atomic_t iscsi_conn;
  223. u32 iscsi_start_cid;
  224. u32 fcoe_init_cid;
  225. u32 fcoe_start_cid;
  226. struct cnic_id_tbl fcoe_cid_tbl;
  227. u32 max_cid_space;
  228. /* per connection parameters */
  229. int num_iscsi_tasks;
  230. int num_ccells;
  231. int task_array_size;
  232. int r2tq_size;
  233. int hq_size;
  234. int num_cqs;
  235. struct delayed_work delete_task;
  236. struct cnic_ctx *ctx_arr;
  237. int ctx_blks;
  238. int ctx_blk_size;
  239. unsigned long ctx_align;
  240. int cids_per_blk;
  241. u32 chip_id;
  242. int func;
  243. u32 shmem_base;
  244. struct cnic_ops *cnic_ops;
  245. int (*start_hw)(struct cnic_dev *);
  246. void (*stop_hw)(struct cnic_dev *);
  247. void (*setup_pgtbl)(struct cnic_dev *,
  248. struct cnic_dma *);
  249. int (*alloc_resc)(struct cnic_dev *);
  250. void (*free_resc)(struct cnic_dev *);
  251. int (*start_cm)(struct cnic_dev *);
  252. void (*stop_cm)(struct cnic_dev *);
  253. void (*enable_int)(struct cnic_dev *);
  254. void (*disable_int_sync)(struct cnic_dev *);
  255. void (*ack_int)(struct cnic_dev *);
  256. void (*arm_int)(struct cnic_dev *, u32 index);
  257. void (*close_conn)(struct cnic_sock *, u32 opcode);
  258. };
  259. struct bnx2x_bd_chain_next {
  260. u32 addr_lo;
  261. u32 addr_hi;
  262. u8 reserved[8];
  263. };
  264. #define ISCSI_DEFAULT_MAX_OUTSTANDING_R2T (1)
  265. #define ISCSI_RAMROD_CMD_ID_UPDATE_CONN (ISCSI_KCQE_OPCODE_UPDATE_CONN)
  266. #define ISCSI_RAMROD_CMD_ID_INIT (ISCSI_KCQE_OPCODE_INIT)
  267. #define CDU_REGION_NUMBER_XCM_AG 2
  268. #define CDU_REGION_NUMBER_UCM_AG 4
  269. #define CDU_VALID_DATA(_cid, _region, _type) \
  270. (((_cid) << 8) | (((_region)&0xf)<<4) | (((_type)&0xf)))
  271. #define CDU_CRC8(_cid, _region, _type) \
  272. (calc_crc8(CDU_VALID_DATA(_cid, _region, _type), 0xff))
  273. #define CDU_RSRVD_VALUE_TYPE_A(_cid, _region, _type) \
  274. (0x80 | ((CDU_CRC8(_cid, _region, _type)) & 0x7f))
  275. #define BNX2X_CONTEXT_MEM_SIZE 1024
  276. #define BNX2X_FCOE_CID 16
  277. #define BNX2X_ISCSI_START_CID 18
  278. #define BNX2X_ISCSI_NUM_CONNECTIONS 128
  279. #define BNX2X_ISCSI_TASK_CONTEXT_SIZE 128
  280. #define BNX2X_ISCSI_MAX_PENDING_R2TS 4
  281. #define BNX2X_ISCSI_R2TQE_SIZE 8
  282. #define BNX2X_ISCSI_HQ_BD_SIZE 64
  283. #define BNX2X_ISCSI_GLB_BUF_SIZE 64
  284. #define BNX2X_ISCSI_PBL_NOT_CACHED 0xff
  285. #define BNX2X_ISCSI_PDU_HEADER_NOT_CACHED 0xff
  286. #define BNX2X_FCOE_NUM_CONNECTIONS 1024
  287. #define BNX2X_FCOE_L5_CID_BASE MAX_ISCSI_TBL_SZ
  288. #define BNX2X_CHIP_IS_E2_PLUS(bp) (CHIP_IS_E2(bp) || CHIP_IS_E3(bp))
  289. #define BNX2X_RX_DESC_CNT (BNX2_PAGE_SIZE / \
  290. sizeof(struct eth_rx_bd))
  291. #define BNX2X_MAX_RX_DESC_CNT (BNX2X_RX_DESC_CNT - 2)
  292. #define BNX2X_RCQ_DESC_CNT (BNX2_PAGE_SIZE / \
  293. sizeof(union eth_rx_cqe))
  294. #define BNX2X_MAX_RCQ_DESC_CNT (BNX2X_RCQ_DESC_CNT - 1)
  295. #define BNX2X_NEXT_RCQE(x) (((x) & BNX2X_MAX_RCQ_DESC_CNT) == \
  296. (BNX2X_MAX_RCQ_DESC_CNT - 1)) ? \
  297. ((x) + 2) : ((x) + 1)
  298. #define BNX2X_DEF_SB_ID HC_SP_SB_ID
  299. #define BNX2X_SHMEM_MF_BLK_OFFSET 0x7e4
  300. #define BNX2X_SHMEM_ADDR(base, field) (base + \
  301. offsetof(struct shmem_region, field))
  302. #define BNX2X_SHMEM2_ADDR(base, field) (base + \
  303. offsetof(struct shmem2_region, field))
  304. #define BNX2X_SHMEM2_HAS(base, field) \
  305. ((base) && \
  306. (CNIC_RD(dev, BNX2X_SHMEM2_ADDR(base, size)) > \
  307. offsetof(struct shmem2_region, field)))
  308. #define BNX2X_MF_CFG_ADDR(base, field) \
  309. ((base) + offsetof(struct mf_cfg, field))
  310. #ifndef ETH_MAX_RX_CLIENTS_E2
  311. #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
  312. #endif
  313. #define CNIC_FUNC(cp) ((cp)->func)
  314. #define BNX2X_HW_CID(bp, x) ((BP_PORT(bp) << 23) | \
  315. (BP_VN(bp) << 17) | (x))
  316. #define BNX2X_SW_CID(x) (x & 0x1ffff)
  317. #define BNX2X_CL_QZONE_ID(bp, cli) \
  318. (BNX2X_CHIP_IS_E2_PLUS(bp) ? cli : \
  319. cli + (BP_PORT(bp) * ETH_MAX_RX_CLIENTS_E1H))
  320. #ifndef MAX_STAT_COUNTER_ID
  321. #define MAX_STAT_COUNTER_ID \
  322. (CHIP_IS_E1H(bp) ? MAX_STAT_COUNTER_ID_E1H : \
  323. ((BNX2X_CHIP_IS_E2_PLUS(bp)) ? MAX_STAT_COUNTER_ID_E2 : \
  324. MAX_STAT_COUNTER_ID_E1))
  325. #endif
  326. #define CNIC_SUPPORTS_FCOE(cp) \
  327. (BNX2X_CHIP_IS_E2_PLUS(bp) && !NO_FCOE(bp))
  328. #define CNIC_RAMROD_TMO (HZ / 4)
  329. #endif