2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
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)
10 * Andy Richter (richtera@us.ibm.com)
11 * Marc Price (mwprice@us.ibm.com)
14 * group x.x.rrrr,x.x.wwww
18 * adapter_name aaaaaaaa
22 * group 0.0.0200 0.0.0201
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
35 * rrrr - the first of 2 consecutive device addresses used for the
37 * The specified address is always used as the input (Read)
38 * channel and the next address is used as the output channel.
40 * wwww - the second of 2 consecutive device addresses used for
42 * The specified address is always used as the output
43 * channel and the previous address is used as the input channel.
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
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
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
62 #include <asm/bitops.h>
63 #include <asm/ccwdev.h>
64 #include <asm/ccwgroup.h>
65 #include <asm/debug.h>
66 #include <asm/idals.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>
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>
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");
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
104 CLAW also uses the s390dbf file system see claw_trace and claw_setup
107 /* following enables tracing */
124 static char debug_buffer
[255];
126 * Debug Facility Stuff
128 static debug_info_t
*claw_dbf_setup
;
129 static debug_info_t
*claw_dbf_trace
;
132 * CLAW Debug Facility functions
135 claw_unregister_debug_facility(void)
138 debug_unregister(claw_dbf_setup
);
140 debug_unregister(claw_dbf_trace
);
144 claw_register_debug_facility(void)
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();
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);
161 claw_set_busy(struct net_device
*dev
)
163 ((struct claw_privbk
*) dev
->priv
)->tbusy
=1;
168 claw_clear_busy(struct net_device
*dev
)
170 clear_bit(0, &(((struct claw_privbk
*) dev
->priv
)->tbusy
));
171 netif_wake_queue(dev
);
176 claw_check_busy(struct net_device
*dev
)
179 return ((struct claw_privbk
*) dev
->priv
)->tbusy
;
183 claw_setbit_busy(int nr
,struct net_device
*dev
)
185 netif_stop_queue(dev
);
186 set_bit(nr
, (void *)&(((struct claw_privbk
*)dev
->priv
)->tbusy
));
190 claw_clearbit_busy(int nr
,struct net_device
*dev
)
192 clear_bit(nr
,(void *)&(((struct claw_privbk
*)dev
->priv
)->tbusy
));
193 netif_wake_queue(dev
);
197 claw_test_and_setbit_busy(int nr
,struct net_device
*dev
)
199 netif_stop_queue(dev
);
200 return test_and_set_bit(nr
,
201 (void *)&(((struct claw_privbk
*) dev
->priv
)->tbusy
));
205 /* Functions for the DEV methods */
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
);
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
);
236 static void dumpit (char *buf
, int len
);
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
);
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
);
270 /* Functions for unpack reads */
271 static void unpack_read (struct net_device
*dev
);
275 static struct ccwgroup_driver claw_group_driver
= {
276 .owner
= THIS_MODULE
,
279 .driver_id
= 0xC3D3C1E6,
281 .remove
= claw_remove_device
,
282 .set_online
= claw_new_device
,
283 .set_offline
= claw_shutdown_device
,
291 /*----------------------------------------------------------------*
293 * this function is called for each CLAW device. *
294 *----------------------------------------------------------------*/
296 claw_probe(struct ccwgroup_device
*cgdev
)
299 struct claw_privbk
*privptr
=NULL
;
302 printk(KERN_INFO
"%s Enter\n",__FUNCTION__
);
304 CLAW_DBF_TEXT(2,setup
,"probe");
305 if (!get_device(&cgdev
->dev
))
308 printk(KERN_INFO
"claw: variable cgdev =\n");
309 dumpit((char *)cgdev
, sizeof(struct ccwgroup_device
));
311 privptr
= kzalloc(sizeof(struct claw_privbk
), GFP_KERNEL
);
312 if (privptr
== NULL
) {
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
,__FUNCTION__
,__LINE__
);
317 CLAW_DBF_TEXT_(2,setup
,"probex%d",-ENOMEM
);
320 privptr
->p_mtc_envelope
= kmalloc( MAX_ENVELOPE_SIZE
, GFP_KERNEL
);
321 privptr
->p_env
= kmalloc(sizeof(struct claw_env
), GFP_KERNEL
);
322 if ((privptr
->p_mtc_envelope
==NULL
) || (privptr
->p_env
==NULL
)) {
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
,__FUNCTION__
,__LINE__
);
327 CLAW_DBF_TEXT_(2,setup
,"probex%d",-ENOMEM
);
330 memset(privptr
->p_mtc_envelope
, 0x00, MAX_ENVELOPE_SIZE
);
331 memset(privptr
->p_env
, 0x00, sizeof(struct claw_env
));
332 memcpy(privptr
->p_env
->adapter_name
,WS_NAME_NOT_DEF
,8);
333 memcpy(privptr
->p_env
->host_name
,WS_NAME_NOT_DEF
,8);
334 memcpy(privptr
->p_env
->api_type
,WS_NAME_NOT_DEF
,8);
335 privptr
->p_env
->packing
= 0;
336 privptr
->p_env
->write_buffers
= 5;
337 privptr
->p_env
->read_buffers
= 5;
338 privptr
->p_env
->read_size
= CLAW_FRAME_SIZE
;
339 privptr
->p_env
->write_size
= CLAW_FRAME_SIZE
;
340 rc
= claw_add_files(&cgdev
->dev
);
343 put_device(&cgdev
->dev
);
344 printk(KERN_WARNING
"add_files failed %s %s Exit Line %d \n",
345 cgdev
->cdev
[0]->dev
.bus_id
,__FUNCTION__
,__LINE__
);
346 CLAW_DBF_TEXT_(2,setup
,"probex%d",rc
);
349 printk(KERN_INFO
"claw: sysfs files added for %s\n",cgdev
->cdev
[0]->dev
.bus_id
);
350 privptr
->p_env
->p_priv
= privptr
;
351 cgdev
->cdev
[0]->handler
= claw_irq_handler
;
352 cgdev
->cdev
[1]->handler
= claw_irq_handler
;
353 cgdev
->dev
.driver_data
= privptr
;
355 printk(KERN_INFO
"claw:%s exit on line %d, "
356 "rc = 0\n",__FUNCTION__
,__LINE__
);
358 CLAW_DBF_TEXT(2,setup
,"prbext 0");
361 } /* end of claw_probe */
363 /*-------------------------------------------------------------------*
365 *-------------------------------------------------------------------*/
368 claw_tx(struct sk_buff
*skb
, struct net_device
*dev
)
371 struct claw_privbk
*privptr
=dev
->priv
;
372 unsigned long saveflags
;
376 printk(KERN_INFO
"%s:%s enter\n",dev
->name
,__FUNCTION__
);
378 CLAW_DBF_TEXT(4,trace
,"claw_tx");
379 p_ch
=&privptr
->channel
[WRITE
];
381 printk(KERN_WARNING
"%s: null pointer passed as sk_buffer\n",
383 privptr
->stats
.tx_dropped
++;
385 printk(KERN_INFO
"%s: %s() exit on line %d, rc = EIO\n",
386 dev
->name
,__FUNCTION__
, __LINE__
);
388 CLAW_DBF_TEXT_(2,trace
,"clawtx%d",-EIO
);
393 printk(KERN_INFO
"%s: variable sk_buff=\n",dev
->name
);
394 dumpit((char *) skb
, sizeof(struct sk_buff
));
395 printk(KERN_INFO
"%s: variable dev=\n",dev
->name
);
396 dumpit((char *) dev
, sizeof(struct net_device
));
398 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
399 rc
=claw_hw_tx( skb
, dev
, 1 );
400 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
402 printk(KERN_INFO
"%s:%s exit on line %d, rc = %d\n",
403 dev
->name
, __FUNCTION__
, __LINE__
, rc
);
405 CLAW_DBF_TEXT_(4,trace
,"clawtx%d",rc
);
407 } /* end of claw_tx */
409 /*------------------------------------------------------------------*
410 * pack the collect queue into an skb and return it *
411 * If not packing just return the top skb from the queue *
412 *------------------------------------------------------------------*/
414 static struct sk_buff
*
415 claw_pack_skb(struct claw_privbk
*privptr
)
417 struct sk_buff
*new_skb
,*held_skb
;
418 struct chbk
*p_ch
= &privptr
->channel
[WRITE
];
419 struct claw_env
*p_env
= privptr
->p_env
;
420 int pkt_cnt
,pk_ind
,so_far
;
422 new_skb
= NULL
; /* assume no dice */
424 CLAW_DBF_TEXT(4,trace
,"PackSKBe");
425 if (!skb_queue_empty(&p_ch
->collect_queue
)) {
427 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
429 dev_kfree_skb_any(held_skb
);
432 if (p_env
->packing
!= DO_PACKED
)
434 /* get a new SKB we will pack at least one */
435 new_skb
= dev_alloc_skb(p_env
->write_size
);
436 if (new_skb
== NULL
) {
437 atomic_inc(&held_skb
->users
);
438 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
441 /* we have packed packet and a place to put it */
444 new_skb
->cb
[1] = 'P'; /* every skb on queue has pack header */
445 while ((pk_ind
) && (held_skb
!= NULL
)) {
446 if (held_skb
->len
+so_far
<= p_env
->write_size
-8) {
447 memcpy(skb_put(new_skb
,held_skb
->len
),
448 held_skb
->data
,held_skb
->len
);
449 privptr
->stats
.tx_packets
++;
450 so_far
+= held_skb
->len
;
452 dev_kfree_skb_any(held_skb
);
453 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
455 atomic_dec(&held_skb
->users
);
458 atomic_inc(&held_skb
->users
);
459 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
463 printk(KERN_INFO
"%s: %s() Packed %d len %d\n",
465 __FUNCTION__
,pkt_cnt
,new_skb
->len
);
468 CLAW_DBF_TEXT(4,trace
,"PackSKBx");
472 /*-------------------------------------------------------------------*
475 *-------------------------------------------------------------------*/
478 claw_change_mtu(struct net_device
*dev
, int new_mtu
)
480 struct claw_privbk
*privptr
=dev
->priv
;
483 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
486 printk(KERN_INFO
"variable dev =\n");
487 dumpit((char *) dev
, sizeof(struct net_device
));
488 printk(KERN_INFO
"variable new_mtu = %d\n", new_mtu
);
490 CLAW_DBF_TEXT(4,trace
,"setmtu");
491 buff_size
= privptr
->p_env
->write_size
;
492 if ((new_mtu
< 60) || (new_mtu
> buff_size
)) {
494 printk(KERN_INFO
"%s:%s Exit on line %d, rc=EINVAL\n",
496 __FUNCTION__
, __LINE__
);
502 printk(KERN_INFO
"%s:%s Exit on line %d\n",dev
->name
,
503 __FUNCTION__
, __LINE__
);
506 } /* end of claw_change_mtu */
509 /*-------------------------------------------------------------------*
512 *-------------------------------------------------------------------*/
514 claw_open(struct net_device
*dev
)
519 unsigned long saveflags
=0;
521 struct claw_privbk
*privptr
;
522 DECLARE_WAITQUEUE(wait
, current
);
523 struct timer_list timer
;
527 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
529 CLAW_DBF_TEXT(4,trace
,"open");
530 if (!dev
|| (dev
->name
[0] == 0x00)) {
531 CLAW_DBF_TEXT(2,trace
,"BadDev");
532 printk(KERN_WARNING
"claw: Bad device at open failing \n");
535 privptr
= (struct claw_privbk
*)dev
->priv
;
536 /* allocate and initialize CCW blocks */
537 if (privptr
->buffs_alloc
== 0) {
540 printk(KERN_INFO
"%s:%s Exit on line %d, rc=ENOMEM\n",
542 __FUNCTION__
, __LINE__
);
543 CLAW_DBF_TEXT(2,trace
,"openmem");
547 privptr
->system_validate_comp
=0;
548 privptr
->release_pend
=0;
549 if(strncmp(privptr
->p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
550 privptr
->p_env
->read_size
=DEF_PACK_BUFSIZE
;
551 privptr
->p_env
->write_size
=DEF_PACK_BUFSIZE
;
552 privptr
->p_env
->packing
=PACKING_ASK
;
554 privptr
->p_env
->packing
=0;
555 privptr
->p_env
->read_size
=CLAW_FRAME_SIZE
;
556 privptr
->p_env
->write_size
=CLAW_FRAME_SIZE
;
559 tasklet_init(&privptr
->channel
[READ
].tasklet
, claw_irq_tasklet
,
560 (unsigned long) &privptr
->channel
[READ
]);
561 for ( i
= 0; i
< 2; i
++) {
562 CLAW_DBF_TEXT_(2,trace
,"opn_ch%d",i
);
563 init_waitqueue_head(&privptr
->channel
[i
].wait
);
564 /* skb_queue_head_init(&p_ch->io_queue); */
567 &privptr
->channel
[WRITE
].collect_queue
);
568 privptr
->channel
[i
].flag_a
= 0;
569 privptr
->channel
[i
].IO_active
= 0;
570 privptr
->channel
[i
].flag
&= ~CLAW_TIMER
;
572 timer
.function
= (void *)claw_timer
;
573 timer
.data
= (unsigned long)(&privptr
->channel
[i
]);
574 timer
.expires
= jiffies
+ 15*HZ
;
576 spin_lock_irqsave(get_ccwdev_lock(
577 privptr
->channel
[i
].cdev
), saveflags
);
578 parm
= (unsigned long) &privptr
->channel
[i
];
579 privptr
->channel
[i
].claw_state
= CLAW_START_HALT_IO
;
581 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
582 rc
= ccw_device_halt(
583 (struct ccw_device
*)privptr
->channel
[i
].cdev
,parm
);
584 set_current_state(TASK_INTERRUPTIBLE
);
585 spin_unlock_irqrestore(
586 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
588 set_current_state(TASK_RUNNING
);
589 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
591 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
592 if((privptr
->channel
[i
].flag
& CLAW_TIMER
) == 0x00)
595 if ((((privptr
->channel
[READ
].last_dstat
|
596 privptr
->channel
[WRITE
].last_dstat
) &
597 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) ||
598 (((privptr
->channel
[READ
].flag
|
599 privptr
->channel
[WRITE
].flag
) & CLAW_TIMER
) != 0x00)) {
601 printk(KERN_INFO
"%s: channel problems during open - read:"
602 " %02x - write: %02x\n",
604 privptr
->channel
[READ
].last_dstat
,
605 privptr
->channel
[WRITE
].last_dstat
);
607 printk(KERN_INFO
"%s: remote side is not ready\n", dev
->name
);
608 CLAW_DBF_TEXT(2,trace
,"notrdy");
610 for ( i
= 0; i
< 2; i
++) {
612 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
614 parm
= (unsigned long) &privptr
->channel
[i
];
615 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
616 rc
= ccw_device_halt(
617 (struct ccw_device
*)&privptr
->channel
[i
].cdev
,
619 spin_unlock_irqrestore(
620 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
623 ccw_check_return_code(
624 privptr
->channel
[i
].cdev
, rc
);
627 free_pages((unsigned long)privptr
->p_buff_ccw
,
628 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
629 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
630 free_pages((unsigned long)privptr
->p_buff_read
,
631 (int)pages_to_order_of_mag(
632 privptr
->p_buff_read_num
));
635 p_buf
=privptr
->p_read_active_first
;
636 while (p_buf
!=NULL
) {
637 free_pages((unsigned long)p_buf
->p_buffer
,
638 (int)pages_to_order_of_mag(
639 privptr
->p_buff_pages_perread
));
643 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
644 free_pages((unsigned long)privptr
->p_buff_write
,
645 (int)pages_to_order_of_mag(
646 privptr
->p_buff_write_num
));
649 p_buf
=privptr
->p_write_active_first
;
650 while (p_buf
!=NULL
) {
651 free_pages((unsigned long)p_buf
->p_buffer
,
652 (int)pages_to_order_of_mag(
653 privptr
->p_buff_pages_perwrite
));
657 privptr
->buffs_alloc
= 0;
658 privptr
->channel
[READ
].flag
= 0x00;
659 privptr
->channel
[WRITE
].flag
= 0x00;
660 privptr
->p_buff_ccw
=NULL
;
661 privptr
->p_buff_read
=NULL
;
662 privptr
->p_buff_write
=NULL
;
663 claw_clear_busy(dev
);
665 printk(KERN_INFO
"%s:%s Exit on line %d, rc=EIO\n",
666 dev
->name
,__FUNCTION__
,__LINE__
);
668 CLAW_DBF_TEXT(2,trace
,"open EIO");
672 /* Send SystemValidate command */
674 claw_clear_busy(dev
);
677 printk(KERN_INFO
"%s:%s Exit on line %d, rc=0\n",
678 dev
->name
,__FUNCTION__
,__LINE__
);
680 CLAW_DBF_TEXT(4,trace
,"openok");
682 } /* end of claw_open */
684 /*-------------------------------------------------------------------*
688 *--------------------------------------------------------------------*/
690 claw_irq_handler(struct ccw_device
*cdev
,
691 unsigned long intparm
, struct irb
*irb
)
693 struct chbk
*p_ch
= NULL
;
694 struct claw_privbk
*privptr
= NULL
;
695 struct net_device
*dev
= NULL
;
696 struct claw_env
*p_env
;
697 struct chbk
*p_ch_r
=NULL
;
701 printk(KERN_INFO
"%s enter \n",__FUNCTION__
);
703 CLAW_DBF_TEXT(4,trace
,"clawirq");
704 /* Bypass all 'unsolicited interrupts' */
705 if (!cdev
->dev
.driver_data
) {
706 printk(KERN_WARNING
"claw: unsolicited interrupt for device:"
707 "%s received c-%02x d-%02x\n",
708 cdev
->dev
.bus_id
,irb
->scsw
.cstat
, irb
->scsw
.dstat
);
710 printk(KERN_INFO
"claw: %s() "
711 "exit on line %d\n",__FUNCTION__
,__LINE__
);
713 CLAW_DBF_TEXT(2,trace
,"badirq");
716 privptr
= (struct claw_privbk
*)cdev
->dev
.driver_data
;
718 /* Try to extract channel from driver data. */
719 if (privptr
->channel
[READ
].cdev
== cdev
)
720 p_ch
= &privptr
->channel
[READ
];
721 else if (privptr
->channel
[WRITE
].cdev
== cdev
)
722 p_ch
= &privptr
->channel
[WRITE
];
724 printk(KERN_WARNING
"claw: Can't determine channel for "
725 "interrupt, device %s\n", cdev
->dev
.bus_id
);
726 CLAW_DBF_TEXT(2,trace
,"badchan");
729 CLAW_DBF_TEXT_(4,trace
,"IRQCH=%d",p_ch
->flag
);
731 dev
= (struct net_device
*) (p_ch
->ndev
);
732 p_env
=privptr
->p_env
;
735 printk(KERN_INFO
"%s: interrupt for device: %04x "
736 "received c-%02x d-%02x state-%02x\n",
737 dev
->name
, p_ch
->devno
, irb
->scsw
.cstat
,
738 irb
->scsw
.dstat
, p_ch
->claw_state
);
741 /* Copy interruption response block. */
742 memcpy(p_ch
->irb
, irb
, sizeof(struct irb
));
744 /* Check for good subchannel return code, otherwise error message */
745 if (irb
->scsw
.cstat
&& !(irb
->scsw
.cstat
& SCHN_STAT_PCI
)) {
746 printk(KERN_INFO
"%s: subchannel check for device: %04x -"
747 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
748 dev
->name
, p_ch
->devno
,
749 irb
->scsw
.cstat
, irb
->scsw
.dstat
,irb
->scsw
.cpa
);
751 dumpit((char *)irb
,sizeof(struct irb
));
752 dumpit((char *)(unsigned long)irb
->scsw
.cpa
,
753 sizeof(struct ccw1
));
756 printk(KERN_INFO
"%s:%s Exit on line %d\n",
757 dev
->name
,__FUNCTION__
,__LINE__
);
759 CLAW_DBF_TEXT(2,trace
,"chanchk");
763 /* Check the reason-code of a unit check */
764 if (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) {
765 ccw_check_unit_check(p_ch
, irb
->ecw
[0]);
768 /* State machine to bring the connection up, down and to restart */
769 p_ch
->last_dstat
= irb
->scsw
.dstat
;
771 switch (p_ch
->claw_state
) {
772 case CLAW_STOP
:/* HALT_IO by claw_release (halt sequence) */
774 printk(KERN_INFO
"%s: CLAW_STOP enter\n", dev
->name
);
776 if (!((p_ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
777 (p_ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
778 (p_ch
->irb
->scsw
.stctl
==
779 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
781 printk(KERN_INFO
"%s:%s Exit on line %d\n",
782 dev
->name
,__FUNCTION__
,__LINE__
);
786 wake_up(&p_ch
->wait
); /* wake up claw_release */
789 printk(KERN_INFO
"%s: CLAW_STOP exit\n", dev
->name
);
792 printk(KERN_INFO
"%s:%s Exit on line %d\n",
793 dev
->name
,__FUNCTION__
,__LINE__
);
795 CLAW_DBF_TEXT(4,trace
,"stop");
798 case CLAW_START_HALT_IO
: /* HALT_IO issued by claw_open */
800 printk(KERN_INFO
"%s: process CLAW_STAT_HALT_IO\n",
803 if (!((p_ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
804 (p_ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
805 (p_ch
->irb
->scsw
.stctl
==
806 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
808 printk(KERN_INFO
"%s:%s Exit on line %d\n",
809 dev
->name
,__FUNCTION__
,__LINE__
);
811 CLAW_DBF_TEXT(4,trace
,"haltio");
814 if (p_ch
->flag
== CLAW_READ
) {
815 p_ch
->claw_state
= CLAW_START_READ
;
816 wake_up(&p_ch
->wait
); /* wake claw_open (READ)*/
819 if (p_ch
->flag
== CLAW_WRITE
) {
820 p_ch
->claw_state
= CLAW_START_WRITE
;
821 /* send SYSTEM_VALIDATE */
822 claw_strt_read(dev
, LOCK_NO
);
823 claw_send_control(dev
,
824 SYSTEM_VALIDATE_REQUEST
,
827 p_env
->adapter_name
);
829 printk(KERN_WARNING
"claw: unsolicited "
830 "interrupt for device:"
831 "%s received c-%02x d-%02x\n",
838 printk(KERN_INFO
"%s: process CLAW_STAT_HALT_IO exit\n",
842 printk(KERN_INFO
"%s:%s Exit on line %d\n",
843 dev
->name
,__FUNCTION__
,__LINE__
);
845 CLAW_DBF_TEXT(4,trace
,"haltio");
847 case CLAW_START_READ
:
848 CLAW_DBF_TEXT(4,trace
,"ReadIRQ");
849 if (p_ch
->irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) {
850 clear_bit(0, (void *)&p_ch
->IO_active
);
851 if ((p_ch
->irb
->ecw
[0] & 0x41) == 0x41 ||
852 (p_ch
->irb
->ecw
[0] & 0x40) == 0x40 ||
853 (p_ch
->irb
->ecw
[0]) == 0)
855 privptr
->stats
.rx_errors
++;
856 printk(KERN_INFO
"%s: Restart is "
857 "required after remote "
862 printk(KERN_INFO
"%s:%s Exit on line %d\n",
863 dev
->name
,__FUNCTION__
,__LINE__
);
865 CLAW_DBF_TEXT(4,trace
,"notrdy");
868 if ((p_ch
->irb
->scsw
.cstat
& SCHN_STAT_PCI
) &&
869 (p_ch
->irb
->scsw
.dstat
==0)) {
870 if (test_and_set_bit(CLAW_BH_ACTIVE
,
871 (void *)&p_ch
->flag_a
) == 0) {
872 tasklet_schedule(&p_ch
->tasklet
);
875 CLAW_DBF_TEXT(4,trace
,"PCINoBH");
878 printk(KERN_INFO
"%s:%s Exit on line %d\n",
879 dev
->name
,__FUNCTION__
,__LINE__
);
881 CLAW_DBF_TEXT(4,trace
,"PCI_read");
884 if(!((p_ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
885 (p_ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
886 (p_ch
->irb
->scsw
.stctl
==
887 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
889 printk(KERN_INFO
"%s:%s Exit on line %d\n",
890 dev
->name
,__FUNCTION__
,__LINE__
);
892 CLAW_DBF_TEXT(4,trace
,"SPend_rd");
895 clear_bit(0, (void *)&p_ch
->IO_active
);
896 claw_clearbit_busy(TB_RETRY
,dev
);
897 if (test_and_set_bit(CLAW_BH_ACTIVE
,
898 (void *)&p_ch
->flag_a
) == 0) {
899 tasklet_schedule(&p_ch
->tasklet
);
902 CLAW_DBF_TEXT(4,trace
,"RdBHAct");
906 printk(KERN_INFO
"%s: process CLAW_START_READ exit\n",
910 printk(KERN_INFO
"%s:%s Exit on line %d\n",
911 dev
->name
,__FUNCTION__
,__LINE__
);
913 CLAW_DBF_TEXT(4,trace
,"RdIRQXit");
915 case CLAW_START_WRITE
:
916 if (p_ch
->irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) {
917 printk(KERN_INFO
"%s: Unit Check Occured in "
918 "write channel\n",dev
->name
);
919 clear_bit(0, (void *)&p_ch
->IO_active
);
920 if (p_ch
->irb
->ecw
[0] & 0x80 ) {
921 printk(KERN_INFO
"%s: Resetting Event "
922 "occurred:\n",dev
->name
);
923 init_timer(&p_ch
->timer
);
924 p_ch
->timer
.function
=
925 (void *)claw_write_retry
;
926 p_ch
->timer
.data
= (unsigned long)p_ch
;
927 p_ch
->timer
.expires
= jiffies
+ 10*HZ
;
928 add_timer(&p_ch
->timer
);
929 printk(KERN_INFO
"%s: write connection "
930 "restarting\n",dev
->name
);
933 printk(KERN_INFO
"%s:%s Exit on line %d\n",
934 dev
->name
,__FUNCTION__
,__LINE__
);
936 CLAW_DBF_TEXT(4,trace
,"rstrtwrt");
939 if (p_ch
->irb
->scsw
.dstat
& DEV_STAT_UNIT_EXCEP
) {
940 clear_bit(0, (void *)&p_ch
->IO_active
);
941 printk(KERN_INFO
"%s: Unit Exception "
942 "Occured in write channel\n",
945 if(!((p_ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
946 (p_ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
947 (p_ch
->irb
->scsw
.stctl
==
948 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
950 printk(KERN_INFO
"%s:%s Exit on line %d\n",
951 dev
->name
,__FUNCTION__
,__LINE__
);
953 CLAW_DBF_TEXT(4,trace
,"writeUE");
956 clear_bit(0, (void *)&p_ch
->IO_active
);
957 if (claw_test_and_setbit_busy(TB_TX
,dev
)==0) {
958 claw_write_next(p_ch
);
959 claw_clearbit_busy(TB_TX
,dev
);
960 claw_clear_busy(dev
);
962 p_ch_r
=(struct chbk
*)&privptr
->channel
[READ
];
963 if (test_and_set_bit(CLAW_BH_ACTIVE
,
964 (void *)&p_ch_r
->flag_a
) == 0) {
965 tasklet_schedule(&p_ch_r
->tasklet
);
969 printk(KERN_INFO
"%s: process CLAW_START_WRITE exit\n",
973 printk(KERN_INFO
"%s:%s Exit on line %d\n",
974 dev
->name
,__FUNCTION__
,__LINE__
);
976 CLAW_DBF_TEXT(4,trace
,"StWtExit");
979 printk(KERN_WARNING
"%s: wrong selection code - irq "
980 "state=%d\n",dev
->name
,p_ch
->claw_state
);
982 printk(KERN_INFO
"%s:%s Exit on line %d\n",
983 dev
->name
,__FUNCTION__
,__LINE__
);
985 CLAW_DBF_TEXT(2,trace
,"badIRQ");
989 } /* end of claw_irq_handler */
992 /*-------------------------------------------------------------------*
995 *--------------------------------------------------------------------*/
997 claw_irq_tasklet ( unsigned long data
)
1000 struct net_device
*dev
;
1001 struct claw_privbk
* privptr
;
1003 p_ch
= (struct chbk
*) data
;
1004 dev
= (struct net_device
*)p_ch
->ndev
;
1006 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
1009 printk(KERN_INFO
"%s: variable p_ch =\n",dev
->name
);
1010 dumpit((char *) p_ch
, sizeof(struct chbk
));
1012 CLAW_DBF_TEXT(4,trace
,"IRQtask");
1014 privptr
= (struct claw_privbk
*) dev
->priv
;
1017 printk(KERN_INFO
"%s: bh routine - state-%02x\n" ,
1018 dev
->name
, p_ch
->claw_state
);
1022 clear_bit(CLAW_BH_ACTIVE
, (void *)&p_ch
->flag_a
);
1023 CLAW_DBF_TEXT(4,trace
,"TskletXt");
1025 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1026 dev
->name
,__FUNCTION__
,__LINE__
);
1029 } /* end of claw_irq_bh */
1031 /*-------------------------------------------------------------------*
1034 *--------------------------------------------------------------------*/
1036 claw_release(struct net_device
*dev
)
1040 unsigned long saveflags
;
1042 struct claw_privbk
*privptr
;
1043 DECLARE_WAITQUEUE(wait
, current
);
1044 struct ccwbk
* p_this_ccw
;
1045 struct ccwbk
* p_buf
;
1049 privptr
= (struct claw_privbk
*) dev
->priv
;
1053 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
1055 CLAW_DBF_TEXT(4,trace
,"release");
1057 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
1058 dumpit((char *) dev
, sizeof(struct net_device
));
1059 printk(KERN_INFO
"Priv Buffalloc %d\n",privptr
->buffs_alloc
);
1060 printk(KERN_INFO
"Priv p_buff_ccw = %p\n",&privptr
->p_buff_ccw
);
1062 privptr
->release_pend
=1;
1063 claw_setbit_busy(TB_STOP
,dev
);
1064 for ( i
= 1; i
>=0 ; i
--) {
1066 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
1067 /* del_timer(&privptr->channel[READ].timer); */
1068 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
1069 privptr
->channel
[i
].IO_active
= 0;
1070 parm
= (unsigned long) &privptr
->channel
[i
];
1072 claw_purge_skb_queue(
1073 &privptr
->channel
[WRITE
].collect_queue
);
1074 rc
= ccw_device_halt (privptr
->channel
[i
].cdev
, parm
);
1075 if (privptr
->system_validate_comp
==0x00) /* never opened? */
1076 init_waitqueue_head(&privptr
->channel
[i
].wait
);
1077 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
1078 set_current_state(TASK_INTERRUPTIBLE
);
1079 spin_unlock_irqrestore(
1080 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
1082 set_current_state(TASK_RUNNING
);
1083 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
1085 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
1088 if (privptr
->pk_skb
!= NULL
) {
1089 dev_kfree_skb_any(privptr
->pk_skb
);
1090 privptr
->pk_skb
= NULL
;
1092 if(privptr
->buffs_alloc
!= 1) {
1094 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1095 dev
->name
,__FUNCTION__
,__LINE__
);
1097 CLAW_DBF_TEXT(4,trace
,"none2fre");
1100 CLAW_DBF_TEXT(4,trace
,"freebufs");
1101 if (privptr
->p_buff_ccw
!= NULL
) {
1102 free_pages((unsigned long)privptr
->p_buff_ccw
,
1103 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
1105 CLAW_DBF_TEXT(4,trace
,"freeread");
1106 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1107 if (privptr
->p_buff_read
!= NULL
) {
1108 free_pages((unsigned long)privptr
->p_buff_read
,
1109 (int)pages_to_order_of_mag(privptr
->p_buff_read_num
));
1113 p_buf
=privptr
->p_read_active_first
;
1114 while (p_buf
!=NULL
) {
1115 free_pages((unsigned long)p_buf
->p_buffer
,
1116 (int)pages_to_order_of_mag(
1117 privptr
->p_buff_pages_perread
));
1121 CLAW_DBF_TEXT(4,trace
,"freewrit");
1122 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1123 free_pages((unsigned long)privptr
->p_buff_write
,
1124 (int)pages_to_order_of_mag(privptr
->p_buff_write_num
));
1127 p_buf
=privptr
->p_write_active_first
;
1128 while (p_buf
!=NULL
) {
1129 free_pages((unsigned long)p_buf
->p_buffer
,
1130 (int)pages_to_order_of_mag(
1131 privptr
->p_buff_pages_perwrite
));
1135 CLAW_DBF_TEXT(4,trace
,"clearptr");
1136 privptr
->buffs_alloc
= 0;
1137 privptr
->p_buff_ccw
=NULL
;
1138 privptr
->p_buff_read
=NULL
;
1139 privptr
->p_buff_write
=NULL
;
1140 privptr
->system_validate_comp
=0;
1141 privptr
->release_pend
=0;
1142 /* Remove any writes that were pending and reset all reads */
1143 p_this_ccw
=privptr
->p_read_active_first
;
1144 while (p_this_ccw
!=NULL
) {
1145 p_this_ccw
->header
.length
=0xffff;
1146 p_this_ccw
->header
.opcode
=0xff;
1147 p_this_ccw
->header
.flag
=0x00;
1148 p_this_ccw
=p_this_ccw
->next
;
1151 while (privptr
->p_write_active_first
!=NULL
) {
1152 p_this_ccw
=privptr
->p_write_active_first
;
1153 p_this_ccw
->header
.flag
=CLAW_PENDING
;
1154 privptr
->p_write_active_first
=p_this_ccw
->next
;
1155 p_this_ccw
->next
=privptr
->p_write_free_chain
;
1156 privptr
->p_write_free_chain
=p_this_ccw
;
1157 ++privptr
->write_free_count
;
1159 privptr
->p_write_active_last
=NULL
;
1160 privptr
->mtc_logical_link
= -1;
1161 privptr
->mtc_skipping
= 1;
1162 privptr
->mtc_offset
=0;
1164 if (((privptr
->channel
[READ
].last_dstat
|
1165 privptr
->channel
[WRITE
].last_dstat
) &
1166 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) {
1167 printk(KERN_WARNING
"%s: channel problems during close - "
1168 "read: %02x - write: %02x\n",
1170 privptr
->channel
[READ
].last_dstat
,
1171 privptr
->channel
[WRITE
].last_dstat
);
1172 CLAW_DBF_TEXT(2,trace
,"badclose");
1175 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1176 dev
->name
,__FUNCTION__
,__LINE__
);
1178 CLAW_DBF_TEXT(4,trace
,"rlsexit");
1180 } /* end of claw_release */
1184 /*-------------------------------------------------------------------*
1185 * claw_write_retry *
1187 *--------------------------------------------------------------------*/
1190 claw_write_retry ( struct chbk
*p_ch
)
1193 struct net_device
*dev
=p_ch
->ndev
;
1197 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
1198 printk(KERN_INFO
"claw: variable p_ch =\n");
1199 dumpit((char *) p_ch
, sizeof(struct chbk
));
1201 CLAW_DBF_TEXT(4,trace
,"w_retry");
1202 if (p_ch
->claw_state
== CLAW_STOP
) {
1204 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1205 dev
->name
,__FUNCTION__
,__LINE__
);
1210 printk( KERN_INFO
"%s:%s state-%02x\n" ,
1215 claw_strt_out_IO( dev
);
1217 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1218 dev
->name
,__FUNCTION__
,__LINE__
);
1220 CLAW_DBF_TEXT(4,trace
,"rtry_xit");
1222 } /* end of claw_write_retry */
1225 /*-------------------------------------------------------------------*
1228 *--------------------------------------------------------------------*/
1231 claw_write_next ( struct chbk
* p_ch
)
1234 struct net_device
*dev
;
1235 struct claw_privbk
*privptr
=NULL
;
1236 struct sk_buff
*pk_skb
;
1240 printk(KERN_INFO
"%s:%s Enter \n",p_ch
->ndev
->name
,__FUNCTION__
);
1241 printk(KERN_INFO
"%s: variable p_ch =\n",p_ch
->ndev
->name
);
1242 dumpit((char *) p_ch
, sizeof(struct chbk
));
1244 CLAW_DBF_TEXT(4,trace
,"claw_wrt");
1245 if (p_ch
->claw_state
== CLAW_STOP
)
1247 dev
= (struct net_device
*) p_ch
->ndev
;
1248 privptr
= (struct claw_privbk
*) dev
->priv
;
1249 claw_free_wrt_buf( dev
);
1250 if ((privptr
->write_free_count
> 0) &&
1251 !skb_queue_empty(&p_ch
->collect_queue
)) {
1252 pk_skb
= claw_pack_skb(privptr
);
1253 while (pk_skb
!= NULL
) {
1254 rc
= claw_hw_tx( pk_skb
, dev
,1);
1255 if (privptr
->write_free_count
> 0) {
1256 pk_skb
= claw_pack_skb(privptr
);
1261 if (privptr
->p_write_active_first
!=NULL
) {
1262 claw_strt_out_IO(dev
);
1266 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1267 dev
->name
,__FUNCTION__
,__LINE__
);
1270 } /* end of claw_write_next */
1272 /*-------------------------------------------------------------------*
1275 *--------------------------------------------------------------------*/
1278 claw_timer ( struct chbk
* p_ch
)
1281 printk(KERN_INFO
"%s:%s Entry\n",p_ch
->ndev
->name
,__FUNCTION__
);
1282 printk(KERN_INFO
"%s: variable p_ch =\n",p_ch
->ndev
->name
);
1283 dumpit((char *) p_ch
, sizeof(struct chbk
));
1285 CLAW_DBF_TEXT(4,trace
,"timer");
1286 p_ch
->flag
|= CLAW_TIMER
;
1287 wake_up(&p_ch
->wait
);
1289 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1290 p_ch
->ndev
->name
,__FUNCTION__
,__LINE__
);
1293 } /* end of claw_timer */
1302 /*-------------------------------------------------------------------*
1304 * pages_to_order_of_mag *
1306 * takes a number of pages from 1 to 512 and returns the *
1307 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1308 * of magnitude get_free_pages() has an upper order of 9 *
1309 *--------------------------------------------------------------------*/
1312 pages_to_order_of_mag(int num_of_pages
)
1314 int order_of_mag
=1; /* assume 2 pages */
1317 printk(KERN_INFO
"%s Enter pages = %d \n",__FUNCTION__
,num_of_pages
);
1319 CLAW_DBF_TEXT_(5,trace
,"pages%d",num_of_pages
);
1320 if (num_of_pages
== 1) {return 0; } /* magnitude of 0 = 1 page */
1321 /* 512 pages = 2Meg on 4k page systems */
1322 if (num_of_pages
>= 512) {return 9; }
1323 /* we have two or more pages order is at least 1 */
1324 for (nump
=2 ;nump
<= 512;nump
*=2) {
1325 if (num_of_pages
<= nump
)
1329 if (order_of_mag
> 9) { order_of_mag
= 9; } /* I know it's paranoid */
1331 printk(KERN_INFO
"%s Exit on line %d, order = %d\n",
1332 __FUNCTION__
,__LINE__
, order_of_mag
);
1334 CLAW_DBF_TEXT_(5,trace
,"mag%d",order_of_mag
);
1335 return order_of_mag
;
1338 /*-------------------------------------------------------------------*
1342 *--------------------------------------------------------------------*/
1344 add_claw_reads(struct net_device
*dev
, struct ccwbk
* p_first
,
1345 struct ccwbk
* p_last
)
1347 struct claw_privbk
*privptr
;
1348 struct ccw1 temp_ccw
;
1349 struct endccw
* p_end
;
1351 struct ccwbk
* p_buf
;
1354 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
1357 printk(KERN_INFO
"dev\n");
1358 dumpit((char *) dev
, sizeof(struct net_device
));
1359 printk(KERN_INFO
"p_first\n");
1360 dumpit((char *) p_first
, sizeof(struct ccwbk
));
1361 printk(KERN_INFO
"p_last\n");
1362 dumpit((char *) p_last
, sizeof(struct ccwbk
));
1364 CLAW_DBF_TEXT(4,trace
,"addreads");
1365 privptr
= dev
->priv
;
1366 p_end
= privptr
->p_end_ccw
;
1368 /* first CCW and last CCW contains a new set of read channel programs
1369 * to apend the running channel programs
1371 if ( p_first
==NULL
) {
1373 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1374 dev
->name
,__FUNCTION__
,__LINE__
);
1376 CLAW_DBF_TEXT(4,trace
,"addexit");
1380 /* set up ending CCW sequence for this segment */
1382 p_end
->read1
=0x00; /* second ending CCW is now active */
1383 /* reset ending CCWs and setup TIC CCWs */
1384 p_end
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1385 p_end
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1386 p_last
->r_TIC_1
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1387 p_last
->r_TIC_2
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1388 p_end
->read2_nop2
.cda
=0;
1389 p_end
->read2_nop2
.count
=1;
1392 p_end
->read1
=0x01; /* first ending CCW is now active */
1393 /* reset ending CCWs and setup TIC CCWs */
1394 p_end
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1395 p_end
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1396 p_last
->r_TIC_1
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1397 p_last
->r_TIC_2
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1398 p_end
->read1_nop2
.cda
=0;
1399 p_end
->read1_nop2
.count
=1;
1402 if ( privptr
-> p_read_active_first
==NULL
) {
1404 printk(KERN_INFO
"%s:%s p_read_active_first == NULL \n",
1405 dev
->name
,__FUNCTION__
);
1406 printk(KERN_INFO
"%s:%s Read active first/last changed \n",
1407 dev
->name
,__FUNCTION__
);
1409 privptr
-> p_read_active_first
= p_first
; /* set new first */
1410 privptr
-> p_read_active_last
= p_last
; /* set new last */
1415 printk(KERN_INFO
"%s:%s Read in progress \n",
1416 dev
->name
,__FUNCTION__
);
1418 /* set up TIC ccw */
1419 temp_ccw
.cda
= (__u32
)__pa(&p_first
->read
);
1422 temp_ccw
.cmd_code
= CCW_CLAW_CMD_TIC
;
1427 /* first set of CCW's is chained to the new read */
1428 /* chain, so the second set is chained to the active chain. */
1429 /* Therefore modify the second set to point to the new */
1430 /* read chain set up TIC CCWs */
1431 /* make sure we update the CCW so channel doesn't fetch it */
1432 /* when it's only half done */
1433 memcpy( &p_end
->read2_nop2
, &temp_ccw
,
1434 sizeof(struct ccw1
));
1435 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1436 (__u32
)__pa(&p_first
->read
);
1437 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1438 (__u32
)__pa(&p_first
->read
);
1441 /* make sure we update the CCW so channel doesn't */
1442 /* fetch it when it is only half done */
1443 memcpy( &p_end
->read1_nop2
, &temp_ccw
,
1444 sizeof(struct ccw1
));
1445 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1446 (__u32
)__pa(&p_first
->read
);
1447 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1448 (__u32
)__pa(&p_first
->read
);
1450 /* chain in new set of blocks */
1451 privptr
->p_read_active_last
->next
= p_first
;
1452 privptr
->p_read_active_last
=p_last
;
1453 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1455 printk(KERN_INFO
"%s:%s dump p_last CCW BK \n",dev
->name
,__FUNCTION__
);
1456 dumpit((char *)p_last
, sizeof(struct ccwbk
));
1457 printk(KERN_INFO
"%s:%s dump p_end CCW BK \n",dev
->name
,__FUNCTION__
);
1458 dumpit((char *)p_end
, sizeof(struct endccw
));
1460 printk(KERN_INFO
"%s:%s dump p_first CCW BK \n",dev
->name
,__FUNCTION__
);
1461 dumpit((char *)p_first
, sizeof(struct ccwbk
));
1462 printk(KERN_INFO
"%s:%s Dump Active CCW chain \n",
1463 dev
->name
,__FUNCTION__
);
1464 p_buf
=privptr
->p_read_active_first
;
1465 while (p_buf
!=NULL
) {
1466 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
1471 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1472 dev
->name
,__FUNCTION__
,__LINE__
);
1474 CLAW_DBF_TEXT(4,trace
,"addexit");
1476 } /* end of add_claw_reads */
1478 /*-------------------------------------------------------------------*
1479 * ccw_check_return_code *
1481 *-------------------------------------------------------------------*/
1484 ccw_check_return_code(struct ccw_device
*cdev
, int return_code
)
1487 printk(KERN_INFO
"%s: %s() > enter \n",
1488 cdev
->dev
.bus_id
,__FUNCTION__
);
1490 CLAW_DBF_TEXT(4,trace
,"ccwret");
1492 printk(KERN_INFO
"variable cdev =\n");
1493 dumpit((char *) cdev
, sizeof(struct ccw_device
));
1494 printk(KERN_INFO
"variable return_code = %d\n",return_code
);
1496 if (return_code
!= 0) {
1497 switch (return_code
) {
1499 printk(KERN_INFO
"%s: Busy !\n",
1503 printk(KERN_EMERG
"%s: Missing device called "
1504 "for IO ENODEV\n", cdev
->dev
.bus_id
);
1507 printk(KERN_EMERG
"%s: Status pending... EIO \n",
1511 printk(KERN_EMERG
"%s: Invalid Dev State EINVAL \n",
1515 printk(KERN_EMERG
"%s: Unknown error in "
1516 "Do_IO %d\n",cdev
->dev
.bus_id
, return_code
);
1520 printk(KERN_INFO
"%s: %s() > exit on line %d\n",
1521 cdev
->dev
.bus_id
,__FUNCTION__
,__LINE__
);
1523 CLAW_DBF_TEXT(4,trace
,"ccwret");
1524 } /* end of ccw_check_return_code */
1526 /*-------------------------------------------------------------------*
1527 * ccw_check_unit_check *
1528 *--------------------------------------------------------------------*/
1531 ccw_check_unit_check(struct chbk
* p_ch
, unsigned char sense
)
1533 struct net_device
*dev
= p_ch
->ndev
;
1536 printk(KERN_INFO
"%s: %s() > enter\n",dev
->name
,__FUNCTION__
);
1539 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
1540 dumpit((char *)dev
, sizeof(struct net_device
));
1541 printk(KERN_INFO
"%s: variable sense =\n",dev
->name
);
1542 dumpit((char *)&sense
, 2);
1544 CLAW_DBF_TEXT(4,trace
,"unitchek");
1546 printk(KERN_INFO
"%s: Unit Check with sense byte:0x%04x\n",
1551 printk(KERN_WARNING
"%s: Interface disconnect or "
1553 "occurred (remote side)\n", dev
->name
);
1556 printk(KERN_WARNING
"%s: System reset occured"
1557 " (remote side)\n", dev
->name
);
1560 else if (sense
& 0x20) {
1562 printk(KERN_WARNING
"%s: Data-streaming "
1563 "timeout)\n", dev
->name
);
1566 printk(KERN_WARNING
"%s: Data-transfer parity"
1567 " error\n", dev
->name
);
1570 else if (sense
& 0x10) {
1572 printk(KERN_WARNING
"%s: Hardware malfunction "
1573 "(remote side)\n", dev
->name
);
1576 printk(KERN_WARNING
"%s: read-data parity error "
1577 "(remote side)\n", dev
->name
);
1582 printk(KERN_INFO
"%s: %s() exit on line %d\n",
1583 dev
->name
,__FUNCTION__
,__LINE__
);
1585 } /* end of ccw_check_unit_check */
1589 /*-------------------------------------------------------------------*
1590 * Dump buffer format *
1592 *--------------------------------------------------------------------*/
1595 dumpit(char* buf
, int len
)
1598 __u32 ct
, sw
, rm
, dup
;
1600 char tbuf
[82], tdup
[82];
1607 char bhex
[82], duphex
[82];
1615 for ( ct
=0; ct
< len
; ct
++, ptr
++, rptr
++ ) {
1618 sprintf(addr
, "%16.16lX",(unsigned long)rptr
);
1620 sprintf(addr
, "%8.8X",(__u32
)rptr
);
1622 sprintf(boff
, "%4.4X", (__u32
)ct
);
1626 if ((sw
== 4) || (sw
== 12)) {
1633 sprintf(tbuf
,"%2.2lX", (unsigned long)*ptr
);
1635 sprintf(tbuf
,"%2.2X", (__u32
)*ptr
);
1639 if ((0!=isprint(*ptr
)) && (*ptr
>= 0x20)) {
1649 if ((strcmp(duphex
, bhex
)) !=0) {
1651 sprintf(tdup
,"Duplicate as above to"
1653 printk( KERN_INFO
" "
1654 " --- %s ---\n",tdup
);
1656 printk( KERN_INFO
" %s (+%s) : %s [%s]\n",
1657 addr
, boff
, bhex
, basc
);
1659 strcpy(duphex
, bhex
);
1670 for ( ; rm
> 0; rm
--, sw
++ ) {
1671 if ((sw
==4) || (sw
==12)) strcat(bhex
, " ");
1672 if (sw
==8) strcat(bhex
, " ");
1677 sprintf(tdup
,"Duplicate as above to %s", addr
);
1678 printk( KERN_INFO
" --- %s ---\n",
1681 printk( KERN_INFO
" %s (+%s) : %s [%s]\n",
1682 addr
, boff
, bhex
, basc
);
1686 sprintf(tdup
,"Duplicate as above to %s", addr
);
1687 printk( KERN_INFO
" --- %s ---\n",
1691 printk( KERN_INFO
" %s (+%s) : %s [%s]\n",
1692 addr
, boff
, bhex
, basc
);
1697 } /* end of dumpit */
1700 /*-------------------------------------------------------------------*
1702 *--------------------------------------------------------------------*/
1704 find_link(struct net_device
*dev
, char *host_name
, char *ws_name
)
1706 struct claw_privbk
*privptr
;
1707 struct claw_env
*p_env
;
1711 printk(KERN_INFO
"%s:%s > enter \n",dev
->name
,__FUNCTION__
);
1713 CLAW_DBF_TEXT(2,setup
,"findlink");
1715 printk(KERN_INFO
"%s: variable dev = \n",dev
->name
);
1716 dumpit((char *) dev
, sizeof(struct net_device
));
1717 printk(KERN_INFO
"%s: variable host_name = %s\n",dev
->name
, host_name
);
1718 printk(KERN_INFO
"%s: variable ws_name = %s\n",dev
->name
, ws_name
);
1721 p_env
=privptr
->p_env
;
1722 switch (p_env
->packing
)
1725 if ((memcmp(WS_APPL_NAME_PACKED
, host_name
, 8)!=0) ||
1726 (memcmp(WS_APPL_NAME_PACKED
, ws_name
, 8)!=0 ))
1731 if ((memcmp(WS_APPL_NAME_IP_NAME
, host_name
, 8)!=0) ||
1732 (memcmp(WS_APPL_NAME_IP_NAME
, ws_name
, 8)!=0 ))
1736 if ((memcmp(HOST_APPL_NAME
, host_name
, 8)!=0) ||
1737 (memcmp(p_env
->api_type
, ws_name
, 8)!=0))
1743 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1744 dev
->name
,__FUNCTION__
,__LINE__
);
1747 } /* end of find_link */
1749 /*-------------------------------------------------------------------*
1753 *-------------------------------------------------------------------*/
1756 claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
)
1759 struct claw_privbk
*privptr
;
1760 struct ccwbk
*p_this_ccw
;
1761 struct ccwbk
*p_first_ccw
;
1762 struct ccwbk
*p_last_ccw
;
1764 signed long len_of_data
;
1765 unsigned long bytesInThisBuffer
;
1766 unsigned char *pDataAddress
;
1767 struct endccw
*pEnd
;
1768 struct ccw1 tempCCW
;
1770 struct claw_env
*p_env
;
1772 struct clawph
*pk_head
;
1775 struct ccwbk
*p_buf
;
1778 printk(KERN_INFO
"%s: %s() > enter\n",dev
->name
,__FUNCTION__
);
1780 CLAW_DBF_TEXT(4,trace
,"hw_tx");
1782 printk(KERN_INFO
"%s: variable dev skb =\n",dev
->name
);
1783 dumpit((char *) skb
, sizeof(struct sk_buff
));
1784 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
1785 dumpit((char *) dev
, sizeof(struct net_device
));
1786 printk(KERN_INFO
"%s: variable linkid = %ld\n",dev
->name
,linkid
);
1788 privptr
= (struct claw_privbk
*) (dev
->priv
);
1789 p_ch
=(struct chbk
*)&privptr
->channel
[WRITE
];
1790 p_env
=privptr
->p_env
;
1792 printk(KERN_INFO
"%s: %s() dump sk_buff \n",dev
->name
,__FUNCTION__
);
1793 dumpit((char *)skb
,sizeof(struct sk_buff
));
1795 claw_free_wrt_buf(dev
); /* Clean up free chain if posible */
1796 /* scan the write queue to free any completed write packets */
1799 if ((p_env
->packing
>= PACK_SEND
) &&
1800 (skb
->cb
[1] != 'P')) {
1801 skb_push(skb
,sizeof(struct clawph
));
1802 pk_head
=(struct clawph
*)skb
->data
;
1803 pk_head
->len
=skb
->len
-sizeof(struct clawph
);
1804 if (pk_head
->len
%4) {
1805 pk_head
->len
+= 4-(pk_head
->len
%4);
1806 skb_pad(skb
,4-(pk_head
->len
%4));
1807 skb_put(skb
,4-(pk_head
->len
%4));
1809 if (p_env
->packing
== DO_PACKED
)
1810 pk_head
->link_num
= linkid
;
1812 pk_head
->link_num
= 0;
1813 pk_head
->flag
= 0x00;
1818 if (claw_check_busy(dev
)) {
1819 if (privptr
->write_free_count
!=0) {
1820 claw_clear_busy(dev
);
1823 claw_strt_out_IO(dev
);
1824 claw_free_wrt_buf( dev
);
1825 if (privptr
->write_free_count
==0) {
1827 printk(KERN_INFO
"%s: "
1828 "(claw_check_busy) no free write "
1829 "buffers\n", dev
->name
);
1831 ch
= &privptr
->channel
[WRITE
];
1832 atomic_inc(&skb
->users
);
1833 skb_queue_tail(&ch
->collect_queue
, skb
);
1837 claw_clear_busy(dev
);
1842 if (claw_test_and_setbit_busy(TB_TX
,dev
)) { /* set to busy */
1844 printk(KERN_INFO
"%s: busy (claw_test_and_setbit_"
1845 "busy)\n", dev
->name
);
1847 ch
= &privptr
->channel
[WRITE
];
1848 atomic_inc(&skb
->users
);
1849 skb_queue_tail(&ch
->collect_queue
, skb
);
1850 claw_strt_out_IO(dev
);
1855 /* See how many write buffers are required to hold this data */
1856 numBuffers
= ( skb
->len
+ privptr
->p_env
->write_size
- 1) /
1857 ( privptr
->p_env
->write_size
);
1859 /* If that number of buffers isn't available, give up for now */
1860 if (privptr
->write_free_count
< numBuffers
||
1861 privptr
->p_write_free_chain
== NULL
) {
1863 claw_setbit_busy(TB_NOBUFFER
,dev
);
1866 printk(KERN_INFO
"%s: busy (claw_setbit_busy"
1867 "(TB_NOBUFFER))\n", dev
->name
);
1868 printk(KERN_INFO
" free_count: %d, numBuffers : %d\n",
1869 (int)privptr
->write_free_count
,(int) numBuffers
);
1871 ch
= &privptr
->channel
[WRITE
];
1872 atomic_inc(&skb
->users
);
1873 skb_queue_tail(&ch
->collect_queue
, skb
);
1874 CLAW_DBF_TEXT(2,trace
,"clawbusy");
1877 pDataAddress
=skb
->data
;
1878 len_of_data
=skb
->len
;
1880 while (len_of_data
> 0) {
1882 printk(KERN_INFO
"%s: %s() length-of-data is %ld \n",
1883 dev
->name
,__FUNCTION__
,len_of_data
);
1884 dumpit((char *)pDataAddress
,64);
1886 p_this_ccw
=privptr
->p_write_free_chain
; /* get a block */
1887 if (p_this_ccw
== NULL
) { /* lost the race */
1888 ch
= &privptr
->channel
[WRITE
];
1889 atomic_inc(&skb
->users
);
1890 skb_queue_tail(&ch
->collect_queue
, skb
);
1893 privptr
->p_write_free_chain
=p_this_ccw
->next
;
1894 p_this_ccw
->next
=NULL
;
1895 --privptr
->write_free_count
; /* -1 */
1896 bytesInThisBuffer
=len_of_data
;
1897 memcpy( p_this_ccw
->p_buffer
,pDataAddress
, bytesInThisBuffer
);
1898 len_of_data
-=bytesInThisBuffer
;
1899 pDataAddress
+=(unsigned long)bytesInThisBuffer
;
1900 /* setup write CCW */
1901 p_this_ccw
->write
.cmd_code
= (linkid
* 8) +1;
1902 if (len_of_data
>0) {
1903 p_this_ccw
->write
.cmd_code
+=MORE_to_COME_FLAG
;
1905 p_this_ccw
->write
.count
=bytesInThisBuffer
;
1906 /* now add to end of this chain */
1907 if (p_first_ccw
==NULL
) {
1908 p_first_ccw
=p_this_ccw
;
1910 if (p_last_ccw
!=NULL
) {
1911 p_last_ccw
->next
=p_this_ccw
;
1912 /* set up TIC ccws */
1913 p_last_ccw
->w_TIC_1
.cda
=
1914 (__u32
)__pa(&p_this_ccw
->write
);
1916 p_last_ccw
=p_this_ccw
; /* save new last block */
1918 printk(KERN_INFO
"%s: %s() > CCW and Buffer %ld bytes long \n",
1919 dev
->name
,__FUNCTION__
,bytesInThisBuffer
);
1920 dumpit((char *)p_this_ccw
, sizeof(struct ccwbk
));
1921 dumpit((char *)p_this_ccw
->p_buffer
, 64);
1925 /* FirstCCW and LastCCW now contain a new set of write channel
1926 * programs to append to the running channel program
1929 if (p_first_ccw
!=NULL
) {
1930 /* setup ending ccw sequence for this segment */
1931 pEnd
=privptr
->p_end_ccw
;
1933 pEnd
->write1
=0x00; /* second end ccw is now active */
1934 /* set up Tic CCWs */
1935 p_last_ccw
->w_TIC_1
.cda
=
1936 (__u32
)__pa(&pEnd
->write2_nop1
);
1937 pEnd
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1938 pEnd
->write2_nop2
.flags
=
1939 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1940 pEnd
->write2_nop2
.cda
=0;
1941 pEnd
->write2_nop2
.count
=1;
1943 else { /* end of if (pEnd->write1)*/
1944 pEnd
->write1
=0x01; /* first end ccw is now active */
1945 /* set up Tic CCWs */
1946 p_last_ccw
->w_TIC_1
.cda
=
1947 (__u32
)__pa(&pEnd
->write1_nop1
);
1948 pEnd
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1949 pEnd
->write1_nop2
.flags
=
1950 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1951 pEnd
->write1_nop2
.cda
=0;
1952 pEnd
->write1_nop2
.count
=1;
1953 } /* end if if (pEnd->write1) */
1956 if (privptr
->p_write_active_first
==NULL
) {
1957 privptr
->p_write_active_first
=p_first_ccw
;
1958 privptr
->p_write_active_last
=p_last_ccw
;
1962 /* set up Tic CCWs */
1964 tempCCW
.cda
=(__u32
)__pa(&p_first_ccw
->write
);
1967 tempCCW
.cmd_code
=CCW_CLAW_CMD_TIC
;
1972 * first set of ending CCW's is chained to the new write
1973 * chain, so the second set is chained to the active chain
1974 * Therefore modify the second set to point the new write chain.
1975 * make sure we update the CCW atomically
1976 * so channel does not fetch it when it's only half done
1978 memcpy( &pEnd
->write2_nop2
, &tempCCW
,
1979 sizeof(struct ccw1
));
1980 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1981 (__u32
)__pa(&p_first_ccw
->write
);
1985 /*make sure we update the CCW atomically
1986 *so channel does not fetch it when it's only half done
1988 memcpy(&pEnd
->write1_nop2
, &tempCCW
,
1989 sizeof(struct ccw1
));
1990 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1991 (__u32
)__pa(&p_first_ccw
->write
);
1993 } /* end if if (pEnd->write1) */
1995 privptr
->p_write_active_last
->next
=p_first_ccw
;
1996 privptr
->p_write_active_last
=p_last_ccw
;
1999 } /* endif (p_first_ccw!=NULL) */
2003 printk(KERN_INFO
"%s: %s() > Dump Active CCW chain \n",
2004 dev
->name
,__FUNCTION__
);
2005 p_buf
=privptr
->p_write_active_first
;
2006 while (p_buf
!=NULL
) {
2007 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
2010 p_buf
=(struct ccwbk
*)privptr
->p_end_ccw
;
2011 dumpit((char *)p_buf
, sizeof(struct endccw
));
2013 dev_kfree_skb_any(skb
);
2020 claw_strt_out_IO(dev
);
2021 /* if write free count is zero , set NOBUFFER */
2023 printk(KERN_INFO
"%s: %s() > free_count is %d\n",
2024 dev
->name
,__FUNCTION__
,
2025 (int) privptr
->write_free_count
);
2027 if (privptr
->write_free_count
==0) {
2028 claw_setbit_busy(TB_NOBUFFER
,dev
);
2031 claw_clearbit_busy(TB_TX
,dev
);
2034 printk(KERN_INFO
"%s: %s() > exit on line %d, rc = %d \n",
2035 dev
->name
,__FUNCTION__
,__LINE__
, rc
);
2038 } /* end of claw_hw_tx */
2040 /*-------------------------------------------------------------------*
2044 *--------------------------------------------------------------------*/
2047 init_ccw_bk(struct net_device
*dev
)
2050 __u32 ccw_blocks_required
;
2051 __u32 ccw_blocks_perpage
;
2052 __u32 ccw_pages_required
;
2053 __u32 claw_reads_perpage
=1;
2054 __u32 claw_read_pages
;
2055 __u32 claw_writes_perpage
=1;
2056 __u32 claw_write_pages
;
2058 struct ccwbk
*p_free_chain
;
2060 struct ccwbk
*p_last_CCWB
;
2061 struct ccwbk
*p_first_CCWB
;
2062 struct endccw
*p_endccw
=NULL
;
2063 addr_t real_address
;
2064 struct claw_privbk
*privptr
=dev
->priv
;
2065 struct clawh
*pClawH
=NULL
;
2066 addr_t real_TIC_address
;
2069 printk(KERN_INFO
"%s: %s() enter \n",dev
->name
,__FUNCTION__
);
2071 CLAW_DBF_TEXT(4,trace
,"init_ccw");
2073 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
2074 dumpit((char *) dev
, sizeof(struct net_device
));
2077 /* initialize statistics field */
2078 privptr
->active_link_ID
=0;
2079 /* initialize ccwbk pointers */
2080 privptr
->p_write_free_chain
=NULL
; /* pointer to free ccw chain*/
2081 privptr
->p_write_active_first
=NULL
; /* pointer to the first write ccw*/
2082 privptr
->p_write_active_last
=NULL
; /* pointer to the last write ccw*/
2083 privptr
->p_read_active_first
=NULL
; /* pointer to the first read ccw*/
2084 privptr
->p_read_active_last
=NULL
; /* pointer to the last read ccw */
2085 privptr
->p_end_ccw
=NULL
; /* pointer to ending ccw */
2086 privptr
->p_claw_signal_blk
=NULL
; /* pointer to signal block */
2087 privptr
->buffs_alloc
= 0;
2088 memset(&privptr
->end_ccw
, 0x00, sizeof(struct endccw
));
2089 memset(&privptr
->ctl_bk
, 0x00, sizeof(struct clawctl
));
2090 /* initialize free write ccwbk counter */
2091 privptr
->write_free_count
=0; /* number of free bufs on write chain */
2095 * We need 1 CCW block for each read buffer, 1 for each
2096 * write buffer, plus 1 for ClawSignalBlock
2098 ccw_blocks_required
=
2099 privptr
->p_env
->read_buffers
+privptr
->p_env
->write_buffers
+1;
2101 printk(KERN_INFO
"%s: %s() "
2102 "ccw_blocks_required=%d\n",
2103 dev
->name
,__FUNCTION__
,
2104 ccw_blocks_required
);
2105 printk(KERN_INFO
"%s: %s() "
2107 dev
->name
,__FUNCTION__
,
2108 (unsigned int)PAGE_SIZE
);
2109 printk(KERN_INFO
"%s: %s() > "
2111 dev
->name
,__FUNCTION__
,
2112 (unsigned int)PAGE_MASK
);
2115 * compute number of CCW blocks that will fit in a page
2117 ccw_blocks_perpage
= PAGE_SIZE
/ CCWBK_SIZE
;
2119 (ccw_blocks_required
+ccw_blocks_perpage
-1) /
2123 printk(KERN_INFO
"%s: %s() > ccw_blocks_perpage=%d\n",
2124 dev
->name
,__FUNCTION__
,
2125 ccw_blocks_perpage
);
2126 printk(KERN_INFO
"%s: %s() > ccw_pages_required=%d\n",
2127 dev
->name
,__FUNCTION__
,
2128 ccw_pages_required
);
2131 * read and write sizes are set by 2 constants in claw.h
2132 * 4k and 32k. Unpacked values other than 4k are not going to
2133 * provide good performance. With packing buffers support 32k
2136 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
2137 claw_reads_perpage
= PAGE_SIZE
/ privptr
->p_env
->read_size
;
2138 claw_read_pages
= (privptr
->p_env
->read_buffers
+
2139 claw_reads_perpage
-1) / claw_reads_perpage
;
2141 else { /* > or equal */
2142 privptr
->p_buff_pages_perread
=
2143 (privptr
->p_env
->read_size
+ PAGE_SIZE
- 1) / PAGE_SIZE
;
2145 privptr
->p_env
->read_buffers
* privptr
->p_buff_pages_perread
;
2147 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
2148 claw_writes_perpage
=
2149 PAGE_SIZE
/ privptr
->p_env
->write_size
;
2151 (privptr
->p_env
->write_buffers
+ claw_writes_perpage
-1) /
2152 claw_writes_perpage
;
2155 else { /* > or equal */
2156 privptr
->p_buff_pages_perwrite
=
2157 (privptr
->p_env
->read_size
+ PAGE_SIZE
- 1) / PAGE_SIZE
;
2159 privptr
->p_env
->write_buffers
* privptr
->p_buff_pages_perwrite
;
2162 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
2163 printk(KERN_INFO
"%s: %s() reads_perpage=%d\n",
2164 dev
->name
,__FUNCTION__
,
2165 claw_reads_perpage
);
2168 printk(KERN_INFO
"%s: %s() pages_perread=%d\n",
2169 dev
->name
,__FUNCTION__
,
2170 privptr
->p_buff_pages_perread
);
2172 printk(KERN_INFO
"%s: %s() read_pages=%d\n",
2173 dev
->name
,__FUNCTION__
,
2175 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
2176 printk(KERN_INFO
"%s: %s() writes_perpage=%d\n",
2177 dev
->name
,__FUNCTION__
,
2178 claw_writes_perpage
);
2181 printk(KERN_INFO
"%s: %s() pages_perwrite=%d\n",
2182 dev
->name
,__FUNCTION__
,
2183 privptr
->p_buff_pages_perwrite
);
2185 printk(KERN_INFO
"%s: %s() write_pages=%d\n",
2186 dev
->name
,__FUNCTION__
,
2192 * allocate ccw_pages_required
2194 if (privptr
->p_buff_ccw
==NULL
) {
2195 privptr
->p_buff_ccw
=
2196 (void *)__get_free_pages(__GFP_DMA
,
2197 (int)pages_to_order_of_mag(ccw_pages_required
));
2198 if (privptr
->p_buff_ccw
==NULL
) {
2199 printk(KERN_INFO
"%s: %s() "
2200 "__get_free_pages for CCWs failed : "
2202 dev
->name
,__FUNCTION__
,
2203 ccw_pages_required
);
2205 printk(KERN_INFO
"%s: %s() > "
2206 "exit on line %d, rc = ENOMEM\n",
2207 dev
->name
,__FUNCTION__
,
2212 privptr
->p_buff_ccw_num
=ccw_pages_required
;
2214 memset(privptr
->p_buff_ccw
, 0x00,
2215 privptr
->p_buff_ccw_num
* PAGE_SIZE
);
2218 * obtain ending ccw block address
2221 privptr
->p_end_ccw
= (struct endccw
*)&privptr
->end_ccw
;
2222 real_address
= (__u32
)__pa(privptr
->p_end_ccw
);
2223 /* Initialize ending CCW block */
2225 printk(KERN_INFO
"%s: %s() begin initialize ending CCW blocks\n",
2226 dev
->name
,__FUNCTION__
);
2229 p_endccw
=privptr
->p_end_ccw
;
2230 p_endccw
->real
=real_address
;
2231 p_endccw
->write1
=0x00;
2232 p_endccw
->read1
=0x00;
2235 p_endccw
->write1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
2236 p_endccw
->write1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2237 p_endccw
->write1_nop1
.count
= 1;
2238 p_endccw
->write1_nop1
.cda
= 0;
2241 p_endccw
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
2242 p_endccw
->write1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
2243 p_endccw
->write1_nop2
.count
= 1;
2244 p_endccw
->write1_nop2
.cda
= 0;
2247 p_endccw
->write2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
2248 p_endccw
->write2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2249 p_endccw
->write2_nop1
.count
= 1;
2250 p_endccw
->write2_nop1
.cda
= 0;
2253 p_endccw
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
2254 p_endccw
->write2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
2255 p_endccw
->write2_nop2
.count
= 1;
2256 p_endccw
->write2_nop2
.cda
= 0;
2259 p_endccw
->read1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
2260 p_endccw
->read1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2261 p_endccw
->read1_nop1
.count
= 1;
2262 p_endccw
->read1_nop1
.cda
= 0;
2265 p_endccw
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
2266 p_endccw
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
2267 p_endccw
->read1_nop2
.count
= 1;
2268 p_endccw
->read1_nop2
.cda
= 0;
2271 p_endccw
->read2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
2272 p_endccw
->read2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2273 p_endccw
->read2_nop1
.count
= 1;
2274 p_endccw
->read2_nop1
.cda
= 0;
2277 p_endccw
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
2278 p_endccw
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
2279 p_endccw
->read2_nop2
.count
= 1;
2280 p_endccw
->read2_nop2
.cda
= 0;
2283 printk(KERN_INFO
"%s: %s() dump claw ending CCW BK \n",
2284 dev
->name
,__FUNCTION__
);
2285 dumpit((char *)p_endccw
, sizeof(struct endccw
));
2289 * Build a chain of CCWs
2294 printk(KERN_INFO
"%s: %s() Begin build a chain of CCW buffer \n",
2295 dev
->name
,__FUNCTION__
);
2297 p_buff
=privptr
->p_buff_ccw
;
2300 for (i
=0 ; i
< ccw_pages_required
; i
++ ) {
2301 real_address
= (__u32
)__pa(p_buff
);
2303 for (j
=0 ; j
< ccw_blocks_perpage
; j
++) {
2304 p_buf
->next
= p_free_chain
;
2305 p_free_chain
= p_buf
;
2306 p_buf
->real
=(__u32
)__pa(p_buf
);
2312 printk(KERN_INFO
"%s: %s() "
2313 "End build a chain of CCW buffer \n",
2314 dev
->name
,__FUNCTION__
);
2316 while (p_buf
!=NULL
) {
2317 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
2323 * Initialize ClawSignalBlock
2327 printk(KERN_INFO
"%s: %s() "
2328 "Begin initialize ClawSignalBlock \n",
2329 dev
->name
,__FUNCTION__
);
2331 if (privptr
->p_claw_signal_blk
==NULL
) {
2332 privptr
->p_claw_signal_blk
=p_free_chain
;
2333 p_free_chain
=p_free_chain
->next
;
2334 pClawH
=(struct clawh
*)privptr
->p_claw_signal_blk
;
2335 pClawH
->length
=0xffff;
2336 pClawH
->opcode
=0xff;
2337 pClawH
->flag
=CLAW_BUSY
;
2340 printk(KERN_INFO
"%s: %s() > End initialize "
2341 "ClawSignalBlock\n",
2342 dev
->name
,__FUNCTION__
);
2343 dumpit((char *)privptr
->p_claw_signal_blk
, sizeof(struct ccwbk
));
2347 * allocate write_pages_required and add to free chain
2349 if (privptr
->p_buff_write
==NULL
) {
2350 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
2351 privptr
->p_buff_write
=
2352 (void *)__get_free_pages(__GFP_DMA
,
2353 (int)pages_to_order_of_mag(claw_write_pages
));
2354 if (privptr
->p_buff_write
==NULL
) {
2355 printk(KERN_INFO
"%s: %s() __get_free_pages for write"
2356 " bufs failed : get is for %d pages\n",
2357 dev
->name
,__FUNCTION__
,claw_write_pages
);
2358 free_pages((unsigned long)privptr
->p_buff_ccw
,
2359 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
2360 privptr
->p_buff_ccw
=NULL
;
2362 printk(KERN_INFO
"%s: %s() > exit on line %d,"
2364 dev
->name
,__FUNCTION__
,__LINE__
);
2369 * Build CLAW write free chain
2373 memset(privptr
->p_buff_write
, 0x00,
2374 ccw_pages_required
* PAGE_SIZE
);
2376 printk(KERN_INFO
"%s: %s() Begin build claw write free "
2377 "chain \n",dev
->name
,__FUNCTION__
);
2379 privptr
->p_write_free_chain
=NULL
;
2381 p_buff
=privptr
->p_buff_write
;
2383 for (i
=0 ; i
< privptr
->p_env
->write_buffers
; i
++) {
2384 p_buf
= p_free_chain
; /* get a CCW */
2385 p_free_chain
= p_buf
->next
;
2386 p_buf
->next
=privptr
->p_write_free_chain
;
2387 privptr
->p_write_free_chain
= p_buf
;
2388 p_buf
-> p_buffer
= (struct clawbuf
*)p_buff
;
2389 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
2390 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2391 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2392 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2393 p_buf
-> w_read_FF
.count
= 1;
2394 p_buf
-> w_read_FF
.cda
=
2395 (__u32
)__pa(&p_buf
-> header
.flag
);
2396 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
2397 p_buf
-> w_TIC_1
.flags
= 0;
2398 p_buf
-> w_TIC_1
.count
= 0;
2400 if (((unsigned long)p_buff
+privptr
->p_env
->write_size
) >=
2401 ((unsigned long)(p_buff
+2*
2402 (privptr
->p_env
->write_size
) -1) & PAGE_MASK
)) {
2403 p_buff
= p_buff
+privptr
->p_env
->write_size
;
2407 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
2409 privptr
->p_write_free_chain
=NULL
;
2410 for (i
= 0; i
< privptr
->p_env
->write_buffers
; i
++) {
2411 p_buff
=(void *)__get_free_pages(__GFP_DMA
,
2412 (int)pages_to_order_of_mag(
2413 privptr
->p_buff_pages_perwrite
) );
2415 printk(KERN_INFO
"%s:%s __get_free_pages "
2416 "for writes buf: get for %d pages\n",
2417 dev
->name
,__FUNCTION__
,
2418 privptr
->p_buff_pages_perwrite
);
2421 printk(KERN_INFO
"%s:%s __get_free_pages"
2422 "for writes buf failed : get is for %d pages\n",
2425 privptr
->p_buff_pages_perwrite
);
2426 free_pages((unsigned long)privptr
->p_buff_ccw
,
2427 (int)pages_to_order_of_mag(
2428 privptr
->p_buff_ccw_num
));
2429 privptr
->p_buff_ccw
=NULL
;
2430 p_buf
=privptr
->p_buff_write
;
2431 while (p_buf
!=NULL
) {
2432 free_pages((unsigned long)
2434 (int)pages_to_order_of_mag(
2435 privptr
->p_buff_pages_perwrite
));
2439 printk(KERN_INFO
"%s: %s exit on line %d, rc = ENOMEM\n",
2445 } /* Error on get_pages */
2446 memset(p_buff
, 0x00, privptr
->p_env
->write_size
);
2447 p_buf
= p_free_chain
;
2448 p_free_chain
= p_buf
->next
;
2449 p_buf
->next
= privptr
->p_write_free_chain
;
2450 privptr
->p_write_free_chain
= p_buf
;
2451 privptr
->p_buff_write
= p_buf
;
2452 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
2453 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
2454 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2455 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2456 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2457 p_buf
-> w_read_FF
.count
= 1;
2458 p_buf
-> w_read_FF
.cda
=
2459 (__u32
)__pa(&p_buf
-> header
.flag
);
2460 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
2461 p_buf
-> w_TIC_1
.flags
= 0;
2462 p_buf
-> w_TIC_1
.count
= 0;
2463 } /* for all write_buffers */
2465 } /* else buffers are PAGE_SIZE or bigger */
2468 privptr
->p_buff_write_num
=claw_write_pages
;
2469 privptr
->write_free_count
=privptr
->p_env
->write_buffers
;
2473 printk(KERN_INFO
"%s:%s End build claw write free chain \n",
2474 dev
->name
,__FUNCTION__
);
2475 p_buf
=privptr
->p_write_free_chain
;
2476 while (p_buf
!=NULL
) {
2477 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
2482 * allocate read_pages_required and chain to free chain
2484 if (privptr
->p_buff_read
==NULL
) {
2485 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
2486 privptr
->p_buff_read
=
2487 (void *)__get_free_pages(__GFP_DMA
,
2488 (int)pages_to_order_of_mag(claw_read_pages
) );
2489 if (privptr
->p_buff_read
==NULL
) {
2490 printk(KERN_INFO
"%s: %s() "
2491 "__get_free_pages for read buf failed : "
2492 "get is for %d pages\n",
2493 dev
->name
,__FUNCTION__
,claw_read_pages
);
2494 free_pages((unsigned long)privptr
->p_buff_ccw
,
2495 (int)pages_to_order_of_mag(
2496 privptr
->p_buff_ccw_num
));
2497 /* free the write pages size is < page size */
2498 free_pages((unsigned long)privptr
->p_buff_write
,
2499 (int)pages_to_order_of_mag(
2500 privptr
->p_buff_write_num
));
2501 privptr
->p_buff_ccw
=NULL
;
2502 privptr
->p_buff_write
=NULL
;
2504 printk(KERN_INFO
"%s: %s() > exit on line %d, rc ="
2505 " ENOMEM\n",dev
->name
,__FUNCTION__
,__LINE__
);
2509 memset(privptr
->p_buff_read
, 0x00, claw_read_pages
* PAGE_SIZE
);
2510 privptr
->p_buff_read_num
=claw_read_pages
;
2512 * Build CLAW read free chain
2516 printk(KERN_INFO
"%s: %s() Begin build claw read free chain \n",
2517 dev
->name
,__FUNCTION__
);
2519 p_buff
=privptr
->p_buff_read
;
2520 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
2521 p_buf
= p_free_chain
;
2522 p_free_chain
= p_buf
->next
;
2524 if (p_last_CCWB
==NULL
) {
2530 p_buf
->next
=p_first_CCWB
;
2532 (__u32
)__pa(&p_first_CCWB
-> read
);
2537 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
2538 /* initialize read command */
2539 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
2540 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
2541 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2542 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
2544 /* initialize read_h command */
2545 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
2546 p_buf
-> read_h
.cda
=
2547 (__u32
)__pa(&(p_buf
->header
));
2548 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2549 p_buf
-> read_h
.count
= sizeof(struct clawh
);
2551 /* initialize Signal command */
2552 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
2553 p_buf
-> signal
.cda
=
2554 (__u32
)__pa(&(pClawH
->flag
));
2555 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2556 p_buf
-> signal
.count
= 1;
2558 /* initialize r_TIC_1 command */
2559 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
2560 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
2561 p_buf
-> r_TIC_1
.flags
= 0;
2562 p_buf
-> r_TIC_1
.count
= 0;
2564 /* initialize r_read_FF command */
2565 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2566 p_buf
-> r_read_FF
.cda
=
2567 (__u32
)__pa(&(pClawH
->flag
));
2568 p_buf
-> r_read_FF
.flags
=
2569 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
2570 p_buf
-> r_read_FF
.count
= 1;
2572 /* initialize r_TIC_2 */
2573 memcpy(&p_buf
->r_TIC_2
,
2574 &p_buf
->r_TIC_1
, sizeof(struct ccw1
));
2576 /* initialize Header */
2577 p_buf
->header
.length
=0xffff;
2578 p_buf
->header
.opcode
=0xff;
2579 p_buf
->header
.flag
=CLAW_PENDING
;
2581 if (((unsigned long)p_buff
+privptr
->p_env
->read_size
) >=
2582 ((unsigned long)(p_buff
+2*(privptr
->p_env
->read_size
) -1)
2584 p_buff
= p_buff
+privptr
->p_env
->read_size
;
2588 (void *)((unsigned long)
2589 (p_buff
+2*(privptr
->p_env
->read_size
) -1)
2592 } /* for read_buffers */
2593 } /* read_size < PAGE_SIZE */
2594 else { /* read Size >= PAGE_SIZE */
2597 printk(KERN_INFO
"%s: %s() Begin build claw read free chain \n",
2598 dev
->name
,__FUNCTION__
);
2600 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
2601 p_buff
= (void *)__get_free_pages(__GFP_DMA
,
2602 (int)pages_to_order_of_mag(privptr
->p_buff_pages_perread
) );
2604 printk(KERN_INFO
"%s: %s() __get_free_pages for read "
2605 "buf failed : get is for %d pages\n",
2606 dev
->name
,__FUNCTION__
,
2607 privptr
->p_buff_pages_perread
);
2608 free_pages((unsigned long)privptr
->p_buff_ccw
,
2609 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
2610 /* free the write pages */
2611 p_buf
=privptr
->p_buff_write
;
2612 while (p_buf
!=NULL
) {
2613 free_pages((unsigned long)p_buf
->p_buffer
,
2614 (int)pages_to_order_of_mag(
2615 privptr
->p_buff_pages_perwrite
));
2618 /* free any read pages already alloc */
2619 p_buf
=privptr
->p_buff_read
;
2620 while (p_buf
!=NULL
) {
2621 free_pages((unsigned long)p_buf
->p_buffer
,
2622 (int)pages_to_order_of_mag(
2623 privptr
->p_buff_pages_perread
));
2626 privptr
->p_buff_ccw
=NULL
;
2627 privptr
->p_buff_write
=NULL
;
2629 printk(KERN_INFO
"%s: %s() exit on line %d, rc = ENOMEM\n",
2630 dev
->name
,__FUNCTION__
,
2635 memset(p_buff
, 0x00, privptr
->p_env
->read_size
);
2636 p_buf
= p_free_chain
;
2637 privptr
->p_buff_read
= p_buf
;
2638 p_free_chain
= p_buf
->next
;
2640 if (p_last_CCWB
==NULL
) {
2646 p_buf
->next
=p_first_CCWB
;
2649 &p_first_CCWB
-> read
);
2653 /* save buff address */
2654 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
2655 /* initialize read command */
2656 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
2657 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
2658 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2659 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
2661 /* initialize read_h command */
2662 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
2663 p_buf
-> read_h
.cda
=
2664 (__u32
)__pa(&(p_buf
->header
));
2665 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2666 p_buf
-> read_h
.count
= sizeof(struct clawh
);
2668 /* initialize Signal command */
2669 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
2670 p_buf
-> signal
.cda
=
2671 (__u32
)__pa(&(pClawH
->flag
));
2672 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2673 p_buf
-> signal
.count
= 1;
2675 /* initialize r_TIC_1 command */
2676 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
2677 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
2678 p_buf
-> r_TIC_1
.flags
= 0;
2679 p_buf
-> r_TIC_1
.count
= 0;
2681 /* initialize r_read_FF command */
2682 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2683 p_buf
-> r_read_FF
.cda
=
2684 (__u32
)__pa(&(pClawH
->flag
));
2685 p_buf
-> r_read_FF
.flags
=
2686 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
2687 p_buf
-> r_read_FF
.count
= 1;
2689 /* initialize r_TIC_2 */
2690 memcpy(&p_buf
->r_TIC_2
, &p_buf
->r_TIC_1
,
2691 sizeof(struct ccw1
));
2693 /* initialize Header */
2694 p_buf
->header
.length
=0xffff;
2695 p_buf
->header
.opcode
=0xff;
2696 p_buf
->header
.flag
=CLAW_PENDING
;
2698 } /* For read_buffers */
2699 } /* read_size >= PAGE_SIZE */
2700 } /* pBuffread = NULL */
2702 printk(KERN_INFO
"%s: %s() > End build claw read free chain \n",
2703 dev
->name
,__FUNCTION__
);
2705 while (p_buf
!=NULL
) {
2706 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
2711 add_claw_reads( dev
,p_first_CCWB
, p_last_CCWB
);
2712 privptr
->buffs_alloc
= 1;
2714 printk(KERN_INFO
"%s: %s() exit on line %d\n",
2715 dev
->name
,__FUNCTION__
,__LINE__
);
2718 } /* end of init_ccw_bk */
2720 /*-------------------------------------------------------------------*
2724 *--------------------------------------------------------------------*/
2727 probe_error( struct ccwgroup_device
*cgdev
)
2729 struct claw_privbk
*privptr
;
2731 printk(KERN_INFO
"%s enter \n",__FUNCTION__
);
2733 CLAW_DBF_TEXT(4,trace
,"proberr");
2735 printk(KERN_INFO
"%s variable cgdev =\n",__FUNCTION__
);
2736 dumpit((char *) cgdev
, sizeof(struct ccwgroup_device
));
2738 privptr
=(struct claw_privbk
*)cgdev
->dev
.driver_data
;
2739 if (privptr
!=NULL
) {
2740 kfree(privptr
->p_env
);
2741 privptr
->p_env
=NULL
;
2742 kfree(privptr
->p_mtc_envelope
);
2743 privptr
->p_mtc_envelope
=NULL
;
2748 printk(KERN_INFO
"%s > exit on line %d\n",
2749 __FUNCTION__
,__LINE__
);
2757 /*-------------------------------------------------------------------*
2758 * claw_process_control *
2761 *--------------------------------------------------------------------*/
2764 claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
)
2767 struct clawbuf
*p_buf
;
2768 struct clawctl ctlbk
;
2769 struct clawctl
*p_ctlbk
;
2770 char temp_host_name
[8];
2771 char temp_ws_name
[8];
2772 struct claw_privbk
*privptr
;
2773 struct claw_env
*p_env
;
2774 struct sysval
*p_sysval
;
2775 struct conncmd
*p_connect
=NULL
;
2777 struct chbk
*p_ch
= NULL
;
2779 printk(KERN_INFO
"%s: %s() > enter \n",
2780 dev
->name
,__FUNCTION__
);
2782 CLAW_DBF_TEXT(2,setup
,"clw_cntl");
2784 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
2785 dumpit((char *) dev
, sizeof(struct net_device
));
2786 printk(KERN_INFO
"%s: variable p_ccw =\n",dev
->name
);
2787 dumpit((char *) p_ccw
, sizeof(struct ccwbk
*));
2789 udelay(1000); /* Wait a ms for the control packets to
2790 *catch up to each other */
2792 p_env
=privptr
->p_env
;
2793 memcpy( &temp_host_name
, p_env
->host_name
, 8);
2794 memcpy( &temp_ws_name
, p_env
->adapter_name
, 8);
2795 printk(KERN_INFO
"%s: CLAW device %.8s: "
2796 "Received Control Packet\n",
2797 dev
->name
, temp_ws_name
);
2798 if (privptr
->release_pend
==1) {
2800 printk(KERN_INFO
"%s: %s() > "
2801 "exit on line %d, rc=0\n",
2802 dev
->name
,__FUNCTION__
,__LINE__
);
2806 p_buf
=p_ccw
->p_buffer
;
2808 if (p_env
->packing
== DO_PACKED
) { /* packing in progress?*/
2809 memcpy(p_ctlbk
, &p_buf
->buffer
[4], sizeof(struct clawctl
));
2811 memcpy(p_ctlbk
, p_buf
, sizeof(struct clawctl
));
2814 printk(KERN_INFO
"%s: dump claw control data inbound\n",dev
->name
);
2815 dumpit((char *)p_ctlbk
, sizeof(struct clawctl
));
2817 switch (p_ctlbk
->command
)
2819 case SYSTEM_VALIDATE_REQUEST
:
2820 if (p_ctlbk
->version
!=CLAW_VERSION_ID
) {
2821 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2822 CLAW_RC_WRONG_VERSION
);
2823 printk("%s: %d is wrong version id. "
2825 dev
->name
, p_ctlbk
->version
,
2828 p_sysval
=(struct sysval
*)&(p_ctlbk
->data
);
2829 printk( "%s: Recv Sys Validate Request: "
2830 "Vers=%d,link_id=%d,Corr=%d,WS name=%."
2831 "8s,Host name=%.8s\n",
2832 dev
->name
, p_ctlbk
->version
,
2834 p_ctlbk
->correlator
,
2836 p_sysval
->host_name
);
2837 if (0!=memcmp(temp_host_name
,p_sysval
->host_name
,8)) {
2838 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2839 CLAW_RC_NAME_MISMATCH
);
2840 CLAW_DBF_TEXT(2,setup
,"HSTBAD");
2841 CLAW_DBF_TEXT_(2,setup
,"%s",p_sysval
->host_name
);
2842 CLAW_DBF_TEXT_(2,setup
,"%s",temp_host_name
);
2843 printk(KERN_INFO
"%s: Host name mismatch\n",
2845 printk(KERN_INFO
"%s: Received :%s: "
2848 p_sysval
->host_name
,
2851 if (0!=memcmp(temp_ws_name
,p_sysval
->WS_name
,8)) {
2852 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2853 CLAW_RC_NAME_MISMATCH
);
2854 CLAW_DBF_TEXT(2,setup
,"WSNBAD");
2855 CLAW_DBF_TEXT_(2,setup
,"%s",p_sysval
->WS_name
);
2856 CLAW_DBF_TEXT_(2,setup
,"%s",temp_ws_name
);
2857 printk(KERN_INFO
"%s: WS name mismatch\n",
2859 printk(KERN_INFO
"%s: Received :%s: "
2865 if (( p_sysval
->write_frame_size
< p_env
->write_size
) &&
2866 ( p_env
->packing
== 0)) {
2867 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2868 CLAW_RC_HOST_RCV_TOO_SMALL
);
2869 printk(KERN_INFO
"%s: host write size is too "
2870 "small\n", dev
->name
);
2871 CLAW_DBF_TEXT(2,setup
,"wrtszbad");
2873 if (( p_sysval
->read_frame_size
< p_env
->read_size
) &&
2874 ( p_env
->packing
== 0)) {
2875 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2876 CLAW_RC_HOST_RCV_TOO_SMALL
);
2877 printk(KERN_INFO
"%s: host read size is too "
2878 "small\n", dev
->name
);
2879 CLAW_DBF_TEXT(2,setup
,"rdsizbad");
2881 claw_snd_sys_validate_rsp(dev
, p_ctlbk
, 0 );
2882 printk("%s: CLAW device %.8s: System validate"
2883 " completed.\n",dev
->name
, temp_ws_name
);
2884 printk("%s: sys Validate Rsize:%d Wsize:%d\n",dev
->name
,
2885 p_sysval
->read_frame_size
,p_sysval
->write_frame_size
);
2886 privptr
->system_validate_comp
=1;
2887 if(strncmp(p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
2888 p_env
->packing
= PACKING_ASK
;
2890 claw_strt_conn_req(dev
);
2893 case SYSTEM_VALIDATE_RESPONSE
:
2894 p_sysval
=(struct sysval
*)&(p_ctlbk
->data
);
2895 printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
2896 "WS name=%.8s,Host name=%.8s\n",
2899 p_ctlbk
->correlator
,
2902 p_sysval
->host_name
);
2903 switch (p_ctlbk
->rc
)
2906 printk(KERN_INFO
"%s: CLAW device "
2907 "%.8s: System validate "
2909 dev
->name
, temp_ws_name
);
2910 if (privptr
->system_validate_comp
== 0)
2911 claw_strt_conn_req(dev
);
2912 privptr
->system_validate_comp
=1;
2914 case CLAW_RC_NAME_MISMATCH
:
2915 printk(KERN_INFO
"%s: Sys Validate "
2916 "Resp : Host, WS name is "
2920 case CLAW_RC_WRONG_VERSION
:
2921 printk(KERN_INFO
"%s: Sys Validate "
2922 "Resp : Wrong version\n",
2925 case CLAW_RC_HOST_RCV_TOO_SMALL
:
2926 printk(KERN_INFO
"%s: Sys Validate "
2927 "Resp : bad frame size\n",
2931 printk(KERN_INFO
"%s: Sys Validate "
2933 dev
->name
, p_ctlbk
->rc
);
2938 case CONNECTION_REQUEST
:
2939 p_connect
=(struct conncmd
*)&(p_ctlbk
->data
);
2940 printk(KERN_INFO
"%s: Recv Conn Req: Vers=%d,link_id=%d,"
2941 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2945 p_ctlbk
->correlator
,
2946 p_connect
->host_name
,
2947 p_connect
->WS_name
);
2948 if (privptr
->active_link_ID
!=0 ) {
2949 claw_snd_disc(dev
, p_ctlbk
);
2950 printk(KERN_INFO
"%s: Conn Req error : "
2951 "already logical link is active \n",
2954 if (p_ctlbk
->linkid
!=1 ) {
2955 claw_snd_disc(dev
, p_ctlbk
);
2956 printk(KERN_INFO
"%s: Conn Req error : "
2957 "req logical link id is not 1\n",
2961 p_connect
->host_name
, p_connect
->WS_name
);
2963 claw_snd_disc(dev
, p_ctlbk
);
2964 printk(KERN_INFO
"%s: Conn Req error : "
2965 "req appl name does not match\n",
2968 claw_send_control(dev
,
2969 CONNECTION_CONFIRM
, p_ctlbk
->linkid
,
2970 p_ctlbk
->correlator
,
2971 0, p_connect
->host_name
,
2972 p_connect
->WS_name
);
2973 if (p_env
->packing
== PACKING_ASK
) {
2974 printk("%s: Now Pack ask\n",dev
->name
);
2975 p_env
->packing
= PACK_SEND
;
2976 claw_snd_conn_req(dev
,0);
2978 printk(KERN_INFO
"%s: CLAW device %.8s: Connection "
2979 "completed link_id=%d.\n",
2980 dev
->name
, temp_ws_name
,
2982 privptr
->active_link_ID
=p_ctlbk
->linkid
;
2983 p_ch
=&privptr
->channel
[WRITE
];
2984 wake_up(&p_ch
->wait
); /* wake up claw_open ( WRITE) */
2986 case CONNECTION_RESPONSE
:
2987 p_connect
=(struct conncmd
*)&(p_ctlbk
->data
);
2988 printk(KERN_INFO
"%s: Revc Conn Resp: Vers=%d,link_id=%d,"
2989 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2993 p_ctlbk
->correlator
,
2995 p_connect
->host_name
,
2996 p_connect
->WS_name
);
2998 if (p_ctlbk
->rc
!=0 ) {
2999 printk(KERN_INFO
"%s: Conn Resp error: rc=%d \n",
3000 dev
->name
, p_ctlbk
->rc
);
3004 p_connect
->host_name
, p_connect
->WS_name
);
3006 claw_snd_disc(dev
, p_ctlbk
);
3007 printk(KERN_INFO
"%s: Conn Resp error: "
3008 "req appl name does not match\n",
3011 /* should be until CONNECTION_CONFIRM */
3012 privptr
->active_link_ID
= - (p_ctlbk
->linkid
);
3014 case CONNECTION_CONFIRM
:
3015 p_connect
=(struct conncmd
*)&(p_ctlbk
->data
);
3016 printk(KERN_INFO
"%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
3017 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
3021 p_ctlbk
->correlator
,
3022 p_connect
->host_name
,
3023 p_connect
->WS_name
);
3024 if (p_ctlbk
->linkid
== -(privptr
->active_link_ID
)) {
3025 privptr
->active_link_ID
=p_ctlbk
->linkid
;
3026 if (p_env
->packing
> PACKING_ASK
) {
3027 printk(KERN_INFO
"%s: Confirmed Now packing\n",dev
->name
);
3028 p_env
->packing
= DO_PACKED
;
3030 p_ch
=&privptr
->channel
[WRITE
];
3031 wake_up(&p_ch
->wait
);
3034 printk(KERN_INFO
"%s: Conn confirm: "
3035 "unexpected linkid=%d \n",
3036 dev
->name
, p_ctlbk
->linkid
);
3037 claw_snd_disc(dev
, p_ctlbk
);
3041 printk(KERN_INFO
"%s: Disconnect: "
3042 "Vers=%d,link_id=%d,Corr=%d\n",
3043 dev
->name
, p_ctlbk
->version
,
3044 p_ctlbk
->linkid
, p_ctlbk
->correlator
);
3045 if ((p_ctlbk
->linkid
== 2) &&
3046 (p_env
->packing
== PACK_SEND
)) {
3047 privptr
->active_link_ID
= 1;
3048 p_env
->packing
= DO_PACKED
;
3051 privptr
->active_link_ID
=0;
3054 printk(KERN_INFO
"%s: CLAW ERROR detected\n",
3058 printk(KERN_INFO
"%s: Unexpected command code=%d \n",
3059 dev
->name
, p_ctlbk
->command
);
3064 printk(KERN_INFO
"%s: %s() exit on line %d, rc = 0\n",
3065 dev
->name
,__FUNCTION__
,__LINE__
);
3069 } /* end of claw_process_control */
3072 /*-------------------------------------------------------------------*
3073 * claw_send_control *
3075 *--------------------------------------------------------------------*/
3078 claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
3079 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
)
3081 struct claw_privbk
*privptr
;
3082 struct clawctl
*p_ctl
;
3083 struct sysval
*p_sysval
;
3084 struct conncmd
*p_connect
;
3085 struct sk_buff
*skb
;
3088 printk(KERN_INFO
"%s:%s > enter \n",dev
->name
,__FUNCTION__
);
3090 CLAW_DBF_TEXT(2,setup
,"sndcntl");
3092 printk(KERN_INFO
"%s: Sending Control Packet \n",dev
->name
);
3093 printk(KERN_INFO
"%s: variable type = 0x%X, link = "
3094 "%d, correlator = %d, rc = %d\n",
3095 dev
->name
,type
, link
, correlator
, rc
);
3096 printk(KERN_INFO
"%s: variable local_name = %s, "
3097 "remote_name = %s\n",dev
->name
, local_name
, remote_name
);
3100 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
3102 p_ctl
->command
=type
;
3103 p_ctl
->version
=CLAW_VERSION_ID
;
3105 p_ctl
->correlator
=correlator
;
3108 p_sysval
=(struct sysval
*)&p_ctl
->data
;
3109 p_connect
=(struct conncmd
*)&p_ctl
->data
;
3111 switch (p_ctl
->command
) {
3112 case SYSTEM_VALIDATE_REQUEST
:
3113 case SYSTEM_VALIDATE_RESPONSE
:
3114 memcpy(&p_sysval
->host_name
, local_name
, 8);
3115 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
3116 if (privptr
->p_env
->packing
> 0) {
3117 p_sysval
->read_frame_size
=DEF_PACK_BUFSIZE
;
3118 p_sysval
->write_frame_size
=DEF_PACK_BUFSIZE
;
3120 /* how big is the piggest group of packets */
3121 p_sysval
->read_frame_size
=privptr
->p_env
->read_size
;
3122 p_sysval
->write_frame_size
=privptr
->p_env
->write_size
;
3124 memset(&p_sysval
->reserved
, 0x00, 4);
3126 case CONNECTION_REQUEST
:
3127 case CONNECTION_RESPONSE
:
3128 case CONNECTION_CONFIRM
:
3130 memcpy(&p_sysval
->host_name
, local_name
, 8);
3131 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
3132 if (privptr
->p_env
->packing
> 0) {
3133 /* How big is the biggest packet */
3134 p_connect
->reserved1
[0]=CLAW_FRAME_SIZE
;
3135 p_connect
->reserved1
[1]=CLAW_FRAME_SIZE
;
3137 memset(&p_connect
->reserved1
, 0x00, 4);
3138 memset(&p_connect
->reserved2
, 0x00, 4);
3145 /* write Control Record to the device */
3148 skb
= dev_alloc_skb(sizeof(struct clawctl
));
3150 printk( "%s:%s low on mem, returning...\n",
3151 dev
->name
,__FUNCTION__
);
3153 printk(KERN_INFO
"%s:%s Exit, rc = ENOMEM\n",
3154 dev
->name
,__FUNCTION__
);
3158 memcpy(skb_put(skb
, sizeof(struct clawctl
)),
3159 p_ctl
, sizeof(struct clawctl
));
3161 printk(KERN_INFO
"%s: outbnd claw cntl data \n",dev
->name
);
3162 dumpit((char *)p_ctl
,sizeof(struct clawctl
));
3164 if (privptr
->p_env
->packing
>= PACK_SEND
)
3165 claw_hw_tx(skb
, dev
, 1);
3167 claw_hw_tx(skb
, dev
, 0);
3169 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3170 dev
->name
,__FUNCTION__
,__LINE__
);
3174 } /* end of claw_send_control */
3176 /*-------------------------------------------------------------------*
3177 * claw_snd_conn_req *
3179 *--------------------------------------------------------------------*/
3181 claw_snd_conn_req(struct net_device
*dev
, __u8 link
)
3184 struct claw_privbk
*privptr
=dev
->priv
;
3185 struct clawctl
*p_ctl
;
3188 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
3190 CLAW_DBF_TEXT(2,setup
,"snd_conn");
3192 printk(KERN_INFO
"%s: variable link = %X, dev =\n",dev
->name
, link
);
3193 dumpit((char *) dev
, sizeof(struct net_device
));
3196 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
3197 p_ctl
->linkid
= link
;
3198 if ( privptr
->system_validate_comp
==0x00 ) {
3200 printk(KERN_INFO
"%s:%s Exit on line %d, rc = 1\n",
3201 dev
->name
,__FUNCTION__
,__LINE__
);
3205 if (privptr
->p_env
->packing
== PACKING_ASK
)
3206 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
3207 WS_APPL_NAME_PACKED
, WS_APPL_NAME_PACKED
);
3208 if (privptr
->p_env
->packing
== PACK_SEND
) {
3209 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
3210 WS_APPL_NAME_IP_NAME
, WS_APPL_NAME_IP_NAME
);
3212 if (privptr
->p_env
->packing
== 0)
3213 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
3214 HOST_APPL_NAME
, privptr
->p_env
->api_type
);
3216 printk(KERN_INFO
"%s:%s Exit on line %d, rc = %d\n",
3217 dev
->name
,__FUNCTION__
,__LINE__
, rc
);
3221 } /* end of claw_snd_conn_req */
3224 /*-------------------------------------------------------------------*
3227 *--------------------------------------------------------------------*/
3230 claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
)
3233 struct conncmd
* p_connect
;
3236 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3238 CLAW_DBF_TEXT(2,setup
,"snd_dsc");
3240 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
3241 dumpit((char *) dev
, sizeof(struct net_device
));
3242 printk(KERN_INFO
"%s: variable p_ctl",dev
->name
);
3243 dumpit((char *) p_ctl
, sizeof(struct clawctl
));
3245 p_connect
=(struct conncmd
*)&p_ctl
->data
;
3247 rc
=claw_send_control(dev
, DISCONNECT
, p_ctl
->linkid
,
3248 p_ctl
->correlator
, 0,
3249 p_connect
->host_name
, p_connect
->WS_name
);
3251 printk(KERN_INFO
"%s:%s Exit on line %d, rc = %d\n",
3252 dev
->name
,__FUNCTION__
, __LINE__
, rc
);
3255 } /* end of claw_snd_disc */
3258 /*-------------------------------------------------------------------*
3259 * claw_snd_sys_validate_rsp *
3261 *--------------------------------------------------------------------*/
3264 claw_snd_sys_validate_rsp(struct net_device
*dev
,
3265 struct clawctl
*p_ctl
, __u32 return_code
)
3267 struct claw_env
* p_env
;
3268 struct claw_privbk
*privptr
;
3272 printk(KERN_INFO
"%s:%s Enter\n",
3273 dev
->name
,__FUNCTION__
);
3275 CLAW_DBF_TEXT(2,setup
,"chkresp");
3277 printk(KERN_INFO
"%s: variable return_code = %d, dev =\n",
3278 dev
->name
, return_code
);
3279 dumpit((char *) dev
, sizeof(struct net_device
));
3280 printk(KERN_INFO
"%s: variable p_ctl =\n",dev
->name
);
3281 dumpit((char *) p_ctl
, sizeof(struct clawctl
));
3283 privptr
= dev
->priv
;
3284 p_env
=privptr
->p_env
;
3285 rc
=claw_send_control(dev
, SYSTEM_VALIDATE_RESPONSE
,
3290 p_env
->adapter_name
);
3292 printk(KERN_INFO
"%s:%s Exit on line %d, rc = %d\n",
3293 dev
->name
,__FUNCTION__
,__LINE__
, rc
);
3296 } /* end of claw_snd_sys_validate_rsp */
3298 /*-------------------------------------------------------------------*
3299 * claw_strt_conn_req *
3301 *--------------------------------------------------------------------*/
3304 claw_strt_conn_req(struct net_device
*dev
)
3309 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3311 CLAW_DBF_TEXT(2,setup
,"conn_req");
3313 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
3314 dumpit((char *) dev
, sizeof(struct net_device
));
3316 rc
=claw_snd_conn_req(dev
, 1);
3318 printk(KERN_INFO
"%s:%s Exit on line %d, rc = %d\n",
3319 dev
->name
,__FUNCTION__
,__LINE__
, rc
);
3322 } /* end of claw_strt_conn_req */
3326 /*-------------------------------------------------------------------*
3328 *-------------------------------------------------------------------*/
3331 net_device_stats
*claw_stats(struct net_device
*dev
)
3333 struct claw_privbk
*privptr
;
3335 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3337 CLAW_DBF_TEXT(4,trace
,"stats");
3338 privptr
= dev
->priv
;
3340 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3341 dev
->name
,__FUNCTION__
,__LINE__
);
3343 return &privptr
->stats
;
3344 } /* end of claw_stats */
3347 /*-------------------------------------------------------------------*
3350 *--------------------------------------------------------------------*/
3352 unpack_read(struct net_device
*dev
)
3354 struct sk_buff
*skb
;
3355 struct claw_privbk
*privptr
;
3356 struct claw_env
*p_env
;
3357 struct ccwbk
*p_this_ccw
;
3358 struct ccwbk
*p_first_ccw
;
3359 struct ccwbk
*p_last_ccw
;
3360 struct clawph
*p_packh
;
3362 struct clawctl
*p_ctlrec
=NULL
;
3367 __u8 mtc_this_frm
=0;
3369 struct chbk
*p_ch
= NULL
;
3374 printk(KERN_INFO
"%s:%s enter \n",dev
->name
,__FUNCTION__
);
3376 CLAW_DBF_TEXT(4,trace
,"unpkread");
3382 p_env
= privptr
->p_env
;
3383 p_this_ccw
=privptr
->p_read_active_first
;
3385 while (p_this_ccw
!=NULL
&& p_this_ccw
->header
.flag
!=CLAW_PENDING
) {
3387 printk(KERN_INFO
"%s p_this_ccw \n",dev
->name
);
3388 dumpit((char*)p_this_ccw
, sizeof(struct ccwbk
));
3389 printk(KERN_INFO
"%s Inbound p_this_ccw->p_buffer(64)"
3390 " pk=%d \n",dev
->name
,p_env
->packing
);
3391 dumpit((char *)p_this_ccw
->p_buffer
, 64 );
3395 p_this_ccw
->header
.flag
=CLAW_PENDING
;
3396 privptr
->p_read_active_first
=p_this_ccw
->next
;
3397 p_this_ccw
->next
=NULL
;
3398 p_packh
= (struct clawph
*)p_this_ccw
->p_buffer
;
3399 if ((p_env
->packing
== PACK_SEND
) &&
3400 (p_packh
->len
== 32) &&
3401 (p_packh
->link_num
== 0)) { /* is it a packed ctl rec? */
3402 p_packh
++; /* peek past pack header */
3403 p_ctlrec
= (struct clawctl
*)p_packh
;
3404 p_packh
--; /* un peek */
3405 if ((p_ctlrec
->command
== CONNECTION_RESPONSE
) ||
3406 (p_ctlrec
->command
== CONNECTION_CONFIRM
))
3407 p_env
->packing
= DO_PACKED
;
3409 if (p_env
->packing
== DO_PACKED
)
3410 link_num
=p_packh
->link_num
;
3412 link_num
=p_this_ccw
->header
.opcode
/ 8;
3413 if ((p_this_ccw
->header
.opcode
& MORE_to_COME_FLAG
)!=0) {
3415 printk(KERN_INFO
"%s: %s > More_to_come is ON\n",
3416 dev
->name
,__FUNCTION__
);
3419 if (p_this_ccw
->header
.length
!=
3420 privptr
->p_env
->read_size
) {
3421 printk(KERN_INFO
" %s: Invalid frame detected "
3422 "length is %02x\n" ,
3423 dev
->name
, p_this_ccw
->header
.length
);
3427 if (privptr
->mtc_skipping
) {
3429 * We're in the mode of skipping past a
3430 * multi-frame message
3431 * that we can't process for some reason or other.
3432 * The first frame without the More-To-Come flag is
3433 * the last frame of the skipped message.
3435 /* in case of More-To-Come not set in this frame */
3436 if (mtc_this_frm
==0) {
3437 privptr
->mtc_skipping
=0; /* Ok, the end */
3438 privptr
->mtc_logical_link
=-1;
3441 printk(KERN_INFO
"%s:%s goto next "
3442 "frame from MoretoComeSkip \n",
3443 dev
->name
,__FUNCTION__
);
3449 claw_process_control(dev
, p_this_ccw
);
3451 printk(KERN_INFO
"%s:%s goto next "
3452 "frame from claw_process_control \n",
3453 dev
->name
,__FUNCTION__
);
3455 CLAW_DBF_TEXT(4,trace
,"UnpkCntl");
3459 if (p_env
->packing
== DO_PACKED
) {
3460 if (pack_off
> p_env
->read_size
)
3462 p_packd
= p_this_ccw
->p_buffer
+pack_off
;
3463 p_packh
= (struct clawph
*) p_packd
;
3464 if ((p_packh
->len
== 0) || /* all done with this frame? */
3465 (p_packh
->flag
!= 0))
3467 bytes_to_mov
= p_packh
->len
;
3468 pack_off
+= bytes_to_mov
+sizeof(struct clawph
);
3471 bytes_to_mov
=p_this_ccw
->header
.length
;
3473 if (privptr
->mtc_logical_link
<0) {
3475 printk(KERN_INFO
"%s: %s mtc_logical_link < 0 \n",
3476 dev
->name
,__FUNCTION__
);
3480 * if More-To-Come is set in this frame then we don't know
3481 * length of entire message, and hence have to allocate
3484 /* We are starting a new envelope */
3485 privptr
->mtc_offset
=0;
3486 privptr
->mtc_logical_link
=link_num
;
3489 if (bytes_to_mov
> (MAX_ENVELOPE_SIZE
- privptr
->mtc_offset
) ) {
3492 printk(KERN_INFO
"%s: %s > goto next "
3493 "frame from MoretoComeSkip \n",
3496 printk(KERN_INFO
" bytes_to_mov %d > (MAX_ENVELOPE_"
3497 "SIZE-privptr->mtc_offset %d)\n",
3498 bytes_to_mov
,(MAX_ENVELOPE_SIZE
- privptr
->mtc_offset
));
3500 privptr
->stats
.rx_frame_errors
++;
3503 if (p_env
->packing
== DO_PACKED
) {
3504 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
3505 p_packd
+sizeof(struct clawph
), bytes_to_mov
);
3508 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
3509 p_this_ccw
->p_buffer
, bytes_to_mov
);
3512 printk(KERN_INFO
"%s: %s() received data \n",
3513 dev
->name
,__FUNCTION__
);
3514 if (p_env
->packing
== DO_PACKED
)
3515 dumpit((char *)p_packd
+sizeof(struct clawph
),32);
3517 dumpit((char *)p_this_ccw
->p_buffer
, 32);
3518 printk(KERN_INFO
"%s: %s() bytelength %d \n",
3519 dev
->name
,__FUNCTION__
,bytes_to_mov
);
3521 if (mtc_this_frm
==0) {
3522 len_of_data
=privptr
->mtc_offset
+bytes_to_mov
;
3523 skb
=dev_alloc_skb(len_of_data
);
3525 memcpy(skb_put(skb
,len_of_data
),
3526 privptr
->p_mtc_envelope
,
3529 skb_reset_mac_header(skb
);
3530 skb
->protocol
=htons(ETH_P_IP
);
3531 skb
->ip_summed
=CHECKSUM_UNNECESSARY
;
3532 privptr
->stats
.rx_packets
++;
3533 privptr
->stats
.rx_bytes
+=len_of_data
;
3536 printk(KERN_INFO
"%s: %s() netif_"
3537 "rx(skb) completed \n",
3538 dev
->name
,__FUNCTION__
);
3542 privptr
->stats
.rx_dropped
++;
3543 printk(KERN_WARNING
"%s: %s() low on memory\n",
3544 dev
->name
,__FUNCTION__
);
3546 privptr
->mtc_offset
=0;
3547 privptr
->mtc_logical_link
=-1;
3550 privptr
->mtc_offset
+=bytes_to_mov
;
3552 if (p_env
->packing
== DO_PACKED
)
3556 * Remove ThisCCWblock from active read queue, and add it
3557 * to queue of free blocks to be reused.
3560 p_this_ccw
->header
.length
=0xffff;
3561 p_this_ccw
->header
.opcode
=0xff;
3563 * add this one to the free queue for later reuse
3565 if (p_first_ccw
==NULL
) {
3566 p_first_ccw
= p_this_ccw
;
3569 p_last_ccw
->next
= p_this_ccw
;
3571 p_last_ccw
= p_this_ccw
;
3573 * chain to next block on active read queue
3575 p_this_ccw
= privptr
->p_read_active_first
;
3576 CLAW_DBF_TEXT_(4,trace
,"rxpkt %d",p
);
3577 } /* end of while */
3579 /* check validity */
3582 printk(KERN_INFO
"%s:%s processed frame is %d \n",
3583 dev
->name
,__FUNCTION__
,i
);
3584 printk(KERN_INFO
"%s:%s F:%lx L:%lx\n",
3587 (unsigned long)p_first_ccw
,
3588 (unsigned long)p_last_ccw
);
3590 CLAW_DBF_TEXT_(4,trace
,"rxfrm %d",i
);
3591 add_claw_reads(dev
, p_first_ccw
, p_last_ccw
);
3592 p_ch
=&privptr
->channel
[READ
];
3593 claw_strt_read(dev
, LOCK_YES
);
3595 printk(KERN_INFO
"%s: %s exit on line %d\n",
3596 dev
->name
, __FUNCTION__
, __LINE__
);
3599 } /* end of unpack_read */
3601 /*-------------------------------------------------------------------*
3604 *--------------------------------------------------------------------*/
3606 claw_strt_read (struct net_device
*dev
, int lock
)
3610 unsigned long saveflags
= 0;
3611 struct claw_privbk
*privptr
=dev
->priv
;
3612 struct ccwbk
*p_ccwbk
;
3614 struct clawh
*p_clawh
;
3615 p_ch
=&privptr
->channel
[READ
];
3618 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
3619 printk(KERN_INFO
"%s: variable lock = %d, dev =\n",dev
->name
, lock
);
3620 dumpit((char *) dev
, sizeof(struct net_device
));
3622 CLAW_DBF_TEXT(4,trace
,"StRdNter");
3623 p_clawh
=(struct clawh
*)privptr
->p_claw_signal_blk
;
3624 p_clawh
->flag
=CLAW_IDLE
; /* 0x00 */
3626 if ((privptr
->p_write_active_first
!=NULL
&&
3627 privptr
->p_write_active_first
->header
.flag
!=CLAW_PENDING
) ||
3628 (privptr
->p_read_active_first
!=NULL
&&
3629 privptr
->p_read_active_first
->header
.flag
!=CLAW_PENDING
)) {
3630 p_clawh
->flag
=CLAW_BUSY
; /* 0xff */
3633 printk(KERN_INFO
"%s:%s state-%02x\n" ,
3634 dev
->name
,__FUNCTION__
, p_ch
->claw_state
);
3636 if (lock
==LOCK_YES
) {
3637 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
3639 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
3641 printk(KERN_INFO
"%s: HOT READ started in %s\n" ,
3642 dev
->name
,__FUNCTION__
);
3643 p_clawh
=(struct clawh
*)privptr
->p_claw_signal_blk
;
3644 dumpit((char *)&p_clawh
->flag
, 1);
3646 CLAW_DBF_TEXT(4,trace
,"HotRead");
3647 p_ccwbk
=privptr
->p_read_active_first
;
3648 parm
= (unsigned long) p_ch
;
3649 rc
= ccw_device_start (p_ch
->cdev
, &p_ccwbk
->read
, parm
,
3652 ccw_check_return_code(p_ch
->cdev
, rc
);
3657 printk(KERN_INFO
"%s: No READ started by %s() In progress\n" ,
3658 dev
->name
,__FUNCTION__
);
3660 CLAW_DBF_TEXT(2,trace
,"ReadAct");
3663 if (lock
==LOCK_YES
) {
3664 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
3667 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3668 dev
->name
,__FUNCTION__
,__LINE__
);
3670 CLAW_DBF_TEXT(4,trace
,"StRdExit");
3672 } /* end of claw_strt_read */
3674 /*-------------------------------------------------------------------*
3675 * claw_strt_out_IO *
3677 *--------------------------------------------------------------------*/
3680 claw_strt_out_IO( struct net_device
*dev
)
3684 struct claw_privbk
*privptr
;
3686 struct ccwbk
*p_first_ccw
;
3689 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3694 privptr
=(struct claw_privbk
*)dev
->priv
;
3695 p_ch
=&privptr
->channel
[WRITE
];
3698 printk(KERN_INFO
"%s:%s state-%02x\n" ,
3699 dev
->name
,__FUNCTION__
,p_ch
->claw_state
);
3701 CLAW_DBF_TEXT(4,trace
,"strt_io");
3702 p_first_ccw
=privptr
->p_write_active_first
;
3704 if (p_ch
->claw_state
== CLAW_STOP
)
3706 if (p_first_ccw
== NULL
) {
3708 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3709 dev
->name
,__FUNCTION__
,__LINE__
);
3713 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
3714 parm
= (unsigned long) p_ch
;
3716 printk(KERN_INFO
"%s:%s do_io \n" ,dev
->name
,__FUNCTION__
);
3717 dumpit((char *)p_first_ccw
, sizeof(struct ccwbk
));
3719 CLAW_DBF_TEXT(2,trace
,"StWrtIO");
3720 rc
= ccw_device_start (p_ch
->cdev
,&p_first_ccw
->write
, parm
,
3723 ccw_check_return_code(p_ch
->cdev
, rc
);
3726 dev
->trans_start
= jiffies
;
3728 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3729 dev
->name
,__FUNCTION__
,__LINE__
);
3733 } /* end of claw_strt_out_IO */
3735 /*-------------------------------------------------------------------*
3736 * Free write buffers *
3738 *--------------------------------------------------------------------*/
3741 claw_free_wrt_buf( struct net_device
*dev
)
3744 struct claw_privbk
*privptr
=(struct claw_privbk
*)dev
->priv
;
3745 struct ccwbk
*p_first_ccw
;
3746 struct ccwbk
*p_last_ccw
;
3747 struct ccwbk
*p_this_ccw
;
3748 struct ccwbk
*p_next_ccw
;
3753 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3754 printk(KERN_INFO
"%s: free count = %d variable dev =\n",
3755 dev
->name
,privptr
->write_free_count
);
3757 CLAW_DBF_TEXT(4,trace
,"freewrtb");
3758 /* scan the write queue to free any completed write packets */
3762 printk(KERN_INFO
"%s: Dump current CCW chain \n",dev
->name
);
3763 p_buf
=privptr
->p_write_active_first
;
3764 while (p_buf
!=NULL
) {
3765 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
3769 printk(KERN_INFO
"%s: privptr->p_write_"
3770 "active_first==NULL\n",dev
->name
);
3772 p_buf
=(struct ccwbk
*)privptr
->p_end_ccw
;
3773 dumpit((char *)p_buf
, sizeof(struct endccw
));
3775 p_this_ccw
=privptr
->p_write_active_first
;
3776 while ( (p_this_ccw
!=NULL
) && (p_this_ccw
->header
.flag
!=CLAW_PENDING
))
3778 p_next_ccw
= p_this_ccw
->next
;
3779 if (((p_next_ccw
!=NULL
) &&
3780 (p_next_ccw
->header
.flag
!=CLAW_PENDING
)) ||
3781 ((p_this_ccw
== privptr
->p_write_active_last
) &&
3782 (p_this_ccw
->header
.flag
!=CLAW_PENDING
))) {
3783 /* The next CCW is OK or this is */
3784 /* the last CCW...free it @A1A */
3785 privptr
->p_write_active_first
=p_this_ccw
->next
;
3786 p_this_ccw
->header
.flag
=CLAW_PENDING
;
3787 p_this_ccw
->next
=privptr
->p_write_free_chain
;
3788 privptr
->p_write_free_chain
=p_this_ccw
;
3789 ++privptr
->write_free_count
;
3790 privptr
->stats
.tx_bytes
+= p_this_ccw
->write
.count
;
3791 p_this_ccw
=privptr
->p_write_active_first
;
3792 privptr
->stats
.tx_packets
++;
3798 if (privptr
->write_free_count
!=0) {
3799 claw_clearbit_busy(TB_NOBUFFER
,dev
);
3801 /* whole chain removed? */
3802 if (privptr
->p_write_active_first
==NULL
) {
3803 privptr
->p_write_active_last
=NULL
;
3805 printk(KERN_INFO
"%s:%s p_write_"
3806 "active_first==NULL\n",dev
->name
,__FUNCTION__
);
3810 printk(KERN_INFO
"%s: Dump arranged CCW chain \n",dev
->name
);
3811 p_buf
=privptr
->p_write_active_first
;
3812 while (p_buf
!=NULL
) {
3813 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
3817 printk(KERN_INFO
"%s: privptr->p_write_active_"
3818 "first==NULL\n",dev
->name
);
3820 p_buf
=(struct ccwbk
*)privptr
->p_end_ccw
;
3821 dumpit((char *)p_buf
, sizeof(struct endccw
));
3824 CLAW_DBF_TEXT_(4,trace
,"FWC=%d",privptr
->write_free_count
);
3826 printk(KERN_INFO
"%s:%s Exit on line %d free_count =%d\n",
3827 dev
->name
,__FUNCTION__
, __LINE__
,privptr
->write_free_count
);
3832 /*-------------------------------------------------------------------*
3833 * claw free netdevice *
3835 *--------------------------------------------------------------------*/
3837 claw_free_netdevice(struct net_device
* dev
, int free_dev
)
3839 struct claw_privbk
*privptr
;
3841 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3843 CLAW_DBF_TEXT(2,setup
,"free_dev");
3847 CLAW_DBF_TEXT_(2,setup
,"%s",dev
->name
);
3848 privptr
= dev
->priv
;
3849 if (dev
->flags
& IFF_RUNNING
)
3852 privptr
->channel
[READ
].ndev
= NULL
; /* say it's free */
3860 CLAW_DBF_TEXT(2,setup
,"feee_ok");
3862 printk(KERN_INFO
"%s:%s Exit\n",dev
->name
,__FUNCTION__
);
3867 * Claw init netdevice
3868 * Initialize everything of the net device except the name and the
3872 claw_init_netdevice(struct net_device
* dev
)
3875 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3877 CLAW_DBF_TEXT(2,setup
,"init_dev");
3878 CLAW_DBF_TEXT_(2,setup
,"%s",dev
->name
);
3880 printk(KERN_WARNING
"claw:%s BAD Device exit line %d\n",
3881 __FUNCTION__
,__LINE__
);
3882 CLAW_DBF_TEXT(2,setup
,"baddev");
3885 dev
->mtu
= CLAW_DEFAULT_MTU_SIZE
;
3886 dev
->hard_start_xmit
= claw_tx
;
3887 dev
->open
= claw_open
;
3888 dev
->stop
= claw_release
;
3889 dev
->get_stats
= claw_stats
;
3890 dev
->change_mtu
= claw_change_mtu
;
3891 dev
->hard_header_len
= 0;
3893 dev
->type
= ARPHRD_SLIP
;
3894 dev
->tx_queue_len
= 1300;
3895 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
3896 SET_MODULE_OWNER(dev
);
3898 printk(KERN_INFO
"%s:%s Exit\n",dev
->name
,__FUNCTION__
);
3900 CLAW_DBF_TEXT(2,setup
,"initok");
3905 * Init a new channel in the privptr->channel[i].
3907 * @param cdev The ccw_device to be added.
3909 * @return 0 on success, !0 on error.
3912 add_channel(struct ccw_device
*cdev
,int i
,struct claw_privbk
*privptr
)
3917 printk(KERN_INFO
"%s:%s Enter\n",cdev
->dev
.bus_id
,__FUNCTION__
);
3919 CLAW_DBF_TEXT_(2,setup
,"%s",cdev
->dev
.bus_id
);
3920 privptr
->channel
[i
].flag
= i
+1; /* Read is 1 Write is 2 */
3921 p_ch
= &privptr
->channel
[i
];
3923 snprintf(p_ch
->id
, CLAW_ID_SIZE
, "cl-%s", cdev
->dev
.bus_id
);
3924 sscanf(cdev
->dev
.bus_id
+4,"%x",&p_ch
->devno
);
3925 if ((p_ch
->irb
= kmalloc(sizeof (struct irb
),GFP_KERNEL
)) == NULL
) {
3926 printk(KERN_WARNING
"%s Out of memory in %s for irb\n",
3927 p_ch
->id
,__FUNCTION__
);
3929 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3930 p_ch
->id
,__FUNCTION__
,__LINE__
);
3934 memset(p_ch
->irb
, 0, sizeof (struct irb
));
3936 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3937 cdev
->dev
.bus_id
,__FUNCTION__
,__LINE__
);
3945 * Setup an interface.
3947 * @param cgdev Device to be setup.
3949 * @returns 0 on success, !0 on failure.
3952 claw_new_device(struct ccwgroup_device
*cgdev
)
3954 struct claw_privbk
*privptr
;
3955 struct claw_env
*p_env
;
3956 struct net_device
*dev
;
3959 pr_debug("%s() called\n", __FUNCTION__
);
3960 printk(KERN_INFO
"claw: add for %s\n",cgdev
->cdev
[READ
]->dev
.bus_id
);
3961 CLAW_DBF_TEXT(2,setup
,"new_dev");
3962 privptr
= cgdev
->dev
.driver_data
;
3963 cgdev
->cdev
[READ
]->dev
.driver_data
= privptr
;
3964 cgdev
->cdev
[WRITE
]->dev
.driver_data
= privptr
;
3967 p_env
= privptr
->p_env
;
3968 sscanf(cgdev
->cdev
[READ
]->dev
.bus_id
+4,"%x",
3969 &p_env
->devno
[READ
]);
3970 sscanf(cgdev
->cdev
[WRITE
]->dev
.bus_id
+4,"%x",
3971 &p_env
->devno
[WRITE
]);
3972 ret
= add_channel(cgdev
->cdev
[0],0,privptr
);
3974 ret
= add_channel(cgdev
->cdev
[1],1,privptr
);
3977 "add channel failed "
3978 "with ret = %d\n", ret
);
3981 ret
= ccw_device_set_online(cgdev
->cdev
[READ
]);
3984 "claw: ccw_device_set_online %s READ failed "
3985 "with ret = %d\n",cgdev
->cdev
[READ
]->dev
.bus_id
,ret
);
3988 ret
= ccw_device_set_online(cgdev
->cdev
[WRITE
]);
3991 "claw: ccw_device_set_online %s WRITE failed "
3992 "with ret = %d\n",cgdev
->cdev
[WRITE
]->dev
.bus_id
, ret
);
3995 dev
= alloc_netdev(0,"claw%d",claw_init_netdevice
);
3997 printk(KERN_WARNING
"%s:alloc_netdev failed\n",__FUNCTION__
);
4000 dev
->priv
= privptr
;
4001 cgdev
->dev
.driver_data
= privptr
;
4002 cgdev
->cdev
[READ
]->dev
.driver_data
= privptr
;
4003 cgdev
->cdev
[WRITE
]->dev
.driver_data
= privptr
;
4005 SET_NETDEV_DEV(dev
, &cgdev
->dev
);
4006 if (register_netdev(dev
) != 0) {
4007 claw_free_netdevice(dev
, 1);
4008 CLAW_DBF_TEXT(2,trace
,"regfail");
4011 dev
->flags
&=~IFF_RUNNING
;
4012 if (privptr
->buffs_alloc
== 0) {
4013 ret
=init_ccw_bk(dev
);
4016 "claw: init_ccw_bk failed with ret=%d\n", ret
);
4017 unregister_netdev(dev
);
4018 claw_free_netdevice(dev
,1);
4019 CLAW_DBF_TEXT(2,trace
,"ccwmem");
4023 privptr
->channel
[READ
].ndev
= dev
;
4024 privptr
->channel
[WRITE
].ndev
= dev
;
4025 privptr
->p_env
->ndev
= dev
;
4027 printk(KERN_INFO
"%s:readsize=%d writesize=%d "
4028 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
4029 dev
->name
, p_env
->read_size
,
4030 p_env
->write_size
, p_env
->read_buffers
,
4031 p_env
->write_buffers
, p_env
->devno
[READ
],
4032 p_env
->devno
[WRITE
]);
4033 printk(KERN_INFO
"%s:host_name:%.8s, adapter_name "
4034 ":%.8s api_type: %.8s\n",
4035 dev
->name
, p_env
->host_name
,
4036 p_env
->adapter_name
, p_env
->api_type
);
4039 ccw_device_set_offline(cgdev
->cdev
[1]);
4040 ccw_device_set_offline(cgdev
->cdev
[0]);
4046 claw_purge_skb_queue(struct sk_buff_head
*q
)
4048 struct sk_buff
*skb
;
4050 CLAW_DBF_TEXT(4,trace
,"purgque");
4052 while ((skb
= skb_dequeue(q
))) {
4053 atomic_dec(&skb
->users
);
4054 dev_kfree_skb_any(skb
);
4059 * Shutdown an interface.
4061 * @param cgdev Device to be shut down.
4063 * @returns 0 on success, !0 on failure.
4066 claw_shutdown_device(struct ccwgroup_device
*cgdev
)
4068 struct claw_privbk
*priv
;
4069 struct net_device
*ndev
;
4072 pr_debug("%s() called\n", __FUNCTION__
);
4073 CLAW_DBF_TEXT_(2,setup
,"%s",cgdev
->dev
.bus_id
);
4074 priv
= cgdev
->dev
.driver_data
;
4077 ndev
= priv
->channel
[READ
].ndev
;
4079 /* Close the device */
4081 "%s: shuting down \n",ndev
->name
);
4082 if (ndev
->flags
& IFF_RUNNING
)
4083 ret
= claw_release(ndev
);
4084 ndev
->flags
&=~IFF_RUNNING
;
4085 unregister_netdev(ndev
);
4086 ndev
->priv
= NULL
; /* cgdev data, not ndev's to free */
4087 claw_free_netdevice(ndev
, 1);
4088 priv
->channel
[READ
].ndev
= NULL
;
4089 priv
->channel
[WRITE
].ndev
= NULL
;
4090 priv
->p_env
->ndev
= NULL
;
4092 ccw_device_set_offline(cgdev
->cdev
[1]);
4093 ccw_device_set_offline(cgdev
->cdev
[0]);
4098 claw_remove_device(struct ccwgroup_device
*cgdev
)
4100 struct claw_privbk
*priv
;
4102 pr_debug("%s() called\n", __FUNCTION__
);
4103 CLAW_DBF_TEXT_(2,setup
,"%s",cgdev
->dev
.bus_id
);
4104 priv
= cgdev
->dev
.driver_data
;
4106 printk(KERN_WARNING
"claw: %s() no Priv exiting\n",__FUNCTION__
);
4109 printk(KERN_INFO
"claw: %s() called %s will be removed.\n",
4110 __FUNCTION__
,cgdev
->cdev
[0]->dev
.bus_id
);
4111 if (cgdev
->state
== CCWGROUP_ONLINE
)
4112 claw_shutdown_device(cgdev
);
4113 claw_remove_files(&cgdev
->dev
);
4114 kfree(priv
->p_mtc_envelope
);
4115 priv
->p_mtc_envelope
=NULL
;
4118 kfree(priv
->channel
[0].irb
);
4119 priv
->channel
[0].irb
=NULL
;
4120 kfree(priv
->channel
[1].irb
);
4121 priv
->channel
[1].irb
=NULL
;
4123 cgdev
->dev
.driver_data
=NULL
;
4124 cgdev
->cdev
[READ
]->dev
.driver_data
= NULL
;
4125 cgdev
->cdev
[WRITE
]->dev
.driver_data
= NULL
;
4126 put_device(&cgdev
->dev
);
4134 claw_hname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4136 struct claw_privbk
*priv
;
4137 struct claw_env
* p_env
;
4139 priv
= dev
->driver_data
;
4142 p_env
= priv
->p_env
;
4143 return sprintf(buf
, "%s\n",p_env
->host_name
);
4147 claw_hname_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4149 struct claw_privbk
*priv
;
4150 struct claw_env
* p_env
;
4152 priv
= dev
->driver_data
;
4155 p_env
= priv
->p_env
;
4156 if (count
> MAX_NAME_LEN
+1)
4158 memset(p_env
->host_name
, 0x20, MAX_NAME_LEN
);
4159 strncpy(p_env
->host_name
,buf
, count
);
4160 p_env
->host_name
[count
-1] = 0x20; /* clear extra 0x0a */
4161 p_env
->host_name
[MAX_NAME_LEN
] = 0x00;
4162 CLAW_DBF_TEXT(2,setup
,"HstnSet");
4163 CLAW_DBF_TEXT_(2,setup
,"%s",p_env
->host_name
);
4168 static DEVICE_ATTR(host_name
, 0644, claw_hname_show
, claw_hname_write
);
4171 claw_adname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4173 struct claw_privbk
*priv
;
4174 struct claw_env
* p_env
;
4176 priv
= dev
->driver_data
;
4179 p_env
= priv
->p_env
;
4180 return sprintf(buf
, "%s\n",p_env
->adapter_name
);
4184 claw_adname_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4186 struct claw_privbk
*priv
;
4187 struct claw_env
* p_env
;
4189 priv
= dev
->driver_data
;
4192 p_env
= priv
->p_env
;
4193 if (count
> MAX_NAME_LEN
+1)
4195 memset(p_env
->adapter_name
, 0x20, MAX_NAME_LEN
);
4196 strncpy(p_env
->adapter_name
,buf
, count
);
4197 p_env
->adapter_name
[count
-1] = 0x20; /* clear extra 0x0a */
4198 p_env
->adapter_name
[MAX_NAME_LEN
] = 0x00;
4199 CLAW_DBF_TEXT(2,setup
,"AdnSet");
4200 CLAW_DBF_TEXT_(2,setup
,"%s",p_env
->adapter_name
);
4205 static DEVICE_ATTR(adapter_name
, 0644, claw_adname_show
, claw_adname_write
);
4208 claw_apname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4210 struct claw_privbk
*priv
;
4211 struct claw_env
* p_env
;
4213 priv
= dev
->driver_data
;
4216 p_env
= priv
->p_env
;
4217 return sprintf(buf
, "%s\n",
4222 claw_apname_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4224 struct claw_privbk
*priv
;
4225 struct claw_env
* p_env
;
4227 priv
= dev
->driver_data
;
4230 p_env
= priv
->p_env
;
4231 if (count
> MAX_NAME_LEN
+1)
4233 memset(p_env
->api_type
, 0x20, MAX_NAME_LEN
);
4234 strncpy(p_env
->api_type
,buf
, count
);
4235 p_env
->api_type
[count
-1] = 0x20; /* we get a loose 0x0a */
4236 p_env
->api_type
[MAX_NAME_LEN
] = 0x00;
4237 if(strncmp(p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
4238 p_env
->read_size
=DEF_PACK_BUFSIZE
;
4239 p_env
->write_size
=DEF_PACK_BUFSIZE
;
4240 p_env
->packing
=PACKING_ASK
;
4241 CLAW_DBF_TEXT(2,setup
,"PACKING");
4245 p_env
->read_size
=CLAW_FRAME_SIZE
;
4246 p_env
->write_size
=CLAW_FRAME_SIZE
;
4247 CLAW_DBF_TEXT(2,setup
,"ApiSet");
4249 CLAW_DBF_TEXT_(2,setup
,"%s",p_env
->api_type
);
4253 static DEVICE_ATTR(api_type
, 0644, claw_apname_show
, claw_apname_write
);
4256 claw_wbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4258 struct claw_privbk
*priv
;
4259 struct claw_env
* p_env
;
4261 priv
= dev
->driver_data
;
4264 p_env
= priv
->p_env
;
4265 return sprintf(buf
, "%d\n", p_env
->write_buffers
);
4269 claw_wbuff_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4271 struct claw_privbk
*priv
;
4272 struct claw_env
* p_env
;
4275 priv
= dev
->driver_data
;
4278 p_env
= priv
->p_env
;
4279 sscanf(buf
, "%i", &nnn
);
4280 if (p_env
->packing
) {
4286 if ((nnn
> max
) || (nnn
< 2))
4288 p_env
->write_buffers
= nnn
;
4289 CLAW_DBF_TEXT(2,setup
,"Wbufset");
4290 CLAW_DBF_TEXT_(2,setup
,"WB=%d",p_env
->write_buffers
);
4294 static DEVICE_ATTR(write_buffer
, 0644, claw_wbuff_show
, claw_wbuff_write
);
4297 claw_rbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4299 struct claw_privbk
*priv
;
4300 struct claw_env
* p_env
;
4302 priv
= dev
->driver_data
;
4305 p_env
= priv
->p_env
;
4306 return sprintf(buf
, "%d\n", p_env
->read_buffers
);
4310 claw_rbuff_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4312 struct claw_privbk
*priv
;
4313 struct claw_env
*p_env
;
4316 priv
= dev
->driver_data
;
4319 p_env
= priv
->p_env
;
4320 sscanf(buf
, "%i", &nnn
);
4321 if (p_env
->packing
) {
4327 if ((nnn
> max
) || (nnn
< 2))
4329 p_env
->read_buffers
= nnn
;
4330 CLAW_DBF_TEXT(2,setup
,"Rbufset");
4331 CLAW_DBF_TEXT_(2,setup
,"RB=%d",p_env
->read_buffers
);
4335 static DEVICE_ATTR(read_buffer
, 0644, claw_rbuff_show
, claw_rbuff_write
);
4337 static struct attribute
*claw_attr
[] = {
4338 &dev_attr_read_buffer
.attr
,
4339 &dev_attr_write_buffer
.attr
,
4340 &dev_attr_adapter_name
.attr
,
4341 &dev_attr_api_type
.attr
,
4342 &dev_attr_host_name
.attr
,
4346 static struct attribute_group claw_attr_group
= {
4351 claw_add_files(struct device
*dev
)
4353 pr_debug("%s() called\n", __FUNCTION__
);
4354 CLAW_DBF_TEXT(2,setup
,"add_file");
4355 return sysfs_create_group(&dev
->kobj
, &claw_attr_group
);
4359 claw_remove_files(struct device
*dev
)
4361 pr_debug("%s() called\n", __FUNCTION__
);
4362 CLAW_DBF_TEXT(2,setup
,"rem_file");
4363 sysfs_remove_group(&dev
->kobj
, &claw_attr_group
);
4366 /*--------------------------------------------------------------------*
4367 * claw_init and cleanup *
4368 *---------------------------------------------------------------------*/
4373 unregister_cu3088_discipline(&claw_group_driver
);
4374 claw_unregister_debug_facility();
4375 printk(KERN_INFO
"claw: Driver unloaded\n");
4380 * Initialize module.
4381 * This is called just after the module is loaded.
4383 * @return 0 on success, !0 on error.
4389 printk(KERN_INFO
"claw: starting driver\n");
4392 printk(KERN_INFO
"claw: %s() enter \n",__FUNCTION__
);
4394 ret
= claw_register_debug_facility();
4396 printk(KERN_WARNING
"claw: %s() debug_register failed %d\n",
4400 CLAW_DBF_TEXT(2,setup
,"init_mod");
4401 ret
= register_cu3088_discipline(&claw_group_driver
);
4403 claw_unregister_debug_facility();
4404 printk(KERN_WARNING
"claw; %s() cu3088 register failed %d\n",
4408 printk(KERN_INFO
"claw: %s() exit \n",__FUNCTION__
);
4413 module_init(claw_init
);
4414 module_exit(claw_cleanup
);
4418 /*--------------------------------------------------------------------*
4420 *---------------------------------------------------------------------*/