GNU Linux-libre 4.14.313-gnu1
[releases.git] / drivers / s390 / net / ctcm_main.c
1 /*
2  * Copyright IBM Corp. 2001, 2009
3  * Author(s):
4  *      Original CTC driver(s):
5  *              Fritz Elfert (felfert@millenux.com)
6  *              Dieter Wellerdiek (wel@de.ibm.com)
7  *              Martin Schwidefsky (schwidefsky@de.ibm.com)
8  *              Denis Joseph Barrow (barrow_dj@yahoo.com)
9  *              Jochen Roehrig (roehrig@de.ibm.com)
10  *              Cornelia Huck <cornelia.huck@de.ibm.com>
11  *      MPC additions:
12  *              Belinda Thompson (belindat@us.ibm.com)
13  *              Andy Richter (richtera@us.ibm.com)
14  *      Revived by:
15  *              Peter Tiedemann (ptiedem@de.ibm.com)
16  */
17
18 #undef DEBUG
19 #undef DEBUGDATA
20 #undef DEBUGCCW
21
22 #define KMSG_COMPONENT "ctcm"
23 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
24
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/errno.h>
30 #include <linux/types.h>
31 #include <linux/interrupt.h>
32 #include <linux/timer.h>
33 #include <linux/bitops.h>
34
35 #include <linux/signal.h>
36 #include <linux/string.h>
37
38 #include <linux/ip.h>
39 #include <linux/if_arp.h>
40 #include <linux/tcp.h>
41 #include <linux/skbuff.h>
42 #include <linux/ctype.h>
43 #include <net/dst.h>
44
45 #include <linux/io.h>
46 #include <asm/ccwdev.h>
47 #include <asm/ccwgroup.h>
48 #include <linux/uaccess.h>
49
50 #include <asm/idals.h>
51
52 #include "ctcm_fsms.h"
53 #include "ctcm_main.h"
54
55 /* Some common global variables */
56
57 /**
58  * The root device for ctcm group devices
59  */
60 static struct device *ctcm_root_dev;
61
62 /*
63  * Linked list of all detected channels.
64  */
65 struct channel *channels;
66
67 /**
68  * Unpack a just received skb and hand it over to
69  * upper layers.
70  *
71  *  ch          The channel where this skb has been received.
72  *  pskb        The received skb.
73  */
74 void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb)
75 {
76         struct net_device *dev = ch->netdev;
77         struct ctcm_priv *priv = dev->ml_priv;
78         __u16 len = *((__u16 *) pskb->data);
79
80         skb_put(pskb, 2 + LL_HEADER_LENGTH);
81         skb_pull(pskb, 2);
82         pskb->dev = dev;
83         pskb->ip_summed = CHECKSUM_UNNECESSARY;
84         while (len > 0) {
85                 struct sk_buff *skb;
86                 int skblen;
87                 struct ll_header *header = (struct ll_header *)pskb->data;
88
89                 skb_pull(pskb, LL_HEADER_LENGTH);
90                 if ((ch->protocol == CTCM_PROTO_S390) &&
91                     (header->type != ETH_P_IP)) {
92                         if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
93                                 ch->logflags |= LOG_FLAG_ILLEGALPKT;
94                                 /*
95                                  * Check packet type only if we stick strictly
96                                  * to S/390's protocol of OS390. This only
97                                  * supports IP. Otherwise allow any packet
98                                  * type.
99                                  */
100                                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
101                                         "%s(%s): Illegal packet type 0x%04x"
102                                         " - dropping",
103                                         CTCM_FUNTAIL, dev->name, header->type);
104                         }
105                         priv->stats.rx_dropped++;
106                         priv->stats.rx_frame_errors++;
107                         return;
108                 }
109                 pskb->protocol = cpu_to_be16(header->type);
110                 if ((header->length <= LL_HEADER_LENGTH) ||
111                     (len <= LL_HEADER_LENGTH)) {
112                         if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
113                                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
114                                         "%s(%s): Illegal packet size %d(%d,%d)"
115                                         "- dropping",
116                                         CTCM_FUNTAIL, dev->name,
117                                         header->length, dev->mtu, len);
118                                 ch->logflags |= LOG_FLAG_ILLEGALSIZE;
119                         }
120
121                         priv->stats.rx_dropped++;
122                         priv->stats.rx_length_errors++;
123                         return;
124                 }
125                 header->length -= LL_HEADER_LENGTH;
126                 len -= LL_HEADER_LENGTH;
127                 if ((header->length > skb_tailroom(pskb)) ||
128                     (header->length > len)) {
129                         if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
130                                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
131                                         "%s(%s): Packet size %d (overrun)"
132                                         " - dropping", CTCM_FUNTAIL,
133                                                 dev->name, header->length);
134                                 ch->logflags |= LOG_FLAG_OVERRUN;
135                         }
136
137                         priv->stats.rx_dropped++;
138                         priv->stats.rx_length_errors++;
139                         return;
140                 }
141                 skb_put(pskb, header->length);
142                 skb_reset_mac_header(pskb);
143                 len -= header->length;
144                 skb = dev_alloc_skb(pskb->len);
145                 if (!skb) {
146                         if (!(ch->logflags & LOG_FLAG_NOMEM)) {
147                                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
148                                         "%s(%s): MEMORY allocation error",
149                                                 CTCM_FUNTAIL, dev->name);
150                                 ch->logflags |= LOG_FLAG_NOMEM;
151                         }
152                         priv->stats.rx_dropped++;
153                         return;
154                 }
155                 skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len),
156                                           pskb->len);
157                 skb_reset_mac_header(skb);
158                 skb->dev = pskb->dev;
159                 skb->protocol = pskb->protocol;
160                 pskb->ip_summed = CHECKSUM_UNNECESSARY;
161                 skblen = skb->len;
162                 /*
163                  * reset logflags
164                  */
165                 ch->logflags = 0;
166                 priv->stats.rx_packets++;
167                 priv->stats.rx_bytes += skblen;
168                 netif_rx_ni(skb);
169                 if (len > 0) {
170                         skb_pull(pskb, header->length);
171                         if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
172                                 CTCM_DBF_DEV_NAME(TRACE, dev,
173                                         "Overrun in ctcm_unpack_skb");
174                                 ch->logflags |= LOG_FLAG_OVERRUN;
175                                 return;
176                         }
177                         skb_put(pskb, LL_HEADER_LENGTH);
178                 }
179         }
180 }
181
182 /**
183  * Release a specific channel in the channel list.
184  *
185  *  ch          Pointer to channel struct to be released.
186  */
187 static void channel_free(struct channel *ch)
188 {
189         CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s)", CTCM_FUNTAIL, ch->id);
190         ch->flags &= ~CHANNEL_FLAGS_INUSE;
191         fsm_newstate(ch->fsm, CTC_STATE_IDLE);
192 }
193
194 /**
195  * Remove a specific channel in the channel list.
196  *
197  *  ch          Pointer to channel struct to be released.
198  */
199 static void channel_remove(struct channel *ch)
200 {
201         struct channel **c = &channels;
202         char chid[CTCM_ID_SIZE+1];
203         int ok = 0;
204
205         if (ch == NULL)
206                 return;
207         else
208                 strncpy(chid, ch->id, CTCM_ID_SIZE);
209
210         channel_free(ch);
211         while (*c) {
212                 if (*c == ch) {
213                         *c = ch->next;
214                         fsm_deltimer(&ch->timer);
215                         if (IS_MPC(ch))
216                                 fsm_deltimer(&ch->sweep_timer);
217
218                         kfree_fsm(ch->fsm);
219                         clear_normalized_cda(&ch->ccw[4]);
220                         if (ch->trans_skb != NULL) {
221                                 clear_normalized_cda(&ch->ccw[1]);
222                                 dev_kfree_skb_any(ch->trans_skb);
223                         }
224                         if (IS_MPC(ch)) {
225                                 tasklet_kill(&ch->ch_tasklet);
226                                 tasklet_kill(&ch->ch_disc_tasklet);
227                                 kfree(ch->discontact_th);
228                         }
229                         kfree(ch->ccw);
230                         kfree(ch->irb);
231                         kfree(ch);
232                         ok = 1;
233                         break;
234                 }
235                 c = &((*c)->next);
236         }
237
238         CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s) %s", CTCM_FUNTAIL,
239                         chid, ok ? "OK" : "failed");
240 }
241
242 /**
243  * Get a specific channel from the channel list.
244  *
245  *  type        Type of channel we are interested in.
246  *  id          Id of channel we are interested in.
247  *  direction   Direction we want to use this channel for.
248  *
249  * returns Pointer to a channel or NULL if no matching channel available.
250  */
251 static struct channel *channel_get(enum ctcm_channel_types type,
252                                         char *id, int direction)
253 {
254         struct channel *ch = channels;
255
256         while (ch && (strncmp(ch->id, id, CTCM_ID_SIZE) || (ch->type != type)))
257                 ch = ch->next;
258         if (!ch) {
259                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
260                                 "%s(%d, %s, %d) not found in channel list\n",
261                                 CTCM_FUNTAIL, type, id, direction);
262         } else {
263                 if (ch->flags & CHANNEL_FLAGS_INUSE)
264                         ch = NULL;
265                 else {
266                         ch->flags |= CHANNEL_FLAGS_INUSE;
267                         ch->flags &= ~CHANNEL_FLAGS_RWMASK;
268                         ch->flags |= (direction == CTCM_WRITE)
269                             ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
270                         fsm_newstate(ch->fsm, CTC_STATE_STOPPED);
271                 }
272         }
273         return ch;
274 }
275
276 static long ctcm_check_irb_error(struct ccw_device *cdev, struct irb *irb)
277 {
278         if (!IS_ERR(irb))
279                 return 0;
280
281         CTCM_DBF_TEXT_(ERROR, CTC_DBF_WARN,
282                         "irb error %ld on device %s\n",
283                                 PTR_ERR(irb), dev_name(&cdev->dev));
284
285         switch (PTR_ERR(irb)) {
286         case -EIO:
287                 dev_err(&cdev->dev,
288                         "An I/O-error occurred on the CTCM device\n");
289                 break;
290         case -ETIMEDOUT:
291                 dev_err(&cdev->dev,
292                         "An adapter hardware operation timed out\n");
293                 break;
294         default:
295                 dev_err(&cdev->dev,
296                         "An error occurred on the adapter hardware\n");
297         }
298         return PTR_ERR(irb);
299 }
300
301
302 /**
303  * Check sense of a unit check.
304  *
305  *  ch          The channel, the sense code belongs to.
306  *  sense       The sense code to inspect.
307  */
308 static void ccw_unit_check(struct channel *ch, __u8 sense)
309 {
310         CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
311                         "%s(%s): %02x",
312                                 CTCM_FUNTAIL, ch->id, sense);
313
314         if (sense & SNS0_INTERVENTION_REQ) {
315                 if (sense & 0x01) {
316                         if (ch->sense_rc != 0x01) {
317                                 pr_notice(
318                                         "%s: The communication peer has "
319                                         "disconnected\n", ch->id);
320                                 ch->sense_rc = 0x01;
321                         }
322                         fsm_event(ch->fsm, CTC_EVENT_UC_RCRESET, ch);
323                 } else {
324                         if (ch->sense_rc != SNS0_INTERVENTION_REQ) {
325                                 pr_notice(
326                                         "%s: The remote operating system is "
327                                         "not available\n", ch->id);
328                                 ch->sense_rc = SNS0_INTERVENTION_REQ;
329                         }
330                         fsm_event(ch->fsm, CTC_EVENT_UC_RSRESET, ch);
331                 }
332         } else if (sense & SNS0_EQUIPMENT_CHECK) {
333                 if (sense & SNS0_BUS_OUT_CHECK) {
334                         if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
335                                 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
336                                         "%s(%s): remote HW error %02x",
337                                                 CTCM_FUNTAIL, ch->id, sense);
338                                 ch->sense_rc = SNS0_BUS_OUT_CHECK;
339                         }
340                         fsm_event(ch->fsm, CTC_EVENT_UC_HWFAIL, ch);
341                 } else {
342                         if (ch->sense_rc != SNS0_EQUIPMENT_CHECK) {
343                                 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
344                                         "%s(%s): remote read parity error %02x",
345                                                 CTCM_FUNTAIL, ch->id, sense);
346                                 ch->sense_rc = SNS0_EQUIPMENT_CHECK;
347                         }
348                         fsm_event(ch->fsm, CTC_EVENT_UC_RXPARITY, ch);
349                 }
350         } else if (sense & SNS0_BUS_OUT_CHECK) {
351                 if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
352                         CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
353                                 "%s(%s): BUS OUT error %02x",
354                                         CTCM_FUNTAIL, ch->id, sense);
355                         ch->sense_rc = SNS0_BUS_OUT_CHECK;
356                 }
357                 if (sense & 0x04)       /* data-streaming timeout */
358                         fsm_event(ch->fsm, CTC_EVENT_UC_TXTIMEOUT, ch);
359                 else                    /* Data-transfer parity error */
360                         fsm_event(ch->fsm, CTC_EVENT_UC_TXPARITY, ch);
361         } else if (sense & SNS0_CMD_REJECT) {
362                 if (ch->sense_rc != SNS0_CMD_REJECT) {
363                         CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
364                                 "%s(%s): Command rejected",
365                                                 CTCM_FUNTAIL, ch->id);
366                         ch->sense_rc = SNS0_CMD_REJECT;
367                 }
368         } else if (sense == 0) {
369                 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
370                         "%s(%s): Unit check ZERO",
371                                         CTCM_FUNTAIL, ch->id);
372                 fsm_event(ch->fsm, CTC_EVENT_UC_ZERO, ch);
373         } else {
374                 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
375                         "%s(%s): Unit check code %02x unknown",
376                                         CTCM_FUNTAIL, ch->id, sense);
377                 fsm_event(ch->fsm, CTC_EVENT_UC_UNKNOWN, ch);
378         }
379 }
380
381 int ctcm_ch_alloc_buffer(struct channel *ch)
382 {
383         clear_normalized_cda(&ch->ccw[1]);
384         ch->trans_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC | GFP_DMA);
385         if (ch->trans_skb == NULL) {
386                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
387                         "%s(%s): %s trans_skb allocation error",
388                         CTCM_FUNTAIL, ch->id,
389                         (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
390                                 "RX" : "TX");
391                 return -ENOMEM;
392         }
393
394         ch->ccw[1].count = ch->max_bufsize;
395         if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
396                 dev_kfree_skb(ch->trans_skb);
397                 ch->trans_skb = NULL;
398                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
399                         "%s(%s): %s set norm_cda failed",
400                         CTCM_FUNTAIL, ch->id,
401                         (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
402                                 "RX" : "TX");
403                 return -ENOMEM;
404         }
405
406         ch->ccw[1].count = 0;
407         ch->trans_skb_data = ch->trans_skb->data;
408         ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
409         return 0;
410 }
411
412 /*
413  * Interface API for upper network layers
414  */
415
416 /**
417  * Open an interface.
418  * Called from generic network layer when ifconfig up is run.
419  *
420  *  dev         Pointer to interface struct.
421  *
422  * returns 0 on success, -ERRNO on failure. (Never fails.)
423  */
424 int ctcm_open(struct net_device *dev)
425 {
426         struct ctcm_priv *priv = dev->ml_priv;
427
428         CTCMY_DBF_DEV_NAME(SETUP, dev, "");
429         if (!IS_MPC(priv))
430                 fsm_event(priv->fsm,    DEV_EVENT_START, dev);
431         return 0;
432 }
433
434 /**
435  * Close an interface.
436  * Called from generic network layer when ifconfig down is run.
437  *
438  *  dev         Pointer to interface struct.
439  *
440  * returns 0 on success, -ERRNO on failure. (Never fails.)
441  */
442 int ctcm_close(struct net_device *dev)
443 {
444         struct ctcm_priv *priv = dev->ml_priv;
445
446         CTCMY_DBF_DEV_NAME(SETUP, dev, "");
447         if (!IS_MPC(priv))
448                 fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
449         return 0;
450 }
451
452
453 /**
454  * Transmit a packet.
455  * This is a helper function for ctcm_tx().
456  *
457  *  ch          Channel to be used for sending.
458  *  skb         Pointer to struct sk_buff of packet to send.
459  *            The linklevel header has already been set up
460  *            by ctcm_tx().
461  *
462  * returns 0 on success, -ERRNO on failure. (Never fails.)
463  */
464 static int ctcm_transmit_skb(struct channel *ch, struct sk_buff *skb)
465 {
466         unsigned long saveflags;
467         struct ll_header header;
468         int rc = 0;
469         __u16 block_len;
470         int ccw_idx;
471         struct sk_buff *nskb;
472         unsigned long hi;
473
474         /* we need to acquire the lock for testing the state
475          * otherwise we can have an IRQ changing the state to
476          * TXIDLE after the test but before acquiring the lock.
477          */
478         spin_lock_irqsave(&ch->collect_lock, saveflags);
479         if (fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) {
480                 int l = skb->len + LL_HEADER_LENGTH;
481
482                 if (ch->collect_len + l > ch->max_bufsize - 2) {
483                         spin_unlock_irqrestore(&ch->collect_lock, saveflags);
484                         return -EBUSY;
485                 } else {
486                         refcount_inc(&skb->users);
487                         header.length = l;
488                         header.type = be16_to_cpu(skb->protocol);
489                         header.unused = 0;
490                         memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
491                                LL_HEADER_LENGTH);
492                         skb_queue_tail(&ch->collect_queue, skb);
493                         ch->collect_len += l;
494                 }
495                 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
496                                 goto done;
497         }
498         spin_unlock_irqrestore(&ch->collect_lock, saveflags);
499         /*
500          * Protect skb against beeing free'd by upper
501          * layers.
502          */
503         refcount_inc(&skb->users);
504         ch->prof.txlen += skb->len;
505         header.length = skb->len + LL_HEADER_LENGTH;
506         header.type = be16_to_cpu(skb->protocol);
507         header.unused = 0;
508         memcpy(skb_push(skb, LL_HEADER_LENGTH), &header, LL_HEADER_LENGTH);
509         block_len = skb->len + 2;
510         *((__u16 *)skb_push(skb, 2)) = block_len;
511
512         /*
513          * IDAL support in CTCM is broken, so we have to
514          * care about skb's above 2G ourselves.
515          */
516         hi = ((unsigned long)skb_tail_pointer(skb) + LL_HEADER_LENGTH) >> 31;
517         if (hi) {
518                 nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
519                 if (!nskb) {
520                         refcount_dec(&skb->users);
521                         skb_pull(skb, LL_HEADER_LENGTH + 2);
522                         ctcm_clear_busy(ch->netdev);
523                         return -ENOMEM;
524                 } else {
525                         skb_put_data(nskb, skb->data, skb->len);
526                         refcount_inc(&nskb->users);
527                         refcount_dec(&skb->users);
528                         dev_kfree_skb_irq(skb);
529                         skb = nskb;
530                 }
531         }
532
533         ch->ccw[4].count = block_len;
534         if (set_normalized_cda(&ch->ccw[4], skb->data)) {
535                 /*
536                  * idal allocation failed, try via copying to
537                  * trans_skb. trans_skb usually has a pre-allocated
538                  * idal.
539                  */
540                 if (ctcm_checkalloc_buffer(ch)) {
541                         /*
542                          * Remove our header. It gets added
543                          * again on retransmit.
544                          */
545                         refcount_dec(&skb->users);
546                         skb_pull(skb, LL_HEADER_LENGTH + 2);
547                         ctcm_clear_busy(ch->netdev);
548                         return -ENOMEM;
549                 }
550
551                 skb_reset_tail_pointer(ch->trans_skb);
552                 ch->trans_skb->len = 0;
553                 ch->ccw[1].count = skb->len;
554                 skb_copy_from_linear_data(skb,
555                                 skb_put(ch->trans_skb, skb->len), skb->len);
556                 refcount_dec(&skb->users);
557                 dev_kfree_skb_irq(skb);
558                 ccw_idx = 0;
559         } else {
560                 skb_queue_tail(&ch->io_queue, skb);
561                 ccw_idx = 3;
562         }
563         if (do_debug_ccw)
564                 ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
565                                         sizeof(struct ccw1) * 3);
566         ch->retry = 0;
567         fsm_newstate(ch->fsm, CTC_STATE_TX);
568         fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
569         spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
570         ch->prof.send_stamp = jiffies;
571         rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
572                                         (unsigned long)ch, 0xff, 0);
573         spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
574         if (ccw_idx == 3)
575                 ch->prof.doios_single++;
576         if (rc != 0) {
577                 fsm_deltimer(&ch->timer);
578                 ctcm_ccw_check_rc(ch, rc, "single skb TX");
579                 if (ccw_idx == 3)
580                         skb_dequeue_tail(&ch->io_queue);
581                 /*
582                  * Remove our header. It gets added
583                  * again on retransmit.
584                  */
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;
591         }
592 done:
593         ctcm_clear_busy(ch->netdev);
594         return rc;
595 }
596
597 static void ctcmpc_send_sweep_req(struct channel *rch)
598 {
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;
604         struct channel *ch;
605         /* int rc = 0; */
606
607         priv = dev->ml_priv;
608         grp = priv->mpcg;
609         ch = priv->channel[CTCM_WRITE];
610
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) {
614                 grp->in_sweep = 1;
615                 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
616                 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
617         }
618
619         sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
620
621         if (sweep_skb == NULL)  {
622                 /* rc = -ENOMEM; */
623                                 goto nomem;
624         }
625
626         header = kmalloc(TH_SWEEP_LENGTH, gfp_type());
627
628         if (!header) {
629                 dev_kfree_skb_any(sweep_skb);
630                 /* rc = -ENOMEM; */
631                                 goto nomem;
632         }
633
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;
640
641         skb_put_data(sweep_skb, header, TH_SWEEP_LENGTH);
642
643         kfree(header);
644
645         netif_trans_update(dev);
646         skb_queue_tail(&ch->sweep_queue, sweep_skb);
647
648         fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
649
650         return;
651
652 nomem:
653         grp->in_sweep = 0;
654         ctcm_clear_busy(dev);
655         fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
656
657         return;
658 }
659
660 /*
661  * MPC mode version of transmit_skb
662  */
663 static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
664 {
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;
671         int rc = 0;
672         int ccw_idx;
673         unsigned long hi;
674         unsigned long saveflags = 0;    /* avoids compiler warning */
675
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));
679
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());
684
685                 if (!p_header) {
686                         spin_unlock_irqrestore(&ch->collect_lock, saveflags);
687                                 goto nomem_exit;
688                 }
689
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;
695                 } else {
696                         p_header->pdu_flag |= PDU_FIRST;
697                 }
698                 p_header->pdu_seq = 0;
699                 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header,
700                        PDU_HEADER_LENGTH);
701
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));
706
707                 skb_queue_tail(&ch->collect_queue, skb);
708                 ch->collect_len += skb->len;
709                 kfree(p_header);
710
711                 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
712                         goto done;
713         }
714
715         /*
716          * Protect skb against beeing free'd by upper
717          * layers.
718          */
719         refcount_inc(&skb->users);
720
721         /*
722          * IDAL support in CTCM is broken, so we have to
723          * care about skb's above 2G ourselves.
724          */
725         hi = ((unsigned long)skb->tail + TH_HEADER_LENGTH) >> 31;
726         if (hi) {
727                 nskb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
728                 if (!nskb) {
729                         goto nomem_exit;
730                 } else {
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);
735                         skb = nskb;
736                 }
737         }
738
739         p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
740
741         if (!p_header)
742                 goto nomem_exit;
743
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;
750         } else {
751                 p_header->pdu_flag |= PDU_FIRST;
752         }
753         memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, PDU_HEADER_LENGTH);
754
755         kfree(p_header);
756
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);
764         }
765
766         p_header = (struct pdu *)skb->data;
767         p_header->pdu_flag |= PDU_LAST;
768
769         ch->prof.txlen += skb->len - PDU_HEADER_LENGTH;
770
771         header = kmalloc(TH_HEADER_LENGTH, gfp_type());
772         if (!header)
773                 goto nomem_exit;
774
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 */
779         ch->th_seq_num++;
780         header->th_seq_num = ch->th_seq_num;
781
782         CTCM_PR_DBGDATA("%s(%s) ToVTAM_th_seq= %08x\n" ,
783                        __func__, dev->name, ch->th_seq_num);
784
785         /* put the TH on the packet */
786         memcpy(skb_push(skb, TH_HEADER_LENGTH), header, TH_HEADER_LENGTH);
787
788         kfree(header);
789
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));
794
795         ch->ccw[4].count = skb->len;
796         if (set_normalized_cda(&ch->ccw[4], skb->data)) {
797                 /*
798                  * idal allocation failed, try via copying to trans_skb.
799                  * trans_skb usually has a pre-allocated idal.
800                  */
801                 if (ctcm_checkalloc_buffer(ch)) {
802                         /*
803                          * Remove our header.
804                          * It gets added again on retransmit.
805                          */
806                                 goto nomem_exit;
807                 }
808
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);
815                 ccw_idx = 0;
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));
821         } else {
822                 skb_queue_tail(&ch->io_queue, skb);
823                 ccw_idx = 3;
824         }
825         ch->retry = 0;
826         fsm_newstate(ch->fsm, CTC_STATE_TX);
827         fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
828
829         if (do_debug_ccw)
830                 ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
831                                         sizeof(struct ccw1) * 3);
832
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],
836                                         (unsigned long)ch, 0xff, 0);
837         spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
838         if (ccw_idx == 3)
839                 ch->prof.doios_single++;
840         if (rc != 0) {
841                 fsm_deltimer(&ch->timer);
842                 ctcm_ccw_check_rc(ch, rc, "single skb TX");
843                 if (ccw_idx == 3)
844                         skb_dequeue_tail(&ch->io_queue);
845         } else if (ccw_idx == 0) {
846                 priv->stats.tx_packets++;
847                 priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
848         }
849         if (ch->th_seq_num > 0xf0000000)        /* Chose at random. */
850                 ctcmpc_send_sweep_req(ch);
851
852         goto done;
853 nomem_exit:
854         CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_CRIT,
855                         "%s(%s): MEMORY allocation ERROR\n",
856                         CTCM_FUNTAIL, ch->id);
857         rc = -ENOMEM;
858         refcount_dec(&skb->users);
859         dev_kfree_skb_any(skb);
860         fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
861 done:
862         CTCM_PR_DEBUG("Exit %s(%s)\n", __func__, dev->name);
863         return rc;
864 }
865
866 /**
867  * Start transmission of a packet.
868  * Called from generic network device layer.
869  */
870 /* first merge version - leaving both functions separated */
871 static netdev_tx_t ctcm_tx(struct sk_buff *skb, struct net_device *dev)
872 {
873         struct ctcm_priv *priv = dev->ml_priv;
874
875         if (skb == NULL) {
876                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
877                                 "%s(%s): NULL sk_buff passed",
878                                         CTCM_FUNTAIL, dev->name);
879                 priv->stats.tx_dropped++;
880                 return NETDEV_TX_OK;
881         }
882         if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
883                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
884                         "%s(%s): Got sk_buff with head room < %ld bytes",
885                         CTCM_FUNTAIL, dev->name, LL_HEADER_LENGTH + 2);
886                 dev_kfree_skb(skb);
887                 priv->stats.tx_dropped++;
888                 return NETDEV_TX_OK;
889         }
890
891         /*
892          * If channels are not running, try to restart them
893          * and throw away packet.
894          */
895         if (fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) {
896                 fsm_event(priv->fsm, DEV_EVENT_START, dev);
897                 dev_kfree_skb(skb);
898                 priv->stats.tx_dropped++;
899                 priv->stats.tx_errors++;
900                 priv->stats.tx_carrier_errors++;
901                 return NETDEV_TX_OK;
902         }
903
904         if (ctcm_test_and_set_busy(dev))
905                 return NETDEV_TX_BUSY;
906
907         netif_trans_update(dev);
908         if (ctcm_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0)
909                 return NETDEV_TX_BUSY;
910         return NETDEV_TX_OK;
911 }
912
913 /* unmerged MPC variant of ctcm_tx */
914 static netdev_tx_t ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
915 {
916         int len = 0;
917         struct ctcm_priv *priv = dev->ml_priv;
918         struct mpc_group *grp  = priv->mpcg;
919         struct sk_buff *newskb = NULL;
920
921         /*
922          * Some sanity checks ...
923          */
924         if (skb == NULL) {
925                 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
926                         "%s(%s): NULL sk_buff passed",
927                                         CTCM_FUNTAIL, dev->name);
928                 priv->stats.tx_dropped++;
929                                         goto done;
930         }
931         if (skb_headroom(skb) < (TH_HEADER_LENGTH + PDU_HEADER_LENGTH)) {
932                 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
933                         "%s(%s): Got sk_buff with head room < %ld bytes",
934                         CTCM_FUNTAIL, dev->name,
935                                 TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
936
937                 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
938
939                 len =  skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
940                 newskb = __dev_alloc_skb(len, gfp_type() | GFP_DMA);
941
942                 if (!newskb) {
943                         CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
944                                 "%s: %s: __dev_alloc_skb failed",
945                                                 __func__, dev->name);
946
947                         dev_kfree_skb_any(skb);
948                         priv->stats.tx_dropped++;
949                         priv->stats.tx_errors++;
950                         priv->stats.tx_carrier_errors++;
951                         fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
952                                         goto done;
953                 }
954                 newskb->protocol = skb->protocol;
955                 skb_reserve(newskb, TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
956                 skb_put_data(newskb, skb->data, skb->len);
957                 dev_kfree_skb_any(skb);
958                 skb = newskb;
959         }
960
961         /*
962          * If channels are not running,
963          * notify anybody about a link failure and throw
964          * away packet.
965          */
966         if ((fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) ||
967            (fsm_getstate(grp->fsm) <  MPCG_STATE_XID2INITW)) {
968                 dev_kfree_skb_any(skb);
969                 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
970                         "%s(%s): inactive MPCGROUP - dropped",
971                                         CTCM_FUNTAIL, dev->name);
972                 priv->stats.tx_dropped++;
973                 priv->stats.tx_errors++;
974                 priv->stats.tx_carrier_errors++;
975                                         goto done;
976         }
977
978         if (ctcm_test_and_set_busy(dev)) {
979                 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
980                         "%s(%s): device busy - dropped",
981                                         CTCM_FUNTAIL, dev->name);
982                 dev_kfree_skb_any(skb);
983                 priv->stats.tx_dropped++;
984                 priv->stats.tx_errors++;
985                 priv->stats.tx_carrier_errors++;
986                 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
987                                         goto done;
988         }
989
990         netif_trans_update(dev);
991         if (ctcmpc_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0) {
992                 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
993                         "%s(%s): device error - dropped",
994                                         CTCM_FUNTAIL, dev->name);
995                 dev_kfree_skb_any(skb);
996                 priv->stats.tx_dropped++;
997                 priv->stats.tx_errors++;
998                 priv->stats.tx_carrier_errors++;
999                 ctcm_clear_busy(dev);
1000                 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1001                                         goto done;
1002         }
1003         ctcm_clear_busy(dev);
1004 done:
1005         if (do_debug)
1006                 MPC_DBF_DEV_NAME(TRACE, dev, "exit");
1007
1008         return NETDEV_TX_OK;    /* handle freeing of skb here */
1009 }
1010
1011
1012 /**
1013  * Sets MTU of an interface.
1014  *
1015  *  dev         Pointer to interface struct.
1016  *  new_mtu     The new MTU to use for this interface.
1017  *
1018  * returns 0 on success, -EINVAL if MTU is out of valid range.
1019  *         (valid range is 576 .. 65527). If VM is on the
1020  *         remote side, maximum MTU is 32760, however this is
1021  *         not checked here.
1022  */
1023 static int ctcm_change_mtu(struct net_device *dev, int new_mtu)
1024 {
1025         struct ctcm_priv *priv;
1026         int max_bufsize;
1027
1028         priv = dev->ml_priv;
1029         max_bufsize = priv->channel[CTCM_READ]->max_bufsize;
1030
1031         if (IS_MPC(priv)) {
1032                 if (new_mtu > max_bufsize - TH_HEADER_LENGTH)
1033                         return -EINVAL;
1034                 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1035         } else {
1036                 if (new_mtu > max_bufsize - LL_HEADER_LENGTH - 2)
1037                         return -EINVAL;
1038                 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1039         }
1040         dev->mtu = new_mtu;
1041         return 0;
1042 }
1043
1044 /**
1045  * Returns interface statistics of a device.
1046  *
1047  *  dev         Pointer to interface struct.
1048  *
1049  * returns Pointer to stats struct of this interface.
1050  */
1051 static struct net_device_stats *ctcm_stats(struct net_device *dev)
1052 {
1053         return &((struct ctcm_priv *)dev->ml_priv)->stats;
1054 }
1055
1056 static void ctcm_free_netdevice(struct net_device *dev)
1057 {
1058         struct ctcm_priv *priv;
1059         struct mpc_group *grp;
1060
1061         CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1062                         "%s(%s)", CTCM_FUNTAIL, dev->name);
1063         priv = dev->ml_priv;
1064         if (priv) {
1065                 grp = priv->mpcg;
1066                 if (grp) {
1067                         if (grp->fsm)
1068                                 kfree_fsm(grp->fsm);
1069                         if (grp->xid_skb)
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);
1074                         kfree(grp);
1075                         priv->mpcg = NULL;
1076                 }
1077                 if (priv->fsm) {
1078                         kfree_fsm(priv->fsm);
1079                         priv->fsm = NULL;
1080                 }
1081                 kfree(priv->xid);
1082                 priv->xid = NULL;
1083         /*
1084          * Note: kfree(priv); is done in "opposite" function of
1085          * allocator function probe_device which is remove_device.
1086          */
1087         }
1088 #ifdef MODULE
1089         free_netdev(dev);
1090 #endif
1091 }
1092
1093 struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
1094
1095 static const struct net_device_ops ctcm_netdev_ops = {
1096         .ndo_open               = ctcm_open,
1097         .ndo_stop               = ctcm_close,
1098         .ndo_get_stats          = ctcm_stats,
1099         .ndo_change_mtu         = ctcm_change_mtu,
1100         .ndo_start_xmit         = ctcm_tx,
1101 };
1102
1103 static const struct net_device_ops ctcm_mpc_netdev_ops = {
1104         .ndo_open               = ctcm_open,
1105         .ndo_stop               = ctcm_close,
1106         .ndo_get_stats          = ctcm_stats,
1107         .ndo_change_mtu         = ctcm_change_mtu,
1108         .ndo_start_xmit         = ctcmpc_tx,
1109 };
1110
1111 static void ctcm_dev_setup(struct net_device *dev)
1112 {
1113         dev->type = ARPHRD_SLIP;
1114         dev->tx_queue_len = 100;
1115         dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1116         dev->min_mtu = 576;
1117         dev->max_mtu = 65527;
1118 }
1119
1120 /*
1121  * Initialize everything of the net device except the name and the
1122  * channel structs.
1123  */
1124 static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv)
1125 {
1126         struct net_device *dev;
1127         struct mpc_group *grp;
1128         if (!priv)
1129                 return NULL;
1130
1131         if (IS_MPC(priv))
1132                 dev = alloc_netdev(0, MPC_DEVICE_GENE, NET_NAME_UNKNOWN,
1133                                    ctcm_dev_setup);
1134         else
1135                 dev = alloc_netdev(0, CTC_DEVICE_GENE, NET_NAME_UNKNOWN,
1136                                    ctcm_dev_setup);
1137
1138         if (!dev) {
1139                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
1140                         "%s: MEMORY allocation ERROR",
1141                         CTCM_FUNTAIL);
1142                 return NULL;
1143         }
1144         dev->ml_priv = priv;
1145         priv->fsm = init_fsm("ctcmdev", dev_state_names, dev_event_names,
1146                                 CTCM_NR_DEV_STATES, CTCM_NR_DEV_EVENTS,
1147                                 dev_fsm, dev_fsm_len, GFP_KERNEL);
1148         if (priv->fsm == NULL) {
1149                 CTCMY_DBF_DEV(SETUP, dev, "init_fsm error");
1150                 free_netdev(dev);
1151                 return NULL;
1152         }
1153         fsm_newstate(priv->fsm, DEV_STATE_STOPPED);
1154         fsm_settimer(priv->fsm, &priv->restart_timer);
1155
1156         if (IS_MPC(priv)) {
1157                 /*  MPC Group Initializations  */
1158                 grp = ctcmpc_init_mpc_group(priv);
1159                 if (grp == NULL) {
1160                         MPC_DBF_DEV(SETUP, dev, "init_mpc_group error");
1161                         free_netdev(dev);
1162                         return NULL;
1163                 }
1164                 tasklet_init(&grp->mpc_tasklet2,
1165                                 mpc_group_ready, (unsigned long)dev);
1166                 dev->mtu = MPC_BUFSIZE_DEFAULT -
1167                                 TH_HEADER_LENGTH - PDU_HEADER_LENGTH;
1168
1169                 dev->netdev_ops = &ctcm_mpc_netdev_ops;
1170                 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1171                 priv->buffer_size = MPC_BUFSIZE_DEFAULT;
1172         } else {
1173                 dev->mtu = CTCM_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
1174                 dev->netdev_ops = &ctcm_netdev_ops;
1175                 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1176         }
1177
1178         CTCMY_DBF_DEV(SETUP, dev, "finished");
1179
1180         return dev;
1181 }
1182
1183 /**
1184  * Main IRQ handler.
1185  *
1186  *  cdev        The ccw_device the interrupt is for.
1187  *  intparm     interruption parameter.
1188  *  irb         interruption response block.
1189  */
1190 static void ctcm_irq_handler(struct ccw_device *cdev,
1191                                 unsigned long intparm, struct irb *irb)
1192 {
1193         struct channel          *ch;
1194         struct net_device       *dev;
1195         struct ctcm_priv        *priv;
1196         struct ccwgroup_device  *cgdev;
1197         int cstat;
1198         int dstat;
1199
1200         CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
1201                 "Enter %s(%s)", CTCM_FUNTAIL, dev_name(&cdev->dev));
1202
1203         if (ctcm_check_irb_error(cdev, irb))
1204                 return;
1205
1206         cgdev = dev_get_drvdata(&cdev->dev);
1207
1208         cstat = irb->scsw.cmd.cstat;
1209         dstat = irb->scsw.cmd.dstat;
1210
1211         /* Check for unsolicited interrupts. */
1212         if (cgdev == NULL) {
1213                 CTCM_DBF_TEXT_(TRACE, CTC_DBF_ERROR,
1214                         "%s(%s) unsolicited irq: c-%02x d-%02x\n",
1215                         CTCM_FUNTAIL, dev_name(&cdev->dev), cstat, dstat);
1216                 dev_warn(&cdev->dev,
1217                         "The adapter received a non-specific IRQ\n");
1218                 return;
1219         }
1220
1221         priv = dev_get_drvdata(&cgdev->dev);
1222
1223         /* Try to extract channel from driver data. */
1224         if (priv->channel[CTCM_READ]->cdev == cdev)
1225                 ch = priv->channel[CTCM_READ];
1226         else if (priv->channel[CTCM_WRITE]->cdev == cdev)
1227                 ch = priv->channel[CTCM_WRITE];
1228         else {
1229                 dev_err(&cdev->dev,
1230                         "%s: Internal error: Can't determine channel for "
1231                         "interrupt device %s\n",
1232                         __func__, dev_name(&cdev->dev));
1233                         /* Explain: inconsistent internal structures */
1234                 return;
1235         }
1236
1237         dev = ch->netdev;
1238         if (dev == NULL) {
1239                 dev_err(&cdev->dev,
1240                         "%s Internal error: net_device is NULL, ch = 0x%p\n",
1241                         __func__, ch);
1242                         /* Explain: inconsistent internal structures */
1243                 return;
1244         }
1245
1246         /* Copy interruption response block. */
1247         memcpy(ch->irb, irb, sizeof(struct irb));
1248
1249         /* Issue error message and return on subchannel error code */
1250         if (irb->scsw.cmd.cstat) {
1251                 fsm_event(ch->fsm, CTC_EVENT_SC_UNKNOWN, ch);
1252                 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
1253                         "%s(%s): sub-ch check %s: cs=%02x ds=%02x",
1254                                 CTCM_FUNTAIL, dev->name, ch->id, cstat, dstat);
1255                 dev_warn(&cdev->dev,
1256                                 "A check occurred on the subchannel\n");
1257                 return;
1258         }
1259
1260         /* Check the reason-code of a unit check */
1261         if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
1262                 if ((irb->ecw[0] & ch->sense_rc) == 0)
1263                         /* print it only once */
1264                         CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
1265                                 "%s(%s): sense=%02x, ds=%02x",
1266                                 CTCM_FUNTAIL, ch->id, irb->ecw[0], dstat);
1267                 ccw_unit_check(ch, irb->ecw[0]);
1268                 return;
1269         }
1270         if (irb->scsw.cmd.dstat & DEV_STAT_BUSY) {
1271                 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION)
1272                         fsm_event(ch->fsm, CTC_EVENT_ATTNBUSY, ch);
1273                 else
1274                         fsm_event(ch->fsm, CTC_EVENT_BUSY, ch);
1275                 return;
1276         }
1277         if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
1278                 fsm_event(ch->fsm, CTC_EVENT_ATTN, ch);
1279                 return;
1280         }
1281         if ((irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
1282             (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
1283             (irb->scsw.cmd.stctl ==
1284              (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
1285                 fsm_event(ch->fsm, CTC_EVENT_FINSTAT, ch);
1286         else
1287                 fsm_event(ch->fsm, CTC_EVENT_IRQ, ch);
1288
1289 }
1290
1291 static const struct device_type ctcm_devtype = {
1292         .name = "ctcm",
1293         .groups = ctcm_attr_groups,
1294 };
1295
1296 /**
1297  * Add ctcm specific attributes.
1298  * Add ctcm private data.
1299  *
1300  *  cgdev       pointer to ccwgroup_device just added
1301  *
1302  * returns 0 on success, !0 on failure.
1303  */
1304 static int ctcm_probe_device(struct ccwgroup_device *cgdev)
1305 {
1306         struct ctcm_priv *priv;
1307
1308         CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1309                         "%s %p",
1310                         __func__, cgdev);
1311
1312         if (!get_device(&cgdev->dev))
1313                 return -ENODEV;
1314
1315         priv = kzalloc(sizeof(struct ctcm_priv), GFP_KERNEL);
1316         if (!priv) {
1317                 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
1318                         "%s: memory allocation failure",
1319                         CTCM_FUNTAIL);
1320                 put_device(&cgdev->dev);
1321                 return -ENOMEM;
1322         }
1323         priv->buffer_size = CTCM_BUFSIZE_DEFAULT;
1324         cgdev->cdev[0]->handler = ctcm_irq_handler;
1325         cgdev->cdev[1]->handler = ctcm_irq_handler;
1326         dev_set_drvdata(&cgdev->dev, priv);
1327         cgdev->dev.type = &ctcm_devtype;
1328
1329         return 0;
1330 }
1331
1332 /**
1333  * Add a new channel to the list of channels.
1334  * Keeps the channel list sorted.
1335  *
1336  *  cdev        The ccw_device to be added.
1337  *  type        The type class of the new channel.
1338  *  priv        Points to the private data of the ccwgroup_device.
1339  *
1340  * returns 0 on success, !0 on error.
1341  */
1342 static int add_channel(struct ccw_device *cdev, enum ctcm_channel_types type,
1343                                 struct ctcm_priv *priv)
1344 {
1345         struct channel **c = &channels;
1346         struct channel *ch;
1347         int ccw_num;
1348         int rc = 0;
1349
1350         CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1351                 "%s(%s), type %d, proto %d",
1352                         __func__, dev_name(&cdev->dev), type, priv->protocol);
1353
1354         ch = kzalloc(sizeof(struct channel), GFP_KERNEL);
1355         if (ch == NULL)
1356                 return -ENOMEM;
1357
1358         ch->protocol = priv->protocol;
1359         if (IS_MPC(priv)) {
1360                 ch->discontact_th = kzalloc(TH_HEADER_LENGTH, gfp_type());
1361                 if (ch->discontact_th == NULL)
1362                                         goto nomem_return;
1363
1364                 ch->discontact_th->th_blk_flag = TH_DISCONTACT;
1365                 tasklet_init(&ch->ch_disc_tasklet,
1366                         mpc_action_send_discontact, (unsigned long)ch);
1367
1368                 tasklet_init(&ch->ch_tasklet, ctcmpc_bh, (unsigned long)ch);
1369                 ch->max_bufsize = (MPC_BUFSIZE_DEFAULT - 35);
1370                 ccw_num = 17;
1371         } else
1372                 ccw_num = 8;
1373
1374         ch->ccw = kzalloc(ccw_num * sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
1375         if (ch->ccw == NULL)
1376                                         goto nomem_return;
1377
1378         ch->cdev = cdev;
1379         snprintf(ch->id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev->dev));
1380         ch->type = type;
1381
1382         /**
1383          * "static" ccws are used in the following way:
1384          *
1385          * ccw[0..2] (Channel program for generic I/O):
1386          *           0: prepare
1387          *           1: read or write (depending on direction) with fixed
1388          *              buffer (idal allocated once when buffer is allocated)
1389          *           2: nop
1390          * ccw[3..5] (Channel program for direct write of packets)
1391          *           3: prepare
1392          *           4: write (idal allocated on every write).
1393          *           5: nop
1394          * ccw[6..7] (Channel program for initial channel setup):
1395          *           6: set extended mode
1396          *           7: nop
1397          *
1398          * ch->ccw[0..5] are initialized in ch_action_start because
1399          * the channel's direction is yet unknown here.
1400          *
1401          * ccws used for xid2 negotiations
1402          *  ch-ccw[8-14] need to be used for the XID exchange either
1403          *    X side XID2 Processing
1404          *       8:  write control
1405          *       9:  write th
1406          *           10: write XID
1407          *           11: read th from secondary
1408          *           12: read XID   from secondary
1409          *           13: read 4 byte ID
1410          *           14: nop
1411          *    Y side XID Processing
1412          *           8:  sense
1413          *       9:  read th
1414          *           10: read XID
1415          *           11: write th
1416          *           12: write XID
1417          *           13: write 4 byte ID
1418          *           14: nop
1419          *
1420          *  ccws used for double noop due to VM timing issues
1421          *  which result in unrecoverable Busy on channel
1422          *       15: nop
1423          *       16: nop
1424          */
1425         ch->ccw[6].cmd_code     = CCW_CMD_SET_EXTENDED;
1426         ch->ccw[6].flags        = CCW_FLAG_SLI;
1427
1428         ch->ccw[7].cmd_code     = CCW_CMD_NOOP;
1429         ch->ccw[7].flags        = CCW_FLAG_SLI;
1430
1431         if (IS_MPC(priv)) {
1432                 ch->ccw[15].cmd_code = CCW_CMD_WRITE;
1433                 ch->ccw[15].flags    = CCW_FLAG_SLI | CCW_FLAG_CC;
1434                 ch->ccw[15].count    = TH_HEADER_LENGTH;
1435                 ch->ccw[15].cda      = virt_to_phys(ch->discontact_th);
1436
1437                 ch->ccw[16].cmd_code = CCW_CMD_NOOP;
1438                 ch->ccw[16].flags    = CCW_FLAG_SLI;
1439
1440                 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1441                                 ctc_ch_event_names, CTC_MPC_NR_STATES,
1442                                 CTC_MPC_NR_EVENTS, ctcmpc_ch_fsm,
1443                                 mpc_ch_fsm_len, GFP_KERNEL);
1444         } else {
1445                 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1446                                 ctc_ch_event_names, CTC_NR_STATES,
1447                                 CTC_NR_EVENTS, ch_fsm,
1448                                 ch_fsm_len, GFP_KERNEL);
1449         }
1450         if (ch->fsm == NULL)
1451                                 goto nomem_return;
1452
1453         fsm_newstate(ch->fsm, CTC_STATE_IDLE);
1454
1455         ch->irb = kzalloc(sizeof(struct irb), GFP_KERNEL);
1456         if (ch->irb == NULL)
1457                                 goto nomem_return;
1458
1459         while (*c && ctcm_less_than((*c)->id, ch->id))
1460                 c = &(*c)->next;
1461
1462         if (*c && (!strncmp((*c)->id, ch->id, CTCM_ID_SIZE))) {
1463                 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1464                                 "%s (%s) already in list, using old entry",
1465                                 __func__, (*c)->id);
1466
1467                                 goto free_return;
1468         }
1469
1470         spin_lock_init(&ch->collect_lock);
1471
1472         fsm_settimer(ch->fsm, &ch->timer);
1473         skb_queue_head_init(&ch->io_queue);
1474         skb_queue_head_init(&ch->collect_queue);
1475
1476         if (IS_MPC(priv)) {
1477                 fsm_settimer(ch->fsm, &ch->sweep_timer);
1478                 skb_queue_head_init(&ch->sweep_queue);
1479         }
1480         ch->next = *c;
1481         *c = ch;
1482         return 0;
1483
1484 nomem_return:
1485         rc = -ENOMEM;
1486
1487 free_return:    /* note that all channel pointers are 0 or valid */
1488         kfree(ch->ccw);
1489         kfree(ch->discontact_th);
1490         kfree_fsm(ch->fsm);
1491         kfree(ch->irb);
1492         kfree(ch);
1493         return rc;
1494 }
1495
1496 /*
1497  * Return type of a detected device.
1498  */
1499 static enum ctcm_channel_types get_channel_type(struct ccw_device_id *id)
1500 {
1501         enum ctcm_channel_types type;
1502         type = (enum ctcm_channel_types)id->driver_info;
1503
1504         if (type == ctcm_channel_type_ficon)
1505                 type = ctcm_channel_type_escon;
1506
1507         return type;
1508 }
1509
1510 /**
1511  *
1512  * Setup an interface.
1513  *
1514  *  cgdev       Device to be setup.
1515  *
1516  * returns 0 on success, !0 on failure.
1517  */
1518 static int ctcm_new_device(struct ccwgroup_device *cgdev)
1519 {
1520         char read_id[CTCM_ID_SIZE];
1521         char write_id[CTCM_ID_SIZE];
1522         int direction;
1523         enum ctcm_channel_types type;
1524         struct ctcm_priv *priv;
1525         struct net_device *dev;
1526         struct ccw_device *cdev0;
1527         struct ccw_device *cdev1;
1528         struct channel *readc;
1529         struct channel *writec;
1530         int ret;
1531         int result;
1532
1533         priv = dev_get_drvdata(&cgdev->dev);
1534         if (!priv) {
1535                 result = -ENODEV;
1536                 goto out_err_result;
1537         }
1538
1539         cdev0 = cgdev->cdev[0];
1540         cdev1 = cgdev->cdev[1];
1541
1542         type = get_channel_type(&cdev0->id);
1543
1544         snprintf(read_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev0->dev));
1545         snprintf(write_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev1->dev));
1546
1547         ret = add_channel(cdev0, type, priv);
1548         if (ret) {
1549                 result = ret;
1550                 goto out_err_result;
1551         }
1552         ret = add_channel(cdev1, type, priv);
1553         if (ret) {
1554                 result = ret;
1555                 goto out_remove_channel1;
1556         }
1557
1558         ret = ccw_device_set_online(cdev0);
1559         if (ret != 0) {
1560                 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
1561                         "%s(%s) set_online rc=%d",
1562                                 CTCM_FUNTAIL, read_id, ret);
1563                 result = -EIO;
1564                 goto out_remove_channel2;
1565         }
1566
1567         ret = ccw_device_set_online(cdev1);
1568         if (ret != 0) {
1569                 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
1570                         "%s(%s) set_online rc=%d",
1571                                 CTCM_FUNTAIL, write_id, ret);
1572
1573                 result = -EIO;
1574                 goto out_ccw1;
1575         }
1576
1577         dev = ctcm_init_netdevice(priv);
1578         if (dev == NULL) {
1579                 result = -ENODEV;
1580                 goto out_ccw2;
1581         }
1582
1583         for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1584                 priv->channel[direction] =
1585                         channel_get(type, direction == CTCM_READ ?
1586                                 read_id : write_id, direction);
1587                 if (priv->channel[direction] == NULL) {
1588                         if (direction == CTCM_WRITE)
1589                                 channel_free(priv->channel[CTCM_READ]);
1590                         result = -ENODEV;
1591                         goto out_dev;
1592                 }
1593                 priv->channel[direction]->netdev = dev;
1594                 priv->channel[direction]->protocol = priv->protocol;
1595                 priv->channel[direction]->max_bufsize = priv->buffer_size;
1596         }
1597         /* sysfs magic */
1598         SET_NETDEV_DEV(dev, &cgdev->dev);
1599
1600         if (register_netdev(dev)) {
1601                 result = -ENODEV;
1602                 goto out_dev;
1603         }
1604
1605         strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name));
1606
1607         dev_info(&dev->dev,
1608                 "setup OK : r/w = %s/%s, protocol : %d\n",
1609                         priv->channel[CTCM_READ]->id,
1610                         priv->channel[CTCM_WRITE]->id, priv->protocol);
1611
1612         CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1613                 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name,
1614                         priv->channel[CTCM_READ]->id,
1615                         priv->channel[CTCM_WRITE]->id, priv->protocol);
1616
1617         return 0;
1618 out_dev:
1619         ctcm_free_netdevice(dev);
1620 out_ccw2:
1621         ccw_device_set_offline(cgdev->cdev[1]);
1622 out_ccw1:
1623         ccw_device_set_offline(cgdev->cdev[0]);
1624 out_remove_channel2:
1625         readc = channel_get(type, read_id, CTCM_READ);
1626         channel_remove(readc);
1627 out_remove_channel1:
1628         writec = channel_get(type, write_id, CTCM_WRITE);
1629         channel_remove(writec);
1630 out_err_result:
1631         return result;
1632 }
1633
1634 /**
1635  * Shutdown an interface.
1636  *
1637  *  cgdev       Device to be shut down.
1638  *
1639  * returns 0 on success, !0 on failure.
1640  */
1641 static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1642 {
1643         struct ctcm_priv *priv;
1644         struct net_device *dev;
1645
1646         priv = dev_get_drvdata(&cgdev->dev);
1647         if (!priv)
1648                 return -ENODEV;
1649
1650         if (priv->channel[CTCM_READ]) {
1651                 dev = priv->channel[CTCM_READ]->netdev;
1652                 CTCM_DBF_DEV(SETUP, dev, "");
1653                 /* Close the device */
1654                 ctcm_close(dev);
1655                 dev->flags &= ~IFF_RUNNING;
1656                 channel_free(priv->channel[CTCM_READ]);
1657         } else
1658                 dev = NULL;
1659
1660         if (priv->channel[CTCM_WRITE])
1661                 channel_free(priv->channel[CTCM_WRITE]);
1662
1663         if (dev) {
1664                 unregister_netdev(dev);
1665                 ctcm_free_netdevice(dev);
1666         }
1667
1668         if (priv->fsm)
1669                 kfree_fsm(priv->fsm);
1670
1671         ccw_device_set_offline(cgdev->cdev[1]);
1672         ccw_device_set_offline(cgdev->cdev[0]);
1673         channel_remove(priv->channel[CTCM_READ]);
1674         channel_remove(priv->channel[CTCM_WRITE]);
1675         priv->channel[CTCM_READ] = priv->channel[CTCM_WRITE] = NULL;
1676
1677         return 0;
1678
1679 }
1680
1681
1682 static void ctcm_remove_device(struct ccwgroup_device *cgdev)
1683 {
1684         struct ctcm_priv *priv = dev_get_drvdata(&cgdev->dev);
1685
1686         CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1687                         "removing device %p, proto : %d",
1688                         cgdev, priv->protocol);
1689
1690         if (cgdev->state == CCWGROUP_ONLINE)
1691                 ctcm_shutdown_device(cgdev);
1692         dev_set_drvdata(&cgdev->dev, NULL);
1693         kfree(priv);
1694         put_device(&cgdev->dev);
1695 }
1696
1697 static int ctcm_pm_suspend(struct ccwgroup_device *gdev)
1698 {
1699         struct ctcm_priv *priv = dev_get_drvdata(&gdev->dev);
1700
1701         if (gdev->state == CCWGROUP_OFFLINE)
1702                 return 0;
1703         netif_device_detach(priv->channel[CTCM_READ]->netdev);
1704         ctcm_close(priv->channel[CTCM_READ]->netdev);
1705         if (!wait_event_timeout(priv->fsm->wait_q,
1706             fsm_getstate(priv->fsm) == DEV_STATE_STOPPED, CTCM_TIME_5_SEC)) {
1707                 netif_device_attach(priv->channel[CTCM_READ]->netdev);
1708                 return -EBUSY;
1709         }
1710         ccw_device_set_offline(gdev->cdev[1]);
1711         ccw_device_set_offline(gdev->cdev[0]);
1712         return 0;
1713 }
1714
1715 static int ctcm_pm_resume(struct ccwgroup_device *gdev)
1716 {
1717         struct ctcm_priv *priv = dev_get_drvdata(&gdev->dev);
1718         int rc;
1719
1720         if (gdev->state == CCWGROUP_OFFLINE)
1721                 return 0;
1722         rc = ccw_device_set_online(gdev->cdev[1]);
1723         if (rc)
1724                 goto err_out;
1725         rc = ccw_device_set_online(gdev->cdev[0]);
1726         if (rc)
1727                 goto err_out;
1728         ctcm_open(priv->channel[CTCM_READ]->netdev);
1729 err_out:
1730         netif_device_attach(priv->channel[CTCM_READ]->netdev);
1731         return rc;
1732 }
1733
1734 static struct ccw_device_id ctcm_ids[] = {
1735         {CCW_DEVICE(0x3088, 0x08), .driver_info = ctcm_channel_type_parallel},
1736         {CCW_DEVICE(0x3088, 0x1e), .driver_info = ctcm_channel_type_ficon},
1737         {CCW_DEVICE(0x3088, 0x1f), .driver_info = ctcm_channel_type_escon},
1738         {},
1739 };
1740 MODULE_DEVICE_TABLE(ccw, ctcm_ids);
1741
1742 static struct ccw_driver ctcm_ccw_driver = {
1743         .driver = {
1744                 .owner  = THIS_MODULE,
1745                 .name   = "ctcm",
1746         },
1747         .ids    = ctcm_ids,
1748         .probe  = ccwgroup_probe_ccwdev,
1749         .remove = ccwgroup_remove_ccwdev,
1750         .int_class = IRQIO_CTC,
1751 };
1752
1753 static struct ccwgroup_driver ctcm_group_driver = {
1754         .driver = {
1755                 .owner  = THIS_MODULE,
1756                 .name   = CTC_DRIVER_NAME,
1757         },
1758         .setup       = ctcm_probe_device,
1759         .remove      = ctcm_remove_device,
1760         .set_online  = ctcm_new_device,
1761         .set_offline = ctcm_shutdown_device,
1762         .freeze      = ctcm_pm_suspend,
1763         .thaw        = ctcm_pm_resume,
1764         .restore     = ctcm_pm_resume,
1765 };
1766
1767 static ssize_t group_store(struct device_driver *ddrv, const char *buf,
1768                            size_t count)
1769 {
1770         int err;
1771
1772         err = ccwgroup_create_dev(ctcm_root_dev, &ctcm_group_driver, 2, buf);
1773         return err ? err : count;
1774 }
1775 static DRIVER_ATTR_WO(group);
1776
1777 static struct attribute *ctcm_drv_attrs[] = {
1778         &driver_attr_group.attr,
1779         NULL,
1780 };
1781 static struct attribute_group ctcm_drv_attr_group = {
1782         .attrs = ctcm_drv_attrs,
1783 };
1784 static const struct attribute_group *ctcm_drv_attr_groups[] = {
1785         &ctcm_drv_attr_group,
1786         NULL,
1787 };
1788
1789 /*
1790  * Module related routines
1791  */
1792
1793 /*
1794  * Prepare to be unloaded. Free IRQ's and release all resources.
1795  * This is called just before this module is unloaded. It is
1796  * not called, if the usage count is !0, so we don't need to check
1797  * for that.
1798  */
1799 static void __exit ctcm_exit(void)
1800 {
1801         ccwgroup_driver_unregister(&ctcm_group_driver);
1802         ccw_driver_unregister(&ctcm_ccw_driver);
1803         root_device_unregister(ctcm_root_dev);
1804         ctcm_unregister_dbf_views();
1805         pr_info("CTCM driver unloaded\n");
1806 }
1807
1808 /*
1809  * Print Banner.
1810  */
1811 static void print_banner(void)
1812 {
1813         pr_info("CTCM driver initialized\n");
1814 }
1815
1816 /**
1817  * Initialize module.
1818  * This is called just after the module is loaded.
1819  *
1820  * returns 0 on success, !0 on error.
1821  */
1822 static int __init ctcm_init(void)
1823 {
1824         int ret;
1825
1826         channels = NULL;
1827
1828         ret = ctcm_register_dbf_views();
1829         if (ret)
1830                 goto out_err;
1831         ctcm_root_dev = root_device_register("ctcm");
1832         ret = PTR_ERR_OR_ZERO(ctcm_root_dev);
1833         if (ret)
1834                 goto register_err;
1835         ret = ccw_driver_register(&ctcm_ccw_driver);
1836         if (ret)
1837                 goto ccw_err;
1838         ctcm_group_driver.driver.groups = ctcm_drv_attr_groups;
1839         ret = ccwgroup_driver_register(&ctcm_group_driver);
1840         if (ret)
1841                 goto ccwgroup_err;
1842         print_banner();
1843         return 0;
1844
1845 ccwgroup_err:
1846         ccw_driver_unregister(&ctcm_ccw_driver);
1847 ccw_err:
1848         root_device_unregister(ctcm_root_dev);
1849 register_err:
1850         ctcm_unregister_dbf_views();
1851 out_err:
1852         pr_err("%s / Initializing the ctcm device driver failed, ret = %d\n",
1853                 __func__, ret);
1854         return ret;
1855 }
1856
1857 module_init(ctcm_init);
1858 module_exit(ctcm_exit);
1859
1860 MODULE_AUTHOR("Peter Tiedemann <ptiedem@de.ibm.com>");
1861 MODULE_DESCRIPTION("Network driver for S/390 CTC + CTCMPC (SNA)");
1862 MODULE_LICENSE("GPL");
1863