2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
5 * Linux for zSeries version
6 * Copyright IBM Corp. 2002, 2009
7 * Author(s) Original code written by:
8 * Kazuo Iimura <iimura@jp.ibm.com>
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
64 #define KMSG_COMPONENT "claw"
66 #include <linux/kernel_stat.h>
67 #include <asm/ccwdev.h>
68 #include <asm/ccwgroup.h>
69 #include <asm/debug.h>
70 #include <asm/idals.h>
72 #include <linux/bitops.h>
73 #include <linux/ctype.h>
74 #include <linux/delay.h>
75 #include <linux/errno.h>
76 #include <linux/if_arp.h>
77 #include <linux/init.h>
78 #include <linux/interrupt.h>
80 #include <linux/kernel.h>
81 #include <linux/module.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/proc_fs.h>
85 #include <linux/sched.h>
86 #include <linux/signal.h>
87 #include <linux/skbuff.h>
88 #include <linux/slab.h>
89 #include <linux/string.h>
90 #include <linux/tcp.h>
91 #include <linux/timer.h>
92 #include <linux/types.h>
97 CLAW uses the s390dbf file system see claw_trace and claw_setup
100 static char version
[] __initdata
= "CLAW driver";
101 static char debug_buffer
[255];
103 * Debug Facility Stuff
105 static debug_info_t
*claw_dbf_setup
;
106 static debug_info_t
*claw_dbf_trace
;
109 * CLAW Debug Facility functions
112 claw_unregister_debug_facility(void)
115 debug_unregister(claw_dbf_setup
);
117 debug_unregister(claw_dbf_trace
);
121 claw_register_debug_facility(void)
123 claw_dbf_setup
= debug_register("claw_setup", 2, 1, 8);
124 claw_dbf_trace
= debug_register("claw_trace", 2, 2, 8);
125 if (claw_dbf_setup
== NULL
|| claw_dbf_trace
== NULL
) {
126 claw_unregister_debug_facility();
129 debug_register_view(claw_dbf_setup
, &debug_hex_ascii_view
);
130 debug_set_level(claw_dbf_setup
, 2);
131 debug_register_view(claw_dbf_trace
, &debug_hex_ascii_view
);
132 debug_set_level(claw_dbf_trace
, 2);
137 claw_set_busy(struct net_device
*dev
)
139 ((struct claw_privbk
*)dev
->ml_priv
)->tbusy
= 1;
144 claw_clear_busy(struct net_device
*dev
)
146 clear_bit(0, &(((struct claw_privbk
*) dev
->ml_priv
)->tbusy
));
147 netif_wake_queue(dev
);
152 claw_check_busy(struct net_device
*dev
)
155 return ((struct claw_privbk
*) dev
->ml_priv
)->tbusy
;
159 claw_setbit_busy(int nr
,struct net_device
*dev
)
161 netif_stop_queue(dev
);
162 set_bit(nr
, (void *)&(((struct claw_privbk
*)dev
->ml_priv
)->tbusy
));
166 claw_clearbit_busy(int nr
,struct net_device
*dev
)
168 clear_bit(nr
, (void *)&(((struct claw_privbk
*)dev
->ml_priv
)->tbusy
));
169 netif_wake_queue(dev
);
173 claw_test_and_setbit_busy(int nr
,struct net_device
*dev
)
175 netif_stop_queue(dev
);
176 return test_and_set_bit(nr
,
177 (void *)&(((struct claw_privbk
*) dev
->ml_priv
)->tbusy
));
181 /* Functions for the DEV methods */
183 static int claw_probe(struct ccwgroup_device
*cgdev
);
184 static void claw_remove_device(struct ccwgroup_device
*cgdev
);
185 static void claw_purge_skb_queue(struct sk_buff_head
*q
);
186 static int claw_new_device(struct ccwgroup_device
*cgdev
);
187 static int claw_shutdown_device(struct ccwgroup_device
*cgdev
);
188 static int claw_tx(struct sk_buff
*skb
, struct net_device
*dev
);
189 static int claw_change_mtu( struct net_device
*dev
, int new_mtu
);
190 static int claw_open(struct net_device
*dev
);
191 static void claw_irq_handler(struct ccw_device
*cdev
,
192 unsigned long intparm
, struct irb
*irb
);
193 static void claw_irq_tasklet ( unsigned long data
);
194 static int claw_release(struct net_device
*dev
);
195 static void claw_write_retry ( struct chbk
* p_ch
);
196 static void claw_write_next ( struct chbk
* p_ch
);
197 static void claw_timer ( struct chbk
* p_ch
);
200 static int add_claw_reads(struct net_device
*dev
,
201 struct ccwbk
* p_first
, struct ccwbk
* p_last
);
202 static void ccw_check_return_code (struct ccw_device
*cdev
, int return_code
);
203 static void ccw_check_unit_check (struct chbk
* p_ch
, unsigned char sense
);
204 static int find_link(struct net_device
*dev
, char *host_name
, char *ws_name
);
205 static int claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
);
206 static int init_ccw_bk(struct net_device
*dev
);
207 static void probe_error( struct ccwgroup_device
*cgdev
);
208 static struct net_device_stats
*claw_stats(struct net_device
*dev
);
209 static int pages_to_order_of_mag(int num_of_pages
);
210 static struct sk_buff
*claw_pack_skb(struct claw_privbk
*privptr
);
211 /* sysfs Functions */
212 static ssize_t
claw_hname_show(struct device
*dev
,
213 struct device_attribute
*attr
, char *buf
);
214 static ssize_t
claw_hname_write(struct device
*dev
,
215 struct device_attribute
*attr
,
216 const char *buf
, size_t count
);
217 static ssize_t
claw_adname_show(struct device
*dev
,
218 struct device_attribute
*attr
, char *buf
);
219 static ssize_t
claw_adname_write(struct device
*dev
,
220 struct device_attribute
*attr
,
221 const char *buf
, size_t count
);
222 static ssize_t
claw_apname_show(struct device
*dev
,
223 struct device_attribute
*attr
, char *buf
);
224 static ssize_t
claw_apname_write(struct device
*dev
,
225 struct device_attribute
*attr
,
226 const char *buf
, size_t count
);
227 static ssize_t
claw_wbuff_show(struct device
*dev
,
228 struct device_attribute
*attr
, char *buf
);
229 static ssize_t
claw_wbuff_write(struct device
*dev
,
230 struct device_attribute
*attr
,
231 const char *buf
, size_t count
);
232 static ssize_t
claw_rbuff_show(struct device
*dev
,
233 struct device_attribute
*attr
, char *buf
);
234 static ssize_t
claw_rbuff_write(struct device
*dev
,
235 struct device_attribute
*attr
,
236 const char *buf
, size_t count
);
237 static int claw_add_files(struct device
*dev
);
238 static void claw_remove_files(struct device
*dev
);
240 /* Functions for System Validate */
241 static int claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
);
242 static int claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
243 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
);
244 static int claw_snd_conn_req(struct net_device
*dev
, __u8 link
);
245 static int claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
);
246 static int claw_snd_sys_validate_rsp(struct net_device
*dev
,
247 struct clawctl
* p_ctl
, __u32 return_code
);
248 static int claw_strt_conn_req(struct net_device
*dev
);
249 static void claw_strt_read(struct net_device
*dev
, int lock
);
250 static void claw_strt_out_IO(struct net_device
*dev
);
251 static void claw_free_wrt_buf(struct net_device
*dev
);
253 /* Functions for unpack reads */
254 static void unpack_read(struct net_device
*dev
);
256 static int claw_pm_prepare(struct ccwgroup_device
*gdev
)
261 /* the root device for claw group devices */
262 static struct device
*claw_root_dev
;
266 static struct ccwgroup_driver claw_group_driver
= {
267 .owner
= THIS_MODULE
,
270 .driver_id
= 0xC3D3C1E6,
272 .remove
= claw_remove_device
,
273 .set_online
= claw_new_device
,
274 .set_offline
= claw_shutdown_device
,
275 .prepare
= claw_pm_prepare
,
278 static struct ccw_device_id claw_ids
[] = {
279 {CCW_DEVICE(0x3088, 0x61), .driver_info
= claw_channel_type_claw
},
282 MODULE_DEVICE_TABLE(ccw
, claw_ids
);
284 static struct ccw_driver claw_ccw_driver
= {
285 .owner
= THIS_MODULE
,
288 .probe
= ccwgroup_probe_ccwdev
,
289 .remove
= ccwgroup_remove_ccwdev
,
293 claw_driver_group_store(struct device_driver
*ddrv
, const char *buf
,
297 err
= ccwgroup_create_from_string(claw_root_dev
,
298 claw_group_driver
.driver_id
,
299 &claw_ccw_driver
, 2, buf
);
300 return err
? err
: count
;
303 static DRIVER_ATTR(group
, 0200, NULL
, claw_driver_group_store
);
305 static struct attribute
*claw_group_attrs
[] = {
306 &driver_attr_group
.attr
,
310 static struct attribute_group claw_group_attr_group
= {
311 .attrs
= claw_group_attrs
,
314 static const struct attribute_group
*claw_group_attr_groups
[] = {
315 &claw_group_attr_group
,
323 /*----------------------------------------------------------------*
325 * this function is called for each CLAW device. *
326 *----------------------------------------------------------------*/
328 claw_probe(struct ccwgroup_device
*cgdev
)
331 struct claw_privbk
*privptr
=NULL
;
333 CLAW_DBF_TEXT(2, setup
, "probe");
334 if (!get_device(&cgdev
->dev
))
336 privptr
= kzalloc(sizeof(struct claw_privbk
), GFP_KERNEL
);
337 dev_set_drvdata(&cgdev
->dev
, privptr
);
338 if (privptr
== NULL
) {
340 put_device(&cgdev
->dev
);
341 CLAW_DBF_TEXT_(2, setup
, "probex%d", -ENOMEM
);
344 privptr
->p_mtc_envelope
= kzalloc( MAX_ENVELOPE_SIZE
, GFP_KERNEL
);
345 privptr
->p_env
= kzalloc(sizeof(struct claw_env
), GFP_KERNEL
);
346 if ((privptr
->p_mtc_envelope
==NULL
) || (privptr
->p_env
==NULL
)) {
348 put_device(&cgdev
->dev
);
349 CLAW_DBF_TEXT_(2, setup
, "probex%d", -ENOMEM
);
352 memcpy(privptr
->p_env
->adapter_name
,WS_NAME_NOT_DEF
,8);
353 memcpy(privptr
->p_env
->host_name
,WS_NAME_NOT_DEF
,8);
354 memcpy(privptr
->p_env
->api_type
,WS_NAME_NOT_DEF
,8);
355 privptr
->p_env
->packing
= 0;
356 privptr
->p_env
->write_buffers
= 5;
357 privptr
->p_env
->read_buffers
= 5;
358 privptr
->p_env
->read_size
= CLAW_FRAME_SIZE
;
359 privptr
->p_env
->write_size
= CLAW_FRAME_SIZE
;
360 rc
= claw_add_files(&cgdev
->dev
);
363 put_device(&cgdev
->dev
);
364 dev_err(&cgdev
->dev
, "Creating the /proc files for a new"
365 " CLAW device failed\n");
366 CLAW_DBF_TEXT_(2, setup
, "probex%d", rc
);
369 privptr
->p_env
->p_priv
= privptr
;
370 cgdev
->cdev
[0]->handler
= claw_irq_handler
;
371 cgdev
->cdev
[1]->handler
= claw_irq_handler
;
372 CLAW_DBF_TEXT(2, setup
, "prbext 0");
375 } /* end of claw_probe */
377 /*-------------------------------------------------------------------*
379 *-------------------------------------------------------------------*/
382 claw_tx(struct sk_buff
*skb
, struct net_device
*dev
)
385 struct claw_privbk
*privptr
= dev
->ml_priv
;
386 unsigned long saveflags
;
389 CLAW_DBF_TEXT(4, trace
, "claw_tx");
390 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
391 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
392 rc
=claw_hw_tx( skb
, dev
, 1 );
393 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
394 CLAW_DBF_TEXT_(4, trace
, "clawtx%d", rc
);
400 } /* end of claw_tx */
402 /*------------------------------------------------------------------*
403 * pack the collect queue into an skb and return it *
404 * If not packing just return the top skb from the queue *
405 *------------------------------------------------------------------*/
407 static struct sk_buff
*
408 claw_pack_skb(struct claw_privbk
*privptr
)
410 struct sk_buff
*new_skb
,*held_skb
;
411 struct chbk
*p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
412 struct claw_env
*p_env
= privptr
->p_env
;
413 int pkt_cnt
,pk_ind
,so_far
;
415 new_skb
= NULL
; /* assume no dice */
417 CLAW_DBF_TEXT(4, trace
, "PackSKBe");
418 if (!skb_queue_empty(&p_ch
->collect_queue
)) {
420 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
422 dev_kfree_skb_any(held_skb
);
425 if (p_env
->packing
!= DO_PACKED
)
427 /* get a new SKB we will pack at least one */
428 new_skb
= dev_alloc_skb(p_env
->write_size
);
429 if (new_skb
== NULL
) {
430 atomic_inc(&held_skb
->users
);
431 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
434 /* we have packed packet and a place to put it */
437 new_skb
->cb
[1] = 'P'; /* every skb on queue has pack header */
438 while ((pk_ind
) && (held_skb
!= NULL
)) {
439 if (held_skb
->len
+so_far
<= p_env
->write_size
-8) {
440 memcpy(skb_put(new_skb
,held_skb
->len
),
441 held_skb
->data
,held_skb
->len
);
442 privptr
->stats
.tx_packets
++;
443 so_far
+= held_skb
->len
;
445 dev_kfree_skb_any(held_skb
);
446 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
448 atomic_dec(&held_skb
->users
);
451 atomic_inc(&held_skb
->users
);
452 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
456 CLAW_DBF_TEXT(4, trace
, "PackSKBx");
460 /*-------------------------------------------------------------------*
463 *-------------------------------------------------------------------*/
466 claw_change_mtu(struct net_device
*dev
, int new_mtu
)
468 struct claw_privbk
*privptr
= dev
->ml_priv
;
470 CLAW_DBF_TEXT(4, trace
, "setmtu");
471 buff_size
= privptr
->p_env
->write_size
;
472 if ((new_mtu
< 60) || (new_mtu
> buff_size
)) {
477 } /* end of claw_change_mtu */
480 /*-------------------------------------------------------------------*
483 *-------------------------------------------------------------------*/
485 claw_open(struct net_device
*dev
)
490 unsigned long saveflags
=0;
492 struct claw_privbk
*privptr
;
493 DECLARE_WAITQUEUE(wait
, current
);
494 struct timer_list timer
;
497 CLAW_DBF_TEXT(4, trace
, "open");
498 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
499 /* allocate and initialize CCW blocks */
500 if (privptr
->buffs_alloc
== 0) {
503 CLAW_DBF_TEXT(2, trace
, "openmem");
507 privptr
->system_validate_comp
=0;
508 privptr
->release_pend
=0;
509 if(strncmp(privptr
->p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
510 privptr
->p_env
->read_size
=DEF_PACK_BUFSIZE
;
511 privptr
->p_env
->write_size
=DEF_PACK_BUFSIZE
;
512 privptr
->p_env
->packing
=PACKING_ASK
;
514 privptr
->p_env
->packing
=0;
515 privptr
->p_env
->read_size
=CLAW_FRAME_SIZE
;
516 privptr
->p_env
->write_size
=CLAW_FRAME_SIZE
;
519 tasklet_init(&privptr
->channel
[READ_CHANNEL
].tasklet
, claw_irq_tasklet
,
520 (unsigned long) &privptr
->channel
[READ_CHANNEL
]);
521 for ( i
= 0; i
< 2; i
++) {
522 CLAW_DBF_TEXT_(2, trace
, "opn_ch%d", i
);
523 init_waitqueue_head(&privptr
->channel
[i
].wait
);
524 /* skb_queue_head_init(&p_ch->io_queue); */
525 if (i
== WRITE_CHANNEL
)
527 &privptr
->channel
[WRITE_CHANNEL
].collect_queue
);
528 privptr
->channel
[i
].flag_a
= 0;
529 privptr
->channel
[i
].IO_active
= 0;
530 privptr
->channel
[i
].flag
&= ~CLAW_TIMER
;
532 timer
.function
= (void *)claw_timer
;
533 timer
.data
= (unsigned long)(&privptr
->channel
[i
]);
534 timer
.expires
= jiffies
+ 15*HZ
;
536 spin_lock_irqsave(get_ccwdev_lock(
537 privptr
->channel
[i
].cdev
), saveflags
);
538 parm
= (unsigned long) &privptr
->channel
[i
];
539 privptr
->channel
[i
].claw_state
= CLAW_START_HALT_IO
;
541 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
542 rc
= ccw_device_halt(
543 (struct ccw_device
*)privptr
->channel
[i
].cdev
,parm
);
544 set_current_state(TASK_INTERRUPTIBLE
);
545 spin_unlock_irqrestore(
546 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
548 set_current_state(TASK_RUNNING
);
549 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
551 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
552 if((privptr
->channel
[i
].flag
& CLAW_TIMER
) == 0x00)
555 if ((((privptr
->channel
[READ_CHANNEL
].last_dstat
|
556 privptr
->channel
[WRITE_CHANNEL
].last_dstat
) &
557 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) ||
558 (((privptr
->channel
[READ_CHANNEL
].flag
|
559 privptr
->channel
[WRITE_CHANNEL
].flag
) & CLAW_TIMER
) != 0x00)) {
560 dev_info(&privptr
->channel
[READ_CHANNEL
].cdev
->dev
,
561 "%s: remote side is not ready\n", dev
->name
);
562 CLAW_DBF_TEXT(2, trace
, "notrdy");
564 for ( i
= 0; i
< 2; i
++) {
566 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
568 parm
= (unsigned long) &privptr
->channel
[i
];
569 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
570 rc
= ccw_device_halt(
571 (struct ccw_device
*)&privptr
->channel
[i
].cdev
,
573 spin_unlock_irqrestore(
574 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
577 ccw_check_return_code(
578 privptr
->channel
[i
].cdev
, rc
);
581 free_pages((unsigned long)privptr
->p_buff_ccw
,
582 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
583 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
584 free_pages((unsigned long)privptr
->p_buff_read
,
585 (int)pages_to_order_of_mag(
586 privptr
->p_buff_read_num
));
589 p_buf
=privptr
->p_read_active_first
;
590 while (p_buf
!=NULL
) {
591 free_pages((unsigned long)p_buf
->p_buffer
,
592 (int)pages_to_order_of_mag(
593 privptr
->p_buff_pages_perread
));
597 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
598 free_pages((unsigned long)privptr
->p_buff_write
,
599 (int)pages_to_order_of_mag(
600 privptr
->p_buff_write_num
));
603 p_buf
=privptr
->p_write_active_first
;
604 while (p_buf
!=NULL
) {
605 free_pages((unsigned long)p_buf
->p_buffer
,
606 (int)pages_to_order_of_mag(
607 privptr
->p_buff_pages_perwrite
));
611 privptr
->buffs_alloc
= 0;
612 privptr
->channel
[READ_CHANNEL
].flag
= 0x00;
613 privptr
->channel
[WRITE_CHANNEL
].flag
= 0x00;
614 privptr
->p_buff_ccw
=NULL
;
615 privptr
->p_buff_read
=NULL
;
616 privptr
->p_buff_write
=NULL
;
617 claw_clear_busy(dev
);
618 CLAW_DBF_TEXT(2, trace
, "open EIO");
622 /* Send SystemValidate command */
624 claw_clear_busy(dev
);
625 CLAW_DBF_TEXT(4, trace
, "openok");
627 } /* end of claw_open */
629 /*-------------------------------------------------------------------*
633 *--------------------------------------------------------------------*/
635 claw_irq_handler(struct ccw_device
*cdev
,
636 unsigned long intparm
, struct irb
*irb
)
638 struct chbk
*p_ch
= NULL
;
639 struct claw_privbk
*privptr
= NULL
;
640 struct net_device
*dev
= NULL
;
641 struct claw_env
*p_env
;
642 struct chbk
*p_ch_r
=NULL
;
644 kstat_cpu(smp_processor_id()).irqs
[IOINT_CLW
]++;
645 CLAW_DBF_TEXT(4, trace
, "clawirq");
646 /* Bypass all 'unsolicited interrupts' */
647 privptr
= dev_get_drvdata(&cdev
->dev
);
649 dev_warn(&cdev
->dev
, "An uninitialized CLAW device received an"
650 " IRQ, c-%02x d-%02x\n",
651 irb
->scsw
.cmd
.cstat
, irb
->scsw
.cmd
.dstat
);
652 CLAW_DBF_TEXT(2, trace
, "badirq");
656 /* Try to extract channel from driver data. */
657 if (privptr
->channel
[READ_CHANNEL
].cdev
== cdev
)
658 p_ch
= &privptr
->channel
[READ_CHANNEL
];
659 else if (privptr
->channel
[WRITE_CHANNEL
].cdev
== cdev
)
660 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
662 dev_warn(&cdev
->dev
, "The device is not a CLAW device\n");
663 CLAW_DBF_TEXT(2, trace
, "badchan");
666 CLAW_DBF_TEXT_(4, trace
, "IRQCH=%d", p_ch
->flag
);
668 dev
= (struct net_device
*) (p_ch
->ndev
);
669 p_env
=privptr
->p_env
;
671 /* Copy interruption response block. */
672 memcpy(p_ch
->irb
, irb
, sizeof(struct irb
));
674 /* Check for good subchannel return code, otherwise info message */
675 if (irb
->scsw
.cmd
.cstat
&& !(irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
)) {
677 "%s: subchannel check for device: %04x -"
678 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
679 dev
->name
, p_ch
->devno
,
680 irb
->scsw
.cmd
.cstat
, irb
->scsw
.cmd
.dstat
,
682 CLAW_DBF_TEXT(2, trace
, "chanchk");
686 /* Check the reason-code of a unit check */
687 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
688 ccw_check_unit_check(p_ch
, irb
->ecw
[0]);
690 /* State machine to bring the connection up, down and to restart */
691 p_ch
->last_dstat
= irb
->scsw
.cmd
.dstat
;
693 switch (p_ch
->claw_state
) {
694 case CLAW_STOP
:/* HALT_IO by claw_release (halt sequence) */
695 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
696 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
697 (p_ch
->irb
->scsw
.cmd
.stctl
==
698 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
))))
700 wake_up(&p_ch
->wait
); /* wake up claw_release */
701 CLAW_DBF_TEXT(4, trace
, "stop");
703 case CLAW_START_HALT_IO
: /* HALT_IO issued by claw_open */
704 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
705 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
706 (p_ch
->irb
->scsw
.cmd
.stctl
==
707 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
708 CLAW_DBF_TEXT(4, trace
, "haltio");
711 if (p_ch
->flag
== CLAW_READ
) {
712 p_ch
->claw_state
= CLAW_START_READ
;
713 wake_up(&p_ch
->wait
); /* wake claw_open (READ)*/
714 } else if (p_ch
->flag
== CLAW_WRITE
) {
715 p_ch
->claw_state
= CLAW_START_WRITE
;
716 /* send SYSTEM_VALIDATE */
717 claw_strt_read(dev
, LOCK_NO
);
718 claw_send_control(dev
,
719 SYSTEM_VALIDATE_REQUEST
,
722 p_env
->adapter_name
);
724 dev_warn(&cdev
->dev
, "The CLAW device received"
725 " an unexpected IRQ, "
728 irb
->scsw
.cmd
.dstat
);
731 CLAW_DBF_TEXT(4, trace
, "haltio");
733 case CLAW_START_READ
:
734 CLAW_DBF_TEXT(4, trace
, "ReadIRQ");
735 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) {
736 clear_bit(0, (void *)&p_ch
->IO_active
);
737 if ((p_ch
->irb
->ecw
[0] & 0x41) == 0x41 ||
738 (p_ch
->irb
->ecw
[0] & 0x40) == 0x40 ||
739 (p_ch
->irb
->ecw
[0]) == 0) {
740 privptr
->stats
.rx_errors
++;
742 "%s: Restart is required after remote "
746 CLAW_DBF_TEXT(4, trace
, "notrdy");
749 if ((p_ch
->irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
) &&
750 (p_ch
->irb
->scsw
.cmd
.dstat
== 0)) {
751 if (test_and_set_bit(CLAW_BH_ACTIVE
,
752 (void *)&p_ch
->flag_a
) == 0)
753 tasklet_schedule(&p_ch
->tasklet
);
755 CLAW_DBF_TEXT(4, trace
, "PCINoBH");
756 CLAW_DBF_TEXT(4, trace
, "PCI_read");
759 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
760 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
761 (p_ch
->irb
->scsw
.cmd
.stctl
==
762 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
763 CLAW_DBF_TEXT(4, trace
, "SPend_rd");
766 clear_bit(0, (void *)&p_ch
->IO_active
);
767 claw_clearbit_busy(TB_RETRY
, dev
);
768 if (test_and_set_bit(CLAW_BH_ACTIVE
,
769 (void *)&p_ch
->flag_a
) == 0)
770 tasklet_schedule(&p_ch
->tasklet
);
772 CLAW_DBF_TEXT(4, trace
, "RdBHAct");
773 CLAW_DBF_TEXT(4, trace
, "RdIRQXit");
775 case CLAW_START_WRITE
:
776 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) {
778 "%s: Unit Check Occured in "
779 "write channel\n", dev
->name
);
780 clear_bit(0, (void *)&p_ch
->IO_active
);
781 if (p_ch
->irb
->ecw
[0] & 0x80) {
783 "%s: Resetting Event "
784 "occurred:\n", dev
->name
);
785 init_timer(&p_ch
->timer
);
786 p_ch
->timer
.function
=
787 (void *)claw_write_retry
;
788 p_ch
->timer
.data
= (unsigned long)p_ch
;
789 p_ch
->timer
.expires
= jiffies
+ 10*HZ
;
790 add_timer(&p_ch
->timer
);
792 "%s: write connection "
793 "restarting\n", dev
->name
);
795 CLAW_DBF_TEXT(4, trace
, "rstrtwrt");
798 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) {
799 clear_bit(0, (void *)&p_ch
->IO_active
);
801 "%s: Unit Exception "
802 "occurred in write channel\n",
805 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
806 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
807 (p_ch
->irb
->scsw
.cmd
.stctl
==
808 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
809 CLAW_DBF_TEXT(4, trace
, "writeUE");
812 clear_bit(0, (void *)&p_ch
->IO_active
);
813 if (claw_test_and_setbit_busy(TB_TX
, dev
) == 0) {
814 claw_write_next(p_ch
);
815 claw_clearbit_busy(TB_TX
, dev
);
816 claw_clear_busy(dev
);
818 p_ch_r
= (struct chbk
*)&privptr
->channel
[READ_CHANNEL
];
819 if (test_and_set_bit(CLAW_BH_ACTIVE
,
820 (void *)&p_ch_r
->flag_a
) == 0)
821 tasklet_schedule(&p_ch_r
->tasklet
);
822 CLAW_DBF_TEXT(4, trace
, "StWtExit");
826 "The CLAW device for %s received an unexpected IRQ\n",
828 CLAW_DBF_TEXT(2, trace
, "badIRQ");
832 } /* end of claw_irq_handler */
835 /*-------------------------------------------------------------------*
838 *--------------------------------------------------------------------*/
840 claw_irq_tasklet ( unsigned long data
)
843 struct net_device
*dev
;
844 struct claw_privbk
* privptr
;
846 p_ch
= (struct chbk
*) data
;
847 dev
= (struct net_device
*)p_ch
->ndev
;
848 CLAW_DBF_TEXT(4, trace
, "IRQtask");
849 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
851 clear_bit(CLAW_BH_ACTIVE
, (void *)&p_ch
->flag_a
);
852 CLAW_DBF_TEXT(4, trace
, "TskletXt");
854 } /* end of claw_irq_bh */
856 /*-------------------------------------------------------------------*
859 *--------------------------------------------------------------------*/
861 claw_release(struct net_device
*dev
)
865 unsigned long saveflags
;
867 struct claw_privbk
*privptr
;
868 DECLARE_WAITQUEUE(wait
, current
);
869 struct ccwbk
* p_this_ccw
;
874 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
877 CLAW_DBF_TEXT(4, trace
, "release");
878 privptr
->release_pend
=1;
879 claw_setbit_busy(TB_STOP
,dev
);
880 for ( i
= 1; i
>=0 ; i
--) {
882 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
883 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
884 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
885 privptr
->channel
[i
].IO_active
= 0;
886 parm
= (unsigned long) &privptr
->channel
[i
];
887 if (i
== WRITE_CHANNEL
)
888 claw_purge_skb_queue(
889 &privptr
->channel
[WRITE_CHANNEL
].collect_queue
);
890 rc
= ccw_device_halt (privptr
->channel
[i
].cdev
, parm
);
891 if (privptr
->system_validate_comp
==0x00) /* never opened? */
892 init_waitqueue_head(&privptr
->channel
[i
].wait
);
893 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
894 set_current_state(TASK_INTERRUPTIBLE
);
895 spin_unlock_irqrestore(
896 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
898 set_current_state(TASK_RUNNING
);
899 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
901 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
904 if (privptr
->pk_skb
!= NULL
) {
905 dev_kfree_skb_any(privptr
->pk_skb
);
906 privptr
->pk_skb
= NULL
;
908 if(privptr
->buffs_alloc
!= 1) {
909 CLAW_DBF_TEXT(4, trace
, "none2fre");
912 CLAW_DBF_TEXT(4, trace
, "freebufs");
913 if (privptr
->p_buff_ccw
!= NULL
) {
914 free_pages((unsigned long)privptr
->p_buff_ccw
,
915 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
917 CLAW_DBF_TEXT(4, trace
, "freeread");
918 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
919 if (privptr
->p_buff_read
!= NULL
) {
920 free_pages((unsigned long)privptr
->p_buff_read
,
921 (int)pages_to_order_of_mag(privptr
->p_buff_read_num
));
925 p_buf
=privptr
->p_read_active_first
;
926 while (p_buf
!=NULL
) {
927 free_pages((unsigned long)p_buf
->p_buffer
,
928 (int)pages_to_order_of_mag(
929 privptr
->p_buff_pages_perread
));
933 CLAW_DBF_TEXT(4, trace
, "freewrit");
934 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
935 free_pages((unsigned long)privptr
->p_buff_write
,
936 (int)pages_to_order_of_mag(privptr
->p_buff_write_num
));
939 p_buf
=privptr
->p_write_active_first
;
940 while (p_buf
!=NULL
) {
941 free_pages((unsigned long)p_buf
->p_buffer
,
942 (int)pages_to_order_of_mag(
943 privptr
->p_buff_pages_perwrite
));
947 CLAW_DBF_TEXT(4, trace
, "clearptr");
948 privptr
->buffs_alloc
= 0;
949 privptr
->p_buff_ccw
=NULL
;
950 privptr
->p_buff_read
=NULL
;
951 privptr
->p_buff_write
=NULL
;
952 privptr
->system_validate_comp
=0;
953 privptr
->release_pend
=0;
954 /* Remove any writes that were pending and reset all reads */
955 p_this_ccw
=privptr
->p_read_active_first
;
956 while (p_this_ccw
!=NULL
) {
957 p_this_ccw
->header
.length
=0xffff;
958 p_this_ccw
->header
.opcode
=0xff;
959 p_this_ccw
->header
.flag
=0x00;
960 p_this_ccw
=p_this_ccw
->next
;
963 while (privptr
->p_write_active_first
!=NULL
) {
964 p_this_ccw
=privptr
->p_write_active_first
;
965 p_this_ccw
->header
.flag
=CLAW_PENDING
;
966 privptr
->p_write_active_first
=p_this_ccw
->next
;
967 p_this_ccw
->next
=privptr
->p_write_free_chain
;
968 privptr
->p_write_free_chain
=p_this_ccw
;
969 ++privptr
->write_free_count
;
971 privptr
->p_write_active_last
=NULL
;
972 privptr
->mtc_logical_link
= -1;
973 privptr
->mtc_skipping
= 1;
974 privptr
->mtc_offset
=0;
976 if (((privptr
->channel
[READ_CHANNEL
].last_dstat
|
977 privptr
->channel
[WRITE_CHANNEL
].last_dstat
) &
978 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) {
979 dev_warn(&privptr
->channel
[READ_CHANNEL
].cdev
->dev
,
980 "Deactivating %s completed with incorrect"
981 " subchannel status "
982 "(read %02x, write %02x)\n",
984 privptr
->channel
[READ_CHANNEL
].last_dstat
,
985 privptr
->channel
[WRITE_CHANNEL
].last_dstat
);
986 CLAW_DBF_TEXT(2, trace
, "badclose");
988 CLAW_DBF_TEXT(4, trace
, "rlsexit");
990 } /* end of claw_release */
992 /*-------------------------------------------------------------------*
995 *--------------------------------------------------------------------*/
998 claw_write_retry ( struct chbk
*p_ch
)
1001 struct net_device
*dev
=p_ch
->ndev
;
1003 CLAW_DBF_TEXT(4, trace
, "w_retry");
1004 if (p_ch
->claw_state
== CLAW_STOP
) {
1007 claw_strt_out_IO( dev
);
1008 CLAW_DBF_TEXT(4, trace
, "rtry_xit");
1010 } /* end of claw_write_retry */
1013 /*-------------------------------------------------------------------*
1016 *--------------------------------------------------------------------*/
1019 claw_write_next ( struct chbk
* p_ch
)
1022 struct net_device
*dev
;
1023 struct claw_privbk
*privptr
=NULL
;
1024 struct sk_buff
*pk_skb
;
1027 CLAW_DBF_TEXT(4, trace
, "claw_wrt");
1028 if (p_ch
->claw_state
== CLAW_STOP
)
1030 dev
= (struct net_device
*) p_ch
->ndev
;
1031 privptr
= (struct claw_privbk
*) dev
->ml_priv
;
1032 claw_free_wrt_buf( dev
);
1033 if ((privptr
->write_free_count
> 0) &&
1034 !skb_queue_empty(&p_ch
->collect_queue
)) {
1035 pk_skb
= claw_pack_skb(privptr
);
1036 while (pk_skb
!= NULL
) {
1037 rc
= claw_hw_tx( pk_skb
, dev
,1);
1038 if (privptr
->write_free_count
> 0) {
1039 pk_skb
= claw_pack_skb(privptr
);
1044 if (privptr
->p_write_active_first
!=NULL
) {
1045 claw_strt_out_IO(dev
);
1048 } /* end of claw_write_next */
1050 /*-------------------------------------------------------------------*
1053 *--------------------------------------------------------------------*/
1056 claw_timer ( struct chbk
* p_ch
)
1058 CLAW_DBF_TEXT(4, trace
, "timer");
1059 p_ch
->flag
|= CLAW_TIMER
;
1060 wake_up(&p_ch
->wait
);
1062 } /* end of claw_timer */
1070 /*-------------------------------------------------------------------*
1072 * pages_to_order_of_mag *
1074 * takes a number of pages from 1 to 512 and returns the *
1075 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1076 * of magnitude get_free_pages() has an upper order of 9 *
1077 *--------------------------------------------------------------------*/
1080 pages_to_order_of_mag(int num_of_pages
)
1082 int order_of_mag
=1; /* assume 2 pages */
1085 CLAW_DBF_TEXT_(5, trace
, "pages%d", num_of_pages
);
1086 if (num_of_pages
== 1) {return 0; } /* magnitude of 0 = 1 page */
1087 /* 512 pages = 2Meg on 4k page systems */
1088 if (num_of_pages
>= 512) {return 9; }
1089 /* we have two or more pages order is at least 1 */
1090 for (nump
=2 ;nump
<= 512;nump
*=2) {
1091 if (num_of_pages
<= nump
)
1095 if (order_of_mag
> 9) { order_of_mag
= 9; } /* I know it's paranoid */
1096 CLAW_DBF_TEXT_(5, trace
, "mag%d", order_of_mag
);
1097 return order_of_mag
;
1100 /*-------------------------------------------------------------------*
1104 *--------------------------------------------------------------------*/
1106 add_claw_reads(struct net_device
*dev
, struct ccwbk
* p_first
,
1107 struct ccwbk
* p_last
)
1109 struct claw_privbk
*privptr
;
1110 struct ccw1 temp_ccw
;
1111 struct endccw
* p_end
;
1112 CLAW_DBF_TEXT(4, trace
, "addreads");
1113 privptr
= dev
->ml_priv
;
1114 p_end
= privptr
->p_end_ccw
;
1116 /* first CCW and last CCW contains a new set of read channel programs
1117 * to apend the running channel programs
1119 if ( p_first
==NULL
) {
1120 CLAW_DBF_TEXT(4, trace
, "addexit");
1124 /* set up ending CCW sequence for this segment */
1126 p_end
->read1
=0x00; /* second ending CCW is now active */
1127 /* reset ending CCWs and setup TIC CCWs */
1128 p_end
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1129 p_end
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1130 p_last
->r_TIC_1
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1131 p_last
->r_TIC_2
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1132 p_end
->read2_nop2
.cda
=0;
1133 p_end
->read2_nop2
.count
=1;
1136 p_end
->read1
=0x01; /* first ending CCW is now active */
1137 /* reset ending CCWs and setup TIC CCWs */
1138 p_end
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1139 p_end
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1140 p_last
->r_TIC_1
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1141 p_last
->r_TIC_2
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1142 p_end
->read1_nop2
.cda
=0;
1143 p_end
->read1_nop2
.count
=1;
1146 if ( privptr
-> p_read_active_first
==NULL
) {
1147 privptr
->p_read_active_first
= p_first
; /* set new first */
1148 privptr
->p_read_active_last
= p_last
; /* set new last */
1152 /* set up TIC ccw */
1153 temp_ccw
.cda
= (__u32
)__pa(&p_first
->read
);
1156 temp_ccw
.cmd_code
= CCW_CLAW_CMD_TIC
;
1161 /* first set of CCW's is chained to the new read */
1162 /* chain, so the second set is chained to the active chain. */
1163 /* Therefore modify the second set to point to the new */
1164 /* read chain set up TIC CCWs */
1165 /* make sure we update the CCW so channel doesn't fetch it */
1166 /* when it's only half done */
1167 memcpy( &p_end
->read2_nop2
, &temp_ccw
,
1168 sizeof(struct ccw1
));
1169 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1170 (__u32
)__pa(&p_first
->read
);
1171 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1172 (__u32
)__pa(&p_first
->read
);
1175 /* make sure we update the CCW so channel doesn't */
1176 /* fetch it when it is only half done */
1177 memcpy( &p_end
->read1_nop2
, &temp_ccw
,
1178 sizeof(struct ccw1
));
1179 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1180 (__u32
)__pa(&p_first
->read
);
1181 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1182 (__u32
)__pa(&p_first
->read
);
1184 /* chain in new set of blocks */
1185 privptr
->p_read_active_last
->next
= p_first
;
1186 privptr
->p_read_active_last
=p_last
;
1187 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1188 CLAW_DBF_TEXT(4, trace
, "addexit");
1190 } /* end of add_claw_reads */
1192 /*-------------------------------------------------------------------*
1193 * ccw_check_return_code *
1195 *-------------------------------------------------------------------*/
1198 ccw_check_return_code(struct ccw_device
*cdev
, int return_code
)
1200 CLAW_DBF_TEXT(4, trace
, "ccwret");
1201 if (return_code
!= 0) {
1202 switch (return_code
) {
1203 case -EBUSY
: /* BUSY is a transient state no action needed */
1206 dev_err(&cdev
->dev
, "The remote channel adapter is not"
1211 "The status of the remote channel adapter"
1215 dev_err(&cdev
->dev
, "The common device layer"
1216 " returned error code %d\n",
1220 CLAW_DBF_TEXT(4, trace
, "ccwret");
1221 } /* end of ccw_check_return_code */
1223 /*-------------------------------------------------------------------*
1224 * ccw_check_unit_check *
1225 *--------------------------------------------------------------------*/
1228 ccw_check_unit_check(struct chbk
* p_ch
, unsigned char sense
)
1230 struct net_device
*ndev
= p_ch
->ndev
;
1231 struct device
*dev
= &p_ch
->cdev
->dev
;
1233 CLAW_DBF_TEXT(4, trace
, "unitchek");
1234 dev_warn(dev
, "The communication peer of %s disconnected\n",
1239 dev_warn(dev
, "The remote channel adapter for"
1240 " %s has been reset\n",
1243 } else if (sense
& 0x20) {
1245 dev_warn(dev
, "A data streaming timeout occurred"
1248 } else if (sense
& 0x10) {
1249 dev_warn(dev
, "The remote channel adapter for %s"
1253 dev_warn(dev
, "A data transfer parity error occurred"
1257 } else if (sense
& 0x10) {
1258 dev_warn(dev
, "A read data parity error occurred"
1263 } /* end of ccw_check_unit_check */
1265 /*-------------------------------------------------------------------*
1267 *--------------------------------------------------------------------*/
1269 find_link(struct net_device
*dev
, char *host_name
, char *ws_name
)
1271 struct claw_privbk
*privptr
;
1272 struct claw_env
*p_env
;
1275 CLAW_DBF_TEXT(2, setup
, "findlink");
1276 privptr
= dev
->ml_priv
;
1277 p_env
=privptr
->p_env
;
1278 switch (p_env
->packing
)
1281 if ((memcmp(WS_APPL_NAME_PACKED
, host_name
, 8)!=0) ||
1282 (memcmp(WS_APPL_NAME_PACKED
, ws_name
, 8)!=0 ))
1287 if ((memcmp(WS_APPL_NAME_IP_NAME
, host_name
, 8)!=0) ||
1288 (memcmp(WS_APPL_NAME_IP_NAME
, ws_name
, 8)!=0 ))
1292 if ((memcmp(HOST_APPL_NAME
, host_name
, 8)!=0) ||
1293 (memcmp(p_env
->api_type
, ws_name
, 8)!=0))
1299 } /* end of find_link */
1301 /*-------------------------------------------------------------------*
1305 *-------------------------------------------------------------------*/
1308 claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
)
1311 struct claw_privbk
*privptr
;
1312 struct ccwbk
*p_this_ccw
;
1313 struct ccwbk
*p_first_ccw
;
1314 struct ccwbk
*p_last_ccw
;
1316 signed long len_of_data
;
1317 unsigned long bytesInThisBuffer
;
1318 unsigned char *pDataAddress
;
1319 struct endccw
*pEnd
;
1320 struct ccw1 tempCCW
;
1322 struct claw_env
*p_env
;
1324 struct clawph
*pk_head
;
1327 CLAW_DBF_TEXT(4, trace
, "hw_tx");
1328 privptr
= (struct claw_privbk
*)(dev
->ml_priv
);
1329 p_ch
= (struct chbk
*)&privptr
->channel
[WRITE_CHANNEL
];
1330 p_env
=privptr
->p_env
;
1331 claw_free_wrt_buf(dev
); /* Clean up free chain if posible */
1332 /* scan the write queue to free any completed write packets */
1335 if ((p_env
->packing
>= PACK_SEND
) &&
1336 (skb
->cb
[1] != 'P')) {
1337 skb_push(skb
,sizeof(struct clawph
));
1338 pk_head
=(struct clawph
*)skb
->data
;
1339 pk_head
->len
=skb
->len
-sizeof(struct clawph
);
1340 if (pk_head
->len
%4) {
1341 pk_head
->len
+= 4-(pk_head
->len
%4);
1342 skb_pad(skb
,4-(pk_head
->len
%4));
1343 skb_put(skb
,4-(pk_head
->len
%4));
1345 if (p_env
->packing
== DO_PACKED
)
1346 pk_head
->link_num
= linkid
;
1348 pk_head
->link_num
= 0;
1349 pk_head
->flag
= 0x00;
1354 if (claw_check_busy(dev
)) {
1355 if (privptr
->write_free_count
!=0) {
1356 claw_clear_busy(dev
);
1359 claw_strt_out_IO(dev
);
1360 claw_free_wrt_buf( dev
);
1361 if (privptr
->write_free_count
==0) {
1362 ch
= &privptr
->channel
[WRITE_CHANNEL
];
1363 atomic_inc(&skb
->users
);
1364 skb_queue_tail(&ch
->collect_queue
, skb
);
1368 claw_clear_busy(dev
);
1373 if (claw_test_and_setbit_busy(TB_TX
,dev
)) { /* set to busy */
1374 ch
= &privptr
->channel
[WRITE_CHANNEL
];
1375 atomic_inc(&skb
->users
);
1376 skb_queue_tail(&ch
->collect_queue
, skb
);
1377 claw_strt_out_IO(dev
);
1382 /* See how many write buffers are required to hold this data */
1383 numBuffers
= DIV_ROUND_UP(skb
->len
, privptr
->p_env
->write_size
);
1385 /* If that number of buffers isn't available, give up for now */
1386 if (privptr
->write_free_count
< numBuffers
||
1387 privptr
->p_write_free_chain
== NULL
) {
1389 claw_setbit_busy(TB_NOBUFFER
,dev
);
1390 ch
= &privptr
->channel
[WRITE_CHANNEL
];
1391 atomic_inc(&skb
->users
);
1392 skb_queue_tail(&ch
->collect_queue
, skb
);
1393 CLAW_DBF_TEXT(2, trace
, "clawbusy");
1396 pDataAddress
=skb
->data
;
1397 len_of_data
=skb
->len
;
1399 while (len_of_data
> 0) {
1400 p_this_ccw
=privptr
->p_write_free_chain
; /* get a block */
1401 if (p_this_ccw
== NULL
) { /* lost the race */
1402 ch
= &privptr
->channel
[WRITE_CHANNEL
];
1403 atomic_inc(&skb
->users
);
1404 skb_queue_tail(&ch
->collect_queue
, skb
);
1407 privptr
->p_write_free_chain
=p_this_ccw
->next
;
1408 p_this_ccw
->next
=NULL
;
1409 --privptr
->write_free_count
; /* -1 */
1410 if (len_of_data
>= privptr
->p_env
->write_size
)
1411 bytesInThisBuffer
= privptr
->p_env
->write_size
;
1413 bytesInThisBuffer
= len_of_data
;
1414 memcpy( p_this_ccw
->p_buffer
,pDataAddress
, bytesInThisBuffer
);
1415 len_of_data
-=bytesInThisBuffer
;
1416 pDataAddress
+=(unsigned long)bytesInThisBuffer
;
1417 /* setup write CCW */
1418 p_this_ccw
->write
.cmd_code
= (linkid
* 8) +1;
1419 if (len_of_data
>0) {
1420 p_this_ccw
->write
.cmd_code
+=MORE_to_COME_FLAG
;
1422 p_this_ccw
->write
.count
=bytesInThisBuffer
;
1423 /* now add to end of this chain */
1424 if (p_first_ccw
==NULL
) {
1425 p_first_ccw
=p_this_ccw
;
1427 if (p_last_ccw
!=NULL
) {
1428 p_last_ccw
->next
=p_this_ccw
;
1429 /* set up TIC ccws */
1430 p_last_ccw
->w_TIC_1
.cda
=
1431 (__u32
)__pa(&p_this_ccw
->write
);
1433 p_last_ccw
=p_this_ccw
; /* save new last block */
1436 /* FirstCCW and LastCCW now contain a new set of write channel
1437 * programs to append to the running channel program
1440 if (p_first_ccw
!=NULL
) {
1441 /* setup ending ccw sequence for this segment */
1442 pEnd
=privptr
->p_end_ccw
;
1444 pEnd
->write1
=0x00; /* second end ccw is now active */
1445 /* set up Tic CCWs */
1446 p_last_ccw
->w_TIC_1
.cda
=
1447 (__u32
)__pa(&pEnd
->write2_nop1
);
1448 pEnd
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1449 pEnd
->write2_nop2
.flags
=
1450 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1451 pEnd
->write2_nop2
.cda
=0;
1452 pEnd
->write2_nop2
.count
=1;
1454 else { /* end of if (pEnd->write1)*/
1455 pEnd
->write1
=0x01; /* first end ccw is now active */
1456 /* set up Tic CCWs */
1457 p_last_ccw
->w_TIC_1
.cda
=
1458 (__u32
)__pa(&pEnd
->write1_nop1
);
1459 pEnd
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1460 pEnd
->write1_nop2
.flags
=
1461 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1462 pEnd
->write1_nop2
.cda
=0;
1463 pEnd
->write1_nop2
.count
=1;
1464 } /* end if if (pEnd->write1) */
1466 if (privptr
->p_write_active_first
==NULL
) {
1467 privptr
->p_write_active_first
=p_first_ccw
;
1468 privptr
->p_write_active_last
=p_last_ccw
;
1471 /* set up Tic CCWs */
1473 tempCCW
.cda
=(__u32
)__pa(&p_first_ccw
->write
);
1476 tempCCW
.cmd_code
=CCW_CLAW_CMD_TIC
;
1481 * first set of ending CCW's is chained to the new write
1482 * chain, so the second set is chained to the active chain
1483 * Therefore modify the second set to point the new write chain.
1484 * make sure we update the CCW atomically
1485 * so channel does not fetch it when it's only half done
1487 memcpy( &pEnd
->write2_nop2
, &tempCCW
,
1488 sizeof(struct ccw1
));
1489 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1490 (__u32
)__pa(&p_first_ccw
->write
);
1494 /*make sure we update the CCW atomically
1495 *so channel does not fetch it when it's only half done
1497 memcpy(&pEnd
->write1_nop2
, &tempCCW
,
1498 sizeof(struct ccw1
));
1499 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1500 (__u32
)__pa(&p_first_ccw
->write
);
1502 } /* end if if (pEnd->write1) */
1504 privptr
->p_write_active_last
->next
=p_first_ccw
;
1505 privptr
->p_write_active_last
=p_last_ccw
;
1508 } /* endif (p_first_ccw!=NULL) */
1509 dev_kfree_skb_any(skb
);
1516 claw_strt_out_IO(dev
);
1517 /* if write free count is zero , set NOBUFFER */
1518 if (privptr
->write_free_count
==0) {
1519 claw_setbit_busy(TB_NOBUFFER
,dev
);
1522 claw_clearbit_busy(TB_TX
,dev
);
1525 } /* end of claw_hw_tx */
1527 /*-------------------------------------------------------------------*
1531 *--------------------------------------------------------------------*/
1534 init_ccw_bk(struct net_device
*dev
)
1537 __u32 ccw_blocks_required
;
1538 __u32 ccw_blocks_perpage
;
1539 __u32 ccw_pages_required
;
1540 __u32 claw_reads_perpage
=1;
1541 __u32 claw_read_pages
;
1542 __u32 claw_writes_perpage
=1;
1543 __u32 claw_write_pages
;
1545 struct ccwbk
*p_free_chain
;
1547 struct ccwbk
*p_last_CCWB
;
1548 struct ccwbk
*p_first_CCWB
;
1549 struct endccw
*p_endccw
=NULL
;
1550 addr_t real_address
;
1551 struct claw_privbk
*privptr
= dev
->ml_priv
;
1552 struct clawh
*pClawH
=NULL
;
1553 addr_t real_TIC_address
;
1555 CLAW_DBF_TEXT(4, trace
, "init_ccw");
1557 /* initialize statistics field */
1558 privptr
->active_link_ID
=0;
1559 /* initialize ccwbk pointers */
1560 privptr
->p_write_free_chain
=NULL
; /* pointer to free ccw chain*/
1561 privptr
->p_write_active_first
=NULL
; /* pointer to the first write ccw*/
1562 privptr
->p_write_active_last
=NULL
; /* pointer to the last write ccw*/
1563 privptr
->p_read_active_first
=NULL
; /* pointer to the first read ccw*/
1564 privptr
->p_read_active_last
=NULL
; /* pointer to the last read ccw */
1565 privptr
->p_end_ccw
=NULL
; /* pointer to ending ccw */
1566 privptr
->p_claw_signal_blk
=NULL
; /* pointer to signal block */
1567 privptr
->buffs_alloc
= 0;
1568 memset(&privptr
->end_ccw
, 0x00, sizeof(struct endccw
));
1569 memset(&privptr
->ctl_bk
, 0x00, sizeof(struct clawctl
));
1570 /* initialize free write ccwbk counter */
1571 privptr
->write_free_count
=0; /* number of free bufs on write chain */
1575 * We need 1 CCW block for each read buffer, 1 for each
1576 * write buffer, plus 1 for ClawSignalBlock
1578 ccw_blocks_required
=
1579 privptr
->p_env
->read_buffers
+privptr
->p_env
->write_buffers
+1;
1581 * compute number of CCW blocks that will fit in a page
1583 ccw_blocks_perpage
= PAGE_SIZE
/ CCWBK_SIZE
;
1585 DIV_ROUND_UP(ccw_blocks_required
, ccw_blocks_perpage
);
1588 * read and write sizes are set by 2 constants in claw.h
1589 * 4k and 32k. Unpacked values other than 4k are not going to
1590 * provide good performance. With packing buffers support 32k
1593 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1594 claw_reads_perpage
= PAGE_SIZE
/ privptr
->p_env
->read_size
;
1595 claw_read_pages
= DIV_ROUND_UP(privptr
->p_env
->read_buffers
,
1596 claw_reads_perpage
);
1598 else { /* > or equal */
1599 privptr
->p_buff_pages_perread
=
1600 DIV_ROUND_UP(privptr
->p_env
->read_size
, PAGE_SIZE
);
1601 claw_read_pages
= privptr
->p_env
->read_buffers
*
1602 privptr
->p_buff_pages_perread
;
1604 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1605 claw_writes_perpage
=
1606 PAGE_SIZE
/ privptr
->p_env
->write_size
;
1607 claw_write_pages
= DIV_ROUND_UP(privptr
->p_env
->write_buffers
,
1608 claw_writes_perpage
);
1611 else { /* > or equal */
1612 privptr
->p_buff_pages_perwrite
=
1613 DIV_ROUND_UP(privptr
->p_env
->read_size
, PAGE_SIZE
);
1614 claw_write_pages
= privptr
->p_env
->write_buffers
*
1615 privptr
->p_buff_pages_perwrite
;
1618 * allocate ccw_pages_required
1620 if (privptr
->p_buff_ccw
==NULL
) {
1621 privptr
->p_buff_ccw
=
1622 (void *)__get_free_pages(__GFP_DMA
,
1623 (int)pages_to_order_of_mag(ccw_pages_required
));
1624 if (privptr
->p_buff_ccw
==NULL
) {
1627 privptr
->p_buff_ccw_num
=ccw_pages_required
;
1629 memset(privptr
->p_buff_ccw
, 0x00,
1630 privptr
->p_buff_ccw_num
* PAGE_SIZE
);
1633 * obtain ending ccw block address
1636 privptr
->p_end_ccw
= (struct endccw
*)&privptr
->end_ccw
;
1637 real_address
= (__u32
)__pa(privptr
->p_end_ccw
);
1638 /* Initialize ending CCW block */
1639 p_endccw
=privptr
->p_end_ccw
;
1640 p_endccw
->real
=real_address
;
1641 p_endccw
->write1
=0x00;
1642 p_endccw
->read1
=0x00;
1645 p_endccw
->write1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1646 p_endccw
->write1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1647 p_endccw
->write1_nop1
.count
= 1;
1648 p_endccw
->write1_nop1
.cda
= 0;
1651 p_endccw
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1652 p_endccw
->write1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1653 p_endccw
->write1_nop2
.count
= 1;
1654 p_endccw
->write1_nop2
.cda
= 0;
1657 p_endccw
->write2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1658 p_endccw
->write2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1659 p_endccw
->write2_nop1
.count
= 1;
1660 p_endccw
->write2_nop1
.cda
= 0;
1663 p_endccw
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1664 p_endccw
->write2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1665 p_endccw
->write2_nop2
.count
= 1;
1666 p_endccw
->write2_nop2
.cda
= 0;
1669 p_endccw
->read1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1670 p_endccw
->read1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1671 p_endccw
->read1_nop1
.count
= 1;
1672 p_endccw
->read1_nop1
.cda
= 0;
1675 p_endccw
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1676 p_endccw
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1677 p_endccw
->read1_nop2
.count
= 1;
1678 p_endccw
->read1_nop2
.cda
= 0;
1681 p_endccw
->read2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1682 p_endccw
->read2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1683 p_endccw
->read2_nop1
.count
= 1;
1684 p_endccw
->read2_nop1
.cda
= 0;
1687 p_endccw
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1688 p_endccw
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1689 p_endccw
->read2_nop2
.count
= 1;
1690 p_endccw
->read2_nop2
.cda
= 0;
1693 * Build a chain of CCWs
1696 p_buff
=privptr
->p_buff_ccw
;
1699 for (i
=0 ; i
< ccw_pages_required
; i
++ ) {
1700 real_address
= (__u32
)__pa(p_buff
);
1702 for (j
=0 ; j
< ccw_blocks_perpage
; j
++) {
1703 p_buf
->next
= p_free_chain
;
1704 p_free_chain
= p_buf
;
1705 p_buf
->real
=(__u32
)__pa(p_buf
);
1711 * Initialize ClawSignalBlock
1714 if (privptr
->p_claw_signal_blk
==NULL
) {
1715 privptr
->p_claw_signal_blk
=p_free_chain
;
1716 p_free_chain
=p_free_chain
->next
;
1717 pClawH
=(struct clawh
*)privptr
->p_claw_signal_blk
;
1718 pClawH
->length
=0xffff;
1719 pClawH
->opcode
=0xff;
1720 pClawH
->flag
=CLAW_BUSY
;
1724 * allocate write_pages_required and add to free chain
1726 if (privptr
->p_buff_write
==NULL
) {
1727 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1728 privptr
->p_buff_write
=
1729 (void *)__get_free_pages(__GFP_DMA
,
1730 (int)pages_to_order_of_mag(claw_write_pages
));
1731 if (privptr
->p_buff_write
==NULL
) {
1732 privptr
->p_buff_ccw
=NULL
;
1736 * Build CLAW write free chain
1740 memset(privptr
->p_buff_write
, 0x00,
1741 ccw_pages_required
* PAGE_SIZE
);
1742 privptr
->p_write_free_chain
=NULL
;
1744 p_buff
=privptr
->p_buff_write
;
1746 for (i
=0 ; i
< privptr
->p_env
->write_buffers
; i
++) {
1747 p_buf
= p_free_chain
; /* get a CCW */
1748 p_free_chain
= p_buf
->next
;
1749 p_buf
->next
=privptr
->p_write_free_chain
;
1750 privptr
->p_write_free_chain
= p_buf
;
1751 p_buf
-> p_buffer
= (struct clawbuf
*)p_buff
;
1752 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
1753 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1754 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1755 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1756 p_buf
-> w_read_FF
.count
= 1;
1757 p_buf
-> w_read_FF
.cda
=
1758 (__u32
)__pa(&p_buf
-> header
.flag
);
1759 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1760 p_buf
-> w_TIC_1
.flags
= 0;
1761 p_buf
-> w_TIC_1
.count
= 0;
1763 if (((unsigned long)p_buff
+
1764 privptr
->p_env
->write_size
) >=
1765 ((unsigned long)(p_buff
+2*
1766 (privptr
->p_env
->write_size
) - 1) & PAGE_MASK
)) {
1767 p_buff
= p_buff
+privptr
->p_env
->write_size
;
1771 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1773 privptr
->p_write_free_chain
=NULL
;
1774 for (i
= 0; i
< privptr
->p_env
->write_buffers
; i
++) {
1775 p_buff
=(void *)__get_free_pages(__GFP_DMA
,
1776 (int)pages_to_order_of_mag(
1777 privptr
->p_buff_pages_perwrite
) );
1779 free_pages((unsigned long)privptr
->p_buff_ccw
,
1780 (int)pages_to_order_of_mag(
1781 privptr
->p_buff_ccw_num
));
1782 privptr
->p_buff_ccw
=NULL
;
1783 p_buf
=privptr
->p_buff_write
;
1784 while (p_buf
!=NULL
) {
1785 free_pages((unsigned long)
1787 (int)pages_to_order_of_mag(
1788 privptr
->p_buff_pages_perwrite
));
1792 } /* Error on get_pages */
1793 memset(p_buff
, 0x00, privptr
->p_env
->write_size
);
1794 p_buf
= p_free_chain
;
1795 p_free_chain
= p_buf
->next
;
1796 p_buf
->next
= privptr
->p_write_free_chain
;
1797 privptr
->p_write_free_chain
= p_buf
;
1798 privptr
->p_buff_write
= p_buf
;
1799 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1800 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
1801 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1802 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1803 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1804 p_buf
-> w_read_FF
.count
= 1;
1805 p_buf
-> w_read_FF
.cda
=
1806 (__u32
)__pa(&p_buf
-> header
.flag
);
1807 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1808 p_buf
-> w_TIC_1
.flags
= 0;
1809 p_buf
-> w_TIC_1
.count
= 0;
1810 } /* for all write_buffers */
1812 } /* else buffers are PAGE_SIZE or bigger */
1815 privptr
->p_buff_write_num
=claw_write_pages
;
1816 privptr
->write_free_count
=privptr
->p_env
->write_buffers
;
1820 * allocate read_pages_required and chain to free chain
1822 if (privptr
->p_buff_read
==NULL
) {
1823 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1824 privptr
->p_buff_read
=
1825 (void *)__get_free_pages(__GFP_DMA
,
1826 (int)pages_to_order_of_mag(claw_read_pages
) );
1827 if (privptr
->p_buff_read
==NULL
) {
1828 free_pages((unsigned long)privptr
->p_buff_ccw
,
1829 (int)pages_to_order_of_mag(
1830 privptr
->p_buff_ccw_num
));
1831 /* free the write pages size is < page size */
1832 free_pages((unsigned long)privptr
->p_buff_write
,
1833 (int)pages_to_order_of_mag(
1834 privptr
->p_buff_write_num
));
1835 privptr
->p_buff_ccw
=NULL
;
1836 privptr
->p_buff_write
=NULL
;
1839 memset(privptr
->p_buff_read
, 0x00, claw_read_pages
* PAGE_SIZE
);
1840 privptr
->p_buff_read_num
=claw_read_pages
;
1842 * Build CLAW read free chain
1845 p_buff
=privptr
->p_buff_read
;
1846 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
1847 p_buf
= p_free_chain
;
1848 p_free_chain
= p_buf
->next
;
1850 if (p_last_CCWB
==NULL
) {
1856 p_buf
->next
=p_first_CCWB
;
1858 (__u32
)__pa(&p_first_CCWB
-> read
);
1863 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1864 /* initialize read command */
1865 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
1866 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
1867 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1868 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
1870 /* initialize read_h command */
1871 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
1872 p_buf
-> read_h
.cda
=
1873 (__u32
)__pa(&(p_buf
->header
));
1874 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1875 p_buf
-> read_h
.count
= sizeof(struct clawh
);
1877 /* initialize Signal command */
1878 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
1879 p_buf
-> signal
.cda
=
1880 (__u32
)__pa(&(pClawH
->flag
));
1881 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1882 p_buf
-> signal
.count
= 1;
1884 /* initialize r_TIC_1 command */
1885 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1886 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
1887 p_buf
-> r_TIC_1
.flags
= 0;
1888 p_buf
-> r_TIC_1
.count
= 0;
1890 /* initialize r_read_FF command */
1891 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1892 p_buf
-> r_read_FF
.cda
=
1893 (__u32
)__pa(&(pClawH
->flag
));
1894 p_buf
-> r_read_FF
.flags
=
1895 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
1896 p_buf
-> r_read_FF
.count
= 1;
1898 /* initialize r_TIC_2 */
1899 memcpy(&p_buf
->r_TIC_2
,
1900 &p_buf
->r_TIC_1
, sizeof(struct ccw1
));
1902 /* initialize Header */
1903 p_buf
->header
.length
=0xffff;
1904 p_buf
->header
.opcode
=0xff;
1905 p_buf
->header
.flag
=CLAW_PENDING
;
1907 if (((unsigned long)p_buff
+privptr
->p_env
->read_size
) >=
1908 ((unsigned long)(p_buff
+2*(privptr
->p_env
->read_size
)
1911 p_buff
= p_buff
+privptr
->p_env
->read_size
;
1915 (void *)((unsigned long)
1916 (p_buff
+2*(privptr
->p_env
->read_size
)-1)
1919 } /* for read_buffers */
1920 } /* read_size < PAGE_SIZE */
1921 else { /* read Size >= PAGE_SIZE */
1922 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
1923 p_buff
= (void *)__get_free_pages(__GFP_DMA
,
1924 (int)pages_to_order_of_mag(
1925 privptr
->p_buff_pages_perread
));
1927 free_pages((unsigned long)privptr
->p_buff_ccw
,
1928 (int)pages_to_order_of_mag(privptr
->
1930 /* free the write pages */
1931 p_buf
=privptr
->p_buff_write
;
1932 while (p_buf
!=NULL
) {
1934 (unsigned long)p_buf
->p_buffer
,
1935 (int)pages_to_order_of_mag(
1936 privptr
->p_buff_pages_perwrite
));
1939 /* free any read pages already alloc */
1940 p_buf
=privptr
->p_buff_read
;
1941 while (p_buf
!=NULL
) {
1943 (unsigned long)p_buf
->p_buffer
,
1944 (int)pages_to_order_of_mag(
1945 privptr
->p_buff_pages_perread
));
1948 privptr
->p_buff_ccw
=NULL
;
1949 privptr
->p_buff_write
=NULL
;
1952 memset(p_buff
, 0x00, privptr
->p_env
->read_size
);
1953 p_buf
= p_free_chain
;
1954 privptr
->p_buff_read
= p_buf
;
1955 p_free_chain
= p_buf
->next
;
1957 if (p_last_CCWB
==NULL
) {
1963 p_buf
->next
=p_first_CCWB
;
1966 &p_first_CCWB
-> read
);
1970 /* save buff address */
1971 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1972 /* initialize read command */
1973 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
1974 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
1975 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1976 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
1978 /* initialize read_h command */
1979 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
1980 p_buf
-> read_h
.cda
=
1981 (__u32
)__pa(&(p_buf
->header
));
1982 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1983 p_buf
-> read_h
.count
= sizeof(struct clawh
);
1985 /* initialize Signal command */
1986 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
1987 p_buf
-> signal
.cda
=
1988 (__u32
)__pa(&(pClawH
->flag
));
1989 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1990 p_buf
-> signal
.count
= 1;
1992 /* initialize r_TIC_1 command */
1993 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1994 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
1995 p_buf
-> r_TIC_1
.flags
= 0;
1996 p_buf
-> r_TIC_1
.count
= 0;
1998 /* initialize r_read_FF command */
1999 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2000 p_buf
-> r_read_FF
.cda
=
2001 (__u32
)__pa(&(pClawH
->flag
));
2002 p_buf
-> r_read_FF
.flags
=
2003 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
2004 p_buf
-> r_read_FF
.count
= 1;
2006 /* initialize r_TIC_2 */
2007 memcpy(&p_buf
->r_TIC_2
, &p_buf
->r_TIC_1
,
2008 sizeof(struct ccw1
));
2010 /* initialize Header */
2011 p_buf
->header
.length
=0xffff;
2012 p_buf
->header
.opcode
=0xff;
2013 p_buf
->header
.flag
=CLAW_PENDING
;
2015 } /* For read_buffers */
2016 } /* read_size >= PAGE_SIZE */
2017 } /* pBuffread = NULL */
2018 add_claw_reads( dev
,p_first_CCWB
, p_last_CCWB
);
2019 privptr
->buffs_alloc
= 1;
2022 } /* end of init_ccw_bk */
2024 /*-------------------------------------------------------------------*
2028 *--------------------------------------------------------------------*/
2031 probe_error( struct ccwgroup_device
*cgdev
)
2033 struct claw_privbk
*privptr
;
2035 CLAW_DBF_TEXT(4, trace
, "proberr");
2036 privptr
= dev_get_drvdata(&cgdev
->dev
);
2037 if (privptr
!= NULL
) {
2038 dev_set_drvdata(&cgdev
->dev
, NULL
);
2039 kfree(privptr
->p_env
);
2040 kfree(privptr
->p_mtc_envelope
);
2045 /*-------------------------------------------------------------------*
2046 * claw_process_control *
2049 *--------------------------------------------------------------------*/
2052 claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
)
2055 struct clawbuf
*p_buf
;
2056 struct clawctl ctlbk
;
2057 struct clawctl
*p_ctlbk
;
2058 char temp_host_name
[8];
2059 char temp_ws_name
[8];
2060 struct claw_privbk
*privptr
;
2061 struct claw_env
*p_env
;
2062 struct sysval
*p_sysval
;
2063 struct conncmd
*p_connect
=NULL
;
2065 struct chbk
*p_ch
= NULL
;
2066 struct device
*tdev
;
2067 CLAW_DBF_TEXT(2, setup
, "clw_cntl");
2068 udelay(1000); /* Wait a ms for the control packets to
2069 *catch up to each other */
2070 privptr
= dev
->ml_priv
;
2071 p_env
=privptr
->p_env
;
2072 tdev
= &privptr
->channel
[READ_CHANNEL
].cdev
->dev
;
2073 memcpy( &temp_host_name
, p_env
->host_name
, 8);
2074 memcpy( &temp_ws_name
, p_env
->adapter_name
, 8);
2075 dev_info(tdev
, "%s: CLAW device %.8s: "
2076 "Received Control Packet\n",
2077 dev
->name
, temp_ws_name
);
2078 if (privptr
->release_pend
==1) {
2081 p_buf
=p_ccw
->p_buffer
;
2083 if (p_env
->packing
== DO_PACKED
) { /* packing in progress?*/
2084 memcpy(p_ctlbk
, &p_buf
->buffer
[4], sizeof(struct clawctl
));
2086 memcpy(p_ctlbk
, p_buf
, sizeof(struct clawctl
));
2088 switch (p_ctlbk
->command
)
2090 case SYSTEM_VALIDATE_REQUEST
:
2091 if (p_ctlbk
->version
!= CLAW_VERSION_ID
) {
2092 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2093 CLAW_RC_WRONG_VERSION
);
2094 dev_warn(tdev
, "The communication peer of %s"
2095 " uses an incorrect API version %d\n",
2096 dev
->name
, p_ctlbk
->version
);
2098 p_sysval
= (struct sysval
*)&(p_ctlbk
->data
);
2099 dev_info(tdev
, "%s: Recv Sys Validate Request: "
2100 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2102 dev
->name
, p_ctlbk
->version
,
2104 p_ctlbk
->correlator
,
2106 p_sysval
->host_name
);
2107 if (memcmp(temp_host_name
, p_sysval
->host_name
, 8)) {
2108 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2109 CLAW_RC_NAME_MISMATCH
);
2110 CLAW_DBF_TEXT(2, setup
, "HSTBAD");
2111 CLAW_DBF_TEXT_(2, setup
, "%s", p_sysval
->host_name
);
2112 CLAW_DBF_TEXT_(2, setup
, "%s", temp_host_name
);
2114 "Host name %s for %s does not match the"
2115 " remote adapter name %s\n",
2116 p_sysval
->host_name
,
2120 if (memcmp(temp_ws_name
, p_sysval
->WS_name
, 8)) {
2121 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2122 CLAW_RC_NAME_MISMATCH
);
2123 CLAW_DBF_TEXT(2, setup
, "WSNBAD");
2124 CLAW_DBF_TEXT_(2, setup
, "%s", p_sysval
->WS_name
);
2125 CLAW_DBF_TEXT_(2, setup
, "%s", temp_ws_name
);
2126 dev_warn(tdev
, "Adapter name %s for %s does not match"
2127 " the remote host name %s\n",
2132 if ((p_sysval
->write_frame_size
< p_env
->write_size
) &&
2133 (p_env
->packing
== 0)) {
2134 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2135 CLAW_RC_HOST_RCV_TOO_SMALL
);
2137 "The local write buffer is smaller than the"
2138 " remote read buffer\n");
2139 CLAW_DBF_TEXT(2, setup
, "wrtszbad");
2141 if ((p_sysval
->read_frame_size
< p_env
->read_size
) &&
2142 (p_env
->packing
== 0)) {
2143 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2144 CLAW_RC_HOST_RCV_TOO_SMALL
);
2146 "The local read buffer is smaller than the"
2147 " remote write buffer\n");
2148 CLAW_DBF_TEXT(2, setup
, "rdsizbad");
2150 claw_snd_sys_validate_rsp(dev
, p_ctlbk
, 0);
2152 "CLAW device %.8s: System validate"
2153 " completed.\n", temp_ws_name
);
2155 "%s: sys Validate Rsize:%d Wsize:%d\n",
2156 dev
->name
, p_sysval
->read_frame_size
,
2157 p_sysval
->write_frame_size
);
2158 privptr
->system_validate_comp
= 1;
2159 if (strncmp(p_env
->api_type
, WS_APPL_NAME_PACKED
, 6) == 0)
2160 p_env
->packing
= PACKING_ASK
;
2161 claw_strt_conn_req(dev
);
2163 case SYSTEM_VALIDATE_RESPONSE
:
2164 p_sysval
= (struct sysval
*)&(p_ctlbk
->data
);
2166 "Settings for %s validated (version=%d, "
2167 "remote device=%d, rc=%d, adapter name=%.8s, "
2168 "host name=%.8s)\n",
2171 p_ctlbk
->correlator
,
2174 p_sysval
->host_name
);
2175 switch (p_ctlbk
->rc
) {
2177 dev_info(tdev
, "%s: CLAW device "
2178 "%.8s: System validate completed.\n",
2179 dev
->name
, temp_ws_name
);
2180 if (privptr
->system_validate_comp
== 0)
2181 claw_strt_conn_req(dev
);
2182 privptr
->system_validate_comp
= 1;
2184 case CLAW_RC_NAME_MISMATCH
:
2185 dev_warn(tdev
, "Validating %s failed because of"
2186 " a host or adapter name mismatch\n",
2189 case CLAW_RC_WRONG_VERSION
:
2190 dev_warn(tdev
, "Validating %s failed because of a"
2191 " version conflict\n",
2194 case CLAW_RC_HOST_RCV_TOO_SMALL
:
2195 dev_warn(tdev
, "Validating %s failed because of a"
2196 " frame size conflict\n",
2200 dev_warn(tdev
, "The communication peer of %s rejected"
2201 " the connection\n",
2207 case CONNECTION_REQUEST
:
2208 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2209 dev_info(tdev
, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2210 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2214 p_ctlbk
->correlator
,
2215 p_connect
->host_name
,
2216 p_connect
->WS_name
);
2217 if (privptr
->active_link_ID
!= 0) {
2218 claw_snd_disc(dev
, p_ctlbk
);
2219 dev_info(tdev
, "%s rejected a connection request"
2220 " because it is already active\n",
2223 if (p_ctlbk
->linkid
!= 1) {
2224 claw_snd_disc(dev
, p_ctlbk
);
2225 dev_info(tdev
, "%s rejected a request to open multiple"
2229 rc
= find_link(dev
, p_connect
->host_name
, p_connect
->WS_name
);
2231 claw_snd_disc(dev
, p_ctlbk
);
2232 dev_info(tdev
, "%s rejected a connection request"
2233 " because of a type mismatch\n",
2236 claw_send_control(dev
,
2237 CONNECTION_CONFIRM
, p_ctlbk
->linkid
,
2238 p_ctlbk
->correlator
,
2239 0, p_connect
->host_name
,
2240 p_connect
->WS_name
);
2241 if (p_env
->packing
== PACKING_ASK
) {
2242 p_env
->packing
= PACK_SEND
;
2243 claw_snd_conn_req(dev
, 0);
2245 dev_info(tdev
, "%s: CLAW device %.8s: Connection "
2246 "completed link_id=%d.\n",
2247 dev
->name
, temp_ws_name
,
2249 privptr
->active_link_ID
= p_ctlbk
->linkid
;
2250 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
2251 wake_up(&p_ch
->wait
); /* wake up claw_open ( WRITE) */
2253 case CONNECTION_RESPONSE
:
2254 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2255 dev_info(tdev
, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
2256 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2260 p_ctlbk
->correlator
,
2262 p_connect
->host_name
,
2263 p_connect
->WS_name
);
2265 if (p_ctlbk
->rc
!= 0) {
2266 dev_warn(tdev
, "The communication peer of %s rejected"
2267 " a connection request\n",
2272 p_connect
->host_name
, p_connect
->WS_name
);
2274 claw_snd_disc(dev
, p_ctlbk
);
2275 dev_warn(tdev
, "The communication peer of %s"
2276 " rejected a connection "
2277 "request because of a type mismatch\n",
2280 /* should be until CONNECTION_CONFIRM */
2281 privptr
->active_link_ID
= -(p_ctlbk
->linkid
);
2283 case CONNECTION_CONFIRM
:
2284 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2286 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2287 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2291 p_ctlbk
->correlator
,
2292 p_connect
->host_name
,
2293 p_connect
->WS_name
);
2294 if (p_ctlbk
->linkid
== -(privptr
->active_link_ID
)) {
2295 privptr
->active_link_ID
= p_ctlbk
->linkid
;
2296 if (p_env
->packing
> PACKING_ASK
) {
2298 "%s: Confirmed Now packing\n", dev
->name
);
2299 p_env
->packing
= DO_PACKED
;
2301 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
2302 wake_up(&p_ch
->wait
);
2304 dev_warn(tdev
, "Activating %s failed because of"
2305 " an incorrect link ID=%d\n",
2306 dev
->name
, p_ctlbk
->linkid
);
2307 claw_snd_disc(dev
, p_ctlbk
);
2311 dev_info(tdev
, "%s: Disconnect: "
2312 "Vers=%d,link_id=%d,Corr=%d\n",
2313 dev
->name
, p_ctlbk
->version
,
2314 p_ctlbk
->linkid
, p_ctlbk
->correlator
);
2315 if ((p_ctlbk
->linkid
== 2) &&
2316 (p_env
->packing
== PACK_SEND
)) {
2317 privptr
->active_link_ID
= 1;
2318 p_env
->packing
= DO_PACKED
;
2320 privptr
->active_link_ID
= 0;
2323 dev_warn(tdev
, "The communication peer of %s failed\n",
2327 dev_warn(tdev
, "The communication peer of %s sent"
2328 " an unknown command code\n",
2334 } /* end of claw_process_control */
2337 /*-------------------------------------------------------------------*
2338 * claw_send_control *
2340 *--------------------------------------------------------------------*/
2343 claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
2344 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
)
2346 struct claw_privbk
*privptr
;
2347 struct clawctl
*p_ctl
;
2348 struct sysval
*p_sysval
;
2349 struct conncmd
*p_connect
;
2350 struct sk_buff
*skb
;
2352 CLAW_DBF_TEXT(2, setup
, "sndcntl");
2353 privptr
= dev
->ml_priv
;
2354 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
2356 p_ctl
->command
=type
;
2357 p_ctl
->version
=CLAW_VERSION_ID
;
2359 p_ctl
->correlator
=correlator
;
2362 p_sysval
=(struct sysval
*)&p_ctl
->data
;
2363 p_connect
=(struct conncmd
*)&p_ctl
->data
;
2365 switch (p_ctl
->command
) {
2366 case SYSTEM_VALIDATE_REQUEST
:
2367 case SYSTEM_VALIDATE_RESPONSE
:
2368 memcpy(&p_sysval
->host_name
, local_name
, 8);
2369 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
2370 if (privptr
->p_env
->packing
> 0) {
2371 p_sysval
->read_frame_size
= DEF_PACK_BUFSIZE
;
2372 p_sysval
->write_frame_size
= DEF_PACK_BUFSIZE
;
2374 /* how big is the biggest group of packets */
2375 p_sysval
->read_frame_size
=
2376 privptr
->p_env
->read_size
;
2377 p_sysval
->write_frame_size
=
2378 privptr
->p_env
->write_size
;
2380 memset(&p_sysval
->reserved
, 0x00, 4);
2382 case CONNECTION_REQUEST
:
2383 case CONNECTION_RESPONSE
:
2384 case CONNECTION_CONFIRM
:
2386 memcpy(&p_sysval
->host_name
, local_name
, 8);
2387 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
2388 if (privptr
->p_env
->packing
> 0) {
2389 /* How big is the biggest packet */
2390 p_connect
->reserved1
[0]=CLAW_FRAME_SIZE
;
2391 p_connect
->reserved1
[1]=CLAW_FRAME_SIZE
;
2393 memset(&p_connect
->reserved1
, 0x00, 4);
2394 memset(&p_connect
->reserved2
, 0x00, 4);
2401 /* write Control Record to the device */
2404 skb
= dev_alloc_skb(sizeof(struct clawctl
));
2408 memcpy(skb_put(skb
, sizeof(struct clawctl
)),
2409 p_ctl
, sizeof(struct clawctl
));
2410 if (privptr
->p_env
->packing
>= PACK_SEND
)
2411 claw_hw_tx(skb
, dev
, 1);
2413 claw_hw_tx(skb
, dev
, 0);
2415 } /* end of claw_send_control */
2417 /*-------------------------------------------------------------------*
2418 * claw_snd_conn_req *
2420 *--------------------------------------------------------------------*/
2422 claw_snd_conn_req(struct net_device
*dev
, __u8 link
)
2425 struct claw_privbk
*privptr
= dev
->ml_priv
;
2426 struct clawctl
*p_ctl
;
2428 CLAW_DBF_TEXT(2, setup
, "snd_conn");
2430 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
2431 p_ctl
->linkid
= link
;
2432 if ( privptr
->system_validate_comp
==0x00 ) {
2435 if (privptr
->p_env
->packing
== PACKING_ASK
)
2436 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2437 WS_APPL_NAME_PACKED
, WS_APPL_NAME_PACKED
);
2438 if (privptr
->p_env
->packing
== PACK_SEND
) {
2439 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2440 WS_APPL_NAME_IP_NAME
, WS_APPL_NAME_IP_NAME
);
2442 if (privptr
->p_env
->packing
== 0)
2443 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2444 HOST_APPL_NAME
, privptr
->p_env
->api_type
);
2447 } /* end of claw_snd_conn_req */
2450 /*-------------------------------------------------------------------*
2453 *--------------------------------------------------------------------*/
2456 claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
)
2459 struct conncmd
* p_connect
;
2461 CLAW_DBF_TEXT(2, setup
, "snd_dsc");
2462 p_connect
=(struct conncmd
*)&p_ctl
->data
;
2464 rc
=claw_send_control(dev
, DISCONNECT
, p_ctl
->linkid
,
2465 p_ctl
->correlator
, 0,
2466 p_connect
->host_name
, p_connect
->WS_name
);
2468 } /* end of claw_snd_disc */
2471 /*-------------------------------------------------------------------*
2472 * claw_snd_sys_validate_rsp *
2474 *--------------------------------------------------------------------*/
2477 claw_snd_sys_validate_rsp(struct net_device
*dev
,
2478 struct clawctl
*p_ctl
, __u32 return_code
)
2480 struct claw_env
* p_env
;
2481 struct claw_privbk
*privptr
;
2484 CLAW_DBF_TEXT(2, setup
, "chkresp");
2485 privptr
= dev
->ml_priv
;
2486 p_env
=privptr
->p_env
;
2487 rc
=claw_send_control(dev
, SYSTEM_VALIDATE_RESPONSE
,
2492 p_env
->adapter_name
);
2494 } /* end of claw_snd_sys_validate_rsp */
2496 /*-------------------------------------------------------------------*
2497 * claw_strt_conn_req *
2499 *--------------------------------------------------------------------*/
2502 claw_strt_conn_req(struct net_device
*dev
)
2506 CLAW_DBF_TEXT(2, setup
, "conn_req");
2507 rc
=claw_snd_conn_req(dev
, 1);
2509 } /* end of claw_strt_conn_req */
2513 /*-------------------------------------------------------------------*
2515 *-------------------------------------------------------------------*/
2518 net_device_stats
*claw_stats(struct net_device
*dev
)
2520 struct claw_privbk
*privptr
;
2522 CLAW_DBF_TEXT(4, trace
, "stats");
2523 privptr
= dev
->ml_priv
;
2524 return &privptr
->stats
;
2525 } /* end of claw_stats */
2528 /*-------------------------------------------------------------------*
2531 *--------------------------------------------------------------------*/
2533 unpack_read(struct net_device
*dev
)
2535 struct sk_buff
*skb
;
2536 struct claw_privbk
*privptr
;
2537 struct claw_env
*p_env
;
2538 struct ccwbk
*p_this_ccw
;
2539 struct ccwbk
*p_first_ccw
;
2540 struct ccwbk
*p_last_ccw
;
2541 struct clawph
*p_packh
;
2543 struct clawctl
*p_ctlrec
=NULL
;
2544 struct device
*p_dev
;
2549 __u8 mtc_this_frm
=0;
2554 CLAW_DBF_TEXT(4, trace
, "unpkread");
2559 privptr
= dev
->ml_priv
;
2561 p_dev
= &privptr
->channel
[READ_CHANNEL
].cdev
->dev
;
2562 p_env
= privptr
->p_env
;
2563 p_this_ccw
=privptr
->p_read_active_first
;
2564 while (p_this_ccw
!=NULL
&& p_this_ccw
->header
.flag
!=CLAW_PENDING
) {
2567 p_this_ccw
->header
.flag
=CLAW_PENDING
;
2568 privptr
->p_read_active_first
=p_this_ccw
->next
;
2569 p_this_ccw
->next
=NULL
;
2570 p_packh
= (struct clawph
*)p_this_ccw
->p_buffer
;
2571 if ((p_env
->packing
== PACK_SEND
) &&
2572 (p_packh
->len
== 32) &&
2573 (p_packh
->link_num
== 0)) { /* is it a packed ctl rec? */
2574 p_packh
++; /* peek past pack header */
2575 p_ctlrec
= (struct clawctl
*)p_packh
;
2576 p_packh
--; /* un peek */
2577 if ((p_ctlrec
->command
== CONNECTION_RESPONSE
) ||
2578 (p_ctlrec
->command
== CONNECTION_CONFIRM
))
2579 p_env
->packing
= DO_PACKED
;
2581 if (p_env
->packing
== DO_PACKED
)
2582 link_num
=p_packh
->link_num
;
2584 link_num
=p_this_ccw
->header
.opcode
/ 8;
2585 if ((p_this_ccw
->header
.opcode
& MORE_to_COME_FLAG
)!=0) {
2587 if (p_this_ccw
->header
.length
!=
2588 privptr
->p_env
->read_size
) {
2590 "The communication peer of %s"
2592 " frame of length %02x\n",
2593 dev
->name
, p_this_ccw
->header
.length
);
2597 if (privptr
->mtc_skipping
) {
2599 * We're in the mode of skipping past a
2600 * multi-frame message
2601 * that we can't process for some reason or other.
2602 * The first frame without the More-To-Come flag is
2603 * the last frame of the skipped message.
2605 /* in case of More-To-Come not set in this frame */
2606 if (mtc_this_frm
==0) {
2607 privptr
->mtc_skipping
=0; /* Ok, the end */
2608 privptr
->mtc_logical_link
=-1;
2614 claw_process_control(dev
, p_this_ccw
);
2615 CLAW_DBF_TEXT(4, trace
, "UnpkCntl");
2619 if (p_env
->packing
== DO_PACKED
) {
2620 if (pack_off
> p_env
->read_size
)
2622 p_packd
= p_this_ccw
->p_buffer
+pack_off
;
2623 p_packh
= (struct clawph
*) p_packd
;
2624 if ((p_packh
->len
== 0) || /* done with this frame? */
2625 (p_packh
->flag
!= 0))
2627 bytes_to_mov
= p_packh
->len
;
2628 pack_off
+= bytes_to_mov
+sizeof(struct clawph
);
2631 bytes_to_mov
=p_this_ccw
->header
.length
;
2633 if (privptr
->mtc_logical_link
<0) {
2636 * if More-To-Come is set in this frame then we don't know
2637 * length of entire message, and hence have to allocate
2640 /* We are starting a new envelope */
2641 privptr
->mtc_offset
=0;
2642 privptr
->mtc_logical_link
=link_num
;
2645 if (bytes_to_mov
> (MAX_ENVELOPE_SIZE
- privptr
->mtc_offset
) ) {
2647 privptr
->stats
.rx_frame_errors
++;
2650 if (p_env
->packing
== DO_PACKED
) {
2651 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
2652 p_packd
+sizeof(struct clawph
), bytes_to_mov
);
2655 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
2656 p_this_ccw
->p_buffer
, bytes_to_mov
);
2658 if (mtc_this_frm
==0) {
2659 len_of_data
=privptr
->mtc_offset
+bytes_to_mov
;
2660 skb
=dev_alloc_skb(len_of_data
);
2662 memcpy(skb_put(skb
,len_of_data
),
2663 privptr
->p_mtc_envelope
,
2666 skb_reset_mac_header(skb
);
2667 skb
->protocol
=htons(ETH_P_IP
);
2668 skb
->ip_summed
=CHECKSUM_UNNECESSARY
;
2669 privptr
->stats
.rx_packets
++;
2670 privptr
->stats
.rx_bytes
+=len_of_data
;
2674 dev_info(p_dev
, "Allocating a buffer for"
2675 " incoming data failed\n");
2676 privptr
->stats
.rx_dropped
++;
2678 privptr
->mtc_offset
=0;
2679 privptr
->mtc_logical_link
=-1;
2682 privptr
->mtc_offset
+=bytes_to_mov
;
2684 if (p_env
->packing
== DO_PACKED
)
2688 * Remove ThisCCWblock from active read queue, and add it
2689 * to queue of free blocks to be reused.
2692 p_this_ccw
->header
.length
=0xffff;
2693 p_this_ccw
->header
.opcode
=0xff;
2695 * add this one to the free queue for later reuse
2697 if (p_first_ccw
==NULL
) {
2698 p_first_ccw
= p_this_ccw
;
2701 p_last_ccw
->next
= p_this_ccw
;
2703 p_last_ccw
= p_this_ccw
;
2705 * chain to next block on active read queue
2707 p_this_ccw
= privptr
->p_read_active_first
;
2708 CLAW_DBF_TEXT_(4, trace
, "rxpkt %d", p
);
2709 } /* end of while */
2711 /* check validity */
2713 CLAW_DBF_TEXT_(4, trace
, "rxfrm %d", i
);
2714 add_claw_reads(dev
, p_first_ccw
, p_last_ccw
);
2715 claw_strt_read(dev
, LOCK_YES
);
2717 } /* end of unpack_read */
2719 /*-------------------------------------------------------------------*
2722 *--------------------------------------------------------------------*/
2724 claw_strt_read (struct net_device
*dev
, int lock
)
2728 unsigned long saveflags
= 0;
2729 struct claw_privbk
*privptr
= dev
->ml_priv
;
2730 struct ccwbk
*p_ccwbk
;
2732 struct clawh
*p_clawh
;
2733 p_ch
= &privptr
->channel
[READ_CHANNEL
];
2735 CLAW_DBF_TEXT(4, trace
, "StRdNter");
2736 p_clawh
=(struct clawh
*)privptr
->p_claw_signal_blk
;
2737 p_clawh
->flag
=CLAW_IDLE
; /* 0x00 */
2739 if ((privptr
->p_write_active_first
!=NULL
&&
2740 privptr
->p_write_active_first
->header
.flag
!=CLAW_PENDING
) ||
2741 (privptr
->p_read_active_first
!=NULL
&&
2742 privptr
->p_read_active_first
->header
.flag
!=CLAW_PENDING
)) {
2743 p_clawh
->flag
=CLAW_BUSY
; /* 0xff */
2745 if (lock
==LOCK_YES
) {
2746 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
2748 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
2749 CLAW_DBF_TEXT(4, trace
, "HotRead");
2750 p_ccwbk
=privptr
->p_read_active_first
;
2751 parm
= (unsigned long) p_ch
;
2752 rc
= ccw_device_start (p_ch
->cdev
, &p_ccwbk
->read
, parm
,
2755 ccw_check_return_code(p_ch
->cdev
, rc
);
2759 CLAW_DBF_TEXT(2, trace
, "ReadAct");
2762 if (lock
==LOCK_YES
) {
2763 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
2765 CLAW_DBF_TEXT(4, trace
, "StRdExit");
2767 } /* end of claw_strt_read */
2769 /*-------------------------------------------------------------------*
2770 * claw_strt_out_IO *
2772 *--------------------------------------------------------------------*/
2775 claw_strt_out_IO( struct net_device
*dev
)
2779 struct claw_privbk
*privptr
;
2781 struct ccwbk
*p_first_ccw
;
2786 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
2787 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
2789 CLAW_DBF_TEXT(4, trace
, "strt_io");
2790 p_first_ccw
=privptr
->p_write_active_first
;
2792 if (p_ch
->claw_state
== CLAW_STOP
)
2794 if (p_first_ccw
== NULL
) {
2797 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
2798 parm
= (unsigned long) p_ch
;
2799 CLAW_DBF_TEXT(2, trace
, "StWrtIO");
2800 rc
= ccw_device_start(p_ch
->cdev
, &p_first_ccw
->write
, parm
,
2803 ccw_check_return_code(p_ch
->cdev
, rc
);
2806 dev
->trans_start
= jiffies
;
2808 } /* end of claw_strt_out_IO */
2810 /*-------------------------------------------------------------------*
2811 * Free write buffers *
2813 *--------------------------------------------------------------------*/
2816 claw_free_wrt_buf( struct net_device
*dev
)
2819 struct claw_privbk
*privptr
= (struct claw_privbk
*)dev
->ml_priv
;
2820 struct ccwbk
*p_first_ccw
;
2821 struct ccwbk
*p_last_ccw
;
2822 struct ccwbk
*p_this_ccw
;
2823 struct ccwbk
*p_next_ccw
;
2825 CLAW_DBF_TEXT(4, trace
, "freewrtb");
2826 /* scan the write queue to free any completed write packets */
2829 p_this_ccw
=privptr
->p_write_active_first
;
2830 while ( (p_this_ccw
!=NULL
) && (p_this_ccw
->header
.flag
!=CLAW_PENDING
))
2832 p_next_ccw
= p_this_ccw
->next
;
2833 if (((p_next_ccw
!=NULL
) &&
2834 (p_next_ccw
->header
.flag
!=CLAW_PENDING
)) ||
2835 ((p_this_ccw
== privptr
->p_write_active_last
) &&
2836 (p_this_ccw
->header
.flag
!=CLAW_PENDING
))) {
2837 /* The next CCW is OK or this is */
2838 /* the last CCW...free it @A1A */
2839 privptr
->p_write_active_first
=p_this_ccw
->next
;
2840 p_this_ccw
->header
.flag
=CLAW_PENDING
;
2841 p_this_ccw
->next
=privptr
->p_write_free_chain
;
2842 privptr
->p_write_free_chain
=p_this_ccw
;
2843 ++privptr
->write_free_count
;
2844 privptr
->stats
.tx_bytes
+= p_this_ccw
->write
.count
;
2845 p_this_ccw
=privptr
->p_write_active_first
;
2846 privptr
->stats
.tx_packets
++;
2852 if (privptr
->write_free_count
!=0) {
2853 claw_clearbit_busy(TB_NOBUFFER
,dev
);
2855 /* whole chain removed? */
2856 if (privptr
->p_write_active_first
==NULL
) {
2857 privptr
->p_write_active_last
=NULL
;
2859 CLAW_DBF_TEXT_(4, trace
, "FWC=%d", privptr
->write_free_count
);
2863 /*-------------------------------------------------------------------*
2864 * claw free netdevice *
2866 *--------------------------------------------------------------------*/
2868 claw_free_netdevice(struct net_device
* dev
, int free_dev
)
2870 struct claw_privbk
*privptr
;
2872 CLAW_DBF_TEXT(2, setup
, "free_dev");
2875 CLAW_DBF_TEXT_(2, setup
, "%s", dev
->name
);
2876 privptr
= dev
->ml_priv
;
2877 if (dev
->flags
& IFF_RUNNING
)
2880 privptr
->channel
[READ_CHANNEL
].ndev
= NULL
; /* say it's free */
2882 dev
->ml_priv
= NULL
;
2888 CLAW_DBF_TEXT(2, setup
, "free_ok");
2892 * Claw init netdevice
2893 * Initialize everything of the net device except the name and the
2896 static const struct net_device_ops claw_netdev_ops
= {
2897 .ndo_open
= claw_open
,
2898 .ndo_stop
= claw_release
,
2899 .ndo_get_stats
= claw_stats
,
2900 .ndo_start_xmit
= claw_tx
,
2901 .ndo_change_mtu
= claw_change_mtu
,
2905 claw_init_netdevice(struct net_device
* dev
)
2907 CLAW_DBF_TEXT(2, setup
, "init_dev");
2908 CLAW_DBF_TEXT_(2, setup
, "%s", dev
->name
);
2909 dev
->mtu
= CLAW_DEFAULT_MTU_SIZE
;
2910 dev
->hard_header_len
= 0;
2912 dev
->type
= ARPHRD_SLIP
;
2913 dev
->tx_queue_len
= 1300;
2914 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
2915 dev
->netdev_ops
= &claw_netdev_ops
;
2916 CLAW_DBF_TEXT(2, setup
, "initok");
2921 * Init a new channel in the privptr->channel[i].
2923 * @param cdev The ccw_device to be added.
2925 * @return 0 on success, !0 on error.
2928 add_channel(struct ccw_device
*cdev
,int i
,struct claw_privbk
*privptr
)
2931 struct ccw_dev_id dev_id
;
2933 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cdev
->dev
));
2934 privptr
->channel
[i
].flag
= i
+1; /* Read is 1 Write is 2 */
2935 p_ch
= &privptr
->channel
[i
];
2937 snprintf(p_ch
->id
, CLAW_ID_SIZE
, "cl-%s", dev_name(&cdev
->dev
));
2938 ccw_device_get_id(cdev
, &dev_id
);
2939 p_ch
->devno
= dev_id
.devno
;
2940 if ((p_ch
->irb
= kzalloc(sizeof (struct irb
),GFP_KERNEL
)) == NULL
) {
2949 * Setup an interface.
2951 * @param cgdev Device to be setup.
2953 * @returns 0 on success, !0 on failure.
2956 claw_new_device(struct ccwgroup_device
*cgdev
)
2958 struct claw_privbk
*privptr
;
2959 struct claw_env
*p_env
;
2960 struct net_device
*dev
;
2962 struct ccw_dev_id dev_id
;
2964 dev_info(&cgdev
->dev
, "add for %s\n",
2965 dev_name(&cgdev
->cdev
[READ_CHANNEL
]->dev
));
2966 CLAW_DBF_TEXT(2, setup
, "new_dev");
2967 privptr
= dev_get_drvdata(&cgdev
->dev
);
2968 dev_set_drvdata(&cgdev
->cdev
[READ_CHANNEL
]->dev
, privptr
);
2969 dev_set_drvdata(&cgdev
->cdev
[WRITE_CHANNEL
]->dev
, privptr
);
2972 p_env
= privptr
->p_env
;
2973 ccw_device_get_id(cgdev
->cdev
[READ_CHANNEL
], &dev_id
);
2974 p_env
->devno
[READ_CHANNEL
] = dev_id
.devno
;
2975 ccw_device_get_id(cgdev
->cdev
[WRITE_CHANNEL
], &dev_id
);
2976 p_env
->devno
[WRITE_CHANNEL
] = dev_id
.devno
;
2977 ret
= add_channel(cgdev
->cdev
[0],0,privptr
);
2979 ret
= add_channel(cgdev
->cdev
[1],1,privptr
);
2981 dev_warn(&cgdev
->dev
, "Creating a CLAW group device"
2982 " failed with error code %d\n", ret
);
2985 ret
= ccw_device_set_online(cgdev
->cdev
[READ_CHANNEL
]);
2987 dev_warn(&cgdev
->dev
,
2988 "Setting the read subchannel online"
2989 " failed with error code %d\n", ret
);
2992 ret
= ccw_device_set_online(cgdev
->cdev
[WRITE_CHANNEL
]);
2994 dev_warn(&cgdev
->dev
,
2995 "Setting the write subchannel online "
2996 "failed with error code %d\n", ret
);
2999 dev
= alloc_netdev(0,"claw%d",claw_init_netdevice
);
3001 dev_warn(&cgdev
->dev
,
3002 "Activating the CLAW device failed\n");
3005 dev
->ml_priv
= privptr
;
3006 dev_set_drvdata(&cgdev
->dev
, privptr
);
3007 dev_set_drvdata(&cgdev
->cdev
[READ_CHANNEL
]->dev
, privptr
);
3008 dev_set_drvdata(&cgdev
->cdev
[WRITE_CHANNEL
]->dev
, privptr
);
3010 SET_NETDEV_DEV(dev
, &cgdev
->dev
);
3011 if (register_netdev(dev
) != 0) {
3012 claw_free_netdevice(dev
, 1);
3013 CLAW_DBF_TEXT(2, trace
, "regfail");
3016 dev
->flags
&=~IFF_RUNNING
;
3017 if (privptr
->buffs_alloc
== 0) {
3018 ret
=init_ccw_bk(dev
);
3020 unregister_netdev(dev
);
3021 claw_free_netdevice(dev
,1);
3022 CLAW_DBF_TEXT(2, trace
, "ccwmem");
3026 privptr
->channel
[READ_CHANNEL
].ndev
= dev
;
3027 privptr
->channel
[WRITE_CHANNEL
].ndev
= dev
;
3028 privptr
->p_env
->ndev
= dev
;
3030 dev_info(&cgdev
->dev
, "%s:readsize=%d writesize=%d "
3031 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3032 dev
->name
, p_env
->read_size
,
3033 p_env
->write_size
, p_env
->read_buffers
,
3034 p_env
->write_buffers
, p_env
->devno
[READ_CHANNEL
],
3035 p_env
->devno
[WRITE_CHANNEL
]);
3036 dev_info(&cgdev
->dev
, "%s:host_name:%.8s, adapter_name "
3037 ":%.8s api_type: %.8s\n",
3038 dev
->name
, p_env
->host_name
,
3039 p_env
->adapter_name
, p_env
->api_type
);
3042 ccw_device_set_offline(cgdev
->cdev
[1]);
3043 ccw_device_set_offline(cgdev
->cdev
[0]);
3048 claw_purge_skb_queue(struct sk_buff_head
*q
)
3050 struct sk_buff
*skb
;
3052 CLAW_DBF_TEXT(4, trace
, "purgque");
3053 while ((skb
= skb_dequeue(q
))) {
3054 atomic_dec(&skb
->users
);
3055 dev_kfree_skb_any(skb
);
3060 * Shutdown an interface.
3062 * @param cgdev Device to be shut down.
3064 * @returns 0 on success, !0 on failure.
3067 claw_shutdown_device(struct ccwgroup_device
*cgdev
)
3069 struct claw_privbk
*priv
;
3070 struct net_device
*ndev
;
3073 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cgdev
->dev
));
3074 priv
= dev_get_drvdata(&cgdev
->dev
);
3077 ndev
= priv
->channel
[READ_CHANNEL
].ndev
;
3079 /* Close the device */
3080 dev_info(&cgdev
->dev
, "%s: shutting down\n",
3082 if (ndev
->flags
& IFF_RUNNING
)
3083 ret
= claw_release(ndev
);
3084 ndev
->flags
&=~IFF_RUNNING
;
3085 unregister_netdev(ndev
);
3086 ndev
->ml_priv
= NULL
; /* cgdev data, not ndev's to free */
3087 claw_free_netdevice(ndev
, 1);
3088 priv
->channel
[READ_CHANNEL
].ndev
= NULL
;
3089 priv
->channel
[WRITE_CHANNEL
].ndev
= NULL
;
3090 priv
->p_env
->ndev
= NULL
;
3092 ccw_device_set_offline(cgdev
->cdev
[1]);
3093 ccw_device_set_offline(cgdev
->cdev
[0]);
3098 claw_remove_device(struct ccwgroup_device
*cgdev
)
3100 struct claw_privbk
*priv
;
3103 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cgdev
->dev
));
3104 priv
= dev_get_drvdata(&cgdev
->dev
);
3106 dev_info(&cgdev
->dev
, " will be removed.\n");
3107 if (cgdev
->state
== CCWGROUP_ONLINE
)
3108 claw_shutdown_device(cgdev
);
3109 claw_remove_files(&cgdev
->dev
);
3110 kfree(priv
->p_mtc_envelope
);
3111 priv
->p_mtc_envelope
=NULL
;
3114 kfree(priv
->channel
[0].irb
);
3115 priv
->channel
[0].irb
=NULL
;
3116 kfree(priv
->channel
[1].irb
);
3117 priv
->channel
[1].irb
=NULL
;
3119 dev_set_drvdata(&cgdev
->dev
, NULL
);
3120 dev_set_drvdata(&cgdev
->cdev
[READ_CHANNEL
]->dev
, NULL
);
3121 dev_set_drvdata(&cgdev
->cdev
[WRITE_CHANNEL
]->dev
, NULL
);
3122 put_device(&cgdev
->dev
);
3132 claw_hname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3134 struct claw_privbk
*priv
;
3135 struct claw_env
* p_env
;
3137 priv
= dev_get_drvdata(dev
);
3140 p_env
= priv
->p_env
;
3141 return sprintf(buf
, "%s\n",p_env
->host_name
);
3145 claw_hname_write(struct device
*dev
, struct device_attribute
*attr
,
3146 const char *buf
, size_t count
)
3148 struct claw_privbk
*priv
;
3149 struct claw_env
* p_env
;
3151 priv
= dev_get_drvdata(dev
);
3154 p_env
= priv
->p_env
;
3155 if (count
> MAX_NAME_LEN
+1)
3157 memset(p_env
->host_name
, 0x20, MAX_NAME_LEN
);
3158 strncpy(p_env
->host_name
,buf
, count
);
3159 p_env
->host_name
[count
-1] = 0x20; /* clear extra 0x0a */
3160 p_env
->host_name
[MAX_NAME_LEN
] = 0x00;
3161 CLAW_DBF_TEXT(2, setup
, "HstnSet");
3162 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->host_name
);
3167 static DEVICE_ATTR(host_name
, 0644, claw_hname_show
, claw_hname_write
);
3170 claw_adname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3172 struct claw_privbk
*priv
;
3173 struct claw_env
* p_env
;
3175 priv
= dev_get_drvdata(dev
);
3178 p_env
= priv
->p_env
;
3179 return sprintf(buf
, "%s\n", p_env
->adapter_name
);
3183 claw_adname_write(struct device
*dev
, struct device_attribute
*attr
,
3184 const char *buf
, size_t count
)
3186 struct claw_privbk
*priv
;
3187 struct claw_env
* p_env
;
3189 priv
= dev_get_drvdata(dev
);
3192 p_env
= priv
->p_env
;
3193 if (count
> MAX_NAME_LEN
+1)
3195 memset(p_env
->adapter_name
, 0x20, MAX_NAME_LEN
);
3196 strncpy(p_env
->adapter_name
,buf
, count
);
3197 p_env
->adapter_name
[count
-1] = 0x20; /* clear extra 0x0a */
3198 p_env
->adapter_name
[MAX_NAME_LEN
] = 0x00;
3199 CLAW_DBF_TEXT(2, setup
, "AdnSet");
3200 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->adapter_name
);
3205 static DEVICE_ATTR(adapter_name
, 0644, claw_adname_show
, claw_adname_write
);
3208 claw_apname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3210 struct claw_privbk
*priv
;
3211 struct claw_env
* p_env
;
3213 priv
= dev_get_drvdata(dev
);
3216 p_env
= priv
->p_env
;
3217 return sprintf(buf
, "%s\n",
3222 claw_apname_write(struct device
*dev
, struct device_attribute
*attr
,
3223 const char *buf
, size_t count
)
3225 struct claw_privbk
*priv
;
3226 struct claw_env
* p_env
;
3228 priv
= dev_get_drvdata(dev
);
3231 p_env
= priv
->p_env
;
3232 if (count
> MAX_NAME_LEN
+1)
3234 memset(p_env
->api_type
, 0x20, MAX_NAME_LEN
);
3235 strncpy(p_env
->api_type
,buf
, count
);
3236 p_env
->api_type
[count
-1] = 0x20; /* we get a loose 0x0a */
3237 p_env
->api_type
[MAX_NAME_LEN
] = 0x00;
3238 if(strncmp(p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
3239 p_env
->read_size
=DEF_PACK_BUFSIZE
;
3240 p_env
->write_size
=DEF_PACK_BUFSIZE
;
3241 p_env
->packing
=PACKING_ASK
;
3242 CLAW_DBF_TEXT(2, setup
, "PACKING");
3246 p_env
->read_size
=CLAW_FRAME_SIZE
;
3247 p_env
->write_size
=CLAW_FRAME_SIZE
;
3248 CLAW_DBF_TEXT(2, setup
, "ApiSet");
3250 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->api_type
);
3254 static DEVICE_ATTR(api_type
, 0644, claw_apname_show
, claw_apname_write
);
3257 claw_wbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3259 struct claw_privbk
*priv
;
3260 struct claw_env
* p_env
;
3262 priv
= dev_get_drvdata(dev
);
3265 p_env
= priv
->p_env
;
3266 return sprintf(buf
, "%d\n", p_env
->write_buffers
);
3270 claw_wbuff_write(struct device
*dev
, struct device_attribute
*attr
,
3271 const char *buf
, size_t count
)
3273 struct claw_privbk
*priv
;
3274 struct claw_env
* p_env
;
3277 priv
= dev_get_drvdata(dev
);
3280 p_env
= priv
->p_env
;
3281 sscanf(buf
, "%i", &nnn
);
3282 if (p_env
->packing
) {
3288 if ((nnn
> max
) || (nnn
< 2))
3290 p_env
->write_buffers
= nnn
;
3291 CLAW_DBF_TEXT(2, setup
, "Wbufset");
3292 CLAW_DBF_TEXT_(2, setup
, "WB=%d", p_env
->write_buffers
);
3296 static DEVICE_ATTR(write_buffer
, 0644, claw_wbuff_show
, claw_wbuff_write
);
3299 claw_rbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3301 struct claw_privbk
*priv
;
3302 struct claw_env
* p_env
;
3304 priv
= dev_get_drvdata(dev
);
3307 p_env
= priv
->p_env
;
3308 return sprintf(buf
, "%d\n", p_env
->read_buffers
);
3312 claw_rbuff_write(struct device
*dev
, struct device_attribute
*attr
,
3313 const char *buf
, size_t count
)
3315 struct claw_privbk
*priv
;
3316 struct claw_env
*p_env
;
3319 priv
= dev_get_drvdata(dev
);
3322 p_env
= priv
->p_env
;
3323 sscanf(buf
, "%i", &nnn
);
3324 if (p_env
->packing
) {
3330 if ((nnn
> max
) || (nnn
< 2))
3332 p_env
->read_buffers
= nnn
;
3333 CLAW_DBF_TEXT(2, setup
, "Rbufset");
3334 CLAW_DBF_TEXT_(2, setup
, "RB=%d", p_env
->read_buffers
);
3338 static DEVICE_ATTR(read_buffer
, 0644, claw_rbuff_show
, claw_rbuff_write
);
3340 static struct attribute
*claw_attr
[] = {
3341 &dev_attr_read_buffer
.attr
,
3342 &dev_attr_write_buffer
.attr
,
3343 &dev_attr_adapter_name
.attr
,
3344 &dev_attr_api_type
.attr
,
3345 &dev_attr_host_name
.attr
,
3349 static struct attribute_group claw_attr_group
= {
3354 claw_add_files(struct device
*dev
)
3356 CLAW_DBF_TEXT(2, setup
, "add_file");
3357 return sysfs_create_group(&dev
->kobj
, &claw_attr_group
);
3361 claw_remove_files(struct device
*dev
)
3363 CLAW_DBF_TEXT(2, setup
, "rem_file");
3364 sysfs_remove_group(&dev
->kobj
, &claw_attr_group
);
3367 /*--------------------------------------------------------------------*
3368 * claw_init and cleanup *
3369 *---------------------------------------------------------------------*/
3374 driver_remove_file(&claw_group_driver
.driver
,
3375 &driver_attr_group
);
3376 ccwgroup_driver_unregister(&claw_group_driver
);
3377 ccw_driver_unregister(&claw_ccw_driver
);
3378 root_device_unregister(claw_root_dev
);
3379 claw_unregister_debug_facility();
3380 pr_info("Driver unloaded\n");
3385 * Initialize module.
3386 * This is called just after the module is loaded.
3388 * @return 0 on success, !0 on error.
3395 pr_info("Loading %s\n", version
);
3396 ret
= claw_register_debug_facility();
3398 pr_err("Registering with the S/390 debug feature"
3399 " failed with error code %d\n", ret
);
3402 CLAW_DBF_TEXT(2, setup
, "init_mod");
3403 claw_root_dev
= root_device_register("claw");
3404 ret
= IS_ERR(claw_root_dev
) ? PTR_ERR(claw_root_dev
) : 0;
3407 ret
= ccw_driver_register(&claw_ccw_driver
);
3410 claw_group_driver
.driver
.groups
= claw_group_attr_groups
;
3411 ret
= ccwgroup_driver_register(&claw_group_driver
);
3417 ccw_driver_unregister(&claw_ccw_driver
);
3419 root_device_unregister(claw_root_dev
);
3421 CLAW_DBF_TEXT(2, setup
, "init_bad");
3422 claw_unregister_debug_facility();
3424 pr_err("Initializing the claw device driver failed\n");
3428 module_init(claw_init
);
3429 module_exit(claw_cleanup
);
3431 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3432 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3433 "Copyright 2000,2008 IBM Corporation\n");
3434 MODULE_LICENSE("GPL");