freebsd_iflib: Merge changes from FreeBSD's master branch.

This commit is contained in:
Augustin Cavalier
2019-04-20 12:28:11 -04:00
parent 5012906434
commit e86136cf87
5 changed files with 541 additions and 419 deletions
@@ -68,6 +68,9 @@ typedef struct if_rxd_frag {
uint16_t irf_len; uint16_t irf_len;
} *if_rxd_frag_t; } *if_rxd_frag_t;
/* bnxt supports 64 with hardware LRO enabled */
#define IFLIB_MAX_RX_SEGS 64
typedef struct if_rxd_info { typedef struct if_rxd_info {
/* set by iflib */ /* set by iflib */
uint16_t iri_qsidx; /* qset index */ uint16_t iri_qsidx; /* qset index */
@@ -244,7 +247,7 @@ struct if_shared_ctx {
/* fields necessary for probe */ /* fields necessary for probe */
pci_vendor_info_t *isc_vendor_info; pci_vendor_info_t *isc_vendor_info;
char *isc_driver_version; const char *isc_driver_version;
/* optional function to transform the read values to match the table*/ /* optional function to transform the read values to match the table*/
void (*isc_parse_devinfo) (uint16_t *device_id, uint16_t *subvendor_id, void (*isc_parse_devinfo) (uint16_t *device_id, uint16_t *subvendor_id,
uint16_t *subdevice_id, uint16_t *rev_id); uint16_t *subdevice_id, uint16_t *rev_id);
@@ -377,6 +380,8 @@ void iflib_set_mac(if_ctx_t ctx, uint8_t mac[ETHER_ADDR_LEN]);
void iflib_request_reset(if_ctx_t ctx); void iflib_request_reset(if_ctx_t ctx);
uint8_t iflib_in_detach(if_ctx_t ctx); uint8_t iflib_in_detach(if_ctx_t ctx);
uint32_t iflib_get_rx_mbuf_sz(if_ctx_t ctx);
/* /*
* If the driver can plug cleanly in to newbus use these * If the driver can plug cleanly in to newbus use these
*/ */
@@ -427,6 +432,7 @@ void iflib_iov_intr_deferred(if_ctx_t ctx);
void iflib_link_state_change(if_ctx_t ctx, int linkstate, uint64_t baudrate); void iflib_link_state_change(if_ctx_t ctx, int linkstate, uint64_t baudrate);
int iflib_dma_alloc(if_ctx_t ctx, int size, iflib_dma_info_t dma, int mapflags); int iflib_dma_alloc(if_ctx_t ctx, int size, iflib_dma_info_t dma, int mapflags);
int iflib_dma_alloc_align(if_ctx_t ctx, int size, int align, iflib_dma_info_t dma, int mapflags);
void iflib_dma_free(iflib_dma_info_t dma); void iflib_dma_free(iflib_dma_info_t dma);
int iflib_dma_alloc_multi(if_ctx_t ctx, int *sizes, iflib_dma_info_t *dmalist, int mapflags, int count); int iflib_dma_alloc_multi(if_ctx_t ctx, int *sizes, iflib_dma_info_t *dmalist, int mapflags, int count);
@@ -22,16 +22,5 @@ struct gtask {
void *ta_context; /* (c) argument for handler */ void *ta_context; /* (c) argument for handler */
}; };
struct grouptask {
struct gtask gt_task;
void *gt_taskqueue;
LIST_ENTRY(grouptask) gt_list;
void *gt_uniq;
#define GROUPTASK_NAMELEN 32
char gt_name[GROUPTASK_NAMELEN];
int16_t gt_irq;
int16_t gt_cpu;
};
#endif #endif
@@ -31,21 +31,36 @@
#ifndef _SYS_GTASKQUEUE_H_ #ifndef _SYS_GTASKQUEUE_H_
#define _SYS_GTASKQUEUE_H_ #define _SYS_GTASKQUEUE_H_
#include <sys/taskqueue.h>
#ifndef _KERNEL #ifndef _KERNEL
#error "no user-serviceable parts inside" #error "no user-serviceable parts inside"
#endif #endif
#include <sys/_task.h>
#include <sys/bus.h>
#include <sys/taskqueue.h>
#include <sys/types.h>
struct gtaskqueue; struct gtaskqueue;
struct taskqgroup; struct taskqgroup;
typedef void (*gtaskqueue_enqueue_fn)(void *context);
/* /*
* Taskqueue groups. Manages dynamic thread groups and irq binding for * Taskqueue groups. Manages dynamic thread groups and irq binding for
* device and other tasks. * device and other tasks.
*/ */
struct grouptask {
struct gtask gt_task;
void *gt_taskqueue;
LIST_ENTRY(grouptask) gt_list;
void *gt_uniq;
#define GROUPTASK_NAMELEN 32
char gt_name[GROUPTASK_NAMELEN];
device_t gt_dev;
struct resource *gt_irq;
int gt_cpu;
};
void gtaskqueue_block(struct gtaskqueue *queue); void gtaskqueue_block(struct gtaskqueue *queue);
void gtaskqueue_unblock(struct gtaskqueue *queue); void gtaskqueue_unblock(struct gtaskqueue *queue);
@@ -56,28 +71,29 @@ void gtaskqueue_drain_all(struct gtaskqueue *queue);
void grouptask_block(struct grouptask *grouptask); void grouptask_block(struct grouptask *grouptask);
void grouptask_unblock(struct grouptask *grouptask); void grouptask_unblock(struct grouptask *grouptask);
int grouptaskqueue_enqueue(struct gtaskqueue *queue, struct gtask *task); int grouptaskqueue_enqueue(struct gtaskqueue *queue, struct gtask *task);
void taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *grptask, void taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *grptask,
void *uniq, int irq, const char *name); void *uniq, device_t dev, struct resource *irq, const char *name);
int taskqgroup_attach_cpu(struct taskqgroup *qgroup, struct grouptask *grptask, int taskqgroup_attach_cpu(struct taskqgroup *qgroup,
void *uniq, int cpu, int irq, const char *name); struct grouptask *grptask, void *uniq, int cpu, device_t dev,
struct resource *irq, const char *name);
void taskqgroup_detach(struct taskqgroup *qgroup, struct grouptask *gtask); void taskqgroup_detach(struct taskqgroup *qgroup, struct grouptask *gtask);
struct taskqgroup *taskqgroup_create(const char *name); struct taskqgroup *taskqgroup_create(const char *name);
void taskqgroup_destroy(struct taskqgroup *qgroup); void taskqgroup_destroy(struct taskqgroup *qgroup);
int taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride); int taskqgroup_adjust(struct taskqgroup *qgroup, int cnt, int stride);
void taskqgroup_config_gtask_init(void *ctx, struct grouptask *gtask, gtask_fn_t *fn, void taskqgroup_config_gtask_init(void *ctx, struct grouptask *gtask,
const char *name); gtask_fn_t *fn, const char *name);
void taskqgroup_config_gtask_deinit(struct grouptask *gtask); void taskqgroup_config_gtask_deinit(struct grouptask *gtask);
#define TASK_ENQUEUED 0x1 #define TASK_ENQUEUED 0x1
#define TASK_SKIP_WAKEUP 0x2 #define TASK_SKIP_WAKEUP 0x2
#define TASK_NOENQUEUE 0x4 #define TASK_NOENQUEUE 0x4
#define GTASK_INIT(gtask, flags, priority, func, context) do { \
#define GTASK_INIT(task, flags, priority, func, context) do { \ (gtask)->ta_flags = flags; \
(task)->ta_flags = flags; \ (gtask)->ta_priority = (priority); \
(task)->ta_priority = (priority); \ (gtask)->ta_func = (func); \
(task)->ta_func = (func); \ (gtask)->ta_context = (context); \
(task)->ta_context = (context); \
} while (0) } while (0)
#define GROUPTASK_INIT(gtask, priority, func, context) \ #define GROUPTASK_INIT(gtask, priority, func, context) \
File diff suppressed because it is too large Load Diff
+38 -62
View File
@@ -70,6 +70,8 @@ struct gtaskqueue_busy {
static struct gtask * const TB_DRAIN_WAITER = (struct gtask *)0x1; static struct gtask * const TB_DRAIN_WAITER = (struct gtask *)0x1;
typedef void (*gtaskqueue_enqueue_fn)(void *context);
struct gtaskqueue { struct gtaskqueue {
STAILQ_HEAD(, gtask) tq_queue; STAILQ_HEAD(, gtask) tq_queue;
gtaskqueue_enqueue_fn tq_enqueue; gtaskqueue_enqueue_fn tq_enqueue;
@@ -562,7 +564,6 @@ gtaskqueue_run_callback(struct gtaskqueue *tq,
tq_callback(tq->tq_cb_contexts[cb_type]); tq_callback(tq->tq_cb_contexts[cb_type]);
} }
static void static void
gtaskqueue_thread_loop(void *arg) gtaskqueue_thread_loop(void *arg)
{ {
@@ -717,7 +718,7 @@ taskqgroup_find(struct taskqgroup *qgroup, void *uniq)
} }
} }
if (idx == -1) if (idx == -1)
panic("taskqgroup_find: Failed to pick a qid."); panic("%s: failed to pick a qid.", __func__);
return (idx); return (idx);
} }
@@ -734,9 +735,9 @@ taskqgroup_find(struct taskqgroup *qgroup, void *uniq)
* adjustment is properly delayed. SI_ORDER_FOURTH is clearly before * adjustment is properly delayed. SI_ORDER_FOURTH is clearly before
* SI_ORDER_ANY and unclearly after the CPUs are started. It would be * SI_ORDER_ANY and unclearly after the CPUs are started. It would be
* simpler for adjustment to pass a flag indicating if it is delayed. * simpler for adjustment to pass a flag indicating if it is delayed.
*/ */
static int tqg_smp_started = 0; static int tqg_smp_started;
static void static void
tqg_record_smp_started(void *arg) tqg_record_smp_started(void *arg)
@@ -749,35 +750,28 @@ SYSINIT(tqg_record_smp_started, SI_SUB_SMP, SI_ORDER_FOURTH,
void void
taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *gtask, taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *gtask,
void *uniq, int irq, const char *name) void *uniq, device_t dev, struct resource *irq, const char *name)
{ {
#ifndef __HAIKU__ int cpu, qid, error;
cpuset_t mask;
#endif
int qid, error;
gtask->gt_uniq = uniq; gtask->gt_uniq = uniq;
snprintf(gtask->gt_name, GROUPTASK_NAMELEN, "%s", name ? name : "grouptask"); snprintf(gtask->gt_name, GROUPTASK_NAMELEN, "%s", name ? name : "grouptask");
gtask->gt_dev = dev;
gtask->gt_irq = irq; gtask->gt_irq = irq;
gtask->gt_cpu = -1; gtask->gt_cpu = -1;
mtx_lock(&qgroup->tqg_lock); mtx_lock(&qgroup->tqg_lock);
qid = taskqgroup_find(qgroup, uniq); qid = taskqgroup_find(qgroup, uniq);
qgroup->tqg_queue[qid].tgc_cnt++; qgroup->tqg_queue[qid].tgc_cnt++;
LIST_INSERT_HEAD(&qgroup->tqg_queue[qid].tgc_tasks, gtask, gt_list); LIST_INSERT_HEAD(&qgroup->tqg_queue[qid].tgc_tasks, gtask, gt_list);
MPASS(qgroup->tqg_queue[qid].tgc_taskq != NULL);
gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq; gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq;
if (irq != -1 && tqg_smp_started) { if (dev != NULL && irq != NULL && tqg_smp_started) {
gtask->gt_cpu = qgroup->tqg_queue[qid].tgc_cpu; cpu = qgroup->tqg_queue[qid].tgc_cpu;
#ifndef __HAIKU__ gtask->gt_cpu = cpu;
CPU_ZERO(&mask);
CPU_SET(qgroup->tqg_queue[qid].tgc_cpu, &mask);
#endif
mtx_unlock(&qgroup->tqg_lock); mtx_unlock(&qgroup->tqg_lock);
#ifndef __HAIKU__ error = bus_bind_intr(dev, irq, cpu);
error = intr_setaffinity(irq, CPU_WHICH_IRQ, &mask);
if (error) if (error)
printf("%s: setaffinity failed for %s: %d\n", __func__, gtask->gt_name, error); printf("%s: binding interrupt failed for %s: %d\n",
#endif __func__, gtask->gt_name, error);
} else } else
mtx_unlock(&qgroup->tqg_lock); mtx_unlock(&qgroup->tqg_lock);
} }
@@ -785,31 +779,22 @@ taskqgroup_attach(struct taskqgroup *qgroup, struct grouptask *gtask,
static void static void
taskqgroup_attach_deferred(struct taskqgroup *qgroup, struct grouptask *gtask) taskqgroup_attach_deferred(struct taskqgroup *qgroup, struct grouptask *gtask)
{ {
#ifndef __HAIKU__
cpuset_t mask;
#endif
int qid, cpu, error; int qid, cpu, error;
mtx_lock(&qgroup->tqg_lock); mtx_lock(&qgroup->tqg_lock);
qid = taskqgroup_find(qgroup, gtask->gt_uniq); qid = taskqgroup_find(qgroup, gtask->gt_uniq);
cpu = qgroup->tqg_queue[qid].tgc_cpu; cpu = qgroup->tqg_queue[qid].tgc_cpu;
#ifndef __HAIKU__ if (gtask->gt_dev != NULL && gtask->gt_irq != NULL) {
if (gtask->gt_irq != -1) {
mtx_unlock(&qgroup->tqg_lock); mtx_unlock(&qgroup->tqg_lock);
error = bus_bind_intr(gtask->gt_dev, gtask->gt_irq, cpu);
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
error = intr_setaffinity(gtask->gt_irq, CPU_WHICH_IRQ, &mask);
mtx_lock(&qgroup->tqg_lock); mtx_lock(&qgroup->tqg_lock);
if (error) if (error)
printf("%s: %s setaffinity failed: %d\n", __func__, gtask->gt_name, error); printf("%s: binding interrupt failed for %s: %d\n",
__func__, gtask->gt_name, error);
} }
#endif
qgroup->tqg_queue[qid].tgc_cnt++; qgroup->tqg_queue[qid].tgc_cnt++;
LIST_INSERT_HEAD(&qgroup->tqg_queue[qid].tgc_tasks, gtask, gt_list);
LIST_INSERT_HEAD(&qgroup->tqg_queue[qid].tgc_tasks, gtask,
gt_list);
MPASS(qgroup->tqg_queue[qid].tgc_taskq != NULL); MPASS(qgroup->tqg_queue[qid].tgc_taskq != NULL);
gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq; gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq;
mtx_unlock(&qgroup->tqg_lock); mtx_unlock(&qgroup->tqg_lock);
@@ -817,16 +802,14 @@ taskqgroup_attach_deferred(struct taskqgroup *qgroup, struct grouptask *gtask)
int int
taskqgroup_attach_cpu(struct taskqgroup *qgroup, struct grouptask *gtask, taskqgroup_attach_cpu(struct taskqgroup *qgroup, struct grouptask *gtask,
void *uniq, int cpu, int irq, const char *name) void *uniq, int cpu, device_t dev, struct resource *irq, const char *name)
{ {
#ifndef __HAIKU__
cpuset_t mask;
#endif
int i, qid, error; int i, qid, error;
qid = -1; qid = -1;
gtask->gt_uniq = uniq; gtask->gt_uniq = uniq;
snprintf(gtask->gt_name, GROUPTASK_NAMELEN, "%s", name ? name : "grouptask"); snprintf(gtask->gt_name, GROUPTASK_NAMELEN, "%s", name ? name : "grouptask");
gtask->gt_dev = dev;
gtask->gt_irq = irq; gtask->gt_irq = irq;
gtask->gt_cpu = cpu; gtask->gt_cpu = cpu;
mtx_lock(&qgroup->tqg_lock); mtx_lock(&qgroup->tqg_lock);
@@ -849,27 +832,24 @@ taskqgroup_attach_cpu(struct taskqgroup *qgroup, struct grouptask *gtask,
cpu = qgroup->tqg_queue[qid].tgc_cpu; cpu = qgroup->tqg_queue[qid].tgc_cpu;
mtx_unlock(&qgroup->tqg_lock); mtx_unlock(&qgroup->tqg_lock);
#ifndef __HAIKU__ if (dev != NULL && irq != NULL && tqg_smp_started) {
CPU_ZERO(&mask); error = bus_bind_intr(dev, irq, cpu);
CPU_SET(cpu, &mask);
if (irq != -1 && tqg_smp_started) {
error = intr_setaffinity(irq, CPU_WHICH_IRQ, &mask);
if (error) if (error)
printf("%s: setaffinity failed: %d\n", __func__, error); printf("%s: binding interrupt failed for %s: %d\n",
__func__, gtask->gt_name, error);
} }
#endif
return (0); return (0);
} }
static int static int
taskqgroup_attach_cpu_deferred(struct taskqgroup *qgroup, struct grouptask *gtask) taskqgroup_attach_cpu_deferred(struct taskqgroup *qgroup, struct grouptask *gtask)
{ {
#ifndef __HAIKU__ device_t dev;
cpuset_t mask; struct resource *irq;
#endif int cpu, error, i, qid;
int i, qid, irq, cpu, error;
qid = -1; qid = -1;
dev = gtask->gt_dev;
irq = gtask->gt_irq; irq = gtask->gt_irq;
cpu = gtask->gt_cpu; cpu = gtask->gt_cpu;
MPASS(tqg_smp_started); MPASS(tqg_smp_started);
@@ -890,16 +870,12 @@ taskqgroup_attach_cpu_deferred(struct taskqgroup *qgroup, struct grouptask *gtas
gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq; gtask->gt_taskqueue = qgroup->tqg_queue[qid].tgc_taskq;
mtx_unlock(&qgroup->tqg_lock); mtx_unlock(&qgroup->tqg_lock);
#ifndef __HAIKU__ if (dev != NULL && irq != NULL) {
CPU_ZERO(&mask); error = bus_bind_intr(dev, irq, cpu);
CPU_SET(cpu, &mask);
if (irq != -1) {
error = intr_setaffinity(irq, CPU_WHICH_IRQ, &mask);
if (error) if (error)
printf("%s: setaffinity failed: %d\n", __func__, error); printf("%s: binding interrupt failed for %s: %d\n",
__func__, gtask->gt_name, error);
} }
#endif
return (0); return (0);
} }
@@ -914,7 +890,7 @@ taskqgroup_detach(struct taskqgroup *qgroup, struct grouptask *gtask)
if (qgroup->tqg_queue[i].tgc_taskq == gtask->gt_taskqueue) if (qgroup->tqg_queue[i].tgc_taskq == gtask->gt_taskqueue)
break; break;
if (i == qgroup->tqg_cnt) if (i == qgroup->tqg_cnt)
panic("taskqgroup_detach: task %s not in group\n", gtask->gt_name); panic("%s: task %s not in group", __func__, gtask->gt_name);
qgroup->tqg_queue[i].tgc_cnt--; qgroup->tqg_queue[i].tgc_cnt--;
LIST_REMOVE(gtask, gt_list); LIST_REMOVE(gtask, gt_list);
mtx_unlock(&qgroup->tqg_lock); mtx_unlock(&qgroup->tqg_lock);
@@ -938,8 +914,7 @@ taskqgroup_binder(void *ctx)
thread_unlock(curthread); thread_unlock(curthread);
if (error) if (error)
printf("%s: setaffinity failed: %d\n", __func__, printf("%s: binding curthread failed: %d\n", __func__, error);
error);
#endif #endif
free(gtask, M_DEVBUF); free(gtask, M_DEVBUF);
} }
@@ -1108,15 +1083,16 @@ taskqgroup_destroy(struct taskqgroup *qgroup)
void void
taskqgroup_config_gtask_init(void *ctx, struct grouptask *gtask, gtask_fn_t *fn, taskqgroup_config_gtask_init(void *ctx, struct grouptask *gtask, gtask_fn_t *fn,
const char *name) const char *name)
{ {
GROUPTASK_INIT(gtask, 0, fn, ctx); GROUPTASK_INIT(gtask, 0, fn, ctx);
taskqgroup_attach(qgroup_config, gtask, gtask, -1, name); taskqgroup_attach(qgroup_config, gtask, gtask, NULL, NULL, name);
} }
void void
taskqgroup_config_gtask_deinit(struct grouptask *gtask) taskqgroup_config_gtask_deinit(struct grouptask *gtask)
{ {
taskqgroup_detach(qgroup_config, gtask); taskqgroup_detach(qgroup_config, gtask);
} }