2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
5 * Linux for zSeries version
6 * Copyright (C) 2002,2005 IBM Corporation
7 * Author(s) Original code written by:
8 * Kazuo Iimura (iimura@jp.ibm.com)
10 * Andy Richter (richtera@us.ibm.com)
11 * Marc Price (mwprice@us.ibm.com)
14 * group x.x.rrrr,x.x.wwww
18 * adapter_name aaaaaaaa
22 * group 0.0.0200 0.0.0201
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
35 * rrrr - the first of 2 consecutive device addresses used for the
37 * The specified address is always used as the input (Read)
38 * channel and the next address is used as the output channel.
40 * wwww - the second of 2 consecutive device addresses used for
42 * The specified address is always used as the output
43 * channel and the previous address is used as the input channel.
45 * read_buffer - specifies number of input buffers to allocate.
46 * write_buffer - specifies number of output buffers to allocate.
47 * host_name - host name
48 * adaptor_name - adaptor name
49 * api_type - API type TCPIP or API will be sent and expected
52 * Note the following requirements:
53 * 1) host_name must match the configured adapter_name on the remote side
54 * 2) adaptor_name must match the configured host name on the remote side
57 * 1.00 Initial release shipped
58 * 1.10 Changes for Buffer allocation
59 * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
60 * 1.25 Added Packing support
64 #define KMSG_COMPONENT "claw"
66 #include <asm/ccwdev.h>
67 #include <asm/ccwgroup.h>
68 #include <asm/debug.h>
69 #include <asm/idals.h>
71 #include <linux/bitops.h>
72 #include <linux/ctype.h>
73 #include <linux/delay.h>
74 #include <linux/errno.h>
75 #include <linux/if_arp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
79 #include <linux/kernel.h>
80 #include <linux/module.h>
81 #include <linux/netdevice.h>
82 #include <linux/etherdevice.h>
83 #include <linux/proc_fs.h>
84 #include <linux/sched.h>
85 #include <linux/signal.h>
86 #include <linux/skbuff.h>
87 #include <linux/slab.h>
88 #include <linux/string.h>
89 #include <linux/tcp.h>
90 #include <linux/timer.h>
91 #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
);
258 static struct ccwgroup_driver claw_group_driver
= {
259 .owner
= THIS_MODULE
,
262 .driver_id
= 0xC3D3C1E6,
264 .remove
= claw_remove_device
,
265 .set_online
= claw_new_device
,
266 .set_offline
= claw_shutdown_device
,
273 /*----------------------------------------------------------------*
275 * this function is called for each CLAW device. *
276 *----------------------------------------------------------------*/
278 claw_probe(struct ccwgroup_device
*cgdev
)
281 struct claw_privbk
*privptr
=NULL
;
283 CLAW_DBF_TEXT(2, setup
, "probe");
284 if (!get_device(&cgdev
->dev
))
286 privptr
= kzalloc(sizeof(struct claw_privbk
), GFP_KERNEL
);
287 cgdev
->dev
.driver_data
= privptr
;
288 if (privptr
== NULL
) {
290 put_device(&cgdev
->dev
);
291 CLAW_DBF_TEXT_(2, setup
, "probex%d", -ENOMEM
);
294 privptr
->p_mtc_envelope
= kzalloc( MAX_ENVELOPE_SIZE
, GFP_KERNEL
);
295 privptr
->p_env
= kzalloc(sizeof(struct claw_env
), GFP_KERNEL
);
296 if ((privptr
->p_mtc_envelope
==NULL
) || (privptr
->p_env
==NULL
)) {
298 put_device(&cgdev
->dev
);
299 CLAW_DBF_TEXT_(2, setup
, "probex%d", -ENOMEM
);
302 memcpy(privptr
->p_env
->adapter_name
,WS_NAME_NOT_DEF
,8);
303 memcpy(privptr
->p_env
->host_name
,WS_NAME_NOT_DEF
,8);
304 memcpy(privptr
->p_env
->api_type
,WS_NAME_NOT_DEF
,8);
305 privptr
->p_env
->packing
= 0;
306 privptr
->p_env
->write_buffers
= 5;
307 privptr
->p_env
->read_buffers
= 5;
308 privptr
->p_env
->read_size
= CLAW_FRAME_SIZE
;
309 privptr
->p_env
->write_size
= CLAW_FRAME_SIZE
;
310 rc
= claw_add_files(&cgdev
->dev
);
313 put_device(&cgdev
->dev
);
314 dev_err(&cgdev
->dev
, "Creating the /proc files for a new"
315 " CLAW device failed\n");
316 CLAW_DBF_TEXT_(2, setup
, "probex%d", rc
);
319 privptr
->p_env
->p_priv
= privptr
;
320 cgdev
->cdev
[0]->handler
= claw_irq_handler
;
321 cgdev
->cdev
[1]->handler
= claw_irq_handler
;
322 CLAW_DBF_TEXT(2, setup
, "prbext 0");
325 } /* end of claw_probe */
327 /*-------------------------------------------------------------------*
329 *-------------------------------------------------------------------*/
332 claw_tx(struct sk_buff
*skb
, struct net_device
*dev
)
335 struct claw_privbk
*privptr
= dev
->ml_priv
;
336 unsigned long saveflags
;
339 CLAW_DBF_TEXT(4, trace
, "claw_tx");
340 p_ch
=&privptr
->channel
[WRITE
];
342 privptr
->stats
.tx_dropped
++;
343 privptr
->stats
.tx_errors
++;
344 CLAW_DBF_TEXT_(2, trace
, "clawtx%d", -EIO
);
347 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
348 rc
=claw_hw_tx( skb
, dev
, 1 );
349 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
350 CLAW_DBF_TEXT_(4, trace
, "clawtx%d", rc
);
352 } /* end of claw_tx */
354 /*------------------------------------------------------------------*
355 * pack the collect queue into an skb and return it *
356 * If not packing just return the top skb from the queue *
357 *------------------------------------------------------------------*/
359 static struct sk_buff
*
360 claw_pack_skb(struct claw_privbk
*privptr
)
362 struct sk_buff
*new_skb
,*held_skb
;
363 struct chbk
*p_ch
= &privptr
->channel
[WRITE
];
364 struct claw_env
*p_env
= privptr
->p_env
;
365 int pkt_cnt
,pk_ind
,so_far
;
367 new_skb
= NULL
; /* assume no dice */
369 CLAW_DBF_TEXT(4, trace
, "PackSKBe");
370 if (!skb_queue_empty(&p_ch
->collect_queue
)) {
372 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
374 dev_kfree_skb_any(held_skb
);
377 if (p_env
->packing
!= DO_PACKED
)
379 /* get a new SKB we will pack at least one */
380 new_skb
= dev_alloc_skb(p_env
->write_size
);
381 if (new_skb
== NULL
) {
382 atomic_inc(&held_skb
->users
);
383 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
386 /* we have packed packet and a place to put it */
389 new_skb
->cb
[1] = 'P'; /* every skb on queue has pack header */
390 while ((pk_ind
) && (held_skb
!= NULL
)) {
391 if (held_skb
->len
+so_far
<= p_env
->write_size
-8) {
392 memcpy(skb_put(new_skb
,held_skb
->len
),
393 held_skb
->data
,held_skb
->len
);
394 privptr
->stats
.tx_packets
++;
395 so_far
+= held_skb
->len
;
397 dev_kfree_skb_any(held_skb
);
398 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
400 atomic_dec(&held_skb
->users
);
403 atomic_inc(&held_skb
->users
);
404 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
408 CLAW_DBF_TEXT(4, trace
, "PackSKBx");
412 /*-------------------------------------------------------------------*
415 *-------------------------------------------------------------------*/
418 claw_change_mtu(struct net_device
*dev
, int new_mtu
)
420 struct claw_privbk
*privptr
= dev
->ml_priv
;
422 CLAW_DBF_TEXT(4, trace
, "setmtu");
423 buff_size
= privptr
->p_env
->write_size
;
424 if ((new_mtu
< 60) || (new_mtu
> buff_size
)) {
429 } /* end of claw_change_mtu */
432 /*-------------------------------------------------------------------*
435 *-------------------------------------------------------------------*/
437 claw_open(struct net_device
*dev
)
442 unsigned long saveflags
=0;
444 struct claw_privbk
*privptr
;
445 DECLARE_WAITQUEUE(wait
, current
);
446 struct timer_list timer
;
449 CLAW_DBF_TEXT(4, trace
, "open");
450 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
451 /* allocate and initialize CCW blocks */
452 if (privptr
->buffs_alloc
== 0) {
455 CLAW_DBF_TEXT(2, trace
, "openmem");
459 privptr
->system_validate_comp
=0;
460 privptr
->release_pend
=0;
461 if(strncmp(privptr
->p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
462 privptr
->p_env
->read_size
=DEF_PACK_BUFSIZE
;
463 privptr
->p_env
->write_size
=DEF_PACK_BUFSIZE
;
464 privptr
->p_env
->packing
=PACKING_ASK
;
466 privptr
->p_env
->packing
=0;
467 privptr
->p_env
->read_size
=CLAW_FRAME_SIZE
;
468 privptr
->p_env
->write_size
=CLAW_FRAME_SIZE
;
471 tasklet_init(&privptr
->channel
[READ
].tasklet
, claw_irq_tasklet
,
472 (unsigned long) &privptr
->channel
[READ
]);
473 for ( i
= 0; i
< 2; i
++) {
474 CLAW_DBF_TEXT_(2, trace
, "opn_ch%d", i
);
475 init_waitqueue_head(&privptr
->channel
[i
].wait
);
476 /* skb_queue_head_init(&p_ch->io_queue); */
479 &privptr
->channel
[WRITE
].collect_queue
);
480 privptr
->channel
[i
].flag_a
= 0;
481 privptr
->channel
[i
].IO_active
= 0;
482 privptr
->channel
[i
].flag
&= ~CLAW_TIMER
;
484 timer
.function
= (void *)claw_timer
;
485 timer
.data
= (unsigned long)(&privptr
->channel
[i
]);
486 timer
.expires
= jiffies
+ 15*HZ
;
488 spin_lock_irqsave(get_ccwdev_lock(
489 privptr
->channel
[i
].cdev
), saveflags
);
490 parm
= (unsigned long) &privptr
->channel
[i
];
491 privptr
->channel
[i
].claw_state
= CLAW_START_HALT_IO
;
493 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
494 rc
= ccw_device_halt(
495 (struct ccw_device
*)privptr
->channel
[i
].cdev
,parm
);
496 set_current_state(TASK_INTERRUPTIBLE
);
497 spin_unlock_irqrestore(
498 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
500 set_current_state(TASK_RUNNING
);
501 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
503 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
504 if((privptr
->channel
[i
].flag
& CLAW_TIMER
) == 0x00)
507 if ((((privptr
->channel
[READ
].last_dstat
|
508 privptr
->channel
[WRITE
].last_dstat
) &
509 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) ||
510 (((privptr
->channel
[READ
].flag
|
511 privptr
->channel
[WRITE
].flag
) & CLAW_TIMER
) != 0x00)) {
512 dev_info(&privptr
->channel
[READ
].cdev
->dev
,
513 "%s: remote side is not ready\n", dev
->name
);
514 CLAW_DBF_TEXT(2, trace
, "notrdy");
516 for ( i
= 0; i
< 2; i
++) {
518 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
520 parm
= (unsigned long) &privptr
->channel
[i
];
521 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
522 rc
= ccw_device_halt(
523 (struct ccw_device
*)&privptr
->channel
[i
].cdev
,
525 spin_unlock_irqrestore(
526 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
529 ccw_check_return_code(
530 privptr
->channel
[i
].cdev
, rc
);
533 free_pages((unsigned long)privptr
->p_buff_ccw
,
534 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
535 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
536 free_pages((unsigned long)privptr
->p_buff_read
,
537 (int)pages_to_order_of_mag(
538 privptr
->p_buff_read_num
));
541 p_buf
=privptr
->p_read_active_first
;
542 while (p_buf
!=NULL
) {
543 free_pages((unsigned long)p_buf
->p_buffer
,
544 (int)pages_to_order_of_mag(
545 privptr
->p_buff_pages_perread
));
549 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
550 free_pages((unsigned long)privptr
->p_buff_write
,
551 (int)pages_to_order_of_mag(
552 privptr
->p_buff_write_num
));
555 p_buf
=privptr
->p_write_active_first
;
556 while (p_buf
!=NULL
) {
557 free_pages((unsigned long)p_buf
->p_buffer
,
558 (int)pages_to_order_of_mag(
559 privptr
->p_buff_pages_perwrite
));
563 privptr
->buffs_alloc
= 0;
564 privptr
->channel
[READ
].flag
= 0x00;
565 privptr
->channel
[WRITE
].flag
= 0x00;
566 privptr
->p_buff_ccw
=NULL
;
567 privptr
->p_buff_read
=NULL
;
568 privptr
->p_buff_write
=NULL
;
569 claw_clear_busy(dev
);
570 CLAW_DBF_TEXT(2, trace
, "open EIO");
574 /* Send SystemValidate command */
576 claw_clear_busy(dev
);
577 CLAW_DBF_TEXT(4, trace
, "openok");
579 } /* end of claw_open */
581 /*-------------------------------------------------------------------*
585 *--------------------------------------------------------------------*/
587 claw_irq_handler(struct ccw_device
*cdev
,
588 unsigned long intparm
, struct irb
*irb
)
590 struct chbk
*p_ch
= NULL
;
591 struct claw_privbk
*privptr
= NULL
;
592 struct net_device
*dev
= NULL
;
593 struct claw_env
*p_env
;
594 struct chbk
*p_ch_r
=NULL
;
596 CLAW_DBF_TEXT(4, trace
, "clawirq");
597 /* Bypass all 'unsolicited interrupts' */
598 if (!cdev
->dev
.driver_data
) {
599 dev_warn(&cdev
->dev
, "An uninitialized CLAW device received an"
600 " IRQ, c-%02x d-%02x\n",
601 irb
->scsw
.cmd
.cstat
, irb
->scsw
.cmd
.dstat
);
602 CLAW_DBF_TEXT(2, trace
, "badirq");
605 privptr
= (struct claw_privbk
*)cdev
->dev
.driver_data
;
607 /* Try to extract channel from driver data. */
608 if (privptr
->channel
[READ
].cdev
== cdev
)
609 p_ch
= &privptr
->channel
[READ
];
610 else if (privptr
->channel
[WRITE
].cdev
== cdev
)
611 p_ch
= &privptr
->channel
[WRITE
];
613 dev_warn(&cdev
->dev
, "The device is not a CLAW device\n");
614 CLAW_DBF_TEXT(2, trace
, "badchan");
617 CLAW_DBF_TEXT_(4, trace
, "IRQCH=%d", p_ch
->flag
);
619 dev
= (struct net_device
*) (p_ch
->ndev
);
620 p_env
=privptr
->p_env
;
622 /* Copy interruption response block. */
623 memcpy(p_ch
->irb
, irb
, sizeof(struct irb
));
625 /* Check for good subchannel return code, otherwise info message */
626 if (irb
->scsw
.cmd
.cstat
&& !(irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
)) {
628 "%s: subchannel check for device: %04x -"
629 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
630 dev
->name
, p_ch
->devno
,
631 irb
->scsw
.cmd
.cstat
, irb
->scsw
.cmd
.dstat
,
633 CLAW_DBF_TEXT(2, trace
, "chanchk");
637 /* Check the reason-code of a unit check */
638 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
639 ccw_check_unit_check(p_ch
, irb
->ecw
[0]);
641 /* State machine to bring the connection up, down and to restart */
642 p_ch
->last_dstat
= irb
->scsw
.cmd
.dstat
;
644 switch (p_ch
->claw_state
) {
645 case CLAW_STOP
:/* HALT_IO by claw_release (halt sequence) */
646 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
647 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
648 (p_ch
->irb
->scsw
.cmd
.stctl
==
649 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
))))
651 wake_up(&p_ch
->wait
); /* wake up claw_release */
652 CLAW_DBF_TEXT(4, trace
, "stop");
654 case CLAW_START_HALT_IO
: /* HALT_IO issued by claw_open */
655 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
656 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
657 (p_ch
->irb
->scsw
.cmd
.stctl
==
658 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
659 CLAW_DBF_TEXT(4, trace
, "haltio");
662 if (p_ch
->flag
== CLAW_READ
) {
663 p_ch
->claw_state
= CLAW_START_READ
;
664 wake_up(&p_ch
->wait
); /* wake claw_open (READ)*/
665 } else if (p_ch
->flag
== CLAW_WRITE
) {
666 p_ch
->claw_state
= CLAW_START_WRITE
;
667 /* send SYSTEM_VALIDATE */
668 claw_strt_read(dev
, LOCK_NO
);
669 claw_send_control(dev
,
670 SYSTEM_VALIDATE_REQUEST
,
673 p_env
->adapter_name
);
675 dev_warn(&cdev
->dev
, "The CLAW device received"
676 " an unexpected IRQ, "
679 irb
->scsw
.cmd
.dstat
);
682 CLAW_DBF_TEXT(4, trace
, "haltio");
684 case CLAW_START_READ
:
685 CLAW_DBF_TEXT(4, trace
, "ReadIRQ");
686 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) {
687 clear_bit(0, (void *)&p_ch
->IO_active
);
688 if ((p_ch
->irb
->ecw
[0] & 0x41) == 0x41 ||
689 (p_ch
->irb
->ecw
[0] & 0x40) == 0x40 ||
690 (p_ch
->irb
->ecw
[0]) == 0) {
691 privptr
->stats
.rx_errors
++;
693 "%s: Restart is required after remote "
697 CLAW_DBF_TEXT(4, trace
, "notrdy");
700 if ((p_ch
->irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
) &&
701 (p_ch
->irb
->scsw
.cmd
.dstat
== 0)) {
702 if (test_and_set_bit(CLAW_BH_ACTIVE
,
703 (void *)&p_ch
->flag_a
) == 0)
704 tasklet_schedule(&p_ch
->tasklet
);
706 CLAW_DBF_TEXT(4, trace
, "PCINoBH");
707 CLAW_DBF_TEXT(4, trace
, "PCI_read");
710 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
711 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
712 (p_ch
->irb
->scsw
.cmd
.stctl
==
713 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
714 CLAW_DBF_TEXT(4, trace
, "SPend_rd");
717 clear_bit(0, (void *)&p_ch
->IO_active
);
718 claw_clearbit_busy(TB_RETRY
, dev
);
719 if (test_and_set_bit(CLAW_BH_ACTIVE
,
720 (void *)&p_ch
->flag_a
) == 0)
721 tasklet_schedule(&p_ch
->tasklet
);
723 CLAW_DBF_TEXT(4, trace
, "RdBHAct");
724 CLAW_DBF_TEXT(4, trace
, "RdIRQXit");
726 case CLAW_START_WRITE
:
727 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) {
729 "%s: Unit Check Occured in "
730 "write channel\n", dev
->name
);
731 clear_bit(0, (void *)&p_ch
->IO_active
);
732 if (p_ch
->irb
->ecw
[0] & 0x80) {
734 "%s: Resetting Event "
735 "occurred:\n", dev
->name
);
736 init_timer(&p_ch
->timer
);
737 p_ch
->timer
.function
=
738 (void *)claw_write_retry
;
739 p_ch
->timer
.data
= (unsigned long)p_ch
;
740 p_ch
->timer
.expires
= jiffies
+ 10*HZ
;
741 add_timer(&p_ch
->timer
);
743 "%s: write connection "
744 "restarting\n", dev
->name
);
746 CLAW_DBF_TEXT(4, trace
, "rstrtwrt");
749 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) {
750 clear_bit(0, (void *)&p_ch
->IO_active
);
752 "%s: Unit Exception "
753 "occurred in write channel\n",
756 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
757 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
758 (p_ch
->irb
->scsw
.cmd
.stctl
==
759 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
760 CLAW_DBF_TEXT(4, trace
, "writeUE");
763 clear_bit(0, (void *)&p_ch
->IO_active
);
764 if (claw_test_and_setbit_busy(TB_TX
, dev
) == 0) {
765 claw_write_next(p_ch
);
766 claw_clearbit_busy(TB_TX
, dev
);
767 claw_clear_busy(dev
);
769 p_ch_r
= (struct chbk
*)&privptr
->channel
[READ
];
770 if (test_and_set_bit(CLAW_BH_ACTIVE
,
771 (void *)&p_ch_r
->flag_a
) == 0)
772 tasklet_schedule(&p_ch_r
->tasklet
);
773 CLAW_DBF_TEXT(4, trace
, "StWtExit");
777 "The CLAW device for %s received an unexpected IRQ\n",
779 CLAW_DBF_TEXT(2, trace
, "badIRQ");
783 } /* end of claw_irq_handler */
786 /*-------------------------------------------------------------------*
789 *--------------------------------------------------------------------*/
791 claw_irq_tasklet ( unsigned long data
)
794 struct net_device
*dev
;
795 struct claw_privbk
* privptr
;
797 p_ch
= (struct chbk
*) data
;
798 dev
= (struct net_device
*)p_ch
->ndev
;
799 CLAW_DBF_TEXT(4, trace
, "IRQtask");
800 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
802 clear_bit(CLAW_BH_ACTIVE
, (void *)&p_ch
->flag_a
);
803 CLAW_DBF_TEXT(4, trace
, "TskletXt");
805 } /* end of claw_irq_bh */
807 /*-------------------------------------------------------------------*
810 *--------------------------------------------------------------------*/
812 claw_release(struct net_device
*dev
)
816 unsigned long saveflags
;
818 struct claw_privbk
*privptr
;
819 DECLARE_WAITQUEUE(wait
, current
);
820 struct ccwbk
* p_this_ccw
;
825 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
828 CLAW_DBF_TEXT(4, trace
, "release");
829 privptr
->release_pend
=1;
830 claw_setbit_busy(TB_STOP
,dev
);
831 for ( i
= 1; i
>=0 ; i
--) {
833 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
834 /* del_timer(&privptr->channel[READ].timer); */
835 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
836 privptr
->channel
[i
].IO_active
= 0;
837 parm
= (unsigned long) &privptr
->channel
[i
];
839 claw_purge_skb_queue(
840 &privptr
->channel
[WRITE
].collect_queue
);
841 rc
= ccw_device_halt (privptr
->channel
[i
].cdev
, parm
);
842 if (privptr
->system_validate_comp
==0x00) /* never opened? */
843 init_waitqueue_head(&privptr
->channel
[i
].wait
);
844 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
845 set_current_state(TASK_INTERRUPTIBLE
);
846 spin_unlock_irqrestore(
847 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
849 set_current_state(TASK_RUNNING
);
850 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
852 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
855 if (privptr
->pk_skb
!= NULL
) {
856 dev_kfree_skb_any(privptr
->pk_skb
);
857 privptr
->pk_skb
= NULL
;
859 if(privptr
->buffs_alloc
!= 1) {
860 CLAW_DBF_TEXT(4, trace
, "none2fre");
863 CLAW_DBF_TEXT(4, trace
, "freebufs");
864 if (privptr
->p_buff_ccw
!= NULL
) {
865 free_pages((unsigned long)privptr
->p_buff_ccw
,
866 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
868 CLAW_DBF_TEXT(4, trace
, "freeread");
869 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
870 if (privptr
->p_buff_read
!= NULL
) {
871 free_pages((unsigned long)privptr
->p_buff_read
,
872 (int)pages_to_order_of_mag(privptr
->p_buff_read_num
));
876 p_buf
=privptr
->p_read_active_first
;
877 while (p_buf
!=NULL
) {
878 free_pages((unsigned long)p_buf
->p_buffer
,
879 (int)pages_to_order_of_mag(
880 privptr
->p_buff_pages_perread
));
884 CLAW_DBF_TEXT(4, trace
, "freewrit");
885 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
886 free_pages((unsigned long)privptr
->p_buff_write
,
887 (int)pages_to_order_of_mag(privptr
->p_buff_write_num
));
890 p_buf
=privptr
->p_write_active_first
;
891 while (p_buf
!=NULL
) {
892 free_pages((unsigned long)p_buf
->p_buffer
,
893 (int)pages_to_order_of_mag(
894 privptr
->p_buff_pages_perwrite
));
898 CLAW_DBF_TEXT(4, trace
, "clearptr");
899 privptr
->buffs_alloc
= 0;
900 privptr
->p_buff_ccw
=NULL
;
901 privptr
->p_buff_read
=NULL
;
902 privptr
->p_buff_write
=NULL
;
903 privptr
->system_validate_comp
=0;
904 privptr
->release_pend
=0;
905 /* Remove any writes that were pending and reset all reads */
906 p_this_ccw
=privptr
->p_read_active_first
;
907 while (p_this_ccw
!=NULL
) {
908 p_this_ccw
->header
.length
=0xffff;
909 p_this_ccw
->header
.opcode
=0xff;
910 p_this_ccw
->header
.flag
=0x00;
911 p_this_ccw
=p_this_ccw
->next
;
914 while (privptr
->p_write_active_first
!=NULL
) {
915 p_this_ccw
=privptr
->p_write_active_first
;
916 p_this_ccw
->header
.flag
=CLAW_PENDING
;
917 privptr
->p_write_active_first
=p_this_ccw
->next
;
918 p_this_ccw
->next
=privptr
->p_write_free_chain
;
919 privptr
->p_write_free_chain
=p_this_ccw
;
920 ++privptr
->write_free_count
;
922 privptr
->p_write_active_last
=NULL
;
923 privptr
->mtc_logical_link
= -1;
924 privptr
->mtc_skipping
= 1;
925 privptr
->mtc_offset
=0;
927 if (((privptr
->channel
[READ
].last_dstat
|
928 privptr
->channel
[WRITE
].last_dstat
) &
929 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) {
930 dev_warn(&privptr
->channel
[READ
].cdev
->dev
,
931 "Deactivating %s completed with incorrect"
932 " subchannel status "
933 "(read %02x, write %02x)\n",
935 privptr
->channel
[READ
].last_dstat
,
936 privptr
->channel
[WRITE
].last_dstat
);
937 CLAW_DBF_TEXT(2, trace
, "badclose");
939 CLAW_DBF_TEXT(4, trace
, "rlsexit");
941 } /* end of claw_release */
943 /*-------------------------------------------------------------------*
946 *--------------------------------------------------------------------*/
949 claw_write_retry ( struct chbk
*p_ch
)
952 struct net_device
*dev
=p_ch
->ndev
;
954 CLAW_DBF_TEXT(4, trace
, "w_retry");
955 if (p_ch
->claw_state
== CLAW_STOP
) {
958 claw_strt_out_IO( dev
);
959 CLAW_DBF_TEXT(4, trace
, "rtry_xit");
961 } /* end of claw_write_retry */
964 /*-------------------------------------------------------------------*
967 *--------------------------------------------------------------------*/
970 claw_write_next ( struct chbk
* p_ch
)
973 struct net_device
*dev
;
974 struct claw_privbk
*privptr
=NULL
;
975 struct sk_buff
*pk_skb
;
978 CLAW_DBF_TEXT(4, trace
, "claw_wrt");
979 if (p_ch
->claw_state
== CLAW_STOP
)
981 dev
= (struct net_device
*) p_ch
->ndev
;
982 privptr
= (struct claw_privbk
*) dev
->ml_priv
;
983 claw_free_wrt_buf( dev
);
984 if ((privptr
->write_free_count
> 0) &&
985 !skb_queue_empty(&p_ch
->collect_queue
)) {
986 pk_skb
= claw_pack_skb(privptr
);
987 while (pk_skb
!= NULL
) {
988 rc
= claw_hw_tx( pk_skb
, dev
,1);
989 if (privptr
->write_free_count
> 0) {
990 pk_skb
= claw_pack_skb(privptr
);
995 if (privptr
->p_write_active_first
!=NULL
) {
996 claw_strt_out_IO(dev
);
999 } /* end of claw_write_next */
1001 /*-------------------------------------------------------------------*
1004 *--------------------------------------------------------------------*/
1007 claw_timer ( struct chbk
* p_ch
)
1009 CLAW_DBF_TEXT(4, trace
, "timer");
1010 p_ch
->flag
|= CLAW_TIMER
;
1011 wake_up(&p_ch
->wait
);
1013 } /* end of claw_timer */
1021 /*-------------------------------------------------------------------*
1023 * pages_to_order_of_mag *
1025 * takes a number of pages from 1 to 512 and returns the *
1026 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1027 * of magnitude get_free_pages() has an upper order of 9 *
1028 *--------------------------------------------------------------------*/
1031 pages_to_order_of_mag(int num_of_pages
)
1033 int order_of_mag
=1; /* assume 2 pages */
1036 CLAW_DBF_TEXT_(5, trace
, "pages%d", num_of_pages
);
1037 if (num_of_pages
== 1) {return 0; } /* magnitude of 0 = 1 page */
1038 /* 512 pages = 2Meg on 4k page systems */
1039 if (num_of_pages
>= 512) {return 9; }
1040 /* we have two or more pages order is at least 1 */
1041 for (nump
=2 ;nump
<= 512;nump
*=2) {
1042 if (num_of_pages
<= nump
)
1046 if (order_of_mag
> 9) { order_of_mag
= 9; } /* I know it's paranoid */
1047 CLAW_DBF_TEXT_(5, trace
, "mag%d", order_of_mag
);
1048 return order_of_mag
;
1051 /*-------------------------------------------------------------------*
1055 *--------------------------------------------------------------------*/
1057 add_claw_reads(struct net_device
*dev
, struct ccwbk
* p_first
,
1058 struct ccwbk
* p_last
)
1060 struct claw_privbk
*privptr
;
1061 struct ccw1 temp_ccw
;
1062 struct endccw
* p_end
;
1063 CLAW_DBF_TEXT(4, trace
, "addreads");
1064 privptr
= dev
->ml_priv
;
1065 p_end
= privptr
->p_end_ccw
;
1067 /* first CCW and last CCW contains a new set of read channel programs
1068 * to apend the running channel programs
1070 if ( p_first
==NULL
) {
1071 CLAW_DBF_TEXT(4, trace
, "addexit");
1075 /* set up ending CCW sequence for this segment */
1077 p_end
->read1
=0x00; /* second ending CCW is now active */
1078 /* reset ending CCWs and setup TIC CCWs */
1079 p_end
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1080 p_end
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1081 p_last
->r_TIC_1
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1082 p_last
->r_TIC_2
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1083 p_end
->read2_nop2
.cda
=0;
1084 p_end
->read2_nop2
.count
=1;
1087 p_end
->read1
=0x01; /* first ending CCW is now active */
1088 /* reset ending CCWs and setup TIC CCWs */
1089 p_end
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1090 p_end
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1091 p_last
->r_TIC_1
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1092 p_last
->r_TIC_2
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1093 p_end
->read1_nop2
.cda
=0;
1094 p_end
->read1_nop2
.count
=1;
1097 if ( privptr
-> p_read_active_first
==NULL
) {
1098 privptr
->p_read_active_first
= p_first
; /* set new first */
1099 privptr
->p_read_active_last
= p_last
; /* set new last */
1103 /* set up TIC ccw */
1104 temp_ccw
.cda
= (__u32
)__pa(&p_first
->read
);
1107 temp_ccw
.cmd_code
= CCW_CLAW_CMD_TIC
;
1112 /* first set of CCW's is chained to the new read */
1113 /* chain, so the second set is chained to the active chain. */
1114 /* Therefore modify the second set to point to the new */
1115 /* read chain set up TIC CCWs */
1116 /* make sure we update the CCW so channel doesn't fetch it */
1117 /* when it's only half done */
1118 memcpy( &p_end
->read2_nop2
, &temp_ccw
,
1119 sizeof(struct ccw1
));
1120 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1121 (__u32
)__pa(&p_first
->read
);
1122 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1123 (__u32
)__pa(&p_first
->read
);
1126 /* make sure we update the CCW so channel doesn't */
1127 /* fetch it when it is only half done */
1128 memcpy( &p_end
->read1_nop2
, &temp_ccw
,
1129 sizeof(struct ccw1
));
1130 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1131 (__u32
)__pa(&p_first
->read
);
1132 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1133 (__u32
)__pa(&p_first
->read
);
1135 /* chain in new set of blocks */
1136 privptr
->p_read_active_last
->next
= p_first
;
1137 privptr
->p_read_active_last
=p_last
;
1138 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1139 CLAW_DBF_TEXT(4, trace
, "addexit");
1141 } /* end of add_claw_reads */
1143 /*-------------------------------------------------------------------*
1144 * ccw_check_return_code *
1146 *-------------------------------------------------------------------*/
1149 ccw_check_return_code(struct ccw_device
*cdev
, int return_code
)
1151 CLAW_DBF_TEXT(4, trace
, "ccwret");
1152 if (return_code
!= 0) {
1153 switch (return_code
) {
1154 case -EBUSY
: /* BUSY is a transient state no action needed */
1157 dev_err(&cdev
->dev
, "The remote channel adapter is not"
1162 "The status of the remote channel adapter"
1166 dev_err(&cdev
->dev
, "The common device layer"
1167 " returned error code %d\n",
1171 CLAW_DBF_TEXT(4, trace
, "ccwret");
1172 } /* end of ccw_check_return_code */
1174 /*-------------------------------------------------------------------*
1175 * ccw_check_unit_check *
1176 *--------------------------------------------------------------------*/
1179 ccw_check_unit_check(struct chbk
* p_ch
, unsigned char sense
)
1181 struct net_device
*ndev
= p_ch
->ndev
;
1182 struct device
*dev
= &p_ch
->cdev
->dev
;
1184 CLAW_DBF_TEXT(4, trace
, "unitchek");
1185 dev_warn(dev
, "The communication peer of %s disconnected\n",
1190 dev_warn(dev
, "The remote channel adapter for"
1191 " %s has been reset\n",
1195 else if (sense
& 0x20) {
1197 dev_warn(dev
, "A data streaming timeout occurred"
1202 dev_warn(dev
, "A data transfer parity error occurred"
1207 else if (sense
& 0x10) {
1209 dev_warn(dev
, "The remote channel adapter for %s"
1214 dev_warn(dev
, "A read data parity error occurred"
1220 } /* end of ccw_check_unit_check */
1222 /*-------------------------------------------------------------------*
1224 *--------------------------------------------------------------------*/
1226 find_link(struct net_device
*dev
, char *host_name
, char *ws_name
)
1228 struct claw_privbk
*privptr
;
1229 struct claw_env
*p_env
;
1232 CLAW_DBF_TEXT(2, setup
, "findlink");
1233 privptr
= dev
->ml_priv
;
1234 p_env
=privptr
->p_env
;
1235 switch (p_env
->packing
)
1238 if ((memcmp(WS_APPL_NAME_PACKED
, host_name
, 8)!=0) ||
1239 (memcmp(WS_APPL_NAME_PACKED
, ws_name
, 8)!=0 ))
1244 if ((memcmp(WS_APPL_NAME_IP_NAME
, host_name
, 8)!=0) ||
1245 (memcmp(WS_APPL_NAME_IP_NAME
, ws_name
, 8)!=0 ))
1249 if ((memcmp(HOST_APPL_NAME
, host_name
, 8)!=0) ||
1250 (memcmp(p_env
->api_type
, ws_name
, 8)!=0))
1256 } /* end of find_link */
1258 /*-------------------------------------------------------------------*
1262 *-------------------------------------------------------------------*/
1265 claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
)
1268 struct claw_privbk
*privptr
;
1269 struct ccwbk
*p_this_ccw
;
1270 struct ccwbk
*p_first_ccw
;
1271 struct ccwbk
*p_last_ccw
;
1273 signed long len_of_data
;
1274 unsigned long bytesInThisBuffer
;
1275 unsigned char *pDataAddress
;
1276 struct endccw
*pEnd
;
1277 struct ccw1 tempCCW
;
1279 struct claw_env
*p_env
;
1281 struct clawph
*pk_head
;
1284 CLAW_DBF_TEXT(4, trace
, "hw_tx");
1285 privptr
= (struct claw_privbk
*)(dev
->ml_priv
);
1286 p_ch
=(struct chbk
*)&privptr
->channel
[WRITE
];
1287 p_env
=privptr
->p_env
;
1288 claw_free_wrt_buf(dev
); /* Clean up free chain if posible */
1289 /* scan the write queue to free any completed write packets */
1292 if ((p_env
->packing
>= PACK_SEND
) &&
1293 (skb
->cb
[1] != 'P')) {
1294 skb_push(skb
,sizeof(struct clawph
));
1295 pk_head
=(struct clawph
*)skb
->data
;
1296 pk_head
->len
=skb
->len
-sizeof(struct clawph
);
1297 if (pk_head
->len
%4) {
1298 pk_head
->len
+= 4-(pk_head
->len
%4);
1299 skb_pad(skb
,4-(pk_head
->len
%4));
1300 skb_put(skb
,4-(pk_head
->len
%4));
1302 if (p_env
->packing
== DO_PACKED
)
1303 pk_head
->link_num
= linkid
;
1305 pk_head
->link_num
= 0;
1306 pk_head
->flag
= 0x00;
1311 if (claw_check_busy(dev
)) {
1312 if (privptr
->write_free_count
!=0) {
1313 claw_clear_busy(dev
);
1316 claw_strt_out_IO(dev
);
1317 claw_free_wrt_buf( dev
);
1318 if (privptr
->write_free_count
==0) {
1319 ch
= &privptr
->channel
[WRITE
];
1320 atomic_inc(&skb
->users
);
1321 skb_queue_tail(&ch
->collect_queue
, skb
);
1325 claw_clear_busy(dev
);
1330 if (claw_test_and_setbit_busy(TB_TX
,dev
)) { /* set to busy */
1331 ch
= &privptr
->channel
[WRITE
];
1332 atomic_inc(&skb
->users
);
1333 skb_queue_tail(&ch
->collect_queue
, skb
);
1334 claw_strt_out_IO(dev
);
1339 /* See how many write buffers are required to hold this data */
1340 numBuffers
= DIV_ROUND_UP(skb
->len
, privptr
->p_env
->write_size
);
1342 /* If that number of buffers isn't available, give up for now */
1343 if (privptr
->write_free_count
< numBuffers
||
1344 privptr
->p_write_free_chain
== NULL
) {
1346 claw_setbit_busy(TB_NOBUFFER
,dev
);
1347 ch
= &privptr
->channel
[WRITE
];
1348 atomic_inc(&skb
->users
);
1349 skb_queue_tail(&ch
->collect_queue
, skb
);
1350 CLAW_DBF_TEXT(2, trace
, "clawbusy");
1353 pDataAddress
=skb
->data
;
1354 len_of_data
=skb
->len
;
1356 while (len_of_data
> 0) {
1357 p_this_ccw
=privptr
->p_write_free_chain
; /* get a block */
1358 if (p_this_ccw
== NULL
) { /* lost the race */
1359 ch
= &privptr
->channel
[WRITE
];
1360 atomic_inc(&skb
->users
);
1361 skb_queue_tail(&ch
->collect_queue
, skb
);
1364 privptr
->p_write_free_chain
=p_this_ccw
->next
;
1365 p_this_ccw
->next
=NULL
;
1366 --privptr
->write_free_count
; /* -1 */
1367 bytesInThisBuffer
=len_of_data
;
1368 memcpy( p_this_ccw
->p_buffer
,pDataAddress
, bytesInThisBuffer
);
1369 len_of_data
-=bytesInThisBuffer
;
1370 pDataAddress
+=(unsigned long)bytesInThisBuffer
;
1371 /* setup write CCW */
1372 p_this_ccw
->write
.cmd_code
= (linkid
* 8) +1;
1373 if (len_of_data
>0) {
1374 p_this_ccw
->write
.cmd_code
+=MORE_to_COME_FLAG
;
1376 p_this_ccw
->write
.count
=bytesInThisBuffer
;
1377 /* now add to end of this chain */
1378 if (p_first_ccw
==NULL
) {
1379 p_first_ccw
=p_this_ccw
;
1381 if (p_last_ccw
!=NULL
) {
1382 p_last_ccw
->next
=p_this_ccw
;
1383 /* set up TIC ccws */
1384 p_last_ccw
->w_TIC_1
.cda
=
1385 (__u32
)__pa(&p_this_ccw
->write
);
1387 p_last_ccw
=p_this_ccw
; /* save new last block */
1390 /* FirstCCW and LastCCW now contain a new set of write channel
1391 * programs to append to the running channel program
1394 if (p_first_ccw
!=NULL
) {
1395 /* setup ending ccw sequence for this segment */
1396 pEnd
=privptr
->p_end_ccw
;
1398 pEnd
->write1
=0x00; /* second end ccw is now active */
1399 /* set up Tic CCWs */
1400 p_last_ccw
->w_TIC_1
.cda
=
1401 (__u32
)__pa(&pEnd
->write2_nop1
);
1402 pEnd
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1403 pEnd
->write2_nop2
.flags
=
1404 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1405 pEnd
->write2_nop2
.cda
=0;
1406 pEnd
->write2_nop2
.count
=1;
1408 else { /* end of if (pEnd->write1)*/
1409 pEnd
->write1
=0x01; /* first end ccw is now active */
1410 /* set up Tic CCWs */
1411 p_last_ccw
->w_TIC_1
.cda
=
1412 (__u32
)__pa(&pEnd
->write1_nop1
);
1413 pEnd
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1414 pEnd
->write1_nop2
.flags
=
1415 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1416 pEnd
->write1_nop2
.cda
=0;
1417 pEnd
->write1_nop2
.count
=1;
1418 } /* end if if (pEnd->write1) */
1420 if (privptr
->p_write_active_first
==NULL
) {
1421 privptr
->p_write_active_first
=p_first_ccw
;
1422 privptr
->p_write_active_last
=p_last_ccw
;
1425 /* set up Tic CCWs */
1427 tempCCW
.cda
=(__u32
)__pa(&p_first_ccw
->write
);
1430 tempCCW
.cmd_code
=CCW_CLAW_CMD_TIC
;
1435 * first set of ending CCW's is chained to the new write
1436 * chain, so the second set is chained to the active chain
1437 * Therefore modify the second set to point the new write chain.
1438 * make sure we update the CCW atomically
1439 * so channel does not fetch it when it's only half done
1441 memcpy( &pEnd
->write2_nop2
, &tempCCW
,
1442 sizeof(struct ccw1
));
1443 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1444 (__u32
)__pa(&p_first_ccw
->write
);
1448 /*make sure we update the CCW atomically
1449 *so channel does not fetch it when it's only half done
1451 memcpy(&pEnd
->write1_nop2
, &tempCCW
,
1452 sizeof(struct ccw1
));
1453 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1454 (__u32
)__pa(&p_first_ccw
->write
);
1456 } /* end if if (pEnd->write1) */
1458 privptr
->p_write_active_last
->next
=p_first_ccw
;
1459 privptr
->p_write_active_last
=p_last_ccw
;
1462 } /* endif (p_first_ccw!=NULL) */
1463 dev_kfree_skb_any(skb
);
1470 claw_strt_out_IO(dev
);
1471 /* if write free count is zero , set NOBUFFER */
1472 if (privptr
->write_free_count
==0) {
1473 claw_setbit_busy(TB_NOBUFFER
,dev
);
1476 claw_clearbit_busy(TB_TX
,dev
);
1479 } /* end of claw_hw_tx */
1481 /*-------------------------------------------------------------------*
1485 *--------------------------------------------------------------------*/
1488 init_ccw_bk(struct net_device
*dev
)
1491 __u32 ccw_blocks_required
;
1492 __u32 ccw_blocks_perpage
;
1493 __u32 ccw_pages_required
;
1494 __u32 claw_reads_perpage
=1;
1495 __u32 claw_read_pages
;
1496 __u32 claw_writes_perpage
=1;
1497 __u32 claw_write_pages
;
1499 struct ccwbk
*p_free_chain
;
1501 struct ccwbk
*p_last_CCWB
;
1502 struct ccwbk
*p_first_CCWB
;
1503 struct endccw
*p_endccw
=NULL
;
1504 addr_t real_address
;
1505 struct claw_privbk
*privptr
= dev
->ml_priv
;
1506 struct clawh
*pClawH
=NULL
;
1507 addr_t real_TIC_address
;
1509 CLAW_DBF_TEXT(4, trace
, "init_ccw");
1511 /* initialize statistics field */
1512 privptr
->active_link_ID
=0;
1513 /* initialize ccwbk pointers */
1514 privptr
->p_write_free_chain
=NULL
; /* pointer to free ccw chain*/
1515 privptr
->p_write_active_first
=NULL
; /* pointer to the first write ccw*/
1516 privptr
->p_write_active_last
=NULL
; /* pointer to the last write ccw*/
1517 privptr
->p_read_active_first
=NULL
; /* pointer to the first read ccw*/
1518 privptr
->p_read_active_last
=NULL
; /* pointer to the last read ccw */
1519 privptr
->p_end_ccw
=NULL
; /* pointer to ending ccw */
1520 privptr
->p_claw_signal_blk
=NULL
; /* pointer to signal block */
1521 privptr
->buffs_alloc
= 0;
1522 memset(&privptr
->end_ccw
, 0x00, sizeof(struct endccw
));
1523 memset(&privptr
->ctl_bk
, 0x00, sizeof(struct clawctl
));
1524 /* initialize free write ccwbk counter */
1525 privptr
->write_free_count
=0; /* number of free bufs on write chain */
1529 * We need 1 CCW block for each read buffer, 1 for each
1530 * write buffer, plus 1 for ClawSignalBlock
1532 ccw_blocks_required
=
1533 privptr
->p_env
->read_buffers
+privptr
->p_env
->write_buffers
+1;
1535 * compute number of CCW blocks that will fit in a page
1537 ccw_blocks_perpage
= PAGE_SIZE
/ CCWBK_SIZE
;
1539 DIV_ROUND_UP(ccw_blocks_required
, ccw_blocks_perpage
);
1542 * read and write sizes are set by 2 constants in claw.h
1543 * 4k and 32k. Unpacked values other than 4k are not going to
1544 * provide good performance. With packing buffers support 32k
1547 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1548 claw_reads_perpage
= PAGE_SIZE
/ privptr
->p_env
->read_size
;
1549 claw_read_pages
= DIV_ROUND_UP(privptr
->p_env
->read_buffers
,
1550 claw_reads_perpage
);
1552 else { /* > or equal */
1553 privptr
->p_buff_pages_perread
=
1554 DIV_ROUND_UP(privptr
->p_env
->read_size
, PAGE_SIZE
);
1555 claw_read_pages
= privptr
->p_env
->read_buffers
*
1556 privptr
->p_buff_pages_perread
;
1558 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1559 claw_writes_perpage
=
1560 PAGE_SIZE
/ privptr
->p_env
->write_size
;
1561 claw_write_pages
= DIV_ROUND_UP(privptr
->p_env
->write_buffers
,
1562 claw_writes_perpage
);
1565 else { /* > or equal */
1566 privptr
->p_buff_pages_perwrite
=
1567 DIV_ROUND_UP(privptr
->p_env
->read_size
, PAGE_SIZE
);
1568 claw_write_pages
= privptr
->p_env
->write_buffers
*
1569 privptr
->p_buff_pages_perwrite
;
1572 * allocate ccw_pages_required
1574 if (privptr
->p_buff_ccw
==NULL
) {
1575 privptr
->p_buff_ccw
=
1576 (void *)__get_free_pages(__GFP_DMA
,
1577 (int)pages_to_order_of_mag(ccw_pages_required
));
1578 if (privptr
->p_buff_ccw
==NULL
) {
1581 privptr
->p_buff_ccw_num
=ccw_pages_required
;
1583 memset(privptr
->p_buff_ccw
, 0x00,
1584 privptr
->p_buff_ccw_num
* PAGE_SIZE
);
1587 * obtain ending ccw block address
1590 privptr
->p_end_ccw
= (struct endccw
*)&privptr
->end_ccw
;
1591 real_address
= (__u32
)__pa(privptr
->p_end_ccw
);
1592 /* Initialize ending CCW block */
1593 p_endccw
=privptr
->p_end_ccw
;
1594 p_endccw
->real
=real_address
;
1595 p_endccw
->write1
=0x00;
1596 p_endccw
->read1
=0x00;
1599 p_endccw
->write1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1600 p_endccw
->write1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1601 p_endccw
->write1_nop1
.count
= 1;
1602 p_endccw
->write1_nop1
.cda
= 0;
1605 p_endccw
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1606 p_endccw
->write1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1607 p_endccw
->write1_nop2
.count
= 1;
1608 p_endccw
->write1_nop2
.cda
= 0;
1611 p_endccw
->write2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1612 p_endccw
->write2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1613 p_endccw
->write2_nop1
.count
= 1;
1614 p_endccw
->write2_nop1
.cda
= 0;
1617 p_endccw
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1618 p_endccw
->write2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1619 p_endccw
->write2_nop2
.count
= 1;
1620 p_endccw
->write2_nop2
.cda
= 0;
1623 p_endccw
->read1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1624 p_endccw
->read1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1625 p_endccw
->read1_nop1
.count
= 1;
1626 p_endccw
->read1_nop1
.cda
= 0;
1629 p_endccw
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1630 p_endccw
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1631 p_endccw
->read1_nop2
.count
= 1;
1632 p_endccw
->read1_nop2
.cda
= 0;
1635 p_endccw
->read2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1636 p_endccw
->read2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1637 p_endccw
->read2_nop1
.count
= 1;
1638 p_endccw
->read2_nop1
.cda
= 0;
1641 p_endccw
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1642 p_endccw
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1643 p_endccw
->read2_nop2
.count
= 1;
1644 p_endccw
->read2_nop2
.cda
= 0;
1647 * Build a chain of CCWs
1650 p_buff
=privptr
->p_buff_ccw
;
1653 for (i
=0 ; i
< ccw_pages_required
; i
++ ) {
1654 real_address
= (__u32
)__pa(p_buff
);
1656 for (j
=0 ; j
< ccw_blocks_perpage
; j
++) {
1657 p_buf
->next
= p_free_chain
;
1658 p_free_chain
= p_buf
;
1659 p_buf
->real
=(__u32
)__pa(p_buf
);
1665 * Initialize ClawSignalBlock
1668 if (privptr
->p_claw_signal_blk
==NULL
) {
1669 privptr
->p_claw_signal_blk
=p_free_chain
;
1670 p_free_chain
=p_free_chain
->next
;
1671 pClawH
=(struct clawh
*)privptr
->p_claw_signal_blk
;
1672 pClawH
->length
=0xffff;
1673 pClawH
->opcode
=0xff;
1674 pClawH
->flag
=CLAW_BUSY
;
1678 * allocate write_pages_required and add to free chain
1680 if (privptr
->p_buff_write
==NULL
) {
1681 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1682 privptr
->p_buff_write
=
1683 (void *)__get_free_pages(__GFP_DMA
,
1684 (int)pages_to_order_of_mag(claw_write_pages
));
1685 if (privptr
->p_buff_write
==NULL
) {
1686 privptr
->p_buff_ccw
=NULL
;
1690 * Build CLAW write free chain
1694 memset(privptr
->p_buff_write
, 0x00,
1695 ccw_pages_required
* PAGE_SIZE
);
1696 privptr
->p_write_free_chain
=NULL
;
1698 p_buff
=privptr
->p_buff_write
;
1700 for (i
=0 ; i
< privptr
->p_env
->write_buffers
; i
++) {
1701 p_buf
= p_free_chain
; /* get a CCW */
1702 p_free_chain
= p_buf
->next
;
1703 p_buf
->next
=privptr
->p_write_free_chain
;
1704 privptr
->p_write_free_chain
= p_buf
;
1705 p_buf
-> p_buffer
= (struct clawbuf
*)p_buff
;
1706 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
1707 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1708 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1709 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1710 p_buf
-> w_read_FF
.count
= 1;
1711 p_buf
-> w_read_FF
.cda
=
1712 (__u32
)__pa(&p_buf
-> header
.flag
);
1713 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1714 p_buf
-> w_TIC_1
.flags
= 0;
1715 p_buf
-> w_TIC_1
.count
= 0;
1717 if (((unsigned long)p_buff
+
1718 privptr
->p_env
->write_size
) >=
1719 ((unsigned long)(p_buff
+2*
1720 (privptr
->p_env
->write_size
) - 1) & PAGE_MASK
)) {
1721 p_buff
= p_buff
+privptr
->p_env
->write_size
;
1725 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1727 privptr
->p_write_free_chain
=NULL
;
1728 for (i
= 0; i
< privptr
->p_env
->write_buffers
; i
++) {
1729 p_buff
=(void *)__get_free_pages(__GFP_DMA
,
1730 (int)pages_to_order_of_mag(
1731 privptr
->p_buff_pages_perwrite
) );
1733 free_pages((unsigned long)privptr
->p_buff_ccw
,
1734 (int)pages_to_order_of_mag(
1735 privptr
->p_buff_ccw_num
));
1736 privptr
->p_buff_ccw
=NULL
;
1737 p_buf
=privptr
->p_buff_write
;
1738 while (p_buf
!=NULL
) {
1739 free_pages((unsigned long)
1741 (int)pages_to_order_of_mag(
1742 privptr
->p_buff_pages_perwrite
));
1746 } /* Error on get_pages */
1747 memset(p_buff
, 0x00, privptr
->p_env
->write_size
);
1748 p_buf
= p_free_chain
;
1749 p_free_chain
= p_buf
->next
;
1750 p_buf
->next
= privptr
->p_write_free_chain
;
1751 privptr
->p_write_free_chain
= p_buf
;
1752 privptr
->p_buff_write
= p_buf
;
1753 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1754 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
1755 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1756 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1757 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1758 p_buf
-> w_read_FF
.count
= 1;
1759 p_buf
-> w_read_FF
.cda
=
1760 (__u32
)__pa(&p_buf
-> header
.flag
);
1761 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1762 p_buf
-> w_TIC_1
.flags
= 0;
1763 p_buf
-> w_TIC_1
.count
= 0;
1764 } /* for all write_buffers */
1766 } /* else buffers are PAGE_SIZE or bigger */
1769 privptr
->p_buff_write_num
=claw_write_pages
;
1770 privptr
->write_free_count
=privptr
->p_env
->write_buffers
;
1774 * allocate read_pages_required and chain to free chain
1776 if (privptr
->p_buff_read
==NULL
) {
1777 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1778 privptr
->p_buff_read
=
1779 (void *)__get_free_pages(__GFP_DMA
,
1780 (int)pages_to_order_of_mag(claw_read_pages
) );
1781 if (privptr
->p_buff_read
==NULL
) {
1782 free_pages((unsigned long)privptr
->p_buff_ccw
,
1783 (int)pages_to_order_of_mag(
1784 privptr
->p_buff_ccw_num
));
1785 /* free the write pages size is < page size */
1786 free_pages((unsigned long)privptr
->p_buff_write
,
1787 (int)pages_to_order_of_mag(
1788 privptr
->p_buff_write_num
));
1789 privptr
->p_buff_ccw
=NULL
;
1790 privptr
->p_buff_write
=NULL
;
1793 memset(privptr
->p_buff_read
, 0x00, claw_read_pages
* PAGE_SIZE
);
1794 privptr
->p_buff_read_num
=claw_read_pages
;
1796 * Build CLAW read free chain
1799 p_buff
=privptr
->p_buff_read
;
1800 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
1801 p_buf
= p_free_chain
;
1802 p_free_chain
= p_buf
->next
;
1804 if (p_last_CCWB
==NULL
) {
1810 p_buf
->next
=p_first_CCWB
;
1812 (__u32
)__pa(&p_first_CCWB
-> read
);
1817 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1818 /* initialize read command */
1819 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
1820 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
1821 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1822 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
1824 /* initialize read_h command */
1825 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
1826 p_buf
-> read_h
.cda
=
1827 (__u32
)__pa(&(p_buf
->header
));
1828 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1829 p_buf
-> read_h
.count
= sizeof(struct clawh
);
1831 /* initialize Signal command */
1832 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
1833 p_buf
-> signal
.cda
=
1834 (__u32
)__pa(&(pClawH
->flag
));
1835 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1836 p_buf
-> signal
.count
= 1;
1838 /* initialize r_TIC_1 command */
1839 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1840 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
1841 p_buf
-> r_TIC_1
.flags
= 0;
1842 p_buf
-> r_TIC_1
.count
= 0;
1844 /* initialize r_read_FF command */
1845 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1846 p_buf
-> r_read_FF
.cda
=
1847 (__u32
)__pa(&(pClawH
->flag
));
1848 p_buf
-> r_read_FF
.flags
=
1849 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
1850 p_buf
-> r_read_FF
.count
= 1;
1852 /* initialize r_TIC_2 */
1853 memcpy(&p_buf
->r_TIC_2
,
1854 &p_buf
->r_TIC_1
, sizeof(struct ccw1
));
1856 /* initialize Header */
1857 p_buf
->header
.length
=0xffff;
1858 p_buf
->header
.opcode
=0xff;
1859 p_buf
->header
.flag
=CLAW_PENDING
;
1861 if (((unsigned long)p_buff
+privptr
->p_env
->read_size
) >=
1862 ((unsigned long)(p_buff
+2*(privptr
->p_env
->read_size
)
1865 p_buff
= p_buff
+privptr
->p_env
->read_size
;
1869 (void *)((unsigned long)
1870 (p_buff
+2*(privptr
->p_env
->read_size
)-1)
1873 } /* for read_buffers */
1874 } /* read_size < PAGE_SIZE */
1875 else { /* read Size >= PAGE_SIZE */
1876 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
1877 p_buff
= (void *)__get_free_pages(__GFP_DMA
,
1878 (int)pages_to_order_of_mag(
1879 privptr
->p_buff_pages_perread
));
1881 free_pages((unsigned long)privptr
->p_buff_ccw
,
1882 (int)pages_to_order_of_mag(privptr
->
1884 /* free the write pages */
1885 p_buf
=privptr
->p_buff_write
;
1886 while (p_buf
!=NULL
) {
1888 (unsigned long)p_buf
->p_buffer
,
1889 (int)pages_to_order_of_mag(
1890 privptr
->p_buff_pages_perwrite
));
1893 /* free any read pages already alloc */
1894 p_buf
=privptr
->p_buff_read
;
1895 while (p_buf
!=NULL
) {
1897 (unsigned long)p_buf
->p_buffer
,
1898 (int)pages_to_order_of_mag(
1899 privptr
->p_buff_pages_perread
));
1902 privptr
->p_buff_ccw
=NULL
;
1903 privptr
->p_buff_write
=NULL
;
1906 memset(p_buff
, 0x00, privptr
->p_env
->read_size
);
1907 p_buf
= p_free_chain
;
1908 privptr
->p_buff_read
= p_buf
;
1909 p_free_chain
= p_buf
->next
;
1911 if (p_last_CCWB
==NULL
) {
1917 p_buf
->next
=p_first_CCWB
;
1920 &p_first_CCWB
-> read
);
1924 /* save buff address */
1925 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1926 /* initialize read command */
1927 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
1928 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
1929 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1930 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
1932 /* initialize read_h command */
1933 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
1934 p_buf
-> read_h
.cda
=
1935 (__u32
)__pa(&(p_buf
->header
));
1936 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1937 p_buf
-> read_h
.count
= sizeof(struct clawh
);
1939 /* initialize Signal command */
1940 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
1941 p_buf
-> signal
.cda
=
1942 (__u32
)__pa(&(pClawH
->flag
));
1943 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1944 p_buf
-> signal
.count
= 1;
1946 /* initialize r_TIC_1 command */
1947 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1948 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
1949 p_buf
-> r_TIC_1
.flags
= 0;
1950 p_buf
-> r_TIC_1
.count
= 0;
1952 /* initialize r_read_FF command */
1953 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1954 p_buf
-> r_read_FF
.cda
=
1955 (__u32
)__pa(&(pClawH
->flag
));
1956 p_buf
-> r_read_FF
.flags
=
1957 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
1958 p_buf
-> r_read_FF
.count
= 1;
1960 /* initialize r_TIC_2 */
1961 memcpy(&p_buf
->r_TIC_2
, &p_buf
->r_TIC_1
,
1962 sizeof(struct ccw1
));
1964 /* initialize Header */
1965 p_buf
->header
.length
=0xffff;
1966 p_buf
->header
.opcode
=0xff;
1967 p_buf
->header
.flag
=CLAW_PENDING
;
1969 } /* For read_buffers */
1970 } /* read_size >= PAGE_SIZE */
1971 } /* pBuffread = NULL */
1972 add_claw_reads( dev
,p_first_CCWB
, p_last_CCWB
);
1973 privptr
->buffs_alloc
= 1;
1976 } /* end of init_ccw_bk */
1978 /*-------------------------------------------------------------------*
1982 *--------------------------------------------------------------------*/
1985 probe_error( struct ccwgroup_device
*cgdev
)
1987 struct claw_privbk
*privptr
;
1989 CLAW_DBF_TEXT(4, trace
, "proberr");
1990 privptr
= (struct claw_privbk
*) cgdev
->dev
.driver_data
;
1991 if (privptr
!= NULL
) {
1992 cgdev
->dev
.driver_data
= NULL
;
1993 kfree(privptr
->p_env
);
1994 kfree(privptr
->p_mtc_envelope
);
1999 /*-------------------------------------------------------------------*
2000 * claw_process_control *
2003 *--------------------------------------------------------------------*/
2006 claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
)
2009 struct clawbuf
*p_buf
;
2010 struct clawctl ctlbk
;
2011 struct clawctl
*p_ctlbk
;
2012 char temp_host_name
[8];
2013 char temp_ws_name
[8];
2014 struct claw_privbk
*privptr
;
2015 struct claw_env
*p_env
;
2016 struct sysval
*p_sysval
;
2017 struct conncmd
*p_connect
=NULL
;
2019 struct chbk
*p_ch
= NULL
;
2020 struct device
*tdev
;
2021 CLAW_DBF_TEXT(2, setup
, "clw_cntl");
2022 udelay(1000); /* Wait a ms for the control packets to
2023 *catch up to each other */
2024 privptr
= dev
->ml_priv
;
2025 p_env
=privptr
->p_env
;
2026 tdev
= &privptr
->channel
[READ
].cdev
->dev
;
2027 memcpy( &temp_host_name
, p_env
->host_name
, 8);
2028 memcpy( &temp_ws_name
, p_env
->adapter_name
, 8);
2029 dev_info(tdev
, "%s: CLAW device %.8s: "
2030 "Received Control Packet\n",
2031 dev
->name
, temp_ws_name
);
2032 if (privptr
->release_pend
==1) {
2035 p_buf
=p_ccw
->p_buffer
;
2037 if (p_env
->packing
== DO_PACKED
) { /* packing in progress?*/
2038 memcpy(p_ctlbk
, &p_buf
->buffer
[4], sizeof(struct clawctl
));
2040 memcpy(p_ctlbk
, p_buf
, sizeof(struct clawctl
));
2042 switch (p_ctlbk
->command
)
2044 case SYSTEM_VALIDATE_REQUEST
:
2045 if (p_ctlbk
->version
!= CLAW_VERSION_ID
) {
2046 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2047 CLAW_RC_WRONG_VERSION
);
2048 dev_warn(tdev
, "The communication peer of %s"
2049 " uses an incorrect API version %d\n",
2050 dev
->name
, p_ctlbk
->version
);
2052 p_sysval
= (struct sysval
*)&(p_ctlbk
->data
);
2053 dev_info(tdev
, "%s: Recv Sys Validate Request: "
2054 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2056 dev
->name
, p_ctlbk
->version
,
2058 p_ctlbk
->correlator
,
2060 p_sysval
->host_name
);
2061 if (memcmp(temp_host_name
, p_sysval
->host_name
, 8)) {
2062 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2063 CLAW_RC_NAME_MISMATCH
);
2064 CLAW_DBF_TEXT(2, setup
, "HSTBAD");
2065 CLAW_DBF_TEXT_(2, setup
, "%s", p_sysval
->host_name
);
2066 CLAW_DBF_TEXT_(2, setup
, "%s", temp_host_name
);
2068 "Host name %s for %s does not match the"
2069 " remote adapter name %s\n",
2070 p_sysval
->host_name
,
2074 if (memcmp(temp_ws_name
, p_sysval
->WS_name
, 8)) {
2075 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2076 CLAW_RC_NAME_MISMATCH
);
2077 CLAW_DBF_TEXT(2, setup
, "WSNBAD");
2078 CLAW_DBF_TEXT_(2, setup
, "%s", p_sysval
->WS_name
);
2079 CLAW_DBF_TEXT_(2, setup
, "%s", temp_ws_name
);
2080 dev_warn(tdev
, "Adapter name %s for %s does not match"
2081 " the remote host name %s\n",
2086 if ((p_sysval
->write_frame_size
< p_env
->write_size
) &&
2087 (p_env
->packing
== 0)) {
2088 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2089 CLAW_RC_HOST_RCV_TOO_SMALL
);
2091 "The local write buffer is smaller than the"
2092 " remote read buffer\n");
2093 CLAW_DBF_TEXT(2, setup
, "wrtszbad");
2095 if ((p_sysval
->read_frame_size
< p_env
->read_size
) &&
2096 (p_env
->packing
== 0)) {
2097 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2098 CLAW_RC_HOST_RCV_TOO_SMALL
);
2100 "The local read buffer is smaller than the"
2101 " remote write buffer\n");
2102 CLAW_DBF_TEXT(2, setup
, "rdsizbad");
2104 claw_snd_sys_validate_rsp(dev
, p_ctlbk
, 0);
2106 "CLAW device %.8s: System validate"
2107 " completed.\n", temp_ws_name
);
2109 "%s: sys Validate Rsize:%d Wsize:%d\n",
2110 dev
->name
, p_sysval
->read_frame_size
,
2111 p_sysval
->write_frame_size
);
2112 privptr
->system_validate_comp
= 1;
2113 if (strncmp(p_env
->api_type
, WS_APPL_NAME_PACKED
, 6) == 0)
2114 p_env
->packing
= PACKING_ASK
;
2115 claw_strt_conn_req(dev
);
2117 case SYSTEM_VALIDATE_RESPONSE
:
2118 p_sysval
= (struct sysval
*)&(p_ctlbk
->data
);
2120 "Settings for %s validated (version=%d, "
2121 "remote device=%d, rc=%d, adapter name=%.8s, "
2122 "host name=%.8s)\n",
2125 p_ctlbk
->correlator
,
2128 p_sysval
->host_name
);
2129 switch (p_ctlbk
->rc
) {
2131 dev_info(tdev
, "%s: CLAW device "
2132 "%.8s: System validate completed.\n",
2133 dev
->name
, temp_ws_name
);
2134 if (privptr
->system_validate_comp
== 0)
2135 claw_strt_conn_req(dev
);
2136 privptr
->system_validate_comp
= 1;
2138 case CLAW_RC_NAME_MISMATCH
:
2139 dev_warn(tdev
, "Validating %s failed because of"
2140 " a host or adapter name mismatch\n",
2143 case CLAW_RC_WRONG_VERSION
:
2144 dev_warn(tdev
, "Validating %s failed because of a"
2145 " version conflict\n",
2148 case CLAW_RC_HOST_RCV_TOO_SMALL
:
2149 dev_warn(tdev
, "Validating %s failed because of a"
2150 " frame size conflict\n",
2154 dev_warn(tdev
, "The communication peer of %s rejected"
2155 " the connection\n",
2161 case CONNECTION_REQUEST
:
2162 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2163 dev_info(tdev
, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2164 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2168 p_ctlbk
->correlator
,
2169 p_connect
->host_name
,
2170 p_connect
->WS_name
);
2171 if (privptr
->active_link_ID
!= 0) {
2172 claw_snd_disc(dev
, p_ctlbk
);
2173 dev_info(tdev
, "%s rejected a connection request"
2174 " because it is already active\n",
2177 if (p_ctlbk
->linkid
!= 1) {
2178 claw_snd_disc(dev
, p_ctlbk
);
2179 dev_info(tdev
, "%s rejected a request to open multiple"
2183 rc
= find_link(dev
, p_connect
->host_name
, p_connect
->WS_name
);
2185 claw_snd_disc(dev
, p_ctlbk
);
2186 dev_info(tdev
, "%s rejected a connection request"
2187 " because of a type mismatch\n",
2190 claw_send_control(dev
,
2191 CONNECTION_CONFIRM
, p_ctlbk
->linkid
,
2192 p_ctlbk
->correlator
,
2193 0, p_connect
->host_name
,
2194 p_connect
->WS_name
);
2195 if (p_env
->packing
== PACKING_ASK
) {
2196 p_env
->packing
= PACK_SEND
;
2197 claw_snd_conn_req(dev
, 0);
2199 dev_info(tdev
, "%s: CLAW device %.8s: Connection "
2200 "completed link_id=%d.\n",
2201 dev
->name
, temp_ws_name
,
2203 privptr
->active_link_ID
= p_ctlbk
->linkid
;
2204 p_ch
= &privptr
->channel
[WRITE
];
2205 wake_up(&p_ch
->wait
); /* wake up claw_open ( WRITE) */
2207 case CONNECTION_RESPONSE
:
2208 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2209 dev_info(tdev
, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
2210 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2214 p_ctlbk
->correlator
,
2216 p_connect
->host_name
,
2217 p_connect
->WS_name
);
2219 if (p_ctlbk
->rc
!= 0) {
2220 dev_warn(tdev
, "The communication peer of %s rejected"
2221 " a connection request\n",
2226 p_connect
->host_name
, p_connect
->WS_name
);
2228 claw_snd_disc(dev
, p_ctlbk
);
2229 dev_warn(tdev
, "The communication peer of %s"
2230 " rejected a connection "
2231 "request because of a type mismatch\n",
2234 /* should be until CONNECTION_CONFIRM */
2235 privptr
->active_link_ID
= -(p_ctlbk
->linkid
);
2237 case CONNECTION_CONFIRM
:
2238 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2240 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2241 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2245 p_ctlbk
->correlator
,
2246 p_connect
->host_name
,
2247 p_connect
->WS_name
);
2248 if (p_ctlbk
->linkid
== -(privptr
->active_link_ID
)) {
2249 privptr
->active_link_ID
= p_ctlbk
->linkid
;
2250 if (p_env
->packing
> PACKING_ASK
) {
2252 "%s: Confirmed Now packing\n", dev
->name
);
2253 p_env
->packing
= DO_PACKED
;
2255 p_ch
= &privptr
->channel
[WRITE
];
2256 wake_up(&p_ch
->wait
);
2258 dev_warn(tdev
, "Activating %s failed because of"
2259 " an incorrect link ID=%d\n",
2260 dev
->name
, p_ctlbk
->linkid
);
2261 claw_snd_disc(dev
, p_ctlbk
);
2265 dev_info(tdev
, "%s: Disconnect: "
2266 "Vers=%d,link_id=%d,Corr=%d\n",
2267 dev
->name
, p_ctlbk
->version
,
2268 p_ctlbk
->linkid
, p_ctlbk
->correlator
);
2269 if ((p_ctlbk
->linkid
== 2) &&
2270 (p_env
->packing
== PACK_SEND
)) {
2271 privptr
->active_link_ID
= 1;
2272 p_env
->packing
= DO_PACKED
;
2274 privptr
->active_link_ID
= 0;
2277 dev_warn(tdev
, "The communication peer of %s failed\n",
2281 dev_warn(tdev
, "The communication peer of %s sent"
2282 " an unknown command code\n",
2288 } /* end of claw_process_control */
2291 /*-------------------------------------------------------------------*
2292 * claw_send_control *
2294 *--------------------------------------------------------------------*/
2297 claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
2298 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
)
2300 struct claw_privbk
*privptr
;
2301 struct clawctl
*p_ctl
;
2302 struct sysval
*p_sysval
;
2303 struct conncmd
*p_connect
;
2304 struct sk_buff
*skb
;
2306 CLAW_DBF_TEXT(2, setup
, "sndcntl");
2307 privptr
= dev
->ml_priv
;
2308 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
2310 p_ctl
->command
=type
;
2311 p_ctl
->version
=CLAW_VERSION_ID
;
2313 p_ctl
->correlator
=correlator
;
2316 p_sysval
=(struct sysval
*)&p_ctl
->data
;
2317 p_connect
=(struct conncmd
*)&p_ctl
->data
;
2319 switch (p_ctl
->command
) {
2320 case SYSTEM_VALIDATE_REQUEST
:
2321 case SYSTEM_VALIDATE_RESPONSE
:
2322 memcpy(&p_sysval
->host_name
, local_name
, 8);
2323 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
2324 if (privptr
->p_env
->packing
> 0) {
2325 p_sysval
->read_frame_size
= DEF_PACK_BUFSIZE
;
2326 p_sysval
->write_frame_size
= DEF_PACK_BUFSIZE
;
2328 /* how big is the biggest group of packets */
2329 p_sysval
->read_frame_size
=
2330 privptr
->p_env
->read_size
;
2331 p_sysval
->write_frame_size
=
2332 privptr
->p_env
->write_size
;
2334 memset(&p_sysval
->reserved
, 0x00, 4);
2336 case CONNECTION_REQUEST
:
2337 case CONNECTION_RESPONSE
:
2338 case CONNECTION_CONFIRM
:
2340 memcpy(&p_sysval
->host_name
, local_name
, 8);
2341 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
2342 if (privptr
->p_env
->packing
> 0) {
2343 /* How big is the biggest packet */
2344 p_connect
->reserved1
[0]=CLAW_FRAME_SIZE
;
2345 p_connect
->reserved1
[1]=CLAW_FRAME_SIZE
;
2347 memset(&p_connect
->reserved1
, 0x00, 4);
2348 memset(&p_connect
->reserved2
, 0x00, 4);
2355 /* write Control Record to the device */
2358 skb
= dev_alloc_skb(sizeof(struct clawctl
));
2362 memcpy(skb_put(skb
, sizeof(struct clawctl
)),
2363 p_ctl
, sizeof(struct clawctl
));
2364 if (privptr
->p_env
->packing
>= PACK_SEND
)
2365 claw_hw_tx(skb
, dev
, 1);
2367 claw_hw_tx(skb
, dev
, 0);
2369 } /* end of claw_send_control */
2371 /*-------------------------------------------------------------------*
2372 * claw_snd_conn_req *
2374 *--------------------------------------------------------------------*/
2376 claw_snd_conn_req(struct net_device
*dev
, __u8 link
)
2379 struct claw_privbk
*privptr
= dev
->ml_priv
;
2380 struct clawctl
*p_ctl
;
2382 CLAW_DBF_TEXT(2, setup
, "snd_conn");
2384 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
2385 p_ctl
->linkid
= link
;
2386 if ( privptr
->system_validate_comp
==0x00 ) {
2389 if (privptr
->p_env
->packing
== PACKING_ASK
)
2390 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2391 WS_APPL_NAME_PACKED
, WS_APPL_NAME_PACKED
);
2392 if (privptr
->p_env
->packing
== PACK_SEND
) {
2393 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2394 WS_APPL_NAME_IP_NAME
, WS_APPL_NAME_IP_NAME
);
2396 if (privptr
->p_env
->packing
== 0)
2397 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2398 HOST_APPL_NAME
, privptr
->p_env
->api_type
);
2401 } /* end of claw_snd_conn_req */
2404 /*-------------------------------------------------------------------*
2407 *--------------------------------------------------------------------*/
2410 claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
)
2413 struct conncmd
* p_connect
;
2415 CLAW_DBF_TEXT(2, setup
, "snd_dsc");
2416 p_connect
=(struct conncmd
*)&p_ctl
->data
;
2418 rc
=claw_send_control(dev
, DISCONNECT
, p_ctl
->linkid
,
2419 p_ctl
->correlator
, 0,
2420 p_connect
->host_name
, p_connect
->WS_name
);
2422 } /* end of claw_snd_disc */
2425 /*-------------------------------------------------------------------*
2426 * claw_snd_sys_validate_rsp *
2428 *--------------------------------------------------------------------*/
2431 claw_snd_sys_validate_rsp(struct net_device
*dev
,
2432 struct clawctl
*p_ctl
, __u32 return_code
)
2434 struct claw_env
* p_env
;
2435 struct claw_privbk
*privptr
;
2438 CLAW_DBF_TEXT(2, setup
, "chkresp");
2439 privptr
= dev
->ml_priv
;
2440 p_env
=privptr
->p_env
;
2441 rc
=claw_send_control(dev
, SYSTEM_VALIDATE_RESPONSE
,
2446 p_env
->adapter_name
);
2448 } /* end of claw_snd_sys_validate_rsp */
2450 /*-------------------------------------------------------------------*
2451 * claw_strt_conn_req *
2453 *--------------------------------------------------------------------*/
2456 claw_strt_conn_req(struct net_device
*dev
)
2460 CLAW_DBF_TEXT(2, setup
, "conn_req");
2461 rc
=claw_snd_conn_req(dev
, 1);
2463 } /* end of claw_strt_conn_req */
2467 /*-------------------------------------------------------------------*
2469 *-------------------------------------------------------------------*/
2472 net_device_stats
*claw_stats(struct net_device
*dev
)
2474 struct claw_privbk
*privptr
;
2476 CLAW_DBF_TEXT(4, trace
, "stats");
2477 privptr
= dev
->ml_priv
;
2478 return &privptr
->stats
;
2479 } /* end of claw_stats */
2482 /*-------------------------------------------------------------------*
2485 *--------------------------------------------------------------------*/
2487 unpack_read(struct net_device
*dev
)
2489 struct sk_buff
*skb
;
2490 struct claw_privbk
*privptr
;
2491 struct claw_env
*p_env
;
2492 struct ccwbk
*p_this_ccw
;
2493 struct ccwbk
*p_first_ccw
;
2494 struct ccwbk
*p_last_ccw
;
2495 struct clawph
*p_packh
;
2497 struct clawctl
*p_ctlrec
=NULL
;
2498 struct device
*p_dev
;
2503 __u8 mtc_this_frm
=0;
2508 CLAW_DBF_TEXT(4, trace
, "unpkread");
2513 privptr
= dev
->ml_priv
;
2515 p_dev
= &privptr
->channel
[READ
].cdev
->dev
;
2516 p_env
= privptr
->p_env
;
2517 p_this_ccw
=privptr
->p_read_active_first
;
2519 while (p_this_ccw
!=NULL
&& p_this_ccw
->header
.flag
!=CLAW_PENDING
) {
2522 p_this_ccw
->header
.flag
=CLAW_PENDING
;
2523 privptr
->p_read_active_first
=p_this_ccw
->next
;
2524 p_this_ccw
->next
=NULL
;
2525 p_packh
= (struct clawph
*)p_this_ccw
->p_buffer
;
2526 if ((p_env
->packing
== PACK_SEND
) &&
2527 (p_packh
->len
== 32) &&
2528 (p_packh
->link_num
== 0)) { /* is it a packed ctl rec? */
2529 p_packh
++; /* peek past pack header */
2530 p_ctlrec
= (struct clawctl
*)p_packh
;
2531 p_packh
--; /* un peek */
2532 if ((p_ctlrec
->command
== CONNECTION_RESPONSE
) ||
2533 (p_ctlrec
->command
== CONNECTION_CONFIRM
))
2534 p_env
->packing
= DO_PACKED
;
2536 if (p_env
->packing
== DO_PACKED
)
2537 link_num
=p_packh
->link_num
;
2539 link_num
=p_this_ccw
->header
.opcode
/ 8;
2540 if ((p_this_ccw
->header
.opcode
& MORE_to_COME_FLAG
)!=0) {
2542 if (p_this_ccw
->header
.length
!=
2543 privptr
->p_env
->read_size
) {
2545 "The communication peer of %s"
2547 " frame of length %02x\n",
2548 dev
->name
, p_this_ccw
->header
.length
);
2552 if (privptr
->mtc_skipping
) {
2554 * We're in the mode of skipping past a
2555 * multi-frame message
2556 * that we can't process for some reason or other.
2557 * The first frame without the More-To-Come flag is
2558 * the last frame of the skipped message.
2560 /* in case of More-To-Come not set in this frame */
2561 if (mtc_this_frm
==0) {
2562 privptr
->mtc_skipping
=0; /* Ok, the end */
2563 privptr
->mtc_logical_link
=-1;
2569 claw_process_control(dev
, p_this_ccw
);
2570 CLAW_DBF_TEXT(4, trace
, "UnpkCntl");
2574 if (p_env
->packing
== DO_PACKED
) {
2575 if (pack_off
> p_env
->read_size
)
2577 p_packd
= p_this_ccw
->p_buffer
+pack_off
;
2578 p_packh
= (struct clawph
*) p_packd
;
2579 if ((p_packh
->len
== 0) || /* done with this frame? */
2580 (p_packh
->flag
!= 0))
2582 bytes_to_mov
= p_packh
->len
;
2583 pack_off
+= bytes_to_mov
+sizeof(struct clawph
);
2586 bytes_to_mov
=p_this_ccw
->header
.length
;
2588 if (privptr
->mtc_logical_link
<0) {
2591 * if More-To-Come is set in this frame then we don't know
2592 * length of entire message, and hence have to allocate
2595 /* We are starting a new envelope */
2596 privptr
->mtc_offset
=0;
2597 privptr
->mtc_logical_link
=link_num
;
2600 if (bytes_to_mov
> (MAX_ENVELOPE_SIZE
- privptr
->mtc_offset
) ) {
2602 privptr
->stats
.rx_frame_errors
++;
2605 if (p_env
->packing
== DO_PACKED
) {
2606 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
2607 p_packd
+sizeof(struct clawph
), bytes_to_mov
);
2610 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
2611 p_this_ccw
->p_buffer
, bytes_to_mov
);
2613 if (mtc_this_frm
==0) {
2614 len_of_data
=privptr
->mtc_offset
+bytes_to_mov
;
2615 skb
=dev_alloc_skb(len_of_data
);
2617 memcpy(skb_put(skb
,len_of_data
),
2618 privptr
->p_mtc_envelope
,
2621 skb_reset_mac_header(skb
);
2622 skb
->protocol
=htons(ETH_P_IP
);
2623 skb
->ip_summed
=CHECKSUM_UNNECESSARY
;
2624 privptr
->stats
.rx_packets
++;
2625 privptr
->stats
.rx_bytes
+=len_of_data
;
2629 dev_info(p_dev
, "Allocating a buffer for"
2630 " incoming data failed\n");
2631 privptr
->stats
.rx_dropped
++;
2633 privptr
->mtc_offset
=0;
2634 privptr
->mtc_logical_link
=-1;
2637 privptr
->mtc_offset
+=bytes_to_mov
;
2639 if (p_env
->packing
== DO_PACKED
)
2643 * Remove ThisCCWblock from active read queue, and add it
2644 * to queue of free blocks to be reused.
2647 p_this_ccw
->header
.length
=0xffff;
2648 p_this_ccw
->header
.opcode
=0xff;
2650 * add this one to the free queue for later reuse
2652 if (p_first_ccw
==NULL
) {
2653 p_first_ccw
= p_this_ccw
;
2656 p_last_ccw
->next
= p_this_ccw
;
2658 p_last_ccw
= p_this_ccw
;
2660 * chain to next block on active read queue
2662 p_this_ccw
= privptr
->p_read_active_first
;
2663 CLAW_DBF_TEXT_(4, trace
, "rxpkt %d", p
);
2664 } /* end of while */
2666 /* check validity */
2668 CLAW_DBF_TEXT_(4, trace
, "rxfrm %d", i
);
2669 add_claw_reads(dev
, p_first_ccw
, p_last_ccw
);
2670 claw_strt_read(dev
, LOCK_YES
);
2672 } /* end of unpack_read */
2674 /*-------------------------------------------------------------------*
2677 *--------------------------------------------------------------------*/
2679 claw_strt_read (struct net_device
*dev
, int lock
)
2683 unsigned long saveflags
= 0;
2684 struct claw_privbk
*privptr
= dev
->ml_priv
;
2685 struct ccwbk
*p_ccwbk
;
2687 struct clawh
*p_clawh
;
2688 p_ch
=&privptr
->channel
[READ
];
2690 CLAW_DBF_TEXT(4, trace
, "StRdNter");
2691 p_clawh
=(struct clawh
*)privptr
->p_claw_signal_blk
;
2692 p_clawh
->flag
=CLAW_IDLE
; /* 0x00 */
2694 if ((privptr
->p_write_active_first
!=NULL
&&
2695 privptr
->p_write_active_first
->header
.flag
!=CLAW_PENDING
) ||
2696 (privptr
->p_read_active_first
!=NULL
&&
2697 privptr
->p_read_active_first
->header
.flag
!=CLAW_PENDING
)) {
2698 p_clawh
->flag
=CLAW_BUSY
; /* 0xff */
2700 if (lock
==LOCK_YES
) {
2701 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
2703 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
2704 CLAW_DBF_TEXT(4, trace
, "HotRead");
2705 p_ccwbk
=privptr
->p_read_active_first
;
2706 parm
= (unsigned long) p_ch
;
2707 rc
= ccw_device_start (p_ch
->cdev
, &p_ccwbk
->read
, parm
,
2710 ccw_check_return_code(p_ch
->cdev
, rc
);
2714 CLAW_DBF_TEXT(2, trace
, "ReadAct");
2717 if (lock
==LOCK_YES
) {
2718 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
2720 CLAW_DBF_TEXT(4, trace
, "StRdExit");
2722 } /* end of claw_strt_read */
2724 /*-------------------------------------------------------------------*
2725 * claw_strt_out_IO *
2727 *--------------------------------------------------------------------*/
2730 claw_strt_out_IO( struct net_device
*dev
)
2734 struct claw_privbk
*privptr
;
2736 struct ccwbk
*p_first_ccw
;
2741 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
2742 p_ch
=&privptr
->channel
[WRITE
];
2744 CLAW_DBF_TEXT(4, trace
, "strt_io");
2745 p_first_ccw
=privptr
->p_write_active_first
;
2747 if (p_ch
->claw_state
== CLAW_STOP
)
2749 if (p_first_ccw
== NULL
) {
2752 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
2753 parm
= (unsigned long) p_ch
;
2754 CLAW_DBF_TEXT(2, trace
, "StWrtIO");
2755 rc
= ccw_device_start(p_ch
->cdev
, &p_first_ccw
->write
, parm
,
2758 ccw_check_return_code(p_ch
->cdev
, rc
);
2761 dev
->trans_start
= jiffies
;
2763 } /* end of claw_strt_out_IO */
2765 /*-------------------------------------------------------------------*
2766 * Free write buffers *
2768 *--------------------------------------------------------------------*/
2771 claw_free_wrt_buf( struct net_device
*dev
)
2774 struct claw_privbk
*privptr
= (struct claw_privbk
*)dev
->ml_priv
;
2775 struct ccwbk
*p_first_ccw
;
2776 struct ccwbk
*p_last_ccw
;
2777 struct ccwbk
*p_this_ccw
;
2778 struct ccwbk
*p_next_ccw
;
2780 CLAW_DBF_TEXT(4, trace
, "freewrtb");
2781 /* scan the write queue to free any completed write packets */
2784 p_this_ccw
=privptr
->p_write_active_first
;
2785 while ( (p_this_ccw
!=NULL
) && (p_this_ccw
->header
.flag
!=CLAW_PENDING
))
2787 p_next_ccw
= p_this_ccw
->next
;
2788 if (((p_next_ccw
!=NULL
) &&
2789 (p_next_ccw
->header
.flag
!=CLAW_PENDING
)) ||
2790 ((p_this_ccw
== privptr
->p_write_active_last
) &&
2791 (p_this_ccw
->header
.flag
!=CLAW_PENDING
))) {
2792 /* The next CCW is OK or this is */
2793 /* the last CCW...free it @A1A */
2794 privptr
->p_write_active_first
=p_this_ccw
->next
;
2795 p_this_ccw
->header
.flag
=CLAW_PENDING
;
2796 p_this_ccw
->next
=privptr
->p_write_free_chain
;
2797 privptr
->p_write_free_chain
=p_this_ccw
;
2798 ++privptr
->write_free_count
;
2799 privptr
->stats
.tx_bytes
+= p_this_ccw
->write
.count
;
2800 p_this_ccw
=privptr
->p_write_active_first
;
2801 privptr
->stats
.tx_packets
++;
2807 if (privptr
->write_free_count
!=0) {
2808 claw_clearbit_busy(TB_NOBUFFER
,dev
);
2810 /* whole chain removed? */
2811 if (privptr
->p_write_active_first
==NULL
) {
2812 privptr
->p_write_active_last
=NULL
;
2814 CLAW_DBF_TEXT_(4, trace
, "FWC=%d", privptr
->write_free_count
);
2818 /*-------------------------------------------------------------------*
2819 * claw free netdevice *
2821 *--------------------------------------------------------------------*/
2823 claw_free_netdevice(struct net_device
* dev
, int free_dev
)
2825 struct claw_privbk
*privptr
;
2827 CLAW_DBF_TEXT(2, setup
, "free_dev");
2830 CLAW_DBF_TEXT_(2, setup
, "%s", dev
->name
);
2831 privptr
= dev
->ml_priv
;
2832 if (dev
->flags
& IFF_RUNNING
)
2835 privptr
->channel
[READ
].ndev
= NULL
; /* say it's free */
2837 dev
->ml_priv
= NULL
;
2843 CLAW_DBF_TEXT(2, setup
, "free_ok");
2847 * Claw init netdevice
2848 * Initialize everything of the net device except the name and the
2851 static const struct net_device_ops claw_netdev_ops
= {
2852 .ndo_open
= claw_open
,
2853 .ndo_stop
= claw_release
,
2854 .ndo_get_stats
= claw_stats
,
2855 .ndo_start_xmit
= claw_tx
,
2856 .ndo_change_mtu
= claw_change_mtu
,
2860 claw_init_netdevice(struct net_device
* dev
)
2862 CLAW_DBF_TEXT(2, setup
, "init_dev");
2863 CLAW_DBF_TEXT_(2, setup
, "%s", dev
->name
);
2864 dev
->mtu
= CLAW_DEFAULT_MTU_SIZE
;
2865 dev
->hard_header_len
= 0;
2867 dev
->type
= ARPHRD_SLIP
;
2868 dev
->tx_queue_len
= 1300;
2869 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
2870 dev
->netdev_ops
= &claw_netdev_ops
;
2871 CLAW_DBF_TEXT(2, setup
, "initok");
2876 * Init a new channel in the privptr->channel[i].
2878 * @param cdev The ccw_device to be added.
2880 * @return 0 on success, !0 on error.
2883 add_channel(struct ccw_device
*cdev
,int i
,struct claw_privbk
*privptr
)
2886 struct ccw_dev_id dev_id
;
2888 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cdev
->dev
));
2889 privptr
->channel
[i
].flag
= i
+1; /* Read is 1 Write is 2 */
2890 p_ch
= &privptr
->channel
[i
];
2892 snprintf(p_ch
->id
, CLAW_ID_SIZE
, "cl-%s", dev_name(&cdev
->dev
));
2893 ccw_device_get_id(cdev
, &dev_id
);
2894 p_ch
->devno
= dev_id
.devno
;
2895 if ((p_ch
->irb
= kzalloc(sizeof (struct irb
),GFP_KERNEL
)) == NULL
) {
2904 * Setup an interface.
2906 * @param cgdev Device to be setup.
2908 * @returns 0 on success, !0 on failure.
2911 claw_new_device(struct ccwgroup_device
*cgdev
)
2913 struct claw_privbk
*privptr
;
2914 struct claw_env
*p_env
;
2915 struct net_device
*dev
;
2917 struct ccw_dev_id dev_id
;
2919 dev_info(&cgdev
->dev
, "add for %s\n",
2920 dev_name(&cgdev
->cdev
[READ
]->dev
));
2921 CLAW_DBF_TEXT(2, setup
, "new_dev");
2922 privptr
= cgdev
->dev
.driver_data
;
2923 cgdev
->cdev
[READ
]->dev
.driver_data
= privptr
;
2924 cgdev
->cdev
[WRITE
]->dev
.driver_data
= privptr
;
2927 p_env
= privptr
->p_env
;
2928 ccw_device_get_id(cgdev
->cdev
[READ
], &dev_id
);
2929 p_env
->devno
[READ
] = dev_id
.devno
;
2930 ccw_device_get_id(cgdev
->cdev
[WRITE
], &dev_id
);
2931 p_env
->devno
[WRITE
] = dev_id
.devno
;
2932 ret
= add_channel(cgdev
->cdev
[0],0,privptr
);
2934 ret
= add_channel(cgdev
->cdev
[1],1,privptr
);
2936 dev_warn(&cgdev
->dev
, "Creating a CLAW group device"
2937 " failed with error code %d\n", ret
);
2940 ret
= ccw_device_set_online(cgdev
->cdev
[READ
]);
2942 dev_warn(&cgdev
->dev
,
2943 "Setting the read subchannel online"
2944 " failed with error code %d\n", ret
);
2947 ret
= ccw_device_set_online(cgdev
->cdev
[WRITE
]);
2949 dev_warn(&cgdev
->dev
,
2950 "Setting the write subchannel online "
2951 "failed with error code %d\n", ret
);
2954 dev
= alloc_netdev(0,"claw%d",claw_init_netdevice
);
2956 dev_warn(&cgdev
->dev
,
2957 "Activating the CLAW device failed\n");
2960 dev
->ml_priv
= privptr
;
2961 cgdev
->dev
.driver_data
= privptr
;
2962 cgdev
->cdev
[READ
]->dev
.driver_data
= privptr
;
2963 cgdev
->cdev
[WRITE
]->dev
.driver_data
= privptr
;
2965 SET_NETDEV_DEV(dev
, &cgdev
->dev
);
2966 if (register_netdev(dev
) != 0) {
2967 claw_free_netdevice(dev
, 1);
2968 CLAW_DBF_TEXT(2, trace
, "regfail");
2971 dev
->flags
&=~IFF_RUNNING
;
2972 if (privptr
->buffs_alloc
== 0) {
2973 ret
=init_ccw_bk(dev
);
2975 unregister_netdev(dev
);
2976 claw_free_netdevice(dev
,1);
2977 CLAW_DBF_TEXT(2, trace
, "ccwmem");
2981 privptr
->channel
[READ
].ndev
= dev
;
2982 privptr
->channel
[WRITE
].ndev
= dev
;
2983 privptr
->p_env
->ndev
= dev
;
2985 dev_info(&cgdev
->dev
, "%s:readsize=%d writesize=%d "
2986 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2987 dev
->name
, p_env
->read_size
,
2988 p_env
->write_size
, p_env
->read_buffers
,
2989 p_env
->write_buffers
, p_env
->devno
[READ
],
2990 p_env
->devno
[WRITE
]);
2991 dev_info(&cgdev
->dev
, "%s:host_name:%.8s, adapter_name "
2992 ":%.8s api_type: %.8s\n",
2993 dev
->name
, p_env
->host_name
,
2994 p_env
->adapter_name
, p_env
->api_type
);
2997 ccw_device_set_offline(cgdev
->cdev
[1]);
2998 ccw_device_set_offline(cgdev
->cdev
[0]);
3003 claw_purge_skb_queue(struct sk_buff_head
*q
)
3005 struct sk_buff
*skb
;
3007 CLAW_DBF_TEXT(4, trace
, "purgque");
3008 while ((skb
= skb_dequeue(q
))) {
3009 atomic_dec(&skb
->users
);
3010 dev_kfree_skb_any(skb
);
3015 * Shutdown an interface.
3017 * @param cgdev Device to be shut down.
3019 * @returns 0 on success, !0 on failure.
3022 claw_shutdown_device(struct ccwgroup_device
*cgdev
)
3024 struct claw_privbk
*priv
;
3025 struct net_device
*ndev
;
3028 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cgdev
->dev
));
3029 priv
= cgdev
->dev
.driver_data
;
3032 ndev
= priv
->channel
[READ
].ndev
;
3034 /* Close the device */
3035 dev_info(&cgdev
->dev
, "%s: shutting down \n",
3037 if (ndev
->flags
& IFF_RUNNING
)
3038 ret
= claw_release(ndev
);
3039 ndev
->flags
&=~IFF_RUNNING
;
3040 unregister_netdev(ndev
);
3041 ndev
->ml_priv
= NULL
; /* cgdev data, not ndev's to free */
3042 claw_free_netdevice(ndev
, 1);
3043 priv
->channel
[READ
].ndev
= NULL
;
3044 priv
->channel
[WRITE
].ndev
= NULL
;
3045 priv
->p_env
->ndev
= NULL
;
3047 ccw_device_set_offline(cgdev
->cdev
[1]);
3048 ccw_device_set_offline(cgdev
->cdev
[0]);
3053 claw_remove_device(struct ccwgroup_device
*cgdev
)
3055 struct claw_privbk
*priv
;
3058 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cgdev
->dev
));
3059 priv
= cgdev
->dev
.driver_data
;
3061 dev_info(&cgdev
->dev
, " will be removed.\n");
3062 if (cgdev
->state
== CCWGROUP_ONLINE
)
3063 claw_shutdown_device(cgdev
);
3064 claw_remove_files(&cgdev
->dev
);
3065 kfree(priv
->p_mtc_envelope
);
3066 priv
->p_mtc_envelope
=NULL
;
3069 kfree(priv
->channel
[0].irb
);
3070 priv
->channel
[0].irb
=NULL
;
3071 kfree(priv
->channel
[1].irb
);
3072 priv
->channel
[1].irb
=NULL
;
3074 cgdev
->dev
.driver_data
=NULL
;
3075 cgdev
->cdev
[READ
]->dev
.driver_data
= NULL
;
3076 cgdev
->cdev
[WRITE
]->dev
.driver_data
= NULL
;
3077 put_device(&cgdev
->dev
);
3087 claw_hname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3089 struct claw_privbk
*priv
;
3090 struct claw_env
* p_env
;
3092 priv
= dev
->driver_data
;
3095 p_env
= priv
->p_env
;
3096 return sprintf(buf
, "%s\n",p_env
->host_name
);
3100 claw_hname_write(struct device
*dev
, struct device_attribute
*attr
,
3101 const char *buf
, size_t count
)
3103 struct claw_privbk
*priv
;
3104 struct claw_env
* p_env
;
3106 priv
= dev
->driver_data
;
3109 p_env
= priv
->p_env
;
3110 if (count
> MAX_NAME_LEN
+1)
3112 memset(p_env
->host_name
, 0x20, MAX_NAME_LEN
);
3113 strncpy(p_env
->host_name
,buf
, count
);
3114 p_env
->host_name
[count
-1] = 0x20; /* clear extra 0x0a */
3115 p_env
->host_name
[MAX_NAME_LEN
] = 0x00;
3116 CLAW_DBF_TEXT(2, setup
, "HstnSet");
3117 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->host_name
);
3122 static DEVICE_ATTR(host_name
, 0644, claw_hname_show
, claw_hname_write
);
3125 claw_adname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3127 struct claw_privbk
*priv
;
3128 struct claw_env
* p_env
;
3130 priv
= dev
->driver_data
;
3133 p_env
= priv
->p_env
;
3134 return sprintf(buf
, "%s\n", p_env
->adapter_name
);
3138 claw_adname_write(struct device
*dev
, struct device_attribute
*attr
,
3139 const char *buf
, size_t count
)
3141 struct claw_privbk
*priv
;
3142 struct claw_env
* p_env
;
3144 priv
= dev
->driver_data
;
3147 p_env
= priv
->p_env
;
3148 if (count
> MAX_NAME_LEN
+1)
3150 memset(p_env
->adapter_name
, 0x20, MAX_NAME_LEN
);
3151 strncpy(p_env
->adapter_name
,buf
, count
);
3152 p_env
->adapter_name
[count
-1] = 0x20; /* clear extra 0x0a */
3153 p_env
->adapter_name
[MAX_NAME_LEN
] = 0x00;
3154 CLAW_DBF_TEXT(2, setup
, "AdnSet");
3155 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->adapter_name
);
3160 static DEVICE_ATTR(adapter_name
, 0644, claw_adname_show
, claw_adname_write
);
3163 claw_apname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3165 struct claw_privbk
*priv
;
3166 struct claw_env
* p_env
;
3168 priv
= dev
->driver_data
;
3171 p_env
= priv
->p_env
;
3172 return sprintf(buf
, "%s\n",
3177 claw_apname_write(struct device
*dev
, struct device_attribute
*attr
,
3178 const char *buf
, size_t count
)
3180 struct claw_privbk
*priv
;
3181 struct claw_env
* p_env
;
3183 priv
= dev
->driver_data
;
3186 p_env
= priv
->p_env
;
3187 if (count
> MAX_NAME_LEN
+1)
3189 memset(p_env
->api_type
, 0x20, MAX_NAME_LEN
);
3190 strncpy(p_env
->api_type
,buf
, count
);
3191 p_env
->api_type
[count
-1] = 0x20; /* we get a loose 0x0a */
3192 p_env
->api_type
[MAX_NAME_LEN
] = 0x00;
3193 if(strncmp(p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
3194 p_env
->read_size
=DEF_PACK_BUFSIZE
;
3195 p_env
->write_size
=DEF_PACK_BUFSIZE
;
3196 p_env
->packing
=PACKING_ASK
;
3197 CLAW_DBF_TEXT(2, setup
, "PACKING");
3201 p_env
->read_size
=CLAW_FRAME_SIZE
;
3202 p_env
->write_size
=CLAW_FRAME_SIZE
;
3203 CLAW_DBF_TEXT(2, setup
, "ApiSet");
3205 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->api_type
);
3209 static DEVICE_ATTR(api_type
, 0644, claw_apname_show
, claw_apname_write
);
3212 claw_wbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3214 struct claw_privbk
*priv
;
3215 struct claw_env
* p_env
;
3217 priv
= dev
->driver_data
;
3220 p_env
= priv
->p_env
;
3221 return sprintf(buf
, "%d\n", p_env
->write_buffers
);
3225 claw_wbuff_write(struct device
*dev
, struct device_attribute
*attr
,
3226 const char *buf
, size_t count
)
3228 struct claw_privbk
*priv
;
3229 struct claw_env
* p_env
;
3232 priv
= dev
->driver_data
;
3235 p_env
= priv
->p_env
;
3236 sscanf(buf
, "%i", &nnn
);
3237 if (p_env
->packing
) {
3243 if ((nnn
> max
) || (nnn
< 2))
3245 p_env
->write_buffers
= nnn
;
3246 CLAW_DBF_TEXT(2, setup
, "Wbufset");
3247 CLAW_DBF_TEXT_(2, setup
, "WB=%d", p_env
->write_buffers
);
3251 static DEVICE_ATTR(write_buffer
, 0644, claw_wbuff_show
, claw_wbuff_write
);
3254 claw_rbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3256 struct claw_privbk
*priv
;
3257 struct claw_env
* p_env
;
3259 priv
= dev
->driver_data
;
3262 p_env
= priv
->p_env
;
3263 return sprintf(buf
, "%d\n", p_env
->read_buffers
);
3267 claw_rbuff_write(struct device
*dev
, struct device_attribute
*attr
,
3268 const char *buf
, size_t count
)
3270 struct claw_privbk
*priv
;
3271 struct claw_env
*p_env
;
3274 priv
= dev
->driver_data
;
3277 p_env
= priv
->p_env
;
3278 sscanf(buf
, "%i", &nnn
);
3279 if (p_env
->packing
) {
3285 if ((nnn
> max
) || (nnn
< 2))
3287 p_env
->read_buffers
= nnn
;
3288 CLAW_DBF_TEXT(2, setup
, "Rbufset");
3289 CLAW_DBF_TEXT_(2, setup
, "RB=%d", p_env
->read_buffers
);
3293 static DEVICE_ATTR(read_buffer
, 0644, claw_rbuff_show
, claw_rbuff_write
);
3295 static struct attribute
*claw_attr
[] = {
3296 &dev_attr_read_buffer
.attr
,
3297 &dev_attr_write_buffer
.attr
,
3298 &dev_attr_adapter_name
.attr
,
3299 &dev_attr_api_type
.attr
,
3300 &dev_attr_host_name
.attr
,
3304 static struct attribute_group claw_attr_group
= {
3309 claw_add_files(struct device
*dev
)
3311 CLAW_DBF_TEXT(2, setup
, "add_file");
3312 return sysfs_create_group(&dev
->kobj
, &claw_attr_group
);
3316 claw_remove_files(struct device
*dev
)
3318 CLAW_DBF_TEXT(2, setup
, "rem_file");
3319 sysfs_remove_group(&dev
->kobj
, &claw_attr_group
);
3322 /*--------------------------------------------------------------------*
3323 * claw_init and cleanup *
3324 *---------------------------------------------------------------------*/
3329 unregister_cu3088_discipline(&claw_group_driver
);
3330 claw_unregister_debug_facility();
3331 pr_info("Driver unloaded\n");
3336 * Initialize module.
3337 * This is called just after the module is loaded.
3339 * @return 0 on success, !0 on error.
3346 pr_info("Loading %s\n", version
);
3347 ret
= claw_register_debug_facility();
3349 pr_err("Registering with the S/390 debug feature"
3350 " failed with error code %d\n", ret
);
3353 CLAW_DBF_TEXT(2, setup
, "init_mod");
3354 ret
= register_cu3088_discipline(&claw_group_driver
);
3356 CLAW_DBF_TEXT(2, setup
, "init_bad");
3357 claw_unregister_debug_facility();
3358 pr_err("Registering with the cu3088 device driver failed "
3359 "with error code %d\n", ret
);
3364 module_init(claw_init
);
3365 module_exit(claw_cleanup
);
3367 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3368 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3369 "Copyright 2000,2008 IBM Corporation\n");
3370 MODULE_LICENSE("GPL");