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 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 inline ccw_check_return_code (struct ccw_device
*cdev
,
228 static void inline ccw_check_unit_check (struct chbk
* p_ch
,
229 unsigned char sense
);
230 static int find_link(struct net_device
*dev
, char *host_name
, char *ws_name
);
231 static int claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
);
232 static int init_ccw_bk(struct net_device
*dev
);
233 static void probe_error( struct ccwgroup_device
*cgdev
);
234 static struct net_device_stats
*claw_stats(struct net_device
*dev
);
235 static int inline pages_to_order_of_mag(int num_of_pages
);
236 static struct sk_buff
*claw_pack_skb(struct claw_privbk
*privptr
);
238 static void dumpit (char *buf
, int len
);
240 /* sysfs Functions */
241 static ssize_t
claw_hname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
);
242 static ssize_t
claw_hname_write(struct device
*dev
, struct device_attribute
*attr
,
243 const char *buf
, size_t count
);
244 static ssize_t
claw_adname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
);
245 static ssize_t
claw_adname_write(struct device
*dev
, struct device_attribute
*attr
,
246 const char *buf
, size_t count
);
247 static ssize_t
claw_apname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
);
248 static ssize_t
claw_apname_write(struct device
*dev
, struct device_attribute
*attr
,
249 const char *buf
, size_t count
);
250 static ssize_t
claw_wbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
);
251 static ssize_t
claw_wbuff_write(struct device
*dev
, struct device_attribute
*attr
,
252 const char *buf
, size_t count
);
253 static ssize_t
claw_rbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
);
254 static ssize_t
claw_rbuff_write(struct device
*dev
, struct device_attribute
*attr
,
255 const char *buf
, size_t count
);
256 static int claw_add_files(struct device
*dev
);
257 static void claw_remove_files(struct device
*dev
);
259 /* Functions for System Validate */
260 static int claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
);
261 static int claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
262 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
);
263 static int claw_snd_conn_req(struct net_device
*dev
, __u8 link
);
264 static int claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
);
265 static int claw_snd_sys_validate_rsp(struct net_device
*dev
,
266 struct clawctl
* p_ctl
, __u32 return_code
);
267 static int claw_strt_conn_req(struct net_device
*dev
);
268 static void claw_strt_read ( struct net_device
*dev
, int lock
);
269 static void claw_strt_out_IO( struct net_device
*dev
);
270 static void claw_free_wrt_buf( struct net_device
*dev
);
272 /* Functions for unpack reads */
273 static void unpack_read (struct net_device
*dev
);
277 static struct ccwgroup_driver claw_group_driver
= {
278 .owner
= THIS_MODULE
,
281 .driver_id
= 0xC3D3C1E6,
283 .remove
= claw_remove_device
,
284 .set_online
= claw_new_device
,
285 .set_offline
= claw_shutdown_device
,
293 /*----------------------------------------------------------------*
295 * this function is called for each CLAW device. *
296 *----------------------------------------------------------------*/
298 claw_probe(struct ccwgroup_device
*cgdev
)
301 struct claw_privbk
*privptr
=NULL
;
304 printk(KERN_INFO
"%s Enter\n",__FUNCTION__
);
306 CLAW_DBF_TEXT(2,setup
,"probe");
307 if (!get_device(&cgdev
->dev
))
310 printk(KERN_INFO
"claw: variable cgdev =\n");
311 dumpit((char *)cgdev
, sizeof(struct ccwgroup_device
));
313 privptr
= kzalloc(sizeof(struct claw_privbk
), GFP_KERNEL
);
314 if (privptr
== NULL
) {
316 put_device(&cgdev
->dev
);
317 printk(KERN_WARNING
"Out of memory %s %s Exit Line %d \n",
318 cgdev
->cdev
[0]->dev
.bus_id
,__FUNCTION__
,__LINE__
);
319 CLAW_DBF_TEXT_(2,setup
,"probex%d",-ENOMEM
);
322 privptr
->p_mtc_envelope
= kmalloc( MAX_ENVELOPE_SIZE
, GFP_KERNEL
);
323 privptr
->p_env
= kmalloc(sizeof(struct claw_env
), GFP_KERNEL
);
324 if ((privptr
->p_mtc_envelope
==NULL
) || (privptr
->p_env
==NULL
)) {
326 put_device(&cgdev
->dev
);
327 printk(KERN_WARNING
"Out of memory %s %s Exit Line %d \n",
328 cgdev
->cdev
[0]->dev
.bus_id
,__FUNCTION__
,__LINE__
);
329 CLAW_DBF_TEXT_(2,setup
,"probex%d",-ENOMEM
);
332 memset(privptr
->p_mtc_envelope
, 0x00, MAX_ENVELOPE_SIZE
);
333 memset(privptr
->p_env
, 0x00, sizeof(struct claw_env
));
334 memcpy(privptr
->p_env
->adapter_name
,WS_NAME_NOT_DEF
,8);
335 memcpy(privptr
->p_env
->host_name
,WS_NAME_NOT_DEF
,8);
336 memcpy(privptr
->p_env
->api_type
,WS_NAME_NOT_DEF
,8);
337 privptr
->p_env
->packing
= 0;
338 privptr
->p_env
->write_buffers
= 5;
339 privptr
->p_env
->read_buffers
= 5;
340 privptr
->p_env
->read_size
= CLAW_FRAME_SIZE
;
341 privptr
->p_env
->write_size
= CLAW_FRAME_SIZE
;
342 rc
= claw_add_files(&cgdev
->dev
);
345 put_device(&cgdev
->dev
);
346 printk(KERN_WARNING
"add_files failed %s %s Exit Line %d \n",
347 cgdev
->cdev
[0]->dev
.bus_id
,__FUNCTION__
,__LINE__
);
348 CLAW_DBF_TEXT_(2,setup
,"probex%d",rc
);
351 printk(KERN_INFO
"claw: sysfs files added for %s\n",cgdev
->cdev
[0]->dev
.bus_id
);
352 privptr
->p_env
->p_priv
= privptr
;
353 cgdev
->cdev
[0]->handler
= claw_irq_handler
;
354 cgdev
->cdev
[1]->handler
= claw_irq_handler
;
355 cgdev
->dev
.driver_data
= privptr
;
357 printk(KERN_INFO
"claw:%s exit on line %d, "
358 "rc = 0\n",__FUNCTION__
,__LINE__
);
360 CLAW_DBF_TEXT(2,setup
,"prbext 0");
363 } /* end of claw_probe */
365 /*-------------------------------------------------------------------*
367 *-------------------------------------------------------------------*/
370 claw_tx(struct sk_buff
*skb
, struct net_device
*dev
)
373 struct claw_privbk
*privptr
=dev
->priv
;
374 unsigned long saveflags
;
378 printk(KERN_INFO
"%s:%s enter\n",dev
->name
,__FUNCTION__
);
380 CLAW_DBF_TEXT(4,trace
,"claw_tx");
381 p_ch
=&privptr
->channel
[WRITE
];
383 printk(KERN_WARNING
"%s: null pointer passed as sk_buffer\n",
385 privptr
->stats
.tx_dropped
++;
387 printk(KERN_INFO
"%s: %s() exit on line %d, rc = EIO\n",
388 dev
->name
,__FUNCTION__
, __LINE__
);
390 CLAW_DBF_TEXT_(2,trace
,"clawtx%d",-EIO
);
395 printk(KERN_INFO
"%s: variable sk_buff=\n",dev
->name
);
396 dumpit((char *) skb
, sizeof(struct sk_buff
));
397 printk(KERN_INFO
"%s: variable dev=\n",dev
->name
);
398 dumpit((char *) dev
, sizeof(struct net_device
));
400 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
401 rc
=claw_hw_tx( skb
, dev
, 1 );
402 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
404 printk(KERN_INFO
"%s:%s exit on line %d, rc = %d\n",
405 dev
->name
, __FUNCTION__
, __LINE__
, rc
);
407 CLAW_DBF_TEXT_(4,trace
,"clawtx%d",rc
);
409 } /* end of claw_tx */
411 /*------------------------------------------------------------------*
412 * pack the collect queue into an skb and return it *
413 * If not packing just return the top skb from the queue *
414 *------------------------------------------------------------------*/
416 static struct sk_buff
*
417 claw_pack_skb(struct claw_privbk
*privptr
)
419 struct sk_buff
*new_skb
,*held_skb
;
420 struct chbk
*p_ch
= &privptr
->channel
[WRITE
];
421 struct claw_env
*p_env
= privptr
->p_env
;
422 int pkt_cnt
,pk_ind
,so_far
;
424 new_skb
= NULL
; /* assume no dice */
426 CLAW_DBF_TEXT(4,trace
,"PackSKBe");
427 if (!skb_queue_empty(&p_ch
->collect_queue
)) {
429 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
431 dev_kfree_skb_any(held_skb
);
434 if (p_env
->packing
!= DO_PACKED
)
436 /* get a new SKB we will pack at least one */
437 new_skb
= dev_alloc_skb(p_env
->write_size
);
438 if (new_skb
== NULL
) {
439 atomic_inc(&held_skb
->users
);
440 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
443 /* we have packed packet and a place to put it */
446 new_skb
->cb
[1] = 'P'; /* every skb on queue has pack header */
447 while ((pk_ind
) && (held_skb
!= NULL
)) {
448 if (held_skb
->len
+so_far
<= p_env
->write_size
-8) {
449 memcpy(skb_put(new_skb
,held_skb
->len
),
450 held_skb
->data
,held_skb
->len
);
451 privptr
->stats
.tx_packets
++;
452 so_far
+= held_skb
->len
;
454 dev_kfree_skb_any(held_skb
);
455 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
457 atomic_dec(&held_skb
->users
);
460 atomic_inc(&held_skb
->users
);
461 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
465 printk(KERN_INFO
"%s: %s() Packed %d len %d\n",
467 __FUNCTION__
,pkt_cnt
,new_skb
->len
);
470 CLAW_DBF_TEXT(4,trace
,"PackSKBx");
474 /*-------------------------------------------------------------------*
477 *-------------------------------------------------------------------*/
480 claw_change_mtu(struct net_device
*dev
, int new_mtu
)
482 struct claw_privbk
*privptr
=dev
->priv
;
485 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
488 printk(KERN_INFO
"variable dev =\n");
489 dumpit((char *) dev
, sizeof(struct net_device
));
490 printk(KERN_INFO
"variable new_mtu = %d\n", new_mtu
);
492 CLAW_DBF_TEXT(4,trace
,"setmtu");
493 buff_size
= privptr
->p_env
->write_size
;
494 if ((new_mtu
< 60) || (new_mtu
> buff_size
)) {
496 printk(KERN_INFO
"%s:%s Exit on line %d, rc=EINVAL\n",
498 __FUNCTION__
, __LINE__
);
504 printk(KERN_INFO
"%s:%s Exit on line %d\n",dev
->name
,
505 __FUNCTION__
, __LINE__
);
508 } /* end of claw_change_mtu */
511 /*-------------------------------------------------------------------*
514 *-------------------------------------------------------------------*/
516 claw_open(struct net_device
*dev
)
521 unsigned long saveflags
=0;
523 struct claw_privbk
*privptr
;
524 DECLARE_WAITQUEUE(wait
, current
);
525 struct timer_list timer
;
529 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
531 CLAW_DBF_TEXT(4,trace
,"open");
532 if (!dev
| (dev
->name
[0] == 0x00)) {
533 CLAW_DBF_TEXT(2,trace
,"BadDev");
534 printk(KERN_WARNING
"claw: Bad device at open failing \n");
537 privptr
= (struct claw_privbk
*)dev
->priv
;
538 /* allocate and initialize CCW blocks */
539 if (privptr
->buffs_alloc
== 0) {
542 printk(KERN_INFO
"%s:%s Exit on line %d, rc=ENOMEM\n",
544 __FUNCTION__
, __LINE__
);
545 CLAW_DBF_TEXT(2,trace
,"openmem");
549 privptr
->system_validate_comp
=0;
550 privptr
->release_pend
=0;
551 if(strncmp(privptr
->p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
552 privptr
->p_env
->read_size
=DEF_PACK_BUFSIZE
;
553 privptr
->p_env
->write_size
=DEF_PACK_BUFSIZE
;
554 privptr
->p_env
->packing
=PACKING_ASK
;
556 privptr
->p_env
->packing
=0;
557 privptr
->p_env
->read_size
=CLAW_FRAME_SIZE
;
558 privptr
->p_env
->write_size
=CLAW_FRAME_SIZE
;
561 tasklet_init(&privptr
->channel
[READ
].tasklet
, claw_irq_tasklet
,
562 (unsigned long) &privptr
->channel
[READ
]);
563 for ( i
= 0; i
< 2; i
++) {
564 CLAW_DBF_TEXT_(2,trace
,"opn_ch%d",i
);
565 init_waitqueue_head(&privptr
->channel
[i
].wait
);
566 /* skb_queue_head_init(&p_ch->io_queue); */
569 &privptr
->channel
[WRITE
].collect_queue
);
570 privptr
->channel
[i
].flag_a
= 0;
571 privptr
->channel
[i
].IO_active
= 0;
572 privptr
->channel
[i
].flag
&= ~CLAW_TIMER
;
574 timer
.function
= (void *)claw_timer
;
575 timer
.data
= (unsigned long)(&privptr
->channel
[i
]);
576 timer
.expires
= jiffies
+ 15*HZ
;
578 spin_lock_irqsave(get_ccwdev_lock(
579 privptr
->channel
[i
].cdev
), saveflags
);
580 parm
= (unsigned long) &privptr
->channel
[i
];
581 privptr
->channel
[i
].claw_state
= CLAW_START_HALT_IO
;
583 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
584 rc
= ccw_device_halt(
585 (struct ccw_device
*)privptr
->channel
[i
].cdev
,parm
);
586 set_current_state(TASK_INTERRUPTIBLE
);
587 spin_unlock_irqrestore(
588 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
590 set_current_state(TASK_RUNNING
);
591 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
593 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
594 if((privptr
->channel
[i
].flag
& CLAW_TIMER
) == 0x00)
597 if ((((privptr
->channel
[READ
].last_dstat
|
598 privptr
->channel
[WRITE
].last_dstat
) &
599 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) ||
600 (((privptr
->channel
[READ
].flag
|
601 privptr
->channel
[WRITE
].flag
) & CLAW_TIMER
) != 0x00)) {
603 printk(KERN_INFO
"%s: channel problems during open - read:"
604 " %02x - write: %02x\n",
606 privptr
->channel
[READ
].last_dstat
,
607 privptr
->channel
[WRITE
].last_dstat
);
609 printk(KERN_INFO
"%s: remote side is not ready\n", dev
->name
);
610 CLAW_DBF_TEXT(2,trace
,"notrdy");
612 for ( i
= 0; i
< 2; i
++) {
614 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
616 parm
= (unsigned long) &privptr
->channel
[i
];
617 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
618 rc
= ccw_device_halt(
619 (struct ccw_device
*)&privptr
->channel
[i
].cdev
,
621 spin_unlock_irqrestore(
622 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
625 ccw_check_return_code(
626 privptr
->channel
[i
].cdev
, rc
);
629 free_pages((unsigned long)privptr
->p_buff_ccw
,
630 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
631 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
632 free_pages((unsigned long)privptr
->p_buff_read
,
633 (int)pages_to_order_of_mag(
634 privptr
->p_buff_read_num
));
637 p_buf
=privptr
->p_read_active_first
;
638 while (p_buf
!=NULL
) {
639 free_pages((unsigned long)p_buf
->p_buffer
,
640 (int)pages_to_order_of_mag(
641 privptr
->p_buff_pages_perread
));
645 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
646 free_pages((unsigned long)privptr
->p_buff_write
,
647 (int)pages_to_order_of_mag(
648 privptr
->p_buff_write_num
));
651 p_buf
=privptr
->p_write_active_first
;
652 while (p_buf
!=NULL
) {
653 free_pages((unsigned long)p_buf
->p_buffer
,
654 (int)pages_to_order_of_mag(
655 privptr
->p_buff_pages_perwrite
));
659 privptr
->buffs_alloc
= 0;
660 privptr
->channel
[READ
].flag
= 0x00;
661 privptr
->channel
[WRITE
].flag
= 0x00;
662 privptr
->p_buff_ccw
=NULL
;
663 privptr
->p_buff_read
=NULL
;
664 privptr
->p_buff_write
=NULL
;
665 claw_clear_busy(dev
);
667 printk(KERN_INFO
"%s:%s Exit on line %d, rc=EIO\n",
668 dev
->name
,__FUNCTION__
,__LINE__
);
670 CLAW_DBF_TEXT(2,trace
,"open EIO");
674 /* Send SystemValidate command */
676 claw_clear_busy(dev
);
679 printk(KERN_INFO
"%s:%s Exit on line %d, rc=0\n",
680 dev
->name
,__FUNCTION__
,__LINE__
);
682 CLAW_DBF_TEXT(4,trace
,"openok");
684 } /* end of claw_open */
686 /*-------------------------------------------------------------------*
690 *--------------------------------------------------------------------*/
692 claw_irq_handler(struct ccw_device
*cdev
,
693 unsigned long intparm
, struct irb
*irb
)
695 struct chbk
*p_ch
= NULL
;
696 struct claw_privbk
*privptr
= NULL
;
697 struct net_device
*dev
= NULL
;
698 struct claw_env
*p_env
;
699 struct chbk
*p_ch_r
=NULL
;
703 printk(KERN_INFO
"%s enter \n",__FUNCTION__
);
705 CLAW_DBF_TEXT(4,trace
,"clawirq");
706 /* Bypass all 'unsolicited interrupts' */
707 if (!cdev
->dev
.driver_data
) {
708 printk(KERN_WARNING
"claw: unsolicited interrupt for device:"
709 "%s received c-%02x d-%02x\n",
710 cdev
->dev
.bus_id
,irb
->scsw
.cstat
, irb
->scsw
.dstat
);
712 printk(KERN_INFO
"claw: %s() "
713 "exit on line %d\n",__FUNCTION__
,__LINE__
);
715 CLAW_DBF_TEXT(2,trace
,"badirq");
718 privptr
= (struct claw_privbk
*)cdev
->dev
.driver_data
;
720 /* Try to extract channel from driver data. */
721 if (privptr
->channel
[READ
].cdev
== cdev
)
722 p_ch
= &privptr
->channel
[READ
];
723 else if (privptr
->channel
[WRITE
].cdev
== cdev
)
724 p_ch
= &privptr
->channel
[WRITE
];
726 printk(KERN_WARNING
"claw: Can't determine channel for "
727 "interrupt, device %s\n", cdev
->dev
.bus_id
);
728 CLAW_DBF_TEXT(2,trace
,"badchan");
731 CLAW_DBF_TEXT_(4,trace
,"IRQCH=%d",p_ch
->flag
);
733 dev
= (struct net_device
*) (p_ch
->ndev
);
734 p_env
=privptr
->p_env
;
737 printk(KERN_INFO
"%s: interrupt for device: %04x "
738 "received c-%02x d-%02x state-%02x\n",
739 dev
->name
, p_ch
->devno
, irb
->scsw
.cstat
,
740 irb
->scsw
.dstat
, p_ch
->claw_state
);
743 /* Copy interruption response block. */
744 memcpy(p_ch
->irb
, irb
, sizeof(struct irb
));
746 /* Check for good subchannel return code, otherwise error message */
747 if (irb
->scsw
.cstat
&& !(irb
->scsw
.cstat
& SCHN_STAT_PCI
)) {
748 printk(KERN_INFO
"%s: subchannel check for device: %04x -"
749 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
750 dev
->name
, p_ch
->devno
,
751 irb
->scsw
.cstat
, irb
->scsw
.dstat
,irb
->scsw
.cpa
);
753 dumpit((char *)irb
,sizeof(struct irb
));
754 dumpit((char *)(unsigned long)irb
->scsw
.cpa
,
755 sizeof(struct ccw1
));
758 printk(KERN_INFO
"%s:%s Exit on line %d\n",
759 dev
->name
,__FUNCTION__
,__LINE__
);
761 CLAW_DBF_TEXT(2,trace
,"chanchk");
765 /* Check the reason-code of a unit check */
766 if (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) {
767 ccw_check_unit_check(p_ch
, irb
->ecw
[0]);
770 /* State machine to bring the connection up, down and to restart */
771 p_ch
->last_dstat
= irb
->scsw
.dstat
;
773 switch (p_ch
->claw_state
) {
774 case CLAW_STOP
:/* HALT_IO by claw_release (halt sequence) */
776 printk(KERN_INFO
"%s: CLAW_STOP enter\n", dev
->name
);
778 if (!((p_ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
779 (p_ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
780 (p_ch
->irb
->scsw
.stctl
==
781 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
783 printk(KERN_INFO
"%s:%s Exit on line %d\n",
784 dev
->name
,__FUNCTION__
,__LINE__
);
788 wake_up(&p_ch
->wait
); /* wake up claw_release */
791 printk(KERN_INFO
"%s: CLAW_STOP exit\n", dev
->name
);
794 printk(KERN_INFO
"%s:%s Exit on line %d\n",
795 dev
->name
,__FUNCTION__
,__LINE__
);
797 CLAW_DBF_TEXT(4,trace
,"stop");
800 case CLAW_START_HALT_IO
: /* HALT_IO issued by claw_open */
802 printk(KERN_INFO
"%s: process CLAW_STAT_HALT_IO\n",
805 if (!((p_ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
806 (p_ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
807 (p_ch
->irb
->scsw
.stctl
==
808 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
810 printk(KERN_INFO
"%s:%s Exit on line %d\n",
811 dev
->name
,__FUNCTION__
,__LINE__
);
813 CLAW_DBF_TEXT(4,trace
,"haltio");
816 if (p_ch
->flag
== CLAW_READ
) {
817 p_ch
->claw_state
= CLAW_START_READ
;
818 wake_up(&p_ch
->wait
); /* wake claw_open (READ)*/
821 if (p_ch
->flag
== CLAW_WRITE
) {
822 p_ch
->claw_state
= CLAW_START_WRITE
;
823 /* send SYSTEM_VALIDATE */
824 claw_strt_read(dev
, LOCK_NO
);
825 claw_send_control(dev
,
826 SYSTEM_VALIDATE_REQUEST
,
829 p_env
->adapter_name
);
831 printk(KERN_WARNING
"claw: unsolicited "
832 "interrupt for device:"
833 "%s received c-%02x d-%02x\n",
840 printk(KERN_INFO
"%s: process CLAW_STAT_HALT_IO exit\n",
844 printk(KERN_INFO
"%s:%s Exit on line %d\n",
845 dev
->name
,__FUNCTION__
,__LINE__
);
847 CLAW_DBF_TEXT(4,trace
,"haltio");
849 case CLAW_START_READ
:
850 CLAW_DBF_TEXT(4,trace
,"ReadIRQ");
851 if (p_ch
->irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) {
852 clear_bit(0, (void *)&p_ch
->IO_active
);
853 if ((p_ch
->irb
->ecw
[0] & 0x41) == 0x41 ||
854 (p_ch
->irb
->ecw
[0] & 0x40) == 0x40 ||
855 (p_ch
->irb
->ecw
[0]) == 0)
857 privptr
->stats
.rx_errors
++;
858 printk(KERN_INFO
"%s: Restart is "
859 "required after remote "
864 printk(KERN_INFO
"%s:%s Exit on line %d\n",
865 dev
->name
,__FUNCTION__
,__LINE__
);
867 CLAW_DBF_TEXT(4,trace
,"notrdy");
870 if ((p_ch
->irb
->scsw
.cstat
& SCHN_STAT_PCI
) &&
871 (p_ch
->irb
->scsw
.dstat
==0)) {
872 if (test_and_set_bit(CLAW_BH_ACTIVE
,
873 (void *)&p_ch
->flag_a
) == 0) {
874 tasklet_schedule(&p_ch
->tasklet
);
877 CLAW_DBF_TEXT(4,trace
,"PCINoBH");
880 printk(KERN_INFO
"%s:%s Exit on line %d\n",
881 dev
->name
,__FUNCTION__
,__LINE__
);
883 CLAW_DBF_TEXT(4,trace
,"PCI_read");
886 if(!((p_ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
887 (p_ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
888 (p_ch
->irb
->scsw
.stctl
==
889 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
891 printk(KERN_INFO
"%s:%s Exit on line %d\n",
892 dev
->name
,__FUNCTION__
,__LINE__
);
894 CLAW_DBF_TEXT(4,trace
,"SPend_rd");
897 clear_bit(0, (void *)&p_ch
->IO_active
);
898 claw_clearbit_busy(TB_RETRY
,dev
);
899 if (test_and_set_bit(CLAW_BH_ACTIVE
,
900 (void *)&p_ch
->flag_a
) == 0) {
901 tasklet_schedule(&p_ch
->tasklet
);
904 CLAW_DBF_TEXT(4,trace
,"RdBHAct");
908 printk(KERN_INFO
"%s: process CLAW_START_READ exit\n",
912 printk(KERN_INFO
"%s:%s Exit on line %d\n",
913 dev
->name
,__FUNCTION__
,__LINE__
);
915 CLAW_DBF_TEXT(4,trace
,"RdIRQXit");
917 case CLAW_START_WRITE
:
918 if (p_ch
->irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) {
919 printk(KERN_INFO
"%s: Unit Check Occured in "
920 "write channel\n",dev
->name
);
921 clear_bit(0, (void *)&p_ch
->IO_active
);
922 if (p_ch
->irb
->ecw
[0] & 0x80 ) {
923 printk(KERN_INFO
"%s: Resetting Event "
924 "occurred:\n",dev
->name
);
925 init_timer(&p_ch
->timer
);
926 p_ch
->timer
.function
=
927 (void *)claw_write_retry
;
928 p_ch
->timer
.data
= (unsigned long)p_ch
;
929 p_ch
->timer
.expires
= jiffies
+ 10*HZ
;
930 add_timer(&p_ch
->timer
);
931 printk(KERN_INFO
"%s: write connection "
932 "restarting\n",dev
->name
);
935 printk(KERN_INFO
"%s:%s Exit on line %d\n",
936 dev
->name
,__FUNCTION__
,__LINE__
);
938 CLAW_DBF_TEXT(4,trace
,"rstrtwrt");
941 if (p_ch
->irb
->scsw
.dstat
& DEV_STAT_UNIT_EXCEP
) {
942 clear_bit(0, (void *)&p_ch
->IO_active
);
943 printk(KERN_INFO
"%s: Unit Exception "
944 "Occured in write channel\n",
947 if(!((p_ch
->irb
->scsw
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
948 (p_ch
->irb
->scsw
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
949 (p_ch
->irb
->scsw
.stctl
==
950 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
952 printk(KERN_INFO
"%s:%s Exit on line %d\n",
953 dev
->name
,__FUNCTION__
,__LINE__
);
955 CLAW_DBF_TEXT(4,trace
,"writeUE");
958 clear_bit(0, (void *)&p_ch
->IO_active
);
959 if (claw_test_and_setbit_busy(TB_TX
,dev
)==0) {
960 claw_write_next(p_ch
);
961 claw_clearbit_busy(TB_TX
,dev
);
962 claw_clear_busy(dev
);
964 p_ch_r
=(struct chbk
*)&privptr
->channel
[READ
];
965 if (test_and_set_bit(CLAW_BH_ACTIVE
,
966 (void *)&p_ch_r
->flag_a
) == 0) {
967 tasklet_schedule(&p_ch_r
->tasklet
);
971 printk(KERN_INFO
"%s: process CLAW_START_WRITE exit\n",
975 printk(KERN_INFO
"%s:%s Exit on line %d\n",
976 dev
->name
,__FUNCTION__
,__LINE__
);
978 CLAW_DBF_TEXT(4,trace
,"StWtExit");
981 printk(KERN_WARNING
"%s: wrong selection code - irq "
982 "state=%d\n",dev
->name
,p_ch
->claw_state
);
984 printk(KERN_INFO
"%s:%s Exit on line %d\n",
985 dev
->name
,__FUNCTION__
,__LINE__
);
987 CLAW_DBF_TEXT(2,trace
,"badIRQ");
991 } /* end of claw_irq_handler */
994 /*-------------------------------------------------------------------*
997 *--------------------------------------------------------------------*/
999 claw_irq_tasklet ( unsigned long data
)
1002 struct net_device
*dev
;
1003 struct claw_privbk
* privptr
;
1005 p_ch
= (struct chbk
*) data
;
1006 dev
= (struct net_device
*)p_ch
->ndev
;
1008 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
1011 printk(KERN_INFO
"%s: variable p_ch =\n",dev
->name
);
1012 dumpit((char *) p_ch
, sizeof(struct chbk
));
1014 CLAW_DBF_TEXT(4,trace
,"IRQtask");
1016 privptr
= (struct claw_privbk
*) dev
->priv
;
1019 printk(KERN_INFO
"%s: bh routine - state-%02x\n" ,
1020 dev
->name
, p_ch
->claw_state
);
1024 clear_bit(CLAW_BH_ACTIVE
, (void *)&p_ch
->flag_a
);
1025 CLAW_DBF_TEXT(4,trace
,"TskletXt");
1027 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1028 dev
->name
,__FUNCTION__
,__LINE__
);
1031 } /* end of claw_irq_bh */
1033 /*-------------------------------------------------------------------*
1036 *--------------------------------------------------------------------*/
1038 claw_release(struct net_device
*dev
)
1042 unsigned long saveflags
;
1044 struct claw_privbk
*privptr
;
1045 DECLARE_WAITQUEUE(wait
, current
);
1046 struct ccwbk
* p_this_ccw
;
1047 struct ccwbk
* p_buf
;
1051 privptr
= (struct claw_privbk
*) dev
->priv
;
1055 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
1057 CLAW_DBF_TEXT(4,trace
,"release");
1059 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
1060 dumpit((char *) dev
, sizeof(struct net_device
));
1061 printk(KERN_INFO
"Priv Buffalloc %d\n",privptr
->buffs_alloc
);
1062 printk(KERN_INFO
"Priv p_buff_ccw = %p\n",&privptr
->p_buff_ccw
);
1064 privptr
->release_pend
=1;
1065 claw_setbit_busy(TB_STOP
,dev
);
1066 for ( i
= 1; i
>=0 ; i
--) {
1068 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
1069 /* del_timer(&privptr->channel[READ].timer); */
1070 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
1071 privptr
->channel
[i
].IO_active
= 0;
1072 parm
= (unsigned long) &privptr
->channel
[i
];
1074 claw_purge_skb_queue(
1075 &privptr
->channel
[WRITE
].collect_queue
);
1076 rc
= ccw_device_halt (privptr
->channel
[i
].cdev
, parm
);
1077 if (privptr
->system_validate_comp
==0x00) /* never opened? */
1078 init_waitqueue_head(&privptr
->channel
[i
].wait
);
1079 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
1080 set_current_state(TASK_INTERRUPTIBLE
);
1081 spin_unlock_irqrestore(
1082 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
1084 set_current_state(TASK_RUNNING
);
1085 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
1087 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
1090 if (privptr
->pk_skb
!= NULL
) {
1091 dev_kfree_skb_any(privptr
->pk_skb
);
1092 privptr
->pk_skb
= NULL
;
1094 if(privptr
->buffs_alloc
!= 1) {
1096 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1097 dev
->name
,__FUNCTION__
,__LINE__
);
1099 CLAW_DBF_TEXT(4,trace
,"none2fre");
1102 CLAW_DBF_TEXT(4,trace
,"freebufs");
1103 if (privptr
->p_buff_ccw
!= NULL
) {
1104 free_pages((unsigned long)privptr
->p_buff_ccw
,
1105 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
1107 CLAW_DBF_TEXT(4,trace
,"freeread");
1108 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1109 if (privptr
->p_buff_read
!= NULL
) {
1110 free_pages((unsigned long)privptr
->p_buff_read
,
1111 (int)pages_to_order_of_mag(privptr
->p_buff_read_num
));
1115 p_buf
=privptr
->p_read_active_first
;
1116 while (p_buf
!=NULL
) {
1117 free_pages((unsigned long)p_buf
->p_buffer
,
1118 (int)pages_to_order_of_mag(
1119 privptr
->p_buff_pages_perread
));
1123 CLAW_DBF_TEXT(4,trace
,"freewrit");
1124 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1125 free_pages((unsigned long)privptr
->p_buff_write
,
1126 (int)pages_to_order_of_mag(privptr
->p_buff_write_num
));
1129 p_buf
=privptr
->p_write_active_first
;
1130 while (p_buf
!=NULL
) {
1131 free_pages((unsigned long)p_buf
->p_buffer
,
1132 (int)pages_to_order_of_mag(
1133 privptr
->p_buff_pages_perwrite
));
1137 CLAW_DBF_TEXT(4,trace
,"clearptr");
1138 privptr
->buffs_alloc
= 0;
1139 privptr
->p_buff_ccw
=NULL
;
1140 privptr
->p_buff_read
=NULL
;
1141 privptr
->p_buff_write
=NULL
;
1142 privptr
->system_validate_comp
=0;
1143 privptr
->release_pend
=0;
1144 /* Remove any writes that were pending and reset all reads */
1145 p_this_ccw
=privptr
->p_read_active_first
;
1146 while (p_this_ccw
!=NULL
) {
1147 p_this_ccw
->header
.length
=0xffff;
1148 p_this_ccw
->header
.opcode
=0xff;
1149 p_this_ccw
->header
.flag
=0x00;
1150 p_this_ccw
=p_this_ccw
->next
;
1153 while (privptr
->p_write_active_first
!=NULL
) {
1154 p_this_ccw
=privptr
->p_write_active_first
;
1155 p_this_ccw
->header
.flag
=CLAW_PENDING
;
1156 privptr
->p_write_active_first
=p_this_ccw
->next
;
1157 p_this_ccw
->next
=privptr
->p_write_free_chain
;
1158 privptr
->p_write_free_chain
=p_this_ccw
;
1159 ++privptr
->write_free_count
;
1161 privptr
->p_write_active_last
=NULL
;
1162 privptr
->mtc_logical_link
= -1;
1163 privptr
->mtc_skipping
= 1;
1164 privptr
->mtc_offset
=0;
1166 if (((privptr
->channel
[READ
].last_dstat
|
1167 privptr
->channel
[WRITE
].last_dstat
) &
1168 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) {
1169 printk(KERN_WARNING
"%s: channel problems during close - "
1170 "read: %02x - write: %02x\n",
1172 privptr
->channel
[READ
].last_dstat
,
1173 privptr
->channel
[WRITE
].last_dstat
);
1174 CLAW_DBF_TEXT(2,trace
,"badclose");
1177 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1178 dev
->name
,__FUNCTION__
,__LINE__
);
1180 CLAW_DBF_TEXT(4,trace
,"rlsexit");
1182 } /* end of claw_release */
1186 /*-------------------------------------------------------------------*
1187 * claw_write_retry *
1189 *--------------------------------------------------------------------*/
1192 claw_write_retry ( struct chbk
*p_ch
)
1195 struct net_device
*dev
=p_ch
->ndev
;
1199 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
1200 printk(KERN_INFO
"claw: variable p_ch =\n");
1201 dumpit((char *) p_ch
, sizeof(struct chbk
));
1203 CLAW_DBF_TEXT(4,trace
,"w_retry");
1204 if (p_ch
->claw_state
== CLAW_STOP
) {
1206 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1207 dev
->name
,__FUNCTION__
,__LINE__
);
1212 printk( KERN_INFO
"%s:%s state-%02x\n" ,
1217 claw_strt_out_IO( dev
);
1219 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1220 dev
->name
,__FUNCTION__
,__LINE__
);
1222 CLAW_DBF_TEXT(4,trace
,"rtry_xit");
1224 } /* end of claw_write_retry */
1227 /*-------------------------------------------------------------------*
1230 *--------------------------------------------------------------------*/
1233 claw_write_next ( struct chbk
* p_ch
)
1236 struct net_device
*dev
;
1237 struct claw_privbk
*privptr
=NULL
;
1238 struct sk_buff
*pk_skb
;
1242 printk(KERN_INFO
"%s:%s Enter \n",p_ch
->ndev
->name
,__FUNCTION__
);
1243 printk(KERN_INFO
"%s: variable p_ch =\n",p_ch
->ndev
->name
);
1244 dumpit((char *) p_ch
, sizeof(struct chbk
));
1246 CLAW_DBF_TEXT(4,trace
,"claw_wrt");
1247 if (p_ch
->claw_state
== CLAW_STOP
)
1249 dev
= (struct net_device
*) p_ch
->ndev
;
1250 privptr
= (struct claw_privbk
*) dev
->priv
;
1251 claw_free_wrt_buf( dev
);
1252 if ((privptr
->write_free_count
> 0) &&
1253 !skb_queue_empty(&p_ch
->collect_queue
)) {
1254 pk_skb
= claw_pack_skb(privptr
);
1255 while (pk_skb
!= NULL
) {
1256 rc
= claw_hw_tx( pk_skb
, dev
,1);
1257 if (privptr
->write_free_count
> 0) {
1258 pk_skb
= claw_pack_skb(privptr
);
1263 if (privptr
->p_write_active_first
!=NULL
) {
1264 claw_strt_out_IO(dev
);
1268 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1269 dev
->name
,__FUNCTION__
,__LINE__
);
1272 } /* end of claw_write_next */
1274 /*-------------------------------------------------------------------*
1277 *--------------------------------------------------------------------*/
1280 claw_timer ( struct chbk
* p_ch
)
1283 printk(KERN_INFO
"%s:%s Entry\n",p_ch
->ndev
->name
,__FUNCTION__
);
1284 printk(KERN_INFO
"%s: variable p_ch =\n",p_ch
->ndev
->name
);
1285 dumpit((char *) p_ch
, sizeof(struct chbk
));
1287 CLAW_DBF_TEXT(4,trace
,"timer");
1288 p_ch
->flag
|= CLAW_TIMER
;
1289 wake_up(&p_ch
->wait
);
1291 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1292 p_ch
->ndev
->name
,__FUNCTION__
,__LINE__
);
1295 } /* end of claw_timer */
1304 /*-------------------------------------------------------------------*
1306 * pages_to_order_of_mag *
1308 * takes a number of pages from 1 to 512 and returns the *
1309 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1310 * of magnitude get_free_pages() has an upper order of 9 *
1311 *--------------------------------------------------------------------*/
1314 pages_to_order_of_mag(int num_of_pages
)
1316 int order_of_mag
=1; /* assume 2 pages */
1319 printk(KERN_INFO
"%s Enter pages = %d \n",__FUNCTION__
,num_of_pages
);
1321 CLAW_DBF_TEXT_(5,trace
,"pages%d",num_of_pages
);
1322 if (num_of_pages
== 1) {return 0; } /* magnitude of 0 = 1 page */
1323 /* 512 pages = 2Meg on 4k page systems */
1324 if (num_of_pages
>= 512) {return 9; }
1325 /* we have two or more pages order is at least 1 */
1326 for (nump
=2 ;nump
<= 512;nump
*=2) {
1327 if (num_of_pages
<= nump
)
1331 if (order_of_mag
> 9) { order_of_mag
= 9; } /* I know it's paranoid */
1333 printk(KERN_INFO
"%s Exit on line %d, order = %d\n",
1334 __FUNCTION__
,__LINE__
, order_of_mag
);
1336 CLAW_DBF_TEXT_(5,trace
,"mag%d",order_of_mag
);
1337 return order_of_mag
;
1340 /*-------------------------------------------------------------------*
1344 *--------------------------------------------------------------------*/
1346 add_claw_reads(struct net_device
*dev
, struct ccwbk
* p_first
,
1347 struct ccwbk
* p_last
)
1349 struct claw_privbk
*privptr
;
1350 struct ccw1 temp_ccw
;
1351 struct endccw
* p_end
;
1353 struct ccwbk
* p_buf
;
1356 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
1359 printk(KERN_INFO
"dev\n");
1360 dumpit((char *) dev
, sizeof(struct net_device
));
1361 printk(KERN_INFO
"p_first\n");
1362 dumpit((char *) p_first
, sizeof(struct ccwbk
));
1363 printk(KERN_INFO
"p_last\n");
1364 dumpit((char *) p_last
, sizeof(struct ccwbk
));
1366 CLAW_DBF_TEXT(4,trace
,"addreads");
1367 privptr
= dev
->priv
;
1368 p_end
= privptr
->p_end_ccw
;
1370 /* first CCW and last CCW contains a new set of read channel programs
1371 * to apend the running channel programs
1373 if ( p_first
==NULL
) {
1375 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1376 dev
->name
,__FUNCTION__
,__LINE__
);
1378 CLAW_DBF_TEXT(4,trace
,"addexit");
1382 /* set up ending CCW sequence for this segment */
1384 p_end
->read1
=0x00; /* second ending CCW is now active */
1385 /* reset ending CCWs and setup TIC CCWs */
1386 p_end
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1387 p_end
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1388 p_last
->r_TIC_1
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1389 p_last
->r_TIC_2
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1390 p_end
->read2_nop2
.cda
=0;
1391 p_end
->read2_nop2
.count
=1;
1394 p_end
->read1
=0x01; /* first ending CCW is now active */
1395 /* reset ending CCWs and setup TIC CCWs */
1396 p_end
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1397 p_end
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1398 p_last
->r_TIC_1
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1399 p_last
->r_TIC_2
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1400 p_end
->read1_nop2
.cda
=0;
1401 p_end
->read1_nop2
.count
=1;
1404 if ( privptr
-> p_read_active_first
==NULL
) {
1406 printk(KERN_INFO
"%s:%s p_read_active_first == NULL \n",
1407 dev
->name
,__FUNCTION__
);
1408 printk(KERN_INFO
"%s:%s Read active first/last changed \n",
1409 dev
->name
,__FUNCTION__
);
1411 privptr
-> p_read_active_first
= p_first
; /* set new first */
1412 privptr
-> p_read_active_last
= p_last
; /* set new last */
1417 printk(KERN_INFO
"%s:%s Read in progress \n",
1418 dev
->name
,__FUNCTION__
);
1420 /* set up TIC ccw */
1421 temp_ccw
.cda
= (__u32
)__pa(&p_first
->read
);
1424 temp_ccw
.cmd_code
= CCW_CLAW_CMD_TIC
;
1429 /* first set of CCW's is chained to the new read */
1430 /* chain, so the second set is chained to the active chain. */
1431 /* Therefore modify the second set to point to the new */
1432 /* read chain set up TIC CCWs */
1433 /* make sure we update the CCW so channel doesn't fetch it */
1434 /* when it's only half done */
1435 memcpy( &p_end
->read2_nop2
, &temp_ccw
,
1436 sizeof(struct ccw1
));
1437 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1438 (__u32
)__pa(&p_first
->read
);
1439 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1440 (__u32
)__pa(&p_first
->read
);
1443 /* make sure we update the CCW so channel doesn't */
1444 /* fetch it when it is only half done */
1445 memcpy( &p_end
->read1_nop2
, &temp_ccw
,
1446 sizeof(struct ccw1
));
1447 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1448 (__u32
)__pa(&p_first
->read
);
1449 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1450 (__u32
)__pa(&p_first
->read
);
1452 /* chain in new set of blocks */
1453 privptr
->p_read_active_last
->next
= p_first
;
1454 privptr
->p_read_active_last
=p_last
;
1455 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1457 printk(KERN_INFO
"%s:%s dump p_last CCW BK \n",dev
->name
,__FUNCTION__
);
1458 dumpit((char *)p_last
, sizeof(struct ccwbk
));
1459 printk(KERN_INFO
"%s:%s dump p_end CCW BK \n",dev
->name
,__FUNCTION__
);
1460 dumpit((char *)p_end
, sizeof(struct endccw
));
1462 printk(KERN_INFO
"%s:%s dump p_first CCW BK \n",dev
->name
,__FUNCTION__
);
1463 dumpit((char *)p_first
, sizeof(struct ccwbk
));
1464 printk(KERN_INFO
"%s:%s Dump Active CCW chain \n",
1465 dev
->name
,__FUNCTION__
);
1466 p_buf
=privptr
->p_read_active_first
;
1467 while (p_buf
!=NULL
) {
1468 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
1473 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1474 dev
->name
,__FUNCTION__
,__LINE__
);
1476 CLAW_DBF_TEXT(4,trace
,"addexit");
1478 } /* end of add_claw_reads */
1480 /*-------------------------------------------------------------------*
1481 * ccw_check_return_code *
1483 *-------------------------------------------------------------------*/
1486 ccw_check_return_code(struct ccw_device
*cdev
, int return_code
)
1489 printk(KERN_INFO
"%s: %s() > enter \n",
1490 cdev
->dev
.bus_id
,__FUNCTION__
);
1492 CLAW_DBF_TEXT(4,trace
,"ccwret");
1494 printk(KERN_INFO
"variable cdev =\n");
1495 dumpit((char *) cdev
, sizeof(struct ccw_device
));
1496 printk(KERN_INFO
"variable return_code = %d\n",return_code
);
1498 if (return_code
!= 0) {
1499 switch (return_code
) {
1501 printk(KERN_INFO
"%s: Busy !\n",
1505 printk(KERN_EMERG
"%s: Missing device called "
1506 "for IO ENODEV\n", cdev
->dev
.bus_id
);
1509 printk(KERN_EMERG
"%s: Status pending... EIO \n",
1513 printk(KERN_EMERG
"%s: Invalid Dev State EINVAL \n",
1517 printk(KERN_EMERG
"%s: Unknown error in "
1518 "Do_IO %d\n",cdev
->dev
.bus_id
, return_code
);
1522 printk(KERN_INFO
"%s: %s() > exit on line %d\n",
1523 cdev
->dev
.bus_id
,__FUNCTION__
,__LINE__
);
1525 CLAW_DBF_TEXT(4,trace
,"ccwret");
1526 } /* end of ccw_check_return_code */
1528 /*-------------------------------------------------------------------*
1529 * ccw_check_unit_check *
1530 *--------------------------------------------------------------------*/
1533 ccw_check_unit_check(struct chbk
* p_ch
, unsigned char sense
)
1535 struct net_device
*dev
= p_ch
->ndev
;
1538 printk(KERN_INFO
"%s: %s() > enter\n",dev
->name
,__FUNCTION__
);
1541 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
1542 dumpit((char *)dev
, sizeof(struct net_device
));
1543 printk(KERN_INFO
"%s: variable sense =\n",dev
->name
);
1544 dumpit((char *)&sense
, 2);
1546 CLAW_DBF_TEXT(4,trace
,"unitchek");
1548 printk(KERN_INFO
"%s: Unit Check with sense byte:0x%04x\n",
1553 printk(KERN_WARNING
"%s: Interface disconnect or "
1555 "occurred (remote side)\n", dev
->name
);
1558 printk(KERN_WARNING
"%s: System reset occured"
1559 " (remote side)\n", dev
->name
);
1562 else if (sense
& 0x20) {
1564 printk(KERN_WARNING
"%s: Data-streaming "
1565 "timeout)\n", dev
->name
);
1568 printk(KERN_WARNING
"%s: Data-transfer parity"
1569 " error\n", dev
->name
);
1572 else if (sense
& 0x10) {
1574 printk(KERN_WARNING
"%s: Hardware malfunction "
1575 "(remote side)\n", dev
->name
);
1578 printk(KERN_WARNING
"%s: read-data parity error "
1579 "(remote side)\n", dev
->name
);
1584 printk(KERN_INFO
"%s: %s() exit on line %d\n",
1585 dev
->name
,__FUNCTION__
,__LINE__
);
1587 } /* end of ccw_check_unit_check */
1591 /*-------------------------------------------------------------------*
1592 * Dump buffer format *
1594 *--------------------------------------------------------------------*/
1597 dumpit(char* buf
, int len
)
1600 __u32 ct
, sw
, rm
, dup
;
1602 char tbuf
[82], tdup
[82];
1609 char bhex
[82], duphex
[82];
1617 for ( ct
=0; ct
< len
; ct
++, ptr
++, rptr
++ ) {
1620 sprintf(addr
, "%16.16lX",(unsigned long)rptr
);
1622 sprintf(addr
, "%8.8X",(__u32
)rptr
);
1624 sprintf(boff
, "%4.4X", (__u32
)ct
);
1628 if ((sw
== 4) || (sw
== 12)) {
1635 sprintf(tbuf
,"%2.2lX", (unsigned long)*ptr
);
1637 sprintf(tbuf
,"%2.2X", (__u32
)*ptr
);
1641 if ((0!=isprint(*ptr
)) && (*ptr
>= 0x20)) {
1651 if ((strcmp(duphex
, bhex
)) !=0) {
1653 sprintf(tdup
,"Duplicate as above to"
1655 printk( KERN_INFO
" "
1656 " --- %s ---\n",tdup
);
1658 printk( KERN_INFO
" %s (+%s) : %s [%s]\n",
1659 addr
, boff
, bhex
, basc
);
1661 strcpy(duphex
, bhex
);
1672 for ( ; rm
> 0; rm
--, sw
++ ) {
1673 if ((sw
==4) || (sw
==12)) strcat(bhex
, " ");
1674 if (sw
==8) strcat(bhex
, " ");
1679 sprintf(tdup
,"Duplicate as above to %s", addr
);
1680 printk( KERN_INFO
" --- %s ---\n",
1683 printk( KERN_INFO
" %s (+%s) : %s [%s]\n",
1684 addr
, boff
, bhex
, basc
);
1688 sprintf(tdup
,"Duplicate as above to %s", addr
);
1689 printk( KERN_INFO
" --- %s ---\n",
1693 printk( KERN_INFO
" %s (+%s) : %s [%s]\n",
1694 addr
, boff
, bhex
, basc
);
1699 } /* end of dumpit */
1702 /*-------------------------------------------------------------------*
1704 *--------------------------------------------------------------------*/
1706 find_link(struct net_device
*dev
, char *host_name
, char *ws_name
)
1708 struct claw_privbk
*privptr
;
1709 struct claw_env
*p_env
;
1713 printk(KERN_INFO
"%s:%s > enter \n",dev
->name
,__FUNCTION__
);
1715 CLAW_DBF_TEXT(2,setup
,"findlink");
1717 printk(KERN_INFO
"%s: variable dev = \n",dev
->name
);
1718 dumpit((char *) dev
, sizeof(struct net_device
));
1719 printk(KERN_INFO
"%s: variable host_name = %s\n",dev
->name
, host_name
);
1720 printk(KERN_INFO
"%s: variable ws_name = %s\n",dev
->name
, ws_name
);
1723 p_env
=privptr
->p_env
;
1724 switch (p_env
->packing
)
1727 if ((memcmp(WS_APPL_NAME_PACKED
, host_name
, 8)!=0) ||
1728 (memcmp(WS_APPL_NAME_PACKED
, ws_name
, 8)!=0 ))
1733 if ((memcmp(WS_APPL_NAME_IP_NAME
, host_name
, 8)!=0) ||
1734 (memcmp(WS_APPL_NAME_IP_NAME
, ws_name
, 8)!=0 ))
1738 if ((memcmp(HOST_APPL_NAME
, host_name
, 8)!=0) ||
1739 (memcmp(p_env
->api_type
, ws_name
, 8)!=0))
1745 printk(KERN_INFO
"%s:%s Exit on line %d\n",
1746 dev
->name
,__FUNCTION__
,__LINE__
);
1749 } /* end of find_link */
1751 /*-------------------------------------------------------------------*
1755 *-------------------------------------------------------------------*/
1758 claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
)
1761 struct claw_privbk
*privptr
;
1762 struct ccwbk
*p_this_ccw
;
1763 struct ccwbk
*p_first_ccw
;
1764 struct ccwbk
*p_last_ccw
;
1766 signed long len_of_data
;
1767 unsigned long bytesInThisBuffer
;
1768 unsigned char *pDataAddress
;
1769 struct endccw
*pEnd
;
1770 struct ccw1 tempCCW
;
1772 struct claw_env
*p_env
;
1774 struct clawph
*pk_head
;
1777 struct ccwbk
*p_buf
;
1780 printk(KERN_INFO
"%s: %s() > enter\n",dev
->name
,__FUNCTION__
);
1782 CLAW_DBF_TEXT(4,trace
,"hw_tx");
1784 printk(KERN_INFO
"%s: variable dev skb =\n",dev
->name
);
1785 dumpit((char *) skb
, sizeof(struct sk_buff
));
1786 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
1787 dumpit((char *) dev
, sizeof(struct net_device
));
1788 printk(KERN_INFO
"%s: variable linkid = %ld\n",dev
->name
,linkid
);
1790 privptr
= (struct claw_privbk
*) (dev
->priv
);
1791 p_ch
=(struct chbk
*)&privptr
->channel
[WRITE
];
1792 p_env
=privptr
->p_env
;
1794 printk(KERN_INFO
"%s: %s() dump sk_buff \n",dev
->name
,__FUNCTION__
);
1795 dumpit((char *)skb
,sizeof(struct sk_buff
));
1797 claw_free_wrt_buf(dev
); /* Clean up free chain if posible */
1798 /* scan the write queue to free any completed write packets */
1801 if ((p_env
->packing
>= PACK_SEND
) &&
1802 (skb
->cb
[1] != 'P')) {
1803 skb_push(skb
,sizeof(struct clawph
));
1804 pk_head
=(struct clawph
*)skb
->data
;
1805 pk_head
->len
=skb
->len
-sizeof(struct clawph
);
1806 if (pk_head
->len
%4) {
1807 pk_head
->len
+= 4-(pk_head
->len
%4);
1808 skb_pad(skb
,4-(pk_head
->len
%4));
1809 skb_put(skb
,4-(pk_head
->len
%4));
1811 if (p_env
->packing
== DO_PACKED
)
1812 pk_head
->link_num
= linkid
;
1814 pk_head
->link_num
= 0;
1815 pk_head
->flag
= 0x00;
1820 if (claw_check_busy(dev
)) {
1821 if (privptr
->write_free_count
!=0) {
1822 claw_clear_busy(dev
);
1825 claw_strt_out_IO(dev
);
1826 claw_free_wrt_buf( dev
);
1827 if (privptr
->write_free_count
==0) {
1829 printk(KERN_INFO
"%s: "
1830 "(claw_check_busy) no free write "
1831 "buffers\n", dev
->name
);
1833 ch
= &privptr
->channel
[WRITE
];
1834 atomic_inc(&skb
->users
);
1835 skb_queue_tail(&ch
->collect_queue
, skb
);
1839 claw_clear_busy(dev
);
1844 if (claw_test_and_setbit_busy(TB_TX
,dev
)) { /* set to busy */
1846 printk(KERN_INFO
"%s: busy (claw_test_and_setbit_"
1847 "busy)\n", dev
->name
);
1849 ch
= &privptr
->channel
[WRITE
];
1850 atomic_inc(&skb
->users
);
1851 skb_queue_tail(&ch
->collect_queue
, skb
);
1852 claw_strt_out_IO(dev
);
1857 /* See how many write buffers are required to hold this data */
1858 numBuffers
= ( skb
->len
+ privptr
->p_env
->write_size
- 1) /
1859 ( privptr
->p_env
->write_size
);
1861 /* If that number of buffers isn't available, give up for now */
1862 if (privptr
->write_free_count
< numBuffers
||
1863 privptr
->p_write_free_chain
== NULL
) {
1865 claw_setbit_busy(TB_NOBUFFER
,dev
);
1868 printk(KERN_INFO
"%s: busy (claw_setbit_busy"
1869 "(TB_NOBUFFER))\n", dev
->name
);
1870 printk(KERN_INFO
" free_count: %d, numBuffers : %d\n",
1871 (int)privptr
->write_free_count
,(int) numBuffers
);
1873 ch
= &privptr
->channel
[WRITE
];
1874 atomic_inc(&skb
->users
);
1875 skb_queue_tail(&ch
->collect_queue
, skb
);
1876 CLAW_DBF_TEXT(2,trace
,"clawbusy");
1879 pDataAddress
=skb
->data
;
1880 len_of_data
=skb
->len
;
1882 while (len_of_data
> 0) {
1884 printk(KERN_INFO
"%s: %s() length-of-data is %ld \n",
1885 dev
->name
,__FUNCTION__
,len_of_data
);
1886 dumpit((char *)pDataAddress
,64);
1888 p_this_ccw
=privptr
->p_write_free_chain
; /* get a block */
1889 if (p_this_ccw
== NULL
) { /* lost the race */
1890 ch
= &privptr
->channel
[WRITE
];
1891 atomic_inc(&skb
->users
);
1892 skb_queue_tail(&ch
->collect_queue
, skb
);
1895 privptr
->p_write_free_chain
=p_this_ccw
->next
;
1896 p_this_ccw
->next
=NULL
;
1897 --privptr
->write_free_count
; /* -1 */
1898 bytesInThisBuffer
=len_of_data
;
1899 memcpy( p_this_ccw
->p_buffer
,pDataAddress
, bytesInThisBuffer
);
1900 len_of_data
-=bytesInThisBuffer
;
1901 pDataAddress
+=(unsigned long)bytesInThisBuffer
;
1902 /* setup write CCW */
1903 p_this_ccw
->write
.cmd_code
= (linkid
* 8) +1;
1904 if (len_of_data
>0) {
1905 p_this_ccw
->write
.cmd_code
+=MORE_to_COME_FLAG
;
1907 p_this_ccw
->write
.count
=bytesInThisBuffer
;
1908 /* now add to end of this chain */
1909 if (p_first_ccw
==NULL
) {
1910 p_first_ccw
=p_this_ccw
;
1912 if (p_last_ccw
!=NULL
) {
1913 p_last_ccw
->next
=p_this_ccw
;
1914 /* set up TIC ccws */
1915 p_last_ccw
->w_TIC_1
.cda
=
1916 (__u32
)__pa(&p_this_ccw
->write
);
1918 p_last_ccw
=p_this_ccw
; /* save new last block */
1920 printk(KERN_INFO
"%s: %s() > CCW and Buffer %ld bytes long \n",
1921 dev
->name
,__FUNCTION__
,bytesInThisBuffer
);
1922 dumpit((char *)p_this_ccw
, sizeof(struct ccwbk
));
1923 dumpit((char *)p_this_ccw
->p_buffer
, 64);
1927 /* FirstCCW and LastCCW now contain a new set of write channel
1928 * programs to append to the running channel program
1931 if (p_first_ccw
!=NULL
) {
1932 /* setup ending ccw sequence for this segment */
1933 pEnd
=privptr
->p_end_ccw
;
1935 pEnd
->write1
=0x00; /* second end ccw is now active */
1936 /* set up Tic CCWs */
1937 p_last_ccw
->w_TIC_1
.cda
=
1938 (__u32
)__pa(&pEnd
->write2_nop1
);
1939 pEnd
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1940 pEnd
->write2_nop2
.flags
=
1941 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1942 pEnd
->write2_nop2
.cda
=0;
1943 pEnd
->write2_nop2
.count
=1;
1945 else { /* end of if (pEnd->write1)*/
1946 pEnd
->write1
=0x01; /* first end ccw is now active */
1947 /* set up Tic CCWs */
1948 p_last_ccw
->w_TIC_1
.cda
=
1949 (__u32
)__pa(&pEnd
->write1_nop1
);
1950 pEnd
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1951 pEnd
->write1_nop2
.flags
=
1952 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1953 pEnd
->write1_nop2
.cda
=0;
1954 pEnd
->write1_nop2
.count
=1;
1955 } /* end if if (pEnd->write1) */
1958 if (privptr
->p_write_active_first
==NULL
) {
1959 privptr
->p_write_active_first
=p_first_ccw
;
1960 privptr
->p_write_active_last
=p_last_ccw
;
1964 /* set up Tic CCWs */
1966 tempCCW
.cda
=(__u32
)__pa(&p_first_ccw
->write
);
1969 tempCCW
.cmd_code
=CCW_CLAW_CMD_TIC
;
1974 * first set of ending CCW's is chained to the new write
1975 * chain, so the second set is chained to the active chain
1976 * Therefore modify the second set to point the new write chain.
1977 * make sure we update the CCW atomically
1978 * so channel does not fetch it when it's only half done
1980 memcpy( &pEnd
->write2_nop2
, &tempCCW
,
1981 sizeof(struct ccw1
));
1982 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1983 (__u32
)__pa(&p_first_ccw
->write
);
1987 /*make sure we update the CCW atomically
1988 *so channel does not fetch it when it's only half done
1990 memcpy(&pEnd
->write1_nop2
, &tempCCW
,
1991 sizeof(struct ccw1
));
1992 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1993 (__u32
)__pa(&p_first_ccw
->write
);
1995 } /* end if if (pEnd->write1) */
1997 privptr
->p_write_active_last
->next
=p_first_ccw
;
1998 privptr
->p_write_active_last
=p_last_ccw
;
2001 } /* endif (p_first_ccw!=NULL) */
2005 printk(KERN_INFO
"%s: %s() > Dump Active CCW chain \n",
2006 dev
->name
,__FUNCTION__
);
2007 p_buf
=privptr
->p_write_active_first
;
2008 while (p_buf
!=NULL
) {
2009 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
2012 p_buf
=(struct ccwbk
*)privptr
->p_end_ccw
;
2013 dumpit((char *)p_buf
, sizeof(struct endccw
));
2015 dev_kfree_skb_any(skb
);
2022 claw_strt_out_IO(dev
);
2023 /* if write free count is zero , set NOBUFFER */
2025 printk(KERN_INFO
"%s: %s() > free_count is %d\n",
2026 dev
->name
,__FUNCTION__
,
2027 (int) privptr
->write_free_count
);
2029 if (privptr
->write_free_count
==0) {
2030 claw_setbit_busy(TB_NOBUFFER
,dev
);
2033 claw_clearbit_busy(TB_TX
,dev
);
2036 printk(KERN_INFO
"%s: %s() > exit on line %d, rc = %d \n",
2037 dev
->name
,__FUNCTION__
,__LINE__
, rc
);
2040 } /* end of claw_hw_tx */
2042 /*-------------------------------------------------------------------*
2046 *--------------------------------------------------------------------*/
2049 init_ccw_bk(struct net_device
*dev
)
2052 __u32 ccw_blocks_required
;
2053 __u32 ccw_blocks_perpage
;
2054 __u32 ccw_pages_required
;
2055 __u32 claw_reads_perpage
=1;
2056 __u32 claw_read_pages
;
2057 __u32 claw_writes_perpage
=1;
2058 __u32 claw_write_pages
;
2060 struct ccwbk
*p_free_chain
;
2062 struct ccwbk
*p_last_CCWB
;
2063 struct ccwbk
*p_first_CCWB
;
2064 struct endccw
*p_endccw
=NULL
;
2065 addr_t real_address
;
2066 struct claw_privbk
*privptr
=dev
->priv
;
2067 struct clawh
*pClawH
=NULL
;
2068 addr_t real_TIC_address
;
2071 printk(KERN_INFO
"%s: %s() enter \n",dev
->name
,__FUNCTION__
);
2073 CLAW_DBF_TEXT(4,trace
,"init_ccw");
2075 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
2076 dumpit((char *) dev
, sizeof(struct net_device
));
2079 /* initialize statistics field */
2080 privptr
->active_link_ID
=0;
2081 /* initialize ccwbk pointers */
2082 privptr
->p_write_free_chain
=NULL
; /* pointer to free ccw chain*/
2083 privptr
->p_write_active_first
=NULL
; /* pointer to the first write ccw*/
2084 privptr
->p_write_active_last
=NULL
; /* pointer to the last write ccw*/
2085 privptr
->p_read_active_first
=NULL
; /* pointer to the first read ccw*/
2086 privptr
->p_read_active_last
=NULL
; /* pointer to the last read ccw */
2087 privptr
->p_end_ccw
=NULL
; /* pointer to ending ccw */
2088 privptr
->p_claw_signal_blk
=NULL
; /* pointer to signal block */
2089 privptr
->buffs_alloc
= 0;
2090 memset(&privptr
->end_ccw
, 0x00, sizeof(struct endccw
));
2091 memset(&privptr
->ctl_bk
, 0x00, sizeof(struct clawctl
));
2092 /* initialize free write ccwbk counter */
2093 privptr
->write_free_count
=0; /* number of free bufs on write chain */
2097 * We need 1 CCW block for each read buffer, 1 for each
2098 * write buffer, plus 1 for ClawSignalBlock
2100 ccw_blocks_required
=
2101 privptr
->p_env
->read_buffers
+privptr
->p_env
->write_buffers
+1;
2103 printk(KERN_INFO
"%s: %s() "
2104 "ccw_blocks_required=%d\n",
2105 dev
->name
,__FUNCTION__
,
2106 ccw_blocks_required
);
2107 printk(KERN_INFO
"%s: %s() "
2109 dev
->name
,__FUNCTION__
,
2110 (unsigned int)PAGE_SIZE
);
2111 printk(KERN_INFO
"%s: %s() > "
2113 dev
->name
,__FUNCTION__
,
2114 (unsigned int)PAGE_MASK
);
2117 * compute number of CCW blocks that will fit in a page
2119 ccw_blocks_perpage
= PAGE_SIZE
/ CCWBK_SIZE
;
2121 (ccw_blocks_required
+ccw_blocks_perpage
-1) /
2125 printk(KERN_INFO
"%s: %s() > ccw_blocks_perpage=%d\n",
2126 dev
->name
,__FUNCTION__
,
2127 ccw_blocks_perpage
);
2128 printk(KERN_INFO
"%s: %s() > ccw_pages_required=%d\n",
2129 dev
->name
,__FUNCTION__
,
2130 ccw_pages_required
);
2133 * read and write sizes are set by 2 constants in claw.h
2134 * 4k and 32k. Unpacked values other than 4k are not going to
2135 * provide good performance. With packing buffers support 32k
2138 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
2139 claw_reads_perpage
= PAGE_SIZE
/ privptr
->p_env
->read_size
;
2140 claw_read_pages
= (privptr
->p_env
->read_buffers
+
2141 claw_reads_perpage
-1) / claw_reads_perpage
;
2143 else { /* > or equal */
2144 privptr
->p_buff_pages_perread
=
2145 (privptr
->p_env
->read_size
+ PAGE_SIZE
- 1) / PAGE_SIZE
;
2147 privptr
->p_env
->read_buffers
* privptr
->p_buff_pages_perread
;
2149 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
2150 claw_writes_perpage
=
2151 PAGE_SIZE
/ privptr
->p_env
->write_size
;
2153 (privptr
->p_env
->write_buffers
+ claw_writes_perpage
-1) /
2154 claw_writes_perpage
;
2157 else { /* > or equal */
2158 privptr
->p_buff_pages_perwrite
=
2159 (privptr
->p_env
->read_size
+ PAGE_SIZE
- 1) / PAGE_SIZE
;
2161 privptr
->p_env
->write_buffers
* privptr
->p_buff_pages_perwrite
;
2164 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
2165 printk(KERN_INFO
"%s: %s() reads_perpage=%d\n",
2166 dev
->name
,__FUNCTION__
,
2167 claw_reads_perpage
);
2170 printk(KERN_INFO
"%s: %s() pages_perread=%d\n",
2171 dev
->name
,__FUNCTION__
,
2172 privptr
->p_buff_pages_perread
);
2174 printk(KERN_INFO
"%s: %s() read_pages=%d\n",
2175 dev
->name
,__FUNCTION__
,
2177 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
2178 printk(KERN_INFO
"%s: %s() writes_perpage=%d\n",
2179 dev
->name
,__FUNCTION__
,
2180 claw_writes_perpage
);
2183 printk(KERN_INFO
"%s: %s() pages_perwrite=%d\n",
2184 dev
->name
,__FUNCTION__
,
2185 privptr
->p_buff_pages_perwrite
);
2187 printk(KERN_INFO
"%s: %s() write_pages=%d\n",
2188 dev
->name
,__FUNCTION__
,
2194 * allocate ccw_pages_required
2196 if (privptr
->p_buff_ccw
==NULL
) {
2197 privptr
->p_buff_ccw
=
2198 (void *)__get_free_pages(__GFP_DMA
,
2199 (int)pages_to_order_of_mag(ccw_pages_required
));
2200 if (privptr
->p_buff_ccw
==NULL
) {
2201 printk(KERN_INFO
"%s: %s() "
2202 "__get_free_pages for CCWs failed : "
2204 dev
->name
,__FUNCTION__
,
2205 ccw_pages_required
);
2207 printk(KERN_INFO
"%s: %s() > "
2208 "exit on line %d, rc = ENOMEM\n",
2209 dev
->name
,__FUNCTION__
,
2214 privptr
->p_buff_ccw_num
=ccw_pages_required
;
2216 memset(privptr
->p_buff_ccw
, 0x00,
2217 privptr
->p_buff_ccw_num
* PAGE_SIZE
);
2220 * obtain ending ccw block address
2223 privptr
->p_end_ccw
= (struct endccw
*)&privptr
->end_ccw
;
2224 real_address
= (__u32
)__pa(privptr
->p_end_ccw
);
2225 /* Initialize ending CCW block */
2227 printk(KERN_INFO
"%s: %s() begin initialize ending CCW blocks\n",
2228 dev
->name
,__FUNCTION__
);
2231 p_endccw
=privptr
->p_end_ccw
;
2232 p_endccw
->real
=real_address
;
2233 p_endccw
->write1
=0x00;
2234 p_endccw
->read1
=0x00;
2237 p_endccw
->write1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
2238 p_endccw
->write1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2239 p_endccw
->write1_nop1
.count
= 1;
2240 p_endccw
->write1_nop1
.cda
= 0;
2243 p_endccw
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
2244 p_endccw
->write1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
2245 p_endccw
->write1_nop2
.count
= 1;
2246 p_endccw
->write1_nop2
.cda
= 0;
2249 p_endccw
->write2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
2250 p_endccw
->write2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2251 p_endccw
->write2_nop1
.count
= 1;
2252 p_endccw
->write2_nop1
.cda
= 0;
2255 p_endccw
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
2256 p_endccw
->write2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
2257 p_endccw
->write2_nop2
.count
= 1;
2258 p_endccw
->write2_nop2
.cda
= 0;
2261 p_endccw
->read1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
2262 p_endccw
->read1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2263 p_endccw
->read1_nop1
.count
= 1;
2264 p_endccw
->read1_nop1
.cda
= 0;
2267 p_endccw
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
2268 p_endccw
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
2269 p_endccw
->read1_nop2
.count
= 1;
2270 p_endccw
->read1_nop2
.cda
= 0;
2273 p_endccw
->read2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
2274 p_endccw
->read2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2275 p_endccw
->read2_nop1
.count
= 1;
2276 p_endccw
->read2_nop1
.cda
= 0;
2279 p_endccw
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
2280 p_endccw
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
2281 p_endccw
->read2_nop2
.count
= 1;
2282 p_endccw
->read2_nop2
.cda
= 0;
2285 printk(KERN_INFO
"%s: %s() dump claw ending CCW BK \n",
2286 dev
->name
,__FUNCTION__
);
2287 dumpit((char *)p_endccw
, sizeof(struct endccw
));
2291 * Build a chain of CCWs
2296 printk(KERN_INFO
"%s: %s() Begin build a chain of CCW buffer \n",
2297 dev
->name
,__FUNCTION__
);
2299 p_buff
=privptr
->p_buff_ccw
;
2302 for (i
=0 ; i
< ccw_pages_required
; i
++ ) {
2303 real_address
= (__u32
)__pa(p_buff
);
2305 for (j
=0 ; j
< ccw_blocks_perpage
; j
++) {
2306 p_buf
->next
= p_free_chain
;
2307 p_free_chain
= p_buf
;
2308 p_buf
->real
=(__u32
)__pa(p_buf
);
2314 printk(KERN_INFO
"%s: %s() "
2315 "End build a chain of CCW buffer \n",
2316 dev
->name
,__FUNCTION__
);
2318 while (p_buf
!=NULL
) {
2319 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
2325 * Initialize ClawSignalBlock
2329 printk(KERN_INFO
"%s: %s() "
2330 "Begin initialize ClawSignalBlock \n",
2331 dev
->name
,__FUNCTION__
);
2333 if (privptr
->p_claw_signal_blk
==NULL
) {
2334 privptr
->p_claw_signal_blk
=p_free_chain
;
2335 p_free_chain
=p_free_chain
->next
;
2336 pClawH
=(struct clawh
*)privptr
->p_claw_signal_blk
;
2337 pClawH
->length
=0xffff;
2338 pClawH
->opcode
=0xff;
2339 pClawH
->flag
=CLAW_BUSY
;
2342 printk(KERN_INFO
"%s: %s() > End initialize "
2343 "ClawSignalBlock\n",
2344 dev
->name
,__FUNCTION__
);
2345 dumpit((char *)privptr
->p_claw_signal_blk
, sizeof(struct ccwbk
));
2349 * allocate write_pages_required and add to free chain
2351 if (privptr
->p_buff_write
==NULL
) {
2352 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
2353 privptr
->p_buff_write
=
2354 (void *)__get_free_pages(__GFP_DMA
,
2355 (int)pages_to_order_of_mag(claw_write_pages
));
2356 if (privptr
->p_buff_write
==NULL
) {
2357 printk(KERN_INFO
"%s: %s() __get_free_pages for write"
2358 " bufs failed : get is for %d pages\n",
2359 dev
->name
,__FUNCTION__
,claw_write_pages
);
2360 free_pages((unsigned long)privptr
->p_buff_ccw
,
2361 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
2362 privptr
->p_buff_ccw
=NULL
;
2364 printk(KERN_INFO
"%s: %s() > exit on line %d,"
2366 dev
->name
,__FUNCTION__
,__LINE__
);
2371 * Build CLAW write free chain
2375 memset(privptr
->p_buff_write
, 0x00,
2376 ccw_pages_required
* PAGE_SIZE
);
2378 printk(KERN_INFO
"%s: %s() Begin build claw write free "
2379 "chain \n",dev
->name
,__FUNCTION__
);
2381 privptr
->p_write_free_chain
=NULL
;
2383 p_buff
=privptr
->p_buff_write
;
2385 for (i
=0 ; i
< privptr
->p_env
->write_buffers
; i
++) {
2386 p_buf
= p_free_chain
; /* get a CCW */
2387 p_free_chain
= p_buf
->next
;
2388 p_buf
->next
=privptr
->p_write_free_chain
;
2389 privptr
->p_write_free_chain
= p_buf
;
2390 p_buf
-> p_buffer
= (struct clawbuf
*)p_buff
;
2391 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
2392 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2393 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2394 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2395 p_buf
-> w_read_FF
.count
= 1;
2396 p_buf
-> w_read_FF
.cda
=
2397 (__u32
)__pa(&p_buf
-> header
.flag
);
2398 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
2399 p_buf
-> w_TIC_1
.flags
= 0;
2400 p_buf
-> w_TIC_1
.count
= 0;
2402 if (((unsigned long)p_buff
+privptr
->p_env
->write_size
) >=
2403 ((unsigned long)(p_buff
+2*
2404 (privptr
->p_env
->write_size
) -1) & PAGE_MASK
)) {
2405 p_buff
= p_buff
+privptr
->p_env
->write_size
;
2409 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
2411 privptr
->p_write_free_chain
=NULL
;
2412 for (i
= 0; i
< privptr
->p_env
->write_buffers
; i
++) {
2413 p_buff
=(void *)__get_free_pages(__GFP_DMA
,
2414 (int)pages_to_order_of_mag(
2415 privptr
->p_buff_pages_perwrite
) );
2417 printk(KERN_INFO
"%s:%s __get_free_pages "
2418 "for writes buf: get for %d pages\n",
2419 dev
->name
,__FUNCTION__
,
2420 privptr
->p_buff_pages_perwrite
);
2423 printk(KERN_INFO
"%s:%s __get_free_pages"
2424 "for writes buf failed : get is for %d pages\n",
2427 privptr
->p_buff_pages_perwrite
);
2428 free_pages((unsigned long)privptr
->p_buff_ccw
,
2429 (int)pages_to_order_of_mag(
2430 privptr
->p_buff_ccw_num
));
2431 privptr
->p_buff_ccw
=NULL
;
2432 p_buf
=privptr
->p_buff_write
;
2433 while (p_buf
!=NULL
) {
2434 free_pages((unsigned long)
2436 (int)pages_to_order_of_mag(
2437 privptr
->p_buff_pages_perwrite
));
2441 printk(KERN_INFO
"%s: %s exit on line %d, rc = ENOMEM\n",
2447 } /* Error on get_pages */
2448 memset(p_buff
, 0x00, privptr
->p_env
->write_size
);
2449 p_buf
= p_free_chain
;
2450 p_free_chain
= p_buf
->next
;
2451 p_buf
->next
= privptr
->p_write_free_chain
;
2452 privptr
->p_write_free_chain
= p_buf
;
2453 privptr
->p_buff_write
= p_buf
;
2454 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
2455 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
2456 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2457 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2458 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2459 p_buf
-> w_read_FF
.count
= 1;
2460 p_buf
-> w_read_FF
.cda
=
2461 (__u32
)__pa(&p_buf
-> header
.flag
);
2462 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
2463 p_buf
-> w_TIC_1
.flags
= 0;
2464 p_buf
-> w_TIC_1
.count
= 0;
2465 } /* for all write_buffers */
2467 } /* else buffers are PAGE_SIZE or bigger */
2470 privptr
->p_buff_write_num
=claw_write_pages
;
2471 privptr
->write_free_count
=privptr
->p_env
->write_buffers
;
2475 printk(KERN_INFO
"%s:%s End build claw write free chain \n",
2476 dev
->name
,__FUNCTION__
);
2477 p_buf
=privptr
->p_write_free_chain
;
2478 while (p_buf
!=NULL
) {
2479 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
2484 * allocate read_pages_required and chain to free chain
2486 if (privptr
->p_buff_read
==NULL
) {
2487 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
2488 privptr
->p_buff_read
=
2489 (void *)__get_free_pages(__GFP_DMA
,
2490 (int)pages_to_order_of_mag(claw_read_pages
) );
2491 if (privptr
->p_buff_read
==NULL
) {
2492 printk(KERN_INFO
"%s: %s() "
2493 "__get_free_pages for read buf failed : "
2494 "get is for %d pages\n",
2495 dev
->name
,__FUNCTION__
,claw_read_pages
);
2496 free_pages((unsigned long)privptr
->p_buff_ccw
,
2497 (int)pages_to_order_of_mag(
2498 privptr
->p_buff_ccw_num
));
2499 /* free the write pages size is < page size */
2500 free_pages((unsigned long)privptr
->p_buff_write
,
2501 (int)pages_to_order_of_mag(
2502 privptr
->p_buff_write_num
));
2503 privptr
->p_buff_ccw
=NULL
;
2504 privptr
->p_buff_write
=NULL
;
2506 printk(KERN_INFO
"%s: %s() > exit on line %d, rc ="
2507 " ENOMEM\n",dev
->name
,__FUNCTION__
,__LINE__
);
2511 memset(privptr
->p_buff_read
, 0x00, claw_read_pages
* PAGE_SIZE
);
2512 privptr
->p_buff_read_num
=claw_read_pages
;
2514 * Build CLAW read free chain
2518 printk(KERN_INFO
"%s: %s() Begin build claw read free chain \n",
2519 dev
->name
,__FUNCTION__
);
2521 p_buff
=privptr
->p_buff_read
;
2522 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
2523 p_buf
= p_free_chain
;
2524 p_free_chain
= p_buf
->next
;
2526 if (p_last_CCWB
==NULL
) {
2532 p_buf
->next
=p_first_CCWB
;
2534 (__u32
)__pa(&p_first_CCWB
-> read
);
2539 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
2540 /* initialize read command */
2541 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
2542 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
2543 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2544 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
2546 /* initialize read_h command */
2547 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
2548 p_buf
-> read_h
.cda
=
2549 (__u32
)__pa(&(p_buf
->header
));
2550 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2551 p_buf
-> read_h
.count
= sizeof(struct clawh
);
2553 /* initialize Signal command */
2554 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
2555 p_buf
-> signal
.cda
=
2556 (__u32
)__pa(&(pClawH
->flag
));
2557 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2558 p_buf
-> signal
.count
= 1;
2560 /* initialize r_TIC_1 command */
2561 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
2562 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
2563 p_buf
-> r_TIC_1
.flags
= 0;
2564 p_buf
-> r_TIC_1
.count
= 0;
2566 /* initialize r_read_FF command */
2567 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2568 p_buf
-> r_read_FF
.cda
=
2569 (__u32
)__pa(&(pClawH
->flag
));
2570 p_buf
-> r_read_FF
.flags
=
2571 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
2572 p_buf
-> r_read_FF
.count
= 1;
2574 /* initialize r_TIC_2 */
2575 memcpy(&p_buf
->r_TIC_2
,
2576 &p_buf
->r_TIC_1
, sizeof(struct ccw1
));
2578 /* initialize Header */
2579 p_buf
->header
.length
=0xffff;
2580 p_buf
->header
.opcode
=0xff;
2581 p_buf
->header
.flag
=CLAW_PENDING
;
2583 if (((unsigned long)p_buff
+privptr
->p_env
->read_size
) >=
2584 ((unsigned long)(p_buff
+2*(privptr
->p_env
->read_size
) -1)
2586 p_buff
= p_buff
+privptr
->p_env
->read_size
;
2590 (void *)((unsigned long)
2591 (p_buff
+2*(privptr
->p_env
->read_size
) -1)
2594 } /* for read_buffers */
2595 } /* read_size < PAGE_SIZE */
2596 else { /* read Size >= PAGE_SIZE */
2599 printk(KERN_INFO
"%s: %s() Begin build claw read free chain \n",
2600 dev
->name
,__FUNCTION__
);
2602 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
2603 p_buff
= (void *)__get_free_pages(__GFP_DMA
,
2604 (int)pages_to_order_of_mag(privptr
->p_buff_pages_perread
) );
2606 printk(KERN_INFO
"%s: %s() __get_free_pages for read "
2607 "buf failed : get is for %d pages\n",
2608 dev
->name
,__FUNCTION__
,
2609 privptr
->p_buff_pages_perread
);
2610 free_pages((unsigned long)privptr
->p_buff_ccw
,
2611 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
2612 /* free the write pages */
2613 p_buf
=privptr
->p_buff_write
;
2614 while (p_buf
!=NULL
) {
2615 free_pages((unsigned long)p_buf
->p_buffer
,
2616 (int)pages_to_order_of_mag(
2617 privptr
->p_buff_pages_perwrite
));
2620 /* free any read pages already alloc */
2621 p_buf
=privptr
->p_buff_read
;
2622 while (p_buf
!=NULL
) {
2623 free_pages((unsigned long)p_buf
->p_buffer
,
2624 (int)pages_to_order_of_mag(
2625 privptr
->p_buff_pages_perread
));
2628 privptr
->p_buff_ccw
=NULL
;
2629 privptr
->p_buff_write
=NULL
;
2631 printk(KERN_INFO
"%s: %s() exit on line %d, rc = ENOMEM\n",
2632 dev
->name
,__FUNCTION__
,
2637 memset(p_buff
, 0x00, privptr
->p_env
->read_size
);
2638 p_buf
= p_free_chain
;
2639 privptr
->p_buff_read
= p_buf
;
2640 p_free_chain
= p_buf
->next
;
2642 if (p_last_CCWB
==NULL
) {
2648 p_buf
->next
=p_first_CCWB
;
2651 &p_first_CCWB
-> read
);
2655 /* save buff address */
2656 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
2657 /* initialize read command */
2658 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
2659 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
2660 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2661 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
2663 /* initialize read_h command */
2664 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
2665 p_buf
-> read_h
.cda
=
2666 (__u32
)__pa(&(p_buf
->header
));
2667 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2668 p_buf
-> read_h
.count
= sizeof(struct clawh
);
2670 /* initialize Signal command */
2671 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
2672 p_buf
-> signal
.cda
=
2673 (__u32
)__pa(&(pClawH
->flag
));
2674 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
2675 p_buf
-> signal
.count
= 1;
2677 /* initialize r_TIC_1 command */
2678 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
2679 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
2680 p_buf
-> r_TIC_1
.flags
= 0;
2681 p_buf
-> r_TIC_1
.count
= 0;
2683 /* initialize r_read_FF command */
2684 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2685 p_buf
-> r_read_FF
.cda
=
2686 (__u32
)__pa(&(pClawH
->flag
));
2687 p_buf
-> r_read_FF
.flags
=
2688 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
2689 p_buf
-> r_read_FF
.count
= 1;
2691 /* initialize r_TIC_2 */
2692 memcpy(&p_buf
->r_TIC_2
, &p_buf
->r_TIC_1
,
2693 sizeof(struct ccw1
));
2695 /* initialize Header */
2696 p_buf
->header
.length
=0xffff;
2697 p_buf
->header
.opcode
=0xff;
2698 p_buf
->header
.flag
=CLAW_PENDING
;
2700 } /* For read_buffers */
2701 } /* read_size >= PAGE_SIZE */
2702 } /* pBuffread = NULL */
2704 printk(KERN_INFO
"%s: %s() > End build claw read free chain \n",
2705 dev
->name
,__FUNCTION__
);
2707 while (p_buf
!=NULL
) {
2708 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
2713 add_claw_reads( dev
,p_first_CCWB
, p_last_CCWB
);
2714 privptr
->buffs_alloc
= 1;
2716 printk(KERN_INFO
"%s: %s() exit on line %d\n",
2717 dev
->name
,__FUNCTION__
,__LINE__
);
2720 } /* end of init_ccw_bk */
2722 /*-------------------------------------------------------------------*
2726 *--------------------------------------------------------------------*/
2729 probe_error( struct ccwgroup_device
*cgdev
)
2731 struct claw_privbk
*privptr
;
2733 printk(KERN_INFO
"%s enter \n",__FUNCTION__
);
2735 CLAW_DBF_TEXT(4,trace
,"proberr");
2737 printk(KERN_INFO
"%s variable cgdev =\n",__FUNCTION__
);
2738 dumpit((char *) cgdev
, sizeof(struct ccwgroup_device
));
2740 privptr
=(struct claw_privbk
*)cgdev
->dev
.driver_data
;
2741 if (privptr
!=NULL
) {
2742 kfree(privptr
->p_env
);
2743 privptr
->p_env
=NULL
;
2744 kfree(privptr
->p_mtc_envelope
);
2745 privptr
->p_mtc_envelope
=NULL
;
2750 printk(KERN_INFO
"%s > exit on line %d\n",
2751 __FUNCTION__
,__LINE__
);
2759 /*-------------------------------------------------------------------*
2760 * claw_process_control *
2763 *--------------------------------------------------------------------*/
2766 claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
)
2769 struct clawbuf
*p_buf
;
2770 struct clawctl ctlbk
;
2771 struct clawctl
*p_ctlbk
;
2772 char temp_host_name
[8];
2773 char temp_ws_name
[8];
2774 struct claw_privbk
*privptr
;
2775 struct claw_env
*p_env
;
2776 struct sysval
*p_sysval
;
2777 struct conncmd
*p_connect
=NULL
;
2779 struct chbk
*p_ch
= NULL
;
2781 printk(KERN_INFO
"%s: %s() > enter \n",
2782 dev
->name
,__FUNCTION__
);
2784 CLAW_DBF_TEXT(2,setup
,"clw_cntl");
2786 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
2787 dumpit((char *) dev
, sizeof(struct net_device
));
2788 printk(KERN_INFO
"%s: variable p_ccw =\n",dev
->name
);
2789 dumpit((char *) p_ccw
, sizeof(struct ccwbk
*));
2791 udelay(1000); /* Wait a ms for the control packets to
2792 *catch up to each other */
2794 p_env
=privptr
->p_env
;
2795 memcpy( &temp_host_name
, p_env
->host_name
, 8);
2796 memcpy( &temp_ws_name
, p_env
->adapter_name
, 8);
2797 printk(KERN_INFO
"%s: CLAW device %.8s: "
2798 "Received Control Packet\n",
2799 dev
->name
, temp_ws_name
);
2800 if (privptr
->release_pend
==1) {
2802 printk(KERN_INFO
"%s: %s() > "
2803 "exit on line %d, rc=0\n",
2804 dev
->name
,__FUNCTION__
,__LINE__
);
2808 p_buf
=p_ccw
->p_buffer
;
2810 if (p_env
->packing
== DO_PACKED
) { /* packing in progress?*/
2811 memcpy(p_ctlbk
, &p_buf
->buffer
[4], sizeof(struct clawctl
));
2813 memcpy(p_ctlbk
, p_buf
, sizeof(struct clawctl
));
2816 printk(KERN_INFO
"%s: dump claw control data inbound\n",dev
->name
);
2817 dumpit((char *)p_ctlbk
, sizeof(struct clawctl
));
2819 switch (p_ctlbk
->command
)
2821 case SYSTEM_VALIDATE_REQUEST
:
2822 if (p_ctlbk
->version
!=CLAW_VERSION_ID
) {
2823 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2824 CLAW_RC_WRONG_VERSION
);
2825 printk("%s: %d is wrong version id. "
2827 dev
->name
, p_ctlbk
->version
,
2830 p_sysval
=(struct sysval
*)&(p_ctlbk
->data
);
2831 printk( "%s: Recv Sys Validate Request: "
2832 "Vers=%d,link_id=%d,Corr=%d,WS name=%."
2833 "8s,Host name=%.8s\n",
2834 dev
->name
, p_ctlbk
->version
,
2836 p_ctlbk
->correlator
,
2838 p_sysval
->host_name
);
2839 if (0!=memcmp(temp_host_name
,p_sysval
->host_name
,8)) {
2840 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2841 CLAW_RC_NAME_MISMATCH
);
2842 CLAW_DBF_TEXT(2,setup
,"HSTBAD");
2843 CLAW_DBF_TEXT_(2,setup
,"%s",p_sysval
->host_name
);
2844 CLAW_DBF_TEXT_(2,setup
,"%s",temp_host_name
);
2845 printk(KERN_INFO
"%s: Host name mismatch\n",
2847 printk(KERN_INFO
"%s: Received :%s: "
2850 p_sysval
->host_name
,
2853 if (0!=memcmp(temp_ws_name
,p_sysval
->WS_name
,8)) {
2854 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2855 CLAW_RC_NAME_MISMATCH
);
2856 CLAW_DBF_TEXT(2,setup
,"WSNBAD");
2857 CLAW_DBF_TEXT_(2,setup
,"%s",p_sysval
->WS_name
);
2858 CLAW_DBF_TEXT_(2,setup
,"%s",temp_ws_name
);
2859 printk(KERN_INFO
"%s: WS name mismatch\n",
2861 printk(KERN_INFO
"%s: Received :%s: "
2867 if (( p_sysval
->write_frame_size
< p_env
->write_size
) &&
2868 ( p_env
->packing
== 0)) {
2869 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2870 CLAW_RC_HOST_RCV_TOO_SMALL
);
2871 printk(KERN_INFO
"%s: host write size is too "
2872 "small\n", dev
->name
);
2873 CLAW_DBF_TEXT(2,setup
,"wrtszbad");
2875 if (( p_sysval
->read_frame_size
< p_env
->read_size
) &&
2876 ( p_env
->packing
== 0)) {
2877 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2878 CLAW_RC_HOST_RCV_TOO_SMALL
);
2879 printk(KERN_INFO
"%s: host read size is too "
2880 "small\n", dev
->name
);
2881 CLAW_DBF_TEXT(2,setup
,"rdsizbad");
2883 claw_snd_sys_validate_rsp(dev
, p_ctlbk
, 0 );
2884 printk("%s: CLAW device %.8s: System validate"
2885 " completed.\n",dev
->name
, temp_ws_name
);
2886 printk("%s: sys Validate Rsize:%d Wsize:%d\n",dev
->name
,
2887 p_sysval
->read_frame_size
,p_sysval
->write_frame_size
);
2888 privptr
->system_validate_comp
=1;
2889 if(strncmp(p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
2890 p_env
->packing
= PACKING_ASK
;
2892 claw_strt_conn_req(dev
);
2895 case SYSTEM_VALIDATE_RESPONSE
:
2896 p_sysval
=(struct sysval
*)&(p_ctlbk
->data
);
2897 printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
2898 "WS name=%.8s,Host name=%.8s\n",
2901 p_ctlbk
->correlator
,
2904 p_sysval
->host_name
);
2905 switch (p_ctlbk
->rc
)
2908 printk(KERN_INFO
"%s: CLAW device "
2909 "%.8s: System validate "
2911 dev
->name
, temp_ws_name
);
2912 if (privptr
->system_validate_comp
== 0)
2913 claw_strt_conn_req(dev
);
2914 privptr
->system_validate_comp
=1;
2916 case CLAW_RC_NAME_MISMATCH
:
2917 printk(KERN_INFO
"%s: Sys Validate "
2918 "Resp : Host, WS name is "
2922 case CLAW_RC_WRONG_VERSION
:
2923 printk(KERN_INFO
"%s: Sys Validate "
2924 "Resp : Wrong version\n",
2927 case CLAW_RC_HOST_RCV_TOO_SMALL
:
2928 printk(KERN_INFO
"%s: Sys Validate "
2929 "Resp : bad frame size\n",
2933 printk(KERN_INFO
"%s: Sys Validate "
2935 dev
->name
, p_ctlbk
->rc
);
2940 case CONNECTION_REQUEST
:
2941 p_connect
=(struct conncmd
*)&(p_ctlbk
->data
);
2942 printk(KERN_INFO
"%s: Recv Conn Req: Vers=%d,link_id=%d,"
2943 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2947 p_ctlbk
->correlator
,
2948 p_connect
->host_name
,
2949 p_connect
->WS_name
);
2950 if (privptr
->active_link_ID
!=0 ) {
2951 claw_snd_disc(dev
, p_ctlbk
);
2952 printk(KERN_INFO
"%s: Conn Req error : "
2953 "already logical link is active \n",
2956 if (p_ctlbk
->linkid
!=1 ) {
2957 claw_snd_disc(dev
, p_ctlbk
);
2958 printk(KERN_INFO
"%s: Conn Req error : "
2959 "req logical link id is not 1\n",
2963 p_connect
->host_name
, p_connect
->WS_name
);
2965 claw_snd_disc(dev
, p_ctlbk
);
2966 printk(KERN_INFO
"%s: Conn Req error : "
2967 "req appl name does not match\n",
2970 claw_send_control(dev
,
2971 CONNECTION_CONFIRM
, p_ctlbk
->linkid
,
2972 p_ctlbk
->correlator
,
2973 0, p_connect
->host_name
,
2974 p_connect
->WS_name
);
2975 if (p_env
->packing
== PACKING_ASK
) {
2976 printk("%s: Now Pack ask\n",dev
->name
);
2977 p_env
->packing
= PACK_SEND
;
2978 claw_snd_conn_req(dev
,0);
2980 printk(KERN_INFO
"%s: CLAW device %.8s: Connection "
2981 "completed link_id=%d.\n",
2982 dev
->name
, temp_ws_name
,
2984 privptr
->active_link_ID
=p_ctlbk
->linkid
;
2985 p_ch
=&privptr
->channel
[WRITE
];
2986 wake_up(&p_ch
->wait
); /* wake up claw_open ( WRITE) */
2988 case CONNECTION_RESPONSE
:
2989 p_connect
=(struct conncmd
*)&(p_ctlbk
->data
);
2990 printk(KERN_INFO
"%s: Revc Conn Resp: Vers=%d,link_id=%d,"
2991 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2995 p_ctlbk
->correlator
,
2997 p_connect
->host_name
,
2998 p_connect
->WS_name
);
3000 if (p_ctlbk
->rc
!=0 ) {
3001 printk(KERN_INFO
"%s: Conn Resp error: rc=%d \n",
3002 dev
->name
, p_ctlbk
->rc
);
3006 p_connect
->host_name
, p_connect
->WS_name
);
3008 claw_snd_disc(dev
, p_ctlbk
);
3009 printk(KERN_INFO
"%s: Conn Resp error: "
3010 "req appl name does not match\n",
3013 /* should be until CONNECTION_CONFIRM */
3014 privptr
->active_link_ID
= - (p_ctlbk
->linkid
);
3016 case CONNECTION_CONFIRM
:
3017 p_connect
=(struct conncmd
*)&(p_ctlbk
->data
);
3018 printk(KERN_INFO
"%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
3019 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
3023 p_ctlbk
->correlator
,
3024 p_connect
->host_name
,
3025 p_connect
->WS_name
);
3026 if (p_ctlbk
->linkid
== -(privptr
->active_link_ID
)) {
3027 privptr
->active_link_ID
=p_ctlbk
->linkid
;
3028 if (p_env
->packing
> PACKING_ASK
) {
3029 printk(KERN_INFO
"%s: Confirmed Now packing\n",dev
->name
);
3030 p_env
->packing
= DO_PACKED
;
3032 p_ch
=&privptr
->channel
[WRITE
];
3033 wake_up(&p_ch
->wait
);
3036 printk(KERN_INFO
"%s: Conn confirm: "
3037 "unexpected linkid=%d \n",
3038 dev
->name
, p_ctlbk
->linkid
);
3039 claw_snd_disc(dev
, p_ctlbk
);
3043 printk(KERN_INFO
"%s: Disconnect: "
3044 "Vers=%d,link_id=%d,Corr=%d\n",
3045 dev
->name
, p_ctlbk
->version
,
3046 p_ctlbk
->linkid
, p_ctlbk
->correlator
);
3047 if ((p_ctlbk
->linkid
== 2) &&
3048 (p_env
->packing
== PACK_SEND
)) {
3049 privptr
->active_link_ID
= 1;
3050 p_env
->packing
= DO_PACKED
;
3053 privptr
->active_link_ID
=0;
3056 printk(KERN_INFO
"%s: CLAW ERROR detected\n",
3060 printk(KERN_INFO
"%s: Unexpected command code=%d \n",
3061 dev
->name
, p_ctlbk
->command
);
3066 printk(KERN_INFO
"%s: %s() exit on line %d, rc = 0\n",
3067 dev
->name
,__FUNCTION__
,__LINE__
);
3071 } /* end of claw_process_control */
3074 /*-------------------------------------------------------------------*
3075 * claw_send_control *
3077 *--------------------------------------------------------------------*/
3080 claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
3081 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
)
3083 struct claw_privbk
*privptr
;
3084 struct clawctl
*p_ctl
;
3085 struct sysval
*p_sysval
;
3086 struct conncmd
*p_connect
;
3087 struct sk_buff
*skb
;
3090 printk(KERN_INFO
"%s:%s > enter \n",dev
->name
,__FUNCTION__
);
3092 CLAW_DBF_TEXT(2,setup
,"sndcntl");
3094 printk(KERN_INFO
"%s: Sending Control Packet \n",dev
->name
);
3095 printk(KERN_INFO
"%s: variable type = 0x%X, link = "
3096 "%d, correlator = %d, rc = %d\n",
3097 dev
->name
,type
, link
, correlator
, rc
);
3098 printk(KERN_INFO
"%s: variable local_name = %s, "
3099 "remote_name = %s\n",dev
->name
, local_name
, remote_name
);
3102 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
3104 p_ctl
->command
=type
;
3105 p_ctl
->version
=CLAW_VERSION_ID
;
3107 p_ctl
->correlator
=correlator
;
3110 p_sysval
=(struct sysval
*)&p_ctl
->data
;
3111 p_connect
=(struct conncmd
*)&p_ctl
->data
;
3113 switch (p_ctl
->command
) {
3114 case SYSTEM_VALIDATE_REQUEST
:
3115 case SYSTEM_VALIDATE_RESPONSE
:
3116 memcpy(&p_sysval
->host_name
, local_name
, 8);
3117 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
3118 if (privptr
->p_env
->packing
> 0) {
3119 p_sysval
->read_frame_size
=DEF_PACK_BUFSIZE
;
3120 p_sysval
->write_frame_size
=DEF_PACK_BUFSIZE
;
3122 /* how big is the piggest group of packets */
3123 p_sysval
->read_frame_size
=privptr
->p_env
->read_size
;
3124 p_sysval
->write_frame_size
=privptr
->p_env
->write_size
;
3126 memset(&p_sysval
->reserved
, 0x00, 4);
3128 case CONNECTION_REQUEST
:
3129 case CONNECTION_RESPONSE
:
3130 case CONNECTION_CONFIRM
:
3132 memcpy(&p_sysval
->host_name
, local_name
, 8);
3133 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
3134 if (privptr
->p_env
->packing
> 0) {
3135 /* How big is the biggest packet */
3136 p_connect
->reserved1
[0]=CLAW_FRAME_SIZE
;
3137 p_connect
->reserved1
[1]=CLAW_FRAME_SIZE
;
3139 memset(&p_connect
->reserved1
, 0x00, 4);
3140 memset(&p_connect
->reserved2
, 0x00, 4);
3147 /* write Control Record to the device */
3150 skb
= dev_alloc_skb(sizeof(struct clawctl
));
3152 printk( "%s:%s low on mem, returning...\n",
3153 dev
->name
,__FUNCTION__
);
3155 printk(KERN_INFO
"%s:%s Exit, rc = ENOMEM\n",
3156 dev
->name
,__FUNCTION__
);
3160 memcpy(skb_put(skb
, sizeof(struct clawctl
)),
3161 p_ctl
, sizeof(struct clawctl
));
3163 printk(KERN_INFO
"%s: outbnd claw cntl data \n",dev
->name
);
3164 dumpit((char *)p_ctl
,sizeof(struct clawctl
));
3166 if (privptr
->p_env
->packing
>= PACK_SEND
)
3167 claw_hw_tx(skb
, dev
, 1);
3169 claw_hw_tx(skb
, dev
, 0);
3171 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3172 dev
->name
,__FUNCTION__
,__LINE__
);
3176 } /* end of claw_send_control */
3178 /*-------------------------------------------------------------------*
3179 * claw_snd_conn_req *
3181 *--------------------------------------------------------------------*/
3183 claw_snd_conn_req(struct net_device
*dev
, __u8 link
)
3186 struct claw_privbk
*privptr
=dev
->priv
;
3187 struct clawctl
*p_ctl
;
3190 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
3192 CLAW_DBF_TEXT(2,setup
,"snd_conn");
3194 printk(KERN_INFO
"%s: variable link = %X, dev =\n",dev
->name
, link
);
3195 dumpit((char *) dev
, sizeof(struct net_device
));
3198 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
3199 p_ctl
->linkid
= link
;
3200 if ( privptr
->system_validate_comp
==0x00 ) {
3202 printk(KERN_INFO
"%s:%s Exit on line %d, rc = 1\n",
3203 dev
->name
,__FUNCTION__
,__LINE__
);
3207 if (privptr
->p_env
->packing
== PACKING_ASK
)
3208 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
3209 WS_APPL_NAME_PACKED
, WS_APPL_NAME_PACKED
);
3210 if (privptr
->p_env
->packing
== PACK_SEND
) {
3211 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
3212 WS_APPL_NAME_IP_NAME
, WS_APPL_NAME_IP_NAME
);
3214 if (privptr
->p_env
->packing
== 0)
3215 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
3216 HOST_APPL_NAME
, privptr
->p_env
->api_type
);
3218 printk(KERN_INFO
"%s:%s Exit on line %d, rc = %d\n",
3219 dev
->name
,__FUNCTION__
,__LINE__
, rc
);
3223 } /* end of claw_snd_conn_req */
3226 /*-------------------------------------------------------------------*
3229 *--------------------------------------------------------------------*/
3232 claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
)
3235 struct conncmd
* p_connect
;
3238 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3240 CLAW_DBF_TEXT(2,setup
,"snd_dsc");
3242 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
3243 dumpit((char *) dev
, sizeof(struct net_device
));
3244 printk(KERN_INFO
"%s: variable p_ctl",dev
->name
);
3245 dumpit((char *) p_ctl
, sizeof(struct clawctl
));
3247 p_connect
=(struct conncmd
*)&p_ctl
->data
;
3249 rc
=claw_send_control(dev
, DISCONNECT
, p_ctl
->linkid
,
3250 p_ctl
->correlator
, 0,
3251 p_connect
->host_name
, p_connect
->WS_name
);
3253 printk(KERN_INFO
"%s:%s Exit on line %d, rc = %d\n",
3254 dev
->name
,__FUNCTION__
, __LINE__
, rc
);
3257 } /* end of claw_snd_disc */
3260 /*-------------------------------------------------------------------*
3261 * claw_snd_sys_validate_rsp *
3263 *--------------------------------------------------------------------*/
3266 claw_snd_sys_validate_rsp(struct net_device
*dev
,
3267 struct clawctl
*p_ctl
, __u32 return_code
)
3269 struct claw_env
* p_env
;
3270 struct claw_privbk
*privptr
;
3274 printk(KERN_INFO
"%s:%s Enter\n",
3275 dev
->name
,__FUNCTION__
);
3277 CLAW_DBF_TEXT(2,setup
,"chkresp");
3279 printk(KERN_INFO
"%s: variable return_code = %d, dev =\n",
3280 dev
->name
, return_code
);
3281 dumpit((char *) dev
, sizeof(struct net_device
));
3282 printk(KERN_INFO
"%s: variable p_ctl =\n",dev
->name
);
3283 dumpit((char *) p_ctl
, sizeof(struct clawctl
));
3285 privptr
= dev
->priv
;
3286 p_env
=privptr
->p_env
;
3287 rc
=claw_send_control(dev
, SYSTEM_VALIDATE_RESPONSE
,
3292 p_env
->adapter_name
);
3294 printk(KERN_INFO
"%s:%s Exit on line %d, rc = %d\n",
3295 dev
->name
,__FUNCTION__
,__LINE__
, rc
);
3298 } /* end of claw_snd_sys_validate_rsp */
3300 /*-------------------------------------------------------------------*
3301 * claw_strt_conn_req *
3303 *--------------------------------------------------------------------*/
3306 claw_strt_conn_req(struct net_device
*dev
)
3311 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3313 CLAW_DBF_TEXT(2,setup
,"conn_req");
3315 printk(KERN_INFO
"%s: variable dev =\n",dev
->name
);
3316 dumpit((char *) dev
, sizeof(struct net_device
));
3318 rc
=claw_snd_conn_req(dev
, 1);
3320 printk(KERN_INFO
"%s:%s Exit on line %d, rc = %d\n",
3321 dev
->name
,__FUNCTION__
,__LINE__
, rc
);
3324 } /* end of claw_strt_conn_req */
3328 /*-------------------------------------------------------------------*
3330 *-------------------------------------------------------------------*/
3333 net_device_stats
*claw_stats(struct net_device
*dev
)
3335 struct claw_privbk
*privptr
;
3337 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3339 CLAW_DBF_TEXT(4,trace
,"stats");
3340 privptr
= dev
->priv
;
3342 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3343 dev
->name
,__FUNCTION__
,__LINE__
);
3345 return &privptr
->stats
;
3346 } /* end of claw_stats */
3349 /*-------------------------------------------------------------------*
3352 *--------------------------------------------------------------------*/
3354 unpack_read(struct net_device
*dev
)
3356 struct sk_buff
*skb
;
3357 struct claw_privbk
*privptr
;
3358 struct claw_env
*p_env
;
3359 struct ccwbk
*p_this_ccw
;
3360 struct ccwbk
*p_first_ccw
;
3361 struct ccwbk
*p_last_ccw
;
3362 struct clawph
*p_packh
;
3364 struct clawctl
*p_ctlrec
=NULL
;
3369 __u8 mtc_this_frm
=0;
3371 struct chbk
*p_ch
= NULL
;
3376 printk(KERN_INFO
"%s:%s enter \n",dev
->name
,__FUNCTION__
);
3378 CLAW_DBF_TEXT(4,trace
,"unpkread");
3384 p_env
= privptr
->p_env
;
3385 p_this_ccw
=privptr
->p_read_active_first
;
3387 while (p_this_ccw
!=NULL
&& p_this_ccw
->header
.flag
!=CLAW_PENDING
) {
3389 printk(KERN_INFO
"%s p_this_ccw \n",dev
->name
);
3390 dumpit((char*)p_this_ccw
, sizeof(struct ccwbk
));
3391 printk(KERN_INFO
"%s Inbound p_this_ccw->p_buffer(64)"
3392 " pk=%d \n",dev
->name
,p_env
->packing
);
3393 dumpit((char *)p_this_ccw
->p_buffer
, 64 );
3397 p_this_ccw
->header
.flag
=CLAW_PENDING
;
3398 privptr
->p_read_active_first
=p_this_ccw
->next
;
3399 p_this_ccw
->next
=NULL
;
3400 p_packh
= (struct clawph
*)p_this_ccw
->p_buffer
;
3401 if ((p_env
->packing
== PACK_SEND
) &&
3402 (p_packh
->len
== 32) &&
3403 (p_packh
->link_num
== 0)) { /* is it a packed ctl rec? */
3404 p_packh
++; /* peek past pack header */
3405 p_ctlrec
= (struct clawctl
*)p_packh
;
3406 p_packh
--; /* un peek */
3407 if ((p_ctlrec
->command
== CONNECTION_RESPONSE
) ||
3408 (p_ctlrec
->command
== CONNECTION_CONFIRM
))
3409 p_env
->packing
= DO_PACKED
;
3411 if (p_env
->packing
== DO_PACKED
)
3412 link_num
=p_packh
->link_num
;
3414 link_num
=p_this_ccw
->header
.opcode
/ 8;
3415 if ((p_this_ccw
->header
.opcode
& MORE_to_COME_FLAG
)!=0) {
3417 printk(KERN_INFO
"%s: %s > More_to_come is ON\n",
3418 dev
->name
,__FUNCTION__
);
3421 if (p_this_ccw
->header
.length
!=
3422 privptr
->p_env
->read_size
) {
3423 printk(KERN_INFO
" %s: Invalid frame detected "
3424 "length is %02x\n" ,
3425 dev
->name
, p_this_ccw
->header
.length
);
3429 if (privptr
->mtc_skipping
) {
3431 * We're in the mode of skipping past a
3432 * multi-frame message
3433 * that we can't process for some reason or other.
3434 * The first frame without the More-To-Come flag is
3435 * the last frame of the skipped message.
3437 /* in case of More-To-Come not set in this frame */
3438 if (mtc_this_frm
==0) {
3439 privptr
->mtc_skipping
=0; /* Ok, the end */
3440 privptr
->mtc_logical_link
=-1;
3443 printk(KERN_INFO
"%s:%s goto next "
3444 "frame from MoretoComeSkip \n",
3445 dev
->name
,__FUNCTION__
);
3451 claw_process_control(dev
, p_this_ccw
);
3453 printk(KERN_INFO
"%s:%s goto next "
3454 "frame from claw_process_control \n",
3455 dev
->name
,__FUNCTION__
);
3457 CLAW_DBF_TEXT(4,trace
,"UnpkCntl");
3461 if (p_env
->packing
== DO_PACKED
) {
3462 if (pack_off
> p_env
->read_size
)
3464 p_packd
= p_this_ccw
->p_buffer
+pack_off
;
3465 p_packh
= (struct clawph
*) p_packd
;
3466 if ((p_packh
->len
== 0) || /* all done with this frame? */
3467 (p_packh
->flag
!= 0))
3469 bytes_to_mov
= p_packh
->len
;
3470 pack_off
+= bytes_to_mov
+sizeof(struct clawph
);
3473 bytes_to_mov
=p_this_ccw
->header
.length
;
3475 if (privptr
->mtc_logical_link
<0) {
3477 printk(KERN_INFO
"%s: %s mtc_logical_link < 0 \n",
3478 dev
->name
,__FUNCTION__
);
3482 * if More-To-Come is set in this frame then we don't know
3483 * length of entire message, and hence have to allocate
3486 /* We are starting a new envelope */
3487 privptr
->mtc_offset
=0;
3488 privptr
->mtc_logical_link
=link_num
;
3491 if (bytes_to_mov
> (MAX_ENVELOPE_SIZE
- privptr
->mtc_offset
) ) {
3494 printk(KERN_INFO
"%s: %s > goto next "
3495 "frame from MoretoComeSkip \n",
3498 printk(KERN_INFO
" bytes_to_mov %d > (MAX_ENVELOPE_"
3499 "SIZE-privptr->mtc_offset %d)\n",
3500 bytes_to_mov
,(MAX_ENVELOPE_SIZE
- privptr
->mtc_offset
));
3502 privptr
->stats
.rx_frame_errors
++;
3505 if (p_env
->packing
== DO_PACKED
) {
3506 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
3507 p_packd
+sizeof(struct clawph
), bytes_to_mov
);
3510 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
3511 p_this_ccw
->p_buffer
, bytes_to_mov
);
3514 printk(KERN_INFO
"%s: %s() received data \n",
3515 dev
->name
,__FUNCTION__
);
3516 if (p_env
->packing
== DO_PACKED
)
3517 dumpit((char *)p_packd
+sizeof(struct clawph
),32);
3519 dumpit((char *)p_this_ccw
->p_buffer
, 32);
3520 printk(KERN_INFO
"%s: %s() bytelength %d \n",
3521 dev
->name
,__FUNCTION__
,bytes_to_mov
);
3523 if (mtc_this_frm
==0) {
3524 len_of_data
=privptr
->mtc_offset
+bytes_to_mov
;
3525 skb
=dev_alloc_skb(len_of_data
);
3527 memcpy(skb_put(skb
,len_of_data
),
3528 privptr
->p_mtc_envelope
,
3530 skb
->mac
.raw
=skb
->data
;
3532 skb
->protocol
=htons(ETH_P_IP
);
3533 skb
->ip_summed
=CHECKSUM_UNNECESSARY
;
3534 privptr
->stats
.rx_packets
++;
3535 privptr
->stats
.rx_bytes
+=len_of_data
;
3538 printk(KERN_INFO
"%s: %s() netif_"
3539 "rx(skb) completed \n",
3540 dev
->name
,__FUNCTION__
);
3544 privptr
->stats
.rx_dropped
++;
3545 printk(KERN_WARNING
"%s: %s() low on memory\n",
3546 dev
->name
,__FUNCTION__
);
3548 privptr
->mtc_offset
=0;
3549 privptr
->mtc_logical_link
=-1;
3552 privptr
->mtc_offset
+=bytes_to_mov
;
3554 if (p_env
->packing
== DO_PACKED
)
3558 * Remove ThisCCWblock from active read queue, and add it
3559 * to queue of free blocks to be reused.
3562 p_this_ccw
->header
.length
=0xffff;
3563 p_this_ccw
->header
.opcode
=0xff;
3565 * add this one to the free queue for later reuse
3567 if (p_first_ccw
==NULL
) {
3568 p_first_ccw
= p_this_ccw
;
3571 p_last_ccw
->next
= p_this_ccw
;
3573 p_last_ccw
= p_this_ccw
;
3575 * chain to next block on active read queue
3577 p_this_ccw
= privptr
->p_read_active_first
;
3578 CLAW_DBF_TEXT_(4,trace
,"rxpkt %d",p
);
3579 } /* end of while */
3581 /* check validity */
3584 printk(KERN_INFO
"%s:%s processed frame is %d \n",
3585 dev
->name
,__FUNCTION__
,i
);
3586 printk(KERN_INFO
"%s:%s F:%lx L:%lx\n",
3589 (unsigned long)p_first_ccw
,
3590 (unsigned long)p_last_ccw
);
3592 CLAW_DBF_TEXT_(4,trace
,"rxfrm %d",i
);
3593 add_claw_reads(dev
, p_first_ccw
, p_last_ccw
);
3594 p_ch
=&privptr
->channel
[READ
];
3595 claw_strt_read(dev
, LOCK_YES
);
3597 printk(KERN_INFO
"%s: %s exit on line %d\n",
3598 dev
->name
, __FUNCTION__
, __LINE__
);
3601 } /* end of unpack_read */
3603 /*-------------------------------------------------------------------*
3606 *--------------------------------------------------------------------*/
3608 claw_strt_read (struct net_device
*dev
, int lock
)
3612 unsigned long saveflags
= 0;
3613 struct claw_privbk
*privptr
=dev
->priv
;
3614 struct ccwbk
*p_ccwbk
;
3616 struct clawh
*p_clawh
;
3617 p_ch
=&privptr
->channel
[READ
];
3620 printk(KERN_INFO
"%s:%s Enter \n",dev
->name
,__FUNCTION__
);
3621 printk(KERN_INFO
"%s: variable lock = %d, dev =\n",dev
->name
, lock
);
3622 dumpit((char *) dev
, sizeof(struct net_device
));
3624 CLAW_DBF_TEXT(4,trace
,"StRdNter");
3625 p_clawh
=(struct clawh
*)privptr
->p_claw_signal_blk
;
3626 p_clawh
->flag
=CLAW_IDLE
; /* 0x00 */
3628 if ((privptr
->p_write_active_first
!=NULL
&&
3629 privptr
->p_write_active_first
->header
.flag
!=CLAW_PENDING
) ||
3630 (privptr
->p_read_active_first
!=NULL
&&
3631 privptr
->p_read_active_first
->header
.flag
!=CLAW_PENDING
)) {
3632 p_clawh
->flag
=CLAW_BUSY
; /* 0xff */
3635 printk(KERN_INFO
"%s:%s state-%02x\n" ,
3636 dev
->name
,__FUNCTION__
, p_ch
->claw_state
);
3638 if (lock
==LOCK_YES
) {
3639 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
3641 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
3643 printk(KERN_INFO
"%s: HOT READ started in %s\n" ,
3644 dev
->name
,__FUNCTION__
);
3645 p_clawh
=(struct clawh
*)privptr
->p_claw_signal_blk
;
3646 dumpit((char *)&p_clawh
->flag
, 1);
3648 CLAW_DBF_TEXT(4,trace
,"HotRead");
3649 p_ccwbk
=privptr
->p_read_active_first
;
3650 parm
= (unsigned long) p_ch
;
3651 rc
= ccw_device_start (p_ch
->cdev
, &p_ccwbk
->read
, parm
,
3654 ccw_check_return_code(p_ch
->cdev
, rc
);
3659 printk(KERN_INFO
"%s: No READ started by %s() In progress\n" ,
3660 dev
->name
,__FUNCTION__
);
3662 CLAW_DBF_TEXT(2,trace
,"ReadAct");
3665 if (lock
==LOCK_YES
) {
3666 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
3669 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3670 dev
->name
,__FUNCTION__
,__LINE__
);
3672 CLAW_DBF_TEXT(4,trace
,"StRdExit");
3674 } /* end of claw_strt_read */
3676 /*-------------------------------------------------------------------*
3677 * claw_strt_out_IO *
3679 *--------------------------------------------------------------------*/
3682 claw_strt_out_IO( struct net_device
*dev
)
3686 struct claw_privbk
*privptr
;
3688 struct ccwbk
*p_first_ccw
;
3691 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3696 privptr
=(struct claw_privbk
*)dev
->priv
;
3697 p_ch
=&privptr
->channel
[WRITE
];
3700 printk(KERN_INFO
"%s:%s state-%02x\n" ,
3701 dev
->name
,__FUNCTION__
,p_ch
->claw_state
);
3703 CLAW_DBF_TEXT(4,trace
,"strt_io");
3704 p_first_ccw
=privptr
->p_write_active_first
;
3706 if (p_ch
->claw_state
== CLAW_STOP
)
3708 if (p_first_ccw
== NULL
) {
3710 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3711 dev
->name
,__FUNCTION__
,__LINE__
);
3715 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
3716 parm
= (unsigned long) p_ch
;
3718 printk(KERN_INFO
"%s:%s do_io \n" ,dev
->name
,__FUNCTION__
);
3719 dumpit((char *)p_first_ccw
, sizeof(struct ccwbk
));
3721 CLAW_DBF_TEXT(2,trace
,"StWrtIO");
3722 rc
= ccw_device_start (p_ch
->cdev
,&p_first_ccw
->write
, parm
,
3725 ccw_check_return_code(p_ch
->cdev
, rc
);
3728 dev
->trans_start
= jiffies
;
3730 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3731 dev
->name
,__FUNCTION__
,__LINE__
);
3735 } /* end of claw_strt_out_IO */
3737 /*-------------------------------------------------------------------*
3738 * Free write buffers *
3740 *--------------------------------------------------------------------*/
3743 claw_free_wrt_buf( struct net_device
*dev
)
3746 struct claw_privbk
*privptr
=(struct claw_privbk
*)dev
->priv
;
3747 struct ccwbk
*p_first_ccw
;
3748 struct ccwbk
*p_last_ccw
;
3749 struct ccwbk
*p_this_ccw
;
3750 struct ccwbk
*p_next_ccw
;
3755 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3756 printk(KERN_INFO
"%s: free count = %d variable dev =\n",
3757 dev
->name
,privptr
->write_free_count
);
3759 CLAW_DBF_TEXT(4,trace
,"freewrtb");
3760 /* scan the write queue to free any completed write packets */
3764 printk(KERN_INFO
"%s: Dump current CCW chain \n",dev
->name
);
3765 p_buf
=privptr
->p_write_active_first
;
3766 while (p_buf
!=NULL
) {
3767 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
3771 printk(KERN_INFO
"%s: privptr->p_write_"
3772 "active_first==NULL\n",dev
->name
);
3774 p_buf
=(struct ccwbk
*)privptr
->p_end_ccw
;
3775 dumpit((char *)p_buf
, sizeof(struct endccw
));
3777 p_this_ccw
=privptr
->p_write_active_first
;
3778 while ( (p_this_ccw
!=NULL
) && (p_this_ccw
->header
.flag
!=CLAW_PENDING
))
3780 p_next_ccw
= p_this_ccw
->next
;
3781 if (((p_next_ccw
!=NULL
) &&
3782 (p_next_ccw
->header
.flag
!=CLAW_PENDING
)) ||
3783 ((p_this_ccw
== privptr
->p_write_active_last
) &&
3784 (p_this_ccw
->header
.flag
!=CLAW_PENDING
))) {
3785 /* The next CCW is OK or this is */
3786 /* the last CCW...free it @A1A */
3787 privptr
->p_write_active_first
=p_this_ccw
->next
;
3788 p_this_ccw
->header
.flag
=CLAW_PENDING
;
3789 p_this_ccw
->next
=privptr
->p_write_free_chain
;
3790 privptr
->p_write_free_chain
=p_this_ccw
;
3791 ++privptr
->write_free_count
;
3792 privptr
->stats
.tx_bytes
+= p_this_ccw
->write
.count
;
3793 p_this_ccw
=privptr
->p_write_active_first
;
3794 privptr
->stats
.tx_packets
++;
3800 if (privptr
->write_free_count
!=0) {
3801 claw_clearbit_busy(TB_NOBUFFER
,dev
);
3803 /* whole chain removed? */
3804 if (privptr
->p_write_active_first
==NULL
) {
3805 privptr
->p_write_active_last
=NULL
;
3807 printk(KERN_INFO
"%s:%s p_write_"
3808 "active_first==NULL\n",dev
->name
,__FUNCTION__
);
3812 printk(KERN_INFO
"%s: Dump arranged CCW chain \n",dev
->name
);
3813 p_buf
=privptr
->p_write_active_first
;
3814 while (p_buf
!=NULL
) {
3815 dumpit((char *)p_buf
, sizeof(struct ccwbk
));
3819 printk(KERN_INFO
"%s: privptr->p_write_active_"
3820 "first==NULL\n",dev
->name
);
3822 p_buf
=(struct ccwbk
*)privptr
->p_end_ccw
;
3823 dumpit((char *)p_buf
, sizeof(struct endccw
));
3826 CLAW_DBF_TEXT_(4,trace
,"FWC=%d",privptr
->write_free_count
);
3828 printk(KERN_INFO
"%s:%s Exit on line %d free_count =%d\n",
3829 dev
->name
,__FUNCTION__
, __LINE__
,privptr
->write_free_count
);
3834 /*-------------------------------------------------------------------*
3835 * claw free netdevice *
3837 *--------------------------------------------------------------------*/
3839 claw_free_netdevice(struct net_device
* dev
, int free_dev
)
3841 struct claw_privbk
*privptr
;
3843 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3845 CLAW_DBF_TEXT(2,setup
,"free_dev");
3849 CLAW_DBF_TEXT_(2,setup
,"%s",dev
->name
);
3850 privptr
= dev
->priv
;
3851 if (dev
->flags
& IFF_RUNNING
)
3854 privptr
->channel
[READ
].ndev
= NULL
; /* say it's free */
3862 CLAW_DBF_TEXT(2,setup
,"feee_ok");
3864 printk(KERN_INFO
"%s:%s Exit\n",dev
->name
,__FUNCTION__
);
3869 * Claw init netdevice
3870 * Initialize everything of the net device except the name and the
3874 claw_init_netdevice(struct net_device
* dev
)
3877 printk(KERN_INFO
"%s:%s Enter\n",dev
->name
,__FUNCTION__
);
3879 CLAW_DBF_TEXT(2,setup
,"init_dev");
3880 CLAW_DBF_TEXT_(2,setup
,"%s",dev
->name
);
3882 printk(KERN_WARNING
"claw:%s BAD Device exit line %d\n",
3883 __FUNCTION__
,__LINE__
);
3884 CLAW_DBF_TEXT(2,setup
,"baddev");
3887 dev
->mtu
= CLAW_DEFAULT_MTU_SIZE
;
3888 dev
->hard_start_xmit
= claw_tx
;
3889 dev
->open
= claw_open
;
3890 dev
->stop
= claw_release
;
3891 dev
->get_stats
= claw_stats
;
3892 dev
->change_mtu
= claw_change_mtu
;
3893 dev
->hard_header_len
= 0;
3895 dev
->type
= ARPHRD_SLIP
;
3896 dev
->tx_queue_len
= 1300;
3897 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
3898 SET_MODULE_OWNER(dev
);
3900 printk(KERN_INFO
"%s:%s Exit\n",dev
->name
,__FUNCTION__
);
3902 CLAW_DBF_TEXT(2,setup
,"initok");
3907 * Init a new channel in the privptr->channel[i].
3909 * @param cdev The ccw_device to be added.
3911 * @return 0 on success, !0 on error.
3914 add_channel(struct ccw_device
*cdev
,int i
,struct claw_privbk
*privptr
)
3919 printk(KERN_INFO
"%s:%s Enter\n",cdev
->dev
.bus_id
,__FUNCTION__
);
3921 CLAW_DBF_TEXT_(2,setup
,"%s",cdev
->dev
.bus_id
);
3922 privptr
->channel
[i
].flag
= i
+1; /* Read is 1 Write is 2 */
3923 p_ch
= &privptr
->channel
[i
];
3925 snprintf(p_ch
->id
, CLAW_ID_SIZE
, "cl-%s", cdev
->dev
.bus_id
);
3926 sscanf(cdev
->dev
.bus_id
+4,"%x",&p_ch
->devno
);
3927 if ((p_ch
->irb
= kmalloc(sizeof (struct irb
),GFP_KERNEL
)) == NULL
) {
3928 printk(KERN_WARNING
"%s Out of memory in %s for irb\n",
3929 p_ch
->id
,__FUNCTION__
);
3931 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3932 p_ch
->id
,__FUNCTION__
,__LINE__
);
3936 memset(p_ch
->irb
, 0, sizeof (struct irb
));
3938 printk(KERN_INFO
"%s:%s Exit on line %d\n",
3939 cdev
->dev
.bus_id
,__FUNCTION__
,__LINE__
);
3947 * Setup an interface.
3949 * @param cgdev Device to be setup.
3951 * @returns 0 on success, !0 on failure.
3954 claw_new_device(struct ccwgroup_device
*cgdev
)
3956 struct claw_privbk
*privptr
;
3957 struct claw_env
*p_env
;
3958 struct net_device
*dev
;
3961 pr_debug("%s() called\n", __FUNCTION__
);
3962 printk(KERN_INFO
"claw: add for %s\n",cgdev
->cdev
[READ
]->dev
.bus_id
);
3963 CLAW_DBF_TEXT(2,setup
,"new_dev");
3964 privptr
= cgdev
->dev
.driver_data
;
3965 cgdev
->cdev
[READ
]->dev
.driver_data
= privptr
;
3966 cgdev
->cdev
[WRITE
]->dev
.driver_data
= privptr
;
3969 p_env
= privptr
->p_env
;
3970 sscanf(cgdev
->cdev
[READ
]->dev
.bus_id
+4,"%x",
3971 &p_env
->devno
[READ
]);
3972 sscanf(cgdev
->cdev
[WRITE
]->dev
.bus_id
+4,"%x",
3973 &p_env
->devno
[WRITE
]);
3974 ret
= add_channel(cgdev
->cdev
[0],0,privptr
);
3976 ret
= add_channel(cgdev
->cdev
[1],1,privptr
);
3979 "add channel failed "
3980 "with ret = %d\n", ret
);
3983 ret
= ccw_device_set_online(cgdev
->cdev
[READ
]);
3986 "claw: ccw_device_set_online %s READ failed "
3987 "with ret = %d\n",cgdev
->cdev
[READ
]->dev
.bus_id
,ret
);
3990 ret
= ccw_device_set_online(cgdev
->cdev
[WRITE
]);
3993 "claw: ccw_device_set_online %s WRITE failed "
3994 "with ret = %d\n",cgdev
->cdev
[WRITE
]->dev
.bus_id
, ret
);
3997 dev
= alloc_netdev(0,"claw%d",claw_init_netdevice
);
3999 printk(KERN_WARNING
"%s:alloc_netdev failed\n",__FUNCTION__
);
4002 dev
->priv
= privptr
;
4003 cgdev
->dev
.driver_data
= privptr
;
4004 cgdev
->cdev
[READ
]->dev
.driver_data
= privptr
;
4005 cgdev
->cdev
[WRITE
]->dev
.driver_data
= privptr
;
4007 SET_NETDEV_DEV(dev
, &cgdev
->dev
);
4008 if (register_netdev(dev
) != 0) {
4009 claw_free_netdevice(dev
, 1);
4010 CLAW_DBF_TEXT(2,trace
,"regfail");
4013 dev
->flags
&=~IFF_RUNNING
;
4014 if (privptr
->buffs_alloc
== 0) {
4015 ret
=init_ccw_bk(dev
);
4018 "claw: init_ccw_bk failed with ret=%d\n", ret
);
4019 unregister_netdev(dev
);
4020 claw_free_netdevice(dev
,1);
4021 CLAW_DBF_TEXT(2,trace
,"ccwmem");
4025 privptr
->channel
[READ
].ndev
= dev
;
4026 privptr
->channel
[WRITE
].ndev
= dev
;
4027 privptr
->p_env
->ndev
= dev
;
4029 printk(KERN_INFO
"%s:readsize=%d writesize=%d "
4030 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
4031 dev
->name
, p_env
->read_size
,
4032 p_env
->write_size
, p_env
->read_buffers
,
4033 p_env
->write_buffers
, p_env
->devno
[READ
],
4034 p_env
->devno
[WRITE
]);
4035 printk(KERN_INFO
"%s:host_name:%.8s, adapter_name "
4036 ":%.8s api_type: %.8s\n",
4037 dev
->name
, p_env
->host_name
,
4038 p_env
->adapter_name
, p_env
->api_type
);
4041 ccw_device_set_offline(cgdev
->cdev
[1]);
4042 ccw_device_set_offline(cgdev
->cdev
[0]);
4048 claw_purge_skb_queue(struct sk_buff_head
*q
)
4050 struct sk_buff
*skb
;
4052 CLAW_DBF_TEXT(4,trace
,"purgque");
4054 while ((skb
= skb_dequeue(q
))) {
4055 atomic_dec(&skb
->users
);
4056 dev_kfree_skb_any(skb
);
4061 * Shutdown an interface.
4063 * @param cgdev Device to be shut down.
4065 * @returns 0 on success, !0 on failure.
4068 claw_shutdown_device(struct ccwgroup_device
*cgdev
)
4070 struct claw_privbk
*priv
;
4071 struct net_device
*ndev
;
4074 pr_debug("%s() called\n", __FUNCTION__
);
4075 CLAW_DBF_TEXT_(2,setup
,"%s",cgdev
->dev
.bus_id
);
4076 priv
= cgdev
->dev
.driver_data
;
4079 ndev
= priv
->channel
[READ
].ndev
;
4081 /* Close the device */
4083 "%s: shuting down \n",ndev
->name
);
4084 if (ndev
->flags
& IFF_RUNNING
)
4085 ret
= claw_release(ndev
);
4086 ndev
->flags
&=~IFF_RUNNING
;
4087 unregister_netdev(ndev
);
4088 ndev
->priv
= NULL
; /* cgdev data, not ndev's to free */
4089 claw_free_netdevice(ndev
, 1);
4090 priv
->channel
[READ
].ndev
= NULL
;
4091 priv
->channel
[WRITE
].ndev
= NULL
;
4092 priv
->p_env
->ndev
= NULL
;
4094 ccw_device_set_offline(cgdev
->cdev
[1]);
4095 ccw_device_set_offline(cgdev
->cdev
[0]);
4100 claw_remove_device(struct ccwgroup_device
*cgdev
)
4102 struct claw_privbk
*priv
;
4104 pr_debug("%s() called\n", __FUNCTION__
);
4105 CLAW_DBF_TEXT_(2,setup
,"%s",cgdev
->dev
.bus_id
);
4106 priv
= cgdev
->dev
.driver_data
;
4108 printk(KERN_WARNING
"claw: %s() no Priv exiting\n",__FUNCTION__
);
4111 printk(KERN_INFO
"claw: %s() called %s will be removed.\n",
4112 __FUNCTION__
,cgdev
->cdev
[0]->dev
.bus_id
);
4113 if (cgdev
->state
== CCWGROUP_ONLINE
)
4114 claw_shutdown_device(cgdev
);
4115 claw_remove_files(&cgdev
->dev
);
4116 kfree(priv
->p_mtc_envelope
);
4117 priv
->p_mtc_envelope
=NULL
;
4120 kfree(priv
->channel
[0].irb
);
4121 priv
->channel
[0].irb
=NULL
;
4122 kfree(priv
->channel
[1].irb
);
4123 priv
->channel
[1].irb
=NULL
;
4125 cgdev
->dev
.driver_data
=NULL
;
4126 cgdev
->cdev
[READ
]->dev
.driver_data
= NULL
;
4127 cgdev
->cdev
[WRITE
]->dev
.driver_data
= NULL
;
4128 put_device(&cgdev
->dev
);
4136 claw_hname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4138 struct claw_privbk
*priv
;
4139 struct claw_env
* p_env
;
4141 priv
= dev
->driver_data
;
4144 p_env
= priv
->p_env
;
4145 return sprintf(buf
, "%s\n",p_env
->host_name
);
4149 claw_hname_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4151 struct claw_privbk
*priv
;
4152 struct claw_env
* p_env
;
4154 priv
= dev
->driver_data
;
4157 p_env
= priv
->p_env
;
4158 if (count
> MAX_NAME_LEN
+1)
4160 memset(p_env
->host_name
, 0x20, MAX_NAME_LEN
);
4161 strncpy(p_env
->host_name
,buf
, count
);
4162 p_env
->host_name
[count
-1] = 0x20; /* clear extra 0x0a */
4163 p_env
->host_name
[MAX_NAME_LEN
] = 0x00;
4164 CLAW_DBF_TEXT(2,setup
,"HstnSet");
4165 CLAW_DBF_TEXT_(2,setup
,"%s",p_env
->host_name
);
4170 static DEVICE_ATTR(host_name
, 0644, claw_hname_show
, claw_hname_write
);
4173 claw_adname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4175 struct claw_privbk
*priv
;
4176 struct claw_env
* p_env
;
4178 priv
= dev
->driver_data
;
4181 p_env
= priv
->p_env
;
4182 return sprintf(buf
, "%s\n",p_env
->adapter_name
);
4186 claw_adname_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4188 struct claw_privbk
*priv
;
4189 struct claw_env
* p_env
;
4191 priv
= dev
->driver_data
;
4194 p_env
= priv
->p_env
;
4195 if (count
> MAX_NAME_LEN
+1)
4197 memset(p_env
->adapter_name
, 0x20, MAX_NAME_LEN
);
4198 strncpy(p_env
->adapter_name
,buf
, count
);
4199 p_env
->adapter_name
[count
-1] = 0x20; /* clear extra 0x0a */
4200 p_env
->adapter_name
[MAX_NAME_LEN
] = 0x00;
4201 CLAW_DBF_TEXT(2,setup
,"AdnSet");
4202 CLAW_DBF_TEXT_(2,setup
,"%s",p_env
->adapter_name
);
4207 static DEVICE_ATTR(adapter_name
, 0644, claw_adname_show
, claw_adname_write
);
4210 claw_apname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4212 struct claw_privbk
*priv
;
4213 struct claw_env
* p_env
;
4215 priv
= dev
->driver_data
;
4218 p_env
= priv
->p_env
;
4219 return sprintf(buf
, "%s\n",
4224 claw_apname_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4226 struct claw_privbk
*priv
;
4227 struct claw_env
* p_env
;
4229 priv
= dev
->driver_data
;
4232 p_env
= priv
->p_env
;
4233 if (count
> MAX_NAME_LEN
+1)
4235 memset(p_env
->api_type
, 0x20, MAX_NAME_LEN
);
4236 strncpy(p_env
->api_type
,buf
, count
);
4237 p_env
->api_type
[count
-1] = 0x20; /* we get a loose 0x0a */
4238 p_env
->api_type
[MAX_NAME_LEN
] = 0x00;
4239 if(strncmp(p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
4240 p_env
->read_size
=DEF_PACK_BUFSIZE
;
4241 p_env
->write_size
=DEF_PACK_BUFSIZE
;
4242 p_env
->packing
=PACKING_ASK
;
4243 CLAW_DBF_TEXT(2,setup
,"PACKING");
4247 p_env
->read_size
=CLAW_FRAME_SIZE
;
4248 p_env
->write_size
=CLAW_FRAME_SIZE
;
4249 CLAW_DBF_TEXT(2,setup
,"ApiSet");
4251 CLAW_DBF_TEXT_(2,setup
,"%s",p_env
->api_type
);
4255 static DEVICE_ATTR(api_type
, 0644, claw_apname_show
, claw_apname_write
);
4258 claw_wbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4260 struct claw_privbk
*priv
;
4261 struct claw_env
* p_env
;
4263 priv
= dev
->driver_data
;
4266 p_env
= priv
->p_env
;
4267 return sprintf(buf
, "%d\n", p_env
->write_buffers
);
4271 claw_wbuff_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4273 struct claw_privbk
*priv
;
4274 struct claw_env
* p_env
;
4277 priv
= dev
->driver_data
;
4280 p_env
= priv
->p_env
;
4281 sscanf(buf
, "%i", &nnn
);
4282 if (p_env
->packing
) {
4288 if ((nnn
> max
) || (nnn
< 2))
4290 p_env
->write_buffers
= nnn
;
4291 CLAW_DBF_TEXT(2,setup
,"Wbufset");
4292 CLAW_DBF_TEXT_(2,setup
,"WB=%d",p_env
->write_buffers
);
4296 static DEVICE_ATTR(write_buffer
, 0644, claw_wbuff_show
, claw_wbuff_write
);
4299 claw_rbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4301 struct claw_privbk
*priv
;
4302 struct claw_env
* p_env
;
4304 priv
= dev
->driver_data
;
4307 p_env
= priv
->p_env
;
4308 return sprintf(buf
, "%d\n", p_env
->read_buffers
);
4312 claw_rbuff_write(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
4314 struct claw_privbk
*priv
;
4315 struct claw_env
*p_env
;
4318 priv
= dev
->driver_data
;
4321 p_env
= priv
->p_env
;
4322 sscanf(buf
, "%i", &nnn
);
4323 if (p_env
->packing
) {
4329 if ((nnn
> max
) || (nnn
< 2))
4331 p_env
->read_buffers
= nnn
;
4332 CLAW_DBF_TEXT(2,setup
,"Rbufset");
4333 CLAW_DBF_TEXT_(2,setup
,"RB=%d",p_env
->read_buffers
);
4337 static DEVICE_ATTR(read_buffer
, 0644, claw_rbuff_show
, claw_rbuff_write
);
4339 static struct attribute
*claw_attr
[] = {
4340 &dev_attr_read_buffer
.attr
,
4341 &dev_attr_write_buffer
.attr
,
4342 &dev_attr_adapter_name
.attr
,
4343 &dev_attr_api_type
.attr
,
4344 &dev_attr_host_name
.attr
,
4348 static struct attribute_group claw_attr_group
= {
4353 claw_add_files(struct device
*dev
)
4355 pr_debug("%s() called\n", __FUNCTION__
);
4356 CLAW_DBF_TEXT(2,setup
,"add_file");
4357 return sysfs_create_group(&dev
->kobj
, &claw_attr_group
);
4361 claw_remove_files(struct device
*dev
)
4363 pr_debug("%s() called\n", __FUNCTION__
);
4364 CLAW_DBF_TEXT(2,setup
,"rem_file");
4365 sysfs_remove_group(&dev
->kobj
, &claw_attr_group
);
4368 /*--------------------------------------------------------------------*
4369 * claw_init and cleanup *
4370 *---------------------------------------------------------------------*/
4375 unregister_cu3088_discipline(&claw_group_driver
);
4376 claw_unregister_debug_facility();
4377 printk(KERN_INFO
"claw: Driver unloaded\n");
4382 * Initialize module.
4383 * This is called just after the module is loaded.
4385 * @return 0 on success, !0 on error.
4391 printk(KERN_INFO
"claw: starting driver\n");
4394 printk(KERN_INFO
"claw: %s() enter \n",__FUNCTION__
);
4396 ret
= claw_register_debug_facility();
4398 printk(KERN_WARNING
"claw: %s() debug_register failed %d\n",
4402 CLAW_DBF_TEXT(2,setup
,"init_mod");
4403 ret
= register_cu3088_discipline(&claw_group_driver
);
4405 claw_unregister_debug_facility();
4406 printk(KERN_WARNING
"claw; %s() cu3088 register failed %d\n",
4410 printk(KERN_INFO
"claw: %s() exit \n",__FUNCTION__
);
4415 module_init(claw_init
);
4416 module_exit(claw_cleanup
);
4420 /*--------------------------------------------------------------------*
4422 *---------------------------------------------------------------------*/