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 if (buffer
->state
!= BUF_STATE_LOCKED
&&
674 buffer
->state
!= BUF_STATE_PROCESSED
)
676 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
677 buffer
->state
= BUF_STATE_READY
;
678 index
= buffer
- channel
->iob
;
680 channel
->ccws
[index
].count
= buffer
->count
;
681 /* Check relevant PCI/suspend bits. */
682 __lcs_ready_buffer_bits(channel
, index
);
683 rc
= __lcs_resume_channel(channel
);
684 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
689 * Mark the buffer as processed. Take care of the suspend bit
690 * of the previous buffer. This function is called from
691 * interrupt context, so the lock must not be taken.
694 __lcs_processed_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
696 int index
, prev
, next
;
698 LCS_DBF_TEXT(5, trace
, "prcsbuff");
699 if (buffer
->state
!= BUF_STATE_READY
)
701 buffer
->state
= BUF_STATE_PROCESSED
;
702 index
= buffer
- channel
->iob
;
703 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
704 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
705 /* Set the suspend bit and clear the PCI bit of this buffer. */
706 channel
->ccws
[index
].flags
|= CCW_FLAG_SUSPEND
;
707 channel
->ccws
[index
].flags
&= ~CCW_FLAG_PCI
;
708 /* Check the suspend bit of the previous buffer. */
709 if (channel
->iob
[prev
].state
== BUF_STATE_READY
) {
711 * Previous buffer is in state ready. It might have
712 * happened in lcs_ready_buffer that the suspend bit
713 * has not been cleared to avoid an endless loop.
716 __lcs_ready_buffer_bits(channel
, prev
);
718 /* Clear PCI bit of next buffer. */
719 channel
->ccws
[next
].flags
&= ~CCW_FLAG_PCI
;
720 return __lcs_resume_channel(channel
);
724 * Put a processed buffer back to state empty.
727 lcs_release_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
731 LCS_DBF_TEXT(5, trace
, "relbuff");
732 if (buffer
->state
!= BUF_STATE_LOCKED
&&
733 buffer
->state
!= BUF_STATE_PROCESSED
)
735 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
736 buffer
->state
= BUF_STATE_EMPTY
;
737 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
741 * Get buffer for a lan command.
743 static struct lcs_buffer
*
744 lcs_get_lancmd(struct lcs_card
*card
, int count
)
746 struct lcs_buffer
*buffer
;
749 LCS_DBF_TEXT(4, trace
, "getlncmd");
750 /* Get buffer and wait if none is available. */
751 wait_event(card
->write
.wait_q
,
752 ((buffer
= lcs_get_buffer(&card
->write
)) != NULL
));
753 count
+= sizeof(struct lcs_header
);
754 *(__u16
*)(buffer
->data
+ count
) = 0;
755 buffer
->count
= count
+ sizeof(__u16
);
756 buffer
->callback
= lcs_release_buffer
;
757 cmd
= (struct lcs_cmd
*) buffer
->data
;
759 cmd
->type
= LCS_FRAME_TYPE_CONTROL
;
766 lcs_get_reply(struct lcs_reply
*reply
)
768 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
769 atomic_inc(&reply
->refcnt
);
773 lcs_put_reply(struct lcs_reply
*reply
)
775 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
776 if (atomic_dec_and_test(&reply
->refcnt
)) {
782 static struct lcs_reply
*
783 lcs_alloc_reply(struct lcs_cmd
*cmd
)
785 struct lcs_reply
*reply
;
787 LCS_DBF_TEXT(4, trace
, "getreply");
789 reply
= kzalloc(sizeof(struct lcs_reply
), GFP_ATOMIC
);
792 atomic_set(&reply
->refcnt
,1);
793 reply
->sequence_no
= cmd
->sequence_no
;
796 init_waitqueue_head(&reply
->wait_q
);
802 * Notifier function for lancmd replies. Called from read irq.
805 lcs_notify_lancmd_waiters(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
807 struct list_head
*l
, *n
;
808 struct lcs_reply
*reply
;
810 LCS_DBF_TEXT(4, trace
, "notiwait");
811 spin_lock(&card
->lock
);
812 list_for_each_safe(l
, n
, &card
->lancmd_waiters
) {
813 reply
= list_entry(l
, struct lcs_reply
, list
);
814 if (reply
->sequence_no
== cmd
->sequence_no
) {
815 lcs_get_reply(reply
);
816 list_del_init(&reply
->list
);
817 if (reply
->callback
!= NULL
)
818 reply
->callback(card
, cmd
);
820 reply
->rc
= cmd
->return_code
;
821 wake_up(&reply
->wait_q
);
822 lcs_put_reply(reply
);
826 spin_unlock(&card
->lock
);
830 * Emit buffer of a lan comand.
833 lcs_lancmd_timeout(unsigned long data
)
835 struct lcs_reply
*reply
, *list_reply
, *r
;
838 LCS_DBF_TEXT(4, trace
, "timeout");
839 reply
= (struct lcs_reply
*) data
;
840 spin_lock_irqsave(&reply
->card
->lock
, flags
);
841 list_for_each_entry_safe(list_reply
, r
,
842 &reply
->card
->lancmd_waiters
,list
) {
843 if (reply
== list_reply
) {
844 lcs_get_reply(reply
);
845 list_del_init(&reply
->list
);
846 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
849 wake_up(&reply
->wait_q
);
850 lcs_put_reply(reply
);
854 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
858 lcs_send_lancmd(struct lcs_card
*card
, struct lcs_buffer
*buffer
,
859 void (*reply_callback
)(struct lcs_card
*, struct lcs_cmd
*))
861 struct lcs_reply
*reply
;
863 struct timer_list timer
;
867 LCS_DBF_TEXT(4, trace
, "sendcmd");
868 cmd
= (struct lcs_cmd
*) buffer
->data
;
869 cmd
->return_code
= 0;
870 cmd
->sequence_no
= card
->sequence_no
++;
871 reply
= lcs_alloc_reply(cmd
);
874 reply
->callback
= reply_callback
;
876 spin_lock_irqsave(&card
->lock
, flags
);
877 list_add_tail(&reply
->list
, &card
->lancmd_waiters
);
878 spin_unlock_irqrestore(&card
->lock
, flags
);
880 buffer
->callback
= lcs_release_buffer
;
881 rc
= lcs_ready_buffer(&card
->write
, buffer
);
885 timer
.function
= lcs_lancmd_timeout
;
886 timer
.data
= (unsigned long) reply
;
887 timer
.expires
= jiffies
+ HZ
*card
->lancmd_timeout
;
889 wait_event(reply
->wait_q
, reply
->received
);
890 del_timer_sync(&timer
);
891 LCS_DBF_TEXT_(4, trace
, "rc:%d",reply
->rc
);
893 lcs_put_reply(reply
);
894 return rc
? -EIO
: 0;
898 * LCS startup command
901 lcs_send_startup(struct lcs_card
*card
, __u8 initiator
)
903 struct lcs_buffer
*buffer
;
906 LCS_DBF_TEXT(2, trace
, "startup");
907 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
908 cmd
= (struct lcs_cmd
*) buffer
->data
;
909 cmd
->cmd_code
= LCS_CMD_STARTUP
;
910 cmd
->initiator
= initiator
;
911 cmd
->cmd
.lcs_startup
.buff_size
= LCS_IOBUFFERSIZE
;
912 return lcs_send_lancmd(card
, buffer
, NULL
);
916 * LCS shutdown command
919 lcs_send_shutdown(struct lcs_card
*card
)
921 struct lcs_buffer
*buffer
;
924 LCS_DBF_TEXT(2, trace
, "shutdown");
925 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
926 cmd
= (struct lcs_cmd
*) buffer
->data
;
927 cmd
->cmd_code
= LCS_CMD_SHUTDOWN
;
928 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
929 return lcs_send_lancmd(card
, buffer
, NULL
);
933 * LCS lanstat command
936 __lcs_lanstat_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
938 LCS_DBF_TEXT(2, trace
, "statcb");
939 memcpy(card
->mac
, cmd
->cmd
.lcs_lanstat_cmd
.mac_addr
, LCS_MAC_LENGTH
);
943 lcs_send_lanstat(struct lcs_card
*card
)
945 struct lcs_buffer
*buffer
;
948 LCS_DBF_TEXT(2,trace
, "cmdstat");
949 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
950 cmd
= (struct lcs_cmd
*) buffer
->data
;
951 /* Setup lanstat command. */
952 cmd
->cmd_code
= LCS_CMD_LANSTAT
;
953 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
954 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
955 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
956 return lcs_send_lancmd(card
, buffer
, __lcs_lanstat_cb
);
960 * send stoplan command
963 lcs_send_stoplan(struct lcs_card
*card
, __u8 initiator
)
965 struct lcs_buffer
*buffer
;
968 LCS_DBF_TEXT(2, trace
, "cmdstpln");
969 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
970 cmd
= (struct lcs_cmd
*) buffer
->data
;
971 cmd
->cmd_code
= LCS_CMD_STOPLAN
;
972 cmd
->initiator
= initiator
;
973 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
974 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
975 return lcs_send_lancmd(card
, buffer
, NULL
);
979 * send startlan command
982 __lcs_send_startlan_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
984 LCS_DBF_TEXT(2, trace
, "srtlancb");
985 card
->lan_type
= cmd
->cmd
.lcs_std_cmd
.lan_type
;
986 card
->portno
= cmd
->cmd
.lcs_std_cmd
.portno
;
990 lcs_send_startlan(struct lcs_card
*card
, __u8 initiator
)
992 struct lcs_buffer
*buffer
;
995 LCS_DBF_TEXT(2, trace
, "cmdstaln");
996 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
997 cmd
= (struct lcs_cmd
*) buffer
->data
;
998 cmd
->cmd_code
= LCS_CMD_STARTLAN
;
999 cmd
->initiator
= initiator
;
1000 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
1001 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
1002 return lcs_send_lancmd(card
, buffer
, __lcs_send_startlan_cb
);
1005 #ifdef CONFIG_IP_MULTICAST
1007 * send setipm command (Multicast)
1010 lcs_send_setipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1012 struct lcs_buffer
*buffer
;
1013 struct lcs_cmd
*cmd
;
1015 LCS_DBF_TEXT(2, trace
, "cmdsetim");
1016 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1017 cmd
= (struct lcs_cmd
*) buffer
->data
;
1018 cmd
->cmd_code
= LCS_CMD_SETIPM
;
1019 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1020 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1021 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1022 cmd
->cmd
.lcs_qipassist
.version
= 4;
1023 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1024 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1025 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1026 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1027 return lcs_send_lancmd(card
, buffer
, NULL
);
1031 * send delipm command (Multicast)
1034 lcs_send_delipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1036 struct lcs_buffer
*buffer
;
1037 struct lcs_cmd
*cmd
;
1039 LCS_DBF_TEXT(2, trace
, "cmddelim");
1040 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1041 cmd
= (struct lcs_cmd
*) buffer
->data
;
1042 cmd
->cmd_code
= LCS_CMD_DELIPM
;
1043 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1044 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1045 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1046 cmd
->cmd
.lcs_qipassist
.version
= 4;
1047 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1048 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1049 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1050 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1051 return lcs_send_lancmd(card
, buffer
, NULL
);
1055 * check if multicast is supported by LCS
1058 __lcs_check_multicast_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1060 LCS_DBF_TEXT(2, trace
, "chkmccb");
1061 card
->ip_assists_supported
=
1062 cmd
->cmd
.lcs_qipassist
.ip_assists_supported
;
1063 card
->ip_assists_enabled
=
1064 cmd
->cmd
.lcs_qipassist
.ip_assists_enabled
;
1068 lcs_check_multicast_support(struct lcs_card
*card
)
1070 struct lcs_buffer
*buffer
;
1071 struct lcs_cmd
*cmd
;
1074 LCS_DBF_TEXT(2, trace
, "cmdqipa");
1075 /* Send query ipassist. */
1076 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
1077 cmd
= (struct lcs_cmd
*) buffer
->data
;
1078 cmd
->cmd_code
= LCS_CMD_QIPASSIST
;
1079 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1080 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1081 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1082 cmd
->cmd
.lcs_qipassist
.version
= 4;
1083 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1084 rc
= lcs_send_lancmd(card
, buffer
, __lcs_check_multicast_cb
);
1086 PRINT_ERR("Query IPAssist failed. Assuming unsupported!\n");
1089 if (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
)
1095 * set or del multicast address on LCS card
1098 lcs_fix_multicast_list(struct lcs_card
*card
)
1100 struct list_head failed_list
;
1101 struct lcs_ipm_list
*ipm
, *tmp
;
1102 unsigned long flags
;
1105 LCS_DBF_TEXT(4,trace
, "fixipm");
1106 INIT_LIST_HEAD(&failed_list
);
1107 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1109 list_for_each_entry_safe(ipm
, tmp
, &card
->ipm_list
, list
){
1110 switch (ipm
->ipm_state
) {
1111 case LCS_IPM_STATE_SET_REQUIRED
:
1112 /* del from ipm_list so noone else can tamper with
1114 list_del_init(&ipm
->list
);
1115 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1116 rc
= lcs_send_setipm(card
, ipm
);
1117 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1119 PRINT_INFO("Adding multicast address failed."
1120 "Table possibly full!\n");
1121 /* store ipm in failed list -> will be added
1122 * to ipm_list again, so a retry will be done
1123 * during the next call of this function */
1124 list_add_tail(&ipm
->list
, &failed_list
);
1126 ipm
->ipm_state
= LCS_IPM_STATE_ON_CARD
;
1127 /* re-insert into ipm_list */
1128 list_add_tail(&ipm
->list
, &card
->ipm_list
);
1131 case LCS_IPM_STATE_DEL_REQUIRED
:
1132 list_del(&ipm
->list
);
1133 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1134 lcs_send_delipm(card
, ipm
);
1135 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1138 case LCS_IPM_STATE_ON_CARD
:
1142 /* re-insert all entries from the failed_list into ipm_list */
1143 list_for_each_entry_safe(ipm
, tmp
, &failed_list
, list
) {
1144 list_del_init(&ipm
->list
);
1145 list_add_tail(&ipm
->list
, &card
->ipm_list
);
1147 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1151 * get mac address for the relevant Multicast address
1154 lcs_get_mac_for_ipm(__u32 ipm
, char *mac
, struct net_device
*dev
)
1156 LCS_DBF_TEXT(4,trace
, "getmac");
1157 if (dev
->type
== ARPHRD_IEEE802_TR
)
1158 ip_tr_mc_map(ipm
, mac
);
1160 ip_eth_mc_map(ipm
, mac
);
1164 * function called by net device to handle multicast address relevant things
1167 lcs_remove_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1169 struct ip_mc_list
*im4
;
1170 struct list_head
*l
;
1171 struct lcs_ipm_list
*ipm
;
1172 unsigned long flags
;
1173 char buf
[MAX_ADDR_LEN
];
1175 LCS_DBF_TEXT(4, trace
, "remmclst");
1176 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1177 list_for_each(l
, &card
->ipm_list
) {
1178 ipm
= list_entry(l
, struct lcs_ipm_list
, list
);
1179 for (im4
= in4_dev
->mc_list
; im4
!= NULL
; im4
= im4
->next
) {
1180 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1181 if ( (ipm
->ipm
.ip_addr
== im4
->multiaddr
) &&
1182 (memcmp(buf
, &ipm
->ipm
.mac_addr
,
1183 LCS_MAC_LENGTH
) == 0) )
1187 ipm
->ipm_state
= LCS_IPM_STATE_DEL_REQUIRED
;
1189 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1192 static inline struct lcs_ipm_list
*
1193 lcs_check_addr_entry(struct lcs_card
*card
, struct ip_mc_list
*im4
, char *buf
)
1195 struct lcs_ipm_list
*tmp
, *ipm
= NULL
;
1196 struct list_head
*l
;
1197 unsigned long flags
;
1199 LCS_DBF_TEXT(4, trace
, "chkmcent");
1200 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1201 list_for_each(l
, &card
->ipm_list
) {
1202 tmp
= list_entry(l
, struct lcs_ipm_list
, list
);
1203 if ( (tmp
->ipm
.ip_addr
== im4
->multiaddr
) &&
1204 (memcmp(buf
, &tmp
->ipm
.mac_addr
,
1205 LCS_MAC_LENGTH
) == 0) ) {
1210 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1215 lcs_set_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1218 struct ip_mc_list
*im4
;
1219 struct lcs_ipm_list
*ipm
;
1220 char buf
[MAX_ADDR_LEN
];
1221 unsigned long flags
;
1223 LCS_DBF_TEXT(4, trace
, "setmclst");
1224 for (im4
= in4_dev
->mc_list
; im4
; im4
= im4
->next
) {
1225 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1226 ipm
= lcs_check_addr_entry(card
, im4
, buf
);
1228 continue; /* Address already in list. */
1229 ipm
= (struct lcs_ipm_list
*)
1230 kzalloc(sizeof(struct lcs_ipm_list
), GFP_ATOMIC
);
1232 PRINT_INFO("Not enough memory to add "
1233 "new multicast entry!\n");
1236 memcpy(&ipm
->ipm
.mac_addr
, buf
, LCS_MAC_LENGTH
);
1237 ipm
->ipm
.ip_addr
= im4
->multiaddr
;
1238 ipm
->ipm_state
= LCS_IPM_STATE_SET_REQUIRED
;
1239 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1240 LCS_DBF_HEX(2,trace
,&ipm
->ipm
.ip_addr
,4);
1241 list_add(&ipm
->list
, &card
->ipm_list
);
1242 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1247 lcs_register_mc_addresses(void *data
)
1249 struct lcs_card
*card
;
1250 struct in_device
*in4_dev
;
1252 card
= (struct lcs_card
*) data
;
1253 daemonize("regipm");
1255 if (!lcs_do_run_thread(card
, LCS_SET_MC_THREAD
))
1257 LCS_DBF_TEXT(4, trace
, "regmulti");
1259 in4_dev
= in_dev_get(card
->dev
);
1260 if (in4_dev
== NULL
)
1262 read_lock(&in4_dev
->mc_list_lock
);
1263 lcs_remove_mc_addresses(card
,in4_dev
);
1264 lcs_set_mc_addresses(card
, in4_dev
);
1265 read_unlock(&in4_dev
->mc_list_lock
);
1266 in_dev_put(in4_dev
);
1268 netif_carrier_off(card
->dev
);
1269 netif_tx_disable(card
->dev
);
1270 wait_event(card
->write
.wait_q
,
1271 (card
->write
.state
!= CH_STATE_RUNNING
));
1272 lcs_fix_multicast_list(card
);
1273 if (card
->state
== DEV_STATE_UP
) {
1274 netif_carrier_on(card
->dev
);
1275 netif_wake_queue(card
->dev
);
1278 lcs_clear_thread_running_bit(card
, LCS_SET_MC_THREAD
);
1282 * function called by net device to
1283 * handle multicast address relevant things
1286 lcs_set_multicast_list(struct net_device
*dev
)
1288 struct lcs_card
*card
;
1290 LCS_DBF_TEXT(4, trace
, "setmulti");
1291 card
= (struct lcs_card
*) dev
->priv
;
1293 if (!lcs_set_thread_start_bit(card
, LCS_SET_MC_THREAD
))
1294 schedule_work(&card
->kernel_thread_starter
);
1297 #endif /* CONFIG_IP_MULTICAST */
1300 lcs_check_irb_error(struct ccw_device
*cdev
, struct irb
*irb
)
1305 switch (PTR_ERR(irb
)) {
1307 PRINT_WARN("i/o-error on device %s\n", cdev
->dev
.bus_id
);
1308 LCS_DBF_TEXT(2, trace
, "ckirberr");
1309 LCS_DBF_TEXT_(2, trace
, " rc%d", -EIO
);
1312 PRINT_WARN("timeout on device %s\n", cdev
->dev
.bus_id
);
1313 LCS_DBF_TEXT(2, trace
, "ckirberr");
1314 LCS_DBF_TEXT_(2, trace
, " rc%d", -ETIMEDOUT
);
1317 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb
),
1319 LCS_DBF_TEXT(2, trace
, "ckirberr");
1320 LCS_DBF_TEXT(2, trace
, " rc???");
1322 return PTR_ERR(irb
);
1326 lcs_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
1331 sense
= (char *) irb
->ecw
;
1332 cstat
= irb
->scsw
.cstat
;
1333 dstat
= irb
->scsw
.dstat
;
1335 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
1336 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
1337 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
1338 LCS_DBF_TEXT(2, trace
, "CGENCHK");
1341 if (dstat
& DEV_STAT_UNIT_CHECK
) {
1342 if (sense
[LCS_SENSE_BYTE_1
] &
1343 LCS_SENSE_RESETTING_EVENT
) {
1344 LCS_DBF_TEXT(2, trace
, "REVIND");
1347 if (sense
[LCS_SENSE_BYTE_0
] &
1348 LCS_SENSE_CMD_REJECT
) {
1349 LCS_DBF_TEXT(2, trace
, "CMDREJ");
1352 if ((!sense
[LCS_SENSE_BYTE_0
]) &&
1353 (!sense
[LCS_SENSE_BYTE_1
]) &&
1354 (!sense
[LCS_SENSE_BYTE_2
]) &&
1355 (!sense
[LCS_SENSE_BYTE_3
])) {
1356 LCS_DBF_TEXT(2, trace
, "ZEROSEN");
1359 LCS_DBF_TEXT(2, trace
, "DGENCHK");
1366 lcs_schedule_recovery(struct lcs_card
*card
)
1368 LCS_DBF_TEXT(2, trace
, "startrec");
1369 if (!lcs_set_thread_start_bit(card
, LCS_RECOVERY_THREAD
))
1370 schedule_work(&card
->kernel_thread_starter
);
1374 * IRQ Handler for LCS channels
1377 lcs_irq(struct ccw_device
*cdev
, unsigned long intparm
, struct irb
*irb
)
1379 struct lcs_card
*card
;
1380 struct lcs_channel
*channel
;
1384 if (lcs_check_irb_error(cdev
, irb
))
1387 card
= CARD_FROM_DEV(cdev
);
1388 if (card
->read
.ccwdev
== cdev
)
1389 channel
= &card
->read
;
1391 channel
= &card
->write
;
1393 cstat
= irb
->scsw
.cstat
;
1394 dstat
= irb
->scsw
.dstat
;
1395 LCS_DBF_TEXT_(5, trace
, "Rint%s",cdev
->dev
.bus_id
);
1396 LCS_DBF_TEXT_(5, trace
, "%4x%4x",irb
->scsw
.cstat
, irb
->scsw
.dstat
);
1397 LCS_DBF_TEXT_(5, trace
, "%4x%4x",irb
->scsw
.fctl
, irb
->scsw
.actl
);
1399 /* Check for channel and device errors presented */
1400 rc
= lcs_get_problem(cdev
, irb
);
1401 if (rc
|| (dstat
& DEV_STAT_UNIT_EXCEP
)) {
1402 PRINT_WARN("check on device %s, dstat=0x%X, cstat=0x%X \n",
1403 cdev
->dev
.bus_id
, dstat
, cstat
);
1405 lcs_schedule_recovery(card
);
1406 wake_up(&card
->wait_q
);
1410 /* How far in the ccw chain have we processed? */
1411 if ((channel
->state
!= CH_STATE_INIT
) &&
1412 (irb
->scsw
.fctl
& SCSW_FCTL_START_FUNC
)) {
1413 index
= (struct ccw1
*) __va((addr_t
) irb
->scsw
.cpa
)
1415 if ((irb
->scsw
.actl
& SCSW_ACTL_SUSPENDED
) ||
1416 (irb
->scsw
.cstat
& SCHN_STAT_PCI
))
1417 /* Bloody io subsystem tells us lies about cpa... */
1418 index
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
1419 while (channel
->io_idx
!= index
) {
1420 __lcs_processed_buffer(channel
,
1421 channel
->iob
+ channel
->io_idx
);
1423 (channel
->io_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1427 if ((irb
->scsw
.dstat
& DEV_STAT_DEV_END
) ||
1428 (irb
->scsw
.dstat
& DEV_STAT_CHN_END
) ||
1429 (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
))
1430 /* Mark channel as stopped. */
1431 channel
->state
= CH_STATE_STOPPED
;
1432 else if (irb
->scsw
.actl
& SCSW_ACTL_SUSPENDED
)
1433 /* CCW execution stopped on a suspend bit. */
1434 channel
->state
= CH_STATE_SUSPENDED
;
1435 if (irb
->scsw
.fctl
& SCSW_FCTL_HALT_FUNC
) {
1436 if (irb
->scsw
.cc
!= 0) {
1437 ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
1440 /* The channel has been stopped by halt_IO. */
1441 channel
->state
= CH_STATE_HALTED
;
1443 if (irb
->scsw
.fctl
& SCSW_FCTL_CLEAR_FUNC
) {
1444 channel
->state
= CH_STATE_CLEARED
;
1446 /* Do the rest in the tasklet. */
1447 tasklet_schedule(&channel
->irq_tasklet
);
1451 * Tasklet for IRQ handler
1454 lcs_tasklet(unsigned long data
)
1456 unsigned long flags
;
1457 struct lcs_channel
*channel
;
1458 struct lcs_buffer
*iob
;
1462 channel
= (struct lcs_channel
*) data
;
1463 LCS_DBF_TEXT_(5, trace
, "tlet%s",channel
->ccwdev
->dev
.bus_id
);
1465 /* Check for processed buffers. */
1467 buf_idx
= channel
->buf_idx
;
1468 while (iob
[buf_idx
].state
== BUF_STATE_PROCESSED
) {
1469 /* Do the callback thing. */
1470 if (iob
[buf_idx
].callback
!= NULL
)
1471 iob
[buf_idx
].callback(channel
, iob
+ buf_idx
);
1472 buf_idx
= (buf_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1474 channel
->buf_idx
= buf_idx
;
1476 if (channel
->state
== CH_STATE_STOPPED
)
1477 // FIXME: what if rc != 0 ??
1478 rc
= lcs_start_channel(channel
);
1479 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1480 if (channel
->state
== CH_STATE_SUSPENDED
&&
1481 channel
->iob
[channel
->io_idx
].state
== BUF_STATE_READY
) {
1482 // FIXME: what if rc != 0 ??
1483 rc
= __lcs_resume_channel(channel
);
1485 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1487 /* Something happened on the channel. Wake up waiters. */
1488 wake_up(&channel
->wait_q
);
1492 * Finish current tx buffer and make it ready for transmit.
1495 __lcs_emit_txbuffer(struct lcs_card
*card
)
1497 LCS_DBF_TEXT(5, trace
, "emittx");
1498 *(__u16
*)(card
->tx_buffer
->data
+ card
->tx_buffer
->count
) = 0;
1499 card
->tx_buffer
->count
+= 2;
1500 lcs_ready_buffer(&card
->write
, card
->tx_buffer
);
1501 card
->tx_buffer
= NULL
;
1506 * Callback for finished tx buffers.
1509 lcs_txbuffer_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1511 struct lcs_card
*card
;
1513 LCS_DBF_TEXT(5, trace
, "txbuffcb");
1514 /* Put buffer back to pool. */
1515 lcs_release_buffer(channel
, buffer
);
1516 card
= (struct lcs_card
*)
1517 ((char *) channel
- offsetof(struct lcs_card
, write
));
1518 if (netif_queue_stopped(card
->dev
) && netif_carrier_ok(card
->dev
))
1519 netif_wake_queue(card
->dev
);
1520 spin_lock(&card
->lock
);
1522 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1524 * Last running tx buffer has finished. Submit partially
1525 * filled current buffer.
1527 __lcs_emit_txbuffer(card
);
1528 spin_unlock(&card
->lock
);
1532 * Packet transmit function called by network stack
1535 __lcs_start_xmit(struct lcs_card
*card
, struct sk_buff
*skb
,
1536 struct net_device
*dev
)
1538 struct lcs_header
*header
;
1541 LCS_DBF_TEXT(5, trace
, "hardxmit");
1543 card
->stats
.tx_dropped
++;
1544 card
->stats
.tx_errors
++;
1547 if (card
->state
!= DEV_STATE_UP
) {
1549 card
->stats
.tx_dropped
++;
1550 card
->stats
.tx_errors
++;
1551 card
->stats
.tx_carrier_errors
++;
1554 if (skb
->protocol
== htons(ETH_P_IPV6
)) {
1558 netif_stop_queue(card
->dev
);
1559 spin_lock(&card
->lock
);
1560 if (card
->tx_buffer
!= NULL
&&
1561 card
->tx_buffer
->count
+ sizeof(struct lcs_header
) +
1562 skb
->len
+ sizeof(u16
) > LCS_IOBUFFERSIZE
)
1563 /* skb too big for current tx buffer. */
1564 __lcs_emit_txbuffer(card
);
1565 if (card
->tx_buffer
== NULL
) {
1566 /* Get new tx buffer */
1567 card
->tx_buffer
= lcs_get_buffer(&card
->write
);
1568 if (card
->tx_buffer
== NULL
) {
1569 card
->stats
.tx_dropped
++;
1573 card
->tx_buffer
->callback
= lcs_txbuffer_cb
;
1574 card
->tx_buffer
->count
= 0;
1576 header
= (struct lcs_header
*)
1577 (card
->tx_buffer
->data
+ card
->tx_buffer
->count
);
1578 card
->tx_buffer
->count
+= skb
->len
+ sizeof(struct lcs_header
);
1579 header
->offset
= card
->tx_buffer
->count
;
1580 header
->type
= card
->lan_type
;
1581 header
->slot
= card
->portno
;
1582 memcpy(header
+ 1, skb
->data
, skb
->len
);
1583 spin_unlock(&card
->lock
);
1584 card
->stats
.tx_bytes
+= skb
->len
;
1585 card
->stats
.tx_packets
++;
1587 netif_wake_queue(card
->dev
);
1588 spin_lock(&card
->lock
);
1589 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1590 /* If this is the first tx buffer emit it immediately. */
1591 __lcs_emit_txbuffer(card
);
1593 spin_unlock(&card
->lock
);
1598 lcs_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1600 struct lcs_card
*card
;
1603 LCS_DBF_TEXT(5, trace
, "pktxmit");
1604 card
= (struct lcs_card
*) dev
->priv
;
1605 rc
= __lcs_start_xmit(card
, skb
, dev
);
1610 * send startlan and lanstat command to make LCS device ready
1613 lcs_startlan_auto(struct lcs_card
*card
)
1617 LCS_DBF_TEXT(2, trace
, "strtauto");
1618 #ifdef CONFIG_NET_ETHERNET
1619 card
->lan_type
= LCS_FRAME_TYPE_ENET
;
1620 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1626 card
->lan_type
= LCS_FRAME_TYPE_TR
;
1627 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1632 card
->lan_type
= LCS_FRAME_TYPE_FDDI
;
1633 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1641 lcs_startlan(struct lcs_card
*card
)
1645 LCS_DBF_TEXT(2, trace
, "startlan");
1647 if (card
->portno
!= LCS_INVALID_PORT_NO
) {
1648 if (card
->lan_type
== LCS_FRAME_TYPE_AUTO
)
1649 rc
= lcs_startlan_auto(card
);
1651 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1653 for (i
= 0; i
<= 16; i
++) {
1655 if (card
->lan_type
!= LCS_FRAME_TYPE_AUTO
)
1656 rc
= lcs_send_startlan(card
,
1657 LCS_INITIATOR_TCPIP
);
1659 /* autodetecting lan type */
1660 rc
= lcs_startlan_auto(card
);
1666 return lcs_send_lanstat(card
);
1671 * LCS detect function
1672 * setup channels and make them I/O ready
1675 lcs_detect(struct lcs_card
*card
)
1679 LCS_DBF_TEXT(2, setup
, "lcsdetct");
1680 /* start/reset card */
1682 netif_stop_queue(card
->dev
);
1683 rc
= lcs_stop_channels(card
);
1685 rc
= lcs_start_channels(card
);
1687 rc
= lcs_send_startup(card
, LCS_INITIATOR_TCPIP
);
1689 rc
= lcs_startlan(card
);
1693 card
->state
= DEV_STATE_UP
;
1695 card
->state
= DEV_STATE_DOWN
;
1696 card
->write
.state
= CH_STATE_INIT
;
1697 card
->read
.state
= CH_STATE_INIT
;
1706 lcs_stopcard(struct lcs_card
*card
)
1710 LCS_DBF_TEXT(3, setup
, "stopcard");
1712 if (card
->read
.state
!= CH_STATE_STOPPED
&&
1713 card
->write
.state
!= CH_STATE_STOPPED
&&
1714 card
->state
== DEV_STATE_UP
) {
1715 lcs_clear_multicast_list(card
);
1716 rc
= lcs_send_stoplan(card
,LCS_INITIATOR_TCPIP
);
1717 rc
= lcs_send_shutdown(card
);
1719 rc
= lcs_stop_channels(card
);
1720 card
->state
= DEV_STATE_DOWN
;
1726 * Kernel Thread helper functions for LGW initiated commands
1729 lcs_start_kernel_thread(struct lcs_card
*card
)
1731 LCS_DBF_TEXT(5, trace
, "krnthrd");
1732 if (lcs_do_start_thread(card
, LCS_RECOVERY_THREAD
))
1733 kernel_thread(lcs_recovery
, (void *) card
, SIGCHLD
);
1734 #ifdef CONFIG_IP_MULTICAST
1735 if (lcs_do_start_thread(card
, LCS_SET_MC_THREAD
))
1736 kernel_thread(lcs_register_mc_addresses
,
1737 (void *) card
, SIGCHLD
);
1742 * Process control frames.
1745 lcs_get_control(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1747 LCS_DBF_TEXT(5, trace
, "getctrl");
1748 if (cmd
->initiator
== LCS_INITIATOR_LGW
) {
1749 switch(cmd
->cmd_code
) {
1750 case LCS_CMD_STARTUP
:
1751 case LCS_CMD_STARTLAN
:
1752 lcs_schedule_recovery(card
);
1754 case LCS_CMD_STOPLAN
:
1755 PRINT_WARN("Stoplan for %s initiated by LGW.\n",
1758 netif_carrier_off(card
->dev
);
1761 PRINT_INFO("UNRECOGNIZED LGW COMMAND\n");
1765 lcs_notify_lancmd_waiters(card
, cmd
);
1769 * Unpack network packet.
1772 lcs_get_skb(struct lcs_card
*card
, char *skb_data
, unsigned int skb_len
)
1774 struct sk_buff
*skb
;
1776 LCS_DBF_TEXT(5, trace
, "getskb");
1777 if (card
->dev
== NULL
||
1778 card
->state
!= DEV_STATE_UP
)
1779 /* The card isn't up. Ignore the packet. */
1782 skb
= dev_alloc_skb(skb_len
);
1784 PRINT_ERR("LCS: alloc_skb failed for device=%s\n",
1786 card
->stats
.rx_dropped
++;
1789 skb
->dev
= card
->dev
;
1790 memcpy(skb_put(skb
, skb_len
), skb_data
, skb_len
);
1791 skb
->protocol
= card
->lan_type_trans(skb
, card
->dev
);
1792 card
->stats
.rx_bytes
+= skb_len
;
1793 card
->stats
.rx_packets
++;
1794 *((__u32
*)skb
->cb
) = ++card
->pkt_seq
;
1799 * LCS main routine to get packets and lancmd replies from the buffers
1802 lcs_get_frames_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1804 struct lcs_card
*card
;
1805 struct lcs_header
*lcs_hdr
;
1808 LCS_DBF_TEXT(5, trace
, "lcsgtpkt");
1809 lcs_hdr
= (struct lcs_header
*) buffer
->data
;
1810 if (lcs_hdr
->offset
== LCS_ILLEGAL_OFFSET
) {
1811 LCS_DBF_TEXT(4, trace
, "-eiogpkt");
1814 card
= (struct lcs_card
*)
1815 ((char *) channel
- offsetof(struct lcs_card
, read
));
1817 while (lcs_hdr
->offset
!= 0) {
1818 if (lcs_hdr
->offset
<= 0 ||
1819 lcs_hdr
->offset
> LCS_IOBUFFERSIZE
||
1820 lcs_hdr
->offset
< offset
) {
1821 /* Offset invalid. */
1822 card
->stats
.rx_length_errors
++;
1823 card
->stats
.rx_errors
++;
1826 /* What kind of frame is it? */
1827 if (lcs_hdr
->type
== LCS_FRAME_TYPE_CONTROL
)
1828 /* Control frame. */
1829 lcs_get_control(card
, (struct lcs_cmd
*) lcs_hdr
);
1830 else if (lcs_hdr
->type
== LCS_FRAME_TYPE_ENET
||
1831 lcs_hdr
->type
== LCS_FRAME_TYPE_TR
||
1832 lcs_hdr
->type
== LCS_FRAME_TYPE_FDDI
)
1833 /* Normal network packet. */
1834 lcs_get_skb(card
, (char *)(lcs_hdr
+ 1),
1835 lcs_hdr
->offset
- offset
-
1836 sizeof(struct lcs_header
));
1838 /* Unknown frame type. */
1839 ; // FIXME: error message ?
1840 /* Proceed to next frame. */
1841 offset
= lcs_hdr
->offset
;
1842 lcs_hdr
->offset
= LCS_ILLEGAL_OFFSET
;
1843 lcs_hdr
= (struct lcs_header
*) (buffer
->data
+ offset
);
1845 /* The buffer is now empty. Make it ready again. */
1846 lcs_ready_buffer(&card
->read
, buffer
);
1850 * get network statistics for ifconfig and other user programs
1852 static struct net_device_stats
*
1853 lcs_getstats(struct net_device
*dev
)
1855 struct lcs_card
*card
;
1857 LCS_DBF_TEXT(4, trace
, "netstats");
1858 card
= (struct lcs_card
*) dev
->priv
;
1859 return &card
->stats
;
1864 * This function will be called by user doing ifconfig xxx down
1867 lcs_stop_device(struct net_device
*dev
)
1869 struct lcs_card
*card
;
1872 LCS_DBF_TEXT(2, trace
, "stopdev");
1873 card
= (struct lcs_card
*) dev
->priv
;
1874 netif_carrier_off(dev
);
1875 netif_tx_disable(dev
);
1876 dev
->flags
&= ~IFF_UP
;
1877 wait_event(card
->write
.wait_q
,
1878 (card
->write
.state
!= CH_STATE_RUNNING
));
1879 rc
= lcs_stopcard(card
);
1881 PRINT_ERR("Try it again!\n ");
1886 * start lcs device and make it runnable
1887 * This function will be called by user doing ifconfig xxx up
1890 lcs_open_device(struct net_device
*dev
)
1892 struct lcs_card
*card
;
1895 LCS_DBF_TEXT(2, trace
, "opendev");
1896 card
= (struct lcs_card
*) dev
->priv
;
1897 /* initialize statistics */
1898 rc
= lcs_detect(card
);
1900 PRINT_ERR("LCS:Error in opening device!\n");
1903 dev
->flags
|= IFF_UP
;
1904 netif_carrier_on(dev
);
1905 netif_wake_queue(dev
);
1906 card
->state
= DEV_STATE_UP
;
1912 * show function for portno called by cat or similar things
1915 lcs_portno_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1917 struct lcs_card
*card
;
1919 card
= (struct lcs_card
*)dev
->driver_data
;
1924 return sprintf(buf
, "%d\n", card
->portno
);
1928 * store the value which is piped to file portno
1931 lcs_portno_store (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1933 struct lcs_card
*card
;
1936 card
= (struct lcs_card
*)dev
->driver_data
;
1941 sscanf(buf
, "%u", &value
);
1942 /* TODO: sanity checks */
1943 card
->portno
= value
;
1949 static DEVICE_ATTR(portno
, 0644, lcs_portno_show
, lcs_portno_store
);
1952 lcs_type_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1954 struct ccwgroup_device
*cgdev
;
1956 cgdev
= to_ccwgroupdev(dev
);
1960 return sprintf(buf
, "%s\n", cu3088_type
[cgdev
->cdev
[0]->id
.driver_info
]);
1963 static DEVICE_ATTR(type
, 0444, lcs_type_show
, NULL
);
1966 lcs_timeout_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1968 struct lcs_card
*card
;
1970 card
= (struct lcs_card
*)dev
->driver_data
;
1972 return card
? sprintf(buf
, "%u\n", card
->lancmd_timeout
) : 0;
1976 lcs_timeout_store (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1978 struct lcs_card
*card
;
1981 card
= (struct lcs_card
*)dev
->driver_data
;
1986 sscanf(buf
, "%u", &value
);
1987 /* TODO: sanity checks */
1988 card
->lancmd_timeout
= value
;
1994 DEVICE_ATTR(lancmd_timeout
, 0644, lcs_timeout_show
, lcs_timeout_store
);
1997 lcs_dev_recover_store(struct device
*dev
, struct device_attribute
*attr
,
1998 const char *buf
, size_t count
)
2000 struct lcs_card
*card
= dev
->driver_data
;
2006 if (card
->state
!= DEV_STATE_UP
)
2008 i
= simple_strtoul(buf
, &tmp
, 16);
2010 lcs_schedule_recovery(card
);
2014 static DEVICE_ATTR(recover
, 0200, NULL
, lcs_dev_recover_store
);
2016 static struct attribute
* lcs_attrs
[] = {
2017 &dev_attr_portno
.attr
,
2018 &dev_attr_type
.attr
,
2019 &dev_attr_lancmd_timeout
.attr
,
2020 &dev_attr_recover
.attr
,
2024 static struct attribute_group lcs_attr_group
= {
2029 * lcs_probe_device is called on establishing a new ccwgroup_device.
2032 lcs_probe_device(struct ccwgroup_device
*ccwgdev
)
2034 struct lcs_card
*card
;
2037 if (!get_device(&ccwgdev
->dev
))
2040 LCS_DBF_TEXT(2, setup
, "add_dev");
2041 card
= lcs_alloc_card();
2043 PRINT_ERR("Allocation of lcs card failed\n");
2044 put_device(&ccwgdev
->dev
);
2047 ret
= sysfs_create_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2049 PRINT_ERR("Creating attributes failed");
2050 lcs_free_card(card
);
2051 put_device(&ccwgdev
->dev
);
2054 ccwgdev
->dev
.driver_data
= card
;
2055 ccwgdev
->cdev
[0]->handler
= lcs_irq
;
2056 ccwgdev
->cdev
[1]->handler
= lcs_irq
;
2057 card
->gdev
= ccwgdev
;
2058 INIT_WORK(&card
->kernel_thread_starter
,
2059 (void *) lcs_start_kernel_thread
, card
);
2060 card
->thread_start_mask
= 0;
2061 card
->thread_allowed_mask
= 0;
2062 card
->thread_running_mask
= 0;
2067 lcs_register_netdev(struct ccwgroup_device
*ccwgdev
)
2069 struct lcs_card
*card
;
2071 LCS_DBF_TEXT(2, setup
, "regnetdv");
2072 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2073 if (card
->dev
->reg_state
!= NETREG_UNINITIALIZED
)
2075 SET_NETDEV_DEV(card
->dev
, &ccwgdev
->dev
);
2076 return register_netdev(card
->dev
);
2080 * lcs_new_device will be called by setting the group device online.
2084 lcs_new_device(struct ccwgroup_device
*ccwgdev
)
2086 struct lcs_card
*card
;
2087 struct net_device
*dev
=NULL
;
2088 enum lcs_dev_states recover_state
;
2091 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2095 LCS_DBF_TEXT(2, setup
, "newdev");
2096 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2097 card
->read
.ccwdev
= ccwgdev
->cdev
[0];
2098 card
->write
.ccwdev
= ccwgdev
->cdev
[1];
2100 recover_state
= card
->state
;
2101 ccw_device_set_online(card
->read
.ccwdev
);
2102 ccw_device_set_online(card
->write
.ccwdev
);
2104 LCS_DBF_TEXT(3, setup
, "lcsnewdv");
2106 lcs_setup_card(card
);
2107 rc
= lcs_detect(card
);
2109 LCS_DBF_TEXT(2, setup
, "dtctfail");
2110 PRINT_WARN("Detection of LCS card failed with return code "
2111 "%d (0x%x)\n", rc
, rc
);
2116 LCS_DBF_TEXT(2, setup
, "samedev");
2117 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2120 switch (card
->lan_type
) {
2121 #ifdef CONFIG_NET_ETHERNET
2122 case LCS_FRAME_TYPE_ENET
:
2123 card
->lan_type_trans
= eth_type_trans
;
2124 dev
= alloc_etherdev(0);
2128 case LCS_FRAME_TYPE_TR
:
2129 card
->lan_type_trans
= tr_type_trans
;
2130 dev
= alloc_trdev(0);
2134 case LCS_FRAME_TYPE_FDDI
:
2135 card
->lan_type_trans
= fddi_type_trans
;
2136 dev
= alloc_fddidev(0);
2140 LCS_DBF_TEXT(3, setup
, "errinit");
2141 PRINT_ERR("LCS: Initialization failed\n");
2142 PRINT_ERR("LCS: No device found!\n");
2148 card
->dev
->priv
= card
;
2149 card
->dev
->open
= lcs_open_device
;
2150 card
->dev
->stop
= lcs_stop_device
;
2151 card
->dev
->hard_start_xmit
= lcs_start_xmit
;
2152 card
->dev
->get_stats
= lcs_getstats
;
2153 SET_MODULE_OWNER(dev
);
2154 memcpy(card
->dev
->dev_addr
, card
->mac
, LCS_MAC_LENGTH
);
2155 #ifdef CONFIG_IP_MULTICAST
2156 if (!lcs_check_multicast_support(card
))
2157 card
->dev
->set_multicast_list
= lcs_set_multicast_list
;
2160 lcs_set_allowed_threads(card
,0xffffffff);
2161 if (recover_state
== DEV_STATE_RECOVER
) {
2162 lcs_set_multicast_list(card
->dev
);
2163 card
->dev
->flags
|= IFF_UP
;
2164 netif_carrier_on(card
->dev
);
2165 netif_wake_queue(card
->dev
);
2166 card
->state
= DEV_STATE_UP
;
2171 if (lcs_register_netdev(ccwgdev
) != 0)
2174 /* Print out supported assists: IPv6 */
2175 PRINT_INFO("LCS device %s %s IPv6 support\n", card
->dev
->name
,
2176 (card
->ip_assists_supported
& LCS_IPASS_IPV6_SUPPORT
) ?
2177 "with" : "without");
2178 /* Print out supported assist: Multicast */
2179 PRINT_INFO("LCS device %s %s Multicast support\n", card
->dev
->name
,
2180 (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
) ?
2181 "with" : "without");
2185 ccw_device_set_offline(card
->read
.ccwdev
);
2186 ccw_device_set_offline(card
->write
.ccwdev
);
2191 * lcs_shutdown_device, called when setting the group device offline.
2194 __lcs_shutdown_device(struct ccwgroup_device
*ccwgdev
, int recovery_mode
)
2196 struct lcs_card
*card
;
2197 enum lcs_dev_states recover_state
;
2200 LCS_DBF_TEXT(3, setup
, "shtdndev");
2201 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2204 if (recovery_mode
== 0) {
2205 lcs_set_allowed_threads(card
, 0);
2206 if (lcs_wait_for_threads(card
, LCS_SET_MC_THREAD
))
2207 return -ERESTARTSYS
;
2209 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2210 recover_state
= card
->state
;
2212 ret
= lcs_stop_device(card
->dev
);
2213 ret
= ccw_device_set_offline(card
->read
.ccwdev
);
2214 ret
= ccw_device_set_offline(card
->write
.ccwdev
);
2215 if (recover_state
== DEV_STATE_UP
) {
2216 card
->state
= DEV_STATE_RECOVER
;
2224 lcs_shutdown_device(struct ccwgroup_device
*ccwgdev
)
2226 return __lcs_shutdown_device(ccwgdev
, 0);
2230 * drive lcs recovery after startup and startlan initiated by Lan Gateway
2233 lcs_recovery(void *ptr
)
2235 struct lcs_card
*card
;
2236 struct ccwgroup_device
*gdev
;
2239 card
= (struct lcs_card
*) ptr
;
2240 daemonize("lcs_recover");
2242 LCS_DBF_TEXT(4, trace
, "recover1");
2243 if (!lcs_do_run_thread(card
, LCS_RECOVERY_THREAD
))
2245 LCS_DBF_TEXT(4, trace
, "recover2");
2247 PRINT_WARN("Recovery of device %s started...\n", gdev
->dev
.bus_id
);
2248 rc
= __lcs_shutdown_device(gdev
, 1);
2249 rc
= lcs_new_device(gdev
);
2251 PRINT_INFO("Device %s successfully recovered!\n",
2254 PRINT_INFO("Device %s could not be recovered!\n",
2256 lcs_clear_thread_running_bit(card
, LCS_RECOVERY_THREAD
);
2261 * lcs_remove_device, free buffers and card
2264 lcs_remove_device(struct ccwgroup_device
*ccwgdev
)
2266 struct lcs_card
*card
;
2268 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2272 PRINT_INFO("Removing lcs group device ....\n");
2273 LCS_DBF_TEXT(3, setup
, "remdev");
2274 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2275 if (ccwgdev
->state
== CCWGROUP_ONLINE
) {
2276 lcs_shutdown_device(ccwgdev
);
2279 unregister_netdev(card
->dev
);
2280 sysfs_remove_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2281 lcs_cleanup_card(card
);
2282 lcs_free_card(card
);
2283 put_device(&ccwgdev
->dev
);
2287 * LCS ccwgroup driver registration
2289 static struct ccwgroup_driver lcs_group_driver
= {
2290 .owner
= THIS_MODULE
,
2293 .driver_id
= 0xD3C3E2,
2294 .probe
= lcs_probe_device
,
2295 .remove
= lcs_remove_device
,
2296 .set_online
= lcs_new_device
,
2297 .set_offline
= lcs_shutdown_device
,
2301 * LCS Module/Kernel initialization function
2304 __init
lcs_init_module(void)
2308 PRINT_INFO("Loading %s\n",version
);
2309 rc
= lcs_register_debug_facility();
2310 LCS_DBF_TEXT(0, setup
, "lcsinit");
2312 PRINT_ERR("Initialization failed\n");
2316 rc
= register_cu3088_discipline(&lcs_group_driver
);
2318 PRINT_ERR("Initialization failed\n");
2326 * LCS module cleanup function
2329 __exit
lcs_cleanup_module(void)
2331 PRINT_INFO("Terminating lcs module.\n");
2332 LCS_DBF_TEXT(0, trace
, "cleanup");
2333 unregister_cu3088_discipline(&lcs_group_driver
);
2334 lcs_unregister_debug_facility();
2337 module_init(lcs_init_module
);
2338 module_exit(lcs_cleanup_module
);
2340 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
2341 MODULE_LICENSE("GPL");