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->ml_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)) {
87 if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
88 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_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
96 "%s(%s): Illegal packet type 0x%04x"
98 CTCM_FUNTAIL, dev->name, header->type);
100 priv->stats.rx_dropped++;
101 priv->stats.rx_frame_errors++;
104 pskb->protocol = ntohs(header->type);
105 if (header->length <= LL_HEADER_LENGTH) {
106 if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
107 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
108 "%s(%s): Illegal packet size %d(%d,%d)"
110 CTCM_FUNTAIL, dev->name,
111 header->length, dev->mtu, len);
112 ch->logflags |= LOG_FLAG_ILLEGALSIZE;
115 priv->stats.rx_dropped++;
116 priv->stats.rx_length_errors++;
119 header->length -= LL_HEADER_LENGTH;
120 len -= LL_HEADER_LENGTH;
121 if ((header->length > skb_tailroom(pskb)) ||
122 (header->length > len)) {
123 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
124 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
125 "%s(%s): Packet size %d (overrun)"
126 " - dropping", CTCM_FUNTAIL,
127 dev->name, header->length);
128 ch->logflags |= LOG_FLAG_OVERRUN;
131 priv->stats.rx_dropped++;
132 priv->stats.rx_length_errors++;
135 skb_put(pskb, header->length);
136 skb_reset_mac_header(pskb);
137 len -= header->length;
138 skb = dev_alloc_skb(pskb->len);
140 if (!(ch->logflags & LOG_FLAG_NOMEM)) {
141 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
142 "%s(%s): MEMORY allocation error",
143 CTCM_FUNTAIL, dev->name);
144 ch->logflags |= LOG_FLAG_NOMEM;
146 priv->stats.rx_dropped++;
149 skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len),
151 skb_reset_mac_header(skb);
152 skb->dev = pskb->dev;
153 skb->protocol = pskb->protocol;
154 pskb->ip_summed = CHECKSUM_UNNECESSARY;
160 priv->stats.rx_packets++;
161 priv->stats.rx_bytes += skblen;
163 dev->last_rx = jiffies;
165 skb_pull(pskb, header->length);
166 if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
167 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
168 CTCM_DBF_DEV_NAME(TRACE, dev,
169 "Overrun in ctcm_unpack_skb");
170 ch->logflags |= LOG_FLAG_OVERRUN;
174 skb_put(pskb, LL_HEADER_LENGTH);
180 * Release a specific channel in the channel list.
182 * ch Pointer to channel struct to be released.
184 static void channel_free(struct channel *ch)
186 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s)", CTCM_FUNTAIL, ch->id);
187 ch->flags &= ~CHANNEL_FLAGS_INUSE;
188 fsm_newstate(ch->fsm, CTC_STATE_IDLE);
192 * Remove a specific channel in the channel list.
194 * ch Pointer to channel struct to be released.
196 static void channel_remove(struct channel *ch)
198 struct channel **c = &channels;
199 char chid[CTCM_ID_SIZE+1];
205 strncpy(chid, ch->id, CTCM_ID_SIZE);
211 fsm_deltimer(&ch->timer);
213 fsm_deltimer(&ch->sweep_timer);
216 clear_normalized_cda(&ch->ccw[4]);
217 if (ch->trans_skb != NULL) {
218 clear_normalized_cda(&ch->ccw[1]);
219 dev_kfree_skb_any(ch->trans_skb);
222 tasklet_kill(&ch->ch_tasklet);
223 tasklet_kill(&ch->ch_disc_tasklet);
224 kfree(ch->discontact_th);
235 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s) %s", CTCM_FUNTAIL,
236 chid, ok ? "OK" : "failed");
240 * Get a specific channel from the channel list.
242 * type Type of channel we are interested in.
243 * id Id of channel we are interested in.
244 * direction Direction we want to use this channel for.
246 * returns Pointer to a channel or NULL if no matching channel available.
248 static struct channel *channel_get(enum channel_types type,
249 char *id, int direction)
251 struct channel *ch = channels;
253 while (ch && (strncmp(ch->id, id, CTCM_ID_SIZE) || (ch->type != type)))
256 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
257 "%s(%d, %s, %d) not found in channel list\n",
258 CTCM_FUNTAIL, type, id, direction);
260 if (ch->flags & CHANNEL_FLAGS_INUSE)
263 ch->flags |= CHANNEL_FLAGS_INUSE;
264 ch->flags &= ~CHANNEL_FLAGS_RWMASK;
265 ch->flags |= (direction == WRITE)
266 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
267 fsm_newstate(ch->fsm, CTC_STATE_STOPPED);
273 static long ctcm_check_irb_error(struct ccw_device *cdev, struct irb *irb)
278 CTCM_DBF_TEXT_(ERROR, CTC_DBF_WARN,
279 "irb error %ld on device %s\n",
280 PTR_ERR(irb), dev_name(&cdev->dev));
282 switch (PTR_ERR(irb)) {
284 ctcm_pr_warn("i/o-error on device %s\n", dev_name(&cdev->dev));
287 ctcm_pr_warn("timeout on device %s\n", dev_name(&cdev->dev));
290 ctcm_pr_warn("unknown error %ld on device %s\n",
291 PTR_ERR(irb), dev_name(&cdev->dev));
298 * Check sense of a unit check.
300 * ch The channel, the sense code belongs to.
301 * sense The sense code to inspect.
303 static inline void ccw_unit_check(struct channel *ch, __u8 sense)
305 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
307 CTCM_FUNTAIL, ch->id, sense);
309 if (sense & SNS0_INTERVENTION_REQ) {
311 if (ch->sense_rc != 0x01) {
312 ctcm_pr_debug("%s: Interface disc. or Sel. "
313 "reset (remote)\n", ch->id);
316 fsm_event(ch->fsm, CTC_EVENT_UC_RCRESET, ch);
318 if (ch->sense_rc != SNS0_INTERVENTION_REQ) {
319 ctcm_pr_debug("%s: System reset (remote)\n",
321 ch->sense_rc = SNS0_INTERVENTION_REQ;
323 fsm_event(ch->fsm, CTC_EVENT_UC_RSRESET, ch);
325 } else if (sense & SNS0_EQUIPMENT_CHECK) {
326 if (sense & SNS0_BUS_OUT_CHECK) {
327 if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
328 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
329 "%s(%s): remote HW error %02x",
330 CTCM_FUNTAIL, ch->id, sense);
331 ch->sense_rc = SNS0_BUS_OUT_CHECK;
333 fsm_event(ch->fsm, CTC_EVENT_UC_HWFAIL, ch);
335 if (ch->sense_rc != SNS0_EQUIPMENT_CHECK) {
336 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
337 "%s(%s): remote read parity error %02x",
338 CTCM_FUNTAIL, ch->id, sense);
339 ch->sense_rc = SNS0_EQUIPMENT_CHECK;
341 fsm_event(ch->fsm, CTC_EVENT_UC_RXPARITY, ch);
343 } else if (sense & SNS0_BUS_OUT_CHECK) {
344 if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
345 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
346 "%s(%s): BUS OUT error %02x",
347 CTCM_FUNTAIL, ch->id, sense);
348 ch->sense_rc = SNS0_BUS_OUT_CHECK;
350 if (sense & 0x04) /* data-streaming timeout */
351 fsm_event(ch->fsm, CTC_EVENT_UC_TXTIMEOUT, ch);
352 else /* Data-transfer parity error */
353 fsm_event(ch->fsm, CTC_EVENT_UC_TXPARITY, ch);
354 } else if (sense & SNS0_CMD_REJECT) {
355 if (ch->sense_rc != SNS0_CMD_REJECT) {
356 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
357 "%s(%s): Command rejected",
358 CTCM_FUNTAIL, ch->id);
359 ch->sense_rc = SNS0_CMD_REJECT;
361 } else if (sense == 0) {
362 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
363 "%s(%s): Unit check ZERO",
364 CTCM_FUNTAIL, ch->id);
365 fsm_event(ch->fsm, CTC_EVENT_UC_ZERO, ch);
367 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
368 "%s(%s): Unit check code %02x unknown",
369 CTCM_FUNTAIL, ch->id, sense);
370 fsm_event(ch->fsm, CTC_EVENT_UC_UNKNOWN, ch);
374 int ctcm_ch_alloc_buffer(struct channel *ch)
376 clear_normalized_cda(&ch->ccw[1]);
377 ch->trans_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC | GFP_DMA);
378 if (ch->trans_skb == NULL) {
379 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
380 "%s(%s): %s trans_skb allocation error",
381 CTCM_FUNTAIL, ch->id,
382 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
386 ch->ccw[1].count = ch->max_bufsize;
387 if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
388 dev_kfree_skb(ch->trans_skb);
389 ch->trans_skb = NULL;
390 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
391 "%s(%s): %s set norm_cda failed",
392 CTCM_FUNTAIL, ch->id,
393 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX");
397 ch->ccw[1].count = 0;
398 ch->trans_skb_data = ch->trans_skb->data;
399 ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
404 * Interface API for upper network layers
409 * Called from generic network layer when ifconfig up is run.
411 * dev Pointer to interface struct.
413 * returns 0 on success, -ERRNO on failure. (Never fails.)
415 int ctcm_open(struct net_device *dev)
417 struct ctcm_priv *priv = dev->ml_priv;
419 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
421 fsm_event(priv->fsm, DEV_EVENT_START, dev);
426 * Close an interface.
427 * Called from generic network layer when ifconfig down is run.
429 * dev Pointer to interface struct.
431 * returns 0 on success, -ERRNO on failure. (Never fails.)
433 int ctcm_close(struct net_device *dev)
435 struct ctcm_priv *priv = dev->ml_priv;
437 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
439 fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
446 * This is a helper function for ctcm_tx().
448 * ch Channel to be used for sending.
449 * skb Pointer to struct sk_buff of packet to send.
450 * The linklevel header has already been set up
453 * returns 0 on success, -ERRNO on failure. (Never fails.)
455 static int ctcm_transmit_skb(struct channel *ch, struct sk_buff *skb)
457 unsigned long saveflags;
458 struct ll_header header;
462 struct sk_buff *nskb;
465 /* we need to acquire the lock for testing the state
466 * otherwise we can have an IRQ changing the state to
467 * TXIDLE after the test but before acquiring the lock.
469 spin_lock_irqsave(&ch->collect_lock, saveflags);
470 if (fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) {
471 int l = skb->len + LL_HEADER_LENGTH;
473 if (ch->collect_len + l > ch->max_bufsize - 2) {
474 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
477 atomic_inc(&skb->users);
479 header.type = skb->protocol;
481 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
483 skb_queue_tail(&ch->collect_queue, skb);
484 ch->collect_len += l;
486 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
489 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
491 * Protect skb against beeing free'd by upper
494 atomic_inc(&skb->users);
495 ch->prof.txlen += skb->len;
496 header.length = skb->len + LL_HEADER_LENGTH;
497 header.type = skb->protocol;
499 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header, LL_HEADER_LENGTH);
500 block_len = skb->len + 2;
501 *((__u16 *)skb_push(skb, 2)) = block_len;
504 * IDAL support in CTCM is broken, so we have to
505 * care about skb's above 2G ourselves.
507 hi = ((unsigned long)skb_tail_pointer(skb) + LL_HEADER_LENGTH) >> 31;
509 nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
511 atomic_dec(&skb->users);
512 skb_pull(skb, LL_HEADER_LENGTH + 2);
513 ctcm_clear_busy(ch->netdev);
516 memcpy(skb_put(nskb, skb->len), skb->data, skb->len);
517 atomic_inc(&nskb->users);
518 atomic_dec(&skb->users);
519 dev_kfree_skb_irq(skb);
524 ch->ccw[4].count = block_len;
525 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
527 * idal allocation failed, try via copying to
528 * trans_skb. trans_skb usually has a pre-allocated
531 if (ctcm_checkalloc_buffer(ch)) {
533 * Remove our header. It gets added
534 * again on retransmit.
536 atomic_dec(&skb->users);
537 skb_pull(skb, LL_HEADER_LENGTH + 2);
538 ctcm_clear_busy(ch->netdev);
542 skb_reset_tail_pointer(ch->trans_skb);
543 ch->trans_skb->len = 0;
544 ch->ccw[1].count = skb->len;
545 skb_copy_from_linear_data(skb,
546 skb_put(ch->trans_skb, skb->len), skb->len);
547 atomic_dec(&skb->users);
548 dev_kfree_skb_irq(skb);
551 skb_queue_tail(&ch->io_queue, skb);
555 fsm_newstate(ch->fsm, CTC_STATE_TX);
556 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
557 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
558 ch->prof.send_stamp = current_kernel_time(); /* xtime */
559 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
560 (unsigned long)ch, 0xff, 0);
561 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
563 ch->prof.doios_single++;
565 fsm_deltimer(&ch->timer);
566 ctcm_ccw_check_rc(ch, rc, "single skb TX");
568 skb_dequeue_tail(&ch->io_queue);
570 * Remove our header. It gets added
571 * again on retransmit.
573 skb_pull(skb, LL_HEADER_LENGTH + 2);
574 } else if (ccw_idx == 0) {
575 struct net_device *dev = ch->netdev;
576 struct ctcm_priv *priv = dev->ml_priv;
577 priv->stats.tx_packets++;
578 priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
581 ctcm_clear_busy(ch->netdev);
585 static void ctcmpc_send_sweep_req(struct channel *rch)
587 struct net_device *dev = rch->netdev;
588 struct ctcm_priv *priv;
589 struct mpc_group *grp;
590 struct th_sweep *header;
591 struct sk_buff *sweep_skb;
597 ch = priv->channel[WRITE];
599 /* sweep processing is not complete until response and request */
600 /* has completed for all read channels in group */
601 if (grp->in_sweep == 0) {
603 grp->sweep_rsp_pend_num = grp->active_channels[READ];
604 grp->sweep_req_pend_num = grp->active_channels[READ];
607 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
609 if (sweep_skb == NULL) {
614 header = kmalloc(TH_SWEEP_LENGTH, gfp_type());
617 dev_kfree_skb_any(sweep_skb);
622 header->th.th_seg = 0x00 ;
623 header->th.th_ch_flag = TH_SWEEP_REQ; /* 0x0f */
624 header->th.th_blk_flag = 0x00;
625 header->th.th_is_xid = 0x00;
626 header->th.th_seq_num = 0x00;
627 header->sw.th_last_seq = ch->th_seq_num;
629 memcpy(skb_put(sweep_skb, TH_SWEEP_LENGTH), header, TH_SWEEP_LENGTH);
633 dev->trans_start = jiffies;
634 skb_queue_tail(&ch->sweep_queue, sweep_skb);
636 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
642 ctcm_clear_busy(dev);
643 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
649 * MPC mode version of transmit_skb
651 static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
653 struct pdu *p_header;
654 struct net_device *dev = ch->netdev;
655 struct ctcm_priv *priv = dev->ml_priv;
656 struct mpc_group *grp = priv->mpcg;
657 struct th_header *header;
658 struct sk_buff *nskb;
662 unsigned long saveflags = 0; /* avoids compiler warning */
665 CTCM_PR_DEBUG("Enter %s: %s, cp=%i ch=0x%p id=%s state=%s\n",
666 __func__, dev->name, smp_processor_id(), ch,
667 ch->id, fsm_getstate_str(ch->fsm));
669 if ((fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) || grp->in_sweep) {
670 spin_lock_irqsave(&ch->collect_lock, saveflags);
671 atomic_inc(&skb->users);
672 p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
675 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
679 p_header->pdu_offset = skb->len;
680 p_header->pdu_proto = 0x01;
681 p_header->pdu_flag = 0x00;
682 if (skb->protocol == ntohs(ETH_P_SNAP)) {
683 p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
685 p_header->pdu_flag |= PDU_FIRST;
687 p_header->pdu_seq = 0;
688 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header,
691 CTCM_PR_DEBUG("%s(%s): Put on collect_q - skb len: %04x \n"
692 "pdu header and data for up to 32 bytes:\n",
693 __func__, dev->name, skb->len);
694 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
696 skb_queue_tail(&ch->collect_queue, skb);
697 ch->collect_len += skb->len;
700 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
705 * Protect skb against beeing free'd by upper
708 atomic_inc(&skb->users);
710 block_len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
712 * IDAL support in CTCM is broken, so we have to
713 * care about skb's above 2G ourselves.
715 hi = ((unsigned long)skb->tail + TH_HEADER_LENGTH) >> 31;
717 nskb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
721 memcpy(skb_put(nskb, skb->len), skb->data, skb->len);
722 atomic_inc(&nskb->users);
723 atomic_dec(&skb->users);
724 dev_kfree_skb_irq(skb);
729 p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
734 p_header->pdu_offset = skb->len;
735 p_header->pdu_proto = 0x01;
736 p_header->pdu_flag = 0x00;
737 p_header->pdu_seq = 0;
738 if (skb->protocol == ntohs(ETH_P_SNAP)) {
739 p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
741 p_header->pdu_flag |= PDU_FIRST;
743 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, PDU_HEADER_LENGTH);
747 if (ch->collect_len > 0) {
748 spin_lock_irqsave(&ch->collect_lock, saveflags);
749 skb_queue_tail(&ch->collect_queue, skb);
750 ch->collect_len += skb->len;
751 skb = skb_dequeue(&ch->collect_queue);
752 ch->collect_len -= skb->len;
753 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
756 p_header = (struct pdu *)skb->data;
757 p_header->pdu_flag |= PDU_LAST;
759 ch->prof.txlen += skb->len - PDU_HEADER_LENGTH;
761 header = kmalloc(TH_HEADER_LENGTH, gfp_type());
765 header->th_seg = 0x00;
766 header->th_ch_flag = TH_HAS_PDU; /* Normal data */
767 header->th_blk_flag = 0x00;
768 header->th_is_xid = 0x00; /* Just data here */
770 header->th_seq_num = ch->th_seq_num;
772 CTCM_PR_DBGDATA("%s(%s) ToVTAM_th_seq= %08x\n" ,
773 __func__, dev->name, ch->th_seq_num);
775 /* put the TH on the packet */
776 memcpy(skb_push(skb, TH_HEADER_LENGTH), header, TH_HEADER_LENGTH);
780 CTCM_PR_DBGDATA("%s(%s): skb len: %04x\n - pdu header and data for "
781 "up to 32 bytes sent to vtam:\n",
782 __func__, dev->name, skb->len);
783 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
785 ch->ccw[4].count = skb->len;
786 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
788 * idal allocation failed, try via copying to trans_skb.
789 * trans_skb usually has a pre-allocated idal.
791 if (ctcm_checkalloc_buffer(ch)) {
794 * It gets added again on retransmit.
799 skb_reset_tail_pointer(ch->trans_skb);
800 ch->trans_skb->len = 0;
801 ch->ccw[1].count = skb->len;
802 memcpy(skb_put(ch->trans_skb, skb->len), skb->data, skb->len);
803 atomic_dec(&skb->users);
804 dev_kfree_skb_irq(skb);
806 CTCM_PR_DBGDATA("%s(%s): trans_skb len: %04x\n"
807 "up to 32 bytes sent to vtam:\n",
808 __func__, dev->name, ch->trans_skb->len);
809 CTCM_D3_DUMP((char *)ch->trans_skb->data,
810 min_t(int, 32, ch->trans_skb->len));
812 skb_queue_tail(&ch->io_queue, skb);
816 fsm_newstate(ch->fsm, CTC_STATE_TX);
817 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
820 ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
821 sizeof(struct ccw1) * 3);
823 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
824 ch->prof.send_stamp = current_kernel_time(); /* xtime */
825 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
826 (unsigned long)ch, 0xff, 0);
827 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
829 ch->prof.doios_single++;
831 fsm_deltimer(&ch->timer);
832 ctcm_ccw_check_rc(ch, rc, "single skb TX");
834 skb_dequeue_tail(&ch->io_queue);
835 } else if (ccw_idx == 0) {
836 priv->stats.tx_packets++;
837 priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
839 if (ch->th_seq_num > 0xf0000000) /* Chose at random. */
840 ctcmpc_send_sweep_req(ch);
844 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_CRIT,
845 "%s(%s): MEMORY allocation ERROR\n",
846 CTCM_FUNTAIL, ch->id);
848 atomic_dec(&skb->users);
849 dev_kfree_skb_any(skb);
850 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
852 CTCM_PR_DEBUG("Exit %s(%s)\n", __func__, dev->name);
857 * Start transmission of a packet.
858 * Called from generic network device layer.
860 * skb Pointer to buffer containing the packet.
861 * dev Pointer to interface struct.
863 * returns 0 if packet consumed, !0 if packet rejected.
864 * Note: If we return !0, then the packet is free'd by
865 * the generic network layer.
867 /* first merge version - leaving both functions separated */
868 static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
870 struct ctcm_priv *priv = dev->ml_priv;
873 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
874 "%s(%s): NULL sk_buff passed",
875 CTCM_FUNTAIL, dev->name);
876 priv->stats.tx_dropped++;
879 if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
880 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
881 "%s(%s): Got sk_buff with head room < %ld bytes",
882 CTCM_FUNTAIL, dev->name, LL_HEADER_LENGTH + 2);
884 priv->stats.tx_dropped++;
889 * If channels are not running, try to restart them
890 * and throw away packet.
892 if (fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) {
893 fsm_event(priv->fsm, DEV_EVENT_START, dev);
895 priv->stats.tx_dropped++;
896 priv->stats.tx_errors++;
897 priv->stats.tx_carrier_errors++;
901 if (ctcm_test_and_set_busy(dev))
904 dev->trans_start = jiffies;
905 if (ctcm_transmit_skb(priv->channel[WRITE], skb) != 0)
910 /* unmerged MPC variant of ctcm_tx */
911 static int ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
914 struct ctcm_priv *priv = dev->ml_priv;
915 struct mpc_group *grp = priv->mpcg;
916 struct sk_buff *newskb = NULL;
919 * Some sanity checks ...
922 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
923 "%s(%s): NULL sk_buff passed",
924 CTCM_FUNTAIL, dev->name);
925 priv->stats.tx_dropped++;
928 if (skb_headroom(skb) < (TH_HEADER_LENGTH + PDU_HEADER_LENGTH)) {
929 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
930 "%s(%s): Got sk_buff with head room < %ld bytes",
931 CTCM_FUNTAIL, dev->name,
932 TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
934 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
936 len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
937 newskb = __dev_alloc_skb(len, gfp_type() | GFP_DMA);
940 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
941 "%s: %s: __dev_alloc_skb failed",
942 __func__, dev->name);
944 dev_kfree_skb_any(skb);
945 priv->stats.tx_dropped++;
946 priv->stats.tx_errors++;
947 priv->stats.tx_carrier_errors++;
948 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
951 newskb->protocol = skb->protocol;
952 skb_reserve(newskb, TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
953 memcpy(skb_put(newskb, skb->len), skb->data, skb->len);
954 dev_kfree_skb_any(skb);
959 * If channels are not running,
960 * notify anybody about a link failure and throw
963 if ((fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) ||
964 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
965 dev_kfree_skb_any(skb);
966 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
967 "%s(%s): inactive MPCGROUP - dropped",
968 CTCM_FUNTAIL, dev->name);
969 priv->stats.tx_dropped++;
970 priv->stats.tx_errors++;
971 priv->stats.tx_carrier_errors++;
975 if (ctcm_test_and_set_busy(dev)) {
976 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
977 "%s(%s): device busy - dropped",
978 CTCM_FUNTAIL, dev->name);
979 dev_kfree_skb_any(skb);
980 priv->stats.tx_dropped++;
981 priv->stats.tx_errors++;
982 priv->stats.tx_carrier_errors++;
983 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
987 dev->trans_start = jiffies;
988 if (ctcmpc_transmit_skb(priv->channel[WRITE], skb) != 0) {
989 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
990 "%s(%s): device error - dropped",
991 CTCM_FUNTAIL, dev->name);
992 dev_kfree_skb_any(skb);
993 priv->stats.tx_dropped++;
994 priv->stats.tx_errors++;
995 priv->stats.tx_carrier_errors++;
996 ctcm_clear_busy(dev);
997 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1000 ctcm_clear_busy(dev);
1003 MPC_DBF_DEV_NAME(TRACE, dev, "exit");
1005 return 0; /* handle freeing of skb here */
1010 * Sets MTU of an interface.
1012 * dev Pointer to interface struct.
1013 * new_mtu The new MTU to use for this interface.
1015 * returns 0 on success, -EINVAL if MTU is out of valid range.
1016 * (valid range is 576 .. 65527). If VM is on the
1017 * remote side, maximum MTU is 32760, however this is
1020 static int ctcm_change_mtu(struct net_device *dev, int new_mtu)
1022 struct ctcm_priv *priv;
1025 if (new_mtu < 576 || new_mtu > 65527)
1028 priv = dev->ml_priv;
1029 max_bufsize = priv->channel[READ]->max_bufsize;
1032 if (new_mtu > max_bufsize - TH_HEADER_LENGTH)
1034 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1036 if (new_mtu > max_bufsize - LL_HEADER_LENGTH - 2)
1038 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1045 * Returns interface statistics of a device.
1047 * dev Pointer to interface struct.
1049 * returns Pointer to stats struct of this interface.
1051 static struct net_device_stats *ctcm_stats(struct net_device *dev)
1053 return &((struct ctcm_priv *)dev->ml_priv)->stats;
1056 static void ctcm_free_netdevice(struct net_device *dev)
1058 struct ctcm_priv *priv;
1059 struct mpc_group *grp;
1061 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1062 "%s(%s)", CTCM_FUNTAIL, dev->name);
1063 priv = dev->ml_priv;
1068 kfree_fsm(grp->fsm);
1070 dev_kfree_skb(grp->xid_skb);
1071 if (grp->rcvd_xid_skb)
1072 dev_kfree_skb(grp->rcvd_xid_skb);
1073 tasklet_kill(&grp->mpc_tasklet2);
1078 kfree_fsm(priv->fsm);
1084 * Note: kfree(priv); is done in "opposite" function of
1085 * allocator function probe_device which is remove_device.
1093 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
1095 void static ctcm_dev_setup(struct net_device *dev)
1097 dev->open = ctcm_open;
1098 dev->stop = ctcm_close;
1099 dev->get_stats = ctcm_stats;
1100 dev->change_mtu = ctcm_change_mtu;
1101 dev->type = ARPHRD_SLIP;
1102 dev->tx_queue_len = 100;
1103 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1107 * Initialize everything of the net device except the name and the
1110 static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv)
1112 struct net_device *dev;
1113 struct mpc_group *grp;
1118 dev = alloc_netdev(0, MPC_DEVICE_GENE, ctcm_dev_setup);
1120 dev = alloc_netdev(0, CTC_DEVICE_GENE, ctcm_dev_setup);
1123 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
1124 "%s: MEMORY allocation ERROR",
1128 dev->ml_priv = priv;
1129 priv->fsm = init_fsm("ctcmdev", dev_state_names, dev_event_names,
1130 CTCM_NR_DEV_STATES, CTCM_NR_DEV_EVENTS,
1131 dev_fsm, dev_fsm_len, GFP_KERNEL);
1132 if (priv->fsm == NULL) {
1133 CTCMY_DBF_DEV(SETUP, dev, "init_fsm error");
1137 fsm_newstate(priv->fsm, DEV_STATE_STOPPED);
1138 fsm_settimer(priv->fsm, &priv->restart_timer);
1141 /* MPC Group Initializations */
1142 grp = ctcmpc_init_mpc_group(priv);
1144 MPC_DBF_DEV(SETUP, dev, "init_mpc_group error");
1148 tasklet_init(&grp->mpc_tasklet2,
1149 mpc_group_ready, (unsigned long)dev);
1150 dev->mtu = MPC_BUFSIZE_DEFAULT -
1151 TH_HEADER_LENGTH - PDU_HEADER_LENGTH;
1153 dev->hard_start_xmit = ctcmpc_tx;
1154 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1155 priv->buffer_size = MPC_BUFSIZE_DEFAULT;
1157 dev->mtu = CTCM_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
1158 dev->hard_start_xmit = ctcm_tx;
1159 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1162 CTCMY_DBF_DEV(SETUP, dev, "finished");
1170 * cdev The ccw_device the interrupt is for.
1171 * intparm interruption parameter.
1172 * irb interruption response block.
1174 static void ctcm_irq_handler(struct ccw_device *cdev,
1175 unsigned long intparm, struct irb *irb)
1178 struct net_device *dev;
1179 struct ctcm_priv *priv;
1180 struct ccwgroup_device *cgdev;
1184 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
1185 "Enter %s(%s)", CTCM_FUNTAIL, dev_name(&cdev->dev));
1187 if (ctcm_check_irb_error(cdev, irb))
1190 cgdev = dev_get_drvdata(&cdev->dev);
1192 cstat = irb->scsw.cmd.cstat;
1193 dstat = irb->scsw.cmd.dstat;
1195 /* Check for unsolicited interrupts. */
1196 if (cgdev == NULL) {
1197 ctcm_pr_warn("ctcm: Got unsolicited irq: c-%02x d-%02x\n",
1202 priv = dev_get_drvdata(&cgdev->dev);
1204 /* Try to extract channel from driver data. */
1205 if (priv->channel[READ]->cdev == cdev)
1206 ch = priv->channel[READ];
1207 else if (priv->channel[WRITE]->cdev == cdev)
1208 ch = priv->channel[WRITE];
1210 ctcm_pr_err("ctcm: Can't determine channel for interrupt, "
1211 "device %s\n", dev_name(&cdev->dev));
1217 ctcm_pr_crit("ctcm: %s dev=NULL bus_id=%s, ch=0x%p\n",
1218 __func__, dev_name(&cdev->dev), ch);
1222 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
1223 "%s(%s): int. for %s: cstat=%02x dstat=%02x",
1224 CTCM_FUNTAIL, dev->name, ch->id, cstat, dstat);
1226 /* Copy interruption response block. */
1227 memcpy(ch->irb, irb, sizeof(struct irb));
1229 if (irb->scsw.cmd.cstat) {
1230 /* Check for good subchannel return code, otherwise error message */
1231 fsm_event(ch->fsm, CTC_EVENT_SC_UNKNOWN, ch);
1232 ctcm_pr_warn("%s: subchannel check for dev: %s - %02x %02x\n",
1233 dev->name, ch->id, irb->scsw.cmd.cstat,
1234 irb->scsw.cmd.dstat);
1238 /* Check the reason-code of a unit check */
1239 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
1240 if ((irb->ecw[0] & ch->sense_rc) == 0)
1241 /* print it only once */
1242 CTCM_DBF_TEXT_(TRACE, CTC_DBF_INFO,
1243 "%s(%s): sense=%02x, ds=%02x",
1244 CTCM_FUNTAIL, ch->id, irb->ecw[0], dstat);
1245 ccw_unit_check(ch, irb->ecw[0]);
1248 if (irb->scsw.cmd.dstat & DEV_STAT_BUSY) {
1249 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION)
1250 fsm_event(ch->fsm, CTC_EVENT_ATTNBUSY, ch);
1252 fsm_event(ch->fsm, CTC_EVENT_BUSY, ch);
1255 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
1256 fsm_event(ch->fsm, CTC_EVENT_ATTN, ch);
1259 if ((irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
1260 (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
1261 (irb->scsw.cmd.stctl ==
1262 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
1263 fsm_event(ch->fsm, CTC_EVENT_FINSTAT, ch);
1265 fsm_event(ch->fsm, CTC_EVENT_IRQ, ch);
1270 * Add ctcm specific attributes.
1271 * Add ctcm private data.
1273 * cgdev pointer to ccwgroup_device just added
1275 * returns 0 on success, !0 on failure.
1277 static int ctcm_probe_device(struct ccwgroup_device *cgdev)
1279 struct ctcm_priv *priv;
1282 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1286 if (!get_device(&cgdev->dev))
1289 priv = kzalloc(sizeof(struct ctcm_priv), GFP_KERNEL);
1291 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
1292 "%s: memory allocation failure",
1294 put_device(&cgdev->dev);
1298 rc = ctcm_add_files(&cgdev->dev);
1301 put_device(&cgdev->dev);
1304 priv->buffer_size = CTCM_BUFSIZE_DEFAULT;
1305 cgdev->cdev[0]->handler = ctcm_irq_handler;
1306 cgdev->cdev[1]->handler = ctcm_irq_handler;
1307 dev_set_drvdata(&cgdev->dev, priv);
1313 * Add a new channel to the list of channels.
1314 * Keeps the channel list sorted.
1316 * cdev The ccw_device to be added.
1317 * type The type class of the new channel.
1318 * priv Points to the private data of the ccwgroup_device.
1320 * returns 0 on success, !0 on error.
1322 static int add_channel(struct ccw_device *cdev, enum channel_types type,
1323 struct ctcm_priv *priv)
1325 struct channel **c = &channels;
1330 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1331 "%s(%s), type %d, proto %d",
1332 __func__, dev_name(&cdev->dev), type, priv->protocol);
1334 ch = kzalloc(sizeof(struct channel), GFP_KERNEL);
1338 ch->protocol = priv->protocol;
1340 ch->discontact_th = (struct th_header *)
1341 kzalloc(TH_HEADER_LENGTH, gfp_type());
1342 if (ch->discontact_th == NULL)
1345 ch->discontact_th->th_blk_flag = TH_DISCONTACT;
1346 tasklet_init(&ch->ch_disc_tasklet,
1347 mpc_action_send_discontact, (unsigned long)ch);
1349 tasklet_init(&ch->ch_tasklet, ctcmpc_bh, (unsigned long)ch);
1350 ch->max_bufsize = (MPC_BUFSIZE_DEFAULT - 35);
1355 ch->ccw = (struct ccw1 *)
1356 kzalloc(ccw_num * sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
1357 if (ch->ccw == NULL)
1361 snprintf(ch->id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev->dev));
1365 * "static" ccws are used in the following way:
1367 * ccw[0..2] (Channel program for generic I/O):
1369 * 1: read or write (depending on direction) with fixed
1370 * buffer (idal allocated once when buffer is allocated)
1372 * ccw[3..5] (Channel program for direct write of packets)
1374 * 4: write (idal allocated on every write).
1376 * ccw[6..7] (Channel program for initial channel setup):
1377 * 6: set extended mode
1380 * ch->ccw[0..5] are initialized in ch_action_start because
1381 * the channel's direction is yet unknown here.
1383 * ccws used for xid2 negotiations
1384 * ch-ccw[8-14] need to be used for the XID exchange either
1385 * X side XID2 Processing
1389 * 11: read th from secondary
1390 * 12: read XID from secondary
1391 * 13: read 4 byte ID
1393 * Y side XID Processing
1399 * 13: write 4 byte ID
1402 * ccws used for double noop due to VM timing issues
1403 * which result in unrecoverable Busy on channel
1407 ch->ccw[6].cmd_code = CCW_CMD_SET_EXTENDED;
1408 ch->ccw[6].flags = CCW_FLAG_SLI;
1410 ch->ccw[7].cmd_code = CCW_CMD_NOOP;
1411 ch->ccw[7].flags = CCW_FLAG_SLI;
1414 ch->ccw[15].cmd_code = CCW_CMD_WRITE;
1415 ch->ccw[15].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1416 ch->ccw[15].count = TH_HEADER_LENGTH;
1417 ch->ccw[15].cda = virt_to_phys(ch->discontact_th);
1419 ch->ccw[16].cmd_code = CCW_CMD_NOOP;
1420 ch->ccw[16].flags = CCW_FLAG_SLI;
1422 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1423 ctc_ch_event_names, CTC_MPC_NR_STATES,
1424 CTC_MPC_NR_EVENTS, ctcmpc_ch_fsm,
1425 mpc_ch_fsm_len, GFP_KERNEL);
1427 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1428 ctc_ch_event_names, CTC_NR_STATES,
1429 CTC_NR_EVENTS, ch_fsm,
1430 ch_fsm_len, GFP_KERNEL);
1432 if (ch->fsm == NULL)
1435 fsm_newstate(ch->fsm, CTC_STATE_IDLE);
1437 ch->irb = kzalloc(sizeof(struct irb), GFP_KERNEL);
1438 if (ch->irb == NULL)
1441 while (*c && ctcm_less_than((*c)->id, ch->id))
1444 if (*c && (!strncmp((*c)->id, ch->id, CTCM_ID_SIZE))) {
1445 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1446 "%s (%s) already in list, using old entry",
1447 __func__, (*c)->id);
1452 spin_lock_init(&ch->collect_lock);
1454 fsm_settimer(ch->fsm, &ch->timer);
1455 skb_queue_head_init(&ch->io_queue);
1456 skb_queue_head_init(&ch->collect_queue);
1459 fsm_settimer(ch->fsm, &ch->sweep_timer);
1460 skb_queue_head_init(&ch->sweep_queue);
1469 free_return: /* note that all channel pointers are 0 or valid */
1471 kfree(ch->discontact_th);
1479 * Return type of a detected device.
1481 static enum channel_types get_channel_type(struct ccw_device_id *id)
1483 enum channel_types type;
1484 type = (enum channel_types)id->driver_info;
1486 if (type == channel_type_ficon)
1487 type = channel_type_escon;
1494 * Setup an interface.
1496 * cgdev Device to be setup.
1498 * returns 0 on success, !0 on failure.
1500 static int ctcm_new_device(struct ccwgroup_device *cgdev)
1502 char read_id[CTCM_ID_SIZE];
1503 char write_id[CTCM_ID_SIZE];
1505 enum channel_types type;
1506 struct ctcm_priv *priv;
1507 struct net_device *dev;
1508 struct ccw_device *cdev0;
1509 struct ccw_device *cdev1;
1512 priv = dev_get_drvdata(&cgdev->dev);
1516 cdev0 = cgdev->cdev[0];
1517 cdev1 = cgdev->cdev[1];
1519 type = get_channel_type(&cdev0->id);
1521 snprintf(read_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev0->dev));
1522 snprintf(write_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev1->dev));
1524 ret = add_channel(cdev0, type, priv);
1527 ret = add_channel(cdev1, type, priv);
1531 ret = ccw_device_set_online(cdev0);
1533 /* may be ok to fail now - can be done later */
1534 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
1535 "%s(%s) set_online rc=%d",
1536 CTCM_FUNTAIL, read_id, ret);
1539 ret = ccw_device_set_online(cdev1);
1541 /* may be ok to fail now - can be done later */
1542 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
1543 "%s(%s) set_online rc=%d",
1544 CTCM_FUNTAIL, write_id, ret);
1547 dev = ctcm_init_netdevice(priv);
1551 for (direction = READ; direction <= WRITE; direction++) {
1552 priv->channel[direction] =
1553 channel_get(type, direction == READ ? read_id : write_id,
1555 if (priv->channel[direction] == NULL) {
1556 if (direction == WRITE)
1557 channel_free(priv->channel[READ]);
1560 priv->channel[direction]->netdev = dev;
1561 priv->channel[direction]->protocol = priv->protocol;
1562 priv->channel[direction]->max_bufsize = priv->buffer_size;
1565 SET_NETDEV_DEV(dev, &cgdev->dev);
1567 if (register_netdev(dev))
1570 if (ctcm_add_attributes(&cgdev->dev)) {
1571 unregister_netdev(dev);
1575 strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name));
1577 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1578 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name,
1579 priv->channel[READ]->id,
1580 priv->channel[WRITE]->id, priv->protocol);
1584 ctcm_free_netdevice(dev);
1586 ccw_device_set_offline(cgdev->cdev[1]);
1587 ccw_device_set_offline(cgdev->cdev[0]);
1593 * Shutdown an interface.
1595 * cgdev Device to be shut down.
1597 * returns 0 on success, !0 on failure.
1599 static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1601 struct ctcm_priv *priv;
1602 struct net_device *dev;
1604 priv = dev_get_drvdata(&cgdev->dev);
1608 if (priv->channel[READ]) {
1609 dev = priv->channel[READ]->netdev;
1610 CTCM_DBF_DEV(SETUP, dev, "");
1611 /* Close the device */
1613 dev->flags &= ~IFF_RUNNING;
1614 ctcm_remove_attributes(&cgdev->dev);
1615 channel_free(priv->channel[READ]);
1619 if (priv->channel[WRITE])
1620 channel_free(priv->channel[WRITE]);
1623 unregister_netdev(dev);
1624 ctcm_free_netdevice(dev);
1628 kfree_fsm(priv->fsm);
1630 ccw_device_set_offline(cgdev->cdev[1]);
1631 ccw_device_set_offline(cgdev->cdev[0]);
1633 if (priv->channel[READ])
1634 channel_remove(priv->channel[READ]);
1635 if (priv->channel[WRITE])
1636 channel_remove(priv->channel[WRITE]);
1637 priv->channel[READ] = priv->channel[WRITE] = NULL;
1644 static void ctcm_remove_device(struct ccwgroup_device *cgdev)
1646 struct ctcm_priv *priv = dev_get_drvdata(&cgdev->dev);
1648 BUG_ON(priv == NULL);
1650 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1651 "removing device %s, r/w = %s/%s, proto : %d",
1652 priv->channel[READ]->netdev->name,
1653 priv->channel[READ]->id, priv->channel[WRITE]->id,
1656 if (cgdev->state == CCWGROUP_ONLINE)
1657 ctcm_shutdown_device(cgdev);
1658 ctcm_remove_files(&cgdev->dev);
1659 dev_set_drvdata(&cgdev->dev, NULL);
1661 put_device(&cgdev->dev);
1664 static struct ccwgroup_driver ctcm_group_driver = {
1665 .owner = THIS_MODULE,
1666 .name = CTC_DRIVER_NAME,
1668 .driver_id = 0xC3E3C3D4, /* CTCM */
1669 .probe = ctcm_probe_device,
1670 .remove = ctcm_remove_device,
1671 .set_online = ctcm_new_device,
1672 .set_offline = ctcm_shutdown_device,
1677 * Module related routines
1681 * Prepare to be unloaded. Free IRQ's and release all resources.
1682 * This is called just before this module is unloaded. It is
1683 * not called, if the usage count is !0, so we don't need to check
1686 static void __exit ctcm_exit(void)
1688 unregister_cu3088_discipline(&ctcm_group_driver);
1689 ctcm_unregister_dbf_views();
1690 ctcm_pr_info("CTCM driver unloaded\n");
1696 static void print_banner(void)
1698 printk(KERN_INFO "CTCM driver initialized\n");
1702 * Initialize module.
1703 * This is called just after the module is loaded.
1705 * returns 0 on success, !0 on error.
1707 static int __init ctcm_init(void)
1713 ret = ctcm_register_dbf_views();
1717 ret = register_cu3088_discipline(&ctcm_group_driver);
1719 ctcm_unregister_dbf_views();
1720 ctcm_pr_crit("ctcm_init failed with register_cu3088_discipline "
1721 "(rc = %d)\n", ret);
1728 module_init(ctcm_init);
1729 module_exit(ctcm_exit);
1731 MODULE_AUTHOR("Peter Tiedemann <ptiedem@de.ibm.com>");
1732 MODULE_DESCRIPTION("Network driver for S/390 CTC + CTCMPC (SNA)");
1733 MODULE_LICENSE("GPL");