2 * drivers/s390/net/ctcm_main.c
4 * Copyright IBM Corp. 2001, 2007
6 * Original CTC driver(s):
7 * Fritz Elfert (felfert@millenux.com)
8 * Dieter Wellerdiek (wel@de.ibm.com)
9 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 * Denis Joseph Barrow (barrow_dj@yahoo.com)
11 * Jochen Roehrig (roehrig@de.ibm.com)
12 * Cornelia Huck <cornelia.huck@de.ibm.com>
14 * Belinda Thompson (belindat@us.ibm.com)
15 * Andy Richter (richtera@us.ibm.com)
17 * Peter Tiedemann (ptiedem@de.ibm.com)
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/errno.h>
29 #include <linux/types.h>
30 #include <linux/interrupt.h>
31 #include <linux/timer.h>
32 #include <linux/bitops.h>
34 #include <linux/signal.h>
35 #include <linux/string.h>
38 #include <linux/if_arp.h>
39 #include <linux/tcp.h>
40 #include <linux/skbuff.h>
41 #include <linux/ctype.h>
45 #include <asm/ccwdev.h>
46 #include <asm/ccwgroup.h>
47 #include <linux/uaccess.h>
49 #include <asm/idals.h>
52 #include "ctcm_fsms.h"
53 #include "ctcm_main.h"
55 /* Some common global variables */
58 * Linked list of all detected channels.
60 struct channel *channels;
63 * Unpack a just received skb and hand it over to
66 * ch The channel where this skb has been received.
67 * pskb The received skb.
69 void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb)
71 struct net_device *dev = ch->netdev;
72 struct ctcm_priv *priv = dev->priv;
73 __u16 len = *((__u16 *) pskb->data);
75 skb_put(pskb, 2 + LL_HEADER_LENGTH);
78 pskb->ip_summed = CHECKSUM_UNNECESSARY;
82 struct ll_header *header = (struct ll_header *)pskb->data;
84 skb_pull(pskb, LL_HEADER_LENGTH);
85 if ((ch->protocol == CTCM_PROTO_S390) &&
86 (header->type != ETH_P_IP)) {
88 if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
90 * Check packet type only if we stick strictly
91 * to S/390's protocol of OS390. This only
92 * supports IP. Otherwise allow any packet
95 ctcm_pr_warn("%s Illegal packet type 0x%04x "
96 "received, dropping\n",
97 dev->name, header->type);
98 ch->logflags |= LOG_FLAG_ILLEGALPKT;
101 priv->stats.rx_dropped++;
102 priv->stats.rx_frame_errors++;
105 pskb->protocol = ntohs(header->type);
106 if (header->length <= LL_HEADER_LENGTH) {
107 if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
109 "%s Illegal packet size %d "
110 "received (MTU=%d blocklen=%d), "
111 "dropping\n", dev->name, header->length,
113 ch->logflags |= LOG_FLAG_ILLEGALSIZE;
116 priv->stats.rx_dropped++;
117 priv->stats.rx_length_errors++;
120 header->length -= LL_HEADER_LENGTH;
121 len -= LL_HEADER_LENGTH;
122 if ((header->length > skb_tailroom(pskb)) ||
123 (header->length > len)) {
124 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
126 "%s Illegal packet size %d (beyond the"
127 " end of received data), dropping\n",
128 dev->name, header->length);
129 ch->logflags |= LOG_FLAG_OVERRUN;
132 priv->stats.rx_dropped++;
133 priv->stats.rx_length_errors++;
136 skb_put(pskb, header->length);
137 skb_reset_mac_header(pskb);
138 len -= header->length;
139 skb = dev_alloc_skb(pskb->len);
141 if (!(ch->logflags & LOG_FLAG_NOMEM)) {
143 "%s Out of memory in ctcm_unpack_skb\n",
145 ch->logflags |= LOG_FLAG_NOMEM;
147 priv->stats.rx_dropped++;
150 skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len),
152 skb_reset_mac_header(skb);
153 skb->dev = pskb->dev;
154 skb->protocol = pskb->protocol;
155 pskb->ip_summed = CHECKSUM_UNNECESSARY;
161 priv->stats.rx_packets++;
162 priv->stats.rx_bytes += skblen;
164 dev->last_rx = jiffies;
166 skb_pull(pskb, header->length);
167 if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
168 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
169 CTCM_DBF_DEV_NAME(TRACE, dev,
170 "Overrun in ctcm_unpack_skb");
171 ch->logflags |= LOG_FLAG_OVERRUN;
175 skb_put(pskb, LL_HEADER_LENGTH);
181 * Release a specific channel in the channel list.
183 * ch Pointer to channel struct to be released.
185 static void channel_free(struct channel *ch)
187 CTCM_DBF_TEXT(TRACE, 2, __FUNCTION__);
188 ch->flags &= ~CHANNEL_FLAGS_INUSE;
189 fsm_newstate(ch->fsm, CTC_STATE_IDLE);
193 * Remove a specific channel in the channel list.
195 * ch Pointer to channel struct to be released.
197 static void channel_remove(struct channel *ch)
199 struct channel **c = &channels;
200 char chid[CTCM_ID_SIZE+1];
206 strncpy(chid, ch->id, CTCM_ID_SIZE);
212 fsm_deltimer(&ch->timer);
214 fsm_deltimer(&ch->sweep_timer);
217 clear_normalized_cda(&ch->ccw[4]);
218 if (ch->trans_skb != NULL) {
219 clear_normalized_cda(&ch->ccw[1]);
220 dev_kfree_skb_any(ch->trans_skb);
223 tasklet_kill(&ch->ch_tasklet);
224 tasklet_kill(&ch->ch_disc_tasklet);
225 kfree(ch->discontact_th);
236 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s) %s", CTCM_FUNTAIL,
237 chid, ok ? "OK" : "failed");
241 * Get a specific channel from the channel list.
243 * type Type of channel we are interested in.
244 * id Id of channel we are interested in.
245 * direction Direction we want to use this channel for.
247 * returns Pointer to a channel or NULL if no matching channel available.
249 static struct channel *channel_get(enum channel_types type,
250 char *id, int direction)
252 struct channel *ch = channels;
256 sprintf(buf, "%s(%d, %s, %d)\n",
257 CTCM_FUNTAIL, type, id, direction);
258 CTCM_DBF_TEXT(TRACE, CTC_DBF_INFO, buf);
260 while (ch && (strncmp(ch->id, id, CTCM_ID_SIZE) || (ch->type != type)))
264 sprintf(buf, "%s(%d, %s, %d) not found in channel list\n",
265 CTCM_FUNTAIL, type, id, direction);
266 CTCM_DBF_TEXT(ERROR, CTC_DBF_ERROR, buf);
268 if (ch->flags & CHANNEL_FLAGS_INUSE)
271 ch->flags |= CHANNEL_FLAGS_INUSE;
272 ch->flags &= ~CHANNEL_FLAGS_RWMASK;
273 ch->flags |= (direction == WRITE)
274 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
275 fsm_newstate(ch->fsm, CTC_STATE_STOPPED);
281 static long ctcm_check_irb_error(struct ccw_device *cdev, struct irb *irb)
286 CTCM_DBF_TEXT_(ERROR, CTC_DBF_WARN, "irb error %ld on device %s\n",
287 PTR_ERR(irb), cdev->dev.bus_id);
289 switch (PTR_ERR(irb)) {
291 ctcm_pr_warn("i/o-error on device %s\n", cdev->dev.bus_id);
294 ctcm_pr_warn("timeout on device %s\n", cdev->dev.bus_id);
297 ctcm_pr_warn("unknown error %ld on device %s\n",
298 PTR_ERR(irb), cdev->dev.bus_id);
305 * Check sense of a unit check.
307 * ch The channel, the sense code belongs to.
308 * sense The sense code to inspect.
310 static inline void ccw_unit_check(struct channel *ch, unsigned char sense)
312 CTCM_DBF_TEXT(TRACE, 5, __FUNCTION__);
313 if (sense & SNS0_INTERVENTION_REQ) {
315 ctcm_pr_debug("%s: Interface disc. or Sel. reset "
316 "(remote)\n", ch->id);
317 fsm_event(ch->fsm, CTC_EVENT_UC_RCRESET, ch);
319 ctcm_pr_debug("%s: System reset (remote)\n", ch->id);
320 fsm_event(ch->fsm, CTC_EVENT_UC_RSRESET, ch);
322 } else if (sense & SNS0_EQUIPMENT_CHECK) {
323 if (sense & SNS0_BUS_OUT_CHECK) {
324 ctcm_pr_warn("%s: Hardware malfunction (remote)\n",
326 fsm_event(ch->fsm, CTC_EVENT_UC_HWFAIL, ch);
328 ctcm_pr_warn("%s: Read-data parity error (remote)\n",
330 fsm_event(ch->fsm, CTC_EVENT_UC_RXPARITY, ch);
332 } else if (sense & SNS0_BUS_OUT_CHECK) {
334 ctcm_pr_warn("%s: Data-streaming timeout)\n", ch->id);
335 fsm_event(ch->fsm, CTC_EVENT_UC_TXTIMEOUT, ch);
337 ctcm_pr_warn("%s: Data-transfer parity error\n",
339 fsm_event(ch->fsm, CTC_EVENT_UC_TXPARITY, ch);
341 } else if (sense & SNS0_CMD_REJECT) {
342 ctcm_pr_warn("%s: Command reject\n", ch->id);
343 } else if (sense == 0) {
344 ctcm_pr_debug("%s: Unit check ZERO\n", ch->id);
345 fsm_event(ch->fsm, CTC_EVENT_UC_ZERO, ch);
347 ctcm_pr_warn("%s: Unit Check with sense code: %02x\n",
349 fsm_event(ch->fsm, CTC_EVENT_UC_UNKNOWN, ch);
353 int ctcm_ch_alloc_buffer(struct channel *ch)
355 CTCM_DBF_TEXT(TRACE, 5, __FUNCTION__);
357 clear_normalized_cda(&ch->ccw[1]);
358 ch->trans_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC | GFP_DMA);
359 if (ch->trans_skb == NULL) {
360 ctcm_pr_warn("%s: Couldn't alloc %s trans_skb\n",
362 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
366 ch->ccw[1].count = ch->max_bufsize;
367 if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
368 dev_kfree_skb(ch->trans_skb);
369 ch->trans_skb = NULL;
370 ctcm_pr_warn("%s: set_normalized_cda for %s "
371 "trans_skb failed, dropping packets\n",
373 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
377 ch->ccw[1].count = 0;
378 ch->trans_skb_data = ch->trans_skb->data;
379 ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
384 * Interface API for upper network layers
389 * Called from generic network layer when ifconfig up is run.
391 * dev Pointer to interface struct.
393 * returns 0 on success, -ERRNO on failure. (Never fails.)
395 int ctcm_open(struct net_device *dev)
397 struct ctcm_priv *priv = dev->priv;
399 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
401 fsm_event(priv->fsm, DEV_EVENT_START, dev);
406 * Close an interface.
407 * Called from generic network layer when ifconfig down is run.
409 * dev Pointer to interface struct.
411 * returns 0 on success, -ERRNO on failure. (Never fails.)
413 int ctcm_close(struct net_device *dev)
415 struct ctcm_priv *priv = dev->priv;
417 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
419 fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
426 * This is a helper function for ctcm_tx().
428 * ch Channel to be used for sending.
429 * skb Pointer to struct sk_buff of packet to send.
430 * The linklevel header has already been set up
433 * returns 0 on success, -ERRNO on failure. (Never fails.)
435 static int ctcm_transmit_skb(struct channel *ch, struct sk_buff *skb)
437 unsigned long saveflags;
438 struct ll_header header;
442 struct sk_buff *nskb;
445 /* we need to acquire the lock for testing the state
446 * otherwise we can have an IRQ changing the state to
447 * TXIDLE after the test but before acquiring the lock.
449 spin_lock_irqsave(&ch->collect_lock, saveflags);
450 if (fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) {
451 int l = skb->len + LL_HEADER_LENGTH;
453 if (ch->collect_len + l > ch->max_bufsize - 2) {
454 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
457 atomic_inc(&skb->users);
459 header.type = skb->protocol;
461 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
463 skb_queue_tail(&ch->collect_queue, skb);
464 ch->collect_len += l;
466 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
469 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
471 * Protect skb against beeing free'd by upper
474 atomic_inc(&skb->users);
475 ch->prof.txlen += skb->len;
476 header.length = skb->len + LL_HEADER_LENGTH;
477 header.type = skb->protocol;
479 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header, LL_HEADER_LENGTH);
480 block_len = skb->len + 2;
481 *((__u16 *)skb_push(skb, 2)) = block_len;
484 * IDAL support in CTCM is broken, so we have to
485 * care about skb's above 2G ourselves.
487 hi = ((unsigned long)skb_tail_pointer(skb) + LL_HEADER_LENGTH) >> 31;
489 nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
491 atomic_dec(&skb->users);
492 skb_pull(skb, LL_HEADER_LENGTH + 2);
493 ctcm_clear_busy(ch->netdev);
496 memcpy(skb_put(nskb, skb->len), skb->data, skb->len);
497 atomic_inc(&nskb->users);
498 atomic_dec(&skb->users);
499 dev_kfree_skb_irq(skb);
504 ch->ccw[4].count = block_len;
505 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
507 * idal allocation failed, try via copying to
508 * trans_skb. trans_skb usually has a pre-allocated
511 if (ctcm_checkalloc_buffer(ch)) {
513 * Remove our header. It gets added
514 * again on retransmit.
516 atomic_dec(&skb->users);
517 skb_pull(skb, LL_HEADER_LENGTH + 2);
518 ctcm_clear_busy(ch->netdev);
522 skb_reset_tail_pointer(ch->trans_skb);
523 ch->trans_skb->len = 0;
524 ch->ccw[1].count = skb->len;
525 skb_copy_from_linear_data(skb,
526 skb_put(ch->trans_skb, skb->len), skb->len);
527 atomic_dec(&skb->users);
528 dev_kfree_skb_irq(skb);
531 skb_queue_tail(&ch->io_queue, skb);
535 fsm_newstate(ch->fsm, CTC_STATE_TX);
536 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
537 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
538 ch->prof.send_stamp = current_kernel_time(); /* xtime */
539 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
540 (unsigned long)ch, 0xff, 0);
541 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
543 ch->prof.doios_single++;
545 fsm_deltimer(&ch->timer);
546 ctcm_ccw_check_rc(ch, rc, "single skb TX");
548 skb_dequeue_tail(&ch->io_queue);
550 * Remove our header. It gets added
551 * again on retransmit.
553 skb_pull(skb, LL_HEADER_LENGTH + 2);
554 } else if (ccw_idx == 0) {
555 struct net_device *dev = ch->netdev;
556 struct ctcm_priv *priv = dev->priv;
557 priv->stats.tx_packets++;
558 priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
561 ctcm_clear_busy(ch->netdev);
565 static void ctcmpc_send_sweep_req(struct channel *rch)
567 struct net_device *dev = rch->netdev;
568 struct ctcm_priv *priv;
569 struct mpc_group *grp;
570 struct th_sweep *header;
571 struct sk_buff *sweep_skb;
577 ch = priv->channel[WRITE];
580 MPC_DBF_DEV_NAME(TRACE, dev, ch->id);
582 /* sweep processing is not complete until response and request */
583 /* has completed for all read channels in group */
584 if (grp->in_sweep == 0) {
586 grp->sweep_rsp_pend_num = grp->active_channels[READ];
587 grp->sweep_req_pend_num = grp->active_channels[READ];
590 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
592 if (sweep_skb == NULL) {
593 printk(KERN_INFO "Couldn't alloc sweep_skb\n");
598 header = kmalloc(TH_SWEEP_LENGTH, gfp_type());
601 dev_kfree_skb_any(sweep_skb);
606 header->th.th_seg = 0x00 ;
607 header->th.th_ch_flag = TH_SWEEP_REQ; /* 0x0f */
608 header->th.th_blk_flag = 0x00;
609 header->th.th_is_xid = 0x00;
610 header->th.th_seq_num = 0x00;
611 header->sw.th_last_seq = ch->th_seq_num;
613 memcpy(skb_put(sweep_skb, TH_SWEEP_LENGTH), header, TH_SWEEP_LENGTH);
617 dev->trans_start = jiffies;
618 skb_queue_tail(&ch->sweep_queue, sweep_skb);
620 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
627 ctcm_clear_busy(dev);
628 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
635 * MPC mode version of transmit_skb
637 static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
639 struct pdu *p_header;
640 struct net_device *dev = ch->netdev;
641 struct ctcm_priv *priv = dev->priv;
642 struct mpc_group *grp = priv->mpcg;
643 struct th_header *header;
644 struct sk_buff *nskb;
648 unsigned long saveflags = 0; /* avoids compiler warning */
653 "ctcm enter: %s(): %s cp=%i ch=0x%p id=%s state=%s\n",
654 __FUNCTION__, dev->name, smp_processor_id(), ch,
655 ch->id, fsm_getstate_str(ch->fsm));
657 if ((fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) || grp->in_sweep) {
658 spin_lock_irqsave(&ch->collect_lock, saveflags);
659 atomic_inc(&skb->users);
660 p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
663 printk(KERN_WARNING "ctcm: OUT OF MEMORY IN %s():"
664 " Data Lost \n", __FUNCTION__);
666 atomic_dec(&skb->users);
667 dev_kfree_skb_any(skb);
668 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
669 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
673 p_header->pdu_offset = skb->len;
674 p_header->pdu_proto = 0x01;
675 p_header->pdu_flag = 0x00;
676 if (skb->protocol == ntohs(ETH_P_SNAP)) {
677 p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
679 p_header->pdu_flag |= PDU_FIRST;
681 p_header->pdu_seq = 0;
682 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header,
686 ctcm_pr_debug("ctcm: %s() Putting on collect_q"
687 " - skb len: %04x \n", __FUNCTION__, skb->len);
688 ctcm_pr_debug("ctcm: %s() pdu header and data"
689 " for up to 32 bytes\n", __FUNCTION__);
690 ctcmpc_dump32((char *)skb->data, skb->len);
693 skb_queue_tail(&ch->collect_queue, skb);
694 ch->collect_len += skb->len;
697 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
702 * Protect skb against beeing free'd by upper
705 atomic_inc(&skb->users);
707 block_len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
709 * IDAL support in CTCM is broken, so we have to
710 * care about skb's above 2G ourselves.
712 hi = ((unsigned long)skb->tail + TH_HEADER_LENGTH) >> 31;
714 nskb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
716 printk(KERN_WARNING "ctcm: %s() OUT OF MEMORY"
717 "- Data Lost \n", __FUNCTION__);
718 atomic_dec(&skb->users);
719 dev_kfree_skb_any(skb);
720 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
723 memcpy(skb_put(nskb, skb->len), skb->data, skb->len);
724 atomic_inc(&nskb->users);
725 atomic_dec(&skb->users);
726 dev_kfree_skb_irq(skb);
731 p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
734 printk(KERN_WARNING "ctcm: %s() OUT OF MEMORY"
735 ": Data Lost \n", __FUNCTION__);
737 atomic_dec(&skb->users);
738 dev_kfree_skb_any(skb);
739 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
743 p_header->pdu_offset = skb->len;
744 p_header->pdu_proto = 0x01;
745 p_header->pdu_flag = 0x00;
746 p_header->pdu_seq = 0;
747 if (skb->protocol == ntohs(ETH_P_SNAP)) {
748 p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
750 p_header->pdu_flag |= PDU_FIRST;
752 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, PDU_HEADER_LENGTH);
756 if (ch->collect_len > 0) {
757 spin_lock_irqsave(&ch->collect_lock, saveflags);
758 skb_queue_tail(&ch->collect_queue, skb);
759 ch->collect_len += skb->len;
760 skb = skb_dequeue(&ch->collect_queue);
761 ch->collect_len -= skb->len;
762 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
765 p_header = (struct pdu *)skb->data;
766 p_header->pdu_flag |= PDU_LAST;
768 ch->prof.txlen += skb->len - PDU_HEADER_LENGTH;
770 header = kmalloc(TH_HEADER_LENGTH, gfp_type());
773 printk(KERN_WARNING "ctcm: %s() OUT OF MEMORY: Data Lost \n",
775 atomic_dec(&skb->users);
776 dev_kfree_skb_any(skb);
777 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
781 header->th_seg = 0x00;
782 header->th_ch_flag = TH_HAS_PDU; /* Normal data */
783 header->th_blk_flag = 0x00;
784 header->th_is_xid = 0x00; /* Just data here */
786 header->th_seq_num = ch->th_seq_num;
789 ctcm_pr_debug("ctcm: %s() ToVTAM_th_seq= %08x\n" ,
790 __FUNCTION__, ch->th_seq_num);
792 /* put the TH on the packet */
793 memcpy(skb_push(skb, TH_HEADER_LENGTH), header, TH_HEADER_LENGTH);
798 ctcm_pr_debug("ctcm: %s(): skb len: %04x \n",
799 __FUNCTION__, skb->len);
800 ctcm_pr_debug("ctcm: %s(): pdu header and data for up to 32 "
801 "bytes sent to vtam\n", __FUNCTION__);
802 ctcmpc_dump32((char *)skb->data, skb->len);
805 ch->ccw[4].count = skb->len;
806 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
808 * idal allocation failed, try via copying to
809 * trans_skb. trans_skb usually has a pre-allocated
812 if (ctcm_checkalloc_buffer(ch)) {
814 * Remove our header. It gets added
815 * again on retransmit.
817 atomic_dec(&skb->users);
818 dev_kfree_skb_any(skb);
819 printk(KERN_WARNING "ctcm: %s()OUT OF MEMORY:"
820 " Data Lost \n", __FUNCTION__);
821 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
825 skb_reset_tail_pointer(ch->trans_skb);
826 ch->trans_skb->len = 0;
827 ch->ccw[1].count = skb->len;
828 memcpy(skb_put(ch->trans_skb, skb->len), skb->data, skb->len);
829 atomic_dec(&skb->users);
830 dev_kfree_skb_irq(skb);
833 ctcm_pr_debug("ctcm: %s() TRANS skb len: %d \n",
834 __FUNCTION__, ch->trans_skb->len);
835 ctcm_pr_debug("ctcm: %s up to 32 bytes of data"
836 " sent to vtam\n", __FUNCTION__);
837 ctcmpc_dump32((char *)ch->trans_skb->data,
841 skb_queue_tail(&ch->io_queue, skb);
845 fsm_newstate(ch->fsm, CTC_STATE_TX);
846 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
849 ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
850 sizeof(struct ccw1) * 3);
852 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
853 ch->prof.send_stamp = current_kernel_time(); /* xtime */
854 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
855 (unsigned long)ch, 0xff, 0);
856 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
858 ch->prof.doios_single++;
860 fsm_deltimer(&ch->timer);
861 ctcm_ccw_check_rc(ch, rc, "single skb TX");
863 skb_dequeue_tail(&ch->io_queue);
864 } else if (ccw_idx == 0) {
865 priv->stats.tx_packets++;
866 priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
868 if (ch->th_seq_num > 0xf0000000) /* Chose 4Billion at random. */
869 ctcmpc_send_sweep_req(ch);
873 ctcm_pr_debug("ctcm exit: %s %s()\n", dev->name, __FUNCTION__);
878 * Start transmission of a packet.
879 * Called from generic network device layer.
881 * skb Pointer to buffer containing the packet.
882 * dev Pointer to interface struct.
884 * returns 0 if packet consumed, !0 if packet rejected.
885 * Note: If we return !0, then the packet is free'd by
886 * the generic network layer.
888 /* first merge version - leaving both functions separated */
889 static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
892 struct ctcm_priv *priv;
894 CTCM_DBF_TEXT(TRACE, 5, __FUNCTION__);
898 ctcm_pr_warn("%s: NULL sk_buff passed\n", dev->name);
899 priv->stats.tx_dropped++;
902 if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
903 ctcm_pr_warn("%s: Got sk_buff with head room < %ld bytes\n",
904 dev->name, LL_HEADER_LENGTH + 2);
906 priv->stats.tx_dropped++;
911 * If channels are not running, try to restart them
912 * and throw away packet.
914 if (fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) {
915 fsm_event(priv->fsm, DEV_EVENT_START, dev);
917 priv->stats.tx_dropped++;
918 priv->stats.tx_errors++;
919 priv->stats.tx_carrier_errors++;
923 if (ctcm_test_and_set_busy(dev))
926 dev->trans_start = jiffies;
927 if (ctcm_transmit_skb(priv->channel[WRITE], skb) != 0)
932 /* unmerged MPC variant of ctcm_tx */
933 static int ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
936 struct ctcm_priv *priv = NULL;
937 struct mpc_group *grp = NULL;
938 struct sk_buff *newskb = NULL;
941 ctcm_pr_debug("ctcmpc enter: %s(): skb:%0lx\n",
942 __FUNCTION__, (unsigned long)skb);
944 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
945 "ctcmpc enter: %s(): skb:%0lx\n",
946 __FUNCTION__, (unsigned long)skb);
951 * Some sanity checks ...
954 ctcm_pr_warn("ctcmpc: %s: NULL sk_buff passed\n", dev->name);
955 priv->stats.tx_dropped++;
958 if (skb_headroom(skb) < (TH_HEADER_LENGTH + PDU_HEADER_LENGTH)) {
959 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_WARN,
960 "%s: Got sk_buff with head room < %ld bytes\n",
961 dev->name, TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
964 ctcmpc_dump32((char *)skb->data, skb->len);
966 len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
967 newskb = __dev_alloc_skb(len, gfp_type() | GFP_DMA);
970 printk(KERN_WARNING "ctcmpc: %s() OUT OF MEMORY-"
974 dev_kfree_skb_any(skb);
975 priv->stats.tx_dropped++;
976 priv->stats.tx_errors++;
977 priv->stats.tx_carrier_errors++;
978 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
981 newskb->protocol = skb->protocol;
982 skb_reserve(newskb, TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
983 memcpy(skb_put(newskb, skb->len), skb->data, skb->len);
984 dev_kfree_skb_any(skb);
989 * If channels are not running,
990 * notify anybody about a link failure and throw
993 if ((fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) ||
994 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
995 dev_kfree_skb_any(skb);
996 printk(KERN_INFO "ctcmpc: %s() DATA RCVD - MPC GROUP "
997 "NOT ACTIVE - DROPPED\n",
999 priv->stats.tx_dropped++;
1000 priv->stats.tx_errors++;
1001 priv->stats.tx_carrier_errors++;
1005 if (ctcm_test_and_set_busy(dev)) {
1006 printk(KERN_WARNING "%s:DEVICE ERR - UNRECOVERABLE DATA LOSS\n",
1008 dev_kfree_skb_any(skb);
1009 priv->stats.tx_dropped++;
1010 priv->stats.tx_errors++;
1011 priv->stats.tx_carrier_errors++;
1012 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1016 dev->trans_start = jiffies;
1017 if (ctcmpc_transmit_skb(priv->channel[WRITE], skb) != 0) {
1018 printk(KERN_WARNING "ctcmpc: %s() DEVICE ERROR"
1021 printk(KERN_WARNING "ctcmpc: %s() DEVICE ERROR"
1022 " - UNRECOVERABLE DATA LOSS\n",
1024 dev_kfree_skb_any(skb);
1025 priv->stats.tx_dropped++;
1026 priv->stats.tx_errors++;
1027 priv->stats.tx_carrier_errors++;
1028 ctcm_clear_busy(dev);
1029 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1032 ctcm_clear_busy(dev);
1035 MPC_DBF_DEV_NAME(TRACE, dev, "exit");
1037 return 0; /* handle freeing of skb here */
1042 * Sets MTU of an interface.
1044 * dev Pointer to interface struct.
1045 * new_mtu The new MTU to use for this interface.
1047 * returns 0 on success, -EINVAL if MTU is out of valid range.
1048 * (valid range is 576 .. 65527). If VM is on the
1049 * remote side, maximum MTU is 32760, however this is
1052 static int ctcm_change_mtu(struct net_device *dev, int new_mtu)
1054 struct ctcm_priv *priv;
1057 CTCM_DBF_TEXT(SETUP, CTC_DBF_INFO, __FUNCTION__);
1059 if (new_mtu < 576 || new_mtu > 65527)
1063 max_bufsize = priv->channel[READ]->max_bufsize;
1066 if (new_mtu > max_bufsize - TH_HEADER_LENGTH)
1068 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1070 if (new_mtu > max_bufsize - LL_HEADER_LENGTH - 2)
1072 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1079 * Returns interface statistics of a device.
1081 * dev Pointer to interface struct.
1083 * returns Pointer to stats struct of this interface.
1085 static struct net_device_stats *ctcm_stats(struct net_device *dev)
1087 return &((struct ctcm_priv *)dev->priv)->stats;
1091 static void ctcm_netdev_unregister(struct net_device *dev)
1093 CTCM_DBF_TEXT(SETUP, CTC_DBF_INFO, __FUNCTION__);
1096 unregister_netdev(dev);
1099 static int ctcm_netdev_register(struct net_device *dev)
1101 CTCM_DBF_TEXT(SETUP, CTC_DBF_INFO, __FUNCTION__);
1102 return register_netdev(dev);
1105 static void ctcm_free_netdevice(struct net_device *dev)
1107 struct ctcm_priv *priv;
1108 struct mpc_group *grp;
1110 CTCM_DBF_TEXT(SETUP, CTC_DBF_INFO, __FUNCTION__);
1119 kfree_fsm(grp->fsm);
1121 dev_kfree_skb(grp->xid_skb);
1122 if (grp->rcvd_xid_skb)
1123 dev_kfree_skb(grp->rcvd_xid_skb);
1124 tasklet_kill(&grp->mpc_tasklet2);
1129 kfree_fsm(priv->fsm);
1135 * Note: kfree(priv); is done in "opposite" function of
1136 * allocator function probe_device which is remove_device.
1144 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
1146 void static ctcm_dev_setup(struct net_device *dev)
1148 dev->open = ctcm_open;
1149 dev->stop = ctcm_close;
1150 dev->get_stats = ctcm_stats;
1151 dev->change_mtu = ctcm_change_mtu;
1152 dev->type = ARPHRD_SLIP;
1153 dev->tx_queue_len = 100;
1154 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1158 * Initialize everything of the net device except the name and the
1161 static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv)
1163 struct net_device *dev;
1164 struct mpc_group *grp;
1169 dev = alloc_netdev(0, MPC_DEVICE_GENE, ctcm_dev_setup);
1171 dev = alloc_netdev(0, CTC_DEVICE_GENE, ctcm_dev_setup);
1174 ctcm_pr_err("%s: Out of memory\n", __FUNCTION__);
1178 priv->fsm = init_fsm("ctcmdev", dev_state_names, dev_event_names,
1179 CTCM_NR_DEV_STATES, CTCM_NR_DEV_EVENTS,
1180 dev_fsm, dev_fsm_len, GFP_KERNEL);
1181 if (priv->fsm == NULL) {
1182 CTCMY_DBF_DEV(SETUP, dev, "init_fsm error");
1186 fsm_newstate(priv->fsm, DEV_STATE_STOPPED);
1187 fsm_settimer(priv->fsm, &priv->restart_timer);
1190 /* MPC Group Initializations */
1191 grp = ctcmpc_init_mpc_group(priv);
1193 MPC_DBF_DEV(SETUP, dev, "init_mpc_group error");
1197 tasklet_init(&grp->mpc_tasklet2,
1198 mpc_group_ready, (unsigned long)dev);
1199 dev->mtu = MPC_BUFSIZE_DEFAULT -
1200 TH_HEADER_LENGTH - PDU_HEADER_LENGTH;
1202 dev->hard_start_xmit = ctcmpc_tx;
1203 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1204 priv->buffer_size = MPC_BUFSIZE_DEFAULT;
1206 dev->mtu = CTCM_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
1207 dev->hard_start_xmit = ctcm_tx;
1208 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1211 CTCMY_DBF_DEV(SETUP, dev, "finished");
1218 * cdev The ccw_device the interrupt is for.
1219 * intparm interruption parameter.
1220 * irb interruption response block.
1222 static void ctcm_irq_handler(struct ccw_device *cdev,
1223 unsigned long intparm, struct irb *irb)
1226 struct net_device *dev;
1227 struct ctcm_priv *priv;
1228 struct ccwgroup_device *cgdev;
1230 CTCM_DBF_TEXT(TRACE, CTC_DBF_DEBUG, __FUNCTION__);
1231 if (ctcm_check_irb_error(cdev, irb))
1234 cgdev = dev_get_drvdata(&cdev->dev);
1236 /* Check for unsolicited interrupts. */
1237 if (cgdev == NULL) {
1238 ctcm_pr_warn("ctcm: Got unsolicited irq: %s c-%02x d-%02x\n",
1239 cdev->dev.bus_id, irb->scsw.cstat,
1244 priv = dev_get_drvdata(&cgdev->dev);
1246 /* Try to extract channel from driver data. */
1247 if (priv->channel[READ]->cdev == cdev)
1248 ch = priv->channel[READ];
1249 else if (priv->channel[WRITE]->cdev == cdev)
1250 ch = priv->channel[WRITE];
1252 ctcm_pr_err("ctcm: Can't determine channel for interrupt, "
1253 "device %s\n", cdev->dev.bus_id);
1257 dev = (struct net_device *)(ch->netdev);
1259 ctcm_pr_crit("ctcm: %s dev=NULL bus_id=%s, ch=0x%p\n",
1260 __FUNCTION__, cdev->dev.bus_id, ch);
1265 ctcm_pr_debug("%s: interrupt for device: %s "
1266 "received c-%02x d-%02x\n",
1272 /* Copy interruption response block. */
1273 memcpy(ch->irb, irb, sizeof(struct irb));
1275 /* Check for good subchannel return code, otherwise error message */
1276 if (irb->scsw.cstat) {
1277 fsm_event(ch->fsm, CTC_EVENT_SC_UNKNOWN, ch);
1278 ctcm_pr_warn("%s: subchannel check for dev: %s - %02x %02x\n",
1279 dev->name, ch->id, irb->scsw.cstat,
1284 /* Check the reason-code of a unit check */
1285 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
1286 ccw_unit_check(ch, irb->ecw[0]);
1289 if (irb->scsw.dstat & DEV_STAT_BUSY) {
1290 if (irb->scsw.dstat & DEV_STAT_ATTENTION)
1291 fsm_event(ch->fsm, CTC_EVENT_ATTNBUSY, ch);
1293 fsm_event(ch->fsm, CTC_EVENT_BUSY, ch);
1296 if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
1297 fsm_event(ch->fsm, CTC_EVENT_ATTN, ch);
1300 if ((irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
1301 (irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
1303 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
1304 fsm_event(ch->fsm, CTC_EVENT_FINSTAT, ch);
1306 fsm_event(ch->fsm, CTC_EVENT_IRQ, ch);
1311 * Add ctcm specific attributes.
1312 * Add ctcm private data.
1314 * cgdev pointer to ccwgroup_device just added
1316 * returns 0 on success, !0 on failure.
1318 static int ctcm_probe_device(struct ccwgroup_device *cgdev)
1320 struct ctcm_priv *priv;
1323 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s %p", __FUNCTION__, cgdev);
1325 if (!get_device(&cgdev->dev))
1328 priv = kzalloc(sizeof(struct ctcm_priv), GFP_KERNEL);
1330 ctcm_pr_err("%s: Out of memory\n", __FUNCTION__);
1331 put_device(&cgdev->dev);
1335 rc = ctcm_add_files(&cgdev->dev);
1338 put_device(&cgdev->dev);
1341 priv->buffer_size = CTCM_BUFSIZE_DEFAULT;
1342 cgdev->cdev[0]->handler = ctcm_irq_handler;
1343 cgdev->cdev[1]->handler = ctcm_irq_handler;
1344 dev_set_drvdata(&cgdev->dev, priv);
1350 * Add a new channel to the list of channels.
1351 * Keeps the channel list sorted.
1353 * cdev The ccw_device to be added.
1354 * type The type class of the new channel.
1355 * priv Points to the private data of the ccwgroup_device.
1357 * returns 0 on success, !0 on error.
1359 static int add_channel(struct ccw_device *cdev, enum channel_types type,
1360 struct ctcm_priv *priv)
1362 struct channel **c = &channels;
1367 CTCM_DBF_TEXT(TRACE, 2, __FUNCTION__);
1368 ch = kzalloc(sizeof(struct channel), GFP_KERNEL);
1372 ch->protocol = priv->protocol;
1374 ch->discontact_th = (struct th_header *)
1375 kzalloc(TH_HEADER_LENGTH, gfp_type());
1376 if (ch->discontact_th == NULL)
1379 ch->discontact_th->th_blk_flag = TH_DISCONTACT;
1380 tasklet_init(&ch->ch_disc_tasklet,
1381 mpc_action_send_discontact, (unsigned long)ch);
1383 tasklet_init(&ch->ch_tasklet, ctcmpc_bh, (unsigned long)ch);
1384 ch->max_bufsize = (MPC_BUFSIZE_DEFAULT - 35);
1389 ch->ccw = (struct ccw1 *)
1390 kzalloc(ccw_num * sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
1391 if (ch->ccw == NULL)
1395 snprintf(ch->id, CTCM_ID_SIZE, "ch-%s", cdev->dev.bus_id);
1399 * "static" ccws are used in the following way:
1401 * ccw[0..2] (Channel program for generic I/O):
1403 * 1: read or write (depending on direction) with fixed
1404 * buffer (idal allocated once when buffer is allocated)
1406 * ccw[3..5] (Channel program for direct write of packets)
1408 * 4: write (idal allocated on every write).
1410 * ccw[6..7] (Channel program for initial channel setup):
1411 * 6: set extended mode
1414 * ch->ccw[0..5] are initialized in ch_action_start because
1415 * the channel's direction is yet unknown here.
1417 * ccws used for xid2 negotiations
1418 * ch-ccw[8-14] need to be used for the XID exchange either
1419 * X side XID2 Processing
1423 * 11: read th from secondary
1424 * 12: read XID from secondary
1425 * 13: read 4 byte ID
1427 * Y side XID Processing
1433 * 13: write 4 byte ID
1436 * ccws used for double noop due to VM timing issues
1437 * which result in unrecoverable Busy on channel
1441 ch->ccw[6].cmd_code = CCW_CMD_SET_EXTENDED;
1442 ch->ccw[6].flags = CCW_FLAG_SLI;
1444 ch->ccw[7].cmd_code = CCW_CMD_NOOP;
1445 ch->ccw[7].flags = CCW_FLAG_SLI;
1448 ch->ccw[15].cmd_code = CCW_CMD_WRITE;
1449 ch->ccw[15].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1450 ch->ccw[15].count = TH_HEADER_LENGTH;
1451 ch->ccw[15].cda = virt_to_phys(ch->discontact_th);
1453 ch->ccw[16].cmd_code = CCW_CMD_NOOP;
1454 ch->ccw[16].flags = CCW_FLAG_SLI;
1456 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1457 ctc_ch_event_names, CTC_MPC_NR_STATES,
1458 CTC_MPC_NR_EVENTS, ctcmpc_ch_fsm,
1459 mpc_ch_fsm_len, GFP_KERNEL);
1461 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1462 ctc_ch_event_names, CTC_NR_STATES,
1463 CTC_NR_EVENTS, ch_fsm,
1464 ch_fsm_len, GFP_KERNEL);
1466 if (ch->fsm == NULL)
1469 fsm_newstate(ch->fsm, CTC_STATE_IDLE);
1471 ch->irb = kzalloc(sizeof(struct irb), GFP_KERNEL);
1472 if (ch->irb == NULL)
1475 while (*c && ctcm_less_than((*c)->id, ch->id))
1478 if (*c && (!strncmp((*c)->id, ch->id, CTCM_ID_SIZE))) {
1479 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1480 "%s (%s) already in list, using old entry",
1481 __FUNCTION__, (*c)->id);
1486 spin_lock_init(&ch->collect_lock);
1488 fsm_settimer(ch->fsm, &ch->timer);
1489 skb_queue_head_init(&ch->io_queue);
1490 skb_queue_head_init(&ch->collect_queue);
1493 fsm_settimer(ch->fsm, &ch->sweep_timer);
1494 skb_queue_head_init(&ch->sweep_queue);
1501 ctcm_pr_warn("ctcm: Out of memory in %s\n", __FUNCTION__);
1504 free_return: /* note that all channel pointers are 0 or valid */
1505 kfree(ch->ccw); /* TODO: check that again */
1506 kfree(ch->discontact_th);
1514 * Return type of a detected device.
1516 static enum channel_types get_channel_type(struct ccw_device_id *id)
1518 enum channel_types type;
1519 type = (enum channel_types)id->driver_info;
1521 if (type == channel_type_ficon)
1522 type = channel_type_escon;
1529 * Setup an interface.
1531 * cgdev Device to be setup.
1533 * returns 0 on success, !0 on failure.
1535 static int ctcm_new_device(struct ccwgroup_device *cgdev)
1537 char read_id[CTCM_ID_SIZE];
1538 char write_id[CTCM_ID_SIZE];
1540 enum channel_types type;
1541 struct ctcm_priv *priv;
1542 struct net_device *dev;
1545 CTCM_DBF_TEXT(SETUP, CTC_DBF_INFO, __FUNCTION__);
1547 priv = dev_get_drvdata(&cgdev->dev);
1551 type = get_channel_type(&cgdev->cdev[0]->id);
1553 snprintf(read_id, CTCM_ID_SIZE, "ch-%s", cgdev->cdev[0]->dev.bus_id);
1554 snprintf(write_id, CTCM_ID_SIZE, "ch-%s", cgdev->cdev[1]->dev.bus_id);
1556 ret = add_channel(cgdev->cdev[0], type, priv);
1559 ret = add_channel(cgdev->cdev[1], type, priv);
1563 ret = ccw_device_set_online(cgdev->cdev[0]);
1565 CTCM_DBF_TEXT(SETUP, CTC_DBF_WARN,
1566 "ccw_device_set_online (cdev[0]) failed ");
1567 ctcm_pr_warn("ccw_device_set_online (cdev[0]) failed "
1568 "with ret = %d\n", ret);
1571 ret = ccw_device_set_online(cgdev->cdev[1]);
1573 CTCM_DBF_TEXT(SETUP, CTC_DBF_WARN,
1574 "ccw_device_set_online (cdev[1]) failed ");
1575 ctcm_pr_warn("ccw_device_set_online (cdev[1]) failed "
1576 "with ret = %d\n", ret);
1579 dev = ctcm_init_netdevice(priv);
1582 ctcm_pr_warn("ctcm_init_netdevice failed\n");
1586 for (direction = READ; direction <= WRITE; direction++) {
1587 priv->channel[direction] =
1588 channel_get(type, direction == READ ? read_id : write_id,
1590 if (priv->channel[direction] == NULL) {
1591 if (direction == WRITE)
1592 channel_free(priv->channel[READ]);
1593 ctcm_free_netdevice(dev);
1596 priv->channel[direction]->netdev = dev;
1597 priv->channel[direction]->protocol = priv->protocol;
1598 priv->channel[direction]->max_bufsize = priv->buffer_size;
1601 SET_NETDEV_DEV(dev, &cgdev->dev);
1603 if (ctcm_netdev_register(dev) != 0) {
1604 ctcm_free_netdevice(dev);
1608 if (ctcm_add_attributes(&cgdev->dev)) {
1609 ctcm_netdev_unregister(dev);
1610 /* dev->priv = NULL; why that ???? */
1611 ctcm_free_netdevice(dev);
1615 strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name));
1617 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1618 "setup(%s) ok : r/w = %s / %s, proto : %d",
1619 dev->name, priv->channel[READ]->id,
1620 priv->channel[WRITE]->id, priv->protocol);
1624 ccw_device_set_offline(cgdev->cdev[1]);
1625 ccw_device_set_offline(cgdev->cdev[0]);
1631 * Shutdown an interface.
1633 * cgdev Device to be shut down.
1635 * returns 0 on success, !0 on failure.
1637 static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1639 struct ctcm_priv *priv;
1640 struct net_device *dev;
1642 priv = dev_get_drvdata(&cgdev->dev);
1646 if (priv->channel[READ]) {
1647 dev = priv->channel[READ]->netdev;
1648 CTCM_DBF_DEV(SETUP, dev, "");
1649 /* Close the device */
1651 dev->flags &= ~IFF_RUNNING;
1652 ctcm_remove_attributes(&cgdev->dev);
1653 channel_free(priv->channel[READ]);
1657 if (priv->channel[WRITE])
1658 channel_free(priv->channel[WRITE]);
1661 ctcm_netdev_unregister(dev);
1662 /* dev->priv = NULL; why that ??? */
1663 ctcm_free_netdevice(dev);
1667 kfree_fsm(priv->fsm);
1669 ccw_device_set_offline(cgdev->cdev[1]);
1670 ccw_device_set_offline(cgdev->cdev[0]);
1672 if (priv->channel[READ])
1673 channel_remove(priv->channel[READ]);
1674 if (priv->channel[WRITE])
1675 channel_remove(priv->channel[WRITE]);
1676 priv->channel[READ] = priv->channel[WRITE] = NULL;
1683 static void ctcm_remove_device(struct ccwgroup_device *cgdev)
1685 struct ctcm_priv *priv;
1687 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, __FUNCTION__);
1689 priv = dev_get_drvdata(&cgdev->dev);
1692 if (cgdev->state == CCWGROUP_ONLINE)
1693 ctcm_shutdown_device(cgdev);
1694 ctcm_remove_files(&cgdev->dev);
1695 dev_set_drvdata(&cgdev->dev, NULL);
1697 put_device(&cgdev->dev);
1700 static struct ccwgroup_driver ctcm_group_driver = {
1701 .owner = THIS_MODULE,
1702 .name = CTC_DRIVER_NAME,
1704 .driver_id = 0xC3E3C3D4, /* CTCM */
1705 .probe = ctcm_probe_device,
1706 .remove = ctcm_remove_device,
1707 .set_online = ctcm_new_device,
1708 .set_offline = ctcm_shutdown_device,
1713 * Module related routines
1717 * Prepare to be unloaded. Free IRQ's and release all resources.
1718 * This is called just before this module is unloaded. It is
1719 * not called, if the usage count is !0, so we don't need to check
1722 static void __exit ctcm_exit(void)
1724 unregister_cu3088_discipline(&ctcm_group_driver);
1725 ctcm_unregister_dbf_views();
1726 ctcm_pr_info("CTCM driver unloaded\n");
1732 static void print_banner(void)
1734 printk(KERN_INFO "CTCM driver initialized\n");
1738 * Initialize module.
1739 * This is called just after the module is loaded.
1741 * returns 0 on success, !0 on error.
1743 static int __init ctcm_init(void)
1749 ret = ctcm_register_dbf_views();
1751 ctcm_pr_crit("ctcm_init failed with ctcm_register_dbf_views "
1755 ret = register_cu3088_discipline(&ctcm_group_driver);
1757 ctcm_unregister_dbf_views();
1758 ctcm_pr_crit("ctcm_init failed with register_cu3088_discipline "
1759 "(rc = %d)\n", ret);
1766 module_init(ctcm_init);
1767 module_exit(ctcm_exit);
1769 MODULE_AUTHOR("Peter Tiedemann <ptiedem@de.ibm.com>");
1770 MODULE_DESCRIPTION("Network driver for S/390 CTC + CTCMPC (SNA)");
1771 MODULE_LICENSE("GPL");