1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2001, 2009
5 * Original CTC driver(s):
6 * Fritz Elfert (felfert@millenux.com)
7 * Dieter Wellerdiek (wel@de.ibm.com)
8 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * Denis Joseph Barrow (barrow_dj@yahoo.com)
10 * Jochen Roehrig (roehrig@de.ibm.com)
11 * Cornelia Huck <cornelia.huck@de.ibm.com>
13 * Belinda Thompson (belindat@us.ibm.com)
14 * Andy Richter (richtera@us.ibm.com)
16 * Peter Tiedemann (ptiedem@de.ibm.com)
23 #define KMSG_COMPONENT "ctcm"
24 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
30 #include <linux/errno.h>
31 #include <linux/types.h>
32 #include <linux/interrupt.h>
33 #include <linux/timer.h>
34 #include <linux/bitops.h>
36 #include <linux/signal.h>
37 #include <linux/string.h>
40 #include <linux/if_arp.h>
41 #include <linux/tcp.h>
42 #include <linux/skbuff.h>
43 #include <linux/ctype.h>
47 #include <asm/ccwdev.h>
48 #include <asm/ccwgroup.h>
49 #include <linux/uaccess.h>
51 #include <asm/idals.h>
53 #include "ctcm_fsms.h"
54 #include "ctcm_main.h"
56 /* Some common global variables */
59 * The root device for ctcm group devices
61 static struct device *ctcm_root_dev;
64 * Linked list of all detected channels.
66 struct channel *channels;
69 * Unpack a just received skb and hand it over to
72 * ch The channel where this skb has been received.
73 * pskb The received skb.
75 void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb)
77 struct net_device *dev = ch->netdev;
78 struct ctcm_priv *priv = dev->ml_priv;
79 __u16 len = *((__u16 *) pskb->data);
81 skb_put(pskb, 2 + LL_HEADER_LENGTH);
84 pskb->ip_summed = CHECKSUM_UNNECESSARY;
88 struct ll_header *header = (struct ll_header *)pskb->data;
90 skb_pull(pskb, LL_HEADER_LENGTH);
91 if ((ch->protocol == CTCM_PROTO_S390) &&
92 (header->type != ETH_P_IP)) {
93 if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
94 ch->logflags |= LOG_FLAG_ILLEGALPKT;
96 * Check packet type only if we stick strictly
97 * to S/390's protocol of OS390. This only
98 * supports IP. Otherwise allow any packet
101 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
102 "%s(%s): Illegal packet type 0x%04x"
104 CTCM_FUNTAIL, dev->name, header->type);
106 priv->stats.rx_dropped++;
107 priv->stats.rx_frame_errors++;
110 pskb->protocol = cpu_to_be16(header->type);
111 if ((header->length <= LL_HEADER_LENGTH) ||
112 (len <= LL_HEADER_LENGTH)) {
113 if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
114 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
115 "%s(%s): Illegal packet size %d(%d,%d)"
117 CTCM_FUNTAIL, dev->name,
118 header->length, dev->mtu, len);
119 ch->logflags |= LOG_FLAG_ILLEGALSIZE;
122 priv->stats.rx_dropped++;
123 priv->stats.rx_length_errors++;
126 header->length -= LL_HEADER_LENGTH;
127 len -= LL_HEADER_LENGTH;
128 if ((header->length > skb_tailroom(pskb)) ||
129 (header->length > len)) {
130 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
131 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
132 "%s(%s): Packet size %d (overrun)"
133 " - dropping", CTCM_FUNTAIL,
134 dev->name, header->length);
135 ch->logflags |= LOG_FLAG_OVERRUN;
138 priv->stats.rx_dropped++;
139 priv->stats.rx_length_errors++;
142 skb_put(pskb, header->length);
143 skb_reset_mac_header(pskb);
144 len -= header->length;
145 skb = dev_alloc_skb(pskb->len);
147 if (!(ch->logflags & LOG_FLAG_NOMEM)) {
148 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
149 "%s(%s): MEMORY allocation error",
150 CTCM_FUNTAIL, dev->name);
151 ch->logflags |= LOG_FLAG_NOMEM;
153 priv->stats.rx_dropped++;
156 skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len),
158 skb_reset_mac_header(skb);
159 skb->dev = pskb->dev;
160 skb->protocol = pskb->protocol;
161 pskb->ip_summed = CHECKSUM_UNNECESSARY;
167 priv->stats.rx_packets++;
168 priv->stats.rx_bytes += skblen;
171 skb_pull(pskb, header->length);
172 if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
173 CTCM_DBF_DEV_NAME(TRACE, dev,
174 "Overrun in ctcm_unpack_skb");
175 ch->logflags |= LOG_FLAG_OVERRUN;
178 skb_put(pskb, LL_HEADER_LENGTH);
184 * Release a specific channel in the channel list.
186 * ch Pointer to channel struct to be released.
188 static void channel_free(struct channel *ch)
190 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s)", CTCM_FUNTAIL, ch->id);
191 ch->flags &= ~CHANNEL_FLAGS_INUSE;
192 fsm_newstate(ch->fsm, CTC_STATE_IDLE);
196 * Remove a specific channel in the channel list.
198 * ch Pointer to channel struct to be released.
200 static void channel_remove(struct channel *ch)
202 struct channel **c = &channels;
203 char chid[CTCM_ID_SIZE+1];
209 strncpy(chid, ch->id, CTCM_ID_SIZE);
215 fsm_deltimer(&ch->timer);
217 fsm_deltimer(&ch->sweep_timer);
220 clear_normalized_cda(&ch->ccw[4]);
221 if (ch->trans_skb != NULL) {
222 clear_normalized_cda(&ch->ccw[1]);
223 dev_kfree_skb_any(ch->trans_skb);
226 tasklet_kill(&ch->ch_tasklet);
227 tasklet_kill(&ch->ch_disc_tasklet);
228 kfree(ch->discontact_th);
239 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s) %s", CTCM_FUNTAIL,
240 chid, ok ? "OK" : "failed");
244 * Get a specific channel from the channel list.
246 * type Type of channel we are interested in.
247 * id Id of channel we are interested in.
248 * direction Direction we want to use this channel for.
250 * returns Pointer to a channel or NULL if no matching channel available.
252 static struct channel *channel_get(enum ctcm_channel_types type,
253 char *id, int direction)
255 struct channel *ch = channels;
257 while (ch && (strncmp(ch->id, id, CTCM_ID_SIZE) || (ch->type != type)))
260 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
261 "%s(%d, %s, %d) not found in channel list\n",
262 CTCM_FUNTAIL, type, id, direction);
264 if (ch->flags & CHANNEL_FLAGS_INUSE)
267 ch->flags |= CHANNEL_FLAGS_INUSE;
268 ch->flags &= ~CHANNEL_FLAGS_RWMASK;
269 ch->flags |= (direction == CTCM_WRITE)
270 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
271 fsm_newstate(ch->fsm, CTC_STATE_STOPPED);
277 static long ctcm_check_irb_error(struct ccw_device *cdev, struct irb *irb)
282 CTCM_DBF_TEXT_(ERROR, CTC_DBF_WARN,
283 "irb error %ld on device %s\n",
284 PTR_ERR(irb), dev_name(&cdev->dev));
286 switch (PTR_ERR(irb)) {
289 "An I/O-error occurred on the CTCM device\n");
293 "An adapter hardware operation timed out\n");
297 "An error occurred on the adapter hardware\n");
304 * Check sense of a unit check.
306 * ch The channel, the sense code belongs to.
307 * sense The sense code to inspect.
309 static void ccw_unit_check(struct channel *ch, __u8 sense)
311 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
313 CTCM_FUNTAIL, ch->id, sense);
315 if (sense & SNS0_INTERVENTION_REQ) {
317 if (ch->sense_rc != 0x01) {
319 "%s: The communication peer has "
320 "disconnected\n", ch->id);
323 fsm_event(ch->fsm, CTC_EVENT_UC_RCRESET, ch);
325 if (ch->sense_rc != SNS0_INTERVENTION_REQ) {
327 "%s: The remote operating system is "
328 "not available\n", ch->id);
329 ch->sense_rc = SNS0_INTERVENTION_REQ;
331 fsm_event(ch->fsm, CTC_EVENT_UC_RSRESET, ch);
333 } else if (sense & SNS0_EQUIPMENT_CHECK) {
334 if (sense & SNS0_BUS_OUT_CHECK) {
335 if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
336 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
337 "%s(%s): remote HW error %02x",
338 CTCM_FUNTAIL, ch->id, sense);
339 ch->sense_rc = SNS0_BUS_OUT_CHECK;
341 fsm_event(ch->fsm, CTC_EVENT_UC_HWFAIL, ch);
343 if (ch->sense_rc != SNS0_EQUIPMENT_CHECK) {
344 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
345 "%s(%s): remote read parity error %02x",
346 CTCM_FUNTAIL, ch->id, sense);
347 ch->sense_rc = SNS0_EQUIPMENT_CHECK;
349 fsm_event(ch->fsm, CTC_EVENT_UC_RXPARITY, ch);
351 } else if (sense & SNS0_BUS_OUT_CHECK) {
352 if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
353 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
354 "%s(%s): BUS OUT error %02x",
355 CTCM_FUNTAIL, ch->id, sense);
356 ch->sense_rc = SNS0_BUS_OUT_CHECK;
358 if (sense & 0x04) /* data-streaming timeout */
359 fsm_event(ch->fsm, CTC_EVENT_UC_TXTIMEOUT, ch);
360 else /* Data-transfer parity error */
361 fsm_event(ch->fsm, CTC_EVENT_UC_TXPARITY, ch);
362 } else if (sense & SNS0_CMD_REJECT) {
363 if (ch->sense_rc != SNS0_CMD_REJECT) {
364 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
365 "%s(%s): Command rejected",
366 CTCM_FUNTAIL, ch->id);
367 ch->sense_rc = SNS0_CMD_REJECT;
369 } else if (sense == 0) {
370 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
371 "%s(%s): Unit check ZERO",
372 CTCM_FUNTAIL, ch->id);
373 fsm_event(ch->fsm, CTC_EVENT_UC_ZERO, ch);
375 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
376 "%s(%s): Unit check code %02x unknown",
377 CTCM_FUNTAIL, ch->id, sense);
378 fsm_event(ch->fsm, CTC_EVENT_UC_UNKNOWN, ch);
382 int ctcm_ch_alloc_buffer(struct channel *ch)
384 clear_normalized_cda(&ch->ccw[1]);
385 ch->trans_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC | GFP_DMA);
386 if (ch->trans_skb == NULL) {
387 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
388 "%s(%s): %s trans_skb allocation error",
389 CTCM_FUNTAIL, ch->id,
390 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
395 ch->ccw[1].count = ch->max_bufsize;
396 if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
397 dev_kfree_skb(ch->trans_skb);
398 ch->trans_skb = NULL;
399 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
400 "%s(%s): %s set norm_cda failed",
401 CTCM_FUNTAIL, ch->id,
402 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
407 ch->ccw[1].count = 0;
408 ch->trans_skb_data = ch->trans_skb->data;
409 ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
414 * Interface API for upper network layers
419 * Called from generic network layer when ifconfig up is run.
421 * dev Pointer to interface struct.
423 * returns 0 on success, -ERRNO on failure. (Never fails.)
425 int ctcm_open(struct net_device *dev)
427 struct ctcm_priv *priv = dev->ml_priv;
429 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
431 fsm_event(priv->fsm, DEV_EVENT_START, dev);
436 * Close an interface.
437 * Called from generic network layer when ifconfig down is run.
439 * dev Pointer to interface struct.
441 * returns 0 on success, -ERRNO on failure. (Never fails.)
443 int ctcm_close(struct net_device *dev)
445 struct ctcm_priv *priv = dev->ml_priv;
447 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
449 fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
456 * This is a helper function for ctcm_tx().
458 * ch Channel to be used for sending.
459 * skb Pointer to struct sk_buff of packet to send.
460 * The linklevel header has already been set up
463 * returns 0 on success, -ERRNO on failure. (Never fails.)
465 static int ctcm_transmit_skb(struct channel *ch, struct sk_buff *skb)
467 unsigned long saveflags;
468 struct ll_header header;
472 struct sk_buff *nskb;
475 /* we need to acquire the lock for testing the state
476 * otherwise we can have an IRQ changing the state to
477 * TXIDLE after the test but before acquiring the lock.
479 spin_lock_irqsave(&ch->collect_lock, saveflags);
480 if (fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) {
481 int l = skb->len + LL_HEADER_LENGTH;
483 if (ch->collect_len + l > ch->max_bufsize - 2) {
484 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
487 refcount_inc(&skb->users);
489 header.type = be16_to_cpu(skb->protocol);
491 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
493 skb_queue_tail(&ch->collect_queue, skb);
494 ch->collect_len += l;
496 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
499 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
501 * Protect skb against beeing free'd by upper
504 refcount_inc(&skb->users);
505 ch->prof.txlen += skb->len;
506 header.length = skb->len + LL_HEADER_LENGTH;
507 header.type = be16_to_cpu(skb->protocol);
509 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header, LL_HEADER_LENGTH);
510 block_len = skb->len + 2;
511 *((__u16 *)skb_push(skb, 2)) = block_len;
514 * IDAL support in CTCM is broken, so we have to
515 * care about skb's above 2G ourselves.
517 hi = ((unsigned long)skb_tail_pointer(skb) + LL_HEADER_LENGTH) >> 31;
519 nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
521 refcount_dec(&skb->users);
522 skb_pull(skb, LL_HEADER_LENGTH + 2);
523 ctcm_clear_busy(ch->netdev);
526 skb_put_data(nskb, skb->data, skb->len);
527 refcount_inc(&nskb->users);
528 refcount_dec(&skb->users);
529 dev_kfree_skb_irq(skb);
534 ch->ccw[4].count = block_len;
535 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
537 * idal allocation failed, try via copying to
538 * trans_skb. trans_skb usually has a pre-allocated
541 if (ctcm_checkalloc_buffer(ch)) {
543 * Remove our header. It gets added
544 * again on retransmit.
546 refcount_dec(&skb->users);
547 skb_pull(skb, LL_HEADER_LENGTH + 2);
548 ctcm_clear_busy(ch->netdev);
552 skb_reset_tail_pointer(ch->trans_skb);
553 ch->trans_skb->len = 0;
554 ch->ccw[1].count = skb->len;
555 skb_copy_from_linear_data(skb,
556 skb_put(ch->trans_skb, skb->len), skb->len);
557 refcount_dec(&skb->users);
558 dev_kfree_skb_irq(skb);
561 skb_queue_tail(&ch->io_queue, skb);
565 ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
566 sizeof(struct ccw1) * 3);
568 fsm_newstate(ch->fsm, CTC_STATE_TX);
569 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
570 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
571 ch->prof.send_stamp = jiffies;
572 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx], 0, 0xff, 0);
573 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
575 ch->prof.doios_single++;
577 fsm_deltimer(&ch->timer);
578 ctcm_ccw_check_rc(ch, rc, "single skb TX");
580 skb_dequeue_tail(&ch->io_queue);
582 * Remove our header. It gets added
583 * again on retransmit.
585 skb_pull(skb, LL_HEADER_LENGTH + 2);
586 } else if (ccw_idx == 0) {
587 struct net_device *dev = ch->netdev;
588 struct ctcm_priv *priv = dev->ml_priv;
589 priv->stats.tx_packets++;
590 priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
593 ctcm_clear_busy(ch->netdev);
597 static void ctcmpc_send_sweep_req(struct channel *rch)
599 struct net_device *dev = rch->netdev;
600 struct ctcm_priv *priv;
601 struct mpc_group *grp;
602 struct th_sweep *header;
603 struct sk_buff *sweep_skb;
609 ch = priv->channel[CTCM_WRITE];
611 /* sweep processing is not complete until response and request */
612 /* has completed for all read channels in group */
613 if (grp->in_sweep == 0) {
615 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
616 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
619 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
621 if (sweep_skb == NULL) {
626 header = kmalloc(TH_SWEEP_LENGTH, gfp_type());
629 dev_kfree_skb_any(sweep_skb);
634 header->th.th_seg = 0x00 ;
635 header->th.th_ch_flag = TH_SWEEP_REQ; /* 0x0f */
636 header->th.th_blk_flag = 0x00;
637 header->th.th_is_xid = 0x00;
638 header->th.th_seq_num = 0x00;
639 header->sw.th_last_seq = ch->th_seq_num;
641 skb_put_data(sweep_skb, header, TH_SWEEP_LENGTH);
645 netif_trans_update(dev);
646 skb_queue_tail(&ch->sweep_queue, sweep_skb);
648 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
654 ctcm_clear_busy(dev);
655 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
661 * MPC mode version of transmit_skb
663 static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
665 struct pdu *p_header;
666 struct net_device *dev = ch->netdev;
667 struct ctcm_priv *priv = dev->ml_priv;
668 struct mpc_group *grp = priv->mpcg;
669 struct th_header *header;
670 struct sk_buff *nskb;
674 unsigned long saveflags = 0; /* avoids compiler warning */
676 CTCM_PR_DEBUG("Enter %s: %s, cp=%i ch=0x%p id=%s state=%s\n",
677 __func__, dev->name, smp_processor_id(), ch,
678 ch->id, fsm_getstate_str(ch->fsm));
680 if ((fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) || grp->in_sweep) {
681 spin_lock_irqsave(&ch->collect_lock, saveflags);
682 refcount_inc(&skb->users);
683 p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
686 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
690 p_header->pdu_offset = skb->len;
691 p_header->pdu_proto = 0x01;
692 p_header->pdu_flag = 0x00;
693 if (be16_to_cpu(skb->protocol) == ETH_P_SNAP) {
694 p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
696 p_header->pdu_flag |= PDU_FIRST;
698 p_header->pdu_seq = 0;
699 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header,
702 CTCM_PR_DEBUG("%s(%s): Put on collect_q - skb len: %04x \n"
703 "pdu header and data for up to 32 bytes:\n",
704 __func__, dev->name, skb->len);
705 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
707 skb_queue_tail(&ch->collect_queue, skb);
708 ch->collect_len += skb->len;
711 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
716 * Protect skb against beeing free'd by upper
719 refcount_inc(&skb->users);
722 * IDAL support in CTCM is broken, so we have to
723 * care about skb's above 2G ourselves.
725 hi = ((unsigned long)skb->tail + TH_HEADER_LENGTH) >> 31;
727 nskb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
731 skb_put_data(nskb, skb->data, skb->len);
732 refcount_inc(&nskb->users);
733 refcount_dec(&skb->users);
734 dev_kfree_skb_irq(skb);
739 p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
744 p_header->pdu_offset = skb->len;
745 p_header->pdu_proto = 0x01;
746 p_header->pdu_flag = 0x00;
747 p_header->pdu_seq = 0;
748 if (be16_to_cpu(skb->protocol) == ETH_P_SNAP) {
749 p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
751 p_header->pdu_flag |= PDU_FIRST;
753 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, PDU_HEADER_LENGTH);
757 if (ch->collect_len > 0) {
758 spin_lock_irqsave(&ch->collect_lock, saveflags);
759 skb_queue_tail(&ch->collect_queue, skb);
760 ch->collect_len += skb->len;
761 skb = skb_dequeue(&ch->collect_queue);
762 ch->collect_len -= skb->len;
763 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
766 p_header = (struct pdu *)skb->data;
767 p_header->pdu_flag |= PDU_LAST;
769 ch->prof.txlen += skb->len - PDU_HEADER_LENGTH;
771 header = kmalloc(TH_HEADER_LENGTH, gfp_type());
775 header->th_seg = 0x00;
776 header->th_ch_flag = TH_HAS_PDU; /* Normal data */
777 header->th_blk_flag = 0x00;
778 header->th_is_xid = 0x00; /* Just data here */
780 header->th_seq_num = ch->th_seq_num;
782 CTCM_PR_DBGDATA("%s(%s) ToVTAM_th_seq= %08x\n" ,
783 __func__, dev->name, ch->th_seq_num);
785 /* put the TH on the packet */
786 memcpy(skb_push(skb, TH_HEADER_LENGTH), header, TH_HEADER_LENGTH);
790 CTCM_PR_DBGDATA("%s(%s): skb len: %04x\n - pdu header and data for "
791 "up to 32 bytes sent to vtam:\n",
792 __func__, dev->name, skb->len);
793 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
795 ch->ccw[4].count = skb->len;
796 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
798 * idal allocation failed, try via copying to trans_skb.
799 * trans_skb usually has a pre-allocated idal.
801 if (ctcm_checkalloc_buffer(ch)) {
804 * It gets added again on retransmit.
809 skb_reset_tail_pointer(ch->trans_skb);
810 ch->trans_skb->len = 0;
811 ch->ccw[1].count = skb->len;
812 skb_put_data(ch->trans_skb, skb->data, skb->len);
813 refcount_dec(&skb->users);
814 dev_kfree_skb_irq(skb);
816 CTCM_PR_DBGDATA("%s(%s): trans_skb len: %04x\n"
817 "up to 32 bytes sent to vtam:\n",
818 __func__, dev->name, ch->trans_skb->len);
819 CTCM_D3_DUMP((char *)ch->trans_skb->data,
820 min_t(int, 32, ch->trans_skb->len));
822 skb_queue_tail(&ch->io_queue, skb);
826 fsm_newstate(ch->fsm, CTC_STATE_TX);
827 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
830 ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
831 sizeof(struct ccw1) * 3);
833 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
834 ch->prof.send_stamp = jiffies;
835 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx], 0, 0xff, 0);
836 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
838 ch->prof.doios_single++;
840 fsm_deltimer(&ch->timer);
841 ctcm_ccw_check_rc(ch, rc, "single skb TX");
843 skb_dequeue_tail(&ch->io_queue);
844 } else if (ccw_idx == 0) {
845 priv->stats.tx_packets++;
846 priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
848 if (ch->th_seq_num > 0xf0000000) /* Chose at random. */
849 ctcmpc_send_sweep_req(ch);
853 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_CRIT,
854 "%s(%s): MEMORY allocation ERROR\n",
855 CTCM_FUNTAIL, ch->id);
857 refcount_dec(&skb->users);
858 dev_kfree_skb_any(skb);
859 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
861 CTCM_PR_DEBUG("Exit %s(%s)\n", __func__, dev->name);
866 * Start transmission of a packet.
867 * Called from generic network device layer.
869 /* first merge version - leaving both functions separated */
870 static netdev_tx_t ctcm_tx(struct sk_buff *skb, struct net_device *dev)
872 struct ctcm_priv *priv = dev->ml_priv;
875 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
876 "%s(%s): NULL sk_buff passed",
877 CTCM_FUNTAIL, dev->name);
878 priv->stats.tx_dropped++;
881 if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
882 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
883 "%s(%s): Got sk_buff with head room < %ld bytes",
884 CTCM_FUNTAIL, dev->name, LL_HEADER_LENGTH + 2);
886 priv->stats.tx_dropped++;
891 * If channels are not running, try to restart them
892 * and throw away packet.
894 if (fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) {
895 fsm_event(priv->fsm, DEV_EVENT_START, dev);
897 priv->stats.tx_dropped++;
898 priv->stats.tx_errors++;
899 priv->stats.tx_carrier_errors++;
903 if (ctcm_test_and_set_busy(dev))
904 return NETDEV_TX_BUSY;
906 netif_trans_update(dev);
907 if (ctcm_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0)
908 return NETDEV_TX_BUSY;
912 /* unmerged MPC variant of ctcm_tx */
913 static netdev_tx_t ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
916 struct ctcm_priv *priv = dev->ml_priv;
917 struct mpc_group *grp = priv->mpcg;
918 struct sk_buff *newskb = NULL;
921 * Some sanity checks ...
924 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
925 "%s(%s): NULL sk_buff passed",
926 CTCM_FUNTAIL, dev->name);
927 priv->stats.tx_dropped++;
930 if (skb_headroom(skb) < (TH_HEADER_LENGTH + PDU_HEADER_LENGTH)) {
931 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
932 "%s(%s): Got sk_buff with head room < %ld bytes",
933 CTCM_FUNTAIL, dev->name,
934 TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
936 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
938 len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
939 newskb = __dev_alloc_skb(len, gfp_type() | GFP_DMA);
942 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
943 "%s: %s: __dev_alloc_skb failed",
944 __func__, dev->name);
946 dev_kfree_skb_any(skb);
947 priv->stats.tx_dropped++;
948 priv->stats.tx_errors++;
949 priv->stats.tx_carrier_errors++;
950 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
953 newskb->protocol = skb->protocol;
954 skb_reserve(newskb, TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
955 skb_put_data(newskb, skb->data, skb->len);
956 dev_kfree_skb_any(skb);
961 * If channels are not running,
962 * notify anybody about a link failure and throw
965 if ((fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) ||
966 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
967 dev_kfree_skb_any(skb);
968 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
969 "%s(%s): inactive MPCGROUP - dropped",
970 CTCM_FUNTAIL, dev->name);
971 priv->stats.tx_dropped++;
972 priv->stats.tx_errors++;
973 priv->stats.tx_carrier_errors++;
977 if (ctcm_test_and_set_busy(dev)) {
978 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
979 "%s(%s): device busy - dropped",
980 CTCM_FUNTAIL, dev->name);
981 dev_kfree_skb_any(skb);
982 priv->stats.tx_dropped++;
983 priv->stats.tx_errors++;
984 priv->stats.tx_carrier_errors++;
985 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
989 netif_trans_update(dev);
990 if (ctcmpc_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0) {
991 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
992 "%s(%s): device error - dropped",
993 CTCM_FUNTAIL, dev->name);
994 dev_kfree_skb_any(skb);
995 priv->stats.tx_dropped++;
996 priv->stats.tx_errors++;
997 priv->stats.tx_carrier_errors++;
998 ctcm_clear_busy(dev);
999 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1002 ctcm_clear_busy(dev);
1005 MPC_DBF_DEV_NAME(TRACE, dev, "exit");
1007 return NETDEV_TX_OK; /* handle freeing of skb here */
1012 * Sets MTU of an interface.
1014 * dev Pointer to interface struct.
1015 * new_mtu The new MTU to use for this interface.
1017 * returns 0 on success, -EINVAL if MTU is out of valid range.
1018 * (valid range is 576 .. 65527). If VM is on the
1019 * remote side, maximum MTU is 32760, however this is
1022 static int ctcm_change_mtu(struct net_device *dev, int new_mtu)
1024 struct ctcm_priv *priv;
1027 priv = dev->ml_priv;
1028 max_bufsize = priv->channel[CTCM_READ]->max_bufsize;
1031 if (new_mtu > max_bufsize - TH_HEADER_LENGTH)
1033 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1035 if (new_mtu > max_bufsize - LL_HEADER_LENGTH - 2)
1037 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1044 * Returns interface statistics of a device.
1046 * dev Pointer to interface struct.
1048 * returns Pointer to stats struct of this interface.
1050 static struct net_device_stats *ctcm_stats(struct net_device *dev)
1052 return &((struct ctcm_priv *)dev->ml_priv)->stats;
1055 static void ctcm_free_netdevice(struct net_device *dev)
1057 struct ctcm_priv *priv;
1058 struct mpc_group *grp;
1060 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1061 "%s(%s)", CTCM_FUNTAIL, dev->name);
1062 priv = dev->ml_priv;
1067 kfree_fsm(grp->fsm);
1068 dev_kfree_skb(grp->xid_skb);
1069 dev_kfree_skb(grp->rcvd_xid_skb);
1070 tasklet_kill(&grp->mpc_tasklet2);
1075 kfree_fsm(priv->fsm);
1081 * Note: kfree(priv); is done in "opposite" function of
1082 * allocator function probe_device which is remove_device.
1090 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
1092 static const struct net_device_ops ctcm_netdev_ops = {
1093 .ndo_open = ctcm_open,
1094 .ndo_stop = ctcm_close,
1095 .ndo_get_stats = ctcm_stats,
1096 .ndo_change_mtu = ctcm_change_mtu,
1097 .ndo_start_xmit = ctcm_tx,
1100 static const struct net_device_ops ctcm_mpc_netdev_ops = {
1101 .ndo_open = ctcm_open,
1102 .ndo_stop = ctcm_close,
1103 .ndo_get_stats = ctcm_stats,
1104 .ndo_change_mtu = ctcm_change_mtu,
1105 .ndo_start_xmit = ctcmpc_tx,
1108 static void ctcm_dev_setup(struct net_device *dev)
1110 dev->type = ARPHRD_SLIP;
1111 dev->tx_queue_len = 100;
1112 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1114 dev->max_mtu = 65527;
1118 * Initialize everything of the net device except the name and the
1121 static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv)
1123 struct net_device *dev;
1124 struct mpc_group *grp;
1129 dev = alloc_netdev(0, MPC_DEVICE_GENE, NET_NAME_UNKNOWN,
1132 dev = alloc_netdev(0, CTC_DEVICE_GENE, NET_NAME_UNKNOWN,
1136 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
1137 "%s: MEMORY allocation ERROR",
1141 dev->ml_priv = priv;
1142 priv->fsm = init_fsm("ctcmdev", dev_state_names, dev_event_names,
1143 CTCM_NR_DEV_STATES, CTCM_NR_DEV_EVENTS,
1144 dev_fsm, dev_fsm_len, GFP_KERNEL);
1145 if (priv->fsm == NULL) {
1146 CTCMY_DBF_DEV(SETUP, dev, "init_fsm error");
1150 fsm_newstate(priv->fsm, DEV_STATE_STOPPED);
1151 fsm_settimer(priv->fsm, &priv->restart_timer);
1154 /* MPC Group Initializations */
1155 grp = ctcmpc_init_mpc_group(priv);
1157 MPC_DBF_DEV(SETUP, dev, "init_mpc_group error");
1161 tasklet_init(&grp->mpc_tasklet2,
1162 mpc_group_ready, (unsigned long)dev);
1163 dev->mtu = MPC_BUFSIZE_DEFAULT -
1164 TH_HEADER_LENGTH - PDU_HEADER_LENGTH;
1166 dev->netdev_ops = &ctcm_mpc_netdev_ops;
1167 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1168 priv->buffer_size = MPC_BUFSIZE_DEFAULT;
1170 dev->mtu = CTCM_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
1171 dev->netdev_ops = &ctcm_netdev_ops;
1172 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1175 CTCMY_DBF_DEV(SETUP, dev, "finished");
1183 * cdev The ccw_device the interrupt is for.
1184 * intparm interruption parameter.
1185 * irb interruption response block.
1187 static void ctcm_irq_handler(struct ccw_device *cdev,
1188 unsigned long intparm, struct irb *irb)
1191 struct net_device *dev;
1192 struct ctcm_priv *priv;
1193 struct ccwgroup_device *cgdev;
1197 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
1198 "Enter %s(%s)", CTCM_FUNTAIL, dev_name(&cdev->dev));
1200 if (ctcm_check_irb_error(cdev, irb))
1203 cgdev = dev_get_drvdata(&cdev->dev);
1205 cstat = irb->scsw.cmd.cstat;
1206 dstat = irb->scsw.cmd.dstat;
1208 /* Check for unsolicited interrupts. */
1209 if (cgdev == NULL) {
1210 CTCM_DBF_TEXT_(TRACE, CTC_DBF_ERROR,
1211 "%s(%s) unsolicited irq: c-%02x d-%02x\n",
1212 CTCM_FUNTAIL, dev_name(&cdev->dev), cstat, dstat);
1213 dev_warn(&cdev->dev,
1214 "The adapter received a non-specific IRQ\n");
1218 priv = dev_get_drvdata(&cgdev->dev);
1220 /* Try to extract channel from driver data. */
1221 if (priv->channel[CTCM_READ]->cdev == cdev)
1222 ch = priv->channel[CTCM_READ];
1223 else if (priv->channel[CTCM_WRITE]->cdev == cdev)
1224 ch = priv->channel[CTCM_WRITE];
1227 "%s: Internal error: Can't determine channel for "
1228 "interrupt device %s\n",
1229 __func__, dev_name(&cdev->dev));
1230 /* Explain: inconsistent internal structures */
1237 "%s Internal error: net_device is NULL, ch = 0x%p\n",
1239 /* Explain: inconsistent internal structures */
1243 /* Copy interruption response block. */
1244 memcpy(ch->irb, irb, sizeof(struct irb));
1246 /* Issue error message and return on subchannel error code */
1247 if (irb->scsw.cmd.cstat) {
1248 fsm_event(ch->fsm, CTC_EVENT_SC_UNKNOWN, ch);
1249 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
1250 "%s(%s): sub-ch check %s: cs=%02x ds=%02x",
1251 CTCM_FUNTAIL, dev->name, ch->id, cstat, dstat);
1252 dev_warn(&cdev->dev,
1253 "A check occurred on the subchannel\n");
1257 /* Check the reason-code of a unit check */
1258 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
1259 if ((irb->ecw[0] & ch->sense_rc) == 0)
1260 /* print it only once */
1261 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
1262 "%s(%s): sense=%02x, ds=%02x",
1263 CTCM_FUNTAIL, ch->id, irb->ecw[0], dstat);
1264 ccw_unit_check(ch, irb->ecw[0]);
1267 if (irb->scsw.cmd.dstat & DEV_STAT_BUSY) {
1268 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION)
1269 fsm_event(ch->fsm, CTC_EVENT_ATTNBUSY, ch);
1271 fsm_event(ch->fsm, CTC_EVENT_BUSY, ch);
1274 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
1275 fsm_event(ch->fsm, CTC_EVENT_ATTN, ch);
1278 if ((irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
1279 (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
1280 (irb->scsw.cmd.stctl ==
1281 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
1282 fsm_event(ch->fsm, CTC_EVENT_FINSTAT, ch);
1284 fsm_event(ch->fsm, CTC_EVENT_IRQ, ch);
1288 static const struct device_type ctcm_devtype = {
1290 .groups = ctcm_attr_groups,
1294 * Add ctcm specific attributes.
1295 * Add ctcm private data.
1297 * cgdev pointer to ccwgroup_device just added
1299 * returns 0 on success, !0 on failure.
1301 static int ctcm_probe_device(struct ccwgroup_device *cgdev)
1303 struct ctcm_priv *priv;
1305 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1309 if (!get_device(&cgdev->dev))
1312 priv = kzalloc(sizeof(struct ctcm_priv), GFP_KERNEL);
1314 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
1315 "%s: memory allocation failure",
1317 put_device(&cgdev->dev);
1320 priv->buffer_size = CTCM_BUFSIZE_DEFAULT;
1321 cgdev->cdev[0]->handler = ctcm_irq_handler;
1322 cgdev->cdev[1]->handler = ctcm_irq_handler;
1323 dev_set_drvdata(&cgdev->dev, priv);
1324 cgdev->dev.type = &ctcm_devtype;
1330 * Add a new channel to the list of channels.
1331 * Keeps the channel list sorted.
1333 * cdev The ccw_device to be added.
1334 * type The type class of the new channel.
1335 * priv Points to the private data of the ccwgroup_device.
1337 * returns 0 on success, !0 on error.
1339 static int add_channel(struct ccw_device *cdev, enum ctcm_channel_types type,
1340 struct ctcm_priv *priv)
1342 struct channel **c = &channels;
1347 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1348 "%s(%s), type %d, proto %d",
1349 __func__, dev_name(&cdev->dev), type, priv->protocol);
1351 ch = kzalloc(sizeof(struct channel), GFP_KERNEL);
1355 ch->protocol = priv->protocol;
1357 ch->discontact_th = kzalloc(TH_HEADER_LENGTH, gfp_type());
1358 if (ch->discontact_th == NULL)
1361 ch->discontact_th->th_blk_flag = TH_DISCONTACT;
1362 tasklet_init(&ch->ch_disc_tasklet,
1363 mpc_action_send_discontact, (unsigned long)ch);
1365 tasklet_init(&ch->ch_tasklet, ctcmpc_bh, (unsigned long)ch);
1366 ch->max_bufsize = (MPC_BUFSIZE_DEFAULT - 35);
1371 ch->ccw = kcalloc(ccw_num, sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
1372 if (ch->ccw == NULL)
1376 snprintf(ch->id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev->dev));
1380 * "static" ccws are used in the following way:
1382 * ccw[0..2] (Channel program for generic I/O):
1384 * 1: read or write (depending on direction) with fixed
1385 * buffer (idal allocated once when buffer is allocated)
1387 * ccw[3..5] (Channel program for direct write of packets)
1389 * 4: write (idal allocated on every write).
1391 * ccw[6..7] (Channel program for initial channel setup):
1392 * 6: set extended mode
1395 * ch->ccw[0..5] are initialized in ch_action_start because
1396 * the channel's direction is yet unknown here.
1398 * ccws used for xid2 negotiations
1399 * ch-ccw[8-14] need to be used for the XID exchange either
1400 * X side XID2 Processing
1404 * 11: read th from secondary
1405 * 12: read XID from secondary
1406 * 13: read 4 byte ID
1408 * Y side XID Processing
1414 * 13: write 4 byte ID
1417 * ccws used for double noop due to VM timing issues
1418 * which result in unrecoverable Busy on channel
1422 ch->ccw[6].cmd_code = CCW_CMD_SET_EXTENDED;
1423 ch->ccw[6].flags = CCW_FLAG_SLI;
1425 ch->ccw[7].cmd_code = CCW_CMD_NOOP;
1426 ch->ccw[7].flags = CCW_FLAG_SLI;
1429 ch->ccw[15].cmd_code = CCW_CMD_WRITE;
1430 ch->ccw[15].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1431 ch->ccw[15].count = TH_HEADER_LENGTH;
1432 ch->ccw[15].cda = virt_to_phys(ch->discontact_th);
1434 ch->ccw[16].cmd_code = CCW_CMD_NOOP;
1435 ch->ccw[16].flags = CCW_FLAG_SLI;
1437 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1438 ctc_ch_event_names, CTC_MPC_NR_STATES,
1439 CTC_MPC_NR_EVENTS, ctcmpc_ch_fsm,
1440 mpc_ch_fsm_len, GFP_KERNEL);
1442 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1443 ctc_ch_event_names, CTC_NR_STATES,
1444 CTC_NR_EVENTS, ch_fsm,
1445 ch_fsm_len, GFP_KERNEL);
1447 if (ch->fsm == NULL)
1450 fsm_newstate(ch->fsm, CTC_STATE_IDLE);
1452 ch->irb = kzalloc(sizeof(struct irb), GFP_KERNEL);
1453 if (ch->irb == NULL)
1456 while (*c && ctcm_less_than((*c)->id, ch->id))
1459 if (*c && (!strncmp((*c)->id, ch->id, CTCM_ID_SIZE))) {
1460 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1461 "%s (%s) already in list, using old entry",
1462 __func__, (*c)->id);
1467 spin_lock_init(&ch->collect_lock);
1469 fsm_settimer(ch->fsm, &ch->timer);
1470 skb_queue_head_init(&ch->io_queue);
1471 skb_queue_head_init(&ch->collect_queue);
1474 fsm_settimer(ch->fsm, &ch->sweep_timer);
1475 skb_queue_head_init(&ch->sweep_queue);
1484 free_return: /* note that all channel pointers are 0 or valid */
1486 kfree(ch->discontact_th);
1494 * Return type of a detected device.
1496 static enum ctcm_channel_types get_channel_type(struct ccw_device_id *id)
1498 enum ctcm_channel_types type;
1499 type = (enum ctcm_channel_types)id->driver_info;
1501 if (type == ctcm_channel_type_ficon)
1502 type = ctcm_channel_type_escon;
1509 * Setup an interface.
1511 * cgdev Device to be setup.
1513 * returns 0 on success, !0 on failure.
1515 static int ctcm_new_device(struct ccwgroup_device *cgdev)
1517 char read_id[CTCM_ID_SIZE];
1518 char write_id[CTCM_ID_SIZE];
1520 enum ctcm_channel_types type;
1521 struct ctcm_priv *priv;
1522 struct net_device *dev;
1523 struct ccw_device *cdev0;
1524 struct ccw_device *cdev1;
1525 struct channel *readc;
1526 struct channel *writec;
1530 priv = dev_get_drvdata(&cgdev->dev);
1533 goto out_err_result;
1536 cdev0 = cgdev->cdev[0];
1537 cdev1 = cgdev->cdev[1];
1539 type = get_channel_type(&cdev0->id);
1541 snprintf(read_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev0->dev));
1542 snprintf(write_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev1->dev));
1544 ret = add_channel(cdev0, type, priv);
1547 goto out_err_result;
1549 ret = add_channel(cdev1, type, priv);
1552 goto out_remove_channel1;
1555 ret = ccw_device_set_online(cdev0);
1557 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
1558 "%s(%s) set_online rc=%d",
1559 CTCM_FUNTAIL, read_id, ret);
1561 goto out_remove_channel2;
1564 ret = ccw_device_set_online(cdev1);
1566 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
1567 "%s(%s) set_online rc=%d",
1568 CTCM_FUNTAIL, write_id, ret);
1574 dev = ctcm_init_netdevice(priv);
1580 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1581 priv->channel[direction] =
1582 channel_get(type, direction == CTCM_READ ?
1583 read_id : write_id, direction);
1584 if (priv->channel[direction] == NULL) {
1585 if (direction == CTCM_WRITE)
1586 channel_free(priv->channel[CTCM_READ]);
1590 priv->channel[direction]->netdev = dev;
1591 priv->channel[direction]->protocol = priv->protocol;
1592 priv->channel[direction]->max_bufsize = priv->buffer_size;
1595 SET_NETDEV_DEV(dev, &cgdev->dev);
1597 if (register_netdev(dev)) {
1602 strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name));
1605 "setup OK : r/w = %s/%s, protocol : %d\n",
1606 priv->channel[CTCM_READ]->id,
1607 priv->channel[CTCM_WRITE]->id, priv->protocol);
1609 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1610 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name,
1611 priv->channel[CTCM_READ]->id,
1612 priv->channel[CTCM_WRITE]->id, priv->protocol);
1616 ctcm_free_netdevice(dev);
1618 ccw_device_set_offline(cgdev->cdev[1]);
1620 ccw_device_set_offline(cgdev->cdev[0]);
1621 out_remove_channel2:
1622 readc = channel_get(type, read_id, CTCM_READ);
1623 channel_remove(readc);
1624 out_remove_channel1:
1625 writec = channel_get(type, write_id, CTCM_WRITE);
1626 channel_remove(writec);
1632 * Shutdown an interface.
1634 * cgdev Device to be shut down.
1636 * returns 0 on success, !0 on failure.
1638 static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1640 struct ctcm_priv *priv;
1641 struct net_device *dev;
1643 priv = dev_get_drvdata(&cgdev->dev);
1647 if (priv->channel[CTCM_READ]) {
1648 dev = priv->channel[CTCM_READ]->netdev;
1649 CTCM_DBF_DEV(SETUP, dev, "");
1650 /* Close the device */
1652 dev->flags &= ~IFF_RUNNING;
1653 channel_free(priv->channel[CTCM_READ]);
1657 if (priv->channel[CTCM_WRITE])
1658 channel_free(priv->channel[CTCM_WRITE]);
1661 unregister_netdev(dev);
1662 ctcm_free_netdevice(dev);
1666 kfree_fsm(priv->fsm);
1668 ccw_device_set_offline(cgdev->cdev[1]);
1669 ccw_device_set_offline(cgdev->cdev[0]);
1670 channel_remove(priv->channel[CTCM_READ]);
1671 channel_remove(priv->channel[CTCM_WRITE]);
1672 priv->channel[CTCM_READ] = priv->channel[CTCM_WRITE] = NULL;
1679 static void ctcm_remove_device(struct ccwgroup_device *cgdev)
1681 struct ctcm_priv *priv = dev_get_drvdata(&cgdev->dev);
1683 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1684 "removing device %p, proto : %d",
1685 cgdev, priv->protocol);
1687 if (cgdev->state == CCWGROUP_ONLINE)
1688 ctcm_shutdown_device(cgdev);
1689 dev_set_drvdata(&cgdev->dev, NULL);
1691 put_device(&cgdev->dev);
1694 static struct ccw_device_id ctcm_ids[] = {
1695 {CCW_DEVICE(0x3088, 0x08), .driver_info = ctcm_channel_type_parallel},
1696 {CCW_DEVICE(0x3088, 0x1e), .driver_info = ctcm_channel_type_ficon},
1697 {CCW_DEVICE(0x3088, 0x1f), .driver_info = ctcm_channel_type_escon},
1700 MODULE_DEVICE_TABLE(ccw, ctcm_ids);
1702 static struct ccw_driver ctcm_ccw_driver = {
1704 .owner = THIS_MODULE,
1708 .probe = ccwgroup_probe_ccwdev,
1709 .remove = ccwgroup_remove_ccwdev,
1710 .int_class = IRQIO_CTC,
1713 static struct ccwgroup_driver ctcm_group_driver = {
1715 .owner = THIS_MODULE,
1716 .name = CTC_DRIVER_NAME,
1718 .ccw_driver = &ctcm_ccw_driver,
1719 .setup = ctcm_probe_device,
1720 .remove = ctcm_remove_device,
1721 .set_online = ctcm_new_device,
1722 .set_offline = ctcm_shutdown_device,
1725 static ssize_t group_store(struct device_driver *ddrv, const char *buf,
1730 err = ccwgroup_create_dev(ctcm_root_dev, &ctcm_group_driver, 2, buf);
1731 return err ? err : count;
1733 static DRIVER_ATTR_WO(group);
1735 static struct attribute *ctcm_drv_attrs[] = {
1736 &driver_attr_group.attr,
1739 static struct attribute_group ctcm_drv_attr_group = {
1740 .attrs = ctcm_drv_attrs,
1742 static const struct attribute_group *ctcm_drv_attr_groups[] = {
1743 &ctcm_drv_attr_group,
1748 * Module related routines
1752 * Prepare to be unloaded. Free IRQ's and release all resources.
1753 * This is called just before this module is unloaded. It is
1754 * not called, if the usage count is !0, so we don't need to check
1757 static void __exit ctcm_exit(void)
1759 ccwgroup_driver_unregister(&ctcm_group_driver);
1760 ccw_driver_unregister(&ctcm_ccw_driver);
1761 root_device_unregister(ctcm_root_dev);
1762 ctcm_unregister_dbf_views();
1763 pr_info("CTCM driver unloaded\n");
1769 static void print_banner(void)
1771 pr_info("CTCM driver initialized\n");
1775 * Initialize module.
1776 * This is called just after the module is loaded.
1778 * returns 0 on success, !0 on error.
1780 static int __init ctcm_init(void)
1786 ret = ctcm_register_dbf_views();
1789 ctcm_root_dev = root_device_register("ctcm");
1790 ret = PTR_ERR_OR_ZERO(ctcm_root_dev);
1793 ret = ccw_driver_register(&ctcm_ccw_driver);
1796 ctcm_group_driver.driver.groups = ctcm_drv_attr_groups;
1797 ret = ccwgroup_driver_register(&ctcm_group_driver);
1804 ccw_driver_unregister(&ctcm_ccw_driver);
1806 root_device_unregister(ctcm_root_dev);
1808 ctcm_unregister_dbf_views();
1810 pr_err("%s / Initializing the ctcm device driver failed, ret = %d\n",
1815 module_init(ctcm_init);
1816 module_exit(ctcm_exit);
1818 MODULE_AUTHOR("Peter Tiedemann <ptiedem@de.ibm.com>");
1819 MODULE_DESCRIPTION("Network driver for S/390 CTC + CTCMPC (SNA)");
1820 MODULE_LICENSE("GPL");