2 * QEMU rocker switch emulation - PCI device
4 * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
5 * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include "qemu/osdep.h"
19 #include "hw/pci/pci.h"
20 #include "hw/qdev-properties.h"
21 #include "migration/vmstate.h"
22 #include "hw/pci/msix.h"
25 #include "qapi/error.h"
26 #include "qapi/qapi-commands-rocker.h"
28 #include "qemu/module.h"
29 #include "qemu/bitops.h"
33 #include "rocker_hw.h"
34 #include "rocker_fp.h"
35 #include "rocker_desc.h"
36 #include "rocker_tlv.h"
37 #include "rocker_world.h"
38 #include "rocker_of_dpa.h"
46 MemoryRegion msix_bar
;
48 /* switch configuration */
49 char *name
; /* switch name */
50 char *world_name
; /* world name */
51 uint32_t fp_ports
; /* front-panel port count */
52 NICPeers
*fp_ports_peers
;
53 MACAddr fp_start_macaddr
; /* front-panel port 0 mac addr */
54 uint64_t switch_id
; /* switch id */
56 /* front-panel ports */
57 FpPort
*fp_port
[ROCKER_FP_PORTS_MAX
];
59 /* register backings */
62 dma_addr_t test_dma_addr
;
63 uint32_t test_dma_size
;
64 uint64_t lower32
; /* lower 32-bit val in 2-part 64-bit access */
70 World
*worlds
[ROCKER_WORLD_TYPE_MAX
];
73 QLIST_ENTRY(rocker
) next
;
76 static QLIST_HEAD(, rocker
) rockers
;
78 Rocker
*rocker_find(const char *name
)
82 QLIST_FOREACH(r
, &rockers
, next
)
83 if (strcmp(r
->name
, name
) == 0) {
90 World
*rocker_get_world(Rocker
*r
, enum rocker_world_type type
)
92 if (type
< ROCKER_WORLD_TYPE_MAX
) {
93 return r
->worlds
[type
];
98 RockerSwitch
*qmp_query_rocker(const char *name
, Error
**errp
)
100 RockerSwitch
*rocker
;
103 r
= rocker_find(name
);
105 error_setg(errp
, "rocker %s not found", name
);
109 rocker
= g_new0(RockerSwitch
, 1);
110 rocker
->name
= g_strdup(r
->name
);
111 rocker
->id
= r
->switch_id
;
112 rocker
->ports
= r
->fp_ports
;
117 RockerPortList
*qmp_query_rocker_ports(const char *name
, Error
**errp
)
119 RockerPortList
*list
= NULL
;
123 r
= rocker_find(name
);
125 error_setg(errp
, "rocker %s not found", name
);
129 for (i
= r
->fp_ports
- 1; i
>= 0; i
--) {
130 QAPI_LIST_PREPEND(list
, fp_port_get_info(r
->fp_port
[i
]));
136 uint32_t rocker_fp_ports(Rocker
*r
)
141 static uint32_t rocker_get_pport_by_tx_ring(Rocker
*r
,
144 return (desc_ring_index(ring
) - 2) / 2 + 1;
147 static int tx_consume(Rocker
*r
, DescInfo
*info
)
149 PCIDevice
*dev
= PCI_DEVICE(r
);
150 char *buf
= desc_get_buf(info
, true);
152 RockerTlv
*tlvs
[ROCKER_TLV_TX_MAX
+ 1];
153 struct iovec iov
[ROCKER_TX_FRAGS_MAX
] = { { 0, }, };
156 uint16_t tx_offload
= ROCKER_TX_OFFLOAD_NONE
;
157 uint16_t tx_l3_csum_off
= 0;
158 uint16_t tx_tso_mss
= 0;
159 uint16_t tx_tso_hdr_len
= 0;
166 return -ROCKER_ENXIO
;
169 rocker_tlv_parse(tlvs
, ROCKER_TLV_TX_MAX
, buf
, desc_tlv_size(info
));
171 if (!tlvs
[ROCKER_TLV_TX_FRAGS
]) {
172 return -ROCKER_EINVAL
;
175 pport
= rocker_get_pport_by_tx_ring(r
, desc_get_ring(info
));
176 if (!fp_port_from_pport(pport
, &port
)) {
177 return -ROCKER_EINVAL
;
180 if (tlvs
[ROCKER_TLV_TX_OFFLOAD
]) {
181 tx_offload
= rocker_tlv_get_u8(tlvs
[ROCKER_TLV_TX_OFFLOAD
]);
184 switch (tx_offload
) {
185 case ROCKER_TX_OFFLOAD_L3_CSUM
:
186 if (!tlvs
[ROCKER_TLV_TX_L3_CSUM_OFF
]) {
187 return -ROCKER_EINVAL
;
190 case ROCKER_TX_OFFLOAD_TSO
:
191 if (!tlvs
[ROCKER_TLV_TX_TSO_MSS
] ||
192 !tlvs
[ROCKER_TLV_TX_TSO_HDR_LEN
]) {
193 return -ROCKER_EINVAL
;
198 if (tlvs
[ROCKER_TLV_TX_L3_CSUM_OFF
]) {
199 tx_l3_csum_off
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_TX_L3_CSUM_OFF
]);
200 qemu_log_mask(LOG_UNIMP
, "rocker %s: L3 not implemented"
201 " (cksum off: %u)\n",
202 __func__
, tx_l3_csum_off
);
205 if (tlvs
[ROCKER_TLV_TX_TSO_MSS
]) {
206 tx_tso_mss
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_TX_TSO_MSS
]);
207 qemu_log_mask(LOG_UNIMP
, "rocker %s: TSO not implemented (MSS: %u)\n",
208 __func__
, tx_tso_mss
);
211 if (tlvs
[ROCKER_TLV_TX_TSO_HDR_LEN
]) {
212 tx_tso_hdr_len
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_TX_TSO_HDR_LEN
]);
213 qemu_log_mask(LOG_UNIMP
, "rocker %s: TSO not implemented"
214 " (hdr length: %u)\n",
215 __func__
, tx_tso_hdr_len
);
218 rocker_tlv_for_each_nested(tlv_frag
, tlvs
[ROCKER_TLV_TX_FRAGS
], rem
) {
222 if (rocker_tlv_type(tlv_frag
) != ROCKER_TLV_TX_FRAG
) {
223 err
= -ROCKER_EINVAL
;
227 rocker_tlv_parse_nested(tlvs
, ROCKER_TLV_TX_FRAG_ATTR_MAX
, tlv_frag
);
229 if (!tlvs
[ROCKER_TLV_TX_FRAG_ATTR_ADDR
] ||
230 !tlvs
[ROCKER_TLV_TX_FRAG_ATTR_LEN
]) {
231 err
= -ROCKER_EINVAL
;
235 frag_addr
= rocker_tlv_get_le64(tlvs
[ROCKER_TLV_TX_FRAG_ATTR_ADDR
]);
236 frag_len
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_TX_FRAG_ATTR_LEN
]);
238 if (iovcnt
>= ROCKER_TX_FRAGS_MAX
) {
239 goto err_too_many_frags
;
241 iov
[iovcnt
].iov_len
= frag_len
;
242 iov
[iovcnt
].iov_base
= g_malloc(frag_len
);
244 pci_dma_read(dev
, frag_addr
, iov
[iovcnt
].iov_base
,
245 iov
[iovcnt
].iov_len
);
250 err
= fp_port_eg(r
->fp_port
[port
], iov
, iovcnt
);
254 for (i
= 0; i
< ROCKER_TX_FRAGS_MAX
; i
++) {
255 g_free(iov
[i
].iov_base
);
261 static int cmd_get_port_settings(Rocker
*r
,
262 DescInfo
*info
, char *buf
,
263 RockerTlv
*cmd_info_tlv
)
265 RockerTlv
*tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MAX
+ 1];
276 enum rocker_world_type mode
;
281 rocker_tlv_parse_nested(tlvs
, ROCKER_TLV_CMD_PORT_SETTINGS_MAX
,
284 if (!tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
]) {
285 return -ROCKER_EINVAL
;
288 pport
= rocker_tlv_get_le32(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
]);
289 if (!fp_port_from_pport(pport
, &port
)) {
290 return -ROCKER_EINVAL
;
292 fp_port
= r
->fp_port
[port
];
294 err
= fp_port_get_settings(fp_port
, &speed
, &duplex
, &autoneg
);
299 fp_port_get_macaddr(fp_port
, &macaddr
);
300 mode
= world_type(fp_port_get_world(fp_port
));
301 learning
= fp_port_get_learning(fp_port
);
302 phys_name
= fp_port_get_name(fp_port
);
304 tlv_size
= rocker_tlv_total_size(0) + /* nest */
305 rocker_tlv_total_size(sizeof(uint32_t)) + /* pport */
306 rocker_tlv_total_size(sizeof(uint32_t)) + /* speed */
307 rocker_tlv_total_size(sizeof(uint8_t)) + /* duplex */
308 rocker_tlv_total_size(sizeof(uint8_t)) + /* autoneg */
309 rocker_tlv_total_size(sizeof(macaddr
.a
)) + /* macaddr */
310 rocker_tlv_total_size(sizeof(uint8_t)) + /* mode */
311 rocker_tlv_total_size(sizeof(uint8_t)) + /* learning */
312 rocker_tlv_total_size(strlen(phys_name
));
314 if (tlv_size
> desc_buf_size(info
)) {
315 return -ROCKER_EMSGSIZE
;
319 nest
= rocker_tlv_nest_start(buf
, &pos
, ROCKER_TLV_CMD_INFO
);
320 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
, pport
);
321 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
, speed
);
322 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
, duplex
);
323 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
, autoneg
);
324 rocker_tlv_put(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
,
325 sizeof(macaddr
.a
), macaddr
.a
);
326 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_MODE
, mode
);
327 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING
,
329 rocker_tlv_put(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_PHYS_NAME
,
330 strlen(phys_name
), phys_name
);
331 rocker_tlv_nest_end(buf
, &pos
, nest
);
333 return desc_set_buf(info
, tlv_size
);
336 static int cmd_set_port_settings(Rocker
*r
,
337 RockerTlv
*cmd_info_tlv
)
339 RockerTlv
*tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MAX
+ 1];
348 enum rocker_world_type mode
;
351 rocker_tlv_parse_nested(tlvs
, ROCKER_TLV_CMD_PORT_SETTINGS_MAX
,
354 if (!tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
]) {
355 return -ROCKER_EINVAL
;
358 pport
= rocker_tlv_get_le32(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
]);
359 if (!fp_port_from_pport(pport
, &port
)) {
360 return -ROCKER_EINVAL
;
362 fp_port
= r
->fp_port
[port
];
364 if (tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
] &&
365 tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
] &&
366 tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
]) {
368 speed
= rocker_tlv_get_le32(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
]);
369 duplex
= rocker_tlv_get_u8(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
]);
370 autoneg
= rocker_tlv_get_u8(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
]);
372 err
= fp_port_set_settings(fp_port
, speed
, duplex
, autoneg
);
378 if (tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
]) {
379 if (rocker_tlv_len(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
]) !=
381 return -ROCKER_EINVAL
;
384 rocker_tlv_data(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
]),
386 fp_port_set_macaddr(fp_port
, &macaddr
);
389 if (tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MODE
]) {
390 mode
= rocker_tlv_get_u8(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MODE
]);
391 if (mode
>= ROCKER_WORLD_TYPE_MAX
) {
392 return -ROCKER_EINVAL
;
394 /* We don't support world change. */
395 if (!fp_port_check_world(fp_port
, r
->worlds
[mode
])) {
396 return -ROCKER_EINVAL
;
400 if (tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING
]) {
402 rocker_tlv_get_u8(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING
]);
403 fp_port_set_learning(fp_port
, learning
);
409 static int cmd_consume(Rocker
*r
, DescInfo
*info
)
411 char *buf
= desc_get_buf(info
, false);
412 RockerTlv
*tlvs
[ROCKER_TLV_CMD_MAX
+ 1];
419 return -ROCKER_ENXIO
;
422 rocker_tlv_parse(tlvs
, ROCKER_TLV_CMD_MAX
, buf
, desc_tlv_size(info
));
424 if (!tlvs
[ROCKER_TLV_CMD_TYPE
] || !tlvs
[ROCKER_TLV_CMD_INFO
]) {
425 return -ROCKER_EINVAL
;
428 cmd
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_CMD_TYPE
]);
429 info_tlv
= tlvs
[ROCKER_TLV_CMD_INFO
];
431 /* This might be reworked to something like this:
432 * Every world will have an array of command handlers from
433 * ROCKER_TLV_CMD_TYPE_UNSPEC to ROCKER_TLV_CMD_TYPE_MAX. There is
434 * up to each world to implement whatever command it want.
435 * It can reference "generic" commands as cmd_set_port_settings or
436 * cmd_get_port_settings
440 case ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_ADD
:
441 case ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_MOD
:
442 case ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_DEL
:
443 case ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_GET_STATS
:
444 case ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_ADD
:
445 case ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_MOD
:
446 case ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_DEL
:
447 case ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_GET_STATS
:
448 world
= r
->worlds
[ROCKER_WORLD_TYPE_OF_DPA
];
449 err
= world_do_cmd(world
, info
, buf
, cmd
, info_tlv
);
451 case ROCKER_TLV_CMD_TYPE_GET_PORT_SETTINGS
:
452 err
= cmd_get_port_settings(r
, info
, buf
, info_tlv
);
454 case ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS
:
455 err
= cmd_set_port_settings(r
, info_tlv
);
458 err
= -ROCKER_EINVAL
;
465 static void rocker_msix_irq(Rocker
*r
, unsigned vector
)
467 PCIDevice
*dev
= PCI_DEVICE(r
);
469 DPRINTF("MSI-X notify request for vector %d\n", vector
);
470 if (vector
>= ROCKER_MSIX_VEC_COUNT(r
->fp_ports
)) {
471 DPRINTF("incorrect vector %d\n", vector
);
474 msix_notify(dev
, vector
);
477 int rocker_event_link_changed(Rocker
*r
, uint32_t pport
, bool link_up
)
479 DescRing
*ring
= r
->rings
[ROCKER_RING_EVENT
];
480 DescInfo
*info
= desc_ring_fetch_desc(ring
);
488 return -ROCKER_ENOBUFS
;
491 tlv_size
= rocker_tlv_total_size(sizeof(uint16_t)) + /* event type */
492 rocker_tlv_total_size(0) + /* nest */
493 rocker_tlv_total_size(sizeof(uint32_t)) + /* pport */
494 rocker_tlv_total_size(sizeof(uint8_t)); /* link up */
496 if (tlv_size
> desc_buf_size(info
)) {
497 err
= -ROCKER_EMSGSIZE
;
501 buf
= desc_get_buf(info
, false);
503 err
= -ROCKER_ENOMEM
;
508 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_EVENT_TYPE
,
509 ROCKER_TLV_EVENT_TYPE_LINK_CHANGED
);
510 nest
= rocker_tlv_nest_start(buf
, &pos
, ROCKER_TLV_EVENT_INFO
);
511 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_EVENT_LINK_CHANGED_PPORT
, pport
);
512 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_EVENT_LINK_CHANGED_LINKUP
,
514 rocker_tlv_nest_end(buf
, &pos
, nest
);
516 err
= desc_set_buf(info
, tlv_size
);
520 if (desc_ring_post_desc(ring
, err
)) {
521 rocker_msix_irq(r
, ROCKER_MSIX_VEC_EVENT
);
527 int rocker_event_mac_vlan_seen(Rocker
*r
, uint32_t pport
, uint8_t *addr
,
530 DescRing
*ring
= r
->rings
[ROCKER_RING_EVENT
];
540 if (!fp_port_from_pport(pport
, &port
)) {
541 return -ROCKER_EINVAL
;
543 fp_port
= r
->fp_port
[port
];
544 if (!fp_port_get_learning(fp_port
)) {
548 info
= desc_ring_fetch_desc(ring
);
550 return -ROCKER_ENOBUFS
;
553 tlv_size
= rocker_tlv_total_size(sizeof(uint16_t)) + /* event type */
554 rocker_tlv_total_size(0) + /* nest */
555 rocker_tlv_total_size(sizeof(uint32_t)) + /* pport */
556 rocker_tlv_total_size(ETH_ALEN
) + /* mac addr */
557 rocker_tlv_total_size(sizeof(uint16_t)); /* vlan_id */
559 if (tlv_size
> desc_buf_size(info
)) {
560 err
= -ROCKER_EMSGSIZE
;
564 buf
= desc_get_buf(info
, false);
566 err
= -ROCKER_ENOMEM
;
571 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_EVENT_TYPE
,
572 ROCKER_TLV_EVENT_TYPE_MAC_VLAN_SEEN
);
573 nest
= rocker_tlv_nest_start(buf
, &pos
, ROCKER_TLV_EVENT_INFO
);
574 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_EVENT_MAC_VLAN_PPORT
, pport
);
575 rocker_tlv_put(buf
, &pos
, ROCKER_TLV_EVENT_MAC_VLAN_MAC
, ETH_ALEN
, addr
);
576 rocker_tlv_put_u16(buf
, &pos
, ROCKER_TLV_EVENT_MAC_VLAN_VLAN_ID
, vlan_id
);
577 rocker_tlv_nest_end(buf
, &pos
, nest
);
579 err
= desc_set_buf(info
, tlv_size
);
583 if (desc_ring_post_desc(ring
, err
)) {
584 rocker_msix_irq(r
, ROCKER_MSIX_VEC_EVENT
);
590 static DescRing
*rocker_get_rx_ring_by_pport(Rocker
*r
,
593 return r
->rings
[(pport
- 1) * 2 + 3];
596 int rx_produce(World
*world
, uint32_t pport
,
597 const struct iovec
*iov
, int iovcnt
, uint8_t copy_to_cpu
)
599 Rocker
*r
= world_rocker(world
);
600 PCIDevice
*dev
= (PCIDevice
*)r
;
601 DescRing
*ring
= rocker_get_rx_ring_by_pport(r
, pport
);
602 DescInfo
*info
= desc_ring_fetch_desc(ring
);
604 size_t data_size
= iov_size(iov
, iovcnt
);
606 uint16_t rx_flags
= 0;
607 uint16_t rx_csum
= 0;
609 RockerTlv
*tlvs
[ROCKER_TLV_RX_MAX
+ 1];
611 uint16_t frag_max_len
;
616 return -ROCKER_ENOBUFS
;
619 buf
= desc_get_buf(info
, false);
624 rocker_tlv_parse(tlvs
, ROCKER_TLV_RX_MAX
, buf
, desc_tlv_size(info
));
626 if (!tlvs
[ROCKER_TLV_RX_FRAG_ADDR
] ||
627 !tlvs
[ROCKER_TLV_RX_FRAG_MAX_LEN
]) {
628 err
= -ROCKER_EINVAL
;
632 frag_addr
= rocker_tlv_get_le64(tlvs
[ROCKER_TLV_RX_FRAG_ADDR
]);
633 frag_max_len
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_RX_FRAG_MAX_LEN
]);
635 if (data_size
> frag_max_len
) {
636 err
= -ROCKER_EMSGSIZE
;
641 rx_flags
|= ROCKER_RX_FLAGS_FWD_OFFLOAD
;
644 /* XXX calc rx flags/csum */
646 tlv_size
= rocker_tlv_total_size(sizeof(uint16_t)) + /* flags */
647 rocker_tlv_total_size(sizeof(uint16_t)) + /* scum */
648 rocker_tlv_total_size(sizeof(uint64_t)) + /* frag addr */
649 rocker_tlv_total_size(sizeof(uint16_t)) + /* frag max len */
650 rocker_tlv_total_size(sizeof(uint16_t)); /* frag len */
652 if (tlv_size
> desc_buf_size(info
)) {
653 err
= -ROCKER_EMSGSIZE
;
658 * iov dma write can be optimized in similar way e1000 does it in
659 * e1000_receive_iov. But maybe if would make sense to introduce
660 * generic helper iov_dma_write.
663 data
= g_malloc(data_size
);
665 iov_to_buf(iov
, iovcnt
, 0, data
, data_size
);
666 pci_dma_write(dev
, frag_addr
, data
, data_size
);
670 rocker_tlv_put_le16(buf
, &pos
, ROCKER_TLV_RX_FLAGS
, rx_flags
);
671 rocker_tlv_put_le16(buf
, &pos
, ROCKER_TLV_RX_CSUM
, rx_csum
);
672 rocker_tlv_put_le64(buf
, &pos
, ROCKER_TLV_RX_FRAG_ADDR
, frag_addr
);
673 rocker_tlv_put_le16(buf
, &pos
, ROCKER_TLV_RX_FRAG_MAX_LEN
, frag_max_len
);
674 rocker_tlv_put_le16(buf
, &pos
, ROCKER_TLV_RX_FRAG_LEN
, data_size
);
676 err
= desc_set_buf(info
, tlv_size
);
679 if (desc_ring_post_desc(ring
, err
)) {
680 rocker_msix_irq(r
, ROCKER_MSIX_VEC_RX(pport
- 1));
686 int rocker_port_eg(Rocker
*r
, uint32_t pport
,
687 const struct iovec
*iov
, int iovcnt
)
692 if (!fp_port_from_pport(pport
, &port
)) {
693 return -ROCKER_EINVAL
;
696 fp_port
= r
->fp_port
[port
];
698 return fp_port_eg(fp_port
, iov
, iovcnt
);
701 static void rocker_test_dma_ctrl(Rocker
*r
, uint32_t val
)
703 PCIDevice
*dev
= PCI_DEVICE(r
);
707 buf
= g_malloc(r
->test_dma_size
);
710 case ROCKER_TEST_DMA_CTRL_CLEAR
:
711 memset(buf
, 0, r
->test_dma_size
);
713 case ROCKER_TEST_DMA_CTRL_FILL
:
714 memset(buf
, 0x96, r
->test_dma_size
);
716 case ROCKER_TEST_DMA_CTRL_INVERT
:
717 pci_dma_read(dev
, r
->test_dma_addr
, buf
, r
->test_dma_size
);
718 for (i
= 0; i
< r
->test_dma_size
; i
++) {
723 DPRINTF("not test dma control val=0x%08x\n", val
);
726 pci_dma_write(dev
, r
->test_dma_addr
, buf
, r
->test_dma_size
);
728 rocker_msix_irq(r
, ROCKER_MSIX_VEC_TEST
);
734 static void rocker_reset(DeviceState
*dev
);
736 static void rocker_control(Rocker
*r
, uint32_t val
)
738 if (val
& ROCKER_CONTROL_RESET
) {
739 rocker_reset(DEVICE(r
));
743 static int rocker_pci_ring_count(Rocker
*r
)
748 * - tx and rx ring per each port
750 return 2 + (2 * r
->fp_ports
);
753 static bool rocker_addr_is_desc_reg(Rocker
*r
, hwaddr addr
)
755 hwaddr start
= ROCKER_DMA_DESC_BASE
;
756 hwaddr end
= start
+ (ROCKER_DMA_DESC_SIZE
* rocker_pci_ring_count(r
));
758 return addr
>= start
&& addr
< end
;
761 static void rocker_port_phys_enable_write(Rocker
*r
, uint64_t new)
768 for (i
= 0; i
< r
->fp_ports
; i
++) {
769 fp_port
= r
->fp_port
[i
];
770 old_enabled
= fp_port_enabled(fp_port
);
771 new_enabled
= (new >> (i
+ 1)) & 0x1;
772 if (new_enabled
== old_enabled
) {
776 fp_port_enable(r
->fp_port
[i
]);
778 fp_port_disable(r
->fp_port
[i
]);
783 static void rocker_io_writel(void *opaque
, hwaddr addr
, uint32_t val
)
787 if (rocker_addr_is_desc_reg(r
, addr
)) {
788 unsigned index
= ROCKER_RING_INDEX(addr
);
789 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
792 case ROCKER_DMA_DESC_ADDR_OFFSET
:
793 r
->lower32
= (uint64_t)val
;
795 case ROCKER_DMA_DESC_ADDR_OFFSET
+ 4:
796 desc_ring_set_base_addr(r
->rings
[index
],
797 ((uint64_t)val
) << 32 | r
->lower32
);
800 case ROCKER_DMA_DESC_SIZE_OFFSET
:
801 desc_ring_set_size(r
->rings
[index
], val
);
803 case ROCKER_DMA_DESC_HEAD_OFFSET
:
804 if (desc_ring_set_head(r
->rings
[index
], val
)) {
805 rocker_msix_irq(r
, desc_ring_get_msix_vector(r
->rings
[index
]));
808 case ROCKER_DMA_DESC_CTRL_OFFSET
:
809 desc_ring_set_ctrl(r
->rings
[index
], val
);
811 case ROCKER_DMA_DESC_CREDITS_OFFSET
:
812 if (desc_ring_ret_credits(r
->rings
[index
], val
)) {
813 rocker_msix_irq(r
, desc_ring_get_msix_vector(r
->rings
[index
]));
817 DPRINTF("not implemented dma reg write(l) addr=0x" TARGET_FMT_plx
818 " val=0x%08x (ring %d, addr=0x%02x)\n",
819 addr
, val
, index
, offset
);
826 case ROCKER_TEST_REG
:
829 case ROCKER_TEST_REG64
:
830 case ROCKER_TEST_DMA_ADDR
:
831 case ROCKER_PORT_PHYS_ENABLE
:
832 r
->lower32
= (uint64_t)val
;
834 case ROCKER_TEST_REG64
+ 4:
835 r
->test_reg64
= ((uint64_t)val
) << 32 | r
->lower32
;
838 case ROCKER_TEST_IRQ
:
839 rocker_msix_irq(r
, val
);
841 case ROCKER_TEST_DMA_SIZE
:
842 r
->test_dma_size
= val
& 0xFFFF;
844 case ROCKER_TEST_DMA_ADDR
+ 4:
845 r
->test_dma_addr
= ((uint64_t)val
) << 32 | r
->lower32
;
848 case ROCKER_TEST_DMA_CTRL
:
849 rocker_test_dma_ctrl(r
, val
);
852 rocker_control(r
, val
);
854 case ROCKER_PORT_PHYS_ENABLE
+ 4:
855 rocker_port_phys_enable_write(r
, ((uint64_t)val
) << 32 | r
->lower32
);
859 DPRINTF("not implemented write(l) addr=0x" TARGET_FMT_plx
860 " val=0x%08x\n", addr
, val
);
865 static void rocker_io_writeq(void *opaque
, hwaddr addr
, uint64_t val
)
869 if (rocker_addr_is_desc_reg(r
, addr
)) {
870 unsigned index
= ROCKER_RING_INDEX(addr
);
871 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
874 case ROCKER_DMA_DESC_ADDR_OFFSET
:
875 desc_ring_set_base_addr(r
->rings
[index
], val
);
878 DPRINTF("not implemented dma reg write(q) addr=0x" TARGET_FMT_plx
879 " val=0x" TARGET_FMT_plx
" (ring %d, offset=0x%02x)\n",
880 addr
, val
, index
, offset
);
887 case ROCKER_TEST_REG64
:
890 case ROCKER_TEST_DMA_ADDR
:
891 r
->test_dma_addr
= val
;
893 case ROCKER_PORT_PHYS_ENABLE
:
894 rocker_port_phys_enable_write(r
, val
);
897 DPRINTF("not implemented write(q) addr=0x" TARGET_FMT_plx
898 " val=0x" TARGET_FMT_plx
"\n", addr
, val
);
904 #define regname(reg) case (reg): return #reg
905 static const char *rocker_reg_name(void *opaque
, hwaddr addr
)
909 if (rocker_addr_is_desc_reg(r
, addr
)) {
910 unsigned index
= ROCKER_RING_INDEX(addr
);
911 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
912 static char buf
[100];
917 sprintf(ring_name
, "cmd");
920 sprintf(ring_name
, "event");
923 sprintf(ring_name
, "%s-%d", index
% 2 ? "rx" : "tx",
928 case ROCKER_DMA_DESC_ADDR_OFFSET
:
929 sprintf(buf
, "Ring[%s] ADDR", ring_name
);
931 case ROCKER_DMA_DESC_ADDR_OFFSET
+4:
932 sprintf(buf
, "Ring[%s] ADDR+4", ring_name
);
934 case ROCKER_DMA_DESC_SIZE_OFFSET
:
935 sprintf(buf
, "Ring[%s] SIZE", ring_name
);
937 case ROCKER_DMA_DESC_HEAD_OFFSET
:
938 sprintf(buf
, "Ring[%s] HEAD", ring_name
);
940 case ROCKER_DMA_DESC_TAIL_OFFSET
:
941 sprintf(buf
, "Ring[%s] TAIL", ring_name
);
943 case ROCKER_DMA_DESC_CTRL_OFFSET
:
944 sprintf(buf
, "Ring[%s] CTRL", ring_name
);
946 case ROCKER_DMA_DESC_CREDITS_OFFSET
:
947 sprintf(buf
, "Ring[%s] CREDITS", ring_name
);
950 sprintf(buf
, "Ring[%s] ???", ring_name
);
955 regname(ROCKER_BOGUS_REG0
);
956 regname(ROCKER_BOGUS_REG1
);
957 regname(ROCKER_BOGUS_REG2
);
958 regname(ROCKER_BOGUS_REG3
);
959 regname(ROCKER_TEST_REG
);
960 regname(ROCKER_TEST_REG64
);
961 regname(ROCKER_TEST_REG64
+4);
962 regname(ROCKER_TEST_IRQ
);
963 regname(ROCKER_TEST_DMA_ADDR
);
964 regname(ROCKER_TEST_DMA_ADDR
+4);
965 regname(ROCKER_TEST_DMA_SIZE
);
966 regname(ROCKER_TEST_DMA_CTRL
);
967 regname(ROCKER_CONTROL
);
968 regname(ROCKER_PORT_PHYS_COUNT
);
969 regname(ROCKER_PORT_PHYS_LINK_STATUS
);
970 regname(ROCKER_PORT_PHYS_LINK_STATUS
+4);
971 regname(ROCKER_PORT_PHYS_ENABLE
);
972 regname(ROCKER_PORT_PHYS_ENABLE
+4);
973 regname(ROCKER_SWITCH_ID
);
974 regname(ROCKER_SWITCH_ID
+4);
980 static const char *rocker_reg_name(void *opaque
, hwaddr addr
)
986 static void rocker_mmio_write(void *opaque
, hwaddr addr
, uint64_t val
,
989 DPRINTF("Write %s addr " TARGET_FMT_plx
990 ", size %u, val " TARGET_FMT_plx
"\n",
991 rocker_reg_name(opaque
, addr
), addr
, size
, val
);
995 rocker_io_writel(opaque
, addr
, val
);
998 rocker_io_writeq(opaque
, addr
, val
);
1003 static uint64_t rocker_port_phys_link_status(Rocker
*r
)
1006 uint64_t status
= 0;
1008 for (i
= 0; i
< r
->fp_ports
; i
++) {
1009 FpPort
*port
= r
->fp_port
[i
];
1011 if (fp_port_get_link_up(port
)) {
1012 status
|= 1 << (i
+ 1);
1018 static uint64_t rocker_port_phys_enable_read(Rocker
*r
)
1023 for (i
= 0; i
< r
->fp_ports
; i
++) {
1024 FpPort
*port
= r
->fp_port
[i
];
1026 if (fp_port_enabled(port
)) {
1027 ret
|= 1 << (i
+ 1);
1033 static uint32_t rocker_io_readl(void *opaque
, hwaddr addr
)
1038 if (rocker_addr_is_desc_reg(r
, addr
)) {
1039 unsigned index
= ROCKER_RING_INDEX(addr
);
1040 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
1043 case ROCKER_DMA_DESC_ADDR_OFFSET
:
1044 ret
= (uint32_t)desc_ring_get_base_addr(r
->rings
[index
]);
1046 case ROCKER_DMA_DESC_ADDR_OFFSET
+ 4:
1047 ret
= (uint32_t)(desc_ring_get_base_addr(r
->rings
[index
]) >> 32);
1049 case ROCKER_DMA_DESC_SIZE_OFFSET
:
1050 ret
= desc_ring_get_size(r
->rings
[index
]);
1052 case ROCKER_DMA_DESC_HEAD_OFFSET
:
1053 ret
= desc_ring_get_head(r
->rings
[index
]);
1055 case ROCKER_DMA_DESC_TAIL_OFFSET
:
1056 ret
= desc_ring_get_tail(r
->rings
[index
]);
1058 case ROCKER_DMA_DESC_CREDITS_OFFSET
:
1059 ret
= desc_ring_get_credits(r
->rings
[index
]);
1062 DPRINTF("not implemented dma reg read(l) addr=0x" TARGET_FMT_plx
1063 " (ring %d, addr=0x%02x)\n", addr
, index
, offset
);
1071 case ROCKER_BOGUS_REG0
:
1072 case ROCKER_BOGUS_REG1
:
1073 case ROCKER_BOGUS_REG2
:
1074 case ROCKER_BOGUS_REG3
:
1077 case ROCKER_TEST_REG
:
1078 ret
= r
->test_reg
* 2;
1080 case ROCKER_TEST_REG64
:
1081 ret
= (uint32_t)(r
->test_reg64
* 2);
1083 case ROCKER_TEST_REG64
+ 4:
1084 ret
= (uint32_t)((r
->test_reg64
* 2) >> 32);
1086 case ROCKER_TEST_DMA_SIZE
:
1087 ret
= r
->test_dma_size
;
1089 case ROCKER_TEST_DMA_ADDR
:
1090 ret
= (uint32_t)r
->test_dma_addr
;
1092 case ROCKER_TEST_DMA_ADDR
+ 4:
1093 ret
= (uint32_t)(r
->test_dma_addr
>> 32);
1095 case ROCKER_PORT_PHYS_COUNT
:
1098 case ROCKER_PORT_PHYS_LINK_STATUS
:
1099 ret
= (uint32_t)rocker_port_phys_link_status(r
);
1101 case ROCKER_PORT_PHYS_LINK_STATUS
+ 4:
1102 ret
= (uint32_t)(rocker_port_phys_link_status(r
) >> 32);
1104 case ROCKER_PORT_PHYS_ENABLE
:
1105 ret
= (uint32_t)rocker_port_phys_enable_read(r
);
1107 case ROCKER_PORT_PHYS_ENABLE
+ 4:
1108 ret
= (uint32_t)(rocker_port_phys_enable_read(r
) >> 32);
1110 case ROCKER_SWITCH_ID
:
1111 ret
= (uint32_t)r
->switch_id
;
1113 case ROCKER_SWITCH_ID
+ 4:
1114 ret
= (uint32_t)(r
->switch_id
>> 32);
1117 DPRINTF("not implemented read(l) addr=0x" TARGET_FMT_plx
"\n", addr
);
1124 static uint64_t rocker_io_readq(void *opaque
, hwaddr addr
)
1129 if (rocker_addr_is_desc_reg(r
, addr
)) {
1130 unsigned index
= ROCKER_RING_INDEX(addr
);
1131 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
1133 switch (addr
& ROCKER_DMA_DESC_MASK
) {
1134 case ROCKER_DMA_DESC_ADDR_OFFSET
:
1135 ret
= desc_ring_get_base_addr(r
->rings
[index
]);
1138 DPRINTF("not implemented dma reg read(q) addr=0x" TARGET_FMT_plx
1139 " (ring %d, addr=0x%02x)\n", addr
, index
, offset
);
1147 case ROCKER_BOGUS_REG0
:
1148 case ROCKER_BOGUS_REG2
:
1149 ret
= 0xDEADBABEDEADBABEULL
;
1151 case ROCKER_TEST_REG64
:
1152 ret
= r
->test_reg64
* 2;
1154 case ROCKER_TEST_DMA_ADDR
:
1155 ret
= r
->test_dma_addr
;
1157 case ROCKER_PORT_PHYS_LINK_STATUS
:
1158 ret
= rocker_port_phys_link_status(r
);
1160 case ROCKER_PORT_PHYS_ENABLE
:
1161 ret
= rocker_port_phys_enable_read(r
);
1163 case ROCKER_SWITCH_ID
:
1167 DPRINTF("not implemented read(q) addr=0x" TARGET_FMT_plx
"\n", addr
);
1174 static uint64_t rocker_mmio_read(void *opaque
, hwaddr addr
, unsigned size
)
1176 DPRINTF("Read %s addr " TARGET_FMT_plx
", size %u\n",
1177 rocker_reg_name(opaque
, addr
), addr
, size
);
1181 return rocker_io_readl(opaque
, addr
);
1183 return rocker_io_readq(opaque
, addr
);
1189 static const MemoryRegionOps rocker_mmio_ops
= {
1190 .read
= rocker_mmio_read
,
1191 .write
= rocker_mmio_write
,
1192 .endianness
= DEVICE_LITTLE_ENDIAN
,
1194 .min_access_size
= 4,
1195 .max_access_size
= 8,
1198 .min_access_size
= 4,
1199 .max_access_size
= 8,
1203 static void rocker_msix_vectors_unuse(Rocker
*r
,
1204 unsigned int num_vectors
)
1206 PCIDevice
*dev
= PCI_DEVICE(r
);
1209 for (i
= 0; i
< num_vectors
; i
++) {
1210 msix_vector_unuse(dev
, i
);
1214 static int rocker_msix_vectors_use(Rocker
*r
,
1215 unsigned int num_vectors
)
1217 PCIDevice
*dev
= PCI_DEVICE(r
);
1221 for (i
= 0; i
< num_vectors
; i
++) {
1222 err
= msix_vector_use(dev
, i
);
1230 rocker_msix_vectors_unuse(r
, i
);
1234 static int rocker_msix_init(Rocker
*r
, Error
**errp
)
1236 PCIDevice
*dev
= PCI_DEVICE(r
);
1239 err
= msix_init(dev
, ROCKER_MSIX_VEC_COUNT(r
->fp_ports
),
1241 ROCKER_PCI_MSIX_BAR_IDX
, ROCKER_PCI_MSIX_TABLE_OFFSET
,
1243 ROCKER_PCI_MSIX_BAR_IDX
, ROCKER_PCI_MSIX_PBA_OFFSET
,
1249 err
= rocker_msix_vectors_use(r
, ROCKER_MSIX_VEC_COUNT(r
->fp_ports
));
1251 goto err_msix_vectors_use
;
1256 err_msix_vectors_use
:
1257 msix_uninit(dev
, &r
->msix_bar
, &r
->msix_bar
);
1261 static void rocker_msix_uninit(Rocker
*r
)
1263 PCIDevice
*dev
= PCI_DEVICE(r
);
1265 msix_uninit(dev
, &r
->msix_bar
, &r
->msix_bar
);
1266 rocker_msix_vectors_unuse(r
, ROCKER_MSIX_VEC_COUNT(r
->fp_ports
));
1269 static World
*rocker_world_type_by_name(Rocker
*r
, const char *name
)
1273 for (i
= 0; i
< ROCKER_WORLD_TYPE_MAX
; i
++) {
1274 if (strcmp(name
, world_name(r
->worlds
[i
])) == 0) {
1275 return r
->worlds
[i
];
1281 static void pci_rocker_realize(PCIDevice
*dev
, Error
**errp
)
1283 Rocker
*r
= ROCKER(dev
);
1284 const MACAddr zero
= { .a
= { 0, 0, 0, 0, 0, 0 } };
1285 const MACAddr dflt
= { .a
= { 0x52, 0x54, 0x00, 0x12, 0x35, 0x01 } };
1286 static int sw_index
;
1289 /* allocate worlds */
1291 r
->worlds
[ROCKER_WORLD_TYPE_OF_DPA
] = of_dpa_world_alloc(r
);
1293 if (!r
->world_name
) {
1294 r
->world_name
= g_strdup(world_name(r
->worlds
[ROCKER_WORLD_TYPE_OF_DPA
]));
1297 r
->world_dflt
= rocker_world_type_by_name(r
, r
->world_name
);
1298 if (!r
->world_dflt
) {
1300 "invalid argument requested world %s does not exist",
1302 goto err_world_type_by_name
;
1305 /* set up memory-mapped region at BAR0 */
1307 memory_region_init_io(&r
->mmio
, OBJECT(r
), &rocker_mmio_ops
, r
,
1308 "rocker-mmio", ROCKER_PCI_BAR0_SIZE
);
1309 pci_register_bar(dev
, ROCKER_PCI_BAR0_IDX
,
1310 PCI_BASE_ADDRESS_SPACE_MEMORY
, &r
->mmio
);
1312 /* set up memory-mapped region for MSI-X */
1314 memory_region_init(&r
->msix_bar
, OBJECT(r
), "rocker-msix-bar",
1315 ROCKER_PCI_MSIX_BAR_SIZE
);
1316 pci_register_bar(dev
, ROCKER_PCI_MSIX_BAR_IDX
,
1317 PCI_BASE_ADDRESS_SPACE_MEMORY
, &r
->msix_bar
);
1321 err
= rocker_msix_init(r
, errp
);
1326 /* validate switch properties */
1329 r
->name
= g_strdup(TYPE_ROCKER
);
1332 if (rocker_find(r
->name
)) {
1333 error_setg(errp
, "%s already exists", r
->name
);
1337 /* Rocker name is passed in port name requests to OS with the intention
1338 * that the name is used in interface names. Limit the length of the
1339 * rocker name to avoid naming problems in the OS. Also, adding the
1340 * port number as p# and unganged breakout b#, where # is at most 2
1341 * digits, so leave room for it too (-1 for string terminator, -3 for
1344 #define ROCKER_IFNAMSIZ 16
1345 #define MAX_ROCKER_NAME_LEN (ROCKER_IFNAMSIZ - 1 - 3 - 3)
1346 if (strlen(r
->name
) > MAX_ROCKER_NAME_LEN
) {
1348 "name too long; please shorten to at most %d chars",
1349 MAX_ROCKER_NAME_LEN
);
1350 goto err_name_too_long
;
1353 if (memcmp(&r
->fp_start_macaddr
, &zero
, sizeof(zero
)) == 0) {
1354 memcpy(&r
->fp_start_macaddr
, &dflt
, sizeof(dflt
));
1355 r
->fp_start_macaddr
.a
[4] += (sw_index
++);
1358 if (!r
->switch_id
) {
1359 memcpy(&r
->switch_id
, &r
->fp_start_macaddr
,
1360 sizeof(r
->fp_start_macaddr
));
1363 if (r
->fp_ports
> ROCKER_FP_PORTS_MAX
) {
1364 r
->fp_ports
= ROCKER_FP_PORTS_MAX
;
1367 r
->rings
= g_new(DescRing
*, rocker_pci_ring_count(r
));
1369 /* Rings are ordered like this:
1379 for (i
= 0; i
< rocker_pci_ring_count(r
); i
++) {
1380 DescRing
*ring
= desc_ring_alloc(r
, i
);
1382 if (i
== ROCKER_RING_CMD
) {
1383 desc_ring_set_consume(ring
, cmd_consume
, ROCKER_MSIX_VEC_CMD
);
1384 } else if (i
== ROCKER_RING_EVENT
) {
1385 desc_ring_set_consume(ring
, NULL
, ROCKER_MSIX_VEC_EVENT
);
1386 } else if (i
% 2 == 0) {
1387 desc_ring_set_consume(ring
, tx_consume
,
1388 ROCKER_MSIX_VEC_TX((i
- 2) / 2));
1389 } else if (i
% 2 == 1) {
1390 desc_ring_set_consume(ring
, NULL
, ROCKER_MSIX_VEC_RX((i
- 3) / 2));
1396 for (i
= 0; i
< r
->fp_ports
; i
++) {
1398 fp_port_alloc(r
, r
->name
, &r
->fp_start_macaddr
,
1399 i
, &r
->fp_ports_peers
[i
]);
1401 r
->fp_port
[i
] = port
;
1402 fp_port_set_world(port
, r
->world_dflt
);
1405 QLIST_INSERT_HEAD(&rockers
, r
, next
);
1411 rocker_msix_uninit(r
);
1413 object_unparent(OBJECT(&r
->msix_bar
));
1414 object_unparent(OBJECT(&r
->mmio
));
1415 err_world_type_by_name
:
1416 for (i
= 0; i
< ROCKER_WORLD_TYPE_MAX
; i
++) {
1418 world_free(r
->worlds
[i
]);
1423 static void pci_rocker_uninit(PCIDevice
*dev
)
1425 Rocker
*r
= ROCKER(dev
);
1428 QLIST_REMOVE(r
, next
);
1430 for (i
= 0; i
< r
->fp_ports
; i
++) {
1431 FpPort
*port
= r
->fp_port
[i
];
1434 r
->fp_port
[i
] = NULL
;
1437 for (i
= 0; i
< rocker_pci_ring_count(r
); i
++) {
1439 desc_ring_free(r
->rings
[i
]);
1444 rocker_msix_uninit(r
);
1445 object_unparent(OBJECT(&r
->msix_bar
));
1446 object_unparent(OBJECT(&r
->mmio
));
1448 for (i
= 0; i
< ROCKER_WORLD_TYPE_MAX
; i
++) {
1450 world_free(r
->worlds
[i
]);
1453 g_free(r
->fp_ports_peers
);
1456 static void rocker_reset(DeviceState
*dev
)
1458 Rocker
*r
= ROCKER(dev
);
1461 for (i
= 0; i
< ROCKER_WORLD_TYPE_MAX
; i
++) {
1463 world_reset(r
->worlds
[i
]);
1466 for (i
= 0; i
< r
->fp_ports
; i
++) {
1467 fp_port_reset(r
->fp_port
[i
]);
1468 fp_port_set_world(r
->fp_port
[i
], r
->world_dflt
);
1473 r
->test_dma_addr
= 0;
1474 r
->test_dma_size
= 0;
1476 for (i
= 0; i
< rocker_pci_ring_count(r
); i
++) {
1477 desc_ring_reset(r
->rings
[i
]);
1480 DPRINTF("Reset done\n");
1483 static Property rocker_properties
[] = {
1484 DEFINE_PROP_STRING("name", Rocker
, name
),
1485 DEFINE_PROP_STRING("world", Rocker
, world_name
),
1486 DEFINE_PROP_MACADDR("fp_start_macaddr", Rocker
,
1488 DEFINE_PROP_UINT64("switch_id", Rocker
,
1490 DEFINE_PROP_ARRAY("ports", Rocker
, fp_ports
,
1491 fp_ports_peers
, qdev_prop_netdev
, NICPeers
),
1492 DEFINE_PROP_END_OF_LIST(),
1495 static const VMStateDescription rocker_vmsd
= {
1496 .name
= TYPE_ROCKER
,
1500 static void rocker_class_init(ObjectClass
*klass
, void *data
)
1502 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1503 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
1505 k
->realize
= pci_rocker_realize
;
1506 k
->exit
= pci_rocker_uninit
;
1507 k
->vendor_id
= PCI_VENDOR_ID_REDHAT
;
1508 k
->device_id
= PCI_DEVICE_ID_REDHAT_ROCKER
;
1509 k
->revision
= ROCKER_PCI_REVISION
;
1510 k
->class_id
= PCI_CLASS_NETWORK_OTHER
;
1511 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
1512 dc
->desc
= "Rocker Switch";
1513 dc
->reset
= rocker_reset
;
1514 device_class_set_props(dc
, rocker_properties
);
1515 dc
->vmsd
= &rocker_vmsd
;
1518 static const TypeInfo rocker_info
= {
1519 .name
= TYPE_ROCKER
,
1520 .parent
= TYPE_PCI_DEVICE
,
1521 .instance_size
= sizeof(Rocker
),
1522 .class_init
= rocker_class_init
,
1523 .interfaces
= (InterfaceInfo
[]) {
1524 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
1529 static void rocker_register_types(void)
1531 type_register_static(&rocker_info
);
1534 type_init(rocker_register_types
)