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.

thunderx.h 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. #ifndef _THUNDERX_H
  2. #define _THUNDERX_H
  3. /** @file
  4. *
  5. * Cavium ThunderX Ethernet driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/list.h>
  11. #include <ipxe/netdevice.h>
  12. #include <ipxe/uaccess.h>
  13. /******************************************************************************
  14. *
  15. * Address space
  16. *
  17. ******************************************************************************
  18. */
  19. /** Size of a cache line */
  20. #define TXNIC_LINE_SIZE 128
  21. /** Virtual function BAR size */
  22. #define TXNIC_VF_BAR_SIZE 0x200000UL
  23. /** Physical function BAR size */
  24. #define TXNIC_PF_BAR_SIZE 0x40000000UL
  25. /** BGX BAR size */
  26. #define TXNIC_BGX_BAR_SIZE 0x400000UL
  27. /** Maximum number of BGX Ethernet interfaces (per node) */
  28. #define TXNIC_NUM_BGX 2
  29. /** Maximum number of Logical MACs (per BGX) */
  30. #define TXNIC_NUM_LMAC 4
  31. /** Maximum number of destination MAC addresses (per BGX) */
  32. #define TXNIC_NUM_DMAC 32
  33. /** Maximum number of steering rules (per BGX) */
  34. #define TXNIC_NUM_STEERING 8
  35. /**
  36. * Calculate node ID
  37. *
  38. * @v addr PCI BAR base address
  39. * @ret node Node ID
  40. */
  41. static inline unsigned int txnic_address_node ( uint64_t addr ) {
  42. /* Node ID is in bits [45:44] of the hardcoded BAR address */
  43. return ( ( addr >> 44 ) & 0x3 );
  44. }
  45. /**
  46. * Calculate BGX Ethernet interface index
  47. *
  48. * @v addr PCI BAR base address
  49. * @ret index Index
  50. */
  51. static inline unsigned int txnic_address_bgx ( uint64_t addr ) {
  52. /* Index is in bit 24 of the hardcoded BAR address */
  53. return ( ( addr >> 24 ) & 0x1 );
  54. }
  55. /******************************************************************************
  56. *
  57. * Send queue
  58. *
  59. ******************************************************************************
  60. */
  61. /** Send queue configuration */
  62. #define TXNIC_QS_SQ_CFG(q) ( ( (q) << 18 ) | 0x010800 )
  63. #define TXNIC_QS_SQ_CFG_ENA ( 1ULL << 19 )
  64. #define TXNIC_QS_SQ_CFG_RESET ( 1ULL << 17 )
  65. #define TXNIC_QS_SQ_CFG_QSIZE(sz) ( ( ( uint64_t ) (sz) ) << 8 )
  66. #define TXNIC_QS_SQ_CFG_QSIZE_1K \
  67. TXNIC_QS_SQ_CFG_QSIZE ( 0 )
  68. /** Send queue base address */
  69. #define TXNIC_QS_SQ_BASE(q) ( ( (q) << 18 ) | 0x010820 )
  70. /** Send queue head pointer */
  71. #define TXNIC_QS_SQ_HEAD(q) ( ( (q) << 18 ) | 0x010828 )
  72. /** Send queue tail pointer */
  73. #define TXNIC_QS_SQ_TAIL(q) ( ( (q) << 18 ) | 0x010830 )
  74. /** Send queue doorbell */
  75. #define TXNIC_QS_SQ_DOOR(q) ( ( (q) << 18 ) | 0x010838 )
  76. /** Send queue status */
  77. #define TXNIC_QS_SQ_STATUS(q) ( ( (q) << 18 ) | 0x010840 )
  78. #define TXNIC_QS_SQ_STATUS_STOPPED ( 1ULL << 21 )
  79. /** Maximum time to wait for a send queue to stop
  80. *
  81. * This is a policy decision.
  82. */
  83. #define TXNIC_SQ_STOP_MAX_WAIT_MS 100
  84. /** A send header subdescriptor */
  85. struct txnic_send_header {
  86. /** Total length */
  87. uint32_t total;
  88. /** Unused */
  89. uint8_t unused_a[2];
  90. /** Subdescriptor count */
  91. uint8_t subdcnt;
  92. /** Flags */
  93. uint8_t flags;
  94. /** Unused */
  95. uint8_t unused_b[8];
  96. } __attribute__ (( packed ));
  97. /** Flags for send header subdescriptor
  98. *
  99. * These comprise SUBDC=0x1 and PNC=0x1.
  100. */
  101. #define TXNIC_SEND_HDR_FLAGS 0x14
  102. /** A send gather subdescriptor */
  103. struct txnic_send_gather {
  104. /** Size */
  105. uint16_t size;
  106. /** Unused */
  107. uint8_t unused[5];
  108. /** Flags */
  109. uint8_t flags;
  110. /** Address */
  111. uint64_t addr;
  112. } __attribute__ (( packed ));
  113. /** Flags for send gather subdescriptor
  114. *
  115. * These comprise SUBDC=0x4 and LD_TYPE=0x0.
  116. */
  117. #define TXNIC_SEND_GATHER_FLAGS 0x40
  118. /** A send queue entry
  119. *
  120. * Each send queue entry comprises a single send header subdescriptor
  121. * and a single send gather subdescriptor.
  122. */
  123. struct txnic_sqe {
  124. /** Send header descriptor */
  125. struct txnic_send_header hdr;
  126. /** Send gather descriptor */
  127. struct txnic_send_gather gather;
  128. } __attribute__ (( packed ));
  129. /** Number of subdescriptors per send queue entry */
  130. #define TXNIC_SQE_SUBDESCS ( sizeof ( struct txnic_sqe ) / \
  131. sizeof ( struct txnic_send_header ) )
  132. /** Number of send queue entries
  133. *
  134. * The minimum send queue size is 1024 entries.
  135. */
  136. #define TXNIC_SQES ( 1024 / TXNIC_SQE_SUBDESCS )
  137. /** Send queue maximum fill level
  138. *
  139. * This is a policy decision.
  140. */
  141. #define TXNIC_SQ_FILL 32
  142. /** Send queue alignment */
  143. #define TXNIC_SQ_ALIGN TXNIC_LINE_SIZE
  144. /** Send queue stride */
  145. #define TXNIC_SQ_STRIDE sizeof ( struct txnic_sqe )
  146. /** Send queue size */
  147. #define TXNIC_SQ_SIZE ( TXNIC_SQES * TXNIC_SQ_STRIDE )
  148. /** A send queue */
  149. struct txnic_sq {
  150. /** Producer counter */
  151. unsigned int prod;
  152. /** Consumer counter */
  153. unsigned int cons;
  154. /** Send queue entries */
  155. userptr_t sqe;
  156. };
  157. /******************************************************************************
  158. *
  159. * Receive queue
  160. *
  161. ******************************************************************************
  162. */
  163. /** Receive queue configuration */
  164. #define TXNIC_QS_RQ_CFG(q) ( ( (q) << 18 ) | 0x010600 )
  165. #define TXNIC_QS_RQ_CFG_ENA ( 1ULL << 1 )
  166. /** Maximum time to wait for a receive queue to disable
  167. *
  168. * This is a policy decision.
  169. */
  170. #define TXNIC_RQ_DISABLE_MAX_WAIT_MS 100
  171. /** Receive buffer descriptor ring configuration */
  172. #define TXNIC_QS_RBDR_CFG(q) ( ( (q) << 18 ) | 0x010c00 )
  173. #define TXNIC_QS_RBDR_CFG_ENA ( 1ULL << 44 )
  174. #define TXNIC_QS_RBDR_CFG_RESET ( 1ULL << 43 )
  175. #define TXNIC_QS_RBDR_CFG_QSIZE(sz) ( ( ( uint64_t ) (sz) ) << 32 )
  176. #define TXNIC_QS_RBDR_CFG_QSIZE_8K \
  177. TXNIC_QS_RBDR_CFG_QSIZE ( 0 )
  178. #define TXNIC_QS_RBDR_CFG_LINES(sz) ( ( ( uint64_t ) (sz) ) << 0 )
  179. /** Receive buffer descriptor ring base address */
  180. #define TXNIC_QS_RBDR_BASE(q) ( ( (q) << 18 ) | 0x010c20 )
  181. /** Receive buffer descriptor ring head pointer */
  182. #define TXNIC_QS_RBDR_HEAD(q) ( ( (q) << 18 ) | 0x010c28 )
  183. /** Receive buffer descriptor ring tail pointer */
  184. #define TXNIC_QS_RBDR_TAIL(q) ( ( (q) << 18 ) | 0x010c30 )
  185. /** Receive buffer descriptor ring doorbell */
  186. #define TXNIC_QS_RBDR_DOOR(q) ( ( (q) << 18 ) | 0x010c38 )
  187. /** Receive buffer descriptor ring status 0 */
  188. #define TXNIC_QS_RBDR_STATUS0(q) ( ( (q) << 18 ) | 0x010c40 )
  189. /** A receive buffer descriptor ring entry */
  190. struct txnic_rbdr_entry {
  191. /** Address */
  192. uint64_t addr;
  193. } __attribute__ (( packed ));
  194. /** A receive queue entry */
  195. struct txnic_rqe {
  196. /** Receive buffer descriptor ring entry */
  197. struct txnic_rbdr_entry rbdre;
  198. } __attribute__ (( packed ));
  199. /** Number of receive queue entries
  200. *
  201. * The minimum receive queue size is 8192 entries.
  202. */
  203. #define TXNIC_RQES 8192
  204. /** Receive queue maximum fill level
  205. *
  206. * This is a policy decision. Must not exceed TXNIC_RQES.
  207. */
  208. #define TXNIC_RQ_FILL 32
  209. /** Receive queue entry size
  210. *
  211. * This is a policy decision.
  212. */
  213. #define TXNIC_RQE_SIZE ( ( ETH_DATA_ALIGN + ETH_FRAME_LEN + \
  214. 4 /* VLAN */ + TXNIC_LINE_SIZE - 1 ) \
  215. & ~( TXNIC_LINE_SIZE - 1 ) )
  216. /** Receive queue alignment */
  217. #define TXNIC_RQ_ALIGN TXNIC_LINE_SIZE
  218. /** Receive queue stride */
  219. #define TXNIC_RQ_STRIDE sizeof ( struct txnic_rqe )
  220. /** Receive queue size */
  221. #define TXNIC_RQ_SIZE ( TXNIC_RQES * TXNIC_RQ_STRIDE )
  222. /** A receive queue */
  223. struct txnic_rq {
  224. /** Producer counter */
  225. unsigned int prod;
  226. /** Consumer counter */
  227. unsigned int cons;
  228. /** Receive queue entries */
  229. userptr_t rqe;
  230. /** I/O buffers */
  231. struct io_buffer *iobuf[TXNIC_RQ_FILL];
  232. };
  233. /******************************************************************************
  234. *
  235. * Completion queue
  236. *
  237. ******************************************************************************
  238. */
  239. /** Completion queue configuration */
  240. #define TXNIC_QS_CQ_CFG(q) ( ( (q) << 18 ) | 0x010400 )
  241. #define TXNIC_QS_CQ_CFG_ENA ( 1ULL << 42 )
  242. #define TXNIC_QS_CQ_CFG_RESET ( 1ULL << 41 )
  243. #define TXNIC_QS_CQ_CFG_QSIZE(sz) ( ( ( uint64_t ) (sz) ) << 32 )
  244. #define TXNIC_QS_CQ_CFG_QSIZE_256 \
  245. TXNIC_QS_CQ_CFG_QSIZE ( 7 )
  246. /** Maximum time to wait for a completion queue to disable
  247. *
  248. * This is a policy decision.
  249. */
  250. #define TXNIC_CQ_DISABLE_MAX_WAIT_MS 100
  251. /** Completion queue base address */
  252. #define TXNIC_QS_CQ_BASE(q) ( ( (q) << 18 ) | 0x010420 )
  253. /** Completion queue head pointer */
  254. #define TXNIC_QS_CQ_HEAD(q) ( ( (q) << 18 ) | 0x010428 )
  255. /** Completion queue tail pointer */
  256. #define TXNIC_QS_CQ_TAIL(q) ( ( (q) << 18 ) | 0x010430 )
  257. /** Completion queue doorbell */
  258. #define TXNIC_QS_CQ_DOOR(q) ( ( (q) << 18 ) | 0x010438 )
  259. /** Completion queue status */
  260. #define TXNIC_QS_CQ_STATUS(q) ( ( (q) << 18 ) | 0x010440 )
  261. #define TXNIC_QS_CQ_STATUS_QCOUNT(status) \
  262. ( ( (status) >> 0 ) & 0xffff )
  263. /** Completion queue status 2 */
  264. #define TXNIC_QS_CQ_STATUS2(q) ( ( (q) << 18 ) | 0x010448 )
  265. /** A send completion queue entry */
  266. struct txnic_cqe_send {
  267. /** Status */
  268. uint8_t send_status;
  269. /** Unused */
  270. uint8_t unused[4];
  271. /** Send queue entry pointer */
  272. uint16_t sqe_ptr;
  273. /** Type */
  274. uint8_t cqe_type;
  275. } __attribute__ (( packed ));
  276. /** Send completion queue entry type */
  277. #define TXNIC_CQE_TYPE_SEND 0x80
  278. /** A receive completion queue entry */
  279. struct txnic_cqe_rx {
  280. /** Error opcode */
  281. uint8_t errop;
  282. /** Unused */
  283. uint8_t unused_a[6];
  284. /** Type */
  285. uint8_t cqe_type;
  286. /** Unused */
  287. uint8_t unused_b[1];
  288. /** Padding */
  289. uint8_t apad;
  290. /** Unused */
  291. uint8_t unused_c[4];
  292. /** Length */
  293. uint16_t len;
  294. } __attribute__ (( packed ));
  295. /** Receive completion queue entry type */
  296. #define TXNIC_CQE_TYPE_RX 0x20
  297. /** Applied padding */
  298. #define TXNIC_CQE_RX_APAD_LEN( apad ) ( (apad) >> 5 )
  299. /** Completion queue entry common fields */
  300. struct txnic_cqe_common {
  301. /** Unused */
  302. uint8_t unused_a[7];
  303. /** Type */
  304. uint8_t cqe_type;
  305. } __attribute__ (( packed ));
  306. /** A completion queue entry */
  307. union txnic_cqe {
  308. /** Common fields */
  309. struct txnic_cqe_common common;
  310. /** Send completion */
  311. struct txnic_cqe_send send;
  312. /** Receive completion */
  313. struct txnic_cqe_rx rx;
  314. };
  315. /** Number of completion queue entries
  316. *
  317. * The minimum completion queue size is 256 entries.
  318. */
  319. #define TXNIC_CQES 256
  320. /** Completion queue alignment */
  321. #define TXNIC_CQ_ALIGN 512
  322. /** Completion queue stride */
  323. #define TXNIC_CQ_STRIDE 512
  324. /** Completion queue size */
  325. #define TXNIC_CQ_SIZE ( TXNIC_CQES * TXNIC_CQ_STRIDE )
  326. /** A completion queue */
  327. struct txnic_cq {
  328. /** Consumer counter */
  329. unsigned int cons;
  330. /** Completion queue entries */
  331. userptr_t cqe;
  332. };
  333. /******************************************************************************
  334. *
  335. * Virtual NIC
  336. *
  337. ******************************************************************************
  338. */
  339. /** A virtual NIC */
  340. struct txnic {
  341. /** Registers */
  342. void *regs;
  343. /** Device name (for debugging) */
  344. const char *name;
  345. /** Network device */
  346. struct net_device *netdev;
  347. /** Send queue */
  348. struct txnic_sq sq;
  349. /** Receive queue */
  350. struct txnic_rq rq;
  351. /** Completion queue */
  352. struct txnic_cq cq;
  353. };
  354. /******************************************************************************
  355. *
  356. * Physical function
  357. *
  358. ******************************************************************************
  359. */
  360. /** Physical function configuration */
  361. #define TXNIC_PF_CFG 0x000000
  362. #define TXNIC_PF_CFG_ENA ( 1ULL << 0 )
  363. /** Backpressure configuration */
  364. #define TXNIC_PF_BP_CFG 0x000080
  365. #define TXNIC_PF_BP_CFG_BP_POLL_ENA ( 1ULL << 6 )
  366. #define TXNIC_PF_BP_CFG_BP_POLL_DLY(dl) ( ( ( uint64_t ) (dl) ) << 0 )
  367. #define TXNIC_PF_BP_CFG_BP_POLL_DLY_DEFAULT \
  368. TXNIC_PF_BP_CFG_BP_POLL_DLY ( 3 )
  369. /** Interface send configuration */
  370. #define TXNIC_PF_INTF_SEND_CFG(in) ( ( (in) << 8 ) | 0x000200 )
  371. #define TXNIC_PF_INTF_SEND_CFG_BLOCK_BGX ( 1ULL << 3 )
  372. #define TXNIC_PF_INTF_SEND_CFG_BLOCK(bl) ( ( ( uint64_t ) (bl) ) << 0 )
  373. /** Interface backpressure configuration */
  374. #define TXNIC_PF_INTF_BP_CFG(in) ( ( (in) << 8 ) | 0x000208 )
  375. #define TXNIC_PF_INTF_BP_CFG_BP_ENA ( 1ULL << 63 )
  376. #define TXNIC_PF_INTF_BP_CFG_BP_ID_BGX ( 1ULL << 3 )
  377. #define TXNIC_PF_INTF_BP_CFG_BP_ID(bp) ( ( ( uint64_t ) (bp) ) << 0 )
  378. /** Port kind configuration */
  379. #define TXNIC_PF_PKIND_CFG(pk) ( ( (pk) << 3 ) | 0x000600 )
  380. #define TXNIC_PF_PKIND_CFG_LENERR_EN ( 1ULL << 33 )
  381. #define TXNIC_PF_PKIND_CFG_MAXLEN(ct) ( ( ( uint64_t ) (ct) ) << 16 )
  382. #define TXNIC_PF_PKIND_CFG_MAXLEN_DISABLE \
  383. TXNIC_PF_PKIND_CFG_MAXLEN ( 0xffff )
  384. #define TXNIC_PF_PKIND_CFG_MINLEN(ct) ( ( ( uint64_t ) (ct) ) << 0 )
  385. #define TXNIC_PF_PKIND_CFG_MINLEN_DISABLE \
  386. TXNIC_PF_PKIND_CFG_MINLEN ( 0x0000 )
  387. /** Match parse index configuration */
  388. #define TXNIC_PF_MPI_CFG(ix) ( ( (ix) << 3 ) | 0x210000 )
  389. #define TXNIC_PF_MPI_CFG_VNIC(vn) ( ( ( uint64_t ) (vn) ) << 24 )
  390. #define TXNIC_PF_MPI_CFG_RSSI_BASE(ix) ( ( ( uint64_t ) (ix) ) << 0 )
  391. /** RSS indirection receive queue */
  392. #define TXNIC_PF_RSSI_RQ(ix) ( ( (ix) << 3 ) | 0x220000 )
  393. #define TXNIC_PF_RSSI_RQ_RQ_QS(qs) ( ( ( uint64_t ) (qs) ) << 3 )
  394. /** LMAC registers */
  395. #define TXNIC_PF_LMAC(lm) ( ( (lm) << 3 ) | 0x240000 )
  396. /** LMAC configuration */
  397. #define TXNIC_PF_LMAC_CFG 0x000000
  398. #define TXNIC_PF_LMAC_CFG_ADJUST(ad) ( ( ( uint64_t ) (ad) ) << 8 )
  399. #define TXNIC_PF_LMAC_CFG_ADJUST_DEFAULT \
  400. TXNIC_PF_LMAC_CFG_ADJUST ( 6 )
  401. #define TXNIC_PF_LMAC_CFG_MIN_PKT_SIZE(sz) ( ( ( uint64_t ) (sz) ) << 0 )
  402. /** LMAC configuration 2 */
  403. #define TXNIC_PF_LMAC_CFG2 0x000100
  404. #define TXNIC_PF_LMAC_CFG2_MAX_PKT_SIZE(sz) ( ( ( uint64_t ) (sz) ) << 0 )
  405. /** LMAC credit */
  406. #define TXNIC_PF_LMAC_CREDIT 0x004000
  407. #define TXNIC_PF_LMAC_CREDIT_CC_UNIT_CNT(ct) ( ( ( uint64_t ) (ct) ) << 12 )
  408. #define TXNIC_PF_LMAC_CREDIT_CC_UNIT_CNT_DEFAULT \
  409. TXNIC_PF_LMAC_CREDIT_CC_UNIT_CNT ( 192 )
  410. #define TXNIC_PF_LMAC_CREDIT_CC_PACKET_CNT(ct) ( ( ( uint64_t ) (ct) ) << 2 )
  411. #define TXNIC_PF_LMAC_CREDIT_CC_PACKET_CNT_DEFAULT \
  412. TXNIC_PF_LMAC_CREDIT_CC_PACKET_CNT ( 511 )
  413. #define TXNIC_PF_LMAC_CREDIT_CC_ENABLE ( 1ULL << 1 )
  414. /** Channel registers */
  415. #define TXNIC_PF_CHAN(ch) ( ( (ch) << 3 ) | 0x400000 )
  416. /** Channel transmit configuration */
  417. #define TXNIC_PF_CHAN_TX_CFG 0x000000
  418. #define TXNIC_PF_CHAN_TX_CFG_BP_ENA ( 1ULL << 0 )
  419. /** Channel receive configuration */
  420. #define TXNIC_PF_CHAN_RX_CFG 0x020000
  421. #define TXNIC_PF_CHAN_RX_CFG_CPI_BASE(ix) ( ( ( uint64_t ) (ix) ) << 48 )
  422. /** Channel receive backpressure configuration */
  423. #define TXNIC_PF_CHAN_RX_BP_CFG 0x080000
  424. #define TXNIC_PF_CHAN_RX_BP_CFG_ENA ( 1ULL << 63 )
  425. #define TXNIC_PF_CHAN_RX_BP_CFG_BPID(bp) ( ( ( uint64_t ) (bp) ) << 0 )
  426. /** Traffic limiter 2 configuration */
  427. #define TXNIC_PF_TL2_CFG(tl) ( ( (tl) << 3 ) | 0x500000 )
  428. #define TXNIC_PF_TL2_CFG_RR_QUANTUM(rr) ( ( ( uint64_t ) (rr) ) << 0 )
  429. #define TXNIC_PF_TL2_CFG_RR_QUANTUM_DEFAULT \
  430. TXNIC_PF_TL2_CFG_RR_QUANTUM ( 0x905 )
  431. /** Traffic limiter 3 configuration */
  432. #define TXNIC_PF_TL3_CFG(tl) ( ( (tl) << 3 ) | 0x600000 )
  433. #define TXNIC_PF_TL3_CFG_RR_QUANTUM(rr) ( ( ( uint64_t ) (rr) ) << 0 )
  434. #define TXNIC_PF_TL3_CFG_RR_QUANTUM_DEFAULT \
  435. TXNIC_PF_TL3_CFG_RR_QUANTUM ( 0x905 )
  436. /** Traffic limiter 3 channel mapping */
  437. #define TXNIC_PF_TL3_CHAN(tl) ( ( (tl) << 3 ) | 0x620000 )
  438. #define TXNIC_PF_TL3_CHAN_CHAN(ch) ( ( (ch) & 0x7f ) << 0 )
  439. /** Traffic limiter 4 configuration */
  440. #define TXNIC_PF_TL4_CFG(tl) ( ( (tl) << 3 ) | 0x800000 )
  441. #define TXNIC_PF_TL4_CFG_SQ_QS(qs) ( ( ( uint64_t ) (qs) ) << 27 )
  442. #define TXNIC_PF_TL4_CFG_RR_QUANTUM(rr) ( ( ( uint64_t ) (rr) ) << 0 )
  443. #define TXNIC_PF_TL4_CFG_RR_QUANTUM_DEFAULT \
  444. TXNIC_PF_TL4_CFG_RR_QUANTUM ( 0x905 )
  445. /** Queue set registers */
  446. #define TXNIC_PF_QS(qs) ( ( (qs) << 21 ) | 0x20000000UL )
  447. /** Queue set configuration */
  448. #define TXNIC_PF_QS_CFG 0x010000
  449. #define TXNIC_PF_QS_CFG_ENA ( 1ULL << 31 )
  450. #define TXNIC_PF_QS_CFG_VNIC(vn) ( ( ( uint64_t ) (vn) ) << 0 )
  451. /** Receive queue configuration */
  452. #define TXNIC_PF_QS_RQ_CFG(q) ( ( (q) << 18 ) | 0x010400 )
  453. #define TXNIC_PF_QS_RQ_CFG_CACHING(cx) ( ( ( uint64_t ) (cx) ) << 26 )
  454. #define TXNIC_PF_QS_RQ_CFG_CACHING_ALL \
  455. TXNIC_PF_QS_RQ_CFG_CACHING ( 1 )
  456. #define TXNIC_PF_QS_RQ_CFG_CQ_QS(qs) ( ( ( uint64_t ) (qs) ) << 19 )
  457. #define TXNIC_PF_QS_RQ_CFG_RBDR_CONT_QS(qs) ( ( ( uint64_t ) (qs) ) << 9 )
  458. #define TXNIC_PF_QS_RQ_CFG_RBDR_STRT_QS(qs) ( ( ( uint64_t ) (qs) ) << 1 )
  459. /** Receive queue drop configuration */
  460. #define TXNIC_PF_QS_RQ_DROP_CFG(q) ( ( (q) << 18 ) | 0x010420 )
  461. /** Receive queue backpressure configuration */
  462. #define TXNIC_PF_QS_RQ_BP_CFG(q) ( ( (q) << 18 ) | 0x010500 )
  463. #define TXNIC_PF_QS_RQ_BP_CFG_RBDR_BP_ENA ( 1ULL << 63 )
  464. #define TXNIC_PF_QS_RQ_BP_CFG_CQ_BP_ENA ( 1ULL << 62 )
  465. #define TXNIC_PF_QS_RQ_BP_CFG_BPID(bp) ( ( ( uint64_t ) (bp) ) << 0 )
  466. /** Send queue configuration */
  467. #define TXNIC_PF_QS_SQ_CFG(q) ( ( (q) << 18 ) | 0x010c00 )
  468. #define TXNIC_PF_QS_SQ_CFG_CQ_QS(qs) ( ( ( uint64_t ) (qs) ) << 3 )
  469. /** Send queue configuration 2 */
  470. #define TXNIC_PF_QS_SQ_CFG2(q) ( ( (q) << 18 ) | 0x010c08 )
  471. #define TXNIC_PF_QS_SQ_CFG2_TL4(tl) ( ( ( uint64_t ) (tl) ) << 0 )
  472. /** A physical function */
  473. struct txnic_pf {
  474. /** Registers */
  475. void *regs;
  476. /** PCI device */
  477. struct pci_device *pci;
  478. /** Node ID */
  479. unsigned int node;
  480. /** Virtual function BAR base */
  481. unsigned long vf_membase;
  482. /** Virtual function BAR stride */
  483. unsigned long vf_stride;
  484. /** List of physical functions */
  485. struct list_head list;
  486. /** BGX Ethernet interfaces (if known) */
  487. struct txnic_bgx *bgx[TXNIC_NUM_BGX];
  488. };
  489. /**
  490. * Calculate virtual NIC index
  491. *
  492. * @v bgx_idx BGX Ethernet interface index
  493. * @v lmac_idx Logical MAC index
  494. * @ret vnic_idx Virtual NIC index
  495. */
  496. #define TXNIC_VNIC_IDX( bgx_idx, lmac_idx ) \
  497. ( ( (bgx_idx) * TXNIC_NUM_LMAC ) + (lmac_idx) )
  498. /**
  499. * Calculate BGX Ethernet interface index
  500. *
  501. * @v vnic_idx Virtual NIC index
  502. * @ret bgx_idx BGX Ethernet interface index
  503. */
  504. #define TXNIC_BGX_IDX( vnic_idx ) ( (vnic_idx) / TXNIC_NUM_LMAC )
  505. /**
  506. * Calculate logical MAC index
  507. *
  508. * @v vnic_idx Virtual NIC index
  509. * @ret lmac_idx Logical MAC index
  510. */
  511. #define TXNIC_LMAC_IDX( vnic_idx ) ( (vnic_idx) % TXNIC_NUM_LMAC )
  512. /**
  513. * Calculate traffic limiter 2 index
  514. *
  515. * @v vnic_idx Virtual NIC index
  516. * @v tl2_idx Traffic limiter 2 index
  517. */
  518. #define TXNIC_TL2_IDX( vnic_idx ) ( (vnic_idx) << 3 )
  519. /**
  520. * Calculate traffic limiter 3 index
  521. *
  522. * @v vnic_idx Virtual NIC index
  523. * @v tl3_idx Traffic limiter 3 index
  524. */
  525. #define TXNIC_TL3_IDX( vnic_idx ) ( (vnic_idx) << 5 )
  526. /**
  527. * Calculate traffic limiter 4 index
  528. *
  529. * @v vnic_idx Virtual NIC index
  530. * @v tl4_idx Traffic limiter 4 index
  531. */
  532. #define TXNIC_TL4_IDX( vnic_idx ) ( (vnic_idx) << 7 )
  533. /**
  534. * Calculate channel index
  535. *
  536. * @v vnic_idx Virtual NIC index
  537. * @v chan_idx Channel index
  538. */
  539. #define TXNIC_CHAN_IDX( vnic_idx ) ( ( TXNIC_BGX_IDX (vnic_idx) << 7 ) | \
  540. ( TXNIC_LMAC_IDX (vnic_idx) << 4 ) )
  541. /******************************************************************************
  542. *
  543. * BGX Ethernet interface
  544. *
  545. ******************************************************************************
  546. */
  547. /** Per-LMAC registers */
  548. #define BGX_LMAC(lm) ( ( (lm) << 20 ) | 0x00000000UL )
  549. /** CMR configuration */
  550. #define BGX_CMR_CONFIG 0x000000
  551. #define BGX_CMR_CONFIG_ENABLE ( 1ULL << 15 )
  552. #define BGX_CMR_CONFIG_DATA_PKT_RX_EN ( 1ULL << 14 )
  553. #define BGX_CMR_CONFIG_DATA_PKT_TX_EN ( 1ULL << 13 )
  554. #define BGX_CMR_CONFIG_LMAC_TYPE_GET(config) \
  555. ( ( (config) >> 8 ) & 0x7 )
  556. #define BGX_CMR_CONFIG_LMAC_TYPE_SET(ty) ( ( ( uint64_t ) (ty) ) << 8 )
  557. #define BGX_CMR_CONFIG_LANE_TO_SDS(ls) ( ( ( uint64_t ) (ls) ) << 0 )
  558. /** CMR global configuration */
  559. #define BGX_CMR_GLOBAL_CONFIG 0x000008
  560. #define BGX_CMR_GLOBAL_CONFIG_FCS_STRIP ( 1ULL << 6 )
  561. /** CMR receive statistics 0 */
  562. #define BGX_CMR_RX_STAT0 0x000070
  563. /** CMR receive statistics 1 */
  564. #define BGX_CMR_RX_STAT1 0x000078
  565. /** CMR receive statistics 2 */
  566. #define BGX_CMR_RX_STAT2 0x000080
  567. /** CMR receive statistics 3 */
  568. #define BGX_CMR_RX_STAT3 0x000088
  569. /** CMR receive statistics 4 */
  570. #define BGX_CMR_RX_STAT4 0x000090
  571. /** CMR receive statistics 5 */
  572. #define BGX_CMR_RX_STAT5 0x000098
  573. /** CMR receive statistics 6 */
  574. #define BGX_CMR_RX_STAT6 0x0000a0
  575. /** CMR receive statistics 7 */
  576. #define BGX_CMR_RX_STAT7 0x0000a8
  577. /** CMR receive statistics 8 */
  578. #define BGX_CMR_RX_STAT8 0x0000b0
  579. /** CMR receive statistics 9 */
  580. #define BGX_CMR_RX_STAT9 0x0000b8
  581. /** CMR receive statistics 10 */
  582. #define BGX_CMR_RX_STAT10 0x0000c0
  583. /** CMR destination MAC control */
  584. #define BGX_CMR_RX_DMAC_CTL 0x0000e8
  585. #define BGX_CMR_RX_DMAC_CTL_MCST_MODE(md) ( ( ( uint64_t ) (md) ) << 1 )
  586. #define BGX_CMR_RX_DMAC_CTL_MCST_MODE_ACCEPT \
  587. BGX_CMR_RX_DMAC_CTL_MCST_MODE ( 1 )
  588. #define BGX_CMR_RX_DMAC_CTL_BCST_ACCEPT ( 1ULL << 0 )
  589. /** CMR destination MAC CAM */
  590. #define BGX_CMR_RX_DMAC_CAM(i) ( ( (i) << 3 ) | 0x000200 )
  591. /** CMR receive steering */
  592. #define BGX_CMR_RX_STEERING(i) ( ( (i) << 3 ) | 0x000300 )
  593. /** CMR backpressure channel mask AND */
  594. #define BGX_CMR_CHAN_MSK_AND 0x000450
  595. #define BGX_CMR_CHAN_MSK_AND_ALL(count) \
  596. ( 0xffffffffffffffffULL >> ( 16 * ( 4 - (count) ) ) )
  597. /** CMR transmit statistics 0 */
  598. #define BGX_CMR_TX_STAT0 0x000600
  599. /** CMR transmit statistics 1 */
  600. #define BGX_CMR_TX_STAT1 0x000608
  601. /** CMR transmit statistics 2 */
  602. #define BGX_CMR_TX_STAT2 0x000610
  603. /** CMR transmit statistics 3 */
  604. #define BGX_CMR_TX_STAT3 0x000618
  605. /** CMR transmit statistics 4 */
  606. #define BGX_CMR_TX_STAT4 0x000620
  607. /** CMR transmit statistics 5 */
  608. #define BGX_CMR_TX_STAT5 0x000628
  609. /** CMR transmit statistics 6 */
  610. #define BGX_CMR_TX_STAT6 0x000630
  611. /** CMR transmit statistics 7 */
  612. #define BGX_CMR_TX_STAT7 0x000638
  613. /** CMR transmit statistics 8 */
  614. #define BGX_CMR_TX_STAT8 0x000640
  615. /** CMR transmit statistics 9 */
  616. #define BGX_CMR_TX_STAT9 0x000648
  617. /** CMR transmit statistics 10 */
  618. #define BGX_CMR_TX_STAT10 0x000650
  619. /** CMR transmit statistics 11 */
  620. #define BGX_CMR_TX_STAT11 0x000658
  621. /** CMR transmit statistics 12 */
  622. #define BGX_CMR_TX_STAT12 0x000660
  623. /** CMR transmit statistics 13 */
  624. #define BGX_CMR_TX_STAT13 0x000668
  625. /** CMR transmit statistics 14 */
  626. #define BGX_CMR_TX_STAT14 0x000670
  627. /** CMR transmit statistics 15 */
  628. #define BGX_CMR_TX_STAT15 0x000678
  629. /** CMR transmit statistics 16 */
  630. #define BGX_CMR_TX_STAT16 0x000680
  631. /** CMR transmit statistics 17 */
  632. #define BGX_CMR_TX_STAT17 0x000688
  633. /** CMR receive logical MACs */
  634. #define BGX_CMR_RX_LMACS 0x000468
  635. #define BGX_CMR_RX_LMACS_LMACS_GET(lmacs) \
  636. ( ( (lmacs) >> 0 ) & 0x7 )
  637. #define BGX_CMR_RX_LMACS_LMACS_SET(ct) ( ( ( uint64_t ) (ct) ) << 0 )
  638. /** CMR transmit logical MACs */
  639. #define BGX_CMR_TX_LMACS 0x001000
  640. #define BGX_CMR_TX_LMACS_LMACS_GET(lmacs) \
  641. ( ( (lmacs) >> 0 ) & 0x7 )
  642. #define BGX_CMR_TX_LMACS_LMACS_SET(ct) ( ( ( uint64_t ) (ct) ) << 0 )
  643. /** SPU control 1 */
  644. #define BGX_SPU_CONTROL1 0x010000
  645. #define BGX_SPU_CONTROL1_RESET ( 1ULL << 15 )
  646. #define BGX_SPU_CONTROL1_LO_PWR ( 1ULL << 11 )
  647. /** SPU reset delay */
  648. #define BGX_SPU_RESET_DELAY_MS 10
  649. /** SPU status 1 */
  650. #define BGX_SPU_STATUS1 0x010008
  651. #define BGX_SPU_STATUS1_FLT ( 1ULL << 7 )
  652. #define BGX_SPU_STATUS1_RCV_LNK ( 1ULL << 2 )
  653. /** SPU status 2 */
  654. #define BGX_SPU_STATUS2 0x010020
  655. #define BGX_SPU_STATUS2_RCVFLT ( 1ULL << 10 )
  656. /** SPU BASE-R status 1 */
  657. #define BGX_SPU_BR_STATUS1 0x010030
  658. #define BGX_SPU_BR_STATUS1_RCV_LNK ( 1ULL << 12 )
  659. #define BGX_SPU_BR_STATUS1_HI_BER ( 1ULL << 1 )
  660. #define BGX_SPU_BR_STATUS1_BLK_LOCK ( 1ULL << 0 )
  661. /** SPU BASE-R status 2 */
  662. #define BGX_SPU_BR_STATUS2 0x010038
  663. #define BGX_SPU_BR_STATUS2_LATCHED_LOCK ( 1ULL << 15 )
  664. #define BGX_SPU_BR_STATUS2_LATCHED_BER ( 1ULL << 14 )
  665. /** SPU BASE-R alignment status */
  666. #define BGX_SPU_BR_ALGN_STATUS 0x010050
  667. #define BGX_SPU_BR_ALGN_STATUS_ALIGND ( 1ULL << 12 )
  668. /** SPU BASE-R link training control */
  669. #define BGX_SPU_BR_PMD_CONTROL 0x010068
  670. #define BGX_SPU_BR_PMD_CONTROL_TRAIN_EN ( 1ULL << 1 )
  671. /** SPU BASE-R link training status */
  672. #define BGX_SPU_BR_PMD_STATUS 0x010070
  673. /** SPU link partner coefficient update */
  674. #define BGX_SPU_BR_PMD_LP_CUP 0x010078
  675. /** SPU local device coefficient update */
  676. #define BGX_SPU_BR_PMD_LD_CUP 0x010088
  677. /** SPU local device status report */
  678. #define BGX_SPU_BR_PMD_LD_REP 0x010090
  679. /** SPU forward error correction control */
  680. #define BGX_SPU_FEC_CONTROL 0x0100a0
  681. /** SPU autonegotation control */
  682. #define BGX_SPU_AN_CONTROL 0x0100c8
  683. /** SPU autonegotiation status */
  684. #define BGX_SPU_AN_STATUS 0x0100d0
  685. #define BGX_SPU_AN_STATUS_XNP_STAT ( 1ULL << 7 )
  686. #define BGX_SPU_AN_STATUS_PAGE_RX ( 1ULL << 6 )
  687. #define BGX_SPU_AN_STATUS_AN_COMPLETE ( 1ULL << 5 )
  688. #define BGX_SPU_AN_STATUS_LINK_STATUS ( 1ULL << 2 )
  689. #define BGX_SPU_AN_STATUS_LP_AN_ABLE ( 1ULL << 0 )
  690. /** SPU interrupt */
  691. #define BGX_SPU_INT 0x010220
  692. #define BGX_SPU_INT_TRAINING_FAIL ( 1ULL << 14 )
  693. #define BGX_SPU_INT_TRAINING_DONE ( 1ULL << 13 )
  694. #define BGX_SPU_INT_AN_COMPLETE ( 1ULL << 12 )
  695. #define BGX_SPU_INT_AN_LINK_GOOD ( 1ULL << 11 )
  696. #define BGX_SPU_INT_AN_PAGE_RX ( 1ULL << 10 )
  697. #define BGX_SPU_INT_FEC_UNCORR ( 1ULL << 9 )
  698. #define BGX_SPU_INT_FEC_CORR ( 1ULL << 8 )
  699. #define BGX_SPU_INT_BIP_ERR ( 1ULL << 7 )
  700. #define BGX_SPU_INT_DBG_SYNC ( 1ULL << 6 )
  701. #define BGX_SPU_INT_ALGNLOS ( 1ULL << 5 )
  702. #define BGX_SPU_INT_SYNLOS ( 1ULL << 4 )
  703. #define BGX_SPU_INT_BITLCKLS ( 1ULL << 3 )
  704. #define BGX_SPU_INT_ERR_BLK ( 1ULL << 2 )
  705. #define BGX_SPU_INT_RX_LINK_DOWN ( 1ULL << 1 )
  706. #define BGX_SPU_INT_RX_LINK_UP ( 1ULL << 0 )
  707. /** LMAC types */
  708. enum txnic_lmac_types {
  709. TXNIC_LMAC_SGMII = 0x0, /**< SGMII/1000BASE-X */
  710. TXNIC_LMAC_XAUI = 0x1, /**< 10GBASE-X/XAUI or DXAUI */
  711. TXNIC_LMAC_RXAUI = 0x2, /**< Reduced XAUI */
  712. TXNIC_LMAC_10G_R = 0x3, /**< 10GBASE-R */
  713. TXNIC_LMAC_40G_R = 0x4, /**< 40GBASE-R */
  714. };
  715. /** An LMAC type */
  716. struct txnic_lmac_type {
  717. /** Name */
  718. const char *name;
  719. /** Number of LMACs */
  720. uint8_t count;
  721. /** Lane-to-SDS mapping */
  722. uint32_t lane_to_sds;
  723. };
  724. /** An LMAC address */
  725. union txnic_lmac_address {
  726. struct {
  727. uint8_t pad[2];
  728. uint8_t raw[ETH_ALEN];
  729. } __attribute__ (( packed ));
  730. uint64_t be64;
  731. };
  732. /** A Logical MAC (LMAC) */
  733. struct txnic_lmac {
  734. /** Registers */
  735. void *regs;
  736. /** Containing BGX Ethernet interface */
  737. struct txnic_bgx *bgx;
  738. /** Virtual NIC index */
  739. unsigned int idx;
  740. /** MAC address */
  741. union txnic_lmac_address mac;
  742. /** Virtual NIC (if applicable) */
  743. struct txnic *vnic;
  744. };
  745. /** A BGX Ethernet interface */
  746. struct txnic_bgx {
  747. /** Registers */
  748. void *regs;
  749. /** PCI device */
  750. struct pci_device *pci;
  751. /** Node ID */
  752. unsigned int node;
  753. /** BGX index */
  754. unsigned int idx;
  755. /** LMAC type */
  756. struct txnic_lmac_type *type;
  757. /** Number of LMACs */
  758. unsigned int count;
  759. /** Link training is in use */
  760. int training;
  761. /** List of BGX Ethernet interfaces */
  762. struct list_head list;
  763. /** Physical function (if known) */
  764. struct txnic_pf *pf;
  765. /** Logical MACs */
  766. struct txnic_lmac lmac[TXNIC_NUM_LMAC];
  767. };
  768. #endif /* _THUNDERX_H */