Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jgarzi...
[linux-2.6] / 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 (C) 2002,2005 IBM Corporation
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  */
62 #include <asm/ccwdev.h>
63 #include <asm/ccwgroup.h>
64 #include <asm/debug.h>
65 #include <asm/idals.h>
66 #include <asm/io.h>
67
68 #include <linux/bitops.h>
69 #include <linux/ctype.h>
70 #include <linux/delay.h>
71 #include <linux/errno.h>
72 #include <linux/if_arp.h>
73 #include <linux/init.h>
74 #include <linux/interrupt.h>
75 #include <linux/ip.h>
76 #include <linux/kernel.h>
77 #include <linux/module.h>
78 #include <linux/netdevice.h>
79 #include <linux/etherdevice.h>
80 #include <linux/proc_fs.h>
81 #include <linux/sched.h>
82 #include <linux/signal.h>
83 #include <linux/skbuff.h>
84 #include <linux/slab.h>
85 #include <linux/string.h>
86 #include <linux/tcp.h>
87 #include <linux/timer.h>
88 #include <linux/types.h>
89
90 #include "cu3088.h"
91 #include "claw.h"
92
93 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
94 MODULE_DESCRIPTION("Linux for zSeries CLAW Driver\n" \
95                         "Copyright 2000,2005 IBM Corporation\n");
96 MODULE_LICENSE("GPL");
97
98 /* Debugging is based on DEBUGMSG, IOTRACE, or FUNCTRACE  options:
99    DEBUGMSG  - Enables output of various debug messages in the code
100    IOTRACE   - Enables output of CCW and other IO related traces
101    FUNCTRACE - Enables output of function entry/exit trace
102    Define any combination of above options to enable tracing
103
104    CLAW also uses the s390dbf file system  see claw_trace and claw_setup
105 */
106
107 /* following enables tracing */
108 //#define DEBUGMSG
109 //#define IOTRACE
110 //#define FUNCTRACE
111
112 #ifdef DEBUGMSG
113 #define DEBUG
114 #endif
115
116 #ifdef IOTRACE
117 #define DEBUG
118 #endif
119
120 #ifdef FUNCTRACE
121 #define DEBUG
122 #endif
123
124 static char debug_buffer[255];
125 /**
126  * Debug Facility Stuff
127  */
128 static debug_info_t *claw_dbf_setup;
129 static debug_info_t *claw_dbf_trace;
130
131 /**
132  *  CLAW Debug Facility functions
133  */
134 static void
135 claw_unregister_debug_facility(void)
136 {
137         if (claw_dbf_setup)
138                 debug_unregister(claw_dbf_setup);
139         if (claw_dbf_trace)
140                 debug_unregister(claw_dbf_trace);
141 }
142
143 static int
144 claw_register_debug_facility(void)
145 {
146         claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
147         claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
148         if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
149                 printk(KERN_WARNING "Not enough memory for debug facility.\n");
150                 claw_unregister_debug_facility();
151                 return -ENOMEM;
152         }
153         debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
154         debug_set_level(claw_dbf_setup, 2);
155         debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
156         debug_set_level(claw_dbf_trace, 2);
157         return 0;
158 }
159
160 static inline void
161 claw_set_busy(struct net_device *dev)
162 {
163  ((struct claw_privbk *) dev->priv)->tbusy=1;
164  eieio();
165 }
166
167 static inline void
168 claw_clear_busy(struct net_device *dev)
169 {
170         clear_bit(0, &(((struct claw_privbk *) dev->priv)->tbusy));
171         netif_wake_queue(dev);
172         eieio();
173 }
174
175 static inline int
176 claw_check_busy(struct net_device *dev)
177 {
178         eieio();
179         return ((struct claw_privbk *) dev->priv)->tbusy;
180 }
181
182 static inline void
183 claw_setbit_busy(int nr,struct net_device *dev)
184 {
185         netif_stop_queue(dev);
186         set_bit(nr, (void *)&(((struct claw_privbk *)dev->priv)->tbusy));
187 }
188
189 static inline void
190 claw_clearbit_busy(int nr,struct net_device *dev)
191 {
192         clear_bit(nr,(void *)&(((struct claw_privbk *)dev->priv)->tbusy));
193         netif_wake_queue(dev);
194 }
195
196 static inline int
197 claw_test_and_setbit_busy(int nr,struct net_device *dev)
198 {
199         netif_stop_queue(dev);
200         return test_and_set_bit(nr,
201                 (void *)&(((struct claw_privbk *) dev->priv)->tbusy));
202 }
203
204
205 /* Functions for the DEV methods */
206
207 static int claw_probe(struct ccwgroup_device *cgdev);
208 static void claw_remove_device(struct ccwgroup_device *cgdev);
209 static void claw_purge_skb_queue(struct sk_buff_head *q);
210 static int claw_new_device(struct ccwgroup_device *cgdev);
211 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
212 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
213 static int claw_change_mtu( struct net_device *dev, int new_mtu);
214 static int claw_open(struct net_device *dev);
215 static void claw_irq_handler(struct ccw_device *cdev,
216         unsigned long intparm, struct irb *irb);
217 static void claw_irq_tasklet ( unsigned long data );
218 static int claw_release(struct net_device *dev);
219 static void claw_write_retry ( struct chbk * p_ch );
220 static void claw_write_next ( struct chbk * p_ch );
221 static void claw_timer ( struct chbk * p_ch );
222
223 /* Functions */
224 static int add_claw_reads(struct net_device *dev,
225         struct ccwbk* p_first, struct ccwbk* p_last);
226 static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
227 static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
228 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
229 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
230 static int init_ccw_bk(struct net_device *dev);
231 static void probe_error( struct ccwgroup_device *cgdev);
232 static struct net_device_stats *claw_stats(struct net_device *dev);
233 static int pages_to_order_of_mag(int num_of_pages);
234 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
235 #ifdef DEBUG
236 static void dumpit (char *buf, int len);
237 #endif
238 /* sysfs Functions */
239 static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
240 static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
241         const char *buf, size_t count);
242 static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
243 static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
244         const char *buf, size_t count);
245 static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
246 static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
247         const char *buf, size_t count);
248 static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
249 static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
250         const char *buf, size_t count);
251 static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
252 static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
253         const char *buf, size_t count);
254 static int claw_add_files(struct device *dev);
255 static void claw_remove_files(struct device *dev);
256
257 /*   Functions for System Validate  */
258 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
259 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
260        __u8 correlator, __u8 rc , char *local_name, char *remote_name);
261 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
262 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
263 static int claw_snd_sys_validate_rsp(struct net_device *dev,
264         struct clawctl * p_ctl, __u32 return_code);
265 static int claw_strt_conn_req(struct net_device *dev );
266 static void claw_strt_read ( struct net_device *dev, int lock );
267 static void claw_strt_out_IO( struct net_device *dev );
268 static void claw_free_wrt_buf( struct net_device *dev );
269
270 /* Functions for unpack reads   */
271 static void unpack_read (struct net_device *dev );
272
273 /* ccwgroup table  */
274
275 static struct ccwgroup_driver claw_group_driver = {
276         .owner       = THIS_MODULE,
277         .name        = "claw",
278         .max_slaves  = 2,
279         .driver_id   = 0xC3D3C1E6,
280         .probe       = claw_probe,
281         .remove      = claw_remove_device,
282         .set_online  = claw_new_device,
283         .set_offline = claw_shutdown_device,
284 };
285
286 /*
287 *
288 *       Key functions
289 */
290
291 /*----------------------------------------------------------------*
292  *   claw_probe                                                   *
293  *      this function is called for each CLAW device.             *
294  *----------------------------------------------------------------*/
295 static int
296 claw_probe(struct ccwgroup_device *cgdev)
297 {
298         int             rc;
299         struct claw_privbk *privptr=NULL;
300
301 #ifdef FUNCTRACE
302         printk(KERN_INFO "%s Enter\n",__func__);
303 #endif
304         CLAW_DBF_TEXT(2,setup,"probe");
305         if (!get_device(&cgdev->dev))
306                 return -ENODEV;
307 #ifdef DEBUGMSG
308         printk(KERN_INFO "claw: variable cgdev =\n");
309         dumpit((char *)cgdev, sizeof(struct ccwgroup_device));
310 #endif
311         privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
312         if (privptr == NULL) {
313                 probe_error(cgdev);
314                 put_device(&cgdev->dev);
315                 printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
316                         cgdev->cdev[0]->dev.bus_id,__func__,__LINE__);
317                 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
318                 return -ENOMEM;
319         }
320         privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
321         privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
322         if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
323                 probe_error(cgdev);
324                 put_device(&cgdev->dev);
325                 printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
326                         cgdev->cdev[0]->dev.bus_id,__func__,__LINE__);
327                 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
328                 return -ENOMEM;
329         }
330         memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
331         memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
332         memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
333         privptr->p_env->packing = 0;
334         privptr->p_env->write_buffers = 5;
335         privptr->p_env->read_buffers = 5;
336         privptr->p_env->read_size = CLAW_FRAME_SIZE;
337         privptr->p_env->write_size = CLAW_FRAME_SIZE;
338         rc = claw_add_files(&cgdev->dev);
339         if (rc) {
340                 probe_error(cgdev);
341                 put_device(&cgdev->dev);
342                 printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
343                         cgdev->cdev[0]->dev.bus_id,__func__,__LINE__);
344                 CLAW_DBF_TEXT_(2,setup,"probex%d",rc);
345                 return rc;
346         }
347         printk(KERN_INFO "claw: sysfs files added for %s\n",cgdev->cdev[0]->dev.bus_id);
348         privptr->p_env->p_priv = privptr;
349         cgdev->cdev[0]->handler = claw_irq_handler;
350         cgdev->cdev[1]->handler = claw_irq_handler;
351         cgdev->dev.driver_data = privptr;
352 #ifdef FUNCTRACE
353         printk(KERN_INFO "claw:%s exit on line %d, "
354                 "rc = 0\n",__func__,__LINE__);
355 #endif
356         CLAW_DBF_TEXT(2,setup,"prbext 0");
357
358         return 0;
359 }  /*  end of claw_probe       */
360
361 /*-------------------------------------------------------------------*
362  *   claw_tx                                                         *
363  *-------------------------------------------------------------------*/
364
365 static int
366 claw_tx(struct sk_buff *skb, struct net_device *dev)
367 {
368         int             rc;
369         struct claw_privbk *privptr=dev->priv;
370         unsigned long saveflags;
371         struct chbk *p_ch;
372
373 #ifdef FUNCTRACE
374         printk(KERN_INFO "%s:%s enter\n",dev->name,__func__);
375 #endif
376         CLAW_DBF_TEXT(4,trace,"claw_tx");
377         p_ch=&privptr->channel[WRITE];
378         if (skb == NULL) {
379                 printk(KERN_WARNING "%s: null pointer passed as sk_buffer\n",
380                         dev->name);
381                 privptr->stats.tx_dropped++;
382 #ifdef FUNCTRACE
383                 printk(KERN_INFO "%s: %s() exit on line %d, rc = EIO\n",
384                         dev->name,__func__, __LINE__);
385 #endif
386                 CLAW_DBF_TEXT_(2,trace,"clawtx%d",-EIO);
387                 return -EIO;
388         }
389
390 #ifdef IOTRACE
391         printk(KERN_INFO "%s: variable sk_buff=\n",dev->name);
392         dumpit((char *) skb, sizeof(struct sk_buff));
393         printk(KERN_INFO "%s: variable dev=\n",dev->name);
394         dumpit((char *) dev, sizeof(struct net_device));
395 #endif
396         spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
397         rc=claw_hw_tx( skb, dev, 1 );
398         spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
399 #ifdef FUNCTRACE
400         printk(KERN_INFO "%s:%s exit on line %d, rc = %d\n",
401                 dev->name, __func__, __LINE__, rc);
402 #endif
403         CLAW_DBF_TEXT_(4,trace,"clawtx%d",rc);
404         return rc;
405 }   /*  end of claw_tx */
406
407 /*------------------------------------------------------------------*
408  *  pack the collect queue into an skb and return it                *
409  *   If not packing just return the top skb from the queue          *
410  *------------------------------------------------------------------*/
411
412 static struct sk_buff *
413 claw_pack_skb(struct claw_privbk *privptr)
414 {
415         struct sk_buff *new_skb,*held_skb;
416         struct chbk *p_ch = &privptr->channel[WRITE];
417         struct claw_env  *p_env = privptr->p_env;
418         int     pkt_cnt,pk_ind,so_far;
419
420         new_skb = NULL;         /* assume no dice */
421         pkt_cnt = 0;
422         CLAW_DBF_TEXT(4,trace,"PackSKBe");
423         if (!skb_queue_empty(&p_ch->collect_queue)) {
424         /* some data */
425                 held_skb = skb_dequeue(&p_ch->collect_queue);
426                 if (held_skb)
427                         dev_kfree_skb_any(held_skb);
428                 else
429                         return NULL;
430                 if (p_env->packing != DO_PACKED)
431                         return held_skb;
432                 /* get a new SKB we will pack at least one */
433                 new_skb = dev_alloc_skb(p_env->write_size);
434                 if (new_skb == NULL) {
435                         atomic_inc(&held_skb->users);
436                         skb_queue_head(&p_ch->collect_queue,held_skb);
437                         return NULL;
438                 }
439                 /* we have packed packet and a place to put it  */
440                 pk_ind = 1;
441                 so_far = 0;
442                 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
443                 while ((pk_ind) && (held_skb != NULL)) {
444                         if (held_skb->len+so_far <= p_env->write_size-8) {
445                                 memcpy(skb_put(new_skb,held_skb->len),
446                                         held_skb->data,held_skb->len);
447                                 privptr->stats.tx_packets++;
448                                 so_far += held_skb->len;
449                                 pkt_cnt++;
450                                 dev_kfree_skb_any(held_skb);
451                                 held_skb = skb_dequeue(&p_ch->collect_queue);
452                                 if (held_skb)
453                                         atomic_dec(&held_skb->users);
454                         } else {
455                                 pk_ind = 0;
456                                 atomic_inc(&held_skb->users);
457                                 skb_queue_head(&p_ch->collect_queue,held_skb);
458                         }
459                 }
460 #ifdef IOTRACE
461                 printk(KERN_INFO "%s: %s() Packed %d len %d\n",
462                         p_env->ndev->name,
463                         __func__,pkt_cnt,new_skb->len);
464 #endif
465         }
466         CLAW_DBF_TEXT(4,trace,"PackSKBx");
467         return new_skb;
468 }
469
470 /*-------------------------------------------------------------------*
471  *   claw_change_mtu                                                 *
472  *                                                                   *
473  *-------------------------------------------------------------------*/
474
475 static int
476 claw_change_mtu(struct net_device *dev, int new_mtu)
477 {
478         struct claw_privbk  *privptr=dev->priv;
479         int buff_size;
480 #ifdef FUNCTRACE
481         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__func__);
482 #endif
483 #ifdef DEBUGMSG
484         printk(KERN_INFO "variable dev =\n");
485         dumpit((char *) dev, sizeof(struct net_device));
486         printk(KERN_INFO "variable new_mtu = %d\n", new_mtu);
487 #endif
488         CLAW_DBF_TEXT(4,trace,"setmtu");
489         buff_size = privptr->p_env->write_size;
490         if ((new_mtu < 60) || (new_mtu > buff_size)) {
491 #ifdef FUNCTRACE
492                 printk(KERN_INFO "%s:%s Exit on line %d, rc=EINVAL\n",
493                 dev->name,
494                 __func__, __LINE__);
495 #endif
496                 return -EINVAL;
497         }
498         dev->mtu = new_mtu;
499 #ifdef FUNCTRACE
500         printk(KERN_INFO "%s:%s Exit on line %d\n",dev->name,
501         __func__, __LINE__);
502 #endif
503         return 0;
504 }  /*   end of claw_change_mtu */
505
506
507 /*-------------------------------------------------------------------*
508  *   claw_open                                                       *
509  *                                                                   *
510  *-------------------------------------------------------------------*/
511 static int
512 claw_open(struct net_device *dev)
513 {
514
515         int     rc;
516         int     i;
517         unsigned long       saveflags=0;
518         unsigned long       parm;
519         struct claw_privbk  *privptr;
520         DECLARE_WAITQUEUE(wait, current);
521         struct timer_list  timer;
522         struct ccwbk *p_buf;
523
524 #ifdef FUNCTRACE
525         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__func__);
526 #endif
527         CLAW_DBF_TEXT(4,trace,"open");
528         if (!dev || (dev->name[0] == 0x00)) {
529                 CLAW_DBF_TEXT(2,trace,"BadDev");
530                 printk(KERN_WARNING "claw: Bad device at open failing \n");
531                 return -ENODEV;
532         }
533         privptr = (struct claw_privbk *)dev->priv;
534         /*   allocate and initialize CCW blocks */
535         if (privptr->buffs_alloc == 0) {
536                 rc=init_ccw_bk(dev);
537                 if (rc) {
538                         printk(KERN_INFO "%s:%s Exit on line %d, rc=ENOMEM\n",
539                         dev->name,
540                         __func__, __LINE__);
541                         CLAW_DBF_TEXT(2,trace,"openmem");
542                         return -ENOMEM;
543                 }
544         }
545         privptr->system_validate_comp=0;
546         privptr->release_pend=0;
547         if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
548                 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
549                 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
550                 privptr->p_env->packing=PACKING_ASK;
551         } else {
552                 privptr->p_env->packing=0;
553                 privptr->p_env->read_size=CLAW_FRAME_SIZE;
554                 privptr->p_env->write_size=CLAW_FRAME_SIZE;
555         }
556         claw_set_busy(dev);
557         tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
558                 (unsigned long) &privptr->channel[READ]);
559         for ( i = 0; i < 2;  i++) {
560                 CLAW_DBF_TEXT_(2,trace,"opn_ch%d",i);
561                 init_waitqueue_head(&privptr->channel[i].wait);
562                 /* skb_queue_head_init(&p_ch->io_queue); */
563                 if (i == WRITE)
564                         skb_queue_head_init(
565                                 &privptr->channel[WRITE].collect_queue);
566                 privptr->channel[i].flag_a = 0;
567                 privptr->channel[i].IO_active = 0;
568                 privptr->channel[i].flag  &= ~CLAW_TIMER;
569                 init_timer(&timer);
570                 timer.function = (void *)claw_timer;
571                 timer.data = (unsigned long)(&privptr->channel[i]);
572                 timer.expires = jiffies + 15*HZ;
573                 add_timer(&timer);
574                 spin_lock_irqsave(get_ccwdev_lock(
575                         privptr->channel[i].cdev), saveflags);
576                 parm = (unsigned long) &privptr->channel[i];
577                 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
578                 rc = 0;
579                 add_wait_queue(&privptr->channel[i].wait, &wait);
580                 rc = ccw_device_halt(
581                         (struct ccw_device *)privptr->channel[i].cdev,parm);
582                 set_current_state(TASK_INTERRUPTIBLE);
583                 spin_unlock_irqrestore(
584                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
585                 schedule();
586                 set_current_state(TASK_RUNNING);
587                 remove_wait_queue(&privptr->channel[i].wait, &wait);
588                 if(rc != 0)
589                         ccw_check_return_code(privptr->channel[i].cdev, rc);
590                 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
591                         del_timer(&timer);
592         }
593         if ((((privptr->channel[READ].last_dstat |
594                 privptr->channel[WRITE].last_dstat) &
595            ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
596            (((privptr->channel[READ].flag |
597                 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
598 #ifdef DEBUGMSG
599                 printk(KERN_INFO "%s: channel problems during open - read:"
600                         " %02x -  write: %02x\n",
601                         dev->name,
602                         privptr->channel[READ].last_dstat,
603                         privptr->channel[WRITE].last_dstat);
604 #endif
605                 printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
606                 CLAW_DBF_TEXT(2,trace,"notrdy");
607
608                 for ( i = 0; i < 2;  i++) {
609                         spin_lock_irqsave(
610                                 get_ccwdev_lock(privptr->channel[i].cdev),
611                                 saveflags);
612                         parm = (unsigned long) &privptr->channel[i];
613                         privptr->channel[i].claw_state = CLAW_STOP;
614                         rc = ccw_device_halt(
615                                 (struct ccw_device *)&privptr->channel[i].cdev,
616                                 parm);
617                         spin_unlock_irqrestore(
618                                 get_ccwdev_lock(privptr->channel[i].cdev),
619                                 saveflags);
620                         if (rc != 0) {
621                                 ccw_check_return_code(
622                                         privptr->channel[i].cdev, rc);
623                         }
624                 }
625                 free_pages((unsigned long)privptr->p_buff_ccw,
626                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
627                 if (privptr->p_env->read_size < PAGE_SIZE) {
628                         free_pages((unsigned long)privptr->p_buff_read,
629                                (int)pages_to_order_of_mag(
630                                         privptr->p_buff_read_num));
631                 }
632                 else {
633                         p_buf=privptr->p_read_active_first;
634                         while (p_buf!=NULL) {
635                                 free_pages((unsigned long)p_buf->p_buffer,
636                                       (int)pages_to_order_of_mag(
637                                         privptr->p_buff_pages_perread ));
638                                 p_buf=p_buf->next;
639                         }
640                 }
641                 if (privptr->p_env->write_size < PAGE_SIZE ) {
642                         free_pages((unsigned long)privptr->p_buff_write,
643                              (int)pages_to_order_of_mag(
644                                 privptr->p_buff_write_num));
645                 }
646                 else {
647                         p_buf=privptr->p_write_active_first;
648                         while (p_buf!=NULL) {
649                                 free_pages((unsigned long)p_buf->p_buffer,
650                                      (int)pages_to_order_of_mag(
651                                         privptr->p_buff_pages_perwrite ));
652                                 p_buf=p_buf->next;
653                         }
654                 }
655                 privptr->buffs_alloc = 0;
656                 privptr->channel[READ].flag= 0x00;
657                 privptr->channel[WRITE].flag = 0x00;
658                 privptr->p_buff_ccw=NULL;
659                 privptr->p_buff_read=NULL;
660                 privptr->p_buff_write=NULL;
661                 claw_clear_busy(dev);
662 #ifdef FUNCTRACE
663                 printk(KERN_INFO "%s:%s Exit on line %d, rc=EIO\n",
664                 dev->name,__func__,__LINE__);
665 #endif
666                 CLAW_DBF_TEXT(2,trace,"open EIO");
667                 return -EIO;
668         }
669
670         /*   Send SystemValidate command */
671
672         claw_clear_busy(dev);
673
674 #ifdef FUNCTRACE
675         printk(KERN_INFO "%s:%s Exit on line %d, rc=0\n",
676                 dev->name,__func__,__LINE__);
677 #endif
678         CLAW_DBF_TEXT(4,trace,"openok");
679         return 0;
680 }    /*     end of claw_open    */
681
682 /*-------------------------------------------------------------------*
683 *                                                                    *
684 *       claw_irq_handler                                             *
685 *                                                                    *
686 *--------------------------------------------------------------------*/
687 static void
688 claw_irq_handler(struct ccw_device *cdev,
689         unsigned long intparm, struct irb *irb)
690 {
691         struct chbk *p_ch = NULL;
692         struct claw_privbk *privptr = NULL;
693         struct net_device *dev = NULL;
694         struct claw_env  *p_env;
695         struct chbk *p_ch_r=NULL;
696
697
698 #ifdef FUNCTRACE
699         printk(KERN_INFO "%s enter  \n",__func__);
700 #endif
701         CLAW_DBF_TEXT(4,trace,"clawirq");
702         /* Bypass all 'unsolicited interrupts' */
703         if (!cdev->dev.driver_data) {
704                 printk(KERN_WARNING "claw: unsolicited interrupt for device:"
705                         "%s received c-%02x d-%02x\n",
706                         cdev->dev.bus_id,irb->scsw.cstat, irb->scsw.dstat);
707 #ifdef FUNCTRACE
708                 printk(KERN_INFO "claw: %s() "
709                         "exit on line %d\n",__func__,__LINE__);
710 #endif
711                 CLAW_DBF_TEXT(2,trace,"badirq");
712                 return;
713         }
714         privptr = (struct claw_privbk *)cdev->dev.driver_data;
715
716         /* Try to extract channel from driver data. */
717         if (privptr->channel[READ].cdev == cdev)
718                 p_ch = &privptr->channel[READ];
719         else if (privptr->channel[WRITE].cdev == cdev)
720                 p_ch = &privptr->channel[WRITE];
721         else {
722                 printk(KERN_WARNING "claw: Can't determine channel for "
723                         "interrupt, device %s\n", cdev->dev.bus_id);
724                 CLAW_DBF_TEXT(2,trace,"badchan");
725                 return;
726         }
727         CLAW_DBF_TEXT_(4,trace,"IRQCH=%d",p_ch->flag);
728
729         dev = (struct net_device *) (p_ch->ndev);
730         p_env=privptr->p_env;
731
732 #ifdef IOTRACE
733         printk(KERN_INFO "%s: interrupt for device: %04x "
734                 "received c-%02x d-%02x state-%02x\n",
735                 dev->name, p_ch->devno, irb->scsw.cstat,
736                 irb->scsw.dstat, p_ch->claw_state);
737 #endif
738
739         /* Copy interruption response block. */
740         memcpy(p_ch->irb, irb, sizeof(struct irb));
741
742         /* Check for good subchannel return code, otherwise error message */
743         if (irb->scsw.cstat  &&  !(irb->scsw.cstat & SCHN_STAT_PCI)) {
744                 printk(KERN_INFO "%s: subchannel check for device: %04x -"
745                         " Sch Stat %02x  Dev Stat %02x CPA - %04x\n",
746                         dev->name, p_ch->devno,
747                         irb->scsw.cstat, irb->scsw.dstat,irb->scsw.cpa);
748 #ifdef IOTRACE
749                 dumpit((char *)irb,sizeof(struct irb));
750                 dumpit((char *)(unsigned long)irb->scsw.cpa,
751                         sizeof(struct ccw1));
752 #endif
753 #ifdef FUNCTRACE
754                 printk(KERN_INFO "%s:%s Exit on line %d\n",
755                 dev->name,__func__,__LINE__);
756 #endif
757                 CLAW_DBF_TEXT(2,trace,"chanchk");
758                 /* return; */
759         }
760
761         /* Check the reason-code of a unit check */
762         if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
763                 ccw_check_unit_check(p_ch, irb->ecw[0]);
764         }
765
766         /* State machine to bring the connection up, down and to restart */
767         p_ch->last_dstat = irb->scsw.dstat;
768
769         switch (p_ch->claw_state) {
770                 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
771 #ifdef DEBUGMSG
772                         printk(KERN_INFO "%s: CLAW_STOP enter\n", dev->name);
773 #endif
774                         if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
775                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
776                         (p_ch->irb->scsw.stctl ==
777                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
778 #ifdef FUNCTRACE
779                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
780                                         dev->name,__func__,__LINE__);
781 #endif
782                                 return;
783                         }
784                         wake_up(&p_ch->wait);   /* wake up claw_release */
785
786 #ifdef DEBUGMSG
787                         printk(KERN_INFO "%s: CLAW_STOP exit\n", dev->name);
788 #endif
789 #ifdef FUNCTRACE
790                         printk(KERN_INFO "%s:%s Exit on line %d\n",
791                                 dev->name,__func__,__LINE__);
792 #endif
793                         CLAW_DBF_TEXT(4,trace,"stop");
794                         return;
795
796                 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open  */
797 #ifdef DEBUGMSG
798                         printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO\n",
799                                 dev->name);
800 #endif
801                         if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
802                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
803                         (p_ch->irb->scsw.stctl ==
804                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
805 #ifdef FUNCTRACE
806                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
807                                         dev->name,__func__,__LINE__);
808 #endif
809                                 CLAW_DBF_TEXT(4,trace,"haltio");
810                                 return;
811                         }
812                         if (p_ch->flag == CLAW_READ) {
813                                 p_ch->claw_state = CLAW_START_READ;
814                                 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
815                         }
816                         else
817                            if (p_ch->flag == CLAW_WRITE) {
818                                 p_ch->claw_state = CLAW_START_WRITE;
819                                 /*      send SYSTEM_VALIDATE                    */
820                                 claw_strt_read(dev, LOCK_NO);
821                                 claw_send_control(dev,
822                                         SYSTEM_VALIDATE_REQUEST,
823                                         0, 0, 0,
824                                         p_env->host_name,
825                                         p_env->adapter_name );
826                         } else {
827                                 printk(KERN_WARNING "claw: unsolicited "
828                                         "interrupt for device:"
829                                         "%s received c-%02x d-%02x\n",
830                                         cdev->dev.bus_id,
831                                         irb->scsw.cstat,
832                                         irb->scsw.dstat);
833                                 return;
834                                 }
835 #ifdef DEBUGMSG
836                         printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO exit\n",
837                                 dev->name);
838 #endif
839 #ifdef FUNCTRACE
840                         printk(KERN_INFO "%s:%s Exit on line %d\n",
841                                 dev->name,__func__,__LINE__);
842 #endif
843                         CLAW_DBF_TEXT(4,trace,"haltio");
844                         return;
845                 case CLAW_START_READ:
846                         CLAW_DBF_TEXT(4,trace,"ReadIRQ");
847                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
848                                 clear_bit(0, (void *)&p_ch->IO_active);
849                                 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
850                                     (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
851                                     (p_ch->irb->ecw[0])        == 0)
852                                 {
853                                         privptr->stats.rx_errors++;
854                                         printk(KERN_INFO "%s: Restart is "
855                                                 "required after remote "
856                                                 "side recovers \n",
857                                                 dev->name);
858                                 }
859 #ifdef FUNCTRACE
860                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
861                                         dev->name,__func__,__LINE__);
862 #endif
863                                         CLAW_DBF_TEXT(4,trace,"notrdy");
864                                         return;
865                         }
866                         if ((p_ch->irb->scsw.cstat & SCHN_STAT_PCI) &&
867                             (p_ch->irb->scsw.dstat==0)) {
868                                 if (test_and_set_bit(CLAW_BH_ACTIVE,
869                                         (void *)&p_ch->flag_a) == 0) {
870                                         tasklet_schedule(&p_ch->tasklet);
871                                 }
872                                 else {
873                                         CLAW_DBF_TEXT(4,trace,"PCINoBH");
874                                 }
875 #ifdef FUNCTRACE
876                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
877                                         dev->name,__func__,__LINE__);
878 #endif
879                                 CLAW_DBF_TEXT(4,trace,"PCI_read");
880                                 return;
881                         }
882                         if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
883                          (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
884                          (p_ch->irb->scsw.stctl ==
885                          (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
886 #ifdef FUNCTRACE
887                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
888                                         dev->name,__func__,__LINE__);
889 #endif
890                                 CLAW_DBF_TEXT(4,trace,"SPend_rd");
891                                 return;
892                         }
893                         clear_bit(0, (void *)&p_ch->IO_active);
894                         claw_clearbit_busy(TB_RETRY,dev);
895                         if (test_and_set_bit(CLAW_BH_ACTIVE,
896                                 (void *)&p_ch->flag_a) == 0) {
897                                 tasklet_schedule(&p_ch->tasklet);
898                          }
899                         else {
900                                 CLAW_DBF_TEXT(4,trace,"RdBHAct");
901                         }
902
903 #ifdef DEBUGMSG
904                         printk(KERN_INFO "%s: process CLAW_START_READ exit\n",
905                                 dev->name);
906 #endif
907 #ifdef FUNCTRACE
908                         printk(KERN_INFO "%s:%s Exit on line %d\n",
909                                 dev->name,__func__,__LINE__);
910 #endif
911                         CLAW_DBF_TEXT(4,trace,"RdIRQXit");
912                         return;
913                 case CLAW_START_WRITE:
914                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
915                                 printk(KERN_INFO "%s: Unit Check Occured in "
916                                         "write channel\n",dev->name);
917                                 clear_bit(0, (void *)&p_ch->IO_active);
918                                 if (p_ch->irb->ecw[0] & 0x80 ) {
919                                         printk(KERN_INFO "%s: Resetting Event "
920                                                 "occurred:\n",dev->name);
921                                         init_timer(&p_ch->timer);
922                                         p_ch->timer.function =
923                                                 (void *)claw_write_retry;
924                                         p_ch->timer.data = (unsigned long)p_ch;
925                                         p_ch->timer.expires = jiffies + 10*HZ;
926                                         add_timer(&p_ch->timer);
927                                         printk(KERN_INFO "%s: write connection "
928                                                 "restarting\n",dev->name);
929                                 }
930 #ifdef FUNCTRACE
931                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
932                                         dev->name,__func__,__LINE__);
933 #endif
934                                 CLAW_DBF_TEXT(4,trace,"rstrtwrt");
935                                 return;
936                         }
937                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
938                                         clear_bit(0, (void *)&p_ch->IO_active);
939                                         printk(KERN_INFO "%s: Unit Exception "
940                                                 "Occured in write channel\n",
941                                                 dev->name);
942                         }
943                         if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
944                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
945                         (p_ch->irb->scsw.stctl ==
946                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
947 #ifdef FUNCTRACE
948                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
949                                         dev->name,__func__,__LINE__);
950 #endif
951                                 CLAW_DBF_TEXT(4,trace,"writeUE");
952                                 return;
953                         }
954                         clear_bit(0, (void *)&p_ch->IO_active);
955                         if (claw_test_and_setbit_busy(TB_TX,dev)==0) {
956                                 claw_write_next(p_ch);
957                                 claw_clearbit_busy(TB_TX,dev);
958                                 claw_clear_busy(dev);
959                         }
960                         p_ch_r=(struct chbk *)&privptr->channel[READ];
961                         if (test_and_set_bit(CLAW_BH_ACTIVE,
962                                         (void *)&p_ch_r->flag_a) == 0) {
963                                 tasklet_schedule(&p_ch_r->tasklet);
964                         }
965
966 #ifdef DEBUGMSG
967                         printk(KERN_INFO "%s: process CLAW_START_WRITE exit\n",
968                                  dev->name);
969 #endif
970 #ifdef FUNCTRACE
971                         printk(KERN_INFO "%s:%s Exit on line %d\n",
972                                 dev->name,__func__,__LINE__);
973 #endif
974                         CLAW_DBF_TEXT(4,trace,"StWtExit");
975                         return;
976                 default:
977                         printk(KERN_WARNING "%s: wrong selection code - irq "
978                                 "state=%d\n",dev->name,p_ch->claw_state);
979 #ifdef FUNCTRACE
980                         printk(KERN_INFO "%s:%s Exit on line %d\n",
981                                 dev->name,__func__,__LINE__);
982 #endif
983                         CLAW_DBF_TEXT(2,trace,"badIRQ");
984                         return;
985         }
986
987 }       /*   end of claw_irq_handler    */
988
989
990 /*-------------------------------------------------------------------*
991 *       claw_irq_tasklet                                             *
992 *                                                                    *
993 *--------------------------------------------------------------------*/
994 static void
995 claw_irq_tasklet ( unsigned long data )
996 {
997         struct chbk * p_ch;
998         struct net_device  *dev;
999         struct claw_privbk *       privptr;
1000
1001         p_ch = (struct chbk *) data;
1002         dev = (struct net_device *)p_ch->ndev;
1003 #ifdef FUNCTRACE
1004         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__func__);
1005 #endif
1006 #ifdef DEBUGMSG
1007         printk(KERN_INFO "%s: variable p_ch =\n",dev->name);
1008         dumpit((char *) p_ch, sizeof(struct chbk));
1009 #endif
1010         CLAW_DBF_TEXT(4,trace,"IRQtask");
1011
1012         privptr = (struct claw_privbk *) dev->priv;
1013
1014 #ifdef DEBUGMSG
1015         printk(KERN_INFO "%s: bh routine - state-%02x\n" ,
1016                 dev->name, p_ch->claw_state);
1017 #endif
1018
1019         unpack_read(dev);
1020         clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
1021         CLAW_DBF_TEXT(4,trace,"TskletXt");
1022 #ifdef FUNCTRACE
1023         printk(KERN_INFO "%s:%s Exit on line %d\n",
1024                 dev->name,__func__,__LINE__);
1025 #endif
1026         return;
1027 }       /*    end of claw_irq_bh    */
1028
1029 /*-------------------------------------------------------------------*
1030 *       claw_release                                                 *
1031 *                                                                    *
1032 *--------------------------------------------------------------------*/
1033 static int
1034 claw_release(struct net_device *dev)
1035 {
1036         int                rc;
1037         int                i;
1038         unsigned long      saveflags;
1039         unsigned long      parm;
1040         struct claw_privbk *privptr;
1041         DECLARE_WAITQUEUE(wait, current);
1042         struct ccwbk*             p_this_ccw;
1043         struct ccwbk*             p_buf;
1044
1045         if (!dev)
1046                 return 0;
1047         privptr = (struct claw_privbk *) dev->priv;
1048         if (!privptr)
1049                 return 0;
1050 #ifdef FUNCTRACE
1051         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__func__);
1052 #endif
1053         CLAW_DBF_TEXT(4,trace,"release");
1054 #ifdef DEBUGMSG
1055         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1056         dumpit((char *) dev, sizeof(struct net_device));
1057         printk(KERN_INFO "Priv Buffalloc %d\n",privptr->buffs_alloc);
1058         printk(KERN_INFO "Priv p_buff_ccw = %p\n",&privptr->p_buff_ccw);
1059 #endif
1060         privptr->release_pend=1;
1061         claw_setbit_busy(TB_STOP,dev);
1062         for ( i = 1; i >=0 ;  i--) {
1063                 spin_lock_irqsave(
1064                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
1065              /*   del_timer(&privptr->channel[READ].timer);  */
1066                 privptr->channel[i].claw_state = CLAW_STOP;
1067                 privptr->channel[i].IO_active = 0;
1068                 parm = (unsigned long) &privptr->channel[i];
1069                 if (i == WRITE)
1070                         claw_purge_skb_queue(
1071                                 &privptr->channel[WRITE].collect_queue);
1072                 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
1073                 if (privptr->system_validate_comp==0x00)  /* never opened? */
1074                    init_waitqueue_head(&privptr->channel[i].wait);
1075                 add_wait_queue(&privptr->channel[i].wait, &wait);
1076                 set_current_state(TASK_INTERRUPTIBLE);
1077                 spin_unlock_irqrestore(
1078                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
1079                 schedule();
1080                 set_current_state(TASK_RUNNING);
1081                 remove_wait_queue(&privptr->channel[i].wait, &wait);
1082                 if (rc != 0) {
1083                         ccw_check_return_code(privptr->channel[i].cdev, rc);
1084                 }
1085         }
1086         if (privptr->pk_skb != NULL) {
1087                 dev_kfree_skb_any(privptr->pk_skb);
1088                 privptr->pk_skb = NULL;
1089         }
1090         if(privptr->buffs_alloc != 1) {
1091 #ifdef FUNCTRACE
1092         printk(KERN_INFO "%s:%s Exit on line %d\n",
1093                 dev->name,__func__,__LINE__);
1094 #endif
1095                 CLAW_DBF_TEXT(4,trace,"none2fre");
1096                 return 0;
1097         }
1098         CLAW_DBF_TEXT(4,trace,"freebufs");
1099         if (privptr->p_buff_ccw != NULL) {
1100                 free_pages((unsigned long)privptr->p_buff_ccw,
1101                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
1102         }
1103         CLAW_DBF_TEXT(4,trace,"freeread");
1104         if (privptr->p_env->read_size < PAGE_SIZE) {
1105             if (privptr->p_buff_read != NULL) {
1106                 free_pages((unsigned long)privptr->p_buff_read,
1107                       (int)pages_to_order_of_mag(privptr->p_buff_read_num));
1108                 }
1109         }
1110         else {
1111                 p_buf=privptr->p_read_active_first;
1112                 while (p_buf!=NULL) {
1113                         free_pages((unsigned long)p_buf->p_buffer,
1114                              (int)pages_to_order_of_mag(
1115                                 privptr->p_buff_pages_perread ));
1116                         p_buf=p_buf->next;
1117                 }
1118         }
1119          CLAW_DBF_TEXT(4,trace,"freewrit");
1120         if (privptr->p_env->write_size < PAGE_SIZE ) {
1121                 free_pages((unsigned long)privptr->p_buff_write,
1122                       (int)pages_to_order_of_mag(privptr->p_buff_write_num));
1123         }
1124         else {
1125                 p_buf=privptr->p_write_active_first;
1126                 while (p_buf!=NULL) {
1127                         free_pages((unsigned long)p_buf->p_buffer,
1128                               (int)pages_to_order_of_mag(
1129                               privptr->p_buff_pages_perwrite ));
1130                         p_buf=p_buf->next;
1131                 }
1132         }
1133          CLAW_DBF_TEXT(4,trace,"clearptr");
1134         privptr->buffs_alloc = 0;
1135         privptr->p_buff_ccw=NULL;
1136         privptr->p_buff_read=NULL;
1137         privptr->p_buff_write=NULL;
1138         privptr->system_validate_comp=0;
1139         privptr->release_pend=0;
1140         /*      Remove any writes that were pending and reset all reads   */
1141         p_this_ccw=privptr->p_read_active_first;
1142         while (p_this_ccw!=NULL) {
1143                 p_this_ccw->header.length=0xffff;
1144                 p_this_ccw->header.opcode=0xff;
1145                 p_this_ccw->header.flag=0x00;
1146                 p_this_ccw=p_this_ccw->next;
1147         }
1148
1149         while (privptr->p_write_active_first!=NULL) {
1150                 p_this_ccw=privptr->p_write_active_first;
1151                 p_this_ccw->header.flag=CLAW_PENDING;
1152                 privptr->p_write_active_first=p_this_ccw->next;
1153                 p_this_ccw->next=privptr->p_write_free_chain;
1154                 privptr->p_write_free_chain=p_this_ccw;
1155                 ++privptr->write_free_count;
1156         }
1157         privptr->p_write_active_last=NULL;
1158         privptr->mtc_logical_link = -1;
1159         privptr->mtc_skipping = 1;
1160         privptr->mtc_offset=0;
1161
1162         if (((privptr->channel[READ].last_dstat |
1163                 privptr->channel[WRITE].last_dstat) &
1164                 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
1165                 printk(KERN_WARNING "%s: channel problems during close - "
1166                         "read: %02x -  write: %02x\n",
1167                 dev->name,
1168                 privptr->channel[READ].last_dstat,
1169                 privptr->channel[WRITE].last_dstat);
1170                  CLAW_DBF_TEXT(2,trace,"badclose");
1171         }
1172 #ifdef FUNCTRACE
1173         printk(KERN_INFO "%s:%s Exit on line %d\n",
1174                 dev->name,__func__,__LINE__);
1175 #endif
1176         CLAW_DBF_TEXT(4,trace,"rlsexit");
1177         return 0;
1178 }      /* end of claw_release     */
1179
1180
1181
1182 /*-------------------------------------------------------------------*
1183 *       claw_write_retry                                             *
1184 *                                                                    *
1185 *--------------------------------------------------------------------*/
1186
1187 static void
1188 claw_write_retry ( struct chbk *p_ch )
1189 {
1190
1191         struct net_device  *dev=p_ch->ndev;
1192
1193
1194 #ifdef FUNCTRACE
1195         printk(KERN_INFO "%s:%s Enter\n",dev->name,__func__);
1196         printk(KERN_INFO "claw: variable p_ch =\n");
1197         dumpit((char *) p_ch, sizeof(struct chbk));
1198 #endif
1199         CLAW_DBF_TEXT(4,trace,"w_retry");
1200         if (p_ch->claw_state == CLAW_STOP) {
1201 #ifdef FUNCTRACE
1202                 printk(KERN_INFO "%s:%s Exit on line %d\n",
1203                         dev->name,__func__,__LINE__);
1204 #endif
1205                 return;
1206         }
1207 #ifdef DEBUGMSG
1208         printk( KERN_INFO "%s:%s  state-%02x\n" ,
1209                 dev->name,
1210                 __func__,
1211                 p_ch->claw_state);
1212 #endif
1213         claw_strt_out_IO( dev );
1214 #ifdef FUNCTRACE
1215         printk(KERN_INFO "%s:%s Exit on line %d\n",
1216                 dev->name,__func__,__LINE__);
1217 #endif
1218         CLAW_DBF_TEXT(4,trace,"rtry_xit");
1219         return;
1220 }      /* end of claw_write_retry      */
1221
1222
1223 /*-------------------------------------------------------------------*
1224 *       claw_write_next                                              *
1225 *                                                                    *
1226 *--------------------------------------------------------------------*/
1227
1228 static void
1229 claw_write_next ( struct chbk * p_ch )
1230 {
1231
1232         struct net_device  *dev;
1233         struct claw_privbk *privptr=NULL;
1234         struct sk_buff *pk_skb;
1235         int     rc;
1236
1237 #ifdef FUNCTRACE
1238         printk(KERN_INFO "%s:%s Enter  \n",p_ch->ndev->name,__func__);
1239         printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
1240         dumpit((char *) p_ch, sizeof(struct chbk));
1241 #endif
1242         CLAW_DBF_TEXT(4,trace,"claw_wrt");
1243         if (p_ch->claw_state == CLAW_STOP)
1244                 return;
1245         dev = (struct net_device *) p_ch->ndev;
1246         privptr = (struct claw_privbk *) dev->priv;
1247         claw_free_wrt_buf( dev );
1248         if ((privptr->write_free_count > 0) &&
1249             !skb_queue_empty(&p_ch->collect_queue)) {
1250                 pk_skb = claw_pack_skb(privptr);
1251                 while (pk_skb != NULL) {
1252                         rc = claw_hw_tx( pk_skb, dev,1);
1253                         if (privptr->write_free_count > 0) {
1254                                 pk_skb = claw_pack_skb(privptr);
1255                         } else
1256                                 pk_skb = NULL;
1257                 }
1258         }
1259         if (privptr->p_write_active_first!=NULL) {
1260                 claw_strt_out_IO(dev);
1261         }
1262
1263 #ifdef FUNCTRACE
1264         printk(KERN_INFO "%s:%s Exit on line %d\n",
1265                 dev->name,__func__,__LINE__);
1266 #endif
1267         return;
1268 }      /* end of claw_write_next      */
1269
1270 /*-------------------------------------------------------------------*
1271 *                                                                    *
1272 *       claw_timer                                                   *
1273 *--------------------------------------------------------------------*/
1274
1275 static void
1276 claw_timer ( struct chbk * p_ch )
1277 {
1278 #ifdef FUNCTRACE
1279         printk(KERN_INFO "%s:%s Entry\n",p_ch->ndev->name,__func__);
1280         printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
1281         dumpit((char *) p_ch, sizeof(struct chbk));
1282 #endif
1283         CLAW_DBF_TEXT(4,trace,"timer");
1284         p_ch->flag |= CLAW_TIMER;
1285         wake_up(&p_ch->wait);
1286 #ifdef FUNCTRACE
1287         printk(KERN_INFO "%s:%s Exit on line %d\n",
1288                 p_ch->ndev->name,__func__,__LINE__);
1289 #endif
1290         return;
1291 }      /* end of claw_timer  */
1292
1293
1294 /*
1295 *
1296 *       functions
1297 */
1298
1299
1300 /*-------------------------------------------------------------------*
1301 *                                                                    *
1302 *     pages_to_order_of_mag                                          *
1303 *                                                                    *
1304 *    takes a number of pages from 1 to 512 and returns the           *
1305 *    log(num_pages)/log(2) get_free_pages() needs a base 2 order     *
1306 *    of magnitude get_free_pages() has an upper order of 9           *
1307 *--------------------------------------------------------------------*/
1308
1309 static int
1310 pages_to_order_of_mag(int num_of_pages)
1311 {
1312         int     order_of_mag=1;         /* assume 2 pages */
1313         int     nump=2;
1314 #ifdef FUNCTRACE
1315         printk(KERN_INFO "%s Enter pages = %d \n",__func__,num_of_pages);
1316 #endif
1317         CLAW_DBF_TEXT_(5,trace,"pages%d",num_of_pages);
1318         if (num_of_pages == 1)   {return 0; }  /* magnitude of 0 = 1 page */
1319         /* 512 pages = 2Meg on 4k page systems */
1320         if (num_of_pages >= 512) {return 9; }
1321         /* we have two or more pages order is at least 1 */
1322         for (nump=2 ;nump <= 512;nump*=2) {
1323           if (num_of_pages <= nump)
1324                   break;
1325           order_of_mag +=1;
1326         }
1327         if (order_of_mag > 9) { order_of_mag = 9; }  /* I know it's paranoid */
1328 #ifdef FUNCTRACE
1329         printk(KERN_INFO "%s Exit on line %d, order = %d\n",
1330         __func__,__LINE__, order_of_mag);
1331 #endif
1332         CLAW_DBF_TEXT_(5,trace,"mag%d",order_of_mag);
1333         return order_of_mag;
1334 }
1335
1336 /*-------------------------------------------------------------------*
1337 *                                                                    *
1338 *     add_claw_reads                                                 *
1339 *                                                                    *
1340 *--------------------------------------------------------------------*/
1341 static int
1342 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1343         struct ccwbk* p_last)
1344 {
1345         struct claw_privbk *privptr;
1346         struct ccw1  temp_ccw;
1347         struct endccw * p_end;
1348 #ifdef IOTRACE
1349         struct ccwbk*  p_buf;
1350 #endif
1351 #ifdef FUNCTRACE
1352         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__func__);
1353 #endif
1354 #ifdef DEBUGMSG
1355         printk(KERN_INFO "dev\n");
1356         dumpit((char *) dev, sizeof(struct net_device));
1357         printk(KERN_INFO "p_first\n");
1358         dumpit((char *) p_first, sizeof(struct ccwbk));
1359         printk(KERN_INFO "p_last\n");
1360         dumpit((char *) p_last, sizeof(struct ccwbk));
1361 #endif
1362         CLAW_DBF_TEXT(4,trace,"addreads");
1363         privptr = dev->priv;
1364         p_end = privptr->p_end_ccw;
1365
1366         /* first CCW and last CCW contains a new set of read channel programs
1367         *       to apend the running channel programs
1368         */
1369         if ( p_first==NULL) {
1370 #ifdef FUNCTRACE
1371                 printk(KERN_INFO "%s:%s Exit on line %d\n",
1372                         dev->name,__func__,__LINE__);
1373 #endif
1374                 CLAW_DBF_TEXT(4,trace,"addexit");
1375                 return 0;
1376         }
1377
1378         /* set up ending CCW sequence for this segment */
1379         if (p_end->read1) {
1380                 p_end->read1=0x00;    /*  second ending CCW is now active */
1381                 /*      reset ending CCWs and setup TIC CCWs              */
1382                 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1383                 p_end->read2_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1384                 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1385                 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1386                 p_end->read2_nop2.cda=0;
1387                 p_end->read2_nop2.count=1;
1388         }
1389         else {
1390                 p_end->read1=0x01;  /* first ending CCW is now active */
1391                 /*      reset ending CCWs and setup TIC CCWs          */
1392                 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1393                 p_end->read1_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1394                 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1395                 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1396                 p_end->read1_nop2.cda=0;
1397                 p_end->read1_nop2.count=1;
1398         }
1399
1400         if ( privptr-> p_read_active_first ==NULL ) {
1401 #ifdef DEBUGMSG
1402                 printk(KERN_INFO "%s:%s p_read_active_first == NULL \n",
1403                         dev->name,__func__);
1404                 printk(KERN_INFO "%s:%s Read active first/last changed \n",
1405                         dev->name,__func__);
1406 #endif
1407                 privptr-> p_read_active_first= p_first;  /*    set new first */
1408                 privptr-> p_read_active_last = p_last;   /*    set new last  */
1409         }
1410         else {
1411
1412 #ifdef DEBUGMSG
1413                 printk(KERN_INFO "%s:%s Read in progress \n",
1414                 dev->name,__func__);
1415 #endif
1416                 /* set up TIC ccw  */
1417                 temp_ccw.cda= (__u32)__pa(&p_first->read);
1418                 temp_ccw.count=0;
1419                 temp_ccw.flags=0;
1420                 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1421
1422
1423                 if (p_end->read1) {
1424
1425                /* first set of CCW's is chained to the new read              */
1426                /* chain, so the second set is chained to the active chain.   */
1427                /* Therefore modify the second set to point to the new        */
1428                /* read chain set up TIC CCWs                                 */
1429                /* make sure we update the CCW so channel doesn't fetch it    */
1430                /* when it's only half done                                   */
1431                         memcpy( &p_end->read2_nop2, &temp_ccw ,
1432                                 sizeof(struct ccw1));
1433                         privptr->p_read_active_last->r_TIC_1.cda=
1434                                 (__u32)__pa(&p_first->read);
1435                         privptr->p_read_active_last->r_TIC_2.cda=
1436                                 (__u32)__pa(&p_first->read);
1437                 }
1438                 else {
1439                         /* make sure we update the CCW so channel doesn't   */
1440                         /* fetch it when it is only half done               */
1441                         memcpy( &p_end->read1_nop2, &temp_ccw ,
1442                                 sizeof(struct ccw1));
1443                         privptr->p_read_active_last->r_TIC_1.cda=
1444                                 (__u32)__pa(&p_first->read);
1445                         privptr->p_read_active_last->r_TIC_2.cda=
1446                                 (__u32)__pa(&p_first->read);
1447                 }
1448                 /*      chain in new set of blocks                              */
1449                 privptr->p_read_active_last->next = p_first;
1450                 privptr->p_read_active_last=p_last;
1451         } /* end of if ( privptr-> p_read_active_first ==NULL)  */
1452 #ifdef IOTRACE
1453         printk(KERN_INFO "%s:%s  dump p_last CCW BK \n",dev->name,__func__);
1454         dumpit((char *)p_last, sizeof(struct ccwbk));
1455         printk(KERN_INFO "%s:%s  dump p_end CCW BK \n",dev->name,__func__);
1456         dumpit((char *)p_end, sizeof(struct endccw));
1457
1458         printk(KERN_INFO "%s:%s dump p_first CCW BK \n",dev->name,__func__);
1459         dumpit((char *)p_first, sizeof(struct ccwbk));
1460         printk(KERN_INFO "%s:%s Dump Active CCW chain \n",
1461                 dev->name,__func__);
1462         p_buf=privptr->p_read_active_first;
1463         while (p_buf!=NULL) {
1464                 dumpit((char *)p_buf, sizeof(struct ccwbk));
1465                 p_buf=p_buf->next;
1466         }
1467 #endif
1468 #ifdef FUNCTRACE
1469         printk(KERN_INFO "%s:%s Exit on line %d\n",
1470                 dev->name,__func__,__LINE__);
1471 #endif
1472         CLAW_DBF_TEXT(4,trace,"addexit");
1473         return 0;
1474 }    /*     end of add_claw_reads   */
1475
1476 /*-------------------------------------------------------------------*
1477  *   ccw_check_return_code                                           *
1478  *                                                                   *
1479  *-------------------------------------------------------------------*/
1480
1481 static void
1482 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1483 {
1484 #ifdef FUNCTRACE
1485         printk(KERN_INFO "%s: %s() > enter  \n",
1486                 cdev->dev.bus_id,__func__);
1487 #endif
1488         CLAW_DBF_TEXT(4,trace,"ccwret");
1489 #ifdef DEBUGMSG
1490         printk(KERN_INFO "variable cdev =\n");
1491         dumpit((char *) cdev, sizeof(struct ccw_device));
1492         printk(KERN_INFO "variable return_code = %d\n",return_code);
1493 #endif
1494         if (return_code != 0) {
1495                 switch (return_code) {
1496                         case -EBUSY:
1497                                 printk(KERN_INFO "%s: Busy !\n",
1498                                         cdev->dev.bus_id);
1499                                 break;
1500                         case -ENODEV:
1501                                 printk(KERN_EMERG "%s: Missing device called "
1502                                         "for IO ENODEV\n", cdev->dev.bus_id);
1503                                 break;
1504                         case -EIO:
1505                                 printk(KERN_EMERG "%s: Status pending... EIO \n",
1506                                         cdev->dev.bus_id);
1507                                 break;
1508                         case -EINVAL:
1509                                 printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
1510                                         cdev->dev.bus_id);
1511                                 break;
1512                         default:
1513                                 printk(KERN_EMERG "%s: Unknown error in "
1514                                  "Do_IO %d\n",cdev->dev.bus_id, return_code);
1515                 }
1516         }
1517 #ifdef FUNCTRACE
1518         printk(KERN_INFO "%s: %s() > exit on line %d\n",
1519                 cdev->dev.bus_id,__func__,__LINE__);
1520 #endif
1521         CLAW_DBF_TEXT(4,trace,"ccwret");
1522 }    /*    end of ccw_check_return_code   */
1523
1524 /*-------------------------------------------------------------------*
1525 *       ccw_check_unit_check                                         *
1526 *--------------------------------------------------------------------*/
1527
1528 static void
1529 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1530 {
1531         struct net_device *dev = p_ch->ndev;
1532
1533 #ifdef FUNCTRACE
1534         printk(KERN_INFO "%s: %s() > enter\n",dev->name,__func__);
1535 #endif
1536 #ifdef DEBUGMSG
1537         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1538         dumpit((char *)dev, sizeof(struct net_device));
1539         printk(KERN_INFO "%s: variable sense =\n",dev->name);
1540         dumpit((char *)&sense, 2);
1541 #endif
1542         CLAW_DBF_TEXT(4,trace,"unitchek");
1543
1544         printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
1545                 dev->name, sense);
1546
1547         if (sense & 0x40) {
1548                 if (sense & 0x01) {
1549                         printk(KERN_WARNING "%s: Interface disconnect or "
1550                                 "Selective reset "
1551                                 "occurred (remote side)\n", dev->name);
1552                 }
1553                 else {
1554                         printk(KERN_WARNING "%s: System reset occured"
1555                                 " (remote side)\n", dev->name);
1556                 }
1557         }
1558         else if (sense & 0x20) {
1559                 if (sense & 0x04) {
1560                         printk(KERN_WARNING "%s: Data-streaming "
1561                                 "timeout)\n", dev->name);
1562                 }
1563                 else  {
1564                         printk(KERN_WARNING "%s: Data-transfer parity"
1565                                 " error\n", dev->name);
1566                 }
1567         }
1568         else if (sense & 0x10) {
1569                 if (sense & 0x20) {
1570                         printk(KERN_WARNING "%s: Hardware malfunction "
1571                                 "(remote side)\n", dev->name);
1572                 }
1573                 else {
1574                         printk(KERN_WARNING "%s: read-data parity error "
1575                                 "(remote side)\n", dev->name);
1576                 }
1577         }
1578
1579 #ifdef FUNCTRACE
1580         printk(KERN_INFO "%s: %s() exit on line %d\n",
1581                 dev->name,__func__,__LINE__);
1582 #endif
1583 }   /*    end of ccw_check_unit_check    */
1584
1585
1586
1587 /*-------------------------------------------------------------------*
1588 * Dump buffer format                                                 *
1589 *                                                                    *
1590 *--------------------------------------------------------------------*/
1591 #ifdef DEBUG
1592 static void
1593 dumpit(char* buf, int len)
1594 {
1595
1596         __u32      ct, sw, rm, dup;
1597         char       *ptr, *rptr;
1598         char       tbuf[82], tdup[82];
1599 #if (CONFIG_64BIT)
1600         char       addr[22];
1601 #else
1602         char       addr[12];
1603 #endif
1604         char       boff[12];
1605         char       bhex[82], duphex[82];
1606         char       basc[40];
1607
1608         sw  = 0;
1609         rptr =ptr=buf;
1610         rm  = 16;
1611         duphex[0]  = 0x00;
1612         dup = 0;
1613         for ( ct=0; ct < len; ct++, ptr++, rptr++ )  {
1614                 if (sw == 0) {
1615 #if (CONFIG_64BIT)
1616                         sprintf(addr, "%16.16lX",(unsigned long)rptr);
1617 #else
1618                         sprintf(addr, "%8.8X",(__u32)rptr);
1619 #endif
1620                         sprintf(boff, "%4.4X", (__u32)ct);
1621                         bhex[0] = '\0';
1622                         basc[0] = '\0';
1623                 }
1624                 if ((sw == 4) || (sw == 12)) {
1625                         strcat(bhex, " ");
1626                 }
1627                 if (sw == 8) {
1628                         strcat(bhex, "  ");
1629                 }
1630 #if (CONFIG_64BIT)
1631                 sprintf(tbuf,"%2.2lX", (unsigned long)*ptr);
1632 #else
1633                 sprintf(tbuf,"%2.2X", (__u32)*ptr);
1634 #endif
1635                 tbuf[2] = '\0';
1636                 strcat(bhex, tbuf);
1637                 if ((0!=isprint(*ptr)) && (*ptr >= 0x20)) {
1638                         basc[sw] = *ptr;
1639                 }
1640                 else {
1641                         basc[sw] = '.';
1642                 }
1643                 basc[sw+1] = '\0';
1644                 sw++;
1645                 rm--;
1646                 if (sw==16) {
1647                         if ((strcmp(duphex, bhex)) !=0) {
1648                                 if (dup !=0) {
1649                                         sprintf(tdup,"Duplicate as above to"
1650                                                 " %s", addr);
1651                                         printk( KERN_INFO "                 "
1652                                                 "   --- %s ---\n",tdup);
1653                                 }
1654                                 printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1655                                          addr, boff, bhex, basc);
1656                                 dup = 0;
1657                                 strcpy(duphex, bhex);
1658                         }
1659                         else {
1660                                 dup++;
1661                         }
1662                         sw = 0;
1663                         rm = 16;
1664                 }
1665         }  /* endfor */
1666
1667         if (sw != 0) {
1668                 for ( ; rm > 0; rm--, sw++ ) {
1669                         if ((sw==4) || (sw==12)) strcat(bhex, " ");
1670                         if (sw==8)               strcat(bhex, "  ");
1671                         strcat(bhex, "  ");
1672                         strcat(basc, " ");
1673                 }
1674                 if (dup !=0) {
1675                         sprintf(tdup,"Duplicate as above to %s", addr);
1676                         printk( KERN_INFO "                    --- %s ---\n",
1677                                 tdup);
1678                 }
1679                 printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1680                         addr, boff, bhex, basc);
1681         }
1682         else {
1683                 if (dup >=1) {
1684                         sprintf(tdup,"Duplicate as above to %s", addr);
1685                         printk( KERN_INFO "                    --- %s ---\n",
1686                                 tdup);
1687                 }
1688                 if (dup !=0) {
1689                         printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1690                                 addr, boff, bhex, basc);
1691                 }
1692         }
1693         return;
1694
1695 }   /*   end of dumpit  */
1696 #endif
1697
1698 /*-------------------------------------------------------------------*
1699 *               find_link                                            *
1700 *--------------------------------------------------------------------*/
1701 static int
1702 find_link(struct net_device *dev, char *host_name, char *ws_name )
1703 {
1704         struct claw_privbk *privptr;
1705         struct claw_env *p_env;
1706         int    rc=0;
1707
1708 #ifdef FUNCTRACE
1709         printk(KERN_INFO "%s:%s > enter  \n",dev->name,__func__);
1710 #endif
1711         CLAW_DBF_TEXT(2,setup,"findlink");
1712 #ifdef DEBUGMSG
1713         printk(KERN_INFO "%s: variable dev = \n",dev->name);
1714         dumpit((char *) dev, sizeof(struct net_device));
1715         printk(KERN_INFO "%s: variable host_name = %s\n",dev->name, host_name);
1716         printk(KERN_INFO "%s: variable ws_name = %s\n",dev->name, ws_name);
1717 #endif
1718         privptr=dev->priv;
1719         p_env=privptr->p_env;
1720         switch (p_env->packing)
1721         {
1722                 case  PACKING_ASK:
1723                         if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1724                             (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1725                              rc = EINVAL;
1726                         break;
1727                 case  DO_PACKED:
1728                 case  PACK_SEND:
1729                         if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1730                             (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1731                                 rc = EINVAL;
1732                         break;
1733                 default:
1734                         if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1735                             (memcmp(p_env->api_type , ws_name, 8)!=0))
1736                                 rc = EINVAL;
1737                         break;
1738         }
1739
1740 #ifdef FUNCTRACE
1741         printk(KERN_INFO "%s:%s Exit on line %d\n",
1742                 dev->name,__func__,__LINE__);
1743 #endif
1744         return 0;
1745 }    /*    end of find_link    */
1746
1747 /*-------------------------------------------------------------------*
1748  *   claw_hw_tx                                                      *
1749  *                                                                   *
1750  *                                                                   *
1751  *-------------------------------------------------------------------*/
1752
1753 static int
1754 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1755 {
1756         int                             rc=0;
1757         struct claw_privbk              *privptr;
1758         struct ccwbk           *p_this_ccw;
1759         struct ccwbk           *p_first_ccw;
1760         struct ccwbk           *p_last_ccw;
1761         __u32                           numBuffers;
1762         signed long                     len_of_data;
1763         unsigned long                   bytesInThisBuffer;
1764         unsigned char                   *pDataAddress;
1765         struct endccw                   *pEnd;
1766         struct ccw1                     tempCCW;
1767         struct chbk                     *p_ch;
1768         struct claw_env                 *p_env;
1769         int                             lock;
1770         struct clawph                   *pk_head;
1771         struct chbk                     *ch;
1772 #ifdef IOTRACE
1773         struct ccwbk                   *p_buf;
1774 #endif
1775 #ifdef FUNCTRACE
1776         printk(KERN_INFO "%s: %s() > enter\n",dev->name,__func__);
1777 #endif
1778         CLAW_DBF_TEXT(4,trace,"hw_tx");
1779 #ifdef DEBUGMSG
1780         printk(KERN_INFO "%s: variable dev skb =\n",dev->name);
1781         dumpit((char *) skb, sizeof(struct sk_buff));
1782         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1783         dumpit((char *) dev, sizeof(struct net_device));
1784         printk(KERN_INFO "%s: variable linkid = %ld\n",dev->name,linkid);
1785 #endif
1786         privptr = (struct claw_privbk *) (dev->priv);
1787         p_ch=(struct chbk *)&privptr->channel[WRITE];
1788         p_env =privptr->p_env;
1789 #ifdef IOTRACE
1790         printk(KERN_INFO "%s: %s() dump sk_buff  \n",dev->name,__func__);
1791         dumpit((char *)skb ,sizeof(struct sk_buff));
1792 #endif
1793         claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1794         /*  scan the write queue to free any completed write packets   */
1795         p_first_ccw=NULL;
1796         p_last_ccw=NULL;
1797         if ((p_env->packing >= PACK_SEND) &&
1798             (skb->cb[1] != 'P')) {
1799                 skb_push(skb,sizeof(struct clawph));
1800                 pk_head=(struct clawph *)skb->data;
1801                 pk_head->len=skb->len-sizeof(struct clawph);
1802                 if (pk_head->len%4)  {
1803                         pk_head->len+= 4-(pk_head->len%4);
1804                         skb_pad(skb,4-(pk_head->len%4));
1805                         skb_put(skb,4-(pk_head->len%4));
1806                 }
1807                 if (p_env->packing == DO_PACKED)
1808                         pk_head->link_num = linkid;
1809                 else
1810                         pk_head->link_num = 0;
1811                 pk_head->flag = 0x00;
1812                 skb_pad(skb,4);
1813                 skb->cb[1] = 'P';
1814         }
1815         if (linkid == 0) {
1816                 if (claw_check_busy(dev)) {
1817                         if (privptr->write_free_count!=0) {
1818                                 claw_clear_busy(dev);
1819                         }
1820                         else {
1821                                 claw_strt_out_IO(dev );
1822                                 claw_free_wrt_buf( dev );
1823                                 if (privptr->write_free_count==0) {
1824 #ifdef IOTRACE
1825                                         printk(KERN_INFO "%s: "
1826                                            "(claw_check_busy) no free write "
1827                                            "buffers\n", dev->name);
1828 #endif
1829                                         ch = &privptr->channel[WRITE];
1830                                         atomic_inc(&skb->users);
1831                                         skb_queue_tail(&ch->collect_queue, skb);
1832                                         goto Done;
1833                                 }
1834                                 else {
1835                                         claw_clear_busy(dev);
1836                                 }
1837                         }
1838                 }
1839                 /*  tx lock  */
1840                 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1841 #ifdef DEBUGMSG
1842                         printk(KERN_INFO "%s:  busy  (claw_test_and_setbit_"
1843                                 "busy)\n", dev->name);
1844 #endif
1845                         ch = &privptr->channel[WRITE];
1846                         atomic_inc(&skb->users);
1847                         skb_queue_tail(&ch->collect_queue, skb);
1848                         claw_strt_out_IO(dev );
1849                         rc=-EBUSY;
1850                         goto Done2;
1851                 }
1852         }
1853         /*      See how many write buffers are required to hold this data */
1854         numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
1855
1856         /*      If that number of buffers isn't available, give up for now */
1857         if (privptr->write_free_count < numBuffers ||
1858             privptr->p_write_free_chain == NULL ) {
1859
1860                 claw_setbit_busy(TB_NOBUFFER,dev);
1861
1862 #ifdef DEBUGMSG
1863                 printk(KERN_INFO "%s:  busy  (claw_setbit_busy"
1864                         "(TB_NOBUFFER))\n", dev->name);
1865                 printk(KERN_INFO "       free_count: %d, numBuffers : %d\n",
1866                         (int)privptr->write_free_count,(int) numBuffers );
1867 #endif
1868                 ch = &privptr->channel[WRITE];
1869                 atomic_inc(&skb->users);
1870                 skb_queue_tail(&ch->collect_queue, skb);
1871                 CLAW_DBF_TEXT(2,trace,"clawbusy");
1872                 goto Done2;
1873         }
1874         pDataAddress=skb->data;
1875         len_of_data=skb->len;
1876
1877         while (len_of_data > 0) {
1878 #ifdef DEBUGMSG
1879                 printk(KERN_INFO "%s: %s() length-of-data is %ld \n",
1880                         dev->name ,__func__,len_of_data);
1881                 dumpit((char *)pDataAddress ,64);
1882 #endif
1883                 p_this_ccw=privptr->p_write_free_chain;  /* get a block */
1884                 if (p_this_ccw == NULL) { /* lost the race */
1885                         ch = &privptr->channel[WRITE];
1886                         atomic_inc(&skb->users);
1887                         skb_queue_tail(&ch->collect_queue, skb);
1888                         goto Done2;
1889                 }
1890                 privptr->p_write_free_chain=p_this_ccw->next;
1891                 p_this_ccw->next=NULL;
1892                 --privptr->write_free_count; /* -1 */
1893                 bytesInThisBuffer=len_of_data;
1894                 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1895                 len_of_data-=bytesInThisBuffer;
1896                 pDataAddress+=(unsigned long)bytesInThisBuffer;
1897                 /*      setup write CCW         */
1898                 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1899                 if (len_of_data>0) {
1900                         p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1901                 }
1902                 p_this_ccw->write.count=bytesInThisBuffer;
1903                 /*      now add to end of this chain    */
1904                 if (p_first_ccw==NULL)    {
1905                         p_first_ccw=p_this_ccw;
1906                 }
1907                 if (p_last_ccw!=NULL) {
1908                         p_last_ccw->next=p_this_ccw;
1909                         /*      set up TIC ccws         */
1910                         p_last_ccw->w_TIC_1.cda=
1911                                 (__u32)__pa(&p_this_ccw->write);
1912                 }
1913                 p_last_ccw=p_this_ccw;      /* save new last block */
1914 #ifdef IOTRACE
1915                 printk(KERN_INFO "%s: %s() > CCW and Buffer %ld bytes long \n",
1916                         dev->name,__func__,bytesInThisBuffer);
1917                 dumpit((char *)p_this_ccw, sizeof(struct ccwbk));
1918                 dumpit((char *)p_this_ccw->p_buffer, 64);
1919 #endif
1920         }
1921
1922         /*      FirstCCW and LastCCW now contain a new set of write channel
1923         *       programs to append to the running channel program
1924         */
1925
1926         if (p_first_ccw!=NULL) {
1927                 /*      setup ending ccw sequence for this segment              */
1928                 pEnd=privptr->p_end_ccw;
1929                 if (pEnd->write1) {
1930                         pEnd->write1=0x00;   /* second end ccw is now active */
1931                         /*      set up Tic CCWs         */
1932                         p_last_ccw->w_TIC_1.cda=
1933                                 (__u32)__pa(&pEnd->write2_nop1);
1934                         pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1935                         pEnd->write2_nop2.flags    =
1936                                 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1937                         pEnd->write2_nop2.cda=0;
1938                         pEnd->write2_nop2.count=1;
1939                 }
1940                 else {  /*  end of if (pEnd->write1)*/
1941                         pEnd->write1=0x01;   /* first end ccw is now active */
1942                         /*      set up Tic CCWs         */
1943                         p_last_ccw->w_TIC_1.cda=
1944                                 (__u32)__pa(&pEnd->write1_nop1);
1945                         pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1946                         pEnd->write1_nop2.flags    =
1947                                 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1948                         pEnd->write1_nop2.cda=0;
1949                         pEnd->write1_nop2.count=1;
1950                 }  /* end if if (pEnd->write1) */
1951
1952
1953                 if (privptr->p_write_active_first==NULL ) {
1954                         privptr->p_write_active_first=p_first_ccw;
1955                         privptr->p_write_active_last=p_last_ccw;
1956                 }
1957                 else {
1958
1959                         /*      set up Tic CCWs         */
1960
1961                         tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1962                         tempCCW.count=0;
1963                         tempCCW.flags=0;
1964                         tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1965
1966                         if (pEnd->write1) {
1967
1968                  /*
1969                  * first set of ending CCW's is chained to the new write
1970                  * chain, so the second set is chained to the active chain
1971                  * Therefore modify the second set to point the new write chain.
1972                  * make sure we update the CCW atomically
1973                  * so channel does not fetch it when it's only half done
1974                  */
1975                                 memcpy( &pEnd->write2_nop2, &tempCCW ,
1976                                         sizeof(struct ccw1));
1977                                 privptr->p_write_active_last->w_TIC_1.cda=
1978                                         (__u32)__pa(&p_first_ccw->write);
1979                         }
1980                         else {
1981
1982                         /*make sure we update the CCW atomically
1983                          *so channel does not fetch it when it's only half done
1984                          */
1985                                 memcpy(&pEnd->write1_nop2, &tempCCW ,
1986                                         sizeof(struct ccw1));
1987                                 privptr->p_write_active_last->w_TIC_1.cda=
1988                                         (__u32)__pa(&p_first_ccw->write);
1989
1990                         } /* end if if (pEnd->write1) */
1991
1992                         privptr->p_write_active_last->next=p_first_ccw;
1993                         privptr->p_write_active_last=p_last_ccw;
1994                 }
1995
1996         } /* endif (p_first_ccw!=NULL)  */
1997
1998
1999 #ifdef IOTRACE
2000         printk(KERN_INFO "%s: %s() >  Dump Active CCW chain \n",
2001                 dev->name,__func__);
2002         p_buf=privptr->p_write_active_first;
2003         while (p_buf!=NULL) {
2004                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2005                 p_buf=p_buf->next;
2006         }
2007         p_buf=(struct ccwbk*)privptr->p_end_ccw;
2008         dumpit((char *)p_buf, sizeof(struct endccw));
2009 #endif
2010         dev_kfree_skb_any(skb);
2011         if (linkid==0) {
2012                 lock=LOCK_NO;
2013         }
2014         else  {
2015                 lock=LOCK_YES;
2016         }
2017         claw_strt_out_IO(dev );
2018         /*      if write free count is zero , set NOBUFFER       */
2019 #ifdef DEBUGMSG
2020         printk(KERN_INFO "%s: %s() > free_count is %d\n",
2021                 dev->name,__func__,
2022                 (int) privptr->write_free_count );
2023 #endif
2024         if (privptr->write_free_count==0) {
2025                 claw_setbit_busy(TB_NOBUFFER,dev);
2026         }
2027 Done2:
2028         claw_clearbit_busy(TB_TX,dev);
2029 Done:
2030 #ifdef FUNCTRACE
2031         printk(KERN_INFO "%s: %s() > exit on line %d, rc = %d \n",
2032                 dev->name,__func__,__LINE__, rc);
2033 #endif
2034         return(rc);
2035 }    /*    end of claw_hw_tx    */
2036
2037 /*-------------------------------------------------------------------*
2038 *                                                                    *
2039 *     init_ccw_bk                                                    *
2040 *                                                                    *
2041 *--------------------------------------------------------------------*/
2042
2043 static int
2044 init_ccw_bk(struct net_device *dev)
2045 {
2046
2047         __u32   ccw_blocks_required;
2048         __u32   ccw_blocks_perpage;
2049         __u32   ccw_pages_required;
2050         __u32   claw_reads_perpage=1;
2051         __u32   claw_read_pages;
2052         __u32   claw_writes_perpage=1;
2053         __u32   claw_write_pages;
2054         void    *p_buff=NULL;
2055         struct ccwbk*p_free_chain;
2056         struct ccwbk*p_buf;
2057         struct ccwbk*p_last_CCWB;
2058         struct ccwbk*p_first_CCWB;
2059         struct endccw *p_endccw=NULL;
2060         addr_t  real_address;
2061         struct claw_privbk *privptr=dev->priv;
2062         struct clawh *pClawH=NULL;
2063         addr_t   real_TIC_address;
2064         int i,j;
2065 #ifdef FUNCTRACE
2066         printk(KERN_INFO "%s: %s() enter  \n",dev->name,__func__);
2067 #endif
2068         CLAW_DBF_TEXT(4,trace,"init_ccw");
2069 #ifdef DEBUGMSG
2070         printk(KERN_INFO "%s: variable dev =\n",dev->name);
2071         dumpit((char *) dev, sizeof(struct net_device));
2072 #endif
2073
2074         /*  initialize  statistics field */
2075         privptr->active_link_ID=0;
2076         /*  initialize  ccwbk pointers  */
2077         privptr->p_write_free_chain=NULL;   /* pointer to free ccw chain*/
2078         privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
2079         privptr->p_write_active_last=NULL;  /* pointer to the last write ccw*/
2080         privptr->p_read_active_first=NULL;  /* pointer to the first read ccw*/
2081         privptr->p_read_active_last=NULL;   /* pointer to the last read ccw */
2082         privptr->p_end_ccw=NULL;            /* pointer to ending ccw        */
2083         privptr->p_claw_signal_blk=NULL;    /* pointer to signal block      */
2084         privptr->buffs_alloc = 0;
2085         memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
2086         memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
2087         /*  initialize  free write ccwbk counter  */
2088         privptr->write_free_count=0;  /* number of free bufs on write chain */
2089         p_last_CCWB = NULL;
2090         p_first_CCWB= NULL;
2091         /*
2092         *  We need 1 CCW block for each read buffer, 1 for each
2093         *  write buffer, plus 1 for ClawSignalBlock
2094         */
2095         ccw_blocks_required =
2096                 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
2097 #ifdef DEBUGMSG
2098         printk(KERN_INFO "%s: %s() "
2099                 "ccw_blocks_required=%d\n",
2100                 dev->name,__func__,
2101                 ccw_blocks_required);
2102         printk(KERN_INFO "%s: %s() "
2103                 "PAGE_SIZE=0x%x\n",
2104                 dev->name,__func__,
2105                 (unsigned int)PAGE_SIZE);
2106         printk(KERN_INFO "%s: %s() > "
2107                 "PAGE_MASK=0x%x\n",
2108                 dev->name,__func__,
2109                 (unsigned int)PAGE_MASK);
2110 #endif
2111         /*
2112         * compute number of CCW blocks that will fit in a page
2113         */
2114         ccw_blocks_perpage= PAGE_SIZE /  CCWBK_SIZE;
2115         ccw_pages_required=
2116                 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
2117
2118 #ifdef DEBUGMSG
2119         printk(KERN_INFO "%s: %s() > ccw_blocks_perpage=%d\n",
2120                 dev->name,__func__,
2121                 ccw_blocks_perpage);
2122         printk(KERN_INFO "%s: %s() > ccw_pages_required=%d\n",
2123                 dev->name,__func__,
2124                 ccw_pages_required);
2125 #endif
2126         /*
2127          *  read and write sizes are set by 2 constants in claw.h
2128          *  4k and 32k.  Unpacked values other than 4k are not going to
2129          * provide good performance. With packing buffers support 32k
2130          * buffers are used.
2131          */
2132         if (privptr->p_env->read_size < PAGE_SIZE) {
2133                 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
2134                 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
2135                                                 claw_reads_perpage);
2136          }
2137          else {       /* > or equal  */
2138                 privptr->p_buff_pages_perread =
2139                         DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
2140                 claw_read_pages = privptr->p_env->read_buffers *
2141                                         privptr->p_buff_pages_perread;
2142          }
2143         if (privptr->p_env->write_size < PAGE_SIZE) {
2144                 claw_writes_perpage =
2145                         PAGE_SIZE / privptr->p_env->write_size;
2146                 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
2147                                                 claw_writes_perpage);
2148
2149         }
2150         else {      /* >  or equal  */
2151                 privptr->p_buff_pages_perwrite =
2152                         DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
2153                 claw_write_pages = privptr->p_env->write_buffers *
2154                                         privptr->p_buff_pages_perwrite;
2155         }
2156 #ifdef DEBUGMSG
2157         if (privptr->p_env->read_size < PAGE_SIZE) {
2158             printk(KERN_INFO "%s: %s() reads_perpage=%d\n",
2159                 dev->name,__func__,
2160                 claw_reads_perpage);
2161         }
2162         else {
2163             printk(KERN_INFO "%s: %s() pages_perread=%d\n",
2164                 dev->name,__func__,
2165                 privptr->p_buff_pages_perread);
2166         }
2167         printk(KERN_INFO "%s: %s() read_pages=%d\n",
2168                 dev->name,__func__,
2169                 claw_read_pages);
2170         if (privptr->p_env->write_size < PAGE_SIZE) {
2171             printk(KERN_INFO "%s: %s() writes_perpage=%d\n",
2172                 dev->name,__func__,
2173                 claw_writes_perpage);
2174         }
2175         else {
2176             printk(KERN_INFO "%s: %s() pages_perwrite=%d\n",
2177                 dev->name,__func__,
2178                 privptr->p_buff_pages_perwrite);
2179         }
2180         printk(KERN_INFO "%s: %s() write_pages=%d\n",
2181                 dev->name,__func__,
2182                 claw_write_pages);
2183 #endif
2184
2185
2186         /*
2187         *               allocate ccw_pages_required
2188         */
2189         if (privptr->p_buff_ccw==NULL) {
2190                 privptr->p_buff_ccw=
2191                         (void *)__get_free_pages(__GFP_DMA,
2192                         (int)pages_to_order_of_mag(ccw_pages_required ));
2193                 if (privptr->p_buff_ccw==NULL) {
2194                         printk(KERN_INFO "%s: %s()  "
2195                                 "__get_free_pages for CCWs failed : "
2196                                 "pages is %d\n",
2197                                 dev->name,__func__,
2198                                 ccw_pages_required );
2199 #ifdef FUNCTRACE
2200                         printk(KERN_INFO "%s: %s() > "
2201                                 "exit on line %d, rc = ENOMEM\n",
2202                                 dev->name,__func__,
2203                                  __LINE__);
2204 #endif
2205                         return -ENOMEM;
2206                 }
2207                 privptr->p_buff_ccw_num=ccw_pages_required;
2208         }
2209         memset(privptr->p_buff_ccw, 0x00,
2210                 privptr->p_buff_ccw_num * PAGE_SIZE);
2211
2212         /*
2213         *               obtain ending ccw block address
2214         *
2215         */
2216         privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
2217         real_address  = (__u32)__pa(privptr->p_end_ccw);
2218         /*                              Initialize ending CCW block       */
2219 #ifdef DEBUGMSG
2220         printk(KERN_INFO "%s: %s() begin initialize ending CCW blocks\n",
2221                 dev->name,__func__);
2222 #endif
2223
2224         p_endccw=privptr->p_end_ccw;
2225         p_endccw->real=real_address;
2226         p_endccw->write1=0x00;
2227         p_endccw->read1=0x00;
2228
2229         /*      write1_nop1                                     */
2230         p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2231         p_endccw->write1_nop1.flags       = CCW_FLAG_SLI | CCW_FLAG_CC;
2232         p_endccw->write1_nop1.count       = 1;
2233         p_endccw->write1_nop1.cda         = 0;
2234
2235         /*      write1_nop2                                     */
2236         p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2237         p_endccw->write1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2238         p_endccw->write1_nop2.count      = 1;
2239         p_endccw->write1_nop2.cda        = 0;
2240
2241         /*      write2_nop1                                     */
2242         p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2243         p_endccw->write2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2244         p_endccw->write2_nop1.count        = 1;
2245         p_endccw->write2_nop1.cda          = 0;
2246
2247         /*      write2_nop2                                     */
2248         p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2249         p_endccw->write2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2250         p_endccw->write2_nop2.count        = 1;
2251         p_endccw->write2_nop2.cda          = 0;
2252
2253         /*      read1_nop1                                      */
2254         p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2255         p_endccw->read1_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2256         p_endccw->read1_nop1.count        = 1;
2257         p_endccw->read1_nop1.cda          = 0;
2258
2259         /*      read1_nop2                                      */
2260         p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2261         p_endccw->read1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2262         p_endccw->read1_nop2.count        = 1;
2263         p_endccw->read1_nop2.cda          = 0;
2264
2265         /*      read2_nop1                                      */
2266         p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2267         p_endccw->read2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2268         p_endccw->read2_nop1.count        = 1;
2269         p_endccw->read2_nop1.cda          = 0;
2270
2271         /*      read2_nop2                                      */
2272         p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2273         p_endccw->read2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2274         p_endccw->read2_nop2.count        = 1;
2275         p_endccw->read2_nop2.cda          = 0;
2276
2277 #ifdef IOTRACE
2278         printk(KERN_INFO "%s: %s() dump claw ending CCW BK \n",
2279                 dev->name,__func__);
2280         dumpit((char *)p_endccw, sizeof(struct endccw));
2281 #endif
2282
2283         /*
2284         *                               Build a chain of CCWs
2285         *
2286         */
2287
2288 #ifdef DEBUGMSG
2289         printk(KERN_INFO "%s: %s()  Begin build a chain of CCW buffer \n",
2290                 dev->name,__func__);
2291 #endif
2292         p_buff=privptr->p_buff_ccw;
2293
2294         p_free_chain=NULL;
2295         for (i=0 ; i < ccw_pages_required; i++ ) {
2296                 real_address  = (__u32)__pa(p_buff);
2297                 p_buf=p_buff;
2298                 for (j=0 ; j < ccw_blocks_perpage ; j++) {
2299                         p_buf->next  = p_free_chain;
2300                         p_free_chain = p_buf;
2301                         p_buf->real=(__u32)__pa(p_buf);
2302                         ++p_buf;
2303                 }
2304                 p_buff+=PAGE_SIZE;
2305         }
2306 #ifdef DEBUGMSG
2307         printk(KERN_INFO "%s: %s() "
2308                 "End build a chain of CCW buffer \n",
2309                         dev->name,__func__);
2310         p_buf=p_free_chain;
2311         while (p_buf!=NULL) {
2312                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2313                 p_buf=p_buf->next;
2314         }
2315 #endif
2316
2317         /*
2318         *                               Initialize ClawSignalBlock
2319         *
2320         */
2321 #ifdef DEBUGMSG
2322         printk(KERN_INFO "%s: %s() "
2323                 "Begin initialize ClawSignalBlock \n",
2324                 dev->name,__func__);
2325 #endif
2326         if (privptr->p_claw_signal_blk==NULL) {
2327                 privptr->p_claw_signal_blk=p_free_chain;
2328                 p_free_chain=p_free_chain->next;
2329                 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
2330                 pClawH->length=0xffff;
2331                 pClawH->opcode=0xff;
2332                 pClawH->flag=CLAW_BUSY;
2333         }
2334 #ifdef DEBUGMSG
2335         printk(KERN_INFO "%s: %s() >  End initialize "
2336                 "ClawSignalBlock\n",
2337                 dev->name,__func__);
2338         dumpit((char *)privptr->p_claw_signal_blk, sizeof(struct ccwbk));
2339 #endif
2340
2341         /*
2342         *               allocate write_pages_required and add to free chain
2343         */
2344         if (privptr->p_buff_write==NULL) {
2345             if (privptr->p_env->write_size < PAGE_SIZE) {
2346                 privptr->p_buff_write=
2347                         (void *)__get_free_pages(__GFP_DMA,
2348                         (int)pages_to_order_of_mag(claw_write_pages ));
2349                 if (privptr->p_buff_write==NULL) {
2350                         printk(KERN_INFO "%s: %s() __get_free_pages for write"
2351                                 " bufs failed : get is for %d pages\n",
2352                                 dev->name,__func__,claw_write_pages );
2353                         free_pages((unsigned long)privptr->p_buff_ccw,
2354                            (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
2355                         privptr->p_buff_ccw=NULL;
2356 #ifdef FUNCTRACE
2357                         printk(KERN_INFO "%s: %s() > exit on line %d,"
2358                                 "rc = ENOMEM\n",
2359                                 dev->name,__func__,__LINE__);
2360 #endif
2361                         return -ENOMEM;
2362                 }
2363                 /*
2364                 *                               Build CLAW write free chain
2365                 *
2366                 */
2367
2368                 memset(privptr->p_buff_write, 0x00,
2369                         ccw_pages_required * PAGE_SIZE);
2370 #ifdef DEBUGMSG
2371                 printk(KERN_INFO "%s: %s() Begin build claw write free "
2372                         "chain \n",dev->name,__func__);
2373 #endif
2374                 privptr->p_write_free_chain=NULL;
2375
2376                 p_buff=privptr->p_buff_write;
2377
2378                 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
2379                         p_buf        = p_free_chain;      /*  get a CCW */
2380                         p_free_chain = p_buf->next;
2381                         p_buf->next  =privptr->p_write_free_chain;
2382                         privptr->p_write_free_chain = p_buf;
2383                         p_buf-> p_buffer        = (struct clawbuf *)p_buff;
2384                         p_buf-> write.cda       = (__u32)__pa(p_buff);
2385                         p_buf-> write.flags     = CCW_FLAG_SLI | CCW_FLAG_CC;
2386                         p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2387                         p_buf-> w_read_FF.flags   = CCW_FLAG_SLI | CCW_FLAG_CC;
2388                         p_buf-> w_read_FF.count   = 1;
2389                         p_buf-> w_read_FF.cda     =
2390                                 (__u32)__pa(&p_buf-> header.flag);
2391                         p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2392                         p_buf-> w_TIC_1.flags      = 0;
2393                         p_buf-> w_TIC_1.count      = 0;
2394
2395                         if (((unsigned long)p_buff+privptr->p_env->write_size) >=
2396                            ((unsigned long)(p_buff+2*
2397                                 (privptr->p_env->write_size) -1) & PAGE_MASK)) {
2398                         p_buff= p_buff+privptr->p_env->write_size;
2399                         }
2400                 }
2401            }
2402            else      /*  Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
2403            {
2404                privptr->p_write_free_chain=NULL;
2405                for (i = 0; i< privptr->p_env->write_buffers ; i++) {
2406                    p_buff=(void *)__get_free_pages(__GFP_DMA,
2407                         (int)pages_to_order_of_mag(
2408                         privptr->p_buff_pages_perwrite) );
2409 #ifdef IOTRACE
2410                    printk(KERN_INFO "%s:%s __get_free_pages "
2411                     "for writes buf: get for %d pages\n",
2412                     dev->name,__func__,
2413                     privptr->p_buff_pages_perwrite);
2414 #endif
2415                    if (p_buff==NULL) {
2416                         printk(KERN_INFO "%s:%s __get_free_pages "
2417                                 "for writes buf failed : get is for %d pages\n",
2418                                 dev->name,
2419                                 __func__,
2420                                 privptr->p_buff_pages_perwrite );
2421                         free_pages((unsigned long)privptr->p_buff_ccw,
2422                               (int)pages_to_order_of_mag(
2423                                         privptr->p_buff_ccw_num));
2424                         privptr->p_buff_ccw=NULL;
2425                         p_buf=privptr->p_buff_write;
2426                         while (p_buf!=NULL) {
2427                                 free_pages((unsigned long)
2428                                         p_buf->p_buffer,
2429                                         (int)pages_to_order_of_mag(
2430                                         privptr->p_buff_pages_perwrite));
2431                                 p_buf=p_buf->next;
2432                         }
2433 #ifdef FUNCTRACE
2434                         printk(KERN_INFO "%s: %s exit on line %d, rc = ENOMEM\n",
2435                         dev->name,
2436                         __func__,
2437                         __LINE__);
2438 #endif
2439                         return -ENOMEM;
2440                    }  /* Error on get_pages   */
2441                    memset(p_buff, 0x00, privptr->p_env->write_size );
2442                    p_buf         = p_free_chain;
2443                    p_free_chain  = p_buf->next;
2444                    p_buf->next   = privptr->p_write_free_chain;
2445                    privptr->p_write_free_chain = p_buf;
2446                    privptr->p_buff_write = p_buf;
2447                    p_buf->p_buffer=(struct clawbuf *)p_buff;
2448                    p_buf-> write.cda     = (__u32)__pa(p_buff);
2449                    p_buf-> write.flags   = CCW_FLAG_SLI | CCW_FLAG_CC;
2450                    p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2451                    p_buf-> w_read_FF.flags    = CCW_FLAG_SLI | CCW_FLAG_CC;
2452                    p_buf-> w_read_FF.count    = 1;
2453                    p_buf-> w_read_FF.cda      =
2454                         (__u32)__pa(&p_buf-> header.flag);
2455                    p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2456                    p_buf-> w_TIC_1.flags   = 0;
2457                    p_buf-> w_TIC_1.count   = 0;
2458                }  /* for all write_buffers   */
2459
2460            }    /* else buffers are PAGE_SIZE or bigger */
2461
2462         }
2463         privptr->p_buff_write_num=claw_write_pages;
2464         privptr->write_free_count=privptr->p_env->write_buffers;
2465
2466
2467 #ifdef DEBUGMSG
2468         printk(KERN_INFO "%s:%s  End build claw write free chain \n",
2469         dev->name,__func__);
2470         p_buf=privptr->p_write_free_chain;
2471         while (p_buf!=NULL) {
2472                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2473                 p_buf=p_buf->next;
2474         }
2475 #endif
2476         /*
2477         *               allocate read_pages_required and chain to free chain
2478         */
2479         if (privptr->p_buff_read==NULL) {
2480             if (privptr->p_env->read_size < PAGE_SIZE)  {
2481                 privptr->p_buff_read=
2482                         (void *)__get_free_pages(__GFP_DMA,
2483                         (int)pages_to_order_of_mag(claw_read_pages) );
2484                 if (privptr->p_buff_read==NULL) {
2485                         printk(KERN_INFO "%s: %s() "
2486                                 "__get_free_pages for read buf failed : "
2487                                 "get is for %d pages\n",
2488                                 dev->name,__func__,claw_read_pages );
2489                         free_pages((unsigned long)privptr->p_buff_ccw,
2490                                 (int)pages_to_order_of_mag(
2491                                         privptr->p_buff_ccw_num));
2492                         /* free the write pages size is < page size  */
2493                         free_pages((unsigned long)privptr->p_buff_write,
2494                                 (int)pages_to_order_of_mag(
2495                                 privptr->p_buff_write_num));
2496                         privptr->p_buff_ccw=NULL;
2497                         privptr->p_buff_write=NULL;
2498 #ifdef FUNCTRACE
2499                         printk(KERN_INFO "%s: %s() > exit on line %d, rc ="
2500                                 " ENOMEM\n",dev->name,__func__,__LINE__);
2501 #endif
2502                         return -ENOMEM;
2503                 }
2504                 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
2505                 privptr->p_buff_read_num=claw_read_pages;
2506                 /*
2507                 *                               Build CLAW read free chain
2508                 *
2509                 */
2510 #ifdef DEBUGMSG
2511                 printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
2512                         dev->name,__func__);
2513 #endif
2514                 p_buff=privptr->p_buff_read;
2515                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
2516                         p_buf        = p_free_chain;
2517                         p_free_chain = p_buf->next;
2518
2519                         if (p_last_CCWB==NULL) {
2520                                 p_buf->next=NULL;
2521                                 real_TIC_address=0;
2522                                 p_last_CCWB=p_buf;
2523                         }
2524                         else {
2525                                 p_buf->next=p_first_CCWB;
2526                                 real_TIC_address=
2527                                 (__u32)__pa(&p_first_CCWB -> read );
2528                         }
2529
2530                         p_first_CCWB=p_buf;
2531
2532                         p_buf->p_buffer=(struct clawbuf *)p_buff;
2533                         /*  initialize read command */
2534                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
2535                         p_buf-> read.cda = (__u32)__pa(p_buff);
2536                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2537                         p_buf-> read.count       = privptr->p_env->read_size;
2538
2539                         /*  initialize read_h command */
2540                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
2541                         p_buf-> read_h.cda =
2542                                 (__u32)__pa(&(p_buf->header));
2543                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2544                         p_buf-> read_h.count      = sizeof(struct clawh);
2545
2546                         /*  initialize Signal command */
2547                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
2548                         p_buf-> signal.cda =
2549                                 (__u32)__pa(&(pClawH->flag));
2550                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2551                         p_buf-> signal.count     = 1;
2552
2553                         /*  initialize r_TIC_1 command */
2554                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2555                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
2556                         p_buf-> r_TIC_1.flags = 0;
2557                         p_buf-> r_TIC_1.count      = 0;
2558
2559                         /*  initialize r_read_FF command */
2560                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2561                         p_buf-> r_read_FF.cda =
2562                                 (__u32)__pa(&(pClawH->flag));
2563                         p_buf-> r_read_FF.flags =
2564                                 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2565                         p_buf-> r_read_FF.count    = 1;
2566
2567                         /*    initialize r_TIC_2          */
2568                         memcpy(&p_buf->r_TIC_2,
2569                                 &p_buf->r_TIC_1, sizeof(struct ccw1));
2570
2571                         /*     initialize Header     */
2572                         p_buf->header.length=0xffff;
2573                         p_buf->header.opcode=0xff;
2574                         p_buf->header.flag=CLAW_PENDING;
2575
2576                         if (((unsigned long)p_buff+privptr->p_env->read_size) >=
2577                                 ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
2578                                  & PAGE_MASK) ) {
2579                                 p_buff= p_buff+privptr->p_env->read_size;
2580                         }
2581                         else {
2582                                 p_buff=
2583                                 (void *)((unsigned long)
2584                                         (p_buff+2*(privptr->p_env->read_size) -1)
2585                                          & PAGE_MASK) ;
2586                         }
2587                 }   /* for read_buffers   */
2588           }         /* read_size < PAGE_SIZE  */
2589           else {  /* read Size >= PAGE_SIZE  */
2590
2591 #ifdef DEBUGMSG
2592         printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
2593                 dev->name,__func__);
2594 #endif
2595                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
2596                         p_buff = (void *)__get_free_pages(__GFP_DMA,
2597                                 (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
2598                         if (p_buff==NULL) {
2599                                 printk(KERN_INFO "%s: %s() __get_free_pages for read "
2600                                         "buf failed : get is for %d pages\n",
2601                                         dev->name,__func__,
2602                                         privptr->p_buff_pages_perread );
2603                                 free_pages((unsigned long)privptr->p_buff_ccw,
2604                                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
2605                                 /* free the write pages  */
2606                                 p_buf=privptr->p_buff_write;
2607                                 while (p_buf!=NULL) {
2608                                         free_pages((unsigned long)p_buf->p_buffer,
2609                                                 (int)pages_to_order_of_mag(
2610                                                 privptr->p_buff_pages_perwrite ));
2611                                         p_buf=p_buf->next;
2612                                 }
2613                                 /* free any read pages already alloc  */
2614                                 p_buf=privptr->p_buff_read;
2615                                 while (p_buf!=NULL) {
2616                                         free_pages((unsigned long)p_buf->p_buffer,
2617                                                 (int)pages_to_order_of_mag(
2618                                                 privptr->p_buff_pages_perread ));
2619                                         p_buf=p_buf->next;
2620                                 }
2621                                 privptr->p_buff_ccw=NULL;
2622                                 privptr->p_buff_write=NULL;
2623 #ifdef FUNCTRACE
2624                                 printk(KERN_INFO "%s: %s() exit on line %d, rc = ENOMEM\n",
2625                                         dev->name,__func__,
2626                                         __LINE__);
2627 #endif
2628                                 return -ENOMEM;
2629                         }
2630                         memset(p_buff, 0x00, privptr->p_env->read_size);
2631                         p_buf        = p_free_chain;
2632                         privptr->p_buff_read = p_buf;
2633                         p_free_chain = p_buf->next;
2634
2635                         if (p_last_CCWB==NULL) {
2636                                 p_buf->next=NULL;
2637                                 real_TIC_address=0;
2638                                 p_last_CCWB=p_buf;
2639                         }
2640                         else {
2641                                 p_buf->next=p_first_CCWB;
2642                                 real_TIC_address=
2643                                         (addr_t)__pa(
2644                                                 &p_first_CCWB -> read );
2645                         }
2646
2647                         p_first_CCWB=p_buf;
2648                                 /* save buff address */
2649                         p_buf->p_buffer=(struct clawbuf *)p_buff;
2650                         /*  initialize read command */
2651                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
2652                         p_buf-> read.cda = (__u32)__pa(p_buff);
2653                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2654                         p_buf-> read.count       = privptr->p_env->read_size;
2655
2656                         /*  initialize read_h command */
2657                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
2658                         p_buf-> read_h.cda =
2659                                 (__u32)__pa(&(p_buf->header));
2660                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2661                         p_buf-> read_h.count      = sizeof(struct clawh);
2662
2663                         /*  initialize Signal command */
2664                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
2665                         p_buf-> signal.cda =
2666                                 (__u32)__pa(&(pClawH->flag));
2667                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2668                         p_buf-> signal.count     = 1;
2669
2670                         /*  initialize r_TIC_1 command */
2671                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2672                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
2673                         p_buf-> r_TIC_1.flags = 0;
2674                         p_buf-> r_TIC_1.count      = 0;
2675
2676                         /*  initialize r_read_FF command */
2677                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2678                         p_buf-> r_read_FF.cda =
2679                                 (__u32)__pa(&(pClawH->flag));
2680                         p_buf-> r_read_FF.flags =
2681                                 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2682                         p_buf-> r_read_FF.count    = 1;
2683
2684                         /*    initialize r_TIC_2          */
2685                         memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
2686                                 sizeof(struct ccw1));
2687
2688                         /*     initialize Header     */
2689                         p_buf->header.length=0xffff;
2690                         p_buf->header.opcode=0xff;
2691                         p_buf->header.flag=CLAW_PENDING;
2692
2693                 }    /* For read_buffers   */
2694           }     /*  read_size >= PAGE_SIZE   */
2695         }       /*  pBuffread = NULL */
2696 #ifdef DEBUGMSG
2697         printk(KERN_INFO "%s: %s() >  End build claw read free chain \n",
2698                 dev->name,__func__);
2699         p_buf=p_first_CCWB;
2700         while (p_buf!=NULL) {
2701                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2702                 p_buf=p_buf->next;
2703         }
2704
2705 #endif
2706         add_claw_reads( dev  ,p_first_CCWB , p_last_CCWB);
2707         privptr->buffs_alloc = 1;
2708 #ifdef FUNCTRACE
2709         printk(KERN_INFO "%s: %s() exit on line %d\n",
2710                 dev->name,__func__,__LINE__);
2711 #endif
2712         return 0;
2713 }    /*    end of init_ccw_bk */
2714
2715 /*-------------------------------------------------------------------*
2716 *                                                                    *
2717 *       probe_error                                                  *
2718 *                                                                    *
2719 *--------------------------------------------------------------------*/
2720
2721 static void
2722 probe_error( struct ccwgroup_device *cgdev)
2723 {
2724   struct claw_privbk *privptr;
2725 #ifdef FUNCTRACE
2726         printk(KERN_INFO "%s enter  \n",__func__);
2727 #endif
2728         CLAW_DBF_TEXT(4,trace,"proberr");
2729 #ifdef DEBUGMSG
2730         printk(KERN_INFO "%s variable cgdev =\n",__func__);
2731         dumpit((char *) cgdev, sizeof(struct ccwgroup_device));
2732 #endif
2733         privptr=(struct claw_privbk *)cgdev->dev.driver_data;
2734         if (privptr!=NULL) {
2735                 kfree(privptr->p_env);
2736                 privptr->p_env=NULL;
2737                 kfree(privptr->p_mtc_envelope);
2738                 privptr->p_mtc_envelope=NULL;
2739                 kfree(privptr);
2740                 privptr=NULL;
2741         }
2742 #ifdef FUNCTRACE
2743         printk(KERN_INFO "%s > exit on line %d\n",
2744                  __func__,__LINE__);
2745 #endif
2746
2747         return;
2748 }    /*    probe_error    */
2749
2750
2751
2752 /*-------------------------------------------------------------------*
2753 *    claw_process_control                                            *
2754 *                                                                    *
2755 *                                                                    *
2756 *--------------------------------------------------------------------*/
2757
2758 static int
2759 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2760 {
2761
2762         struct clawbuf *p_buf;
2763         struct clawctl  ctlbk;
2764         struct clawctl *p_ctlbk;
2765         char    temp_host_name[8];
2766         char    temp_ws_name[8];
2767         struct claw_privbk *privptr;
2768         struct claw_env *p_env;
2769         struct sysval *p_sysval;
2770         struct conncmd *p_connect=NULL;
2771         int rc;
2772         struct chbk *p_ch = NULL;
2773 #ifdef FUNCTRACE
2774         printk(KERN_INFO "%s: %s() > enter  \n",
2775                 dev->name,__func__);
2776 #endif
2777         CLAW_DBF_TEXT(2,setup,"clw_cntl");
2778 #ifdef DEBUGMSG
2779         printk(KERN_INFO "%s: variable dev =\n",dev->name);
2780         dumpit((char *) dev, sizeof(struct net_device));
2781         printk(KERN_INFO "%s: variable p_ccw =\n",dev->name);
2782         dumpit((char *) p_ccw, sizeof(struct ccwbk *));
2783 #endif
2784         udelay(1000);  /* Wait a ms for the control packets to
2785                         *catch up to each other */
2786         privptr=dev->priv;
2787         p_env=privptr->p_env;
2788         memcpy( &temp_host_name, p_env->host_name, 8);
2789         memcpy( &temp_ws_name, p_env->adapter_name , 8);
2790         printk(KERN_INFO "%s: CLAW device %.8s: "
2791                 "Received Control Packet\n",
2792                 dev->name, temp_ws_name);
2793         if (privptr->release_pend==1) {
2794 #ifdef FUNCTRACE
2795                 printk(KERN_INFO "%s: %s() > "
2796                         "exit on line %d, rc=0\n",
2797                         dev->name,__func__,__LINE__);
2798 #endif
2799                 return 0;
2800         }
2801         p_buf=p_ccw->p_buffer;
2802         p_ctlbk=&ctlbk;
2803         if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2804                 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2805         } else {
2806                 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2807         }
2808 #ifdef IOTRACE
2809         printk(KERN_INFO "%s: dump claw control data inbound\n",dev->name);
2810         dumpit((char *)p_ctlbk, sizeof(struct clawctl));
2811 #endif
2812         switch (p_ctlbk->command)
2813         {
2814                 case SYSTEM_VALIDATE_REQUEST:
2815                         if (p_ctlbk->version!=CLAW_VERSION_ID) {
2816                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2817                                         CLAW_RC_WRONG_VERSION );
2818                                 printk("%s: %d is wrong version id. "
2819                                         "Expected %d\n",
2820                                         dev->name, p_ctlbk->version,
2821                                         CLAW_VERSION_ID);
2822                         }
2823                         p_sysval=(struct sysval *)&(p_ctlbk->data);
2824                         printk( "%s: Recv Sys Validate Request: "
2825                                 "Vers=%d,link_id=%d,Corr=%d,WS name=%."
2826                                 "8s,Host name=%.8s\n",
2827                                 dev->name, p_ctlbk->version,
2828                                 p_ctlbk->linkid,
2829                                 p_ctlbk->correlator,
2830                                 p_sysval->WS_name,
2831                                 p_sysval->host_name);
2832                         if (0!=memcmp(temp_host_name,p_sysval->host_name,8)) {
2833                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2834                                         CLAW_RC_NAME_MISMATCH );
2835                                 CLAW_DBF_TEXT(2,setup,"HSTBAD");
2836                                 CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->host_name);
2837                                 CLAW_DBF_TEXT_(2,setup,"%s",temp_host_name);
2838                                 printk(KERN_INFO "%s:  Host name mismatch\n",
2839                                         dev->name);
2840                                 printk(KERN_INFO "%s: Received :%s: "
2841                                         "expected :%s: \n",
2842                                         dev->name,
2843                                         p_sysval->host_name,
2844                                         temp_host_name);
2845                         }
2846                         if (0!=memcmp(temp_ws_name,p_sysval->WS_name,8)) {
2847                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2848                                         CLAW_RC_NAME_MISMATCH );
2849                                 CLAW_DBF_TEXT(2,setup,"WSNBAD");
2850                                 CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->WS_name);
2851                                 CLAW_DBF_TEXT_(2,setup,"%s",temp_ws_name);
2852                                 printk(KERN_INFO "%s: WS name mismatch\n",
2853                                         dev->name);
2854                                  printk(KERN_INFO "%s: Received :%s: "
2855                                         "expected :%s: \n",
2856                                         dev->name,
2857                                         p_sysval->WS_name,
2858                                         temp_ws_name);
2859                         }
2860                         if (( p_sysval->write_frame_size < p_env->write_size) &&
2861                            ( p_env->packing == 0)) {
2862                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2863                                         CLAW_RC_HOST_RCV_TOO_SMALL );
2864                                 printk(KERN_INFO "%s: host write size is too "
2865                                         "small\n", dev->name);
2866                                 CLAW_DBF_TEXT(2,setup,"wrtszbad");
2867                         }
2868                         if (( p_sysval->read_frame_size < p_env->read_size) &&
2869                            ( p_env->packing == 0)) {
2870                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2871                                         CLAW_RC_HOST_RCV_TOO_SMALL );
2872                                 printk(KERN_INFO "%s: host read size is too "
2873                                         "small\n", dev->name);
2874                                 CLAW_DBF_TEXT(2,setup,"rdsizbad");
2875                         }
2876                         claw_snd_sys_validate_rsp(dev, p_ctlbk, 0 );
2877                         printk("%s: CLAW device %.8s: System validate"
2878                                 " completed.\n",dev->name, temp_ws_name);
2879                         printk("%s: sys Validate Rsize:%d Wsize:%d\n",dev->name,
2880                                 p_sysval->read_frame_size,p_sysval->write_frame_size);
2881                         privptr->system_validate_comp=1;
2882                         if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
2883                                 p_env->packing = PACKING_ASK;
2884                         }
2885                         claw_strt_conn_req(dev);
2886                         break;
2887
2888                 case SYSTEM_VALIDATE_RESPONSE:
2889                         p_sysval=(struct sysval *)&(p_ctlbk->data);
2890                         printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
2891                                 "WS name=%.8s,Host name=%.8s\n",
2892                                 dev->name,
2893                                 p_ctlbk->version,
2894                                 p_ctlbk->correlator,
2895                                 p_ctlbk->rc,
2896                                 p_sysval->WS_name,
2897                                 p_sysval->host_name);
2898                         switch (p_ctlbk->rc)
2899                         {
2900                                 case 0:
2901                                         printk(KERN_INFO "%s: CLAW device "
2902                                                 "%.8s: System validate "
2903                                                 "completed.\n",
2904                                                 dev->name, temp_ws_name);
2905                                         if (privptr->system_validate_comp == 0)
2906                                                 claw_strt_conn_req(dev);
2907                                         privptr->system_validate_comp=1;
2908                                         break;
2909                                 case CLAW_RC_NAME_MISMATCH:
2910                                         printk(KERN_INFO "%s: Sys Validate "
2911                                                 "Resp : Host, WS name is "
2912                                                 "mismatch\n",
2913                                                 dev->name);
2914                                         break;
2915                                 case CLAW_RC_WRONG_VERSION:
2916                                         printk(KERN_INFO "%s: Sys Validate "
2917                                                 "Resp : Wrong version\n",
2918                                                 dev->name);
2919                                         break;
2920                                 case CLAW_RC_HOST_RCV_TOO_SMALL:
2921                                         printk(KERN_INFO "%s: Sys Validate "
2922                                                 "Resp : bad frame size\n",
2923                                                 dev->name);
2924                                         break;
2925                                 default:
2926                                         printk(KERN_INFO "%s: Sys Validate "
2927                                                 "error code=%d \n",
2928                                                  dev->name, p_ctlbk->rc );
2929                                         break;
2930                         }
2931                         break;
2932
2933                 case CONNECTION_REQUEST:
2934                         p_connect=(struct conncmd *)&(p_ctlbk->data);
2935                         printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2936                                 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2937                                 dev->name,
2938                                 p_ctlbk->version,
2939                                 p_ctlbk->linkid,
2940                                 p_ctlbk->correlator,
2941                                 p_connect->host_name,
2942                                 p_connect->WS_name);
2943                         if (privptr->active_link_ID!=0 ) {
2944                                 claw_snd_disc(dev, p_ctlbk);
2945                                 printk(KERN_INFO "%s: Conn Req error : "
2946                                         "already logical link is active \n",
2947                                         dev->name);
2948                         }
2949                         if (p_ctlbk->linkid!=1 ) {
2950                                 claw_snd_disc(dev, p_ctlbk);
2951                                 printk(KERN_INFO "%s: Conn Req error : "
2952                                         "req logical link id is not 1\n",
2953                                         dev->name);
2954                         }
2955                         rc=find_link(dev,
2956                                 p_connect->host_name, p_connect->WS_name);
2957                         if (rc!=0) {
2958                                 claw_snd_disc(dev, p_ctlbk);
2959                                 printk(KERN_INFO "%s: Conn Req error : "
2960                                         "req appl name does not match\n",
2961                                          dev->name);
2962                         }
2963                         claw_send_control(dev,
2964                                 CONNECTION_CONFIRM, p_ctlbk->linkid,
2965                                 p_ctlbk->correlator,
2966                                 0, p_connect->host_name,
2967                                 p_connect->WS_name);
2968                         if (p_env->packing == PACKING_ASK) {
2969                                 printk("%s: Now Pack ask\n",dev->name);
2970                                 p_env->packing = PACK_SEND;
2971                                 claw_snd_conn_req(dev,0);
2972                         }
2973                         printk(KERN_INFO "%s: CLAW device %.8s: Connection "
2974                                 "completed link_id=%d.\n",
2975                                 dev->name, temp_ws_name,
2976                                 p_ctlbk->linkid);
2977                         privptr->active_link_ID=p_ctlbk->linkid;
2978                         p_ch=&privptr->channel[WRITE];
2979                         wake_up(&p_ch->wait);  /* wake up claw_open ( WRITE) */
2980                         break;
2981                 case CONNECTION_RESPONSE:
2982                         p_connect=(struct conncmd *)&(p_ctlbk->data);
2983                         printk(KERN_INFO "%s: Revc Conn Resp: Vers=%d,link_id=%d,"
2984                                 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2985                                 dev->name,
2986                                 p_ctlbk->version,
2987                                 p_ctlbk->linkid,
2988                                 p_ctlbk->correlator,
2989                                 p_ctlbk->rc,
2990                                 p_connect->host_name,
2991                                 p_connect->WS_name);
2992
2993                         if (p_ctlbk->rc !=0 ) {
2994                                 printk(KERN_INFO "%s: Conn Resp error: rc=%d \n",
2995                                         dev->name, p_ctlbk->rc);
2996                                 return 1;
2997                         }
2998                         rc=find_link(dev,
2999                                 p_connect->host_name, p_connect->WS_name);
3000                         if (rc!=0) {
3001                                 claw_snd_disc(dev, p_ctlbk);
3002                                 printk(KERN_INFO "%s: Conn Resp error: "
3003                                         "req appl name does not match\n",
3004                                          dev->name);
3005                         }
3006                         /* should be until CONNECTION_CONFIRM */
3007                         privptr->active_link_ID =  - (p_ctlbk->linkid);
3008                         break;
3009                 case CONNECTION_CONFIRM:
3010                         p_connect=(struct conncmd *)&(p_ctlbk->data);
3011                         printk(KERN_INFO "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
3012                                 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
3013                         dev->name,
3014                         p_ctlbk->version,
3015                         p_ctlbk->linkid,
3016                         p_ctlbk->correlator,
3017                         p_connect->host_name,
3018                         p_connect->WS_name);
3019                         if (p_ctlbk->linkid== -(privptr->active_link_ID)) {
3020                                 privptr->active_link_ID=p_ctlbk->linkid;
3021                                 if (p_env->packing > PACKING_ASK) {
3022                                         printk(KERN_INFO "%s: Confirmed Now packing\n",dev->name);
3023                                         p_env->packing = DO_PACKED;
3024                                         }
3025                                 p_ch=&privptr->channel[WRITE];
3026                                 wake_up(&p_ch->wait);
3027                         }
3028                         else {
3029                                 printk(KERN_INFO "%s: Conn confirm: "
3030                                         "unexpected linkid=%d \n",
3031                                         dev->name, p_ctlbk->linkid);
3032                                 claw_snd_disc(dev, p_ctlbk);
3033                         }
3034                         break;
3035                 case DISCONNECT:
3036                         printk(KERN_INFO "%s: Disconnect: "
3037                                 "Vers=%d,link_id=%d,Corr=%d\n",
3038                                 dev->name, p_ctlbk->version,
3039                                 p_ctlbk->linkid, p_ctlbk->correlator);
3040                         if ((p_ctlbk->linkid == 2) &&
3041                             (p_env->packing == PACK_SEND)) {
3042                                 privptr->active_link_ID = 1;
3043                                 p_env->packing = DO_PACKED;
3044                         }
3045                         else
3046                                 privptr->active_link_ID=0;
3047                         break;
3048                 case CLAW_ERROR:
3049                         printk(KERN_INFO "%s: CLAW ERROR detected\n",
3050                                 dev->name);
3051                         break;
3052                 default:
3053                         printk(KERN_INFO "%s:  Unexpected command code=%d \n",
3054                                 dev->name,  p_ctlbk->command);
3055                         break;
3056         }
3057
3058 #ifdef FUNCTRACE
3059         printk(KERN_INFO "%s: %s() exit on line %d, rc = 0\n",
3060                 dev->name,__func__,__LINE__);
3061 #endif
3062
3063         return 0;
3064 }   /*    end of claw_process_control    */
3065
3066
3067 /*-------------------------------------------------------------------*
3068 *               claw_send_control                                    *
3069 *                                                                    *
3070 *--------------------------------------------------------------------*/
3071
3072 static int
3073 claw_send_control(struct net_device *dev, __u8 type, __u8 link,
3074          __u8 correlator, __u8 rc, char *local_name, char *remote_name)
3075 {
3076         struct claw_privbk              *privptr;
3077         struct clawctl                  *p_ctl;
3078         struct sysval                   *p_sysval;
3079         struct conncmd                  *p_connect;
3080         struct sk_buff                  *skb;
3081
3082 #ifdef FUNCTRACE
3083         printk(KERN_INFO "%s:%s > enter  \n",dev->name,__func__);
3084 #endif
3085         CLAW_DBF_TEXT(2,setup,"sndcntl");
3086 #ifdef DEBUGMSG
3087         printk(KERN_INFO "%s: Sending Control Packet \n",dev->name);
3088         printk(KERN_INFO "%s: variable type = 0x%X, link = "
3089                 "%d, correlator = %d, rc = %d\n",
3090                 dev->name,type, link, correlator, rc);
3091         printk(KERN_INFO "%s: variable local_name = %s, "
3092                 "remote_name = %s\n",dev->name, local_name, remote_name);
3093 #endif
3094         privptr=dev->priv;
3095         p_ctl=(struct clawctl *)&privptr->ctl_bk;
3096
3097         p_ctl->command=type;
3098         p_ctl->version=CLAW_VERSION_ID;
3099         p_ctl->linkid=link;
3100         p_ctl->correlator=correlator;
3101         p_ctl->rc=rc;
3102
3103         p_sysval=(struct sysval *)&p_ctl->data;
3104         p_connect=(struct conncmd *)&p_ctl->data;
3105
3106         switch (p_ctl->command) {
3107                 case SYSTEM_VALIDATE_REQUEST:
3108                 case SYSTEM_VALIDATE_RESPONSE:
3109                         memcpy(&p_sysval->host_name, local_name, 8);
3110                         memcpy(&p_sysval->WS_name, remote_name, 8);
3111                         if (privptr->p_env->packing > 0) {
3112                                 p_sysval->read_frame_size=DEF_PACK_BUFSIZE;
3113                                 p_sysval->write_frame_size=DEF_PACK_BUFSIZE;
3114                         } else {
3115                                 /* how big is the piggest group of packets */
3116                                 p_sysval->read_frame_size=privptr->p_env->read_size;
3117                                 p_sysval->write_frame_size=privptr->p_env->write_size;
3118                         }
3119                         memset(&p_sysval->reserved, 0x00, 4);
3120                         break;
3121                 case CONNECTION_REQUEST:
3122                 case CONNECTION_RESPONSE:
3123                 case CONNECTION_CONFIRM:
3124                 case DISCONNECT:
3125                         memcpy(&p_sysval->host_name, local_name, 8);
3126                         memcpy(&p_sysval->WS_name, remote_name, 8);
3127                         if (privptr->p_env->packing > 0) {
3128                         /* How big is the biggest packet */
3129                                 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
3130                                 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
3131                         } else {
3132                                 memset(&p_connect->reserved1, 0x00, 4);
3133                                 memset(&p_connect->reserved2, 0x00, 4);
3134                         }
3135                         break;
3136                 default:
3137                         break;
3138         }
3139
3140         /*      write Control Record to the device                   */
3141
3142
3143         skb = dev_alloc_skb(sizeof(struct clawctl));
3144         if (!skb) {
3145                 printk(  "%s:%s low on mem, returning...\n",
3146                         dev->name,__func__);
3147 #ifdef DEBUG
3148                 printk(KERN_INFO "%s:%s Exit, rc = ENOMEM\n",
3149                         dev->name,__func__);
3150 #endif
3151                 return -ENOMEM;
3152         }
3153         memcpy(skb_put(skb, sizeof(struct clawctl)),
3154                 p_ctl, sizeof(struct clawctl));
3155 #ifdef IOTRACE
3156          printk(KERN_INFO "%s: outbnd claw cntl data \n",dev->name);
3157         dumpit((char *)p_ctl,sizeof(struct clawctl));
3158 #endif
3159         if (privptr->p_env->packing >= PACK_SEND)
3160                 claw_hw_tx(skb, dev, 1);
3161         else
3162                 claw_hw_tx(skb, dev, 0);
3163 #ifdef FUNCTRACE
3164         printk(KERN_INFO "%s:%s Exit on line %d\n",
3165                 dev->name,__func__,__LINE__);
3166 #endif
3167
3168         return 0;
3169 }  /*   end of claw_send_control  */
3170
3171 /*-------------------------------------------------------------------*
3172 *               claw_snd_conn_req                                    *
3173 *                                                                    *
3174 *--------------------------------------------------------------------*/
3175 static int
3176 claw_snd_conn_req(struct net_device *dev, __u8 link)
3177 {
3178         int                rc;
3179         struct claw_privbk *privptr=dev->priv;
3180         struct clawctl     *p_ctl;
3181
3182 #ifdef FUNCTRACE
3183         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__func__);
3184 #endif
3185         CLAW_DBF_TEXT(2,setup,"snd_conn");
3186 #ifdef  DEBUGMSG
3187         printk(KERN_INFO "%s: variable link = %X, dev =\n",dev->name, link);
3188         dumpit((char *) dev, sizeof(struct net_device));
3189 #endif
3190         rc = 1;
3191         p_ctl=(struct clawctl *)&privptr->ctl_bk;
3192         p_ctl->linkid = link;
3193         if ( privptr->system_validate_comp==0x00 ) {
3194 #ifdef FUNCTRACE
3195                 printk(KERN_INFO "%s:%s Exit on line %d, rc = 1\n",
3196                         dev->name,__func__,__LINE__);
3197 #endif
3198                 return rc;
3199         }
3200         if (privptr->p_env->packing == PACKING_ASK )
3201                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3202                         WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
3203         if (privptr->p_env->packing == PACK_SEND)  {
3204                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3205                         WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
3206         }
3207         if (privptr->p_env->packing == 0)
3208                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3209                         HOST_APPL_NAME, privptr->p_env->api_type);
3210 #ifdef FUNCTRACE
3211         printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3212                 dev->name,__func__,__LINE__, rc);
3213 #endif
3214         return rc;
3215
3216 }  /*  end of claw_snd_conn_req */
3217
3218
3219 /*-------------------------------------------------------------------*
3220 *               claw_snd_disc                                        *
3221 *                                                                    *
3222 *--------------------------------------------------------------------*/
3223
3224 static int
3225 claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
3226 {
3227         int rc;
3228         struct conncmd *  p_connect;
3229
3230 #ifdef FUNCTRACE
3231         printk(KERN_INFO "%s:%s Enter\n",dev->name,__func__);
3232 #endif
3233         CLAW_DBF_TEXT(2,setup,"snd_dsc");
3234 #ifdef  DEBUGMSG
3235         printk(KERN_INFO "%s: variable dev =\n",dev->name);
3236         dumpit((char *) dev, sizeof(struct net_device));
3237         printk(KERN_INFO "%s: variable p_ctl",dev->name);
3238         dumpit((char *) p_ctl, sizeof(struct clawctl));
3239 #endif
3240         p_connect=(struct conncmd *)&p_ctl->data;
3241
3242         rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
3243                 p_ctl->correlator, 0,
3244                 p_connect->host_name, p_connect->WS_name);
3245 #ifdef FUNCTRACE
3246         printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3247                 dev->name,__func__, __LINE__, rc);
3248 #endif
3249         return rc;
3250 }     /*   end of claw_snd_disc    */
3251
3252
3253 /*-------------------------------------------------------------------*
3254 *               claw_snd_sys_validate_rsp                            *
3255 *                                                                    *
3256 *--------------------------------------------------------------------*/
3257
3258 static int
3259 claw_snd_sys_validate_rsp(struct net_device *dev,
3260         struct clawctl *p_ctl, __u32 return_code)
3261 {
3262         struct claw_env *  p_env;
3263         struct claw_privbk *privptr;
3264         int    rc;
3265
3266 #ifdef FUNCTRACE
3267         printk(KERN_INFO "%s:%s Enter\n",
3268                 dev->name,__func__);
3269 #endif
3270         CLAW_DBF_TEXT(2,setup,"chkresp");
3271 #ifdef DEBUGMSG
3272         printk(KERN_INFO "%s: variable return_code = %d, dev =\n",
3273                 dev->name, return_code);
3274         dumpit((char *) dev, sizeof(struct net_device));
3275         printk(KERN_INFO "%s: variable p_ctl =\n",dev->name);
3276         dumpit((char *) p_ctl, sizeof(struct clawctl));
3277 #endif
3278         privptr = dev->priv;
3279         p_env=privptr->p_env;
3280         rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
3281                 p_ctl->linkid,
3282                 p_ctl->correlator,
3283                 return_code,
3284                 p_env->host_name,
3285                 p_env->adapter_name  );
3286 #ifdef FUNCTRACE
3287         printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3288                 dev->name,__func__,__LINE__, rc);
3289 #endif
3290         return rc;
3291 }     /*    end of claw_snd_sys_validate_rsp    */
3292
3293 /*-------------------------------------------------------------------*
3294 *               claw_strt_conn_req                                   *
3295 *                                                                    *
3296 *--------------------------------------------------------------------*/
3297
3298 static int
3299 claw_strt_conn_req(struct net_device *dev )
3300 {
3301         int rc;
3302
3303 #ifdef FUNCTRACE
3304         printk(KERN_INFO "%s:%s Enter\n",dev->name,__func__);
3305 #endif
3306         CLAW_DBF_TEXT(2,setup,"conn_req");
3307 #ifdef DEBUGMSG
3308         printk(KERN_INFO "%s: variable dev =\n",dev->name);
3309         dumpit((char *) dev, sizeof(struct net_device));
3310 #endif
3311         rc=claw_snd_conn_req(dev, 1);
3312 #ifdef FUNCTRACE
3313         printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3314                 dev->name,__func__,__LINE__, rc);
3315 #endif
3316         return rc;
3317 }    /*   end of claw_strt_conn_req   */
3318
3319
3320
3321 /*-------------------------------------------------------------------*
3322  *   claw_stats                                                      *
3323  *-------------------------------------------------------------------*/
3324
3325 static struct
3326 net_device_stats *claw_stats(struct net_device *dev)
3327 {
3328         struct claw_privbk *privptr;
3329 #ifdef FUNCTRACE
3330         printk(KERN_INFO "%s:%s Enter\n",dev->name,__func__);
3331 #endif
3332         CLAW_DBF_TEXT(4,trace,"stats");
3333         privptr = dev->priv;
3334 #ifdef FUNCTRACE
3335         printk(KERN_INFO "%s:%s Exit on line %d\n",
3336                 dev->name,__func__,__LINE__);
3337 #endif
3338         return &privptr->stats;
3339 }     /*   end of claw_stats   */
3340
3341
3342 /*-------------------------------------------------------------------*
3343 *       unpack_read                                                  *
3344 *                                                                    *
3345 *--------------------------------------------------------------------*/
3346 static void
3347 unpack_read(struct net_device *dev )
3348 {
3349         struct sk_buff *skb;
3350         struct claw_privbk *privptr;
3351         struct claw_env    *p_env;
3352         struct ccwbk    *p_this_ccw;
3353         struct ccwbk    *p_first_ccw;
3354         struct ccwbk    *p_last_ccw;
3355         struct clawph   *p_packh;
3356         void            *p_packd;
3357         struct clawctl  *p_ctlrec=NULL;
3358
3359         __u32   len_of_data;
3360         __u32   pack_off;
3361         __u8    link_num;
3362         __u8    mtc_this_frm=0;
3363         __u32   bytes_to_mov;
3364         struct chbk *p_ch = NULL;
3365         int     i=0;
3366         int     p=0;
3367
3368 #ifdef FUNCTRACE
3369         printk(KERN_INFO "%s:%s enter  \n",dev->name,__func__);
3370 #endif
3371         CLAW_DBF_TEXT(4,trace,"unpkread");
3372         p_first_ccw=NULL;
3373         p_last_ccw=NULL;
3374         p_packh=NULL;
3375         p_packd=NULL;
3376         privptr=dev->priv;
3377         p_env = privptr->p_env;
3378         p_this_ccw=privptr->p_read_active_first;
3379         i=0;
3380         while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
3381 #ifdef IOTRACE
3382                 printk(KERN_INFO "%s p_this_ccw \n",dev->name);
3383                 dumpit((char*)p_this_ccw, sizeof(struct ccwbk));
3384                 printk(KERN_INFO "%s Inbound p_this_ccw->p_buffer(64)"
3385                         " pk=%d \n",dev->name,p_env->packing);
3386                 dumpit((char *)p_this_ccw->p_buffer, 64 );
3387 #endif
3388                 pack_off = 0;
3389                 p = 0;
3390                 p_this_ccw->header.flag=CLAW_PENDING;
3391                 privptr->p_read_active_first=p_this_ccw->next;
3392                 p_this_ccw->next=NULL;
3393                 p_packh = (struct clawph *)p_this_ccw->p_buffer;
3394                 if ((p_env->packing == PACK_SEND) &&
3395                     (p_packh->len == 32)           &&
3396                     (p_packh->link_num == 0)) {   /* is it a packed ctl rec? */
3397                         p_packh++;  /* peek past pack header */
3398                         p_ctlrec = (struct clawctl *)p_packh;
3399                         p_packh--;  /* un peek */
3400                         if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
3401                             (p_ctlrec->command == CONNECTION_CONFIRM))
3402                                 p_env->packing = DO_PACKED;
3403                 }
3404                 if (p_env->packing == DO_PACKED)
3405                         link_num=p_packh->link_num;
3406                 else
3407                         link_num=p_this_ccw->header.opcode / 8;
3408                 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
3409 #ifdef DEBUGMSG
3410                         printk(KERN_INFO "%s: %s > More_to_come is ON\n",
3411                         dev->name,__func__);
3412 #endif
3413                         mtc_this_frm=1;
3414                         if (p_this_ccw->header.length!=
3415                                 privptr->p_env->read_size ) {
3416                                 printk(KERN_INFO " %s: Invalid frame detected "
3417                                         "length is %02x\n" ,
3418                                         dev->name, p_this_ccw->header.length);
3419                         }
3420                 }
3421
3422                 if (privptr->mtc_skipping) {
3423                         /*
3424                         *   We're in the mode of skipping past a
3425                         *   multi-frame message
3426                         *   that we can't process for some reason or other.
3427                         *   The first frame without the More-To-Come flag is
3428                         *   the last frame of the skipped message.
3429                         */
3430                         /*  in case of More-To-Come not set in this frame */
3431                         if (mtc_this_frm==0) {
3432                                 privptr->mtc_skipping=0; /* Ok, the end */
3433                                 privptr->mtc_logical_link=-1;
3434                         }
3435 #ifdef DEBUGMSG
3436                         printk(KERN_INFO "%s:%s goto next "
3437                                 "frame from MoretoComeSkip \n",
3438                                 dev->name,__func__);
3439 #endif
3440                         goto NextFrame;
3441                 }
3442
3443                 if (link_num==0) {
3444                         claw_process_control(dev, p_this_ccw);
3445 #ifdef DEBUGMSG
3446                         printk(KERN_INFO "%s:%s goto next "
3447                                 "frame from claw_process_control \n",
3448                                 dev->name,__func__);
3449 #endif
3450                         CLAW_DBF_TEXT(4,trace,"UnpkCntl");
3451                         goto NextFrame;
3452                 }
3453 unpack_next:
3454                 if (p_env->packing == DO_PACKED) {
3455                         if (pack_off > p_env->read_size)
3456                                 goto NextFrame;
3457                         p_packd = p_this_ccw->p_buffer+pack_off;
3458                         p_packh = (struct clawph *) p_packd;
3459                         if ((p_packh->len == 0) || /* all done with this frame? */
3460                             (p_packh->flag != 0))
3461                                 goto NextFrame;
3462                         bytes_to_mov = p_packh->len;
3463                         pack_off += bytes_to_mov+sizeof(struct clawph);
3464                         p++;
3465                 } else {
3466                         bytes_to_mov=p_this_ccw->header.length;
3467                 }
3468                 if (privptr->mtc_logical_link<0) {
3469 #ifdef DEBUGMSG
3470                 printk(KERN_INFO "%s: %s mtc_logical_link < 0  \n",
3471                         dev->name,__func__);
3472 #endif
3473
3474                 /*
3475                 *  if More-To-Come is set in this frame then we don't know
3476                 *  length of entire message, and hence have to allocate
3477                 *  large buffer   */
3478
3479                 /*      We are starting a new envelope  */
3480                 privptr->mtc_offset=0;
3481                         privptr->mtc_logical_link=link_num;
3482                 }
3483
3484                 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
3485                         /*      error     */
3486 #ifdef DEBUGMSG
3487                         printk(KERN_INFO "%s: %s > goto next "
3488                                 "frame from MoretoComeSkip \n",
3489                                 dev->name,
3490                                 __func__);
3491                         printk(KERN_INFO "      bytes_to_mov %d > (MAX_ENVELOPE_"
3492                                 "SIZE-privptr->mtc_offset %d)\n",
3493                                 bytes_to_mov,(MAX_ENVELOPE_SIZE- privptr->mtc_offset));
3494 #endif
3495                         privptr->stats.rx_frame_errors++;
3496                         goto NextFrame;
3497                 }
3498                 if (p_env->packing == DO_PACKED) {
3499                         memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
3500                                 p_packd+sizeof(struct clawph), bytes_to_mov);
3501
3502                 } else  {
3503                         memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
3504                                 p_this_ccw->p_buffer, bytes_to_mov);
3505                 }
3506 #ifdef DEBUGMSG
3507                 printk(KERN_INFO "%s: %s() received data \n",
3508                         dev->name,__func__);
3509                 if (p_env->packing == DO_PACKED)
3510                         dumpit((char *)p_packd+sizeof(struct clawph),32);
3511                 else
3512                         dumpit((char *)p_this_ccw->p_buffer, 32);
3513                 printk(KERN_INFO "%s: %s() bytelength %d \n",
3514                         dev->name,__func__,bytes_to_mov);
3515 #endif
3516                 if (mtc_this_frm==0) {
3517                         len_of_data=privptr->mtc_offset+bytes_to_mov;
3518                         skb=dev_alloc_skb(len_of_data);
3519                         if (skb) {
3520                                 memcpy(skb_put(skb,len_of_data),
3521                                         privptr->p_mtc_envelope,
3522                                         len_of_data);
3523                                 skb->dev=dev;
3524                                 skb_reset_mac_header(skb);
3525                                 skb->protocol=htons(ETH_P_IP);
3526                                 skb->ip_summed=CHECKSUM_UNNECESSARY;
3527                                 privptr->stats.rx_packets++;
3528                                 privptr->stats.rx_bytes+=len_of_data;
3529                                 netif_rx(skb);
3530 #ifdef DEBUGMSG
3531                                 printk(KERN_INFO "%s: %s() netif_"
3532                                         "rx(skb) completed \n",
3533                                         dev->name,__func__);
3534 #endif
3535                         }
3536                         else {
3537                                 privptr->stats.rx_dropped++;
3538                                 printk(KERN_WARNING "%s: %s() low on memory\n",
3539                                 dev->name,__func__);
3540                         }
3541                         privptr->mtc_offset=0;
3542                         privptr->mtc_logical_link=-1;
3543                 }
3544                 else {
3545                         privptr->mtc_offset+=bytes_to_mov;
3546                 }
3547                 if (p_env->packing == DO_PACKED)
3548                         goto unpack_next;
3549 NextFrame:
3550                 /*
3551                 *   Remove ThisCCWblock from active read queue, and add it
3552                 *   to queue of free blocks to be reused.
3553                 */
3554                 i++;
3555                 p_this_ccw->header.length=0xffff;
3556                 p_this_ccw->header.opcode=0xff;
3557                 /*
3558                 *       add this one to the free queue for later reuse
3559                 */
3560                 if (p_first_ccw==NULL) {
3561                         p_first_ccw = p_this_ccw;
3562                 }
3563                 else {
3564                         p_last_ccw->next = p_this_ccw;
3565                 }
3566                 p_last_ccw = p_this_ccw;
3567                 /*
3568                 *       chain to next block on active read queue
3569                 */
3570                 p_this_ccw = privptr->p_read_active_first;
3571                 CLAW_DBF_TEXT_(4,trace,"rxpkt %d",p);
3572         } /* end of while */
3573
3574         /*      check validity                  */
3575
3576 #ifdef IOTRACE
3577         printk(KERN_INFO "%s:%s processed frame is %d \n",
3578                 dev->name,__func__,i);
3579         printk(KERN_INFO "%s:%s  F:%lx L:%lx\n",
3580                 dev->name,
3581                 __func__,
3582                 (unsigned long)p_first_ccw,
3583                 (unsigned long)p_last_ccw);
3584 #endif
3585         CLAW_DBF_TEXT_(4,trace,"rxfrm %d",i);
3586         add_claw_reads(dev, p_first_ccw, p_last_ccw);
3587         p_ch=&privptr->channel[READ];
3588         claw_strt_read(dev, LOCK_YES);
3589 #ifdef FUNCTRACE
3590         printk(KERN_INFO "%s: %s exit on line %d\n",
3591                 dev->name, __func__, __LINE__);
3592 #endif
3593         return;
3594 }     /*  end of unpack_read   */
3595
3596 /*-------------------------------------------------------------------*
3597 *       claw_strt_read                                               *
3598 *                                                                    *
3599 *--------------------------------------------------------------------*/
3600 static void
3601 claw_strt_read (struct net_device *dev, int lock )
3602 {
3603         int        rc = 0;
3604         __u32      parm;
3605         unsigned long  saveflags = 0;
3606         struct claw_privbk *privptr=dev->priv;
3607         struct ccwbk*p_ccwbk;
3608         struct chbk *p_ch;
3609         struct clawh *p_clawh;
3610         p_ch=&privptr->channel[READ];
3611
3612 #ifdef FUNCTRACE
3613         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__func__);
3614         printk(KERN_INFO "%s: variable lock = %d, dev =\n",dev->name, lock);
3615         dumpit((char *) dev, sizeof(struct net_device));
3616 #endif
3617         CLAW_DBF_TEXT(4,trace,"StRdNter");
3618         p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
3619         p_clawh->flag=CLAW_IDLE;    /* 0x00 */
3620
3621         if ((privptr->p_write_active_first!=NULL &&
3622              privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
3623             (privptr->p_read_active_first!=NULL &&
3624              privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
3625                 p_clawh->flag=CLAW_BUSY;    /* 0xff */
3626         }
3627 #ifdef DEBUGMSG
3628         printk(KERN_INFO "%s:%s state-%02x\n" ,
3629                 dev->name,__func__, p_ch->claw_state);
3630 #endif
3631         if (lock==LOCK_YES) {
3632                 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
3633         }
3634         if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
3635 #ifdef DEBUGMSG
3636                 printk(KERN_INFO "%s: HOT READ started in %s\n" ,
3637                         dev->name,__func__);
3638                 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
3639                 dumpit((char *)&p_clawh->flag , 1);
3640 #endif
3641                 CLAW_DBF_TEXT(4,trace,"HotRead");
3642                 p_ccwbk=privptr->p_read_active_first;
3643                 parm = (unsigned long) p_ch;
3644                 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
3645                                        0xff, 0);
3646                 if (rc != 0) {
3647                         ccw_check_return_code(p_ch->cdev, rc);
3648                 }
3649         }
3650         else {
3651 #ifdef DEBUGMSG
3652                 printk(KERN_INFO "%s: No READ started by %s() In progress\n" ,
3653                         dev->name,__func__);
3654 #endif
3655                 CLAW_DBF_TEXT(2,trace,"ReadAct");
3656         }
3657
3658         if (lock==LOCK_YES) {
3659                 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
3660         }
3661 #ifdef FUNCTRACE
3662         printk(KERN_INFO "%s:%s Exit on line %d\n",
3663                 dev->name,__func__,__LINE__);
3664 #endif
3665         CLAW_DBF_TEXT(4,trace,"StRdExit");
3666         return;
3667 }       /*    end of claw_strt_read    */
3668
3669 /*-------------------------------------------------------------------*
3670 *       claw_strt_out_IO                                             *
3671 *                                                                    *
3672 *--------------------------------------------------------------------*/
3673
3674 static void
3675 claw_strt_out_IO( struct net_device *dev )
3676 {
3677         int                     rc = 0;
3678         unsigned long           parm;
3679         struct claw_privbk      *privptr;
3680         struct chbk             *p_ch;
3681         struct ccwbk    *p_first_ccw;
3682
3683 #ifdef FUNCTRACE
3684         printk(KERN_INFO "%s:%s Enter\n",dev->name,__func__);
3685 #endif
3686         if (!dev) {
3687                 return;
3688         }
3689         privptr=(struct claw_privbk *)dev->priv;
3690         p_ch=&privptr->channel[WRITE];
3691
3692 #ifdef DEBUGMSG
3693         printk(KERN_INFO "%s:%s state-%02x\n" ,
3694                 dev->name,__func__,p_ch->claw_state);
3695 #endif
3696         CLAW_DBF_TEXT(4,trace,"strt_io");
3697         p_first_ccw=privptr->p_write_active_first;
3698
3699         if (p_ch->claw_state == CLAW_STOP)
3700                 return;
3701         if (p_first_ccw == NULL) {
3702 #ifdef FUNCTRACE
3703                 printk(KERN_INFO "%s:%s Exit on line %d\n",
3704                         dev->name,__func__,__LINE__);
3705 #endif
3706                 return;
3707         }
3708         if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
3709                 parm = (unsigned long) p_ch;
3710 #ifdef DEBUGMSG
3711                 printk(KERN_INFO "%s:%s do_io \n" ,dev->name,__func__);
3712                 dumpit((char *)p_first_ccw, sizeof(struct ccwbk));
3713 #endif
3714                 CLAW_DBF_TEXT(2,trace,"StWrtIO");
3715                 rc = ccw_device_start (p_ch->cdev,&p_first_ccw->write, parm,
3716                                        0xff, 0);
3717                 if (rc != 0) {
3718                         ccw_check_return_code(p_ch->cdev, rc);
3719                 }
3720         }
3721         dev->trans_start = jiffies;
3722 #ifdef FUNCTRACE
3723         printk(KERN_INFO "%s:%s Exit on line %d\n",
3724                 dev->name,__func__,__LINE__);
3725 #endif
3726
3727         return;
3728 }       /*    end of claw_strt_out_IO    */
3729
3730 /*-------------------------------------------------------------------*
3731 *       Free write buffers                                           *
3732 *                                                                    *
3733 *--------------------------------------------------------------------*/
3734
3735 static void
3736 claw_free_wrt_buf( struct net_device *dev )
3737 {
3738
3739         struct claw_privbk *privptr=(struct claw_privbk *)dev->priv;
3740         struct ccwbk*p_first_ccw;
3741         struct ccwbk*p_last_ccw;
3742         struct ccwbk*p_this_ccw;
3743         struct ccwbk*p_next_ccw;
3744 #ifdef IOTRACE
3745         struct ccwbk*p_buf;
3746 #endif
3747 #ifdef FUNCTRACE
3748         printk(KERN_INFO "%s:%s Enter\n",dev->name,__func__);
3749         printk(KERN_INFO "%s: free count = %d  variable dev =\n",
3750                 dev->name,privptr->write_free_count);
3751 #endif
3752         CLAW_DBF_TEXT(4,trace,"freewrtb");
3753         /*  scan the write queue to free any completed write packets   */
3754         p_first_ccw=NULL;
3755         p_last_ccw=NULL;
3756 #ifdef IOTRACE
3757         printk(KERN_INFO "%s:  Dump current CCW chain \n",dev->name  );
3758         p_buf=privptr->p_write_active_first;
3759         while (p_buf!=NULL) {
3760                 dumpit((char *)p_buf, sizeof(struct ccwbk));
3761                 p_buf=p_buf->next;
3762         }
3763         if (p_buf==NULL) {
3764                 printk(KERN_INFO "%s: privptr->p_write_"
3765                         "active_first==NULL\n",dev->name  );
3766         }
3767         p_buf=(struct ccwbk*)privptr->p_end_ccw;
3768         dumpit((char *)p_buf, sizeof(struct endccw));
3769 #endif
3770         p_this_ccw=privptr->p_write_active_first;
3771         while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
3772         {
3773                 p_next_ccw = p_this_ccw->next;
3774                 if (((p_next_ccw!=NULL) &&
3775                      (p_next_ccw->header.flag!=CLAW_PENDING)) ||
3776                     ((p_this_ccw == privptr->p_write_active_last) &&
3777                      (p_this_ccw->header.flag!=CLAW_PENDING))) {
3778                         /* The next CCW is OK or this is  */
3779                         /* the last CCW...free it   @A1A  */
3780                         privptr->p_write_active_first=p_this_ccw->next;
3781                         p_this_ccw->header.flag=CLAW_PENDING;
3782                         p_this_ccw->next=privptr->p_write_free_chain;
3783                         privptr->p_write_free_chain=p_this_ccw;
3784                         ++privptr->write_free_count;
3785                         privptr->stats.tx_bytes+= p_this_ccw->write.count;
3786                         p_this_ccw=privptr->p_write_active_first;
3787                         privptr->stats.tx_packets++;
3788                 }
3789                 else {
3790                         break;
3791                 }
3792         }
3793         if (privptr->write_free_count!=0) {
3794                 claw_clearbit_busy(TB_NOBUFFER,dev);
3795         }
3796         /*   whole chain removed?   */
3797         if (privptr->p_write_active_first==NULL) {
3798                 privptr->p_write_active_last=NULL;
3799 #ifdef DEBUGMSG
3800                 printk(KERN_INFO "%s:%s p_write_"
3801                         "active_first==NULL\n",dev->name,__func__);
3802 #endif
3803         }
3804 #ifdef IOTRACE
3805         printk(KERN_INFO "%s: Dump arranged CCW chain \n",dev->name  );
3806         p_buf=privptr->p_write_active_first;
3807         while (p_buf!=NULL) {
3808                 dumpit((char *)p_buf, sizeof(struct ccwbk));
3809                 p_buf=p_buf->next;
3810         }
3811         if (p_buf==NULL) {
3812                 printk(KERN_INFO "%s: privptr->p_write_active_"
3813                         "first==NULL\n",dev->name  );
3814         }
3815         p_buf=(struct ccwbk*)privptr->p_end_ccw;
3816         dumpit((char *)p_buf, sizeof(struct endccw));
3817 #endif
3818
3819         CLAW_DBF_TEXT_(4,trace,"FWC=%d",privptr->write_free_count);
3820 #ifdef FUNCTRACE
3821         printk(KERN_INFO "%s:%s Exit on line %d free_count =%d\n",
3822                 dev->name,__func__, __LINE__,privptr->write_free_count);
3823 #endif
3824         return;
3825 }
3826
3827 /*-------------------------------------------------------------------*
3828 *       claw free netdevice                                          *
3829 *                                                                    *
3830 *--------------------------------------------------------------------*/
3831 static void
3832 claw_free_netdevice(struct net_device * dev, int free_dev)
3833 {
3834         struct claw_privbk *privptr;
3835 #ifdef FUNCTRACE
3836         printk(KERN_INFO "%s:%s Enter\n",dev->name,__func__);
3837 #endif
3838         CLAW_DBF_TEXT(2,setup,"free_dev");
3839
3840         if (!dev)
3841                 return;
3842         CLAW_DBF_TEXT_(2,setup,"%s",dev->name);
3843         privptr = dev->priv;
3844         if (dev->flags & IFF_RUNNING)
3845                 claw_release(dev);
3846         if (privptr) {
3847                 privptr->channel[READ].ndev = NULL;  /* say it's free */
3848         }
3849         dev->priv=NULL;
3850 #ifdef MODULE
3851         if (free_dev) {
3852                 free_netdev(dev);
3853         }
3854 #endif
3855         CLAW_DBF_TEXT(2,setup,"feee_ok");
3856 #ifdef FUNCTRACE
3857         printk(KERN_INFO "%s:%s Exit\n",dev->name,__func__);
3858 #endif
3859 }
3860
3861 /**
3862  * Claw init netdevice
3863  * Initialize everything of the net device except the name and the
3864  * channel structs.
3865  */
3866 static void
3867 claw_init_netdevice(struct net_device * dev)
3868 {
3869 #ifdef FUNCTRACE
3870         printk(KERN_INFO "%s:%s Enter\n",dev->name,__func__);
3871 #endif
3872         CLAW_DBF_TEXT(2,setup,"init_dev");
3873         CLAW_DBF_TEXT_(2,setup,"%s",dev->name);
3874         if (!dev) {
3875         printk(KERN_WARNING "claw:%s BAD Device exit line %d\n",
3876                 __func__,__LINE__);
3877                 CLAW_DBF_TEXT(2,setup,"baddev");
3878                 return;
3879         }
3880         dev->mtu = CLAW_DEFAULT_MTU_SIZE;
3881         dev->hard_start_xmit = claw_tx;
3882         dev->open = claw_open;
3883         dev->stop = claw_release;
3884         dev->get_stats = claw_stats;
3885         dev->change_mtu = claw_change_mtu;
3886         dev->hard_header_len = 0;
3887         dev->addr_len = 0;
3888         dev->type = ARPHRD_SLIP;
3889         dev->tx_queue_len = 1300;
3890         dev->flags = IFF_POINTOPOINT | IFF_NOARP;
3891 #ifdef FUNCTRACE
3892         printk(KERN_INFO "%s:%s Exit\n",dev->name,__func__);
3893 #endif
3894         CLAW_DBF_TEXT(2,setup,"initok");
3895         return;
3896 }
3897
3898 /**
3899  * Init a new channel in the privptr->channel[i].
3900  *
3901  * @param cdev  The ccw_device to be added.
3902  *
3903  * @return 0 on success, !0 on error.
3904  */
3905 static int
3906 add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
3907 {
3908         struct chbk *p_ch;
3909         struct ccw_dev_id dev_id;
3910
3911 #ifdef FUNCTRACE
3912         printk(KERN_INFO "%s:%s Enter\n",cdev->dev.bus_id,__func__);
3913 #endif
3914         CLAW_DBF_TEXT_(2,setup,"%s",cdev->dev.bus_id);
3915         privptr->channel[i].flag  = i+1;   /* Read is 1 Write is 2 */
3916         p_ch = &privptr->channel[i];
3917         p_ch->cdev = cdev;
3918         snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", cdev->dev.bus_id);
3919         ccw_device_get_id(cdev, &dev_id);
3920         p_ch->devno = dev_id.devno;
3921         if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
3922                 printk(KERN_WARNING "%s Out of memory in %s for irb\n",
3923                         p_ch->id,__func__);
3924 #ifdef FUNCTRACE
3925                 printk(KERN_INFO "%s:%s Exit on line %d\n",
3926                         p_ch->id,__func__,__LINE__);
3927 #endif
3928                 return -ENOMEM;
3929         }
3930 #ifdef FUNCTRACE
3931                 printk(KERN_INFO "%s:%s Exit on line %d\n",
3932                         cdev->dev.bus_id,__func__,__LINE__);
3933 #endif
3934         return 0;
3935 }
3936
3937
3938 /**
3939  *
3940  * Setup an interface.
3941  *
3942  * @param cgdev  Device to be setup.
3943  *
3944  * @returns 0 on success, !0 on failure.
3945  */
3946 static int
3947 claw_new_device(struct ccwgroup_device *cgdev)
3948 {
3949         struct claw_privbk *privptr;
3950         struct claw_env *p_env;
3951         struct net_device *dev;
3952         int ret;
3953         struct ccw_dev_id dev_id;
3954
3955         pr_debug("%s() called\n", __func__);
3956         printk(KERN_INFO "claw: add for %s\n",cgdev->cdev[READ]->dev.bus_id);
3957         CLAW_DBF_TEXT(2,setup,"new_dev");
3958         privptr = cgdev->dev.driver_data;
3959         cgdev->cdev[READ]->dev.driver_data = privptr;
3960         cgdev->cdev[WRITE]->dev.driver_data = privptr;
3961         if (!privptr)
3962                 return -ENODEV;
3963         p_env = privptr->p_env;
3964         ccw_device_get_id(cgdev->cdev[READ], &dev_id);
3965         p_env->devno[READ] = dev_id.devno;
3966         ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
3967         p_env->devno[WRITE] = dev_id.devno;
3968         ret = add_channel(cgdev->cdev[0],0,privptr);
3969         if (ret == 0)
3970                 ret = add_channel(cgdev->cdev[1],1,privptr);
3971         if (ret != 0) {
3972                         printk(KERN_WARNING
3973                         "add channel failed "
3974                                 "with ret = %d\n", ret);
3975                         goto out;
3976         }
3977         ret = ccw_device_set_online(cgdev->cdev[READ]);
3978         if (ret != 0) {
3979                 printk(KERN_WARNING
3980                  "claw: ccw_device_set_online %s READ failed "
3981                         "with ret = %d\n",cgdev->cdev[READ]->dev.bus_id,ret);
3982                 goto out;
3983         }
3984         ret = ccw_device_set_online(cgdev->cdev[WRITE]);
3985         if (ret != 0) {
3986                 printk(KERN_WARNING
3987                  "claw: ccw_device_set_online %s WRITE failed "
3988                         "with ret = %d\n",cgdev->cdev[WRITE]->dev.bus_id, ret);
3989                 goto out;
3990         }
3991         dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
3992         if (!dev) {
3993                 printk(KERN_WARNING "%s:alloc_netdev failed\n",__func__);
3994                 goto out;
3995         }
3996         dev->priv = privptr;
3997         cgdev->dev.driver_data = privptr;
3998         cgdev->cdev[READ]->dev.driver_data = privptr;
3999         cgdev->cdev[WRITE]->dev.driver_data = privptr;
4000         /* sysfs magic */
4001         SET_NETDEV_DEV(dev, &cgdev->dev);
4002         if (register_netdev(dev) != 0) {
4003                 claw_free_netdevice(dev, 1);
4004                 CLAW_DBF_TEXT(2,trace,"regfail");
4005                 goto out;
4006         }
4007         dev->flags &=~IFF_RUNNING;
4008         if (privptr->buffs_alloc == 0) {
4009                 ret=init_ccw_bk(dev);
4010                 if (ret !=0) {
4011                         printk(KERN_WARNING
4012                          "claw: init_ccw_bk failed with ret=%d\n", ret);
4013                         unregister_netdev(dev);
4014                         claw_free_netdevice(dev,1);
4015                         CLAW_DBF_TEXT(2,trace,"ccwmem");
4016                         goto out;
4017                 }
4018         }
4019         privptr->channel[READ].ndev = dev;
4020         privptr->channel[WRITE].ndev = dev;
4021         privptr->p_env->ndev = dev;
4022
4023         printk(KERN_INFO "%s:readsize=%d  writesize=%d "
4024                 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
4025                 dev->name, p_env->read_size,
4026                 p_env->write_size, p_env->read_buffers,
4027                 p_env->write_buffers, p_env->devno[READ],
4028                 p_env->devno[WRITE]);
4029         printk(KERN_INFO "%s:host_name:%.8s, adapter_name "
4030                 ":%.8s api_type: %.8s\n",
4031                 dev->name, p_env->host_name,
4032                 p_env->adapter_name , p_env->api_type);
4033         return 0;
4034 out:
4035         ccw_device_set_offline(cgdev->cdev[1]);
4036         ccw_device_set_offline(cgdev->cdev[0]);
4037
4038         return -ENODEV;
4039 }
4040
4041 static void
4042 claw_purge_skb_queue(struct sk_buff_head *q)
4043 {
4044         struct sk_buff *skb;
4045
4046         CLAW_DBF_TEXT(4,trace,"purgque");
4047
4048         while ((skb = skb_dequeue(q))) {
4049                 atomic_dec(&skb->users);
4050                 dev_kfree_skb_any(skb);
4051         }
4052 }
4053
4054 /**
4055  * Shutdown an interface.
4056  *
4057  * @param cgdev  Device to be shut down.
4058  *
4059  * @returns 0 on success, !0 on failure.
4060  */
4061 static int
4062 claw_shutdown_device(struct ccwgroup_device *cgdev)
4063 {
4064         struct claw_privbk *priv;
4065         struct net_device *ndev;
4066         int     ret;
4067
4068         pr_debug("%s() called\n", __func__);
4069         CLAW_DBF_TEXT_(2,setup,"%s",cgdev->dev.bus_id);
4070         priv = cgdev->dev.driver_data;
4071         if (!priv)
4072                 return -ENODEV;
4073         ndev = priv->channel[READ].ndev;
4074         if (ndev) {
4075                 /* Close the device */
4076                 printk(KERN_INFO
4077                         "%s: shuting down \n",ndev->name);
4078                 if (ndev->flags & IFF_RUNNING)
4079                         ret = claw_release(ndev);
4080                 ndev->flags &=~IFF_RUNNING;
4081                 unregister_netdev(ndev);
4082                 ndev->priv = NULL;  /* cgdev data, not ndev's to free */
4083                 claw_free_netdevice(ndev, 1);
4084                 priv->channel[READ].ndev = NULL;
4085                 priv->channel[WRITE].ndev = NULL;
4086                 priv->p_env->ndev = NULL;
4087         }
4088         ccw_device_set_offline(cgdev->cdev[1]);
4089         ccw_device_set_offline(cgdev->cdev[0]);
4090         return 0;
4091 }
4092
4093 static void
4094 claw_remove_device(struct ccwgroup_device *cgdev)
4095 {
4096         struct claw_privbk *priv;
4097
4098         pr_debug("%s() called\n", __func__);
4099         CLAW_DBF_TEXT_(2,setup,"%s",cgdev->dev.bus_id);
4100         priv = cgdev->dev.driver_data;
4101         if (!priv) {
4102                 printk(KERN_WARNING "claw: %s() no Priv exiting\n",__func__);
4103                 return;
4104         }
4105         printk(KERN_INFO "claw: %s() called %s will be removed.\n",
4106                         __func__,cgdev->cdev[0]->dev.bus_id);
4107         if (cgdev->state == CCWGROUP_ONLINE)
4108                 claw_shutdown_device(cgdev);
4109         claw_remove_files(&cgdev->dev);
4110         kfree(priv->p_mtc_envelope);
4111         priv->p_mtc_envelope=NULL;
4112         kfree(priv->p_env);
4113         priv->p_env=NULL;
4114         kfree(priv->channel[0].irb);
4115         priv->channel[0].irb=NULL;
4116         kfree(priv->channel[1].irb);
4117         priv->channel[1].irb=NULL;
4118         kfree(priv);
4119         cgdev->dev.driver_data=NULL;
4120         cgdev->cdev[READ]->dev.driver_data = NULL;
4121         cgdev->cdev[WRITE]->dev.driver_data = NULL;
4122         put_device(&cgdev->dev);
4123 }
4124
4125
4126 /*
4127  * sysfs attributes
4128  */
4129 static ssize_t
4130 claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
4131 {
4132         struct claw_privbk *priv;
4133         struct claw_env *  p_env;
4134
4135         priv = dev->driver_data;
4136         if (!priv)
4137                 return -ENODEV;
4138         p_env = priv->p_env;
4139         return sprintf(buf, "%s\n",p_env->host_name);
4140 }
4141
4142 static ssize_t
4143 claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4144 {
4145         struct claw_privbk *priv;
4146         struct claw_env *  p_env;
4147
4148         priv = dev->driver_data;
4149         if (!priv)
4150                 return -ENODEV;
4151         p_env = priv->p_env;
4152         if (count > MAX_NAME_LEN+1)
4153                 return -EINVAL;
4154         memset(p_env->host_name, 0x20, MAX_NAME_LEN);
4155         strncpy(p_env->host_name,buf, count);
4156         p_env->host_name[count-1] = 0x20;  /* clear extra 0x0a */
4157         p_env->host_name[MAX_NAME_LEN] = 0x00;
4158         CLAW_DBF_TEXT(2,setup,"HstnSet");
4159         CLAW_DBF_TEXT_(2,setup,"%s",p_env->host_name);
4160
4161         return count;
4162 }
4163
4164 static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
4165
4166 static ssize_t
4167 claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
4168 {
4169         struct claw_privbk *priv;
4170         struct claw_env *  p_env;
4171
4172         priv = dev->driver_data;
4173         if (!priv)
4174                 return -ENODEV;
4175         p_env = priv->p_env;
4176         return sprintf(buf, "%s\n",p_env->adapter_name);
4177 }
4178
4179 static ssize_t
4180 claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4181 {
4182         struct claw_privbk *priv;
4183         struct claw_env *  p_env;
4184
4185         priv = dev->driver_data;
4186         if (!priv)
4187                 return -ENODEV;
4188         p_env = priv->p_env;
4189         if (count > MAX_NAME_LEN+1)
4190                 return -EINVAL;
4191         memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
4192         strncpy(p_env->adapter_name,buf, count);
4193         p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
4194         p_env->adapter_name[MAX_NAME_LEN] = 0x00;
4195         CLAW_DBF_TEXT(2,setup,"AdnSet");
4196         CLAW_DBF_TEXT_(2,setup,"%s",p_env->adapter_name);
4197
4198         return count;
4199 }
4200
4201 static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
4202
4203 static ssize_t
4204 claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
4205 {
4206         struct claw_privbk *priv;
4207         struct claw_env *  p_env;
4208
4209         priv = dev->driver_data;
4210         if (!priv)
4211                 return -ENODEV;
4212         p_env = priv->p_env;
4213         return sprintf(buf, "%s\n",
4214                        p_env->api_type);
4215 }
4216
4217 static ssize_t
4218 claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4219 {
4220         struct claw_privbk *priv;
4221         struct claw_env *  p_env;
4222
4223         priv = dev->driver_data;
4224         if (!priv)
4225                 return -ENODEV;
4226         p_env = priv->p_env;
4227         if (count > MAX_NAME_LEN+1)
4228                 return -EINVAL;
4229         memset(p_env->api_type, 0x20, MAX_NAME_LEN);
4230         strncpy(p_env->api_type,buf, count);
4231         p_env->api_type[count-1] = 0x20;  /* we get a loose 0x0a */
4232         p_env->api_type[MAX_NAME_LEN] = 0x00;
4233         if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
4234                 p_env->read_size=DEF_PACK_BUFSIZE;
4235                 p_env->write_size=DEF_PACK_BUFSIZE;
4236                 p_env->packing=PACKING_ASK;
4237                 CLAW_DBF_TEXT(2,setup,"PACKING");
4238         }
4239         else {
4240                 p_env->packing=0;
4241                 p_env->read_size=CLAW_FRAME_SIZE;
4242                 p_env->write_size=CLAW_FRAME_SIZE;
4243                 CLAW_DBF_TEXT(2,setup,"ApiSet");
4244         }
4245         CLAW_DBF_TEXT_(2,setup,"%s",p_env->api_type);
4246         return count;
4247 }
4248
4249 static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
4250
4251 static ssize_t
4252 claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
4253 {
4254         struct claw_privbk *priv;
4255         struct claw_env * p_env;
4256
4257         priv = dev->driver_data;
4258         if (!priv)
4259                 return -ENODEV;
4260         p_env = priv->p_env;
4261         return sprintf(buf, "%d\n", p_env->write_buffers);
4262 }
4263
4264 static ssize_t
4265 claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4266 {
4267         struct claw_privbk *priv;
4268         struct claw_env *  p_env;
4269         int nnn,max;
4270
4271         priv = dev->driver_data;
4272         if (!priv)
4273                 return -ENODEV;
4274         p_env = priv->p_env;
4275         sscanf(buf, "%i", &nnn);
4276         if (p_env->packing) {
4277                 max = 64;
4278         }
4279         else {
4280                 max = 512;
4281         }
4282         if ((nnn > max ) || (nnn < 2))
4283                 return -EINVAL;
4284         p_env->write_buffers = nnn;
4285         CLAW_DBF_TEXT(2,setup,"Wbufset");
4286         CLAW_DBF_TEXT_(2,setup,"WB=%d",p_env->write_buffers);
4287         return count;
4288 }
4289
4290 static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
4291
4292 static ssize_t
4293 claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
4294 {
4295         struct claw_privbk *priv;
4296         struct claw_env *  p_env;
4297
4298         priv = dev->driver_data;
4299         if (!priv)
4300                 return -ENODEV;
4301         p_env = priv->p_env;
4302         return sprintf(buf, "%d\n", p_env->read_buffers);
4303 }
4304
4305 static ssize_t
4306 claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4307 {
4308         struct claw_privbk *priv;
4309         struct claw_env *p_env;
4310         int nnn,max;
4311
4312         priv = dev->driver_data;
4313         if (!priv)
4314                 return -ENODEV;
4315         p_env = priv->p_env;
4316         sscanf(buf, "%i", &nnn);
4317         if (p_env->packing) {
4318                 max = 64;
4319         }
4320         else {
4321                 max = 512;
4322         }
4323         if ((nnn > max ) || (nnn < 2))
4324                 return -EINVAL;
4325         p_env->read_buffers = nnn;
4326         CLAW_DBF_TEXT(2,setup,"Rbufset");
4327         CLAW_DBF_TEXT_(2,setup,"RB=%d",p_env->read_buffers);
4328         return count;
4329 }
4330
4331 static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
4332
4333 static struct attribute *claw_attr[] = {
4334         &dev_attr_read_buffer.attr,
4335         &dev_attr_write_buffer.attr,
4336         &dev_attr_adapter_name.attr,
4337         &dev_attr_api_type.attr,
4338         &dev_attr_host_name.attr,
4339         NULL,
4340 };
4341
4342 static struct attribute_group claw_attr_group = {
4343         .attrs = claw_attr,
4344 };
4345
4346 static int
4347 claw_add_files(struct device *dev)
4348 {
4349         pr_debug("%s() called\n", __func__);
4350         CLAW_DBF_TEXT(2,setup,"add_file");
4351         return sysfs_create_group(&dev->kobj, &claw_attr_group);
4352 }
4353
4354 static void
4355 claw_remove_files(struct device *dev)
4356 {
4357         pr_debug("%s() called\n", __func__);
4358         CLAW_DBF_TEXT(2,setup,"rem_file");
4359         sysfs_remove_group(&dev->kobj, &claw_attr_group);
4360 }
4361
4362 /*--------------------------------------------------------------------*
4363 *    claw_init  and cleanup                                           *
4364 *---------------------------------------------------------------------*/
4365
4366 static void __exit
4367 claw_cleanup(void)
4368 {
4369         unregister_cu3088_discipline(&claw_group_driver);
4370         claw_unregister_debug_facility();
4371         printk(KERN_INFO "claw: Driver unloaded\n");
4372
4373 }
4374
4375 /**
4376  * Initialize module.
4377  * This is called just after the module is loaded.
4378  *
4379  * @return 0 on success, !0 on error.
4380  */
4381 static int __init
4382 claw_init(void)
4383 {
4384         int ret = 0;
4385         printk(KERN_INFO "claw: starting driver\n");
4386
4387 #ifdef FUNCTRACE
4388         printk(KERN_INFO "claw: %s() enter \n",__func__);
4389 #endif
4390         ret = claw_register_debug_facility();
4391         if (ret) {
4392                 printk(KERN_WARNING "claw: %s() debug_register failed %d\n",
4393                         __func__,ret);
4394                 return ret;
4395         }
4396         CLAW_DBF_TEXT(2,setup,"init_mod");
4397         ret = register_cu3088_discipline(&claw_group_driver);
4398         if (ret) {
4399                 claw_unregister_debug_facility();
4400                 printk(KERN_WARNING "claw; %s() cu3088 register failed %d\n",
4401                         __func__,ret);
4402         }
4403 #ifdef FUNCTRACE
4404         printk(KERN_INFO "claw: %s() exit \n",__func__);
4405 #endif
4406         return ret;
4407 }
4408
4409 module_init(claw_init);
4410 module_exit(claw_cleanup);
4411
4412
4413
4414 /*--------------------------------------------------------------------*
4415 *    End of File                                                      *
4416 *---------------------------------------------------------------------*/
4417
4418