2 * Linux for S/390 Lan Channel Station Network Driver
4 * Copyright IBM Corp. 1999, 2009
5 * Author(s): Original Code written by
6 * DJ Barrow <djbarrow@de.ibm.com,barrow_dj@yahoo.com>
8 * Frank Pavlic <fpavlic@de.ibm.com> and
9 * Martin Schwidefsky <schwidefsky@de.ibm.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define KMSG_COMPONENT "lcs"
27 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
29 #include <linux/module.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/fddidevice.h>
34 #include <linux/inetdevice.h>
36 #include <linux/igmp.h>
37 #include <linux/delay.h>
38 #include <linux/kthread.h>
39 #include <linux/slab.h>
43 #include <asm/debug.h>
44 #include <asm/idals.h>
45 #include <asm/timex.h>
46 #include <linux/device.h>
47 #include <asm/ccwgroup.h>
52 #if !defined(CONFIG_ETHERNET) && !defined(CONFIG_FDDI)
53 #error Cannot compile lcs.c without some net devices switched on.
57 * initialization string for output
60 static char version[] __initdata = "LCS driver";
63 * the root device for lcs group devices
65 static struct device *lcs_root_dev;
70 static void lcs_tasklet(unsigned long);
71 static void lcs_start_kernel_thread(struct work_struct *);
72 static void lcs_get_frames_cb(struct lcs_channel *, struct lcs_buffer *);
73 #ifdef CONFIG_IP_MULTICAST
74 static int lcs_send_delipm(struct lcs_card *, struct lcs_ipm_list *);
75 #endif /* CONFIG_IP_MULTICAST */
76 static int lcs_recovery(void *ptr);
79 * Debug Facility Stuff
81 static char debug_buffer[255];
82 static debug_info_t *lcs_dbf_setup;
83 static debug_info_t *lcs_dbf_trace;
86 * LCS Debug Facility functions
89 lcs_unregister_debug_facility(void)
91 debug_unregister(lcs_dbf_setup);
92 debug_unregister(lcs_dbf_trace);
96 lcs_register_debug_facility(void)
98 lcs_dbf_setup = debug_register("lcs_setup", 2, 1, 8);
99 lcs_dbf_trace = debug_register("lcs_trace", 4, 1, 8);
100 if (lcs_dbf_setup == NULL || lcs_dbf_trace == NULL) {
101 pr_err("Not enough memory for debug facility.\n");
102 lcs_unregister_debug_facility();
105 debug_register_view(lcs_dbf_setup, &debug_hex_ascii_view);
106 debug_set_level(lcs_dbf_setup, 2);
107 debug_register_view(lcs_dbf_trace, &debug_hex_ascii_view);
108 debug_set_level(lcs_dbf_trace, 2);
113 * Allocate io buffers.
116 lcs_alloc_channel(struct lcs_channel *channel)
120 LCS_DBF_TEXT(2, setup, "ichalloc");
121 for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
122 /* alloc memory fo iobuffer */
123 channel->iob[cnt].data =
124 kzalloc(LCS_IOBUFFERSIZE, GFP_DMA | GFP_KERNEL);
125 if (channel->iob[cnt].data == NULL)
127 channel->iob[cnt].state = LCS_BUF_STATE_EMPTY;
129 if (cnt < LCS_NUM_BUFFS) {
130 /* Not all io buffers could be allocated. */
131 LCS_DBF_TEXT(2, setup, "echalloc");
133 kfree(channel->iob[cnt].data);
143 lcs_free_channel(struct lcs_channel *channel)
147 LCS_DBF_TEXT(2, setup, "ichfree");
148 for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
149 kfree(channel->iob[cnt].data);
150 channel->iob[cnt].data = NULL;
158 lcs_cleanup_channel(struct lcs_channel *channel)
160 LCS_DBF_TEXT(3, setup, "cleanch");
161 /* Kill write channel tasklets. */
162 tasklet_kill(&channel->irq_tasklet);
163 /* Free channel buffers. */
164 lcs_free_channel(channel);
168 * LCS free memory for card and channels.
171 lcs_free_card(struct lcs_card *card)
173 LCS_DBF_TEXT(2, setup, "remcard");
174 LCS_DBF_HEX(2, setup, &card, sizeof(void*));
179 * LCS alloc memory for card and channels
181 static struct lcs_card *
184 struct lcs_card *card;
187 LCS_DBF_TEXT(2, setup, "alloclcs");
189 card = kzalloc(sizeof(struct lcs_card), GFP_KERNEL | GFP_DMA);
192 card->lan_type = LCS_FRAME_TYPE_AUTO;
194 card->lancmd_timeout = LCS_LANCMD_TIMEOUT_DEFAULT;
195 /* Allocate io buffers for the read channel. */
196 rc = lcs_alloc_channel(&card->read);
198 LCS_DBF_TEXT(2, setup, "iccwerr");
202 /* Allocate io buffers for the write channel. */
203 rc = lcs_alloc_channel(&card->write);
205 LCS_DBF_TEXT(2, setup, "iccwerr");
206 lcs_cleanup_channel(&card->read);
211 #ifdef CONFIG_IP_MULTICAST
212 INIT_LIST_HEAD(&card->ipm_list);
214 LCS_DBF_HEX(2, setup, &card, sizeof(void*));
219 * Setup read channel.
222 lcs_setup_read_ccws(struct lcs_card *card)
226 LCS_DBF_TEXT(2, setup, "ireadccw");
227 /* Setup read ccws. */
228 memset(card->read.ccws, 0, sizeof (struct ccw1) * (LCS_NUM_BUFFS + 1));
229 for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
230 card->read.ccws[cnt].cmd_code = LCS_CCW_READ;
231 card->read.ccws[cnt].count = LCS_IOBUFFERSIZE;
232 card->read.ccws[cnt].flags =
233 CCW_FLAG_CC | CCW_FLAG_SLI | CCW_FLAG_PCI;
235 * Note: we have allocated the buffer with GFP_DMA, so
236 * we do not need to do set_normalized_cda.
238 card->read.ccws[cnt].cda =
239 (__u32) __pa(card->read.iob[cnt].data);
240 ((struct lcs_header *)
241 card->read.iob[cnt].data)->offset = LCS_ILLEGAL_OFFSET;
242 card->read.iob[cnt].callback = lcs_get_frames_cb;
243 card->read.iob[cnt].state = LCS_BUF_STATE_READY;
244 card->read.iob[cnt].count = LCS_IOBUFFERSIZE;
246 card->read.ccws[0].flags &= ~CCW_FLAG_PCI;
247 card->read.ccws[LCS_NUM_BUFFS - 1].flags &= ~CCW_FLAG_PCI;
248 card->read.ccws[LCS_NUM_BUFFS - 1].flags |= CCW_FLAG_SUSPEND;
249 /* Last ccw is a tic (transfer in channel). */
250 card->read.ccws[LCS_NUM_BUFFS].cmd_code = LCS_CCW_TRANSFER;
251 card->read.ccws[LCS_NUM_BUFFS].cda =
252 (__u32) __pa(card->read.ccws);
253 /* Setg initial state of the read channel. */
254 card->read.state = LCS_CH_STATE_INIT;
256 card->read.io_idx = 0;
257 card->read.buf_idx = 0;
261 lcs_setup_read(struct lcs_card *card)
263 LCS_DBF_TEXT(3, setup, "initread");
265 lcs_setup_read_ccws(card);
266 /* Initialize read channel tasklet. */
267 card->read.irq_tasklet.data = (unsigned long) &card->read;
268 card->read.irq_tasklet.func = lcs_tasklet;
269 /* Initialize waitqueue. */
270 init_waitqueue_head(&card->read.wait_q);
274 * Setup write channel.
277 lcs_setup_write_ccws(struct lcs_card *card)
281 LCS_DBF_TEXT(3, setup, "iwritccw");
282 /* Setup write ccws. */
283 memset(card->write.ccws, 0, sizeof(struct ccw1) * (LCS_NUM_BUFFS + 1));
284 for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
285 card->write.ccws[cnt].cmd_code = LCS_CCW_WRITE;
286 card->write.ccws[cnt].count = 0;
287 card->write.ccws[cnt].flags =
288 CCW_FLAG_SUSPEND | CCW_FLAG_CC | CCW_FLAG_SLI;
290 * Note: we have allocated the buffer with GFP_DMA, so
291 * we do not need to do set_normalized_cda.
293 card->write.ccws[cnt].cda =
294 (__u32) __pa(card->write.iob[cnt].data);
296 /* Last ccw is a tic (transfer in channel). */
297 card->write.ccws[LCS_NUM_BUFFS].cmd_code = LCS_CCW_TRANSFER;
298 card->write.ccws[LCS_NUM_BUFFS].cda =
299 (__u32) __pa(card->write.ccws);
300 /* Set initial state of the write channel. */
301 card->read.state = LCS_CH_STATE_INIT;
303 card->write.io_idx = 0;
304 card->write.buf_idx = 0;
308 lcs_setup_write(struct lcs_card *card)
310 LCS_DBF_TEXT(3, setup, "initwrit");
312 lcs_setup_write_ccws(card);
313 /* Initialize write channel tasklet. */
314 card->write.irq_tasklet.data = (unsigned long) &card->write;
315 card->write.irq_tasklet.func = lcs_tasklet;
316 /* Initialize waitqueue. */
317 init_waitqueue_head(&card->write.wait_q);
321 lcs_set_allowed_threads(struct lcs_card *card, unsigned long threads)
325 spin_lock_irqsave(&card->mask_lock, flags);
326 card->thread_allowed_mask = threads;
327 spin_unlock_irqrestore(&card->mask_lock, flags);
328 wake_up(&card->wait_q);
330 static int lcs_threads_running(struct lcs_card *card, unsigned long threads)
335 spin_lock_irqsave(&card->mask_lock, flags);
336 rc = (card->thread_running_mask & threads);
337 spin_unlock_irqrestore(&card->mask_lock, flags);
342 lcs_wait_for_threads(struct lcs_card *card, unsigned long threads)
344 return wait_event_interruptible(card->wait_q,
345 lcs_threads_running(card, threads) == 0);
348 static int lcs_set_thread_start_bit(struct lcs_card *card, unsigned long thread)
352 spin_lock_irqsave(&card->mask_lock, flags);
353 if ( !(card->thread_allowed_mask & thread) ||
354 (card->thread_start_mask & thread) ) {
355 spin_unlock_irqrestore(&card->mask_lock, flags);
358 card->thread_start_mask |= thread;
359 spin_unlock_irqrestore(&card->mask_lock, flags);
364 lcs_clear_thread_running_bit(struct lcs_card *card, unsigned long thread)
368 spin_lock_irqsave(&card->mask_lock, flags);
369 card->thread_running_mask &= ~thread;
370 spin_unlock_irqrestore(&card->mask_lock, flags);
371 wake_up(&card->wait_q);
374 static int __lcs_do_run_thread(struct lcs_card *card, unsigned long thread)
379 spin_lock_irqsave(&card->mask_lock, flags);
380 if (card->thread_start_mask & thread){
381 if ((card->thread_allowed_mask & thread) &&
382 !(card->thread_running_mask & thread)){
384 card->thread_start_mask &= ~thread;
385 card->thread_running_mask |= thread;
389 spin_unlock_irqrestore(&card->mask_lock, flags);
394 lcs_do_run_thread(struct lcs_card *card, unsigned long thread)
397 wait_event(card->wait_q,
398 (rc = __lcs_do_run_thread(card, thread)) >= 0);
403 lcs_do_start_thread(struct lcs_card *card, unsigned long thread)
408 spin_lock_irqsave(&card->mask_lock, flags);
409 LCS_DBF_TEXT_(4, trace, " %02x%02x%02x",
410 (u8) card->thread_start_mask,
411 (u8) card->thread_allowed_mask,
412 (u8) card->thread_running_mask);
413 rc = (card->thread_start_mask & thread);
414 spin_unlock_irqrestore(&card->mask_lock, flags);
419 * Initialize channels,card and state machines.
422 lcs_setup_card(struct lcs_card *card)
424 LCS_DBF_TEXT(2, setup, "initcard");
425 LCS_DBF_HEX(2, setup, &card, sizeof(void*));
427 lcs_setup_read(card);
428 lcs_setup_write(card);
429 /* Set cards initial state. */
430 card->state = DEV_STATE_DOWN;
431 card->tx_buffer = NULL;
432 card->tx_emitted = 0;
434 init_waitqueue_head(&card->wait_q);
435 spin_lock_init(&card->lock);
436 spin_lock_init(&card->ipm_lock);
437 spin_lock_init(&card->mask_lock);
438 #ifdef CONFIG_IP_MULTICAST
439 INIT_LIST_HEAD(&card->ipm_list);
441 INIT_LIST_HEAD(&card->lancmd_waiters);
444 static void lcs_clear_multicast_list(struct lcs_card *card)
446 #ifdef CONFIG_IP_MULTICAST
447 struct lcs_ipm_list *ipm;
450 /* Free multicast list. */
451 LCS_DBF_TEXT(3, setup, "clmclist");
452 spin_lock_irqsave(&card->ipm_lock, flags);
453 while (!list_empty(&card->ipm_list)){
454 ipm = list_entry(card->ipm_list.next,
455 struct lcs_ipm_list, list);
456 list_del(&ipm->list);
457 if (ipm->ipm_state != LCS_IPM_STATE_SET_REQUIRED){
458 spin_unlock_irqrestore(&card->ipm_lock, flags);
459 lcs_send_delipm(card, ipm);
460 spin_lock_irqsave(&card->ipm_lock, flags);
464 spin_unlock_irqrestore(&card->ipm_lock, flags);
468 * Cleanup channels,card and state machines.
471 lcs_cleanup_card(struct lcs_card *card)
474 LCS_DBF_TEXT(3, setup, "cleancrd");
475 LCS_DBF_HEX(2,setup,&card,sizeof(void*));
477 if (card->dev != NULL)
478 free_netdev(card->dev);
479 /* Cleanup channels. */
480 lcs_cleanup_channel(&card->write);
481 lcs_cleanup_channel(&card->read);
488 lcs_start_channel(struct lcs_channel *channel)
493 LCS_DBF_TEXT_(4, trace,"ssch%s", dev_name(&channel->ccwdev->dev));
494 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
495 rc = ccw_device_start(channel->ccwdev,
496 channel->ccws + channel->io_idx, 0, 0,
497 DOIO_DENY_PREFETCH | DOIO_ALLOW_SUSPEND);
499 channel->state = LCS_CH_STATE_RUNNING;
500 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
502 LCS_DBF_TEXT_(4,trace,"essh%s",
503 dev_name(&channel->ccwdev->dev));
504 dev_err(&channel->ccwdev->dev,
505 "Starting an LCS device resulted in an error,"
512 lcs_clear_channel(struct lcs_channel *channel)
517 LCS_DBF_TEXT(4,trace,"clearch");
518 LCS_DBF_TEXT_(4, trace, "%s", dev_name(&channel->ccwdev->dev));
519 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
520 rc = ccw_device_clear(channel->ccwdev, (addr_t) channel);
521 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
523 LCS_DBF_TEXT_(4, trace, "ecsc%s",
524 dev_name(&channel->ccwdev->dev));
527 wait_event(channel->wait_q, (channel->state == LCS_CH_STATE_CLEARED));
528 channel->state = LCS_CH_STATE_STOPPED;
537 lcs_stop_channel(struct lcs_channel *channel)
542 if (channel->state == LCS_CH_STATE_STOPPED)
544 LCS_DBF_TEXT(4,trace,"haltsch");
545 LCS_DBF_TEXT_(4, trace, "%s", dev_name(&channel->ccwdev->dev));
546 channel->state = LCS_CH_STATE_INIT;
547 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
548 rc = ccw_device_halt(channel->ccwdev, (addr_t) channel);
549 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
551 LCS_DBF_TEXT_(4, trace, "ehsc%s",
552 dev_name(&channel->ccwdev->dev));
555 /* Asynchronous halt initialted. Wait for its completion. */
556 wait_event(channel->wait_q, (channel->state == LCS_CH_STATE_HALTED));
557 lcs_clear_channel(channel);
562 * start read and write channel
565 lcs_start_channels(struct lcs_card *card)
569 LCS_DBF_TEXT(2, trace, "chstart");
570 /* start read channel */
571 rc = lcs_start_channel(&card->read);
574 /* start write channel */
575 rc = lcs_start_channel(&card->write);
577 lcs_stop_channel(&card->read);
582 * stop read and write channel
585 lcs_stop_channels(struct lcs_card *card)
587 LCS_DBF_TEXT(2, trace, "chhalt");
588 lcs_stop_channel(&card->read);
589 lcs_stop_channel(&card->write);
596 static struct lcs_buffer *
597 __lcs_get_buffer(struct lcs_channel *channel)
601 LCS_DBF_TEXT(5, trace, "_getbuff");
602 index = channel->io_idx;
604 if (channel->iob[index].state == LCS_BUF_STATE_EMPTY) {
605 channel->iob[index].state = LCS_BUF_STATE_LOCKED;
606 return channel->iob + index;
608 index = (index + 1) & (LCS_NUM_BUFFS - 1);
609 } while (index != channel->io_idx);
613 static struct lcs_buffer *
614 lcs_get_buffer(struct lcs_channel *channel)
616 struct lcs_buffer *buffer;
619 LCS_DBF_TEXT(5, trace, "getbuff");
620 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
621 buffer = __lcs_get_buffer(channel);
622 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
627 * Resume channel program if the channel is suspended.
630 __lcs_resume_channel(struct lcs_channel *channel)
634 if (channel->state != LCS_CH_STATE_SUSPENDED)
636 if (channel->ccws[channel->io_idx].flags & CCW_FLAG_SUSPEND)
638 LCS_DBF_TEXT_(5, trace, "rsch%s", dev_name(&channel->ccwdev->dev));
639 rc = ccw_device_resume(channel->ccwdev);
641 LCS_DBF_TEXT_(4, trace, "ersc%s",
642 dev_name(&channel->ccwdev->dev));
643 dev_err(&channel->ccwdev->dev,
644 "Sending data from the LCS device to the LAN failed"
647 channel->state = LCS_CH_STATE_RUNNING;
653 * Make a buffer ready for processing.
655 static void __lcs_ready_buffer_bits(struct lcs_channel *channel, int index)
659 LCS_DBF_TEXT(5, trace, "rdybits");
660 prev = (index - 1) & (LCS_NUM_BUFFS - 1);
661 next = (index + 1) & (LCS_NUM_BUFFS - 1);
662 /* Check if we may clear the suspend bit of this buffer. */
663 if (channel->ccws[next].flags & CCW_FLAG_SUSPEND) {
664 /* Check if we have to set the PCI bit. */
665 if (!(channel->ccws[prev].flags & CCW_FLAG_SUSPEND))
666 /* Suspend bit of the previous buffer is not set. */
667 channel->ccws[index].flags |= CCW_FLAG_PCI;
668 /* Suspend bit of the next buffer is set. */
669 channel->ccws[index].flags &= ~CCW_FLAG_SUSPEND;
674 lcs_ready_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
679 LCS_DBF_TEXT(5, trace, "rdybuff");
680 BUG_ON(buffer->state != LCS_BUF_STATE_LOCKED &&
681 buffer->state != LCS_BUF_STATE_PROCESSED);
682 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
683 buffer->state = LCS_BUF_STATE_READY;
684 index = buffer - channel->iob;
686 channel->ccws[index].count = buffer->count;
687 /* Check relevant PCI/suspend bits. */
688 __lcs_ready_buffer_bits(channel, index);
689 rc = __lcs_resume_channel(channel);
690 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
695 * Mark the buffer as processed. Take care of the suspend bit
696 * of the previous buffer. This function is called from
697 * interrupt context, so the lock must not be taken.
700 __lcs_processed_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
702 int index, prev, next;
704 LCS_DBF_TEXT(5, trace, "prcsbuff");
705 BUG_ON(buffer->state != LCS_BUF_STATE_READY);
706 buffer->state = LCS_BUF_STATE_PROCESSED;
707 index = buffer - channel->iob;
708 prev = (index - 1) & (LCS_NUM_BUFFS - 1);
709 next = (index + 1) & (LCS_NUM_BUFFS - 1);
710 /* Set the suspend bit and clear the PCI bit of this buffer. */
711 channel->ccws[index].flags |= CCW_FLAG_SUSPEND;
712 channel->ccws[index].flags &= ~CCW_FLAG_PCI;
713 /* Check the suspend bit of the previous buffer. */
714 if (channel->iob[prev].state == LCS_BUF_STATE_READY) {
716 * Previous buffer is in state ready. It might have
717 * happened in lcs_ready_buffer that the suspend bit
718 * has not been cleared to avoid an endless loop.
721 __lcs_ready_buffer_bits(channel, prev);
723 /* Clear PCI bit of next buffer. */
724 channel->ccws[next].flags &= ~CCW_FLAG_PCI;
725 return __lcs_resume_channel(channel);
729 * Put a processed buffer back to state empty.
732 lcs_release_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
736 LCS_DBF_TEXT(5, trace, "relbuff");
737 BUG_ON(buffer->state != LCS_BUF_STATE_LOCKED &&
738 buffer->state != LCS_BUF_STATE_PROCESSED);
739 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
740 buffer->state = LCS_BUF_STATE_EMPTY;
741 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
745 * Get buffer for a lan command.
747 static struct lcs_buffer *
748 lcs_get_lancmd(struct lcs_card *card, int count)
750 struct lcs_buffer *buffer;
753 LCS_DBF_TEXT(4, trace, "getlncmd");
754 /* Get buffer and wait if none is available. */
755 wait_event(card->write.wait_q,
756 ((buffer = lcs_get_buffer(&card->write)) != NULL));
757 count += sizeof(struct lcs_header);
758 *(__u16 *)(buffer->data + count) = 0;
759 buffer->count = count + sizeof(__u16);
760 buffer->callback = lcs_release_buffer;
761 cmd = (struct lcs_cmd *) buffer->data;
763 cmd->type = LCS_FRAME_TYPE_CONTROL;
770 lcs_get_reply(struct lcs_reply *reply)
772 WARN_ON(atomic_read(&reply->refcnt) <= 0);
773 atomic_inc(&reply->refcnt);
777 lcs_put_reply(struct lcs_reply *reply)
779 WARN_ON(atomic_read(&reply->refcnt) <= 0);
780 if (atomic_dec_and_test(&reply->refcnt)) {
786 static struct lcs_reply *
787 lcs_alloc_reply(struct lcs_cmd *cmd)
789 struct lcs_reply *reply;
791 LCS_DBF_TEXT(4, trace, "getreply");
793 reply = kzalloc(sizeof(struct lcs_reply), GFP_ATOMIC);
796 atomic_set(&reply->refcnt,1);
797 reply->sequence_no = cmd->sequence_no;
800 init_waitqueue_head(&reply->wait_q);
806 * Notifier function for lancmd replies. Called from read irq.
809 lcs_notify_lancmd_waiters(struct lcs_card *card, struct lcs_cmd *cmd)
811 struct list_head *l, *n;
812 struct lcs_reply *reply;
814 LCS_DBF_TEXT(4, trace, "notiwait");
815 spin_lock(&card->lock);
816 list_for_each_safe(l, n, &card->lancmd_waiters) {
817 reply = list_entry(l, struct lcs_reply, list);
818 if (reply->sequence_no == cmd->sequence_no) {
819 lcs_get_reply(reply);
820 list_del_init(&reply->list);
821 if (reply->callback != NULL)
822 reply->callback(card, cmd);
824 reply->rc = cmd->return_code;
825 wake_up(&reply->wait_q);
826 lcs_put_reply(reply);
830 spin_unlock(&card->lock);
834 * Emit buffer of a lan command.
837 lcs_lancmd_timeout(unsigned long data)
839 struct lcs_reply *reply, *list_reply, *r;
842 LCS_DBF_TEXT(4, trace, "timeout");
843 reply = (struct lcs_reply *) data;
844 spin_lock_irqsave(&reply->card->lock, flags);
845 list_for_each_entry_safe(list_reply, r,
846 &reply->card->lancmd_waiters,list) {
847 if (reply == list_reply) {
848 lcs_get_reply(reply);
849 list_del_init(&reply->list);
850 spin_unlock_irqrestore(&reply->card->lock, flags);
853 wake_up(&reply->wait_q);
854 lcs_put_reply(reply);
858 spin_unlock_irqrestore(&reply->card->lock, flags);
862 lcs_send_lancmd(struct lcs_card *card, struct lcs_buffer *buffer,
863 void (*reply_callback)(struct lcs_card *, struct lcs_cmd *))
865 struct lcs_reply *reply;
867 struct timer_list timer;
871 LCS_DBF_TEXT(4, trace, "sendcmd");
872 cmd = (struct lcs_cmd *) buffer->data;
873 cmd->return_code = 0;
874 cmd->sequence_no = card->sequence_no++;
875 reply = lcs_alloc_reply(cmd);
878 reply->callback = reply_callback;
880 spin_lock_irqsave(&card->lock, flags);
881 list_add_tail(&reply->list, &card->lancmd_waiters);
882 spin_unlock_irqrestore(&card->lock, flags);
884 buffer->callback = lcs_release_buffer;
885 rc = lcs_ready_buffer(&card->write, buffer);
888 init_timer_on_stack(&timer);
889 timer.function = lcs_lancmd_timeout;
890 timer.data = (unsigned long) reply;
891 timer.expires = jiffies + HZ*card->lancmd_timeout;
893 wait_event(reply->wait_q, reply->received);
894 del_timer_sync(&timer);
895 destroy_timer_on_stack(&timer);
896 LCS_DBF_TEXT_(4, trace, "rc:%d",reply->rc);
898 lcs_put_reply(reply);
899 return rc ? -EIO : 0;
903 * LCS startup command
906 lcs_send_startup(struct lcs_card *card, __u8 initiator)
908 struct lcs_buffer *buffer;
911 LCS_DBF_TEXT(2, trace, "startup");
912 buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
913 cmd = (struct lcs_cmd *) buffer->data;
914 cmd->cmd_code = LCS_CMD_STARTUP;
915 cmd->initiator = initiator;
916 cmd->cmd.lcs_startup.buff_size = LCS_IOBUFFERSIZE;
917 return lcs_send_lancmd(card, buffer, NULL);
921 * LCS shutdown command
924 lcs_send_shutdown(struct lcs_card *card)
926 struct lcs_buffer *buffer;
929 LCS_DBF_TEXT(2, trace, "shutdown");
930 buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
931 cmd = (struct lcs_cmd *) buffer->data;
932 cmd->cmd_code = LCS_CMD_SHUTDOWN;
933 cmd->initiator = LCS_INITIATOR_TCPIP;
934 return lcs_send_lancmd(card, buffer, NULL);
938 * LCS lanstat command
941 __lcs_lanstat_cb(struct lcs_card *card, struct lcs_cmd *cmd)
943 LCS_DBF_TEXT(2, trace, "statcb");
944 memcpy(card->mac, cmd->cmd.lcs_lanstat_cmd.mac_addr, LCS_MAC_LENGTH);
948 lcs_send_lanstat(struct lcs_card *card)
950 struct lcs_buffer *buffer;
953 LCS_DBF_TEXT(2,trace, "cmdstat");
954 buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
955 cmd = (struct lcs_cmd *) buffer->data;
956 /* Setup lanstat command. */
957 cmd->cmd_code = LCS_CMD_LANSTAT;
958 cmd->initiator = LCS_INITIATOR_TCPIP;
959 cmd->cmd.lcs_std_cmd.lan_type = card->lan_type;
960 cmd->cmd.lcs_std_cmd.portno = card->portno;
961 return lcs_send_lancmd(card, buffer, __lcs_lanstat_cb);
965 * send stoplan command
968 lcs_send_stoplan(struct lcs_card *card, __u8 initiator)
970 struct lcs_buffer *buffer;
973 LCS_DBF_TEXT(2, trace, "cmdstpln");
974 buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
975 cmd = (struct lcs_cmd *) buffer->data;
976 cmd->cmd_code = LCS_CMD_STOPLAN;
977 cmd->initiator = initiator;
978 cmd->cmd.lcs_std_cmd.lan_type = card->lan_type;
979 cmd->cmd.lcs_std_cmd.portno = card->portno;
980 return lcs_send_lancmd(card, buffer, NULL);
984 * send startlan command
987 __lcs_send_startlan_cb(struct lcs_card *card, struct lcs_cmd *cmd)
989 LCS_DBF_TEXT(2, trace, "srtlancb");
990 card->lan_type = cmd->cmd.lcs_std_cmd.lan_type;
991 card->portno = cmd->cmd.lcs_std_cmd.portno;
995 lcs_send_startlan(struct lcs_card *card, __u8 initiator)
997 struct lcs_buffer *buffer;
1000 LCS_DBF_TEXT(2, trace, "cmdstaln");
1001 buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
1002 cmd = (struct lcs_cmd *) buffer->data;
1003 cmd->cmd_code = LCS_CMD_STARTLAN;
1004 cmd->initiator = initiator;
1005 cmd->cmd.lcs_std_cmd.lan_type = card->lan_type;
1006 cmd->cmd.lcs_std_cmd.portno = card->portno;
1007 return lcs_send_lancmd(card, buffer, __lcs_send_startlan_cb);
1010 #ifdef CONFIG_IP_MULTICAST
1012 * send setipm command (Multicast)
1015 lcs_send_setipm(struct lcs_card *card,struct lcs_ipm_list *ipm_list)
1017 struct lcs_buffer *buffer;
1018 struct lcs_cmd *cmd;
1020 LCS_DBF_TEXT(2, trace, "cmdsetim");
1021 buffer = lcs_get_lancmd(card, LCS_MULTICAST_CMD_SIZE);
1022 cmd = (struct lcs_cmd *) buffer->data;
1023 cmd->cmd_code = LCS_CMD_SETIPM;
1024 cmd->initiator = LCS_INITIATOR_TCPIP;
1025 cmd->cmd.lcs_qipassist.lan_type = card->lan_type;
1026 cmd->cmd.lcs_qipassist.portno = card->portno;
1027 cmd->cmd.lcs_qipassist.version = 4;
1028 cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
1029 memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair,
1030 &ipm_list->ipm, sizeof (struct lcs_ip_mac_pair));
1031 LCS_DBF_TEXT_(2, trace, "%x",ipm_list->ipm.ip_addr);
1032 return lcs_send_lancmd(card, buffer, NULL);
1036 * send delipm command (Multicast)
1039 lcs_send_delipm(struct lcs_card *card,struct lcs_ipm_list *ipm_list)
1041 struct lcs_buffer *buffer;
1042 struct lcs_cmd *cmd;
1044 LCS_DBF_TEXT(2, trace, "cmddelim");
1045 buffer = lcs_get_lancmd(card, LCS_MULTICAST_CMD_SIZE);
1046 cmd = (struct lcs_cmd *) buffer->data;
1047 cmd->cmd_code = LCS_CMD_DELIPM;
1048 cmd->initiator = LCS_INITIATOR_TCPIP;
1049 cmd->cmd.lcs_qipassist.lan_type = card->lan_type;
1050 cmd->cmd.lcs_qipassist.portno = card->portno;
1051 cmd->cmd.lcs_qipassist.version = 4;
1052 cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
1053 memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair,
1054 &ipm_list->ipm, sizeof (struct lcs_ip_mac_pair));
1055 LCS_DBF_TEXT_(2, trace, "%x",ipm_list->ipm.ip_addr);
1056 return lcs_send_lancmd(card, buffer, NULL);
1060 * check if multicast is supported by LCS
1063 __lcs_check_multicast_cb(struct lcs_card *card, struct lcs_cmd *cmd)
1065 LCS_DBF_TEXT(2, trace, "chkmccb");
1066 card->ip_assists_supported =
1067 cmd->cmd.lcs_qipassist.ip_assists_supported;
1068 card->ip_assists_enabled =
1069 cmd->cmd.lcs_qipassist.ip_assists_enabled;
1073 lcs_check_multicast_support(struct lcs_card *card)
1075 struct lcs_buffer *buffer;
1076 struct lcs_cmd *cmd;
1079 LCS_DBF_TEXT(2, trace, "cmdqipa");
1080 /* Send query ipassist. */
1081 buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE);
1082 cmd = (struct lcs_cmd *) buffer->data;
1083 cmd->cmd_code = LCS_CMD_QIPASSIST;
1084 cmd->initiator = LCS_INITIATOR_TCPIP;
1085 cmd->cmd.lcs_qipassist.lan_type = card->lan_type;
1086 cmd->cmd.lcs_qipassist.portno = card->portno;
1087 cmd->cmd.lcs_qipassist.version = 4;
1088 cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
1089 rc = lcs_send_lancmd(card, buffer, __lcs_check_multicast_cb);
1091 pr_err("Query IPAssist failed. Assuming unsupported!\n");
1094 if (card->ip_assists_supported & LCS_IPASS_MULTICAST_SUPPORT)
1100 * set or del multicast address on LCS card
1103 lcs_fix_multicast_list(struct lcs_card *card)
1105 struct list_head failed_list;
1106 struct lcs_ipm_list *ipm, *tmp;
1107 unsigned long flags;
1110 LCS_DBF_TEXT(4,trace, "fixipm");
1111 INIT_LIST_HEAD(&failed_list);
1112 spin_lock_irqsave(&card->ipm_lock, flags);
1114 list_for_each_entry_safe(ipm, tmp, &card->ipm_list, list){
1115 switch (ipm->ipm_state) {
1116 case LCS_IPM_STATE_SET_REQUIRED:
1117 /* del from ipm_list so no one else can tamper with
1119 list_del_init(&ipm->list);
1120 spin_unlock_irqrestore(&card->ipm_lock, flags);
1121 rc = lcs_send_setipm(card, ipm);
1122 spin_lock_irqsave(&card->ipm_lock, flags);
1124 pr_info("Adding multicast address failed."
1125 " Table possibly full!\n");
1126 /* store ipm in failed list -> will be added
1127 * to ipm_list again, so a retry will be done
1128 * during the next call of this function */
1129 list_add_tail(&ipm->list, &failed_list);
1131 ipm->ipm_state = LCS_IPM_STATE_ON_CARD;
1132 /* re-insert into ipm_list */
1133 list_add_tail(&ipm->list, &card->ipm_list);
1136 case LCS_IPM_STATE_DEL_REQUIRED:
1137 list_del(&ipm->list);
1138 spin_unlock_irqrestore(&card->ipm_lock, flags);
1139 lcs_send_delipm(card, ipm);
1140 spin_lock_irqsave(&card->ipm_lock, flags);
1143 case LCS_IPM_STATE_ON_CARD:
1147 /* re-insert all entries from the failed_list into ipm_list */
1148 list_for_each_entry_safe(ipm, tmp, &failed_list, list)
1149 list_move_tail(&ipm->list, &card->ipm_list);
1151 spin_unlock_irqrestore(&card->ipm_lock, flags);
1155 * get mac address for the relevant Multicast address
1158 lcs_get_mac_for_ipm(__be32 ipm, char *mac, struct net_device *dev)
1160 LCS_DBF_TEXT(4,trace, "getmac");
1161 ip_eth_mc_map(ipm, mac);
1165 * function called by net device to handle multicast address relevant things
1167 static void lcs_remove_mc_addresses(struct lcs_card *card,
1168 struct in_device *in4_dev)
1170 struct ip_mc_list *im4;
1171 struct list_head *l;
1172 struct lcs_ipm_list *ipm;
1173 unsigned long flags;
1174 char buf[MAX_ADDR_LEN];
1176 LCS_DBF_TEXT(4, trace, "remmclst");
1177 spin_lock_irqsave(&card->ipm_lock, flags);
1178 list_for_each(l, &card->ipm_list) {
1179 ipm = list_entry(l, struct lcs_ipm_list, list);
1180 for (im4 = rcu_dereference(in4_dev->mc_list);
1181 im4 != NULL; im4 = rcu_dereference(im4->next_rcu)) {
1182 lcs_get_mac_for_ipm(im4->multiaddr, buf, card->dev);
1183 if ( (ipm->ipm.ip_addr == im4->multiaddr) &&
1184 (memcmp(buf, &ipm->ipm.mac_addr,
1185 LCS_MAC_LENGTH) == 0) )
1189 ipm->ipm_state = LCS_IPM_STATE_DEL_REQUIRED;
1191 spin_unlock_irqrestore(&card->ipm_lock, flags);
1194 static struct lcs_ipm_list *lcs_check_addr_entry(struct lcs_card *card,
1195 struct ip_mc_list *im4,
1198 struct lcs_ipm_list *tmp, *ipm = NULL;
1199 struct list_head *l;
1200 unsigned long flags;
1202 LCS_DBF_TEXT(4, trace, "chkmcent");
1203 spin_lock_irqsave(&card->ipm_lock, flags);
1204 list_for_each(l, &card->ipm_list) {
1205 tmp = list_entry(l, struct lcs_ipm_list, list);
1206 if ( (tmp->ipm.ip_addr == im4->multiaddr) &&
1207 (memcmp(buf, &tmp->ipm.mac_addr,
1208 LCS_MAC_LENGTH) == 0) ) {
1213 spin_unlock_irqrestore(&card->ipm_lock, flags);
1217 static void lcs_set_mc_addresses(struct lcs_card *card,
1218 struct in_device *in4_dev)
1221 struct ip_mc_list *im4;
1222 struct lcs_ipm_list *ipm;
1223 char buf[MAX_ADDR_LEN];
1224 unsigned long flags;
1226 LCS_DBF_TEXT(4, trace, "setmclst");
1227 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
1228 im4 = rcu_dereference(im4->next_rcu)) {
1229 lcs_get_mac_for_ipm(im4->multiaddr, buf, card->dev);
1230 ipm = lcs_check_addr_entry(card, im4, buf);
1232 continue; /* Address already in list. */
1233 ipm = kzalloc(sizeof(struct lcs_ipm_list), GFP_ATOMIC);
1235 pr_info("Not enough memory to add"
1236 " new multicast entry!\n");
1239 memcpy(&ipm->ipm.mac_addr, buf, LCS_MAC_LENGTH);
1240 ipm->ipm.ip_addr = im4->multiaddr;
1241 ipm->ipm_state = LCS_IPM_STATE_SET_REQUIRED;
1242 spin_lock_irqsave(&card->ipm_lock, flags);
1243 LCS_DBF_HEX(2,trace,&ipm->ipm.ip_addr,4);
1244 list_add(&ipm->list, &card->ipm_list);
1245 spin_unlock_irqrestore(&card->ipm_lock, flags);
1250 lcs_register_mc_addresses(void *data)
1252 struct lcs_card *card;
1253 struct in_device *in4_dev;
1255 card = (struct lcs_card *) data;
1257 if (!lcs_do_run_thread(card, LCS_SET_MC_THREAD))
1259 LCS_DBF_TEXT(4, trace, "regmulti");
1261 in4_dev = in_dev_get(card->dev);
1262 if (in4_dev == NULL)
1265 lcs_remove_mc_addresses(card,in4_dev);
1266 lcs_set_mc_addresses(card, in4_dev);
1268 in_dev_put(in4_dev);
1270 netif_carrier_off(card->dev);
1271 netif_tx_disable(card->dev);
1272 wait_event(card->write.wait_q,
1273 (card->write.state != LCS_CH_STATE_RUNNING));
1274 lcs_fix_multicast_list(card);
1275 if (card->state == DEV_STATE_UP) {
1276 netif_carrier_on(card->dev);
1277 netif_wake_queue(card->dev);
1280 lcs_clear_thread_running_bit(card, LCS_SET_MC_THREAD);
1283 #endif /* CONFIG_IP_MULTICAST */
1286 * function called by net device to
1287 * handle multicast address relevant things
1290 lcs_set_multicast_list(struct net_device *dev)
1292 #ifdef CONFIG_IP_MULTICAST
1293 struct lcs_card *card;
1295 LCS_DBF_TEXT(4, trace, "setmulti");
1296 card = (struct lcs_card *) dev->ml_priv;
1298 if (!lcs_set_thread_start_bit(card, LCS_SET_MC_THREAD))
1299 schedule_work(&card->kernel_thread_starter);
1300 #endif /* CONFIG_IP_MULTICAST */
1304 lcs_check_irb_error(struct ccw_device *cdev, struct irb *irb)
1309 switch (PTR_ERR(irb)) {
1311 dev_warn(&cdev->dev,
1312 "An I/O-error occurred on the LCS device\n");
1313 LCS_DBF_TEXT(2, trace, "ckirberr");
1314 LCS_DBF_TEXT_(2, trace, " rc%d", -EIO);
1317 dev_warn(&cdev->dev,
1318 "A command timed out on the LCS device\n");
1319 LCS_DBF_TEXT(2, trace, "ckirberr");
1320 LCS_DBF_TEXT_(2, trace, " rc%d", -ETIMEDOUT);
1323 dev_warn(&cdev->dev,
1324 "An error occurred on the LCS device, rc=%ld\n",
1326 LCS_DBF_TEXT(2, trace, "ckirberr");
1327 LCS_DBF_TEXT(2, trace, " rc???");
1329 return PTR_ERR(irb);
1333 lcs_get_problem(struct ccw_device *cdev, struct irb *irb)
1338 sense = (char *) irb->ecw;
1339 cstat = irb->scsw.cmd.cstat;
1340 dstat = irb->scsw.cmd.dstat;
1342 if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
1343 SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
1344 SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) {
1345 LCS_DBF_TEXT(2, trace, "CGENCHK");
1348 if (dstat & DEV_STAT_UNIT_CHECK) {
1349 if (sense[LCS_SENSE_BYTE_1] &
1350 LCS_SENSE_RESETTING_EVENT) {
1351 LCS_DBF_TEXT(2, trace, "REVIND");
1354 if (sense[LCS_SENSE_BYTE_0] &
1355 LCS_SENSE_CMD_REJECT) {
1356 LCS_DBF_TEXT(2, trace, "CMDREJ");
1359 if ((!sense[LCS_SENSE_BYTE_0]) &&
1360 (!sense[LCS_SENSE_BYTE_1]) &&
1361 (!sense[LCS_SENSE_BYTE_2]) &&
1362 (!sense[LCS_SENSE_BYTE_3])) {
1363 LCS_DBF_TEXT(2, trace, "ZEROSEN");
1366 LCS_DBF_TEXT(2, trace, "DGENCHK");
1373 lcs_schedule_recovery(struct lcs_card *card)
1375 LCS_DBF_TEXT(2, trace, "startrec");
1376 if (!lcs_set_thread_start_bit(card, LCS_RECOVERY_THREAD))
1377 schedule_work(&card->kernel_thread_starter);
1381 * IRQ Handler for LCS channels
1384 lcs_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
1386 struct lcs_card *card;
1387 struct lcs_channel *channel;
1391 if (lcs_check_irb_error(cdev, irb))
1394 card = CARD_FROM_DEV(cdev);
1395 if (card->read.ccwdev == cdev)
1396 channel = &card->read;
1398 channel = &card->write;
1400 cstat = irb->scsw.cmd.cstat;
1401 dstat = irb->scsw.cmd.dstat;
1402 LCS_DBF_TEXT_(5, trace, "Rint%s", dev_name(&cdev->dev));
1403 LCS_DBF_TEXT_(5, trace, "%4x%4x", irb->scsw.cmd.cstat,
1404 irb->scsw.cmd.dstat);
1405 LCS_DBF_TEXT_(5, trace, "%4x%4x", irb->scsw.cmd.fctl,
1406 irb->scsw.cmd.actl);
1408 /* Check for channel and device errors presented */
1409 rc = lcs_get_problem(cdev, irb);
1410 if (rc || (dstat & DEV_STAT_UNIT_EXCEP)) {
1411 dev_warn(&cdev->dev,
1412 "The LCS device stopped because of an error,"
1413 " dstat=0x%X, cstat=0x%X \n",
1416 channel->state = LCS_CH_STATE_ERROR;
1419 if (channel->state == LCS_CH_STATE_ERROR) {
1420 lcs_schedule_recovery(card);
1421 wake_up(&card->wait_q);
1424 /* How far in the ccw chain have we processed? */
1425 if ((channel->state != LCS_CH_STATE_INIT) &&
1426 (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) &&
1427 (irb->scsw.cmd.cpa != 0)) {
1428 index = (struct ccw1 *) __va((addr_t) irb->scsw.cmd.cpa)
1430 if ((irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED) ||
1431 (irb->scsw.cmd.cstat & SCHN_STAT_PCI))
1432 /* Bloody io subsystem tells us lies about cpa... */
1433 index = (index - 1) & (LCS_NUM_BUFFS - 1);
1434 while (channel->io_idx != index) {
1435 __lcs_processed_buffer(channel,
1436 channel->iob + channel->io_idx);
1438 (channel->io_idx + 1) & (LCS_NUM_BUFFS - 1);
1442 if ((irb->scsw.cmd.dstat & DEV_STAT_DEV_END) ||
1443 (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) ||
1444 (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK))
1445 /* Mark channel as stopped. */
1446 channel->state = LCS_CH_STATE_STOPPED;
1447 else if (irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED)
1448 /* CCW execution stopped on a suspend bit. */
1449 channel->state = LCS_CH_STATE_SUSPENDED;
1450 if (irb->scsw.cmd.fctl & SCSW_FCTL_HALT_FUNC) {
1451 if (irb->scsw.cmd.cc != 0) {
1452 ccw_device_halt(channel->ccwdev, (addr_t) channel);
1455 /* The channel has been stopped by halt_IO. */
1456 channel->state = LCS_CH_STATE_HALTED;
1458 if (irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC)
1459 channel->state = LCS_CH_STATE_CLEARED;
1460 /* Do the rest in the tasklet. */
1461 tasklet_schedule(&channel->irq_tasklet);
1465 * Tasklet for IRQ handler
1468 lcs_tasklet(unsigned long data)
1470 unsigned long flags;
1471 struct lcs_channel *channel;
1472 struct lcs_buffer *iob;
1475 channel = (struct lcs_channel *) data;
1476 LCS_DBF_TEXT_(5, trace, "tlet%s", dev_name(&channel->ccwdev->dev));
1478 /* Check for processed buffers. */
1480 buf_idx = channel->buf_idx;
1481 while (iob[buf_idx].state == LCS_BUF_STATE_PROCESSED) {
1482 /* Do the callback thing. */
1483 if (iob[buf_idx].callback != NULL)
1484 iob[buf_idx].callback(channel, iob + buf_idx);
1485 buf_idx = (buf_idx + 1) & (LCS_NUM_BUFFS - 1);
1487 channel->buf_idx = buf_idx;
1489 if (channel->state == LCS_CH_STATE_STOPPED)
1490 lcs_start_channel(channel);
1491 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1492 if (channel->state == LCS_CH_STATE_SUSPENDED &&
1493 channel->iob[channel->io_idx].state == LCS_BUF_STATE_READY)
1494 __lcs_resume_channel(channel);
1495 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1497 /* Something happened on the channel. Wake up waiters. */
1498 wake_up(&channel->wait_q);
1502 * Finish current tx buffer and make it ready for transmit.
1505 __lcs_emit_txbuffer(struct lcs_card *card)
1507 LCS_DBF_TEXT(5, trace, "emittx");
1508 *(__u16 *)(card->tx_buffer->data + card->tx_buffer->count) = 0;
1509 card->tx_buffer->count += 2;
1510 lcs_ready_buffer(&card->write, card->tx_buffer);
1511 card->tx_buffer = NULL;
1516 * Callback for finished tx buffers.
1519 lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
1521 struct lcs_card *card;
1523 LCS_DBF_TEXT(5, trace, "txbuffcb");
1524 /* Put buffer back to pool. */
1525 lcs_release_buffer(channel, buffer);
1526 card = container_of(channel, struct lcs_card, write);
1527 if (netif_queue_stopped(card->dev) && netif_carrier_ok(card->dev))
1528 netif_wake_queue(card->dev);
1529 spin_lock(&card->lock);
1531 if (card->tx_emitted <= 0 && card->tx_buffer != NULL)
1533 * Last running tx buffer has finished. Submit partially
1534 * filled current buffer.
1536 __lcs_emit_txbuffer(card);
1537 spin_unlock(&card->lock);
1541 * Packet transmit function called by network stack
1543 static netdev_tx_t __lcs_start_xmit(struct lcs_card *card, struct sk_buff *skb,
1544 struct net_device *dev)
1546 struct lcs_header *header;
1547 int rc = NETDEV_TX_OK;
1549 LCS_DBF_TEXT(5, trace, "hardxmit");
1551 card->stats.tx_dropped++;
1552 card->stats.tx_errors++;
1553 return NETDEV_TX_OK;
1555 if (card->state != DEV_STATE_UP) {
1557 card->stats.tx_dropped++;
1558 card->stats.tx_errors++;
1559 card->stats.tx_carrier_errors++;
1560 return NETDEV_TX_OK;
1562 if (skb->protocol == htons(ETH_P_IPV6)) {
1564 return NETDEV_TX_OK;
1566 netif_stop_queue(card->dev);
1567 spin_lock(&card->lock);
1568 if (card->tx_buffer != NULL &&
1569 card->tx_buffer->count + sizeof(struct lcs_header) +
1570 skb->len + sizeof(u16) > LCS_IOBUFFERSIZE)
1571 /* skb too big for current tx buffer. */
1572 __lcs_emit_txbuffer(card);
1573 if (card->tx_buffer == NULL) {
1574 /* Get new tx buffer */
1575 card->tx_buffer = lcs_get_buffer(&card->write);
1576 if (card->tx_buffer == NULL) {
1577 card->stats.tx_dropped++;
1578 rc = NETDEV_TX_BUSY;
1581 card->tx_buffer->callback = lcs_txbuffer_cb;
1582 card->tx_buffer->count = 0;
1584 header = (struct lcs_header *)
1585 (card->tx_buffer->data + card->tx_buffer->count);
1586 card->tx_buffer->count += skb->len + sizeof(struct lcs_header);
1587 header->offset = card->tx_buffer->count;
1588 header->type = card->lan_type;
1589 header->slot = card->portno;
1590 skb_copy_from_linear_data(skb, header + 1, skb->len);
1591 spin_unlock(&card->lock);
1592 card->stats.tx_bytes += skb->len;
1593 card->stats.tx_packets++;
1595 netif_wake_queue(card->dev);
1596 spin_lock(&card->lock);
1597 if (card->tx_emitted <= 0 && card->tx_buffer != NULL)
1598 /* If this is the first tx buffer emit it immediately. */
1599 __lcs_emit_txbuffer(card);
1601 spin_unlock(&card->lock);
1605 static netdev_tx_t lcs_start_xmit(struct sk_buff *skb, struct net_device *dev)
1607 struct lcs_card *card;
1610 LCS_DBF_TEXT(5, trace, "pktxmit");
1611 card = (struct lcs_card *) dev->ml_priv;
1612 rc = __lcs_start_xmit(card, skb, dev);
1617 * send startlan and lanstat command to make LCS device ready
1620 lcs_startlan_auto(struct lcs_card *card)
1624 LCS_DBF_TEXT(2, trace, "strtauto");
1625 #ifdef CONFIG_ETHERNET
1626 card->lan_type = LCS_FRAME_TYPE_ENET;
1627 rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP);
1633 card->lan_type = LCS_FRAME_TYPE_FDDI;
1634 rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP);
1642 lcs_startlan(struct lcs_card *card)
1646 LCS_DBF_TEXT(2, trace, "startlan");
1648 if (card->portno != LCS_INVALID_PORT_NO) {
1649 if (card->lan_type == LCS_FRAME_TYPE_AUTO)
1650 rc = lcs_startlan_auto(card);
1652 rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP);
1654 for (i = 0; i <= 16; i++) {
1656 if (card->lan_type != LCS_FRAME_TYPE_AUTO)
1657 rc = lcs_send_startlan(card,
1658 LCS_INITIATOR_TCPIP);
1660 /* autodetecting lan type */
1661 rc = lcs_startlan_auto(card);
1667 return lcs_send_lanstat(card);
1672 * LCS detect function
1673 * setup channels and make them I/O ready
1676 lcs_detect(struct lcs_card *card)
1680 LCS_DBF_TEXT(2, setup, "lcsdetct");
1681 /* start/reset card */
1683 netif_stop_queue(card->dev);
1684 rc = lcs_stop_channels(card);
1686 rc = lcs_start_channels(card);
1688 rc = lcs_send_startup(card, LCS_INITIATOR_TCPIP);
1690 rc = lcs_startlan(card);
1694 card->state = DEV_STATE_UP;
1696 card->state = DEV_STATE_DOWN;
1697 card->write.state = LCS_CH_STATE_INIT;
1698 card->read.state = LCS_CH_STATE_INIT;
1707 lcs_stopcard(struct lcs_card *card)
1711 LCS_DBF_TEXT(3, setup, "stopcard");
1713 if (card->read.state != LCS_CH_STATE_STOPPED &&
1714 card->write.state != LCS_CH_STATE_STOPPED &&
1715 card->read.state != LCS_CH_STATE_ERROR &&
1716 card->write.state != LCS_CH_STATE_ERROR &&
1717 card->state == DEV_STATE_UP) {
1718 lcs_clear_multicast_list(card);
1719 rc = lcs_send_stoplan(card,LCS_INITIATOR_TCPIP);
1720 rc = lcs_send_shutdown(card);
1722 rc = lcs_stop_channels(card);
1723 card->state = DEV_STATE_DOWN;
1729 * Kernel Thread helper functions for LGW initiated commands
1732 lcs_start_kernel_thread(struct work_struct *work)
1734 struct lcs_card *card = container_of(work, struct lcs_card, kernel_thread_starter);
1735 LCS_DBF_TEXT(5, trace, "krnthrd");
1736 if (lcs_do_start_thread(card, LCS_RECOVERY_THREAD))
1737 kthread_run(lcs_recovery, card, "lcs_recover");
1738 #ifdef CONFIG_IP_MULTICAST
1739 if (lcs_do_start_thread(card, LCS_SET_MC_THREAD))
1740 kthread_run(lcs_register_mc_addresses, card, "regipm");
1745 * Process control frames.
1748 lcs_get_control(struct lcs_card *card, struct lcs_cmd *cmd)
1750 LCS_DBF_TEXT(5, trace, "getctrl");
1751 if (cmd->initiator == LCS_INITIATOR_LGW) {
1752 switch(cmd->cmd_code) {
1753 case LCS_CMD_STARTUP:
1754 case LCS_CMD_STARTLAN:
1755 lcs_schedule_recovery(card);
1757 case LCS_CMD_STOPLAN:
1759 pr_warn("Stoplan for %s initiated by LGW\n",
1761 netif_carrier_off(card->dev);
1765 LCS_DBF_TEXT(5, trace, "noLGWcmd");
1769 lcs_notify_lancmd_waiters(card, cmd);
1773 * Unpack network packet.
1776 lcs_get_skb(struct lcs_card *card, char *skb_data, unsigned int skb_len)
1778 struct sk_buff *skb;
1780 LCS_DBF_TEXT(5, trace, "getskb");
1781 if (card->dev == NULL ||
1782 card->state != DEV_STATE_UP)
1783 /* The card isn't up. Ignore the packet. */
1786 skb = dev_alloc_skb(skb_len);
1788 dev_err(&card->dev->dev,
1789 " Allocating a socket buffer to interface %s failed\n",
1791 card->stats.rx_dropped++;
1794 skb_put_data(skb, skb_data, skb_len);
1795 skb->protocol = card->lan_type_trans(skb, card->dev);
1796 card->stats.rx_bytes += skb_len;
1797 card->stats.rx_packets++;
1798 if (skb->protocol == htons(ETH_P_802_2))
1799 *((__u32 *)skb->cb) = ++card->pkt_seq;
1804 * LCS main routine to get packets and lancmd replies from the buffers
1807 lcs_get_frames_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
1809 struct lcs_card *card;
1810 struct lcs_header *lcs_hdr;
1813 LCS_DBF_TEXT(5, trace, "lcsgtpkt");
1814 lcs_hdr = (struct lcs_header *) buffer->data;
1815 if (lcs_hdr->offset == LCS_ILLEGAL_OFFSET) {
1816 LCS_DBF_TEXT(4, trace, "-eiogpkt");
1819 card = container_of(channel, struct lcs_card, read);
1821 while (lcs_hdr->offset != 0) {
1822 if (lcs_hdr->offset <= 0 ||
1823 lcs_hdr->offset > LCS_IOBUFFERSIZE ||
1824 lcs_hdr->offset < offset) {
1825 /* Offset invalid. */
1826 card->stats.rx_length_errors++;
1827 card->stats.rx_errors++;
1830 /* What kind of frame is it? */
1831 if (lcs_hdr->type == LCS_FRAME_TYPE_CONTROL)
1832 /* Control frame. */
1833 lcs_get_control(card, (struct lcs_cmd *) lcs_hdr);
1834 else if (lcs_hdr->type == LCS_FRAME_TYPE_ENET ||
1835 lcs_hdr->type == LCS_FRAME_TYPE_TR ||
1836 lcs_hdr->type == LCS_FRAME_TYPE_FDDI)
1837 /* Normal network packet. */
1838 lcs_get_skb(card, (char *)(lcs_hdr + 1),
1839 lcs_hdr->offset - offset -
1840 sizeof(struct lcs_header));
1842 /* Unknown frame type. */
1843 ; // FIXME: error message ?
1844 /* Proceed to next frame. */
1845 offset = lcs_hdr->offset;
1846 lcs_hdr->offset = LCS_ILLEGAL_OFFSET;
1847 lcs_hdr = (struct lcs_header *) (buffer->data + offset);
1849 /* The buffer is now empty. Make it ready again. */
1850 lcs_ready_buffer(&card->read, buffer);
1854 * get network statistics for ifconfig and other user programs
1856 static struct net_device_stats *
1857 lcs_getstats(struct net_device *dev)
1859 struct lcs_card *card;
1861 LCS_DBF_TEXT(4, trace, "netstats");
1862 card = (struct lcs_card *) dev->ml_priv;
1863 return &card->stats;
1868 * This function will be called by user doing ifconfig xxx down
1871 lcs_stop_device(struct net_device *dev)
1873 struct lcs_card *card;
1876 LCS_DBF_TEXT(2, trace, "stopdev");
1877 card = (struct lcs_card *) dev->ml_priv;
1878 netif_carrier_off(dev);
1879 netif_tx_disable(dev);
1880 dev->flags &= ~IFF_UP;
1881 wait_event(card->write.wait_q,
1882 (card->write.state != LCS_CH_STATE_RUNNING));
1883 rc = lcs_stopcard(card);
1885 dev_err(&card->dev->dev,
1886 " Shutting down the LCS device failed\n");
1891 * start lcs device and make it runnable
1892 * This function will be called by user doing ifconfig xxx up
1895 lcs_open_device(struct net_device *dev)
1897 struct lcs_card *card;
1900 LCS_DBF_TEXT(2, trace, "opendev");
1901 card = (struct lcs_card *) dev->ml_priv;
1902 /* initialize statistics */
1903 rc = lcs_detect(card);
1905 pr_err("Error in opening device!\n");
1908 dev->flags |= IFF_UP;
1909 netif_carrier_on(dev);
1910 netif_wake_queue(dev);
1911 card->state = DEV_STATE_UP;
1917 * show function for portno called by cat or similar things
1920 lcs_portno_show (struct device *dev, struct device_attribute *attr, char *buf)
1922 struct lcs_card *card;
1924 card = dev_get_drvdata(dev);
1929 return sprintf(buf, "%d\n", card->portno);
1933 * store the value which is piped to file portno
1936 lcs_portno_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1938 struct lcs_card *card;
1942 card = dev_get_drvdata(dev);
1947 rc = kstrtos16(buf, 0, &value);
1950 /* TODO: sanity checks */
1951 card->portno = value;
1957 static DEVICE_ATTR(portno, 0644, lcs_portno_show, lcs_portno_store);
1959 static const char *lcs_type[] = {
1964 "unknown channel type",
1965 "unsupported channel type",
1969 lcs_type_show(struct device *dev, struct device_attribute *attr, char *buf)
1971 struct ccwgroup_device *cgdev;
1973 cgdev = to_ccwgroupdev(dev);
1977 return sprintf(buf, "%s\n", lcs_type[cgdev->cdev[0]->id.driver_info]);
1980 static DEVICE_ATTR(type, 0444, lcs_type_show, NULL);
1983 lcs_timeout_show(struct device *dev, struct device_attribute *attr, char *buf)
1985 struct lcs_card *card;
1987 card = dev_get_drvdata(dev);
1989 return card ? sprintf(buf, "%u\n", card->lancmd_timeout) : 0;
1993 lcs_timeout_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1995 struct lcs_card *card;
1999 card = dev_get_drvdata(dev);
2004 rc = kstrtouint(buf, 0, &value);
2007 /* TODO: sanity checks */
2008 card->lancmd_timeout = value;
2014 static DEVICE_ATTR(lancmd_timeout, 0644, lcs_timeout_show, lcs_timeout_store);
2017 lcs_dev_recover_store(struct device *dev, struct device_attribute *attr,
2018 const char *buf, size_t count)
2020 struct lcs_card *card = dev_get_drvdata(dev);
2026 if (card->state != DEV_STATE_UP)
2028 i = simple_strtoul(buf, &tmp, 16);
2030 lcs_schedule_recovery(card);
2034 static DEVICE_ATTR(recover, 0200, NULL, lcs_dev_recover_store);
2036 static struct attribute * lcs_attrs[] = {
2037 &dev_attr_portno.attr,
2038 &dev_attr_type.attr,
2039 &dev_attr_lancmd_timeout.attr,
2040 &dev_attr_recover.attr,
2043 static struct attribute_group lcs_attr_group = {
2046 static const struct attribute_group *lcs_attr_groups[] = {
2050 static const struct device_type lcs_devtype = {
2052 .groups = lcs_attr_groups,
2056 * lcs_probe_device is called on establishing a new ccwgroup_device.
2059 lcs_probe_device(struct ccwgroup_device *ccwgdev)
2061 struct lcs_card *card;
2063 if (!get_device(&ccwgdev->dev))
2066 LCS_DBF_TEXT(2, setup, "add_dev");
2067 card = lcs_alloc_card();
2069 LCS_DBF_TEXT_(2, setup, " rc%d", -ENOMEM);
2070 put_device(&ccwgdev->dev);
2073 dev_set_drvdata(&ccwgdev->dev, card);
2074 ccwgdev->cdev[0]->handler = lcs_irq;
2075 ccwgdev->cdev[1]->handler = lcs_irq;
2076 card->gdev = ccwgdev;
2077 INIT_WORK(&card->kernel_thread_starter, lcs_start_kernel_thread);
2078 card->thread_start_mask = 0;
2079 card->thread_allowed_mask = 0;
2080 card->thread_running_mask = 0;
2081 ccwgdev->dev.type = &lcs_devtype;
2087 lcs_register_netdev(struct ccwgroup_device *ccwgdev)
2089 struct lcs_card *card;
2091 LCS_DBF_TEXT(2, setup, "regnetdv");
2092 card = dev_get_drvdata(&ccwgdev->dev);
2093 if (card->dev->reg_state != NETREG_UNINITIALIZED)
2095 SET_NETDEV_DEV(card->dev, &ccwgdev->dev);
2096 return register_netdev(card->dev);
2100 * lcs_new_device will be called by setting the group device online.
2102 static const struct net_device_ops lcs_netdev_ops = {
2103 .ndo_open = lcs_open_device,
2104 .ndo_stop = lcs_stop_device,
2105 .ndo_get_stats = lcs_getstats,
2106 .ndo_start_xmit = lcs_start_xmit,
2109 static const struct net_device_ops lcs_mc_netdev_ops = {
2110 .ndo_open = lcs_open_device,
2111 .ndo_stop = lcs_stop_device,
2112 .ndo_get_stats = lcs_getstats,
2113 .ndo_start_xmit = lcs_start_xmit,
2114 .ndo_set_rx_mode = lcs_set_multicast_list,
2118 lcs_new_device(struct ccwgroup_device *ccwgdev)
2120 struct lcs_card *card;
2121 struct net_device *dev=NULL;
2122 enum lcs_dev_states recover_state;
2125 card = dev_get_drvdata(&ccwgdev->dev);
2129 LCS_DBF_TEXT(2, setup, "newdev");
2130 LCS_DBF_HEX(3, setup, &card, sizeof(void*));
2131 card->read.ccwdev = ccwgdev->cdev[0];
2132 card->write.ccwdev = ccwgdev->cdev[1];
2134 recover_state = card->state;
2135 rc = ccw_device_set_online(card->read.ccwdev);
2138 rc = ccw_device_set_online(card->write.ccwdev);
2142 LCS_DBF_TEXT(3, setup, "lcsnewdv");
2144 lcs_setup_card(card);
2145 rc = lcs_detect(card);
2147 LCS_DBF_TEXT(2, setup, "dtctfail");
2148 dev_err(&ccwgdev->dev,
2149 "Detecting a network adapter for LCS devices"
2150 " failed with rc=%d (0x%x)\n", rc, rc);
2155 LCS_DBF_TEXT(2, setup, "samedev");
2156 LCS_DBF_HEX(3, setup, &card, sizeof(void*));
2159 switch (card->lan_type) {
2160 #ifdef CONFIG_ETHERNET
2161 case LCS_FRAME_TYPE_ENET:
2162 card->lan_type_trans = eth_type_trans;
2163 dev = alloc_etherdev(0);
2167 case LCS_FRAME_TYPE_FDDI:
2168 card->lan_type_trans = fddi_type_trans;
2169 dev = alloc_fddidev(0);
2173 LCS_DBF_TEXT(3, setup, "errinit");
2174 pr_err(" Initialization failed\n");
2180 card->dev->ml_priv = card;
2181 card->dev->netdev_ops = &lcs_netdev_ops;
2182 memcpy(card->dev->dev_addr, card->mac, LCS_MAC_LENGTH);
2183 #ifdef CONFIG_IP_MULTICAST
2184 if (!lcs_check_multicast_support(card))
2185 card->dev->netdev_ops = &lcs_mc_netdev_ops;
2188 lcs_set_allowed_threads(card,0xffffffff);
2189 if (recover_state == DEV_STATE_RECOVER) {
2190 lcs_set_multicast_list(card->dev);
2191 card->dev->flags |= IFF_UP;
2192 netif_carrier_on(card->dev);
2193 netif_wake_queue(card->dev);
2194 card->state = DEV_STATE_UP;
2199 if (lcs_register_netdev(ccwgdev) != 0)
2202 /* Print out supported assists: IPv6 */
2203 pr_info("LCS device %s %s IPv6 support\n", card->dev->name,
2204 (card->ip_assists_supported & LCS_IPASS_IPV6_SUPPORT) ?
2205 "with" : "without");
2206 /* Print out supported assist: Multicast */
2207 pr_info("LCS device %s %s Multicast support\n", card->dev->name,
2208 (card->ip_assists_supported & LCS_IPASS_MULTICAST_SUPPORT) ?
2209 "with" : "without");
2213 ccw_device_set_offline(card->write.ccwdev);
2215 ccw_device_set_offline(card->read.ccwdev);
2221 * lcs_shutdown_device, called when setting the group device offline.
2224 __lcs_shutdown_device(struct ccwgroup_device *ccwgdev, int recovery_mode)
2226 struct lcs_card *card;
2227 enum lcs_dev_states recover_state;
2228 int ret = 0, ret2 = 0, ret3 = 0;
2230 LCS_DBF_TEXT(3, setup, "shtdndev");
2231 card = dev_get_drvdata(&ccwgdev->dev);
2234 if (recovery_mode == 0) {
2235 lcs_set_allowed_threads(card, 0);
2236 if (lcs_wait_for_threads(card, LCS_SET_MC_THREAD))
2237 return -ERESTARTSYS;
2239 LCS_DBF_HEX(3, setup, &card, sizeof(void*));
2240 recover_state = card->state;
2242 ret = lcs_stop_device(card->dev);
2243 ret2 = ccw_device_set_offline(card->read.ccwdev);
2244 ret3 = ccw_device_set_offline(card->write.ccwdev);
2246 ret = (ret2) ? ret2 : ret3;
2248 LCS_DBF_TEXT_(3, setup, "1err:%d", ret);
2249 if (recover_state == DEV_STATE_UP) {
2250 card->state = DEV_STATE_RECOVER;
2256 lcs_shutdown_device(struct ccwgroup_device *ccwgdev)
2258 return __lcs_shutdown_device(ccwgdev, 0);
2262 * drive lcs recovery after startup and startlan initiated by Lan Gateway
2265 lcs_recovery(void *ptr)
2267 struct lcs_card *card;
2268 struct ccwgroup_device *gdev;
2271 card = (struct lcs_card *) ptr;
2273 LCS_DBF_TEXT(4, trace, "recover1");
2274 if (!lcs_do_run_thread(card, LCS_RECOVERY_THREAD))
2276 LCS_DBF_TEXT(4, trace, "recover2");
2278 dev_warn(&gdev->dev,
2279 "A recovery process has been started for the LCS device\n");
2280 rc = __lcs_shutdown_device(gdev, 1);
2281 rc = lcs_new_device(gdev);
2283 pr_info("Device %s successfully recovered!\n",
2286 pr_info("Device %s could not be recovered!\n",
2288 lcs_clear_thread_running_bit(card, LCS_RECOVERY_THREAD);
2293 * lcs_remove_device, free buffers and card
2296 lcs_remove_device(struct ccwgroup_device *ccwgdev)
2298 struct lcs_card *card;
2300 card = dev_get_drvdata(&ccwgdev->dev);
2304 LCS_DBF_TEXT(3, setup, "remdev");
2305 LCS_DBF_HEX(3, setup, &card, sizeof(void*));
2306 if (ccwgdev->state == CCWGROUP_ONLINE) {
2307 lcs_shutdown_device(ccwgdev);
2310 unregister_netdev(card->dev);
2311 lcs_cleanup_card(card);
2312 lcs_free_card(card);
2313 dev_set_drvdata(&ccwgdev->dev, NULL);
2314 put_device(&ccwgdev->dev);
2317 static int lcs_pm_suspend(struct lcs_card *card)
2320 netif_device_detach(card->dev);
2321 lcs_set_allowed_threads(card, 0);
2322 lcs_wait_for_threads(card, 0xffffffff);
2323 if (card->state != DEV_STATE_DOWN)
2324 __lcs_shutdown_device(card->gdev, 1);
2328 static int lcs_pm_resume(struct lcs_card *card)
2332 if (card->state == DEV_STATE_RECOVER)
2333 rc = lcs_new_device(card->gdev);
2335 netif_device_attach(card->dev);
2337 dev_warn(&card->gdev->dev, "The lcs device driver "
2338 "failed to recover the device\n");
2343 static int lcs_prepare(struct ccwgroup_device *gdev)
2348 static void lcs_complete(struct ccwgroup_device *gdev)
2353 static int lcs_freeze(struct ccwgroup_device *gdev)
2355 struct lcs_card *card = dev_get_drvdata(&gdev->dev);
2356 return lcs_pm_suspend(card);
2359 static int lcs_thaw(struct ccwgroup_device *gdev)
2361 struct lcs_card *card = dev_get_drvdata(&gdev->dev);
2362 return lcs_pm_resume(card);
2365 static int lcs_restore(struct ccwgroup_device *gdev)
2367 struct lcs_card *card = dev_get_drvdata(&gdev->dev);
2368 return lcs_pm_resume(card);
2371 static struct ccw_device_id lcs_ids[] = {
2372 {CCW_DEVICE(0x3088, 0x08), .driver_info = lcs_channel_type_parallel},
2373 {CCW_DEVICE(0x3088, 0x1f), .driver_info = lcs_channel_type_2216},
2374 {CCW_DEVICE(0x3088, 0x60), .driver_info = lcs_channel_type_osa2},
2377 MODULE_DEVICE_TABLE(ccw, lcs_ids);
2379 static struct ccw_driver lcs_ccw_driver = {
2381 .owner = THIS_MODULE,
2385 .probe = ccwgroup_probe_ccwdev,
2386 .remove = ccwgroup_remove_ccwdev,
2387 .int_class = IRQIO_LCS,
2391 * LCS ccwgroup driver registration
2393 static struct ccwgroup_driver lcs_group_driver = {
2395 .owner = THIS_MODULE,
2398 .setup = lcs_probe_device,
2399 .remove = lcs_remove_device,
2400 .set_online = lcs_new_device,
2401 .set_offline = lcs_shutdown_device,
2402 .prepare = lcs_prepare,
2403 .complete = lcs_complete,
2404 .freeze = lcs_freeze,
2406 .restore = lcs_restore,
2409 static ssize_t group_store(struct device_driver *ddrv, const char *buf,
2413 err = ccwgroup_create_dev(lcs_root_dev, &lcs_group_driver, 2, buf);
2414 return err ? err : count;
2416 static DRIVER_ATTR_WO(group);
2418 static struct attribute *lcs_drv_attrs[] = {
2419 &driver_attr_group.attr,
2422 static struct attribute_group lcs_drv_attr_group = {
2423 .attrs = lcs_drv_attrs,
2425 static const struct attribute_group *lcs_drv_attr_groups[] = {
2426 &lcs_drv_attr_group,
2431 * LCS Module/Kernel initialization function
2434 __init lcs_init_module(void)
2438 pr_info("Loading %s\n", version);
2439 rc = lcs_register_debug_facility();
2440 LCS_DBF_TEXT(0, setup, "lcsinit");
2443 lcs_root_dev = root_device_register("lcs");
2444 rc = PTR_ERR_OR_ZERO(lcs_root_dev);
2447 rc = ccw_driver_register(&lcs_ccw_driver);
2450 lcs_group_driver.driver.groups = lcs_drv_attr_groups;
2451 rc = ccwgroup_driver_register(&lcs_group_driver);
2457 ccw_driver_unregister(&lcs_ccw_driver);
2459 root_device_unregister(lcs_root_dev);
2461 lcs_unregister_debug_facility();
2463 pr_err("Initializing the lcs device driver failed\n");
2469 * LCS module cleanup function
2472 __exit lcs_cleanup_module(void)
2474 pr_info("Terminating lcs module.\n");
2475 LCS_DBF_TEXT(0, trace, "cleanup");
2476 ccwgroup_driver_unregister(&lcs_group_driver);
2477 ccw_driver_unregister(&lcs_ccw_driver);
2478 root_device_unregister(lcs_root_dev);
2479 lcs_unregister_debug_facility();
2482 module_init(lcs_init_module);
2483 module_exit(lcs_cleanup_module);
2485 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
2486 MODULE_LICENSE("GPL");