1 /* SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) OR BSD-2-Clause */
2 /* Copyright(c) 2023 Advanced Micro Devices, Inc. */
4 #ifndef _PDS_CORE_IF_H_
5 #define _PDS_CORE_IF_H_
7 #define PCI_VENDOR_ID_PENSANDO 0x1dd8
8 #define PCI_DEVICE_ID_PENSANDO_CORE_PF 0x100c
9 #define PCI_DEVICE_ID_VIRTIO_NET_TRANS 0x1000
10 #define PCI_DEVICE_ID_PENSANDO_IONIC_ETH_VF 0x1003
11 #define PCI_DEVICE_ID_PENSANDO_VDPA_VF 0x100b
12 #define PDS_CORE_BARS_MAX 4
13 #define PDS_CORE_PCI_BAR_DBELL 1
16 #define PDS_CORE_DEV_INFO_SIGNATURE 0x44455649 /* 'DEVI' */
17 #define PDS_CORE_BAR0_SIZE 0x8000
18 #define PDS_CORE_BAR0_DEV_INFO_REGS_OFFSET 0x0000
19 #define PDS_CORE_BAR0_DEV_CMD_REGS_OFFSET 0x0800
20 #define PDS_CORE_BAR0_DEV_CMD_DATA_REGS_OFFSET 0x0c00
21 #define PDS_CORE_BAR0_INTR_STATUS_OFFSET 0x1000
22 #define PDS_CORE_BAR0_INTR_CTRL_OFFSET 0x2000
23 #define PDS_CORE_DEV_CMD_DONE 0x00000001
25 #define PDS_CORE_DEVCMD_TIMEOUT 5
27 #define PDS_CORE_CLIENT_ID 0
28 #define PDS_CORE_ASIC_TYPE_CAPRI 0
31 * enum pds_core_cmd_opcode - Device commands
33 enum pds_core_cmd_opcode
{
36 PDS_CORE_CMD_IDENTIFY
= 1,
37 PDS_CORE_CMD_RESET
= 2,
38 PDS_CORE_CMD_INIT
= 3,
40 PDS_CORE_CMD_FW_DOWNLOAD
= 4,
41 PDS_CORE_CMD_FW_CONTROL
= 5,
44 PDS_CORE_CMD_VF_GETATTR
= 60,
45 PDS_CORE_CMD_VF_SETATTR
= 61,
46 PDS_CORE_CMD_VF_CTRL
= 62,
48 /* Add commands before this line */
54 * enum pds_core_status_code - Device command return codes
56 enum pds_core_status_code
{
57 PDS_RC_SUCCESS
= 0, /* Success */
58 PDS_RC_EVERSION
= 1, /* Incorrect version for request */
59 PDS_RC_EOPCODE
= 2, /* Invalid cmd opcode */
60 PDS_RC_EIO
= 3, /* I/O error */
61 PDS_RC_EPERM
= 4, /* Permission denied */
62 PDS_RC_EQID
= 5, /* Bad qid */
63 PDS_RC_EQTYPE
= 6, /* Bad qtype */
64 PDS_RC_ENOENT
= 7, /* No such element */
65 PDS_RC_EINTR
= 8, /* operation interrupted */
66 PDS_RC_EAGAIN
= 9, /* Try again */
67 PDS_RC_ENOMEM
= 10, /* Out of memory */
68 PDS_RC_EFAULT
= 11, /* Bad address */
69 PDS_RC_EBUSY
= 12, /* Device or resource busy */
70 PDS_RC_EEXIST
= 13, /* object already exists */
71 PDS_RC_EINVAL
= 14, /* Invalid argument */
72 PDS_RC_ENOSPC
= 15, /* No space left or alloc failure */
73 PDS_RC_ERANGE
= 16, /* Parameter out of range */
74 PDS_RC_BAD_ADDR
= 17, /* Descriptor contains a bad ptr */
75 PDS_RC_DEV_CMD
= 18, /* Device cmd attempted on AdminQ */
76 PDS_RC_ENOSUPP
= 19, /* Operation not supported */
77 PDS_RC_ERROR
= 29, /* Generic error */
78 PDS_RC_ERDMA
= 30, /* Generic RDMA error */
79 PDS_RC_EVFID
= 31, /* VF ID does not exist */
80 PDS_RC_BAD_FW
= 32, /* FW file is invalid or corrupted */
81 PDS_RC_ECLIENT
= 33, /* No such client id */
82 PDS_RC_BAD_PCI
= 255, /* Broken PCI when reading status */
86 * struct pds_core_drv_identity - Driver identity information
87 * @drv_type: Driver type (enum pds_core_driver_type)
88 * @os_dist: OS distribution, numeric format
89 * @os_dist_str: OS distribution, string format
90 * @kernel_ver: Kernel version, numeric format
91 * @kernel_ver_str: Kernel version, string format
92 * @driver_ver_str: Driver version, string format
94 struct pds_core_drv_identity
{
97 char os_dist_str
[128];
99 char kernel_ver_str
[32];
100 char driver_ver_str
[32];
103 #define PDS_DEV_TYPE_MAX 16
105 * struct pds_core_dev_identity - Device identity information
106 * @version: Version of device identify
107 * @type: Identify type (0 for now)
108 * @state: Device state
109 * @rsvd: Word boundary padding
110 * @nlifs: Number of LIFs provisioned
111 * @nintrs: Number of interrupts provisioned
112 * @ndbpgs_per_lif: Number of doorbell pages per LIF
113 * @intr_coal_mult: Interrupt coalescing multiplication factor
114 * Scale user-supplied interrupt coalescing
115 * value in usecs to device units using:
116 * device units = usecs * mult / div
117 * @intr_coal_div: Interrupt coalescing division factor
118 * Scale user-supplied interrupt coalescing
119 * value in usecs to device units using:
120 * device units = usecs * mult / div
121 * @vif_types: How many of each VIF device type is supported
123 struct pds_core_dev_identity
{
130 __le32 ndbpgs_per_lif
;
131 __le32 intr_coal_mult
;
132 __le32 intr_coal_div
;
133 __le16 vif_types
[PDS_DEV_TYPE_MAX
];
136 #define PDS_CORE_IDENTITY_VERSION_1 1
139 * struct pds_core_dev_identify_cmd - Driver/device identify command
140 * @opcode: Opcode PDS_CORE_CMD_IDENTIFY
141 * @ver: Highest version of identify supported by driver
143 * Expects to find driver identification info (struct pds_core_drv_identity)
144 * in cmd_regs->data. Driver should keep the devcmd interface locked
145 * while preparing the driver info.
147 struct pds_core_dev_identify_cmd
{
153 * struct pds_core_dev_identify_comp - Device identify command completion
154 * @status: Status of the command (enum pds_core_status_code)
155 * @ver: Version of identify returned by device
157 * Device identification info (struct pds_core_dev_identity) can be found
158 * in cmd_regs->data. Driver should keep the devcmd interface locked
159 * while reading the results.
161 struct pds_core_dev_identify_comp
{
167 * struct pds_core_dev_reset_cmd - Device reset command
168 * @opcode: Opcode PDS_CORE_CMD_RESET
170 * Resets and clears all LIFs, VDevs, and VIFs on the device.
172 struct pds_core_dev_reset_cmd
{
177 * struct pds_core_dev_reset_comp - Reset command completion
178 * @status: Status of the command (enum pds_core_status_code)
180 struct pds_core_dev_reset_comp
{
185 * struct pds_core_dev_init_data - Pointers and info needed for the Core
186 * initialization PDS_CORE_CMD_INIT command. The in and out structs are
187 * overlays on the pds_core_dev_cmd_regs.data space for passing data down
188 * to the firmware on init, and then returning initialization results.
190 struct pds_core_dev_init_data_in
{
191 __le64 adminq_q_base
;
192 __le64 adminq_cq_base
;
193 __le64 notifyq_cq_base
;
197 u8 notifyq_ring_size
;
200 struct pds_core_dev_init_data_out
{
201 __le32 core_hw_index
;
202 __le32 adminq_hw_index
;
203 __le32 notifyq_hw_index
;
209 * struct pds_core_dev_init_cmd - Core device initialize
210 * @opcode: opcode PDS_CORE_CMD_INIT
212 * Initializes the core device and sets up the AdminQ and NotifyQ.
213 * Expects to find initialization data (struct pds_core_dev_init_data_in)
214 * in cmd_regs->data. Driver should keep the devcmd interface locked
215 * while preparing the driver info.
217 struct pds_core_dev_init_cmd
{
222 * struct pds_core_dev_init_comp - Core init completion
223 * @status: Status of the command (enum pds_core_status_code)
225 * Initialization result data (struct pds_core_dev_init_data_in)
226 * is found in cmd_regs->data.
228 struct pds_core_dev_init_comp
{
233 * struct pds_core_fw_download_cmd - Firmware download command
235 * @rsvd: Word boundary padding
236 * @addr: DMA address of the firmware buffer
237 * @offset: offset of the firmware buffer within the full image
238 * @length: number of valid bytes in the firmware buffer
240 struct pds_core_fw_download_cmd
{
249 * struct pds_core_fw_download_comp - Firmware download completion
250 * @status: Status of the command (enum pds_core_status_code)
252 struct pds_core_fw_download_comp
{
257 * enum pds_core_fw_control_oper - FW control operations
258 * @PDS_CORE_FW_INSTALL_ASYNC: Install firmware asynchronously
259 * @PDS_CORE_FW_INSTALL_STATUS: Firmware installation status
260 * @PDS_CORE_FW_ACTIVATE_ASYNC: Activate firmware asynchronously
261 * @PDS_CORE_FW_ACTIVATE_STATUS: Firmware activate status
262 * @PDS_CORE_FW_UPDATE_CLEANUP: Cleanup any firmware update leftovers
263 * @PDS_CORE_FW_GET_BOOT: Return current active firmware slot
264 * @PDS_CORE_FW_SET_BOOT: Set active firmware slot for next boot
265 * @PDS_CORE_FW_GET_LIST: Return list of installed firmware images
267 enum pds_core_fw_control_oper
{
268 PDS_CORE_FW_INSTALL_ASYNC
= 0,
269 PDS_CORE_FW_INSTALL_STATUS
= 1,
270 PDS_CORE_FW_ACTIVATE_ASYNC
= 2,
271 PDS_CORE_FW_ACTIVATE_STATUS
= 3,
272 PDS_CORE_FW_UPDATE_CLEANUP
= 4,
273 PDS_CORE_FW_GET_BOOT
= 5,
274 PDS_CORE_FW_SET_BOOT
= 6,
275 PDS_CORE_FW_GET_LIST
= 7,
278 enum pds_core_fw_slot
{
279 PDS_CORE_FW_SLOT_INVALID
= 0,
280 PDS_CORE_FW_SLOT_A
= 1,
281 PDS_CORE_FW_SLOT_B
= 2,
282 PDS_CORE_FW_SLOT_GOLD
= 3,
286 * struct pds_core_fw_control_cmd - Firmware control command
288 * @rsvd: Word boundary padding
289 * @oper: firmware control operation (enum pds_core_fw_control_oper)
290 * @slot: slot to operate on (enum pds_core_fw_slot)
292 struct pds_core_fw_control_cmd
{
300 * struct pds_core_fw_control_comp - Firmware control copletion
301 * @status: Status of the command (enum pds_core_status_code)
302 * @rsvd: Word alignment space
303 * @slot: Slot number (enum pds_core_fw_slot)
304 * @rsvd1: Struct padding
307 struct pds_core_fw_control_comp
{
315 struct pds_core_fw_name_info
{
316 #define PDS_CORE_FWSLOT_BUFLEN 8
317 #define PDS_CORE_FWVERS_BUFLEN 32
318 char slotname
[PDS_CORE_FWSLOT_BUFLEN
];
319 char fw_version
[PDS_CORE_FWVERS_BUFLEN
];
322 struct pds_core_fw_list_info
{
323 #define PDS_CORE_FWVERS_LIST_LEN 16
325 struct pds_core_fw_name_info fw_names
[PDS_CORE_FWVERS_LIST_LEN
];
328 enum pds_core_vf_attr
{
329 PDS_CORE_VF_ATTR_SPOOFCHK
= 1,
330 PDS_CORE_VF_ATTR_TRUST
= 2,
331 PDS_CORE_VF_ATTR_MAC
= 3,
332 PDS_CORE_VF_ATTR_LINKSTATE
= 4,
333 PDS_CORE_VF_ATTR_VLAN
= 5,
334 PDS_CORE_VF_ATTR_RATE
= 6,
335 PDS_CORE_VF_ATTR_STATSADDR
= 7,
339 * enum pds_core_vf_link_status - Virtual Function link status
340 * @PDS_CORE_VF_LINK_STATUS_AUTO: Use link state of the uplink
341 * @PDS_CORE_VF_LINK_STATUS_UP: Link always up
342 * @PDS_CORE_VF_LINK_STATUS_DOWN: Link always down
344 enum pds_core_vf_link_status
{
345 PDS_CORE_VF_LINK_STATUS_AUTO
= 0,
346 PDS_CORE_VF_LINK_STATUS_UP
= 1,
347 PDS_CORE_VF_LINK_STATUS_DOWN
= 2,
351 * struct pds_core_vf_setattr_cmd - Set VF attributes on the NIC
353 * @attr: Attribute type (enum pds_core_vf_attr)
354 * @vf_index: VF index
355 * @macaddr: mac address
357 * @maxrate: max Tx rate in Mbps
358 * @spoofchk: enable address spoof checking
359 * @trust: enable VF trust
360 * @linkstate: set link up or down
361 * @stats: stats addr struct
362 * @stats.pa: set DMA address for VF stats
363 * @stats.len: length of VF stats space
364 * @pad: force union to specific size
366 struct pds_core_vf_setattr_cmd
{
385 struct pds_core_vf_setattr_comp
{
395 * struct pds_core_vf_getattr_cmd - Get VF attributes from the NIC
397 * @attr: Attribute type (enum pds_core_vf_attr)
398 * @vf_index: VF index
400 struct pds_core_vf_getattr_cmd
{
406 struct pds_core_vf_getattr_comp
{
423 enum pds_core_vf_ctrl_opcode
{
424 PDS_CORE_VF_CTRL_START_ALL
= 0,
425 PDS_CORE_VF_CTRL_START
= 1,
429 * struct pds_core_vf_ctrl_cmd - VF control command
430 * @opcode: Opcode for the command
431 * @ctrl_opcode: VF control operation type
432 * @vf_index: VF Index. It is unused if op START_ALL is used.
435 struct pds_core_vf_ctrl_cmd
{
442 * struct pds_core_vf_ctrl_comp - VF_CTRL command completion.
443 * @status: Status of the command (enum pds_core_status_code)
445 struct pds_core_vf_ctrl_comp
{
450 * union pds_core_dev_cmd - Overlay of core device command structures
452 union pds_core_dev_cmd
{
456 struct pds_core_dev_identify_cmd identify
;
457 struct pds_core_dev_init_cmd init
;
458 struct pds_core_dev_reset_cmd reset
;
459 struct pds_core_fw_download_cmd fw_download
;
460 struct pds_core_fw_control_cmd fw_control
;
462 struct pds_core_vf_setattr_cmd vf_setattr
;
463 struct pds_core_vf_getattr_cmd vf_getattr
;
464 struct pds_core_vf_ctrl_cmd vf_ctrl
;
468 * union pds_core_dev_comp - Overlay of core device completion structures
470 union pds_core_dev_comp
{
474 struct pds_core_dev_identify_comp identify
;
475 struct pds_core_dev_reset_comp reset
;
476 struct pds_core_dev_init_comp init
;
477 struct pds_core_fw_download_comp fw_download
;
478 struct pds_core_fw_control_comp fw_control
;
480 struct pds_core_vf_setattr_comp vf_setattr
;
481 struct pds_core_vf_getattr_comp vf_getattr
;
482 struct pds_core_vf_ctrl_comp vf_ctrl
;
486 * struct pds_core_dev_hwstamp_regs - Hardware current timestamp registers
487 * @tick_low: Low 32 bits of hardware timestamp
488 * @tick_high: High 32 bits of hardware timestamp
490 struct pds_core_dev_hwstamp_regs
{
496 * struct pds_core_dev_info_regs - Device info register format (read-only)
497 * @signature: Signature value of 0x44455649 ('DEVI')
498 * @version: Current version of info
499 * @asic_type: Asic type
500 * @asic_rev: Asic revision
501 * @fw_status: Firmware status
502 * bit 0 - 1 = fw running
503 * bit 4-7 - 4 bit generation number, changes on fw restart
504 * @fw_heartbeat: Firmware heartbeat counter
505 * @serial_num: Serial number
506 * @fw_version: Firmware version
507 * @oprom_regs: oprom_regs to store oprom debug enable/disable and bmp
508 * @rsvd_pad1024: Struct padding
509 * @hwstamp: Hardware current timestamp registers
510 * @rsvd_pad2048: Struct padding
512 struct pds_core_dev_info_regs
{
513 #define PDS_CORE_DEVINFO_FWVERS_BUFLEN 32
514 #define PDS_CORE_DEVINFO_SERIAL_BUFLEN 32
519 #define PDS_CORE_FW_STS_F_STOPPED 0x00
520 #define PDS_CORE_FW_STS_F_RUNNING 0x01
521 #define PDS_CORE_FW_STS_F_GENERATION 0xF0
524 char fw_version
[PDS_CORE_DEVINFO_FWVERS_BUFLEN
];
525 char serial_num
[PDS_CORE_DEVINFO_SERIAL_BUFLEN
];
526 u8 oprom_regs
[32]; /* reserved */
527 u8 rsvd_pad1024
[916];
528 struct pds_core_dev_hwstamp_regs hwstamp
; /* on 1k boundary */
529 u8 rsvd_pad2048
[1016];
533 * struct pds_core_dev_cmd_regs - Device command register format (read-write)
534 * @doorbell: Device Cmd Doorbell, write-only
535 * Write a 1 to signal device to process cmd
536 * @done: Command completed indicator, poll for completion
537 * bit 0 == 1 when command is complete
538 * @cmd: Opcode-specific command bytes
539 * @comp: Opcode-specific response bytes
540 * @rsvd: Struct padding
541 * @data: Opcode-specific side-data
543 struct pds_core_dev_cmd_regs
{
546 union pds_core_dev_cmd cmd
;
547 union pds_core_dev_comp comp
;
553 * struct pds_core_dev_regs - Device register format for bar 0 page 0
554 * @info: Device info registers
555 * @devcmd: Device command registers
557 struct pds_core_dev_regs
{
558 struct pds_core_dev_info_regs info
;
559 struct pds_core_dev_cmd_regs devcmd
;
563 static_assert(sizeof(struct pds_core_drv_identity
) <= 1912);
564 static_assert(sizeof(struct pds_core_dev_identity
) <= 1912);
565 static_assert(sizeof(union pds_core_dev_cmd
) == 64);
566 static_assert(sizeof(union pds_core_dev_comp
) == 16);
567 static_assert(sizeof(struct pds_core_dev_info_regs
) == 2048);
568 static_assert(sizeof(struct pds_core_dev_cmd_regs
) == 2048);
569 static_assert(sizeof(struct pds_core_dev_regs
) == 4096);
570 #endif /* __CHECKER__ */
572 #endif /* _PDS_CORE_IF_H_ */