You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mtnic.h 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. FILE_LICENCE ( GPL2_ONLY );
  34. #ifndef H_MTNIC_IF_DEFS_H
  35. #define H_MTNIC_IF_DEFS_H
  36. /*
  37. * Device setup
  38. */
  39. #define MTNIC_MAX_PORTS 2
  40. #define MTNIC_PORT1 0
  41. #define MTNIC_PORT2 1
  42. #define NUM_TX_RINGS 1
  43. #define NUM_RX_RINGS 1
  44. #define NUM_CQS (NUM_RX_RINGS + NUM_TX_RINGS)
  45. #define GO_BIT_TIMEOUT 6000
  46. #define TBIT_RETRIES 100
  47. #define UNITS_BUFFER_SIZE 8 /* can be configured to 4/8/16 */
  48. #define MAX_GAP_PROD_CONS ( UNITS_BUFFER_SIZE / 4 )
  49. #define ETH_DEF_LEN 1540 /* 40 bytes used by the card */
  50. #define ETH_FCS_LEN 14
  51. #define DEF_MTU ETH_DEF_LEN + ETH_FCS_LEN
  52. #define DEF_IOBUF_SIZE ETH_DEF_LEN
  53. #define MAC_ADDRESS_SIZE 6
  54. #define NUM_EQES 16
  55. #define ROUND_TO_CHECK 0x400
  56. #define DELAY_LINK_CHECK 300
  57. #define CHECK_LINK_TIMES 7
  58. #define XNOR(x,y) (!(x) == !(y))
  59. #define dma_addr_t unsigned long
  60. #define PAGE_SIZE 4096
  61. #define PAGE_MASK (PAGE_SIZE - 1)
  62. #define MTNIC_MAILBOX_SIZE PAGE_SIZE
  63. /* BITOPS */
  64. #define MTNIC_BC_OFF(bc) ((bc) >> 8)
  65. #define MTNIC_BC_SZ(bc) ((bc) & 0xff)
  66. #define MTNIC_BC_ONES(size) (~((int)0x80000000 >> (31 - size)))
  67. #define MTNIC_BC_MASK(bc) \
  68. (MTNIC_BC_ONES(MTNIC_BC_SZ(bc)) << MTNIC_BC_OFF(bc))
  69. #define MTNIC_BC_VAL(val, bc) \
  70. (((val) & MTNIC_BC_ONES(MTNIC_BC_SZ(bc))) << MTNIC_BC_OFF(bc))
  71. /*
  72. * Sub word fields - bit code base extraction/setting etc
  73. */
  74. /* Encode two values */
  75. #define MTNIC_BC(off, size) ((off << 8) | (size & 0xff))
  76. /* Get value of field 'bc' from 'x' */
  77. #define MTNIC_BC_GET(x, bc) \
  78. (((x) >> MTNIC_BC_OFF(bc)) & MTNIC_BC_ONES(MTNIC_BC_SZ(bc)))
  79. /* Set value of field 'bc' of 'x' to 'val' */
  80. #define MTNIC_BC_SET(x, val, bc) \
  81. ((x) = ((x) & ~MTNIC_BC_MASK(bc)) | MTNIC_BC_VAL(val, bc))
  82. /* Like MTNIC_BC_SET, except the previous value is assumed to be 0 */
  83. #define MTNIC_BC_PUT(x, val, bc) ((x) |= MTNIC_BC_VAL(val, bc))
  84. /*
  85. * Device constants
  86. */
  87. typedef enum mtnic_if_cmd {
  88. /* NIC commands: */
  89. MTNIC_IF_CMD_QUERY_FW = 0x004, /* query FW (size, version, etc) */
  90. MTNIC_IF_CMD_MAP_FW = 0xfff, /* map pages for FW image */
  91. MTNIC_IF_CMD_RUN_FW = 0xff6, /* run the FW */
  92. MTNIC_IF_CMD_QUERY_CAP = 0x001, /* query MTNIC capabilities */
  93. MTNIC_IF_CMD_MAP_PAGES = 0x002, /* map physical pages to HW */
  94. MTNIC_IF_CMD_OPEN_NIC = 0x003, /* run the firmware */
  95. MTNIC_IF_CMD_CONFIG_RX = 0x005, /* general receive configuration */
  96. MTNIC_IF_CMD_CONFIG_TX = 0x006, /* general transmit configuration */
  97. MTNIC_IF_CMD_CONFIG_INT_FREQ = 0x007, /* interrupt timers freq limits */
  98. MTNIC_IF_CMD_HEART_BEAT = 0x008, /* NOP command testing liveliness */
  99. MTNIC_IF_CMD_CLOSE_NIC = 0x009, /* release memory and stop the NIC */
  100. /* Port commands: */
  101. MTNIC_IF_CMD_CONFIG_PORT_RSS_STEER = 0x10, /* set RSS mode */
  102. MTNIC_IF_CMD_SET_PORT_RSS_INDIRECTION = 0x11, /* set RSS indirection tbl */
  103. MTNIC_IF_CMD_CONFIG_PORT_PRIO_STEERING = 0x12, /* set PRIORITY mode */
  104. MTNIC_IF_CMD_CONFIG_PORT_ADDR_STEER = 0x13, /* set Address steer mode */
  105. MTNIC_IF_CMD_CONFIG_PORT_VLAN_FILTER = 0x14, /* configure VLAN filter */
  106. MTNIC_IF_CMD_CONFIG_PORT_MCAST_FILTER = 0x15, /* configure mcast filter */
  107. MTNIC_IF_CMD_ENABLE_PORT_MCAST_FILTER = 0x16, /* enable/disable */
  108. MTNIC_IF_CMD_SET_PORT_MTU = 0x17, /* set port MTU */
  109. MTNIC_IF_CMD_SET_PORT_PROMISCUOUS_MODE = 0x18, /* enable/disable promisc */
  110. MTNIC_IF_CMD_SET_PORT_DEFAULT_RING = 0x19, /* set the default ring */
  111. MTNIC_IF_CMD_SET_PORT_STATE = 0x1a, /* set link up/down */
  112. MTNIC_IF_CMD_DUMP_STAT = 0x1b, /* dump statistics */
  113. MTNIC_IF_CMD_ARM_PORT_STATE_EVENT = 0x1c, /* arm the port state event */
  114. /* Ring / Completion queue commands: */
  115. MTNIC_IF_CMD_CONFIG_CQ = 0x20, /* set up completion queue */
  116. MTNIC_IF_CMD_CONFIG_RX_RING = 0x21, /* setup Rx ring */
  117. MTNIC_IF_CMD_SET_RX_RING_ADDR = 0x22, /* set Rx ring filter by address */
  118. MTNIC_IF_CMD_SET_RX_RING_MCAST = 0x23, /* set Rx ring mcast filter */
  119. MTNIC_IF_CMD_ARM_RX_RING_WM = 0x24, /* one-time low-watermark INT */
  120. MTNIC_IF_CMD_CONFIG_TX_RING = 0x25, /* set up Tx ring */
  121. MTNIC_IF_CMD_ENFORCE_TX_RING_ADDR = 0x26, /* setup anti spoofing */
  122. MTNIC_IF_CMD_CONFIG_EQ = 0x27, /* config EQ ring */
  123. MTNIC_IF_CMD_RELEASE_RESOURCE = 0x28, /* release internal ref to resource */
  124. }
  125. mtnic_if_cmd_t;
  126. /** selectors for MTNIC_IF_CMD_QUERY_CAP */
  127. typedef enum mtnic_if_caps {
  128. MTNIC_IF_CAP_MAX_TX_RING_PER_PORT = 0x0,
  129. MTNIC_IF_CAP_MAX_RX_RING_PER_PORT = 0x1,
  130. MTNIC_IF_CAP_MAX_CQ_PER_PORT = 0x2,
  131. MTNIC_IF_CAP_NUM_PORTS = 0x3,
  132. MTNIC_IF_CAP_MAX_TX_DESC = 0x4,
  133. MTNIC_IF_CAP_MAX_RX_DESC = 0x5,
  134. MTNIC_IF_CAP_MAX_CQES = 0x6,
  135. MTNIC_IF_CAP_MAX_TX_SG_ENTRIES = 0x7,
  136. MTNIC_IF_CAP_MAX_RX_SG_ENTRIES = 0x8,
  137. MTNIC_IF_CAP_MEM_KEY = 0x9, /* key to mem (after map_pages) */
  138. MTNIC_IF_CAP_RSS_HASH_TYPE = 0xa, /* one of mtnic_if_rss_types_t */
  139. MTNIC_IF_CAP_MAX_PORT_UCAST_ADDR = 0xc,
  140. MTNIC_IF_CAP_MAX_RING_UCAST_ADDR = 0xd, /* only for ADDR steer */
  141. MTNIC_IF_CAP_MAX_PORT_MCAST_ADDR = 0xe,
  142. MTNIC_IF_CAP_MAX_RING_MCAST_ADDR = 0xf, /* only for ADDR steer */
  143. MTNIC_IF_CAP_INTA = 0x10,
  144. MTNIC_IF_CAP_BOARD_ID_LOW = 0x11,
  145. MTNIC_IF_CAP_BOARD_ID_HIGH = 0x12,
  146. MTNIC_IF_CAP_TX_CQ_DB_OFFSET = 0x13, /* offset in bytes for TX, CQ doorbell record */
  147. MTNIC_IF_CAP_EQ_DB_OFFSET = 0x14, /* offset in bytes for EQ doorbell record */
  148. /* These are per port - using port number from cap modifier field */
  149. MTNIC_IF_CAP_SPEED = 0x20,
  150. MTNIC_IF_CAP_DEFAULT_MAC = 0x21,
  151. MTNIC_IF_CAP_EQ_OFFSET = 0x22,
  152. MTNIC_IF_CAP_CQ_OFFSET = 0x23,
  153. MTNIC_IF_CAP_TX_OFFSET = 0x24,
  154. MTNIC_IF_CAP_RX_OFFSET = 0x25,
  155. } mtnic_if_caps_t;
  156. typedef enum mtnic_if_steer_types {
  157. MTNIC_IF_STEER_NONE = 0,
  158. MTNIC_IF_STEER_PRIORITY = 1,
  159. MTNIC_IF_STEER_RSS = 2,
  160. MTNIC_IF_STEER_ADDRESS = 3,
  161. } mtnic_if_steer_types_t;
  162. /** types of memory access modes */
  163. typedef enum mtnic_if_memory_types {
  164. MTNIC_IF_MEM_TYPE_SNOOP = 1,
  165. MTNIC_IF_MEM_TYPE_NO_SNOOP = 2
  166. } mtnic_if_memory_types_t;
  167. enum {
  168. MTNIC_HCR_BASE = 0x1f000,
  169. MTNIC_HCR_SIZE = 0x0001c,
  170. MTNIC_CLR_INT_SIZE = 0x00008,
  171. };
  172. #define MTNIC_RESET_OFFSET 0xF0010
  173. /********************************************************************
  174. * Device private data structures
  175. *
  176. * This section contains structures of all device private data:
  177. * descriptors, rings, CQs, EQ ....
  178. *
  179. *
  180. *********************************************************************/
  181. /*
  182. * Descriptor format
  183. */
  184. struct mtnic_ctrl_seg {
  185. u32 op_own;
  186. #define MTNIC_BIT_DESC_OWN 0x80000000
  187. #define MTNIC_OPCODE_SEND 0xa
  188. u32 size_vlan;
  189. u32 flags;
  190. #define MTNIC_BIT_NO_ICRC 0x2
  191. #define MTNIC_BIT_TX_COMP 0xc
  192. u32 reserved;
  193. };
  194. struct mtnic_data_seg {
  195. u32 count;
  196. #define MTNIC_INLINE 0x80000000
  197. u32 mem_type;
  198. #define MTNIC_MEMTYPE_PAD 0x100
  199. u32 addr_h;
  200. u32 addr_l;
  201. };
  202. struct mtnic_tx_desc {
  203. struct mtnic_ctrl_seg ctrl;
  204. struct mtnic_data_seg data; /* at least one data segment */
  205. };
  206. struct mtnic_rx_desc {
  207. u16 reserved1;
  208. u16 next;
  209. u32 reserved2[3];
  210. struct mtnic_data_seg data; /* actual number of entries depends on
  211. * rx ring stride */
  212. };
  213. /*
  214. * Rings
  215. */
  216. struct mtnic_rx_db_record {
  217. u32 count;
  218. };
  219. struct mtnic_ring {
  220. u32 size; /* REMOVE ____cacheline_aligned_in_smp; *//* number of Rx descs or TXBBs */
  221. u32 size_mask;
  222. u16 stride;
  223. u16 cq; /* index of port CQ associated with this ring */
  224. u32 prod;
  225. u32 cons; /* holds the last consumed index */
  226. /* Buffers */
  227. u32 buf_size; /* ring buffer size in bytes */
  228. dma_addr_t dma;
  229. void *buf;
  230. struct io_buffer *iobuf[UNITS_BUFFER_SIZE];
  231. /* Tx only */
  232. struct mtnic_txcq_db *txcq_db;
  233. u32 db_offset;
  234. /* Rx ring only */
  235. dma_addr_t iobuf_dma;
  236. struct mtnic_rx_db_record *db;
  237. dma_addr_t db_dma;
  238. };
  239. /*
  240. * CQ
  241. */
  242. struct mtnic_cqe {
  243. u8 vp; /* VLAN present */
  244. u8 reserved1[3];
  245. u32 rss_hash;
  246. u32 reserved2;
  247. u16 vlan_prio;
  248. u16 reserved3;
  249. u8 flags_h;
  250. u8 flags_l_rht;
  251. u8 ipv6_mask;
  252. u8 enc_bf;
  253. #define MTNIC_BIT_BAD_FCS 0x10
  254. #define MTNIC_OPCODE_ERROR 0x1e
  255. u32 byte_cnt;
  256. u16 index;
  257. u16 chksum;
  258. u8 reserved4[3];
  259. u8 op_tr_own;
  260. #define MTNIC_BIT_CQ_OWN 0x80
  261. };
  262. struct mtnic_cq_db_record {
  263. u32 update_ci;
  264. u32 cmd_ci;
  265. };
  266. struct mtnic_cq {
  267. int num; /* CQ number (on attached port) */
  268. u32 size; /* number of CQEs in CQ */
  269. u32 last; /* number of CQEs consumed */
  270. struct mtnic_cq_db_record *db;
  271. struct net_device *dev;
  272. dma_addr_t db_dma;
  273. u8 is_rx;
  274. u16 ring; /* ring associated with this CQ */
  275. u32 offset_ind;
  276. /* CQE ring */
  277. u32 buf_size; /* ring size in bytes */
  278. struct mtnic_cqe *buf;
  279. dma_addr_t dma;
  280. };
  281. /*
  282. * EQ
  283. */
  284. struct mtnic_eqe {
  285. u8 reserved1;
  286. u8 type;
  287. u8 reserved2;
  288. u8 subtype;
  289. u8 reserved3[3];
  290. u8 ring_cq;
  291. u32 reserved4;
  292. u8 port;
  293. #define MTNIC_MASK_EQE_PORT MTNIC_BC(4,2)
  294. u8 reserved5[2];
  295. u8 syndrome;
  296. u8 reserved6[15];
  297. u8 own;
  298. #define MTNIC_BIT_EQE_OWN 0x80
  299. };
  300. struct mtnic_eq {
  301. u32 size; /* number of EQEs in ring */
  302. u32 buf_size; /* EQ size in bytes */
  303. void *buf;
  304. dma_addr_t dma;
  305. };
  306. enum mtnic_state {
  307. CARD_DOWN,
  308. CARD_INITIALIZED,
  309. CARD_UP,
  310. CARD_LINK_DOWN,
  311. };
  312. /* FW */
  313. struct mtnic_pages {
  314. u32 num;
  315. u32 *buf;
  316. };
  317. struct mtnic_err_buf {
  318. u64 offset;
  319. u32 size;
  320. };
  321. struct mtnic_cmd {
  322. void *buf;
  323. unsigned long mapping;
  324. u32 tbit;
  325. };
  326. struct mtnic_txcq_db {
  327. u32 reserved1[5];
  328. u32 send_db;
  329. u32 reserved2[2];
  330. u32 cq_arm;
  331. u32 cq_ci;
  332. };
  333. /*
  334. * Device private data
  335. *
  336. */
  337. struct mtnic {
  338. struct net_device *netdev[MTNIC_MAX_PORTS];
  339. struct mtnic_if_cmd_reg *hcr;
  340. struct mtnic_cmd cmd;
  341. struct pci_device *pdev;
  342. struct mtnic_eq eq;
  343. u32 *eq_db;
  344. /* Firmware and board info */
  345. u64 fw_ver;
  346. struct {
  347. struct mtnic_pages fw_pages;
  348. struct mtnic_pages extra_pages;
  349. struct mtnic_err_buf err_buf;
  350. u16 ifc_rev;
  351. u8 num_ports;
  352. u64 mac[MTNIC_MAX_PORTS];
  353. u16 cq_offset;
  354. u16 tx_offset[MTNIC_MAX_PORTS];
  355. u16 rx_offset[MTNIC_MAX_PORTS];
  356. u32 mem_type_snoop_be;
  357. u32 txcq_db_offset;
  358. u32 eq_db_offset;
  359. } fw;
  360. };
  361. struct mtnic_port {
  362. struct mtnic *mtnic;
  363. u8 port;
  364. enum mtnic_state state;
  365. /* TX, RX, CQs, EQ */
  366. struct mtnic_ring tx_ring;
  367. struct mtnic_ring rx_ring;
  368. struct mtnic_cq cq[NUM_CQS];
  369. u32 poll_counter;
  370. struct net_device *netdev;
  371. };
  372. /***************************************************************************
  373. * NIC COMMANDS
  374. *
  375. * The section below provides struct definition for commands parameters,
  376. * and arguments values enumeration.
  377. *
  378. * The format used for the struct names is:
  379. * mtnic_if_<cmd name>_<in|out>_<imm|mbox>
  380. *
  381. ***************************************************************************/
  382. /**
  383. * Command Register (Command interface)
  384. */
  385. struct mtnic_if_cmd_reg {
  386. unsigned long in_param_h;
  387. u32 in_param_l;
  388. u32 input_modifier;
  389. u32 out_param_h;
  390. u32 out_param_l;
  391. u32 token;
  392. #define MTNIC_MASK_CMD_REG_TOKEN MTNIC_BC(16,32)
  393. u32 status_go_opcode;
  394. #define MTNIC_MASK_CMD_REG_OPCODE MTNIC_BC(0,16)
  395. #define MTNIC_MASK_CMD_REG_T_BIT MTNIC_BC(21,1)
  396. #define MTNIC_MASK_CMD_REG_GO_BIT MTNIC_BC(23,1)
  397. #define MTNIC_MASK_CMD_REG_STATUS MTNIC_BC(24,8)
  398. };
  399. /* CMD QUERY_FW */
  400. struct mtnic_if_query_fw_out_mbox {
  401. u16 fw_pages; /* Total number of memory pages the device requires */
  402. u16 rev_maj;
  403. u16 rev_smin;
  404. u16 rev_min;
  405. u16 reserved1;
  406. u16 ifc_rev; /* major revision of the command interface */
  407. u8 ft;
  408. u8 reserved2[3];
  409. u32 reserved3[4];
  410. u64 clr_int_base;
  411. u32 reserved4[2];
  412. u64 err_buf_start;
  413. u32 err_buf_size;
  414. };
  415. /* CMD MTNIC_IF_CMD_QUERY_CAP */
  416. struct mtnic_if_query_cap_in_imm {
  417. u16 reserved1;
  418. u8 cap_modifier; /* a modifier for the particular capability */
  419. u8 cap_index; /* the index of the capability queried */
  420. u32 reserved2;
  421. };
  422. /* CMD OPEN_NIC */
  423. struct mtnic_if_open_nic_in_mbox {
  424. u16 reserved1;
  425. u16 mkey; /* number of mem keys for all chip*/
  426. u32 mkey_entry; /* mem key entries for each key*/
  427. u8 log_rx_p1; /* log2 rx rings for port1 */
  428. u8 log_cq_p1; /* log2 cq for port1 */
  429. u8 log_tx_p1; /* log2 tx rings for port1 */
  430. u8 steer_p1; /* port 1 steering mode */
  431. u16 reserved2;
  432. u8 log_vlan_p1; /* log2 vlan per rx port1 */
  433. u8 log_mac_p1; /* log2 mac per rx port1 */
  434. u8 log_rx_p2; /* log2 rx rings for port1 */
  435. u8 log_cq_p2; /* log2 cq for port1 */
  436. u8 log_tx_p2; /* log2 tx rings for port1 */
  437. u8 steer_p2; /* port 1 steering mode */
  438. u16 reserved3;
  439. u8 log_vlan_p2; /* log2 vlan per rx port1 */
  440. u8 log_mac_p2; /* log2 mac per rx port1 */
  441. };
  442. /* CMD CONFIG_RX */
  443. struct mtnic_if_config_rx_in_imm {
  444. u16 spkt_size; /* size of small packets interrupts enabled on CQ */
  445. u16 resp_rcv_pause_frm_mcast_vlan_comp; /* Two flags see MASK below */
  446. /* Enable response to receive pause frames */
  447. /* Use VLAN in exact-match multicast checks (see SET_RX_RING_MCAST) */
  448. };
  449. /* CMD CONFIG_TX */
  450. struct mtnic_if_config_send_in_imm {
  451. u32 enph_gpf; /* Enable PseudoHeader and GeneratePauseFrames flags */
  452. u32 reserved;
  453. };
  454. /* CMD HEART_BEAT */
  455. struct mtnic_if_heart_beat_out_imm {
  456. u32 flags; /* several flags */
  457. #define MTNIC_MASK_HEAR_BEAT_INT_ERROR MTNIC_BC(31,1)
  458. u32 reserved;
  459. };
  460. /*
  461. * PORT COMMANDS
  462. */
  463. /* CMD CONFIG_PORT_VLAN_FILTER */
  464. /* in mbox is a 4K bits mask - bit per VLAN */
  465. struct mtnic_if_config_port_vlan_filter_in_mbox {
  466. u64 filter[64]; /* vlans[63:0] sit in filter[0], vlans[127:64] sit in filter[1] .. */
  467. };
  468. /* CMD SET_PORT_MTU */
  469. struct mtnic_if_set_port_mtu_in_imm {
  470. u16 reserved1;
  471. u16 mtu; /* The MTU of the port in bytes */
  472. u32 reserved2;
  473. };
  474. /* CMD SET_PORT_DEFAULT_RING */
  475. struct mtnic_if_set_port_default_ring_in_imm {
  476. u8 reserved1[3];
  477. u8 ring; /* Index of ring that collects promiscuous traffic */
  478. u32 reserved2;
  479. };
  480. /* CMD SET_PORT_STATE */
  481. struct mtnic_if_set_port_state_in_imm {
  482. u32 state; /* if 1 the port state should be up */
  483. #define MTNIC_MASK_CONFIG_PORT_STATE MTNIC_BC(0,1)
  484. u32 reserved;
  485. };
  486. /* CMD CONFIG_CQ */
  487. struct mtnic_if_config_cq_in_mbox {
  488. u8 reserved1;
  489. u8 cq;
  490. u8 size; /* Num CQs is 2^size (size <= 22) */
  491. u8 offset; /* start address of CQE in first page (11:6) */
  492. u16 tlast; /* interrupt moderation timer from last completion usec */
  493. u8 flags; /* flags */
  494. u8 int_vector; /* MSI index if MSI is enabled, otherwise reserved */
  495. u16 reserved2;
  496. u16 max_cnt; /* interrupt moderation counter */
  497. u8 page_size; /* each mapped page is 2^(12+page_size) bytes */
  498. u8 reserved4[3];
  499. u32 db_record_addr_h; /*physical address of CQ doorbell record */
  500. u32 db_record_addr_l; /*physical address of CQ doorbell record */
  501. u32 page_address[0]; /* 64 bit page addresses of CQ buffer */
  502. };
  503. /* CMD CONFIG_RX_RING */
  504. struct mtnic_if_config_rx_ring_in_mbox {
  505. u8 reserved1;
  506. u8 ring; /* The ring index (with offset) */
  507. u8 stride_size; /* stride and size */
  508. /* Entry size = 16* (2^stride) bytes */
  509. #define MTNIC_MASK_CONFIG_RX_RING_STRIDE MTNIC_BC(4,3)
  510. /* Rx ring size is 2^size entries */
  511. #define MTNIC_MASK_CONFIG_RX_RING_SIZE MTNIC_BC(0,4)
  512. u8 flags; /* Bit0 - header separation */
  513. u8 page_size; /* Each mapped page is 2^(12+page_size) bytes */
  514. u8 reserved2[2];
  515. u8 cq; /* CQ associated with this ring */
  516. u32 db_record_addr_h;
  517. u32 db_record_addr_l;
  518. u32 page_address[0];/* Array of 2^size 64b page descriptor addresses */
  519. /* Must hold all Rx descriptors + doorbell record. */
  520. };
  521. /* The modifier for SET_RX_RING_ADDR */
  522. struct mtnic_if_set_rx_ring_modifier {
  523. u8 reserved;
  524. u8 port_num;
  525. u8 index;
  526. u8 ring;
  527. };
  528. /* CMD SET_RX_RING_ADDR */
  529. struct mtnic_if_set_rx_ring_addr_in_imm {
  530. u16 mac_47_32; /* UCAST MAC Address bits 47:32 */
  531. u16 flags_vlan_id; /* MAC/VLAN flags and vlan id */
  532. #define MTNIC_MASK_SET_RX_RING_ADDR_VLAN_ID MTNIC_BC(0,12)
  533. #define MTNIC_MASK_SET_RX_RING_ADDR_BY_MAC MTNIC_BC(12,1)
  534. #define MTNIC_MASK_SET_RX_RING_ADDR_BY_VLAN MTNIC_BC(13,1)
  535. u32 mac_31_0; /* UCAST MAC Address bits 31:0 */
  536. };
  537. /* CMD CONFIG_TX_RING */
  538. struct mtnic_if_config_send_ring_in_mbox {
  539. u16 ring; /* The ring index (with offset) */
  540. #define MTNIC_MASK_CONFIG_TX_RING_INDEX MTNIC_BC(0,8)
  541. u8 size; /* Tx ring size is 32*2^size bytes */
  542. #define MTNIC_MASK_CONFIG_TX_RING_SIZE MTNIC_BC(0,4)
  543. u8 reserved;
  544. u8 page_size; /* Each mapped page is 2^(12+page_size) bytes */
  545. u8 qos_class; /* The COS used for this Tx */
  546. u16 cq; /* CQ associated with this ring */
  547. #define MTNIC_MASK_CONFIG_TX_CQ_INDEX MTNIC_BC(0,8)
  548. u32 page_address[0]; /* 64 bit page addresses of descriptor buffer. */
  549. /* The buffer must accommodate all Tx descriptors */
  550. };
  551. /* CMD CONFIG_EQ */
  552. struct mtnic_if_config_eq_in_mbox {
  553. u8 reserved1;
  554. u8 int_vector; /* MSI index if MSI enabled; otherwise reserved */
  555. #define MTNIC_MASK_CONFIG_EQ_INT_VEC MTNIC_BC(0,6)
  556. u8 size; /* Num CQs is 2^size entries (size <= 22) */
  557. #define MTNIC_MASK_CONFIG_EQ_SIZE MTNIC_BC(0,5)
  558. u8 offset; /* Start address of CQE in first page (11:6) */
  559. #define MTNIC_MASK_CONFIG_EQ_OFFSET MTNIC_BC(0,6)
  560. u8 page_size; /* Each mapped page is 2^(12+page_size) bytes*/
  561. u8 reserved[3];
  562. u32 page_address[0]; /* 64 bit page addresses of EQ buffer */
  563. };
  564. /* CMD RELEASE_RESOURCE */
  565. enum mtnic_if_resource_types {
  566. MTNIC_IF_RESOURCE_TYPE_CQ = 0,
  567. MTNIC_IF_RESOURCE_TYPE_RX_RING,
  568. MTNIC_IF_RESOURCE_TYPE_TX_RING,
  569. MTNIC_IF_RESOURCE_TYPE_EQ
  570. };
  571. struct mtnic_if_release_resource_in_imm {
  572. u8 reserved1;
  573. u8 index; /* must be 0 for TYPE_EQ */
  574. u8 reserved2;
  575. u8 type; /* see enum mtnic_if_resource_types */
  576. u32 reserved3;
  577. };
  578. /*******************************************************************
  579. *
  580. * PCI addon structures
  581. *
  582. ********************************************************************/
  583. struct pcidev {
  584. unsigned long bar[6];
  585. u32 dev_config_space[64];
  586. struct pci_device *dev;
  587. u8 bus;
  588. u8 devfn;
  589. };
  590. struct dev_pci_struct {
  591. struct pcidev dev;
  592. struct pcidev br;
  593. };
  594. /* The only global var */
  595. struct dev_pci_struct mtnic_pci_dev;
  596. #endif /* H_MTNIC_IF_DEFS_H */