#include <rte_atomic.h>
#include <rte_dev.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
#include <rte_devargs.h>
+#include <rte_interrupts.h>
#define FAILSAFE_DRIVER_NAME "Fail-safe PMD"
#define PMD_FAILSAFE_PARAM_STRING \
"dev(<ifc>)," \
"exec(<shell command>)," \
+ "fd(<fd number>)," \
"mac=mac_addr," \
"hotplug_poll=u64" \
""
#define FAILSAFE_MAX_ETHPORTS 2
#define FAILSAFE_MAX_ETHADDR 128
+#define DEVARGS_MAXLEN 4096
+
/* TYPES */
struct rxq {
struct fs_priv *priv;
uint16_t qid;
- /* id of last sub_device polled */
- uint8_t last_polled;
+ /* next sub_device to poll */
+ struct sub_device *sdev;
unsigned int socket_id;
+ int event_fd;
+ unsigned int enable_events:1;
struct rte_eth_rxq_info info;
rte_atomic64_t refcnt[];
};
DEV_STARTED,
};
+struct fs_stats {
+ struct rte_eth_stats stats;
+ uint64_t timestamp;
+};
+
struct sub_device {
/* Exhaustive DPDK device description */
+ struct sub_device *next;
struct rte_devargs devargs;
struct rte_bus *bus;
struct rte_device *dev;
uint8_t sid;
/* Device state machine */
enum dev_state state;
+ /* Last stats snapshot passed to user */
+ struct fs_stats stats_snapshot;
/* Some device are defined as a command line */
char *cmdline;
+ /* Others are retrieved through a file descriptor */
+ char *fd_str;
/* fail-safe device backreference */
struct rte_eth_dev *fs_dev;
/* flag calling for recollection */
volatile unsigned int remove:1;
+ /* flow isolation state */
+ int flow_isolated:1;
};
struct fs_priv {
uint32_t mac_addr_pool[FAILSAFE_MAX_ETHADDR];
/* current capabilities */
struct rte_eth_dev_info infos;
+ struct rte_intr_handle intr_handle; /* Port interrupt handle. */
/*
* Fail-safe state machine.
* This level will be tracking state of the EAL and eth
* synchronized state.
*/
enum dev_state state;
+ struct rte_eth_stats stats_accumulator;
unsigned int pending_alarm:1; /* An alarm is pending */
+ /* flow isolation state */
+ int flow_isolated:1;
};
+/* FAILSAFE_INTR */
+
+int failsafe_rx_intr_install(struct rte_eth_dev *dev);
+void failsafe_rx_intr_uninstall(struct rte_eth_dev *dev);
+
/* MISC */
int failsafe_hotplug_alarm_install(struct rte_eth_dev *dev);
int failsafe_eth_dev_state_sync(struct rte_eth_dev *dev);
void failsafe_dev_remove(struct rte_eth_dev *dev);
-int failsafe_eth_rmv_event_callback(uint8_t port_id,
+void failsafe_stats_increment(struct rte_eth_stats *to,
+ struct rte_eth_stats *from);
+int failsafe_eth_rmv_event_callback(uint16_t port_id,
enum rte_eth_event_type type,
void *arg, void *out);
+int failsafe_eth_lsc_event_callback(uint16_t port_id,
+ enum rte_eth_event_type event,
+ void *cb_arg, void *out);
/* GLOBALS */
* dev: (struct rte_eth_dev *), fail-safe ethdev
* state: (enum dev_state), minimum acceptable device state
*/
-#define FOREACH_SUBDEV_STATE(s, i, dev, state) \
- for (i = fs_find_next((dev), 0, state); \
- i < PRIV(dev)->subs_tail && (s = &PRIV(dev)->subs[i]); \
- i = fs_find_next((dev), i + 1, state))
+#define FOREACH_SUBDEV_STATE(s, i, dev, state) \
+ for (s = fs_find_next((dev), 0, state, &i); \
+ s != NULL; \
+ s = fs_find_next((dev), i + 1, state, &i))
/**
* Iterator construct over fail-safe sub-devices:
* a: (rte_atomic64_t)
*/
#define FS_ATOMIC_P(a) \
- rte_atomic64_add(&(a), 1)
+ rte_atomic64_set(&(a), 1)
/**
* a: (rte_atomic64_t)
*/
#define FS_ATOMIC_V(a) \
- rte_atomic64_sub(&(a), 1)
+ rte_atomic64_set(&(a), 0)
/**
* s: (struct sub_device *)
/* inlined functions */
-static inline uint8_t
-fs_find_next(struct rte_eth_dev *dev, uint8_t sid,
- enum dev_state min_state)
+static inline struct sub_device *
+fs_find_next(struct rte_eth_dev *dev,
+ uint8_t sid,
+ enum dev_state min_state,
+ uint8_t *sid_out)
{
- while (sid < PRIV(dev)->subs_tail) {
- if (PRIV(dev)->subs[sid].state >= min_state)
+ struct sub_device *subs;
+ uint8_t tail;
+
+ subs = PRIV(dev)->subs;
+ tail = PRIV(dev)->subs_tail;
+ while (sid < tail) {
+ if (subs[sid].state >= min_state)
break;
sid++;
}
- if (sid >= PRIV(dev)->subs_tail)
- return PRIV(dev)->subs_tail;
- return sid;
+ *sid_out = sid;
+ if (sid >= tail)
+ return NULL;
+ return &subs[sid];
}
/*
} else if ((txd && txd->state < req_state) ||
txd == NULL ||
txd == banned) {
- struct sub_device *sdev;
+ struct sub_device *sdev = NULL;
uint8_t i;
/* Using acceptable device */
PRIV(dev)->subs_tx = i;
break;
}
- } else if (txd && txd->state < req_state) {
- DEBUG("No device ready, deactivating tx_dev");
- PRIV(dev)->subs_tx = PRIV(dev)->subs_tail;
+ if (i >= PRIV(dev)->subs_tail || sdev == NULL) {
+ DEBUG("No device ready, deactivating tx_dev");
+ PRIV(dev)->subs_tx = PRIV(dev)->subs_tail;
+ }
} else {
return;
}
rte_wmb();
}
+/*
+ * Adjust error value and rte_errno to the fail-safe actual error value.
+ */
+static inline int
+fs_err(struct sub_device *sdev, int err)
+{
+ /* A device removal shouldn't be reported as an error. */
+ if (sdev->remove == 1 || err == -EIO)
+ return rte_errno = 0;
+ return err;
+}
#endif /* _RTE_ETH_FAILSAFE_PRIVATE_H_ */