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/trdevice.h>
34 #include <linux/fddidevice.h>
35 #include <linux/inetdevice.h>
37 #include <linux/igmp.h>
38 #include <linux/delay.h>
39 #include <linux/kthread.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>
53 #if !defined(CONFIG_NET_ETHERNET) && \
54 !defined(CONFIG_TR) && !defined(CONFIG_FDDI)
55 #error Cannot compile lcs.c without some net devices switched on.
59 * initialization string for output
62 static char version
[] __initdata
= "LCS driver";
63 static char debug_buffer
[255];
68 static void lcs_tasklet(unsigned long);
69 static void lcs_start_kernel_thread(struct work_struct
*);
70 static void lcs_get_frames_cb(struct lcs_channel
*, struct lcs_buffer
*);
71 #ifdef CONFIG_IP_MULTICAST
72 static int lcs_send_delipm(struct lcs_card
*, struct lcs_ipm_list
*);
73 #endif /* CONFIG_IP_MULTICAST */
74 static int lcs_recovery(void *ptr
);
77 * Debug Facility Stuff
79 static debug_info_t
*lcs_dbf_setup
;
80 static debug_info_t
*lcs_dbf_trace
;
83 * LCS Debug Facility functions
86 lcs_unregister_debug_facility(void)
89 debug_unregister(lcs_dbf_setup
);
91 debug_unregister(lcs_dbf_trace
);
95 lcs_register_debug_facility(void)
97 lcs_dbf_setup
= debug_register("lcs_setup", 2, 1, 8);
98 lcs_dbf_trace
= debug_register("lcs_trace", 4, 1, 8);
99 if (lcs_dbf_setup
== NULL
|| lcs_dbf_trace
== NULL
) {
100 pr_err("Not enough memory for debug facility.\n");
101 lcs_unregister_debug_facility();
104 debug_register_view(lcs_dbf_setup
, &debug_hex_ascii_view
);
105 debug_set_level(lcs_dbf_setup
, 2);
106 debug_register_view(lcs_dbf_trace
, &debug_hex_ascii_view
);
107 debug_set_level(lcs_dbf_trace
, 2);
112 * Allocate io buffers.
115 lcs_alloc_channel(struct lcs_channel
*channel
)
119 LCS_DBF_TEXT(2, setup
, "ichalloc");
120 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
121 /* alloc memory fo iobuffer */
122 channel
->iob
[cnt
].data
=
123 kzalloc(LCS_IOBUFFERSIZE
, GFP_DMA
| GFP_KERNEL
);
124 if (channel
->iob
[cnt
].data
== NULL
)
126 channel
->iob
[cnt
].state
= LCS_BUF_STATE_EMPTY
;
128 if (cnt
< LCS_NUM_BUFFS
) {
129 /* Not all io buffers could be allocated. */
130 LCS_DBF_TEXT(2, setup
, "echalloc");
132 kfree(channel
->iob
[cnt
].data
);
142 lcs_free_channel(struct lcs_channel
*channel
)
146 LCS_DBF_TEXT(2, setup
, "ichfree");
147 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
148 kfree(channel
->iob
[cnt
].data
);
149 channel
->iob
[cnt
].data
= NULL
;
157 lcs_cleanup_channel(struct lcs_channel
*channel
)
159 LCS_DBF_TEXT(3, setup
, "cleanch");
160 /* Kill write channel tasklets. */
161 tasklet_kill(&channel
->irq_tasklet
);
162 /* Free channel buffers. */
163 lcs_free_channel(channel
);
167 * LCS free memory for card and channels.
170 lcs_free_card(struct lcs_card
*card
)
172 LCS_DBF_TEXT(2, setup
, "remcard");
173 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
178 * LCS alloc memory for card and channels
180 static struct lcs_card
*
183 struct lcs_card
*card
;
186 LCS_DBF_TEXT(2, setup
, "alloclcs");
188 card
= kzalloc(sizeof(struct lcs_card
), GFP_KERNEL
| GFP_DMA
);
191 card
->lan_type
= LCS_FRAME_TYPE_AUTO
;
193 card
->lancmd_timeout
= LCS_LANCMD_TIMEOUT_DEFAULT
;
194 /* Allocate io buffers for the read channel. */
195 rc
= lcs_alloc_channel(&card
->read
);
197 LCS_DBF_TEXT(2, setup
, "iccwerr");
201 /* Allocate io buffers for the write channel. */
202 rc
= lcs_alloc_channel(&card
->write
);
204 LCS_DBF_TEXT(2, setup
, "iccwerr");
205 lcs_cleanup_channel(&card
->read
);
210 #ifdef CONFIG_IP_MULTICAST
211 INIT_LIST_HEAD(&card
->ipm_list
);
213 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
218 * Setup read channel.
221 lcs_setup_read_ccws(struct lcs_card
*card
)
225 LCS_DBF_TEXT(2, setup
, "ireadccw");
226 /* Setup read ccws. */
227 memset(card
->read
.ccws
, 0, sizeof (struct ccw1
) * (LCS_NUM_BUFFS
+ 1));
228 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
229 card
->read
.ccws
[cnt
].cmd_code
= LCS_CCW_READ
;
230 card
->read
.ccws
[cnt
].count
= LCS_IOBUFFERSIZE
;
231 card
->read
.ccws
[cnt
].flags
=
232 CCW_FLAG_CC
| CCW_FLAG_SLI
| CCW_FLAG_PCI
;
234 * Note: we have allocated the buffer with GFP_DMA, so
235 * we do not need to do set_normalized_cda.
237 card
->read
.ccws
[cnt
].cda
=
238 (__u32
) __pa(card
->read
.iob
[cnt
].data
);
239 ((struct lcs_header
*)
240 card
->read
.iob
[cnt
].data
)->offset
= LCS_ILLEGAL_OFFSET
;
241 card
->read
.iob
[cnt
].callback
= lcs_get_frames_cb
;
242 card
->read
.iob
[cnt
].state
= LCS_BUF_STATE_READY
;
243 card
->read
.iob
[cnt
].count
= LCS_IOBUFFERSIZE
;
245 card
->read
.ccws
[0].flags
&= ~CCW_FLAG_PCI
;
246 card
->read
.ccws
[LCS_NUM_BUFFS
- 1].flags
&= ~CCW_FLAG_PCI
;
247 card
->read
.ccws
[LCS_NUM_BUFFS
- 1].flags
|= CCW_FLAG_SUSPEND
;
248 /* Last ccw is a tic (transfer in channel). */
249 card
->read
.ccws
[LCS_NUM_BUFFS
].cmd_code
= LCS_CCW_TRANSFER
;
250 card
->read
.ccws
[LCS_NUM_BUFFS
].cda
=
251 (__u32
) __pa(card
->read
.ccws
);
252 /* Setg initial state of the read channel. */
253 card
->read
.state
= LCS_CH_STATE_INIT
;
255 card
->read
.io_idx
= 0;
256 card
->read
.buf_idx
= 0;
260 lcs_setup_read(struct lcs_card
*card
)
262 LCS_DBF_TEXT(3, setup
, "initread");
264 lcs_setup_read_ccws(card
);
265 /* Initialize read channel tasklet. */
266 card
->read
.irq_tasklet
.data
= (unsigned long) &card
->read
;
267 card
->read
.irq_tasklet
.func
= lcs_tasklet
;
268 /* Initialize waitqueue. */
269 init_waitqueue_head(&card
->read
.wait_q
);
273 * Setup write channel.
276 lcs_setup_write_ccws(struct lcs_card
*card
)
280 LCS_DBF_TEXT(3, setup
, "iwritccw");
281 /* Setup write ccws. */
282 memset(card
->write
.ccws
, 0, sizeof(struct ccw1
) * LCS_NUM_BUFFS
+ 1);
283 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
284 card
->write
.ccws
[cnt
].cmd_code
= LCS_CCW_WRITE
;
285 card
->write
.ccws
[cnt
].count
= 0;
286 card
->write
.ccws
[cnt
].flags
=
287 CCW_FLAG_SUSPEND
| CCW_FLAG_CC
| CCW_FLAG_SLI
;
289 * Note: we have allocated the buffer with GFP_DMA, so
290 * we do not need to do set_normalized_cda.
292 card
->write
.ccws
[cnt
].cda
=
293 (__u32
) __pa(card
->write
.iob
[cnt
].data
);
295 /* Last ccw is a tic (transfer in channel). */
296 card
->write
.ccws
[LCS_NUM_BUFFS
].cmd_code
= LCS_CCW_TRANSFER
;
297 card
->write
.ccws
[LCS_NUM_BUFFS
].cda
=
298 (__u32
) __pa(card
->write
.ccws
);
299 /* Set initial state of the write channel. */
300 card
->read
.state
= LCS_CH_STATE_INIT
;
302 card
->write
.io_idx
= 0;
303 card
->write
.buf_idx
= 0;
307 lcs_setup_write(struct lcs_card
*card
)
309 LCS_DBF_TEXT(3, setup
, "initwrit");
311 lcs_setup_write_ccws(card
);
312 /* Initialize write channel tasklet. */
313 card
->write
.irq_tasklet
.data
= (unsigned long) &card
->write
;
314 card
->write
.irq_tasklet
.func
= lcs_tasklet
;
315 /* Initialize waitqueue. */
316 init_waitqueue_head(&card
->write
.wait_q
);
320 lcs_set_allowed_threads(struct lcs_card
*card
, unsigned long threads
)
324 spin_lock_irqsave(&card
->mask_lock
, flags
);
325 card
->thread_allowed_mask
= threads
;
326 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
327 wake_up(&card
->wait_q
);
330 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);
349 lcs_set_thread_start_bit(struct lcs_card
*card
, unsigned long thread
)
353 spin_lock_irqsave(&card
->mask_lock
, flags
);
354 if ( !(card
->thread_allowed_mask
& thread
) ||
355 (card
->thread_start_mask
& thread
) ) {
356 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
359 card
->thread_start_mask
|= thread
;
360 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
365 lcs_clear_thread_running_bit(struct lcs_card
*card
, unsigned long thread
)
369 spin_lock_irqsave(&card
->mask_lock
, flags
);
370 card
->thread_running_mask
&= ~thread
;
371 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
372 wake_up(&card
->wait_q
);
376 __lcs_do_run_thread(struct lcs_card
*card
, unsigned long thread
)
381 spin_lock_irqsave(&card
->mask_lock
, flags
);
382 if (card
->thread_start_mask
& thread
){
383 if ((card
->thread_allowed_mask
& thread
) &&
384 !(card
->thread_running_mask
& thread
)){
386 card
->thread_start_mask
&= ~thread
;
387 card
->thread_running_mask
|= thread
;
391 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
396 lcs_do_run_thread(struct lcs_card
*card
, unsigned long thread
)
399 wait_event(card
->wait_q
,
400 (rc
= __lcs_do_run_thread(card
, thread
)) >= 0);
405 lcs_do_start_thread(struct lcs_card
*card
, unsigned long thread
)
410 spin_lock_irqsave(&card
->mask_lock
, flags
);
411 LCS_DBF_TEXT_(4, trace
, " %02x%02x%02x",
412 (u8
) card
->thread_start_mask
,
413 (u8
) card
->thread_allowed_mask
,
414 (u8
) card
->thread_running_mask
);
415 rc
= (card
->thread_start_mask
& thread
);
416 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
421 * Initialize channels,card and state machines.
424 lcs_setup_card(struct lcs_card
*card
)
426 LCS_DBF_TEXT(2, setup
, "initcard");
427 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
429 lcs_setup_read(card
);
430 lcs_setup_write(card
);
431 /* Set cards initial state. */
432 card
->state
= DEV_STATE_DOWN
;
433 card
->tx_buffer
= NULL
;
434 card
->tx_emitted
= 0;
436 init_waitqueue_head(&card
->wait_q
);
437 spin_lock_init(&card
->lock
);
438 spin_lock_init(&card
->ipm_lock
);
439 spin_lock_init(&card
->mask_lock
);
440 #ifdef CONFIG_IP_MULTICAST
441 INIT_LIST_HEAD(&card
->ipm_list
);
443 INIT_LIST_HEAD(&card
->lancmd_waiters
);
447 lcs_clear_multicast_list(struct lcs_card
*card
)
449 #ifdef CONFIG_IP_MULTICAST
450 struct lcs_ipm_list
*ipm
;
453 /* Free multicast list. */
454 LCS_DBF_TEXT(3, setup
, "clmclist");
455 spin_lock_irqsave(&card
->ipm_lock
, flags
);
456 while (!list_empty(&card
->ipm_list
)){
457 ipm
= list_entry(card
->ipm_list
.next
,
458 struct lcs_ipm_list
, list
);
459 list_del(&ipm
->list
);
460 if (ipm
->ipm_state
!= LCS_IPM_STATE_SET_REQUIRED
){
461 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
462 lcs_send_delipm(card
, ipm
);
463 spin_lock_irqsave(&card
->ipm_lock
, flags
);
467 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
471 * Cleanup channels,card and state machines.
474 lcs_cleanup_card(struct lcs_card
*card
)
477 LCS_DBF_TEXT(3, setup
, "cleancrd");
478 LCS_DBF_HEX(2,setup
,&card
,sizeof(void*));
480 if (card
->dev
!= NULL
)
481 free_netdev(card
->dev
);
482 /* Cleanup channels. */
483 lcs_cleanup_channel(&card
->write
);
484 lcs_cleanup_channel(&card
->read
);
491 lcs_start_channel(struct lcs_channel
*channel
)
496 LCS_DBF_TEXT_(4, trace
,"ssch%s", dev_name(&channel
->ccwdev
->dev
));
497 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
498 rc
= ccw_device_start(channel
->ccwdev
,
499 channel
->ccws
+ channel
->io_idx
, 0, 0,
500 DOIO_DENY_PREFETCH
| DOIO_ALLOW_SUSPEND
);
502 channel
->state
= LCS_CH_STATE_RUNNING
;
503 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
505 LCS_DBF_TEXT_(4,trace
,"essh%s",
506 dev_name(&channel
->ccwdev
->dev
));
507 dev_err(&channel
->ccwdev
->dev
,
508 "Starting an LCS device resulted in an error,"
515 lcs_clear_channel(struct lcs_channel
*channel
)
520 LCS_DBF_TEXT(4,trace
,"clearch");
521 LCS_DBF_TEXT_(4, trace
, "%s", dev_name(&channel
->ccwdev
->dev
));
522 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
523 rc
= ccw_device_clear(channel
->ccwdev
, (addr_t
) channel
);
524 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
526 LCS_DBF_TEXT_(4, trace
, "ecsc%s",
527 dev_name(&channel
->ccwdev
->dev
));
530 wait_event(channel
->wait_q
, (channel
->state
== LCS_CH_STATE_CLEARED
));
531 channel
->state
= LCS_CH_STATE_STOPPED
;
540 lcs_stop_channel(struct lcs_channel
*channel
)
545 if (channel
->state
== LCS_CH_STATE_STOPPED
)
547 LCS_DBF_TEXT(4,trace
,"haltsch");
548 LCS_DBF_TEXT_(4, trace
, "%s", dev_name(&channel
->ccwdev
->dev
));
549 channel
->state
= LCS_CH_STATE_INIT
;
550 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
551 rc
= ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
552 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
554 LCS_DBF_TEXT_(4, trace
, "ehsc%s",
555 dev_name(&channel
->ccwdev
->dev
));
558 /* Asynchronous halt initialted. Wait for its completion. */
559 wait_event(channel
->wait_q
, (channel
->state
== LCS_CH_STATE_HALTED
));
560 lcs_clear_channel(channel
);
565 * start read and write channel
568 lcs_start_channels(struct lcs_card
*card
)
572 LCS_DBF_TEXT(2, trace
, "chstart");
573 /* start read channel */
574 rc
= lcs_start_channel(&card
->read
);
577 /* start write channel */
578 rc
= lcs_start_channel(&card
->write
);
580 lcs_stop_channel(&card
->read
);
585 * stop read and write channel
588 lcs_stop_channels(struct lcs_card
*card
)
590 LCS_DBF_TEXT(2, trace
, "chhalt");
591 lcs_stop_channel(&card
->read
);
592 lcs_stop_channel(&card
->write
);
599 static struct lcs_buffer
*
600 __lcs_get_buffer(struct lcs_channel
*channel
)
604 LCS_DBF_TEXT(5, trace
, "_getbuff");
605 index
= channel
->io_idx
;
607 if (channel
->iob
[index
].state
== LCS_BUF_STATE_EMPTY
) {
608 channel
->iob
[index
].state
= LCS_BUF_STATE_LOCKED
;
609 return channel
->iob
+ index
;
611 index
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
612 } while (index
!= channel
->io_idx
);
616 static struct lcs_buffer
*
617 lcs_get_buffer(struct lcs_channel
*channel
)
619 struct lcs_buffer
*buffer
;
622 LCS_DBF_TEXT(5, trace
, "getbuff");
623 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
624 buffer
= __lcs_get_buffer(channel
);
625 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
630 * Resume channel program if the channel is suspended.
633 __lcs_resume_channel(struct lcs_channel
*channel
)
637 if (channel
->state
!= LCS_CH_STATE_SUSPENDED
)
639 if (channel
->ccws
[channel
->io_idx
].flags
& CCW_FLAG_SUSPEND
)
641 LCS_DBF_TEXT_(5, trace
, "rsch%s", dev_name(&channel
->ccwdev
->dev
));
642 rc
= ccw_device_resume(channel
->ccwdev
);
644 LCS_DBF_TEXT_(4, trace
, "ersc%s",
645 dev_name(&channel
->ccwdev
->dev
));
646 dev_err(&channel
->ccwdev
->dev
,
647 "Sending data from the LCS device to the LAN failed"
650 channel
->state
= LCS_CH_STATE_RUNNING
;
656 * Make a buffer ready for processing.
659 __lcs_ready_buffer_bits(struct lcs_channel
*channel
, int index
)
663 LCS_DBF_TEXT(5, trace
, "rdybits");
664 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
665 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
666 /* Check if we may clear the suspend bit of this buffer. */
667 if (channel
->ccws
[next
].flags
& CCW_FLAG_SUSPEND
) {
668 /* Check if we have to set the PCI bit. */
669 if (!(channel
->ccws
[prev
].flags
& CCW_FLAG_SUSPEND
))
670 /* Suspend bit of the previous buffer is not set. */
671 channel
->ccws
[index
].flags
|= CCW_FLAG_PCI
;
672 /* Suspend bit of the next buffer is set. */
673 channel
->ccws
[index
].flags
&= ~CCW_FLAG_SUSPEND
;
678 lcs_ready_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
683 LCS_DBF_TEXT(5, trace
, "rdybuff");
684 BUG_ON(buffer
->state
!= LCS_BUF_STATE_LOCKED
&&
685 buffer
->state
!= LCS_BUF_STATE_PROCESSED
);
686 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
687 buffer
->state
= LCS_BUF_STATE_READY
;
688 index
= buffer
- channel
->iob
;
690 channel
->ccws
[index
].count
= buffer
->count
;
691 /* Check relevant PCI/suspend bits. */
692 __lcs_ready_buffer_bits(channel
, index
);
693 rc
= __lcs_resume_channel(channel
);
694 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
699 * Mark the buffer as processed. Take care of the suspend bit
700 * of the previous buffer. This function is called from
701 * interrupt context, so the lock must not be taken.
704 __lcs_processed_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
706 int index
, prev
, next
;
708 LCS_DBF_TEXT(5, trace
, "prcsbuff");
709 BUG_ON(buffer
->state
!= LCS_BUF_STATE_READY
);
710 buffer
->state
= LCS_BUF_STATE_PROCESSED
;
711 index
= buffer
- channel
->iob
;
712 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
713 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
714 /* Set the suspend bit and clear the PCI bit of this buffer. */
715 channel
->ccws
[index
].flags
|= CCW_FLAG_SUSPEND
;
716 channel
->ccws
[index
].flags
&= ~CCW_FLAG_PCI
;
717 /* Check the suspend bit of the previous buffer. */
718 if (channel
->iob
[prev
].state
== LCS_BUF_STATE_READY
) {
720 * Previous buffer is in state ready. It might have
721 * happened in lcs_ready_buffer that the suspend bit
722 * has not been cleared to avoid an endless loop.
725 __lcs_ready_buffer_bits(channel
, prev
);
727 /* Clear PCI bit of next buffer. */
728 channel
->ccws
[next
].flags
&= ~CCW_FLAG_PCI
;
729 return __lcs_resume_channel(channel
);
733 * Put a processed buffer back to state empty.
736 lcs_release_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
740 LCS_DBF_TEXT(5, trace
, "relbuff");
741 BUG_ON(buffer
->state
!= LCS_BUF_STATE_LOCKED
&&
742 buffer
->state
!= LCS_BUF_STATE_PROCESSED
);
743 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
744 buffer
->state
= LCS_BUF_STATE_EMPTY
;
745 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
749 * Get buffer for a lan command.
751 static struct lcs_buffer
*
752 lcs_get_lancmd(struct lcs_card
*card
, int count
)
754 struct lcs_buffer
*buffer
;
757 LCS_DBF_TEXT(4, trace
, "getlncmd");
758 /* Get buffer and wait if none is available. */
759 wait_event(card
->write
.wait_q
,
760 ((buffer
= lcs_get_buffer(&card
->write
)) != NULL
));
761 count
+= sizeof(struct lcs_header
);
762 *(__u16
*)(buffer
->data
+ count
) = 0;
763 buffer
->count
= count
+ sizeof(__u16
);
764 buffer
->callback
= lcs_release_buffer
;
765 cmd
= (struct lcs_cmd
*) buffer
->data
;
767 cmd
->type
= LCS_FRAME_TYPE_CONTROL
;
774 lcs_get_reply(struct lcs_reply
*reply
)
776 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
777 atomic_inc(&reply
->refcnt
);
781 lcs_put_reply(struct lcs_reply
*reply
)
783 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
784 if (atomic_dec_and_test(&reply
->refcnt
)) {
790 static struct lcs_reply
*
791 lcs_alloc_reply(struct lcs_cmd
*cmd
)
793 struct lcs_reply
*reply
;
795 LCS_DBF_TEXT(4, trace
, "getreply");
797 reply
= kzalloc(sizeof(struct lcs_reply
), GFP_ATOMIC
);
800 atomic_set(&reply
->refcnt
,1);
801 reply
->sequence_no
= cmd
->sequence_no
;
804 init_waitqueue_head(&reply
->wait_q
);
810 * Notifier function for lancmd replies. Called from read irq.
813 lcs_notify_lancmd_waiters(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
815 struct list_head
*l
, *n
;
816 struct lcs_reply
*reply
;
818 LCS_DBF_TEXT(4, trace
, "notiwait");
819 spin_lock(&card
->lock
);
820 list_for_each_safe(l
, n
, &card
->lancmd_waiters
) {
821 reply
= list_entry(l
, struct lcs_reply
, list
);
822 if (reply
->sequence_no
== cmd
->sequence_no
) {
823 lcs_get_reply(reply
);
824 list_del_init(&reply
->list
);
825 if (reply
->callback
!= NULL
)
826 reply
->callback(card
, cmd
);
828 reply
->rc
= cmd
->return_code
;
829 wake_up(&reply
->wait_q
);
830 lcs_put_reply(reply
);
834 spin_unlock(&card
->lock
);
838 * Emit buffer of a lan comand.
841 lcs_lancmd_timeout(unsigned long data
)
843 struct lcs_reply
*reply
, *list_reply
, *r
;
846 LCS_DBF_TEXT(4, trace
, "timeout");
847 reply
= (struct lcs_reply
*) data
;
848 spin_lock_irqsave(&reply
->card
->lock
, flags
);
849 list_for_each_entry_safe(list_reply
, r
,
850 &reply
->card
->lancmd_waiters
,list
) {
851 if (reply
== list_reply
) {
852 lcs_get_reply(reply
);
853 list_del_init(&reply
->list
);
854 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
857 wake_up(&reply
->wait_q
);
858 lcs_put_reply(reply
);
862 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
866 lcs_send_lancmd(struct lcs_card
*card
, struct lcs_buffer
*buffer
,
867 void (*reply_callback
)(struct lcs_card
*, struct lcs_cmd
*))
869 struct lcs_reply
*reply
;
871 struct timer_list timer
;
875 LCS_DBF_TEXT(4, trace
, "sendcmd");
876 cmd
= (struct lcs_cmd
*) buffer
->data
;
877 cmd
->return_code
= 0;
878 cmd
->sequence_no
= card
->sequence_no
++;
879 reply
= lcs_alloc_reply(cmd
);
882 reply
->callback
= reply_callback
;
884 spin_lock_irqsave(&card
->lock
, flags
);
885 list_add_tail(&reply
->list
, &card
->lancmd_waiters
);
886 spin_unlock_irqrestore(&card
->lock
, flags
);
888 buffer
->callback
= lcs_release_buffer
;
889 rc
= lcs_ready_buffer(&card
->write
, buffer
);
893 timer
.function
= lcs_lancmd_timeout
;
894 timer
.data
= (unsigned long) reply
;
895 timer
.expires
= jiffies
+ HZ
*card
->lancmd_timeout
;
897 wait_event(reply
->wait_q
, reply
->received
);
898 del_timer_sync(&timer
);
899 LCS_DBF_TEXT_(4, trace
, "rc:%d",reply
->rc
);
901 lcs_put_reply(reply
);
902 return rc
? -EIO
: 0;
906 * LCS startup command
909 lcs_send_startup(struct lcs_card
*card
, __u8 initiator
)
911 struct lcs_buffer
*buffer
;
914 LCS_DBF_TEXT(2, trace
, "startup");
915 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
916 cmd
= (struct lcs_cmd
*) buffer
->data
;
917 cmd
->cmd_code
= LCS_CMD_STARTUP
;
918 cmd
->initiator
= initiator
;
919 cmd
->cmd
.lcs_startup
.buff_size
= LCS_IOBUFFERSIZE
;
920 return lcs_send_lancmd(card
, buffer
, NULL
);
924 * LCS shutdown command
927 lcs_send_shutdown(struct lcs_card
*card
)
929 struct lcs_buffer
*buffer
;
932 LCS_DBF_TEXT(2, trace
, "shutdown");
933 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
934 cmd
= (struct lcs_cmd
*) buffer
->data
;
935 cmd
->cmd_code
= LCS_CMD_SHUTDOWN
;
936 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
937 return lcs_send_lancmd(card
, buffer
, NULL
);
941 * LCS lanstat command
944 __lcs_lanstat_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
946 LCS_DBF_TEXT(2, trace
, "statcb");
947 memcpy(card
->mac
, cmd
->cmd
.lcs_lanstat_cmd
.mac_addr
, LCS_MAC_LENGTH
);
951 lcs_send_lanstat(struct lcs_card
*card
)
953 struct lcs_buffer
*buffer
;
956 LCS_DBF_TEXT(2,trace
, "cmdstat");
957 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
958 cmd
= (struct lcs_cmd
*) buffer
->data
;
959 /* Setup lanstat command. */
960 cmd
->cmd_code
= LCS_CMD_LANSTAT
;
961 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
962 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
963 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
964 return lcs_send_lancmd(card
, buffer
, __lcs_lanstat_cb
);
968 * send stoplan command
971 lcs_send_stoplan(struct lcs_card
*card
, __u8 initiator
)
973 struct lcs_buffer
*buffer
;
976 LCS_DBF_TEXT(2, trace
, "cmdstpln");
977 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
978 cmd
= (struct lcs_cmd
*) buffer
->data
;
979 cmd
->cmd_code
= LCS_CMD_STOPLAN
;
980 cmd
->initiator
= initiator
;
981 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
982 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
983 return lcs_send_lancmd(card
, buffer
, NULL
);
987 * send startlan command
990 __lcs_send_startlan_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
992 LCS_DBF_TEXT(2, trace
, "srtlancb");
993 card
->lan_type
= cmd
->cmd
.lcs_std_cmd
.lan_type
;
994 card
->portno
= cmd
->cmd
.lcs_std_cmd
.portno
;
998 lcs_send_startlan(struct lcs_card
*card
, __u8 initiator
)
1000 struct lcs_buffer
*buffer
;
1001 struct lcs_cmd
*cmd
;
1003 LCS_DBF_TEXT(2, trace
, "cmdstaln");
1004 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
1005 cmd
= (struct lcs_cmd
*) buffer
->data
;
1006 cmd
->cmd_code
= LCS_CMD_STARTLAN
;
1007 cmd
->initiator
= initiator
;
1008 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
1009 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
1010 return lcs_send_lancmd(card
, buffer
, __lcs_send_startlan_cb
);
1013 #ifdef CONFIG_IP_MULTICAST
1015 * send setipm command (Multicast)
1018 lcs_send_setipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1020 struct lcs_buffer
*buffer
;
1021 struct lcs_cmd
*cmd
;
1023 LCS_DBF_TEXT(2, trace
, "cmdsetim");
1024 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1025 cmd
= (struct lcs_cmd
*) buffer
->data
;
1026 cmd
->cmd_code
= LCS_CMD_SETIPM
;
1027 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1028 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1029 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1030 cmd
->cmd
.lcs_qipassist
.version
= 4;
1031 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1032 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1033 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1034 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1035 return lcs_send_lancmd(card
, buffer
, NULL
);
1039 * send delipm command (Multicast)
1042 lcs_send_delipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1044 struct lcs_buffer
*buffer
;
1045 struct lcs_cmd
*cmd
;
1047 LCS_DBF_TEXT(2, trace
, "cmddelim");
1048 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1049 cmd
= (struct lcs_cmd
*) buffer
->data
;
1050 cmd
->cmd_code
= LCS_CMD_DELIPM
;
1051 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1052 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1053 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1054 cmd
->cmd
.lcs_qipassist
.version
= 4;
1055 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1056 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1057 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1058 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1059 return lcs_send_lancmd(card
, buffer
, NULL
);
1063 * check if multicast is supported by LCS
1066 __lcs_check_multicast_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1068 LCS_DBF_TEXT(2, trace
, "chkmccb");
1069 card
->ip_assists_supported
=
1070 cmd
->cmd
.lcs_qipassist
.ip_assists_supported
;
1071 card
->ip_assists_enabled
=
1072 cmd
->cmd
.lcs_qipassist
.ip_assists_enabled
;
1076 lcs_check_multicast_support(struct lcs_card
*card
)
1078 struct lcs_buffer
*buffer
;
1079 struct lcs_cmd
*cmd
;
1082 LCS_DBF_TEXT(2, trace
, "cmdqipa");
1083 /* Send query ipassist. */
1084 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
1085 cmd
= (struct lcs_cmd
*) buffer
->data
;
1086 cmd
->cmd_code
= LCS_CMD_QIPASSIST
;
1087 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1088 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1089 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1090 cmd
->cmd
.lcs_qipassist
.version
= 4;
1091 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1092 rc
= lcs_send_lancmd(card
, buffer
, __lcs_check_multicast_cb
);
1094 pr_err("Query IPAssist failed. Assuming unsupported!\n");
1097 if (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
)
1103 * set or del multicast address on LCS card
1106 lcs_fix_multicast_list(struct lcs_card
*card
)
1108 struct list_head failed_list
;
1109 struct lcs_ipm_list
*ipm
, *tmp
;
1110 unsigned long flags
;
1113 LCS_DBF_TEXT(4,trace
, "fixipm");
1114 INIT_LIST_HEAD(&failed_list
);
1115 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1117 list_for_each_entry_safe(ipm
, tmp
, &card
->ipm_list
, list
){
1118 switch (ipm
->ipm_state
) {
1119 case LCS_IPM_STATE_SET_REQUIRED
:
1120 /* del from ipm_list so noone else can tamper with
1122 list_del_init(&ipm
->list
);
1123 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1124 rc
= lcs_send_setipm(card
, ipm
);
1125 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1127 pr_info("Adding multicast address failed."
1128 " Table possibly full!\n");
1129 /* store ipm in failed list -> will be added
1130 * to ipm_list again, so a retry will be done
1131 * during the next call of this function */
1132 list_add_tail(&ipm
->list
, &failed_list
);
1134 ipm
->ipm_state
= LCS_IPM_STATE_ON_CARD
;
1135 /* re-insert into ipm_list */
1136 list_add_tail(&ipm
->list
, &card
->ipm_list
);
1139 case LCS_IPM_STATE_DEL_REQUIRED
:
1140 list_del(&ipm
->list
);
1141 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1142 lcs_send_delipm(card
, ipm
);
1143 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1146 case LCS_IPM_STATE_ON_CARD
:
1150 /* re-insert all entries from the failed_list into ipm_list */
1151 list_for_each_entry_safe(ipm
, tmp
, &failed_list
, list
)
1152 list_move_tail(&ipm
->list
, &card
->ipm_list
);
1154 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1158 * get mac address for the relevant Multicast address
1161 lcs_get_mac_for_ipm(__be32 ipm
, char *mac
, struct net_device
*dev
)
1163 LCS_DBF_TEXT(4,trace
, "getmac");
1164 if (dev
->type
== ARPHRD_IEEE802_TR
)
1165 ip_tr_mc_map(ipm
, mac
);
1167 ip_eth_mc_map(ipm
, mac
);
1171 * function called by net device to handle multicast address relevant things
1174 lcs_remove_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1176 struct ip_mc_list
*im4
;
1177 struct list_head
*l
;
1178 struct lcs_ipm_list
*ipm
;
1179 unsigned long flags
;
1180 char buf
[MAX_ADDR_LEN
];
1182 LCS_DBF_TEXT(4, trace
, "remmclst");
1183 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1184 list_for_each(l
, &card
->ipm_list
) {
1185 ipm
= list_entry(l
, struct lcs_ipm_list
, list
);
1186 for (im4
= in4_dev
->mc_list
; im4
!= NULL
; im4
= im4
->next
) {
1187 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1188 if ( (ipm
->ipm
.ip_addr
== im4
->multiaddr
) &&
1189 (memcmp(buf
, &ipm
->ipm
.mac_addr
,
1190 LCS_MAC_LENGTH
) == 0) )
1194 ipm
->ipm_state
= LCS_IPM_STATE_DEL_REQUIRED
;
1196 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1199 static inline struct lcs_ipm_list
*
1200 lcs_check_addr_entry(struct lcs_card
*card
, struct ip_mc_list
*im4
, char *buf
)
1202 struct lcs_ipm_list
*tmp
, *ipm
= NULL
;
1203 struct list_head
*l
;
1204 unsigned long flags
;
1206 LCS_DBF_TEXT(4, trace
, "chkmcent");
1207 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1208 list_for_each(l
, &card
->ipm_list
) {
1209 tmp
= list_entry(l
, struct lcs_ipm_list
, list
);
1210 if ( (tmp
->ipm
.ip_addr
== im4
->multiaddr
) &&
1211 (memcmp(buf
, &tmp
->ipm
.mac_addr
,
1212 LCS_MAC_LENGTH
) == 0) ) {
1217 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1222 lcs_set_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1225 struct ip_mc_list
*im4
;
1226 struct lcs_ipm_list
*ipm
;
1227 char buf
[MAX_ADDR_LEN
];
1228 unsigned long flags
;
1230 LCS_DBF_TEXT(4, trace
, "setmclst");
1231 for (im4
= in4_dev
->mc_list
; im4
; im4
= im4
->next
) {
1232 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1233 ipm
= lcs_check_addr_entry(card
, im4
, buf
);
1235 continue; /* Address already in list. */
1236 ipm
= (struct lcs_ipm_list
*)
1237 kzalloc(sizeof(struct lcs_ipm_list
), GFP_ATOMIC
);
1239 pr_info("Not enough memory to add"
1240 " new multicast entry!\n");
1243 memcpy(&ipm
->ipm
.mac_addr
, buf
, LCS_MAC_LENGTH
);
1244 ipm
->ipm
.ip_addr
= im4
->multiaddr
;
1245 ipm
->ipm_state
= LCS_IPM_STATE_SET_REQUIRED
;
1246 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1247 LCS_DBF_HEX(2,trace
,&ipm
->ipm
.ip_addr
,4);
1248 list_add(&ipm
->list
, &card
->ipm_list
);
1249 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1254 lcs_register_mc_addresses(void *data
)
1256 struct lcs_card
*card
;
1257 struct in_device
*in4_dev
;
1259 card
= (struct lcs_card
*) data
;
1261 if (!lcs_do_run_thread(card
, LCS_SET_MC_THREAD
))
1263 LCS_DBF_TEXT(4, trace
, "regmulti");
1265 in4_dev
= in_dev_get(card
->dev
);
1266 if (in4_dev
== NULL
)
1268 read_lock(&in4_dev
->mc_list_lock
);
1269 lcs_remove_mc_addresses(card
,in4_dev
);
1270 lcs_set_mc_addresses(card
, in4_dev
);
1271 read_unlock(&in4_dev
->mc_list_lock
);
1272 in_dev_put(in4_dev
);
1274 netif_carrier_off(card
->dev
);
1275 netif_tx_disable(card
->dev
);
1276 wait_event(card
->write
.wait_q
,
1277 (card
->write
.state
!= LCS_CH_STATE_RUNNING
));
1278 lcs_fix_multicast_list(card
);
1279 if (card
->state
== DEV_STATE_UP
) {
1280 netif_carrier_on(card
->dev
);
1281 netif_wake_queue(card
->dev
);
1284 lcs_clear_thread_running_bit(card
, LCS_SET_MC_THREAD
);
1287 #endif /* CONFIG_IP_MULTICAST */
1290 * function called by net device to
1291 * handle multicast address relevant things
1294 lcs_set_multicast_list(struct net_device
*dev
)
1296 #ifdef CONFIG_IP_MULTICAST
1297 struct lcs_card
*card
;
1299 LCS_DBF_TEXT(4, trace
, "setmulti");
1300 card
= (struct lcs_card
*) dev
->ml_priv
;
1302 if (!lcs_set_thread_start_bit(card
, LCS_SET_MC_THREAD
))
1303 schedule_work(&card
->kernel_thread_starter
);
1304 #endif /* CONFIG_IP_MULTICAST */
1308 lcs_check_irb_error(struct ccw_device
*cdev
, struct irb
*irb
)
1313 switch (PTR_ERR(irb
)) {
1315 dev_warn(&cdev
->dev
,
1316 "An I/O-error occurred on the LCS device\n");
1317 LCS_DBF_TEXT(2, trace
, "ckirberr");
1318 LCS_DBF_TEXT_(2, trace
, " rc%d", -EIO
);
1321 dev_warn(&cdev
->dev
,
1322 "A command timed out on the LCS device\n");
1323 LCS_DBF_TEXT(2, trace
, "ckirberr");
1324 LCS_DBF_TEXT_(2, trace
, " rc%d", -ETIMEDOUT
);
1327 dev_warn(&cdev
->dev
,
1328 "An error occurred on the LCS device, rc=%ld\n",
1330 LCS_DBF_TEXT(2, trace
, "ckirberr");
1331 LCS_DBF_TEXT(2, trace
, " rc???");
1333 return PTR_ERR(irb
);
1337 lcs_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
1342 sense
= (char *) irb
->ecw
;
1343 cstat
= irb
->scsw
.cmd
.cstat
;
1344 dstat
= irb
->scsw
.cmd
.dstat
;
1346 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
1347 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
1348 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
1349 LCS_DBF_TEXT(2, trace
, "CGENCHK");
1352 if (dstat
& DEV_STAT_UNIT_CHECK
) {
1353 if (sense
[LCS_SENSE_BYTE_1
] &
1354 LCS_SENSE_RESETTING_EVENT
) {
1355 LCS_DBF_TEXT(2, trace
, "REVIND");
1358 if (sense
[LCS_SENSE_BYTE_0
] &
1359 LCS_SENSE_CMD_REJECT
) {
1360 LCS_DBF_TEXT(2, trace
, "CMDREJ");
1363 if ((!sense
[LCS_SENSE_BYTE_0
]) &&
1364 (!sense
[LCS_SENSE_BYTE_1
]) &&
1365 (!sense
[LCS_SENSE_BYTE_2
]) &&
1366 (!sense
[LCS_SENSE_BYTE_3
])) {
1367 LCS_DBF_TEXT(2, trace
, "ZEROSEN");
1370 LCS_DBF_TEXT(2, trace
, "DGENCHK");
1377 lcs_schedule_recovery(struct lcs_card
*card
)
1379 LCS_DBF_TEXT(2, trace
, "startrec");
1380 if (!lcs_set_thread_start_bit(card
, LCS_RECOVERY_THREAD
))
1381 schedule_work(&card
->kernel_thread_starter
);
1385 * IRQ Handler for LCS channels
1388 lcs_irq(struct ccw_device
*cdev
, unsigned long intparm
, struct irb
*irb
)
1390 struct lcs_card
*card
;
1391 struct lcs_channel
*channel
;
1395 if (lcs_check_irb_error(cdev
, irb
))
1398 card
= CARD_FROM_DEV(cdev
);
1399 if (card
->read
.ccwdev
== cdev
)
1400 channel
= &card
->read
;
1402 channel
= &card
->write
;
1404 cstat
= irb
->scsw
.cmd
.cstat
;
1405 dstat
= irb
->scsw
.cmd
.dstat
;
1406 LCS_DBF_TEXT_(5, trace
, "Rint%s", dev_name(&cdev
->dev
));
1407 LCS_DBF_TEXT_(5, trace
, "%4x%4x", irb
->scsw
.cmd
.cstat
,
1408 irb
->scsw
.cmd
.dstat
);
1409 LCS_DBF_TEXT_(5, trace
, "%4x%4x", irb
->scsw
.cmd
.fctl
,
1410 irb
->scsw
.cmd
.actl
);
1412 /* Check for channel and device errors presented */
1413 rc
= lcs_get_problem(cdev
, irb
);
1414 if (rc
|| (dstat
& DEV_STAT_UNIT_EXCEP
)) {
1415 dev_warn(&cdev
->dev
,
1416 "The LCS device stopped because of an error,"
1417 " dstat=0x%X, cstat=0x%X \n",
1420 channel
->state
= LCS_CH_STATE_ERROR
;
1423 if (channel
->state
== LCS_CH_STATE_ERROR
) {
1424 lcs_schedule_recovery(card
);
1425 wake_up(&card
->wait_q
);
1428 /* How far in the ccw chain have we processed? */
1429 if ((channel
->state
!= LCS_CH_STATE_INIT
) &&
1430 (irb
->scsw
.cmd
.fctl
& SCSW_FCTL_START_FUNC
) &&
1431 (irb
->scsw
.cmd
.cpa
!= 0)) {
1432 index
= (struct ccw1
*) __va((addr_t
) irb
->scsw
.cmd
.cpa
)
1434 if ((irb
->scsw
.cmd
.actl
& SCSW_ACTL_SUSPENDED
) ||
1435 (irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
))
1436 /* Bloody io subsystem tells us lies about cpa... */
1437 index
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
1438 while (channel
->io_idx
!= index
) {
1439 __lcs_processed_buffer(channel
,
1440 channel
->iob
+ channel
->io_idx
);
1442 (channel
->io_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1446 if ((irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) ||
1447 (irb
->scsw
.cmd
.dstat
& DEV_STAT_CHN_END
) ||
1448 (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
))
1449 /* Mark channel as stopped. */
1450 channel
->state
= LCS_CH_STATE_STOPPED
;
1451 else if (irb
->scsw
.cmd
.actl
& SCSW_ACTL_SUSPENDED
)
1452 /* CCW execution stopped on a suspend bit. */
1453 channel
->state
= LCS_CH_STATE_SUSPENDED
;
1454 if (irb
->scsw
.cmd
.fctl
& SCSW_FCTL_HALT_FUNC
) {
1455 if (irb
->scsw
.cmd
.cc
!= 0) {
1456 ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
1459 /* The channel has been stopped by halt_IO. */
1460 channel
->state
= LCS_CH_STATE_HALTED
;
1462 if (irb
->scsw
.cmd
.fctl
& SCSW_FCTL_CLEAR_FUNC
)
1463 channel
->state
= LCS_CH_STATE_CLEARED
;
1464 /* Do the rest in the tasklet. */
1465 tasklet_schedule(&channel
->irq_tasklet
);
1469 * Tasklet for IRQ handler
1472 lcs_tasklet(unsigned long data
)
1474 unsigned long flags
;
1475 struct lcs_channel
*channel
;
1476 struct lcs_buffer
*iob
;
1480 channel
= (struct lcs_channel
*) data
;
1481 LCS_DBF_TEXT_(5, trace
, "tlet%s", dev_name(&channel
->ccwdev
->dev
));
1483 /* Check for processed buffers. */
1485 buf_idx
= channel
->buf_idx
;
1486 while (iob
[buf_idx
].state
== LCS_BUF_STATE_PROCESSED
) {
1487 /* Do the callback thing. */
1488 if (iob
[buf_idx
].callback
!= NULL
)
1489 iob
[buf_idx
].callback(channel
, iob
+ buf_idx
);
1490 buf_idx
= (buf_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1492 channel
->buf_idx
= buf_idx
;
1494 if (channel
->state
== LCS_CH_STATE_STOPPED
)
1495 // FIXME: what if rc != 0 ??
1496 rc
= lcs_start_channel(channel
);
1497 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1498 if (channel
->state
== LCS_CH_STATE_SUSPENDED
&&
1499 channel
->iob
[channel
->io_idx
].state
== LCS_BUF_STATE_READY
) {
1500 // FIXME: what if rc != 0 ??
1501 rc
= __lcs_resume_channel(channel
);
1503 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1505 /* Something happened on the channel. Wake up waiters. */
1506 wake_up(&channel
->wait_q
);
1510 * Finish current tx buffer and make it ready for transmit.
1513 __lcs_emit_txbuffer(struct lcs_card
*card
)
1515 LCS_DBF_TEXT(5, trace
, "emittx");
1516 *(__u16
*)(card
->tx_buffer
->data
+ card
->tx_buffer
->count
) = 0;
1517 card
->tx_buffer
->count
+= 2;
1518 lcs_ready_buffer(&card
->write
, card
->tx_buffer
);
1519 card
->tx_buffer
= NULL
;
1524 * Callback for finished tx buffers.
1527 lcs_txbuffer_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1529 struct lcs_card
*card
;
1531 LCS_DBF_TEXT(5, trace
, "txbuffcb");
1532 /* Put buffer back to pool. */
1533 lcs_release_buffer(channel
, buffer
);
1534 card
= container_of(channel
, struct lcs_card
, write
);
1535 if (netif_queue_stopped(card
->dev
) && netif_carrier_ok(card
->dev
))
1536 netif_wake_queue(card
->dev
);
1537 spin_lock(&card
->lock
);
1539 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1541 * Last running tx buffer has finished. Submit partially
1542 * filled current buffer.
1544 __lcs_emit_txbuffer(card
);
1545 spin_unlock(&card
->lock
);
1549 * Packet transmit function called by network stack
1552 __lcs_start_xmit(struct lcs_card
*card
, struct sk_buff
*skb
,
1553 struct net_device
*dev
)
1555 struct lcs_header
*header
;
1558 LCS_DBF_TEXT(5, trace
, "hardxmit");
1560 card
->stats
.tx_dropped
++;
1561 card
->stats
.tx_errors
++;
1564 if (card
->state
!= DEV_STATE_UP
) {
1566 card
->stats
.tx_dropped
++;
1567 card
->stats
.tx_errors
++;
1568 card
->stats
.tx_carrier_errors
++;
1571 if (skb
->protocol
== htons(ETH_P_IPV6
)) {
1575 netif_stop_queue(card
->dev
);
1576 spin_lock(&card
->lock
);
1577 if (card
->tx_buffer
!= NULL
&&
1578 card
->tx_buffer
->count
+ sizeof(struct lcs_header
) +
1579 skb
->len
+ sizeof(u16
) > LCS_IOBUFFERSIZE
)
1580 /* skb too big for current tx buffer. */
1581 __lcs_emit_txbuffer(card
);
1582 if (card
->tx_buffer
== NULL
) {
1583 /* Get new tx buffer */
1584 card
->tx_buffer
= lcs_get_buffer(&card
->write
);
1585 if (card
->tx_buffer
== NULL
) {
1586 card
->stats
.tx_dropped
++;
1587 rc
= NETDEV_TX_BUSY
;
1590 card
->tx_buffer
->callback
= lcs_txbuffer_cb
;
1591 card
->tx_buffer
->count
= 0;
1593 header
= (struct lcs_header
*)
1594 (card
->tx_buffer
->data
+ card
->tx_buffer
->count
);
1595 card
->tx_buffer
->count
+= skb
->len
+ sizeof(struct lcs_header
);
1596 header
->offset
= card
->tx_buffer
->count
;
1597 header
->type
= card
->lan_type
;
1598 header
->slot
= card
->portno
;
1599 skb_copy_from_linear_data(skb
, header
+ 1, skb
->len
);
1600 spin_unlock(&card
->lock
);
1601 card
->stats
.tx_bytes
+= skb
->len
;
1602 card
->stats
.tx_packets
++;
1604 netif_wake_queue(card
->dev
);
1605 spin_lock(&card
->lock
);
1606 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1607 /* If this is the first tx buffer emit it immediately. */
1608 __lcs_emit_txbuffer(card
);
1610 spin_unlock(&card
->lock
);
1615 lcs_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1617 struct lcs_card
*card
;
1620 LCS_DBF_TEXT(5, trace
, "pktxmit");
1621 card
= (struct lcs_card
*) dev
->ml_priv
;
1622 rc
= __lcs_start_xmit(card
, skb
, dev
);
1627 * send startlan and lanstat command to make LCS device ready
1630 lcs_startlan_auto(struct lcs_card
*card
)
1634 LCS_DBF_TEXT(2, trace
, "strtauto");
1635 #ifdef CONFIG_NET_ETHERNET
1636 card
->lan_type
= LCS_FRAME_TYPE_ENET
;
1637 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1643 card
->lan_type
= LCS_FRAME_TYPE_TR
;
1644 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1649 card
->lan_type
= LCS_FRAME_TYPE_FDDI
;
1650 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1658 lcs_startlan(struct lcs_card
*card
)
1662 LCS_DBF_TEXT(2, trace
, "startlan");
1664 if (card
->portno
!= LCS_INVALID_PORT_NO
) {
1665 if (card
->lan_type
== LCS_FRAME_TYPE_AUTO
)
1666 rc
= lcs_startlan_auto(card
);
1668 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1670 for (i
= 0; i
<= 16; i
++) {
1672 if (card
->lan_type
!= LCS_FRAME_TYPE_AUTO
)
1673 rc
= lcs_send_startlan(card
,
1674 LCS_INITIATOR_TCPIP
);
1676 /* autodetecting lan type */
1677 rc
= lcs_startlan_auto(card
);
1683 return lcs_send_lanstat(card
);
1688 * LCS detect function
1689 * setup channels and make them I/O ready
1692 lcs_detect(struct lcs_card
*card
)
1696 LCS_DBF_TEXT(2, setup
, "lcsdetct");
1697 /* start/reset card */
1699 netif_stop_queue(card
->dev
);
1700 rc
= lcs_stop_channels(card
);
1702 rc
= lcs_start_channels(card
);
1704 rc
= lcs_send_startup(card
, LCS_INITIATOR_TCPIP
);
1706 rc
= lcs_startlan(card
);
1710 card
->state
= DEV_STATE_UP
;
1712 card
->state
= DEV_STATE_DOWN
;
1713 card
->write
.state
= LCS_CH_STATE_INIT
;
1714 card
->read
.state
= LCS_CH_STATE_INIT
;
1723 lcs_stopcard(struct lcs_card
*card
)
1727 LCS_DBF_TEXT(3, setup
, "stopcard");
1729 if (card
->read
.state
!= LCS_CH_STATE_STOPPED
&&
1730 card
->write
.state
!= LCS_CH_STATE_STOPPED
&&
1731 card
->read
.state
!= LCS_CH_STATE_ERROR
&&
1732 card
->write
.state
!= LCS_CH_STATE_ERROR
&&
1733 card
->state
== DEV_STATE_UP
) {
1734 lcs_clear_multicast_list(card
);
1735 rc
= lcs_send_stoplan(card
,LCS_INITIATOR_TCPIP
);
1736 rc
= lcs_send_shutdown(card
);
1738 rc
= lcs_stop_channels(card
);
1739 card
->state
= DEV_STATE_DOWN
;
1745 * Kernel Thread helper functions for LGW initiated commands
1748 lcs_start_kernel_thread(struct work_struct
*work
)
1750 struct lcs_card
*card
= container_of(work
, struct lcs_card
, kernel_thread_starter
);
1751 LCS_DBF_TEXT(5, trace
, "krnthrd");
1752 if (lcs_do_start_thread(card
, LCS_RECOVERY_THREAD
))
1753 kthread_run(lcs_recovery
, card
, "lcs_recover");
1754 #ifdef CONFIG_IP_MULTICAST
1755 if (lcs_do_start_thread(card
, LCS_SET_MC_THREAD
))
1756 kthread_run(lcs_register_mc_addresses
, card
, "regipm");
1761 * Process control frames.
1764 lcs_get_control(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1766 LCS_DBF_TEXT(5, trace
, "getctrl");
1767 if (cmd
->initiator
== LCS_INITIATOR_LGW
) {
1768 switch(cmd
->cmd_code
) {
1769 case LCS_CMD_STARTUP
:
1770 case LCS_CMD_STARTLAN
:
1771 lcs_schedule_recovery(card
);
1773 case LCS_CMD_STOPLAN
:
1774 pr_warning("Stoplan for %s initiated by LGW.\n",
1777 netif_carrier_off(card
->dev
);
1780 LCS_DBF_TEXT(5, trace
, "noLGWcmd");
1784 lcs_notify_lancmd_waiters(card
, cmd
);
1788 * Unpack network packet.
1791 lcs_get_skb(struct lcs_card
*card
, char *skb_data
, unsigned int skb_len
)
1793 struct sk_buff
*skb
;
1795 LCS_DBF_TEXT(5, trace
, "getskb");
1796 if (card
->dev
== NULL
||
1797 card
->state
!= DEV_STATE_UP
)
1798 /* The card isn't up. Ignore the packet. */
1801 skb
= dev_alloc_skb(skb_len
);
1803 dev_err(&card
->dev
->dev
,
1804 " Allocating a socket buffer to interface %s failed\n",
1806 card
->stats
.rx_dropped
++;
1809 memcpy(skb_put(skb
, skb_len
), skb_data
, skb_len
);
1810 skb
->protocol
= card
->lan_type_trans(skb
, card
->dev
);
1811 card
->stats
.rx_bytes
+= skb_len
;
1812 card
->stats
.rx_packets
++;
1813 if (skb
->protocol
== htons(ETH_P_802_2
))
1814 *((__u32
*)skb
->cb
) = ++card
->pkt_seq
;
1819 * LCS main routine to get packets and lancmd replies from the buffers
1822 lcs_get_frames_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1824 struct lcs_card
*card
;
1825 struct lcs_header
*lcs_hdr
;
1828 LCS_DBF_TEXT(5, trace
, "lcsgtpkt");
1829 lcs_hdr
= (struct lcs_header
*) buffer
->data
;
1830 if (lcs_hdr
->offset
== LCS_ILLEGAL_OFFSET
) {
1831 LCS_DBF_TEXT(4, trace
, "-eiogpkt");
1834 card
= container_of(channel
, struct lcs_card
, read
);
1836 while (lcs_hdr
->offset
!= 0) {
1837 if (lcs_hdr
->offset
<= 0 ||
1838 lcs_hdr
->offset
> LCS_IOBUFFERSIZE
||
1839 lcs_hdr
->offset
< offset
) {
1840 /* Offset invalid. */
1841 card
->stats
.rx_length_errors
++;
1842 card
->stats
.rx_errors
++;
1845 /* What kind of frame is it? */
1846 if (lcs_hdr
->type
== LCS_FRAME_TYPE_CONTROL
)
1847 /* Control frame. */
1848 lcs_get_control(card
, (struct lcs_cmd
*) lcs_hdr
);
1849 else if (lcs_hdr
->type
== LCS_FRAME_TYPE_ENET
||
1850 lcs_hdr
->type
== LCS_FRAME_TYPE_TR
||
1851 lcs_hdr
->type
== LCS_FRAME_TYPE_FDDI
)
1852 /* Normal network packet. */
1853 lcs_get_skb(card
, (char *)(lcs_hdr
+ 1),
1854 lcs_hdr
->offset
- offset
-
1855 sizeof(struct lcs_header
));
1857 /* Unknown frame type. */
1858 ; // FIXME: error message ?
1859 /* Proceed to next frame. */
1860 offset
= lcs_hdr
->offset
;
1861 lcs_hdr
->offset
= LCS_ILLEGAL_OFFSET
;
1862 lcs_hdr
= (struct lcs_header
*) (buffer
->data
+ offset
);
1864 /* The buffer is now empty. Make it ready again. */
1865 lcs_ready_buffer(&card
->read
, buffer
);
1869 * get network statistics for ifconfig and other user programs
1871 static struct net_device_stats
*
1872 lcs_getstats(struct net_device
*dev
)
1874 struct lcs_card
*card
;
1876 LCS_DBF_TEXT(4, trace
, "netstats");
1877 card
= (struct lcs_card
*) dev
->ml_priv
;
1878 return &card
->stats
;
1883 * This function will be called by user doing ifconfig xxx down
1886 lcs_stop_device(struct net_device
*dev
)
1888 struct lcs_card
*card
;
1891 LCS_DBF_TEXT(2, trace
, "stopdev");
1892 card
= (struct lcs_card
*) dev
->ml_priv
;
1893 netif_carrier_off(dev
);
1894 netif_tx_disable(dev
);
1895 dev
->flags
&= ~IFF_UP
;
1896 wait_event(card
->write
.wait_q
,
1897 (card
->write
.state
!= LCS_CH_STATE_RUNNING
));
1898 rc
= lcs_stopcard(card
);
1900 dev_err(&card
->dev
->dev
,
1901 " Shutting down the LCS device failed\n ");
1906 * start lcs device and make it runnable
1907 * This function will be called by user doing ifconfig xxx up
1910 lcs_open_device(struct net_device
*dev
)
1912 struct lcs_card
*card
;
1915 LCS_DBF_TEXT(2, trace
, "opendev");
1916 card
= (struct lcs_card
*) dev
->ml_priv
;
1917 /* initialize statistics */
1918 rc
= lcs_detect(card
);
1920 pr_err("Error in opening device!\n");
1923 dev
->flags
|= IFF_UP
;
1924 netif_carrier_on(dev
);
1925 netif_wake_queue(dev
);
1926 card
->state
= DEV_STATE_UP
;
1932 * show function for portno called by cat or similar things
1935 lcs_portno_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1937 struct lcs_card
*card
;
1939 card
= dev_get_drvdata(dev
);
1944 return sprintf(buf
, "%d\n", card
->portno
);
1948 * store the value which is piped to file portno
1951 lcs_portno_store (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1953 struct lcs_card
*card
;
1956 card
= dev_get_drvdata(dev
);
1961 sscanf(buf
, "%u", &value
);
1962 /* TODO: sanity checks */
1963 card
->portno
= value
;
1969 static DEVICE_ATTR(portno
, 0644, lcs_portno_show
, lcs_portno_store
);
1972 lcs_type_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1974 struct ccwgroup_device
*cgdev
;
1976 cgdev
= to_ccwgroupdev(dev
);
1980 return sprintf(buf
, "%s\n", cu3088_type
[cgdev
->cdev
[0]->id
.driver_info
]);
1983 static DEVICE_ATTR(type
, 0444, lcs_type_show
, NULL
);
1986 lcs_timeout_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1988 struct lcs_card
*card
;
1990 card
= dev_get_drvdata(dev
);
1992 return card
? sprintf(buf
, "%u\n", card
->lancmd_timeout
) : 0;
1996 lcs_timeout_store (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1998 struct lcs_card
*card
;
2001 card
= dev_get_drvdata(dev
);
2006 sscanf(buf
, "%u", &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
,
2044 static struct attribute_group lcs_attr_group
= {
2049 * lcs_probe_device is called on establishing a new ccwgroup_device.
2052 lcs_probe_device(struct ccwgroup_device
*ccwgdev
)
2054 struct lcs_card
*card
;
2057 if (!get_device(&ccwgdev
->dev
))
2060 LCS_DBF_TEXT(2, setup
, "add_dev");
2061 card
= lcs_alloc_card();
2063 LCS_DBF_TEXT_(2, setup
, " rc%d", -ENOMEM
);
2064 put_device(&ccwgdev
->dev
);
2067 ret
= sysfs_create_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2069 lcs_free_card(card
);
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;
2085 lcs_register_netdev(struct ccwgroup_device
*ccwgdev
)
2087 struct lcs_card
*card
;
2089 LCS_DBF_TEXT(2, setup
, "regnetdv");
2090 card
= dev_get_drvdata(&ccwgdev
->dev
);
2091 if (card
->dev
->reg_state
!= NETREG_UNINITIALIZED
)
2093 SET_NETDEV_DEV(card
->dev
, &ccwgdev
->dev
);
2094 return register_netdev(card
->dev
);
2098 * lcs_new_device will be called by setting the group device online.
2100 static const struct net_device_ops lcs_netdev_ops
= {
2101 .ndo_open
= lcs_open_device
,
2102 .ndo_stop
= lcs_stop_device
,
2103 .ndo_get_stats
= lcs_getstats
,
2104 .ndo_start_xmit
= lcs_start_xmit
,
2107 static const struct net_device_ops lcs_mc_netdev_ops
= {
2108 .ndo_open
= lcs_open_device
,
2109 .ndo_stop
= lcs_stop_device
,
2110 .ndo_get_stats
= lcs_getstats
,
2111 .ndo_start_xmit
= lcs_start_xmit
,
2112 .ndo_set_multicast_list
= lcs_set_multicast_list
,
2116 lcs_new_device(struct ccwgroup_device
*ccwgdev
)
2118 struct lcs_card
*card
;
2119 struct net_device
*dev
=NULL
;
2120 enum lcs_dev_states recover_state
;
2123 card
= dev_get_drvdata(&ccwgdev
->dev
);
2127 LCS_DBF_TEXT(2, setup
, "newdev");
2128 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2129 card
->read
.ccwdev
= ccwgdev
->cdev
[0];
2130 card
->write
.ccwdev
= ccwgdev
->cdev
[1];
2132 recover_state
= card
->state
;
2133 ccw_device_set_online(card
->read
.ccwdev
);
2134 ccw_device_set_online(card
->write
.ccwdev
);
2136 LCS_DBF_TEXT(3, setup
, "lcsnewdv");
2138 lcs_setup_card(card
);
2139 rc
= lcs_detect(card
);
2141 LCS_DBF_TEXT(2, setup
, "dtctfail");
2142 dev_err(&card
->dev
->dev
,
2143 "Detecting a network adapter for LCS devices"
2144 " failed with rc=%d (0x%x)\n", rc
, rc
);
2149 LCS_DBF_TEXT(2, setup
, "samedev");
2150 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2153 switch (card
->lan_type
) {
2154 #ifdef CONFIG_NET_ETHERNET
2155 case LCS_FRAME_TYPE_ENET
:
2156 card
->lan_type_trans
= eth_type_trans
;
2157 dev
= alloc_etherdev(0);
2161 case LCS_FRAME_TYPE_TR
:
2162 card
->lan_type_trans
= tr_type_trans
;
2163 dev
= alloc_trdev(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
->read
.ccwdev
);
2214 ccw_device_set_offline(card
->write
.ccwdev
);
2219 * lcs_shutdown_device, called when setting the group device offline.
2222 __lcs_shutdown_device(struct ccwgroup_device
*ccwgdev
, int recovery_mode
)
2224 struct lcs_card
*card
;
2225 enum lcs_dev_states recover_state
;
2228 LCS_DBF_TEXT(3, setup
, "shtdndev");
2229 card
= dev_get_drvdata(&ccwgdev
->dev
);
2232 if (recovery_mode
== 0) {
2233 lcs_set_allowed_threads(card
, 0);
2234 if (lcs_wait_for_threads(card
, LCS_SET_MC_THREAD
))
2235 return -ERESTARTSYS
;
2237 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2238 recover_state
= card
->state
;
2240 ret
= lcs_stop_device(card
->dev
);
2241 ret
= ccw_device_set_offline(card
->read
.ccwdev
);
2242 ret
= ccw_device_set_offline(card
->write
.ccwdev
);
2243 if (recover_state
== DEV_STATE_UP
) {
2244 card
->state
= DEV_STATE_RECOVER
;
2252 lcs_shutdown_device(struct ccwgroup_device
*ccwgdev
)
2254 return __lcs_shutdown_device(ccwgdev
, 0);
2258 * drive lcs recovery after startup and startlan initiated by Lan Gateway
2261 lcs_recovery(void *ptr
)
2263 struct lcs_card
*card
;
2264 struct ccwgroup_device
*gdev
;
2267 card
= (struct lcs_card
*) ptr
;
2269 LCS_DBF_TEXT(4, trace
, "recover1");
2270 if (!lcs_do_run_thread(card
, LCS_RECOVERY_THREAD
))
2272 LCS_DBF_TEXT(4, trace
, "recover2");
2274 dev_warn(&gdev
->dev
,
2275 "A recovery process has been started for the LCS device\n");
2276 rc
= __lcs_shutdown_device(gdev
, 1);
2277 rc
= lcs_new_device(gdev
);
2279 pr_info("Device %s successfully recovered!\n",
2282 pr_info("Device %s could not be recovered!\n",
2284 lcs_clear_thread_running_bit(card
, LCS_RECOVERY_THREAD
);
2289 * lcs_remove_device, free buffers and card
2292 lcs_remove_device(struct ccwgroup_device
*ccwgdev
)
2294 struct lcs_card
*card
;
2296 card
= dev_get_drvdata(&ccwgdev
->dev
);
2300 LCS_DBF_TEXT(3, setup
, "remdev");
2301 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2302 if (ccwgdev
->state
== CCWGROUP_ONLINE
) {
2303 lcs_shutdown_device(ccwgdev
);
2306 unregister_netdev(card
->dev
);
2307 sysfs_remove_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2308 lcs_cleanup_card(card
);
2309 lcs_free_card(card
);
2310 put_device(&ccwgdev
->dev
);
2313 static int lcs_pm_suspend(struct lcs_card
*card
)
2316 netif_device_detach(card
->dev
);
2317 lcs_set_allowed_threads(card
, 0);
2318 lcs_wait_for_threads(card
, 0xffffffff);
2319 if (card
->state
!= DEV_STATE_DOWN
)
2320 __lcs_shutdown_device(card
->gdev
, 1);
2324 static int lcs_pm_resume(struct lcs_card
*card
)
2328 if (card
->state
== DEV_STATE_RECOVER
)
2329 rc
= lcs_new_device(card
->gdev
);
2331 netif_device_attach(card
->dev
);
2333 dev_warn(&card
->gdev
->dev
, "The lcs device driver "
2334 "failed to recover the device\n");
2339 static int lcs_prepare(struct ccwgroup_device
*gdev
)
2344 static void lcs_complete(struct ccwgroup_device
*gdev
)
2349 static int lcs_freeze(struct ccwgroup_device
*gdev
)
2351 struct lcs_card
*card
= dev_get_drvdata(&gdev
->dev
);
2352 return lcs_pm_suspend(card
);
2355 static int lcs_thaw(struct ccwgroup_device
*gdev
)
2357 struct lcs_card
*card
= dev_get_drvdata(&gdev
->dev
);
2358 return lcs_pm_resume(card
);
2361 static int lcs_restore(struct ccwgroup_device
*gdev
)
2363 struct lcs_card
*card
= dev_get_drvdata(&gdev
->dev
);
2364 return lcs_pm_resume(card
);
2368 * LCS ccwgroup driver registration
2370 static struct ccwgroup_driver lcs_group_driver
= {
2371 .owner
= THIS_MODULE
,
2374 .driver_id
= 0xD3C3E2,
2375 .probe
= lcs_probe_device
,
2376 .remove
= lcs_remove_device
,
2377 .set_online
= lcs_new_device
,
2378 .set_offline
= lcs_shutdown_device
,
2379 .prepare
= lcs_prepare
,
2380 .complete
= lcs_complete
,
2381 .freeze
= lcs_freeze
,
2383 .restore
= lcs_restore
,
2387 * LCS Module/Kernel initialization function
2390 __init
lcs_init_module(void)
2394 pr_info("Loading %s\n", version
);
2395 rc
= lcs_register_debug_facility();
2396 LCS_DBF_TEXT(0, setup
, "lcsinit");
2398 pr_err("Initialization failed\n");
2402 rc
= register_cu3088_discipline(&lcs_group_driver
);
2404 pr_err("Initialization failed\n");
2412 * LCS module cleanup function
2415 __exit
lcs_cleanup_module(void)
2417 pr_info("Terminating lcs module.\n");
2418 LCS_DBF_TEXT(0, trace
, "cleanup");
2419 unregister_cu3088_discipline(&lcs_group_driver
);
2420 lcs_unregister_debug_facility();
2423 module_init(lcs_init_module
);
2424 module_exit(lcs_cleanup_module
);
2426 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
2427 MODULE_LICENSE("GPL");