cnic.h 10 KB

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