diff options
author | David Woodhouse <David.Woodhouse@intel.com> | 2009-01-27 00:20:04 -0500 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2009-01-27 00:20:04 -0500 |
commit | 01e2ffac7dbc0700c972eb38619870034a0b3418 (patch) | |
tree | 6a4fd81d4db8b5f375d21ce9c3153a8017846c12 /drivers/atm/solos-pci.c | |
parent | 316bea79369334d11f8a6e22317a928d94c50ae5 (diff) |
solos: Handle attribute show/store in kernel more sanely
There are still a _lot_ of attributes, but for at least the basic ones
we want to be able to get/set them from the kernel. Especially the ones
we want to inform the ATM core about (link state, speed).
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/atm/solos-pci.c')
-rw-r--r-- | drivers/atm/solos-pci.c | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c index 5179dbf9bd18..d9262a428dd6 100644 --- a/drivers/atm/solos-pci.c +++ b/drivers/atm/solos-pci.c | |||
@@ -38,6 +38,8 @@ | |||
38 | #include <linux/device.h> | 38 | #include <linux/device.h> |
39 | #include <linux/kobject.h> | 39 | #include <linux/kobject.h> |
40 | #include <linux/firmware.h> | 40 | #include <linux/firmware.h> |
41 | #include <linux/ctype.h> | ||
42 | #include <linux/swab.h> | ||
41 | 43 | ||
42 | #define VERSION "0.07" | 44 | #define VERSION "0.07" |
43 | #define PTAG "solos-pci" | 45 | #define PTAG "solos-pci" |
@@ -91,11 +93,23 @@ struct solos_card { | |||
91 | spinlock_t tx_lock; | 93 | spinlock_t tx_lock; |
92 | spinlock_t tx_queue_lock; | 94 | spinlock_t tx_queue_lock; |
93 | spinlock_t cli_queue_lock; | 95 | spinlock_t cli_queue_lock; |
96 | spinlock_t param_queue_lock; | ||
97 | struct list_head param_queue; | ||
94 | struct sk_buff_head tx_queue[4]; | 98 | struct sk_buff_head tx_queue[4]; |
95 | struct sk_buff_head cli_queue[4]; | 99 | struct sk_buff_head cli_queue[4]; |
100 | wait_queue_head_t param_wq; | ||
96 | wait_queue_head_t fw_wq; | 101 | wait_queue_head_t fw_wq; |
97 | }; | 102 | }; |
98 | 103 | ||
104 | |||
105 | struct solos_param { | ||
106 | struct list_head list; | ||
107 | pid_t pid; | ||
108 | int port; | ||
109 | struct sk_buff *response; | ||
110 | wait_queue_head_t wq; | ||
111 | }; | ||
112 | |||
99 | #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data) | 113 | #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data) |
100 | 114 | ||
101 | MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>"); | 115 | MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>"); |
@@ -131,6 +145,168 @@ static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb) | |||
131 | dev_kfree_skb_any(skb); | 145 | dev_kfree_skb_any(skb); |
132 | } | 146 | } |
133 | 147 | ||
148 | static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr, | ||
149 | char *buf) | ||
150 | { | ||
151 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); | ||
152 | struct solos_card *card = atmdev->dev_data; | ||
153 | struct solos_param prm; | ||
154 | struct sk_buff *skb; | ||
155 | struct pkt_hdr *header; | ||
156 | int buflen; | ||
157 | |||
158 | buflen = strlen(attr->attr.name) + 10; | ||
159 | |||
160 | skb = alloc_skb(buflen, GFP_KERNEL); | ||
161 | if (!skb) { | ||
162 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n"); | ||
163 | return -ENOMEM; | ||
164 | } | ||
165 | |||
166 | header = (void *)skb_put(skb, sizeof(*header)); | ||
167 | |||
168 | buflen = snprintf((void *)&header[1], buflen - 1, | ||
169 | "L%05d\n%s\n", current->pid, attr->attr.name); | ||
170 | skb_put(skb, buflen); | ||
171 | |||
172 | header->size = cpu_to_le16(buflen); | ||
173 | header->vpi = cpu_to_le16(0); | ||
174 | header->vci = cpu_to_le16(0); | ||
175 | header->type = cpu_to_le16(PKT_COMMAND); | ||
176 | |||
177 | prm.pid = current->pid; | ||
178 | prm.response = NULL; | ||
179 | prm.port = SOLOS_CHAN(atmdev); | ||
180 | |||
181 | spin_lock_irq(&card->param_queue_lock); | ||
182 | list_add(&prm.list, &card->param_queue); | ||
183 | spin_unlock_irq(&card->param_queue_lock); | ||
184 | |||
185 | fpga_queue(card, prm.port, skb, NULL); | ||
186 | |||
187 | wait_event_timeout(card->param_wq, prm.response, 5 * HZ); | ||
188 | |||
189 | spin_lock_irq(&card->param_queue_lock); | ||
190 | list_del(&prm.list); | ||
191 | spin_unlock_irq(&card->param_queue_lock); | ||
192 | |||
193 | if (!prm.response) | ||
194 | return -EIO; | ||
195 | |||
196 | buflen = prm.response->len; | ||
197 | memcpy(buf, prm.response->data, buflen); | ||
198 | kfree_skb(prm.response); | ||
199 | |||
200 | return buflen; | ||
201 | } | ||
202 | |||
203 | static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr, | ||
204 | const char *buf, size_t count) | ||
205 | { | ||
206 | struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); | ||
207 | struct solos_card *card = atmdev->dev_data; | ||
208 | struct solos_param prm; | ||
209 | struct sk_buff *skb; | ||
210 | struct pkt_hdr *header; | ||
211 | int buflen; | ||
212 | ssize_t ret; | ||
213 | |||
214 | buflen = strlen(attr->attr.name) + 11 + count; | ||
215 | |||
216 | skb = alloc_skb(buflen, GFP_KERNEL); | ||
217 | if (!skb) { | ||
218 | dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n"); | ||
219 | return -ENOMEM; | ||
220 | } | ||
221 | |||
222 | header = (void *)skb_put(skb, sizeof(*header)); | ||
223 | |||
224 | buflen = snprintf((void *)&header[1], buflen - 1, | ||
225 | "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf); | ||
226 | |||
227 | skb_put(skb, buflen); | ||
228 | header->size = cpu_to_le16(buflen); | ||
229 | header->vpi = cpu_to_le16(0); | ||
230 | header->vci = cpu_to_le16(0); | ||
231 | header->type = cpu_to_le16(PKT_COMMAND); | ||
232 | |||
233 | prm.pid = current->pid; | ||
234 | prm.response = NULL; | ||
235 | prm.port = SOLOS_CHAN(atmdev); | ||
236 | |||
237 | spin_lock_irq(&card->param_queue_lock); | ||
238 | list_add(&prm.list, &card->param_queue); | ||
239 | spin_unlock_irq(&card->param_queue_lock); | ||
240 | |||
241 | fpga_queue(card, prm.port, skb, NULL); | ||
242 | |||
243 | wait_event_timeout(card->param_wq, prm.response, 5 * HZ); | ||
244 | |||
245 | spin_lock_irq(&card->param_queue_lock); | ||
246 | list_del(&prm.list); | ||
247 | spin_unlock_irq(&card->param_queue_lock); | ||
248 | |||
249 | skb = prm.response; | ||
250 | |||
251 | if (!skb) | ||
252 | return -EIO; | ||
253 | |||
254 | buflen = skb->len; | ||
255 | |||
256 | /* Sometimes it has a newline, sometimes it doesn't. */ | ||
257 | if (skb->data[buflen - 1] == '\n') | ||
258 | buflen--; | ||
259 | |||
260 | if (buflen == 2 && !strncmp(skb->data, "OK", 2)) | ||
261 | ret = count; | ||
262 | else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5)) | ||
263 | ret = -EIO; | ||
264 | else { | ||
265 | /* We know we have enough space allocated for this; we allocated | ||
266 | it ourselves */ | ||
267 | skb->data[buflen] = 0; | ||
268 | |||
269 | dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n", | ||
270 | skb->data); | ||
271 | ret = -EIO; | ||
272 | } | ||
273 | kfree_skb(skb); | ||
274 | |||
275 | return ret; | ||
276 | } | ||
277 | |||
278 | static int process_command(struct solos_card *card, int port, struct sk_buff *skb) | ||
279 | { | ||
280 | struct solos_param *prm; | ||
281 | unsigned long flags; | ||
282 | int cmdpid; | ||
283 | int found = 0; | ||
284 | |||
285 | if (skb->len < 7) | ||
286 | return 0; | ||
287 | |||
288 | if (skb->data[0] != 'L' || !isdigit(skb->data[1]) || | ||
289 | !isdigit(skb->data[2]) || !isdigit(skb->data[3]) || | ||
290 | !isdigit(skb->data[4]) || !isdigit(skb->data[5]) || | ||
291 | skb->data[6] != '\n') | ||
292 | return 0; | ||
293 | |||
294 | cmdpid = simple_strtol(&skb->data[1], NULL, 10); | ||
295 | |||
296 | spin_lock_irqsave(&card->param_queue_lock, flags); | ||
297 | list_for_each_entry(prm, &card->param_queue, list) { | ||
298 | if (prm->port == port && prm->pid == cmdpid) { | ||
299 | prm->response = skb; | ||
300 | skb_pull(skb, 7); | ||
301 | wake_up(&card->param_wq); | ||
302 | found = 1; | ||
303 | break; | ||
304 | } | ||
305 | } | ||
306 | spin_unlock_irqrestore(&card->param_queue_lock, flags); | ||
307 | return found; | ||
308 | } | ||
309 | |||
134 | static ssize_t console_show(struct device *dev, struct device_attribute *attr, | 310 | static ssize_t console_show(struct device *dev, struct device_attribute *attr, |
135 | char *buf) | 311 | char *buf) |
136 | { | 312 | { |
@@ -195,6 +371,8 @@ static ssize_t console_store(struct device *dev, struct device_attribute *attr, | |||
195 | } | 371 | } |
196 | 372 | ||
197 | static DEVICE_ATTR(console, 0644, console_show, console_store); | 373 | static DEVICE_ATTR(console, 0644, console_show, console_store); |
374 | static DEVICE_ATTR(OperationalMode, 0444, solos_param_show, NULL); | ||
375 | static DEVICE_ATTR(AutoStart, 0644, solos_param_show, solos_param_store); | ||
198 | 376 | ||
199 | static int flash_upgrade(struct solos_card *card, int chip) | 377 | static int flash_upgrade(struct solos_card *card, int chip) |
200 | { | 378 | { |
@@ -351,6 +529,8 @@ void solos_bh(unsigned long card_arg) | |||
351 | 529 | ||
352 | case PKT_COMMAND: | 530 | case PKT_COMMAND: |
353 | default: /* FIXME: Not really, surely? */ | 531 | default: /* FIXME: Not really, surely? */ |
532 | if (process_command(card, port, skb)) | ||
533 | break; | ||
354 | spin_lock(&card->cli_queue_lock); | 534 | spin_lock(&card->cli_queue_lock); |
355 | if (skb_queue_len(&card->cli_queue[port]) > 10) { | 535 | if (skb_queue_len(&card->cli_queue[port]) > 10) { |
356 | if (net_ratelimit()) | 536 | if (net_ratelimit()) |
@@ -671,6 +851,7 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
671 | 851 | ||
672 | card->dev = dev; | 852 | card->dev = dev; |
673 | init_waitqueue_head(&card->fw_wq); | 853 | init_waitqueue_head(&card->fw_wq); |
854 | init_waitqueue_head(&card->param_wq); | ||
674 | 855 | ||
675 | err = pci_enable_device(dev); | 856 | err = pci_enable_device(dev); |
676 | if (err) { | 857 | if (err) { |
@@ -722,6 +903,8 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
722 | spin_lock_init(&card->tx_lock); | 903 | spin_lock_init(&card->tx_lock); |
723 | spin_lock_init(&card->tx_queue_lock); | 904 | spin_lock_init(&card->tx_queue_lock); |
724 | spin_lock_init(&card->cli_queue_lock); | 905 | spin_lock_init(&card->cli_queue_lock); |
906 | spin_lock_init(&card->param_queue_lock); | ||
907 | INIT_LIST_HEAD(&card->param_queue); | ||
725 | 908 | ||
726 | /* | 909 | /* |
727 | // Set Loopback mode | 910 | // Set Loopback mode |
@@ -804,6 +987,10 @@ static int atm_init(struct solos_card *card) | |||
804 | } | 987 | } |
805 | if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console)) | 988 | if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console)) |
806 | dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i); | 989 | dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i); |
990 | if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_OperationalMode)) | ||
991 | dev_err(&card->dev->dev, "Could not register opmode attr for ATM device %d\n", i); | ||
992 | if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_AutoStart)) | ||
993 | dev_err(&card->dev->dev, "Could not register autostart attr for ATM device %d\n", i); | ||
807 | 994 | ||
808 | dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number); | 995 | dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number); |
809 | 996 | ||