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
*);
73 * Debug Facility Stuff
75 static debug_info_t
*lcs_dbf_setup
;
76 static debug_info_t
*lcs_dbf_trace
;
79 * LCS Debug Facility functions
82 lcs_unregister_debug_facility(void)
85 debug_unregister(lcs_dbf_setup
);
87 debug_unregister(lcs_dbf_trace
);
91 lcs_register_debug_facility(void)
93 lcs_dbf_setup
= debug_register("lcs_setup", 2, 1, 8);
94 lcs_dbf_trace
= debug_register("lcs_trace", 2, 2, 8);
95 if (lcs_dbf_setup
== NULL
|| lcs_dbf_trace
== NULL
) {
96 PRINT_ERR("Not enough memory for debug facility.\n");
97 lcs_unregister_debug_facility();
100 debug_register_view(lcs_dbf_setup
, &debug_hex_ascii_view
);
101 debug_set_level(lcs_dbf_setup
, 2);
102 debug_register_view(lcs_dbf_trace
, &debug_hex_ascii_view
);
103 debug_set_level(lcs_dbf_trace
, 2);
108 * Allocate io buffers.
111 lcs_alloc_channel(struct lcs_channel
*channel
)
115 LCS_DBF_TEXT(2, setup
, "ichalloc");
116 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
117 /* alloc memory fo iobuffer */
118 channel
->iob
[cnt
].data
=
119 kzalloc(LCS_IOBUFFERSIZE
, GFP_DMA
| GFP_KERNEL
);
120 if (channel
->iob
[cnt
].data
== NULL
)
122 channel
->iob
[cnt
].state
= BUF_STATE_EMPTY
;
124 if (cnt
< LCS_NUM_BUFFS
) {
125 /* Not all io buffers could be allocated. */
126 LCS_DBF_TEXT(2, setup
, "echalloc");
128 kfree(channel
->iob
[cnt
].data
);
138 lcs_free_channel(struct lcs_channel
*channel
)
142 LCS_DBF_TEXT(2, setup
, "ichfree");
143 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
144 kfree(channel
->iob
[cnt
].data
);
145 channel
->iob
[cnt
].data
= NULL
;
153 lcs_cleanup_channel(struct lcs_channel
*channel
)
155 LCS_DBF_TEXT(3, setup
, "cleanch");
156 /* Kill write channel tasklets. */
157 tasklet_kill(&channel
->irq_tasklet
);
158 /* Free channel buffers. */
159 lcs_free_channel(channel
);
163 * LCS free memory for card and channels.
166 lcs_free_card(struct lcs_card
*card
)
168 LCS_DBF_TEXT(2, setup
, "remcard");
169 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
174 * LCS alloc memory for card and channels
176 static struct lcs_card
*
179 struct lcs_card
*card
;
182 LCS_DBF_TEXT(2, setup
, "alloclcs");
184 card
= kzalloc(sizeof(struct lcs_card
), GFP_KERNEL
| GFP_DMA
);
187 card
->lan_type
= LCS_FRAME_TYPE_AUTO
;
189 card
->lancmd_timeout
= LCS_LANCMD_TIMEOUT_DEFAULT
;
190 /* Allocate io buffers for the read channel. */
191 rc
= lcs_alloc_channel(&card
->read
);
193 LCS_DBF_TEXT(2, setup
, "iccwerr");
197 /* Allocate io buffers for the write channel. */
198 rc
= lcs_alloc_channel(&card
->write
);
200 LCS_DBF_TEXT(2, setup
, "iccwerr");
201 lcs_cleanup_channel(&card
->read
);
206 #ifdef CONFIG_IP_MULTICAST
207 INIT_LIST_HEAD(&card
->ipm_list
);
209 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
214 * Setup read channel.
217 lcs_setup_read_ccws(struct lcs_card
*card
)
221 LCS_DBF_TEXT(2, setup
, "ireadccw");
222 /* Setup read ccws. */
223 memset(card
->read
.ccws
, 0, sizeof (struct ccw1
) * (LCS_NUM_BUFFS
+ 1));
224 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
225 card
->read
.ccws
[cnt
].cmd_code
= LCS_CCW_READ
;
226 card
->read
.ccws
[cnt
].count
= LCS_IOBUFFERSIZE
;
227 card
->read
.ccws
[cnt
].flags
=
228 CCW_FLAG_CC
| CCW_FLAG_SLI
| CCW_FLAG_PCI
;
230 * Note: we have allocated the buffer with GFP_DMA, so
231 * we do not need to do set_normalized_cda.
233 card
->read
.ccws
[cnt
].cda
=
234 (__u32
) __pa(card
->read
.iob
[cnt
].data
);
235 ((struct lcs_header
*)
236 card
->read
.iob
[cnt
].data
)->offset
= LCS_ILLEGAL_OFFSET
;
237 card
->read
.iob
[cnt
].callback
= lcs_get_frames_cb
;
238 card
->read
.iob
[cnt
].state
= BUF_STATE_READY
;
239 card
->read
.iob
[cnt
].count
= LCS_IOBUFFERSIZE
;
241 card
->read
.ccws
[0].flags
&= ~CCW_FLAG_PCI
;
242 card
->read
.ccws
[LCS_NUM_BUFFS
- 1].flags
&= ~CCW_FLAG_PCI
;
243 card
->read
.ccws
[LCS_NUM_BUFFS
- 1].flags
|= CCW_FLAG_SUSPEND
;
244 /* Last ccw is a tic (transfer in channel). */
245 card
->read
.ccws
[LCS_NUM_BUFFS
].cmd_code
= LCS_CCW_TRANSFER
;
246 card
->read
.ccws
[LCS_NUM_BUFFS
].cda
=
247 (__u32
) __pa(card
->read
.ccws
);
248 /* Setg initial state of the read channel. */
249 card
->read
.state
= CH_STATE_INIT
;
251 card
->read
.io_idx
= 0;
252 card
->read
.buf_idx
= 0;
256 lcs_setup_read(struct lcs_card
*card
)
258 LCS_DBF_TEXT(3, setup
, "initread");
260 lcs_setup_read_ccws(card
);
261 /* Initialize read channel tasklet. */
262 card
->read
.irq_tasklet
.data
= (unsigned long) &card
->read
;
263 card
->read
.irq_tasklet
.func
= lcs_tasklet
;
264 /* Initialize waitqueue. */
265 init_waitqueue_head(&card
->read
.wait_q
);
269 * Setup write channel.
272 lcs_setup_write_ccws(struct lcs_card
*card
)
276 LCS_DBF_TEXT(3, setup
, "iwritccw");
277 /* Setup write ccws. */
278 memset(card
->write
.ccws
, 0, sizeof(struct ccw1
) * LCS_NUM_BUFFS
+ 1);
279 for (cnt
= 0; cnt
< LCS_NUM_BUFFS
; cnt
++) {
280 card
->write
.ccws
[cnt
].cmd_code
= LCS_CCW_WRITE
;
281 card
->write
.ccws
[cnt
].count
= 0;
282 card
->write
.ccws
[cnt
].flags
=
283 CCW_FLAG_SUSPEND
| CCW_FLAG_CC
| CCW_FLAG_SLI
;
285 * Note: we have allocated the buffer with GFP_DMA, so
286 * we do not need to do set_normalized_cda.
288 card
->write
.ccws
[cnt
].cda
=
289 (__u32
) __pa(card
->write
.iob
[cnt
].data
);
291 /* Last ccw is a tic (transfer in channel). */
292 card
->write
.ccws
[LCS_NUM_BUFFS
].cmd_code
= LCS_CCW_TRANSFER
;
293 card
->write
.ccws
[LCS_NUM_BUFFS
].cda
=
294 (__u32
) __pa(card
->write
.ccws
);
295 /* Set initial state of the write channel. */
296 card
->read
.state
= CH_STATE_INIT
;
298 card
->write
.io_idx
= 0;
299 card
->write
.buf_idx
= 0;
303 lcs_setup_write(struct lcs_card
*card
)
305 LCS_DBF_TEXT(3, setup
, "initwrit");
307 lcs_setup_write_ccws(card
);
308 /* Initialize write channel tasklet. */
309 card
->write
.irq_tasklet
.data
= (unsigned long) &card
->write
;
310 card
->write
.irq_tasklet
.func
= lcs_tasklet
;
311 /* Initialize waitqueue. */
312 init_waitqueue_head(&card
->write
.wait_q
);
316 lcs_set_allowed_threads(struct lcs_card
*card
, unsigned long threads
)
320 spin_lock_irqsave(&card
->mask_lock
, flags
);
321 card
->thread_allowed_mask
= threads
;
322 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
323 wake_up(&card
->wait_q
);
326 lcs_threads_running(struct lcs_card
*card
, unsigned long threads
)
331 spin_lock_irqsave(&card
->mask_lock
, flags
);
332 rc
= (card
->thread_running_mask
& threads
);
333 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
338 lcs_wait_for_threads(struct lcs_card
*card
, unsigned long threads
)
340 return wait_event_interruptible(card
->wait_q
,
341 lcs_threads_running(card
, threads
) == 0);
345 lcs_set_thread_start_bit(struct lcs_card
*card
, unsigned long thread
)
349 spin_lock_irqsave(&card
->mask_lock
, flags
);
350 if ( !(card
->thread_allowed_mask
& thread
) ||
351 (card
->thread_start_mask
& thread
) ) {
352 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
355 card
->thread_start_mask
|= thread
;
356 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
361 lcs_clear_thread_running_bit(struct lcs_card
*card
, unsigned long thread
)
365 spin_lock_irqsave(&card
->mask_lock
, flags
);
366 card
->thread_running_mask
&= ~thread
;
367 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
368 wake_up(&card
->wait_q
);
372 __lcs_do_run_thread(struct lcs_card
*card
, unsigned long thread
)
377 spin_lock_irqsave(&card
->mask_lock
, flags
);
378 if (card
->thread_start_mask
& thread
){
379 if ((card
->thread_allowed_mask
& thread
) &&
380 !(card
->thread_running_mask
& thread
)){
382 card
->thread_start_mask
&= ~thread
;
383 card
->thread_running_mask
|= thread
;
387 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
392 lcs_do_run_thread(struct lcs_card
*card
, unsigned long thread
)
395 wait_event(card
->wait_q
,
396 (rc
= __lcs_do_run_thread(card
, thread
)) >= 0);
401 lcs_do_start_thread(struct lcs_card
*card
, unsigned long thread
)
406 spin_lock_irqsave(&card
->mask_lock
, flags
);
407 LCS_DBF_TEXT_(4, trace
, " %02x%02x%02x",
408 (u8
) card
->thread_start_mask
,
409 (u8
) card
->thread_allowed_mask
,
410 (u8
) card
->thread_running_mask
);
411 rc
= (card
->thread_start_mask
& thread
);
412 spin_unlock_irqrestore(&card
->mask_lock
, flags
);
417 * Initialize channels,card and state machines.
420 lcs_setup_card(struct lcs_card
*card
)
422 LCS_DBF_TEXT(2, setup
, "initcard");
423 LCS_DBF_HEX(2, setup
, &card
, sizeof(void*));
425 lcs_setup_read(card
);
426 lcs_setup_write(card
);
427 /* Set cards initial state. */
428 card
->state
= DEV_STATE_DOWN
;
429 card
->tx_buffer
= NULL
;
430 card
->tx_emitted
= 0;
432 /* Initialize kernel thread task used for LGW commands. */
433 INIT_WORK(&card
->kernel_thread_starter
,
434 (void *)lcs_start_kernel_thread
,card
);
435 card
->thread_start_mask
= 0;
436 card
->thread_allowed_mask
= 0;
437 card
->thread_running_mask
= 0;
438 init_waitqueue_head(&card
->wait_q
);
439 spin_lock_init(&card
->lock
);
440 spin_lock_init(&card
->ipm_lock
);
441 spin_lock_init(&card
->mask_lock
);
442 #ifdef CONFIG_IP_MULTICAST
443 INIT_LIST_HEAD(&card
->ipm_list
);
445 INIT_LIST_HEAD(&card
->lancmd_waiters
);
449 lcs_clear_multicast_list(struct lcs_card
*card
)
451 #ifdef CONFIG_IP_MULTICAST
452 struct lcs_ipm_list
*ipm
;
455 /* Free multicast list. */
456 LCS_DBF_TEXT(3, setup
, "clmclist");
457 spin_lock_irqsave(&card
->ipm_lock
, flags
);
458 while (!list_empty(&card
->ipm_list
)){
459 ipm
= list_entry(card
->ipm_list
.next
,
460 struct lcs_ipm_list
, list
);
461 list_del(&ipm
->list
);
462 if (ipm
->ipm_state
!= LCS_IPM_STATE_SET_REQUIRED
){
463 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
464 lcs_send_delipm(card
, ipm
);
465 spin_lock_irqsave(&card
->ipm_lock
, flags
);
469 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
473 * Cleanup channels,card and state machines.
476 lcs_cleanup_card(struct lcs_card
*card
)
479 LCS_DBF_TEXT(3, setup
, "cleancrd");
480 LCS_DBF_HEX(2,setup
,&card
,sizeof(void*));
482 if (card
->dev
!= NULL
)
483 free_netdev(card
->dev
);
484 /* Cleanup channels. */
485 lcs_cleanup_channel(&card
->write
);
486 lcs_cleanup_channel(&card
->read
);
493 lcs_start_channel(struct lcs_channel
*channel
)
498 LCS_DBF_TEXT_(4,trace
,"ssch%s", channel
->ccwdev
->dev
.bus_id
);
499 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
500 rc
= ccw_device_start(channel
->ccwdev
,
501 channel
->ccws
+ channel
->io_idx
, 0, 0,
502 DOIO_DENY_PREFETCH
| DOIO_ALLOW_SUSPEND
);
504 channel
->state
= CH_STATE_RUNNING
;
505 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
507 LCS_DBF_TEXT_(4,trace
,"essh%s", channel
->ccwdev
->dev
.bus_id
);
508 PRINT_ERR("Error in starting channel, rc=%d!\n", rc
);
514 lcs_clear_channel(struct lcs_channel
*channel
)
519 LCS_DBF_TEXT(4,trace
,"clearch");
520 LCS_DBF_TEXT_(4,trace
,"%s", channel
->ccwdev
->dev
.bus_id
);
521 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
522 rc
= ccw_device_clear(channel
->ccwdev
, (addr_t
) channel
);
523 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
525 LCS_DBF_TEXT_(4,trace
,"ecsc%s", channel
->ccwdev
->dev
.bus_id
);
528 wait_event(channel
->wait_q
, (channel
->state
== CH_STATE_CLEARED
));
529 channel
->state
= CH_STATE_STOPPED
;
538 lcs_stop_channel(struct lcs_channel
*channel
)
543 if (channel
->state
== CH_STATE_STOPPED
)
545 LCS_DBF_TEXT(4,trace
,"haltsch");
546 LCS_DBF_TEXT_(4,trace
,"%s", channel
->ccwdev
->dev
.bus_id
);
547 channel
->state
= CH_STATE_INIT
;
548 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
549 rc
= ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
550 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
552 LCS_DBF_TEXT_(4,trace
,"ehsc%s", channel
->ccwdev
->dev
.bus_id
);
555 /* Asynchronous halt initialted. Wait for its completion. */
556 wait_event(channel
->wait_q
, (channel
->state
== CH_STATE_HALTED
));
557 lcs_clear_channel(channel
);
562 * start read and write channel
565 lcs_start_channels(struct lcs_card
*card
)
569 LCS_DBF_TEXT(2, trace
, "chstart");
570 /* start read channel */
571 rc
= lcs_start_channel(&card
->read
);
574 /* start write channel */
575 rc
= lcs_start_channel(&card
->write
);
577 lcs_stop_channel(&card
->read
);
582 * stop read and write channel
585 lcs_stop_channels(struct lcs_card
*card
)
587 LCS_DBF_TEXT(2, trace
, "chhalt");
588 lcs_stop_channel(&card
->read
);
589 lcs_stop_channel(&card
->write
);
596 static struct lcs_buffer
*
597 __lcs_get_buffer(struct lcs_channel
*channel
)
601 LCS_DBF_TEXT(5, trace
, "_getbuff");
602 index
= channel
->io_idx
;
604 if (channel
->iob
[index
].state
== BUF_STATE_EMPTY
) {
605 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
606 return channel
->iob
+ index
;
608 index
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
609 } while (index
!= channel
->io_idx
);
613 static struct lcs_buffer
*
614 lcs_get_buffer(struct lcs_channel
*channel
)
616 struct lcs_buffer
*buffer
;
619 LCS_DBF_TEXT(5, trace
, "getbuff");
620 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
621 buffer
= __lcs_get_buffer(channel
);
622 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
627 * Resume channel program if the channel is suspended.
630 __lcs_resume_channel(struct lcs_channel
*channel
)
634 if (channel
->state
!= CH_STATE_SUSPENDED
)
636 if (channel
->ccws
[channel
->io_idx
].flags
& CCW_FLAG_SUSPEND
)
638 LCS_DBF_TEXT_(5, trace
, "rsch%s", channel
->ccwdev
->dev
.bus_id
);
639 rc
= ccw_device_resume(channel
->ccwdev
);
641 LCS_DBF_TEXT_(4, trace
, "ersc%s", channel
->ccwdev
->dev
.bus_id
);
642 PRINT_ERR("Error in lcs_resume_channel: rc=%d\n",rc
);
644 channel
->state
= CH_STATE_RUNNING
;
650 * Make a buffer ready for processing.
653 __lcs_ready_buffer_bits(struct lcs_channel
*channel
, int index
)
657 LCS_DBF_TEXT(5, trace
, "rdybits");
658 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
659 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
660 /* Check if we may clear the suspend bit of this buffer. */
661 if (channel
->ccws
[next
].flags
& CCW_FLAG_SUSPEND
) {
662 /* Check if we have to set the PCI bit. */
663 if (!(channel
->ccws
[prev
].flags
& CCW_FLAG_SUSPEND
))
664 /* Suspend bit of the previous buffer is not set. */
665 channel
->ccws
[index
].flags
|= CCW_FLAG_PCI
;
666 /* Suspend bit of the next buffer is set. */
667 channel
->ccws
[index
].flags
&= ~CCW_FLAG_SUSPEND
;
672 lcs_ready_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
677 LCS_DBF_TEXT(5, trace
, "rdybuff");
678 if (buffer
->state
!= BUF_STATE_LOCKED
&&
679 buffer
->state
!= BUF_STATE_PROCESSED
)
681 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
682 buffer
->state
= BUF_STATE_READY
;
683 index
= buffer
- channel
->iob
;
685 channel
->ccws
[index
].count
= buffer
->count
;
686 /* Check relevant PCI/suspend bits. */
687 __lcs_ready_buffer_bits(channel
, index
);
688 rc
= __lcs_resume_channel(channel
);
689 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
694 * Mark the buffer as processed. Take care of the suspend bit
695 * of the previous buffer. This function is called from
696 * interrupt context, so the lock must not be taken.
699 __lcs_processed_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
701 int index
, prev
, next
;
703 LCS_DBF_TEXT(5, trace
, "prcsbuff");
704 if (buffer
->state
!= BUF_STATE_READY
)
706 buffer
->state
= BUF_STATE_PROCESSED
;
707 index
= buffer
- channel
->iob
;
708 prev
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
709 next
= (index
+ 1) & (LCS_NUM_BUFFS
- 1);
710 /* Set the suspend bit and clear the PCI bit of this buffer. */
711 channel
->ccws
[index
].flags
|= CCW_FLAG_SUSPEND
;
712 channel
->ccws
[index
].flags
&= ~CCW_FLAG_PCI
;
713 /* Check the suspend bit of the previous buffer. */
714 if (channel
->iob
[prev
].state
== BUF_STATE_READY
) {
716 * Previous buffer is in state ready. It might have
717 * happened in lcs_ready_buffer that the suspend bit
718 * has not been cleared to avoid an endless loop.
721 __lcs_ready_buffer_bits(channel
, prev
);
723 /* Clear PCI bit of next buffer. */
724 channel
->ccws
[next
].flags
&= ~CCW_FLAG_PCI
;
725 return __lcs_resume_channel(channel
);
729 * Put a processed buffer back to state empty.
732 lcs_release_buffer(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
736 LCS_DBF_TEXT(5, trace
, "relbuff");
737 if (buffer
->state
!= BUF_STATE_LOCKED
&&
738 buffer
->state
!= BUF_STATE_PROCESSED
)
740 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
741 buffer
->state
= BUF_STATE_EMPTY
;
742 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
746 * Get buffer for a lan command.
748 static struct lcs_buffer
*
749 lcs_get_lancmd(struct lcs_card
*card
, int count
)
751 struct lcs_buffer
*buffer
;
754 LCS_DBF_TEXT(4, trace
, "getlncmd");
755 /* Get buffer and wait if none is available. */
756 wait_event(card
->write
.wait_q
,
757 ((buffer
= lcs_get_buffer(&card
->write
)) != NULL
));
758 count
+= sizeof(struct lcs_header
);
759 *(__u16
*)(buffer
->data
+ count
) = 0;
760 buffer
->count
= count
+ sizeof(__u16
);
761 buffer
->callback
= lcs_release_buffer
;
762 cmd
= (struct lcs_cmd
*) buffer
->data
;
764 cmd
->type
= LCS_FRAME_TYPE_CONTROL
;
771 lcs_get_reply(struct lcs_reply
*reply
)
773 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
774 atomic_inc(&reply
->refcnt
);
778 lcs_put_reply(struct lcs_reply
*reply
)
780 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
781 if (atomic_dec_and_test(&reply
->refcnt
)) {
787 static struct lcs_reply
*
788 lcs_alloc_reply(struct lcs_cmd
*cmd
)
790 struct lcs_reply
*reply
;
792 LCS_DBF_TEXT(4, trace
, "getreply");
794 reply
= kzalloc(sizeof(struct lcs_reply
), GFP_ATOMIC
);
797 atomic_set(&reply
->refcnt
,1);
798 reply
->sequence_no
= cmd
->sequence_no
;
801 init_waitqueue_head(&reply
->wait_q
);
807 * Notifier function for lancmd replies. Called from read irq.
810 lcs_notify_lancmd_waiters(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
812 struct list_head
*l
, *n
;
813 struct lcs_reply
*reply
;
815 LCS_DBF_TEXT(4, trace
, "notiwait");
816 spin_lock(&card
->lock
);
817 list_for_each_safe(l
, n
, &card
->lancmd_waiters
) {
818 reply
= list_entry(l
, struct lcs_reply
, list
);
819 if (reply
->sequence_no
== cmd
->sequence_no
) {
820 lcs_get_reply(reply
);
821 list_del_init(&reply
->list
);
822 if (reply
->callback
!= NULL
)
823 reply
->callback(card
, cmd
);
825 reply
->rc
= cmd
->return_code
;
826 wake_up(&reply
->wait_q
);
827 lcs_put_reply(reply
);
831 spin_unlock(&card
->lock
);
835 * Emit buffer of a lan comand.
838 lcs_lancmd_timeout(unsigned long data
)
840 struct lcs_reply
*reply
, *list_reply
, *r
;
843 LCS_DBF_TEXT(4, trace
, "timeout");
844 reply
= (struct lcs_reply
*) data
;
845 spin_lock_irqsave(&reply
->card
->lock
, flags
);
846 list_for_each_entry_safe(list_reply
, r
,
847 &reply
->card
->lancmd_waiters
,list
) {
848 if (reply
== list_reply
) {
849 lcs_get_reply(reply
);
850 list_del_init(&reply
->list
);
851 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
854 wake_up(&reply
->wait_q
);
855 lcs_put_reply(reply
);
859 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
863 lcs_send_lancmd(struct lcs_card
*card
, struct lcs_buffer
*buffer
,
864 void (*reply_callback
)(struct lcs_card
*, struct lcs_cmd
*))
866 struct lcs_reply
*reply
;
868 struct timer_list timer
;
872 LCS_DBF_TEXT(4, trace
, "sendcmd");
873 cmd
= (struct lcs_cmd
*) buffer
->data
;
874 cmd
->return_code
= 0;
875 cmd
->sequence_no
= card
->sequence_no
++;
876 reply
= lcs_alloc_reply(cmd
);
879 reply
->callback
= reply_callback
;
881 spin_lock_irqsave(&card
->lock
, flags
);
882 list_add_tail(&reply
->list
, &card
->lancmd_waiters
);
883 spin_unlock_irqrestore(&card
->lock
, flags
);
885 buffer
->callback
= lcs_release_buffer
;
886 rc
= lcs_ready_buffer(&card
->write
, buffer
);
890 timer
.function
= lcs_lancmd_timeout
;
891 timer
.data
= (unsigned long) reply
;
892 timer
.expires
= jiffies
+ HZ
*card
->lancmd_timeout
;
894 wait_event(reply
->wait_q
, reply
->received
);
895 del_timer_sync(&timer
);
896 LCS_DBF_TEXT_(4, trace
, "rc:%d",reply
->rc
);
898 lcs_put_reply(reply
);
899 return rc
? -EIO
: 0;
903 * LCS startup command
906 lcs_send_startup(struct lcs_card
*card
, __u8 initiator
)
908 struct lcs_buffer
*buffer
;
911 LCS_DBF_TEXT(2, trace
, "startup");
912 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
913 cmd
= (struct lcs_cmd
*) buffer
->data
;
914 cmd
->cmd_code
= LCS_CMD_STARTUP
;
915 cmd
->initiator
= initiator
;
916 cmd
->cmd
.lcs_startup
.buff_size
= LCS_IOBUFFERSIZE
;
917 return lcs_send_lancmd(card
, buffer
, NULL
);
921 * LCS shutdown command
924 lcs_send_shutdown(struct lcs_card
*card
)
926 struct lcs_buffer
*buffer
;
929 LCS_DBF_TEXT(2, trace
, "shutdown");
930 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
931 cmd
= (struct lcs_cmd
*) buffer
->data
;
932 cmd
->cmd_code
= LCS_CMD_SHUTDOWN
;
933 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
934 return lcs_send_lancmd(card
, buffer
, NULL
);
938 * LCS lanstat command
941 __lcs_lanstat_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
943 LCS_DBF_TEXT(2, trace
, "statcb");
944 memcpy(card
->mac
, cmd
->cmd
.lcs_lanstat_cmd
.mac_addr
, LCS_MAC_LENGTH
);
948 lcs_send_lanstat(struct lcs_card
*card
)
950 struct lcs_buffer
*buffer
;
953 LCS_DBF_TEXT(2,trace
, "cmdstat");
954 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
955 cmd
= (struct lcs_cmd
*) buffer
->data
;
956 /* Setup lanstat command. */
957 cmd
->cmd_code
= LCS_CMD_LANSTAT
;
958 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
959 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
960 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
961 return lcs_send_lancmd(card
, buffer
, __lcs_lanstat_cb
);
965 * send stoplan command
968 lcs_send_stoplan(struct lcs_card
*card
, __u8 initiator
)
970 struct lcs_buffer
*buffer
;
973 LCS_DBF_TEXT(2, trace
, "cmdstpln");
974 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
975 cmd
= (struct lcs_cmd
*) buffer
->data
;
976 cmd
->cmd_code
= LCS_CMD_STOPLAN
;
977 cmd
->initiator
= initiator
;
978 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
979 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
980 return lcs_send_lancmd(card
, buffer
, NULL
);
984 * send startlan command
987 __lcs_send_startlan_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
989 LCS_DBF_TEXT(2, trace
, "srtlancb");
990 card
->lan_type
= cmd
->cmd
.lcs_std_cmd
.lan_type
;
991 card
->portno
= cmd
->cmd
.lcs_std_cmd
.portno
;
995 lcs_send_startlan(struct lcs_card
*card
, __u8 initiator
)
997 struct lcs_buffer
*buffer
;
1000 LCS_DBF_TEXT(2, trace
, "cmdstaln");
1001 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
1002 cmd
= (struct lcs_cmd
*) buffer
->data
;
1003 cmd
->cmd_code
= LCS_CMD_STARTLAN
;
1004 cmd
->initiator
= initiator
;
1005 cmd
->cmd
.lcs_std_cmd
.lan_type
= card
->lan_type
;
1006 cmd
->cmd
.lcs_std_cmd
.portno
= card
->portno
;
1007 return lcs_send_lancmd(card
, buffer
, __lcs_send_startlan_cb
);
1010 #ifdef CONFIG_IP_MULTICAST
1012 * send setipm command (Multicast)
1015 lcs_send_setipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1017 struct lcs_buffer
*buffer
;
1018 struct lcs_cmd
*cmd
;
1020 LCS_DBF_TEXT(2, trace
, "cmdsetim");
1021 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1022 cmd
= (struct lcs_cmd
*) buffer
->data
;
1023 cmd
->cmd_code
= LCS_CMD_SETIPM
;
1024 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1025 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1026 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1027 cmd
->cmd
.lcs_qipassist
.version
= 4;
1028 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1029 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1030 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1031 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1032 return lcs_send_lancmd(card
, buffer
, NULL
);
1036 * send delipm command (Multicast)
1039 lcs_send_delipm(struct lcs_card
*card
,struct lcs_ipm_list
*ipm_list
)
1041 struct lcs_buffer
*buffer
;
1042 struct lcs_cmd
*cmd
;
1044 LCS_DBF_TEXT(2, trace
, "cmddelim");
1045 buffer
= lcs_get_lancmd(card
, LCS_MULTICAST_CMD_SIZE
);
1046 cmd
= (struct lcs_cmd
*) buffer
->data
;
1047 cmd
->cmd_code
= LCS_CMD_DELIPM
;
1048 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1049 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1050 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1051 cmd
->cmd
.lcs_qipassist
.version
= 4;
1052 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1053 memcpy(cmd
->cmd
.lcs_qipassist
.lcs_ipass_ctlmsg
.ip_mac_pair
,
1054 &ipm_list
->ipm
, sizeof (struct lcs_ip_mac_pair
));
1055 LCS_DBF_TEXT_(2, trace
, "%x",ipm_list
->ipm
.ip_addr
);
1056 return lcs_send_lancmd(card
, buffer
, NULL
);
1060 * check if multicast is supported by LCS
1063 __lcs_check_multicast_cb(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1065 LCS_DBF_TEXT(2, trace
, "chkmccb");
1066 card
->ip_assists_supported
=
1067 cmd
->cmd
.lcs_qipassist
.ip_assists_supported
;
1068 card
->ip_assists_enabled
=
1069 cmd
->cmd
.lcs_qipassist
.ip_assists_enabled
;
1073 lcs_check_multicast_support(struct lcs_card
*card
)
1075 struct lcs_buffer
*buffer
;
1076 struct lcs_cmd
*cmd
;
1079 LCS_DBF_TEXT(2, trace
, "cmdqipa");
1080 /* Send query ipassist. */
1081 buffer
= lcs_get_lancmd(card
, LCS_STD_CMD_SIZE
);
1082 cmd
= (struct lcs_cmd
*) buffer
->data
;
1083 cmd
->cmd_code
= LCS_CMD_QIPASSIST
;
1084 cmd
->initiator
= LCS_INITIATOR_TCPIP
;
1085 cmd
->cmd
.lcs_qipassist
.lan_type
= card
->lan_type
;
1086 cmd
->cmd
.lcs_qipassist
.portno
= card
->portno
;
1087 cmd
->cmd
.lcs_qipassist
.version
= 4;
1088 cmd
->cmd
.lcs_qipassist
.num_ip_pairs
= 1;
1089 rc
= lcs_send_lancmd(card
, buffer
, __lcs_check_multicast_cb
);
1091 PRINT_ERR("Query IPAssist failed. Assuming unsupported!\n");
1094 if (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
)
1100 * set or del multicast address on LCS card
1103 lcs_fix_multicast_list(struct lcs_card
*card
)
1105 struct list_head failed_list
;
1106 struct lcs_ipm_list
*ipm
, *tmp
;
1107 unsigned long flags
;
1110 LCS_DBF_TEXT(4,trace
, "fixipm");
1111 INIT_LIST_HEAD(&failed_list
);
1112 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1114 list_for_each_entry_safe(ipm
, tmp
, &card
->ipm_list
, list
){
1115 switch (ipm
->ipm_state
) {
1116 case LCS_IPM_STATE_SET_REQUIRED
:
1117 /* del from ipm_list so noone else can tamper with
1119 list_del_init(&ipm
->list
);
1120 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1121 rc
= lcs_send_setipm(card
, ipm
);
1122 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1124 PRINT_INFO("Adding multicast address failed."
1125 "Table possibly full!\n");
1126 /* store ipm in failed list -> will be added
1127 * to ipm_list again, so a retry will be done
1128 * during the next call of this function */
1129 list_add_tail(&ipm
->list
, &failed_list
);
1131 ipm
->ipm_state
= LCS_IPM_STATE_ON_CARD
;
1132 /* re-insert into ipm_list */
1133 list_add_tail(&ipm
->list
, &card
->ipm_list
);
1136 case LCS_IPM_STATE_DEL_REQUIRED
:
1137 list_del(&ipm
->list
);
1138 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1139 lcs_send_delipm(card
, ipm
);
1140 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1143 case LCS_IPM_STATE_ON_CARD
:
1147 /* re-insert all entries from the failed_list into ipm_list */
1148 list_for_each_entry_safe(ipm
, tmp
, &failed_list
, list
) {
1149 list_del_init(&ipm
->list
);
1150 list_add_tail(&ipm
->list
, &card
->ipm_list
);
1152 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1153 if (card
->state
== DEV_STATE_UP
)
1154 netif_wake_queue(card
->dev
);
1158 * get mac address for the relevant Multicast address
1161 lcs_get_mac_for_ipm(__u32 ipm
, char *mac
, struct net_device
*dev
)
1163 LCS_DBF_TEXT(4,trace
, "getmac");
1164 if (dev
->type
== ARPHRD_IEEE802_TR
)
1165 ip_tr_mc_map(ipm
, mac
);
1167 ip_eth_mc_map(ipm
, mac
);
1171 * function called by net device to handle multicast address relevant things
1174 lcs_remove_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1176 struct ip_mc_list
*im4
;
1177 struct list_head
*l
;
1178 struct lcs_ipm_list
*ipm
;
1179 unsigned long flags
;
1180 char buf
[MAX_ADDR_LEN
];
1182 LCS_DBF_TEXT(4, trace
, "remmclst");
1183 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1184 list_for_each(l
, &card
->ipm_list
) {
1185 ipm
= list_entry(l
, struct lcs_ipm_list
, list
);
1186 for (im4
= in4_dev
->mc_list
; im4
!= NULL
; im4
= im4
->next
) {
1187 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1188 if ( (ipm
->ipm
.ip_addr
== im4
->multiaddr
) &&
1189 (memcmp(buf
, &ipm
->ipm
.mac_addr
,
1190 LCS_MAC_LENGTH
) == 0) )
1194 ipm
->ipm_state
= LCS_IPM_STATE_DEL_REQUIRED
;
1196 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1199 static inline struct lcs_ipm_list
*
1200 lcs_check_addr_entry(struct lcs_card
*card
, struct ip_mc_list
*im4
, char *buf
)
1202 struct lcs_ipm_list
*tmp
, *ipm
= NULL
;
1203 struct list_head
*l
;
1204 unsigned long flags
;
1206 LCS_DBF_TEXT(4, trace
, "chkmcent");
1207 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1208 list_for_each(l
, &card
->ipm_list
) {
1209 tmp
= list_entry(l
, struct lcs_ipm_list
, list
);
1210 if ( (tmp
->ipm
.ip_addr
== im4
->multiaddr
) &&
1211 (memcmp(buf
, &tmp
->ipm
.mac_addr
,
1212 LCS_MAC_LENGTH
) == 0) ) {
1217 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1222 lcs_set_mc_addresses(struct lcs_card
*card
, struct in_device
*in4_dev
)
1225 struct ip_mc_list
*im4
;
1226 struct lcs_ipm_list
*ipm
;
1227 char buf
[MAX_ADDR_LEN
];
1228 unsigned long flags
;
1230 LCS_DBF_TEXT(4, trace
, "setmclst");
1231 for (im4
= in4_dev
->mc_list
; im4
; im4
= im4
->next
) {
1232 lcs_get_mac_for_ipm(im4
->multiaddr
, buf
, card
->dev
);
1233 ipm
= lcs_check_addr_entry(card
, im4
, buf
);
1235 continue; /* Address already in list. */
1236 ipm
= (struct lcs_ipm_list
*)
1237 kmalloc(sizeof(struct lcs_ipm_list
), GFP_ATOMIC
);
1239 PRINT_INFO("Not enough memory to add "
1240 "new multicast entry!\n");
1243 memset(ipm
, 0, sizeof(struct lcs_ipm_list
));
1244 memcpy(&ipm
->ipm
.mac_addr
, buf
, LCS_MAC_LENGTH
);
1245 ipm
->ipm
.ip_addr
= im4
->multiaddr
;
1246 ipm
->ipm_state
= LCS_IPM_STATE_SET_REQUIRED
;
1247 spin_lock_irqsave(&card
->ipm_lock
, flags
);
1248 list_add(&ipm
->list
, &card
->ipm_list
);
1249 spin_unlock_irqrestore(&card
->ipm_lock
, flags
);
1254 lcs_register_mc_addresses(void *data
)
1256 struct lcs_card
*card
;
1257 struct in_device
*in4_dev
;
1259 card
= (struct lcs_card
*) data
;
1260 daemonize("regipm");
1262 if (!lcs_do_run_thread(card
, LCS_SET_MC_THREAD
))
1264 LCS_DBF_TEXT(4, trace
, "regmulti");
1266 in4_dev
= in_dev_get(card
->dev
);
1267 if (in4_dev
== NULL
)
1269 read_lock(&in4_dev
->mc_list_lock
);
1270 lcs_remove_mc_addresses(card
,in4_dev
);
1271 lcs_set_mc_addresses(card
, in4_dev
);
1272 read_unlock(&in4_dev
->mc_list_lock
);
1273 in_dev_put(in4_dev
);
1275 lcs_fix_multicast_list(card
);
1277 lcs_clear_thread_running_bit(card
, LCS_SET_MC_THREAD
);
1281 * function called by net device to
1282 * handle multicast address relevant things
1285 lcs_set_multicast_list(struct net_device
*dev
)
1287 struct lcs_card
*card
;
1289 LCS_DBF_TEXT(4, trace
, "setmulti");
1290 card
= (struct lcs_card
*) dev
->priv
;
1292 if (!lcs_set_thread_start_bit(card
, LCS_SET_MC_THREAD
))
1293 schedule_work(&card
->kernel_thread_starter
);
1296 #endif /* CONFIG_IP_MULTICAST */
1299 lcs_check_irb_error(struct ccw_device
*cdev
, struct irb
*irb
)
1304 switch (PTR_ERR(irb
)) {
1306 PRINT_WARN("i/o-error on device %s\n", cdev
->dev
.bus_id
);
1307 LCS_DBF_TEXT(2, trace
, "ckirberr");
1308 LCS_DBF_TEXT_(2, trace
, " rc%d", -EIO
);
1311 PRINT_WARN("timeout on device %s\n", cdev
->dev
.bus_id
);
1312 LCS_DBF_TEXT(2, trace
, "ckirberr");
1313 LCS_DBF_TEXT_(2, trace
, " rc%d", -ETIMEDOUT
);
1316 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb
),
1318 LCS_DBF_TEXT(2, trace
, "ckirberr");
1319 LCS_DBF_TEXT(2, trace
, " rc???");
1321 return PTR_ERR(irb
);
1326 * IRQ Handler for LCS channels
1329 lcs_irq(struct ccw_device
*cdev
, unsigned long intparm
, struct irb
*irb
)
1331 struct lcs_card
*card
;
1332 struct lcs_channel
*channel
;
1335 if (lcs_check_irb_error(cdev
, irb
))
1338 card
= CARD_FROM_DEV(cdev
);
1339 if (card
->read
.ccwdev
== cdev
)
1340 channel
= &card
->read
;
1342 channel
= &card
->write
;
1344 LCS_DBF_TEXT_(5, trace
, "Rint%s",cdev
->dev
.bus_id
);
1345 LCS_DBF_TEXT_(5, trace
, "%4x%4x",irb
->scsw
.cstat
, irb
->scsw
.dstat
);
1346 LCS_DBF_TEXT_(5, trace
, "%4x%4x",irb
->scsw
.fctl
, irb
->scsw
.actl
);
1348 /* How far in the ccw chain have we processed? */
1349 if ((channel
->state
!= CH_STATE_INIT
) &&
1350 (irb
->scsw
.fctl
& SCSW_FCTL_START_FUNC
)) {
1351 index
= (struct ccw1
*) __va((addr_t
) irb
->scsw
.cpa
)
1353 if ((irb
->scsw
.actl
& SCSW_ACTL_SUSPENDED
) ||
1354 (irb
->scsw
.cstat
| SCHN_STAT_PCI
))
1355 /* Bloody io subsystem tells us lies about cpa... */
1356 index
= (index
- 1) & (LCS_NUM_BUFFS
- 1);
1357 while (channel
->io_idx
!= index
) {
1358 __lcs_processed_buffer(channel
,
1359 channel
->iob
+ channel
->io_idx
);
1361 (channel
->io_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1365 if ((irb
->scsw
.dstat
& DEV_STAT_DEV_END
) ||
1366 (irb
->scsw
.dstat
& DEV_STAT_CHN_END
) ||
1367 (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
))
1368 /* Mark channel as stopped. */
1369 channel
->state
= CH_STATE_STOPPED
;
1370 else if (irb
->scsw
.actl
& SCSW_ACTL_SUSPENDED
)
1371 /* CCW execution stopped on a suspend bit. */
1372 channel
->state
= CH_STATE_SUSPENDED
;
1374 if (irb
->scsw
.fctl
& SCSW_FCTL_HALT_FUNC
) {
1375 if (irb
->scsw
.cc
!= 0) {
1376 ccw_device_halt(channel
->ccwdev
, (addr_t
) channel
);
1379 /* The channel has been stopped by halt_IO. */
1380 channel
->state
= CH_STATE_HALTED
;
1383 if (irb
->scsw
.fctl
& SCSW_FCTL_CLEAR_FUNC
) {
1384 channel
->state
= CH_STATE_CLEARED
;
1386 /* Do the rest in the tasklet. */
1387 tasklet_schedule(&channel
->irq_tasklet
);
1391 * Tasklet for IRQ handler
1394 lcs_tasklet(unsigned long data
)
1396 unsigned long flags
;
1397 struct lcs_channel
*channel
;
1398 struct lcs_buffer
*iob
;
1402 channel
= (struct lcs_channel
*) data
;
1403 LCS_DBF_TEXT_(5, trace
, "tlet%s",channel
->ccwdev
->dev
.bus_id
);
1405 /* Check for processed buffers. */
1407 buf_idx
= channel
->buf_idx
;
1408 while (iob
[buf_idx
].state
== BUF_STATE_PROCESSED
) {
1409 /* Do the callback thing. */
1410 if (iob
[buf_idx
].callback
!= NULL
)
1411 iob
[buf_idx
].callback(channel
, iob
+ buf_idx
);
1412 buf_idx
= (buf_idx
+ 1) & (LCS_NUM_BUFFS
- 1);
1414 channel
->buf_idx
= buf_idx
;
1416 if (channel
->state
== CH_STATE_STOPPED
)
1417 // FIXME: what if rc != 0 ??
1418 rc
= lcs_start_channel(channel
);
1419 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1420 if (channel
->state
== CH_STATE_SUSPENDED
&&
1421 channel
->iob
[channel
->io_idx
].state
== BUF_STATE_READY
) {
1422 // FIXME: what if rc != 0 ??
1423 rc
= __lcs_resume_channel(channel
);
1425 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1427 /* Something happened on the channel. Wake up waiters. */
1428 wake_up(&channel
->wait_q
);
1432 * Finish current tx buffer and make it ready for transmit.
1435 __lcs_emit_txbuffer(struct lcs_card
*card
)
1437 LCS_DBF_TEXT(5, trace
, "emittx");
1438 *(__u16
*)(card
->tx_buffer
->data
+ card
->tx_buffer
->count
) = 0;
1439 card
->tx_buffer
->count
+= 2;
1440 lcs_ready_buffer(&card
->write
, card
->tx_buffer
);
1441 card
->tx_buffer
= NULL
;
1446 * Callback for finished tx buffers.
1449 lcs_txbuffer_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1451 struct lcs_card
*card
;
1453 LCS_DBF_TEXT(5, trace
, "txbuffcb");
1454 /* Put buffer back to pool. */
1455 lcs_release_buffer(channel
, buffer
);
1456 card
= (struct lcs_card
*)
1457 ((char *) channel
- offsetof(struct lcs_card
, write
));
1458 if (netif_queue_stopped(card
->dev
))
1459 netif_wake_queue(card
->dev
);
1460 spin_lock(&card
->lock
);
1462 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1464 * Last running tx buffer has finished. Submit partially
1465 * filled current buffer.
1467 __lcs_emit_txbuffer(card
);
1468 spin_unlock(&card
->lock
);
1472 * Packet transmit function called by network stack
1475 __lcs_start_xmit(struct lcs_card
*card
, struct sk_buff
*skb
,
1476 struct net_device
*dev
)
1478 struct lcs_header
*header
;
1481 LCS_DBF_TEXT(5, trace
, "hardxmit");
1483 card
->stats
.tx_dropped
++;
1484 card
->stats
.tx_errors
++;
1487 if (card
->state
!= DEV_STATE_UP
) {
1489 card
->stats
.tx_dropped
++;
1490 card
->stats
.tx_errors
++;
1491 card
->stats
.tx_carrier_errors
++;
1494 netif_stop_queue(card
->dev
);
1495 spin_lock(&card
->lock
);
1496 if (card
->tx_buffer
!= NULL
&&
1497 card
->tx_buffer
->count
+ sizeof(struct lcs_header
) +
1498 skb
->len
+ sizeof(u16
) > LCS_IOBUFFERSIZE
)
1499 /* skb too big for current tx buffer. */
1500 __lcs_emit_txbuffer(card
);
1501 if (card
->tx_buffer
== NULL
) {
1502 /* Get new tx buffer */
1503 card
->tx_buffer
= lcs_get_buffer(&card
->write
);
1504 if (card
->tx_buffer
== NULL
) {
1505 card
->stats
.tx_dropped
++;
1509 card
->tx_buffer
->callback
= lcs_txbuffer_cb
;
1510 card
->tx_buffer
->count
= 0;
1512 header
= (struct lcs_header
*)
1513 (card
->tx_buffer
->data
+ card
->tx_buffer
->count
);
1514 card
->tx_buffer
->count
+= skb
->len
+ sizeof(struct lcs_header
);
1515 header
->offset
= card
->tx_buffer
->count
;
1516 header
->type
= card
->lan_type
;
1517 header
->slot
= card
->portno
;
1518 memcpy(header
+ 1, skb
->data
, skb
->len
);
1519 spin_unlock(&card
->lock
);
1520 card
->stats
.tx_bytes
+= skb
->len
;
1521 card
->stats
.tx_packets
++;
1523 netif_wake_queue(card
->dev
);
1524 spin_lock(&card
->lock
);
1525 if (card
->tx_emitted
<= 0 && card
->tx_buffer
!= NULL
)
1526 /* If this is the first tx buffer emit it immediately. */
1527 __lcs_emit_txbuffer(card
);
1529 spin_unlock(&card
->lock
);
1534 lcs_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1536 struct lcs_card
*card
;
1539 LCS_DBF_TEXT(5, trace
, "pktxmit");
1540 card
= (struct lcs_card
*) dev
->priv
;
1541 rc
= __lcs_start_xmit(card
, skb
, dev
);
1546 * send startlan and lanstat command to make LCS device ready
1549 lcs_startlan_auto(struct lcs_card
*card
)
1553 LCS_DBF_TEXT(2, trace
, "strtauto");
1554 #ifdef CONFIG_NET_ETHERNET
1555 card
->lan_type
= LCS_FRAME_TYPE_ENET
;
1556 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1562 card
->lan_type
= LCS_FRAME_TYPE_TR
;
1563 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1568 card
->lan_type
= LCS_FRAME_TYPE_FDDI
;
1569 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1577 lcs_startlan(struct lcs_card
*card
)
1581 LCS_DBF_TEXT(2, trace
, "startlan");
1583 if (card
->portno
!= LCS_INVALID_PORT_NO
) {
1584 if (card
->lan_type
== LCS_FRAME_TYPE_AUTO
)
1585 rc
= lcs_startlan_auto(card
);
1587 rc
= lcs_send_startlan(card
, LCS_INITIATOR_TCPIP
);
1589 for (i
= 0; i
<= 16; i
++) {
1591 if (card
->lan_type
!= LCS_FRAME_TYPE_AUTO
)
1592 rc
= lcs_send_startlan(card
,
1593 LCS_INITIATOR_TCPIP
);
1595 /* autodetecting lan type */
1596 rc
= lcs_startlan_auto(card
);
1602 return lcs_send_lanstat(card
);
1607 * LCS detect function
1608 * setup channels and make them I/O ready
1611 lcs_detect(struct lcs_card
*card
)
1615 LCS_DBF_TEXT(2, setup
, "lcsdetct");
1616 /* start/reset card */
1618 netif_stop_queue(card
->dev
);
1619 rc
= lcs_stop_channels(card
);
1621 rc
= lcs_start_channels(card
);
1623 rc
= lcs_send_startup(card
, LCS_INITIATOR_TCPIP
);
1625 rc
= lcs_startlan(card
);
1629 card
->state
= DEV_STATE_UP
;
1631 card
->state
= DEV_STATE_DOWN
;
1632 card
->write
.state
= CH_STATE_INIT
;
1633 card
->read
.state
= CH_STATE_INIT
;
1642 lcs_resetcard(struct lcs_card
*card
)
1646 LCS_DBF_TEXT(2, trace
, "rescard");
1647 for (retries
= 0; retries
< 10; retries
++) {
1648 if (lcs_detect(card
) == 0) {
1649 netif_wake_queue(card
->dev
);
1650 card
->state
= DEV_STATE_UP
;
1651 PRINT_INFO("LCS device %s successfully restarted!\n",
1657 PRINT_ERR("Error in Reseting LCS card!\n");
1666 lcs_stopcard(struct lcs_card
*card
)
1670 LCS_DBF_TEXT(3, setup
, "stopcard");
1672 if (card
->read
.state
!= CH_STATE_STOPPED
&&
1673 card
->write
.state
!= CH_STATE_STOPPED
&&
1674 card
->state
== DEV_STATE_UP
) {
1675 lcs_clear_multicast_list(card
);
1676 rc
= lcs_send_stoplan(card
,LCS_INITIATOR_TCPIP
);
1677 rc
= lcs_send_shutdown(card
);
1679 rc
= lcs_stop_channels(card
);
1680 card
->state
= DEV_STATE_DOWN
;
1686 * LGW initiated commands
1689 lcs_lgw_startlan_thread(void *data
)
1691 struct lcs_card
*card
;
1693 card
= (struct lcs_card
*) data
;
1694 daemonize("lgwstpln");
1696 if (!lcs_do_run_thread(card
, LCS_STARTLAN_THREAD
))
1698 LCS_DBF_TEXT(4, trace
, "lgwstpln");
1700 netif_stop_queue(card
->dev
);
1701 if (lcs_startlan(card
) == 0) {
1702 netif_wake_queue(card
->dev
);
1703 card
->state
= DEV_STATE_UP
;
1704 PRINT_INFO("LCS Startlan for device %s succeeded!\n",
1708 PRINT_ERR("LCS Startlan for device %s failed!\n",
1710 lcs_clear_thread_running_bit(card
, LCS_STARTLAN_THREAD
);
1715 * Send startup command initiated by Lan Gateway
1718 lcs_lgw_startup_thread(void *data
)
1722 struct lcs_card
*card
;
1724 card
= (struct lcs_card
*) data
;
1725 daemonize("lgwstaln");
1727 if (!lcs_do_run_thread(card
, LCS_STARTUP_THREAD
))
1729 LCS_DBF_TEXT(4, trace
, "lgwstaln");
1731 netif_stop_queue(card
->dev
);
1732 rc
= lcs_send_startup(card
, LCS_INITIATOR_LGW
);
1734 PRINT_ERR("Startup for LCS device %s initiated " \
1735 "by LGW failed!\nReseting card ...\n",
1737 /* do a card reset */
1738 rc
= lcs_resetcard(card
);
1742 rc
= lcs_startlan(card
);
1744 netif_wake_queue(card
->dev
);
1745 card
->state
= DEV_STATE_UP
;
1749 PRINT_INFO("LCS Startup for device %s succeeded!\n",
1752 PRINT_ERR("LCS Startup for device %s failed!\n",
1754 lcs_clear_thread_running_bit(card
, LCS_STARTUP_THREAD
);
1760 * send stoplan command initiated by Lan Gateway
1763 lcs_lgw_stoplan_thread(void *data
)
1765 struct lcs_card
*card
;
1768 card
= (struct lcs_card
*) data
;
1769 daemonize("lgwstop");
1771 if (!lcs_do_run_thread(card
, LCS_STOPLAN_THREAD
))
1773 LCS_DBF_TEXT(4, trace
, "lgwstop");
1775 netif_stop_queue(card
->dev
);
1776 if (lcs_send_stoplan(card
, LCS_INITIATOR_LGW
) == 0)
1777 PRINT_INFO("Stoplan for %s initiated by LGW succeeded!\n",
1780 PRINT_ERR("Stoplan %s initiated by LGW failed!\n",
1782 /*Try to reset the card, stop it on failure */
1783 rc
= lcs_resetcard(card
);
1785 rc
= lcs_stopcard(card
);
1786 lcs_clear_thread_running_bit(card
, LCS_STOPLAN_THREAD
);
1791 * Kernel Thread helper functions for LGW initiated commands
1794 lcs_start_kernel_thread(struct lcs_card
*card
)
1796 LCS_DBF_TEXT(5, trace
, "krnthrd");
1797 if (lcs_do_start_thread(card
, LCS_STARTUP_THREAD
))
1798 kernel_thread(lcs_lgw_startup_thread
, (void *) card
, SIGCHLD
);
1799 if (lcs_do_start_thread(card
, LCS_STARTLAN_THREAD
))
1800 kernel_thread(lcs_lgw_startlan_thread
, (void *) card
, SIGCHLD
);
1801 if (lcs_do_start_thread(card
, LCS_STOPLAN_THREAD
))
1802 kernel_thread(lcs_lgw_stoplan_thread
, (void *) card
, SIGCHLD
);
1803 #ifdef CONFIG_IP_MULTICAST
1804 if (lcs_do_start_thread(card
, LCS_SET_MC_THREAD
))
1805 kernel_thread(lcs_register_mc_addresses
, (void *) card
, SIGCHLD
);
1810 * Process control frames.
1813 lcs_get_control(struct lcs_card
*card
, struct lcs_cmd
*cmd
)
1815 LCS_DBF_TEXT(5, trace
, "getctrl");
1816 if (cmd
->initiator
== LCS_INITIATOR_LGW
) {
1817 switch(cmd
->cmd_code
) {
1818 case LCS_CMD_STARTUP
:
1819 if (!lcs_set_thread_start_bit(card
,
1820 LCS_STARTUP_THREAD
))
1821 schedule_work(&card
->kernel_thread_starter
);
1823 case LCS_CMD_STARTLAN
:
1824 if (!lcs_set_thread_start_bit(card
,
1825 LCS_STARTLAN_THREAD
))
1826 schedule_work(&card
->kernel_thread_starter
);
1828 case LCS_CMD_STOPLAN
:
1829 if (!lcs_set_thread_start_bit(card
,
1830 LCS_STOPLAN_THREAD
))
1831 schedule_work(&card
->kernel_thread_starter
);
1834 PRINT_INFO("UNRECOGNIZED LGW COMMAND\n");
1838 lcs_notify_lancmd_waiters(card
, cmd
);
1842 * Unpack network packet.
1845 lcs_get_skb(struct lcs_card
*card
, char *skb_data
, unsigned int skb_len
)
1847 struct sk_buff
*skb
;
1849 LCS_DBF_TEXT(5, trace
, "getskb");
1850 if (card
->dev
== NULL
||
1851 card
->state
!= DEV_STATE_UP
)
1852 /* The card isn't up. Ignore the packet. */
1855 skb
= dev_alloc_skb(skb_len
);
1857 PRINT_ERR("LCS: alloc_skb failed for device=%s\n",
1859 card
->stats
.rx_dropped
++;
1862 skb
->dev
= card
->dev
;
1863 memcpy(skb_put(skb
, skb_len
), skb_data
, skb_len
);
1864 skb
->protocol
= card
->lan_type_trans(skb
, card
->dev
);
1865 card
->stats
.rx_bytes
+= skb_len
;
1866 card
->stats
.rx_packets
++;
1867 *((__u32
*)skb
->cb
) = ++card
->pkt_seq
;
1872 * LCS main routine to get packets and lancmd replies from the buffers
1875 lcs_get_frames_cb(struct lcs_channel
*channel
, struct lcs_buffer
*buffer
)
1877 struct lcs_card
*card
;
1878 struct lcs_header
*lcs_hdr
;
1881 LCS_DBF_TEXT(5, trace
, "lcsgtpkt");
1882 lcs_hdr
= (struct lcs_header
*) buffer
->data
;
1883 if (lcs_hdr
->offset
== LCS_ILLEGAL_OFFSET
) {
1884 LCS_DBF_TEXT(4, trace
, "-eiogpkt");
1887 card
= (struct lcs_card
*)
1888 ((char *) channel
- offsetof(struct lcs_card
, read
));
1890 while (lcs_hdr
->offset
!= 0) {
1891 if (lcs_hdr
->offset
<= 0 ||
1892 lcs_hdr
->offset
> LCS_IOBUFFERSIZE
||
1893 lcs_hdr
->offset
< offset
) {
1894 /* Offset invalid. */
1895 card
->stats
.rx_length_errors
++;
1896 card
->stats
.rx_errors
++;
1899 /* What kind of frame is it? */
1900 if (lcs_hdr
->type
== LCS_FRAME_TYPE_CONTROL
)
1901 /* Control frame. */
1902 lcs_get_control(card
, (struct lcs_cmd
*) lcs_hdr
);
1903 else if (lcs_hdr
->type
== LCS_FRAME_TYPE_ENET
||
1904 lcs_hdr
->type
== LCS_FRAME_TYPE_TR
||
1905 lcs_hdr
->type
== LCS_FRAME_TYPE_FDDI
)
1906 /* Normal network packet. */
1907 lcs_get_skb(card
, (char *)(lcs_hdr
+ 1),
1908 lcs_hdr
->offset
- offset
-
1909 sizeof(struct lcs_header
));
1911 /* Unknown frame type. */
1912 ; // FIXME: error message ?
1913 /* Proceed to next frame. */
1914 offset
= lcs_hdr
->offset
;
1915 lcs_hdr
->offset
= LCS_ILLEGAL_OFFSET
;
1916 lcs_hdr
= (struct lcs_header
*) (buffer
->data
+ offset
);
1918 /* The buffer is now empty. Make it ready again. */
1919 lcs_ready_buffer(&card
->read
, buffer
);
1923 * get network statistics for ifconfig and other user programs
1925 static struct net_device_stats
*
1926 lcs_getstats(struct net_device
*dev
)
1928 struct lcs_card
*card
;
1930 LCS_DBF_TEXT(4, trace
, "netstats");
1931 card
= (struct lcs_card
*) dev
->priv
;
1932 return &card
->stats
;
1937 * This function will be called by user doing ifconfig xxx down
1940 lcs_stop_device(struct net_device
*dev
)
1942 struct lcs_card
*card
;
1945 LCS_DBF_TEXT(2, trace
, "stopdev");
1946 card
= (struct lcs_card
*) dev
->priv
;
1947 netif_stop_queue(dev
);
1948 dev
->flags
&= ~IFF_UP
;
1949 rc
= lcs_stopcard(card
);
1951 PRINT_ERR("Try it again!\n ");
1956 * start lcs device and make it runnable
1957 * This function will be called by user doing ifconfig xxx up
1960 lcs_open_device(struct net_device
*dev
)
1962 struct lcs_card
*card
;
1965 LCS_DBF_TEXT(2, trace
, "opendev");
1966 card
= (struct lcs_card
*) dev
->priv
;
1967 /* initialize statistics */
1968 rc
= lcs_detect(card
);
1970 PRINT_ERR("LCS:Error in opening device!\n");
1973 dev
->flags
|= IFF_UP
;
1974 netif_wake_queue(dev
);
1975 card
->state
= DEV_STATE_UP
;
1981 * show function for portno called by cat or similar things
1984 lcs_portno_show (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1986 struct lcs_card
*card
;
1988 card
= (struct lcs_card
*)dev
->driver_data
;
1993 return sprintf(buf
, "%d\n", card
->portno
);
1997 * store the value which is piped to file portno
2000 lcs_portno_store (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
2002 struct lcs_card
*card
;
2005 card
= (struct lcs_card
*)dev
->driver_data
;
2010 sscanf(buf
, "%u", &value
);
2011 /* TODO: sanity checks */
2012 card
->portno
= value
;
2018 static DEVICE_ATTR(portno
, 0644, lcs_portno_show
, lcs_portno_store
);
2021 lcs_type_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2023 struct ccwgroup_device
*cgdev
;
2025 cgdev
= to_ccwgroupdev(dev
);
2029 return sprintf(buf
, "%s\n", cu3088_type
[cgdev
->cdev
[0]->id
.driver_info
]);
2032 static DEVICE_ATTR(type
, 0444, lcs_type_show
, NULL
);
2035 lcs_timeout_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2037 struct lcs_card
*card
;
2039 card
= (struct lcs_card
*)dev
->driver_data
;
2041 return card
? sprintf(buf
, "%u\n", card
->lancmd_timeout
) : 0;
2045 lcs_timeout_store (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
2047 struct lcs_card
*card
;
2050 card
= (struct lcs_card
*)dev
->driver_data
;
2055 sscanf(buf
, "%u", &value
);
2056 /* TODO: sanity checks */
2057 card
->lancmd_timeout
= value
;
2063 DEVICE_ATTR(lancmd_timeout
, 0644, lcs_timeout_show
, lcs_timeout_store
);
2065 static struct attribute
* lcs_attrs
[] = {
2066 &dev_attr_portno
.attr
,
2067 &dev_attr_type
.attr
,
2068 &dev_attr_lancmd_timeout
.attr
,
2072 static struct attribute_group lcs_attr_group
= {
2077 * lcs_probe_device is called on establishing a new ccwgroup_device.
2080 lcs_probe_device(struct ccwgroup_device
*ccwgdev
)
2082 struct lcs_card
*card
;
2085 if (!get_device(&ccwgdev
->dev
))
2088 LCS_DBF_TEXT(2, setup
, "add_dev");
2089 card
= lcs_alloc_card();
2091 PRINT_ERR("Allocation of lcs card failed\n");
2092 put_device(&ccwgdev
->dev
);
2095 ret
= sysfs_create_group(&ccwgdev
->dev
.kobj
, &lcs_attr_group
);
2097 PRINT_ERR("Creating attributes failed");
2098 lcs_free_card(card
);
2099 put_device(&ccwgdev
->dev
);
2102 ccwgdev
->dev
.driver_data
= card
;
2103 ccwgdev
->cdev
[0]->handler
= lcs_irq
;
2104 ccwgdev
->cdev
[1]->handler
= lcs_irq
;
2109 lcs_register_netdev(struct ccwgroup_device
*ccwgdev
)
2111 struct lcs_card
*card
;
2113 LCS_DBF_TEXT(2, setup
, "regnetdv");
2114 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2115 if (card
->dev
->reg_state
!= NETREG_UNINITIALIZED
)
2117 SET_NETDEV_DEV(card
->dev
, &ccwgdev
->dev
);
2118 return register_netdev(card
->dev
);
2122 * lcs_new_device will be called by setting the group device online.
2126 lcs_new_device(struct ccwgroup_device
*ccwgdev
)
2128 struct lcs_card
*card
;
2129 struct net_device
*dev
=NULL
;
2130 enum lcs_dev_states recover_state
;
2133 card
= (struct lcs_card
*)ccwgdev
->dev
.driver_data
;
2137 LCS_DBF_TEXT(2, setup
, "newdev");
2138 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2139 card
->read
.ccwdev
= ccwgdev
->cdev
[0];
2140 card
->write
.ccwdev
= ccwgdev
->cdev
[1];
2142 recover_state
= card
->state
;
2143 ccw_device_set_online(card
->read
.ccwdev
);
2144 ccw_device_set_online(card
->write
.ccwdev
);
2146 LCS_DBF_TEXT(3, setup
, "lcsnewdv");
2148 lcs_setup_card(card
);
2149 rc
= lcs_detect(card
);
2151 LCS_DBF_TEXT(2, setup
, "dtctfail");
2152 PRINT_WARN("Detection of LCS card failed with return code "
2153 "%d (0x%x)\n", rc
, rc
);
2158 LCS_DBF_TEXT(2, setup
, "samedev");
2159 LCS_DBF_HEX(3, setup
, &card
, sizeof(void*));
2162 switch (card
->lan_type
) {
2163 #ifdef CONFIG_NET_ETHERNET
2164 case LCS_FRAME_TYPE_ENET
:
2165 card
->lan_type_trans
= eth_type_trans
;
2166 dev
= alloc_etherdev(0);
2170 case LCS_FRAME_TYPE_TR
:
2171 card
->lan_type_trans
= tr_type_trans
;
2172 dev
= alloc_trdev(0);
2176 case LCS_FRAME_TYPE_FDDI
:
2177 card
->lan_type_trans
= fddi_type_trans
;
2178 dev
= alloc_fddidev(0);
2182 LCS_DBF_TEXT(3, setup
, "errinit");
2183 PRINT_ERR("LCS: Initialization failed\n");
2184 PRINT_ERR("LCS: No device found!\n");
2190 card
->dev
->priv
= card
;
2191 card
->dev
->open
= lcs_open_device
;
2192 card
->dev
->stop
= lcs_stop_device
;
2193 card
->dev
->hard_start_xmit
= lcs_start_xmit
;
2194 card
->dev
->get_stats
= lcs_getstats
;
2195 SET_MODULE_OWNER(dev
);
2196 memcpy(card
->dev
->dev_addr
, card
->mac
, LCS_MAC_LENGTH
);
2197 #ifdef CONFIG_IP_MULTICAST
2198 if (!lcs_check_multicast_support(card
))
2199 card
->dev
->set_multicast_list
= lcs_set_multicast_list
;
2202 lcs_set_allowed_threads(card
,0xffffffff);
2203 if (recover_state
== DEV_STATE_RECOVER
) {
2204 lcs_set_multicast_list(card
->dev
);
2205 card
->dev
->flags
|= IFF_UP
;
2206 netif_wake_queue(card
->dev
);
2207 card
->state
= DEV_STATE_UP
;
2212 if (lcs_register_netdev(ccwgdev
) != 0)
2215 /* Print out supported assists: IPv6 */
2216 PRINT_INFO("LCS device %s %s IPv6 support\n", card
->dev
->name
,
2217 (card
->ip_assists_supported
& LCS_IPASS_IPV6_SUPPORT
) ?
2218 "with" : "without");
2219 /* Print out supported assist: Multicast */
2220 PRINT_INFO("LCS device %s %s Multicast support\n", card
->dev
->name
,
2221 (card
->ip_assists_supported
& LCS_IPASS_MULTICAST_SUPPORT
) ?
2222 "with" : "without");
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");
2328 * LCS module cleanup function
2331 __exit
lcs_cleanup_module(void)
2333 PRINT_INFO("Terminating lcs module.\n");
2334 LCS_DBF_TEXT(0, trace
, "cleanup");
2335 unregister_cu3088_discipline(&lcs_group_driver
);
2336 lcs_unregister_debug_facility();
2339 module_init(lcs_init_module
);
2340 module_exit(lcs_cleanup_module
);
2342 MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>");
2343 MODULE_LICENSE("GPL");