xref: /linux-6.15/include/linux/pds/pds_adminq.h (revision bf8a352d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2023 Advanced Micro Devices, Inc */
3 
4 #ifndef _PDS_CORE_ADMINQ_H_
5 #define _PDS_CORE_ADMINQ_H_
6 
7 #define PDSC_ADMINQ_MAX_POLL_INTERVAL	256
8 
9 enum pds_core_adminq_flags {
10 	PDS_AQ_FLAG_FASTPOLL	= BIT(1),	/* completion poll at 1ms */
11 };
12 
13 /*
14  * enum pds_core_adminq_opcode - AdminQ command opcodes
15  * These commands are only processed on AdminQ, not available in devcmd
16  */
17 enum pds_core_adminq_opcode {
18 	PDS_AQ_CMD_NOP			= 0,
19 
20 	/* Client control */
21 	PDS_AQ_CMD_CLIENT_REG		= 6,
22 	PDS_AQ_CMD_CLIENT_UNREG		= 7,
23 	PDS_AQ_CMD_CLIENT_CMD		= 8,
24 
25 	/* LIF commands */
26 	PDS_AQ_CMD_LIF_IDENTIFY		= 20,
27 	PDS_AQ_CMD_LIF_INIT		= 21,
28 	PDS_AQ_CMD_LIF_RESET		= 22,
29 	PDS_AQ_CMD_LIF_GETATTR		= 23,
30 	PDS_AQ_CMD_LIF_SETATTR		= 24,
31 	PDS_AQ_CMD_LIF_SETPHC		= 25,
32 
33 	PDS_AQ_CMD_RX_MODE_SET		= 30,
34 	PDS_AQ_CMD_RX_FILTER_ADD	= 31,
35 	PDS_AQ_CMD_RX_FILTER_DEL	= 32,
36 
37 	/* Queue commands */
38 	PDS_AQ_CMD_Q_IDENTIFY		= 39,
39 	PDS_AQ_CMD_Q_INIT		= 40,
40 	PDS_AQ_CMD_Q_CONTROL		= 41,
41 
42 	/* SR/IOV commands */
43 	PDS_AQ_CMD_VF_GETATTR		= 60,
44 	PDS_AQ_CMD_VF_SETATTR		= 61,
45 };
46 
47 /*
48  * enum pds_core_notifyq_opcode - NotifyQ event codes
49  */
50 enum pds_core_notifyq_opcode {
51 	PDS_EVENT_LINK_CHANGE		= 1,
52 	PDS_EVENT_RESET			= 2,
53 	PDS_EVENT_XCVR			= 5,
54 	PDS_EVENT_CLIENT		= 6,
55 };
56 
57 #define PDS_COMP_COLOR_MASK  0x80
58 
59 /**
60  * struct pds_core_notifyq_event - Generic event reporting structure
61  * @eid:   event number
62  * @ecode: event code
63  *
64  * This is the generic event report struct from which the other
65  * actual events will be formed.
66  */
67 struct pds_core_notifyq_event {
68 	__le64 eid;
69 	__le16 ecode;
70 };
71 
72 /**
73  * struct pds_core_link_change_event - Link change event notification
74  * @eid:		event number
75  * @ecode:		event code = PDS_EVENT_LINK_CHANGE
76  * @link_status:	link up/down, with error bits
77  * @link_speed:		speed of the network link
78  *
79  * Sent when the network link state changes between UP and DOWN
80  */
81 struct pds_core_link_change_event {
82 	__le64 eid;
83 	__le16 ecode;
84 	__le16 link_status;
85 	__le32 link_speed;	/* units of 1Mbps: e.g. 10000 = 10Gbps */
86 };
87 
88 /**
89  * struct pds_core_reset_event - Reset event notification
90  * @eid:		event number
91  * @ecode:		event code = PDS_EVENT_RESET
92  * @reset_code:		reset type
93  * @state:		0=pending, 1=complete, 2=error
94  *
95  * Sent when the NIC or some subsystem is going to be or
96  * has been reset.
97  */
98 struct pds_core_reset_event {
99 	__le64 eid;
100 	__le16 ecode;
101 	u8     reset_code;
102 	u8     state;
103 };
104 
105 /**
106  * struct pds_core_client_event - Client event notification
107  * @eid:		event number
108  * @ecode:		event code = PDS_EVENT_CLIENT
109  * @client_id:          client to sent event to
110  * @client_event:       wrapped event struct for the client
111  *
112  * Sent when an event needs to be passed on to a client
113  */
114 struct pds_core_client_event {
115 	__le64 eid;
116 	__le16 ecode;
117 	__le16 client_id;
118 	u8     client_event[54];
119 };
120 
121 /**
122  * struct pds_core_notifyq_cmd - Placeholder for building qcq
123  * @data:      anonymous field for building the qcq
124  */
125 struct pds_core_notifyq_cmd {
126 	__le32 data;	/* Not used but needed for qcq structure */
127 };
128 
129 /*
130  * union pds_core_notifyq_comp - Overlay of notifyq event structures
131  */
132 union pds_core_notifyq_comp {
133 	struct {
134 		__le64 eid;
135 		__le16 ecode;
136 	};
137 	struct pds_core_notifyq_event     event;
138 	struct pds_core_link_change_event link_change;
139 	struct pds_core_reset_event       reset;
140 	u8     data[64];
141 };
142 
143 #define PDS_DEVNAME_LEN		32
144 /**
145  * struct pds_core_client_reg_cmd - Register a new client with DSC
146  * @opcode:         opcode PDS_AQ_CMD_CLIENT_REG
147  * @rsvd:           word boundary padding
148  * @devname:        text name of client device
149  * @vif_type:       what type of device (enum pds_core_vif_types)
150  *
151  * Tell the DSC of the new client, and receive a client_id from DSC.
152  */
153 struct pds_core_client_reg_cmd {
154 	u8     opcode;
155 	u8     rsvd[3];
156 	char   devname[PDS_DEVNAME_LEN];
157 	u8     vif_type;
158 };
159 
160 /**
161  * struct pds_core_client_reg_comp - Client registration completion
162  * @status:     Status of the command (enum pdc_core_status_code)
163  * @rsvd:       Word boundary padding
164  * @comp_index: Index in the descriptor ring for which this is the completion
165  * @client_id:  New id assigned by DSC
166  * @rsvd1:      Word boundary padding
167  * @color:      Color bit
168  */
169 struct pds_core_client_reg_comp {
170 	u8     status;
171 	u8     rsvd;
172 	__le16 comp_index;
173 	__le16 client_id;
174 	u8     rsvd1[9];
175 	u8     color;
176 };
177 
178 /**
179  * struct pds_core_client_unreg_cmd - Unregister a client from DSC
180  * @opcode:     opcode PDS_AQ_CMD_CLIENT_UNREG
181  * @rsvd:       word boundary padding
182  * @client_id:  id of client being removed
183  *
184  * Tell the DSC this client is going away and remove its context
185  * This uses the generic completion.
186  */
187 struct pds_core_client_unreg_cmd {
188 	u8     opcode;
189 	u8     rsvd;
190 	__le16 client_id;
191 };
192 
193 /**
194  * struct pds_core_client_request_cmd - Pass along a wrapped client AdminQ cmd
195  * @opcode:     opcode PDS_AQ_CMD_CLIENT_CMD
196  * @rsvd:       word boundary padding
197  * @client_id:  id of client being removed
198  * @client_cmd: the wrapped client command
199  *
200  * Proxy post an adminq command for the client.
201  * This uses the generic completion.
202  */
203 struct pds_core_client_request_cmd {
204 	u8     opcode;
205 	u8     rsvd;
206 	__le16 client_id;
207 	u8     client_cmd[60];
208 };
209 
210 #define PDS_CORE_MAX_FRAGS		16
211 
212 #define PDS_CORE_QCQ_F_INITED		BIT(0)
213 #define PDS_CORE_QCQ_F_SG		BIT(1)
214 #define PDS_CORE_QCQ_F_INTR		BIT(2)
215 #define PDS_CORE_QCQ_F_TX_STATS		BIT(3)
216 #define PDS_CORE_QCQ_F_RX_STATS		BIT(4)
217 #define PDS_CORE_QCQ_F_NOTIFYQ		BIT(5)
218 #define PDS_CORE_QCQ_F_CMB_RINGS	BIT(6)
219 #define PDS_CORE_QCQ_F_CORE		BIT(7)
220 
221 enum pds_core_lif_type {
222 	PDS_CORE_LIF_TYPE_DEFAULT = 0,
223 };
224 
225 /**
226  * union pds_core_lif_config - LIF configuration
227  * @state:	    LIF state (enum pds_core_lif_state)
228  * @rsvd:           Word boundary padding
229  * @name:	    LIF name
230  * @rsvd2:          Word boundary padding
231  * @features:	    LIF features active (enum pds_core_hw_features)
232  * @queue_count:    Queue counts per queue-type
233  * @words:          Full union buffer size
234  */
235 union pds_core_lif_config {
236 	struct {
237 		u8     state;
238 		u8     rsvd[3];
239 		char   name[PDS_CORE_IFNAMSIZ];
240 		u8     rsvd2[12];
241 		__le64 features;
242 		__le32 queue_count[PDS_CORE_QTYPE_MAX];
243 	} __packed;
244 	__le32 words[64];
245 };
246 
247 /**
248  * struct pds_core_lif_status - LIF status register
249  * @eid:	     most recent NotifyQ event id
250  * @rsvd:            full struct size
251  */
252 struct pds_core_lif_status {
253 	__le64 eid;
254 	u8     rsvd[56];
255 };
256 
257 /**
258  * struct pds_core_lif_info - LIF info structure
259  * @config:	LIF configuration structure
260  * @status:	LIF status structure
261  */
262 struct pds_core_lif_info {
263 	union pds_core_lif_config config;
264 	struct pds_core_lif_status status;
265 };
266 
267 /**
268  * struct pds_core_lif_identity - LIF identity information (type-specific)
269  * @features:		LIF features (see enum pds_core_hw_features)
270  * @version:		Identify structure version
271  * @hw_index:		LIF hardware index
272  * @rsvd:		Word boundary padding
273  * @max_nb_sessions:	Maximum number of sessions supported
274  * @rsvd2:		buffer padding
275  * @config:		LIF config struct with features, q counts
276  */
277 struct pds_core_lif_identity {
278 	__le64 features;
279 	u8     version;
280 	u8     hw_index;
281 	u8     rsvd[2];
282 	__le32 max_nb_sessions;
283 	u8     rsvd2[120];
284 	union pds_core_lif_config config;
285 };
286 
287 /**
288  * struct pds_core_lif_identify_cmd - Get LIF identity info command
289  * @opcode:	Opcode PDS_AQ_CMD_LIF_IDENTIFY
290  * @type:	LIF type (enum pds_core_lif_type)
291  * @client_id:	Client identifier
292  * @ver:	Version of identify returned by device
293  * @rsvd:       Word boundary padding
294  * @ident_pa:	DMA address to receive identity info
295  *
296  * Firmware will copy LIF identity data (struct pds_core_lif_identity)
297  * into the buffer address given.
298  */
299 struct pds_core_lif_identify_cmd {
300 	u8     opcode;
301 	u8     type;
302 	__le16 client_id;
303 	u8     ver;
304 	u8     rsvd[3];
305 	__le64 ident_pa;
306 };
307 
308 /**
309  * struct pds_core_lif_identify_comp - LIF identify command completion
310  * @status:	Status of the command (enum pds_core_status_code)
311  * @ver:	Version of identify returned by device
312  * @bytes:	Bytes copied into the buffer
313  * @rsvd:       Word boundary padding
314  * @color:      Color bit
315  */
316 struct pds_core_lif_identify_comp {
317 	u8     status;
318 	u8     ver;
319 	__le16 bytes;
320 	u8     rsvd[11];
321 	u8     color;
322 };
323 
324 /**
325  * struct pds_core_lif_init_cmd - LIF init command
326  * @opcode:	Opcode PDS_AQ_CMD_LIF_INIT
327  * @type:	LIF type (enum pds_core_lif_type)
328  * @client_id:	Client identifier
329  * @rsvd:       Word boundary padding
330  * @info_pa:	Destination address for LIF info (struct pds_core_lif_info)
331  */
332 struct pds_core_lif_init_cmd {
333 	u8     opcode;
334 	u8     type;
335 	__le16 client_id;
336 	__le32 rsvd;
337 	__le64 info_pa;
338 };
339 
340 /**
341  * struct pds_core_lif_init_comp - LIF init command completion
342  * @status:	Status of the command (enum pds_core_status_code)
343  * @rsvd:       Word boundary padding
344  * @hw_index:	Hardware index of the initialized LIF
345  * @rsvd1:      Word boundary padding
346  * @color:      Color bit
347  */
348 struct pds_core_lif_init_comp {
349 	u8 status;
350 	u8 rsvd;
351 	__le16 hw_index;
352 	u8     rsvd1[11];
353 	u8     color;
354 };
355 
356 /**
357  * struct pds_core_lif_reset_cmd - LIF reset command
358  * Will reset only the specified LIF.
359  * @opcode:	Opcode PDS_AQ_CMD_LIF_RESET
360  * @rsvd:       Word boundary padding
361  * @client_id:	Client identifier
362  */
363 struct pds_core_lif_reset_cmd {
364 	u8     opcode;
365 	u8     rsvd;
366 	__le16 client_id;
367 };
368 
369 /**
370  * enum pds_core_lif_attr - List of LIF attributes
371  * @PDS_CORE_LIF_ATTR_STATE:		LIF state attribute
372  * @PDS_CORE_LIF_ATTR_NAME:		LIF name attribute
373  * @PDS_CORE_LIF_ATTR_FEATURES:		LIF features attribute
374  * @PDS_CORE_LIF_ATTR_STATS_CTRL:	LIF statistics control attribute
375  */
376 enum pds_core_lif_attr {
377 	PDS_CORE_LIF_ATTR_STATE		= 0,
378 	PDS_CORE_LIF_ATTR_NAME		= 1,
379 	PDS_CORE_LIF_ATTR_FEATURES	= 4,
380 	PDS_CORE_LIF_ATTR_STATS_CTRL	= 6,
381 };
382 
383 /**
384  * struct pds_core_lif_setattr_cmd - Set LIF attributes on the NIC
385  * @opcode:	Opcode PDS_AQ_CMD_LIF_SETATTR
386  * @attr:	Attribute type (enum pds_core_lif_attr)
387  * @client_id:	Client identifier
388  * @state:	LIF state (enum pds_core_lif_state)
389  * @name:	The name string, 0 terminated
390  * @features:	Features (enum pds_core_hw_features)
391  * @stats_ctl:	Stats control commands (enum pds_core_stats_ctl_cmd)
392  * @rsvd:       Command Buffer padding
393  */
394 struct pds_core_lif_setattr_cmd {
395 	u8     opcode;
396 	u8     attr;
397 	__le16 client_id;
398 	union {
399 		u8      state;
400 		char    name[PDS_CORE_IFNAMSIZ];
401 		__le64  features;
402 		u8      stats_ctl;
403 		u8      rsvd[60];
404 	} __packed;
405 };
406 
407 /**
408  * struct pds_core_lif_setattr_comp - LIF set attr command completion
409  * @status:	Status of the command (enum pds_core_status_code)
410  * @rsvd:       Word boundary padding
411  * @comp_index: Index in the descriptor ring for which this is the completion
412  * @features:	Features (enum pds_core_hw_features)
413  * @rsvd2:      Word boundary padding
414  * @color:	Color bit
415  */
416 struct pds_core_lif_setattr_comp {
417 	u8     status;
418 	u8     rsvd;
419 	__le16 comp_index;
420 	union {
421 		__le64  features;
422 		u8      rsvd2[11];
423 	} __packed;
424 	u8     color;
425 };
426 
427 /**
428  * struct pds_core_lif_getattr_cmd - Get LIF attributes from the NIC
429  * @opcode:	Opcode PDS_AQ_CMD_LIF_GETATTR
430  * @attr:	Attribute type (enum pds_core_lif_attr)
431  * @client_id:	Client identifier
432  */
433 struct pds_core_lif_getattr_cmd {
434 	u8     opcode;
435 	u8     attr;
436 	__le16 client_id;
437 };
438 
439 /**
440  * struct pds_core_lif_getattr_comp - LIF get attr command completion
441  * @status:	Status of the command (enum pds_core_status_code)
442  * @rsvd:       Word boundary padding
443  * @comp_index: Index in the descriptor ring for which this is the completion
444  * @state:	LIF state (enum pds_core_lif_state)
445  * @name:	LIF name string, 0 terminated
446  * @features:	Features (enum pds_core_hw_features)
447  * @rsvd2:      Word boundary padding
448  * @color:	Color bit
449  */
450 struct pds_core_lif_getattr_comp {
451 	u8     status;
452 	u8     rsvd;
453 	__le16 comp_index;
454 	union {
455 		u8      state;
456 		__le64  features;
457 		u8      rsvd2[11];
458 	} __packed;
459 	u8     color;
460 };
461 
462 /**
463  * union pds_core_q_identity - Queue identity information
464  * @version:	Queue type version that can be used with FW
465  * @supported:	Bitfield of queue versions, first bit = ver 0
466  * @rsvd:       Word boundary padding
467  * @features:	Queue features
468  * @desc_sz:	Descriptor size
469  * @comp_sz:	Completion descriptor size
470  * @rsvd2:      Word boundary padding
471  */
472 struct pds_core_q_identity {
473 	u8      version;
474 	u8      supported;
475 	u8      rsvd[6];
476 #define PDS_CORE_QIDENT_F_CQ	0x01	/* queue has completion ring */
477 	__le64  features;
478 	__le16  desc_sz;
479 	__le16  comp_sz;
480 	u8      rsvd2[6];
481 };
482 
483 /**
484  * struct pds_core_q_identify_cmd - queue identify command
485  * @opcode:	Opcode PDS_AQ_CMD_Q_IDENTIFY
486  * @type:	Logical queue type (enum pds_core_logical_qtype)
487  * @client_id:	Client identifier
488  * @ver:	Highest queue type version that the driver supports
489  * @rsvd:       Word boundary padding
490  * @ident_pa:   DMA address to receive the data (struct pds_core_q_identity)
491  */
492 struct pds_core_q_identify_cmd {
493 	u8     opcode;
494 	u8     type;
495 	__le16 client_id;
496 	u8     ver;
497 	u8     rsvd[3];
498 	__le64 ident_pa;
499 };
500 
501 /**
502  * struct pds_core_q_identify_comp - queue identify command completion
503  * @status:	Status of the command (enum pds_core_status_code)
504  * @rsvd:       Word boundary padding
505  * @comp_index:	Index in the descriptor ring for which this is the completion
506  * @ver:	Queue type version that can be used with FW
507  * @rsvd1:      Word boundary padding
508  * @color:      Color bit
509  */
510 struct pds_core_q_identify_comp {
511 	u8     status;
512 	u8     rsvd;
513 	__le16 comp_index;
514 	u8     ver;
515 	u8     rsvd1[10];
516 	u8     color;
517 };
518 
519 /**
520  * struct pds_core_q_init_cmd - Queue init command
521  * @opcode:	  Opcode PDS_AQ_CMD_Q_INIT
522  * @type:	  Logical queue type
523  * @client_id:	  Client identifier
524  * @ver:	  Queue type version
525  * @rsvd:         Word boundary padding
526  * @index:	  (LIF, qtype) relative admin queue index
527  * @intr_index:	  Interrupt control register index, or Event queue index
528  * @pid:	  Process ID
529  * @flags:
530  *    IRQ:	  Interrupt requested on completion
531  *    ENA:	  Enable the queue.  If ENA=0 the queue is initialized
532  *		  but remains disabled, to be later enabled with the
533  *		  Queue Enable command. If ENA=1, then queue is
534  *		  initialized and then enabled.
535  * @cos:	  Class of service for this queue
536  * @ring_size:	  Queue ring size, encoded as a log2(size), in
537  *		  number of descriptors.  The actual ring size is
538  *		  (1 << ring_size).  For example, to select a ring size
539  *		  of 64 descriptors write ring_size = 6. The minimum
540  *		  ring_size value is 2 for a ring of 4 descriptors.
541  *		  The maximum ring_size value is 12 for a ring of 4k
542  *		  descriptors. Values of ring_size <2 and >12 are
543  *		  reserved.
544  * @ring_base:	  Queue ring base address
545  * @cq_ring_base: Completion queue ring base address
546  */
547 struct pds_core_q_init_cmd {
548 	u8     opcode;
549 	u8     type;
550 	__le16 client_id;
551 	u8     ver;
552 	u8     rsvd[3];
553 	__le32 index;
554 	__le16 pid;
555 	__le16 intr_index;
556 	__le16 flags;
557 #define PDS_CORE_QINIT_F_IRQ	0x01	/* Request interrupt on completion */
558 #define PDS_CORE_QINIT_F_ENA	0x02	/* Enable the queue */
559 	u8     cos;
560 #define PDS_CORE_QSIZE_MIN_LG2	2
561 #define PDS_CORE_QSIZE_MAX_LG2	12
562 	u8     ring_size;
563 	__le64 ring_base;
564 	__le64 cq_ring_base;
565 } __packed;
566 
567 /**
568  * struct pds_core_q_init_comp - Queue init command completion
569  * @status:	Status of the command (enum pds_core_status_code)
570  * @rsvd:       Word boundary padding
571  * @comp_index:	Index in the descriptor ring for which this is the completion
572  * @hw_index:	Hardware Queue ID
573  * @hw_type:	Hardware Queue type
574  * @rsvd2:      Word boundary padding
575  * @color:	Color
576  */
577 struct pds_core_q_init_comp {
578 	u8     status;
579 	u8     rsvd;
580 	__le16 comp_index;
581 	__le32 hw_index;
582 	u8     hw_type;
583 	u8     rsvd2[6];
584 	u8     color;
585 };
586 
587 union pds_core_adminq_cmd {
588 	u8     opcode;
589 	u8     bytes[64];
590 
591 	struct pds_core_client_reg_cmd     client_reg;
592 	struct pds_core_client_unreg_cmd   client_unreg;
593 	struct pds_core_client_request_cmd client_request;
594 
595 	struct pds_core_lif_identify_cmd  lif_ident;
596 	struct pds_core_lif_init_cmd      lif_init;
597 	struct pds_core_lif_reset_cmd     lif_reset;
598 	struct pds_core_lif_setattr_cmd   lif_setattr;
599 	struct pds_core_lif_getattr_cmd   lif_getattr;
600 
601 	struct pds_core_q_identify_cmd    q_ident;
602 	struct pds_core_q_init_cmd        q_init;
603 };
604 
605 union pds_core_adminq_comp {
606 	struct {
607 		u8     status;
608 		u8     rsvd;
609 		__le16 comp_index;
610 		u8     rsvd2[11];
611 		u8     color;
612 	};
613 	u32    words[4];
614 
615 	struct pds_core_client_reg_comp   client_reg;
616 
617 	struct pds_core_lif_identify_comp lif_ident;
618 	struct pds_core_lif_init_comp     lif_init;
619 	struct pds_core_lif_setattr_comp  lif_setattr;
620 	struct pds_core_lif_getattr_comp  lif_getattr;
621 
622 	struct pds_core_q_identify_comp   q_ident;
623 	struct pds_core_q_init_comp       q_init;
624 };
625 
626 #ifndef __CHECKER__
627 static_assert(sizeof(union pds_core_adminq_cmd) == 64);
628 static_assert(sizeof(union pds_core_adminq_comp) == 16);
629 static_assert(sizeof(union pds_core_notifyq_comp) == 64);
630 #endif /* __CHECKER__ */
631 
632 /* The color bit is a 'done' bit for the completion descriptors
633  * where the meaning alternates between '1' and '0' for alternating
634  * passes through the completion descriptor ring.
635  */
636 static inline bool pdsc_color_match(u8 color, bool done_color)
637 {
638 	return (!!(color & PDS_COMP_COLOR_MASK)) == done_color;
639 }
640 
641 struct pdsc;
642 int pdsc_adminq_post(struct pdsc *pdsc,
643 		     union pds_core_adminq_cmd *cmd,
644 		     union pds_core_adminq_comp *comp,
645 		     bool fast_poll);
646 
647 #endif /* _PDS_CORE_ADMINQ_H_ */
648