]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/padata.h
stmmac: add init/exit callback in plat_stmmacenet_data struct
[net-next-2.6.git] / include / linux / padata.h
CommitLineData
16295bec
SK
1/*
2 * padata.h - header for the padata parallelization interface
3 *
4 * Copyright (C) 2008, 2009 secunet Security Networks AG
5 * Copyright (C) 2008, 2009 Steffen Klassert <steffen.klassert@secunet.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#ifndef PADATA_H
22#define PADATA_H
23
24#include <linux/workqueue.h>
25#include <linux/spinlock.h>
26#include <linux/list.h>
d46a5ac7 27#include <linux/timer.h>
e15bacbe 28#include <linux/notifier.h>
5e017dc3 29#include <linux/kobject.h>
e15bacbe
DK
30
31#define PADATA_CPU_SERIAL 0x01
32#define PADATA_CPU_PARALLEL 0x02
16295bec 33
0198ffd1
SK
34/**
35 * struct padata_priv - Embedded to the users data structure.
36 *
37 * @list: List entry, to attach to the padata lists.
38 * @pd: Pointer to the internal control structure.
39 * @cb_cpu: Callback cpu for serializatioon.
40 * @seq_nr: Sequence number of the parallelized data object.
41 * @info: Used to pass information from the parallel to the serial function.
42 * @parallel: Parallel execution function.
43 * @serial: Serial complete function.
44 */
16295bec
SK
45struct padata_priv {
46 struct list_head list;
47 struct parallel_data *pd;
48 int cb_cpu;
49 int seq_nr;
50 int info;
51 void (*parallel)(struct padata_priv *padata);
52 void (*serial)(struct padata_priv *padata);
53};
54
0198ffd1
SK
55/**
56 * struct padata_list
57 *
58 * @list: List head.
59 * @lock: List lock.
60 */
16295bec
SK
61struct padata_list {
62 struct list_head list;
63 spinlock_t lock;
64};
65
0198ffd1 66/**
e15bacbe
DK
67* struct padata_serial_queue - The percpu padata serial queue
68*
69* @serial: List to wait for serialization after reordering.
70* @work: work struct for serialization.
71* @pd: Backpointer to the internal control structure.
72*/
73struct padata_serial_queue {
74 struct padata_list serial;
75 struct work_struct work;
76 struct parallel_data *pd;
77};
78
79/**
80 * struct padata_parallel_queue - The percpu padata parallel queue
0198ffd1
SK
81 *
82 * @parallel: List to wait for parallelization.
83 * @reorder: List to wait for reordering after parallel processing.
84 * @serial: List to wait for serialization after reordering.
85 * @pwork: work struct for parallelization.
86 * @swork: work struct for serialization.
87 * @pd: Backpointer to the internal control structure.
e15bacbe
DK
88 * @work: work struct for parallelization.
89 * @num_obj: Number of objects that are processed by this cpu.
0198ffd1
SK
90 * @cpu_index: Index of the cpu.
91 */
e15bacbe
DK
92struct padata_parallel_queue {
93 struct padata_list parallel;
94 struct padata_list reorder;
95 struct parallel_data *pd;
96 struct work_struct work;
97 atomic_t num_obj;
98 int cpu_index;
16295bec
SK
99};
100
c635696c
SK
101/**
102 * struct padata_cpumask - The cpumasks for the parallel/serial workers
103 *
104 * @pcpu: cpumask for the parallel workers.
105 * @cbcpu: cpumask for the serial (callback) workers.
106 */
107struct padata_cpumask {
108 cpumask_var_t pcpu;
109 cpumask_var_t cbcpu;
110};
e15bacbe 111
0198ffd1
SK
112/**
113 * struct parallel_data - Internal control structure, covers everything
114 * that depends on the cpumask in use.
115 *
116 * @pinst: padata instance.
e15bacbe
DK
117 * @pqueue: percpu padata queues used for parallelization.
118 * @squeue: percpu padata queues used for serialuzation.
0198ffd1
SK
119 * @seq_nr: The sequence number that will be attached to the next object.
120 * @reorder_objects: Number of objects waiting in the reorder queues.
121 * @refcnt: Number of objects holding a reference on this parallel_data.
122 * @max_seq_nr: Maximal used sequence number.
c635696c 123 * @cpumask: The cpumasks in use for parallel and serial workers.
0198ffd1 124 * @lock: Reorder lock.
5f1a8c1b 125 * @processed: Number of already processed objects.
0198ffd1
SK
126 * @timer: Reorder timer.
127 */
16295bec 128struct parallel_data {
e15bacbe 129 struct padata_instance *pinst;
57a2ce5f
NK
130 struct padata_parallel_queue __percpu *pqueue;
131 struct padata_serial_queue __percpu *squeue;
c635696c
SK
132 atomic_t seq_nr;
133 atomic_t reorder_objects;
134 atomic_t refcnt;
135 unsigned int max_seq_nr;
136 struct padata_cpumask cpumask;
137 spinlock_t lock ____cacheline_aligned;
138 unsigned int processed;
139 struct timer_list timer;
16295bec
SK
140};
141
0198ffd1
SK
142/**
143 * struct padata_instance - The overall control structure.
144 *
145 * @cpu_notifier: cpu hotplug notifier.
146 * @wq: The workqueue in use.
147 * @pd: The internal control structure.
c635696c 148 * @cpumask: User supplied cpumasks for parallel and serial works.
e15bacbe
DK
149 * @cpumask_change_notifier: Notifiers chain for user-defined notify
150 * callbacks that will be called when either @pcpu or @cbcpu
5e017dc3
DK
151 * or both cpumasks change.
152 * @kobj: padata instance kernel object.
0198ffd1
SK
153 * @lock: padata instance lock.
154 * @flags: padata flags.
155 */
16295bec 156struct padata_instance {
e15bacbe
DK
157 struct notifier_block cpu_notifier;
158 struct workqueue_struct *wq;
159 struct parallel_data *pd;
c635696c 160 struct padata_cpumask cpumask;
e15bacbe 161 struct blocking_notifier_head cpumask_change_notifier;
5e017dc3 162 struct kobject kobj;
e15bacbe
DK
163 struct mutex lock;
164 u8 flags;
165#define PADATA_INIT 1
166#define PADATA_RESET 2
167#define PADATA_INVALID 4
16295bec
SK
168};
169
e6cc1170
SK
170extern struct padata_instance *padata_alloc_possible(
171 struct workqueue_struct *wq);
172extern struct padata_instance *padata_alloc(struct workqueue_struct *wq,
173 const struct cpumask *pcpumask,
174 const struct cpumask *cbcpumask);
16295bec
SK
175extern void padata_free(struct padata_instance *pinst);
176extern int padata_do_parallel(struct padata_instance *pinst,
177 struct padata_priv *padata, int cb_cpu);
178extern void padata_do_serial(struct padata_priv *padata);
e15bacbe 179extern int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
16295bec 180 cpumask_var_t cpumask);
65ff577e
SK
181extern int padata_set_cpumasks(struct padata_instance *pinst,
182 cpumask_var_t pcpumask,
183 cpumask_var_t cbcpumask);
e15bacbe
DK
184extern int padata_add_cpu(struct padata_instance *pinst, int cpu, int mask);
185extern int padata_remove_cpu(struct padata_instance *pinst, int cpu, int mask);
4c879170 186extern int padata_start(struct padata_instance *pinst);
16295bec 187extern void padata_stop(struct padata_instance *pinst);
e15bacbe
DK
188extern int padata_register_cpumask_notifier(struct padata_instance *pinst,
189 struct notifier_block *nblock);
190extern int padata_unregister_cpumask_notifier(struct padata_instance *pinst,
191 struct notifier_block *nblock);
16295bec 192#endif