blob: 84777e369a29b3c94d3952cd684fca9d09a290eb [file] [log] [blame]
Peter Tiedemann293d9842008-02-08 00:03:49 +01001/*
2 * drivers/s390/net/ctcm_main.c
3 *
Frank Blaschkab8a2d422009-06-16 10:30:32 +02004 * Copyright IBM Corp. 2001, 2009
Peter Tiedemann293d9842008-02-08 00:03:49 +01005 * Author(s):
6 * Original CTC driver(s):
7 * Fritz Elfert (felfert@millenux.com)
8 * Dieter Wellerdiek (wel@de.ibm.com)
9 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 * Denis Joseph Barrow (barrow_dj@yahoo.com)
11 * Jochen Roehrig (roehrig@de.ibm.com)
12 * Cornelia Huck <cornelia.huck@de.ibm.com>
13 * MPC additions:
14 * Belinda Thompson (belindat@us.ibm.com)
15 * Andy Richter (richtera@us.ibm.com)
16 * Revived by:
17 * Peter Tiedemann (ptiedem@de.ibm.com)
18 */
19
20#undef DEBUG
21#undef DEBUGDATA
22#undef DEBUGCCW
23
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +010024#define KMSG_COMPONENT "ctcm"
25#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
26
Peter Tiedemann293d9842008-02-08 00:03:49 +010027#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/slab.h>
31#include <linux/errno.h>
32#include <linux/types.h>
33#include <linux/interrupt.h>
34#include <linux/timer.h>
35#include <linux/bitops.h>
36
37#include <linux/signal.h>
38#include <linux/string.h>
39
40#include <linux/ip.h>
41#include <linux/if_arp.h>
42#include <linux/tcp.h>
43#include <linux/skbuff.h>
44#include <linux/ctype.h>
45#include <net/dst.h>
46
47#include <linux/io.h>
48#include <asm/ccwdev.h>
49#include <asm/ccwgroup.h>
50#include <linux/uaccess.h>
51
52#include <asm/idals.h>
53
Peter Tiedemann293d9842008-02-08 00:03:49 +010054#include "ctcm_fsms.h"
55#include "ctcm_main.h"
56
57/* Some common global variables */
58
Ursula Braun0ca8cc62009-11-12 21:46:29 +000059/**
60 * The root device for ctcm group devices
61 */
62static struct device *ctcm_root_dev;
63
Peter Tiedemann293d9842008-02-08 00:03:49 +010064/*
65 * Linked list of all detected channels.
66 */
67struct channel *channels;
68
69/**
70 * Unpack a just received skb and hand it over to
71 * upper layers.
72 *
73 * ch The channel where this skb has been received.
74 * pskb The received skb.
75 */
76void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb)
77{
78 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +020079 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +010080 __u16 len = *((__u16 *) pskb->data);
81
82 skb_put(pskb, 2 + LL_HEADER_LENGTH);
83 skb_pull(pskb, 2);
84 pskb->dev = dev;
85 pskb->ip_summed = CHECKSUM_UNNECESSARY;
86 while (len > 0) {
87 struct sk_buff *skb;
88 int skblen;
89 struct ll_header *header = (struct ll_header *)pskb->data;
90
91 skb_pull(pskb, LL_HEADER_LENGTH);
92 if ((ch->protocol == CTCM_PROTO_S390) &&
93 (header->type != ETH_P_IP)) {
Peter Tiedemann293d9842008-02-08 00:03:49 +010094 if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +020095 ch->logflags |= LOG_FLAG_ILLEGALPKT;
Peter Tiedemann293d9842008-02-08 00:03:49 +010096 /*
97 * Check packet type only if we stick strictly
98 * to S/390's protocol of OS390. This only
99 * supports IP. Otherwise allow any packet
100 * type.
101 */
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200102 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
103 "%s(%s): Illegal packet type 0x%04x"
104 " - dropping",
105 CTCM_FUNTAIL, dev->name, header->type);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100106 }
Peter Tiedemann293d9842008-02-08 00:03:49 +0100107 priv->stats.rx_dropped++;
108 priv->stats.rx_frame_errors++;
109 return;
110 }
111 pskb->protocol = ntohs(header->type);
Roel Kluinfb8585f2009-03-24 03:27:48 +0000112 if ((header->length <= LL_HEADER_LENGTH) ||
113 (len <= LL_HEADER_LENGTH)) {
Peter Tiedemann293d9842008-02-08 00:03:49 +0100114 if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200115 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
116 "%s(%s): Illegal packet size %d(%d,%d)"
117 "- dropping",
118 CTCM_FUNTAIL, dev->name,
119 header->length, dev->mtu, len);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100120 ch->logflags |= LOG_FLAG_ILLEGALSIZE;
121 }
122
123 priv->stats.rx_dropped++;
124 priv->stats.rx_length_errors++;
125 return;
126 }
127 header->length -= LL_HEADER_LENGTH;
128 len -= LL_HEADER_LENGTH;
129 if ((header->length > skb_tailroom(pskb)) ||
130 (header->length > len)) {
131 if (!(ch->logflags & LOG_FLAG_OVERRUN)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200132 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
133 "%s(%s): Packet size %d (overrun)"
134 " - dropping", CTCM_FUNTAIL,
135 dev->name, header->length);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100136 ch->logflags |= LOG_FLAG_OVERRUN;
137 }
138
139 priv->stats.rx_dropped++;
140 priv->stats.rx_length_errors++;
141 return;
142 }
143 skb_put(pskb, header->length);
144 skb_reset_mac_header(pskb);
145 len -= header->length;
146 skb = dev_alloc_skb(pskb->len);
147 if (!skb) {
148 if (!(ch->logflags & LOG_FLAG_NOMEM)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200149 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
150 "%s(%s): MEMORY allocation error",
151 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100152 ch->logflags |= LOG_FLAG_NOMEM;
153 }
154 priv->stats.rx_dropped++;
155 return;
156 }
157 skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len),
158 pskb->len);
159 skb_reset_mac_header(skb);
160 skb->dev = pskb->dev;
161 skb->protocol = pskb->protocol;
162 pskb->ip_summed = CHECKSUM_UNNECESSARY;
163 skblen = skb->len;
164 /*
165 * reset logflags
166 */
167 ch->logflags = 0;
168 priv->stats.rx_packets++;
169 priv->stats.rx_bytes += skblen;
170 netif_rx_ni(skb);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100171 if (len > 0) {
172 skb_pull(pskb, header->length);
173 if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
Joel A. Fowlere2fc8cb2009-03-24 03:27:49 +0000174 CTCM_DBF_DEV_NAME(TRACE, dev,
175 "Overrun in ctcm_unpack_skb");
176 ch->logflags |= LOG_FLAG_OVERRUN;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100177 return;
178 }
179 skb_put(pskb, LL_HEADER_LENGTH);
180 }
181 }
182}
183
184/**
185 * Release a specific channel in the channel list.
186 *
187 * ch Pointer to channel struct to be released.
188 */
189static void channel_free(struct channel *ch)
190{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200191 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s)", CTCM_FUNTAIL, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100192 ch->flags &= ~CHANNEL_FLAGS_INUSE;
193 fsm_newstate(ch->fsm, CTC_STATE_IDLE);
194}
195
196/**
197 * Remove a specific channel in the channel list.
198 *
199 * ch Pointer to channel struct to be released.
200 */
201static void channel_remove(struct channel *ch)
202{
203 struct channel **c = &channels;
204 char chid[CTCM_ID_SIZE+1];
205 int ok = 0;
206
207 if (ch == NULL)
208 return;
209 else
210 strncpy(chid, ch->id, CTCM_ID_SIZE);
211
212 channel_free(ch);
213 while (*c) {
214 if (*c == ch) {
215 *c = ch->next;
216 fsm_deltimer(&ch->timer);
217 if (IS_MPC(ch))
218 fsm_deltimer(&ch->sweep_timer);
219
220 kfree_fsm(ch->fsm);
221 clear_normalized_cda(&ch->ccw[4]);
222 if (ch->trans_skb != NULL) {
223 clear_normalized_cda(&ch->ccw[1]);
224 dev_kfree_skb_any(ch->trans_skb);
225 }
226 if (IS_MPC(ch)) {
227 tasklet_kill(&ch->ch_tasklet);
228 tasklet_kill(&ch->ch_disc_tasklet);
229 kfree(ch->discontact_th);
230 }
231 kfree(ch->ccw);
232 kfree(ch->irb);
233 kfree(ch);
234 ok = 1;
235 break;
236 }
237 c = &((*c)->next);
238 }
239
240 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s) %s", CTCM_FUNTAIL,
241 chid, ok ? "OK" : "failed");
242}
243
244/**
245 * Get a specific channel from the channel list.
246 *
247 * type Type of channel we are interested in.
248 * id Id of channel we are interested in.
249 * direction Direction we want to use this channel for.
250 *
251 * returns Pointer to a channel or NULL if no matching channel available.
252 */
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000253static struct channel *channel_get(enum ctcm_channel_types type,
Peter Tiedemann293d9842008-02-08 00:03:49 +0100254 char *id, int direction)
255{
256 struct channel *ch = channels;
257
Peter Tiedemann293d9842008-02-08 00:03:49 +0100258 while (ch && (strncmp(ch->id, id, CTCM_ID_SIZE) || (ch->type != type)))
259 ch = ch->next;
260 if (!ch) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200261 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
262 "%s(%d, %s, %d) not found in channel list\n",
Peter Tiedemann293d9842008-02-08 00:03:49 +0100263 CTCM_FUNTAIL, type, id, direction);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100264 } else {
265 if (ch->flags & CHANNEL_FLAGS_INUSE)
266 ch = NULL;
267 else {
268 ch->flags |= CHANNEL_FLAGS_INUSE;
269 ch->flags &= ~CHANNEL_FLAGS_RWMASK;
Ursula Braun3c09e262010-08-12 01:58:28 +0000270 ch->flags |= (direction == CTCM_WRITE)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100271 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
272 fsm_newstate(ch->fsm, CTC_STATE_STOPPED);
273 }
274 }
275 return ch;
276}
277
278static long ctcm_check_irb_error(struct ccw_device *cdev, struct irb *irb)
279{
280 if (!IS_ERR(irb))
281 return 0;
282
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200283 CTCM_DBF_TEXT_(ERROR, CTC_DBF_WARN,
284 "irb error %ld on device %s\n",
Kay Sievers2a0217d2008-10-10 21:33:09 +0200285 PTR_ERR(irb), dev_name(&cdev->dev));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100286
287 switch (PTR_ERR(irb)) {
288 case -EIO:
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +0100289 dev_err(&cdev->dev,
290 "An I/O-error occurred on the CTCM device\n");
Peter Tiedemann293d9842008-02-08 00:03:49 +0100291 break;
292 case -ETIMEDOUT:
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +0100293 dev_err(&cdev->dev,
294 "An adapter hardware operation timed out\n");
Peter Tiedemann293d9842008-02-08 00:03:49 +0100295 break;
296 default:
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +0100297 dev_err(&cdev->dev,
298 "An error occurred on the adapter hardware\n");
Peter Tiedemann293d9842008-02-08 00:03:49 +0100299 }
300 return PTR_ERR(irb);
301}
302
303
304/**
305 * Check sense of a unit check.
306 *
307 * ch The channel, the sense code belongs to.
308 * sense The sense code to inspect.
309 */
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200310static inline void ccw_unit_check(struct channel *ch, __u8 sense)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100311{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200312 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
313 "%s(%s): %02x",
314 CTCM_FUNTAIL, ch->id, sense);
315
Peter Tiedemann293d9842008-02-08 00:03:49 +0100316 if (sense & SNS0_INTERVENTION_REQ) {
317 if (sense & 0x01) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200318 if (ch->sense_rc != 0x01) {
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +0100319 pr_notice(
320 "%s: The communication peer has "
321 "disconnected\n", ch->id);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200322 ch->sense_rc = 0x01;
323 }
Peter Tiedemann293d9842008-02-08 00:03:49 +0100324 fsm_event(ch->fsm, CTC_EVENT_UC_RCRESET, ch);
325 } else {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200326 if (ch->sense_rc != SNS0_INTERVENTION_REQ) {
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +0100327 pr_notice(
328 "%s: The remote operating system is "
329 "not available\n", ch->id);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200330 ch->sense_rc = SNS0_INTERVENTION_REQ;
331 }
Peter Tiedemann293d9842008-02-08 00:03:49 +0100332 fsm_event(ch->fsm, CTC_EVENT_UC_RSRESET, ch);
333 }
334 } else if (sense & SNS0_EQUIPMENT_CHECK) {
335 if (sense & SNS0_BUS_OUT_CHECK) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200336 if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
337 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
338 "%s(%s): remote HW error %02x",
339 CTCM_FUNTAIL, ch->id, sense);
340 ch->sense_rc = SNS0_BUS_OUT_CHECK;
341 }
Peter Tiedemann293d9842008-02-08 00:03:49 +0100342 fsm_event(ch->fsm, CTC_EVENT_UC_HWFAIL, ch);
343 } else {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200344 if (ch->sense_rc != SNS0_EQUIPMENT_CHECK) {
345 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
346 "%s(%s): remote read parity error %02x",
347 CTCM_FUNTAIL, ch->id, sense);
348 ch->sense_rc = SNS0_EQUIPMENT_CHECK;
349 }
Peter Tiedemann293d9842008-02-08 00:03:49 +0100350 fsm_event(ch->fsm, CTC_EVENT_UC_RXPARITY, ch);
351 }
352 } else if (sense & SNS0_BUS_OUT_CHECK) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200353 if (ch->sense_rc != SNS0_BUS_OUT_CHECK) {
354 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
355 "%s(%s): BUS OUT error %02x",
356 CTCM_FUNTAIL, ch->id, sense);
357 ch->sense_rc = SNS0_BUS_OUT_CHECK;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100358 }
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200359 if (sense & 0x04) /* data-streaming timeout */
360 fsm_event(ch->fsm, CTC_EVENT_UC_TXTIMEOUT, ch);
361 else /* Data-transfer parity error */
362 fsm_event(ch->fsm, CTC_EVENT_UC_TXPARITY, ch);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100363 } else if (sense & SNS0_CMD_REJECT) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200364 if (ch->sense_rc != SNS0_CMD_REJECT) {
365 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
366 "%s(%s): Command rejected",
367 CTCM_FUNTAIL, ch->id);
368 ch->sense_rc = SNS0_CMD_REJECT;
369 }
Peter Tiedemann293d9842008-02-08 00:03:49 +0100370 } else if (sense == 0) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200371 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
372 "%s(%s): Unit check ZERO",
373 CTCM_FUNTAIL, ch->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100374 fsm_event(ch->fsm, CTC_EVENT_UC_ZERO, ch);
375 } else {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200376 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
377 "%s(%s): Unit check code %02x unknown",
378 CTCM_FUNTAIL, ch->id, sense);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100379 fsm_event(ch->fsm, CTC_EVENT_UC_UNKNOWN, ch);
380 }
381}
382
383int ctcm_ch_alloc_buffer(struct channel *ch)
384{
Peter Tiedemann293d9842008-02-08 00:03:49 +0100385 clear_normalized_cda(&ch->ccw[1]);
386 ch->trans_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC | GFP_DMA);
387 if (ch->trans_skb == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200388 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
389 "%s(%s): %s trans_skb allocation error",
390 CTCM_FUNTAIL, ch->id,
Ursula Braun3c09e262010-08-12 01:58:28 +0000391 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
392 "RX" : "TX");
Peter Tiedemann293d9842008-02-08 00:03:49 +0100393 return -ENOMEM;
394 }
395
396 ch->ccw[1].count = ch->max_bufsize;
397 if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) {
398 dev_kfree_skb(ch->trans_skb);
399 ch->trans_skb = NULL;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200400 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
401 "%s(%s): %s set norm_cda failed",
402 CTCM_FUNTAIL, ch->id,
Ursula Braun3c09e262010-08-12 01:58:28 +0000403 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
404 "RX" : "TX");
Peter Tiedemann293d9842008-02-08 00:03:49 +0100405 return -ENOMEM;
406 }
407
408 ch->ccw[1].count = 0;
409 ch->trans_skb_data = ch->trans_skb->data;
410 ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED;
411 return 0;
412}
413
414/*
415 * Interface API for upper network layers
416 */
417
418/**
419 * Open an interface.
420 * Called from generic network layer when ifconfig up is run.
421 *
422 * dev Pointer to interface struct.
423 *
424 * returns 0 on success, -ERRNO on failure. (Never fails.)
425 */
426int ctcm_open(struct net_device *dev)
427{
Peter Tiedemann261893d2008-08-21 17:10:24 +0200428 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100429
430 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
431 if (!IS_MPC(priv))
432 fsm_event(priv->fsm, DEV_EVENT_START, dev);
433 return 0;
434}
435
436/**
437 * Close an interface.
438 * Called from generic network layer when ifconfig down is run.
439 *
440 * dev Pointer to interface struct.
441 *
442 * returns 0 on success, -ERRNO on failure. (Never fails.)
443 */
444int ctcm_close(struct net_device *dev)
445{
Peter Tiedemann261893d2008-08-21 17:10:24 +0200446 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100447
448 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
449 if (!IS_MPC(priv))
450 fsm_event(priv->fsm, DEV_EVENT_STOP, dev);
451 return 0;
452}
453
454
455/**
456 * Transmit a packet.
457 * This is a helper function for ctcm_tx().
458 *
459 * ch Channel to be used for sending.
460 * skb Pointer to struct sk_buff of packet to send.
461 * The linklevel header has already been set up
462 * by ctcm_tx().
463 *
464 * returns 0 on success, -ERRNO on failure. (Never fails.)
465 */
466static int ctcm_transmit_skb(struct channel *ch, struct sk_buff *skb)
467{
468 unsigned long saveflags;
469 struct ll_header header;
470 int rc = 0;
471 __u16 block_len;
472 int ccw_idx;
473 struct sk_buff *nskb;
474 unsigned long hi;
475
476 /* we need to acquire the lock for testing the state
477 * otherwise we can have an IRQ changing the state to
478 * TXIDLE after the test but before acquiring the lock.
479 */
480 spin_lock_irqsave(&ch->collect_lock, saveflags);
481 if (fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) {
482 int l = skb->len + LL_HEADER_LENGTH;
483
484 if (ch->collect_len + l > ch->max_bufsize - 2) {
485 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
486 return -EBUSY;
487 } else {
488 atomic_inc(&skb->users);
489 header.length = l;
490 header.type = skb->protocol;
491 header.unused = 0;
492 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header,
493 LL_HEADER_LENGTH);
494 skb_queue_tail(&ch->collect_queue, skb);
495 ch->collect_len += l;
496 }
497 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
498 goto done;
499 }
500 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
501 /*
502 * Protect skb against beeing free'd by upper
503 * layers.
504 */
505 atomic_inc(&skb->users);
506 ch->prof.txlen += skb->len;
507 header.length = skb->len + LL_HEADER_LENGTH;
508 header.type = skb->protocol;
509 header.unused = 0;
510 memcpy(skb_push(skb, LL_HEADER_LENGTH), &header, LL_HEADER_LENGTH);
511 block_len = skb->len + 2;
512 *((__u16 *)skb_push(skb, 2)) = block_len;
513
514 /*
515 * IDAL support in CTCM is broken, so we have to
516 * care about skb's above 2G ourselves.
517 */
518 hi = ((unsigned long)skb_tail_pointer(skb) + LL_HEADER_LENGTH) >> 31;
519 if (hi) {
520 nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
521 if (!nskb) {
522 atomic_dec(&skb->users);
523 skb_pull(skb, LL_HEADER_LENGTH + 2);
524 ctcm_clear_busy(ch->netdev);
525 return -ENOMEM;
526 } else {
527 memcpy(skb_put(nskb, skb->len), skb->data, skb->len);
528 atomic_inc(&nskb->users);
529 atomic_dec(&skb->users);
530 dev_kfree_skb_irq(skb);
531 skb = nskb;
532 }
533 }
534
535 ch->ccw[4].count = block_len;
536 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
537 /*
538 * idal allocation failed, try via copying to
539 * trans_skb. trans_skb usually has a pre-allocated
540 * idal.
541 */
542 if (ctcm_checkalloc_buffer(ch)) {
543 /*
544 * Remove our header. It gets added
545 * again on retransmit.
546 */
547 atomic_dec(&skb->users);
548 skb_pull(skb, LL_HEADER_LENGTH + 2);
549 ctcm_clear_busy(ch->netdev);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200550 return -ENOMEM;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100551 }
552
553 skb_reset_tail_pointer(ch->trans_skb);
554 ch->trans_skb->len = 0;
555 ch->ccw[1].count = skb->len;
556 skb_copy_from_linear_data(skb,
557 skb_put(ch->trans_skb, skb->len), skb->len);
558 atomic_dec(&skb->users);
559 dev_kfree_skb_irq(skb);
560 ccw_idx = 0;
561 } else {
562 skb_queue_tail(&ch->io_queue, skb);
563 ccw_idx = 3;
564 }
Ursula Braunce1f8932012-03-07 02:06:26 +0000565 if (do_debug_ccw)
566 ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
567 sizeof(struct ccw1) * 3);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100568 ch->retry = 0;
569 fsm_newstate(ch->fsm, CTC_STATE_TX);
570 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
571 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
572 ch->prof.send_stamp = current_kernel_time(); /* xtime */
573 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
574 (unsigned long)ch, 0xff, 0);
575 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
576 if (ccw_idx == 3)
577 ch->prof.doios_single++;
578 if (rc != 0) {
579 fsm_deltimer(&ch->timer);
580 ctcm_ccw_check_rc(ch, rc, "single skb TX");
581 if (ccw_idx == 3)
582 skb_dequeue_tail(&ch->io_queue);
583 /*
584 * Remove our header. It gets added
585 * again on retransmit.
586 */
587 skb_pull(skb, LL_HEADER_LENGTH + 2);
588 } else if (ccw_idx == 0) {
589 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200590 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100591 priv->stats.tx_packets++;
592 priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH;
593 }
594done:
595 ctcm_clear_busy(ch->netdev);
596 return rc;
597}
598
599static void ctcmpc_send_sweep_req(struct channel *rch)
600{
601 struct net_device *dev = rch->netdev;
602 struct ctcm_priv *priv;
603 struct mpc_group *grp;
604 struct th_sweep *header;
605 struct sk_buff *sweep_skb;
606 struct channel *ch;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200607 /* int rc = 0; */
Peter Tiedemann293d9842008-02-08 00:03:49 +0100608
Peter Tiedemann261893d2008-08-21 17:10:24 +0200609 priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100610 grp = priv->mpcg;
Ursula Braun3c09e262010-08-12 01:58:28 +0000611 ch = priv->channel[CTCM_WRITE];
Peter Tiedemann293d9842008-02-08 00:03:49 +0100612
Peter Tiedemann293d9842008-02-08 00:03:49 +0100613 /* sweep processing is not complete until response and request */
614 /* has completed for all read channels in group */
615 if (grp->in_sweep == 0) {
616 grp->in_sweep = 1;
Ursula Braun3c09e262010-08-12 01:58:28 +0000617 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
618 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
Peter Tiedemann293d9842008-02-08 00:03:49 +0100619 }
620
621 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
622
623 if (sweep_skb == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200624 /* rc = -ENOMEM; */
625 goto nomem;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100626 }
627
628 header = kmalloc(TH_SWEEP_LENGTH, gfp_type());
629
630 if (!header) {
631 dev_kfree_skb_any(sweep_skb);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200632 /* rc = -ENOMEM; */
633 goto nomem;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100634 }
635
636 header->th.th_seg = 0x00 ;
637 header->th.th_ch_flag = TH_SWEEP_REQ; /* 0x0f */
638 header->th.th_blk_flag = 0x00;
639 header->th.th_is_xid = 0x00;
640 header->th.th_seq_num = 0x00;
641 header->sw.th_last_seq = ch->th_seq_num;
642
643 memcpy(skb_put(sweep_skb, TH_SWEEP_LENGTH), header, TH_SWEEP_LENGTH);
644
645 kfree(header);
646
647 dev->trans_start = jiffies;
648 skb_queue_tail(&ch->sweep_queue, sweep_skb);
649
650 fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch);
651
652 return;
653
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200654nomem:
655 grp->in_sweep = 0;
656 ctcm_clear_busy(dev);
657 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100658
659 return;
660}
661
662/*
663 * MPC mode version of transmit_skb
664 */
665static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb)
666{
667 struct pdu *p_header;
668 struct net_device *dev = ch->netdev;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200669 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100670 struct mpc_group *grp = priv->mpcg;
671 struct th_header *header;
672 struct sk_buff *nskb;
673 int rc = 0;
674 int ccw_idx;
675 unsigned long hi;
676 unsigned long saveflags = 0; /* avoids compiler warning */
Peter Tiedemann293d9842008-02-08 00:03:49 +0100677
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200678 CTCM_PR_DEBUG("Enter %s: %s, cp=%i ch=0x%p id=%s state=%s\n",
679 __func__, dev->name, smp_processor_id(), ch,
680 ch->id, fsm_getstate_str(ch->fsm));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100681
682 if ((fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) || grp->in_sweep) {
683 spin_lock_irqsave(&ch->collect_lock, saveflags);
684 atomic_inc(&skb->users);
685 p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
686
687 if (!p_header) {
Peter Tiedemann293d9842008-02-08 00:03:49 +0100688 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200689 goto nomem_exit;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100690 }
691
692 p_header->pdu_offset = skb->len;
693 p_header->pdu_proto = 0x01;
694 p_header->pdu_flag = 0x00;
695 if (skb->protocol == ntohs(ETH_P_SNAP)) {
696 p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
697 } else {
698 p_header->pdu_flag |= PDU_FIRST;
699 }
700 p_header->pdu_seq = 0;
701 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header,
702 PDU_HEADER_LENGTH);
703
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200704 CTCM_PR_DEBUG("%s(%s): Put on collect_q - skb len: %04x \n"
705 "pdu header and data for up to 32 bytes:\n",
706 __func__, dev->name, skb->len);
707 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100708
709 skb_queue_tail(&ch->collect_queue, skb);
710 ch->collect_len += skb->len;
711 kfree(p_header);
712
713 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
714 goto done;
715 }
716
717 /*
718 * Protect skb against beeing free'd by upper
719 * layers.
720 */
721 atomic_inc(&skb->users);
722
Peter Tiedemann293d9842008-02-08 00:03:49 +0100723 /*
724 * IDAL support in CTCM is broken, so we have to
725 * care about skb's above 2G ourselves.
726 */
727 hi = ((unsigned long)skb->tail + TH_HEADER_LENGTH) >> 31;
728 if (hi) {
729 nskb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA);
730 if (!nskb) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200731 goto nomem_exit;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100732 } else {
733 memcpy(skb_put(nskb, skb->len), skb->data, skb->len);
734 atomic_inc(&nskb->users);
735 atomic_dec(&skb->users);
736 dev_kfree_skb_irq(skb);
737 skb = nskb;
738 }
739 }
740
741 p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type());
742
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200743 if (!p_header)
744 goto nomem_exit;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100745
746 p_header->pdu_offset = skb->len;
747 p_header->pdu_proto = 0x01;
748 p_header->pdu_flag = 0x00;
749 p_header->pdu_seq = 0;
750 if (skb->protocol == ntohs(ETH_P_SNAP)) {
751 p_header->pdu_flag |= PDU_FIRST | PDU_CNTL;
752 } else {
753 p_header->pdu_flag |= PDU_FIRST;
754 }
755 memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, PDU_HEADER_LENGTH);
756
757 kfree(p_header);
758
759 if (ch->collect_len > 0) {
760 spin_lock_irqsave(&ch->collect_lock, saveflags);
761 skb_queue_tail(&ch->collect_queue, skb);
762 ch->collect_len += skb->len;
763 skb = skb_dequeue(&ch->collect_queue);
764 ch->collect_len -= skb->len;
765 spin_unlock_irqrestore(&ch->collect_lock, saveflags);
766 }
767
768 p_header = (struct pdu *)skb->data;
769 p_header->pdu_flag |= PDU_LAST;
770
771 ch->prof.txlen += skb->len - PDU_HEADER_LENGTH;
772
773 header = kmalloc(TH_HEADER_LENGTH, gfp_type());
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200774 if (!header)
775 goto nomem_exit;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100776
777 header->th_seg = 0x00;
778 header->th_ch_flag = TH_HAS_PDU; /* Normal data */
779 header->th_blk_flag = 0x00;
780 header->th_is_xid = 0x00; /* Just data here */
781 ch->th_seq_num++;
782 header->th_seq_num = ch->th_seq_num;
783
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200784 CTCM_PR_DBGDATA("%s(%s) ToVTAM_th_seq= %08x\n" ,
785 __func__, dev->name, ch->th_seq_num);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100786
787 /* put the TH on the packet */
788 memcpy(skb_push(skb, TH_HEADER_LENGTH), header, TH_HEADER_LENGTH);
789
790 kfree(header);
791
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200792 CTCM_PR_DBGDATA("%s(%s): skb len: %04x\n - pdu header and data for "
793 "up to 32 bytes sent to vtam:\n",
794 __func__, dev->name, skb->len);
795 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100796
797 ch->ccw[4].count = skb->len;
798 if (set_normalized_cda(&ch->ccw[4], skb->data)) {
799 /*
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200800 * idal allocation failed, try via copying to trans_skb.
801 * trans_skb usually has a pre-allocated idal.
Peter Tiedemann293d9842008-02-08 00:03:49 +0100802 */
803 if (ctcm_checkalloc_buffer(ch)) {
804 /*
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200805 * Remove our header.
806 * It gets added again on retransmit.
Peter Tiedemann293d9842008-02-08 00:03:49 +0100807 */
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200808 goto nomem_exit;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100809 }
810
811 skb_reset_tail_pointer(ch->trans_skb);
812 ch->trans_skb->len = 0;
813 ch->ccw[1].count = skb->len;
814 memcpy(skb_put(ch->trans_skb, skb->len), skb->data, skb->len);
815 atomic_dec(&skb->users);
816 dev_kfree_skb_irq(skb);
817 ccw_idx = 0;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200818 CTCM_PR_DBGDATA("%s(%s): trans_skb len: %04x\n"
819 "up to 32 bytes sent to vtam:\n",
820 __func__, dev->name, ch->trans_skb->len);
821 CTCM_D3_DUMP((char *)ch->trans_skb->data,
822 min_t(int, 32, ch->trans_skb->len));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100823 } else {
824 skb_queue_tail(&ch->io_queue, skb);
825 ccw_idx = 3;
826 }
827 ch->retry = 0;
828 fsm_newstate(ch->fsm, CTC_STATE_TX);
829 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
830
831 if (do_debug_ccw)
832 ctcmpc_dumpit((char *)&ch->ccw[ccw_idx],
833 sizeof(struct ccw1) * 3);
834
835 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
836 ch->prof.send_stamp = current_kernel_time(); /* xtime */
837 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
838 (unsigned long)ch, 0xff, 0);
839 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
840 if (ccw_idx == 3)
841 ch->prof.doios_single++;
842 if (rc != 0) {
843 fsm_deltimer(&ch->timer);
844 ctcm_ccw_check_rc(ch, rc, "single skb TX");
845 if (ccw_idx == 3)
846 skb_dequeue_tail(&ch->io_queue);
847 } else if (ccw_idx == 0) {
848 priv->stats.tx_packets++;
849 priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH;
850 }
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200851 if (ch->th_seq_num > 0xf0000000) /* Chose at random. */
Peter Tiedemann293d9842008-02-08 00:03:49 +0100852 ctcmpc_send_sweep_req(ch);
853
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200854 goto done;
855nomem_exit:
856 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_CRIT,
857 "%s(%s): MEMORY allocation ERROR\n",
858 CTCM_FUNTAIL, ch->id);
859 rc = -ENOMEM;
860 atomic_dec(&skb->users);
861 dev_kfree_skb_any(skb);
862 fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100863done:
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200864 CTCM_PR_DEBUG("Exit %s(%s)\n", __func__, dev->name);
865 return rc;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100866}
867
868/**
869 * Start transmission of a packet.
870 * Called from generic network device layer.
871 *
872 * skb Pointer to buffer containing the packet.
873 * dev Pointer to interface struct.
874 *
875 * returns 0 if packet consumed, !0 if packet rejected.
876 * Note: If we return !0, then the packet is free'd by
877 * the generic network layer.
878 */
879/* first merge version - leaving both functions separated */
880static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
881{
Peter Tiedemann261893d2008-08-21 17:10:24 +0200882 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100883
884 if (skb == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200885 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
886 "%s(%s): NULL sk_buff passed",
887 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100888 priv->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000889 return NETDEV_TX_OK;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100890 }
891 if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200892 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
893 "%s(%s): Got sk_buff with head room < %ld bytes",
894 CTCM_FUNTAIL, dev->name, LL_HEADER_LENGTH + 2);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100895 dev_kfree_skb(skb);
896 priv->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000897 return NETDEV_TX_OK;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100898 }
899
900 /*
901 * If channels are not running, try to restart them
902 * and throw away packet.
903 */
904 if (fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) {
905 fsm_event(priv->fsm, DEV_EVENT_START, dev);
906 dev_kfree_skb(skb);
907 priv->stats.tx_dropped++;
908 priv->stats.tx_errors++;
909 priv->stats.tx_carrier_errors++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000910 return NETDEV_TX_OK;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100911 }
912
913 if (ctcm_test_and_set_busy(dev))
Ursula Braun3a05d142009-03-24 03:27:47 +0000914 return NETDEV_TX_BUSY;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100915
916 dev->trans_start = jiffies;
Ursula Braun3c09e262010-08-12 01:58:28 +0000917 if (ctcm_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0)
Ursula Braun3a05d142009-03-24 03:27:47 +0000918 return NETDEV_TX_BUSY;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000919 return NETDEV_TX_OK;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100920}
921
922/* unmerged MPC variant of ctcm_tx */
923static int ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
924{
925 int len = 0;
Peter Tiedemann261893d2008-08-21 17:10:24 +0200926 struct ctcm_priv *priv = dev->ml_priv;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200927 struct mpc_group *grp = priv->mpcg;
Peter Tiedemann293d9842008-02-08 00:03:49 +0100928 struct sk_buff *newskb = NULL;
929
Peter Tiedemann293d9842008-02-08 00:03:49 +0100930 /*
931 * Some sanity checks ...
932 */
933 if (skb == NULL) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200934 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
935 "%s(%s): NULL sk_buff passed",
936 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100937 priv->stats.tx_dropped++;
938 goto done;
939 }
940 if (skb_headroom(skb) < (TH_HEADER_LENGTH + PDU_HEADER_LENGTH)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200941 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
942 "%s(%s): Got sk_buff with head room < %ld bytes",
943 CTCM_FUNTAIL, dev->name,
944 TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100945
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200946 CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100947
948 len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
949 newskb = __dev_alloc_skb(len, gfp_type() | GFP_DMA);
950
951 if (!newskb) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200952 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR,
953 "%s: %s: __dev_alloc_skb failed",
954 __func__, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100955
956 dev_kfree_skb_any(skb);
957 priv->stats.tx_dropped++;
958 priv->stats.tx_errors++;
959 priv->stats.tx_carrier_errors++;
960 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
961 goto done;
962 }
963 newskb->protocol = skb->protocol;
964 skb_reserve(newskb, TH_HEADER_LENGTH + PDU_HEADER_LENGTH);
965 memcpy(skb_put(newskb, skb->len), skb->data, skb->len);
966 dev_kfree_skb_any(skb);
967 skb = newskb;
968 }
969
970 /*
971 * If channels are not running,
972 * notify anybody about a link failure and throw
973 * away packet.
974 */
975 if ((fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) ||
976 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
977 dev_kfree_skb_any(skb);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200978 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
979 "%s(%s): inactive MPCGROUP - dropped",
980 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100981 priv->stats.tx_dropped++;
982 priv->stats.tx_errors++;
983 priv->stats.tx_carrier_errors++;
984 goto done;
985 }
986
987 if (ctcm_test_and_set_busy(dev)) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +0200988 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
989 "%s(%s): device busy - dropped",
990 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100991 dev_kfree_skb_any(skb);
992 priv->stats.tx_dropped++;
993 priv->stats.tx_errors++;
994 priv->stats.tx_carrier_errors++;
995 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
996 goto done;
997 }
998
999 dev->trans_start = jiffies;
Ursula Braun3c09e262010-08-12 01:58:28 +00001000 if (ctcmpc_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001001 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
1002 "%s(%s): device error - dropped",
1003 CTCM_FUNTAIL, dev->name);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001004 dev_kfree_skb_any(skb);
1005 priv->stats.tx_dropped++;
1006 priv->stats.tx_errors++;
1007 priv->stats.tx_carrier_errors++;
1008 ctcm_clear_busy(dev);
1009 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1010 goto done;
1011 }
1012 ctcm_clear_busy(dev);
1013done:
1014 if (do_debug)
1015 MPC_DBF_DEV_NAME(TRACE, dev, "exit");
1016
Patrick McHardy6ed10652009-06-23 06:03:08 +00001017 return NETDEV_TX_OK; /* handle freeing of skb here */
Peter Tiedemann293d9842008-02-08 00:03:49 +01001018}
1019
1020
1021/**
1022 * Sets MTU of an interface.
1023 *
1024 * dev Pointer to interface struct.
1025 * new_mtu The new MTU to use for this interface.
1026 *
1027 * returns 0 on success, -EINVAL if MTU is out of valid range.
1028 * (valid range is 576 .. 65527). If VM is on the
1029 * remote side, maximum MTU is 32760, however this is
1030 * not checked here.
1031 */
1032static int ctcm_change_mtu(struct net_device *dev, int new_mtu)
1033{
1034 struct ctcm_priv *priv;
1035 int max_bufsize;
1036
Peter Tiedemann293d9842008-02-08 00:03:49 +01001037 if (new_mtu < 576 || new_mtu > 65527)
1038 return -EINVAL;
1039
Peter Tiedemann261893d2008-08-21 17:10:24 +02001040 priv = dev->ml_priv;
Ursula Braun3c09e262010-08-12 01:58:28 +00001041 max_bufsize = priv->channel[CTCM_READ]->max_bufsize;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001042
1043 if (IS_MPC(priv)) {
1044 if (new_mtu > max_bufsize - TH_HEADER_LENGTH)
1045 return -EINVAL;
1046 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1047 } else {
1048 if (new_mtu > max_bufsize - LL_HEADER_LENGTH - 2)
1049 return -EINVAL;
1050 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1051 }
1052 dev->mtu = new_mtu;
1053 return 0;
1054}
1055
1056/**
1057 * Returns interface statistics of a device.
1058 *
1059 * dev Pointer to interface struct.
1060 *
1061 * returns Pointer to stats struct of this interface.
1062 */
1063static struct net_device_stats *ctcm_stats(struct net_device *dev)
1064{
Peter Tiedemann261893d2008-08-21 17:10:24 +02001065 return &((struct ctcm_priv *)dev->ml_priv)->stats;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001066}
1067
Peter Tiedemann293d9842008-02-08 00:03:49 +01001068static void ctcm_free_netdevice(struct net_device *dev)
1069{
1070 struct ctcm_priv *priv;
1071 struct mpc_group *grp;
1072
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001073 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1074 "%s(%s)", CTCM_FUNTAIL, dev->name);
Peter Tiedemann261893d2008-08-21 17:10:24 +02001075 priv = dev->ml_priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001076 if (priv) {
1077 grp = priv->mpcg;
1078 if (grp) {
1079 if (grp->fsm)
1080 kfree_fsm(grp->fsm);
1081 if (grp->xid_skb)
1082 dev_kfree_skb(grp->xid_skb);
1083 if (grp->rcvd_xid_skb)
1084 dev_kfree_skb(grp->rcvd_xid_skb);
1085 tasklet_kill(&grp->mpc_tasklet2);
1086 kfree(grp);
1087 priv->mpcg = NULL;
1088 }
1089 if (priv->fsm) {
1090 kfree_fsm(priv->fsm);
1091 priv->fsm = NULL;
1092 }
1093 kfree(priv->xid);
1094 priv->xid = NULL;
1095 /*
1096 * Note: kfree(priv); is done in "opposite" function of
1097 * allocator function probe_device which is remove_device.
1098 */
1099 }
1100#ifdef MODULE
1101 free_netdev(dev);
1102#endif
1103}
1104
1105struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv);
1106
Frank Blaschka69b3aa62009-01-09 03:43:57 +00001107static const struct net_device_ops ctcm_netdev_ops = {
1108 .ndo_open = ctcm_open,
1109 .ndo_stop = ctcm_close,
1110 .ndo_get_stats = ctcm_stats,
1111 .ndo_change_mtu = ctcm_change_mtu,
1112 .ndo_start_xmit = ctcm_tx,
1113};
1114
1115static const struct net_device_ops ctcm_mpc_netdev_ops = {
1116 .ndo_open = ctcm_open,
1117 .ndo_stop = ctcm_close,
1118 .ndo_get_stats = ctcm_stats,
1119 .ndo_change_mtu = ctcm_change_mtu,
1120 .ndo_start_xmit = ctcmpc_tx,
1121};
1122
Peter Tiedemann293d9842008-02-08 00:03:49 +01001123void static ctcm_dev_setup(struct net_device *dev)
1124{
Peter Tiedemann293d9842008-02-08 00:03:49 +01001125 dev->type = ARPHRD_SLIP;
1126 dev->tx_queue_len = 100;
1127 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1128}
1129
1130/*
1131 * Initialize everything of the net device except the name and the
1132 * channel structs.
1133 */
1134static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv)
1135{
1136 struct net_device *dev;
1137 struct mpc_group *grp;
1138 if (!priv)
1139 return NULL;
1140
1141 if (IS_MPC(priv))
1142 dev = alloc_netdev(0, MPC_DEVICE_GENE, ctcm_dev_setup);
1143 else
1144 dev = alloc_netdev(0, CTC_DEVICE_GENE, ctcm_dev_setup);
1145
1146 if (!dev) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001147 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
1148 "%s: MEMORY allocation ERROR",
1149 CTCM_FUNTAIL);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001150 return NULL;
1151 }
Peter Tiedemann261893d2008-08-21 17:10:24 +02001152 dev->ml_priv = priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001153 priv->fsm = init_fsm("ctcmdev", dev_state_names, dev_event_names,
1154 CTCM_NR_DEV_STATES, CTCM_NR_DEV_EVENTS,
1155 dev_fsm, dev_fsm_len, GFP_KERNEL);
1156 if (priv->fsm == NULL) {
1157 CTCMY_DBF_DEV(SETUP, dev, "init_fsm error");
Vasiliy Kulikovbc685802010-09-26 18:56:06 -07001158 free_netdev(dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001159 return NULL;
1160 }
1161 fsm_newstate(priv->fsm, DEV_STATE_STOPPED);
1162 fsm_settimer(priv->fsm, &priv->restart_timer);
1163
1164 if (IS_MPC(priv)) {
1165 /* MPC Group Initializations */
1166 grp = ctcmpc_init_mpc_group(priv);
1167 if (grp == NULL) {
1168 MPC_DBF_DEV(SETUP, dev, "init_mpc_group error");
Vasiliy Kulikovbc685802010-09-26 18:56:06 -07001169 free_netdev(dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001170 return NULL;
1171 }
1172 tasklet_init(&grp->mpc_tasklet2,
1173 mpc_group_ready, (unsigned long)dev);
1174 dev->mtu = MPC_BUFSIZE_DEFAULT -
1175 TH_HEADER_LENGTH - PDU_HEADER_LENGTH;
1176
Frank Blaschka69b3aa62009-01-09 03:43:57 +00001177 dev->netdev_ops = &ctcm_mpc_netdev_ops;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001178 dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH;
1179 priv->buffer_size = MPC_BUFSIZE_DEFAULT;
1180 } else {
1181 dev->mtu = CTCM_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
Frank Blaschka69b3aa62009-01-09 03:43:57 +00001182 dev->netdev_ops = &ctcm_netdev_ops;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001183 dev->hard_header_len = LL_HEADER_LENGTH + 2;
1184 }
1185
1186 CTCMY_DBF_DEV(SETUP, dev, "finished");
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001187
Peter Tiedemann293d9842008-02-08 00:03:49 +01001188 return dev;
1189}
1190
1191/**
1192 * Main IRQ handler.
1193 *
1194 * cdev The ccw_device the interrupt is for.
1195 * intparm interruption parameter.
1196 * irb interruption response block.
1197 */
1198static void ctcm_irq_handler(struct ccw_device *cdev,
1199 unsigned long intparm, struct irb *irb)
1200{
1201 struct channel *ch;
1202 struct net_device *dev;
1203 struct ctcm_priv *priv;
1204 struct ccwgroup_device *cgdev;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001205 int cstat;
1206 int dstat;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001207
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001208 CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG,
Kay Sievers2a0217d2008-10-10 21:33:09 +02001209 "Enter %s(%s)", CTCM_FUNTAIL, dev_name(&cdev->dev));
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001210
Peter Tiedemann293d9842008-02-08 00:03:49 +01001211 if (ctcm_check_irb_error(cdev, irb))
1212 return;
1213
1214 cgdev = dev_get_drvdata(&cdev->dev);
1215
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001216 cstat = irb->scsw.cmd.cstat;
1217 dstat = irb->scsw.cmd.dstat;
1218
Peter Tiedemann293d9842008-02-08 00:03:49 +01001219 /* Check for unsolicited interrupts. */
1220 if (cgdev == NULL) {
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001221 CTCM_DBF_TEXT_(TRACE, CTC_DBF_ERROR,
1222 "%s(%s) unsolicited irq: c-%02x d-%02x\n",
1223 CTCM_FUNTAIL, dev_name(&cdev->dev), cstat, dstat);
1224 dev_warn(&cdev->dev,
1225 "The adapter received a non-specific IRQ\n");
Peter Tiedemann293d9842008-02-08 00:03:49 +01001226 return;
1227 }
1228
1229 priv = dev_get_drvdata(&cgdev->dev);
1230
1231 /* Try to extract channel from driver data. */
Ursula Braun3c09e262010-08-12 01:58:28 +00001232 if (priv->channel[CTCM_READ]->cdev == cdev)
1233 ch = priv->channel[CTCM_READ];
1234 else if (priv->channel[CTCM_WRITE]->cdev == cdev)
1235 ch = priv->channel[CTCM_WRITE];
Peter Tiedemann293d9842008-02-08 00:03:49 +01001236 else {
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001237 dev_err(&cdev->dev,
1238 "%s: Internal error: Can't determine channel for "
1239 "interrupt device %s\n",
1240 __func__, dev_name(&cdev->dev));
1241 /* Explain: inconsistent internal structures */
Peter Tiedemann293d9842008-02-08 00:03:49 +01001242 return;
1243 }
1244
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001245 dev = ch->netdev;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001246 if (dev == NULL) {
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001247 dev_err(&cdev->dev,
1248 "%s Internal error: net_device is NULL, ch = 0x%p\n",
1249 __func__, ch);
1250 /* Explain: inconsistent internal structures */
Peter Tiedemann293d9842008-02-08 00:03:49 +01001251 return;
1252 }
1253
Peter Tiedemann293d9842008-02-08 00:03:49 +01001254 /* Copy interruption response block. */
1255 memcpy(ch->irb, irb, sizeof(struct irb));
1256
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001257 /* Issue error message and return on subchannel error code */
Peter Oberparleiter23d805b62008-07-14 09:58:50 +02001258 if (irb->scsw.cmd.cstat) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001259 fsm_event(ch->fsm, CTC_EVENT_SC_UNKNOWN, ch);
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001260 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
1261 "%s(%s): sub-ch check %s: cs=%02x ds=%02x",
1262 CTCM_FUNTAIL, dev->name, ch->id, cstat, dstat);
1263 dev_warn(&cdev->dev,
1264 "A check occurred on the subchannel\n");
Peter Tiedemann293d9842008-02-08 00:03:49 +01001265 return;
1266 }
1267
1268 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b62008-07-14 09:58:50 +02001269 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001270 if ((irb->ecw[0] & ch->sense_rc) == 0)
1271 /* print it only once */
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001272 CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN,
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001273 "%s(%s): sense=%02x, ds=%02x",
1274 CTCM_FUNTAIL, ch->id, irb->ecw[0], dstat);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001275 ccw_unit_check(ch, irb->ecw[0]);
1276 return;
1277 }
Peter Oberparleiter23d805b62008-07-14 09:58:50 +02001278 if (irb->scsw.cmd.dstat & DEV_STAT_BUSY) {
1279 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION)
Peter Tiedemann293d9842008-02-08 00:03:49 +01001280 fsm_event(ch->fsm, CTC_EVENT_ATTNBUSY, ch);
1281 else
1282 fsm_event(ch->fsm, CTC_EVENT_BUSY, ch);
1283 return;
1284 }
Peter Oberparleiter23d805b62008-07-14 09:58:50 +02001285 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001286 fsm_event(ch->fsm, CTC_EVENT_ATTN, ch);
1287 return;
1288 }
Peter Oberparleiter23d805b62008-07-14 09:58:50 +02001289 if ((irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
1290 (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
1291 (irb->scsw.cmd.stctl ==
Peter Tiedemann293d9842008-02-08 00:03:49 +01001292 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
1293 fsm_event(ch->fsm, CTC_EVENT_FINSTAT, ch);
1294 else
1295 fsm_event(ch->fsm, CTC_EVENT_IRQ, ch);
1296
1297}
1298
Sebastian Ott20cdffa2012-05-15 17:54:12 +02001299static const struct device_type ctcm_devtype = {
1300 .name = "ctcm",
1301 .groups = ctcm_attr_groups,
1302};
1303
Peter Tiedemann293d9842008-02-08 00:03:49 +01001304/**
1305 * Add ctcm specific attributes.
1306 * Add ctcm private data.
1307 *
1308 * cgdev pointer to ccwgroup_device just added
1309 *
1310 * returns 0 on success, !0 on failure.
1311 */
1312static int ctcm_probe_device(struct ccwgroup_device *cgdev)
1313{
1314 struct ctcm_priv *priv;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001315
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001316 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1317 "%s %p",
1318 __func__, cgdev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001319
1320 if (!get_device(&cgdev->dev))
1321 return -ENODEV;
1322
1323 priv = kzalloc(sizeof(struct ctcm_priv), GFP_KERNEL);
1324 if (!priv) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001325 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
1326 "%s: memory allocation failure",
1327 CTCM_FUNTAIL);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001328 put_device(&cgdev->dev);
1329 return -ENOMEM;
1330 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001331 priv->buffer_size = CTCM_BUFSIZE_DEFAULT;
1332 cgdev->cdev[0]->handler = ctcm_irq_handler;
1333 cgdev->cdev[1]->handler = ctcm_irq_handler;
1334 dev_set_drvdata(&cgdev->dev, priv);
Sebastian Ott20cdffa2012-05-15 17:54:12 +02001335 cgdev->dev.type = &ctcm_devtype;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001336
1337 return 0;
1338}
1339
1340/**
1341 * Add a new channel to the list of channels.
1342 * Keeps the channel list sorted.
1343 *
1344 * cdev The ccw_device to be added.
1345 * type The type class of the new channel.
1346 * priv Points to the private data of the ccwgroup_device.
1347 *
1348 * returns 0 on success, !0 on error.
1349 */
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001350static int add_channel(struct ccw_device *cdev, enum ctcm_channel_types type,
Peter Tiedemann293d9842008-02-08 00:03:49 +01001351 struct ctcm_priv *priv)
1352{
1353 struct channel **c = &channels;
1354 struct channel *ch;
1355 int ccw_num;
1356 int rc = 0;
1357
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001358 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1359 "%s(%s), type %d, proto %d",
Kay Sievers2a0217d2008-10-10 21:33:09 +02001360 __func__, dev_name(&cdev->dev), type, priv->protocol);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001361
Peter Tiedemann293d9842008-02-08 00:03:49 +01001362 ch = kzalloc(sizeof(struct channel), GFP_KERNEL);
1363 if (ch == NULL)
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001364 return -ENOMEM;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001365
1366 ch->protocol = priv->protocol;
1367 if (IS_MPC(priv)) {
Julia Lawallae57b202010-05-16 21:15:13 +00001368 ch->discontact_th = kzalloc(TH_HEADER_LENGTH, gfp_type());
Peter Tiedemann293d9842008-02-08 00:03:49 +01001369 if (ch->discontact_th == NULL)
1370 goto nomem_return;
1371
1372 ch->discontact_th->th_blk_flag = TH_DISCONTACT;
1373 tasklet_init(&ch->ch_disc_tasklet,
1374 mpc_action_send_discontact, (unsigned long)ch);
1375
1376 tasklet_init(&ch->ch_tasklet, ctcmpc_bh, (unsigned long)ch);
1377 ch->max_bufsize = (MPC_BUFSIZE_DEFAULT - 35);
1378 ccw_num = 17;
1379 } else
1380 ccw_num = 8;
1381
Julia Lawallae57b202010-05-16 21:15:13 +00001382 ch->ccw = kzalloc(ccw_num * sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001383 if (ch->ccw == NULL)
1384 goto nomem_return;
1385
1386 ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001387 snprintf(ch->id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev->dev));
Peter Tiedemann293d9842008-02-08 00:03:49 +01001388 ch->type = type;
1389
1390 /**
1391 * "static" ccws are used in the following way:
1392 *
1393 * ccw[0..2] (Channel program for generic I/O):
1394 * 0: prepare
1395 * 1: read or write (depending on direction) with fixed
1396 * buffer (idal allocated once when buffer is allocated)
1397 * 2: nop
1398 * ccw[3..5] (Channel program for direct write of packets)
1399 * 3: prepare
1400 * 4: write (idal allocated on every write).
1401 * 5: nop
1402 * ccw[6..7] (Channel program for initial channel setup):
1403 * 6: set extended mode
1404 * 7: nop
1405 *
1406 * ch->ccw[0..5] are initialized in ch_action_start because
1407 * the channel's direction is yet unknown here.
1408 *
1409 * ccws used for xid2 negotiations
1410 * ch-ccw[8-14] need to be used for the XID exchange either
1411 * X side XID2 Processing
1412 * 8: write control
1413 * 9: write th
1414 * 10: write XID
1415 * 11: read th from secondary
1416 * 12: read XID from secondary
1417 * 13: read 4 byte ID
1418 * 14: nop
1419 * Y side XID Processing
1420 * 8: sense
1421 * 9: read th
1422 * 10: read XID
1423 * 11: write th
1424 * 12: write XID
1425 * 13: write 4 byte ID
1426 * 14: nop
1427 *
1428 * ccws used for double noop due to VM timing issues
1429 * which result in unrecoverable Busy on channel
1430 * 15: nop
1431 * 16: nop
1432 */
1433 ch->ccw[6].cmd_code = CCW_CMD_SET_EXTENDED;
1434 ch->ccw[6].flags = CCW_FLAG_SLI;
1435
1436 ch->ccw[7].cmd_code = CCW_CMD_NOOP;
1437 ch->ccw[7].flags = CCW_FLAG_SLI;
1438
1439 if (IS_MPC(priv)) {
1440 ch->ccw[15].cmd_code = CCW_CMD_WRITE;
1441 ch->ccw[15].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1442 ch->ccw[15].count = TH_HEADER_LENGTH;
1443 ch->ccw[15].cda = virt_to_phys(ch->discontact_th);
1444
1445 ch->ccw[16].cmd_code = CCW_CMD_NOOP;
1446 ch->ccw[16].flags = CCW_FLAG_SLI;
1447
1448 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1449 ctc_ch_event_names, CTC_MPC_NR_STATES,
1450 CTC_MPC_NR_EVENTS, ctcmpc_ch_fsm,
1451 mpc_ch_fsm_len, GFP_KERNEL);
1452 } else {
1453 ch->fsm = init_fsm(ch->id, ctc_ch_state_names,
1454 ctc_ch_event_names, CTC_NR_STATES,
1455 CTC_NR_EVENTS, ch_fsm,
1456 ch_fsm_len, GFP_KERNEL);
1457 }
1458 if (ch->fsm == NULL)
1459 goto free_return;
1460
1461 fsm_newstate(ch->fsm, CTC_STATE_IDLE);
1462
1463 ch->irb = kzalloc(sizeof(struct irb), GFP_KERNEL);
1464 if (ch->irb == NULL)
1465 goto nomem_return;
1466
1467 while (*c && ctcm_less_than((*c)->id, ch->id))
1468 c = &(*c)->next;
1469
1470 if (*c && (!strncmp((*c)->id, ch->id, CTCM_ID_SIZE))) {
1471 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1472 "%s (%s) already in list, using old entry",
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001473 __func__, (*c)->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001474
1475 goto free_return;
1476 }
1477
1478 spin_lock_init(&ch->collect_lock);
1479
1480 fsm_settimer(ch->fsm, &ch->timer);
1481 skb_queue_head_init(&ch->io_queue);
1482 skb_queue_head_init(&ch->collect_queue);
1483
1484 if (IS_MPC(priv)) {
1485 fsm_settimer(ch->fsm, &ch->sweep_timer);
1486 skb_queue_head_init(&ch->sweep_queue);
1487 }
1488 ch->next = *c;
1489 *c = ch;
1490 return 0;
1491
1492nomem_return:
Peter Tiedemann293d9842008-02-08 00:03:49 +01001493 rc = -ENOMEM;
1494
1495free_return: /* note that all channel pointers are 0 or valid */
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001496 kfree(ch->ccw);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001497 kfree(ch->discontact_th);
1498 kfree_fsm(ch->fsm);
1499 kfree(ch->irb);
1500 kfree(ch);
1501 return rc;
1502}
1503
1504/*
1505 * Return type of a detected device.
1506 */
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001507static enum ctcm_channel_types get_channel_type(struct ccw_device_id *id)
Peter Tiedemann293d9842008-02-08 00:03:49 +01001508{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001509 enum ctcm_channel_types type;
1510 type = (enum ctcm_channel_types)id->driver_info;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001511
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001512 if (type == ctcm_channel_type_ficon)
1513 type = ctcm_channel_type_escon;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001514
1515 return type;
1516}
1517
1518/**
1519 *
1520 * Setup an interface.
1521 *
1522 * cgdev Device to be setup.
1523 *
1524 * returns 0 on success, !0 on failure.
1525 */
1526static int ctcm_new_device(struct ccwgroup_device *cgdev)
1527{
1528 char read_id[CTCM_ID_SIZE];
1529 char write_id[CTCM_ID_SIZE];
1530 int direction;
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001531 enum ctcm_channel_types type;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001532 struct ctcm_priv *priv;
1533 struct net_device *dev;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001534 struct ccw_device *cdev0;
1535 struct ccw_device *cdev1;
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001536 struct channel *readc;
1537 struct channel *writec;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001538 int ret;
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001539 int result;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001540
Peter Tiedemann293d9842008-02-08 00:03:49 +01001541 priv = dev_get_drvdata(&cgdev->dev);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001542 if (!priv) {
1543 result = -ENODEV;
1544 goto out_err_result;
1545 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001546
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001547 cdev0 = cgdev->cdev[0];
1548 cdev1 = cgdev->cdev[1];
Peter Tiedemann293d9842008-02-08 00:03:49 +01001549
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001550 type = get_channel_type(&cdev0->id);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001551
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02001552 snprintf(read_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev0->dev));
1553 snprintf(write_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev1->dev));
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001554
1555 ret = add_channel(cdev0, type, priv);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001556 if (ret) {
1557 result = ret;
1558 goto out_err_result;
1559 }
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001560 ret = add_channel(cdev1, type, priv);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001561 if (ret) {
1562 result = ret;
1563 goto out_remove_channel1;
1564 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001565
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001566 ret = ccw_device_set_online(cdev0);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001567 if (ret != 0) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001568 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
1569 "%s(%s) set_online rc=%d",
1570 CTCM_FUNTAIL, read_id, ret);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001571 result = -EIO;
1572 goto out_remove_channel2;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001573 }
1574
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001575 ret = ccw_device_set_online(cdev1);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001576 if (ret != 0) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001577 CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE,
1578 "%s(%s) set_online rc=%d",
1579 CTCM_FUNTAIL, write_id, ret);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001580
1581 result = -EIO;
1582 goto out_ccw1;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001583 }
1584
1585 dev = ctcm_init_netdevice(priv);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001586 if (dev == NULL) {
1587 result = -ENODEV;
1588 goto out_ccw2;
1589 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001590
Ursula Braun3c09e262010-08-12 01:58:28 +00001591 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
Peter Tiedemann293d9842008-02-08 00:03:49 +01001592 priv->channel[direction] =
Ursula Braun3c09e262010-08-12 01:58:28 +00001593 channel_get(type, direction == CTCM_READ ?
1594 read_id : write_id, direction);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001595 if (priv->channel[direction] == NULL) {
Ursula Braun3c09e262010-08-12 01:58:28 +00001596 if (direction == CTCM_WRITE)
1597 channel_free(priv->channel[CTCM_READ]);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001598 goto out_dev;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001599 }
1600 priv->channel[direction]->netdev = dev;
1601 priv->channel[direction]->protocol = priv->protocol;
1602 priv->channel[direction]->max_bufsize = priv->buffer_size;
1603 }
1604 /* sysfs magic */
1605 SET_NETDEV_DEV(dev, &cgdev->dev);
1606
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001607 if (register_netdev(dev)) {
1608 result = -ENODEV;
1609 goto out_dev;
1610 }
Peter Tiedemann293d9842008-02-08 00:03:49 +01001611
Peter Tiedemann293d9842008-02-08 00:03:49 +01001612 strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name));
1613
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001614 dev_info(&dev->dev,
1615 "setup OK : r/w = %s/%s, protocol : %d\n",
Ursula Braun3c09e262010-08-12 01:58:28 +00001616 priv->channel[CTCM_READ]->id,
1617 priv->channel[CTCM_WRITE]->id, priv->protocol);
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001618
Peter Tiedemann293d9842008-02-08 00:03:49 +01001619 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001620 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name,
Ursula Braun3c09e262010-08-12 01:58:28 +00001621 priv->channel[CTCM_READ]->id,
1622 priv->channel[CTCM_WRITE]->id, priv->protocol);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001623
1624 return 0;
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001625out_dev:
1626 ctcm_free_netdevice(dev);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001627out_ccw2:
Peter Tiedemann293d9842008-02-08 00:03:49 +01001628 ccw_device_set_offline(cgdev->cdev[1]);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001629out_ccw1:
Peter Tiedemann293d9842008-02-08 00:03:49 +01001630 ccw_device_set_offline(cgdev->cdev[0]);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001631out_remove_channel2:
Ursula Braun3c09e262010-08-12 01:58:28 +00001632 readc = channel_get(type, read_id, CTCM_READ);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001633 channel_remove(readc);
1634out_remove_channel1:
Ursula Braun3c09e262010-08-12 01:58:28 +00001635 writec = channel_get(type, write_id, CTCM_WRITE);
Einar Luecka1c1f5e2009-10-14 22:54:59 +00001636 channel_remove(writec);
1637out_err_result:
1638 return result;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001639}
1640
1641/**
1642 * Shutdown an interface.
1643 *
1644 * cgdev Device to be shut down.
1645 *
1646 * returns 0 on success, !0 on failure.
1647 */
1648static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1649{
1650 struct ctcm_priv *priv;
1651 struct net_device *dev;
1652
1653 priv = dev_get_drvdata(&cgdev->dev);
1654 if (!priv)
1655 return -ENODEV;
1656
Ursula Braun3c09e262010-08-12 01:58:28 +00001657 if (priv->channel[CTCM_READ]) {
1658 dev = priv->channel[CTCM_READ]->netdev;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001659 CTCM_DBF_DEV(SETUP, dev, "");
1660 /* Close the device */
1661 ctcm_close(dev);
1662 dev->flags &= ~IFF_RUNNING;
Ursula Braun3c09e262010-08-12 01:58:28 +00001663 channel_free(priv->channel[CTCM_READ]);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001664 } else
1665 dev = NULL;
1666
Ursula Braun3c09e262010-08-12 01:58:28 +00001667 if (priv->channel[CTCM_WRITE])
1668 channel_free(priv->channel[CTCM_WRITE]);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001669
1670 if (dev) {
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001671 unregister_netdev(dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001672 ctcm_free_netdevice(dev);
1673 }
1674
1675 if (priv->fsm)
1676 kfree_fsm(priv->fsm);
1677
1678 ccw_device_set_offline(cgdev->cdev[1]);
1679 ccw_device_set_offline(cgdev->cdev[0]);
1680
Ursula Braun3c09e262010-08-12 01:58:28 +00001681 if (priv->channel[CTCM_READ])
1682 channel_remove(priv->channel[CTCM_READ]);
1683 if (priv->channel[CTCM_WRITE])
1684 channel_remove(priv->channel[CTCM_WRITE]);
1685 priv->channel[CTCM_READ] = priv->channel[CTCM_WRITE] = NULL;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001686
1687 return 0;
1688
1689}
1690
1691
1692static void ctcm_remove_device(struct ccwgroup_device *cgdev)
1693{
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001694 struct ctcm_priv *priv = dev_get_drvdata(&cgdev->dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001695
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001696 BUG_ON(priv == NULL);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001697
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001698 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
Ursula Braun8ac6d452009-05-19 21:38:38 +00001699 "removing device %p, proto : %d",
1700 cgdev, priv->protocol);
Peter Tiedemannaa3f2cb2008-07-18 15:24:57 +02001701
Peter Tiedemann293d9842008-02-08 00:03:49 +01001702 if (cgdev->state == CCWGROUP_ONLINE)
1703 ctcm_shutdown_device(cgdev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001704 dev_set_drvdata(&cgdev->dev, NULL);
1705 kfree(priv);
1706 put_device(&cgdev->dev);
1707}
1708
Frank Blaschkab8a2d422009-06-16 10:30:32 +02001709static int ctcm_pm_suspend(struct ccwgroup_device *gdev)
1710{
1711 struct ctcm_priv *priv = dev_get_drvdata(&gdev->dev);
1712
1713 if (gdev->state == CCWGROUP_OFFLINE)
1714 return 0;
Ursula Braun3c09e262010-08-12 01:58:28 +00001715 netif_device_detach(priv->channel[CTCM_READ]->netdev);
1716 ctcm_close(priv->channel[CTCM_READ]->netdev);
Frank Blaschka1e1815b2009-11-12 21:46:28 +00001717 if (!wait_event_timeout(priv->fsm->wait_q,
1718 fsm_getstate(priv->fsm) == DEV_STATE_STOPPED, CTCM_TIME_5_SEC)) {
Ursula Braun3c09e262010-08-12 01:58:28 +00001719 netif_device_attach(priv->channel[CTCM_READ]->netdev);
Frank Blaschka1e1815b2009-11-12 21:46:28 +00001720 return -EBUSY;
1721 }
Frank Blaschkab8a2d422009-06-16 10:30:32 +02001722 ccw_device_set_offline(gdev->cdev[1]);
1723 ccw_device_set_offline(gdev->cdev[0]);
1724 return 0;
1725}
1726
1727static int ctcm_pm_resume(struct ccwgroup_device *gdev)
1728{
1729 struct ctcm_priv *priv = dev_get_drvdata(&gdev->dev);
1730 int rc;
1731
1732 if (gdev->state == CCWGROUP_OFFLINE)
1733 return 0;
1734 rc = ccw_device_set_online(gdev->cdev[1]);
1735 if (rc)
1736 goto err_out;
1737 rc = ccw_device_set_online(gdev->cdev[0]);
1738 if (rc)
1739 goto err_out;
Ursula Braun3c09e262010-08-12 01:58:28 +00001740 ctcm_open(priv->channel[CTCM_READ]->netdev);
Frank Blaschkab8a2d422009-06-16 10:30:32 +02001741err_out:
Ursula Braun3c09e262010-08-12 01:58:28 +00001742 netif_device_attach(priv->channel[CTCM_READ]->netdev);
Frank Blaschkab8a2d422009-06-16 10:30:32 +02001743 return rc;
1744}
1745
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001746static struct ccw_device_id ctcm_ids[] = {
1747 {CCW_DEVICE(0x3088, 0x08), .driver_info = ctcm_channel_type_parallel},
1748 {CCW_DEVICE(0x3088, 0x1e), .driver_info = ctcm_channel_type_ficon},
1749 {CCW_DEVICE(0x3088, 0x1f), .driver_info = ctcm_channel_type_escon},
1750 {},
1751};
1752MODULE_DEVICE_TABLE(ccw, ctcm_ids);
1753
1754static struct ccw_driver ctcm_ccw_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +01001755 .driver = {
1756 .owner = THIS_MODULE,
1757 .name = "ctcm",
1758 },
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001759 .ids = ctcm_ids,
1760 .probe = ccwgroup_probe_ccwdev,
1761 .remove = ccwgroup_remove_ccwdev,
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001762 .int_class = IOINT_CTC,
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001763};
1764
Peter Tiedemann293d9842008-02-08 00:03:49 +01001765static struct ccwgroup_driver ctcm_group_driver = {
Sebastian Ott3c190c52011-03-23 10:16:04 +01001766 .driver = {
1767 .owner = THIS_MODULE,
1768 .name = CTC_DRIVER_NAME,
1769 },
Sebastian Ott20cdffa2012-05-15 17:54:12 +02001770 .setup = ctcm_probe_device,
Peter Tiedemann293d9842008-02-08 00:03:49 +01001771 .remove = ctcm_remove_device,
1772 .set_online = ctcm_new_device,
1773 .set_offline = ctcm_shutdown_device,
Frank Blaschkab8a2d422009-06-16 10:30:32 +02001774 .freeze = ctcm_pm_suspend,
1775 .thaw = ctcm_pm_resume,
1776 .restore = ctcm_pm_resume,
Peter Tiedemann293d9842008-02-08 00:03:49 +01001777};
1778
Sebastian Ott20cdffa2012-05-15 17:54:12 +02001779static ssize_t ctcm_driver_group_store(struct device_driver *ddrv,
1780 const char *buf, size_t count)
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001781{
1782 int err;
1783
Sebastian Ott9814fdf2012-05-15 18:03:46 +02001784 err = ccwgroup_create_dev(ctcm_root_dev, &ctcm_group_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001785 return err ? err : count;
1786}
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001787static DRIVER_ATTR(group, 0200, NULL, ctcm_driver_group_store);
1788
1789static struct attribute *ctcm_group_attrs[] = {
1790 &driver_attr_group.attr,
1791 NULL,
1792};
1793
1794static struct attribute_group ctcm_group_attr_group = {
1795 .attrs = ctcm_group_attrs,
1796};
1797
Heiko Carstens302689a2009-11-17 06:47:02 -08001798static const struct attribute_group *ctcm_group_attr_groups[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001799 &ctcm_group_attr_group,
1800 NULL,
1801};
Peter Tiedemann293d9842008-02-08 00:03:49 +01001802
1803/*
1804 * Module related routines
1805 */
1806
1807/*
1808 * Prepare to be unloaded. Free IRQ's and release all resources.
1809 * This is called just before this module is unloaded. It is
1810 * not called, if the usage count is !0, so we don't need to check
1811 * for that.
1812 */
1813static void __exit ctcm_exit(void)
1814{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001815 driver_remove_file(&ctcm_group_driver.driver, &driver_attr_group);
1816 ccwgroup_driver_unregister(&ctcm_group_driver);
1817 ccw_driver_unregister(&ctcm_ccw_driver);
1818 root_device_unregister(ctcm_root_dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001819 ctcm_unregister_dbf_views();
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001820 pr_info("CTCM driver unloaded\n");
Peter Tiedemann293d9842008-02-08 00:03:49 +01001821}
1822
1823/*
1824 * Print Banner.
1825 */
1826static void print_banner(void)
1827{
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +01001828 pr_info("CTCM driver initialized\n");
Peter Tiedemann293d9842008-02-08 00:03:49 +01001829}
1830
1831/**
1832 * Initialize module.
1833 * This is called just after the module is loaded.
1834 *
1835 * returns 0 on success, !0 on error.
1836 */
1837static int __init ctcm_init(void)
1838{
1839 int ret;
1840
1841 channels = NULL;
1842
1843 ret = ctcm_register_dbf_views();
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001844 if (ret)
1845 goto out_err;
1846 ctcm_root_dev = root_device_register("ctcm");
1847 ret = IS_ERR(ctcm_root_dev) ? PTR_ERR(ctcm_root_dev) : 0;
1848 if (ret)
1849 goto register_err;
1850 ret = ccw_driver_register(&ctcm_ccw_driver);
1851 if (ret)
1852 goto ccw_err;
1853 ctcm_group_driver.driver.groups = ctcm_group_attr_groups;
1854 ret = ccwgroup_driver_register(&ctcm_group_driver);
1855 if (ret)
1856 goto ccwgroup_err;
Peter Tiedemann293d9842008-02-08 00:03:49 +01001857 print_banner();
Ursula Braun0ca8cc62009-11-12 21:46:29 +00001858 return 0;
1859
1860ccwgroup_err:
1861 ccw_driver_unregister(&ctcm_ccw_driver);
1862ccw_err:
1863 root_device_unregister(ctcm_root_dev);
1864register_err:
1865 ctcm_unregister_dbf_views();
1866out_err:
1867 pr_err("%s / Initializing the ctcm device driver failed, ret = %d\n",
1868 __func__, ret);
Peter Tiedemann293d9842008-02-08 00:03:49 +01001869 return ret;
1870}
1871
1872module_init(ctcm_init);
1873module_exit(ctcm_exit);
1874
1875MODULE_AUTHOR("Peter Tiedemann <ptiedem@de.ibm.com>");
1876MODULE_DESCRIPTION("Network driver for S/390 CTC + CTCMPC (SNA)");
1877MODULE_LICENSE("GPL");
1878