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.
19 #include "hw/pci/pci.h"
20 #include "hw/pci/msix.h"
24 #include "qemu/bitops.h"
25 #include "qmp-commands.h"
28 #include "rocker_hw.h"
29 #include "rocker_fp.h"
30 #include "rocker_desc.h"
31 #include "rocker_tlv.h"
32 #include "rocker_world.h"
33 #include "rocker_of_dpa.h"
41 MemoryRegion msix_bar
;
43 /* switch configuration */
44 char *name
; /* switch name */
45 uint32_t fp_ports
; /* front-panel port count */
46 NICPeers
*fp_ports_peers
;
47 MACAddr fp_start_macaddr
; /* front-panel port 0 mac addr */
48 uint64_t switch_id
; /* switch id */
50 /* front-panel ports */
51 FpPort
*fp_port
[ROCKER_FP_PORTS_MAX
];
53 /* register backings */
56 dma_addr_t test_dma_addr
;
57 uint32_t test_dma_size
;
58 uint64_t lower32
; /* lower 32-bit val in 2-part 64-bit access */
64 World
*worlds
[ROCKER_WORLD_TYPE_MAX
];
67 QLIST_ENTRY(rocker
) next
;
70 #define ROCKER "rocker"
72 #define to_rocker(obj) \
73 OBJECT_CHECK(Rocker, (obj), ROCKER)
75 static QLIST_HEAD(, rocker
) rockers
;
77 Rocker
*rocker_find(const char *name
)
81 QLIST_FOREACH(r
, &rockers
, next
)
82 if (strcmp(r
->name
, name
) == 0) {
89 World
*rocker_get_world(Rocker
*r
, enum rocker_world_type type
)
91 if (type
< ROCKER_WORLD_TYPE_MAX
) {
92 return r
->worlds
[type
];
97 RockerSwitch
*qmp_query_rocker(const char *name
, Error
**errp
)
102 r
= rocker_find(name
);
104 error_set(errp
, ERROR_CLASS_GENERIC_ERROR
,
105 "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_set(errp
, ERROR_CLASS_GENERIC_ERROR
,
126 "rocker %s not found", name
);
130 for (i
= r
->fp_ports
- 1; i
>= 0; i
--) {
131 RockerPortList
*info
= g_malloc0(sizeof(*info
));
132 info
->value
= g_malloc0(sizeof(*info
->value
));
133 struct fp_port
*port
= r
->fp_port
[i
];
135 fp_port_get_info(port
, info
);
143 uint32_t rocker_fp_ports(Rocker
*r
)
148 static uint32_t rocker_get_pport_by_tx_ring(Rocker
*r
,
151 return (desc_ring_index(ring
) - 2) / 2 + 1;
154 static int tx_consume(Rocker
*r
, DescInfo
*info
)
156 PCIDevice
*dev
= PCI_DEVICE(r
);
157 char *buf
= desc_get_buf(info
, true);
159 RockerTlv
*tlvs
[ROCKER_TLV_TX_MAX
+ 1];
160 struct iovec iov
[ROCKER_TX_FRAGS_MAX
] = { { 0, }, };
163 uint16_t tx_offload
= ROCKER_TX_OFFLOAD_NONE
;
164 uint16_t tx_l3_csum_off
= 0;
165 uint16_t tx_tso_mss
= 0;
166 uint16_t tx_tso_hdr_len
= 0;
173 return -ROCKER_ENXIO
;
176 rocker_tlv_parse(tlvs
, ROCKER_TLV_TX_MAX
, buf
, desc_tlv_size(info
));
178 if (!tlvs
[ROCKER_TLV_TX_FRAGS
]) {
179 return -ROCKER_EINVAL
;
182 pport
= rocker_get_pport_by_tx_ring(r
, desc_get_ring(info
));
183 if (!fp_port_from_pport(pport
, &port
)) {
184 return -ROCKER_EINVAL
;
187 if (tlvs
[ROCKER_TLV_TX_OFFLOAD
]) {
188 tx_offload
= rocker_tlv_get_u8(tlvs
[ROCKER_TLV_TX_OFFLOAD
]);
191 switch (tx_offload
) {
192 case ROCKER_TX_OFFLOAD_L3_CSUM
:
193 if (!tlvs
[ROCKER_TLV_TX_L3_CSUM_OFF
]) {
194 return -ROCKER_EINVAL
;
197 case ROCKER_TX_OFFLOAD_TSO
:
198 if (!tlvs
[ROCKER_TLV_TX_TSO_MSS
] ||
199 !tlvs
[ROCKER_TLV_TX_TSO_HDR_LEN
]) {
200 return -ROCKER_EINVAL
;
205 if (tlvs
[ROCKER_TLV_TX_L3_CSUM_OFF
]) {
206 tx_l3_csum_off
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_TX_L3_CSUM_OFF
]);
209 if (tlvs
[ROCKER_TLV_TX_TSO_MSS
]) {
210 tx_tso_mss
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_TX_TSO_MSS
]);
213 if (tlvs
[ROCKER_TLV_TX_TSO_HDR_LEN
]) {
214 tx_tso_hdr_len
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_TX_TSO_HDR_LEN
]);
217 rocker_tlv_for_each_nested(tlv_frag
, tlvs
[ROCKER_TLV_TX_FRAGS
], rem
) {
221 if (rocker_tlv_type(tlv_frag
) != ROCKER_TLV_TX_FRAG
) {
222 err
= -ROCKER_EINVAL
;
226 rocker_tlv_parse_nested(tlvs
, ROCKER_TLV_TX_FRAG_ATTR_MAX
, tlv_frag
);
228 if (!tlvs
[ROCKER_TLV_TX_FRAG_ATTR_ADDR
] ||
229 !tlvs
[ROCKER_TLV_TX_FRAG_ATTR_LEN
]) {
230 err
= -ROCKER_EINVAL
;
234 frag_addr
= rocker_tlv_get_le64(tlvs
[ROCKER_TLV_TX_FRAG_ATTR_ADDR
]);
235 frag_len
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_TX_FRAG_ATTR_LEN
]);
237 iov
[iovcnt
].iov_len
= frag_len
;
238 iov
[iovcnt
].iov_base
= g_malloc(frag_len
);
239 if (!iov
[iovcnt
].iov_base
) {
240 err
= -ROCKER_ENOMEM
;
244 if (pci_dma_read(dev
, frag_addr
, iov
[iovcnt
].iov_base
,
245 iov
[iovcnt
].iov_len
)) {
250 if (++iovcnt
> ROCKER_TX_FRAGS_MAX
) {
251 goto err_too_many_frags
;
256 /* XXX perform Tx offloads */
257 /* XXX silence compiler for now */
258 tx_l3_csum_off
+= tx_tso_mss
= tx_tso_hdr_len
= 0;
261 err
= fp_port_eg(r
->fp_port
[port
], iov
, iovcnt
);
267 for (i
= 0; i
< ROCKER_TX_FRAGS_MAX
; i
++) {
268 g_free(iov
[i
].iov_base
);
274 static int cmd_get_port_settings(Rocker
*r
,
275 DescInfo
*info
, char *buf
,
276 RockerTlv
*cmd_info_tlv
)
278 RockerTlv
*tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MAX
+ 1];
289 enum rocker_world_type mode
;
294 rocker_tlv_parse_nested(tlvs
, ROCKER_TLV_CMD_PORT_SETTINGS_MAX
,
297 if (!tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
]) {
298 return -ROCKER_EINVAL
;
301 pport
= rocker_tlv_get_le32(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
]);
302 if (!fp_port_from_pport(pport
, &port
)) {
303 return -ROCKER_EINVAL
;
305 fp_port
= r
->fp_port
[port
];
307 err
= fp_port_get_settings(fp_port
, &speed
, &duplex
, &autoneg
);
312 fp_port_get_macaddr(fp_port
, &macaddr
);
313 mode
= world_type(fp_port_get_world(fp_port
));
314 learning
= fp_port_get_learning(fp_port
);
315 phys_name
= fp_port_get_name(fp_port
);
317 tlv_size
= rocker_tlv_total_size(0) + /* nest */
318 rocker_tlv_total_size(sizeof(uint32_t)) + /* pport */
319 rocker_tlv_total_size(sizeof(uint32_t)) + /* speed */
320 rocker_tlv_total_size(sizeof(uint8_t)) + /* duplex */
321 rocker_tlv_total_size(sizeof(uint8_t)) + /* autoneg */
322 rocker_tlv_total_size(sizeof(macaddr
.a
)) + /* macaddr */
323 rocker_tlv_total_size(sizeof(uint8_t)) + /* mode */
324 rocker_tlv_total_size(sizeof(uint8_t)) + /* learning */
325 rocker_tlv_total_size(strlen(phys_name
));
327 if (tlv_size
> desc_buf_size(info
)) {
328 return -ROCKER_EMSGSIZE
;
332 nest
= rocker_tlv_nest_start(buf
, &pos
, ROCKER_TLV_CMD_INFO
);
333 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
, pport
);
334 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
, speed
);
335 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
, duplex
);
336 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
, autoneg
);
337 rocker_tlv_put(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
,
338 sizeof(macaddr
.a
), macaddr
.a
);
339 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_MODE
, mode
);
340 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING
,
342 rocker_tlv_put(buf
, &pos
, ROCKER_TLV_CMD_PORT_SETTINGS_PHYS_NAME
,
343 strlen(phys_name
), phys_name
);
344 rocker_tlv_nest_end(buf
, &pos
, nest
);
346 return desc_set_buf(info
, tlv_size
);
349 static int cmd_set_port_settings(Rocker
*r
,
350 RockerTlv
*cmd_info_tlv
)
352 RockerTlv
*tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MAX
+ 1];
361 enum rocker_world_type mode
;
364 rocker_tlv_parse_nested(tlvs
, ROCKER_TLV_CMD_PORT_SETTINGS_MAX
,
367 if (!tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
]) {
368 return -ROCKER_EINVAL
;
371 pport
= rocker_tlv_get_le32(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
]);
372 if (!fp_port_from_pport(pport
, &port
)) {
373 return -ROCKER_EINVAL
;
375 fp_port
= r
->fp_port
[port
];
377 if (tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
] &&
378 tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
] &&
379 tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
]) {
381 speed
= rocker_tlv_get_le32(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
]);
382 duplex
= rocker_tlv_get_u8(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
]);
383 autoneg
= rocker_tlv_get_u8(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
]);
385 err
= fp_port_set_settings(fp_port
, speed
, duplex
, autoneg
);
391 if (tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
]) {
392 if (rocker_tlv_len(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
]) !=
394 return -ROCKER_EINVAL
;
397 rocker_tlv_data(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
]),
399 fp_port_set_macaddr(fp_port
, &macaddr
);
402 if (tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MODE
]) {
403 mode
= rocker_tlv_get_u8(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_MODE
]);
404 fp_port_set_world(fp_port
, r
->worlds
[mode
]);
407 if (tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING
]) {
409 rocker_tlv_get_u8(tlvs
[ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING
]);
410 fp_port_set_learning(fp_port
, learning
);
416 static int cmd_consume(Rocker
*r
, DescInfo
*info
)
418 char *buf
= desc_get_buf(info
, false);
419 RockerTlv
*tlvs
[ROCKER_TLV_CMD_MAX
+ 1];
426 return -ROCKER_ENXIO
;
429 rocker_tlv_parse(tlvs
, ROCKER_TLV_CMD_MAX
, buf
, desc_tlv_size(info
));
431 if (!tlvs
[ROCKER_TLV_CMD_TYPE
] || !tlvs
[ROCKER_TLV_CMD_INFO
]) {
432 return -ROCKER_EINVAL
;
435 cmd
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_CMD_TYPE
]);
436 info_tlv
= tlvs
[ROCKER_TLV_CMD_INFO
];
438 /* This might be reworked to something like this:
439 * Every world will have an array of command handlers from
440 * ROCKER_TLV_CMD_TYPE_UNSPEC to ROCKER_TLV_CMD_TYPE_MAX. There is
441 * up to each world to implement whatever command it want.
442 * It can reference "generic" commands as cmd_set_port_settings or
443 * cmd_get_port_settings
447 case ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_ADD
:
448 case ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_MOD
:
449 case ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_DEL
:
450 case ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_GET_STATS
:
451 case ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_ADD
:
452 case ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_MOD
:
453 case ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_DEL
:
454 case ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_GET_STATS
:
455 world
= r
->worlds
[ROCKER_WORLD_TYPE_OF_DPA
];
456 err
= world_do_cmd(world
, info
, buf
, cmd
, info_tlv
);
458 case ROCKER_TLV_CMD_TYPE_GET_PORT_SETTINGS
:
459 err
= cmd_get_port_settings(r
, info
, buf
, info_tlv
);
461 case ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS
:
462 err
= cmd_set_port_settings(r
, info_tlv
);
465 err
= -ROCKER_EINVAL
;
472 static void rocker_msix_irq(Rocker
*r
, unsigned vector
)
474 PCIDevice
*dev
= PCI_DEVICE(r
);
476 DPRINTF("MSI-X notify request for vector %d\n", vector
);
477 if (vector
>= ROCKER_MSIX_VEC_COUNT(r
->fp_ports
)) {
478 DPRINTF("incorrect vector %d\n", vector
);
481 msix_notify(dev
, vector
);
484 int rocker_event_link_changed(Rocker
*r
, uint32_t pport
, bool link_up
)
486 DescRing
*ring
= r
->rings
[ROCKER_RING_EVENT
];
487 DescInfo
*info
= desc_ring_fetch_desc(ring
);
495 return -ROCKER_ENOBUFS
;
498 tlv_size
= rocker_tlv_total_size(sizeof(uint16_t)) + /* event type */
499 rocker_tlv_total_size(0) + /* nest */
500 rocker_tlv_total_size(sizeof(uint32_t)) + /* pport */
501 rocker_tlv_total_size(sizeof(uint8_t)); /* link up */
503 if (tlv_size
> desc_buf_size(info
)) {
504 err
= -ROCKER_EMSGSIZE
;
508 buf
= desc_get_buf(info
, false);
510 err
= -ROCKER_ENOMEM
;
515 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_EVENT_TYPE
,
516 ROCKER_TLV_EVENT_TYPE_LINK_CHANGED
);
517 nest
= rocker_tlv_nest_start(buf
, &pos
, ROCKER_TLV_EVENT_INFO
);
518 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_EVENT_LINK_CHANGED_PPORT
, pport
);
519 rocker_tlv_put_u8(buf
, &pos
, ROCKER_TLV_EVENT_LINK_CHANGED_LINKUP
,
521 rocker_tlv_nest_end(buf
, &pos
, nest
);
523 err
= desc_set_buf(info
, tlv_size
);
527 if (desc_ring_post_desc(ring
, err
)) {
528 rocker_msix_irq(r
, ROCKER_MSIX_VEC_EVENT
);
534 int rocker_event_mac_vlan_seen(Rocker
*r
, uint32_t pport
, uint8_t *addr
,
537 DescRing
*ring
= r
->rings
[ROCKER_RING_EVENT
];
547 if (!fp_port_from_pport(pport
, &port
)) {
548 return -ROCKER_EINVAL
;
550 fp_port
= r
->fp_port
[port
];
551 if (!fp_port_get_learning(fp_port
)) {
555 info
= desc_ring_fetch_desc(ring
);
557 return -ROCKER_ENOBUFS
;
560 tlv_size
= rocker_tlv_total_size(sizeof(uint16_t)) + /* event type */
561 rocker_tlv_total_size(0) + /* nest */
562 rocker_tlv_total_size(sizeof(uint32_t)) + /* pport */
563 rocker_tlv_total_size(ETH_ALEN
) + /* mac addr */
564 rocker_tlv_total_size(sizeof(uint16_t)); /* vlan_id */
566 if (tlv_size
> desc_buf_size(info
)) {
567 err
= -ROCKER_EMSGSIZE
;
571 buf
= desc_get_buf(info
, false);
573 err
= -ROCKER_ENOMEM
;
578 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_EVENT_TYPE
,
579 ROCKER_TLV_EVENT_TYPE_MAC_VLAN_SEEN
);
580 nest
= rocker_tlv_nest_start(buf
, &pos
, ROCKER_TLV_EVENT_INFO
);
581 rocker_tlv_put_le32(buf
, &pos
, ROCKER_TLV_EVENT_MAC_VLAN_PPORT
, pport
);
582 rocker_tlv_put(buf
, &pos
, ROCKER_TLV_EVENT_MAC_VLAN_MAC
, ETH_ALEN
, addr
);
583 rocker_tlv_put_u16(buf
, &pos
, ROCKER_TLV_EVENT_MAC_VLAN_VLAN_ID
, vlan_id
);
584 rocker_tlv_nest_end(buf
, &pos
, nest
);
586 err
= desc_set_buf(info
, tlv_size
);
590 if (desc_ring_post_desc(ring
, err
)) {
591 rocker_msix_irq(r
, ROCKER_MSIX_VEC_EVENT
);
597 static DescRing
*rocker_get_rx_ring_by_pport(Rocker
*r
,
600 return r
->rings
[(pport
- 1) * 2 + 3];
603 int rx_produce(World
*world
, uint32_t pport
,
604 const struct iovec
*iov
, int iovcnt
, uint8_t copy_to_cpu
)
606 Rocker
*r
= world_rocker(world
);
607 PCIDevice
*dev
= (PCIDevice
*)r
;
608 DescRing
*ring
= rocker_get_rx_ring_by_pport(r
, pport
);
609 DescInfo
*info
= desc_ring_fetch_desc(ring
);
611 size_t data_size
= iov_size(iov
, iovcnt
);
613 uint16_t rx_flags
= 0;
614 uint16_t rx_csum
= 0;
616 RockerTlv
*tlvs
[ROCKER_TLV_RX_MAX
+ 1];
618 uint16_t frag_max_len
;
623 return -ROCKER_ENOBUFS
;
626 buf
= desc_get_buf(info
, false);
631 rocker_tlv_parse(tlvs
, ROCKER_TLV_RX_MAX
, buf
, desc_tlv_size(info
));
633 if (!tlvs
[ROCKER_TLV_RX_FRAG_ADDR
] ||
634 !tlvs
[ROCKER_TLV_RX_FRAG_MAX_LEN
]) {
635 err
= -ROCKER_EINVAL
;
639 frag_addr
= rocker_tlv_get_le64(tlvs
[ROCKER_TLV_RX_FRAG_ADDR
]);
640 frag_max_len
= rocker_tlv_get_le16(tlvs
[ROCKER_TLV_RX_FRAG_MAX_LEN
]);
642 if (data_size
> frag_max_len
) {
643 err
= -ROCKER_EMSGSIZE
;
648 rx_flags
|= ROCKER_RX_FLAGS_FWD_OFFLOAD
;
651 /* XXX calc rx flags/csum */
653 tlv_size
= rocker_tlv_total_size(sizeof(uint16_t)) + /* flags */
654 rocker_tlv_total_size(sizeof(uint16_t)) + /* scum */
655 rocker_tlv_total_size(sizeof(uint64_t)) + /* frag addr */
656 rocker_tlv_total_size(sizeof(uint16_t)) + /* frag max len */
657 rocker_tlv_total_size(sizeof(uint16_t)); /* frag len */
659 if (tlv_size
> desc_buf_size(info
)) {
660 err
= -ROCKER_EMSGSIZE
;
665 * iov dma write can be optimized in similar way e1000 does it in
666 * e1000_receive_iov. But maybe if would make sense to introduce
667 * generic helper iov_dma_write.
670 data
= g_malloc(data_size
);
672 err
= -ROCKER_ENOMEM
;
675 iov_to_buf(iov
, iovcnt
, 0, data
, data_size
);
676 pci_dma_write(dev
, frag_addr
, data
, data_size
);
680 rocker_tlv_put_le16(buf
, &pos
, ROCKER_TLV_RX_FLAGS
, rx_flags
);
681 rocker_tlv_put_le16(buf
, &pos
, ROCKER_TLV_RX_CSUM
, rx_csum
);
682 rocker_tlv_put_le64(buf
, &pos
, ROCKER_TLV_RX_FRAG_ADDR
, frag_addr
);
683 rocker_tlv_put_le16(buf
, &pos
, ROCKER_TLV_RX_FRAG_MAX_LEN
, frag_max_len
);
684 rocker_tlv_put_le16(buf
, &pos
, ROCKER_TLV_RX_FRAG_LEN
, data_size
);
686 err
= desc_set_buf(info
, tlv_size
);
689 if (desc_ring_post_desc(ring
, err
)) {
690 rocker_msix_irq(r
, ROCKER_MSIX_VEC_RX(pport
- 1));
696 int rocker_port_eg(Rocker
*r
, uint32_t pport
,
697 const struct iovec
*iov
, int iovcnt
)
702 if (!fp_port_from_pport(pport
, &port
)) {
703 return -ROCKER_EINVAL
;
706 fp_port
= r
->fp_port
[port
];
708 return fp_port_eg(fp_port
, iov
, iovcnt
);
711 static void rocker_test_dma_ctrl(Rocker
*r
, uint32_t val
)
713 PCIDevice
*dev
= PCI_DEVICE(r
);
717 buf
= g_malloc(r
->test_dma_size
);
720 DPRINTF("test dma buffer alloc failed");
725 case ROCKER_TEST_DMA_CTRL_CLEAR
:
726 memset(buf
, 0, r
->test_dma_size
);
728 case ROCKER_TEST_DMA_CTRL_FILL
:
729 memset(buf
, 0x96, r
->test_dma_size
);
731 case ROCKER_TEST_DMA_CTRL_INVERT
:
732 pci_dma_read(dev
, r
->test_dma_addr
, buf
, r
->test_dma_size
);
733 for (i
= 0; i
< r
->test_dma_size
; i
++) {
738 DPRINTF("not test dma control val=0x%08x\n", val
);
741 pci_dma_write(dev
, r
->test_dma_addr
, buf
, r
->test_dma_size
);
743 rocker_msix_irq(r
, ROCKER_MSIX_VEC_TEST
);
749 static void rocker_reset(DeviceState
*dev
);
751 static void rocker_control(Rocker
*r
, uint32_t val
)
753 if (val
& ROCKER_CONTROL_RESET
) {
754 rocker_reset(DEVICE(r
));
758 static int rocker_pci_ring_count(Rocker
*r
)
763 * - tx and rx ring per each port
765 return 2 + (2 * r
->fp_ports
);
768 static bool rocker_addr_is_desc_reg(Rocker
*r
, hwaddr addr
)
770 hwaddr start
= ROCKER_DMA_DESC_BASE
;
771 hwaddr end
= start
+ (ROCKER_DMA_DESC_SIZE
* rocker_pci_ring_count(r
));
773 return addr
>= start
&& addr
< end
;
776 static void rocker_port_phys_enable_write(Rocker
*r
, uint64_t new)
783 for (i
= 0; i
< r
->fp_ports
; i
++) {
784 fp_port
= r
->fp_port
[i
];
785 old_enabled
= fp_port_enabled(fp_port
);
786 new_enabled
= (new >> (i
+ 1)) & 0x1;
787 if (new_enabled
== old_enabled
) {
791 fp_port_enable(r
->fp_port
[i
]);
793 fp_port_disable(r
->fp_port
[i
]);
798 static void rocker_io_writel(void *opaque
, hwaddr addr
, uint32_t val
)
802 if (rocker_addr_is_desc_reg(r
, addr
)) {
803 unsigned index
= ROCKER_RING_INDEX(addr
);
804 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
807 case ROCKER_DMA_DESC_ADDR_OFFSET
:
808 r
->lower32
= (uint64_t)val
;
810 case ROCKER_DMA_DESC_ADDR_OFFSET
+ 4:
811 desc_ring_set_base_addr(r
->rings
[index
],
812 ((uint64_t)val
) << 32 | r
->lower32
);
815 case ROCKER_DMA_DESC_SIZE_OFFSET
:
816 desc_ring_set_size(r
->rings
[index
], val
);
818 case ROCKER_DMA_DESC_HEAD_OFFSET
:
819 if (desc_ring_set_head(r
->rings
[index
], val
)) {
820 rocker_msix_irq(r
, desc_ring_get_msix_vector(r
->rings
[index
]));
823 case ROCKER_DMA_DESC_CTRL_OFFSET
:
824 desc_ring_set_ctrl(r
->rings
[index
], val
);
826 case ROCKER_DMA_DESC_CREDITS_OFFSET
:
827 if (desc_ring_ret_credits(r
->rings
[index
], val
)) {
828 rocker_msix_irq(r
, desc_ring_get_msix_vector(r
->rings
[index
]));
832 DPRINTF("not implemented dma reg write(l) addr=0x" TARGET_FMT_plx
833 " val=0x%08x (ring %d, addr=0x%02x)\n",
834 addr
, val
, index
, offset
);
841 case ROCKER_TEST_REG
:
844 case ROCKER_TEST_REG64
:
845 case ROCKER_TEST_DMA_ADDR
:
846 case ROCKER_PORT_PHYS_ENABLE
:
847 r
->lower32
= (uint64_t)val
;
849 case ROCKER_TEST_REG64
+ 4:
850 r
->test_reg64
= ((uint64_t)val
) << 32 | r
->lower32
;
853 case ROCKER_TEST_IRQ
:
854 rocker_msix_irq(r
, val
);
856 case ROCKER_TEST_DMA_SIZE
:
857 r
->test_dma_size
= val
;
859 case ROCKER_TEST_DMA_ADDR
+ 4:
860 r
->test_dma_addr
= ((uint64_t)val
) << 32 | r
->lower32
;
863 case ROCKER_TEST_DMA_CTRL
:
864 rocker_test_dma_ctrl(r
, val
);
867 rocker_control(r
, val
);
869 case ROCKER_PORT_PHYS_ENABLE
+ 4:
870 rocker_port_phys_enable_write(r
, ((uint64_t)val
) << 32 | r
->lower32
);
874 DPRINTF("not implemented write(l) addr=0x" TARGET_FMT_plx
875 " val=0x%08x\n", addr
, val
);
880 static void rocker_io_writeq(void *opaque
, hwaddr addr
, uint64_t val
)
884 if (rocker_addr_is_desc_reg(r
, addr
)) {
885 unsigned index
= ROCKER_RING_INDEX(addr
);
886 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
889 case ROCKER_DMA_DESC_ADDR_OFFSET
:
890 desc_ring_set_base_addr(r
->rings
[index
], val
);
893 DPRINTF("not implemented dma reg write(q) addr=0x" TARGET_FMT_plx
894 " val=0x" TARGET_FMT_plx
" (ring %d, offset=0x%02x)\n",
895 addr
, val
, index
, offset
);
902 case ROCKER_TEST_REG64
:
905 case ROCKER_TEST_DMA_ADDR
:
906 r
->test_dma_addr
= val
;
908 case ROCKER_PORT_PHYS_ENABLE
:
909 rocker_port_phys_enable_write(r
, val
);
912 DPRINTF("not implemented write(q) addr=0x" TARGET_FMT_plx
913 " val=0x" TARGET_FMT_plx
"\n", addr
, val
);
919 #define regname(reg) case (reg): return #reg
920 static const char *rocker_reg_name(void *opaque
, hwaddr addr
)
924 if (rocker_addr_is_desc_reg(r
, addr
)) {
925 unsigned index
= ROCKER_RING_INDEX(addr
);
926 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
927 static char buf
[100];
932 sprintf(ring_name
, "cmd");
935 sprintf(ring_name
, "event");
938 sprintf(ring_name
, "%s-%d", index
% 2 ? "rx" : "tx",
943 case ROCKER_DMA_DESC_ADDR_OFFSET
:
944 sprintf(buf
, "Ring[%s] ADDR", ring_name
);
946 case ROCKER_DMA_DESC_ADDR_OFFSET
+4:
947 sprintf(buf
, "Ring[%s] ADDR+4", ring_name
);
949 case ROCKER_DMA_DESC_SIZE_OFFSET
:
950 sprintf(buf
, "Ring[%s] SIZE", ring_name
);
952 case ROCKER_DMA_DESC_HEAD_OFFSET
:
953 sprintf(buf
, "Ring[%s] HEAD", ring_name
);
955 case ROCKER_DMA_DESC_TAIL_OFFSET
:
956 sprintf(buf
, "Ring[%s] TAIL", ring_name
);
958 case ROCKER_DMA_DESC_CTRL_OFFSET
:
959 sprintf(buf
, "Ring[%s] CTRL", ring_name
);
961 case ROCKER_DMA_DESC_CREDITS_OFFSET
:
962 sprintf(buf
, "Ring[%s] CREDITS", ring_name
);
965 sprintf(buf
, "Ring[%s] ???", ring_name
);
970 regname(ROCKER_BOGUS_REG0
);
971 regname(ROCKER_BOGUS_REG1
);
972 regname(ROCKER_BOGUS_REG2
);
973 regname(ROCKER_BOGUS_REG3
);
974 regname(ROCKER_TEST_REG
);
975 regname(ROCKER_TEST_REG64
);
976 regname(ROCKER_TEST_REG64
+4);
977 regname(ROCKER_TEST_IRQ
);
978 regname(ROCKER_TEST_DMA_ADDR
);
979 regname(ROCKER_TEST_DMA_ADDR
+4);
980 regname(ROCKER_TEST_DMA_SIZE
);
981 regname(ROCKER_TEST_DMA_CTRL
);
982 regname(ROCKER_CONTROL
);
983 regname(ROCKER_PORT_PHYS_COUNT
);
984 regname(ROCKER_PORT_PHYS_LINK_STATUS
);
985 regname(ROCKER_PORT_PHYS_LINK_STATUS
+4);
986 regname(ROCKER_PORT_PHYS_ENABLE
);
987 regname(ROCKER_PORT_PHYS_ENABLE
+4);
988 regname(ROCKER_SWITCH_ID
);
989 regname(ROCKER_SWITCH_ID
+4);
995 static const char *rocker_reg_name(void *opaque
, hwaddr addr
)
1001 static void rocker_mmio_write(void *opaque
, hwaddr addr
, uint64_t val
,
1004 DPRINTF("Write %s addr " TARGET_FMT_plx
1005 ", size %u, val " TARGET_FMT_plx
"\n",
1006 rocker_reg_name(opaque
, addr
), addr
, size
, val
);
1010 rocker_io_writel(opaque
, addr
, val
);
1013 rocker_io_writeq(opaque
, addr
, val
);
1018 static uint64_t rocker_port_phys_link_status(Rocker
*r
)
1021 uint64_t status
= 0;
1023 for (i
= 0; i
< r
->fp_ports
; i
++) {
1024 FpPort
*port
= r
->fp_port
[i
];
1026 if (fp_port_get_link_up(port
)) {
1027 status
|= 1 << (i
+ 1);
1033 static uint64_t rocker_port_phys_enable_read(Rocker
*r
)
1038 for (i
= 0; i
< r
->fp_ports
; i
++) {
1039 FpPort
*port
= r
->fp_port
[i
];
1041 if (fp_port_enabled(port
)) {
1042 ret
|= 1 << (i
+ 1);
1048 static uint32_t rocker_io_readl(void *opaque
, hwaddr addr
)
1053 if (rocker_addr_is_desc_reg(r
, addr
)) {
1054 unsigned index
= ROCKER_RING_INDEX(addr
);
1055 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
1058 case ROCKER_DMA_DESC_ADDR_OFFSET
:
1059 ret
= (uint32_t)desc_ring_get_base_addr(r
->rings
[index
]);
1061 case ROCKER_DMA_DESC_ADDR_OFFSET
+ 4:
1062 ret
= (uint32_t)(desc_ring_get_base_addr(r
->rings
[index
]) >> 32);
1064 case ROCKER_DMA_DESC_SIZE_OFFSET
:
1065 ret
= desc_ring_get_size(r
->rings
[index
]);
1067 case ROCKER_DMA_DESC_HEAD_OFFSET
:
1068 ret
= desc_ring_get_head(r
->rings
[index
]);
1070 case ROCKER_DMA_DESC_TAIL_OFFSET
:
1071 ret
= desc_ring_get_tail(r
->rings
[index
]);
1073 case ROCKER_DMA_DESC_CREDITS_OFFSET
:
1074 ret
= desc_ring_get_credits(r
->rings
[index
]);
1077 DPRINTF("not implemented dma reg read(l) addr=0x" TARGET_FMT_plx
1078 " (ring %d, addr=0x%02x)\n", addr
, index
, offset
);
1086 case ROCKER_BOGUS_REG0
:
1087 case ROCKER_BOGUS_REG1
:
1088 case ROCKER_BOGUS_REG2
:
1089 case ROCKER_BOGUS_REG3
:
1092 case ROCKER_TEST_REG
:
1093 ret
= r
->test_reg
* 2;
1095 case ROCKER_TEST_REG64
:
1096 ret
= (uint32_t)(r
->test_reg64
* 2);
1098 case ROCKER_TEST_REG64
+ 4:
1099 ret
= (uint32_t)((r
->test_reg64
* 2) >> 32);
1101 case ROCKER_TEST_DMA_SIZE
:
1102 ret
= r
->test_dma_size
;
1104 case ROCKER_TEST_DMA_ADDR
:
1105 ret
= (uint32_t)r
->test_dma_addr
;
1107 case ROCKER_TEST_DMA_ADDR
+ 4:
1108 ret
= (uint32_t)(r
->test_dma_addr
>> 32);
1110 case ROCKER_PORT_PHYS_COUNT
:
1113 case ROCKER_PORT_PHYS_LINK_STATUS
:
1114 ret
= (uint32_t)rocker_port_phys_link_status(r
);
1116 case ROCKER_PORT_PHYS_LINK_STATUS
+ 4:
1117 ret
= (uint32_t)(rocker_port_phys_link_status(r
) >> 32);
1119 case ROCKER_PORT_PHYS_ENABLE
:
1120 ret
= (uint32_t)rocker_port_phys_enable_read(r
);
1122 case ROCKER_PORT_PHYS_ENABLE
+ 4:
1123 ret
= (uint32_t)(rocker_port_phys_enable_read(r
) >> 32);
1125 case ROCKER_SWITCH_ID
:
1126 ret
= (uint32_t)r
->switch_id
;
1128 case ROCKER_SWITCH_ID
+ 4:
1129 ret
= (uint32_t)(r
->switch_id
>> 32);
1132 DPRINTF("not implemented read(l) addr=0x" TARGET_FMT_plx
"\n", addr
);
1139 static uint64_t rocker_io_readq(void *opaque
, hwaddr addr
)
1144 if (rocker_addr_is_desc_reg(r
, addr
)) {
1145 unsigned index
= ROCKER_RING_INDEX(addr
);
1146 unsigned offset
= addr
& ROCKER_DMA_DESC_MASK
;
1148 switch (addr
& ROCKER_DMA_DESC_MASK
) {
1149 case ROCKER_DMA_DESC_ADDR_OFFSET
:
1150 ret
= desc_ring_get_base_addr(r
->rings
[index
]);
1153 DPRINTF("not implemented dma reg read(q) addr=0x" TARGET_FMT_plx
1154 " (ring %d, addr=0x%02x)\n", addr
, index
, offset
);
1162 case ROCKER_BOGUS_REG0
:
1163 case ROCKER_BOGUS_REG2
:
1164 ret
= 0xDEADBABEDEADBABEULL
;
1166 case ROCKER_TEST_REG64
:
1167 ret
= r
->test_reg64
* 2;
1169 case ROCKER_TEST_DMA_ADDR
:
1170 ret
= r
->test_dma_addr
;
1172 case ROCKER_PORT_PHYS_LINK_STATUS
:
1173 ret
= rocker_port_phys_link_status(r
);
1175 case ROCKER_PORT_PHYS_ENABLE
:
1176 ret
= rocker_port_phys_enable_read(r
);
1178 case ROCKER_SWITCH_ID
:
1182 DPRINTF("not implemented read(q) addr=0x" TARGET_FMT_plx
"\n", addr
);
1189 static uint64_t rocker_mmio_read(void *opaque
, hwaddr addr
, unsigned size
)
1191 DPRINTF("Read %s addr " TARGET_FMT_plx
", size %u\n",
1192 rocker_reg_name(opaque
, addr
), addr
, size
);
1196 return rocker_io_readl(opaque
, addr
);
1198 return rocker_io_readq(opaque
, addr
);
1204 static const MemoryRegionOps rocker_mmio_ops
= {
1205 .read
= rocker_mmio_read
,
1206 .write
= rocker_mmio_write
,
1207 .endianness
= DEVICE_LITTLE_ENDIAN
,
1209 .min_access_size
= 4,
1210 .max_access_size
= 8,
1213 .min_access_size
= 4,
1214 .max_access_size
= 8,
1218 static void rocker_msix_vectors_unuse(Rocker
*r
,
1219 unsigned int num_vectors
)
1221 PCIDevice
*dev
= PCI_DEVICE(r
);
1224 for (i
= 0; i
< num_vectors
; i
++) {
1225 msix_vector_unuse(dev
, i
);
1229 static int rocker_msix_vectors_use(Rocker
*r
,
1230 unsigned int num_vectors
)
1232 PCIDevice
*dev
= PCI_DEVICE(r
);
1236 for (i
= 0; i
< num_vectors
; i
++) {
1237 err
= msix_vector_use(dev
, i
);
1245 rocker_msix_vectors_unuse(r
, i
);
1249 static int rocker_msix_init(Rocker
*r
)
1251 PCIDevice
*dev
= PCI_DEVICE(r
);
1254 err
= msix_init(dev
, ROCKER_MSIX_VEC_COUNT(r
->fp_ports
),
1256 ROCKER_PCI_MSIX_BAR_IDX
, ROCKER_PCI_MSIX_TABLE_OFFSET
,
1258 ROCKER_PCI_MSIX_BAR_IDX
, ROCKER_PCI_MSIX_PBA_OFFSET
,
1264 err
= rocker_msix_vectors_use(r
, ROCKER_MSIX_VEC_COUNT(r
->fp_ports
));
1266 goto err_msix_vectors_use
;
1271 err_msix_vectors_use
:
1272 msix_uninit(dev
, &r
->msix_bar
, &r
->msix_bar
);
1276 static void rocker_msix_uninit(Rocker
*r
)
1278 PCIDevice
*dev
= PCI_DEVICE(r
);
1280 msix_uninit(dev
, &r
->msix_bar
, &r
->msix_bar
);
1281 rocker_msix_vectors_unuse(r
, ROCKER_MSIX_VEC_COUNT(r
->fp_ports
));
1284 static int pci_rocker_init(PCIDevice
*dev
)
1286 Rocker
*r
= to_rocker(dev
);
1287 const MACAddr zero
= { .a
= { 0, 0, 0, 0, 0, 0 } };
1288 const MACAddr dflt
= { .a
= { 0x52, 0x54, 0x00, 0x12, 0x35, 0x01 } };
1289 static int sw_index
;
1292 /* allocate worlds */
1294 r
->worlds
[ROCKER_WORLD_TYPE_OF_DPA
] = of_dpa_world_alloc(r
);
1295 r
->world_dflt
= r
->worlds
[ROCKER_WORLD_TYPE_OF_DPA
];
1297 for (i
= 0; i
< ROCKER_WORLD_TYPE_MAX
; i
++) {
1298 if (!r
->worlds
[i
]) {
1299 goto err_world_alloc
;
1303 /* set up memory-mapped region at BAR0 */
1305 memory_region_init_io(&r
->mmio
, OBJECT(r
), &rocker_mmio_ops
, r
,
1306 "rocker-mmio", ROCKER_PCI_BAR0_SIZE
);
1307 pci_register_bar(dev
, ROCKER_PCI_BAR0_IDX
,
1308 PCI_BASE_ADDRESS_SPACE_MEMORY
, &r
->mmio
);
1310 /* set up memory-mapped region for MSI-X */
1312 memory_region_init(&r
->msix_bar
, OBJECT(r
), "rocker-msix-bar",
1313 ROCKER_PCI_MSIX_BAR_SIZE
);
1314 pci_register_bar(dev
, ROCKER_PCI_MSIX_BAR_IDX
,
1315 PCI_BASE_ADDRESS_SPACE_MEMORY
, &r
->msix_bar
);
1319 err
= rocker_msix_init(r
);
1324 /* validate switch properties */
1327 r
->name
= g_strdup(ROCKER
);
1330 if (rocker_find(r
->name
)) {
1335 /* Rocker name is passed in port name requests to OS with the intention
1336 * that the name is used in interface names. Limit the length of the
1337 * rocker name to avoid naming problems in the OS. Also, adding the
1338 * port number as p# and unganged breakout b#, where # is at most 2
1339 * digits, so leave room for it too (-1 for string terminator, -3 for
1342 #define ROCKER_IFNAMSIZ 16
1343 #define MAX_ROCKER_NAME_LEN (ROCKER_IFNAMSIZ - 1 - 3 - 3)
1344 if (strlen(r
->name
) > MAX_ROCKER_NAME_LEN
) {
1346 "rocker: name too long; please shorten to at most %d chars\n",
1347 MAX_ROCKER_NAME_LEN
);
1351 if (memcmp(&r
->fp_start_macaddr
, &zero
, sizeof(zero
)) == 0) {
1352 memcpy(&r
->fp_start_macaddr
, &dflt
, sizeof(dflt
));
1353 r
->fp_start_macaddr
.a
[4] += (sw_index
++);
1356 if (!r
->switch_id
) {
1357 memcpy(&r
->switch_id
, &r
->fp_start_macaddr
,
1358 sizeof(r
->fp_start_macaddr
));
1361 if (r
->fp_ports
> ROCKER_FP_PORTS_MAX
) {
1362 r
->fp_ports
= ROCKER_FP_PORTS_MAX
;
1365 r
->rings
= g_malloc(sizeof(DescRing
*) * rocker_pci_ring_count(r
));
1367 goto err_rings_alloc
;
1370 /* Rings are ordered like this:
1381 for (i
= 0; i
< rocker_pci_ring_count(r
); i
++) {
1382 DescRing
*ring
= desc_ring_alloc(r
, i
);
1385 goto err_ring_alloc
;
1388 if (i
== ROCKER_RING_CMD
) {
1389 desc_ring_set_consume(ring
, cmd_consume
, ROCKER_MSIX_VEC_CMD
);
1390 } else if (i
== ROCKER_RING_EVENT
) {
1391 desc_ring_set_consume(ring
, NULL
, ROCKER_MSIX_VEC_EVENT
);
1392 } else if (i
% 2 == 0) {
1393 desc_ring_set_consume(ring
, tx_consume
,
1394 ROCKER_MSIX_VEC_TX((i
- 2) / 2));
1395 } else if (i
% 2 == 1) {
1396 desc_ring_set_consume(ring
, NULL
, ROCKER_MSIX_VEC_RX((i
- 3) / 2));
1402 for (i
= 0; i
< r
->fp_ports
; i
++) {
1404 fp_port_alloc(r
, r
->name
, &r
->fp_start_macaddr
,
1405 i
, &r
->fp_ports_peers
[i
]);
1408 goto err_port_alloc
;
1411 r
->fp_port
[i
] = port
;
1412 fp_port_set_world(port
, r
->world_dflt
);
1415 QLIST_INSERT_HEAD(&rockers
, r
, next
);
1420 for (--i
; i
>= 0; i
--) {
1421 FpPort
*port
= r
->fp_port
[i
];
1424 i
= rocker_pci_ring_count(r
);
1426 for (--i
; i
>= 0; i
--) {
1427 desc_ring_free(r
->rings
[i
]);
1432 rocker_msix_uninit(r
);
1434 object_unparent(OBJECT(&r
->msix_bar
));
1435 object_unparent(OBJECT(&r
->mmio
));
1437 for (i
= 0; i
< ROCKER_WORLD_TYPE_MAX
; i
++) {
1439 world_free(r
->worlds
[i
]);
1445 static void pci_rocker_uninit(PCIDevice
*dev
)
1447 Rocker
*r
= to_rocker(dev
);
1450 QLIST_REMOVE(r
, next
);
1452 for (i
= 0; i
< r
->fp_ports
; i
++) {
1453 FpPort
*port
= r
->fp_port
[i
];
1456 r
->fp_port
[i
] = NULL
;
1459 for (i
= 0; i
< rocker_pci_ring_count(r
); i
++) {
1461 desc_ring_free(r
->rings
[i
]);
1466 rocker_msix_uninit(r
);
1467 object_unparent(OBJECT(&r
->msix_bar
));
1468 object_unparent(OBJECT(&r
->mmio
));
1470 for (i
= 0; i
< ROCKER_WORLD_TYPE_MAX
; i
++) {
1472 world_free(r
->worlds
[i
]);
1475 g_free(r
->fp_ports_peers
);
1478 static void rocker_reset(DeviceState
*dev
)
1480 Rocker
*r
= to_rocker(dev
);
1483 for (i
= 0; i
< ROCKER_WORLD_TYPE_MAX
; i
++) {
1485 world_reset(r
->worlds
[i
]);
1488 for (i
= 0; i
< r
->fp_ports
; i
++) {
1489 fp_port_reset(r
->fp_port
[i
]);
1490 fp_port_set_world(r
->fp_port
[i
], r
->world_dflt
);
1495 r
->test_dma_addr
= 0;
1496 r
->test_dma_size
= 0;
1498 for (i
= 0; i
< rocker_pci_ring_count(r
); i
++) {
1499 desc_ring_reset(r
->rings
[i
]);
1502 DPRINTF("Reset done\n");
1505 static Property rocker_properties
[] = {
1506 DEFINE_PROP_STRING("name", Rocker
, name
),
1507 DEFINE_PROP_MACADDR("fp_start_macaddr", Rocker
,
1509 DEFINE_PROP_UINT64("switch_id", Rocker
,
1511 DEFINE_PROP_ARRAY("ports", Rocker
, fp_ports
,
1512 fp_ports_peers
, qdev_prop_netdev
, NICPeers
),
1513 DEFINE_PROP_END_OF_LIST(),
1516 static const VMStateDescription rocker_vmsd
= {
1521 static void rocker_class_init(ObjectClass
*klass
, void *data
)
1523 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1524 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
1526 k
->init
= pci_rocker_init
;
1527 k
->exit
= pci_rocker_uninit
;
1528 k
->vendor_id
= PCI_VENDOR_ID_REDHAT
;
1529 k
->device_id
= PCI_DEVICE_ID_REDHAT_ROCKER
;
1530 k
->revision
= ROCKER_PCI_REVISION
;
1531 k
->class_id
= PCI_CLASS_NETWORK_OTHER
;
1532 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
1533 dc
->desc
= "Rocker Switch";
1534 dc
->reset
= rocker_reset
;
1535 dc
->props
= rocker_properties
;
1536 dc
->vmsd
= &rocker_vmsd
;
1539 static const TypeInfo rocker_info
= {
1541 .parent
= TYPE_PCI_DEVICE
,
1542 .instance_size
= sizeof(Rocker
),
1543 .class_init
= rocker_class_init
,
1546 static void rocker_register_types(void)
1548 type_register_static(&rocker_info
);
1551 type_init(rocker_register_types
)