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 30KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  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. #include <ipxe/pcimsix.h>
  12. struct intelxl_nic;
  13. /** BAR size */
  14. #define INTELXL_BAR_SIZE 0x200000
  15. /** Alignment
  16. *
  17. * No data structure requires greater than 256 byte alignment.
  18. */
  19. #define INTELXL_ALIGN 256
  20. /******************************************************************************
  21. *
  22. * Admin queue
  23. *
  24. ******************************************************************************
  25. */
  26. /** PF Admin Command Queue register block */
  27. #define INTELXL_ADMIN_CMD 0x080000
  28. /** PF Admin Event Queue register block */
  29. #define INTELXL_ADMIN_EVT 0x080080
  30. /** Admin Queue Base Address Low Register (offset) */
  31. #define INTELXL_ADMIN_BAL 0x000
  32. /** Admin Queue Base Address High Register (offset) */
  33. #define INTELXL_ADMIN_BAH 0x100
  34. /** Admin Queue Length Register (offset) */
  35. #define INTELXL_ADMIN_LEN 0x200
  36. #define INTELXL_ADMIN_LEN_LEN(x) ( (x) << 0 ) /**< Queue length */
  37. #define INTELXL_ADMIN_LEN_ENABLE 0x80000000UL /**< Queue enable */
  38. /** Admin Queue Head Register (offset) */
  39. #define INTELXL_ADMIN_HEAD 0x300
  40. /** Admin Queue Tail Register (offset) */
  41. #define INTELXL_ADMIN_TAIL 0x400
  42. /** Admin queue register offsets
  43. *
  44. * The physical and virtual function register maps have no discernible
  45. * relationship.
  46. */
  47. struct intelxl_admin_offsets {
  48. /** Base Address Low Register offset */
  49. unsigned int bal;
  50. /** Base Address High Register offset */
  51. unsigned int bah;
  52. /** Length Register offset */
  53. unsigned int len;
  54. /** Head Register offset */
  55. unsigned int head;
  56. /** Tail Register offset */
  57. unsigned int tail;
  58. };
  59. /** Admin queue data buffer command parameters */
  60. struct intelxl_admin_buffer_params {
  61. /** Reserved */
  62. uint8_t reserved[8];
  63. /** Buffer address high */
  64. uint32_t high;
  65. /** Buffer address low */
  66. uint32_t low;
  67. } __attribute__ (( packed ));
  68. /** Admin queue Get Version command */
  69. #define INTELXL_ADMIN_VERSION 0x0001
  70. /** Admin queue version number */
  71. struct intelxl_admin_version {
  72. /** Major version number */
  73. uint16_t major;
  74. /** Minor version number */
  75. uint16_t minor;
  76. } __attribute__ (( packed ));
  77. /** Admin queue Get Version command parameters */
  78. struct intelxl_admin_version_params {
  79. /** ROM version */
  80. uint32_t rom;
  81. /** Firmware build ID */
  82. uint32_t build;
  83. /** Firmware version */
  84. struct intelxl_admin_version firmware;
  85. /** API version */
  86. struct intelxl_admin_version api;
  87. } __attribute__ (( packed ));
  88. /** Admin queue Driver Version command */
  89. #define INTELXL_ADMIN_DRIVER 0x0002
  90. /** Admin queue Driver Version command parameters */
  91. struct intelxl_admin_driver_params {
  92. /** Driver version */
  93. uint8_t major;
  94. /** Minor version */
  95. uint8_t minor;
  96. /** Build version */
  97. uint8_t build;
  98. /** Sub-build version */
  99. uint8_t sub;
  100. /** Reserved */
  101. uint8_t reserved[4];
  102. /** Data buffer address */
  103. uint64_t address;
  104. } __attribute__ (( packed ));
  105. /** Admin queue Driver Version data buffer */
  106. struct intelxl_admin_driver_buffer {
  107. /** Driver name */
  108. char name[32];
  109. } __attribute__ (( packed ));
  110. /** Admin queue Shutdown command */
  111. #define INTELXL_ADMIN_SHUTDOWN 0x0003
  112. /** Admin queue Shutdown command parameters */
  113. struct intelxl_admin_shutdown_params {
  114. /** Driver unloading */
  115. uint8_t unloading;
  116. /** Reserved */
  117. uint8_t reserved[15];
  118. } __attribute__ (( packed ));
  119. /** Driver is unloading */
  120. #define INTELXL_ADMIN_SHUTDOWN_UNLOADING 0x01
  121. /** Admin queue Clear PXE Mode command */
  122. #define INTELXL_ADMIN_CLEAR_PXE 0x0110
  123. /** Admin queue Clear PXE Mode command parameters */
  124. struct intelxl_admin_clear_pxe_params {
  125. /** Magic value */
  126. uint8_t magic;
  127. /** Reserved */
  128. uint8_t reserved[15];
  129. } __attribute__ (( packed ));
  130. /** Clear PXE Mode magic value */
  131. #define INTELXL_ADMIN_CLEAR_PXE_MAGIC 0x02
  132. /** Admin queue Get Switch Configuration command */
  133. #define INTELXL_ADMIN_SWITCH 0x0200
  134. /** Switching element configuration */
  135. struct intelxl_admin_switch_config {
  136. /** Switching element type */
  137. uint8_t type;
  138. /** Revision */
  139. uint8_t revision;
  140. /** Switching element ID */
  141. uint16_t seid;
  142. /** Uplink switching element ID */
  143. uint16_t uplink;
  144. /** Downlink switching element ID */
  145. uint16_t downlink;
  146. /** Reserved */
  147. uint8_t reserved_b[3];
  148. /** Connection type */
  149. uint8_t connection;
  150. /** Reserved */
  151. uint8_t reserved_c[2];
  152. /** Element specific information */
  153. uint16_t info;
  154. } __attribute__ (( packed ));
  155. /** Virtual Station Inferface element type */
  156. #define INTELXL_ADMIN_SWITCH_TYPE_VSI 19
  157. /** Admin queue Get Switch Configuration command parameters */
  158. struct intelxl_admin_switch_params {
  159. /** Starting switching element identifier */
  160. uint16_t next;
  161. /** Reserved */
  162. uint8_t reserved[6];
  163. /** Data buffer address */
  164. uint64_t address;
  165. } __attribute__ (( packed ));
  166. /** Admin queue Get Switch Configuration data buffer */
  167. struct intelxl_admin_switch_buffer {
  168. /** Number of switching elements reported */
  169. uint16_t count;
  170. /** Total number of switching elements */
  171. uint16_t total;
  172. /** Reserved */
  173. uint8_t reserved_a[12];
  174. /** Switch configuration */
  175. struct intelxl_admin_switch_config cfg;
  176. } __attribute__ (( packed ));
  177. /** Admin queue Get VSI Parameters command */
  178. #define INTELXL_ADMIN_VSI 0x0212
  179. /** Admin queue Get VSI Parameters command parameters */
  180. struct intelxl_admin_vsi_params {
  181. /** VSI switching element ID */
  182. uint16_t vsi;
  183. /** Reserved */
  184. uint8_t reserved[6];
  185. /** Data buffer address */
  186. uint64_t address;
  187. } __attribute__ (( packed ));
  188. /** Admin queue Get VSI Parameters data buffer */
  189. struct intelxl_admin_vsi_buffer {
  190. /** Reserved */
  191. uint8_t reserved_a[30];
  192. /** Queue numbers */
  193. uint16_t queue[16];
  194. /** Reserved */
  195. uint8_t reserved_b[34];
  196. /** Queue set handles for each traffic class */
  197. uint16_t qset[8];
  198. /** Reserved */
  199. uint8_t reserved_c[16];
  200. } __attribute__ (( packed ));
  201. /** Admin queue Set VSI Promiscuous Modes command */
  202. #define INTELXL_ADMIN_PROMISC 0x0254
  203. /** Admin queue Set VSI Promiscuous Modes command parameters */
  204. struct intelxl_admin_promisc_params {
  205. /** Flags */
  206. uint16_t flags;
  207. /** Valid flags */
  208. uint16_t valid;
  209. /** VSI switching element ID */
  210. uint16_t vsi;
  211. /** Reserved */
  212. uint8_t reserved[10];
  213. } __attribute__ (( packed ));
  214. /** Promiscuous unicast mode */
  215. #define INTELXL_ADMIN_PROMISC_FL_UNICAST 0x0001
  216. /** Promiscuous multicast mode */
  217. #define INTELXL_ADMIN_PROMISC_FL_MULTICAST 0x0002
  218. /** Promiscuous broadcast mode */
  219. #define INTELXL_ADMIN_PROMISC_FL_BROADCAST 0x0004
  220. /** Promiscuous VLAN mode */
  221. #define INTELXL_ADMIN_PROMISC_FL_VLAN 0x0010
  222. /** Admin queue Restart Autonegotiation command */
  223. #define INTELXL_ADMIN_AUTONEG 0x0605
  224. /** Admin queue Restart Autonegotiation command parameters */
  225. struct intelxl_admin_autoneg_params {
  226. /** Flags */
  227. uint8_t flags;
  228. /** Reserved */
  229. uint8_t reserved[15];
  230. } __attribute__ (( packed ));
  231. /** Restart autonegotiation */
  232. #define INTELXL_ADMIN_AUTONEG_FL_RESTART 0x02
  233. /** Enable link */
  234. #define INTELXL_ADMIN_AUTONEG_FL_ENABLE 0x04
  235. /** Admin queue Get Link Status command */
  236. #define INTELXL_ADMIN_LINK 0x0607
  237. /** Admin queue Get Link Status command parameters */
  238. struct intelxl_admin_link_params {
  239. /** Link status notification */
  240. uint8_t notify;
  241. /** Reserved */
  242. uint8_t reserved_a;
  243. /** PHY type */
  244. uint8_t phy;
  245. /** Link speed */
  246. uint8_t speed;
  247. /** Link status */
  248. uint8_t status;
  249. /** Reserved */
  250. uint8_t reserved_b[11];
  251. } __attribute__ (( packed ));
  252. /** Notify driver of link status changes */
  253. #define INTELXL_ADMIN_LINK_NOTIFY 0x03
  254. /** Link is up */
  255. #define INTELXL_ADMIN_LINK_UP 0x01
  256. /** Admin queue Send Message to PF command */
  257. #define INTELXL_ADMIN_SEND_TO_PF 0x0801
  258. /** Admin queue Send Message to VF command */
  259. #define INTELXL_ADMIN_SEND_TO_VF 0x0802
  260. /** Admin Queue VF Reset opcode */
  261. #define INTELXL_ADMIN_VF_RESET 0x00000002
  262. /** Admin Queue VF Get Resources opcode */
  263. #define INTELXL_ADMIN_VF_GET_RESOURCES 0x00000003
  264. /** Admin Queue VF Get Resources data buffer */
  265. struct intelxl_admin_vf_get_resources_buffer {
  266. /** Reserved */
  267. uint8_t reserved_a[20];
  268. /** VSI switching element ID */
  269. uint16_t vsi;
  270. /** Reserved */
  271. uint8_t reserved_b[8];
  272. /** MAC address */
  273. uint8_t mac[ETH_ALEN];
  274. } __attribute__ (( packed ));
  275. /** Admin Queue VF Status Change Event opcode */
  276. #define INTELXL_ADMIN_VF_STATUS 0x00000011
  277. /** Link status change event type */
  278. #define INTELXL_ADMIN_VF_STATUS_LINK 0x00000001
  279. /** Link status change event data */
  280. struct intelxl_admin_vf_status_link {
  281. /** Link speed */
  282. uint32_t speed;
  283. /** Link status */
  284. uint8_t status;
  285. /** Reserved */
  286. uint8_t reserved[3];
  287. } __attribute__ (( packed ));
  288. /** Admin Queue VF Status Change Event data buffer */
  289. struct intelxl_admin_vf_status_buffer {
  290. /** Event type */
  291. uint32_t event;
  292. /** Event data */
  293. union {
  294. /** Link change event data */
  295. struct intelxl_admin_vf_status_link link;
  296. } data;
  297. /** Reserved */
  298. uint8_t reserved[4];
  299. } __attribute__ (( packed ));
  300. /** Admin Queue VF Configure Queues opcode */
  301. #define INTELXL_ADMIN_VF_CONFIGURE 0x00000006
  302. /** Admin Queue VF Configure Queues data buffer */
  303. struct intelxl_admin_vf_configure_buffer {
  304. /** VSI switching element ID */
  305. uint16_t vsi;
  306. /** Number of queue pairs */
  307. uint16_t count;
  308. /** Reserved */
  309. uint8_t reserved_a[4];
  310. /** Transmit queue */
  311. struct {
  312. /** VSI switching element ID */
  313. uint16_t vsi;
  314. /** Queue ID */
  315. uint16_t id;
  316. /** Queue count */
  317. uint16_t count;
  318. /** Reserved */
  319. uint8_t reserved_a[2];
  320. /** Base address */
  321. uint64_t base;
  322. /** Reserved */
  323. uint8_t reserved_b[8];
  324. } __attribute__ (( packed )) tx;
  325. /** Receive queue */
  326. struct {
  327. /** VSI switching element ID */
  328. uint16_t vsi;
  329. /** Queue ID */
  330. uint16_t id;
  331. /** Queue count */
  332. uint32_t count;
  333. /** Reserved */
  334. uint8_t reserved_a[4];
  335. /** Data buffer length */
  336. uint32_t len;
  337. /** Maximum frame size */
  338. uint32_t mfs;
  339. /** Reserved */
  340. uint8_t reserved_b[4];
  341. /** Base address */
  342. uint64_t base;
  343. /** Reserved */
  344. uint8_t reserved_c[8];
  345. } __attribute__ (( packed )) rx;
  346. /** Reserved
  347. *
  348. * This field exists only due to a bug in the PF driver's
  349. * message validation logic, which causes it to miscalculate
  350. * the expected message length.
  351. */
  352. uint8_t reserved_b[64];
  353. } __attribute__ (( packed ));
  354. /** Admin Queue VF IRQ Map opcode */
  355. #define INTELXL_ADMIN_VF_IRQ_MAP 0x00000007
  356. /** Admin Queue VF IRQ Map data buffer */
  357. struct intelxl_admin_vf_irq_map_buffer {
  358. /** Number of interrupt vectors */
  359. uint16_t count;
  360. /** VSI switching element ID */
  361. uint16_t vsi;
  362. /** Interrupt vector ID */
  363. uint16_t vec;
  364. /** Receive queue bitmap */
  365. uint16_t rxmap;
  366. /** Transmit queue bitmap */
  367. uint16_t txmap;
  368. /** Receive interrupt throttling index */
  369. uint16_t rxitr;
  370. /** Transmit interrupt throttling index */
  371. uint16_t txitr;
  372. /** Reserved
  373. *
  374. * This field exists only due to a bug in the PF driver's
  375. * message validation logic, which causes it to miscalculate
  376. * the expected message length.
  377. */
  378. uint8_t reserved[12];
  379. } __attribute__ (( packed ));
  380. /** Admin Queue VF Enable Queues opcode */
  381. #define INTELXL_ADMIN_VF_ENABLE 0x00000008
  382. /** Admin Queue VF Disable Queues opcode */
  383. #define INTELXL_ADMIN_VF_DISABLE 0x00000009
  384. /** Admin Queue VF Enable/Disable Queues data buffer */
  385. struct intelxl_admin_vf_queues_buffer {
  386. /** VSI switching element ID */
  387. uint16_t vsi;
  388. /** Reserved */
  389. uint8_t reserved[2];
  390. /** Receive queue bitmask */
  391. uint32_t rx;
  392. /** Transmit queue bitmask */
  393. uint32_t tx;
  394. } __attribute__ (( packed ));
  395. /** Admin Queue VF Configure Promiscuous Mode opcode */
  396. #define INTELXL_ADMIN_VF_PROMISC 0x0000000e
  397. /** Admin Queue VF Configure Promiscuous Mode data buffer */
  398. struct intelxl_admin_vf_promisc_buffer {
  399. /** VSI switching element ID */
  400. uint16_t vsi;
  401. /** Flags */
  402. uint16_t flags;
  403. } __attribute__ (( packed ));
  404. /** Admin queue command parameters */
  405. union intelxl_admin_params {
  406. /** Additional data buffer command parameters */
  407. struct intelxl_admin_buffer_params buffer;
  408. /** Get Version command parameters */
  409. struct intelxl_admin_version_params version;
  410. /** Driver Version command parameters */
  411. struct intelxl_admin_driver_params driver;
  412. /** Shutdown command parameters */
  413. struct intelxl_admin_shutdown_params shutdown;
  414. /** Clear PXE Mode command parameters */
  415. struct intelxl_admin_clear_pxe_params pxe;
  416. /** Get Switch Configuration command parameters */
  417. struct intelxl_admin_switch_params sw;
  418. /** Get VSI Parameters command parameters */
  419. struct intelxl_admin_vsi_params vsi;
  420. /** Set VSI Promiscuous Modes command parameters */
  421. struct intelxl_admin_promisc_params promisc;
  422. /** Restart Autonegotiation command parameters */
  423. struct intelxl_admin_autoneg_params autoneg;
  424. /** Get Link Status command parameters */
  425. struct intelxl_admin_link_params link;
  426. } __attribute__ (( packed ));
  427. /** Admin queue data buffer */
  428. union intelxl_admin_buffer {
  429. /** Driver Version data buffer */
  430. struct intelxl_admin_driver_buffer driver;
  431. /** Get Switch Configuration data buffer */
  432. struct intelxl_admin_switch_buffer sw;
  433. /** Get VSI Parameters data buffer */
  434. struct intelxl_admin_vsi_buffer vsi;
  435. /** VF Get Resources data buffer */
  436. struct intelxl_admin_vf_get_resources_buffer res;
  437. /** VF Status Change Event data buffer */
  438. struct intelxl_admin_vf_status_buffer stat;
  439. /** VF Configure Queues data buffer */
  440. struct intelxl_admin_vf_configure_buffer cfg;
  441. /** VF Enable/Disable Queues data buffer */
  442. struct intelxl_admin_vf_queues_buffer queues;
  443. /** VF Configure Promiscuous Mode data buffer */
  444. struct intelxl_admin_vf_promisc_buffer promisc;
  445. /*** VF IRQ Map data buffer */
  446. struct intelxl_admin_vf_irq_map_buffer irq;
  447. /** Alignment padding */
  448. uint8_t pad[INTELXL_ALIGN];
  449. } __attribute__ (( packed ));
  450. /** Admin queue descriptor */
  451. struct intelxl_admin_descriptor {
  452. /** Flags */
  453. uint16_t flags;
  454. /** Opcode */
  455. uint16_t opcode;
  456. /** Data length */
  457. uint16_t len;
  458. /** Return value */
  459. uint16_t ret;
  460. /** Opaque cookie / VF opcode */
  461. union {
  462. /** Cookie */
  463. uint32_t cookie;
  464. /** VF opcode */
  465. uint32_t vopcode;
  466. };
  467. /** VF return value */
  468. int32_t vret;
  469. /** Parameters */
  470. union intelxl_admin_params params;
  471. } __attribute__ (( packed ));
  472. /** Admin descriptor done */
  473. #define INTELXL_ADMIN_FL_DD 0x0001
  474. /** Admin descriptor contains a completion */
  475. #define INTELXL_ADMIN_FL_CMP 0x0002
  476. /** Admin descriptor completed in error */
  477. #define INTELXL_ADMIN_FL_ERR 0x0004
  478. /** Admin descriptor uses data buffer for command parameters */
  479. #define INTELXL_ADMIN_FL_RD 0x0400
  480. /** Admin descriptor uses data buffer */
  481. #define INTELXL_ADMIN_FL_BUF 0x1000
  482. /** Admin queue */
  483. struct intelxl_admin {
  484. /** Descriptors */
  485. struct intelxl_admin_descriptor *desc;
  486. /** Data buffers */
  487. union intelxl_admin_buffer *buf;
  488. /** Queue index */
  489. unsigned int index;
  490. /** Register block base */
  491. unsigned int base;
  492. /** Register offsets */
  493. const struct intelxl_admin_offsets *regs;
  494. };
  495. /**
  496. * Initialise admin queue
  497. *
  498. * @v admin Admin queue
  499. * @v base Register block base
  500. * @v regs Register offsets
  501. */
  502. static inline __attribute__ (( always_inline )) void
  503. intelxl_init_admin ( struct intelxl_admin *admin, unsigned int base,
  504. const struct intelxl_admin_offsets *regs ) {
  505. admin->base = base;
  506. admin->regs = regs;
  507. }
  508. /** Number of admin queue descriptors */
  509. #define INTELXL_ADMIN_NUM_DESC 4
  510. /** Maximum time to wait for an admin request to complete */
  511. #define INTELXL_ADMIN_MAX_WAIT_MS 100
  512. /** Admin queue API major version */
  513. #define INTELXL_ADMIN_API_MAJOR 1
  514. /******************************************************************************
  515. *
  516. * Transmit and receive queue context
  517. *
  518. ******************************************************************************
  519. */
  520. /** CMLAN Context Data Register */
  521. #define INTELXL_PFCM_LANCTXDATA(x) ( 0x10c100 + ( 0x80 * (x) ) )
  522. /** CMLAN Context Control Register */
  523. #define INTELXL_PFCM_LANCTXCTL 0x10c300
  524. #define INTELXL_PFCM_LANCTXCTL_QUEUE_NUM(x) \
  525. ( (x) << 0 ) /**< Queue number */
  526. #define INTELXL_PFCM_LANCTXCTL_SUB_LINE(x) \
  527. ( (x) << 12 ) /**< Sub-line */
  528. #define INTELXL_PFCM_LANCTXCTL_TYPE(x) \
  529. ( (x) << 15 ) /**< Queue type */
  530. #define INTELXL_PFCM_LANCTXCTL_TYPE_RX \
  531. INTELXL_PFCM_LANCTXCTL_TYPE ( 0x0 ) /**< RX queue type */
  532. #define INTELXL_PFCM_LANCTXCTL_TYPE_TX \
  533. INTELXL_PFCM_LANCTXCTL_TYPE ( 0x1 ) /**< TX queue type */
  534. #define INTELXL_PFCM_LANCTXCTL_OP_CODE(x) \
  535. ( (x) << 17 ) /**< Op code */
  536. #define INTELXL_PFCM_LANCTXCTL_OP_CODE_READ \
  537. INTELXL_PFCM_LANCTXCTL_OP_CODE ( 0x0 ) /**< Read context */
  538. #define INTELXL_PFCM_LANCTXCTL_OP_CODE_WRITE \
  539. INTELXL_PFCM_LANCTXCTL_OP_CODE ( 0x1 ) /**< Write context */
  540. /** CMLAN Context Status Register */
  541. #define INTELXL_PFCM_LANCTXSTAT 0x10c380
  542. #define INTELXL_PFCM_LANCTXSTAT_DONE 0x00000001UL /**< Complete */
  543. /** Queue context line */
  544. struct intelxl_context_line {
  545. /** Raw data */
  546. uint32_t raw[4];
  547. } __attribute__ (( packed ));
  548. /** Transmit queue context */
  549. struct intelxl_context_tx {
  550. /** Head pointer */
  551. uint16_t head;
  552. /** Flags */
  553. uint16_t flags;
  554. /** Base address */
  555. uint64_t base;
  556. /** Reserved */
  557. uint8_t reserved_a[8];
  558. /** Queue count */
  559. uint16_t count;
  560. /** Reserved */
  561. uint8_t reserved_b[100];
  562. /** Queue set */
  563. uint16_t qset;
  564. /** Reserved */
  565. uint8_t reserved_c[4];
  566. } __attribute__ (( packed ));
  567. /** New transmit queue context */
  568. #define INTELXL_CTX_TX_FL_NEW 0x4000
  569. /** Transmit queue base address */
  570. #define INTELXL_CTX_TX_BASE( base ) ( (base) >> 7 )
  571. /** Transmit queue count */
  572. #define INTELXL_CTX_TX_COUNT( count ) ( (count) << 1 )
  573. /** Transmit queue set */
  574. #define INTELXL_CTX_TX_QSET( qset) ( (qset) << 4 )
  575. /** Receive queue context */
  576. struct intelxl_context_rx {
  577. /** Head pointer */
  578. uint16_t head;
  579. /** Reserved */
  580. uint8_t reserved_a[2];
  581. /** Base address and queue count */
  582. uint64_t base_count;
  583. /** Data buffer length */
  584. uint16_t len;
  585. /** Flags */
  586. uint8_t flags;
  587. /** Reserved */
  588. uint8_t reserved_b[7];
  589. /** Maximum frame size */
  590. uint16_t mfs;
  591. } __attribute__ (( packed ));
  592. /** Receive queue base address and queue count */
  593. #define INTELXL_CTX_RX_BASE_COUNT( base, count ) \
  594. ( ( (base) >> 7 ) | ( ( ( uint64_t ) (count) ) << 57 ) )
  595. /** Receive queue data buffer length */
  596. #define INTELXL_CTX_RX_LEN( len ) ( (len) >> 1 )
  597. /** Use 32-byte receive descriptors */
  598. #define INTELXL_CTX_RX_FL_DSIZE 0x10
  599. /** Strip CRC from received packets */
  600. #define INTELXL_CTX_RX_FL_CRCSTRIP 0x20
  601. /** Receive queue maximum frame size */
  602. #define INTELXL_CTX_RX_MFS( mfs ) ( (mfs) >> 2 )
  603. /** Maximum time to wait for a context operation to complete */
  604. #define INTELXL_CTX_MAX_WAIT_MS 100
  605. /** Time to wait for a queue to become enabled */
  606. #define INTELXL_QUEUE_ENABLE_DELAY_US 20
  607. /** Time to wait for a transmit queue to become pre-disabled */
  608. #define INTELXL_QUEUE_PRE_DISABLE_DELAY_US 400
  609. /** Maximum time to wait for a queue to become disabled */
  610. #define INTELXL_QUEUE_DISABLE_MAX_WAIT_MS 1000
  611. /******************************************************************************
  612. *
  613. * Transmit and receive descriptors
  614. *
  615. ******************************************************************************
  616. */
  617. /** Global Transmit Queue Head register */
  618. #define INTELXL_QTX_HEAD(x) ( 0x0e4000 + ( 0x4 * (x) ) )
  619. /** Global Transmit Pre Queue Disable register */
  620. #define INTELXL_GLLAN_TXPRE_QDIS(x) ( 0x0e6500 + ( 0x4 * ( (x) / 0x80 ) ) )
  621. #define INTELXL_GLLAN_TXPRE_QDIS_QINDX(x) \
  622. ( (x) << 0 ) /**< Queue index */
  623. #define INTELXL_GLLAN_TXPRE_QDIS_SET_QDIS \
  624. 0x40000000UL /**< Set disable */
  625. #define INTELXL_GLLAN_TXPRE_QDIS_CLEAR_QDIS \
  626. 0x80000000UL /**< Clear disable */
  627. /** Global Transmit Queue register block */
  628. #define INTELXL_QTX(x) ( 0x100000 + ( 0x4 * (x) ) )
  629. /** Global Receive Queue register block */
  630. #define INTELXL_QRX(x) ( 0x120000 + ( 0x4 * (x) ) )
  631. /** Queue Enable Register (offset) */
  632. #define INTELXL_QXX_ENA 0x0000
  633. #define INTELXL_QXX_ENA_REQ 0x00000001UL /**< Enable request */
  634. #define INTELXL_QXX_ENA_STAT 0x00000004UL /**< Enabled status */
  635. /** Queue Control Register (offset) */
  636. #define INTELXL_QXX_CTL 0x4000
  637. #define INTELXL_QXX_CTL_PFVF_Q(x) ( (x) << 0 ) /**< PF/VF queue */
  638. #define INTELXL_QXX_CTL_PFVF_Q_PF \
  639. INTELXL_QXX_CTL_PFVF_Q ( 0x2 ) /**< PF queue */
  640. #define INTELXL_QXX_CTL_PFVF_PF_INDX(x) ( (x) << 2 ) /**< PF index */
  641. /** Queue Tail Pointer Register (offset) */
  642. #define INTELXL_QXX_TAIL 0x8000
  643. /** Global RLAN Control 0 register */
  644. #define INTELXL_GLLAN_RCTL_0 0x12a500
  645. #define INTELXL_GLLAN_RCTL_0_PXE_MODE 0x00000001UL /**< PXE mode */
  646. /** Transmit data descriptor */
  647. struct intelxl_tx_data_descriptor {
  648. /** Buffer address */
  649. uint64_t address;
  650. /** Flags */
  651. uint32_t flags;
  652. /** Length */
  653. uint32_t len;
  654. } __attribute__ (( packed ));
  655. /** Transmit data descriptor type */
  656. #define INTELXL_TX_DATA_DTYP 0x0
  657. /** Transmit data descriptor end of packet */
  658. #define INTELXL_TX_DATA_EOP 0x10
  659. /** Transmit data descriptor report status */
  660. #define INTELXL_TX_DATA_RS 0x20
  661. /** Transmit data descriptor pretty please
  662. *
  663. * This bit is completely missing from older versions of the XL710
  664. * datasheet. Later versions describe it innocuously as "reserved,
  665. * must be 1". Without this bit, everything will appear to work (up
  666. * to and including the port "transmit good octets" counter), but no
  667. * packet will actually be sent.
  668. */
  669. #define INTELXL_TX_DATA_JFDI 0x40
  670. /** Transmit data descriptor length */
  671. #define INTELXL_TX_DATA_LEN( len ) ( (len) << 2 )
  672. /** Transmit writeback descriptor */
  673. struct intelxl_tx_writeback_descriptor {
  674. /** Reserved */
  675. uint8_t reserved_a[8];
  676. /** Flags */
  677. uint8_t flags;
  678. /** Reserved */
  679. uint8_t reserved_b[7];
  680. } __attribute__ (( packed ));
  681. /** Transmit writeback descriptor complete */
  682. #define INTELXL_TX_WB_FL_DD 0x01
  683. /** Transmit descriptor */
  684. union intelxl_tx_descriptor {
  685. /** Transmit data descriptor */
  686. struct intelxl_tx_data_descriptor data;
  687. /** Transmit writeback descriptor */
  688. struct intelxl_tx_writeback_descriptor wb;
  689. };
  690. /** Receive data descriptor */
  691. struct intelxl_rx_data_descriptor {
  692. /** Buffer address */
  693. uint64_t address;
  694. /** Flags */
  695. uint32_t flags;
  696. /** Reserved */
  697. uint8_t reserved[20];
  698. } __attribute__ (( packed ));
  699. /** Receive writeback descriptor */
  700. struct intelxl_rx_writeback_descriptor {
  701. /** Reserved */
  702. uint8_t reserved_a[2];
  703. /** VLAN tag */
  704. uint16_t vlan;
  705. /** Reserved */
  706. uint8_t reserved_b[4];
  707. /** Flags */
  708. uint32_t flags;
  709. /** Length */
  710. uint32_t len;
  711. /** Reserved */
  712. uint8_t reserved_c[16];
  713. } __attribute__ (( packed ));
  714. /** Receive writeback descriptor complete */
  715. #define INTELXL_RX_WB_FL_DD 0x00000001UL
  716. /** Receive writeback descriptor VLAN tag present */
  717. #define INTELXL_RX_WB_FL_VLAN 0x00000004UL
  718. /** Receive writeback descriptor error */
  719. #define INTELXL_RX_WB_FL_RXE 0x00080000UL
  720. /** Receive writeback descriptor length */
  721. #define INTELXL_RX_WB_LEN(len) ( ( (len) >> 6 ) & 0x3fff )
  722. /** Packet descriptor */
  723. union intelxl_rx_descriptor {
  724. /** Receive data descriptor */
  725. struct intelxl_rx_data_descriptor data;
  726. /** Receive writeback descriptor */
  727. struct intelxl_rx_writeback_descriptor wb;
  728. };
  729. /** Descriptor ring */
  730. struct intelxl_ring {
  731. /** Descriptors */
  732. union {
  733. /** Transmit descriptors */
  734. union intelxl_tx_descriptor *tx;
  735. /** Receive descriptors */
  736. union intelxl_rx_descriptor *rx;
  737. /** Raw data */
  738. void *raw;
  739. } desc;
  740. /** Producer index */
  741. unsigned int prod;
  742. /** Consumer index */
  743. unsigned int cons;
  744. /** Register block */
  745. unsigned int reg;
  746. /** Tail register */
  747. unsigned int tail;
  748. /** Length (in bytes) */
  749. size_t len;
  750. /** Program queue context
  751. *
  752. * @v intelxl Intel device
  753. * @v address Descriptor ring base address
  754. */
  755. int ( * context ) ( struct intelxl_nic *intelxl, physaddr_t address );
  756. };
  757. /**
  758. * Initialise descriptor ring
  759. *
  760. * @v ring Descriptor ring
  761. * @v count Number of descriptors
  762. * @v len Length of a single descriptor
  763. * @v context Method to program queue context
  764. */
  765. static inline __attribute__ (( always_inline)) void
  766. intelxl_init_ring ( struct intelxl_ring *ring, unsigned int count, size_t len,
  767. int ( * context ) ( struct intelxl_nic *intelxl,
  768. physaddr_t address ) ) {
  769. ring->len = ( count * len );
  770. ring->context = context;
  771. }
  772. /** Number of transmit descriptors
  773. *
  774. * Chosen to exceed the receive ring fill level, in order to avoid
  775. * running out of transmit descriptors when sending TCP ACKs.
  776. */
  777. #define INTELXL_TX_NUM_DESC 64
  778. /** Transmit descriptor ring maximum fill level */
  779. #define INTELXL_TX_FILL ( INTELXL_TX_NUM_DESC - 1 )
  780. /** Number of receive descriptors
  781. *
  782. * Must be a multiple of 32.
  783. */
  784. #define INTELXL_RX_NUM_DESC 32
  785. /** Receive descriptor ring fill level
  786. *
  787. * Must be a multiple of 8 and greater than 8.
  788. */
  789. #define INTELXL_RX_FILL 16
  790. /******************************************************************************
  791. *
  792. * Top level
  793. *
  794. ******************************************************************************
  795. */
  796. /** PF Interrupt Zero Dynamic Control Register */
  797. #define INTELXL_PFINT_DYN_CTL0 0x038480
  798. #define INTELXL_INT_DYN_CTL_INTENA 0x00000001UL /**< Enable */
  799. #define INTELXL_INT_DYN_CTL_CLEARPBA 0x00000002UL /**< Acknowledge */
  800. #define INTELXL_INT_DYN_CTL_INTENA_MASK 0x80000000UL /**< Ignore enable */
  801. /** PF Interrupt Zero Linked List Register */
  802. #define INTELXL_PFINT_LNKLST0 0x038500
  803. #define INTELXL_PFINT_LNKLST0_FIRSTQ_INDX(x) \
  804. ( (x) << 0 ) /**< Queue index */
  805. #define INTELXL_PFINT_LNKLST0_FIRSTQ_INDX_NONE \
  806. INTELXL_PFINT_LNKLST0_FIRSTQ_INDX ( 0x7ff ) /**< End of list */
  807. #define INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE(x) \
  808. ( (x) << 11 ) /**< Queue type */
  809. #define INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE_RX \
  810. INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE ( 0x0 ) /**< Receive queue */
  811. #define INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE_TX \
  812. INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE ( 0x1 ) /**< Transmit queue */
  813. /** PF Interrupt Zero Cause Enablement Register */
  814. #define INTELXL_PFINT_ICR0_ENA 0x038800
  815. #define INTELXL_PFINT_ICR0_ENA_ADMINQ 0x40000000UL /**< Admin event */
  816. /** Receive Queue Interrupt Cause Control Register */
  817. #define INTELXL_QINT_RQCTL(x) ( 0x03a000 + ( 0x4 * (x) ) )
  818. #define INTELXL_QINT_RQCTL_NEXTQ_INDX(x) ( (x) << 16 ) /**< Queue index */
  819. #define INTELXL_QINT_RQCTL_NEXTQ_INDX_NONE \
  820. INTELXL_QINT_RQCTL_NEXTQ_INDX ( 0x7ff ) /**< End of list */
  821. #define INTELXL_QINT_RQCTL_NEXTQ_TYPE(x) ( (x) << 27 ) /**< Queue type */
  822. #define INTELXL_QINT_RQCTL_NEXTQ_TYPE_RX \
  823. INTELXL_QINT_RQCTL_NEXTQ_TYPE ( 0x0 ) /**< Receive queue */
  824. #define INTELXL_QINT_RQCTL_NEXTQ_TYPE_TX \
  825. INTELXL_QINT_RQCTL_NEXTQ_TYPE ( 0x1 ) /**< Transmit queue */
  826. #define INTELXL_QINT_RQCTL_CAUSE_ENA 0x40000000UL /**< Enable */
  827. /** Transmit Queue Interrupt Cause Control Register */
  828. #define INTELXL_QINT_TQCTL(x) ( 0x03c000 + ( 0x4 * (x) ) )
  829. #define INTELXL_QINT_TQCTL_NEXTQ_INDX(x) ( (x) << 16 ) /**< Queue index */
  830. #define INTELXL_QINT_TQCTL_NEXTQ_INDX_NONE \
  831. INTELXL_QINT_TQCTL_NEXTQ_INDX ( 0x7ff ) /**< End of list */
  832. #define INTELXL_QINT_TQCTL_NEXTQ_TYPE(x) ( (x) << 27 ) /**< Queue type */
  833. #define INTELXL_QINT_TQCTL_NEXTQ_TYPE_RX \
  834. INTELXL_QINT_TQCTL_NEXTQ_TYPE ( 0x0 ) /**< Receive queue */
  835. #define INTELXL_QINT_TQCTL_NEXTQ_TYPE_TX \
  836. INTELXL_QINT_TQCTL_NEXTQ_TYPE ( 0x1 ) /**< Transmit queue */
  837. #define INTELXL_QINT_TQCTL_CAUSE_ENA 0x40000000UL /**< Enable */
  838. /** PF Control Register */
  839. #define INTELXL_PFGEN_CTRL 0x092400
  840. #define INTELXL_PFGEN_CTRL_PFSWR 0x00000001UL /**< Software Reset */
  841. /** Time to delay for device reset, in milliseconds */
  842. #define INTELXL_RESET_DELAY_MS 100
  843. /** PF Queue Allocation Register */
  844. #define INTELXL_PFLAN_QALLOC 0x1c0400
  845. #define INTELXL_PFLAN_QALLOC_FIRSTQ(x) \
  846. ( ( (x) >> 0 ) & 0x7ff ) /**< First queue */
  847. #define INTELXL_PFLAN_QALLOC_LASTQ(x) \
  848. ( ( (x) >> 16 ) & 0x7ff ) /**< Last queue */
  849. /** PF LAN Port Number Register */
  850. #define INTELXL_PFGEN_PORTNUM 0x1c0480
  851. #define INTELXL_PFGEN_PORTNUM_PORT_NUM(x) \
  852. ( ( (x) >> 0 ) & 0x3 ) /**< Port number */
  853. /** Port MAC Address Low Register */
  854. #define INTELXL_PRTGL_SAL 0x1e2120
  855. /** Port MAC Address High Register */
  856. #define INTELXL_PRTGL_SAH 0x1e2140
  857. #define INTELXL_PRTGL_SAH_MFS_GET(x) ( (x) >> 16 ) /**< Max frame size */
  858. #define INTELXL_PRTGL_SAH_MFS_SET(x) ( (x) << 16 ) /**< Max frame size */
  859. /** Receive address */
  860. union intelxl_receive_address {
  861. struct {
  862. uint32_t low;
  863. uint32_t high;
  864. } __attribute__ (( packed )) reg;
  865. uint8_t raw[ETH_ALEN];
  866. };
  867. /** An Intel 40Gigabit network card */
  868. struct intelxl_nic {
  869. /** Registers */
  870. void *regs;
  871. /** Maximum frame size */
  872. size_t mfs;
  873. /** Physical function number */
  874. unsigned int pf;
  875. /** Absolute queue number base */
  876. unsigned int base;
  877. /** Port number */
  878. unsigned int port;
  879. /** Queue number */
  880. unsigned int queue;
  881. /** Virtual Station Interface switching element ID */
  882. unsigned int vsi;
  883. /** Queue set handle */
  884. unsigned int qset;
  885. /** Interrupt control register */
  886. unsigned int intr;
  887. /** MSI-X capability */
  888. struct pci_msix msix;
  889. /** MSI-X dummy interrupt target */
  890. uint32_t msg;
  891. /** PCI Express capability offset */
  892. unsigned int exp;
  893. /** Admin command queue */
  894. struct intelxl_admin command;
  895. /** Admin event queue */
  896. struct intelxl_admin event;
  897. /** Current VF opcode */
  898. unsigned int vopcode;
  899. /** Current VF return value */
  900. int vret;
  901. /** Current VF event data buffer */
  902. union intelxl_admin_buffer vbuf;
  903. /** Transmit descriptor ring */
  904. struct intelxl_ring tx;
  905. /** Receive descriptor ring */
  906. struct intelxl_ring rx;
  907. /** Receive I/O buffers */
  908. struct io_buffer *rx_iobuf[INTELXL_RX_NUM_DESC];
  909. };
  910. extern int intelxl_msix_enable ( struct intelxl_nic *intelxl,
  911. struct pci_device *pci );
  912. extern void intelxl_msix_disable ( struct intelxl_nic *intelxl,
  913. struct pci_device *pci );
  914. extern struct intelxl_admin_descriptor *
  915. intelxl_admin_command_descriptor ( struct intelxl_nic *intelxl );
  916. extern union intelxl_admin_buffer *
  917. intelxl_admin_command_buffer ( struct intelxl_nic *intelxl );
  918. extern int intelxl_admin_command ( struct intelxl_nic *intelxl );
  919. extern void intelxl_poll_admin ( struct net_device *netdev );
  920. extern int intelxl_open_admin ( struct intelxl_nic *intelxl );
  921. extern void intelxl_reopen_admin ( struct intelxl_nic *intelxl );
  922. extern void intelxl_close_admin ( struct intelxl_nic *intelxl );
  923. extern int intelxl_alloc_ring ( struct intelxl_nic *intelxl,
  924. struct intelxl_ring *ring );
  925. extern void intelxl_free_ring ( struct intelxl_nic *intelxl,
  926. struct intelxl_ring *ring );
  927. extern void intelxl_empty_rx ( struct intelxl_nic *intelxl );
  928. extern int intelxl_transmit ( struct net_device *netdev,
  929. struct io_buffer *iobuf );
  930. extern void intelxl_poll ( struct net_device *netdev );
  931. extern void intelxlvf_admin_event ( struct net_device *netdev,
  932. struct intelxl_admin_descriptor *evt,
  933. union intelxl_admin_buffer *buf );
  934. #endif /* _INTELXL_H */