Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[pandora-kernel.git] / drivers / s390 / net / claw.c
1 /*
2  *  drivers/s390/net/claw.c
3  *    ESCON CLAW network driver
4  *
5  *  Linux for zSeries version
6  *    Copyright IBM Corp. 2002, 2009
7  *  Author(s) Original code written by:
8  *              Kazuo Iimura <iimura@jp.ibm.com>
9  *            Rewritten by
10  *              Andy Richter <richtera@us.ibm.com>
11  *              Marc Price <mwprice@us.ibm.com>
12  *
13  *    sysfs parms:
14  *   group x.x.rrrr,x.x.wwww
15  *   read_buffer nnnnnnn
16  *   write_buffer nnnnnn
17  *   host_name  aaaaaaaa
18  *   adapter_name aaaaaaaa
19  *   api_type    aaaaaaaa
20  *
21  *  eg.
22  *   group  0.0.0200 0.0.0201
23  *   read_buffer 25
24  *   write_buffer 20
25  *   host_name LINUX390
26  *   adapter_name RS6K
27  *   api_type     TCPIP
28  *
29  *  where
30  *
31  *   The device id is decided by the order entries
32  *   are added to the group the first is claw0 the second claw1
33  *   up to CLAW_MAX_DEV
34  *
35  *   rrrr     - the first of 2 consecutive device addresses used for the
36  *              CLAW protocol.
37  *              The specified address is always used as the input (Read)
38  *              channel and the next address is used as the output channel.
39  *
40  *   wwww     - the second of 2 consecutive device addresses used for
41  *              the CLAW protocol.
42  *              The specified address is always used as the output
43  *              channel and the previous address is used as the input channel.
44  *
45  *   read_buffer        -       specifies number of input buffers to allocate.
46  *   write_buffer       -       specifies number of output buffers to allocate.
47  *   host_name          -       host name
48  *   adaptor_name       -       adaptor name
49  *   api_type           -       API type TCPIP or API will be sent and expected
50  *                              as ws_name
51  *
52  *   Note the following requirements:
53  *   1)  host_name must match the configured adapter_name on the remote side
54  *   2)  adaptor_name must match the configured host name on the remote side
55  *
56  *  Change History
57  *    1.00  Initial release shipped
58  *    1.10  Changes for Buffer allocation
59  *    1.15  Changed for 2.6 Kernel  No longer compiles on 2.4 or lower
60  *    1.25  Added Packing support
61  *    1.5
62  */
63
64 #define KMSG_COMPONENT "claw"
65
66 #include <linux/kernel_stat.h>
67 #include <asm/ccwdev.h>
68 #include <asm/ccwgroup.h>
69 #include <asm/debug.h>
70 #include <asm/idals.h>
71 #include <asm/io.h>
72 #include <linux/bitops.h>
73 #include <linux/ctype.h>
74 #include <linux/delay.h>
75 #include <linux/errno.h>
76 #include <linux/if_arp.h>
77 #include <linux/init.h>
78 #include <linux/interrupt.h>
79 #include <linux/ip.h>
80 #include <linux/kernel.h>
81 #include <linux/module.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/proc_fs.h>
85 #include <linux/sched.h>
86 #include <linux/signal.h>
87 #include <linux/skbuff.h>
88 #include <linux/slab.h>
89 #include <linux/string.h>
90 #include <linux/tcp.h>
91 #include <linux/timer.h>
92 #include <linux/types.h>
93
94 #include "claw.h"
95
96 /*
97    CLAW uses the s390dbf file system  see claw_trace and claw_setup
98 */
99
100 static char version[] __initdata = "CLAW driver";
101 static char debug_buffer[255];
102 /**
103  * Debug Facility Stuff
104  */
105 static debug_info_t *claw_dbf_setup;
106 static debug_info_t *claw_dbf_trace;
107
108 /**
109  *  CLAW Debug Facility functions
110  */
111 static void
112 claw_unregister_debug_facility(void)
113 {
114         if (claw_dbf_setup)
115                 debug_unregister(claw_dbf_setup);
116         if (claw_dbf_trace)
117                 debug_unregister(claw_dbf_trace);
118 }
119
120 static int
121 claw_register_debug_facility(void)
122 {
123         claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
124         claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
125         if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
126                 claw_unregister_debug_facility();
127                 return -ENOMEM;
128         }
129         debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
130         debug_set_level(claw_dbf_setup, 2);
131         debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
132         debug_set_level(claw_dbf_trace, 2);
133         return 0;
134 }
135
136 static inline void
137 claw_set_busy(struct net_device *dev)
138 {
139  ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
140  eieio();
141 }
142
143 static inline void
144 claw_clear_busy(struct net_device *dev)
145 {
146         clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
147         netif_wake_queue(dev);
148         eieio();
149 }
150
151 static inline int
152 claw_check_busy(struct net_device *dev)
153 {
154         eieio();
155         return ((struct claw_privbk *) dev->ml_priv)->tbusy;
156 }
157
158 static inline void
159 claw_setbit_busy(int nr,struct net_device *dev)
160 {
161         netif_stop_queue(dev);
162         set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
163 }
164
165 static inline void
166 claw_clearbit_busy(int nr,struct net_device *dev)
167 {
168         clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
169         netif_wake_queue(dev);
170 }
171
172 static inline int
173 claw_test_and_setbit_busy(int nr,struct net_device *dev)
174 {
175         netif_stop_queue(dev);
176         return test_and_set_bit(nr,
177                 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
178 }
179
180
181 /* Functions for the DEV methods */
182
183 static int claw_probe(struct ccwgroup_device *cgdev);
184 static void claw_remove_device(struct ccwgroup_device *cgdev);
185 static void claw_purge_skb_queue(struct sk_buff_head *q);
186 static int claw_new_device(struct ccwgroup_device *cgdev);
187 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
188 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
189 static int claw_change_mtu( struct net_device *dev, int new_mtu);
190 static int claw_open(struct net_device *dev);
191 static void claw_irq_handler(struct ccw_device *cdev,
192         unsigned long intparm, struct irb *irb);
193 static void claw_irq_tasklet ( unsigned long data );
194 static int claw_release(struct net_device *dev);
195 static void claw_write_retry ( struct chbk * p_ch );
196 static void claw_write_next ( struct chbk * p_ch );
197 static void claw_timer ( struct chbk * p_ch );
198
199 /* Functions */
200 static int add_claw_reads(struct net_device *dev,
201         struct ccwbk* p_first, struct ccwbk* p_last);
202 static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
203 static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
204 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
205 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
206 static int init_ccw_bk(struct net_device *dev);
207 static void probe_error( struct ccwgroup_device *cgdev);
208 static struct net_device_stats *claw_stats(struct net_device *dev);
209 static int pages_to_order_of_mag(int num_of_pages);
210 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
211 /* sysfs Functions */
212 static ssize_t claw_hname_show(struct device *dev,
213         struct device_attribute *attr, char *buf);
214 static ssize_t claw_hname_write(struct device *dev,
215         struct device_attribute *attr,
216         const char *buf, size_t count);
217 static ssize_t claw_adname_show(struct device *dev,
218         struct device_attribute *attr, char *buf);
219 static ssize_t claw_adname_write(struct device *dev,
220         struct device_attribute *attr,
221         const char *buf, size_t count);
222 static ssize_t claw_apname_show(struct device *dev,
223         struct device_attribute *attr, char *buf);
224 static ssize_t claw_apname_write(struct device *dev,
225         struct device_attribute *attr,
226         const char *buf, size_t count);
227 static ssize_t claw_wbuff_show(struct device *dev,
228         struct device_attribute *attr, char *buf);
229 static ssize_t claw_wbuff_write(struct device *dev,
230         struct device_attribute *attr,
231         const char *buf, size_t count);
232 static ssize_t claw_rbuff_show(struct device *dev,
233         struct device_attribute *attr, char *buf);
234 static ssize_t claw_rbuff_write(struct device *dev,
235         struct device_attribute *attr,
236         const char *buf, size_t count);
237 static int claw_add_files(struct device *dev);
238 static void claw_remove_files(struct device *dev);
239
240 /*   Functions for System Validate  */
241 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
242 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
243        __u8 correlator, __u8 rc , char *local_name, char *remote_name);
244 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
245 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
246 static int claw_snd_sys_validate_rsp(struct net_device *dev,
247         struct clawctl * p_ctl, __u32 return_code);
248 static int claw_strt_conn_req(struct net_device *dev );
249 static void claw_strt_read(struct net_device *dev, int lock);
250 static void claw_strt_out_IO(struct net_device *dev);
251 static void claw_free_wrt_buf(struct net_device *dev);
252
253 /* Functions for unpack reads   */
254 static void unpack_read(struct net_device *dev);
255
256 static int claw_pm_prepare(struct ccwgroup_device *gdev)
257 {
258         return -EPERM;
259 }
260
261 /* the root device for claw group devices */
262 static struct device *claw_root_dev;
263
264 /* ccwgroup table  */
265
266 static struct ccwgroup_driver claw_group_driver = {
267         .driver = {
268                 .owner  = THIS_MODULE,
269                 .name   = "claw",
270         },
271         .max_slaves  = 2,
272         .driver_id   = 0xC3D3C1E6,
273         .probe       = claw_probe,
274         .remove      = claw_remove_device,
275         .set_online  = claw_new_device,
276         .set_offline = claw_shutdown_device,
277         .prepare     = claw_pm_prepare,
278 };
279
280 static struct ccw_device_id claw_ids[] = {
281         {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
282         {},
283 };
284 MODULE_DEVICE_TABLE(ccw, claw_ids);
285
286 static struct ccw_driver claw_ccw_driver = {
287         .driver = {
288                 .owner  = THIS_MODULE,
289                 .name   = "claw",
290         },
291         .ids    = claw_ids,
292         .probe  = ccwgroup_probe_ccwdev,
293         .remove = ccwgroup_remove_ccwdev,
294 };
295
296 static ssize_t
297 claw_driver_group_store(struct device_driver *ddrv, const char *buf,
298                         size_t count)
299 {
300         int err;
301         err = ccwgroup_create_from_string(claw_root_dev,
302                                           claw_group_driver.driver_id,
303                                           &claw_ccw_driver, 2, buf);
304         return err ? err : count;
305 }
306
307 static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
308
309 static struct attribute *claw_group_attrs[] = {
310         &driver_attr_group.attr,
311         NULL,
312 };
313
314 static struct attribute_group claw_group_attr_group = {
315         .attrs = claw_group_attrs,
316 };
317
318 static const struct attribute_group *claw_group_attr_groups[] = {
319         &claw_group_attr_group,
320         NULL,
321 };
322
323 /*
324 *       Key functions
325 */
326
327 /*----------------------------------------------------------------*
328  *   claw_probe                                                   *
329  *      this function is called for each CLAW device.             *
330  *----------------------------------------------------------------*/
331 static int
332 claw_probe(struct ccwgroup_device *cgdev)
333 {
334         int             rc;
335         struct claw_privbk *privptr=NULL;
336
337         CLAW_DBF_TEXT(2, setup, "probe");
338         if (!get_device(&cgdev->dev))
339                 return -ENODEV;
340         privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
341         dev_set_drvdata(&cgdev->dev, privptr);
342         if (privptr == NULL) {
343                 probe_error(cgdev);
344                 put_device(&cgdev->dev);
345                 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
346                 return -ENOMEM;
347         }
348         privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
349         privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
350         if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
351                 probe_error(cgdev);
352                 put_device(&cgdev->dev);
353                 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
354                 return -ENOMEM;
355         }
356         memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
357         memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
358         memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
359         privptr->p_env->packing = 0;
360         privptr->p_env->write_buffers = 5;
361         privptr->p_env->read_buffers = 5;
362         privptr->p_env->read_size = CLAW_FRAME_SIZE;
363         privptr->p_env->write_size = CLAW_FRAME_SIZE;
364         rc = claw_add_files(&cgdev->dev);
365         if (rc) {
366                 probe_error(cgdev);
367                 put_device(&cgdev->dev);
368                 dev_err(&cgdev->dev, "Creating the /proc files for a new"
369                 " CLAW device failed\n");
370                 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
371                 return rc;
372         }
373         privptr->p_env->p_priv = privptr;
374         cgdev->cdev[0]->handler = claw_irq_handler;
375         cgdev->cdev[1]->handler = claw_irq_handler;
376         CLAW_DBF_TEXT(2, setup, "prbext 0");
377
378         return 0;
379 }  /*  end of claw_probe       */
380
381 /*-------------------------------------------------------------------*
382  *   claw_tx                                                         *
383  *-------------------------------------------------------------------*/
384
385 static int
386 claw_tx(struct sk_buff *skb, struct net_device *dev)
387 {
388         int             rc;
389         struct claw_privbk *privptr = dev->ml_priv;
390         unsigned long saveflags;
391         struct chbk *p_ch;
392
393         CLAW_DBF_TEXT(4, trace, "claw_tx");
394         p_ch = &privptr->channel[WRITE_CHANNEL];
395         spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
396         rc=claw_hw_tx( skb, dev, 1 );
397         spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
398         CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
399         if (rc)
400                 rc = NETDEV_TX_BUSY;
401         else
402                 rc = NETDEV_TX_OK;
403         return rc;
404 }   /*  end of claw_tx */
405
406 /*------------------------------------------------------------------*
407  *  pack the collect queue into an skb and return it                *
408  *   If not packing just return the top skb from the queue          *
409  *------------------------------------------------------------------*/
410
411 static struct sk_buff *
412 claw_pack_skb(struct claw_privbk *privptr)
413 {
414         struct sk_buff *new_skb,*held_skb;
415         struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
416         struct claw_env  *p_env = privptr->p_env;
417         int     pkt_cnt,pk_ind,so_far;
418
419         new_skb = NULL;         /* assume no dice */
420         pkt_cnt = 0;
421         CLAW_DBF_TEXT(4, trace, "PackSKBe");
422         if (!skb_queue_empty(&p_ch->collect_queue)) {
423         /* some data */
424                 held_skb = skb_dequeue(&p_ch->collect_queue);
425                 if (held_skb)
426                         dev_kfree_skb_any(held_skb);
427                 else
428                         return NULL;
429                 if (p_env->packing != DO_PACKED)
430                         return held_skb;
431                 /* get a new SKB we will pack at least one */
432                 new_skb = dev_alloc_skb(p_env->write_size);
433                 if (new_skb == NULL) {
434                         atomic_inc(&held_skb->users);
435                         skb_queue_head(&p_ch->collect_queue,held_skb);
436                         return NULL;
437                 }
438                 /* we have packed packet and a place to put it  */
439                 pk_ind = 1;
440                 so_far = 0;
441                 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
442                 while ((pk_ind) && (held_skb != NULL)) {
443                         if (held_skb->len+so_far <= p_env->write_size-8) {
444                                 memcpy(skb_put(new_skb,held_skb->len),
445                                         held_skb->data,held_skb->len);
446                                 privptr->stats.tx_packets++;
447                                 so_far += held_skb->len;
448                                 pkt_cnt++;
449                                 dev_kfree_skb_any(held_skb);
450                                 held_skb = skb_dequeue(&p_ch->collect_queue);
451                                 if (held_skb)
452                                         atomic_dec(&held_skb->users);
453                         } else {
454                                 pk_ind = 0;
455                                 atomic_inc(&held_skb->users);
456                                 skb_queue_head(&p_ch->collect_queue,held_skb);
457                         }
458                 }
459         }
460         CLAW_DBF_TEXT(4, trace, "PackSKBx");
461         return new_skb;
462 }
463
464 /*-------------------------------------------------------------------*
465  *   claw_change_mtu                                                 *
466  *                                                                   *
467  *-------------------------------------------------------------------*/
468
469 static int
470 claw_change_mtu(struct net_device *dev, int new_mtu)
471 {
472         struct claw_privbk *privptr = dev->ml_priv;
473         int buff_size;
474         CLAW_DBF_TEXT(4, trace, "setmtu");
475         buff_size = privptr->p_env->write_size;
476         if ((new_mtu < 60) || (new_mtu > buff_size)) {
477                 return -EINVAL;
478         }
479         dev->mtu = new_mtu;
480         return 0;
481 }  /*   end of claw_change_mtu */
482
483
484 /*-------------------------------------------------------------------*
485  *   claw_open                                                       *
486  *                                                                   *
487  *-------------------------------------------------------------------*/
488 static int
489 claw_open(struct net_device *dev)
490 {
491
492         int     rc;
493         int     i;
494         unsigned long       saveflags=0;
495         unsigned long       parm;
496         struct claw_privbk  *privptr;
497         DECLARE_WAITQUEUE(wait, current);
498         struct timer_list  timer;
499         struct ccwbk *p_buf;
500
501         CLAW_DBF_TEXT(4, trace, "open");
502         privptr = (struct claw_privbk *)dev->ml_priv;
503         /*   allocate and initialize CCW blocks */
504         if (privptr->buffs_alloc == 0) {
505                 rc=init_ccw_bk(dev);
506                 if (rc) {
507                         CLAW_DBF_TEXT(2, trace, "openmem");
508                         return -ENOMEM;
509                 }
510         }
511         privptr->system_validate_comp=0;
512         privptr->release_pend=0;
513         if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
514                 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
515                 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
516                 privptr->p_env->packing=PACKING_ASK;
517         } else {
518                 privptr->p_env->packing=0;
519                 privptr->p_env->read_size=CLAW_FRAME_SIZE;
520                 privptr->p_env->write_size=CLAW_FRAME_SIZE;
521         }
522         claw_set_busy(dev);
523         tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
524                 (unsigned long) &privptr->channel[READ_CHANNEL]);
525         for ( i = 0; i < 2;  i++) {
526                 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
527                 init_waitqueue_head(&privptr->channel[i].wait);
528                 /* skb_queue_head_init(&p_ch->io_queue); */
529                 if (i == WRITE_CHANNEL)
530                         skb_queue_head_init(
531                                 &privptr->channel[WRITE_CHANNEL].collect_queue);
532                 privptr->channel[i].flag_a = 0;
533                 privptr->channel[i].IO_active = 0;
534                 privptr->channel[i].flag  &= ~CLAW_TIMER;
535                 init_timer(&timer);
536                 timer.function = (void *)claw_timer;
537                 timer.data = (unsigned long)(&privptr->channel[i]);
538                 timer.expires = jiffies + 15*HZ;
539                 add_timer(&timer);
540                 spin_lock_irqsave(get_ccwdev_lock(
541                         privptr->channel[i].cdev), saveflags);
542                 parm = (unsigned long) &privptr->channel[i];
543                 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
544                 rc = 0;
545                 add_wait_queue(&privptr->channel[i].wait, &wait);
546                 rc = ccw_device_halt(
547                         (struct ccw_device *)privptr->channel[i].cdev,parm);
548                 set_current_state(TASK_INTERRUPTIBLE);
549                 spin_unlock_irqrestore(
550                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
551                 schedule();
552                 set_current_state(TASK_RUNNING);
553                 remove_wait_queue(&privptr->channel[i].wait, &wait);
554                 if(rc != 0)
555                         ccw_check_return_code(privptr->channel[i].cdev, rc);
556                 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
557                         del_timer(&timer);
558         }
559         if ((((privptr->channel[READ_CHANNEL].last_dstat |
560                 privptr->channel[WRITE_CHANNEL].last_dstat) &
561            ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
562            (((privptr->channel[READ_CHANNEL].flag |
563                 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
564                 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
565                         "%s: remote side is not ready\n", dev->name);
566                 CLAW_DBF_TEXT(2, trace, "notrdy");
567
568                 for ( i = 0; i < 2;  i++) {
569                         spin_lock_irqsave(
570                                 get_ccwdev_lock(privptr->channel[i].cdev),
571                                 saveflags);
572                         parm = (unsigned long) &privptr->channel[i];
573                         privptr->channel[i].claw_state = CLAW_STOP;
574                         rc = ccw_device_halt(
575                                 (struct ccw_device *)&privptr->channel[i].cdev,
576                                 parm);
577                         spin_unlock_irqrestore(
578                                 get_ccwdev_lock(privptr->channel[i].cdev),
579                                 saveflags);
580                         if (rc != 0) {
581                                 ccw_check_return_code(
582                                         privptr->channel[i].cdev, rc);
583                         }
584                 }
585                 free_pages((unsigned long)privptr->p_buff_ccw,
586                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
587                 if (privptr->p_env->read_size < PAGE_SIZE) {
588                         free_pages((unsigned long)privptr->p_buff_read,
589                                (int)pages_to_order_of_mag(
590                                         privptr->p_buff_read_num));
591                 }
592                 else {
593                         p_buf=privptr->p_read_active_first;
594                         while (p_buf!=NULL) {
595                                 free_pages((unsigned long)p_buf->p_buffer,
596                                       (int)pages_to_order_of_mag(
597                                         privptr->p_buff_pages_perread ));
598                                 p_buf=p_buf->next;
599                         }
600                 }
601                 if (privptr->p_env->write_size < PAGE_SIZE ) {
602                         free_pages((unsigned long)privptr->p_buff_write,
603                              (int)pages_to_order_of_mag(
604                                 privptr->p_buff_write_num));
605                 }
606                 else {
607                         p_buf=privptr->p_write_active_first;
608                         while (p_buf!=NULL) {
609                                 free_pages((unsigned long)p_buf->p_buffer,
610                                      (int)pages_to_order_of_mag(
611                                         privptr->p_buff_pages_perwrite ));
612                                 p_buf=p_buf->next;
613                         }
614                 }
615                 privptr->buffs_alloc = 0;
616                 privptr->channel[READ_CHANNEL].flag = 0x00;
617                 privptr->channel[WRITE_CHANNEL].flag = 0x00;
618                 privptr->p_buff_ccw=NULL;
619                 privptr->p_buff_read=NULL;
620                 privptr->p_buff_write=NULL;
621                 claw_clear_busy(dev);
622                 CLAW_DBF_TEXT(2, trace, "open EIO");
623                 return -EIO;
624         }
625
626         /*   Send SystemValidate command */
627
628         claw_clear_busy(dev);
629         CLAW_DBF_TEXT(4, trace, "openok");
630         return 0;
631 }    /*     end of claw_open    */
632
633 /*-------------------------------------------------------------------*
634 *                                                                    *
635 *       claw_irq_handler                                             *
636 *                                                                    *
637 *--------------------------------------------------------------------*/
638 static void
639 claw_irq_handler(struct ccw_device *cdev,
640         unsigned long intparm, struct irb *irb)
641 {
642         struct chbk *p_ch = NULL;
643         struct claw_privbk *privptr = NULL;
644         struct net_device *dev = NULL;
645         struct claw_env  *p_env;
646         struct chbk *p_ch_r=NULL;
647
648         kstat_cpu(smp_processor_id()).irqs[IOINT_CLW]++;
649         CLAW_DBF_TEXT(4, trace, "clawirq");
650         /* Bypass all 'unsolicited interrupts' */
651         privptr = dev_get_drvdata(&cdev->dev);
652         if (!privptr) {
653                 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
654                         " IRQ, c-%02x d-%02x\n",
655                         irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
656                 CLAW_DBF_TEXT(2, trace, "badirq");
657                 return;
658         }
659
660         /* Try to extract channel from driver data. */
661         if (privptr->channel[READ_CHANNEL].cdev == cdev)
662                 p_ch = &privptr->channel[READ_CHANNEL];
663         else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
664                 p_ch = &privptr->channel[WRITE_CHANNEL];
665         else {
666                 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
667                 CLAW_DBF_TEXT(2, trace, "badchan");
668                 return;
669         }
670         CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
671
672         dev = (struct net_device *) (p_ch->ndev);
673         p_env=privptr->p_env;
674
675         /* Copy interruption response block. */
676         memcpy(p_ch->irb, irb, sizeof(struct irb));
677
678         /* Check for good subchannel return code, otherwise info message */
679         if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
680                 dev_info(&cdev->dev,
681                         "%s: subchannel check for device: %04x -"
682                         " Sch Stat %02x  Dev Stat %02x CPA - %04x\n",
683                         dev->name, p_ch->devno,
684                         irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
685                         irb->scsw.cmd.cpa);
686                 CLAW_DBF_TEXT(2, trace, "chanchk");
687                 /* return; */
688         }
689
690         /* Check the reason-code of a unit check */
691         if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
692                 ccw_check_unit_check(p_ch, irb->ecw[0]);
693
694         /* State machine to bring the connection up, down and to restart */
695         p_ch->last_dstat = irb->scsw.cmd.dstat;
696
697         switch (p_ch->claw_state) {
698         case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
699                 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
700                 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
701                 (p_ch->irb->scsw.cmd.stctl ==
702                 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
703                         return;
704                 wake_up(&p_ch->wait);   /* wake up claw_release */
705                 CLAW_DBF_TEXT(4, trace, "stop");
706                 return;
707         case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open  */
708                 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
709                 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
710                 (p_ch->irb->scsw.cmd.stctl ==
711                 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
712                         CLAW_DBF_TEXT(4, trace, "haltio");
713                         return;
714                 }
715                 if (p_ch->flag == CLAW_READ) {
716                         p_ch->claw_state = CLAW_START_READ;
717                         wake_up(&p_ch->wait); /* wake claw_open (READ)*/
718                 } else if (p_ch->flag == CLAW_WRITE) {
719                         p_ch->claw_state = CLAW_START_WRITE;
720                         /*      send SYSTEM_VALIDATE                    */
721                         claw_strt_read(dev, LOCK_NO);
722                         claw_send_control(dev,
723                                 SYSTEM_VALIDATE_REQUEST,
724                                 0, 0, 0,
725                                 p_env->host_name,
726                                 p_env->adapter_name);
727                 } else {
728                         dev_warn(&cdev->dev, "The CLAW device received"
729                                 " an unexpected IRQ, "
730                                 "c-%02x d-%02x\n",
731                                 irb->scsw.cmd.cstat,
732                                 irb->scsw.cmd.dstat);
733                         return;
734                         }
735                 CLAW_DBF_TEXT(4, trace, "haltio");
736                 return;
737         case CLAW_START_READ:
738                 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
739                 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
740                         clear_bit(0, (void *)&p_ch->IO_active);
741                         if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
742                             (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
743                             (p_ch->irb->ecw[0])        == 0) {
744                                 privptr->stats.rx_errors++;
745                                 dev_info(&cdev->dev,
746                                         "%s: Restart is required after remote "
747                                         "side recovers \n",
748                                         dev->name);
749                         }
750                         CLAW_DBF_TEXT(4, trace, "notrdy");
751                         return;
752                 }
753                 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
754                         (p_ch->irb->scsw.cmd.dstat == 0)) {
755                         if (test_and_set_bit(CLAW_BH_ACTIVE,
756                                 (void *)&p_ch->flag_a) == 0)
757                                 tasklet_schedule(&p_ch->tasklet);
758                         else
759                                 CLAW_DBF_TEXT(4, trace, "PCINoBH");
760                         CLAW_DBF_TEXT(4, trace, "PCI_read");
761                         return;
762                 }
763                 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
764                  (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
765                  (p_ch->irb->scsw.cmd.stctl ==
766                  (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
767                         CLAW_DBF_TEXT(4, trace, "SPend_rd");
768                         return;
769                 }
770                 clear_bit(0, (void *)&p_ch->IO_active);
771                 claw_clearbit_busy(TB_RETRY, dev);
772                 if (test_and_set_bit(CLAW_BH_ACTIVE,
773                         (void *)&p_ch->flag_a) == 0)
774                         tasklet_schedule(&p_ch->tasklet);
775                 else
776                         CLAW_DBF_TEXT(4, trace, "RdBHAct");
777                 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
778                 return;
779         case CLAW_START_WRITE:
780                 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
781                         dev_info(&cdev->dev,
782                                 "%s: Unit Check Occurred in "
783                                 "write channel\n", dev->name);
784                         clear_bit(0, (void *)&p_ch->IO_active);
785                         if (p_ch->irb->ecw[0] & 0x80) {
786                                 dev_info(&cdev->dev,
787                                         "%s: Resetting Event "
788                                         "occurred:\n", dev->name);
789                                 init_timer(&p_ch->timer);
790                                 p_ch->timer.function =
791                                         (void *)claw_write_retry;
792                                 p_ch->timer.data = (unsigned long)p_ch;
793                                 p_ch->timer.expires = jiffies + 10*HZ;
794                                 add_timer(&p_ch->timer);
795                                 dev_info(&cdev->dev,
796                                         "%s: write connection "
797                                         "restarting\n", dev->name);
798                         }
799                         CLAW_DBF_TEXT(4, trace, "rstrtwrt");
800                         return;
801                 }
802                 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
803                         clear_bit(0, (void *)&p_ch->IO_active);
804                         dev_info(&cdev->dev,
805                                 "%s: Unit Exception "
806                                 "occurred in write channel\n",
807                                 dev->name);
808                 }
809                 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
810                 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
811                 (p_ch->irb->scsw.cmd.stctl ==
812                 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
813                         CLAW_DBF_TEXT(4, trace, "writeUE");
814                         return;
815                 }
816                 clear_bit(0, (void *)&p_ch->IO_active);
817                 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
818                         claw_write_next(p_ch);
819                         claw_clearbit_busy(TB_TX, dev);
820                         claw_clear_busy(dev);
821                 }
822                 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
823                 if (test_and_set_bit(CLAW_BH_ACTIVE,
824                         (void *)&p_ch_r->flag_a) == 0)
825                         tasklet_schedule(&p_ch_r->tasklet);
826                 CLAW_DBF_TEXT(4, trace, "StWtExit");
827                 return;
828         default:
829                 dev_warn(&cdev->dev,
830                         "The CLAW device for %s received an unexpected IRQ\n",
831                          dev->name);
832                 CLAW_DBF_TEXT(2, trace, "badIRQ");
833                 return;
834         }
835
836 }       /*   end of claw_irq_handler    */
837
838
839 /*-------------------------------------------------------------------*
840 *       claw_irq_tasklet                                             *
841 *                                                                    *
842 *--------------------------------------------------------------------*/
843 static void
844 claw_irq_tasklet ( unsigned long data )
845 {
846         struct chbk * p_ch;
847         struct net_device  *dev;
848         struct claw_privbk *       privptr;
849
850         p_ch = (struct chbk *) data;
851         dev = (struct net_device *)p_ch->ndev;
852         CLAW_DBF_TEXT(4, trace, "IRQtask");
853         privptr = (struct claw_privbk *)dev->ml_priv;
854         unpack_read(dev);
855         clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
856         CLAW_DBF_TEXT(4, trace, "TskletXt");
857         return;
858 }       /*    end of claw_irq_bh    */
859
860 /*-------------------------------------------------------------------*
861 *       claw_release                                                 *
862 *                                                                    *
863 *--------------------------------------------------------------------*/
864 static int
865 claw_release(struct net_device *dev)
866 {
867         int                rc;
868         int                i;
869         unsigned long      saveflags;
870         unsigned long      parm;
871         struct claw_privbk *privptr;
872         DECLARE_WAITQUEUE(wait, current);
873         struct ccwbk*             p_this_ccw;
874         struct ccwbk*             p_buf;
875
876         if (!dev)
877                 return 0;
878         privptr = (struct claw_privbk *)dev->ml_priv;
879         if (!privptr)
880                 return 0;
881         CLAW_DBF_TEXT(4, trace, "release");
882         privptr->release_pend=1;
883         claw_setbit_busy(TB_STOP,dev);
884         for ( i = 1; i >=0 ;  i--) {
885                 spin_lock_irqsave(
886                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
887              /*   del_timer(&privptr->channel[READ_CHANNEL].timer);  */
888                 privptr->channel[i].claw_state = CLAW_STOP;
889                 privptr->channel[i].IO_active = 0;
890                 parm = (unsigned long) &privptr->channel[i];
891                 if (i == WRITE_CHANNEL)
892                         claw_purge_skb_queue(
893                                 &privptr->channel[WRITE_CHANNEL].collect_queue);
894                 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
895                 if (privptr->system_validate_comp==0x00)  /* never opened? */
896                    init_waitqueue_head(&privptr->channel[i].wait);
897                 add_wait_queue(&privptr->channel[i].wait, &wait);
898                 set_current_state(TASK_INTERRUPTIBLE);
899                 spin_unlock_irqrestore(
900                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
901                 schedule();
902                 set_current_state(TASK_RUNNING);
903                 remove_wait_queue(&privptr->channel[i].wait, &wait);
904                 if (rc != 0) {
905                         ccw_check_return_code(privptr->channel[i].cdev, rc);
906                 }
907         }
908         if (privptr->pk_skb != NULL) {
909                 dev_kfree_skb_any(privptr->pk_skb);
910                 privptr->pk_skb = NULL;
911         }
912         if(privptr->buffs_alloc != 1) {
913                 CLAW_DBF_TEXT(4, trace, "none2fre");
914                 return 0;
915         }
916         CLAW_DBF_TEXT(4, trace, "freebufs");
917         if (privptr->p_buff_ccw != NULL) {
918                 free_pages((unsigned long)privptr->p_buff_ccw,
919                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
920         }
921         CLAW_DBF_TEXT(4, trace, "freeread");
922         if (privptr->p_env->read_size < PAGE_SIZE) {
923             if (privptr->p_buff_read != NULL) {
924                 free_pages((unsigned long)privptr->p_buff_read,
925                       (int)pages_to_order_of_mag(privptr->p_buff_read_num));
926                 }
927         }
928         else {
929                 p_buf=privptr->p_read_active_first;
930                 while (p_buf!=NULL) {
931                         free_pages((unsigned long)p_buf->p_buffer,
932                              (int)pages_to_order_of_mag(
933                                 privptr->p_buff_pages_perread ));
934                         p_buf=p_buf->next;
935                 }
936         }
937          CLAW_DBF_TEXT(4, trace, "freewrit");
938         if (privptr->p_env->write_size < PAGE_SIZE ) {
939                 free_pages((unsigned long)privptr->p_buff_write,
940                       (int)pages_to_order_of_mag(privptr->p_buff_write_num));
941         }
942         else {
943                 p_buf=privptr->p_write_active_first;
944                 while (p_buf!=NULL) {
945                         free_pages((unsigned long)p_buf->p_buffer,
946                               (int)pages_to_order_of_mag(
947                               privptr->p_buff_pages_perwrite ));
948                         p_buf=p_buf->next;
949                 }
950         }
951          CLAW_DBF_TEXT(4, trace, "clearptr");
952         privptr->buffs_alloc = 0;
953         privptr->p_buff_ccw=NULL;
954         privptr->p_buff_read=NULL;
955         privptr->p_buff_write=NULL;
956         privptr->system_validate_comp=0;
957         privptr->release_pend=0;
958         /*      Remove any writes that were pending and reset all reads   */
959         p_this_ccw=privptr->p_read_active_first;
960         while (p_this_ccw!=NULL) {
961                 p_this_ccw->header.length=0xffff;
962                 p_this_ccw->header.opcode=0xff;
963                 p_this_ccw->header.flag=0x00;
964                 p_this_ccw=p_this_ccw->next;
965         }
966
967         while (privptr->p_write_active_first!=NULL) {
968                 p_this_ccw=privptr->p_write_active_first;
969                 p_this_ccw->header.flag=CLAW_PENDING;
970                 privptr->p_write_active_first=p_this_ccw->next;
971                 p_this_ccw->next=privptr->p_write_free_chain;
972                 privptr->p_write_free_chain=p_this_ccw;
973                 ++privptr->write_free_count;
974         }
975         privptr->p_write_active_last=NULL;
976         privptr->mtc_logical_link = -1;
977         privptr->mtc_skipping = 1;
978         privptr->mtc_offset=0;
979
980         if (((privptr->channel[READ_CHANNEL].last_dstat |
981                 privptr->channel[WRITE_CHANNEL].last_dstat) &
982                 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
983                 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
984                         "Deactivating %s completed with incorrect"
985                         " subchannel status "
986                         "(read %02x, write %02x)\n",
987                 dev->name,
988                 privptr->channel[READ_CHANNEL].last_dstat,
989                 privptr->channel[WRITE_CHANNEL].last_dstat);
990                  CLAW_DBF_TEXT(2, trace, "badclose");
991         }
992         CLAW_DBF_TEXT(4, trace, "rlsexit");
993         return 0;
994 }      /* end of claw_release     */
995
996 /*-------------------------------------------------------------------*
997 *       claw_write_retry                                             *
998 *                                                                    *
999 *--------------------------------------------------------------------*/
1000
1001 static void
1002 claw_write_retry ( struct chbk *p_ch )
1003 {
1004
1005         struct net_device  *dev=p_ch->ndev;
1006
1007         CLAW_DBF_TEXT(4, trace, "w_retry");
1008         if (p_ch->claw_state == CLAW_STOP) {
1009                 return;
1010         }
1011         claw_strt_out_IO( dev );
1012         CLAW_DBF_TEXT(4, trace, "rtry_xit");
1013         return;
1014 }      /* end of claw_write_retry      */
1015
1016
1017 /*-------------------------------------------------------------------*
1018 *       claw_write_next                                              *
1019 *                                                                    *
1020 *--------------------------------------------------------------------*/
1021
1022 static void
1023 claw_write_next ( struct chbk * p_ch )
1024 {
1025
1026         struct net_device  *dev;
1027         struct claw_privbk *privptr=NULL;
1028         struct sk_buff *pk_skb;
1029         int     rc;
1030
1031         CLAW_DBF_TEXT(4, trace, "claw_wrt");
1032         if (p_ch->claw_state == CLAW_STOP)
1033                 return;
1034         dev = (struct net_device *) p_ch->ndev;
1035         privptr = (struct claw_privbk *) dev->ml_priv;
1036         claw_free_wrt_buf( dev );
1037         if ((privptr->write_free_count > 0) &&
1038             !skb_queue_empty(&p_ch->collect_queue)) {
1039                 pk_skb = claw_pack_skb(privptr);
1040                 while (pk_skb != NULL) {
1041                         rc = claw_hw_tx( pk_skb, dev,1);
1042                         if (privptr->write_free_count > 0) {
1043                                 pk_skb = claw_pack_skb(privptr);
1044                         } else
1045                                 pk_skb = NULL;
1046                 }
1047         }
1048         if (privptr->p_write_active_first!=NULL) {
1049                 claw_strt_out_IO(dev);
1050         }
1051         return;
1052 }      /* end of claw_write_next      */
1053
1054 /*-------------------------------------------------------------------*
1055 *                                                                    *
1056 *       claw_timer                                                   *
1057 *--------------------------------------------------------------------*/
1058
1059 static void
1060 claw_timer ( struct chbk * p_ch )
1061 {
1062         CLAW_DBF_TEXT(4, trace, "timer");
1063         p_ch->flag |= CLAW_TIMER;
1064         wake_up(&p_ch->wait);
1065         return;
1066 }      /* end of claw_timer  */
1067
1068 /*
1069 *
1070 *       functions
1071 */
1072
1073
1074 /*-------------------------------------------------------------------*
1075 *                                                                    *
1076 *     pages_to_order_of_mag                                          *
1077 *                                                                    *
1078 *    takes a number of pages from 1 to 512 and returns the           *
1079 *    log(num_pages)/log(2) get_free_pages() needs a base 2 order     *
1080 *    of magnitude get_free_pages() has an upper order of 9           *
1081 *--------------------------------------------------------------------*/
1082
1083 static int
1084 pages_to_order_of_mag(int num_of_pages)
1085 {
1086         int     order_of_mag=1;         /* assume 2 pages */
1087         int     nump;
1088
1089         CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
1090         if (num_of_pages == 1)   {return 0; }  /* magnitude of 0 = 1 page */
1091         /* 512 pages = 2Meg on 4k page systems */
1092         if (num_of_pages >= 512) {return 9; }
1093         /* we have two or more pages order is at least 1 */
1094         for (nump=2 ;nump <= 512;nump*=2) {
1095           if (num_of_pages <= nump)
1096                   break;
1097           order_of_mag +=1;
1098         }
1099         if (order_of_mag > 9) { order_of_mag = 9; }  /* I know it's paranoid */
1100         CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
1101         return order_of_mag;
1102 }
1103
1104 /*-------------------------------------------------------------------*
1105 *                                                                    *
1106 *     add_claw_reads                                                 *
1107 *                                                                    *
1108 *--------------------------------------------------------------------*/
1109 static int
1110 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1111         struct ccwbk* p_last)
1112 {
1113         struct claw_privbk *privptr;
1114         struct ccw1  temp_ccw;
1115         struct endccw * p_end;
1116         CLAW_DBF_TEXT(4, trace, "addreads");
1117         privptr = dev->ml_priv;
1118         p_end = privptr->p_end_ccw;
1119
1120         /* first CCW and last CCW contains a new set of read channel programs
1121         *       to apend the running channel programs
1122         */
1123         if ( p_first==NULL) {
1124                 CLAW_DBF_TEXT(4, trace, "addexit");
1125                 return 0;
1126         }
1127
1128         /* set up ending CCW sequence for this segment */
1129         if (p_end->read1) {
1130                 p_end->read1=0x00;    /*  second ending CCW is now active */
1131                 /*      reset ending CCWs and setup TIC CCWs              */
1132                 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1133                 p_end->read2_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1134                 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1135                 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1136                 p_end->read2_nop2.cda=0;
1137                 p_end->read2_nop2.count=1;
1138         }
1139         else {
1140                 p_end->read1=0x01;  /* first ending CCW is now active */
1141                 /*      reset ending CCWs and setup TIC CCWs          */
1142                 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1143                 p_end->read1_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1144                 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1145                 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1146                 p_end->read1_nop2.cda=0;
1147                 p_end->read1_nop2.count=1;
1148         }
1149
1150         if ( privptr-> p_read_active_first ==NULL ) {
1151                 privptr->p_read_active_first = p_first;  /*  set new first */
1152                 privptr->p_read_active_last  = p_last;   /*  set new last  */
1153         }
1154         else {
1155
1156                 /* set up TIC ccw  */
1157                 temp_ccw.cda= (__u32)__pa(&p_first->read);
1158                 temp_ccw.count=0;
1159                 temp_ccw.flags=0;
1160                 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1161
1162
1163                 if (p_end->read1) {
1164
1165                /* first set of CCW's is chained to the new read              */
1166                /* chain, so the second set is chained to the active chain.   */
1167                /* Therefore modify the second set to point to the new        */
1168                /* read chain set up TIC CCWs                                 */
1169                /* make sure we update the CCW so channel doesn't fetch it    */
1170                /* when it's only half done                                   */
1171                         memcpy( &p_end->read2_nop2, &temp_ccw ,
1172                                 sizeof(struct ccw1));
1173                         privptr->p_read_active_last->r_TIC_1.cda=
1174                                 (__u32)__pa(&p_first->read);
1175                         privptr->p_read_active_last->r_TIC_2.cda=
1176                                 (__u32)__pa(&p_first->read);
1177                 }
1178                 else {
1179                         /* make sure we update the CCW so channel doesn't   */
1180                         /* fetch it when it is only half done               */
1181                         memcpy( &p_end->read1_nop2, &temp_ccw ,
1182                                 sizeof(struct ccw1));
1183                         privptr->p_read_active_last->r_TIC_1.cda=
1184                                 (__u32)__pa(&p_first->read);
1185                         privptr->p_read_active_last->r_TIC_2.cda=
1186                                 (__u32)__pa(&p_first->read);
1187                 }
1188                 /*      chain in new set of blocks                         */
1189                 privptr->p_read_active_last->next = p_first;
1190                 privptr->p_read_active_last=p_last;
1191         } /* end of if ( privptr-> p_read_active_first ==NULL)  */
1192         CLAW_DBF_TEXT(4, trace, "addexit");
1193         return 0;
1194 }    /*     end of add_claw_reads   */
1195
1196 /*-------------------------------------------------------------------*
1197  *   ccw_check_return_code                                           *
1198  *                                                                   *
1199  *-------------------------------------------------------------------*/
1200
1201 static void
1202 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1203 {
1204         CLAW_DBF_TEXT(4, trace, "ccwret");
1205         if (return_code != 0) {
1206                 switch (return_code) {
1207                 case -EBUSY: /* BUSY is a transient state no action needed */
1208                         break;
1209                 case -ENODEV:
1210                         dev_err(&cdev->dev, "The remote channel adapter is not"
1211                                 " available\n");
1212                         break;
1213                 case -EINVAL:
1214                         dev_err(&cdev->dev,
1215                                 "The status of the remote channel adapter"
1216                                 " is not valid\n");
1217                         break;
1218                 default:
1219                         dev_err(&cdev->dev, "The common device layer"
1220                                 " returned error code %d\n",
1221                                   return_code);
1222                 }
1223         }
1224         CLAW_DBF_TEXT(4, trace, "ccwret");
1225 }    /*    end of ccw_check_return_code   */
1226
1227 /*-------------------------------------------------------------------*
1228 *       ccw_check_unit_check                                         *
1229 *--------------------------------------------------------------------*/
1230
1231 static void
1232 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1233 {
1234         struct net_device *ndev = p_ch->ndev;
1235         struct device *dev = &p_ch->cdev->dev;
1236
1237         CLAW_DBF_TEXT(4, trace, "unitchek");
1238         dev_warn(dev, "The communication peer of %s disconnected\n",
1239                 ndev->name);
1240
1241         if (sense & 0x40) {
1242                 if (sense & 0x01) {
1243                         dev_warn(dev, "The remote channel adapter for"
1244                                 " %s has been reset\n",
1245                                 ndev->name);
1246                 }
1247         } else if (sense & 0x20) {
1248                 if (sense & 0x04) {
1249                         dev_warn(dev, "A data streaming timeout occurred"
1250                                 " for %s\n",
1251                                 ndev->name);
1252                 } else if (sense & 0x10) {
1253                         dev_warn(dev, "The remote channel adapter for %s"
1254                                 " is faulty\n",
1255                                 ndev->name);
1256                 } else {
1257                         dev_warn(dev, "A data transfer parity error occurred"
1258                                 " for %s\n",
1259                                 ndev->name);
1260                 }
1261         } else if (sense & 0x10) {
1262                 dev_warn(dev, "A read data parity error occurred"
1263                         " for %s\n",
1264                         ndev->name);
1265         }
1266
1267 }   /*    end of ccw_check_unit_check    */
1268
1269 /*-------------------------------------------------------------------*
1270 *               find_link                                            *
1271 *--------------------------------------------------------------------*/
1272 static int
1273 find_link(struct net_device *dev, char *host_name, char *ws_name )
1274 {
1275         struct claw_privbk *privptr;
1276         struct claw_env *p_env;
1277         int    rc=0;
1278
1279         CLAW_DBF_TEXT(2, setup, "findlink");
1280         privptr = dev->ml_priv;
1281         p_env=privptr->p_env;
1282         switch (p_env->packing)
1283         {
1284                 case  PACKING_ASK:
1285                         if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1286                             (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1287                              rc = EINVAL;
1288                         break;
1289                 case  DO_PACKED:
1290                 case  PACK_SEND:
1291                         if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1292                             (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1293                                 rc = EINVAL;
1294                         break;
1295                 default:
1296                         if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1297                             (memcmp(p_env->api_type , ws_name, 8)!=0))
1298                                 rc = EINVAL;
1299                         break;
1300         }
1301
1302         return rc;
1303 }    /*    end of find_link    */
1304
1305 /*-------------------------------------------------------------------*
1306  *   claw_hw_tx                                                      *
1307  *                                                                   *
1308  *                                                                   *
1309  *-------------------------------------------------------------------*/
1310
1311 static int
1312 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1313 {
1314         int                             rc=0;
1315         struct claw_privbk              *privptr;
1316         struct ccwbk           *p_this_ccw;
1317         struct ccwbk           *p_first_ccw;
1318         struct ccwbk           *p_last_ccw;
1319         __u32                           numBuffers;
1320         signed long                     len_of_data;
1321         unsigned long                   bytesInThisBuffer;
1322         unsigned char                   *pDataAddress;
1323         struct endccw                   *pEnd;
1324         struct ccw1                     tempCCW;
1325         struct chbk                     *p_ch;
1326         struct claw_env                 *p_env;
1327         int                             lock;
1328         struct clawph                   *pk_head;
1329         struct chbk                     *ch;
1330
1331         CLAW_DBF_TEXT(4, trace, "hw_tx");
1332         privptr = (struct claw_privbk *)(dev->ml_priv);
1333         p_ch = (struct chbk *)&privptr->channel[WRITE_CHANNEL];
1334         p_env =privptr->p_env;
1335         claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1336         /*  scan the write queue to free any completed write packets   */
1337         p_first_ccw=NULL;
1338         p_last_ccw=NULL;
1339         if ((p_env->packing >= PACK_SEND) &&
1340             (skb->cb[1] != 'P')) {
1341                 skb_push(skb,sizeof(struct clawph));
1342                 pk_head=(struct clawph *)skb->data;
1343                 pk_head->len=skb->len-sizeof(struct clawph);
1344                 if (pk_head->len%4)  {
1345                         pk_head->len+= 4-(pk_head->len%4);
1346                         skb_pad(skb,4-(pk_head->len%4));
1347                         skb_put(skb,4-(pk_head->len%4));
1348                 }
1349                 if (p_env->packing == DO_PACKED)
1350                         pk_head->link_num = linkid;
1351                 else
1352                         pk_head->link_num = 0;
1353                 pk_head->flag = 0x00;
1354                 skb_pad(skb,4);
1355                 skb->cb[1] = 'P';
1356         }
1357         if (linkid == 0) {
1358                 if (claw_check_busy(dev)) {
1359                         if (privptr->write_free_count!=0) {
1360                                 claw_clear_busy(dev);
1361                         }
1362                         else {
1363                                 claw_strt_out_IO(dev );
1364                                 claw_free_wrt_buf( dev );
1365                                 if (privptr->write_free_count==0) {
1366                                         ch = &privptr->channel[WRITE_CHANNEL];
1367                                         atomic_inc(&skb->users);
1368                                         skb_queue_tail(&ch->collect_queue, skb);
1369                                         goto Done;
1370                                 }
1371                                 else {
1372                                         claw_clear_busy(dev);
1373                                 }
1374                         }
1375                 }
1376                 /*  tx lock  */
1377                 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1378                         ch = &privptr->channel[WRITE_CHANNEL];
1379                         atomic_inc(&skb->users);
1380                         skb_queue_tail(&ch->collect_queue, skb);
1381                         claw_strt_out_IO(dev );
1382                         rc=-EBUSY;
1383                         goto Done2;
1384                 }
1385         }
1386         /*      See how many write buffers are required to hold this data */
1387         numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
1388
1389         /*      If that number of buffers isn't available, give up for now */
1390         if (privptr->write_free_count < numBuffers ||
1391             privptr->p_write_free_chain == NULL ) {
1392
1393                 claw_setbit_busy(TB_NOBUFFER,dev);
1394                 ch = &privptr->channel[WRITE_CHANNEL];
1395                 atomic_inc(&skb->users);
1396                 skb_queue_tail(&ch->collect_queue, skb);
1397                 CLAW_DBF_TEXT(2, trace, "clawbusy");
1398                 goto Done2;
1399         }
1400         pDataAddress=skb->data;
1401         len_of_data=skb->len;
1402
1403         while (len_of_data > 0) {
1404                 p_this_ccw=privptr->p_write_free_chain;  /* get a block */
1405                 if (p_this_ccw == NULL) { /* lost the race */
1406                         ch = &privptr->channel[WRITE_CHANNEL];
1407                         atomic_inc(&skb->users);
1408                         skb_queue_tail(&ch->collect_queue, skb);
1409                         goto Done2;
1410                 }
1411                 privptr->p_write_free_chain=p_this_ccw->next;
1412                 p_this_ccw->next=NULL;
1413                 --privptr->write_free_count; /* -1 */
1414                 if (len_of_data >= privptr->p_env->write_size)
1415                         bytesInThisBuffer = privptr->p_env->write_size;
1416                 else
1417                         bytesInThisBuffer = len_of_data;
1418                 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1419                 len_of_data-=bytesInThisBuffer;
1420                 pDataAddress+=(unsigned long)bytesInThisBuffer;
1421                 /*      setup write CCW         */
1422                 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1423                 if (len_of_data>0) {
1424                         p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1425                 }
1426                 p_this_ccw->write.count=bytesInThisBuffer;
1427                 /*      now add to end of this chain    */
1428                 if (p_first_ccw==NULL)    {
1429                         p_first_ccw=p_this_ccw;
1430                 }
1431                 if (p_last_ccw!=NULL) {
1432                         p_last_ccw->next=p_this_ccw;
1433                         /*      set up TIC ccws         */
1434                         p_last_ccw->w_TIC_1.cda=
1435                                 (__u32)__pa(&p_this_ccw->write);
1436                 }
1437                 p_last_ccw=p_this_ccw;      /* save new last block */
1438         }
1439
1440         /*      FirstCCW and LastCCW now contain a new set of write channel
1441         *       programs to append to the running channel program
1442         */
1443
1444         if (p_first_ccw!=NULL) {
1445                 /*      setup ending ccw sequence for this segment           */
1446                 pEnd=privptr->p_end_ccw;
1447                 if (pEnd->write1) {
1448                         pEnd->write1=0x00;   /* second end ccw is now active */
1449                         /*      set up Tic CCWs         */
1450                         p_last_ccw->w_TIC_1.cda=
1451                                 (__u32)__pa(&pEnd->write2_nop1);
1452                         pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1453                         pEnd->write2_nop2.flags    =
1454                                 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1455                         pEnd->write2_nop2.cda=0;
1456                         pEnd->write2_nop2.count=1;
1457                 }
1458                 else {  /*  end of if (pEnd->write1)*/
1459                         pEnd->write1=0x01;   /* first end ccw is now active */
1460                         /*      set up Tic CCWs         */
1461                         p_last_ccw->w_TIC_1.cda=
1462                                 (__u32)__pa(&pEnd->write1_nop1);
1463                         pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1464                         pEnd->write1_nop2.flags    =
1465                                 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1466                         pEnd->write1_nop2.cda=0;
1467                         pEnd->write1_nop2.count=1;
1468                 }  /* end if if (pEnd->write1) */
1469
1470                 if (privptr->p_write_active_first==NULL ) {
1471                         privptr->p_write_active_first=p_first_ccw;
1472                         privptr->p_write_active_last=p_last_ccw;
1473                 }
1474                 else {
1475                         /*      set up Tic CCWs         */
1476
1477                         tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1478                         tempCCW.count=0;
1479                         tempCCW.flags=0;
1480                         tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1481
1482                         if (pEnd->write1) {
1483
1484                  /*
1485                  * first set of ending CCW's is chained to the new write
1486                  * chain, so the second set is chained to the active chain
1487                  * Therefore modify the second set to point the new write chain.
1488                  * make sure we update the CCW atomically
1489                  * so channel does not fetch it when it's only half done
1490                  */
1491                                 memcpy( &pEnd->write2_nop2, &tempCCW ,
1492                                         sizeof(struct ccw1));
1493                                 privptr->p_write_active_last->w_TIC_1.cda=
1494                                         (__u32)__pa(&p_first_ccw->write);
1495                         }
1496                         else {
1497
1498                         /*make sure we update the CCW atomically
1499                          *so channel does not fetch it when it's only half done
1500                          */
1501                                 memcpy(&pEnd->write1_nop2, &tempCCW ,
1502                                         sizeof(struct ccw1));
1503                                 privptr->p_write_active_last->w_TIC_1.cda=
1504                                         (__u32)__pa(&p_first_ccw->write);
1505
1506                         } /* end if if (pEnd->write1) */
1507
1508                         privptr->p_write_active_last->next=p_first_ccw;
1509                         privptr->p_write_active_last=p_last_ccw;
1510                 }
1511
1512         } /* endif (p_first_ccw!=NULL)  */
1513         dev_kfree_skb_any(skb);
1514         if (linkid==0) {
1515                 lock=LOCK_NO;
1516         }
1517         else  {
1518                 lock=LOCK_YES;
1519         }
1520         claw_strt_out_IO(dev );
1521         /*      if write free count is zero , set NOBUFFER       */
1522         if (privptr->write_free_count==0) {
1523                 claw_setbit_busy(TB_NOBUFFER,dev);
1524         }
1525 Done2:
1526         claw_clearbit_busy(TB_TX,dev);
1527 Done:
1528         return(rc);
1529 }    /*    end of claw_hw_tx    */
1530
1531 /*-------------------------------------------------------------------*
1532 *                                                                    *
1533 *     init_ccw_bk                                                    *
1534 *                                                                    *
1535 *--------------------------------------------------------------------*/
1536
1537 static int
1538 init_ccw_bk(struct net_device *dev)
1539 {
1540
1541         __u32   ccw_blocks_required;
1542         __u32   ccw_blocks_perpage;
1543         __u32   ccw_pages_required;
1544         __u32   claw_reads_perpage=1;
1545         __u32   claw_read_pages;
1546         __u32   claw_writes_perpage=1;
1547         __u32   claw_write_pages;
1548         void    *p_buff=NULL;
1549         struct ccwbk*p_free_chain;
1550         struct ccwbk*p_buf;
1551         struct ccwbk*p_last_CCWB;
1552         struct ccwbk*p_first_CCWB;
1553         struct endccw *p_endccw=NULL;
1554         addr_t  real_address;
1555         struct claw_privbk *privptr = dev->ml_priv;
1556         struct clawh *pClawH=NULL;
1557         addr_t   real_TIC_address;
1558         int i,j;
1559         CLAW_DBF_TEXT(4, trace, "init_ccw");
1560
1561         /*  initialize  statistics field */
1562         privptr->active_link_ID=0;
1563         /*  initialize  ccwbk pointers  */
1564         privptr->p_write_free_chain=NULL;   /* pointer to free ccw chain*/
1565         privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1566         privptr->p_write_active_last=NULL;  /* pointer to the last write ccw*/
1567         privptr->p_read_active_first=NULL;  /* pointer to the first read ccw*/
1568         privptr->p_read_active_last=NULL;   /* pointer to the last read ccw */
1569         privptr->p_end_ccw=NULL;            /* pointer to ending ccw        */
1570         privptr->p_claw_signal_blk=NULL;    /* pointer to signal block      */
1571         privptr->buffs_alloc = 0;
1572         memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1573         memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1574         /*  initialize  free write ccwbk counter  */
1575         privptr->write_free_count=0;  /* number of free bufs on write chain */
1576         p_last_CCWB = NULL;
1577         p_first_CCWB= NULL;
1578         /*
1579         *  We need 1 CCW block for each read buffer, 1 for each
1580         *  write buffer, plus 1 for ClawSignalBlock
1581         */
1582         ccw_blocks_required =
1583                 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
1584         /*
1585         * compute number of CCW blocks that will fit in a page
1586         */
1587         ccw_blocks_perpage= PAGE_SIZE /  CCWBK_SIZE;
1588         ccw_pages_required=
1589                 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
1590
1591         /*
1592          *  read and write sizes are set by 2 constants in claw.h
1593          *  4k and 32k.  Unpacked values other than 4k are not going to
1594          * provide good performance. With packing buffers support 32k
1595          * buffers are used.
1596          */
1597         if (privptr->p_env->read_size < PAGE_SIZE) {
1598                 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1599                 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1600                                                 claw_reads_perpage);
1601          }
1602          else {       /* > or equal  */
1603                 privptr->p_buff_pages_perread =
1604                         DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1605                 claw_read_pages = privptr->p_env->read_buffers *
1606                                         privptr->p_buff_pages_perread;
1607          }
1608         if (privptr->p_env->write_size < PAGE_SIZE) {
1609                 claw_writes_perpage =
1610                         PAGE_SIZE / privptr->p_env->write_size;
1611                 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1612                                                 claw_writes_perpage);
1613
1614         }
1615         else {      /* >  or equal  */
1616                 privptr->p_buff_pages_perwrite =
1617                         DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1618                 claw_write_pages = privptr->p_env->write_buffers *
1619                                         privptr->p_buff_pages_perwrite;
1620         }
1621         /*
1622         *               allocate ccw_pages_required
1623         */
1624         if (privptr->p_buff_ccw==NULL) {
1625                 privptr->p_buff_ccw=
1626                         (void *)__get_free_pages(__GFP_DMA,
1627                         (int)pages_to_order_of_mag(ccw_pages_required ));
1628                 if (privptr->p_buff_ccw==NULL) {
1629                         return -ENOMEM;
1630                 }
1631                 privptr->p_buff_ccw_num=ccw_pages_required;
1632         }
1633         memset(privptr->p_buff_ccw, 0x00,
1634                 privptr->p_buff_ccw_num * PAGE_SIZE);
1635
1636         /*
1637         *               obtain ending ccw block address
1638         *
1639         */
1640         privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1641         real_address  = (__u32)__pa(privptr->p_end_ccw);
1642         /*                              Initialize ending CCW block       */
1643         p_endccw=privptr->p_end_ccw;
1644         p_endccw->real=real_address;
1645         p_endccw->write1=0x00;
1646         p_endccw->read1=0x00;
1647
1648         /*      write1_nop1                                     */
1649         p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1650         p_endccw->write1_nop1.flags       = CCW_FLAG_SLI | CCW_FLAG_CC;
1651         p_endccw->write1_nop1.count       = 1;
1652         p_endccw->write1_nop1.cda         = 0;
1653
1654         /*      write1_nop2                                     */
1655         p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1656         p_endccw->write1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1657         p_endccw->write1_nop2.count      = 1;
1658         p_endccw->write1_nop2.cda        = 0;
1659
1660         /*      write2_nop1                                     */
1661         p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1662         p_endccw->write2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
1663         p_endccw->write2_nop1.count        = 1;
1664         p_endccw->write2_nop1.cda          = 0;
1665
1666         /*      write2_nop2                                     */
1667         p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1668         p_endccw->write2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1669         p_endccw->write2_nop2.count        = 1;
1670         p_endccw->write2_nop2.cda          = 0;
1671
1672         /*      read1_nop1                                      */
1673         p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1674         p_endccw->read1_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
1675         p_endccw->read1_nop1.count        = 1;
1676         p_endccw->read1_nop1.cda          = 0;
1677
1678         /*      read1_nop2                                      */
1679         p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1680         p_endccw->read1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1681         p_endccw->read1_nop2.count        = 1;
1682         p_endccw->read1_nop2.cda          = 0;
1683
1684         /*      read2_nop1                                      */
1685         p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1686         p_endccw->read2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
1687         p_endccw->read2_nop1.count        = 1;
1688         p_endccw->read2_nop1.cda          = 0;
1689
1690         /*      read2_nop2                                      */
1691         p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1692         p_endccw->read2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1693         p_endccw->read2_nop2.count        = 1;
1694         p_endccw->read2_nop2.cda          = 0;
1695
1696         /*
1697         *                               Build a chain of CCWs
1698         *
1699         */
1700         p_buff=privptr->p_buff_ccw;
1701
1702         p_free_chain=NULL;
1703         for (i=0 ; i < ccw_pages_required; i++ ) {
1704                 real_address  = (__u32)__pa(p_buff);
1705                 p_buf=p_buff;
1706                 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1707                         p_buf->next  = p_free_chain;
1708                         p_free_chain = p_buf;
1709                         p_buf->real=(__u32)__pa(p_buf);
1710                         ++p_buf;
1711                 }
1712                 p_buff+=PAGE_SIZE;
1713         }
1714         /*
1715         *                               Initialize ClawSignalBlock
1716         *
1717         */
1718         if (privptr->p_claw_signal_blk==NULL) {
1719                 privptr->p_claw_signal_blk=p_free_chain;
1720                 p_free_chain=p_free_chain->next;
1721                 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1722                 pClawH->length=0xffff;
1723                 pClawH->opcode=0xff;
1724                 pClawH->flag=CLAW_BUSY;
1725         }
1726
1727         /*
1728         *               allocate write_pages_required and add to free chain
1729         */
1730         if (privptr->p_buff_write==NULL) {
1731             if (privptr->p_env->write_size < PAGE_SIZE) {
1732                 privptr->p_buff_write=
1733                         (void *)__get_free_pages(__GFP_DMA,
1734                         (int)pages_to_order_of_mag(claw_write_pages ));
1735                 if (privptr->p_buff_write==NULL) {
1736                         privptr->p_buff_ccw=NULL;
1737                         return -ENOMEM;
1738                 }
1739                 /*
1740                 *                               Build CLAW write free chain
1741                 *
1742                 */
1743
1744                 memset(privptr->p_buff_write, 0x00,
1745                         ccw_pages_required * PAGE_SIZE);
1746                 privptr->p_write_free_chain=NULL;
1747
1748                 p_buff=privptr->p_buff_write;
1749
1750                 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1751                         p_buf        = p_free_chain;      /*  get a CCW */
1752                         p_free_chain = p_buf->next;
1753                         p_buf->next  =privptr->p_write_free_chain;
1754                         privptr->p_write_free_chain = p_buf;
1755                         p_buf-> p_buffer        = (struct clawbuf *)p_buff;
1756                         p_buf-> write.cda       = (__u32)__pa(p_buff);
1757                         p_buf-> write.flags     = CCW_FLAG_SLI | CCW_FLAG_CC;
1758                         p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1759                         p_buf-> w_read_FF.flags   = CCW_FLAG_SLI | CCW_FLAG_CC;
1760                         p_buf-> w_read_FF.count   = 1;
1761                         p_buf-> w_read_FF.cda     =
1762                                 (__u32)__pa(&p_buf-> header.flag);
1763                         p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1764                         p_buf-> w_TIC_1.flags      = 0;
1765                         p_buf-> w_TIC_1.count      = 0;
1766
1767                         if (((unsigned long)p_buff +
1768                                             privptr->p_env->write_size) >=
1769                            ((unsigned long)(p_buff+2*
1770                             (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1771                                 p_buff = p_buff+privptr->p_env->write_size;
1772                         }
1773                 }
1774            }
1775            else      /*  Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1776            {
1777                privptr->p_write_free_chain=NULL;
1778                for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1779                    p_buff=(void *)__get_free_pages(__GFP_DMA,
1780                         (int)pages_to_order_of_mag(
1781                         privptr->p_buff_pages_perwrite) );
1782                    if (p_buff==NULL) {
1783                         free_pages((unsigned long)privptr->p_buff_ccw,
1784                               (int)pages_to_order_of_mag(
1785                                         privptr->p_buff_ccw_num));
1786                         privptr->p_buff_ccw=NULL;
1787                         p_buf=privptr->p_buff_write;
1788                         while (p_buf!=NULL) {
1789                                 free_pages((unsigned long)
1790                                         p_buf->p_buffer,
1791                                         (int)pages_to_order_of_mag(
1792                                         privptr->p_buff_pages_perwrite));
1793                                 p_buf=p_buf->next;
1794                         }
1795                         return -ENOMEM;
1796                    }  /* Error on get_pages   */
1797                    memset(p_buff, 0x00, privptr->p_env->write_size );
1798                    p_buf         = p_free_chain;
1799                    p_free_chain  = p_buf->next;
1800                    p_buf->next   = privptr->p_write_free_chain;
1801                    privptr->p_write_free_chain = p_buf;
1802                    privptr->p_buff_write = p_buf;
1803                    p_buf->p_buffer=(struct clawbuf *)p_buff;
1804                    p_buf-> write.cda     = (__u32)__pa(p_buff);
1805                    p_buf-> write.flags   = CCW_FLAG_SLI | CCW_FLAG_CC;
1806                    p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1807                    p_buf-> w_read_FF.flags    = CCW_FLAG_SLI | CCW_FLAG_CC;
1808                    p_buf-> w_read_FF.count    = 1;
1809                    p_buf-> w_read_FF.cda      =
1810                         (__u32)__pa(&p_buf-> header.flag);
1811                    p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1812                    p_buf-> w_TIC_1.flags   = 0;
1813                    p_buf-> w_TIC_1.count   = 0;
1814                }  /* for all write_buffers   */
1815
1816            }    /* else buffers are PAGE_SIZE or bigger */
1817
1818         }
1819         privptr->p_buff_write_num=claw_write_pages;
1820         privptr->write_free_count=privptr->p_env->write_buffers;
1821
1822
1823         /*
1824         *               allocate read_pages_required and chain to free chain
1825         */
1826         if (privptr->p_buff_read==NULL) {
1827             if (privptr->p_env->read_size < PAGE_SIZE)  {
1828                 privptr->p_buff_read=
1829                         (void *)__get_free_pages(__GFP_DMA,
1830                         (int)pages_to_order_of_mag(claw_read_pages) );
1831                 if (privptr->p_buff_read==NULL) {
1832                         free_pages((unsigned long)privptr->p_buff_ccw,
1833                                 (int)pages_to_order_of_mag(
1834                                         privptr->p_buff_ccw_num));
1835                         /* free the write pages size is < page size  */
1836                         free_pages((unsigned long)privptr->p_buff_write,
1837                                 (int)pages_to_order_of_mag(
1838                                 privptr->p_buff_write_num));
1839                         privptr->p_buff_ccw=NULL;
1840                         privptr->p_buff_write=NULL;
1841                         return -ENOMEM;
1842                 }
1843                 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1844                 privptr->p_buff_read_num=claw_read_pages;
1845                 /*
1846                 *                               Build CLAW read free chain
1847                 *
1848                 */
1849                 p_buff=privptr->p_buff_read;
1850                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1851                         p_buf        = p_free_chain;
1852                         p_free_chain = p_buf->next;
1853
1854                         if (p_last_CCWB==NULL) {
1855                                 p_buf->next=NULL;
1856                                 real_TIC_address=0;
1857                                 p_last_CCWB=p_buf;
1858                         }
1859                         else {
1860                                 p_buf->next=p_first_CCWB;
1861                                 real_TIC_address=
1862                                 (__u32)__pa(&p_first_CCWB -> read );
1863                         }
1864
1865                         p_first_CCWB=p_buf;
1866
1867                         p_buf->p_buffer=(struct clawbuf *)p_buff;
1868                         /*  initialize read command */
1869                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1870                         p_buf-> read.cda = (__u32)__pa(p_buff);
1871                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1872                         p_buf-> read.count       = privptr->p_env->read_size;
1873
1874                         /*  initialize read_h command */
1875                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1876                         p_buf-> read_h.cda =
1877                                 (__u32)__pa(&(p_buf->header));
1878                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1879                         p_buf-> read_h.count      = sizeof(struct clawh);
1880
1881                         /*  initialize Signal command */
1882                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1883                         p_buf-> signal.cda =
1884                                 (__u32)__pa(&(pClawH->flag));
1885                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1886                         p_buf-> signal.count     = 1;
1887
1888                         /*  initialize r_TIC_1 command */
1889                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1890                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1891                         p_buf-> r_TIC_1.flags = 0;
1892                         p_buf-> r_TIC_1.count      = 0;
1893
1894                         /*  initialize r_read_FF command */
1895                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1896                         p_buf-> r_read_FF.cda =
1897                                 (__u32)__pa(&(pClawH->flag));
1898                         p_buf-> r_read_FF.flags =
1899                                 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1900                         p_buf-> r_read_FF.count    = 1;
1901
1902                         /*    initialize r_TIC_2          */
1903                         memcpy(&p_buf->r_TIC_2,
1904                                 &p_buf->r_TIC_1, sizeof(struct ccw1));
1905
1906                         /*     initialize Header     */
1907                         p_buf->header.length=0xffff;
1908                         p_buf->header.opcode=0xff;
1909                         p_buf->header.flag=CLAW_PENDING;
1910
1911                         if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1912                           ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1913                                  -1)
1914                            & PAGE_MASK)) {
1915                                 p_buff= p_buff+privptr->p_env->read_size;
1916                         }
1917                         else {
1918                                 p_buff=
1919                                 (void *)((unsigned long)
1920                                         (p_buff+2*(privptr->p_env->read_size)-1)
1921                                          & PAGE_MASK) ;
1922                         }
1923                 }   /* for read_buffers   */
1924           }         /* read_size < PAGE_SIZE  */
1925           else {  /* read Size >= PAGE_SIZE  */
1926                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1927                         p_buff = (void *)__get_free_pages(__GFP_DMA,
1928                                 (int)pages_to_order_of_mag(
1929                                         privptr->p_buff_pages_perread));
1930                         if (p_buff==NULL) {
1931                                 free_pages((unsigned long)privptr->p_buff_ccw,
1932                                         (int)pages_to_order_of_mag(privptr->
1933                                         p_buff_ccw_num));
1934                                 /* free the write pages  */
1935                                 p_buf=privptr->p_buff_write;
1936                                 while (p_buf!=NULL) {
1937                                         free_pages(
1938                                             (unsigned long)p_buf->p_buffer,
1939                                             (int)pages_to_order_of_mag(
1940                                             privptr->p_buff_pages_perwrite));
1941                                         p_buf=p_buf->next;
1942                                 }
1943                                 /* free any read pages already alloc  */
1944                                 p_buf=privptr->p_buff_read;
1945                                 while (p_buf!=NULL) {
1946                                         free_pages(
1947                                             (unsigned long)p_buf->p_buffer,
1948                                             (int)pages_to_order_of_mag(
1949                                              privptr->p_buff_pages_perread));
1950                                         p_buf=p_buf->next;
1951                                 }
1952                                 privptr->p_buff_ccw=NULL;
1953                                 privptr->p_buff_write=NULL;
1954                                 return -ENOMEM;
1955                         }
1956                         memset(p_buff, 0x00, privptr->p_env->read_size);
1957                         p_buf        = p_free_chain;
1958                         privptr->p_buff_read = p_buf;
1959                         p_free_chain = p_buf->next;
1960
1961                         if (p_last_CCWB==NULL) {
1962                                 p_buf->next=NULL;
1963                                 real_TIC_address=0;
1964                                 p_last_CCWB=p_buf;
1965                         }
1966                         else {
1967                                 p_buf->next=p_first_CCWB;
1968                                 real_TIC_address=
1969                                         (addr_t)__pa(
1970                                                 &p_first_CCWB -> read );
1971                         }
1972
1973                         p_first_CCWB=p_buf;
1974                                 /* save buff address */
1975                         p_buf->p_buffer=(struct clawbuf *)p_buff;
1976                         /*  initialize read command */
1977                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1978                         p_buf-> read.cda = (__u32)__pa(p_buff);
1979                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1980                         p_buf-> read.count       = privptr->p_env->read_size;
1981
1982                         /*  initialize read_h command */
1983                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1984                         p_buf-> read_h.cda =
1985                                 (__u32)__pa(&(p_buf->header));
1986                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1987                         p_buf-> read_h.count      = sizeof(struct clawh);
1988
1989                         /*  initialize Signal command */
1990                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1991                         p_buf-> signal.cda =
1992                                 (__u32)__pa(&(pClawH->flag));
1993                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1994                         p_buf-> signal.count     = 1;
1995
1996                         /*  initialize r_TIC_1 command */
1997                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1998                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1999                         p_buf-> r_TIC_1.flags = 0;
2000                         p_buf-> r_TIC_1.count      = 0;
2001
2002                         /*  initialize r_read_FF command */
2003                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2004                         p_buf-> r_read_FF.cda =
2005                                 (__u32)__pa(&(pClawH->flag));
2006                         p_buf-> r_read_FF.flags =
2007                                 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2008                         p_buf-> r_read_FF.count    = 1;
2009
2010                         /*    initialize r_TIC_2          */
2011                         memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
2012                                 sizeof(struct ccw1));
2013
2014                         /*     initialize Header     */
2015                         p_buf->header.length=0xffff;
2016                         p_buf->header.opcode=0xff;
2017                         p_buf->header.flag=CLAW_PENDING;
2018
2019                 }    /* For read_buffers   */
2020           }     /*  read_size >= PAGE_SIZE   */
2021         }       /*  pBuffread = NULL */
2022         add_claw_reads( dev  ,p_first_CCWB , p_last_CCWB);
2023         privptr->buffs_alloc = 1;
2024
2025         return 0;
2026 }    /*    end of init_ccw_bk */
2027
2028 /*-------------------------------------------------------------------*
2029 *                                                                    *
2030 *       probe_error                                                  *
2031 *                                                                    *
2032 *--------------------------------------------------------------------*/
2033
2034 static void
2035 probe_error( struct ccwgroup_device *cgdev)
2036 {
2037         struct claw_privbk *privptr;
2038
2039         CLAW_DBF_TEXT(4, trace, "proberr");
2040         privptr = dev_get_drvdata(&cgdev->dev);
2041         if (privptr != NULL) {
2042                 dev_set_drvdata(&cgdev->dev, NULL);
2043                 kfree(privptr->p_env);
2044                 kfree(privptr->p_mtc_envelope);
2045                 kfree(privptr);
2046         }
2047 }    /*    probe_error    */
2048
2049 /*-------------------------------------------------------------------*
2050 *    claw_process_control                                            *
2051 *                                                                    *
2052 *                                                                    *
2053 *--------------------------------------------------------------------*/
2054
2055 static int
2056 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2057 {
2058
2059         struct clawbuf *p_buf;
2060         struct clawctl  ctlbk;
2061         struct clawctl *p_ctlbk;
2062         char    temp_host_name[8];
2063         char    temp_ws_name[8];
2064         struct claw_privbk *privptr;
2065         struct claw_env *p_env;
2066         struct sysval *p_sysval;
2067         struct conncmd *p_connect=NULL;
2068         int rc;
2069         struct chbk *p_ch = NULL;
2070         struct device *tdev;
2071         CLAW_DBF_TEXT(2, setup, "clw_cntl");
2072         udelay(1000);  /* Wait a ms for the control packets to
2073                         *catch up to each other */
2074         privptr = dev->ml_priv;
2075         p_env=privptr->p_env;
2076         tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
2077         memcpy( &temp_host_name, p_env->host_name, 8);
2078         memcpy( &temp_ws_name, p_env->adapter_name , 8);
2079         dev_info(tdev, "%s: CLAW device %.8s: "
2080                 "Received Control Packet\n",
2081                 dev->name, temp_ws_name);
2082         if (privptr->release_pend==1) {
2083                 return 0;
2084         }
2085         p_buf=p_ccw->p_buffer;
2086         p_ctlbk=&ctlbk;
2087         if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2088                 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2089         } else {
2090                 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2091         }
2092         switch (p_ctlbk->command)
2093         {
2094         case SYSTEM_VALIDATE_REQUEST:
2095                 if (p_ctlbk->version != CLAW_VERSION_ID) {
2096                         claw_snd_sys_validate_rsp(dev, p_ctlbk,
2097                                 CLAW_RC_WRONG_VERSION);
2098                         dev_warn(tdev, "The communication peer of %s"
2099                                 " uses an incorrect API version %d\n",
2100                                 dev->name, p_ctlbk->version);
2101                 }
2102                 p_sysval = (struct sysval *)&(p_ctlbk->data);
2103                 dev_info(tdev, "%s: Recv Sys Validate Request: "
2104                         "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2105                         "Host name=%.8s\n",
2106                         dev->name, p_ctlbk->version,
2107                         p_ctlbk->linkid,
2108                         p_ctlbk->correlator,
2109                         p_sysval->WS_name,
2110                         p_sysval->host_name);
2111                 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2112                         claw_snd_sys_validate_rsp(dev, p_ctlbk,
2113                                 CLAW_RC_NAME_MISMATCH);
2114                         CLAW_DBF_TEXT(2, setup, "HSTBAD");
2115                         CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2116                         CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
2117                         dev_warn(tdev,
2118                                 "Host name %s for %s does not match the"
2119                                 " remote adapter name %s\n",
2120                                 p_sysval->host_name,
2121                                 dev->name,
2122                                 temp_host_name);
2123                 }
2124                 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2125                         claw_snd_sys_validate_rsp(dev, p_ctlbk,
2126                                 CLAW_RC_NAME_MISMATCH);
2127                         CLAW_DBF_TEXT(2, setup, "WSNBAD");
2128                         CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2129                         CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
2130                         dev_warn(tdev, "Adapter name %s for %s does not match"
2131                                 " the remote host name %s\n",
2132                                 p_sysval->WS_name,
2133                                 dev->name,
2134                                 temp_ws_name);
2135                 }
2136                 if ((p_sysval->write_frame_size < p_env->write_size) &&
2137                     (p_env->packing == 0)) {
2138                         claw_snd_sys_validate_rsp(dev, p_ctlbk,
2139                                 CLAW_RC_HOST_RCV_TOO_SMALL);
2140                         dev_warn(tdev,
2141                                 "The local write buffer is smaller than the"
2142                                 " remote read buffer\n");
2143                         CLAW_DBF_TEXT(2, setup, "wrtszbad");
2144                 }
2145                 if ((p_sysval->read_frame_size < p_env->read_size) &&
2146                     (p_env->packing == 0)) {
2147                         claw_snd_sys_validate_rsp(dev, p_ctlbk,
2148                                 CLAW_RC_HOST_RCV_TOO_SMALL);
2149                         dev_warn(tdev,
2150                                 "The local read buffer is smaller than the"
2151                                 " remote write buffer\n");
2152                         CLAW_DBF_TEXT(2, setup, "rdsizbad");
2153                 }
2154                 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
2155                 dev_info(tdev,
2156                         "CLAW device %.8s: System validate"
2157                         " completed.\n", temp_ws_name);
2158                 dev_info(tdev,
2159                         "%s: sys Validate Rsize:%d Wsize:%d\n",
2160                         dev->name, p_sysval->read_frame_size,
2161                         p_sysval->write_frame_size);
2162                 privptr->system_validate_comp = 1;
2163                 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2164                         p_env->packing = PACKING_ASK;
2165                 claw_strt_conn_req(dev);
2166                 break;
2167         case SYSTEM_VALIDATE_RESPONSE:
2168                 p_sysval = (struct sysval *)&(p_ctlbk->data);
2169                 dev_info(tdev,
2170                         "Settings for %s validated (version=%d, "
2171                         "remote device=%d, rc=%d, adapter name=%.8s, "
2172                         "host name=%.8s)\n",
2173                         dev->name,
2174                         p_ctlbk->version,
2175                         p_ctlbk->correlator,
2176                         p_ctlbk->rc,
2177                         p_sysval->WS_name,
2178                         p_sysval->host_name);
2179                 switch (p_ctlbk->rc) {
2180                 case 0:
2181                         dev_info(tdev, "%s: CLAW device "
2182                                 "%.8s: System validate completed.\n",
2183                                 dev->name, temp_ws_name);
2184                         if (privptr->system_validate_comp == 0)
2185                                 claw_strt_conn_req(dev);
2186                         privptr->system_validate_comp = 1;
2187                         break;
2188                 case CLAW_RC_NAME_MISMATCH:
2189                         dev_warn(tdev, "Validating %s failed because of"
2190                                 " a host or adapter name mismatch\n",
2191                                 dev->name);
2192                         break;
2193                 case CLAW_RC_WRONG_VERSION:
2194                         dev_warn(tdev, "Validating %s failed because of a"
2195                                 " version conflict\n",
2196                                 dev->name);
2197                         break;
2198                 case CLAW_RC_HOST_RCV_TOO_SMALL:
2199                         dev_warn(tdev, "Validating %s failed because of a"
2200                                 " frame size conflict\n",
2201                                 dev->name);
2202                         break;
2203                 default:
2204                         dev_warn(tdev, "The communication peer of %s rejected"
2205                                 " the connection\n",
2206                                  dev->name);
2207                         break;
2208                 }
2209                 break;
2210
2211         case CONNECTION_REQUEST:
2212                 p_connect = (struct conncmd *)&(p_ctlbk->data);
2213                 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2214                         "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2215                         dev->name,
2216                         p_ctlbk->version,
2217                         p_ctlbk->linkid,
2218                         p_ctlbk->correlator,
2219                         p_connect->host_name,
2220                         p_connect->WS_name);
2221                 if (privptr->active_link_ID != 0) {
2222                         claw_snd_disc(dev, p_ctlbk);
2223                         dev_info(tdev, "%s rejected a connection request"
2224                                 " because it is already active\n",
2225                                 dev->name);
2226                 }
2227                 if (p_ctlbk->linkid != 1) {
2228                         claw_snd_disc(dev, p_ctlbk);
2229                         dev_info(tdev, "%s rejected a request to open multiple"
2230                                 " connections\n",
2231                                 dev->name);
2232                 }
2233                 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2234                 if (rc != 0) {
2235                         claw_snd_disc(dev, p_ctlbk);
2236                         dev_info(tdev, "%s rejected a connection request"
2237                                 " because of a type mismatch\n",
2238                                 dev->name);
2239                 }
2240                 claw_send_control(dev,
2241                         CONNECTION_CONFIRM, p_ctlbk->linkid,
2242                         p_ctlbk->correlator,
2243                         0, p_connect->host_name,
2244                         p_connect->WS_name);
2245                 if (p_env->packing == PACKING_ASK) {
2246                         p_env->packing = PACK_SEND;
2247                         claw_snd_conn_req(dev, 0);
2248                 }
2249                 dev_info(tdev, "%s: CLAW device %.8s: Connection "
2250                         "completed link_id=%d.\n",
2251                         dev->name, temp_ws_name,
2252                         p_ctlbk->linkid);
2253                         privptr->active_link_ID = p_ctlbk->linkid;
2254                         p_ch = &privptr->channel[WRITE_CHANNEL];
2255                         wake_up(&p_ch->wait);  /* wake up claw_open ( WRITE) */
2256                 break;
2257         case CONNECTION_RESPONSE:
2258                 p_connect = (struct conncmd *)&(p_ctlbk->data);
2259                 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
2260                         "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2261                         dev->name,
2262                         p_ctlbk->version,
2263                         p_ctlbk->linkid,
2264                         p_ctlbk->correlator,
2265                         p_ctlbk->rc,
2266                         p_connect->host_name,
2267                         p_connect->WS_name);
2268
2269                 if (p_ctlbk->rc != 0) {
2270                         dev_warn(tdev, "The communication peer of %s rejected"
2271                                 " a connection request\n",
2272                                 dev->name);
2273                         return 1;
2274                 }
2275                 rc = find_link(dev,
2276                         p_connect->host_name, p_connect->WS_name);
2277                 if (rc != 0) {
2278                         claw_snd_disc(dev, p_ctlbk);
2279                         dev_warn(tdev, "The communication peer of %s"
2280                                 " rejected a connection "
2281                                 "request because of a type mismatch\n",
2282                                  dev->name);
2283                 }
2284                 /* should be until CONNECTION_CONFIRM */
2285                 privptr->active_link_ID = -(p_ctlbk->linkid);
2286                 break;
2287         case CONNECTION_CONFIRM:
2288                 p_connect = (struct conncmd *)&(p_ctlbk->data);
2289                 dev_info(tdev,
2290                         "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2291                         "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2292                         dev->name,
2293                         p_ctlbk->version,
2294                         p_ctlbk->linkid,
2295                         p_ctlbk->correlator,
2296                         p_connect->host_name,
2297                         p_connect->WS_name);
2298                 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2299                         privptr->active_link_ID = p_ctlbk->linkid;
2300                         if (p_env->packing > PACKING_ASK) {
2301                                 dev_info(tdev,
2302                                 "%s: Confirmed Now packing\n", dev->name);
2303                                 p_env->packing = DO_PACKED;
2304                         }
2305                         p_ch = &privptr->channel[WRITE_CHANNEL];
2306                         wake_up(&p_ch->wait);
2307                 } else {
2308                         dev_warn(tdev, "Activating %s failed because of"
2309                                 " an incorrect link ID=%d\n",
2310                                 dev->name, p_ctlbk->linkid);
2311                         claw_snd_disc(dev, p_ctlbk);
2312                 }
2313                 break;
2314         case DISCONNECT:
2315                 dev_info(tdev, "%s: Disconnect: "
2316                         "Vers=%d,link_id=%d,Corr=%d\n",
2317                         dev->name, p_ctlbk->version,
2318                         p_ctlbk->linkid, p_ctlbk->correlator);
2319                 if ((p_ctlbk->linkid == 2) &&
2320                     (p_env->packing == PACK_SEND)) {
2321                         privptr->active_link_ID = 1;
2322                         p_env->packing = DO_PACKED;
2323                 } else
2324                         privptr->active_link_ID = 0;
2325                 break;
2326         case CLAW_ERROR:
2327                 dev_warn(tdev, "The communication peer of %s failed\n",
2328                         dev->name);
2329                 break;
2330         default:
2331                 dev_warn(tdev, "The communication peer of %s sent"
2332                         " an unknown command code\n",
2333                         dev->name);
2334                 break;
2335         }
2336
2337         return 0;
2338 }   /*    end of claw_process_control    */
2339
2340
2341 /*-------------------------------------------------------------------*
2342 *               claw_send_control                                    *
2343 *                                                                    *
2344 *--------------------------------------------------------------------*/
2345
2346 static int
2347 claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2348          __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2349 {
2350         struct claw_privbk              *privptr;
2351         struct clawctl                  *p_ctl;
2352         struct sysval                   *p_sysval;
2353         struct conncmd                  *p_connect;
2354         struct sk_buff                  *skb;
2355
2356         CLAW_DBF_TEXT(2, setup, "sndcntl");
2357         privptr = dev->ml_priv;
2358         p_ctl=(struct clawctl *)&privptr->ctl_bk;
2359
2360         p_ctl->command=type;
2361         p_ctl->version=CLAW_VERSION_ID;
2362         p_ctl->linkid=link;
2363         p_ctl->correlator=correlator;
2364         p_ctl->rc=rc;
2365
2366         p_sysval=(struct sysval *)&p_ctl->data;
2367         p_connect=(struct conncmd *)&p_ctl->data;
2368
2369         switch (p_ctl->command) {
2370                 case SYSTEM_VALIDATE_REQUEST:
2371                 case SYSTEM_VALIDATE_RESPONSE:
2372                         memcpy(&p_sysval->host_name, local_name, 8);
2373                         memcpy(&p_sysval->WS_name, remote_name, 8);
2374                         if (privptr->p_env->packing > 0) {
2375                                 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2376                                 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
2377                         } else {
2378                                 /* how big is the biggest group of packets */
2379                            p_sysval->read_frame_size =
2380                                 privptr->p_env->read_size;
2381                            p_sysval->write_frame_size =
2382                                 privptr->p_env->write_size;
2383                         }
2384                         memset(&p_sysval->reserved, 0x00, 4);
2385                         break;
2386                 case CONNECTION_REQUEST:
2387                 case CONNECTION_RESPONSE:
2388                 case CONNECTION_CONFIRM:
2389                 case DISCONNECT:
2390                         memcpy(&p_sysval->host_name, local_name, 8);
2391                         memcpy(&p_sysval->WS_name, remote_name, 8);
2392                         if (privptr->p_env->packing > 0) {
2393                         /* How big is the biggest packet */
2394                                 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2395                                 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2396                         } else {
2397                                 memset(&p_connect->reserved1, 0x00, 4);
2398                                 memset(&p_connect->reserved2, 0x00, 4);
2399                         }
2400                         break;
2401                 default:
2402                         break;
2403         }
2404
2405         /*      write Control Record to the device                   */
2406
2407
2408         skb = dev_alloc_skb(sizeof(struct clawctl));
2409         if (!skb) {
2410                 return -ENOMEM;
2411         }
2412         memcpy(skb_put(skb, sizeof(struct clawctl)),
2413                 p_ctl, sizeof(struct clawctl));
2414         if (privptr->p_env->packing >= PACK_SEND)
2415                 claw_hw_tx(skb, dev, 1);
2416         else
2417                 claw_hw_tx(skb, dev, 0);
2418         return 0;
2419 }  /*   end of claw_send_control  */
2420
2421 /*-------------------------------------------------------------------*
2422 *               claw_snd_conn_req                                    *
2423 *                                                                    *
2424 *--------------------------------------------------------------------*/
2425 static int
2426 claw_snd_conn_req(struct net_device *dev, __u8 link)
2427 {
2428         int                rc;
2429         struct claw_privbk *privptr = dev->ml_priv;
2430         struct clawctl     *p_ctl;
2431
2432         CLAW_DBF_TEXT(2, setup, "snd_conn");
2433         rc = 1;
2434         p_ctl=(struct clawctl *)&privptr->ctl_bk;
2435         p_ctl->linkid = link;
2436         if ( privptr->system_validate_comp==0x00 ) {
2437                 return rc;
2438         }
2439         if (privptr->p_env->packing == PACKING_ASK )
2440                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2441                         WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2442         if (privptr->p_env->packing == PACK_SEND)  {
2443                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2444                         WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2445         }
2446         if (privptr->p_env->packing == 0)
2447                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2448                         HOST_APPL_NAME, privptr->p_env->api_type);
2449         return rc;
2450
2451 }  /*  end of claw_snd_conn_req */
2452
2453
2454 /*-------------------------------------------------------------------*
2455 *               claw_snd_disc                                        *
2456 *                                                                    *
2457 *--------------------------------------------------------------------*/
2458
2459 static int
2460 claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2461 {
2462         int rc;
2463         struct conncmd *  p_connect;
2464
2465         CLAW_DBF_TEXT(2, setup, "snd_dsc");
2466         p_connect=(struct conncmd *)&p_ctl->data;
2467
2468         rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2469                 p_ctl->correlator, 0,
2470                 p_connect->host_name, p_connect->WS_name);
2471         return rc;
2472 }     /*   end of claw_snd_disc    */
2473
2474
2475 /*-------------------------------------------------------------------*
2476 *               claw_snd_sys_validate_rsp                            *
2477 *                                                                    *
2478 *--------------------------------------------------------------------*/
2479
2480 static int
2481 claw_snd_sys_validate_rsp(struct net_device *dev,
2482         struct clawctl *p_ctl, __u32 return_code)
2483 {
2484         struct claw_env *  p_env;
2485         struct claw_privbk *privptr;
2486         int    rc;
2487
2488         CLAW_DBF_TEXT(2, setup, "chkresp");
2489         privptr = dev->ml_priv;
2490         p_env=privptr->p_env;
2491         rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2492                 p_ctl->linkid,
2493                 p_ctl->correlator,
2494                 return_code,
2495                 p_env->host_name,
2496                 p_env->adapter_name  );
2497         return rc;
2498 }     /*    end of claw_snd_sys_validate_rsp    */
2499
2500 /*-------------------------------------------------------------------*
2501 *               claw_strt_conn_req                                   *
2502 *                                                                    *
2503 *--------------------------------------------------------------------*/
2504
2505 static int
2506 claw_strt_conn_req(struct net_device *dev )
2507 {
2508         int rc;
2509
2510         CLAW_DBF_TEXT(2, setup, "conn_req");
2511         rc=claw_snd_conn_req(dev, 1);
2512         return rc;
2513 }    /*   end of claw_strt_conn_req   */
2514
2515
2516
2517 /*-------------------------------------------------------------------*
2518  *   claw_stats                                                      *
2519  *-------------------------------------------------------------------*/
2520
2521 static struct
2522 net_device_stats *claw_stats(struct net_device *dev)
2523 {
2524         struct claw_privbk *privptr;
2525
2526         CLAW_DBF_TEXT(4, trace, "stats");
2527         privptr = dev->ml_priv;
2528         return &privptr->stats;
2529 }     /*   end of claw_stats   */
2530
2531
2532 /*-------------------------------------------------------------------*
2533 *       unpack_read                                                  *
2534 *                                                                    *
2535 *--------------------------------------------------------------------*/
2536 static void
2537 unpack_read(struct net_device *dev )
2538 {
2539         struct sk_buff *skb;
2540         struct claw_privbk *privptr;
2541         struct claw_env    *p_env;
2542         struct ccwbk    *p_this_ccw;
2543         struct ccwbk    *p_first_ccw;
2544         struct ccwbk    *p_last_ccw;
2545         struct clawph   *p_packh;
2546         void            *p_packd;
2547         struct clawctl  *p_ctlrec=NULL;
2548         struct device   *p_dev;
2549
2550         __u32   len_of_data;
2551         __u32   pack_off;
2552         __u8    link_num;
2553         __u8    mtc_this_frm=0;
2554         __u32   bytes_to_mov;
2555         int     i=0;
2556         int     p=0;
2557
2558         CLAW_DBF_TEXT(4, trace, "unpkread");
2559         p_first_ccw=NULL;
2560         p_last_ccw=NULL;
2561         p_packh=NULL;
2562         p_packd=NULL;
2563         privptr = dev->ml_priv;
2564
2565         p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
2566         p_env = privptr->p_env;
2567         p_this_ccw=privptr->p_read_active_first;
2568         while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
2569                 pack_off = 0;
2570                 p = 0;
2571                 p_this_ccw->header.flag=CLAW_PENDING;
2572                 privptr->p_read_active_first=p_this_ccw->next;
2573                 p_this_ccw->next=NULL;
2574                 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2575                 if ((p_env->packing == PACK_SEND) &&
2576                     (p_packh->len == 32)           &&
2577                     (p_packh->link_num == 0)) {   /* is it a packed ctl rec? */
2578                         p_packh++;  /* peek past pack header */
2579                         p_ctlrec = (struct clawctl *)p_packh;
2580                         p_packh--;  /* un peek */
2581                         if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2582                             (p_ctlrec->command == CONNECTION_CONFIRM))
2583                                 p_env->packing = DO_PACKED;
2584                 }
2585                 if (p_env->packing == DO_PACKED)
2586                         link_num=p_packh->link_num;
2587                 else
2588                         link_num=p_this_ccw->header.opcode / 8;
2589                 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
2590                         mtc_this_frm=1;
2591                         if (p_this_ccw->header.length!=
2592                                 privptr->p_env->read_size ) {
2593                                 dev_warn(p_dev,
2594                                         "The communication peer of %s"
2595                                         " sent a faulty"
2596                                         " frame of length %02x\n",
2597                                         dev->name, p_this_ccw->header.length);
2598                         }
2599                 }
2600
2601                 if (privptr->mtc_skipping) {
2602                         /*
2603                         *   We're in the mode of skipping past a
2604                         *   multi-frame message
2605                         *   that we can't process for some reason or other.
2606                         *   The first frame without the More-To-Come flag is
2607                         *   the last frame of the skipped message.
2608                         */
2609                         /*  in case of More-To-Come not set in this frame */
2610                         if (mtc_this_frm==0) {
2611                                 privptr->mtc_skipping=0; /* Ok, the end */
2612                                 privptr->mtc_logical_link=-1;
2613                         }
2614                         goto NextFrame;
2615                 }
2616
2617                 if (link_num==0) {
2618                         claw_process_control(dev, p_this_ccw);
2619                         CLAW_DBF_TEXT(4, trace, "UnpkCntl");
2620                         goto NextFrame;
2621                 }
2622 unpack_next:
2623                 if (p_env->packing == DO_PACKED) {
2624                         if (pack_off > p_env->read_size)
2625                                 goto NextFrame;
2626                         p_packd = p_this_ccw->p_buffer+pack_off;
2627                         p_packh = (struct clawph *) p_packd;
2628                         if ((p_packh->len == 0) || /* done with this frame? */
2629                             (p_packh->flag != 0))
2630                                 goto NextFrame;
2631                         bytes_to_mov = p_packh->len;
2632                         pack_off += bytes_to_mov+sizeof(struct clawph);
2633                         p++;
2634                 } else {
2635                         bytes_to_mov=p_this_ccw->header.length;
2636                 }
2637                 if (privptr->mtc_logical_link<0) {
2638
2639                 /*
2640                 *  if More-To-Come is set in this frame then we don't know
2641                 *  length of entire message, and hence have to allocate
2642                 *  large buffer   */
2643
2644                 /*      We are starting a new envelope  */
2645                 privptr->mtc_offset=0;
2646                         privptr->mtc_logical_link=link_num;
2647                 }
2648
2649                 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2650                         /*      error     */
2651                         privptr->stats.rx_frame_errors++;
2652                         goto NextFrame;
2653                 }
2654                 if (p_env->packing == DO_PACKED) {
2655                         memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2656                                 p_packd+sizeof(struct clawph), bytes_to_mov);
2657
2658                 } else  {
2659                         memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2660                                 p_this_ccw->p_buffer, bytes_to_mov);
2661                 }
2662                 if (mtc_this_frm==0) {
2663                         len_of_data=privptr->mtc_offset+bytes_to_mov;
2664                         skb=dev_alloc_skb(len_of_data);
2665                         if (skb) {
2666                                 memcpy(skb_put(skb,len_of_data),
2667                                         privptr->p_mtc_envelope,
2668                                         len_of_data);
2669                                 skb->dev=dev;
2670                                 skb_reset_mac_header(skb);
2671                                 skb->protocol=htons(ETH_P_IP);
2672                                 skb->ip_summed=CHECKSUM_UNNECESSARY;
2673                                 privptr->stats.rx_packets++;
2674                                 privptr->stats.rx_bytes+=len_of_data;
2675                                 netif_rx(skb);
2676                         }
2677                         else {
2678                                 dev_info(p_dev, "Allocating a buffer for"
2679                                         " incoming data failed\n");
2680                                 privptr->stats.rx_dropped++;
2681                         }
2682                         privptr->mtc_offset=0;
2683                         privptr->mtc_logical_link=-1;
2684                 }
2685                 else {
2686                         privptr->mtc_offset+=bytes_to_mov;
2687                 }
2688                 if (p_env->packing == DO_PACKED)
2689                         goto unpack_next;
2690 NextFrame:
2691                 /*
2692                 *   Remove ThisCCWblock from active read queue, and add it
2693                 *   to queue of free blocks to be reused.
2694                 */
2695                 i++;
2696                 p_this_ccw->header.length=0xffff;
2697                 p_this_ccw->header.opcode=0xff;
2698                 /*
2699                 *       add this one to the free queue for later reuse
2700                 */
2701                 if (p_first_ccw==NULL) {
2702                         p_first_ccw = p_this_ccw;
2703                 }
2704                 else {
2705                         p_last_ccw->next = p_this_ccw;
2706                 }
2707                 p_last_ccw = p_this_ccw;
2708                 /*
2709                 *       chain to next block on active read queue
2710                 */
2711                 p_this_ccw = privptr->p_read_active_first;
2712                 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
2713         } /* end of while */
2714
2715         /*      check validity                  */
2716
2717         CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
2718         add_claw_reads(dev, p_first_ccw, p_last_ccw);
2719         claw_strt_read(dev, LOCK_YES);
2720         return;
2721 }     /*  end of unpack_read   */
2722
2723 /*-------------------------------------------------------------------*
2724 *       claw_strt_read                                               *
2725 *                                                                    *
2726 *--------------------------------------------------------------------*/
2727 static void
2728 claw_strt_read (struct net_device *dev, int lock )
2729 {
2730         int        rc = 0;
2731         __u32      parm;
2732         unsigned long  saveflags = 0;
2733         struct claw_privbk *privptr = dev->ml_priv;
2734         struct ccwbk*p_ccwbk;
2735         struct chbk *p_ch;
2736         struct clawh *p_clawh;
2737         p_ch = &privptr->channel[READ_CHANNEL];
2738
2739         CLAW_DBF_TEXT(4, trace, "StRdNter");
2740         p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2741         p_clawh->flag=CLAW_IDLE;    /* 0x00 */
2742
2743         if ((privptr->p_write_active_first!=NULL &&
2744              privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2745             (privptr->p_read_active_first!=NULL &&
2746              privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2747                 p_clawh->flag=CLAW_BUSY;    /* 0xff */
2748         }
2749         if (lock==LOCK_YES) {
2750                 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2751         }
2752         if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2753                 CLAW_DBF_TEXT(4, trace, "HotRead");
2754                 p_ccwbk=privptr->p_read_active_first;
2755                 parm = (unsigned long) p_ch;
2756                 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2757                                        0xff, 0);
2758                 if (rc != 0) {
2759                         ccw_check_return_code(p_ch->cdev, rc);
2760                 }
2761         }
2762         else {
2763                 CLAW_DBF_TEXT(2, trace, "ReadAct");
2764         }
2765
2766         if (lock==LOCK_YES) {
2767                 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2768         }
2769         CLAW_DBF_TEXT(4, trace, "StRdExit");
2770         return;
2771 }       /*    end of claw_strt_read    */
2772
2773 /*-------------------------------------------------------------------*
2774 *       claw_strt_out_IO                                             *
2775 *                                                                    *
2776 *--------------------------------------------------------------------*/
2777
2778 static void
2779 claw_strt_out_IO( struct net_device *dev )
2780 {
2781         int                     rc = 0;
2782         unsigned long           parm;
2783         struct claw_privbk      *privptr;
2784         struct chbk             *p_ch;
2785         struct ccwbk    *p_first_ccw;
2786
2787         if (!dev) {
2788                 return;
2789         }
2790         privptr = (struct claw_privbk *)dev->ml_priv;
2791         p_ch = &privptr->channel[WRITE_CHANNEL];
2792
2793         CLAW_DBF_TEXT(4, trace, "strt_io");
2794         p_first_ccw=privptr->p_write_active_first;
2795
2796         if (p_ch->claw_state == CLAW_STOP)
2797                 return;
2798         if (p_first_ccw == NULL) {
2799                 return;
2800         }
2801         if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2802                 parm = (unsigned long) p_ch;
2803                 CLAW_DBF_TEXT(2, trace, "StWrtIO");
2804                 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2805                                       0xff, 0);
2806                 if (rc != 0) {
2807                         ccw_check_return_code(p_ch->cdev, rc);
2808                 }
2809         }
2810         dev->trans_start = jiffies;
2811         return;
2812 }       /*    end of claw_strt_out_IO    */
2813
2814 /*-------------------------------------------------------------------*
2815 *       Free write buffers                                           *
2816 *                                                                    *
2817 *--------------------------------------------------------------------*/
2818
2819 static void
2820 claw_free_wrt_buf( struct net_device *dev )
2821 {
2822
2823         struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
2824         struct ccwbk*p_first_ccw;
2825         struct ccwbk*p_last_ccw;
2826         struct ccwbk*p_this_ccw;
2827         struct ccwbk*p_next_ccw;
2828
2829         CLAW_DBF_TEXT(4, trace, "freewrtb");
2830         /*  scan the write queue to free any completed write packets   */
2831         p_first_ccw=NULL;
2832         p_last_ccw=NULL;
2833         p_this_ccw=privptr->p_write_active_first;
2834         while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2835         {
2836                 p_next_ccw = p_this_ccw->next;
2837                 if (((p_next_ccw!=NULL) &&
2838                      (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2839                     ((p_this_ccw == privptr->p_write_active_last) &&
2840                      (p_this_ccw->header.flag!=CLAW_PENDING))) {
2841                         /* The next CCW is OK or this is  */
2842                         /* the last CCW...free it   @A1A  */
2843                         privptr->p_write_active_first=p_this_ccw->next;
2844                         p_this_ccw->header.flag=CLAW_PENDING;
2845                         p_this_ccw->next=privptr->p_write_free_chain;
2846                         privptr->p_write_free_chain=p_this_ccw;
2847                         ++privptr->write_free_count;
2848                         privptr->stats.tx_bytes+= p_this_ccw->write.count;
2849                         p_this_ccw=privptr->p_write_active_first;
2850                         privptr->stats.tx_packets++;
2851                 }
2852                 else {
2853                         break;
2854                 }
2855         }
2856         if (privptr->write_free_count!=0) {
2857                 claw_clearbit_busy(TB_NOBUFFER,dev);
2858         }
2859         /*   whole chain removed?   */
2860         if (privptr->p_write_active_first==NULL) {
2861                 privptr->p_write_active_last=NULL;
2862         }
2863         CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
2864         return;
2865 }
2866
2867 /*-------------------------------------------------------------------*
2868 *       claw free netdevice                                          *
2869 *                                                                    *
2870 *--------------------------------------------------------------------*/
2871 static void
2872 claw_free_netdevice(struct net_device * dev, int free_dev)
2873 {
2874         struct claw_privbk *privptr;
2875
2876         CLAW_DBF_TEXT(2, setup, "free_dev");
2877         if (!dev)
2878                 return;
2879         CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2880         privptr = dev->ml_priv;
2881         if (dev->flags & IFF_RUNNING)
2882                 claw_release(dev);
2883         if (privptr) {
2884                 privptr->channel[READ_CHANNEL].ndev = NULL;  /* say it's free */
2885         }
2886         dev->ml_priv = NULL;
2887 #ifdef MODULE
2888         if (free_dev) {
2889                 free_netdev(dev);
2890         }
2891 #endif
2892         CLAW_DBF_TEXT(2, setup, "free_ok");
2893 }
2894
2895 /**
2896  * Claw init netdevice
2897  * Initialize everything of the net device except the name and the
2898  * channel structs.
2899  */
2900 static const struct net_device_ops claw_netdev_ops = {
2901         .ndo_open               = claw_open,
2902         .ndo_stop               = claw_release,
2903         .ndo_get_stats          = claw_stats,
2904         .ndo_start_xmit         = claw_tx,
2905         .ndo_change_mtu         = claw_change_mtu,
2906 };
2907
2908 static void
2909 claw_init_netdevice(struct net_device * dev)
2910 {
2911         CLAW_DBF_TEXT(2, setup, "init_dev");
2912         CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2913         dev->mtu = CLAW_DEFAULT_MTU_SIZE;
2914         dev->hard_header_len = 0;
2915         dev->addr_len = 0;
2916         dev->type = ARPHRD_SLIP;
2917         dev->tx_queue_len = 1300;
2918         dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2919         dev->netdev_ops = &claw_netdev_ops;
2920         CLAW_DBF_TEXT(2, setup, "initok");
2921         return;
2922 }
2923
2924 /**
2925  * Init a new channel in the privptr->channel[i].
2926  *
2927  * @param cdev  The ccw_device to be added.
2928  *
2929  * @return 0 on success, !0 on error.
2930  */
2931 static int
2932 add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2933 {
2934         struct chbk *p_ch;
2935         struct ccw_dev_id dev_id;
2936
2937         CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
2938         privptr->channel[i].flag  = i+1;   /* Read is 1 Write is 2 */
2939         p_ch = &privptr->channel[i];
2940         p_ch->cdev = cdev;
2941         snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
2942         ccw_device_get_id(cdev, &dev_id);
2943         p_ch->devno = dev_id.devno;
2944         if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
2945                 return -ENOMEM;
2946         }
2947         return 0;
2948 }
2949
2950
2951 /**
2952  *
2953  * Setup an interface.
2954  *
2955  * @param cgdev  Device to be setup.
2956  *
2957  * @returns 0 on success, !0 on failure.
2958  */
2959 static int
2960 claw_new_device(struct ccwgroup_device *cgdev)
2961 {
2962         struct claw_privbk *privptr;
2963         struct claw_env *p_env;
2964         struct net_device *dev;
2965         int ret;
2966         struct ccw_dev_id dev_id;
2967
2968         dev_info(&cgdev->dev, "add for %s\n",
2969                  dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
2970         CLAW_DBF_TEXT(2, setup, "new_dev");
2971         privptr = dev_get_drvdata(&cgdev->dev);
2972         dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2973         dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
2974         if (!privptr)
2975                 return -ENODEV;
2976         p_env = privptr->p_env;
2977         ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2978         p_env->devno[READ_CHANNEL] = dev_id.devno;
2979         ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2980         p_env->devno[WRITE_CHANNEL] = dev_id.devno;
2981         ret = add_channel(cgdev->cdev[0],0,privptr);
2982         if (ret == 0)
2983                 ret = add_channel(cgdev->cdev[1],1,privptr);
2984         if (ret != 0) {
2985                 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2986                         " failed with error code %d\n", ret);
2987                 goto out;
2988         }
2989         ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
2990         if (ret != 0) {
2991                 dev_warn(&cgdev->dev,
2992                         "Setting the read subchannel online"
2993                         " failed with error code %d\n", ret);
2994                 goto out;
2995         }
2996         ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
2997         if (ret != 0) {
2998                 dev_warn(&cgdev->dev,
2999                         "Setting the write subchannel online "
3000                         "failed with error code %d\n", ret);
3001                 goto out;
3002         }
3003         dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
3004         if (!dev) {
3005                 dev_warn(&cgdev->dev,
3006                         "Activating the CLAW device failed\n");
3007                 goto out;
3008         }
3009         dev->ml_priv = privptr;
3010         dev_set_drvdata(&cgdev->dev, privptr);
3011         dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
3012         dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
3013         /* sysfs magic */
3014         SET_NETDEV_DEV(dev, &cgdev->dev);
3015         if (register_netdev(dev) != 0) {
3016                 claw_free_netdevice(dev, 1);
3017                 CLAW_DBF_TEXT(2, trace, "regfail");
3018                 goto out;
3019         }
3020         dev->flags &=~IFF_RUNNING;
3021         if (privptr->buffs_alloc == 0) {
3022                 ret=init_ccw_bk(dev);
3023                 if (ret !=0) {
3024                         unregister_netdev(dev);
3025                         claw_free_netdevice(dev,1);
3026                         CLAW_DBF_TEXT(2, trace, "ccwmem");
3027                         goto out;
3028                 }
3029         }
3030         privptr->channel[READ_CHANNEL].ndev = dev;
3031         privptr->channel[WRITE_CHANNEL].ndev = dev;
3032         privptr->p_env->ndev = dev;
3033
3034         dev_info(&cgdev->dev, "%s:readsize=%d  writesize=%d "
3035                 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3036                 dev->name, p_env->read_size,
3037                 p_env->write_size, p_env->read_buffers,
3038                 p_env->write_buffers, p_env->devno[READ_CHANNEL],
3039                 p_env->devno[WRITE_CHANNEL]);
3040         dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
3041                 ":%.8s api_type: %.8s\n",
3042                 dev->name, p_env->host_name,
3043                 p_env->adapter_name , p_env->api_type);
3044         return 0;
3045 out:
3046         ccw_device_set_offline(cgdev->cdev[1]);
3047         ccw_device_set_offline(cgdev->cdev[0]);
3048         return -ENODEV;
3049 }
3050
3051 static void
3052 claw_purge_skb_queue(struct sk_buff_head *q)
3053 {
3054         struct sk_buff *skb;
3055
3056         CLAW_DBF_TEXT(4, trace, "purgque");
3057         while ((skb = skb_dequeue(q))) {
3058                 atomic_dec(&skb->users);
3059                 dev_kfree_skb_any(skb);
3060         }
3061 }
3062
3063 /**
3064  * Shutdown an interface.
3065  *
3066  * @param cgdev  Device to be shut down.
3067  *
3068  * @returns 0 on success, !0 on failure.
3069  */
3070 static int
3071 claw_shutdown_device(struct ccwgroup_device *cgdev)
3072 {
3073         struct claw_privbk *priv;
3074         struct net_device *ndev;
3075         int     ret;
3076
3077         CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
3078         priv = dev_get_drvdata(&cgdev->dev);
3079         if (!priv)
3080                 return -ENODEV;
3081         ndev = priv->channel[READ_CHANNEL].ndev;
3082         if (ndev) {
3083                 /* Close the device */
3084                 dev_info(&cgdev->dev, "%s: shutting down\n",
3085                         ndev->name);
3086                 if (ndev->flags & IFF_RUNNING)
3087                         ret = claw_release(ndev);
3088                 ndev->flags &=~IFF_RUNNING;
3089                 unregister_netdev(ndev);
3090                 ndev->ml_priv = NULL;  /* cgdev data, not ndev's to free */
3091                 claw_free_netdevice(ndev, 1);
3092                 priv->channel[READ_CHANNEL].ndev = NULL;
3093                 priv->channel[WRITE_CHANNEL].ndev = NULL;
3094                 priv->p_env->ndev = NULL;
3095         }
3096         ccw_device_set_offline(cgdev->cdev[1]);
3097         ccw_device_set_offline(cgdev->cdev[0]);
3098         return 0;
3099 }
3100
3101 static void
3102 claw_remove_device(struct ccwgroup_device *cgdev)
3103 {
3104         struct claw_privbk *priv;
3105
3106         BUG_ON(!cgdev);
3107         CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
3108         priv = dev_get_drvdata(&cgdev->dev);
3109         BUG_ON(!priv);
3110         dev_info(&cgdev->dev, " will be removed.\n");
3111         if (cgdev->state == CCWGROUP_ONLINE)
3112                 claw_shutdown_device(cgdev);
3113         claw_remove_files(&cgdev->dev);
3114         kfree(priv->p_mtc_envelope);
3115         priv->p_mtc_envelope=NULL;
3116         kfree(priv->p_env);
3117         priv->p_env=NULL;
3118         kfree(priv->channel[0].irb);
3119         priv->channel[0].irb=NULL;
3120         kfree(priv->channel[1].irb);
3121         priv->channel[1].irb=NULL;
3122         kfree(priv);
3123         dev_set_drvdata(&cgdev->dev, NULL);
3124         dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3125         dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
3126         put_device(&cgdev->dev);
3127
3128         return;
3129 }
3130
3131
3132 /*
3133  * sysfs attributes
3134  */
3135 static ssize_t
3136 claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
3137 {
3138         struct claw_privbk *priv;
3139         struct claw_env *  p_env;
3140
3141         priv = dev_get_drvdata(dev);
3142         if (!priv)
3143                 return -ENODEV;
3144         p_env = priv->p_env;
3145         return sprintf(buf, "%s\n",p_env->host_name);
3146 }
3147
3148 static ssize_t
3149 claw_hname_write(struct device *dev, struct device_attribute *attr,
3150          const char *buf, size_t count)
3151 {
3152         struct claw_privbk *priv;
3153         struct claw_env *  p_env;
3154
3155         priv = dev_get_drvdata(dev);
3156         if (!priv)
3157                 return -ENODEV;
3158         p_env = priv->p_env;
3159         if (count > MAX_NAME_LEN+1)
3160                 return -EINVAL;
3161         memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3162         strncpy(p_env->host_name,buf, count);
3163         p_env->host_name[count-1] = 0x20;  /* clear extra 0x0a */
3164         p_env->host_name[MAX_NAME_LEN] = 0x00;
3165         CLAW_DBF_TEXT(2, setup, "HstnSet");
3166         CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
3167
3168         return count;
3169 }
3170
3171 static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3172
3173 static ssize_t
3174 claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
3175 {
3176         struct claw_privbk *priv;
3177         struct claw_env *  p_env;
3178
3179         priv = dev_get_drvdata(dev);
3180         if (!priv)
3181                 return -ENODEV;
3182         p_env = priv->p_env;
3183         return sprintf(buf, "%s\n", p_env->adapter_name);
3184 }
3185
3186 static ssize_t
3187 claw_adname_write(struct device *dev, struct device_attribute *attr,
3188          const char *buf, size_t count)
3189 {
3190         struct claw_privbk *priv;
3191         struct claw_env *  p_env;
3192
3193         priv = dev_get_drvdata(dev);
3194         if (!priv)
3195                 return -ENODEV;
3196         p_env = priv->p_env;
3197         if (count > MAX_NAME_LEN+1)
3198                 return -EINVAL;
3199         memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3200         strncpy(p_env->adapter_name,buf, count);
3201         p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3202         p_env->adapter_name[MAX_NAME_LEN] = 0x00;
3203         CLAW_DBF_TEXT(2, setup, "AdnSet");
3204         CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
3205
3206         return count;
3207 }
3208
3209 static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3210
3211 static ssize_t
3212 claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
3213 {
3214         struct claw_privbk *priv;
3215         struct claw_env *  p_env;
3216
3217         priv = dev_get_drvdata(dev);
3218         if (!priv)
3219                 return -ENODEV;
3220         p_env = priv->p_env;
3221         return sprintf(buf, "%s\n",
3222                        p_env->api_type);
3223 }
3224
3225 static ssize_t
3226 claw_apname_write(struct device *dev, struct device_attribute *attr,
3227         const char *buf, size_t count)
3228 {
3229         struct claw_privbk *priv;
3230         struct claw_env *  p_env;
3231
3232         priv = dev_get_drvdata(dev);
3233         if (!priv)
3234                 return -ENODEV;
3235         p_env = priv->p_env;
3236         if (count > MAX_NAME_LEN+1)
3237                 return -EINVAL;
3238         memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3239         strncpy(p_env->api_type,buf, count);
3240         p_env->api_type[count-1] = 0x20;  /* we get a loose 0x0a */
3241         p_env->api_type[MAX_NAME_LEN] = 0x00;
3242         if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3243                 p_env->read_size=DEF_PACK_BUFSIZE;
3244                 p_env->write_size=DEF_PACK_BUFSIZE;
3245                 p_env->packing=PACKING_ASK;
3246                 CLAW_DBF_TEXT(2, setup, "PACKING");
3247         }
3248         else {
3249                 p_env->packing=0;
3250                 p_env->read_size=CLAW_FRAME_SIZE;
3251                 p_env->write_size=CLAW_FRAME_SIZE;
3252                 CLAW_DBF_TEXT(2, setup, "ApiSet");
3253         }
3254         CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
3255         return count;
3256 }
3257
3258 static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3259
3260 static ssize_t
3261 claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3262 {
3263         struct claw_privbk *priv;
3264         struct claw_env * p_env;
3265
3266         priv = dev_get_drvdata(dev);
3267         if (!priv)
3268                 return -ENODEV;
3269         p_env = priv->p_env;
3270         return sprintf(buf, "%d\n", p_env->write_buffers);
3271 }
3272
3273 static ssize_t
3274 claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3275         const char *buf, size_t count)
3276 {
3277         struct claw_privbk *priv;
3278         struct claw_env *  p_env;
3279         int nnn,max;
3280
3281         priv = dev_get_drvdata(dev);
3282         if (!priv)
3283                 return -ENODEV;
3284         p_env = priv->p_env;
3285         sscanf(buf, "%i", &nnn);
3286         if (p_env->packing) {
3287                 max = 64;
3288         }
3289         else {
3290                 max = 512;
3291         }
3292         if ((nnn > max ) || (nnn < 2))
3293                 return -EINVAL;
3294         p_env->write_buffers = nnn;
3295         CLAW_DBF_TEXT(2, setup, "Wbufset");
3296         CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
3297         return count;
3298 }
3299
3300 static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3301
3302 static ssize_t
3303 claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3304 {
3305         struct claw_privbk *priv;
3306         struct claw_env *  p_env;
3307
3308         priv = dev_get_drvdata(dev);
3309         if (!priv)
3310                 return -ENODEV;
3311         p_env = priv->p_env;
3312         return sprintf(buf, "%d\n", p_env->read_buffers);
3313 }
3314
3315 static ssize_t
3316 claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3317         const char *buf, size_t count)
3318 {
3319         struct claw_privbk *priv;
3320         struct claw_env *p_env;
3321         int nnn,max;
3322
3323         priv = dev_get_drvdata(dev);
3324         if (!priv)
3325                 return -ENODEV;
3326         p_env = priv->p_env;
3327         sscanf(buf, "%i", &nnn);
3328         if (p_env->packing) {
3329                 max = 64;
3330         }
3331         else {
3332                 max = 512;
3333         }
3334         if ((nnn > max ) || (nnn < 2))
3335                 return -EINVAL;
3336         p_env->read_buffers = nnn;
3337         CLAW_DBF_TEXT(2, setup, "Rbufset");
3338         CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
3339         return count;
3340 }
3341
3342 static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3343
3344 static struct attribute *claw_attr[] = {
3345         &dev_attr_read_buffer.attr,
3346         &dev_attr_write_buffer.attr,
3347         &dev_attr_adapter_name.attr,
3348         &dev_attr_api_type.attr,
3349         &dev_attr_host_name.attr,
3350         NULL,
3351 };
3352
3353 static struct attribute_group claw_attr_group = {
3354         .attrs = claw_attr,
3355 };
3356
3357 static int
3358 claw_add_files(struct device *dev)
3359 {
3360         CLAW_DBF_TEXT(2, setup, "add_file");
3361         return sysfs_create_group(&dev->kobj, &claw_attr_group);
3362 }
3363
3364 static void
3365 claw_remove_files(struct device *dev)
3366 {
3367         CLAW_DBF_TEXT(2, setup, "rem_file");
3368         sysfs_remove_group(&dev->kobj, &claw_attr_group);
3369 }
3370
3371 /*--------------------------------------------------------------------*
3372 *    claw_init  and cleanup                                           *
3373 *---------------------------------------------------------------------*/
3374
3375 static void __exit
3376 claw_cleanup(void)
3377 {
3378         driver_remove_file(&claw_group_driver.driver,
3379                            &driver_attr_group);
3380         ccwgroup_driver_unregister(&claw_group_driver);
3381         ccw_driver_unregister(&claw_ccw_driver);
3382         root_device_unregister(claw_root_dev);
3383         claw_unregister_debug_facility();
3384         pr_info("Driver unloaded\n");
3385
3386 }
3387
3388 /**
3389  * Initialize module.
3390  * This is called just after the module is loaded.
3391  *
3392  * @return 0 on success, !0 on error.
3393  */
3394 static int __init
3395 claw_init(void)
3396 {
3397         int ret = 0;
3398
3399         pr_info("Loading %s\n", version);
3400         ret = claw_register_debug_facility();
3401         if (ret) {
3402                 pr_err("Registering with the S/390 debug feature"
3403                         " failed with error code %d\n", ret);
3404                 goto out_err;
3405         }
3406         CLAW_DBF_TEXT(2, setup, "init_mod");
3407         claw_root_dev = root_device_register("claw");
3408         ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0;
3409         if (ret)
3410                 goto register_err;
3411         ret = ccw_driver_register(&claw_ccw_driver);
3412         if (ret)
3413                 goto ccw_err;
3414         claw_group_driver.driver.groups = claw_group_attr_groups;
3415         ret = ccwgroup_driver_register(&claw_group_driver);
3416         if (ret)
3417                 goto ccwgroup_err;
3418         return 0;
3419
3420 ccwgroup_err:
3421         ccw_driver_unregister(&claw_ccw_driver);
3422 ccw_err:
3423         root_device_unregister(claw_root_dev);
3424 register_err:
3425         CLAW_DBF_TEXT(2, setup, "init_bad");
3426         claw_unregister_debug_facility();
3427 out_err:
3428         pr_err("Initializing the claw device driver failed\n");
3429         return ret;
3430 }
3431
3432 module_init(claw_init);
3433 module_exit(claw_cleanup);
3434
3435 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3436 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3437                         "Copyright 2000,2008 IBM Corporation\n");
3438 MODULE_LICENSE("GPL");