cnic.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /* cnic.h: Broadcom CNIC core network driver.
  2. *
  3. * Copyright (c) 2006-2010 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. struct cnic_redirect_entry {
  61. struct dst_entry *old_dst;
  62. struct dst_entry *new_dst;
  63. };
  64. #define MAX_COMPLETED_KCQE 64
  65. #define MAX_CNIC_L5_CONTEXT 256
  66. #define MAX_CM_SK_TBL_SZ MAX_CNIC_L5_CONTEXT
  67. #define MAX_ISCSI_TBL_SZ 256
  68. #define CNIC_LOCAL_PORT_MIN 60000
  69. #define CNIC_LOCAL_PORT_MAX 61024
  70. #define CNIC_LOCAL_PORT_RANGE (CNIC_LOCAL_PORT_MAX - CNIC_LOCAL_PORT_MIN)
  71. #define KWQE_CNT (BCM_PAGE_SIZE / sizeof(struct kwqe))
  72. #define KCQE_CNT (BCM_PAGE_SIZE / sizeof(struct kcqe))
  73. #define MAX_KWQE_CNT (KWQE_CNT - 1)
  74. #define MAX_KCQE_CNT (KCQE_CNT - 1)
  75. #define MAX_KWQ_IDX ((KWQ_PAGE_CNT * KWQE_CNT) - 1)
  76. #define MAX_KCQ_IDX ((KCQ_PAGE_CNT * KCQE_CNT) - 1)
  77. #define KWQ_PG(x) (((x) & ~MAX_KWQE_CNT) >> (BCM_PAGE_BITS - 5))
  78. #define KWQ_IDX(x) ((x) & MAX_KWQE_CNT)
  79. #define KCQ_PG(x) (((x) & ~MAX_KCQE_CNT) >> (BCM_PAGE_BITS - 5))
  80. #define KCQ_IDX(x) ((x) & MAX_KCQE_CNT)
  81. #define BNX2X_NEXT_KCQE(x) (((x) & (MAX_KCQE_CNT - 1)) == \
  82. (MAX_KCQE_CNT - 1)) ? \
  83. (x) + 2 : (x) + 1
  84. #define BNX2X_KWQ_DATA_PG(cp, x) ((x) / (cp)->kwq_16_data_pp)
  85. #define BNX2X_KWQ_DATA_IDX(cp, x) ((x) % (cp)->kwq_16_data_pp)
  86. #define BNX2X_KWQ_DATA(cp, x) \
  87. &(cp)->kwq_16_data[BNX2X_KWQ_DATA_PG(cp, x)][BNX2X_KWQ_DATA_IDX(cp, x)]
  88. #define DEF_IPID_START 0x8000
  89. #define DEF_KA_TIMEOUT 10000
  90. #define DEF_KA_INTERVAL 300000
  91. #define DEF_KA_MAX_PROBE_COUNT 3
  92. #define DEF_TOS 0
  93. #define DEF_TTL 0xfe
  94. #define DEF_SND_SEQ_SCALE 0
  95. #define DEF_RCV_BUF 0xffff
  96. #define DEF_SND_BUF 0xffff
  97. #define DEF_SEED 0
  98. #define DEF_MAX_RT_TIME 500
  99. #define DEF_MAX_DA_COUNT 2
  100. #define DEF_SWS_TIMER 1000
  101. #define DEF_MAX_CWND 0xffff
  102. struct cnic_ctx {
  103. u32 cid;
  104. void *ctx;
  105. dma_addr_t mapping;
  106. };
  107. #define BNX2_MAX_CID 0x2000
  108. struct cnic_dma {
  109. int num_pages;
  110. void **pg_arr;
  111. dma_addr_t *pg_map_arr;
  112. int pgtbl_size;
  113. u32 *pgtbl;
  114. dma_addr_t pgtbl_map;
  115. };
  116. struct cnic_id_tbl {
  117. spinlock_t lock;
  118. u32 start;
  119. u32 max;
  120. u32 next;
  121. unsigned long *table;
  122. };
  123. #define CNIC_KWQ16_DATA_SIZE 128
  124. struct kwqe_16_data {
  125. u8 data[CNIC_KWQ16_DATA_SIZE];
  126. };
  127. struct cnic_iscsi {
  128. struct cnic_dma task_array_info;
  129. struct cnic_dma r2tq_info;
  130. struct cnic_dma hq_info;
  131. };
  132. struct cnic_context {
  133. u32 cid;
  134. struct kwqe_16_data *kwqe_data;
  135. dma_addr_t kwqe_data_mapping;
  136. wait_queue_head_t waitq;
  137. int wait_cond;
  138. unsigned long timestamp;
  139. unsigned long ctx_flags;
  140. #define CTX_FL_OFFLD_START 0
  141. #define CTX_FL_DELETE_WAIT 1
  142. u8 ulp_proto_id;
  143. union {
  144. struct cnic_iscsi *iscsi;
  145. } proto;
  146. };
  147. struct kcq_info {
  148. struct cnic_dma dma;
  149. struct kcqe **kcq;
  150. u16 *hw_prod_idx_ptr;
  151. u16 sw_prod_idx;
  152. u16 *status_idx_ptr;
  153. u32 io_addr;
  154. };
  155. struct iro {
  156. u32 base;
  157. u16 m1;
  158. u16 m2;
  159. u16 m3;
  160. u16 size;
  161. };
  162. struct cnic_uio_dev {
  163. struct uio_info cnic_uinfo;
  164. u32 uio_dev;
  165. int l2_ring_size;
  166. void *l2_ring;
  167. dma_addr_t l2_ring_map;
  168. int l2_buf_size;
  169. void *l2_buf;
  170. dma_addr_t l2_buf_map;
  171. struct cnic_dev *dev;
  172. struct pci_dev *pdev;
  173. struct list_head list;
  174. };
  175. struct cnic_local {
  176. spinlock_t cnic_ulp_lock;
  177. void *ulp_handle[MAX_CNIC_ULP_TYPE];
  178. unsigned long ulp_flags[MAX_CNIC_ULP_TYPE];
  179. #define ULP_F_INIT 0
  180. #define ULP_F_START 1
  181. #define ULP_F_CALL_PENDING 2
  182. struct cnic_ulp_ops __rcu *ulp_ops[MAX_CNIC_ULP_TYPE];
  183. unsigned long cnic_local_flags;
  184. #define CNIC_LCL_FL_KWQ_INIT 0x0
  185. #define CNIC_LCL_FL_L2_WAIT 0x1
  186. #define CNIC_LCL_FL_RINGS_INITED 0x2
  187. #define CNIC_LCL_FL_STOP_ISCSI 0x4
  188. struct cnic_dev *dev;
  189. struct cnic_eth_dev *ethdev;
  190. struct cnic_uio_dev *udev;
  191. int l2_rx_ring_size;
  192. int l2_single_buf_size;
  193. u16 *rx_cons_ptr;
  194. u16 *tx_cons_ptr;
  195. u16 rx_cons;
  196. u16 tx_cons;
  197. struct iro *iro_arr;
  198. #define IRO (((struct cnic_local *) dev->cnic_priv)->iro_arr)
  199. struct cnic_dma kwq_info;
  200. struct kwqe **kwq;
  201. struct cnic_dma kwq_16_data_info;
  202. u16 max_kwq_idx;
  203. u16 kwq_prod_idx;
  204. u32 kwq_io_addr;
  205. u16 *kwq_con_idx_ptr;
  206. u16 kwq_con_idx;
  207. struct kcq_info kcq1;
  208. struct kcq_info kcq2;
  209. union {
  210. void *gen;
  211. struct status_block_msix *bnx2;
  212. struct host_hc_status_block_e1x *bnx2x_e1x;
  213. /* index values - which counter to update */
  214. #define SM_RX_ID 0
  215. #define SM_TX_ID 1
  216. } status_blk;
  217. struct host_sp_status_block *bnx2x_def_status_blk;
  218. u32 status_blk_num;
  219. u32 bnx2x_igu_sb_id;
  220. u32 int_num;
  221. u32 last_status_idx;
  222. struct tasklet_struct cnic_irq_task;
  223. struct kcqe *completed_kcq[MAX_COMPLETED_KCQE];
  224. struct cnic_sock *csk_tbl;
  225. struct cnic_id_tbl csk_port_tbl;
  226. struct cnic_dma conn_buf_info;
  227. struct cnic_dma gbl_buf_info;
  228. struct cnic_iscsi *iscsi_tbl;
  229. struct cnic_context *ctx_tbl;
  230. struct cnic_id_tbl cid_tbl;
  231. atomic_t iscsi_conn;
  232. u32 iscsi_start_cid;
  233. u32 fcoe_init_cid;
  234. u32 fcoe_start_cid;
  235. struct cnic_id_tbl fcoe_cid_tbl;
  236. u32 max_cid_space;
  237. /* per connection parameters */
  238. int num_iscsi_tasks;
  239. int num_ccells;
  240. int task_array_size;
  241. int r2tq_size;
  242. int hq_size;
  243. int num_cqs;
  244. struct delayed_work delete_task;
  245. struct cnic_ctx *ctx_arr;
  246. int ctx_blks;
  247. int ctx_blk_size;
  248. unsigned long ctx_align;
  249. int cids_per_blk;
  250. u32 chip_id;
  251. int func;
  252. u32 pfid;
  253. u32 shmem_base;
  254. struct cnic_ops *cnic_ops;
  255. int (*start_hw)(struct cnic_dev *);
  256. void (*stop_hw)(struct cnic_dev *);
  257. void (*setup_pgtbl)(struct cnic_dev *,
  258. struct cnic_dma *);
  259. int (*alloc_resc)(struct cnic_dev *);
  260. void (*free_resc)(struct cnic_dev *);
  261. int (*start_cm)(struct cnic_dev *);
  262. void (*stop_cm)(struct cnic_dev *);
  263. void (*enable_int)(struct cnic_dev *);
  264. void (*disable_int_sync)(struct cnic_dev *);
  265. void (*ack_int)(struct cnic_dev *);
  266. void (*close_conn)(struct cnic_sock *, u32 opcode);
  267. u16 (*next_idx)(u16);
  268. u16 (*hw_idx)(u16);
  269. };
  270. struct bnx2x_bd_chain_next {
  271. u32 addr_lo;
  272. u32 addr_hi;
  273. u8 reserved[8];
  274. };
  275. #define ISCSI_DEFAULT_MAX_OUTSTANDING_R2T (1)
  276. #define ISCSI_RAMROD_CMD_ID_UPDATE_CONN (ISCSI_KCQE_OPCODE_UPDATE_CONN)
  277. #define ISCSI_RAMROD_CMD_ID_INIT (ISCSI_KCQE_OPCODE_INIT)
  278. #define CDU_REGION_NUMBER_XCM_AG 2
  279. #define CDU_REGION_NUMBER_UCM_AG 4
  280. #define CDU_VALID_DATA(_cid, _region, _type) \
  281. (((_cid) << 8) | (((_region)&0xf)<<4) | (((_type)&0xf)))
  282. #define CDU_CRC8(_cid, _region, _type) \
  283. (calc_crc8(CDU_VALID_DATA(_cid, _region, _type), 0xff))
  284. #define CDU_RSRVD_VALUE_TYPE_A(_cid, _region, _type) \
  285. (0x80 | ((CDU_CRC8(_cid, _region, _type)) & 0x7f))
  286. #define BNX2X_CONTEXT_MEM_SIZE 1024
  287. #define BNX2X_FCOE_CID 16
  288. #define BNX2X_ISCSI_START_CID 18
  289. #define BNX2X_ISCSI_NUM_CONNECTIONS 128
  290. #define BNX2X_ISCSI_TASK_CONTEXT_SIZE 128
  291. #define BNX2X_ISCSI_MAX_PENDING_R2TS 4
  292. #define BNX2X_ISCSI_R2TQE_SIZE 8
  293. #define BNX2X_ISCSI_HQ_BD_SIZE 64
  294. #define BNX2X_ISCSI_CONN_BUF_SIZE 64
  295. #define BNX2X_ISCSI_GLB_BUF_SIZE 64
  296. #define BNX2X_ISCSI_PBL_NOT_CACHED 0xff
  297. #define BNX2X_ISCSI_PDU_HEADER_NOT_CACHED 0xff
  298. #define BNX2X_FCOE_NUM_CONNECTIONS 128
  299. #define BNX2X_FCOE_L5_CID_BASE MAX_ISCSI_TBL_SZ
  300. #define BNX2X_CHIP_NUM_57710 0x164e
  301. #define BNX2X_CHIP_NUM_57711 0x164f
  302. #define BNX2X_CHIP_NUM_57711E 0x1650
  303. #define BNX2X_CHIP_NUM_57712 0x1662
  304. #define BNX2X_CHIP_NUM_57712E 0x1663
  305. #define BNX2X_CHIP_NUM_57713 0x1651
  306. #define BNX2X_CHIP_NUM_57713E 0x1652
  307. #define BNX2X_CHIP_NUM(x) (x >> 16)
  308. #define BNX2X_CHIP_IS_57710(x) \
  309. (BNX2X_CHIP_NUM(x) == BNX2X_CHIP_NUM_57710)
  310. #define BNX2X_CHIP_IS_57711(x) \
  311. (BNX2X_CHIP_NUM(x) == BNX2X_CHIP_NUM_57711)
  312. #define BNX2X_CHIP_IS_57711E(x) \
  313. (BNX2X_CHIP_NUM(x) == BNX2X_CHIP_NUM_57711E)
  314. #define BNX2X_CHIP_IS_E1H(x) \
  315. (BNX2X_CHIP_IS_57711(x) || BNX2X_CHIP_IS_57711E(x))
  316. #define BNX2X_CHIP_IS_57712(x) \
  317. (BNX2X_CHIP_NUM(x) == BNX2X_CHIP_NUM_57712)
  318. #define BNX2X_CHIP_IS_57712E(x) \
  319. (BNX2X_CHIP_NUM(x) == BNX2X_CHIP_NUM_57712E)
  320. #define BNX2X_CHIP_IS_57713(x) \
  321. (BNX2X_CHIP_NUM(x) == BNX2X_CHIP_NUM_57713)
  322. #define BNX2X_CHIP_IS_57713E(x) \
  323. (BNX2X_CHIP_NUM(x) == BNX2X_CHIP_NUM_57713E)
  324. #define BNX2X_CHIP_IS_E2(x) \
  325. (BNX2X_CHIP_IS_57712(x) || BNX2X_CHIP_IS_57712E(x) || \
  326. BNX2X_CHIP_IS_57713(x) || BNX2X_CHIP_IS_57713E(x))
  327. #define IS_E1H_OFFSET BNX2X_CHIP_IS_E1H(cp->chip_id)
  328. #define BNX2X_RX_DESC_CNT (BCM_PAGE_SIZE / sizeof(struct eth_rx_bd))
  329. #define BNX2X_MAX_RX_DESC_CNT (BNX2X_RX_DESC_CNT - 2)
  330. #define BNX2X_RCQ_DESC_CNT (BCM_PAGE_SIZE / sizeof(union eth_rx_cqe))
  331. #define BNX2X_MAX_RCQ_DESC_CNT (BNX2X_RCQ_DESC_CNT - 1)
  332. #define BNX2X_NEXT_RCQE(x) (((x) & BNX2X_MAX_RCQ_DESC_CNT) == \
  333. (BNX2X_MAX_RCQ_DESC_CNT - 1)) ? \
  334. ((x) + 2) : ((x) + 1)
  335. #define BNX2X_DEF_SB_ID HC_SP_SB_ID
  336. #define BNX2X_SHMEM_MF_BLK_OFFSET 0x7e4
  337. #define BNX2X_SHMEM_ADDR(base, field) (base + \
  338. offsetof(struct shmem_region, field))
  339. #define BNX2X_SHMEM2_ADDR(base, field) (base + \
  340. offsetof(struct shmem2_region, field))
  341. #define BNX2X_SHMEM2_HAS(base, field) \
  342. ((base) && \
  343. (CNIC_RD(dev, BNX2X_SHMEM2_ADDR(base, size)) > \
  344. offsetof(struct shmem2_region, field)))
  345. #define BNX2X_MF_CFG_ADDR(base, field) \
  346. ((base) + offsetof(struct mf_cfg, field))
  347. #ifndef ETH_MAX_RX_CLIENTS_E2
  348. #define ETH_MAX_RX_CLIENTS_E2 ETH_MAX_RX_CLIENTS_E1H
  349. #endif
  350. #define CNIC_PORT(cp) ((cp)->pfid & 1)
  351. #define CNIC_FUNC(cp) ((cp)->func)
  352. #define CNIC_PATH(cp) (!BNX2X_CHIP_IS_E2(cp->chip_id) ? 0 :\
  353. (CNIC_FUNC(cp) & 1))
  354. #define CNIC_E1HVN(cp) ((cp)->pfid >> 1)
  355. #define BNX2X_HW_CID(cp, x) ((CNIC_PORT(cp) << 23) | \
  356. (CNIC_E1HVN(cp) << 17) | (x))
  357. #define BNX2X_SW_CID(x) (x & 0x1ffff)
  358. #define BNX2X_CL_QZONE_ID(cp, cli) \
  359. (cli + (CNIC_PORT(cp) * (BNX2X_CHIP_IS_E2(cp->chip_id) ?\
  360. ETH_MAX_RX_CLIENTS_E2 : \
  361. ETH_MAX_RX_CLIENTS_E1H)))
  362. #define TCP_TSTORM_OOO_DROP_AND_PROC_ACK (0<<4)
  363. #endif