xref: /linux/include/linux/pds/pds_core_if.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) OR BSD-2-Clause */
2 /* Copyright(c) 2023 Advanced Micro Devices, Inc. */
3 
4 #ifndef _PDS_CORE_IF_H_
5 #define _PDS_CORE_IF_H_
6 
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
14 
15 /* Bar0 */
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
24 
25 #define PDS_CORE_DEVCMD_TIMEOUT			5
26 
27 #define PDS_CORE_CLIENT_ID			0
28 #define PDS_CORE_ASIC_TYPE_CAPRI		0
29 
30 /*
31  * enum pds_core_cmd_opcode - Device commands
32  */
33 enum pds_core_cmd_opcode {
34 	/* Core init */
35 	PDS_CORE_CMD_NOP		= 0,
36 	PDS_CORE_CMD_IDENTIFY		= 1,
37 	PDS_CORE_CMD_RESET		= 2,
38 	PDS_CORE_CMD_INIT		= 3,
39 
40 	PDS_CORE_CMD_FW_DOWNLOAD	= 4,
41 	PDS_CORE_CMD_FW_CONTROL		= 5,
42 
43 	PDS_CORE_CMD_GET_COMPONENT_INFO	= 6,
44 	PDS_CORE_CMD_SEND_PKG_DATA	= 7,
45 	PDS_CORE_CMD_SEND_COMPONENT_TBL	= 8,
46 	PDS_CORE_CMD_SEND_COMPONENT	= 9,
47 	PDS_CORE_CMD_FINALIZE_UPDATE	= 10,
48 	PDS_CORE_CMD_MATCH_RECORD_DESC	= 11,
49 	PDS_CORE_CMD_HOST_MEM		= 12,
50 
51 	/* SR/IOV commands */
52 	PDS_CORE_CMD_VF_GETATTR		= 60,
53 	PDS_CORE_CMD_VF_SETATTR		= 61,
54 	PDS_CORE_CMD_VF_CTRL		= 62,
55 
56 	/* Add commands before this line */
57 	PDS_CORE_CMD_MAX,
58 	PDS_CORE_CMD_COUNT
59 };
60 
61 /*
62  * enum pds_core_status_code - Device command return codes
63  */
64 enum pds_core_status_code {
65 	PDS_RC_SUCCESS	= 0,	/* Success */
66 	PDS_RC_EVERSION	= 1,	/* Incorrect version for request */
67 	PDS_RC_EOPCODE	= 2,	/* Invalid cmd opcode */
68 	PDS_RC_EIO	= 3,	/* I/O error */
69 	PDS_RC_EPERM	= 4,	/* Permission denied */
70 	PDS_RC_EQID	= 5,	/* Bad qid */
71 	PDS_RC_EQTYPE	= 6,	/* Bad qtype */
72 	PDS_RC_ENOENT	= 7,	/* No such element */
73 	PDS_RC_EINTR	= 8,	/* operation interrupted */
74 	PDS_RC_EAGAIN	= 9,	/* Try again */
75 	PDS_RC_ENOMEM	= 10,	/* Out of memory */
76 	PDS_RC_EFAULT	= 11,	/* Bad address */
77 	PDS_RC_EBUSY	= 12,	/* Device or resource busy */
78 	PDS_RC_EEXIST	= 13,	/* object already exists */
79 	PDS_RC_EINVAL	= 14,	/* Invalid argument */
80 	PDS_RC_ENOSPC	= 15,	/* No space left or alloc failure */
81 	PDS_RC_ERANGE	= 16,	/* Parameter out of range */
82 	PDS_RC_BAD_ADDR	= 17,	/* Descriptor contains a bad ptr */
83 	PDS_RC_DEV_CMD	= 18,	/* Device cmd attempted on AdminQ */
84 	PDS_RC_ENOSUPP	= 19,	/* Operation not supported */
85 	PDS_RC_ERROR	= 29,	/* Generic error */
86 	PDS_RC_ERDMA	= 30,	/* Generic RDMA error */
87 	PDS_RC_EVFID	= 31,	/* VF ID does not exist */
88 	PDS_RC_BAD_FW	= 32,	/* FW file is invalid or corrupted */
89 	PDS_RC_ECLIENT	= 33,   /* No such client id */
90 	PDS_RC_BAD_PCI	= 255,  /* Broken PCI when reading status */
91 };
92 
93 /**
94  * struct pds_core_drv_identity - Driver identity information
95  * @drv_type:         Driver type (enum pds_core_driver_type)
96  * @os_dist:          OS distribution, numeric format
97  * @os_dist_str:      OS distribution, string format
98  * @kernel_ver:       Kernel version, numeric format
99  * @kernel_ver_str:   Kernel version, string format
100  * @driver_ver_str:   Driver version, string format
101  */
102 struct pds_core_drv_identity {
103 	__le32 drv_type;
104 	__le32 os_dist;
105 	char   os_dist_str[128];
106 	__le32 kernel_ver;
107 	char   kernel_ver_str[32];
108 	char   driver_ver_str[32];
109 };
110 
111 /**
112  * enum pds_core_dev_capability - Device capabilities
113  * @PDS_CORE_DEV_CAP_PLDM_FW_UPDATE: Device only supports FW update via PLDM
114  * @PDS_CORE_DEV_CAP_HOST_MEM: Device supports host memory for fw use
115  */
116 enum pds_core_dev_capability {
117 	PDS_CORE_DEV_CAP_PLDM_FW_UPDATE = BIT(0),
118 	PDS_CORE_DEV_CAP_HOST_MEM = BIT(1),
119 };
120 
121 #define PDS_DEV_TYPE_MAX	16
122 /**
123  * struct pds_core_dev_identity - Device identity information
124  * @version:	      Version of device identify
125  * @type:	      Identify type (0 for now)
126  * @state:	      Device state
127  * @rsvd:	      Word boundary padding
128  * @nlifs:	      Number of LIFs provisioned
129  * @nintrs:	      Number of interrupts provisioned
130  * @ndbpgs_per_lif:   Number of doorbell pages per LIF
131  * @intr_coal_mult:   Interrupt coalescing multiplication factor
132  *		      Scale user-supplied interrupt coalescing
133  *		      value in usecs to device units using:
134  *		      device units = usecs * mult / div
135  * @intr_coal_div:    Interrupt coalescing division factor
136  *		      Scale user-supplied interrupt coalescing
137  *		      value in usecs to device units using:
138  *		      device units = usecs * mult / div
139  * @vif_types:        How many of each VIF device type is supported
140  * @max_fw_slots:     Number of firmware components reported by device
141  *		      only supported on version >= PDS_CORE_IDENTITY_VERSION_2
142  * @rsvd2:	      Word boundary padding
143  * @capabilities:     Device capabilities
144  *		      only supported on version >= PDS_CORE_IDENTITY_VERSION_2
145  */
146 struct pds_core_dev_identity {
147 	u8     version;
148 	u8     type;
149 	u8     state;
150 	u8     rsvd;
151 	__le32 nlifs;
152 	__le32 nintrs;
153 	__le32 ndbpgs_per_lif;
154 	__le32 intr_coal_mult;
155 	__le32 intr_coal_div;
156 	__le16 vif_types[PDS_DEV_TYPE_MAX];
157 	__le16 max_fw_slots;
158 	u8     rsvd2[6];
159 	__le64 capabilities;
160 };
161 
162 #define PDS_CORE_IDENTITY_VERSION_1	1
163 #define PDS_CORE_IDENTITY_VERSION_2	2
164 
165 /**
166  * struct pds_core_dev_identify_cmd - Driver/device identify command
167  * @opcode:	Opcode PDS_CORE_CMD_IDENTIFY
168  * @ver:	Highest version of identify supported by driver
169  *
170  * Expects to find driver identification info (struct pds_core_drv_identity)
171  * in cmd_regs->data.  Driver should keep the devcmd interface locked
172  * while preparing the driver info.
173  */
174 struct pds_core_dev_identify_cmd {
175 	u8 opcode;
176 	u8 ver;
177 };
178 
179 /**
180  * struct pds_core_dev_identify_comp - Device identify command completion
181  * @status:	Status of the command (enum pds_core_status_code)
182  * @ver:	Version of identify returned by device
183  *
184  * Device identification info (struct pds_core_dev_identity) can be found
185  * in cmd_regs->data.  Driver should keep the devcmd interface locked
186  * while reading the results.
187  */
188 struct pds_core_dev_identify_comp {
189 	u8 status;
190 	u8 ver;
191 };
192 
193 /**
194  * struct pds_core_dev_reset_cmd - Device reset command
195  * @opcode:	Opcode PDS_CORE_CMD_RESET
196  *
197  * Resets and clears all LIFs, VDevs, and VIFs on the device.
198  */
199 struct pds_core_dev_reset_cmd {
200 	u8 opcode;
201 };
202 
203 /**
204  * struct pds_core_dev_reset_comp - Reset command completion
205  * @status:	Status of the command (enum pds_core_status_code)
206  */
207 struct pds_core_dev_reset_comp {
208 	u8 status;
209 };
210 
211 /*
212  * struct pds_core_dev_init_data - Pointers and info needed for the Core
213  * initialization PDS_CORE_CMD_INIT command.  The in and out structs are
214  * overlays on the pds_core_dev_cmd_regs.data space for passing data down
215  * to the firmware on init, and then returning initialization results.
216  */
217 struct pds_core_dev_init_data_in {
218 	__le64 adminq_q_base;
219 	__le64 adminq_cq_base;
220 	__le64 notifyq_cq_base;
221 	__le32 flags;
222 	__le16 intr_index;
223 	u8     adminq_ring_size;
224 	u8     notifyq_ring_size;
225 };
226 
227 struct pds_core_dev_init_data_out {
228 	__le32 core_hw_index;
229 	__le32 adminq_hw_index;
230 	__le32 notifyq_hw_index;
231 	u8     adminq_hw_type;
232 	u8     notifyq_hw_type;
233 };
234 
235 /**
236  * struct pds_core_dev_init_cmd - Core device initialize
237  * @opcode:          opcode PDS_CORE_CMD_INIT
238  *
239  * Initializes the core device and sets up the AdminQ and NotifyQ.
240  * Expects to find initialization data (struct pds_core_dev_init_data_in)
241  * in cmd_regs->data.  Driver should keep the devcmd interface locked
242  * while preparing the driver info.
243  */
244 struct pds_core_dev_init_cmd {
245 	u8     opcode;
246 };
247 
248 /**
249  * struct pds_core_dev_init_comp - Core init completion
250  * @status:     Status of the command (enum pds_core_status_code)
251  *
252  * Initialization result data (struct pds_core_dev_init_data_in)
253  * is found in cmd_regs->data.
254  */
255 struct pds_core_dev_init_comp {
256 	u8     status;
257 };
258 
259 /**
260  * struct pds_core_fw_download_cmd - Firmware download command
261  * @opcode:     opcode
262  * @rsvd:	Word boundary padding
263  * @addr:       DMA address of the firmware buffer
264  * @offset:     offset of the firmware buffer within the full image
265  * @length:     number of valid bytes in the firmware buffer
266  */
267 struct pds_core_fw_download_cmd {
268 	u8     opcode;
269 	u8     rsvd[3];
270 	__le32 offset;
271 	__le64 addr;
272 	__le32 length;
273 };
274 
275 /**
276  * struct pds_core_fw_download_comp - Firmware download completion
277  * @status:     Status of the command (enum pds_core_status_code)
278  */
279 struct pds_core_fw_download_comp {
280 	u8     status;
281 };
282 
283 /**
284  * enum pds_core_fw_control_oper - FW control operations
285  * @PDS_CORE_FW_INSTALL_ASYNC:     Install firmware asynchronously
286  * @PDS_CORE_FW_INSTALL_STATUS:    Firmware installation status
287  * @PDS_CORE_FW_ACTIVATE_ASYNC:    Activate firmware asynchronously
288  * @PDS_CORE_FW_ACTIVATE_STATUS:   Firmware activate status
289  * @PDS_CORE_FW_UPDATE_CLEANUP:    Cleanup any firmware update leftovers
290  * @PDS_CORE_FW_GET_BOOT:          Return current active firmware slot
291  * @PDS_CORE_FW_SET_BOOT:          Set active firmware slot for next boot
292  * @PDS_CORE_FW_GET_LIST:          Return list of installed firmware images
293  */
294 enum pds_core_fw_control_oper {
295 	PDS_CORE_FW_INSTALL_ASYNC          = 0,
296 	PDS_CORE_FW_INSTALL_STATUS         = 1,
297 	PDS_CORE_FW_ACTIVATE_ASYNC         = 2,
298 	PDS_CORE_FW_ACTIVATE_STATUS        = 3,
299 	PDS_CORE_FW_UPDATE_CLEANUP         = 4,
300 	PDS_CORE_FW_GET_BOOT               = 5,
301 	PDS_CORE_FW_SET_BOOT               = 6,
302 	PDS_CORE_FW_GET_LIST               = 7,
303 };
304 
305 /**
306  * enum pds_core_fw_slot - Firmware slot identifiers
307  * @PDS_CORE_FW_SLOT_INVALID: Let firmware select slot based on package metadata
308  * @PDS_CORE_FW_SLOT_A:       Primary firmware slot A
309  * @PDS_CORE_FW_SLOT_B:       Primary firmware slot B
310  * @PDS_CORE_FW_SLOT_GOLD:    Gold/recovery firmware slot
311  * @PDS_CORE_FW_SLOT_MAX:     Sentinel value indicating no slot resolved
312  */
313 enum pds_core_fw_slot {
314 	PDS_CORE_FW_SLOT_INVALID    = 0,
315 	PDS_CORE_FW_SLOT_A	    = 1,
316 	PDS_CORE_FW_SLOT_B          = 2,
317 	PDS_CORE_FW_SLOT_GOLD       = 3,
318 	PDS_CORE_FW_SLOT_MAX        = 0xff,
319 };
320 
321 /**
322  * struct pds_core_fw_control_cmd - Firmware control command
323  * @opcode:    opcode
324  * @rsvd:      Word boundary padding
325  * @oper:      firmware control operation (enum pds_core_fw_control_oper)
326  * @slot:      slot to operate on (enum pds_core_fw_slot)
327  */
328 struct pds_core_fw_control_cmd {
329 	u8  opcode;
330 	u8  rsvd[3];
331 	u8  oper;
332 	u8  slot;
333 };
334 
335 /**
336  * struct pds_core_fw_control_comp - Firmware control copletion
337  * @status:	Status of the command (enum pds_core_status_code)
338  * @rsvd:	Word alignment space
339  * @slot:	Slot number (enum pds_core_fw_slot)
340  * @rsvd1:	Struct padding
341  * @color:	Color bit
342  */
343 struct pds_core_fw_control_comp {
344 	u8     status;
345 	u8     rsvd[3];
346 	u8     slot;
347 	u8     rsvd1[10];
348 	u8     color;
349 };
350 
351 struct pds_core_fw_name_info {
352 #define PDS_CORE_FWSLOT_BUFLEN		8
353 #define PDS_CORE_FWVERS_BUFLEN		32
354 	char   slotname[PDS_CORE_FWSLOT_BUFLEN];
355 	char   fw_version[PDS_CORE_FWVERS_BUFLEN];
356 };
357 
358 struct pds_core_fw_list_info {
359 #define PDS_CORE_FWVERS_LIST_LEN	16
360 	u8 num_fw_slots;
361 	struct pds_core_fw_name_info fw_names[PDS_CORE_FWVERS_LIST_LEN];
362 } __packed;
363 
364 enum pds_core_vf_attr {
365 	PDS_CORE_VF_ATTR_SPOOFCHK	= 1,
366 	PDS_CORE_VF_ATTR_TRUST		= 2,
367 	PDS_CORE_VF_ATTR_MAC		= 3,
368 	PDS_CORE_VF_ATTR_LINKSTATE	= 4,
369 	PDS_CORE_VF_ATTR_VLAN		= 5,
370 	PDS_CORE_VF_ATTR_RATE		= 6,
371 	PDS_CORE_VF_ATTR_STATSADDR	= 7,
372 };
373 
374 /**
375  * enum pds_core_vf_link_status - Virtual Function link status
376  * @PDS_CORE_VF_LINK_STATUS_AUTO:   Use link state of the uplink
377  * @PDS_CORE_VF_LINK_STATUS_UP:     Link always up
378  * @PDS_CORE_VF_LINK_STATUS_DOWN:   Link always down
379  */
380 enum pds_core_vf_link_status {
381 	PDS_CORE_VF_LINK_STATUS_AUTO = 0,
382 	PDS_CORE_VF_LINK_STATUS_UP   = 1,
383 	PDS_CORE_VF_LINK_STATUS_DOWN = 2,
384 };
385 
386 /**
387  * struct pds_core_vf_setattr_cmd - Set VF attributes on the NIC
388  * @opcode:     Opcode
389  * @attr:       Attribute type (enum pds_core_vf_attr)
390  * @vf_index:   VF index
391  * @macaddr:	mac address
392  * @vlanid:	vlan ID
393  * @maxrate:	max Tx rate in Mbps
394  * @spoofchk:	enable address spoof checking
395  * @trust:	enable VF trust
396  * @linkstate:	set link up or down
397  * @stats:	stats addr struct
398  * @stats.pa:	set DMA address for VF stats
399  * @stats.len:	length of VF stats space
400  * @pad:	force union to specific size
401  */
402 struct pds_core_vf_setattr_cmd {
403 	u8     opcode;
404 	u8     attr;
405 	__le16 vf_index;
406 	union {
407 		u8     macaddr[6];
408 		__le16 vlanid;
409 		__le32 maxrate;
410 		u8     spoofchk;
411 		u8     trust;
412 		u8     linkstate;
413 		struct {
414 			__le64 pa;
415 			__le32 len;
416 		} stats;
417 		u8     pad[60];
418 	} __packed;
419 };
420 
421 struct pds_core_vf_setattr_comp {
422 	u8     status;
423 	u8     attr;
424 	__le16 vf_index;
425 	__le16 comp_index;
426 	u8     rsvd[9];
427 	u8     color;
428 };
429 
430 /**
431  * struct pds_core_vf_getattr_cmd - Get VF attributes from the NIC
432  * @opcode:     Opcode
433  * @attr:       Attribute type (enum pds_core_vf_attr)
434  * @vf_index:   VF index
435  */
436 struct pds_core_vf_getattr_cmd {
437 	u8     opcode;
438 	u8     attr;
439 	__le16 vf_index;
440 };
441 
442 struct pds_core_vf_getattr_comp {
443 	u8     status;
444 	u8     attr;
445 	__le16 vf_index;
446 	union {
447 		u8     macaddr[6];
448 		__le16 vlanid;
449 		__le32 maxrate;
450 		u8     spoofchk;
451 		u8     trust;
452 		u8     linkstate;
453 		__le64 stats_pa;
454 		u8     pad[11];
455 	} __packed;
456 	u8     color;
457 };
458 
459 enum pds_core_vf_ctrl_opcode {
460 	PDS_CORE_VF_CTRL_START_ALL	= 0,
461 	PDS_CORE_VF_CTRL_START		= 1,
462 };
463 
464 /**
465  * struct pds_core_vf_ctrl_cmd - VF control command
466  * @opcode:         Opcode for the command
467  * @ctrl_opcode:    VF control operation type
468  * @vf_index:       VF Index. It is unused if op START_ALL is used.
469  */
470 
471 struct pds_core_vf_ctrl_cmd {
472 	u8	opcode;
473 	u8	ctrl_opcode;
474 	__le16	vf_index;
475 };
476 
477 /**
478  * struct pds_core_vf_ctrl_comp - VF_CTRL command completion.
479  * @status:     Status of the command (enum pds_core_status_code)
480  */
481 struct pds_core_vf_ctrl_comp {
482 	u8	status;
483 };
484 
485 /**
486  * struct pds_core_send_pkg_data_cmd - Send package data command
487  * @opcode: Opcode PDS_CORE_CMD_SEND_PKG_DATA
488  * @ver: Driver's max support version of this command
489  * @total_len: Total length of the package data
490  * @offset: Offset in the package data, non-zero if multiple commands are
491  *	    needed for sending the package data
492  * @data_len: Length of data stored at data_pa
493  * @data_pa: Data physical address for DMA to device
494  *
495  * The package data may be too large to store in a single buffer, so multiple
496  * PDS_CORE_CMD_SEND_PKG_DATA devcmds may be needed.
497  */
498 struct pds_core_send_pkg_data_cmd {
499 	u8 opcode;
500 	u8 ver;
501 	__le16 total_len;
502 	__le16 offset;
503 	__le16 data_len;
504 	__le64 data_pa;
505 };
506 
507 /**
508  * struct pds_core_send_pkg_data_comp - Send package data completion
509  * @status: Status of the command (enum pds_core_status_code)
510  * @ver: Device's max supported version of this command
511  * @rsvd: Word boundary padding
512  */
513 struct pds_core_send_pkg_data_comp {
514 	u8 status;
515 	u8 ver;
516 	u8 rsvd[2];
517 };
518 
519 /**
520  * struct pds_core_component_tbl - Component table details
521  * @comparison_stamp: Comparison stamp used for component version checks
522  * @classification: Vendor specific classification info
523  * @identifier: Component's ID
524  * @transfer_flag: Part of the component table this request represents
525  * @version_str_type: The types of strings used
526  * @version_str_len: Length of @version_str
527  * @version_str: Component version information
528  */
529 struct pds_core_component_tbl {
530 	__le32 comparison_stamp;
531 	__le16 classification;
532 	__le16 identifier;
533 	u8     transfer_flag;
534 	u8     version_str_type;
535 	u8     version_str_len;
536 	u8     version_str[];
537 };
538 
539 /**
540  * struct pds_core_send_component_tbl_cmd - Send component table command
541  * @opcode: Opcode PDS_CORE_CMD_SEND_COMPONENT_TBL
542  * @ver: Driver's max support version of this command
543  * @slot_id: enum pds_core_fw_slot
544  * @rsvd: Word boundary padding
545  *
546  * Expects to find component table info (struct pds_core_component_tbl)
547  * in cmd_regs->data.  Driver should keep the devcmd interface locked
548  * while preparing the component table info.
549  */
550 struct pds_core_send_component_tbl_cmd {
551 	u8 opcode;
552 	u8 ver;
553 	u8 slot_id;
554 	u8 rsvd;
555 };
556 
557 enum pds_core_component_resp_code {
558 	PDS_CORE_COMPONENT_VALID = 0x0,
559 	PDS_CORE_COMPONENT_STAMP_IDENTICAL = 0x1,
560 	PDS_CORE_COMPONENT_STAMP_LOWER = 0x2,
561 	PDS_CORE_COMPONENT_STAMP_OR_VERSION_INVALID = 0x3,
562 	PDS_CORE_COMPONENT_CONFLICT = 0x4,
563 	PDS_CORE_COMPONENT_PREREQS_NOT_MET = 0x5,
564 	PDS_CORE_COMPONENT_NOT_SUPPORTED = 0x6,
565 	PDS_CORE_COMPONENT_FW_TYPE_INVALID = 0xd0,
566 };
567 
568 /**
569  * struct pds_core_send_component_tbl_comp - Send component table completion
570  * @status: Status of the command (enum pds_core_status_code)
571  * @ver: Device's max supported version of this command
572  * @completion_code: Component completion code
573  * @response: Component response
574  * @response_code: Component response code
575  * @slot_id: Actual slot_id of the component (enum pds_core_fw_slot)
576  * @rsvd: Word boundary padding
577  */
578 struct pds_core_send_component_tbl_comp {
579 	u8 status;
580 	u8 ver;
581 	u8 completion_code;
582 	u8 response;
583 	u8 response_code;
584 	u8 slot_id;
585 	u8 rsvd[2];
586 };
587 
588 /**
589  * enum pds_core_send_component_op - PDS_CORE_CMD_SEND_COMPONENT operation
590  * @PDS_CORE_SEND_COMPONENT_START: Initial operation to start transfer
591  * @PDS_CORE_SEND_COMPONENT_STATUS: Subsequent calls to check on status
592  */
593 enum pds_core_send_component_op {
594 	PDS_CORE_SEND_COMPONENT_START = 0,
595 	PDS_CORE_SEND_COMPONENT_STATUS = 1,
596 };
597 
598 #define PDS_CORE_FW_COMPONENT_ID_INVALID 0xFFFF
599 /**
600  * struct pds_core_flash_component - Component details
601  * @comparison_stamp: Comparison stamp used for component version checks
602  * @image_size: Component image size
603  * @classification: Vendor specific classification info
604  * @identifier: Component's ID
605  * @options: Component options
606  * @rsvd: Word boundary padding
607  * @version_str_type: The types of strings used
608  * @version_str_len: Length of @version_str
609  * @version_str: Component version information
610  */
611 struct pds_core_flash_component {
612 	__le32 comparison_stamp;
613 	__le32 image_size;
614 	__le16 classification;
615 	__le16 identifier;
616 	__le16 options;
617 	u8 rsvd[3];
618 	u8 version_str_type;
619 	u8 version_str_len;
620 	u8 version_str[];
621 };
622 
623 /**
624  * struct pds_core_send_component_cmd - Send component command
625  * @opcode: Opcode PDS_CORE_CMD_SEND_COMPONENT
626  * @ver: Driver's max supported version of this command
627  * @slot_id: enum pds_core_fw_slot
628  * @operation: enum pds_core_send_component_op
629  * @offset: Offset into the component, non-zero if multiple commands
630  *	    are needed for a single component
631  * @data_len: Length of this part of the component stored at @data_pa
632  * @rsvd: Word boundary padding
633  * @data_pa: DMA address of the component
634  *
635  * A component may be too large to store in a single buffer, so multiple
636  * PDS_CORE_CMD_SEND_COMPONENT devcmds may be needed.
637  *
638  * Expects to find flash component info (struct pds_core_flash_component)
639  * in cmd_regs->data. Driver should keep the devcmd interface locked
640  * while preparing and sending the flash component info.
641  */
642 struct pds_core_send_component_cmd {
643 	u8 opcode;
644 	u8 ver;
645 	u8 slot_id;
646 	u8 operation;
647 	__le32 offset;
648 	__le32 data_len;
649 	u8 rsvd[4];
650 	__le64 data_pa;
651 };
652 
653 /**
654  * struct pds_core_send_component_comp - Send component completion
655  * @status: Status of the command (enum pds_core_status_code)
656  * @ver: Device's max supported version of this command
657  * @completion_code: Completion code
658  * @compat_response: Compatibility response (0 = Component can be updated)
659  * @compat_response_code: Compatibility response code
660  * @rsvd: Word boundary padding
661  */
662 struct pds_core_send_component_comp {
663 	u8 status;
664 	u8 ver;
665 	u8 completion_code;
666 	u8 compat_response;
667 	u8 compat_response_code;
668 	u8 rsvd[3];
669 };
670 
671 /**
672  * enum pds_core_fw_component_type - Firmware component type
673  * @PDS_CORE_FW_TYPE_UNKNOWN: Unknown component type
674  * @PDS_CORE_FW_TYPE_MAIN: Main firmware
675  * @PDS_CORE_FW_TYPE_BOOT: Boot loader
676  * @PDS_CORE_FW_TYPE_CPLD: CPLD firmware
677  * @PDS_CORE_FW_TYPE_SECURE: Secure firmware
678  * @PDS_CORE_FW_TYPE_FPGA: FPGA configuration
679  * @PDS_CORE_FW_TYPE_SUC_MAIN: System Unit Controller firmware
680  * @PDS_CORE_FW_TYPE_SUC_BOOT: System Unit Controller bootloader
681  * @PDS_CORE_FW_TYPE_UBOOT: U-Boot bootloader
682  *
683  * Gold/recovery variants are identified by slot_id == PDS_CORE_FW_SLOT_GOLD
684  * and reported with a ".gold" suffix (e.g., fw.gold).
685  */
686 enum pds_core_fw_component_type {
687 	PDS_CORE_FW_TYPE_UNKNOWN   = 0,
688 	PDS_CORE_FW_TYPE_MAIN      = 1,
689 	PDS_CORE_FW_TYPE_BOOT      = 2,
690 	PDS_CORE_FW_TYPE_CPLD      = 3,
691 	PDS_CORE_FW_TYPE_SECURE    = 4,
692 	PDS_CORE_FW_TYPE_FPGA      = 5,
693 	PDS_CORE_FW_TYPE_SUC_MAIN  = 6,
694 	PDS_CORE_FW_TYPE_SUC_BOOT  = 7,
695 	PDS_CORE_FW_TYPE_UBOOT     = 8,
696 };
697 
698 /**
699  * enum pds_core_component_info_flags - Component info flags
700  * @PDS_CORE_FW_COMPONENT_INFO_F_RUNNING: Component is currently running
701  * @PDS_CORE_FW_COMPONENT_INFO_F_STARTUP: Component version on next FW boot
702  * @PDS_CORE_FW_COMPONENT_INFO_F_FIXED: Component is fixed and cannot be updated
703  * @PDS_CORE_FW_COMPONENT_INFO_F_UPDATE_BY_NAME: Component can be updated
704  *	by name
705  */
706 enum pds_core_component_info_flags {
707 	PDS_CORE_FW_COMPONENT_INFO_F_RUNNING = BIT(0),
708 	PDS_CORE_FW_COMPONENT_INFO_F_STARTUP = BIT(1),
709 	PDS_CORE_FW_COMPONENT_INFO_F_FIXED = BIT(2),
710 	PDS_CORE_FW_COMPONENT_INFO_F_UPDATE_BY_NAME = BIT(3),
711 };
712 
713 /**
714  * struct pds_core_fw_component_info - GET_COMPONENT_INFO entry
715  * @name: Component's name
716  * @component_type: enum pds_core_fw_component_type
717  * @rsvd: Word boundary padding
718  * @flags: enum pds_core_component_info_flags
719  * @identifier: Component's identifier
720  * @slot_id: Component's slot identifier
721  * @version: Component's version
722  */
723 struct pds_core_fw_component_info {
724 #define PDS_CORE_FW_COMPONENT_NAME_BUFLEN 24
725 	char name[PDS_CORE_FW_COMPONENT_NAME_BUFLEN];
726 	u8 component_type;
727 	u8 rsvd[3];
728 	__le16 flags;
729 	u8 identifier;
730 	u8 slot_id;
731 #define PDS_CORE_FW_COMPONENT_VER_BUFLEN 32
732 	char version[PDS_CORE_FW_COMPONENT_VER_BUFLEN];
733 };
734 
735 #define PDS_CORE_FW_COMPONENT_LIST_LEN	((PDS_PAGE_SIZE - 8) / \
736 		sizeof(struct pds_core_fw_component_info))
737 
738 /**
739  * struct pds_core_component_list_info - GET_COMPONENT_INFO completion data
740  * @num_components: Number of valid components
741  * @rsvd: Word boundary padding
742  * @info: List of valid components
743  */
744 struct pds_core_component_list_info {
745 	u8 num_components;
746 	u8 rsvd[7];
747 	struct pds_core_fw_component_info info[PDS_CORE_FW_COMPONENT_LIST_LEN];
748 };
749 
750 /**
751  * struct pds_core_get_component_info_cmd - GET_COMPONENT_INFO command
752  * @opcode: PDS_CORE_CMD_GET_COMPONENT_INFO
753  * @ver: Driver's max supported version of this command
754  * @data_len: Length of data at data_pa
755  * @rsvd: Word boundary padding
756  * @data_pa: DMA address of data
757  *
758  * FW populates struct pds_core_component_list_info pointed to by @data_pa
759  */
760 struct pds_core_get_component_info_cmd {
761 	u8 opcode;
762 	u8 ver;
763 	__le16 data_len;
764 	u8 rsvd[4];
765 	__le64 data_pa;
766 };
767 
768 /**
769  * struct pds_core_get_component_info_comp - GET_COMPONENT_INFO completion
770  * @status: enum pds_core_status_code
771  * @ver: Device's max supported version of this command
772  * @rsvd: Word boundary padding
773  */
774 struct pds_core_get_component_info_comp {
775 	u8 status;
776 	u8 ver;
777 	u8 rsvd[2];
778 };
779 
780 /**
781  * struct pds_core_finalize_update_cmd - FINALIZE_UPDATE command
782  * @opcode: PDS_CORE_CMD_FINALIZE_UPDATE
783  * @ver: Driver's max support version of this command
784  * @rsvd: Word boundary padding
785  *
786  * Driver sends at the end of updating all components to finalize the update
787  */
788 struct pds_core_finalize_update_cmd {
789 	u8 opcode;
790 	u8 ver;
791 	u8 rsvd[2];
792 };
793 
794 /**
795  * struct pds_core_finalize_update_comp - FINALIZE_UPDATE completion
796  * @status: enum pds_core_status_code
797  * @ver: Device's max supported version of this command
798  * @rsvd: Word boundary padding
799  */
800 struct pds_core_finalize_update_comp {
801 	u8 status;
802 	u8 ver;
803 	u8 rsvd[2];
804 };
805 
806 /**
807  * struct pds_core_match_record_desc_cmd - MATCH_RECORD_DESC command
808  * @opcode: PDS_CORE_CMD_MATCH_RECORD_DESC
809  * @ver: Driver's max supported version of this command
810  * @type: PLDM Descriptor Identifier Type
811  * @size: Length of the Descriptor Identifier Value
812  * @rsvd: Word boundary padding
813  *
814  * Expects to find the Descriptor Identifier Data in cmd_regs->data. Driver
815  * should keep the devcmd interface locked while preparing and sending this
816  * command.
817  */
818 struct pds_core_match_record_desc_cmd {
819 	u8 opcode;
820 	u8 ver;
821 	__le16 type;
822 	__le16 size;
823 	u8 rsvd[2];
824 };
825 
826 /**
827  * struct pds_core_match_record_desc_comp - MATCH_RECORD_DESC completion
828  * @status: enum pds_core_status_code
829  * @ver: Device's max supported version of this command
830  * @match: Whether or not the Record Descriptor matches the device
831  * @rsvd: Word boundary padding
832  *
833  * When status is PDS_RC_SUCCESS, then @match is valid, otherwise it's
834  * undefined.
835  */
836 struct pds_core_match_record_desc_comp {
837 	u8 status;
838 	u8 ver;
839 	u8 match;
840 	u8 rsvd;
841 };
842 
843 /**
844  * enum pds_core_host_mem_oper - HOST_MEM sub-operations
845  * @PDS_CORE_HOST_MEM_GET_COUNT: Query number of memory requests
846  * @PDS_CORE_HOST_MEM_QUERY:     Query details of a memory request
847  * @PDS_CORE_HOST_MEM_ADD:       Provide allocated memory to firmware
848  * @PDS_CORE_HOST_MEM_DEL:       Notify firmware of memory deallocation
849  */
850 enum pds_core_host_mem_oper {
851 	PDS_CORE_HOST_MEM_GET_COUNT	= 0,
852 	PDS_CORE_HOST_MEM_QUERY		= 1,
853 	PDS_CORE_HOST_MEM_ADD		= 2,
854 	PDS_CORE_HOST_MEM_DEL		= 3,
855 };
856 
857 /**
858  * struct pds_core_host_mem_cmd - HOST_MEM command
859  * @opcode:     Opcode PDS_CORE_CMD_HOST_MEM
860  * @oper:       Operation (enum pds_core_host_mem_oper)
861  * @index:      Memory request index (GET_COUNT: max_count, QUERY: index)
862  * @tag:        Tag for this memory request (ADD/DEL)
863  * @reason:     Reason for deletion (DEL only)
864  * @rsvd:       Reserved
865  * @max_contig: Maximum contiguous memory size (GET_COUNT only)
866  * @size:       Size of memory in bytes (ADD only)
867  * @buf_pa:     DMA address of memory (ADD only)
868  *
869  * Unified command for all host memory operations. Fields are reused
870  * across operations to minimize opcode space usage.
871  */
872 struct pds_core_host_mem_cmd {
873 	u8     opcode;
874 	u8     oper;
875 	__le16 index;
876 	__le16 tag;
877 	u8     reason;
878 	u8     rsvd;
879 	__le32 max_contig;
880 	__le32 size;
881 	__le64 buf_pa;
882 };
883 
884 /**
885  * struct pds_core_host_mem_comp - HOST_MEM completion
886  * @status:       Status of the command (enum pds_core_status_code)
887  * @oper:         Operation that was performed
888  * @count:        Number of memory requests (GET_COUNT)
889  * @size:         Size of memory request in bytes (QUERY)
890  * @tag:          Tag for this memory request (QUERY/DEL)
891  * @rsvd:         Reserved
892  */
893 struct pds_core_host_mem_comp {
894 	u8     status;
895 	u8     oper;
896 	__le16 count;
897 	__le32 size;
898 	__le16 tag;
899 	u8     rsvd[6];
900 };
901 
902 /*
903  * union pds_core_dev_cmd - Overlay of core device command structures
904  */
905 union pds_core_dev_cmd {
906 	u8     opcode;
907 	u32    words[16];
908 
909 	struct pds_core_dev_identify_cmd identify;
910 	struct pds_core_dev_init_cmd     init;
911 	struct pds_core_dev_reset_cmd    reset;
912 	struct pds_core_fw_download_cmd  fw_download;
913 	struct pds_core_fw_control_cmd   fw_control;
914 
915 	struct pds_core_vf_setattr_cmd   vf_setattr;
916 	struct pds_core_vf_getattr_cmd   vf_getattr;
917 	struct pds_core_vf_ctrl_cmd      vf_ctrl;
918 
919 	struct pds_core_get_component_info_cmd get_component_info;
920 	struct pds_core_send_pkg_data_cmd      send_pkg_data;
921 	struct pds_core_send_component_tbl_cmd send_component_tbl;
922 	struct pds_core_send_component_cmd     send_component;
923 	struct pds_core_finalize_update_cmd    finalize_update;
924 	struct pds_core_match_record_desc_cmd  match_record_desc;
925 	struct pds_core_host_mem_cmd           host_mem;
926 };
927 
928 /*
929  * union pds_core_dev_comp - Overlay of core device completion structures
930  */
931 union pds_core_dev_comp {
932 	u8                                status;
933 	u8                                bytes[16];
934 
935 	struct pds_core_dev_identify_comp identify;
936 	struct pds_core_dev_reset_comp    reset;
937 	struct pds_core_dev_init_comp     init;
938 	struct pds_core_fw_download_comp  fw_download;
939 	struct pds_core_fw_control_comp   fw_control;
940 
941 	struct pds_core_vf_setattr_comp   vf_setattr;
942 	struct pds_core_vf_getattr_comp   vf_getattr;
943 	struct pds_core_vf_ctrl_comp      vf_ctrl;
944 
945 	struct pds_core_get_component_info_comp get_component_info;
946 	struct pds_core_send_pkg_data_comp      send_pkg_data;
947 	struct pds_core_send_component_tbl_comp send_component_tbl;
948 	struct pds_core_send_component_comp     send_component;
949 	struct pds_core_finalize_update_comp    finalize_update;
950 	struct pds_core_match_record_desc_comp  match_record_desc;
951 	struct pds_core_host_mem_comp           host_mem;
952 };
953 
954 /**
955  * struct pds_core_dev_hwstamp_regs - Hardware current timestamp registers
956  * @tick_low:        Low 32 bits of hardware timestamp
957  * @tick_high:       High 32 bits of hardware timestamp
958  */
959 struct pds_core_dev_hwstamp_regs {
960 	u32    tick_low;
961 	u32    tick_high;
962 };
963 
964 /**
965  * struct pds_core_dev_info_regs - Device info register format (read-only)
966  * @signature:       Signature value of 0x44455649 ('DEVI')
967  * @version:         Current version of info
968  * @asic_type:       Asic type
969  * @asic_rev:        Asic revision
970  * @fw_status:       Firmware status
971  *			bit 0   - 1 = fw running
972  *			bit 4-7 - 4 bit generation number, changes on fw restart
973  * @fw_heartbeat:    Firmware heartbeat counter
974  * @serial_num:      Serial number
975  * @fw_version:      Firmware version
976  * @oprom_regs:      oprom_regs to store oprom debug enable/disable and bmp
977  * @rsvd_pad1024:    Struct padding
978  * @hwstamp:         Hardware current timestamp registers
979  * @rsvd_pad2048:    Struct padding
980  */
981 struct pds_core_dev_info_regs {
982 #define PDS_CORE_DEVINFO_FWVERS_BUFLEN 32
983 #define PDS_CORE_DEVINFO_SERIAL_BUFLEN 32
984 	u32    signature;
985 	u8     version;
986 	u8     asic_type;
987 	u8     asic_rev;
988 #define PDS_CORE_FW_STS_F_STOPPED	0x00
989 #define PDS_CORE_FW_STS_F_RUNNING	0x01
990 #define PDS_CORE_FW_STS_F_GENERATION	0xF0
991 	u8     fw_status;
992 	__le32 fw_heartbeat;
993 	char   fw_version[PDS_CORE_DEVINFO_FWVERS_BUFLEN];
994 	char   serial_num[PDS_CORE_DEVINFO_SERIAL_BUFLEN];
995 	u8     oprom_regs[32];     /* reserved */
996 	u8     rsvd_pad1024[916];
997 	struct pds_core_dev_hwstamp_regs hwstamp;   /* on 1k boundary */
998 	u8     rsvd_pad2048[1016];
999 } __packed;
1000 
1001 /**
1002  * struct pds_core_dev_cmd_regs - Device command register format (read-write)
1003  * @doorbell:	Device Cmd Doorbell, write-only
1004  *              Write a 1 to signal device to process cmd
1005  * @done:	Command completed indicator, poll for completion
1006  *              bit 0 == 1 when command is complete
1007  * @cmd:	Opcode-specific command bytes
1008  * @comp:	Opcode-specific response bytes
1009  * @rsvd:	Struct padding
1010  * @data:	Opcode-specific side-data
1011  */
1012 struct pds_core_dev_cmd_regs {
1013 	u32                     doorbell;
1014 	u32                     done;
1015 	union pds_core_dev_cmd  cmd;
1016 	union pds_core_dev_comp comp;
1017 	u8                      rsvd[48];
1018 	u32                     data[478];
1019 } __packed;
1020 
1021 /**
1022  * struct pds_core_dev_regs - Device register format for bar 0 page 0
1023  * @info:            Device info registers
1024  * @devcmd:          Device command registers
1025  */
1026 struct pds_core_dev_regs {
1027 	struct pds_core_dev_info_regs info;
1028 	struct pds_core_dev_cmd_regs  devcmd;
1029 } __packed;
1030 
1031 #ifndef __CHECKER__
1032 static_assert(sizeof(struct pds_core_drv_identity) <= 1912);
1033 static_assert(sizeof(struct pds_core_dev_identity) <= 1912);
1034 static_assert(sizeof(union pds_core_dev_cmd) == 64);
1035 static_assert(sizeof(union pds_core_dev_comp) == 16);
1036 static_assert(sizeof(struct pds_core_dev_info_regs) == 2048);
1037 static_assert(sizeof(struct pds_core_dev_cmd_regs) == 2048);
1038 static_assert(sizeof(struct pds_core_dev_regs) == 4096);
1039 #endif /* __CHECKER__ */
1040 
1041 #endif /* _PDS_CORE_IF_H_ */
1042