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.

intelxl.h 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. #ifndef _INTELX_H
  2. #define _INTELX_H
  3. /** @file
  4. *
  5. * Intel 40 Gigabit Ethernet network card driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/if_ether.h>
  11. struct intelxl_nic;
  12. /** BAR size */
  13. #define INTELXL_BAR_SIZE 0x200000
  14. /** Alignment
  15. *
  16. * No data structure requires greater than 128 byte alignment.
  17. */
  18. #define INTELXL_ALIGN 128
  19. /******************************************************************************
  20. *
  21. * Admin queue
  22. *
  23. ******************************************************************************
  24. */
  25. /** PF Admin Command Queue register block */
  26. #define INTELXL_ADMIN_CMD 0x080000
  27. /** PF Admin Event Queue register block */
  28. #define INTELXL_ADMIN_EVT 0x080080
  29. /** Admin Queue Base Address Low Register (offset) */
  30. #define INTELXL_ADMIN_BAL 0x000
  31. /** Admin Queue Base Address High Register (offset) */
  32. #define INTELXL_ADMIN_BAH 0x100
  33. /** Admin Queue Length Register (offset) */
  34. #define INTELXL_ADMIN_LEN 0x200
  35. #define INTELXL_ADMIN_LEN_LEN(x) ( (x) << 0 ) /**< Queue length */
  36. #define INTELXL_ADMIN_LEN_ENABLE 0x80000000UL /**< Queue enable */
  37. /** Admin Queue Head Register (offset) */
  38. #define INTELXL_ADMIN_HEAD 0x300
  39. /** Admin Queue Tail Register (offset) */
  40. #define INTELXL_ADMIN_TAIL 0x400
  41. /** Admin queue data buffer command parameters */
  42. struct intelxl_admin_buffer_params {
  43. /** Reserved */
  44. uint8_t reserved[8];
  45. /** Buffer address high */
  46. uint32_t high;
  47. /** Buffer address low */
  48. uint32_t low;
  49. } __attribute__ (( packed ));
  50. /** Admin queue Get Version command */
  51. #define INTELXL_ADMIN_VERSION 0x0001
  52. /** Admin queue version number */
  53. struct intelxl_admin_version {
  54. /** Major version number */
  55. uint16_t major;
  56. /** Minor version number */
  57. uint16_t minor;
  58. } __attribute__ (( packed ));
  59. /** Admin queue Get Version command parameters */
  60. struct intelxl_admin_version_params {
  61. /** ROM version */
  62. uint32_t rom;
  63. /** Firmware build ID */
  64. uint32_t build;
  65. /** Firmware version */
  66. struct intelxl_admin_version firmware;
  67. /** API version */
  68. struct intelxl_admin_version api;
  69. } __attribute__ (( packed ));
  70. /** Admin queue Driver Version command */
  71. #define INTELXL_ADMIN_DRIVER 0x0002
  72. /** Admin queue Driver Version command parameters */
  73. struct intelxl_admin_driver_params {
  74. /** Driver version */
  75. uint8_t major;
  76. /** Minor version */
  77. uint8_t minor;
  78. /** Build version */
  79. uint8_t build;
  80. /** Sub-build version */
  81. uint8_t sub;
  82. /** Reserved */
  83. uint8_t reserved[4];
  84. /** Data buffer address */
  85. uint64_t address;
  86. } __attribute__ (( packed ));
  87. /** Admin queue Driver Version data buffer */
  88. struct intelxl_admin_driver_buffer {
  89. /** Driver name */
  90. char name[32];
  91. } __attribute__ (( packed ));
  92. /** Admin queue Shutdown command */
  93. #define INTELXL_ADMIN_SHUTDOWN 0x0003
  94. /** Admin queue Shutdown command parameters */
  95. struct intelxl_admin_shutdown_params {
  96. /** Driver unloading */
  97. uint8_t unloading;
  98. /** Reserved */
  99. uint8_t reserved[15];
  100. } __attribute__ (( packed ));
  101. /** Driver is unloading */
  102. #define INTELXL_ADMIN_SHUTDOWN_UNLOADING 0x01
  103. /** Admin queue Get Switch Configuration command */
  104. #define INTELXL_ADMIN_SWITCH 0x0200
  105. /** Switching element configuration */
  106. struct intelxl_admin_switch_config {
  107. /** Switching element type */
  108. uint8_t type;
  109. /** Revision */
  110. uint8_t revision;
  111. /** Switching element ID */
  112. uint16_t seid;
  113. /** Uplink switching element ID */
  114. uint16_t uplink;
  115. /** Downlink switching element ID */
  116. uint16_t downlink;
  117. /** Reserved */
  118. uint8_t reserved_b[3];
  119. /** Connection type */
  120. uint8_t connection;
  121. /** Reserved */
  122. uint8_t reserved_c[2];
  123. /** Element specific information */
  124. uint16_t info;
  125. } __attribute__ (( packed ));
  126. /** Virtual Station Inferface element type */
  127. #define INTELXL_ADMIN_SWITCH_TYPE_VSI 19
  128. /** Admin queue Get Switch Configuration command parameters */
  129. struct intelxl_admin_switch_params {
  130. /** Starting switching element identifier */
  131. uint16_t next;
  132. /** Reserved */
  133. uint8_t reserved[6];
  134. /** Data buffer address */
  135. uint64_t address;
  136. } __attribute__ (( packed ));
  137. /** Admin queue Get Switch Configuration data buffer */
  138. struct intelxl_admin_switch_buffer {
  139. /** Number of switching elements reported */
  140. uint16_t count;
  141. /** Total number of switching elements */
  142. uint16_t total;
  143. /** Reserved */
  144. uint8_t reserved_a[12];
  145. /** Switch configuration */
  146. struct intelxl_admin_switch_config cfg;
  147. } __attribute__ (( packed ));
  148. /** Admin queue Get VSI Parameters command */
  149. #define INTELXL_ADMIN_VSI 0x0212
  150. /** Admin queue Get VSI Parameters command parameters */
  151. struct intelxl_admin_vsi_params {
  152. /** VSI switching element ID */
  153. uint16_t vsi;
  154. /** Reserved */
  155. uint8_t reserved[6];
  156. /** Data buffer address */
  157. uint64_t address;
  158. } __attribute__ (( packed ));
  159. /** Admin queue Get VSI Parameters data buffer */
  160. struct intelxl_admin_vsi_buffer {
  161. /** Reserved */
  162. uint8_t reserved_a[30];
  163. /** Queue numbers */
  164. uint16_t queue[16];
  165. /** Reserved */
  166. uint8_t reserved_b[34];
  167. /** Queue set handles for each traffic class */
  168. uint16_t qset[8];
  169. /** Reserved */
  170. uint8_t reserved_c[16];
  171. } __attribute__ (( packed ));
  172. /** Admin queue Set VSI Promiscuous Modes command */
  173. #define INTELXL_ADMIN_PROMISC 0x0254
  174. /** Admin queue Set VSI Promiscuous Modes command parameters */
  175. struct intelxl_admin_promisc_params {
  176. /** Flags */
  177. uint16_t flags;
  178. /** Valid flags */
  179. uint16_t valid;
  180. /** VSI switching element ID */
  181. uint16_t vsi;
  182. /** Reserved */
  183. uint8_t reserved[10];
  184. } __attribute__ (( packed ));
  185. /** Promiscuous unicast mode */
  186. #define INTELXL_ADMIN_PROMISC_FL_UNICAST 0x0001
  187. /** Promiscuous multicast mode */
  188. #define INTELXL_ADMIN_PROMISC_FL_MULTICAST 0x0002
  189. /** Promiscuous broadcast mode */
  190. #define INTELXL_ADMIN_PROMISC_FL_BROADCAST 0x0004
  191. /** Promiscuous VLAN mode */
  192. #define INTELXL_ADMIN_PROMISC_FL_VLAN 0x0010
  193. /** Admin queue Restart Autonegotiation command */
  194. #define INTELXL_ADMIN_AUTONEG 0x0605
  195. /** Admin queue Restart Autonegotiation command parameters */
  196. struct intelxl_admin_autoneg_params {
  197. /** Flags */
  198. uint8_t flags;
  199. /** Reserved */
  200. uint8_t reserved[15];
  201. } __attribute__ (( packed ));
  202. /** Restart autonegotiation */
  203. #define INTELXL_ADMIN_AUTONEG_FL_RESTART 0x02
  204. /** Enable link */
  205. #define INTELXL_ADMIN_AUTONEG_FL_ENABLE 0x04
  206. /** Admin queue Get Link Status command */
  207. #define INTELXL_ADMIN_LINK 0x0607
  208. /** Admin queue Get Link Status command parameters */
  209. struct intelxl_admin_link_params {
  210. /** Link status notification */
  211. uint8_t notify;
  212. /** Reserved */
  213. uint8_t reserved_a;
  214. /** PHY type */
  215. uint8_t phy;
  216. /** Link speed */
  217. uint8_t speed;
  218. /** Link status */
  219. uint8_t status;
  220. /** Reserved */
  221. uint8_t reserved_b[11];
  222. } __attribute__ (( packed ));
  223. /** Notify driver of link status changes */
  224. #define INTELXL_ADMIN_LINK_NOTIFY 0x03
  225. /** Link is up */
  226. #define INTELXL_ADMIN_LINK_UP 0x01
  227. /** Admin queue command parameters */
  228. union intelxl_admin_params {
  229. /** Additional data buffer command parameters */
  230. struct intelxl_admin_buffer_params buffer;
  231. /** Get Version command parameters */
  232. struct intelxl_admin_version_params version;
  233. /** Driver Version command parameters */
  234. struct intelxl_admin_driver_params driver;
  235. /** Shutdown command parameters */
  236. struct intelxl_admin_shutdown_params shutdown;
  237. /** Get Switch Configuration command parameters */
  238. struct intelxl_admin_switch_params sw;
  239. /** Get VSI Parameters command parameters */
  240. struct intelxl_admin_vsi_params vsi;
  241. /** Set VSI Promiscuous Modes command parameters */
  242. struct intelxl_admin_promisc_params promisc;
  243. /** Restart Autonegotiation command parameters */
  244. struct intelxl_admin_autoneg_params autoneg;
  245. /** Get Link Status command parameters */
  246. struct intelxl_admin_link_params link;
  247. } __attribute__ (( packed ));
  248. /** Admin queue data buffer */
  249. union intelxl_admin_buffer {
  250. /** Driver Version data buffer */
  251. struct intelxl_admin_driver_buffer driver;
  252. /** Get Switch Configuration data buffer */
  253. struct intelxl_admin_switch_buffer sw;
  254. /** Get VSI Parameters data buffer */
  255. struct intelxl_admin_vsi_buffer vsi;
  256. } __attribute__ (( packed ));
  257. /** Admin queue descriptor */
  258. struct intelxl_admin_descriptor {
  259. /** Flags */
  260. uint16_t flags;
  261. /** Opcode */
  262. uint16_t opcode;
  263. /** Data length */
  264. uint16_t len;
  265. /** Return value */
  266. uint16_t ret;
  267. /** Cookie */
  268. uint32_t cookie;
  269. /** Reserved */
  270. uint32_t reserved;
  271. /** Parameters */
  272. union intelxl_admin_params params;
  273. } __attribute__ (( packed ));
  274. /** Admin descriptor done */
  275. #define INTELXL_ADMIN_FL_DD 0x0001
  276. /** Admin descriptor contains a completion */
  277. #define INTELXL_ADMIN_FL_CMP 0x0002
  278. /** Admin descriptor completed in error */
  279. #define INTELXL_ADMIN_FL_ERR 0x0004
  280. /** Admin descriptor uses data buffer for command parameters */
  281. #define INTELXL_ADMIN_FL_RD 0x0400
  282. /** Admin descriptor uses data buffer */
  283. #define INTELXL_ADMIN_FL_BUF 0x1000
  284. /** Admin queue */
  285. struct intelxl_admin {
  286. /** Descriptors */
  287. struct intelxl_admin_descriptor *desc;
  288. /** Queue index */
  289. unsigned int index;
  290. /** Register block */
  291. unsigned int reg;
  292. /** Data buffer */
  293. union intelxl_admin_buffer *buffer;
  294. };
  295. /**
  296. * Initialise admin queue
  297. *
  298. * @v admin Admin queue
  299. * @v reg Register block
  300. */
  301. static inline __attribute__ (( always_inline )) void
  302. intelxl_init_admin ( struct intelxl_admin *admin, unsigned int reg ) {
  303. admin->reg = reg;
  304. }
  305. /** Number of admin queue descriptors */
  306. #define INTELXL_ADMIN_NUM_DESC 4
  307. /** Maximum time to wait for an admin request to complete */
  308. #define INTELXL_ADMIN_MAX_WAIT_MS 100
  309. /** Admin queue API major version */
  310. #define INTELXL_ADMIN_API_MAJOR 1
  311. /******************************************************************************
  312. *
  313. * Transmit and receive queue context
  314. *
  315. ******************************************************************************
  316. */
  317. /** CMLAN Context Data Register */
  318. #define INTELXL_PFCM_LANCTXDATA(x) ( 0x10c100 + ( 0x80 * (x) ) )
  319. /** CMLAN Context Control Register */
  320. #define INTELXL_PFCM_LANCTXCTL 0x10c300
  321. #define INTELXL_PFCM_LANCTXCTL_QUEUE_NUM(x) \
  322. ( (x) << 0 ) /**< Queue number */
  323. #define INTELXL_PFCM_LANCTXCTL_SUB_LINE(x) \
  324. ( (x) << 12 ) /**< Sub-line */
  325. #define INTELXL_PFCM_LANCTXCTL_TYPE(x) \
  326. ( (x) << 15 ) /**< Queue type */
  327. #define INTELXL_PFCM_LANCTXCTL_TYPE_RX \
  328. INTELXL_PFCM_LANCTXCTL_TYPE ( 0x0 ) /**< RX queue type */
  329. #define INTELXL_PFCM_LANCTXCTL_TYPE_TX \
  330. INTELXL_PFCM_LANCTXCTL_TYPE ( 0x1 ) /**< TX queue type */
  331. #define INTELXL_PFCM_LANCTXCTL_OP_CODE(x) \
  332. ( (x) << 17 ) /**< Op code */
  333. #define INTELXL_PFCM_LANCTXCTL_OP_CODE_READ \
  334. INTELXL_PFCM_LANCTXCTL_OP_CODE ( 0x0 ) /**< Read context */
  335. #define INTELXL_PFCM_LANCTXCTL_OP_CODE_WRITE \
  336. INTELXL_PFCM_LANCTXCTL_OP_CODE ( 0x1 ) /**< Write context */
  337. /** CMLAN Context Status Register */
  338. #define INTELXL_PFCM_LANCTXSTAT 0x10c380
  339. #define INTELXL_PFCM_LANCTXSTAT_DONE 0x00000001UL /**< Complete */
  340. /** Queue context line */
  341. struct intelxl_context_line {
  342. /** Raw data */
  343. uint32_t raw[4];
  344. } __attribute__ (( packed ));
  345. /** Transmit queue context */
  346. struct intelxl_context_tx {
  347. /** Head pointer */
  348. uint16_t head;
  349. /** Flags */
  350. uint16_t flags;
  351. /** Base address */
  352. uint64_t base;
  353. /** Reserved */
  354. uint8_t reserved_a[8];
  355. /** Queue count */
  356. uint16_t count;
  357. /** Reserved */
  358. uint8_t reserved_b[100];
  359. /** Queue set */
  360. uint16_t qset;
  361. /** Reserved */
  362. uint8_t reserved_c[4];
  363. } __attribute__ (( packed ));
  364. /** New transmit queue context */
  365. #define INTELXL_CTX_TX_FL_NEW 0x4000
  366. /** Transmit queue base address */
  367. #define INTELXL_CTX_TX_BASE( base ) ( (base) >> 7 )
  368. /** Transmit queue count */
  369. #define INTELXL_CTX_TX_COUNT( count ) ( (count) << 1 )
  370. /** Transmit queue set */
  371. #define INTELXL_CTX_TX_QSET( qset) ( (qset) << 4 )
  372. /** Receive queue context */
  373. struct intelxl_context_rx {
  374. /** Head pointer */
  375. uint16_t head;
  376. /** Reserved */
  377. uint8_t reserved_a[2];
  378. /** Base address and queue count */
  379. uint64_t base_count;
  380. /** Data buffer length */
  381. uint16_t len;
  382. /** Flags */
  383. uint8_t flags;
  384. /** Reserved */
  385. uint8_t reserved_b[7];
  386. /** Maximum frame size */
  387. uint16_t mfs;
  388. } __attribute__ (( packed ));
  389. /** Receive queue base address and queue count */
  390. #define INTELXL_CTX_RX_BASE_COUNT( base, count ) \
  391. ( ( (base) >> 7 ) | ( ( ( uint64_t ) (count) ) << 57 ) )
  392. /** Receive queue data buffer length */
  393. #define INTELXL_CTX_RX_LEN( len ) ( (len) >> 1 )
  394. /** Strip CRC from received packets */
  395. #define INTELXL_CTX_RX_FL_CRCSTRIP 0x20
  396. /** Receive queue maximum frame size */
  397. #define INTELXL_CTX_RX_MFS( mfs ) ( (mfs) >> 2 )
  398. /** Maximum time to wait for a context operation to complete */
  399. #define INTELXL_CTX_MAX_WAIT_MS 100
  400. /** Time to wait for a queue to become enabled */
  401. #define INTELXL_QUEUE_ENABLE_DELAY_US 20
  402. /** Time to wait for a transmit queue to become pre-disabled */
  403. #define INTELXL_QUEUE_PRE_DISABLE_DELAY_US 400
  404. /** Maximum time to wait for a queue to become disabled */
  405. #define INTELXL_QUEUE_DISABLE_MAX_WAIT_MS 1000
  406. /******************************************************************************
  407. *
  408. * Transmit and receive descriptors
  409. *
  410. ******************************************************************************
  411. */
  412. /** Global Transmit Queue Head register */
  413. #define INTELXL_QTX_HEAD(x) ( 0x0e4000 + ( 0x4 * (x) ) )
  414. /** Global Transmit Pre Queue Disable register */
  415. #define INTELXL_GLLAN_TXPRE_QDIS(x) ( 0x0e6500 + ( 0x4 * ( (x) / 0x80 ) ) )
  416. #define INTELXL_GLLAN_TXPRE_QDIS_QINDX(x) \
  417. ( (x) << 0 ) /**< Queue index */
  418. #define INTELXL_GLLAN_TXPRE_QDIS_SET_QDIS \
  419. 0x40000000UL /**< Set disable */
  420. #define INTELXL_GLLAN_TXPRE_QDIS_CLEAR_QDIS \
  421. 0x80000000UL /**< Clear disable */
  422. /** Global Transmit Queue register block */
  423. #define INTELXL_QTX(x) ( 0x100000 + ( 0x4 * (x) ) )
  424. /** Global Receive Queue register block */
  425. #define INTELXL_QRX(x) ( 0x120000 + ( 0x4 * (x) ) )
  426. /** Queue Enable Register (offset) */
  427. #define INTELXL_QXX_ENA 0x0000
  428. #define INTELXL_QXX_ENA_REQ 0x00000001UL /**< Enable request */
  429. #define INTELXL_QXX_ENA_STAT 0x00000004UL /**< Enabled status */
  430. /** Queue Control Register (offset) */
  431. #define INTELXL_QXX_CTL 0x4000
  432. #define INTELXL_QXX_CTL_PFVF_Q(x) ( (x) << 0 ) /**< PF/VF queue */
  433. #define INTELXL_QXX_CTL_PFVF_Q_PF \
  434. INTELXL_QXX_CTL_PFVF_Q ( 0x2 ) /**< PF queue */
  435. #define INTELXL_QXX_CTL_PFVF_PF_INDX(x) ( (x) << 2 ) /**< PF index */
  436. /** Queue Tail Pointer Register (offset) */
  437. #define INTELXL_QXX_TAIL 0x8000
  438. /** Transmit data descriptor */
  439. struct intelxl_tx_data_descriptor {
  440. /** Buffer address */
  441. uint64_t address;
  442. /** Flags */
  443. uint32_t flags;
  444. /** Length */
  445. uint32_t len;
  446. } __attribute__ (( packed ));
  447. /** Transmit data descriptor type */
  448. #define INTELXL_TX_DATA_DTYP 0x0
  449. /** Transmit data descriptor end of packet */
  450. #define INTELXL_TX_DATA_EOP 0x10
  451. /** Transmit data descriptor report status */
  452. #define INTELXL_TX_DATA_RS 0x20
  453. /** Transmit data descriptor pretty please
  454. *
  455. * This bit is completely missing from older versions of the XL710
  456. * datasheet. Later versions describe it innocuously as "reserved,
  457. * must be 1". Without this bit, everything will appear to work (up
  458. * to and including the port "transmit good octets" counter), but no
  459. * packet will actually be sent.
  460. */
  461. #define INTELXL_TX_DATA_JFDI 0x40
  462. /** Transmit data descriptor length */
  463. #define INTELXL_TX_DATA_LEN( len ) ( (len) << 2 )
  464. /** Transmit writeback descriptor */
  465. struct intelxl_tx_writeback_descriptor {
  466. /** Reserved */
  467. uint8_t reserved_a[8];
  468. /** Flags */
  469. uint8_t flags;
  470. /** Reserved */
  471. uint8_t reserved_b[7];
  472. } __attribute__ (( packed ));
  473. /** Transmit writeback descriptor complete */
  474. #define INTELXL_TX_WB_FL_DD 0x01
  475. /** Receive data descriptor */
  476. struct intelxl_rx_data_descriptor {
  477. /** Buffer address */
  478. uint64_t address;
  479. /** Flags */
  480. uint32_t flags;
  481. /** Reserved */
  482. uint8_t reserved[4];
  483. } __attribute__ (( packed ));
  484. /** Receive writeback descriptor */
  485. struct intelxl_rx_writeback_descriptor {
  486. /** Reserved */
  487. uint8_t reserved_a[2];
  488. /** VLAN tag */
  489. uint16_t vlan;
  490. /** Reserved */
  491. uint8_t reserved_b[4];
  492. /** Flags */
  493. uint32_t flags;
  494. /** Length */
  495. uint32_t len;
  496. } __attribute__ (( packed ));
  497. /** Receive writeback descriptor complete */
  498. #define INTELXL_RX_WB_FL_DD 0x00000001UL
  499. /** Receive writeback descriptor VLAN tag present */
  500. #define INTELXL_RX_WB_FL_VLAN 0x00000004UL
  501. /** Receive writeback descriptor error */
  502. #define INTELXL_RX_WB_FL_RXE 0x00080000UL
  503. /** Receive writeback descriptor length */
  504. #define INTELXL_RX_WB_LEN(len) ( ( (len) >> 6 ) & 0x3fff )
  505. /** Packet descriptor */
  506. union intelxl_descriptor {
  507. /** Transmit data descriptor */
  508. struct intelxl_tx_data_descriptor tx;
  509. /** Transmit writeback descriptor */
  510. struct intelxl_tx_writeback_descriptor tx_wb;
  511. /** Receive data descriptor */
  512. struct intelxl_rx_data_descriptor rx;
  513. /** Receive writeback descriptor */
  514. struct intelxl_rx_writeback_descriptor rx_wb;
  515. };
  516. /** Descriptor ring */
  517. struct intelxl_ring {
  518. /** Descriptors */
  519. union intelxl_descriptor *desc;
  520. /** Producer index */
  521. unsigned int prod;
  522. /** Consumer index */
  523. unsigned int cons;
  524. /** Register block */
  525. unsigned int reg;
  526. /** Length (in bytes) */
  527. size_t len;
  528. /** Program queue context
  529. *
  530. * @v intelxl Intel device
  531. * @v address Descriptor ring base address
  532. */
  533. int ( * context ) ( struct intelxl_nic *intelxl, physaddr_t address );
  534. };
  535. /**
  536. * Initialise descriptor ring
  537. *
  538. * @v ring Descriptor ring
  539. * @v count Number of descriptors
  540. * @v context Method to program queue context
  541. */
  542. static inline __attribute__ (( always_inline)) void
  543. intelxl_init_ring ( struct intelxl_ring *ring, unsigned int count,
  544. int ( * context ) ( struct intelxl_nic *intelxl,
  545. physaddr_t address ) ) {
  546. ring->len = ( count * sizeof ( ring->desc[0] ) );
  547. ring->context = context;
  548. }
  549. /** Number of transmit descriptors */
  550. #define INTELXL_TX_NUM_DESC 16
  551. /** Transmit descriptor ring maximum fill level */
  552. #define INTELXL_TX_FILL ( INTELXL_TX_NUM_DESC - 1 )
  553. /** Number of receive descriptors
  554. *
  555. * In PXE mode (i.e. able to post single receive descriptors), 8
  556. * descriptors is the only permitted value covering all possible
  557. * numbers of PFs.
  558. */
  559. #define INTELXL_RX_NUM_DESC 8
  560. /** Receive descriptor ring fill level */
  561. #define INTELXL_RX_FILL ( INTELXL_RX_NUM_DESC - 1 )
  562. /******************************************************************************
  563. *
  564. * Top level
  565. *
  566. ******************************************************************************
  567. */
  568. /** PF Interrupt Zero Dynamic Control Register */
  569. #define INTELXL_PFINT_DYN_CTL0 0x038480
  570. #define INTELXL_PFINT_DYN_CTL0_INTENA 0x00000001UL /**< Enable */
  571. #define INTELXL_PFINT_DYN_CTL0_CLEARPBA 0x00000002UL /**< Acknowledge */
  572. #define INTELXL_PFINT_DYN_CTL0_INTENA_MASK 0x80000000UL /**< Ignore enable */
  573. /** PF Interrupt Zero Linked List Register */
  574. #define INTELXL_PFINT_LNKLST0 0x038500
  575. #define INTELXL_PFINT_LNKLST0_FIRSTQ_INDX(x) \
  576. ( (x) << 0 ) /**< Queue index */
  577. #define INTELXL_PFINT_LNKLST0_FIRSTQ_INDX_NONE \
  578. INTELXL_PFINT_LNKLST0_FIRSTQ_INDX ( 0x7ff ) /**< End of list */
  579. #define INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE(x) \
  580. ( (x) << 11 ) /**< Queue type */
  581. #define INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE_RX \
  582. INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE ( 0x0 ) /**< Receive queue */
  583. #define INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE_TX \
  584. INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE ( 0x1 ) /**< Transmit queue */
  585. /** PF Interrupt Zero Cause Enablement Register */
  586. #define INTELXL_PFINT_ICR0_ENA 0x038800
  587. #define INTELXL_PFINT_ICR0_ENA_ADMINQ 0x40000000UL /**< Admin event */
  588. /** Receive Queue Interrupt Cause Control Register */
  589. #define INTELXL_QINT_RQCTL(x) ( 0x03a000 + ( 0x4 * (x) ) )
  590. #define INTELXL_QINT_RQCTL_NEXTQ_INDX(x) ( (x) << 16 ) /**< Queue index */
  591. #define INTELXL_QINT_RQCTL_NEXTQ_INDX_NONE \
  592. INTELXL_QINT_RQCTL_NEXTQ_INDX ( 0x7ff ) /**< End of list */
  593. #define INTELXL_QINT_RQCTL_NEXTQ_TYPE(x) ( (x) << 27 ) /**< Queue type */
  594. #define INTELXL_QINT_RQCTL_NEXTQ_TYPE_RX \
  595. INTELXL_QINT_RQCTL_NEXTQ_TYPE ( 0x0 ) /**< Receive queue */
  596. #define INTELXL_QINT_RQCTL_NEXTQ_TYPE_TX \
  597. INTELXL_QINT_RQCTL_NEXTQ_TYPE ( 0x1 ) /**< Transmit queue */
  598. #define INTELXL_QINT_RQCTL_CAUSE_ENA 0x40000000UL /**< Enable */
  599. /** Transmit Queue Interrupt Cause Control Register */
  600. #define INTELXL_QINT_TQCTL(x) ( 0x03c000 + ( 0x4 * (x) ) )
  601. #define INTELXL_QINT_TQCTL_NEXTQ_INDX(x) ( (x) << 16 ) /**< Queue index */
  602. #define INTELXL_QINT_TQCTL_NEXTQ_INDX_NONE \
  603. INTELXL_QINT_TQCTL_NEXTQ_INDX ( 0x7ff ) /**< End of list */
  604. #define INTELXL_QINT_TQCTL_NEXTQ_TYPE(x) ( (x) << 27 ) /**< Queue type */
  605. #define INTELXL_QINT_TQCTL_NEXTQ_TYPE_RX \
  606. INTELXL_QINT_TQCTL_NEXTQ_TYPE ( 0x0 ) /**< Receive queue */
  607. #define INTELXL_QINT_TQCTL_NEXTQ_TYPE_TX \
  608. INTELXL_QINT_TQCTL_NEXTQ_TYPE ( 0x1 ) /**< Transmit queue */
  609. #define INTELXL_QINT_TQCTL_CAUSE_ENA 0x40000000UL /**< Enable */
  610. /** PF Control Register */
  611. #define INTELXL_PFGEN_CTRL 0x092400
  612. #define INTELXL_PFGEN_CTRL_PFSWR 0x00000001UL /**< Software Reset */
  613. /** Time to delay for device reset, in milliseconds */
  614. #define INTELXL_RESET_DELAY_MS 100
  615. /** PF Queue Allocation Register */
  616. #define INTELXL_PFLAN_QALLOC 0x1c0400
  617. #define INTELXL_PFLAN_QALLOC_FIRSTQ(x) \
  618. ( ( (x) >> 0 ) & 0x7ff ) /**< First queue */
  619. #define INTELXL_PFLAN_QALLOC_LASTQ(x) \
  620. ( ( (x) >> 16 ) & 0x7ff ) /**< Last queue */
  621. /** PF LAN Port Number Register */
  622. #define INTELXL_PFGEN_PORTNUM 0x1c0480
  623. #define INTELXL_PFGEN_PORTNUM_PORT_NUM(x) \
  624. ( ( (x) >> 0 ) & 0x3 ) /**< Port number */
  625. /** Port MAC Address Low Register */
  626. #define INTELXL_PRTGL_SAL 0x1e2120
  627. /** Port MAC Address High Register */
  628. #define INTELXL_PRTGL_SAH 0x1e2140
  629. #define INTELXL_PRTGL_SAH_MFS_GET(x) ( (x) >> 16 ) /**< Max frame size */
  630. #define INTELXL_PRTGL_SAH_MFS_SET(x) ( (x) << 16 ) /**< Max frame size */
  631. /** Receive address */
  632. union intelxl_receive_address {
  633. struct {
  634. uint32_t low;
  635. uint32_t high;
  636. } __attribute__ (( packed )) reg;
  637. uint8_t raw[ETH_ALEN];
  638. };
  639. /** An Intel 40Gigabit network card */
  640. struct intelxl_nic {
  641. /** Registers */
  642. void *regs;
  643. /** Maximum frame size */
  644. size_t mfs;
  645. /** Physical function number */
  646. unsigned int pf;
  647. /** Absolute queue number base */
  648. unsigned int base;
  649. /** Port number */
  650. unsigned int port;
  651. /** Queue number */
  652. unsigned int queue;
  653. /** Virtual Station Interface switching element ID */
  654. unsigned int vsi;
  655. /** Queue set handle */
  656. unsigned int qset;
  657. /** Admin command queue */
  658. struct intelxl_admin command;
  659. /** Admin event queue */
  660. struct intelxl_admin event;
  661. /** Transmit descriptor ring */
  662. struct intelxl_ring tx;
  663. /** Receive descriptor ring */
  664. struct intelxl_ring rx;
  665. /** Receive I/O buffers */
  666. struct io_buffer *rx_iobuf[INTELXL_RX_NUM_DESC];
  667. };
  668. #endif /* _INTELXL_H */