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 (pavlic@de.ibm.com) and
12 * Martin Schwidefsky <schwidefsky@de.ibm.com>
14 * $Revision: 1.92 $ $Date: 2004/09/03 08:06:11 $
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <linux/module.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h>
35 #include <linux/trdevice.h>
36 #include <linux/fddidevice.h>
37 #include <linux/inetdevice.h>
39 #include <linux/igmp.h>
40 #include <linux/delay.h>
44 #include <asm/debug.h>
45 #include <asm/idals.h>
46 #include <asm/timex.h>
47 #include <linux/device.h>
48 #include <asm/ccwgroup.h>
54 #if !defined(CONFIG_NET_ETHERNET) && \
55 !defined(CONFIG_TR) && !defined(CONFIG_FDDI)
56 #error Cannot compile lcs.c without some net devices switched on.
60 * initialization string for output
62 #define VERSION_LCS_C "$Revision: 1.92 $"
64 static char version
[] __initdata
= "LCS driver ("VERSION_LCS_C
"/" VERSION_LCS_H
")";
65 static char debug_buffer
[255];
70 static void lcs_tasklet(unsigned long);
71 static void lcs_start_kernel_thread(struct lcs_card
*card
);
72 static void lcs_get_frames_cb(struct lcs_channel
*, struct lcs_buffer
*);
73 static int lcs_send_delipm(struct lcs_card
*, struct lcs_ipm_list
*);
76 * Debug Facility Stuff
78 static debug_info_t
*lcs_dbf_setup
;
79 static debug_info_t
*lcs_dbf_trace
;
82 * LCS Debug Facility functions
85 lcs_unregister_debug_facility(void)
88 debug_unregister(lcs_dbf_setup
);
90 debug_unregister(lcs_dbf_trace
);
94 lcs_register_debug_facility(void)
96 lcs_dbf_setup
= debug_register("lcs_setup", 1, 1, 8);
97 lcs_dbf_trace
= debug_register("lcs_trace", 1, 2, 8);
98 if (lcs_dbf_setup
== NULL
|| lcs_dbf_trace
== NULL
) {
99 PRINT_ERR("Not enough memory for debug facility.\n");
100 lcs_unregister_debug_facility();
103 debug_register_view(lcs_dbf_setup
, &debug_hex_ascii_view
);
104 debug_set_level(lcs_dbf_setup
, 4);
105 debug_register_view(lcs_dbf_trace
, &debug_hex_ascii_view
);
106 debug_set_level(lcs_dbf_trace
, 4);
111 * Allocate io buffers.
114 lcs_alloc_channel(struct lcs_channel
*channel
)
118 LCS_DBF_TEXT(2, setup
, "ichalloc");
119 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
120 /* alloc memory fo iobuffer */
121 channel
->iob
[cnt
].data
= (void *)
122 kmalloc(LCS_IOBUFFERSIZE
, GFP_DMA
| GFP_KERNEL
);
123 if (channel
->iob
[cnt
].data
== NULL
)
125 memset(channel
->iob
[cnt
].data
, 0, LCS_IOBUFFERSIZE
);
126 channel
->iob
[cnt
].state
= BUF_STATE_EMPTY
;
128 if (cnt
< LCS_NUM_BUFFS
) {
129 /* Not all io buffers could be allocated. */
130 LCS_DBF_TEXT(2, setup
, "echalloc");
132 kfree(channel
->iob
[cnt
].data
);
142 lcs_free_channel(struct lcs_channel
*channel
)
146 LCS_DBF_TEXT(2, setup
, "ichfree");
147 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
148 if (channel
->iob
[cnt
].data
!= NULL
)
149 kfree(channel
->iob
[cnt
].data
);
150 channel
->iob
[cnt
].data
= NULL
;
158 lcs_cleanup_channel(struct lcs_channel
*channel
)
160 LCS_DBF_TEXT(3, setup
, "cleanch");
161 /* Kill write channel tasklets. */
162 tasklet_kill(&channel
->irq_tasklet
);
163 /* Free channel buffers. */
164 lcs_free_channel(channel
);
168 * LCS free memory for card and channels.
171 lcs_free_card(struct lcs_card
*card
)
173 LCS_DBF_TEXT(2, setup
, "remcard");
174 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
179 * LCS alloc memory for card and channels
181 static struct lcs_card
*
184 struct lcs_card
*card
;
187 LCS_DBF_TEXT(2, setup
, "alloclcs");
189 card
= kmalloc(sizeof(struct lcs_card
), GFP_KERNEL
| GFP_DMA
);
192 memset(card
, 0, sizeof(struct lcs_card
));
193 card
->lan_type
= LCS_FRAME_TYPE_AUTO
;
194 card
->lancmd_timeout
= LCS_LANCMD_TIMEOUT_DEFAULT
;
195 /* Allocate io buffers for the read channel. */
196 rc
= lcs_alloc_channel(&card
->read
);
198 LCS_DBF_TEXT(2, setup
, "iccwerr");
202 /* Allocate io buffers for the write channel. */
203 rc
= lcs_alloc_channel(&card
->write
);
205 LCS_DBF_TEXT(2, setup
, "iccwerr");
206 lcs_cleanup_channel(&card
->read
);
211 #ifdef CONFIG_IP_MULTICAST
212 INIT_LIST_HEAD(&card
->ipm_list
);
214 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
219 * Setup read channel.
222 lcs_setup_read_ccws(struct lcs_card
*card
)
226 LCS_DBF_TEXT(2, setup
, "ireadccw");
227 /* Setup read ccws. */
228 memset(card
->read
.ccws
, 0, sizeof (struct ccw1
) * (LCS_NUM_BUFFS
+ 1));
229 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
230 card
->read
.ccws
[cnt
].cmd_code
= LCS_CCW_READ
;
231 card
->read
.ccws
[cnt
].count
= LCS_IOBUFFERSIZE
;
232 card
->read
.ccws
[cnt
].flags
=
233 CCW_FLAG_CC
| CCW_FLAG_SLI
| CCW_FLAG_PCI
;
235 * Note: we have allocated the buffer with GFP_DMA, so
236 * we do not need to do set_normalized_cda.
238 card
->read
.ccws
[cnt
].cda
=
239 (__u32
) __pa(card
->read
.iob
[cnt
].data
);
240 ((struct lcs_header
*)
241 card
->read
.iob
[cnt
].data
)->offset
= LCS_ILLEGAL_OFFSET
;
242 card
->read
.iob
[cnt
].callback
= lcs_get_frames_cb
;
243 card
->read
.iob
[cnt
].state
= BUF_STATE_READY
;
244 card
->read
.iob
[cnt
].count
= LCS_IOBUFFERSIZE
;
246 card
->read
.ccws
[0].flags
&= ~CCW_FLAG_PCI
;
247 card
->read
.ccws
[LCS_NUM_BUFFS
- 1].flags
&= ~CCW_FLAG_PCI
;
248 card
->read
.ccws
[LCS_NUM_BUFFS
- 1].flags
|= CCW_FLAG_SUSPEND
;
249 /* Last ccw is a tic (transfer in channel). */
250 card
->read
.ccws
[LCS_NUM_BUFFS
].cmd_code
= LCS_CCW_TRANSFER
;
251 card
->read
.ccws
[LCS_NUM_BUFFS
].cda
=
252 (__u32
) __pa(card
->read
.ccws
);
253 /* Setg initial state of the read channel. */
254 card
->read
.state
= CH_STATE_INIT
;
256 card
->read
.io_idx
= 0;
257 card
->read
.buf_idx
= 0;
261 lcs_setup_read(struct lcs_card
*card
)
263 LCS_DBF_TEXT(3, setup
, "initread");
265 lcs_setup_read_ccws(card
);
266 /* Initialize read channel tasklet. */
267 card
->read
.irq_tasklet
.data
= (unsigned long) &card
->read
;
268 card
->read
.irq_tasklet
.func
= lcs_tasklet
;
269 /* Initialize waitqueue. */
270 init_waitqueue_head(&card
->read
.wait_q
);
274 * Setup write channel.
277 lcs_setup_write_ccws(struct lcs_card
*card
)
281 LCS_DBF_TEXT(3, setup
, "iwritccw");
282 /* Setup write ccws. */
283 memset(card
->write
.ccws
, 0, sizeof(struct ccw1
) * LCS_NUM_BUFFS
+ 1);
284 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
285 card
->write
.ccws
[cnt
].cmd_code
= LCS_CCW_WRITE
;
286 card
->write
.ccws
[cnt
].count
= 0;
287 card
->write
.ccws
[cnt
].flags
=
288 CCW_FLAG_SUSPEND
| CCW_FLAG_CC
| CCW_FLAG_SLI
;
290 * Note: we have allocated the buffer with GFP_DMA, so
291 * we do not need to do set_normalized_cda.
293 card
->write
.ccws
[cnt
].cda
=
294 (__u32
) __pa(card
->write
.iob
[cnt
].data
);
296 /* Last ccw is a tic (transfer in channel). */
297 card
->write
.ccws
[LCS_NUM_BUFFS
].cmd_code
= LCS_CCW_TRANSFER
;
298 card
->write
.ccws
[LCS_NUM_BUFFS
].cda
=
299 (__u32
) __pa(card
->write
.ccws
);
300 /* Set initial state of the write channel. */
301 card
->read
.state
= CH_STATE_INIT
;
303 card
->write
.io_idx
= 0;
304 card
->write
.buf_idx
= 0;
308 lcs_setup_write(struct lcs_card
*card
)
310 LCS_DBF_TEXT(3, setup
, "initwrit");
312 lcs_setup_write_ccws(card
);
313 /* Initialize write channel tasklet. */
314 card
->write
.irq_tasklet
.data
= (unsigned long) &card
->write
;
315 card
->write
.irq_tasklet
.func
= lcs_tasklet
;
316 /* Initialize waitqueue. */
317 init_waitqueue_head(&card
->write
.wait_q
);
321 lcs_set_allowed_threads(struct lcs_card
*card
, unsigned long threads
)
325 spin_lock_irqsave(&card
->mask_lock
, flags
);
326 card
->thread_allowed_mask
= threads
;
327 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
328 wake_up(&card
->wait_q
);
331 lcs_threads_running(struct lcs_card
*card
, unsigned long threads
)
336 spin_lock_irqsave(&card
->mask_lock
, flags
);
337 rc
= (card
->thread_running_mask
& threads
);
338 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
343 lcs_wait_for_threads(struct lcs_card
*card
, unsigned long threads
)
345 return wait_event_interruptible(card
->wait_q
,
346 lcs_threads_running(card
, threads
) == 0);
350 lcs_set_thread_start_bit(struct lcs_card
*card
, unsigned long thread
)
354 spin_lock_irqsave(&card
->mask_lock
, flags
);
355 if ( !(card
->thread_allowed_mask
& thread
) ||
356 (card
->thread_start_mask
& thread
) ) {
357 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
360 card
->thread_start_mask
|= thread
;
361 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
366 lcs_clear_thread_running_bit(struct lcs_card
*card
, unsigned long thread
)
370 spin_lock_irqsave(&card
->mask_lock
, flags
);
371 card
->thread_running_mask
&= ~thread
;
372 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
373 wake_up(&card
->wait_q
);
377 __lcs_do_run_thread(struct lcs_card
*card
, unsigned long thread
)
382 spin_lock_irqsave(&card
->mask_lock
, flags
);
383 if (card
->thread_start_mask
& thread
){
384 if ((card
->thread_allowed_mask
& thread
) &&
385 !(card
->thread_running_mask
& thread
)){
387 card
->thread_start_mask
&= ~thread
;
388 card
->thread_running_mask
|= thread
;
392 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
397 lcs_do_run_thread(struct lcs_card
*card
, unsigned long thread
)
400 wait_event(card
->wait_q
,
401 (rc
= __lcs_do_run_thread(card
, thread
)) >= 0);
406 lcs_do_start_thread(struct lcs_card
*card
, unsigned long thread
)
411 spin_lock_irqsave(&card
->mask_lock
, flags
);
412 LCS_DBF_TEXT_(4, trace
, " %02x%02x%02x",
413 (u8
) card
->thread_start_mask
,
414 (u8
) card
->thread_allowed_mask
,
415 (u8
) card
->thread_running_mask
);
416 rc
= (card
->thread_start_mask
& thread
);
417 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
422 * Initialize channels,card and state machines.
425 lcs_setup_card(struct lcs_card
*card
)
427 LCS_DBF_TEXT(2, setup
, "initcard");
428 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
430 lcs_setup_read(card
);
431 lcs_setup_write(card
);
432 /* Set cards initial state. */
433 card
->state
= DEV_STATE_DOWN
;
434 card
->tx_buffer
= NULL
;
435 card
->tx_emitted
= 0;
437 /* Initialize kernel thread task used for LGW commands. */
438 INIT_WORK(&card
->kernel_thread_starter
,
439 (void *)lcs_start_kernel_thread
,card
);
440 card
->thread_start_mask
= 0;
441 card
->thread_allowed_mask
= 0;
442 card
->thread_running_mask
= 0;
443 init_waitqueue_head(&card
->wait_q
);
444 spin_lock_init(&card
->lock
);
445 spin_lock_init(&card
->ipm_lock
);
446 spin_lock_init(&card
->mask_lock
);
447 #ifdef CONFIG_IP_MULTICAST
448 INIT_LIST_HEAD(&card
->ipm_list
);
450 INIT_LIST_HEAD(&card
->lancmd_waiters
);
454 lcs_clear_multicast_list(struct lcs_card
*card
)
456 #ifdef CONFIG_IP_MULTICAST
457 struct lcs_ipm_list
*ipm
;
460 /* Free multicast list. */
461 LCS_DBF_TEXT(3, setup
, "clmclist");
462 spin_lock_irqsave(&card
->ipm_lock
, flags
);
463 while (!list_empty(&card
->ipm_list
)){
464 ipm
= list_entry(card
->ipm_list
.next
,
465 struct lcs_ipm_list
, list
);
466 list_del(&ipm
->list
);
467 if (ipm
->ipm_state
!= LCS_IPM_STATE_SET_REQUIRED
){
468 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
469 lcs_send_delipm(card
, ipm
);
470 spin_lock_irqsave(&card
->ipm_lock
, flags
);
474 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
478 * Cleanup channels,card and state machines.
481 lcs_cleanup_card(struct lcs_card
*card
)
484 LCS_DBF_TEXT(3, setup
, "cleancrd");
485 LCS_DBF_HEX(2,setup
,&card
,sizeof(void*));
487 if (card
->dev
!= NULL
)
488 free_netdev(card
->dev
);
489 /* Cleanup channels. */
490 lcs_cleanup_channel(&card
->write
);
491 lcs_cleanup_channel(&card
->read
);
498 lcs_start_channel(struct lcs_channel
*channel
)
503 LCS_DBF_TEXT_(4,trace
,"ssch%s", channel
->ccwdev
->dev
.bus_id
);
504 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
505 rc
= ccw_device_start(channel
->ccwdev
,
506 channel
->ccws
+ channel
->io_idx
, 0, 0,
507 DOIO_DENY_PREFETCH
| DOIO_ALLOW_SUSPEND
);
509 channel
->state
= CH_STATE_RUNNING
;
510 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
512 LCS_DBF_TEXT_(4,trace
,"essh%s", channel
->ccwdev
->dev
.bus_id
);
513 PRINT_ERR("Error in starting channel, rc=%d!\n", rc
);
519 lcs_clear_channel(struct lcs_channel
*channel
)
524 LCS_DBF_TEXT(4,trace
,"clearch");
525 LCS_DBF_TEXT_(4,trace
,"%s", channel
->ccwdev
->dev
.bus_id
);
526 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
527 rc
= ccw_device_clear(channel
->ccwdev
, (addr_t
) channel
);
528 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
530 LCS_DBF_TEXT_(4,trace
,"ecsc%s", channel
->ccwdev
->dev
.bus_id
);
533 wait_event(channel
->wait_q
, (channel
->state
== CH_STATE_CLEARED
));
534 channel
->state
= CH_STATE_STOPPED
;
543 lcs_stop_channel(struct lcs_channel
*channel
)
548 if (channel
->state
== CH_STATE_STOPPED
)
550 LCS_DBF_TEXT(4,trace
,"haltsch");
551 LCS_DBF_TEXT_(4,trace
,"%s", channel
->ccwdev
->dev
.bus_id
);
552 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
553 rc
= ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
554 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
556 LCS_DBF_TEXT_(4,trace
,"ehsc%s", channel
->ccwdev
->dev
.bus_id
);
559 /* Asynchronous halt initialted. Wait for its completion. */
560 wait_event(channel
->wait_q
, (channel
->state
== CH_STATE_HALTED
));
561 lcs_clear_channel(channel
);
566 * start read and write channel
569 lcs_start_channels(struct lcs_card
*card
)
573 LCS_DBF_TEXT(2, trace
, "chstart");
574 /* start read channel */
575 rc
= lcs_start_channel(&card
->read
);
578 /* start write channel */
579 rc
= lcs_start_channel(&card
->write
);
581 lcs_stop_channel(&card
->read
);
586 * stop read and write channel
589 lcs_stop_channels(struct lcs_card
*card
)
591 LCS_DBF_TEXT(2, trace
, "chhalt");
592 lcs_stop_channel(&card
->read
);
593 lcs_stop_channel(&card
->write
);
600 static struct lcs_buffer
*
601 __lcs_get_buffer(struct lcs_channel
*channel
)
605 LCS_DBF_TEXT(5, trace
, "_getbuff");
606 index
= channel
->io_idx
;
608 if (channel
->iob
[index
].state
== BUF_STATE_EMPTY
) {
609 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
610 return channel
->iob
+ index
;
612 index
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
613 } while (index
!= channel
->io_idx
);
617 static struct lcs_buffer
*
618 lcs_get_buffer(struct lcs_channel
*channel
)
620 struct lcs_buffer
*buffer
;
623 LCS_DBF_TEXT(5, trace
, "getbuff");
624 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
625 buffer
= __lcs_get_buffer(channel
);
626 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
631 * Resume channel program if the channel is suspended.
634 __lcs_resume_channel(struct lcs_channel
*channel
)
638 if (channel
->state
!= CH_STATE_SUSPENDED
)
640 if (channel
->ccws
[channel
->io_idx
].flags
& CCW_FLAG_SUSPEND
)
642 LCS_DBF_TEXT_(5, trace
, "rsch%s", channel
->ccwdev
->dev
.bus_id
);
643 rc
= ccw_device_resume(channel
->ccwdev
);
645 LCS_DBF_TEXT_(4, trace
, "ersc%s", channel
->ccwdev
->dev
.bus_id
);
646 PRINT_ERR("Error in lcs_resume_channel: rc=%d\n",rc
);
648 channel
->state
= CH_STATE_RUNNING
;
654 * Make a buffer ready for processing.
657 __lcs_ready_buffer_bits(struct lcs_channel
*channel
, int index
)
661 LCS_DBF_TEXT(5, trace
, "rdybits");
662 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
663 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
664 /* Check if we may clear the suspend bit of this buffer. */
665 if (channel
->ccws
[next
].flags
& CCW_FLAG_SUSPEND
) {
666 /* Check if we have to set the PCI bit. */
667 if (!(channel
->ccws
[prev
].flags
& CCW_FLAG_SUSPEND
))
668 /* Suspend bit of the previous buffer is not set. */
669 channel
->ccws
[index
].flags
|= CCW_FLAG_PCI
;
670 /* Suspend bit of the next buffer is set. */
671 channel
->ccws
[index
].flags
&= ~CCW_FLAG_SUSPEND
;
676 lcs_ready_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
681 LCS_DBF_TEXT(5, trace
, "rdybuff");
682 if (buffer
->state
!= BUF_STATE_LOCKED
&&
683 buffer
->state
!= BUF_STATE_PROCESSED
)
685 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
686 buffer
->state
= BUF_STATE_READY
;
687 index
= buffer
- channel
->iob
;
689 channel
->ccws
[index
].count
= buffer
->count
;
690 /* Check relevant PCI/suspend bits. */
691 __lcs_ready_buffer_bits(channel
, index
);
692 rc
= __lcs_resume_channel(channel
);
693 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
698 * Mark the buffer as processed. Take care of the suspend bit
699 * of the previous buffer. This function is called from
700 * interrupt context, so the lock must not be taken.
703 __lcs_processed_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
705 int index
, prev
, next
;
707 LCS_DBF_TEXT(5, trace
, "prcsbuff");
708 if (buffer
->state
!= BUF_STATE_READY
)
710 buffer
->state
= BUF_STATE_PROCESSED
;
711 index
= buffer
- channel
->iob
;
712 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
713 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
714 /* Set the suspend bit and clear the PCI bit of this buffer. */
715 channel
->ccws
[index
].flags
|= CCW_FLAG_SUSPEND
;
716 channel
->ccws
[index
].flags
&= ~CCW_FLAG_PCI
;
717 /* Check the suspend bit of the previous buffer. */
718 if (channel
->iob
[prev
].state
== BUF_STATE_READY
) {
720 * Previous buffer is in state ready. It might have
721 * happened in lcs_ready_buffer that the suspend bit
722 * has not been cleared to avoid an endless loop.
725 __lcs_ready_buffer_bits(channel
, prev
);
727 /* Clear PCI bit of next buffer. */
728 channel
->ccws
[next
].flags
&= ~CCW_FLAG_PCI
;
729 return __lcs_resume_channel(channel
);
733 * Put a processed buffer back to state empty.
736 lcs_release_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
740 LCS_DBF_TEXT(5, trace
, "relbuff");
741 if (buffer
->state
!= BUF_STATE_LOCKED
&&
742 buffer
->state
!= BUF_STATE_PROCESSED
)
744 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
745 buffer
->state
= BUF_STATE_EMPTY
;
746 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
750 * Get buffer for a lan command.
752 static struct lcs_buffer
*
753 lcs_get_lancmd(struct lcs_card
*card
, int count
)
755 struct lcs_buffer
*buffer
;
758 LCS_DBF_TEXT(4, trace
, "getlncmd");
759 /* Get buffer and wait if none is available. */
760 wait_event(card
->write
.wait_q
,
761 ((buffer
= lcs_get_buffer(&card
->write
)) != NULL
));
762 count
+= sizeof(struct lcs_header
);
763 *(__u16
*)(buffer
->data
+ count
) = 0;
764 buffer
->count
= count
+ sizeof(__u16
);
765 buffer
->callback
= lcs_release_buffer
;
766 cmd
= (struct lcs_cmd
*) buffer
->data
;
768 cmd
->type
= LCS_FRAME_TYPE_CONTROL
;
775 lcs_get_reply(struct lcs_reply
*reply
)
777 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
778 atomic_inc(&reply
->refcnt
);
782 lcs_put_reply(struct lcs_reply
*reply
)
784 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
785 if (atomic_dec_and_test(&reply
->refcnt
)) {
791 static struct lcs_reply
*
792 lcs_alloc_reply(struct lcs_cmd
*cmd
)
794 struct lcs_reply
*reply
;
796 LCS_DBF_TEXT(4, trace
, "getreply");
798 reply
= kmalloc(sizeof(struct lcs_reply
), GFP_ATOMIC
);
801 memset(reply
,0,sizeof(struct lcs_reply
));
802 atomic_set(&reply
->refcnt
,1);
803 reply
->sequence_no
= cmd
->sequence_no
;
806 init_waitqueue_head(&reply
->wait_q
);
812 * Notifier function for lancmd replies. Called from read irq.
815 lcs_notify_lancmd_waiters(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
817 struct list_head
*l
, *n
;
818 struct lcs_reply
*reply
;
820 LCS_DBF_TEXT(4, trace
, "notiwait");
821 spin_lock(&card
->lock
);
822 list_for_each_safe(l
, n
, &card
->lancmd_waiters
) {
823 reply
= list_entry(l
, struct lcs_reply
, list
);
824 if (reply
->sequence_no
== cmd
->sequence_no
) {
825 lcs_get_reply(reply
);
826 list_del_init(&reply
->list
);
827 if (reply
->callback
!= NULL
)
828 reply
->callback(card
, cmd
);
830 reply
->rc
= cmd
->return_code
;
831 wake_up(&reply
->wait_q
);
832 lcs_put_reply(reply
);
836 spin_unlock(&card
->lock
);
840 * Emit buffer of a lan comand.
843 lcs_lancmd_timeout(unsigned long data
)
845 struct lcs_reply
*reply
, *list_reply
, *r
;
848 LCS_DBF_TEXT(4, trace
, "timeout");
849 reply
= (struct lcs_reply
*) data
;
850 spin_lock_irqsave(&reply
->card
->lock
, flags
);
851 list_for_each_entry_safe(list_reply
, r
,
852 &reply
->card
->lancmd_waiters
,list
) {
853 if (reply
== list_reply
) {
854 lcs_get_reply(reply
);
855 list_del_init(&reply
->list
);
856 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
859 wake_up(&reply
->wait_q
);
860 lcs_put_reply(reply
);
864 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
868 lcs_send_lancmd(struct lcs_card
*card
, struct lcs_buffer
*buffer
,
869 void (*reply_callback
)(struct lcs_card
*, struct lcs_cmd
*))
871 struct lcs_reply
*reply
;
873 struct timer_list timer
;
877 LCS_DBF_TEXT(4, trace
, "sendcmd");
878 cmd
= (struct lcs_cmd
*) buffer
->data
;
879 cmd
->return_code
= 0;
880 cmd
->sequence_no
= card
->sequence_no
++;
881 reply
= lcs_alloc_reply(cmd
);
884 reply
->callback
= reply_callback
;
886 spin_lock_irqsave(&card
->lock
, flags
);
887 list_add_tail(&reply
->list
, &card
->lancmd_waiters
);
888 spin_unlock_irqrestore(&card
->lock
, flags
);
890 buffer
->callback
= lcs_release_buffer
;
891 rc
= lcs_ready_buffer(&card
->write
, buffer
);
895 timer
.function
= lcs_lancmd_timeout
;
896 timer
.data
= (unsigned long) reply
;
897 timer
.expires
= jiffies
+ HZ
*card
->lancmd_timeout
;
899 wait_event(reply
->wait_q
, reply
->received
);
900 del_timer_sync(&timer
);
901 LCS_DBF_TEXT_(4, trace
, "rc:%d",reply
->rc
);
903 lcs_put_reply(reply
);
904 return rc
? -EIO
: 0;
908 * LCS startup command
911 lcs_send_startup(struct lcs_card
*card
, __u8 initiator
)
913 struct lcs_buffer
*buffer
;
916 LCS_DBF_TEXT(2, trace
, "startup");
917 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
918 cmd
= (struct lcs_cmd
*) buffer
->data
;
919 cmd
->cmd_code
= LCS_CMD_STARTUP
;
920 cmd
->initiator
= initiator
;
921 cmd
->cmd
.lcs_startup
.buff_size
= LCS_IOBUFFERSIZE
;
922 return lcs_send_lancmd(card
, buffer
, NULL
);
926 * LCS shutdown command
929 lcs_send_shutdown(struct lcs_card
*card
)
931 struct lcs_buffer
*buffer
;
934 LCS_DBF_TEXT(2, trace
, "shutdown");
935 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
936 cmd
= (struct lcs_cmd
*) buffer
->data
;
937 cmd
->cmd_code
= LCS_CMD_SHUTDOWN
;
938 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
939 return lcs_send_lancmd(card
, buffer
, NULL
);
943 * LCS lanstat command
946 __lcs_lanstat_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
948 LCS_DBF_TEXT(2, trace
, "statcb");
949 memcpy(card
->mac
, cmd
->cmd
.lcs_lanstat_cmd
.mac_addr
, LCS_MAC_LENGTH
);
953 lcs_send_lanstat(struct lcs_card
*card
)
955 struct lcs_buffer
*buffer
;
958 LCS_DBF_TEXT(2,trace
, "cmdstat");
959 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
960 cmd
= (struct lcs_cmd
*) buffer
->data
;
961 /* Setup lanstat command. */
962 cmd
->cmd_code
= LCS_CMD_LANSTAT
;
963 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
964 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
965 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
966 return lcs_send_lancmd(card
, buffer
, __lcs_lanstat_cb
);
970 * send stoplan command
973 lcs_send_stoplan(struct lcs_card
*card
, __u8 initiator
)
975 struct lcs_buffer
*buffer
;
978 LCS_DBF_TEXT(2, trace
, "cmdstpln");
979 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
980 cmd
= (struct lcs_cmd
*) buffer
->data
;
981 cmd
->cmd_code
= LCS_CMD_STOPLAN
;
982 cmd
->initiator
= initiator
;
983 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
984 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
985 return lcs_send_lancmd(card
, buffer
, NULL
);
989 * send startlan command
992 __lcs_send_startlan_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
994 LCS_DBF_TEXT(2, trace
, "srtlancb");
995 card
->lan_type
= cmd
->cmd
.lcs_std_cmd
.lan_type
;
996 card
->portno
= cmd
->cmd
.lcs_std_cmd
.portno
;
1000 lcs_send_startlan(struct lcs_card
*card
, __u8 initiator
)
1002 struct lcs_buffer
*buffer
;
1003 struct lcs_cmd
*cmd
;
1005 LCS_DBF_TEXT(2, trace
, "cmdstaln");
1006 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
1007 cmd
= (struct lcs_cmd
*) buffer
->data
;
1008 cmd
->cmd_code
= LCS_CMD_STARTLAN
;
1009 cmd
->initiator
= initiator
;
1010 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
1011 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
1012 return lcs_send_lancmd(card
, buffer
, __lcs_send_startlan_cb
);
1015 #ifdef CONFIG_IP_MULTICAST
1017 * send setipm command (Multicast)
1020 lcs_send_setipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1022 struct lcs_buffer
*buffer
;
1023 struct lcs_cmd
*cmd
;
1025 LCS_DBF_TEXT(2, trace
, "cmdsetim");
1026 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1027 cmd
= (struct lcs_cmd
*) buffer
->data
;
1028 cmd
->cmd_code
= LCS_CMD_SETIPM
;
1029 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1030 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1031 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1032 cmd
->cmd
.lcs_qipassist
.version
= 4;
1033 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1034 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1035 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1036 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1037 return lcs_send_lancmd(card
, buffer
, NULL
);
1041 * send delipm command (Multicast)
1044 lcs_send_delipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1046 struct lcs_buffer
*buffer
;
1047 struct lcs_cmd
*cmd
;
1049 LCS_DBF_TEXT(2, trace
, "cmddelim");
1050 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1051 cmd
= (struct lcs_cmd
*) buffer
->data
;
1052 cmd
->cmd_code
= LCS_CMD_DELIPM
;
1053 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1054 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1055 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1056 cmd
->cmd
.lcs_qipassist
.version
= 4;
1057 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1058 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1059 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1060 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1061 return lcs_send_lancmd(card
, buffer
, NULL
);
1065 * check if multicast is supported by LCS
1068 __lcs_check_multicast_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1070 LCS_DBF_TEXT(2, trace
, "chkmccb");
1071 card
->ip_assists_supported
=
1072 cmd
->cmd
.lcs_qipassist
.ip_assists_supported
;
1073 card
->ip_assists_enabled
=
1074 cmd
->cmd
.lcs_qipassist
.ip_assists_enabled
;
1078 lcs_check_multicast_support(struct lcs_card
*card
)
1080 struct lcs_buffer
*buffer
;
1081 struct lcs_cmd
*cmd
;
1084 LCS_DBF_TEXT(2, trace
, "cmdqipa");
1085 /* Send query ipassist. */
1086 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
1087 cmd
= (struct lcs_cmd
*) buffer
->data
;
1088 cmd
->cmd_code
= LCS_CMD_QIPASSIST
;
1089 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1090 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1091 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1092 cmd
->cmd
.lcs_qipassist
.version
= 4;
1093 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1094 rc
= lcs_send_lancmd(card
, buffer
, __lcs_check_multicast_cb
);
1096 PRINT_ERR("Query IPAssist failed. Assuming unsupported!\n");
1099 /* Print out supported assists: IPv6 */
1100 PRINT_INFO("LCS device %s %s IPv6 support\n", card
->dev
->name
,
1101 (card
->ip_assists_supported
& LCS_IPASS_IPV6_SUPPORT
) ?
1102 "with" : "without");
1103 /* Print out supported assist: Multicast */
1104 PRINT_INFO("LCS device %s %s Multicast support\n", card
->dev
->name
,
1105 (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
) ?
1106 "with" : "without");
1107 if (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
)
1113 * set or del multicast address on LCS card
1116 lcs_fix_multicast_list(struct lcs_card
*card
)
1118 struct list_head failed_list
;
1119 struct lcs_ipm_list
*ipm
, *tmp
;
1120 unsigned long flags
;
1123 LCS_DBF_TEXT(4,trace
, "fixipm");
1124 INIT_LIST_HEAD(&failed_list
);
1125 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1127 list_for_each_entry_safe(ipm
, tmp
, &card
->ipm_list
, list
){
1128 switch (ipm
->ipm_state
) {
1129 case LCS_IPM_STATE_SET_REQUIRED
:
1130 /* del from ipm_list so noone else can tamper with
1132 list_del_init(&ipm
->list
);
1133 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1134 rc
= lcs_send_setipm(card
, ipm
);
1135 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1137 PRINT_INFO("Adding multicast address failed."
1138 "Table possibly full!\n");
1139 /* store ipm in failed list -> will be added
1140 * to ipm_list again, so a retry will be done
1141 * during the next call of this function */
1142 list_add_tail(&ipm
->list
, &failed_list
);
1144 ipm
->ipm_state
= LCS_IPM_STATE_ON_CARD
;
1145 /* re-insert into ipm_list */
1146 list_add_tail(&ipm
->list
, &card
->ipm_list
);
1149 case LCS_IPM_STATE_DEL_REQUIRED
:
1150 list_del(&ipm
->list
);
1151 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1152 lcs_send_delipm(card
, ipm
);
1153 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1156 case LCS_IPM_STATE_ON_CARD
:
1160 /* re-insert all entries from the failed_list into ipm_list */
1161 list_for_each_entry(ipm
, &failed_list
, list
) {
1162 list_del_init(&ipm
->list
);
1163 list_add_tail(&ipm
->list
, &card
->ipm_list
);
1165 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1166 if (card
->state
== DEV_STATE_UP
)
1167 netif_wake_queue(card
->dev
);
1171 * get mac address for the relevant Multicast address
1174 lcs_get_mac_for_ipm(__u32 ipm
, char *mac
, struct net_device
*dev
)
1176 LCS_DBF_TEXT(4,trace
, "getmac");
1177 if (dev
->type
== ARPHRD_IEEE802_TR
)
1178 ip_tr_mc_map(ipm
, mac
);
1180 ip_eth_mc_map(ipm
, mac
);
1184 * function called by net device to handle multicast address relevant things
1187 lcs_remove_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1189 struct ip_mc_list
*im4
;
1190 struct list_head
*l
;
1191 struct lcs_ipm_list
*ipm
;
1192 unsigned long flags
;
1193 char buf
[MAX_ADDR_LEN
];
1195 LCS_DBF_TEXT(4, trace
, "remmclst");
1196 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1197 list_for_each(l
, &card
->ipm_list
) {
1198 ipm
= list_entry(l
, struct lcs_ipm_list
, list
);
1199 for (im4
= in4_dev
->mc_list
; im4
!= NULL
; im4
= im4
->next
) {
1200 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1201 if ( (ipm
->ipm
.ip_addr
== im4
->multiaddr
) &&
1202 (memcmp(buf
, &ipm
->ipm
.mac_addr
,
1203 LCS_MAC_LENGTH
) == 0) )
1207 ipm
->ipm_state
= LCS_IPM_STATE_DEL_REQUIRED
;
1209 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1212 static inline struct lcs_ipm_list
*
1213 lcs_check_addr_entry(struct lcs_card
*card
, struct ip_mc_list
*im4
, char *buf
)
1215 struct lcs_ipm_list
*tmp
, *ipm
= NULL
;
1216 struct list_head
*l
;
1217 unsigned long flags
;
1219 LCS_DBF_TEXT(4, trace
, "chkmcent");
1220 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1221 list_for_each(l
, &card
->ipm_list
) {
1222 tmp
= list_entry(l
, struct lcs_ipm_list
, list
);
1223 if ( (tmp
->ipm
.ip_addr
== im4
->multiaddr
) &&
1224 (memcmp(buf
, &tmp
->ipm
.mac_addr
,
1225 LCS_MAC_LENGTH
) == 0) ) {
1230 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1235 lcs_set_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1238 struct ip_mc_list
*im4
;
1239 struct lcs_ipm_list
*ipm
;
1240 char buf
[MAX_ADDR_LEN
];
1241 unsigned long flags
;
1243 LCS_DBF_TEXT(4, trace
, "setmclst");
1244 for (im4
= in4_dev
->mc_list
; im4
; im4
= im4
->next
) {
1245 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1246 ipm
= lcs_check_addr_entry(card
, im4
, buf
);
1248 continue; /* Address already in list. */
1249 ipm
= (struct lcs_ipm_list
*)
1250 kmalloc(sizeof(struct lcs_ipm_list
), GFP_ATOMIC
);
1252 PRINT_INFO("Not enough memory to add "
1253 "new multicast entry!\n");
1256 memset(ipm
, 0, sizeof(struct lcs_ipm_list
));
1257 memcpy(&ipm
->ipm
.mac_addr
, buf
, LCS_MAC_LENGTH
);
1258 ipm
->ipm
.ip_addr
= im4
->multiaddr
;
1259 ipm
->ipm_state
= LCS_IPM_STATE_SET_REQUIRED
;
1260 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1261 list_add(&ipm
->list
, &card
->ipm_list
);
1262 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1267 lcs_register_mc_addresses(void *data
)
1269 struct lcs_card
*card
;
1270 struct in_device
*in4_dev
;
1272 card
= (struct lcs_card
*) data
;
1273 daemonize("regipm");
1275 if (!lcs_do_run_thread(card
, LCS_SET_MC_THREAD
))
1277 LCS_DBF_TEXT(4, trace
, "regmulti");
1279 in4_dev
= in_dev_get(card
->dev
);
1280 if (in4_dev
== NULL
)
1282 read_lock(&in4_dev
->mc_list_lock
);
1283 lcs_remove_mc_addresses(card
,in4_dev
);
1284 lcs_set_mc_addresses(card
, in4_dev
);
1285 read_unlock(&in4_dev
->mc_list_lock
);
1286 in_dev_put(in4_dev
);
1288 lcs_fix_multicast_list(card
);
1290 lcs_clear_thread_running_bit(card
, LCS_SET_MC_THREAD
);
1294 * function called by net device to
1295 * handle multicast address relevant things
1298 lcs_set_multicast_list(struct net_device
*dev
)
1300 struct lcs_card
*card
;
1302 LCS_DBF_TEXT(4, trace
, "setmulti");
1303 card
= (struct lcs_card
*) dev
->priv
;
1305 if (!lcs_set_thread_start_bit(card
, LCS_SET_MC_THREAD
)) {
1306 schedule_work(&card
->kernel_thread_starter
);
1310 #endif /* CONFIG_IP_MULTICAST */
1313 lcs_check_irb_error(struct ccw_device
*cdev
, struct irb
*irb
)
1318 switch (PTR_ERR(irb
)) {
1320 PRINT_WARN("i/o-error on device %s\n", cdev
->dev
.bus_id
);
1321 LCS_DBF_TEXT(2, trace
, "ckirberr");
1322 LCS_DBF_TEXT_(2, trace
, " rc%d", -EIO
);
1325 PRINT_WARN("timeout on device %s\n", cdev
->dev
.bus_id
);
1326 LCS_DBF_TEXT(2, trace
, "ckirberr");
1327 LCS_DBF_TEXT_(2, trace
, " rc%d", -ETIMEDOUT
);
1330 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb
),
1332 LCS_DBF_TEXT(2, trace
, "ckirberr");
1333 LCS_DBF_TEXT(2, trace
, " rc???");
1335 return PTR_ERR(irb
);
1340 * IRQ Handler for LCS channels
1343 lcs_irq(struct ccw_device
*cdev
, unsigned long intparm
, struct irb
*irb
)
1345 struct lcs_card
*card
;
1346 struct lcs_channel
*channel
;
1349 if (lcs_check_irb_error(cdev
, irb
))
1352 card
= CARD_FROM_DEV(cdev
);
1353 if (card
->read
.ccwdev
== cdev
)
1354 channel
= &card
->read
;
1356 channel
= &card
->write
;
1358 LCS_DBF_TEXT_(5, trace
, "Rint%s",cdev
->dev
.bus_id
);
1359 LCS_DBF_TEXT_(5, trace
, "%4x%4x",irb
->scsw
.cstat
, irb
->scsw
.dstat
);
1361 /* How far in the ccw chain have we processed? */
1362 if ((channel
->state
!= CH_STATE_INIT
) &&
1363 (irb
->scsw
.fctl
& SCSW_FCTL_START_FUNC
)) {
1364 index
= (struct ccw1
*) __va((addr_t
) irb
->scsw
.cpa
)
1366 if ((irb
->scsw
.actl
& SCSW_ACTL_SUSPENDED
) ||
1367 (irb
->scsw
.cstat
| SCHN_STAT_PCI
))
1368 /* Bloody io subsystem tells us lies about cpa... */
1369 index
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
1370 while (channel
->io_idx
!= index
) {
1371 __lcs_processed_buffer(channel
,
1372 channel
->iob
+ channel
->io_idx
);
1374 (channel
->io_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1378 if ((irb
->scsw
.dstat
& DEV_STAT_DEV_END
) ||
1379 (irb
->scsw
.dstat
& DEV_STAT_CHN_END
) ||
1380 (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
))
1381 /* Mark channel as stopped. */
1382 channel
->state
= CH_STATE_STOPPED
;
1383 else if (irb
->scsw
.actl
& SCSW_ACTL_SUSPENDED
)
1384 /* CCW execution stopped on a suspend bit. */
1385 channel
->state
= CH_STATE_SUSPENDED
;
1387 if (irb
->scsw
.fctl
& SCSW_FCTL_HALT_FUNC
) {
1388 if (irb
->scsw
.cc
!= 0) {
1389 ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
1392 /* The channel has been stopped by halt_IO. */
1393 channel
->state
= CH_STATE_HALTED
;
1396 if (irb
->scsw
.fctl
& SCSW_FCTL_CLEAR_FUNC
) {
1397 channel
->state
= CH_STATE_CLEARED
;
1399 /* Do the rest in the tasklet. */
1400 tasklet_schedule(&channel
->irq_tasklet
);
1404 * Tasklet for IRQ handler
1407 lcs_tasklet(unsigned long data
)
1409 unsigned long flags
;
1410 struct lcs_channel
*channel
;
1411 struct lcs_buffer
*iob
;
1415 channel
= (struct lcs_channel
*) data
;
1416 LCS_DBF_TEXT_(5, trace
, "tlet%s",channel
->ccwdev
->dev
.bus_id
);
1418 /* Check for processed buffers. */
1420 buf_idx
= channel
->buf_idx
;
1421 while (iob
[buf_idx
].state
== BUF_STATE_PROCESSED
) {
1422 /* Do the callback thing. */
1423 if (iob
[buf_idx
].callback
!= NULL
)
1424 iob
[buf_idx
].callback(channel
, iob
+ buf_idx
);
1425 buf_idx
= (buf_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1427 channel
->buf_idx
= buf_idx
;
1429 if (channel
->state
== CH_STATE_STOPPED
)
1430 // FIXME: what if rc != 0 ??
1431 rc
= lcs_start_channel(channel
);
1432 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1433 if (channel
->state
== CH_STATE_SUSPENDED
&&
1434 channel
->iob
[channel
->io_idx
].state
== BUF_STATE_READY
) {
1435 // FIXME: what if rc != 0 ??
1436 rc
= __lcs_resume_channel(channel
);
1438 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1440 /* Something happened on the channel. Wake up waiters. */
1441 wake_up(&channel
->wait_q
);
1445 * Finish current tx buffer and make it ready for transmit.
1448 __lcs_emit_txbuffer(struct lcs_card
*card
)
1450 LCS_DBF_TEXT(5, trace
, "emittx");
1451 *(__u16
*)(card
->tx_buffer
->data
+ card
->tx_buffer
->count
) = 0;
1452 card
->tx_buffer
->count
+= 2;
1453 lcs_ready_buffer(&card
->write
, card
->tx_buffer
);
1454 card
->tx_buffer
= NULL
;
1459 * Callback for finished tx buffers.
1462 lcs_txbuffer_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1464 struct lcs_card
*card
;
1466 LCS_DBF_TEXT(5, trace
, "txbuffcb");
1467 /* Put buffer back to pool. */
1468 lcs_release_buffer(channel
, buffer
);
1469 card
= (struct lcs_card
*)
1470 ((char *) channel
- offsetof(struct lcs_card
, write
));
1471 spin_lock(&card
->lock
);
1473 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1475 * Last running tx buffer has finished. Submit partially
1476 * filled current buffer.
1478 __lcs_emit_txbuffer(card
);
1479 spin_unlock(&card
->lock
);
1483 * Packet transmit function called by network stack
1486 __lcs_start_xmit(struct lcs_card
*card
, struct sk_buff
*skb
,
1487 struct net_device
*dev
)
1489 struct lcs_header
*header
;
1491 LCS_DBF_TEXT(5, trace
, "hardxmit");
1493 card
->stats
.tx_dropped
++;
1494 card
->stats
.tx_errors
++;
1497 if (card
->state
!= DEV_STATE_UP
) {
1499 card
->stats
.tx_dropped
++;
1500 card
->stats
.tx_errors
++;
1501 card
->stats
.tx_carrier_errors
++;
1504 if (netif_queue_stopped(dev
) ) {
1505 card
->stats
.tx_dropped
++;
1508 if (card
->tx_buffer
!= NULL
&&
1509 card
->tx_buffer
->count
+ sizeof(struct lcs_header
) +
1510 skb
->len
+ sizeof(u16
) > LCS_IOBUFFERSIZE
)
1511 /* skb too big for current tx buffer. */
1512 __lcs_emit_txbuffer(card
);
1513 if (card
->tx_buffer
== NULL
) {
1514 /* Get new tx buffer */
1515 card
->tx_buffer
= lcs_get_buffer(&card
->write
);
1516 if (card
->tx_buffer
== NULL
) {
1517 card
->stats
.tx_dropped
++;
1520 card
->tx_buffer
->callback
= lcs_txbuffer_cb
;
1521 card
->tx_buffer
->count
= 0;
1523 header
= (struct lcs_header
*)
1524 (card
->tx_buffer
->data
+ card
->tx_buffer
->count
);
1525 card
->tx_buffer
->count
+= skb
->len
+ sizeof(struct lcs_header
);
1526 header
->offset
= card
->tx_buffer
->count
;
1527 header
->type
= card
->lan_type
;
1528 header
->slot
= card
->portno
;
1529 memcpy(header
+ 1, skb
->data
, skb
->len
);
1530 card
->stats
.tx_bytes
+= skb
->len
;
1531 card
->stats
.tx_packets
++;
1533 if (card
->tx_emitted
<= 0)
1534 /* If this is the first tx buffer emit it immediately. */
1535 __lcs_emit_txbuffer(card
);
1540 lcs_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1542 struct lcs_card
*card
;
1545 LCS_DBF_TEXT(5, trace
, "pktxmit");
1546 card
= (struct lcs_card
*) dev
->priv
;
1547 spin_lock(&card
->lock
);
1548 rc
= __lcs_start_xmit(card
, skb
, dev
);
1549 spin_unlock(&card
->lock
);
1554 * send startlan and lanstat command to make LCS device ready
1557 lcs_startlan_auto(struct lcs_card
*card
)
1561 LCS_DBF_TEXT(2, trace
, "strtauto");
1562 #ifdef CONFIG_NET_ETHERNET
1563 card
->lan_type
= LCS_FRAME_TYPE_ENET
;
1564 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1570 card
->lan_type
= LCS_FRAME_TYPE_TR
;
1571 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1576 card
->lan_type
= LCS_FRAME_TYPE_FDDI
;
1577 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1585 lcs_startlan(struct lcs_card
*card
)
1589 LCS_DBF_TEXT(2, trace
, "startlan");
1591 if (card
->portno
!= LCS_INVALID_PORT_NO
) {
1592 if (card
->lan_type
== LCS_FRAME_TYPE_AUTO
)
1593 rc
= lcs_startlan_auto(card
);
1595 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1597 for (i
= 0; i
<= 16; i
++) {
1599 if (card
->lan_type
!= LCS_FRAME_TYPE_AUTO
)
1600 rc
= lcs_send_startlan(card
,
1601 LCS_INITIATOR_TCPIP
);
1603 /* autodetecting lan type */
1604 rc
= lcs_startlan_auto(card
);
1610 return lcs_send_lanstat(card
);
1615 * LCS detect function
1616 * setup channels and make them I/O ready
1619 lcs_detect(struct lcs_card
*card
)
1623 LCS_DBF_TEXT(2, setup
, "lcsdetct");
1624 /* start/reset card */
1626 netif_stop_queue(card
->dev
);
1627 card
->write
.state
= CH_STATE_INIT
;
1628 card
->read
.state
= CH_STATE_INIT
;
1629 rc
= lcs_stop_channels(card
);
1631 rc
= lcs_start_channels(card
);
1633 rc
= lcs_send_startup(card
, LCS_INITIATOR_TCPIP
);
1635 rc
= lcs_startlan(card
);
1639 card
->state
= DEV_STATE_UP
;
1641 card
->state
= DEV_STATE_DOWN
;
1642 card
->write
.state
= CH_STATE_INIT
;
1643 card
->read
.state
= CH_STATE_INIT
;
1652 lcs_resetcard(struct lcs_card
*card
)
1656 LCS_DBF_TEXT(2, trace
, "rescard");
1657 for (retries
= 0; retries
< 10; retries
++) {
1658 if (lcs_detect(card
) == 0) {
1659 netif_wake_queue(card
->dev
);
1660 card
->state
= DEV_STATE_UP
;
1661 PRINT_INFO("LCS device %s successfully restarted!\n",
1667 PRINT_ERR("Error in Reseting LCS card!\n");
1676 lcs_stopcard(struct lcs_card
*card
)
1680 LCS_DBF_TEXT(3, setup
, "stopcard");
1682 if (card
->read
.state
!= CH_STATE_STOPPED
&&
1683 card
->write
.state
!= CH_STATE_STOPPED
&&
1684 card
->state
== DEV_STATE_UP
) {
1685 lcs_clear_multicast_list(card
);
1686 rc
= lcs_send_stoplan(card
,LCS_INITIATOR_TCPIP
);
1687 rc
= lcs_send_shutdown(card
);
1689 rc
= lcs_stop_channels(card
);
1690 card
->state
= DEV_STATE_DOWN
;
1696 * LGW initiated commands
1699 lcs_lgw_startlan_thread(void *data
)
1701 struct lcs_card
*card
;
1703 card
= (struct lcs_card
*) data
;
1704 daemonize("lgwstpln");
1706 if (!lcs_do_run_thread(card
, LCS_STARTLAN_THREAD
))
1708 LCS_DBF_TEXT(4, trace
, "lgwstpln");
1710 netif_stop_queue(card
->dev
);
1711 if (lcs_startlan(card
) == 0) {
1712 netif_wake_queue(card
->dev
);
1713 card
->state
= DEV_STATE_UP
;
1714 PRINT_INFO("LCS Startlan for device %s succeeded!\n",
1718 PRINT_ERR("LCS Startlan for device %s failed!\n",
1720 lcs_clear_thread_running_bit(card
, LCS_STARTLAN_THREAD
);
1725 * Send startup command initiated by Lan Gateway
1728 lcs_lgw_startup_thread(void *data
)
1732 struct lcs_card
*card
;
1734 card
= (struct lcs_card
*) data
;
1735 daemonize("lgwstaln");
1737 if (!lcs_do_run_thread(card
, LCS_STARTUP_THREAD
))
1739 LCS_DBF_TEXT(4, trace
, "lgwstaln");
1741 netif_stop_queue(card
->dev
);
1742 rc
= lcs_send_startup(card
, LCS_INITIATOR_LGW
);
1744 PRINT_ERR("Startup for LCS device %s initiated " \
1745 "by LGW failed!\nReseting card ...\n",
1747 /* do a card reset */
1748 rc
= lcs_resetcard(card
);
1752 rc
= lcs_startlan(card
);
1754 netif_wake_queue(card
->dev
);
1755 card
->state
= DEV_STATE_UP
;
1759 PRINT_INFO("LCS Startup for device %s succeeded!\n",
1762 PRINT_ERR("LCS Startup for device %s failed!\n",
1764 lcs_clear_thread_running_bit(card
, LCS_STARTUP_THREAD
);
1770 * send stoplan command initiated by Lan Gateway
1773 lcs_lgw_stoplan_thread(void *data
)
1775 struct lcs_card
*card
;
1778 card
= (struct lcs_card
*) data
;
1779 daemonize("lgwstop");
1781 if (!lcs_do_run_thread(card
, LCS_STOPLAN_THREAD
))
1783 LCS_DBF_TEXT(4, trace
, "lgwstop");
1785 netif_stop_queue(card
->dev
);
1786 if (lcs_send_stoplan(card
, LCS_INITIATOR_LGW
) == 0)
1787 PRINT_INFO("Stoplan for %s initiated by LGW succeeded!\n",
1790 PRINT_ERR("Stoplan %s initiated by LGW failed!\n",
1792 /*Try to reset the card, stop it on failure */
1793 rc
= lcs_resetcard(card
);
1795 rc
= lcs_stopcard(card
);
1796 lcs_clear_thread_running_bit(card
, LCS_STOPLAN_THREAD
);
1801 * Kernel Thread helper functions for LGW initiated commands
1804 lcs_start_kernel_thread(struct lcs_card
*card
)
1806 LCS_DBF_TEXT(5, trace
, "krnthrd");
1807 if (lcs_do_start_thread(card
, LCS_STARTUP_THREAD
))
1808 kernel_thread(lcs_lgw_startup_thread
, (void *) card
, SIGCHLD
);
1809 if (lcs_do_start_thread(card
, LCS_STARTLAN_THREAD
))
1810 kernel_thread(lcs_lgw_startlan_thread
, (void *) card
, SIGCHLD
);
1811 if (lcs_do_start_thread(card
, LCS_STOPLAN_THREAD
))
1812 kernel_thread(lcs_lgw_stoplan_thread
, (void *) card
, SIGCHLD
);
1813 #ifdef CONFIG_IP_MULTICAST
1814 if (lcs_do_start_thread(card
, LCS_SET_MC_THREAD
))
1815 kernel_thread(lcs_register_mc_addresses
, (void *) card
, SIGCHLD
);
1820 * Process control frames.
1823 lcs_get_control(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1825 LCS_DBF_TEXT(5, trace
, "getctrl");
1826 if (cmd
->initiator
== LCS_INITIATOR_LGW
) {
1827 switch(cmd
->cmd_code
) {
1828 case LCS_CMD_STARTUP
:
1829 if (!lcs_set_thread_start_bit(card
,
1830 LCS_STARTUP_THREAD
))
1831 schedule_work(&card
->kernel_thread_starter
);
1833 case LCS_CMD_STARTLAN
:
1834 if (!lcs_set_thread_start_bit(card
,
1835 LCS_STARTLAN_THREAD
))
1836 schedule_work(&card
->kernel_thread_starter
);
1838 case LCS_CMD_STOPLAN
:
1839 if (!lcs_set_thread_start_bit(card
,
1840 LCS_STOPLAN_THREAD
))
1841 schedule_work(&card
->kernel_thread_starter
);
1844 PRINT_INFO("UNRECOGNIZED LGW COMMAND\n");
1848 lcs_notify_lancmd_waiters(card
, cmd
);
1852 * Unpack network packet.
1855 lcs_get_skb(struct lcs_card
*card
, char *skb_data
, unsigned int skb_len
)
1857 struct sk_buff
*skb
;
1859 LCS_DBF_TEXT(5, trace
, "getskb");
1860 if (card
->dev
== NULL
||
1861 card
->state
!= DEV_STATE_UP
)
1862 /* The card isn't up. Ignore the packet. */
1865 skb
= dev_alloc_skb(skb_len
);
1867 PRINT_ERR("LCS: alloc_skb failed for device=%s\n",
1869 card
->stats
.rx_dropped
++;
1872 skb
->dev
= card
->dev
;
1873 memcpy(skb_put(skb
, skb_len
), skb_data
, skb_len
);
1874 skb
->protocol
= card
->lan_type_trans(skb
, card
->dev
);
1875 card
->stats
.rx_bytes
+= skb_len
;
1876 card
->stats
.rx_packets
++;
1881 * LCS main routine to get packets and lancmd replies from the buffers
1884 lcs_get_frames_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1886 struct lcs_card
*card
;
1887 struct lcs_header
*lcs_hdr
;
1890 LCS_DBF_TEXT(5, trace
, "lcsgtpkt");
1891 lcs_hdr
= (struct lcs_header
*) buffer
->data
;
1892 if (lcs_hdr
->offset
== LCS_ILLEGAL_OFFSET
) {
1893 LCS_DBF_TEXT(4, trace
, "-eiogpkt");
1896 card
= (struct lcs_card
*)
1897 ((char *) channel
- offsetof(struct lcs_card
, read
));
1899 while (lcs_hdr
->offset
!= 0) {
1900 if (lcs_hdr
->offset
<= 0 ||
1901 lcs_hdr
->offset
> LCS_IOBUFFERSIZE
||
1902 lcs_hdr
->offset
< offset
) {
1903 /* Offset invalid. */
1904 card
->stats
.rx_length_errors
++;
1905 card
->stats
.rx_errors
++;
1908 /* What kind of frame is it? */
1909 if (lcs_hdr
->type
== LCS_FRAME_TYPE_CONTROL
)
1910 /* Control frame. */
1911 lcs_get_control(card
, (struct lcs_cmd
*) lcs_hdr
);
1912 else if (lcs_hdr
->type
== LCS_FRAME_TYPE_ENET
||
1913 lcs_hdr
->type
== LCS_FRAME_TYPE_TR
||
1914 lcs_hdr
->type
== LCS_FRAME_TYPE_FDDI
)
1915 /* Normal network packet. */
1916 lcs_get_skb(card
, (char *)(lcs_hdr
+ 1),
1917 lcs_hdr
->offset
- offset
-
1918 sizeof(struct lcs_header
));
1920 /* Unknown frame type. */
1921 ; // FIXME: error message ?
1922 /* Proceed to next frame. */
1923 offset
= lcs_hdr
->offset
;
1924 lcs_hdr
->offset
= LCS_ILLEGAL_OFFSET
;
1925 lcs_hdr
= (struct lcs_header
*) (buffer
->data
+ offset
);
1927 /* The buffer is now empty. Make it ready again. */
1928 lcs_ready_buffer(&card
->read
, buffer
);
1932 * get network statistics for ifconfig and other user programs
1934 static struct net_device_stats
*
1935 lcs_getstats(struct net_device
*dev
)
1937 struct lcs_card
*card
;
1939 LCS_DBF_TEXT(4, trace
, "netstats");
1940 card
= (struct lcs_card
*) dev
->priv
;
1941 return &card
->stats
;
1946 * This function will be called by user doing ifconfig xxx down
1949 lcs_stop_device(struct net_device
*dev
)
1951 struct lcs_card
*card
;
1954 LCS_DBF_TEXT(2, trace
, "stopdev");
1955 card
= (struct lcs_card
*) dev
->priv
;
1956 netif_stop_queue(dev
);
1957 dev
->flags
&= ~IFF_UP
;
1958 rc
= lcs_stopcard(card
);
1960 PRINT_ERR("Try it again!\n ");
1965 * start lcs device and make it runnable
1966 * This function will be called by user doing ifconfig xxx up
1969 lcs_open_device(struct net_device
*dev
)
1971 struct lcs_card
*card
;
1974 LCS_DBF_TEXT(2, trace
, "opendev");
1975 card
= (struct lcs_card
*) dev
->priv
;
1976 /* initialize statistics */
1977 rc
= lcs_detect(card
);
1979 PRINT_ERR("LCS:Error in opening device!\n");
1982 dev
->flags
|= IFF_UP
;
1983 netif_wake_queue(dev
);
1984 card
->state
= DEV_STATE_UP
;
1990 * show function for portno called by cat or similar things
1993 lcs_portno_show (struct device
*dev
, char *buf
)
1995 struct lcs_card
*card
;
1997 card
= (struct lcs_card
*)dev
->driver_data
;
2002 return sprintf(buf
, "%d\n", card
->portno
);
2006 * store the value which is piped to file portno
2009 lcs_portno_store (struct device
*dev
, const char *buf
, size_t count
)
2011 struct lcs_card
*card
;
2014 card
= (struct lcs_card
*)dev
->driver_data
;
2019 sscanf(buf
, "%u", &value
);
2020 /* TODO: sanity checks */
2021 card
->portno
= value
;
2027 static DEVICE_ATTR(portno
, 0644, lcs_portno_show
, lcs_portno_store
);
2030 lcs_type_show(struct device
*dev
, char *buf
)
2032 struct ccwgroup_device
*cgdev
;
2034 cgdev
= to_ccwgroupdev(dev
);
2038 return sprintf(buf
, "%s\n", cu3088_type
[cgdev
->cdev
[0]->id
.driver_info
]);
2041 static DEVICE_ATTR(type
, 0444, lcs_type_show
, NULL
);
2044 lcs_timeout_show(struct device
*dev
, char *buf
)
2046 struct lcs_card
*card
;
2048 card
= (struct lcs_card
*)dev
->driver_data
;
2050 return card
? sprintf(buf
, "%u\n", card
->lancmd_timeout
) : 0;
2054 lcs_timeout_store (struct device
*dev
, const char *buf
, size_t count
)
2056 struct lcs_card
*card
;
2059 card
= (struct lcs_card
*)dev
->driver_data
;
2064 sscanf(buf
, "%u", &value
);
2065 /* TODO: sanity checks */
2066 card
->lancmd_timeout
= value
;
2072 DEVICE_ATTR(lancmd_timeout
, 0644, lcs_timeout_show
, lcs_timeout_store
);
2074 static struct attribute
* lcs_attrs
[] = {
2075 &dev_attr_portno
.attr
,
2076 &dev_attr_type
.attr
,
2077 &dev_attr_lancmd_timeout
.attr
,
2081 static struct attribute_group lcs_attr_group
= {
2086 * lcs_probe_device is called on establishing a new ccwgroup_device.
2089 lcs_probe_device(struct ccwgroup_device
*ccwgdev
)
2091 struct lcs_card
*card
;
2094 if (!get_device(&ccwgdev
->dev
))
2097 LCS_DBF_TEXT(2, setup
, "add_dev");
2098 card
= lcs_alloc_card();
2100 PRINT_ERR("Allocation of lcs card failed\n");
2101 put_device(&ccwgdev
->dev
);
2104 ret
= sysfs_create_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2106 PRINT_ERR("Creating attributes failed");
2107 lcs_free_card(card
);
2108 put_device(&ccwgdev
->dev
);
2111 ccwgdev
->dev
.driver_data
= card
;
2112 ccwgdev
->cdev
[0]->handler
= lcs_irq
;
2113 ccwgdev
->cdev
[1]->handler
= lcs_irq
;
2118 lcs_register_netdev(struct ccwgroup_device
*ccwgdev
)
2120 struct lcs_card
*card
;
2122 LCS_DBF_TEXT(2, setup
, "regnetdv");
2123 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2124 if (card
->dev
->reg_state
!= NETREG_UNINITIALIZED
)
2126 SET_NETDEV_DEV(card
->dev
, &ccwgdev
->dev
);
2127 return register_netdev(card
->dev
);
2131 * lcs_new_device will be called by setting the group device online.
2135 lcs_new_device(struct ccwgroup_device
*ccwgdev
)
2137 struct lcs_card
*card
;
2138 struct net_device
*dev
=NULL
;
2139 enum lcs_dev_states recover_state
;
2142 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2146 LCS_DBF_TEXT(2, setup
, "newdev");
2147 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2148 card
->read
.ccwdev
= ccwgdev
->cdev
[0];
2149 card
->write
.ccwdev
= ccwgdev
->cdev
[1];
2151 recover_state
= card
->state
;
2152 ccw_device_set_online(card
->read
.ccwdev
);
2153 ccw_device_set_online(card
->write
.ccwdev
);
2155 LCS_DBF_TEXT(3, setup
, "lcsnewdv");
2157 lcs_setup_card(card
);
2158 rc
= lcs_detect(card
);
2160 LCS_DBF_TEXT(2, setup
, "dtctfail");
2161 PRINT_WARN("Detection of LCS card failed with return code "
2162 "%d (0x%x)\n", rc
, rc
);
2167 LCS_DBF_TEXT(2, setup
, "samedev");
2168 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2171 switch (card
->lan_type
) {
2172 #ifdef CONFIG_NET_ETHERNET
2173 case LCS_FRAME_TYPE_ENET
:
2174 card
->lan_type_trans
= eth_type_trans
;
2175 dev
= alloc_etherdev(0);
2179 case LCS_FRAME_TYPE_TR
:
2180 card
->lan_type_trans
= tr_type_trans
;
2181 dev
= alloc_trdev(0);
2185 case LCS_FRAME_TYPE_FDDI
:
2186 card
->lan_type_trans
= fddi_type_trans
;
2187 dev
= alloc_fddidev(0);
2191 LCS_DBF_TEXT(3, setup
, "errinit");
2192 PRINT_ERR("LCS: Initialization failed\n");
2193 PRINT_ERR("LCS: No device found!\n");
2200 card
->dev
->priv
= card
;
2201 card
->dev
->open
= lcs_open_device
;
2202 card
->dev
->stop
= lcs_stop_device
;
2203 card
->dev
->hard_start_xmit
= lcs_start_xmit
;
2204 card
->dev
->get_stats
= lcs_getstats
;
2205 SET_MODULE_OWNER(dev
);
2206 if (lcs_register_netdev(ccwgdev
) != 0)
2208 memcpy(card
->dev
->dev_addr
, card
->mac
, LCS_MAC_LENGTH
);
2209 #ifdef CONFIG_IP_MULTICAST
2210 if (!lcs_check_multicast_support(card
))
2211 card
->dev
->set_multicast_list
= lcs_set_multicast_list
;
2213 netif_stop_queue(card
->dev
);
2214 lcs_set_allowed_threads(card
,0xffffffff);
2215 if (recover_state
== DEV_STATE_RECOVER
) {
2216 lcs_set_multicast_list(card
->dev
);
2217 card
->dev
->flags
|= IFF_UP
;
2218 netif_wake_queue(card
->dev
);
2219 card
->state
= DEV_STATE_UP
;
2226 ccw_device_set_offline(card
->read
.ccwdev
);
2227 ccw_device_set_offline(card
->write
.ccwdev
);
2232 * lcs_shutdown_device, called when setting the group device offline.
2235 lcs_shutdown_device(struct ccwgroup_device
*ccwgdev
)
2237 struct lcs_card
*card
;
2238 enum lcs_dev_states recover_state
;
2241 LCS_DBF_TEXT(3, setup
, "shtdndev");
2242 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2245 lcs_set_allowed_threads(card
, 0);
2246 if (lcs_wait_for_threads(card
, LCS_SET_MC_THREAD
))
2247 return -ERESTARTSYS
;
2248 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2249 recover_state
= card
->state
;
2251 ret
= lcs_stop_device(card
->dev
);
2252 ret
= ccw_device_set_offline(card
->read
.ccwdev
);
2253 ret
= ccw_device_set_offline(card
->write
.ccwdev
);
2254 if (recover_state
== DEV_STATE_UP
) {
2255 card
->state
= DEV_STATE_RECOVER
;
2263 * lcs_remove_device, free buffers and card
2266 lcs_remove_device(struct ccwgroup_device
*ccwgdev
)
2268 struct lcs_card
*card
;
2270 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2274 PRINT_INFO("Removing lcs group device ....\n");
2275 LCS_DBF_TEXT(3, setup
, "remdev");
2276 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2277 if (ccwgdev
->state
== CCWGROUP_ONLINE
) {
2278 lcs_shutdown_device(ccwgdev
);
2281 unregister_netdev(card
->dev
);
2282 sysfs_remove_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2283 lcs_cleanup_card(card
);
2284 lcs_free_card(card
);
2285 put_device(&ccwgdev
->dev
);
2289 * LCS ccwgroup driver registration
2291 static struct ccwgroup_driver lcs_group_driver
= {
2292 .owner
= THIS_MODULE
,
2295 .driver_id
= 0xD3C3E2,
2296 .probe
= lcs_probe_device
,
2297 .remove
= lcs_remove_device
,
2298 .set_online
= lcs_new_device
,
2299 .set_offline
= lcs_shutdown_device
,
2303 * LCS Module/Kernel initialization function
2306 __init
lcs_init_module(void)
2310 PRINT_INFO("Loading %s\n",version
);
2311 rc
= lcs_register_debug_facility();
2312 LCS_DBF_TEXT(0, setup
, "lcsinit");
2314 PRINT_ERR("Initialization failed\n");
2318 rc
= register_cu3088_discipline(&lcs_group_driver
);
2320 PRINT_ERR("Initialization failed\n");
2329 * LCS module cleanup function
2332 __exit
lcs_cleanup_module(void)
2334 PRINT_INFO("Terminating lcs module.\n");
2335 LCS_DBF_TEXT(0, trace
, "cleanup");
2336 unregister_cu3088_discipline(&lcs_group_driver
);
2337 lcs_unregister_debug_facility();
2340 module_init(lcs_init_module
);
2341 module_exit(lcs_cleanup_module
);
2343 MODULE_AUTHOR("Frank Pavlic <pavlic@de.ibm.com>");
2344 MODULE_LICENSE("GPL");