2 * linux/drivers/s390/net/lcs.c
4 * Linux for S/390 Lan Channel Station Network Driver
6 * Copyright (C) 1999-2001 IBM Deutschland Entwicklung GmbH,
8 * Author(s): Original Code written by
9 * DJ Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
11 * Frank Pavlic (fpavlic@de.ibm.com) and
12 * Martin Schwidefsky <schwidefsky@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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>
42 #include <asm/debug.h>
43 #include <asm/idals.h>
44 #include <asm/timex.h>
45 #include <linux/device.h>
46 #include <asm/ccwgroup.h>
52 #if !defined(CONFIG_NET_ETHERNET) && \
53 !defined(CONFIG_TR) && !defined(CONFIG_FDDI)
54 #error Cannot compile lcs.c without some net devices switched on.
58 * initialization string for output
61 static char version
[] __initdata
= "LCS driver";
62 static char debug_buffer
[255];
67 static void lcs_tasklet(unsigned long);
68 static void lcs_start_kernel_thread(struct lcs_card
*card
);
69 static void lcs_get_frames_cb(struct lcs_channel
*, struct lcs_buffer
*);
70 static int lcs_send_delipm(struct lcs_card
*, struct lcs_ipm_list
*);
71 static int lcs_recovery(void *ptr
);
74 * Debug Facility Stuff
76 static debug_info_t
*lcs_dbf_setup
;
77 static debug_info_t
*lcs_dbf_trace
;
80 * LCS Debug Facility functions
83 lcs_unregister_debug_facility(void)
86 debug_unregister(lcs_dbf_setup
);
88 debug_unregister(lcs_dbf_trace
);
92 lcs_register_debug_facility(void)
94 lcs_dbf_setup
= debug_register("lcs_setup", 2, 1, 8);
95 lcs_dbf_trace
= debug_register("lcs_trace", 2, 2, 8);
96 if (lcs_dbf_setup
== NULL
|| lcs_dbf_trace
== NULL
) {
97 PRINT_ERR("Not enough memory for debug facility.\n");
98 lcs_unregister_debug_facility();
101 debug_register_view(lcs_dbf_setup
, &debug_hex_ascii_view
);
102 debug_set_level(lcs_dbf_setup
, 2);
103 debug_register_view(lcs_dbf_trace
, &debug_hex_ascii_view
);
104 debug_set_level(lcs_dbf_trace
, 2);
109 * Allocate io buffers.
112 lcs_alloc_channel(struct lcs_channel
*channel
)
116 LCS_DBF_TEXT(2, setup
, "ichalloc");
117 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
118 /* alloc memory fo iobuffer */
119 channel
->iob
[cnt
].data
=
120 kzalloc(LCS_IOBUFFERSIZE
, GFP_DMA
| GFP_KERNEL
);
121 if (channel
->iob
[cnt
].data
== NULL
)
123 channel
->iob
[cnt
].state
= BUF_STATE_EMPTY
;
125 if (cnt
< LCS_NUM_BUFFS
) {
126 /* Not all io buffers could be allocated. */
127 LCS_DBF_TEXT(2, setup
, "echalloc");
129 kfree(channel
->iob
[cnt
].data
);
139 lcs_free_channel(struct lcs_channel
*channel
)
143 LCS_DBF_TEXT(2, setup
, "ichfree");
144 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
145 kfree(channel
->iob
[cnt
].data
);
146 channel
->iob
[cnt
].data
= NULL
;
154 lcs_cleanup_channel(struct lcs_channel
*channel
)
156 LCS_DBF_TEXT(3, setup
, "cleanch");
157 /* Kill write channel tasklets. */
158 tasklet_kill(&channel
->irq_tasklet
);
159 /* Free channel buffers. */
160 lcs_free_channel(channel
);
164 * LCS free memory for card and channels.
167 lcs_free_card(struct lcs_card
*card
)
169 LCS_DBF_TEXT(2, setup
, "remcard");
170 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
175 * LCS alloc memory for card and channels
177 static struct lcs_card
*
180 struct lcs_card
*card
;
183 LCS_DBF_TEXT(2, setup
, "alloclcs");
185 card
= kzalloc(sizeof(struct lcs_card
), GFP_KERNEL
| GFP_DMA
);
188 card
->lan_type
= LCS_FRAME_TYPE_AUTO
;
190 card
->lancmd_timeout
= LCS_LANCMD_TIMEOUT_DEFAULT
;
191 /* Allocate io buffers for the read channel. */
192 rc
= lcs_alloc_channel(&card
->read
);
194 LCS_DBF_TEXT(2, setup
, "iccwerr");
198 /* Allocate io buffers for the write channel. */
199 rc
= lcs_alloc_channel(&card
->write
);
201 LCS_DBF_TEXT(2, setup
, "iccwerr");
202 lcs_cleanup_channel(&card
->read
);
207 #ifdef CONFIG_IP_MULTICAST
208 INIT_LIST_HEAD(&card
->ipm_list
);
210 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
215 * Setup read channel.
218 lcs_setup_read_ccws(struct lcs_card
*card
)
222 LCS_DBF_TEXT(2, setup
, "ireadccw");
223 /* Setup read ccws. */
224 memset(card
->read
.ccws
, 0, sizeof (struct ccw1
) * (LCS_NUM_BUFFS
+ 1));
225 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
226 card
->read
.ccws
[cnt
].cmd_code
= LCS_CCW_READ
;
227 card
->read
.ccws
[cnt
].count
= LCS_IOBUFFERSIZE
;
228 card
->read
.ccws
[cnt
].flags
=
229 CCW_FLAG_CC
| CCW_FLAG_SLI
| CCW_FLAG_PCI
;
231 * Note: we have allocated the buffer with GFP_DMA, so
232 * we do not need to do set_normalized_cda.
234 card
->read
.ccws
[cnt
].cda
=
235 (__u32
) __pa(card
->read
.iob
[cnt
].data
);
236 ((struct lcs_header
*)
237 card
->read
.iob
[cnt
].data
)->offset
= LCS_ILLEGAL_OFFSET
;
238 card
->read
.iob
[cnt
].callback
= lcs_get_frames_cb
;
239 card
->read
.iob
[cnt
].state
= BUF_STATE_READY
;
240 card
->read
.iob
[cnt
].count
= LCS_IOBUFFERSIZE
;
242 card
->read
.ccws
[0].flags
&= ~CCW_FLAG_PCI
;
243 card
->read
.ccws
[LCS_NUM_BUFFS
- 1].flags
&= ~CCW_FLAG_PCI
;
244 card
->read
.ccws
[LCS_NUM_BUFFS
- 1].flags
|= CCW_FLAG_SUSPEND
;
245 /* Last ccw is a tic (transfer in channel). */
246 card
->read
.ccws
[LCS_NUM_BUFFS
].cmd_code
= LCS_CCW_TRANSFER
;
247 card
->read
.ccws
[LCS_NUM_BUFFS
].cda
=
248 (__u32
) __pa(card
->read
.ccws
);
249 /* Setg initial state of the read channel. */
250 card
->read
.state
= CH_STATE_INIT
;
252 card
->read
.io_idx
= 0;
253 card
->read
.buf_idx
= 0;
257 lcs_setup_read(struct lcs_card
*card
)
259 LCS_DBF_TEXT(3, setup
, "initread");
261 lcs_setup_read_ccws(card
);
262 /* Initialize read channel tasklet. */
263 card
->read
.irq_tasklet
.data
= (unsigned long) &card
->read
;
264 card
->read
.irq_tasklet
.func
= lcs_tasklet
;
265 /* Initialize waitqueue. */
266 init_waitqueue_head(&card
->read
.wait_q
);
270 * Setup write channel.
273 lcs_setup_write_ccws(struct lcs_card
*card
)
277 LCS_DBF_TEXT(3, setup
, "iwritccw");
278 /* Setup write ccws. */
279 memset(card
->write
.ccws
, 0, sizeof(struct ccw1
) * LCS_NUM_BUFFS
+ 1);
280 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
281 card
->write
.ccws
[cnt
].cmd_code
= LCS_CCW_WRITE
;
282 card
->write
.ccws
[cnt
].count
= 0;
283 card
->write
.ccws
[cnt
].flags
=
284 CCW_FLAG_SUSPEND
| CCW_FLAG_CC
| CCW_FLAG_SLI
;
286 * Note: we have allocated the buffer with GFP_DMA, so
287 * we do not need to do set_normalized_cda.
289 card
->write
.ccws
[cnt
].cda
=
290 (__u32
) __pa(card
->write
.iob
[cnt
].data
);
292 /* Last ccw is a tic (transfer in channel). */
293 card
->write
.ccws
[LCS_NUM_BUFFS
].cmd_code
= LCS_CCW_TRANSFER
;
294 card
->write
.ccws
[LCS_NUM_BUFFS
].cda
=
295 (__u32
) __pa(card
->write
.ccws
);
296 /* Set initial state of the write channel. */
297 card
->read
.state
= CH_STATE_INIT
;
299 card
->write
.io_idx
= 0;
300 card
->write
.buf_idx
= 0;
304 lcs_setup_write(struct lcs_card
*card
)
306 LCS_DBF_TEXT(3, setup
, "initwrit");
308 lcs_setup_write_ccws(card
);
309 /* Initialize write channel tasklet. */
310 card
->write
.irq_tasklet
.data
= (unsigned long) &card
->write
;
311 card
->write
.irq_tasklet
.func
= lcs_tasklet
;
312 /* Initialize waitqueue. */
313 init_waitqueue_head(&card
->write
.wait_q
);
317 lcs_set_allowed_threads(struct lcs_card
*card
, unsigned long threads
)
321 spin_lock_irqsave(&card
->mask_lock
, flags
);
322 card
->thread_allowed_mask
= threads
;
323 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
324 wake_up(&card
->wait_q
);
327 lcs_threads_running(struct lcs_card
*card
, unsigned long threads
)
332 spin_lock_irqsave(&card
->mask_lock
, flags
);
333 rc
= (card
->thread_running_mask
& threads
);
334 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
339 lcs_wait_for_threads(struct lcs_card
*card
, unsigned long threads
)
341 return wait_event_interruptible(card
->wait_q
,
342 lcs_threads_running(card
, threads
) == 0);
346 lcs_set_thread_start_bit(struct lcs_card
*card
, unsigned long thread
)
350 spin_lock_irqsave(&card
->mask_lock
, flags
);
351 if ( !(card
->thread_allowed_mask
& thread
) ||
352 (card
->thread_start_mask
& thread
) ) {
353 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
356 card
->thread_start_mask
|= thread
;
357 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
362 lcs_clear_thread_running_bit(struct lcs_card
*card
, unsigned long thread
)
366 spin_lock_irqsave(&card
->mask_lock
, flags
);
367 card
->thread_running_mask
&= ~thread
;
368 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
369 wake_up(&card
->wait_q
);
373 __lcs_do_run_thread(struct lcs_card
*card
, unsigned long thread
)
378 spin_lock_irqsave(&card
->mask_lock
, flags
);
379 if (card
->thread_start_mask
& thread
){
380 if ((card
->thread_allowed_mask
& thread
) &&
381 !(card
->thread_running_mask
& thread
)){
383 card
->thread_start_mask
&= ~thread
;
384 card
->thread_running_mask
|= thread
;
388 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
393 lcs_do_run_thread(struct lcs_card
*card
, unsigned long thread
)
396 wait_event(card
->wait_q
,
397 (rc
= __lcs_do_run_thread(card
, thread
)) >= 0);
402 lcs_do_start_thread(struct lcs_card
*card
, unsigned long thread
)
407 spin_lock_irqsave(&card
->mask_lock
, flags
);
408 LCS_DBF_TEXT_(4, trace
, " %02x%02x%02x",
409 (u8
) card
->thread_start_mask
,
410 (u8
) card
->thread_allowed_mask
,
411 (u8
) card
->thread_running_mask
);
412 rc
= (card
->thread_start_mask
& thread
);
413 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
418 * Initialize channels,card and state machines.
421 lcs_setup_card(struct lcs_card
*card
)
423 LCS_DBF_TEXT(2, setup
, "initcard");
424 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
426 lcs_setup_read(card
);
427 lcs_setup_write(card
);
428 /* Set cards initial state. */
429 card
->state
= DEV_STATE_DOWN
;
430 card
->tx_buffer
= NULL
;
431 card
->tx_emitted
= 0;
433 init_waitqueue_head(&card
->wait_q
);
434 spin_lock_init(&card
->lock
);
435 spin_lock_init(&card
->ipm_lock
);
436 spin_lock_init(&card
->mask_lock
);
437 #ifdef CONFIG_IP_MULTICAST
438 INIT_LIST_HEAD(&card
->ipm_list
);
440 INIT_LIST_HEAD(&card
->lancmd_waiters
);
444 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", channel
->ccwdev
->dev
.bus_id
);
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
= CH_STATE_RUNNING
;
500 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
502 LCS_DBF_TEXT_(4,trace
,"essh%s", channel
->ccwdev
->dev
.bus_id
);
503 PRINT_ERR("Error in starting channel, rc=%d!\n", rc
);
509 lcs_clear_channel(struct lcs_channel
*channel
)
514 LCS_DBF_TEXT(4,trace
,"clearch");
515 LCS_DBF_TEXT_(4,trace
,"%s", channel
->ccwdev
->dev
.bus_id
);
516 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
517 rc
= ccw_device_clear(channel
->ccwdev
, (addr_t
) channel
);
518 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
520 LCS_DBF_TEXT_(4,trace
,"ecsc%s", channel
->ccwdev
->dev
.bus_id
);
523 wait_event(channel
->wait_q
, (channel
->state
== CH_STATE_CLEARED
));
524 channel
->state
= CH_STATE_STOPPED
;
533 lcs_stop_channel(struct lcs_channel
*channel
)
538 if (channel
->state
== CH_STATE_STOPPED
)
540 LCS_DBF_TEXT(4,trace
,"haltsch");
541 LCS_DBF_TEXT_(4,trace
,"%s", channel
->ccwdev
->dev
.bus_id
);
542 channel
->state
= CH_STATE_INIT
;
543 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
544 rc
= ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
545 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
547 LCS_DBF_TEXT_(4,trace
,"ehsc%s", channel
->ccwdev
->dev
.bus_id
);
550 /* Asynchronous halt initialted. Wait for its completion. */
551 wait_event(channel
->wait_q
, (channel
->state
== CH_STATE_HALTED
));
552 lcs_clear_channel(channel
);
557 * start read and write channel
560 lcs_start_channels(struct lcs_card
*card
)
564 LCS_DBF_TEXT(2, trace
, "chstart");
565 /* start read channel */
566 rc
= lcs_start_channel(&card
->read
);
569 /* start write channel */
570 rc
= lcs_start_channel(&card
->write
);
572 lcs_stop_channel(&card
->read
);
577 * stop read and write channel
580 lcs_stop_channels(struct lcs_card
*card
)
582 LCS_DBF_TEXT(2, trace
, "chhalt");
583 lcs_stop_channel(&card
->read
);
584 lcs_stop_channel(&card
->write
);
591 static struct lcs_buffer
*
592 __lcs_get_buffer(struct lcs_channel
*channel
)
596 LCS_DBF_TEXT(5, trace
, "_getbuff");
597 index
= channel
->io_idx
;
599 if (channel
->iob
[index
].state
== BUF_STATE_EMPTY
) {
600 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
601 return channel
->iob
+ index
;
603 index
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
604 } while (index
!= channel
->io_idx
);
608 static struct lcs_buffer
*
609 lcs_get_buffer(struct lcs_channel
*channel
)
611 struct lcs_buffer
*buffer
;
614 LCS_DBF_TEXT(5, trace
, "getbuff");
615 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
616 buffer
= __lcs_get_buffer(channel
);
617 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
622 * Resume channel program if the channel is suspended.
625 __lcs_resume_channel(struct lcs_channel
*channel
)
629 if (channel
->state
!= CH_STATE_SUSPENDED
)
631 if (channel
->ccws
[channel
->io_idx
].flags
& CCW_FLAG_SUSPEND
)
633 LCS_DBF_TEXT_(5, trace
, "rsch%s", channel
->ccwdev
->dev
.bus_id
);
634 rc
= ccw_device_resume(channel
->ccwdev
);
636 LCS_DBF_TEXT_(4, trace
, "ersc%s", channel
->ccwdev
->dev
.bus_id
);
637 PRINT_ERR("Error in lcs_resume_channel: rc=%d\n",rc
);
639 channel
->state
= CH_STATE_RUNNING
;
645 * Make a buffer ready for processing.
648 __lcs_ready_buffer_bits(struct lcs_channel
*channel
, int index
)
652 LCS_DBF_TEXT(5, trace
, "rdybits");
653 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
654 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
655 /* Check if we may clear the suspend bit of this buffer. */
656 if (channel
->ccws
[next
].flags
& CCW_FLAG_SUSPEND
) {
657 /* Check if we have to set the PCI bit. */
658 if (!(channel
->ccws
[prev
].flags
& CCW_FLAG_SUSPEND
))
659 /* Suspend bit of the previous buffer is not set. */
660 channel
->ccws
[index
].flags
|= CCW_FLAG_PCI
;
661 /* Suspend bit of the next buffer is set. */
662 channel
->ccws
[index
].flags
&= ~CCW_FLAG_SUSPEND
;
667 lcs_ready_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
672 LCS_DBF_TEXT(5, trace
, "rdybuff");
673 BUG_ON(buffer
->state
!= BUF_STATE_LOCKED
&&
674 buffer
->state
!= BUF_STATE_PROCESSED
);
675 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
676 buffer
->state
= BUF_STATE_READY
;
677 index
= buffer
- channel
->iob
;
679 channel
->ccws
[index
].count
= buffer
->count
;
680 /* Check relevant PCI/suspend bits. */
681 __lcs_ready_buffer_bits(channel
, index
);
682 rc
= __lcs_resume_channel(channel
);
683 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
688 * Mark the buffer as processed. Take care of the suspend bit
689 * of the previous buffer. This function is called from
690 * interrupt context, so the lock must not be taken.
693 __lcs_processed_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
695 int index
, prev
, next
;
697 LCS_DBF_TEXT(5, trace
, "prcsbuff");
698 BUG_ON(buffer
->state
!= BUF_STATE_READY
);
699 buffer
->state
= BUF_STATE_PROCESSED
;
700 index
= buffer
- channel
->iob
;
701 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
702 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
703 /* Set the suspend bit and clear the PCI bit of this buffer. */
704 channel
->ccws
[index
].flags
|= CCW_FLAG_SUSPEND
;
705 channel
->ccws
[index
].flags
&= ~CCW_FLAG_PCI
;
706 /* Check the suspend bit of the previous buffer. */
707 if (channel
->iob
[prev
].state
== BUF_STATE_READY
) {
709 * Previous buffer is in state ready. It might have
710 * happened in lcs_ready_buffer that the suspend bit
711 * has not been cleared to avoid an endless loop.
714 __lcs_ready_buffer_bits(channel
, prev
);
716 /* Clear PCI bit of next buffer. */
717 channel
->ccws
[next
].flags
&= ~CCW_FLAG_PCI
;
718 return __lcs_resume_channel(channel
);
722 * Put a processed buffer back to state empty.
725 lcs_release_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
729 LCS_DBF_TEXT(5, trace
, "relbuff");
730 BUG_ON(buffer
->state
!= BUF_STATE_LOCKED
&&
731 buffer
->state
!= BUF_STATE_PROCESSED
);
732 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
733 buffer
->state
= BUF_STATE_EMPTY
;
734 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
738 * Get buffer for a lan command.
740 static struct lcs_buffer
*
741 lcs_get_lancmd(struct lcs_card
*card
, int count
)
743 struct lcs_buffer
*buffer
;
746 LCS_DBF_TEXT(4, trace
, "getlncmd");
747 /* Get buffer and wait if none is available. */
748 wait_event(card
->write
.wait_q
,
749 ((buffer
= lcs_get_buffer(&card
->write
)) != NULL
));
750 count
+= sizeof(struct lcs_header
);
751 *(__u16
*)(buffer
->data
+ count
) = 0;
752 buffer
->count
= count
+ sizeof(__u16
);
753 buffer
->callback
= lcs_release_buffer
;
754 cmd
= (struct lcs_cmd
*) buffer
->data
;
756 cmd
->type
= LCS_FRAME_TYPE_CONTROL
;
763 lcs_get_reply(struct lcs_reply
*reply
)
765 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
766 atomic_inc(&reply
->refcnt
);
770 lcs_put_reply(struct lcs_reply
*reply
)
772 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
773 if (atomic_dec_and_test(&reply
->refcnt
)) {
779 static struct lcs_reply
*
780 lcs_alloc_reply(struct lcs_cmd
*cmd
)
782 struct lcs_reply
*reply
;
784 LCS_DBF_TEXT(4, trace
, "getreply");
786 reply
= kzalloc(sizeof(struct lcs_reply
), GFP_ATOMIC
);
789 atomic_set(&reply
->refcnt
,1);
790 reply
->sequence_no
= cmd
->sequence_no
;
793 init_waitqueue_head(&reply
->wait_q
);
799 * Notifier function for lancmd replies. Called from read irq.
802 lcs_notify_lancmd_waiters(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
804 struct list_head
*l
, *n
;
805 struct lcs_reply
*reply
;
807 LCS_DBF_TEXT(4, trace
, "notiwait");
808 spin_lock(&card
->lock
);
809 list_for_each_safe(l
, n
, &card
->lancmd_waiters
) {
810 reply
= list_entry(l
, struct lcs_reply
, list
);
811 if (reply
->sequence_no
== cmd
->sequence_no
) {
812 lcs_get_reply(reply
);
813 list_del_init(&reply
->list
);
814 if (reply
->callback
!= NULL
)
815 reply
->callback(card
, cmd
);
817 reply
->rc
= cmd
->return_code
;
818 wake_up(&reply
->wait_q
);
819 lcs_put_reply(reply
);
823 spin_unlock(&card
->lock
);
827 * Emit buffer of a lan comand.
830 lcs_lancmd_timeout(unsigned long data
)
832 struct lcs_reply
*reply
, *list_reply
, *r
;
835 LCS_DBF_TEXT(4, trace
, "timeout");
836 reply
= (struct lcs_reply
*) data
;
837 spin_lock_irqsave(&reply
->card
->lock
, flags
);
838 list_for_each_entry_safe(list_reply
, r
,
839 &reply
->card
->lancmd_waiters
,list
) {
840 if (reply
== list_reply
) {
841 lcs_get_reply(reply
);
842 list_del_init(&reply
->list
);
843 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
846 wake_up(&reply
->wait_q
);
847 lcs_put_reply(reply
);
851 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
855 lcs_send_lancmd(struct lcs_card
*card
, struct lcs_buffer
*buffer
,
856 void (*reply_callback
)(struct lcs_card
*, struct lcs_cmd
*))
858 struct lcs_reply
*reply
;
860 struct timer_list timer
;
864 LCS_DBF_TEXT(4, trace
, "sendcmd");
865 cmd
= (struct lcs_cmd
*) buffer
->data
;
866 cmd
->return_code
= 0;
867 cmd
->sequence_no
= card
->sequence_no
++;
868 reply
= lcs_alloc_reply(cmd
);
871 reply
->callback
= reply_callback
;
873 spin_lock_irqsave(&card
->lock
, flags
);
874 list_add_tail(&reply
->list
, &card
->lancmd_waiters
);
875 spin_unlock_irqrestore(&card
->lock
, flags
);
877 buffer
->callback
= lcs_release_buffer
;
878 rc
= lcs_ready_buffer(&card
->write
, buffer
);
882 timer
.function
= lcs_lancmd_timeout
;
883 timer
.data
= (unsigned long) reply
;
884 timer
.expires
= jiffies
+ HZ
*card
->lancmd_timeout
;
886 wait_event(reply
->wait_q
, reply
->received
);
887 del_timer_sync(&timer
);
888 LCS_DBF_TEXT_(4, trace
, "rc:%d",reply
->rc
);
890 lcs_put_reply(reply
);
891 return rc
? -EIO
: 0;
895 * LCS startup command
898 lcs_send_startup(struct lcs_card
*card
, __u8 initiator
)
900 struct lcs_buffer
*buffer
;
903 LCS_DBF_TEXT(2, trace
, "startup");
904 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
905 cmd
= (struct lcs_cmd
*) buffer
->data
;
906 cmd
->cmd_code
= LCS_CMD_STARTUP
;
907 cmd
->initiator
= initiator
;
908 cmd
->cmd
.lcs_startup
.buff_size
= LCS_IOBUFFERSIZE
;
909 return lcs_send_lancmd(card
, buffer
, NULL
);
913 * LCS shutdown command
916 lcs_send_shutdown(struct lcs_card
*card
)
918 struct lcs_buffer
*buffer
;
921 LCS_DBF_TEXT(2, trace
, "shutdown");
922 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
923 cmd
= (struct lcs_cmd
*) buffer
->data
;
924 cmd
->cmd_code
= LCS_CMD_SHUTDOWN
;
925 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
926 return lcs_send_lancmd(card
, buffer
, NULL
);
930 * LCS lanstat command
933 __lcs_lanstat_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
935 LCS_DBF_TEXT(2, trace
, "statcb");
936 memcpy(card
->mac
, cmd
->cmd
.lcs_lanstat_cmd
.mac_addr
, LCS_MAC_LENGTH
);
940 lcs_send_lanstat(struct lcs_card
*card
)
942 struct lcs_buffer
*buffer
;
945 LCS_DBF_TEXT(2,trace
, "cmdstat");
946 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
947 cmd
= (struct lcs_cmd
*) buffer
->data
;
948 /* Setup lanstat command. */
949 cmd
->cmd_code
= LCS_CMD_LANSTAT
;
950 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
951 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
952 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
953 return lcs_send_lancmd(card
, buffer
, __lcs_lanstat_cb
);
957 * send stoplan command
960 lcs_send_stoplan(struct lcs_card
*card
, __u8 initiator
)
962 struct lcs_buffer
*buffer
;
965 LCS_DBF_TEXT(2, trace
, "cmdstpln");
966 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
967 cmd
= (struct lcs_cmd
*) buffer
->data
;
968 cmd
->cmd_code
= LCS_CMD_STOPLAN
;
969 cmd
->initiator
= initiator
;
970 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
971 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
972 return lcs_send_lancmd(card
, buffer
, NULL
);
976 * send startlan command
979 __lcs_send_startlan_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
981 LCS_DBF_TEXT(2, trace
, "srtlancb");
982 card
->lan_type
= cmd
->cmd
.lcs_std_cmd
.lan_type
;
983 card
->portno
= cmd
->cmd
.lcs_std_cmd
.portno
;
987 lcs_send_startlan(struct lcs_card
*card
, __u8 initiator
)
989 struct lcs_buffer
*buffer
;
992 LCS_DBF_TEXT(2, trace
, "cmdstaln");
993 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
994 cmd
= (struct lcs_cmd
*) buffer
->data
;
995 cmd
->cmd_code
= LCS_CMD_STARTLAN
;
996 cmd
->initiator
= initiator
;
997 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
998 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
999 return lcs_send_lancmd(card
, buffer
, __lcs_send_startlan_cb
);
1002 #ifdef CONFIG_IP_MULTICAST
1004 * send setipm command (Multicast)
1007 lcs_send_setipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1009 struct lcs_buffer
*buffer
;
1010 struct lcs_cmd
*cmd
;
1012 LCS_DBF_TEXT(2, trace
, "cmdsetim");
1013 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1014 cmd
= (struct lcs_cmd
*) buffer
->data
;
1015 cmd
->cmd_code
= LCS_CMD_SETIPM
;
1016 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1017 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1018 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1019 cmd
->cmd
.lcs_qipassist
.version
= 4;
1020 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1021 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1022 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1023 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1024 return lcs_send_lancmd(card
, buffer
, NULL
);
1028 * send delipm command (Multicast)
1031 lcs_send_delipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1033 struct lcs_buffer
*buffer
;
1034 struct lcs_cmd
*cmd
;
1036 LCS_DBF_TEXT(2, trace
, "cmddelim");
1037 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1038 cmd
= (struct lcs_cmd
*) buffer
->data
;
1039 cmd
->cmd_code
= LCS_CMD_DELIPM
;
1040 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1041 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1042 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1043 cmd
->cmd
.lcs_qipassist
.version
= 4;
1044 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1045 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1046 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1047 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1048 return lcs_send_lancmd(card
, buffer
, NULL
);
1052 * check if multicast is supported by LCS
1055 __lcs_check_multicast_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1057 LCS_DBF_TEXT(2, trace
, "chkmccb");
1058 card
->ip_assists_supported
=
1059 cmd
->cmd
.lcs_qipassist
.ip_assists_supported
;
1060 card
->ip_assists_enabled
=
1061 cmd
->cmd
.lcs_qipassist
.ip_assists_enabled
;
1065 lcs_check_multicast_support(struct lcs_card
*card
)
1067 struct lcs_buffer
*buffer
;
1068 struct lcs_cmd
*cmd
;
1071 LCS_DBF_TEXT(2, trace
, "cmdqipa");
1072 /* Send query ipassist. */
1073 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
1074 cmd
= (struct lcs_cmd
*) buffer
->data
;
1075 cmd
->cmd_code
= LCS_CMD_QIPASSIST
;
1076 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1077 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1078 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1079 cmd
->cmd
.lcs_qipassist
.version
= 4;
1080 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1081 rc
= lcs_send_lancmd(card
, buffer
, __lcs_check_multicast_cb
);
1083 PRINT_ERR("Query IPAssist failed. Assuming unsupported!\n");
1086 if (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
)
1092 * set or del multicast address on LCS card
1095 lcs_fix_multicast_list(struct lcs_card
*card
)
1097 struct list_head failed_list
;
1098 struct lcs_ipm_list
*ipm
, *tmp
;
1099 unsigned long flags
;
1102 LCS_DBF_TEXT(4,trace
, "fixipm");
1103 INIT_LIST_HEAD(&failed_list
);
1104 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1106 list_for_each_entry_safe(ipm
, tmp
, &card
->ipm_list
, list
){
1107 switch (ipm
->ipm_state
) {
1108 case LCS_IPM_STATE_SET_REQUIRED
:
1109 /* del from ipm_list so noone else can tamper with
1111 list_del_init(&ipm
->list
);
1112 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1113 rc
= lcs_send_setipm(card
, ipm
);
1114 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1116 PRINT_INFO("Adding multicast address failed."
1117 "Table possibly full!\n");
1118 /* store ipm in failed list -> will be added
1119 * to ipm_list again, so a retry will be done
1120 * during the next call of this function */
1121 list_add_tail(&ipm
->list
, &failed_list
);
1123 ipm
->ipm_state
= LCS_IPM_STATE_ON_CARD
;
1124 /* re-insert into ipm_list */
1125 list_add_tail(&ipm
->list
, &card
->ipm_list
);
1128 case LCS_IPM_STATE_DEL_REQUIRED
:
1129 list_del(&ipm
->list
);
1130 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1131 lcs_send_delipm(card
, ipm
);
1132 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1135 case LCS_IPM_STATE_ON_CARD
:
1139 /* re-insert all entries from the failed_list into ipm_list */
1140 list_for_each_entry_safe(ipm
, tmp
, &failed_list
, list
)
1141 list_move_tail(&ipm
->list
, &card
->ipm_list
);
1143 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1147 * get mac address for the relevant Multicast address
1150 lcs_get_mac_for_ipm(__be32 ipm
, char *mac
, struct net_device
*dev
)
1152 LCS_DBF_TEXT(4,trace
, "getmac");
1153 if (dev
->type
== ARPHRD_IEEE802_TR
)
1154 ip_tr_mc_map(ipm
, mac
);
1156 ip_eth_mc_map(ipm
, mac
);
1160 * function called by net device to handle multicast address relevant things
1163 lcs_remove_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1165 struct ip_mc_list
*im4
;
1166 struct list_head
*l
;
1167 struct lcs_ipm_list
*ipm
;
1168 unsigned long flags
;
1169 char buf
[MAX_ADDR_LEN
];
1171 LCS_DBF_TEXT(4, trace
, "remmclst");
1172 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1173 list_for_each(l
, &card
->ipm_list
) {
1174 ipm
= list_entry(l
, struct lcs_ipm_list
, list
);
1175 for (im4
= in4_dev
->mc_list
; im4
!= NULL
; im4
= im4
->next
) {
1176 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1177 if ( (ipm
->ipm
.ip_addr
== im4
->multiaddr
) &&
1178 (memcmp(buf
, &ipm
->ipm
.mac_addr
,
1179 LCS_MAC_LENGTH
) == 0) )
1183 ipm
->ipm_state
= LCS_IPM_STATE_DEL_REQUIRED
;
1185 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1188 static inline struct lcs_ipm_list
*
1189 lcs_check_addr_entry(struct lcs_card
*card
, struct ip_mc_list
*im4
, char *buf
)
1191 struct lcs_ipm_list
*tmp
, *ipm
= NULL
;
1192 struct list_head
*l
;
1193 unsigned long flags
;
1195 LCS_DBF_TEXT(4, trace
, "chkmcent");
1196 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1197 list_for_each(l
, &card
->ipm_list
) {
1198 tmp
= list_entry(l
, struct lcs_ipm_list
, list
);
1199 if ( (tmp
->ipm
.ip_addr
== im4
->multiaddr
) &&
1200 (memcmp(buf
, &tmp
->ipm
.mac_addr
,
1201 LCS_MAC_LENGTH
) == 0) ) {
1206 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1211 lcs_set_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1214 struct ip_mc_list
*im4
;
1215 struct lcs_ipm_list
*ipm
;
1216 char buf
[MAX_ADDR_LEN
];
1217 unsigned long flags
;
1219 LCS_DBF_TEXT(4, trace
, "setmclst");
1220 for (im4
= in4_dev
->mc_list
; im4
; im4
= im4
->next
) {
1221 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1222 ipm
= lcs_check_addr_entry(card
, im4
, buf
);
1224 continue; /* Address already in list. */
1225 ipm
= (struct lcs_ipm_list
*)
1226 kzalloc(sizeof(struct lcs_ipm_list
), GFP_ATOMIC
);
1228 PRINT_INFO("Not enough memory to add "
1229 "new multicast entry!\n");
1232 memcpy(&ipm
->ipm
.mac_addr
, buf
, LCS_MAC_LENGTH
);
1233 ipm
->ipm
.ip_addr
= im4
->multiaddr
;
1234 ipm
->ipm_state
= LCS_IPM_STATE_SET_REQUIRED
;
1235 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1236 LCS_DBF_HEX(2,trace
,&ipm
->ipm
.ip_addr
,4);
1237 list_add(&ipm
->list
, &card
->ipm_list
);
1238 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1243 lcs_register_mc_addresses(void *data
)
1245 struct lcs_card
*card
;
1246 struct in_device
*in4_dev
;
1248 card
= (struct lcs_card
*) data
;
1249 daemonize("regipm");
1251 if (!lcs_do_run_thread(card
, LCS_SET_MC_THREAD
))
1253 LCS_DBF_TEXT(4, trace
, "regmulti");
1255 in4_dev
= in_dev_get(card
->dev
);
1256 if (in4_dev
== NULL
)
1258 read_lock(&in4_dev
->mc_list_lock
);
1259 lcs_remove_mc_addresses(card
,in4_dev
);
1260 lcs_set_mc_addresses(card
, in4_dev
);
1261 read_unlock(&in4_dev
->mc_list_lock
);
1262 in_dev_put(in4_dev
);
1264 netif_carrier_off(card
->dev
);
1265 netif_tx_disable(card
->dev
);
1266 wait_event(card
->write
.wait_q
,
1267 (card
->write
.state
!= CH_STATE_RUNNING
));
1268 lcs_fix_multicast_list(card
);
1269 if (card
->state
== DEV_STATE_UP
) {
1270 netif_carrier_on(card
->dev
);
1271 netif_wake_queue(card
->dev
);
1274 lcs_clear_thread_running_bit(card
, LCS_SET_MC_THREAD
);
1278 * function called by net device to
1279 * handle multicast address relevant things
1282 lcs_set_multicast_list(struct net_device
*dev
)
1284 struct lcs_card
*card
;
1286 LCS_DBF_TEXT(4, trace
, "setmulti");
1287 card
= (struct lcs_card
*) dev
->priv
;
1289 if (!lcs_set_thread_start_bit(card
, LCS_SET_MC_THREAD
))
1290 schedule_work(&card
->kernel_thread_starter
);
1293 #endif /* CONFIG_IP_MULTICAST */
1296 lcs_check_irb_error(struct ccw_device
*cdev
, struct irb
*irb
)
1301 switch (PTR_ERR(irb
)) {
1303 PRINT_WARN("i/o-error on device %s\n", cdev
->dev
.bus_id
);
1304 LCS_DBF_TEXT(2, trace
, "ckirberr");
1305 LCS_DBF_TEXT_(2, trace
, " rc%d", -EIO
);
1308 PRINT_WARN("timeout on device %s\n", cdev
->dev
.bus_id
);
1309 LCS_DBF_TEXT(2, trace
, "ckirberr");
1310 LCS_DBF_TEXT_(2, trace
, " rc%d", -ETIMEDOUT
);
1313 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb
),
1315 LCS_DBF_TEXT(2, trace
, "ckirberr");
1316 LCS_DBF_TEXT(2, trace
, " rc???");
1318 return PTR_ERR(irb
);
1322 lcs_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
1327 sense
= (char *) irb
->ecw
;
1328 cstat
= irb
->scsw
.cstat
;
1329 dstat
= irb
->scsw
.dstat
;
1331 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
1332 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
1333 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
1334 LCS_DBF_TEXT(2, trace
, "CGENCHK");
1337 if (dstat
& DEV_STAT_UNIT_CHECK
) {
1338 if (sense
[LCS_SENSE_BYTE_1
] &
1339 LCS_SENSE_RESETTING_EVENT
) {
1340 LCS_DBF_TEXT(2, trace
, "REVIND");
1343 if (sense
[LCS_SENSE_BYTE_0
] &
1344 LCS_SENSE_CMD_REJECT
) {
1345 LCS_DBF_TEXT(2, trace
, "CMDREJ");
1348 if ((!sense
[LCS_SENSE_BYTE_0
]) &&
1349 (!sense
[LCS_SENSE_BYTE_1
]) &&
1350 (!sense
[LCS_SENSE_BYTE_2
]) &&
1351 (!sense
[LCS_SENSE_BYTE_3
])) {
1352 LCS_DBF_TEXT(2, trace
, "ZEROSEN");
1355 LCS_DBF_TEXT(2, trace
, "DGENCHK");
1362 lcs_schedule_recovery(struct lcs_card
*card
)
1364 LCS_DBF_TEXT(2, trace
, "startrec");
1365 if (!lcs_set_thread_start_bit(card
, LCS_RECOVERY_THREAD
))
1366 schedule_work(&card
->kernel_thread_starter
);
1370 * IRQ Handler for LCS channels
1373 lcs_irq(struct ccw_device
*cdev
, unsigned long intparm
, struct irb
*irb
)
1375 struct lcs_card
*card
;
1376 struct lcs_channel
*channel
;
1380 if (lcs_check_irb_error(cdev
, irb
))
1383 card
= CARD_FROM_DEV(cdev
);
1384 if (card
->read
.ccwdev
== cdev
)
1385 channel
= &card
->read
;
1387 channel
= &card
->write
;
1389 cstat
= irb
->scsw
.cstat
;
1390 dstat
= irb
->scsw
.dstat
;
1391 LCS_DBF_TEXT_(5, trace
, "Rint%s",cdev
->dev
.bus_id
);
1392 LCS_DBF_TEXT_(5, trace
, "%4x%4x",irb
->scsw
.cstat
, irb
->scsw
.dstat
);
1393 LCS_DBF_TEXT_(5, trace
, "%4x%4x",irb
->scsw
.fctl
, irb
->scsw
.actl
);
1395 /* Check for channel and device errors presented */
1396 rc
= lcs_get_problem(cdev
, irb
);
1397 if (rc
|| (dstat
& DEV_STAT_UNIT_EXCEP
)) {
1398 PRINT_WARN("check on device %s, dstat=0x%X, cstat=0x%X \n",
1399 cdev
->dev
.bus_id
, dstat
, cstat
);
1401 lcs_schedule_recovery(card
);
1402 wake_up(&card
->wait_q
);
1406 /* How far in the ccw chain have we processed? */
1407 if ((channel
->state
!= CH_STATE_INIT
) &&
1408 (irb
->scsw
.fctl
& SCSW_FCTL_START_FUNC
)) {
1409 index
= (struct ccw1
*) __va((addr_t
) irb
->scsw
.cpa
)
1411 if ((irb
->scsw
.actl
& SCSW_ACTL_SUSPENDED
) ||
1412 (irb
->scsw
.cstat
& SCHN_STAT_PCI
))
1413 /* Bloody io subsystem tells us lies about cpa... */
1414 index
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
1415 while (channel
->io_idx
!= index
) {
1416 __lcs_processed_buffer(channel
,
1417 channel
->iob
+ channel
->io_idx
);
1419 (channel
->io_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1423 if ((irb
->scsw
.dstat
& DEV_STAT_DEV_END
) ||
1424 (irb
->scsw
.dstat
& DEV_STAT_CHN_END
) ||
1425 (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
))
1426 /* Mark channel as stopped. */
1427 channel
->state
= CH_STATE_STOPPED
;
1428 else if (irb
->scsw
.actl
& SCSW_ACTL_SUSPENDED
)
1429 /* CCW execution stopped on a suspend bit. */
1430 channel
->state
= CH_STATE_SUSPENDED
;
1431 if (irb
->scsw
.fctl
& SCSW_FCTL_HALT_FUNC
) {
1432 if (irb
->scsw
.cc
!= 0) {
1433 ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
1436 /* The channel has been stopped by halt_IO. */
1437 channel
->state
= CH_STATE_HALTED
;
1439 if (irb
->scsw
.fctl
& SCSW_FCTL_CLEAR_FUNC
) {
1440 channel
->state
= CH_STATE_CLEARED
;
1442 /* Do the rest in the tasklet. */
1443 tasklet_schedule(&channel
->irq_tasklet
);
1447 * Tasklet for IRQ handler
1450 lcs_tasklet(unsigned long data
)
1452 unsigned long flags
;
1453 struct lcs_channel
*channel
;
1454 struct lcs_buffer
*iob
;
1458 channel
= (struct lcs_channel
*) data
;
1459 LCS_DBF_TEXT_(5, trace
, "tlet%s",channel
->ccwdev
->dev
.bus_id
);
1461 /* Check for processed buffers. */
1463 buf_idx
= channel
->buf_idx
;
1464 while (iob
[buf_idx
].state
== BUF_STATE_PROCESSED
) {
1465 /* Do the callback thing. */
1466 if (iob
[buf_idx
].callback
!= NULL
)
1467 iob
[buf_idx
].callback(channel
, iob
+ buf_idx
);
1468 buf_idx
= (buf_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1470 channel
->buf_idx
= buf_idx
;
1472 if (channel
->state
== CH_STATE_STOPPED
)
1473 // FIXME: what if rc != 0 ??
1474 rc
= lcs_start_channel(channel
);
1475 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1476 if (channel
->state
== CH_STATE_SUSPENDED
&&
1477 channel
->iob
[channel
->io_idx
].state
== BUF_STATE_READY
) {
1478 // FIXME: what if rc != 0 ??
1479 rc
= __lcs_resume_channel(channel
);
1481 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1483 /* Something happened on the channel. Wake up waiters. */
1484 wake_up(&channel
->wait_q
);
1488 * Finish current tx buffer and make it ready for transmit.
1491 __lcs_emit_txbuffer(struct lcs_card
*card
)
1493 LCS_DBF_TEXT(5, trace
, "emittx");
1494 *(__u16
*)(card
->tx_buffer
->data
+ card
->tx_buffer
->count
) = 0;
1495 card
->tx_buffer
->count
+= 2;
1496 lcs_ready_buffer(&card
->write
, card
->tx_buffer
);
1497 card
->tx_buffer
= NULL
;
1502 * Callback for finished tx buffers.
1505 lcs_txbuffer_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1507 struct lcs_card
*card
;
1509 LCS_DBF_TEXT(5, trace
, "txbuffcb");
1510 /* Put buffer back to pool. */
1511 lcs_release_buffer(channel
, buffer
);
1512 card
= (struct lcs_card
*)
1513 ((char *) channel
- offsetof(struct lcs_card
, write
));
1514 if (netif_queue_stopped(card
->dev
) && netif_carrier_ok(card
->dev
))
1515 netif_wake_queue(card
->dev
);
1516 spin_lock(&card
->lock
);
1518 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1520 * Last running tx buffer has finished. Submit partially
1521 * filled current buffer.
1523 __lcs_emit_txbuffer(card
);
1524 spin_unlock(&card
->lock
);
1528 * Packet transmit function called by network stack
1531 __lcs_start_xmit(struct lcs_card
*card
, struct sk_buff
*skb
,
1532 struct net_device
*dev
)
1534 struct lcs_header
*header
;
1537 LCS_DBF_TEXT(5, trace
, "hardxmit");
1539 card
->stats
.tx_dropped
++;
1540 card
->stats
.tx_errors
++;
1543 if (card
->state
!= DEV_STATE_UP
) {
1545 card
->stats
.tx_dropped
++;
1546 card
->stats
.tx_errors
++;
1547 card
->stats
.tx_carrier_errors
++;
1550 if (skb
->protocol
== htons(ETH_P_IPV6
)) {
1554 netif_stop_queue(card
->dev
);
1555 spin_lock(&card
->lock
);
1556 if (card
->tx_buffer
!= NULL
&&
1557 card
->tx_buffer
->count
+ sizeof(struct lcs_header
) +
1558 skb
->len
+ sizeof(u16
) > LCS_IOBUFFERSIZE
)
1559 /* skb too big for current tx buffer. */
1560 __lcs_emit_txbuffer(card
);
1561 if (card
->tx_buffer
== NULL
) {
1562 /* Get new tx buffer */
1563 card
->tx_buffer
= lcs_get_buffer(&card
->write
);
1564 if (card
->tx_buffer
== NULL
) {
1565 card
->stats
.tx_dropped
++;
1569 card
->tx_buffer
->callback
= lcs_txbuffer_cb
;
1570 card
->tx_buffer
->count
= 0;
1572 header
= (struct lcs_header
*)
1573 (card
->tx_buffer
->data
+ card
->tx_buffer
->count
);
1574 card
->tx_buffer
->count
+= skb
->len
+ sizeof(struct lcs_header
);
1575 header
->offset
= card
->tx_buffer
->count
;
1576 header
->type
= card
->lan_type
;
1577 header
->slot
= card
->portno
;
1578 memcpy(header
+ 1, skb
->data
, skb
->len
);
1579 spin_unlock(&card
->lock
);
1580 card
->stats
.tx_bytes
+= skb
->len
;
1581 card
->stats
.tx_packets
++;
1583 netif_wake_queue(card
->dev
);
1584 spin_lock(&card
->lock
);
1585 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1586 /* If this is the first tx buffer emit it immediately. */
1587 __lcs_emit_txbuffer(card
);
1589 spin_unlock(&card
->lock
);
1594 lcs_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1596 struct lcs_card
*card
;
1599 LCS_DBF_TEXT(5, trace
, "pktxmit");
1600 card
= (struct lcs_card
*) dev
->priv
;
1601 rc
= __lcs_start_xmit(card
, skb
, dev
);
1606 * send startlan and lanstat command to make LCS device ready
1609 lcs_startlan_auto(struct lcs_card
*card
)
1613 LCS_DBF_TEXT(2, trace
, "strtauto");
1614 #ifdef CONFIG_NET_ETHERNET
1615 card
->lan_type
= LCS_FRAME_TYPE_ENET
;
1616 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1622 card
->lan_type
= LCS_FRAME_TYPE_TR
;
1623 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1628 card
->lan_type
= LCS_FRAME_TYPE_FDDI
;
1629 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1637 lcs_startlan(struct lcs_card
*card
)
1641 LCS_DBF_TEXT(2, trace
, "startlan");
1643 if (card
->portno
!= LCS_INVALID_PORT_NO
) {
1644 if (card
->lan_type
== LCS_FRAME_TYPE_AUTO
)
1645 rc
= lcs_startlan_auto(card
);
1647 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1649 for (i
= 0; i
<= 16; i
++) {
1651 if (card
->lan_type
!= LCS_FRAME_TYPE_AUTO
)
1652 rc
= lcs_send_startlan(card
,
1653 LCS_INITIATOR_TCPIP
);
1655 /* autodetecting lan type */
1656 rc
= lcs_startlan_auto(card
);
1662 return lcs_send_lanstat(card
);
1667 * LCS detect function
1668 * setup channels and make them I/O ready
1671 lcs_detect(struct lcs_card
*card
)
1675 LCS_DBF_TEXT(2, setup
, "lcsdetct");
1676 /* start/reset card */
1678 netif_stop_queue(card
->dev
);
1679 rc
= lcs_stop_channels(card
);
1681 rc
= lcs_start_channels(card
);
1683 rc
= lcs_send_startup(card
, LCS_INITIATOR_TCPIP
);
1685 rc
= lcs_startlan(card
);
1689 card
->state
= DEV_STATE_UP
;
1691 card
->state
= DEV_STATE_DOWN
;
1692 card
->write
.state
= CH_STATE_INIT
;
1693 card
->read
.state
= CH_STATE_INIT
;
1702 lcs_stopcard(struct lcs_card
*card
)
1706 LCS_DBF_TEXT(3, setup
, "stopcard");
1708 if (card
->read
.state
!= CH_STATE_STOPPED
&&
1709 card
->write
.state
!= CH_STATE_STOPPED
&&
1710 card
->state
== DEV_STATE_UP
) {
1711 lcs_clear_multicast_list(card
);
1712 rc
= lcs_send_stoplan(card
,LCS_INITIATOR_TCPIP
);
1713 rc
= lcs_send_shutdown(card
);
1715 rc
= lcs_stop_channels(card
);
1716 card
->state
= DEV_STATE_DOWN
;
1722 * Kernel Thread helper functions for LGW initiated commands
1725 lcs_start_kernel_thread(struct lcs_card
*card
)
1727 LCS_DBF_TEXT(5, trace
, "krnthrd");
1728 if (lcs_do_start_thread(card
, LCS_RECOVERY_THREAD
))
1729 kernel_thread(lcs_recovery
, (void *) card
, SIGCHLD
);
1730 #ifdef CONFIG_IP_MULTICAST
1731 if (lcs_do_start_thread(card
, LCS_SET_MC_THREAD
))
1732 kernel_thread(lcs_register_mc_addresses
,
1733 (void *) card
, SIGCHLD
);
1738 * Process control frames.
1741 lcs_get_control(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1743 LCS_DBF_TEXT(5, trace
, "getctrl");
1744 if (cmd
->initiator
== LCS_INITIATOR_LGW
) {
1745 switch(cmd
->cmd_code
) {
1746 case LCS_CMD_STARTUP
:
1747 case LCS_CMD_STARTLAN
:
1748 lcs_schedule_recovery(card
);
1750 case LCS_CMD_STOPLAN
:
1751 PRINT_WARN("Stoplan for %s initiated by LGW.\n",
1754 netif_carrier_off(card
->dev
);
1757 PRINT_INFO("UNRECOGNIZED LGW COMMAND\n");
1761 lcs_notify_lancmd_waiters(card
, cmd
);
1765 * Unpack network packet.
1768 lcs_get_skb(struct lcs_card
*card
, char *skb_data
, unsigned int skb_len
)
1770 struct sk_buff
*skb
;
1772 LCS_DBF_TEXT(5, trace
, "getskb");
1773 if (card
->dev
== NULL
||
1774 card
->state
!= DEV_STATE_UP
)
1775 /* The card isn't up. Ignore the packet. */
1778 skb
= dev_alloc_skb(skb_len
);
1780 PRINT_ERR("LCS: alloc_skb failed for device=%s\n",
1782 card
->stats
.rx_dropped
++;
1785 skb
->dev
= card
->dev
;
1786 memcpy(skb_put(skb
, skb_len
), skb_data
, skb_len
);
1787 skb
->protocol
= card
->lan_type_trans(skb
, card
->dev
);
1788 card
->stats
.rx_bytes
+= skb_len
;
1789 card
->stats
.rx_packets
++;
1790 *((__u32
*)skb
->cb
) = ++card
->pkt_seq
;
1795 * LCS main routine to get packets and lancmd replies from the buffers
1798 lcs_get_frames_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1800 struct lcs_card
*card
;
1801 struct lcs_header
*lcs_hdr
;
1804 LCS_DBF_TEXT(5, trace
, "lcsgtpkt");
1805 lcs_hdr
= (struct lcs_header
*) buffer
->data
;
1806 if (lcs_hdr
->offset
== LCS_ILLEGAL_OFFSET
) {
1807 LCS_DBF_TEXT(4, trace
, "-eiogpkt");
1810 card
= (struct lcs_card
*)
1811 ((char *) channel
- offsetof(struct lcs_card
, read
));
1813 while (lcs_hdr
->offset
!= 0) {
1814 if (lcs_hdr
->offset
<= 0 ||
1815 lcs_hdr
->offset
> LCS_IOBUFFERSIZE
||
1816 lcs_hdr
->offset
< offset
) {
1817 /* Offset invalid. */
1818 card
->stats
.rx_length_errors
++;
1819 card
->stats
.rx_errors
++;
1822 /* What kind of frame is it? */
1823 if (lcs_hdr
->type
== LCS_FRAME_TYPE_CONTROL
)
1824 /* Control frame. */
1825 lcs_get_control(card
, (struct lcs_cmd
*) lcs_hdr
);
1826 else if (lcs_hdr
->type
== LCS_FRAME_TYPE_ENET
||
1827 lcs_hdr
->type
== LCS_FRAME_TYPE_TR
||
1828 lcs_hdr
->type
== LCS_FRAME_TYPE_FDDI
)
1829 /* Normal network packet. */
1830 lcs_get_skb(card
, (char *)(lcs_hdr
+ 1),
1831 lcs_hdr
->offset
- offset
-
1832 sizeof(struct lcs_header
));
1834 /* Unknown frame type. */
1835 ; // FIXME: error message ?
1836 /* Proceed to next frame. */
1837 offset
= lcs_hdr
->offset
;
1838 lcs_hdr
->offset
= LCS_ILLEGAL_OFFSET
;
1839 lcs_hdr
= (struct lcs_header
*) (buffer
->data
+ offset
);
1841 /* The buffer is now empty. Make it ready again. */
1842 lcs_ready_buffer(&card
->read
, buffer
);
1846 * get network statistics for ifconfig and other user programs
1848 static struct net_device_stats
*
1849 lcs_getstats(struct net_device
*dev
)
1851 struct lcs_card
*card
;
1853 LCS_DBF_TEXT(4, trace
, "netstats");
1854 card
= (struct lcs_card
*) dev
->priv
;
1855 return &card
->stats
;
1860 * This function will be called by user doing ifconfig xxx down
1863 lcs_stop_device(struct net_device
*dev
)
1865 struct lcs_card
*card
;
1868 LCS_DBF_TEXT(2, trace
, "stopdev");
1869 card
= (struct lcs_card
*) dev
->priv
;
1870 netif_carrier_off(dev
);
1871 netif_tx_disable(dev
);
1872 dev
->flags
&= ~IFF_UP
;
1873 wait_event(card
->write
.wait_q
,
1874 (card
->write
.state
!= CH_STATE_RUNNING
));
1875 rc
= lcs_stopcard(card
);
1877 PRINT_ERR("Try it again!\n ");
1882 * start lcs device and make it runnable
1883 * This function will be called by user doing ifconfig xxx up
1886 lcs_open_device(struct net_device
*dev
)
1888 struct lcs_card
*card
;
1891 LCS_DBF_TEXT(2, trace
, "opendev");
1892 card
= (struct lcs_card
*) dev
->priv
;
1893 /* initialize statistics */
1894 rc
= lcs_detect(card
);
1896 PRINT_ERR("LCS:Error in opening device!\n");
1899 dev
->flags
|= IFF_UP
;
1900 netif_carrier_on(dev
);
1901 netif_wake_queue(dev
);
1902 card
->state
= DEV_STATE_UP
;
1908 * show function for portno called by cat or similar things
1911 lcs_portno_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1913 struct lcs_card
*card
;
1915 card
= (struct lcs_card
*)dev
->driver_data
;
1920 return sprintf(buf
, "%d\n", card
->portno
);
1924 * store the value which is piped to file portno
1927 lcs_portno_store (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1929 struct lcs_card
*card
;
1932 card
= (struct lcs_card
*)dev
->driver_data
;
1937 sscanf(buf
, "%u", &value
);
1938 /* TODO: sanity checks */
1939 card
->portno
= value
;
1945 static DEVICE_ATTR(portno
, 0644, lcs_portno_show
, lcs_portno_store
);
1948 lcs_type_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1950 struct ccwgroup_device
*cgdev
;
1952 cgdev
= to_ccwgroupdev(dev
);
1956 return sprintf(buf
, "%s\n", cu3088_type
[cgdev
->cdev
[0]->id
.driver_info
]);
1959 static DEVICE_ATTR(type
, 0444, lcs_type_show
, NULL
);
1962 lcs_timeout_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1964 struct lcs_card
*card
;
1966 card
= (struct lcs_card
*)dev
->driver_data
;
1968 return card
? sprintf(buf
, "%u\n", card
->lancmd_timeout
) : 0;
1972 lcs_timeout_store (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1974 struct lcs_card
*card
;
1977 card
= (struct lcs_card
*)dev
->driver_data
;
1982 sscanf(buf
, "%u", &value
);
1983 /* TODO: sanity checks */
1984 card
->lancmd_timeout
= value
;
1990 DEVICE_ATTR(lancmd_timeout
, 0644, lcs_timeout_show
, lcs_timeout_store
);
1993 lcs_dev_recover_store(struct device
*dev
, struct device_attribute
*attr
,
1994 const char *buf
, size_t count
)
1996 struct lcs_card
*card
= dev
->driver_data
;
2002 if (card
->state
!= DEV_STATE_UP
)
2004 i
= simple_strtoul(buf
, &tmp
, 16);
2006 lcs_schedule_recovery(card
);
2010 static DEVICE_ATTR(recover
, 0200, NULL
, lcs_dev_recover_store
);
2012 static struct attribute
* lcs_attrs
[] = {
2013 &dev_attr_portno
.attr
,
2014 &dev_attr_type
.attr
,
2015 &dev_attr_lancmd_timeout
.attr
,
2016 &dev_attr_recover
.attr
,
2020 static struct attribute_group lcs_attr_group
= {
2025 * lcs_probe_device is called on establishing a new ccwgroup_device.
2028 lcs_probe_device(struct ccwgroup_device
*ccwgdev
)
2030 struct lcs_card
*card
;
2033 if (!get_device(&ccwgdev
->dev
))
2036 LCS_DBF_TEXT(2, setup
, "add_dev");
2037 card
= lcs_alloc_card();
2039 PRINT_ERR("Allocation of lcs card failed\n");
2040 put_device(&ccwgdev
->dev
);
2043 ret
= sysfs_create_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2045 PRINT_ERR("Creating attributes failed");
2046 lcs_free_card(card
);
2047 put_device(&ccwgdev
->dev
);
2050 ccwgdev
->dev
.driver_data
= card
;
2051 ccwgdev
->cdev
[0]->handler
= lcs_irq
;
2052 ccwgdev
->cdev
[1]->handler
= lcs_irq
;
2053 card
->gdev
= ccwgdev
;
2054 INIT_WORK(&card
->kernel_thread_starter
,
2055 (void *) lcs_start_kernel_thread
, card
);
2056 card
->thread_start_mask
= 0;
2057 card
->thread_allowed_mask
= 0;
2058 card
->thread_running_mask
= 0;
2063 lcs_register_netdev(struct ccwgroup_device
*ccwgdev
)
2065 struct lcs_card
*card
;
2067 LCS_DBF_TEXT(2, setup
, "regnetdv");
2068 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2069 if (card
->dev
->reg_state
!= NETREG_UNINITIALIZED
)
2071 SET_NETDEV_DEV(card
->dev
, &ccwgdev
->dev
);
2072 return register_netdev(card
->dev
);
2076 * lcs_new_device will be called by setting the group device online.
2080 lcs_new_device(struct ccwgroup_device
*ccwgdev
)
2082 struct lcs_card
*card
;
2083 struct net_device
*dev
=NULL
;
2084 enum lcs_dev_states recover_state
;
2087 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2091 LCS_DBF_TEXT(2, setup
, "newdev");
2092 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2093 card
->read
.ccwdev
= ccwgdev
->cdev
[0];
2094 card
->write
.ccwdev
= ccwgdev
->cdev
[1];
2096 recover_state
= card
->state
;
2097 ccw_device_set_online(card
->read
.ccwdev
);
2098 ccw_device_set_online(card
->write
.ccwdev
);
2100 LCS_DBF_TEXT(3, setup
, "lcsnewdv");
2102 lcs_setup_card(card
);
2103 rc
= lcs_detect(card
);
2105 LCS_DBF_TEXT(2, setup
, "dtctfail");
2106 PRINT_WARN("Detection of LCS card failed with return code "
2107 "%d (0x%x)\n", rc
, rc
);
2112 LCS_DBF_TEXT(2, setup
, "samedev");
2113 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2116 switch (card
->lan_type
) {
2117 #ifdef CONFIG_NET_ETHERNET
2118 case LCS_FRAME_TYPE_ENET
:
2119 card
->lan_type_trans
= eth_type_trans
;
2120 dev
= alloc_etherdev(0);
2124 case LCS_FRAME_TYPE_TR
:
2125 card
->lan_type_trans
= tr_type_trans
;
2126 dev
= alloc_trdev(0);
2130 case LCS_FRAME_TYPE_FDDI
:
2131 card
->lan_type_trans
= fddi_type_trans
;
2132 dev
= alloc_fddidev(0);
2136 LCS_DBF_TEXT(3, setup
, "errinit");
2137 PRINT_ERR("LCS: Initialization failed\n");
2138 PRINT_ERR("LCS: No device found!\n");
2144 card
->dev
->priv
= card
;
2145 card
->dev
->open
= lcs_open_device
;
2146 card
->dev
->stop
= lcs_stop_device
;
2147 card
->dev
->hard_start_xmit
= lcs_start_xmit
;
2148 card
->dev
->get_stats
= lcs_getstats
;
2149 SET_MODULE_OWNER(dev
);
2150 memcpy(card
->dev
->dev_addr
, card
->mac
, LCS_MAC_LENGTH
);
2151 #ifdef CONFIG_IP_MULTICAST
2152 if (!lcs_check_multicast_support(card
))
2153 card
->dev
->set_multicast_list
= lcs_set_multicast_list
;
2156 lcs_set_allowed_threads(card
,0xffffffff);
2157 if (recover_state
== DEV_STATE_RECOVER
) {
2158 lcs_set_multicast_list(card
->dev
);
2159 card
->dev
->flags
|= IFF_UP
;
2160 netif_carrier_on(card
->dev
);
2161 netif_wake_queue(card
->dev
);
2162 card
->state
= DEV_STATE_UP
;
2167 if (lcs_register_netdev(ccwgdev
) != 0)
2170 /* Print out supported assists: IPv6 */
2171 PRINT_INFO("LCS device %s %s IPv6 support\n", card
->dev
->name
,
2172 (card
->ip_assists_supported
& LCS_IPASS_IPV6_SUPPORT
) ?
2173 "with" : "without");
2174 /* Print out supported assist: Multicast */
2175 PRINT_INFO("LCS device %s %s Multicast support\n", card
->dev
->name
,
2176 (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
) ?
2177 "with" : "without");
2181 ccw_device_set_offline(card
->read
.ccwdev
);
2182 ccw_device_set_offline(card
->write
.ccwdev
);
2187 * lcs_shutdown_device, called when setting the group device offline.
2190 __lcs_shutdown_device(struct ccwgroup_device
*ccwgdev
, int recovery_mode
)
2192 struct lcs_card
*card
;
2193 enum lcs_dev_states recover_state
;
2196 LCS_DBF_TEXT(3, setup
, "shtdndev");
2197 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2200 if (recovery_mode
== 0) {
2201 lcs_set_allowed_threads(card
, 0);
2202 if (lcs_wait_for_threads(card
, LCS_SET_MC_THREAD
))
2203 return -ERESTARTSYS
;
2205 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2206 recover_state
= card
->state
;
2208 ret
= lcs_stop_device(card
->dev
);
2209 ret
= ccw_device_set_offline(card
->read
.ccwdev
);
2210 ret
= ccw_device_set_offline(card
->write
.ccwdev
);
2211 if (recover_state
== DEV_STATE_UP
) {
2212 card
->state
= DEV_STATE_RECOVER
;
2220 lcs_shutdown_device(struct ccwgroup_device
*ccwgdev
)
2222 return __lcs_shutdown_device(ccwgdev
, 0);
2226 * drive lcs recovery after startup and startlan initiated by Lan Gateway
2229 lcs_recovery(void *ptr
)
2231 struct lcs_card
*card
;
2232 struct ccwgroup_device
*gdev
;
2235 card
= (struct lcs_card
*) ptr
;
2236 daemonize("lcs_recover");
2238 LCS_DBF_TEXT(4, trace
, "recover1");
2239 if (!lcs_do_run_thread(card
, LCS_RECOVERY_THREAD
))
2241 LCS_DBF_TEXT(4, trace
, "recover2");
2243 PRINT_WARN("Recovery of device %s started...\n", gdev
->dev
.bus_id
);
2244 rc
= __lcs_shutdown_device(gdev
, 1);
2245 rc
= lcs_new_device(gdev
);
2247 PRINT_INFO("Device %s successfully recovered!\n",
2250 PRINT_INFO("Device %s could not be recovered!\n",
2252 lcs_clear_thread_running_bit(card
, LCS_RECOVERY_THREAD
);
2257 * lcs_remove_device, free buffers and card
2260 lcs_remove_device(struct ccwgroup_device
*ccwgdev
)
2262 struct lcs_card
*card
;
2264 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2268 PRINT_INFO("Removing lcs group device ....\n");
2269 LCS_DBF_TEXT(3, setup
, "remdev");
2270 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2271 if (ccwgdev
->state
== CCWGROUP_ONLINE
) {
2272 lcs_shutdown_device(ccwgdev
);
2275 unregister_netdev(card
->dev
);
2276 sysfs_remove_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2277 lcs_cleanup_card(card
);
2278 lcs_free_card(card
);
2279 put_device(&ccwgdev
->dev
);
2283 * LCS ccwgroup driver registration
2285 static struct ccwgroup_driver lcs_group_driver
= {
2286 .owner
= THIS_MODULE
,
2289 .driver_id
= 0xD3C3E2,
2290 .probe
= lcs_probe_device
,
2291 .remove
= lcs_remove_device
,
2292 .set_online
= lcs_new_device
,
2293 .set_offline
= lcs_shutdown_device
,
2297 * LCS Module/Kernel initialization function
2300 __init
lcs_init_module(void)
2304 PRINT_INFO("Loading %s\n",version
);
2305 rc
= lcs_register_debug_facility();
2306 LCS_DBF_TEXT(0, setup
, "lcsinit");
2308 PRINT_ERR("Initialization failed\n");
2312 rc
= register_cu3088_discipline(&lcs_group_driver
);
2314 PRINT_ERR("Initialization failed\n");
2322 * LCS module cleanup function
2325 __exit
lcs_cleanup_module(void)
2327 PRINT_INFO("Terminating lcs module.\n");
2328 LCS_DBF_TEXT(0, trace
, "cleanup");
2329 unregister_cu3088_discipline(&lcs_group_driver
);
2330 lcs_unregister_debug_facility();
2333 module_init(lcs_init_module
);
2334 module_exit(lcs_cleanup_module
);
2336 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
2337 MODULE_LICENSE("GPL");