blob: a08b1682c8e852c216c0a6beafab2138f00a0d78 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
4 *
Frank Pavlic8e84c802005-09-06 15:03:09 +02005 * Linux for zSeries version
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (C) 2002,2005 IBM Corporation
7 * Author(s) Original code written by:
8 * Kazuo Iimura (iimura@jp.ibm.com)
9 * Rewritten by
10 * Andy Richter (richtera@us.ibm.com)
11 * Marc Price (mwprice@us.ibm.com)
12 *
13 * sysfs parms:
14 * group x.x.rrrr,x.x.wwww
15 * read_buffer nnnnnnn
16 * write_buffer nnnnnn
17 * host_name aaaaaaaa
18 * adapter_name aaaaaaaa
19 * api_type aaaaaaaa
20 *
21 * eg.
22 * group 0.0.0200 0.0.0201
23 * read_buffer 25
24 * write_buffer 20
25 * host_name LINUX390
26 * adapter_name RS6K
27 * api_type TCPIP
28 *
29 * where
30 *
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
33 * up to CLAW_MAX_DEV
34 *
35 * rrrr - the first of 2 consecutive device addresses used for the
36 * CLAW protocol.
37 * The specified address is always used as the input (Read)
38 * channel and the next address is used as the output channel.
39 *
40 * wwww - the second of 2 consecutive device addresses used for
41 * the CLAW protocol.
42 * The specified address is always used as the output
43 * channel and the previous address is used as the input channel.
44 *
45 * read_buffer - specifies number of input buffers to allocate.
46 * write_buffer - specifies number of output buffers to allocate.
47 * host_name - host name
48 * adaptor_name - adaptor name
49 * api_type - API type TCPIP or API will be sent and expected
50 * as ws_name
51 *
52 * Note the following requirements:
53 * 1) host_name must match the configured adapter_name on the remote side
54 * 2) adaptor_name must match the configured host name on the remote side
55 *
56 * Change History
57 * 1.00 Initial release shipped
58 * 1.10 Changes for Buffer allocation
59 * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
60 * 1.25 Added Packing support
Andy Richterb805da72008-07-18 15:24:56 +020061 * 1.5
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include <asm/ccwdev.h>
64#include <asm/ccwgroup.h>
65#include <asm/debug.h>
66#include <asm/idals.h>
67#include <asm/io.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070068#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#include <linux/ctype.h>
70#include <linux/delay.h>
71#include <linux/errno.h>
72#include <linux/if_arp.h>
73#include <linux/init.h>
74#include <linux/interrupt.h>
75#include <linux/ip.h>
76#include <linux/kernel.h>
77#include <linux/module.h>
78#include <linux/netdevice.h>
79#include <linux/etherdevice.h>
80#include <linux/proc_fs.h>
81#include <linux/sched.h>
82#include <linux/signal.h>
83#include <linux/skbuff.h>
84#include <linux/slab.h>
85#include <linux/string.h>
86#include <linux/tcp.h>
87#include <linux/timer.h>
88#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90#include "cu3088.h"
91#include "claw.h"
92
Andy Richterb805da72008-07-18 15:24:56 +020093/*
94 CLAW uses the s390dbf file system see claw_trace and claw_setup
Linus Torvalds1da177e2005-04-16 15:20:36 -070095*/
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Heiko Carstens2b67fc42007-02-05 21:16:47 +010098static char debug_buffer[255];
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/**
100 * Debug Facility Stuff
101 */
102static debug_info_t *claw_dbf_setup;
103static debug_info_t *claw_dbf_trace;
104
105/**
106 * CLAW Debug Facility functions
107 */
108static void
109claw_unregister_debug_facility(void)
110{
111 if (claw_dbf_setup)
112 debug_unregister(claw_dbf_setup);
113 if (claw_dbf_trace)
114 debug_unregister(claw_dbf_trace);
115}
116
117static int
118claw_register_debug_facility(void)
119{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700120 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
121 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 claw_unregister_debug_facility();
124 return -ENOMEM;
125 }
126 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
127 debug_set_level(claw_dbf_setup, 2);
128 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
129 debug_set_level(claw_dbf_trace, 2);
130 return 0;
131}
132
133static inline void
134claw_set_busy(struct net_device *dev)
135{
136 ((struct claw_privbk *) dev->priv)->tbusy=1;
137 eieio();
138}
139
140static inline void
141claw_clear_busy(struct net_device *dev)
142{
143 clear_bit(0, &(((struct claw_privbk *) dev->priv)->tbusy));
144 netif_wake_queue(dev);
145 eieio();
146}
147
148static inline int
149claw_check_busy(struct net_device *dev)
150{
151 eieio();
152 return ((struct claw_privbk *) dev->priv)->tbusy;
153}
154
155static inline void
156claw_setbit_busy(int nr,struct net_device *dev)
157{
158 netif_stop_queue(dev);
159 set_bit(nr, (void *)&(((struct claw_privbk *)dev->priv)->tbusy));
160}
161
162static inline void
163claw_clearbit_busy(int nr,struct net_device *dev)
164{
165 clear_bit(nr,(void *)&(((struct claw_privbk *)dev->priv)->tbusy));
166 netif_wake_queue(dev);
167}
168
169static inline int
170claw_test_and_setbit_busy(int nr,struct net_device *dev)
171{
172 netif_stop_queue(dev);
173 return test_and_set_bit(nr,
174 (void *)&(((struct claw_privbk *) dev->priv)->tbusy));
175}
176
177
178/* Functions for the DEV methods */
179
180static int claw_probe(struct ccwgroup_device *cgdev);
181static void claw_remove_device(struct ccwgroup_device *cgdev);
182static void claw_purge_skb_queue(struct sk_buff_head *q);
183static int claw_new_device(struct ccwgroup_device *cgdev);
184static int claw_shutdown_device(struct ccwgroup_device *cgdev);
185static int claw_tx(struct sk_buff *skb, struct net_device *dev);
186static int claw_change_mtu( struct net_device *dev, int new_mtu);
187static int claw_open(struct net_device *dev);
188static void claw_irq_handler(struct ccw_device *cdev,
189 unsigned long intparm, struct irb *irb);
190static void claw_irq_tasklet ( unsigned long data );
191static int claw_release(struct net_device *dev);
192static void claw_write_retry ( struct chbk * p_ch );
193static void claw_write_next ( struct chbk * p_ch );
194static void claw_timer ( struct chbk * p_ch );
195
196/* Functions */
197static int add_claw_reads(struct net_device *dev,
198 struct ccwbk* p_first, struct ccwbk* p_last);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100199static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
200static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static int find_link(struct net_device *dev, char *host_name, char *ws_name );
202static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
203static int init_ccw_bk(struct net_device *dev);
204static void probe_error( struct ccwgroup_device *cgdev);
205static struct net_device_stats *claw_stats(struct net_device *dev);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100206static int pages_to_order_of_mag(int num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208/* sysfs Functions */
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400209static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
210static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 const char *buf, size_t count);
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400212static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
213static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 const char *buf, size_t count);
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400215static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
216static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 const char *buf, size_t count);
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400218static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
219static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 const char *buf, size_t count);
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400221static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
222static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 const char *buf, size_t count);
224static int claw_add_files(struct device *dev);
225static void claw_remove_files(struct device *dev);
226
227/* Functions for System Validate */
228static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
229static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
230 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
231static int claw_snd_conn_req(struct net_device *dev, __u8 link);
232static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
233static int claw_snd_sys_validate_rsp(struct net_device *dev,
234 struct clawctl * p_ctl, __u32 return_code);
235static int claw_strt_conn_req(struct net_device *dev );
Andy Richterb805da72008-07-18 15:24:56 +0200236static void claw_strt_read(struct net_device *dev, int lock);
237static void claw_strt_out_IO(struct net_device *dev);
238static void claw_free_wrt_buf(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240/* Functions for unpack reads */
Andy Richterb805da72008-07-18 15:24:56 +0200241static void unpack_read(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243/* ccwgroup table */
244
245static struct ccwgroup_driver claw_group_driver = {
246 .owner = THIS_MODULE,
247 .name = "claw",
248 .max_slaves = 2,
249 .driver_id = 0xC3D3C1E6,
250 .probe = claw_probe,
251 .remove = claw_remove_device,
252 .set_online = claw_new_device,
253 .set_offline = claw_shutdown_device,
254};
255
256/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257* Key functions
258*/
259
260/*----------------------------------------------------------------*
261 * claw_probe *
262 * this function is called for each CLAW device. *
263 *----------------------------------------------------------------*/
264static int
265claw_probe(struct ccwgroup_device *cgdev)
266{
267 int rc;
268 struct claw_privbk *privptr=NULL;
269
Andy Richterb805da72008-07-18 15:24:56 +0200270 CLAW_DBF_TEXT(2, setup, "probe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 if (!get_device(&cgdev->dev))
272 return -ENODEV;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800273 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (privptr == NULL) {
275 probe_error(cgdev);
276 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200277 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 return -ENOMEM;
279 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700280 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
281 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
283 probe_error(cgdev);
284 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200285 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return -ENOMEM;
287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
289 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
290 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
291 privptr->p_env->packing = 0;
292 privptr->p_env->write_buffers = 5;
293 privptr->p_env->read_buffers = 5;
294 privptr->p_env->read_size = CLAW_FRAME_SIZE;
295 privptr->p_env->write_size = CLAW_FRAME_SIZE;
296 rc = claw_add_files(&cgdev->dev);
297 if (rc) {
298 probe_error(cgdev);
299 put_device(&cgdev->dev);
300 printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +0200301 cgdev->cdev[0]->dev.bus_id,__func__,__LINE__);
Andy Richterb805da72008-07-18 15:24:56 +0200302 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 return rc;
304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 privptr->p_env->p_priv = privptr;
306 cgdev->cdev[0]->handler = claw_irq_handler;
307 cgdev->cdev[1]->handler = claw_irq_handler;
308 cgdev->dev.driver_data = privptr;
Andy Richterb805da72008-07-18 15:24:56 +0200309 CLAW_DBF_TEXT(2, setup, "prbext 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 return 0;
312} /* end of claw_probe */
313
314/*-------------------------------------------------------------------*
315 * claw_tx *
316 *-------------------------------------------------------------------*/
317
318static int
319claw_tx(struct sk_buff *skb, struct net_device *dev)
320{
321 int rc;
322 struct claw_privbk *privptr=dev->priv;
323 unsigned long saveflags;
324 struct chbk *p_ch;
325
Andy Richterb805da72008-07-18 15:24:56 +0200326 CLAW_DBF_TEXT(4, trace, "claw_tx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 p_ch=&privptr->channel[WRITE];
328 if (skb == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 privptr->stats.tx_dropped++;
Andy Richterb805da72008-07-18 15:24:56 +0200330 privptr->stats.tx_errors++;
331 CLAW_DBF_TEXT_(2, trace, "clawtx%d", -EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return -EIO;
333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
335 rc=claw_hw_tx( skb, dev, 1 );
336 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200337 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 return rc;
339} /* end of claw_tx */
340
341/*------------------------------------------------------------------*
342 * pack the collect queue into an skb and return it *
343 * If not packing just return the top skb from the queue *
344 *------------------------------------------------------------------*/
345
346static struct sk_buff *
347claw_pack_skb(struct claw_privbk *privptr)
348{
349 struct sk_buff *new_skb,*held_skb;
350 struct chbk *p_ch = &privptr->channel[WRITE];
351 struct claw_env *p_env = privptr->p_env;
352 int pkt_cnt,pk_ind,so_far;
353
354 new_skb = NULL; /* assume no dice */
355 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200356 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700357 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 /* some data */
359 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200361 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 else
363 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200364 if (p_env->packing != DO_PACKED)
365 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 /* get a new SKB we will pack at least one */
367 new_skb = dev_alloc_skb(p_env->write_size);
368 if (new_skb == NULL) {
369 atomic_inc(&held_skb->users);
370 skb_queue_head(&p_ch->collect_queue,held_skb);
371 return NULL;
372 }
373 /* we have packed packet and a place to put it */
374 pk_ind = 1;
375 so_far = 0;
376 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
377 while ((pk_ind) && (held_skb != NULL)) {
378 if (held_skb->len+so_far <= p_env->write_size-8) {
379 memcpy(skb_put(new_skb,held_skb->len),
380 held_skb->data,held_skb->len);
381 privptr->stats.tx_packets++;
382 so_far += held_skb->len;
383 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200384 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 held_skb = skb_dequeue(&p_ch->collect_queue);
386 if (held_skb)
387 atomic_dec(&held_skb->users);
388 } else {
389 pk_ind = 0;
390 atomic_inc(&held_skb->users);
391 skb_queue_head(&p_ch->collect_queue,held_skb);
392 }
393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 }
Andy Richterb805da72008-07-18 15:24:56 +0200395 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 return new_skb;
397}
398
399/*-------------------------------------------------------------------*
400 * claw_change_mtu *
401 * *
402 *-------------------------------------------------------------------*/
403
404static int
405claw_change_mtu(struct net_device *dev, int new_mtu)
406{
407 struct claw_privbk *privptr=dev->priv;
408 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200409 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 buff_size = privptr->p_env->write_size;
411 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return -EINVAL;
413 }
414 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return 0;
416} /* end of claw_change_mtu */
417
418
419/*-------------------------------------------------------------------*
420 * claw_open *
421 * *
422 *-------------------------------------------------------------------*/
423static int
424claw_open(struct net_device *dev)
425{
426
427 int rc;
428 int i;
429 unsigned long saveflags=0;
430 unsigned long parm;
431 struct claw_privbk *privptr;
432 DECLARE_WAITQUEUE(wait, current);
433 struct timer_list timer;
434 struct ccwbk *p_buf;
435
Andy Richterb805da72008-07-18 15:24:56 +0200436 CLAW_DBF_TEXT(4, trace, "open");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 privptr = (struct claw_privbk *)dev->priv;
438 /* allocate and initialize CCW blocks */
439 if (privptr->buffs_alloc == 0) {
440 rc=init_ccw_bk(dev);
441 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200442 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return -ENOMEM;
444 }
445 }
446 privptr->system_validate_comp=0;
447 privptr->release_pend=0;
448 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
449 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
450 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
451 privptr->p_env->packing=PACKING_ASK;
452 } else {
453 privptr->p_env->packing=0;
454 privptr->p_env->read_size=CLAW_FRAME_SIZE;
455 privptr->p_env->write_size=CLAW_FRAME_SIZE;
456 }
457 claw_set_busy(dev);
458 tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
459 (unsigned long) &privptr->channel[READ]);
460 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200461 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 init_waitqueue_head(&privptr->channel[i].wait);
463 /* skb_queue_head_init(&p_ch->io_queue); */
464 if (i == WRITE)
465 skb_queue_head_init(
466 &privptr->channel[WRITE].collect_queue);
467 privptr->channel[i].flag_a = 0;
468 privptr->channel[i].IO_active = 0;
469 privptr->channel[i].flag &= ~CLAW_TIMER;
470 init_timer(&timer);
471 timer.function = (void *)claw_timer;
472 timer.data = (unsigned long)(&privptr->channel[i]);
473 timer.expires = jiffies + 15*HZ;
474 add_timer(&timer);
475 spin_lock_irqsave(get_ccwdev_lock(
476 privptr->channel[i].cdev), saveflags);
477 parm = (unsigned long) &privptr->channel[i];
478 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
479 rc = 0;
480 add_wait_queue(&privptr->channel[i].wait, &wait);
481 rc = ccw_device_halt(
482 (struct ccw_device *)privptr->channel[i].cdev,parm);
483 set_current_state(TASK_INTERRUPTIBLE);
484 spin_unlock_irqrestore(
485 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
486 schedule();
487 set_current_state(TASK_RUNNING);
488 remove_wait_queue(&privptr->channel[i].wait, &wait);
489 if(rc != 0)
490 ccw_check_return_code(privptr->channel[i].cdev, rc);
491 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
492 del_timer(&timer);
493 }
494 if ((((privptr->channel[READ].last_dstat |
495 privptr->channel[WRITE].last_dstat) &
496 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
497 (((privptr->channel[READ].flag |
498 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200500 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 for ( i = 0; i < 2; i++) {
503 spin_lock_irqsave(
504 get_ccwdev_lock(privptr->channel[i].cdev),
505 saveflags);
506 parm = (unsigned long) &privptr->channel[i];
507 privptr->channel[i].claw_state = CLAW_STOP;
508 rc = ccw_device_halt(
509 (struct ccw_device *)&privptr->channel[i].cdev,
510 parm);
511 spin_unlock_irqrestore(
512 get_ccwdev_lock(privptr->channel[i].cdev),
513 saveflags);
514 if (rc != 0) {
515 ccw_check_return_code(
516 privptr->channel[i].cdev, rc);
517 }
518 }
519 free_pages((unsigned long)privptr->p_buff_ccw,
520 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
521 if (privptr->p_env->read_size < PAGE_SIZE) {
522 free_pages((unsigned long)privptr->p_buff_read,
523 (int)pages_to_order_of_mag(
524 privptr->p_buff_read_num));
525 }
526 else {
527 p_buf=privptr->p_read_active_first;
528 while (p_buf!=NULL) {
529 free_pages((unsigned long)p_buf->p_buffer,
530 (int)pages_to_order_of_mag(
531 privptr->p_buff_pages_perread ));
532 p_buf=p_buf->next;
533 }
534 }
535 if (privptr->p_env->write_size < PAGE_SIZE ) {
536 free_pages((unsigned long)privptr->p_buff_write,
537 (int)pages_to_order_of_mag(
538 privptr->p_buff_write_num));
539 }
540 else {
541 p_buf=privptr->p_write_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_perwrite ));
546 p_buf=p_buf->next;
547 }
548 }
549 privptr->buffs_alloc = 0;
550 privptr->channel[READ].flag= 0x00;
551 privptr->channel[WRITE].flag = 0x00;
552 privptr->p_buff_ccw=NULL;
553 privptr->p_buff_read=NULL;
554 privptr->p_buff_write=NULL;
555 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200556 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return -EIO;
558 }
559
560 /* Send SystemValidate command */
561
562 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200563 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 return 0;
565} /* end of claw_open */
566
567/*-------------------------------------------------------------------*
568* *
569* claw_irq_handler *
570* *
571*--------------------------------------------------------------------*/
572static void
573claw_irq_handler(struct ccw_device *cdev,
574 unsigned long intparm, struct irb *irb)
575{
576 struct chbk *p_ch = NULL;
577 struct claw_privbk *privptr = NULL;
578 struct net_device *dev = NULL;
579 struct claw_env *p_env;
580 struct chbk *p_ch_r=NULL;
581
Andy Richterb805da72008-07-18 15:24:56 +0200582 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 /* Bypass all 'unsolicited interrupts' */
584 if (!cdev->dev.driver_data) {
585 printk(KERN_WARNING "claw: unsolicited interrupt for device:"
586 "%s received c-%02x d-%02x\n",
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200587 cdev->dev.bus_id, irb->scsw.cmd.cstat,
588 irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200589 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return;
591 }
592 privptr = (struct claw_privbk *)cdev->dev.driver_data;
593
594 /* Try to extract channel from driver data. */
595 if (privptr->channel[READ].cdev == cdev)
596 p_ch = &privptr->channel[READ];
597 else if (privptr->channel[WRITE].cdev == cdev)
598 p_ch = &privptr->channel[WRITE];
599 else {
600 printk(KERN_WARNING "claw: Can't determine channel for "
601 "interrupt, device %s\n", cdev->dev.bus_id);
Andy Richterb805da72008-07-18 15:24:56 +0200602 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 return;
604 }
Andy Richterb805da72008-07-18 15:24:56 +0200605 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 dev = (struct net_device *) (p_ch->ndev);
608 p_env=privptr->p_env;
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 /* Copy interruption response block. */
611 memcpy(p_ch->irb, irb, sizeof(struct irb));
612
Andy Richterb805da72008-07-18 15:24:56 +0200613 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200614 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 printk(KERN_INFO "%s: subchannel check for device: %04x -"
616 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
617 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200618 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
619 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200620 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 /* return; */
622 }
623
624 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200625 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200629 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200632 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
633 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
634 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
635 (p_ch->irb->scsw.cmd.stctl ==
636 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
637 return;
638 wake_up(&p_ch->wait); /* wake up claw_release */
639 CLAW_DBF_TEXT(4, trace, "stop");
640 return;
641 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
642 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
643 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
644 (p_ch->irb->scsw.cmd.stctl ==
645 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
646 CLAW_DBF_TEXT(4, trace, "haltio");
647 return;
648 }
649 if (p_ch->flag == CLAW_READ) {
650 p_ch->claw_state = CLAW_START_READ;
651 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
652 } else if (p_ch->flag == CLAW_WRITE) {
653 p_ch->claw_state = CLAW_START_WRITE;
654 /* send SYSTEM_VALIDATE */
655 claw_strt_read(dev, LOCK_NO);
656 claw_send_control(dev,
657 SYSTEM_VALIDATE_REQUEST,
658 0, 0, 0,
659 p_env->host_name,
660 p_env->adapter_name);
661 } else {
662 printk(KERN_WARNING "claw: unsolicited "
663 "interrupt for device:"
664 "%s received c-%02x d-%02x\n",
665 cdev->dev.bus_id,
666 irb->scsw.cmd.cstat,
667 irb->scsw.cmd.dstat);
668 return;
669 }
670 CLAW_DBF_TEXT(4, trace, "haltio");
671 return;
672 case CLAW_START_READ:
673 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
674 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
675 clear_bit(0, (void *)&p_ch->IO_active);
676 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
677 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
678 (p_ch->irb->ecw[0]) == 0) {
679 privptr->stats.rx_errors++;
680 printk(KERN_INFO "%s: Restart is "
681 "required after remote "
682 "side recovers \n",
683 dev->name);
684 }
685 CLAW_DBF_TEXT(4, trace, "notrdy");
686 return;
687 }
688 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
689 (p_ch->irb->scsw.cmd.dstat == 0)) {
690 if (test_and_set_bit(CLAW_BH_ACTIVE,
691 (void *)&p_ch->flag_a) == 0)
692 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 else
Andy Richterb805da72008-07-18 15:24:56 +0200694 CLAW_DBF_TEXT(4, trace, "PCINoBH");
695 CLAW_DBF_TEXT(4, trace, "PCI_read");
696 return;
697 }
698 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
699 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
700 (p_ch->irb->scsw.cmd.stctl ==
701 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
702 CLAW_DBF_TEXT(4, trace, "SPend_rd");
703 return;
704 }
705 clear_bit(0, (void *)&p_ch->IO_active);
706 claw_clearbit_busy(TB_RETRY, dev);
707 if (test_and_set_bit(CLAW_BH_ACTIVE,
708 (void *)&p_ch->flag_a) == 0)
709 tasklet_schedule(&p_ch->tasklet);
710 else
711 CLAW_DBF_TEXT(4, trace, "RdBHAct");
712 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
713 return;
714 case CLAW_START_WRITE:
715 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
716 printk(KERN_INFO "%s: Unit Check Occured in "
717 "write channel\n", dev->name);
718 clear_bit(0, (void *)&p_ch->IO_active);
719 if (p_ch->irb->ecw[0] & 0x80) {
720 printk(KERN_INFO "%s: Resetting Event "
721 "occurred:\n", dev->name);
722 init_timer(&p_ch->timer);
723 p_ch->timer.function =
724 (void *)claw_write_retry;
725 p_ch->timer.data = (unsigned long)p_ch;
726 p_ch->timer.expires = jiffies + 10*HZ;
727 add_timer(&p_ch->timer);
728 printk(KERN_INFO "%s: write connection "
729 "restarting\n", dev->name);
730 }
731 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
732 return;
733 }
734 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
735 clear_bit(0, (void *)&p_ch->IO_active);
736 printk(KERN_INFO "%s: Unit Exception "
737 "Occured in write channel\n",
738 dev->name);
739 }
740 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
741 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
742 (p_ch->irb->scsw.cmd.stctl ==
743 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
744 CLAW_DBF_TEXT(4, trace, "writeUE");
745 return;
746 }
747 clear_bit(0, (void *)&p_ch->IO_active);
748 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
749 claw_write_next(p_ch);
750 claw_clearbit_busy(TB_TX, dev);
751 claw_clear_busy(dev);
752 }
753 p_ch_r = (struct chbk *)&privptr->channel[READ];
754 if (test_and_set_bit(CLAW_BH_ACTIVE,
755 (void *)&p_ch_r->flag_a) == 0)
756 tasklet_schedule(&p_ch_r->tasklet);
757 CLAW_DBF_TEXT(4, trace, "StWtExit");
758 return;
759 default:
760 printk(KERN_WARNING "%s: wrong selection code - irq "
761 "state=%d\n", dev->name, p_ch->claw_state);
762 CLAW_DBF_TEXT(2, trace, "badIRQ");
763 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765
766} /* end of claw_irq_handler */
767
768
769/*-------------------------------------------------------------------*
770* claw_irq_tasklet *
771* *
772*--------------------------------------------------------------------*/
773static void
774claw_irq_tasklet ( unsigned long data )
775{
776 struct chbk * p_ch;
777 struct net_device *dev;
778 struct claw_privbk * privptr;
779
780 p_ch = (struct chbk *) data;
781 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200782 CLAW_DBF_TEXT(4, trace, "IRQtask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 privptr = (struct claw_privbk *) dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 unpack_read(dev);
785 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200786 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 return;
788} /* end of claw_irq_bh */
789
790/*-------------------------------------------------------------------*
791* claw_release *
792* *
793*--------------------------------------------------------------------*/
794static int
795claw_release(struct net_device *dev)
796{
797 int rc;
798 int i;
799 unsigned long saveflags;
800 unsigned long parm;
801 struct claw_privbk *privptr;
802 DECLARE_WAITQUEUE(wait, current);
803 struct ccwbk* p_this_ccw;
804 struct ccwbk* p_buf;
805
806 if (!dev)
807 return 0;
808 privptr = (struct claw_privbk *) dev->priv;
809 if (!privptr)
810 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200811 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 privptr->release_pend=1;
813 claw_setbit_busy(TB_STOP,dev);
814 for ( i = 1; i >=0 ; i--) {
815 spin_lock_irqsave(
816 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
817 /* del_timer(&privptr->channel[READ].timer); */
818 privptr->channel[i].claw_state = CLAW_STOP;
819 privptr->channel[i].IO_active = 0;
820 parm = (unsigned long) &privptr->channel[i];
821 if (i == WRITE)
822 claw_purge_skb_queue(
823 &privptr->channel[WRITE].collect_queue);
824 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
825 if (privptr->system_validate_comp==0x00) /* never opened? */
826 init_waitqueue_head(&privptr->channel[i].wait);
827 add_wait_queue(&privptr->channel[i].wait, &wait);
828 set_current_state(TASK_INTERRUPTIBLE);
829 spin_unlock_irqrestore(
830 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
831 schedule();
832 set_current_state(TASK_RUNNING);
833 remove_wait_queue(&privptr->channel[i].wait, &wait);
834 if (rc != 0) {
835 ccw_check_return_code(privptr->channel[i].cdev, rc);
836 }
837 }
838 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200839 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 privptr->pk_skb = NULL;
841 }
842 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200843 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return 0;
845 }
Andy Richterb805da72008-07-18 15:24:56 +0200846 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (privptr->p_buff_ccw != NULL) {
848 free_pages((unsigned long)privptr->p_buff_ccw,
849 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
850 }
Andy Richterb805da72008-07-18 15:24:56 +0200851 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 if (privptr->p_env->read_size < PAGE_SIZE) {
853 if (privptr->p_buff_read != NULL) {
854 free_pages((unsigned long)privptr->p_buff_read,
855 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
856 }
857 }
858 else {
859 p_buf=privptr->p_read_active_first;
860 while (p_buf!=NULL) {
861 free_pages((unsigned long)p_buf->p_buffer,
862 (int)pages_to_order_of_mag(
863 privptr->p_buff_pages_perread ));
864 p_buf=p_buf->next;
865 }
866 }
Andy Richterb805da72008-07-18 15:24:56 +0200867 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 if (privptr->p_env->write_size < PAGE_SIZE ) {
869 free_pages((unsigned long)privptr->p_buff_write,
870 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
871 }
872 else {
873 p_buf=privptr->p_write_active_first;
874 while (p_buf!=NULL) {
875 free_pages((unsigned long)p_buf->p_buffer,
876 (int)pages_to_order_of_mag(
877 privptr->p_buff_pages_perwrite ));
878 p_buf=p_buf->next;
879 }
880 }
Andy Richterb805da72008-07-18 15:24:56 +0200881 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 privptr->buffs_alloc = 0;
883 privptr->p_buff_ccw=NULL;
884 privptr->p_buff_read=NULL;
885 privptr->p_buff_write=NULL;
886 privptr->system_validate_comp=0;
887 privptr->release_pend=0;
888 /* Remove any writes that were pending and reset all reads */
889 p_this_ccw=privptr->p_read_active_first;
890 while (p_this_ccw!=NULL) {
891 p_this_ccw->header.length=0xffff;
892 p_this_ccw->header.opcode=0xff;
893 p_this_ccw->header.flag=0x00;
894 p_this_ccw=p_this_ccw->next;
895 }
896
897 while (privptr->p_write_active_first!=NULL) {
898 p_this_ccw=privptr->p_write_active_first;
899 p_this_ccw->header.flag=CLAW_PENDING;
900 privptr->p_write_active_first=p_this_ccw->next;
901 p_this_ccw->next=privptr->p_write_free_chain;
902 privptr->p_write_free_chain=p_this_ccw;
903 ++privptr->write_free_count;
904 }
905 privptr->p_write_active_last=NULL;
906 privptr->mtc_logical_link = -1;
907 privptr->mtc_skipping = 1;
908 privptr->mtc_offset=0;
909
910 if (((privptr->channel[READ].last_dstat |
911 privptr->channel[WRITE].last_dstat) &
912 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
913 printk(KERN_WARNING "%s: channel problems during close - "
914 "read: %02x - write: %02x\n",
915 dev->name,
916 privptr->channel[READ].last_dstat,
917 privptr->channel[WRITE].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200918 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
Andy Richterb805da72008-07-18 15:24:56 +0200920 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 return 0;
922} /* end of claw_release */
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924/*-------------------------------------------------------------------*
925* claw_write_retry *
926* *
927*--------------------------------------------------------------------*/
928
929static void
930claw_write_retry ( struct chbk *p_ch )
931{
932
933 struct net_device *dev=p_ch->ndev;
934
Andy Richterb805da72008-07-18 15:24:56 +0200935 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 return;
938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +0200940 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 return;
942} /* end of claw_write_retry */
943
944
945/*-------------------------------------------------------------------*
946* claw_write_next *
947* *
948*--------------------------------------------------------------------*/
949
950static void
951claw_write_next ( struct chbk * p_ch )
952{
953
954 struct net_device *dev;
955 struct claw_privbk *privptr=NULL;
956 struct sk_buff *pk_skb;
957 int rc;
958
Andy Richterb805da72008-07-18 15:24:56 +0200959 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (p_ch->claw_state == CLAW_STOP)
961 return;
962 dev = (struct net_device *) p_ch->ndev;
963 privptr = (struct claw_privbk *) dev->priv;
964 claw_free_wrt_buf( dev );
965 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -0700966 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 pk_skb = claw_pack_skb(privptr);
968 while (pk_skb != NULL) {
969 rc = claw_hw_tx( pk_skb, dev,1);
970 if (privptr->write_free_count > 0) {
971 pk_skb = claw_pack_skb(privptr);
972 } else
973 pk_skb = NULL;
974 }
975 }
976 if (privptr->p_write_active_first!=NULL) {
977 claw_strt_out_IO(dev);
978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 return;
980} /* end of claw_write_next */
981
982/*-------------------------------------------------------------------*
983* *
984* claw_timer *
985*--------------------------------------------------------------------*/
986
987static void
988claw_timer ( struct chbk * p_ch )
989{
Andy Richterb805da72008-07-18 15:24:56 +0200990 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 p_ch->flag |= CLAW_TIMER;
992 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 return;
994} /* end of claw_timer */
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996/*
997*
998* functions
999*/
1000
1001
1002/*-------------------------------------------------------------------*
1003* *
1004* pages_to_order_of_mag *
1005* *
1006* takes a number of pages from 1 to 512 and returns the *
1007* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1008* of magnitude get_free_pages() has an upper order of 9 *
1009*--------------------------------------------------------------------*/
1010
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001011static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012pages_to_order_of_mag(int num_of_pages)
1013{
1014 int order_of_mag=1; /* assume 2 pages */
1015 int nump=2;
Andy Richterb805da72008-07-18 15:24:56 +02001016
1017 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1019 /* 512 pages = 2Meg on 4k page systems */
1020 if (num_of_pages >= 512) {return 9; }
1021 /* we have two or more pages order is at least 1 */
1022 for (nump=2 ;nump <= 512;nump*=2) {
1023 if (num_of_pages <= nump)
1024 break;
1025 order_of_mag +=1;
1026 }
1027 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001028 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 return order_of_mag;
1030}
1031
1032/*-------------------------------------------------------------------*
1033* *
1034* add_claw_reads *
1035* *
1036*--------------------------------------------------------------------*/
1037static int
1038add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1039 struct ccwbk* p_last)
1040{
1041 struct claw_privbk *privptr;
1042 struct ccw1 temp_ccw;
1043 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001044 CLAW_DBF_TEXT(4, trace, "addreads");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 privptr = dev->priv;
1046 p_end = privptr->p_end_ccw;
1047
1048 /* first CCW and last CCW contains a new set of read channel programs
1049 * to apend the running channel programs
1050 */
1051 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001052 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 return 0;
1054 }
1055
1056 /* set up ending CCW sequence for this segment */
1057 if (p_end->read1) {
1058 p_end->read1=0x00; /* second ending CCW is now active */
1059 /* reset ending CCWs and setup TIC CCWs */
1060 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1061 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1062 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1063 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1064 p_end->read2_nop2.cda=0;
1065 p_end->read2_nop2.count=1;
1066 }
1067 else {
1068 p_end->read1=0x01; /* first ending CCW is now active */
1069 /* reset ending CCWs and setup TIC CCWs */
1070 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1071 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1072 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1073 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1074 p_end->read1_nop2.cda=0;
1075 p_end->read1_nop2.count=1;
1076 }
1077
1078 if ( privptr-> p_read_active_first ==NULL ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 privptr-> p_read_active_first= p_first; /* set new first */
1080 privptr-> p_read_active_last = p_last; /* set new last */
1081 }
1082 else {
1083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 /* set up TIC ccw */
1085 temp_ccw.cda= (__u32)__pa(&p_first->read);
1086 temp_ccw.count=0;
1087 temp_ccw.flags=0;
1088 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1089
1090
1091 if (p_end->read1) {
1092
1093 /* first set of CCW's is chained to the new read */
1094 /* chain, so the second set is chained to the active chain. */
1095 /* Therefore modify the second set to point to the new */
1096 /* read chain set up TIC CCWs */
1097 /* make sure we update the CCW so channel doesn't fetch it */
1098 /* when it's only half done */
1099 memcpy( &p_end->read2_nop2, &temp_ccw ,
1100 sizeof(struct ccw1));
1101 privptr->p_read_active_last->r_TIC_1.cda=
1102 (__u32)__pa(&p_first->read);
1103 privptr->p_read_active_last->r_TIC_2.cda=
1104 (__u32)__pa(&p_first->read);
1105 }
1106 else {
1107 /* make sure we update the CCW so channel doesn't */
1108 /* fetch it when it is only half done */
1109 memcpy( &p_end->read1_nop2, &temp_ccw ,
1110 sizeof(struct ccw1));
1111 privptr->p_read_active_last->r_TIC_1.cda=
1112 (__u32)__pa(&p_first->read);
1113 privptr->p_read_active_last->r_TIC_2.cda=
1114 (__u32)__pa(&p_first->read);
1115 }
1116 /* chain in new set of blocks */
1117 privptr->p_read_active_last->next = p_first;
1118 privptr->p_read_active_last=p_last;
1119 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001120 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 return 0;
1122} /* end of add_claw_reads */
1123
1124/*-------------------------------------------------------------------*
1125 * ccw_check_return_code *
1126 * *
1127 *-------------------------------------------------------------------*/
1128
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001129static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130ccw_check_return_code(struct ccw_device *cdev, int return_code)
1131{
Andy Richterb805da72008-07-18 15:24:56 +02001132 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 if (return_code != 0) {
1134 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001135 case -EBUSY: /* BUSY is a transient state no action needed */
1136 break;
1137 case -ENODEV:
1138 printk(KERN_EMERG "%s: Missing device called "
1139 "for IO ENODEV\n", cdev->dev.bus_id);
1140 break;
1141 case -EIO:
1142 printk(KERN_EMERG "%s: Status pending... EIO \n",
1143 cdev->dev.bus_id);
1144 break;
1145 case -EINVAL:
1146 printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
1147 cdev->dev.bus_id);
1148 break;
1149 default:
1150 printk(KERN_EMERG "%s: Unknown error in "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 "Do_IO %d\n",cdev->dev.bus_id, return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001152 }
1153 }
1154 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155} /* end of ccw_check_return_code */
1156
1157/*-------------------------------------------------------------------*
1158* ccw_check_unit_check *
1159*--------------------------------------------------------------------*/
1160
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001161static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1163{
Andy Richterb805da72008-07-18 15:24:56 +02001164 struct net_device *ndev = p_ch->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Andy Richterb805da72008-07-18 15:24:56 +02001166 CLAW_DBF_TEXT(4, trace, "unitchek");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
Andy Richterb805da72008-07-18 15:24:56 +02001168 ndev->name, sense);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 if (sense & 0x40) {
1171 if (sense & 0x01) {
1172 printk(KERN_WARNING "%s: Interface disconnect or "
1173 "Selective reset "
Andy Richterb805da72008-07-18 15:24:56 +02001174 "occurred (remote side)\n", ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
1176 else {
1177 printk(KERN_WARNING "%s: System reset occured"
Andy Richterb805da72008-07-18 15:24:56 +02001178 " (remote side)\n", ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 }
1180 }
1181 else if (sense & 0x20) {
1182 if (sense & 0x04) {
1183 printk(KERN_WARNING "%s: Data-streaming "
Andy Richterb805da72008-07-18 15:24:56 +02001184 "timeout)\n", ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 }
1186 else {
1187 printk(KERN_WARNING "%s: Data-transfer parity"
Andy Richterb805da72008-07-18 15:24:56 +02001188 " error\n", ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190 }
1191 else if (sense & 0x10) {
1192 if (sense & 0x20) {
1193 printk(KERN_WARNING "%s: Hardware malfunction "
Andy Richterb805da72008-07-18 15:24:56 +02001194 "(remote side)\n", ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 }
1196 else {
1197 printk(KERN_WARNING "%s: read-data parity error "
Andy Richterb805da72008-07-18 15:24:56 +02001198 "(remote side)\n", ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
1200 }
1201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202} /* end of ccw_check_unit_check */
1203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204/*-------------------------------------------------------------------*
1205* find_link *
1206*--------------------------------------------------------------------*/
1207static int
1208find_link(struct net_device *dev, char *host_name, char *ws_name )
1209{
1210 struct claw_privbk *privptr;
1211 struct claw_env *p_env;
1212 int rc=0;
1213
Andy Richterb805da72008-07-18 15:24:56 +02001214 CLAW_DBF_TEXT(2, setup, "findlink");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 privptr=dev->priv;
1216 p_env=privptr->p_env;
1217 switch (p_env->packing)
1218 {
1219 case PACKING_ASK:
1220 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1221 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1222 rc = EINVAL;
1223 break;
1224 case DO_PACKED:
1225 case PACK_SEND:
1226 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1227 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1228 rc = EINVAL;
1229 break;
1230 default:
1231 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1232 (memcmp(p_env->api_type , ws_name, 8)!=0))
1233 rc = EINVAL;
1234 break;
1235 }
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 return 0;
1238} /* end of find_link */
1239
1240/*-------------------------------------------------------------------*
1241 * claw_hw_tx *
1242 * *
1243 * *
1244 *-------------------------------------------------------------------*/
1245
1246static int
1247claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1248{
1249 int rc=0;
1250 struct claw_privbk *privptr;
1251 struct ccwbk *p_this_ccw;
1252 struct ccwbk *p_first_ccw;
1253 struct ccwbk *p_last_ccw;
1254 __u32 numBuffers;
1255 signed long len_of_data;
1256 unsigned long bytesInThisBuffer;
1257 unsigned char *pDataAddress;
1258 struct endccw *pEnd;
1259 struct ccw1 tempCCW;
1260 struct chbk *p_ch;
1261 struct claw_env *p_env;
1262 int lock;
1263 struct clawph *pk_head;
1264 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001265
1266 CLAW_DBF_TEXT(4, trace, "hw_tx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 privptr = (struct claw_privbk *) (dev->priv);
1268 p_ch=(struct chbk *)&privptr->channel[WRITE];
1269 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1271 /* scan the write queue to free any completed write packets */
1272 p_first_ccw=NULL;
1273 p_last_ccw=NULL;
1274 if ((p_env->packing >= PACK_SEND) &&
1275 (skb->cb[1] != 'P')) {
1276 skb_push(skb,sizeof(struct clawph));
1277 pk_head=(struct clawph *)skb->data;
1278 pk_head->len=skb->len-sizeof(struct clawph);
1279 if (pk_head->len%4) {
1280 pk_head->len+= 4-(pk_head->len%4);
1281 skb_pad(skb,4-(pk_head->len%4));
1282 skb_put(skb,4-(pk_head->len%4));
1283 }
1284 if (p_env->packing == DO_PACKED)
1285 pk_head->link_num = linkid;
1286 else
1287 pk_head->link_num = 0;
1288 pk_head->flag = 0x00;
1289 skb_pad(skb,4);
1290 skb->cb[1] = 'P';
1291 }
1292 if (linkid == 0) {
1293 if (claw_check_busy(dev)) {
1294 if (privptr->write_free_count!=0) {
1295 claw_clear_busy(dev);
1296 }
1297 else {
1298 claw_strt_out_IO(dev );
1299 claw_free_wrt_buf( dev );
1300 if (privptr->write_free_count==0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 ch = &privptr->channel[WRITE];
1302 atomic_inc(&skb->users);
1303 skb_queue_tail(&ch->collect_queue, skb);
1304 goto Done;
1305 }
1306 else {
1307 claw_clear_busy(dev);
1308 }
1309 }
1310 }
1311 /* tx lock */
1312 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 ch = &privptr->channel[WRITE];
1314 atomic_inc(&skb->users);
1315 skb_queue_tail(&ch->collect_queue, skb);
1316 claw_strt_out_IO(dev );
1317 rc=-EBUSY;
1318 goto Done2;
1319 }
1320 }
1321 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001322 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324 /* If that number of buffers isn't available, give up for now */
1325 if (privptr->write_free_count < numBuffers ||
1326 privptr->p_write_free_chain == NULL ) {
1327
1328 claw_setbit_busy(TB_NOBUFFER,dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 ch = &privptr->channel[WRITE];
1330 atomic_inc(&skb->users);
1331 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001332 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 goto Done2;
1334 }
1335 pDataAddress=skb->data;
1336 len_of_data=skb->len;
1337
1338 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1340 if (p_this_ccw == NULL) { /* lost the race */
1341 ch = &privptr->channel[WRITE];
1342 atomic_inc(&skb->users);
1343 skb_queue_tail(&ch->collect_queue, skb);
1344 goto Done2;
1345 }
1346 privptr->p_write_free_chain=p_this_ccw->next;
1347 p_this_ccw->next=NULL;
1348 --privptr->write_free_count; /* -1 */
1349 bytesInThisBuffer=len_of_data;
1350 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1351 len_of_data-=bytesInThisBuffer;
1352 pDataAddress+=(unsigned long)bytesInThisBuffer;
1353 /* setup write CCW */
1354 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1355 if (len_of_data>0) {
1356 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1357 }
1358 p_this_ccw->write.count=bytesInThisBuffer;
1359 /* now add to end of this chain */
1360 if (p_first_ccw==NULL) {
1361 p_first_ccw=p_this_ccw;
1362 }
1363 if (p_last_ccw!=NULL) {
1364 p_last_ccw->next=p_this_ccw;
1365 /* set up TIC ccws */
1366 p_last_ccw->w_TIC_1.cda=
1367 (__u32)__pa(&p_this_ccw->write);
1368 }
1369 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 }
1371
1372 /* FirstCCW and LastCCW now contain a new set of write channel
1373 * programs to append to the running channel program
1374 */
1375
1376 if (p_first_ccw!=NULL) {
1377 /* setup ending ccw sequence for this segment */
1378 pEnd=privptr->p_end_ccw;
1379 if (pEnd->write1) {
1380 pEnd->write1=0x00; /* second end ccw is now active */
1381 /* set up Tic CCWs */
1382 p_last_ccw->w_TIC_1.cda=
1383 (__u32)__pa(&pEnd->write2_nop1);
1384 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1385 pEnd->write2_nop2.flags =
1386 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1387 pEnd->write2_nop2.cda=0;
1388 pEnd->write2_nop2.count=1;
1389 }
1390 else { /* end of if (pEnd->write1)*/
1391 pEnd->write1=0x01; /* first end ccw is now active */
1392 /* set up Tic CCWs */
1393 p_last_ccw->w_TIC_1.cda=
1394 (__u32)__pa(&pEnd->write1_nop1);
1395 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1396 pEnd->write1_nop2.flags =
1397 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1398 pEnd->write1_nop2.cda=0;
1399 pEnd->write1_nop2.count=1;
1400 } /* end if if (pEnd->write1) */
1401
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 if (privptr->p_write_active_first==NULL ) {
1403 privptr->p_write_active_first=p_first_ccw;
1404 privptr->p_write_active_last=p_last_ccw;
1405 }
1406 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 /* set up Tic CCWs */
1408
1409 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1410 tempCCW.count=0;
1411 tempCCW.flags=0;
1412 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1413
1414 if (pEnd->write1) {
1415
1416 /*
1417 * first set of ending CCW's is chained to the new write
1418 * chain, so the second set is chained to the active chain
1419 * Therefore modify the second set to point the new write chain.
1420 * make sure we update the CCW atomically
1421 * so channel does not fetch it when it's only half done
1422 */
1423 memcpy( &pEnd->write2_nop2, &tempCCW ,
1424 sizeof(struct ccw1));
1425 privptr->p_write_active_last->w_TIC_1.cda=
1426 (__u32)__pa(&p_first_ccw->write);
1427 }
1428 else {
1429
1430 /*make sure we update the CCW atomically
1431 *so channel does not fetch it when it's only half done
1432 */
1433 memcpy(&pEnd->write1_nop2, &tempCCW ,
1434 sizeof(struct ccw1));
1435 privptr->p_write_active_last->w_TIC_1.cda=
1436 (__u32)__pa(&p_first_ccw->write);
1437
1438 } /* end if if (pEnd->write1) */
1439
1440 privptr->p_write_active_last->next=p_first_ccw;
1441 privptr->p_write_active_last=p_last_ccw;
1442 }
1443
1444 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001445 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 if (linkid==0) {
1447 lock=LOCK_NO;
1448 }
1449 else {
1450 lock=LOCK_YES;
1451 }
1452 claw_strt_out_IO(dev );
1453 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 if (privptr->write_free_count==0) {
1455 claw_setbit_busy(TB_NOBUFFER,dev);
1456 }
1457Done2:
1458 claw_clearbit_busy(TB_TX,dev);
1459Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 return(rc);
1461} /* end of claw_hw_tx */
1462
1463/*-------------------------------------------------------------------*
1464* *
1465* init_ccw_bk *
1466* *
1467*--------------------------------------------------------------------*/
1468
1469static int
1470init_ccw_bk(struct net_device *dev)
1471{
1472
1473 __u32 ccw_blocks_required;
1474 __u32 ccw_blocks_perpage;
1475 __u32 ccw_pages_required;
1476 __u32 claw_reads_perpage=1;
1477 __u32 claw_read_pages;
1478 __u32 claw_writes_perpage=1;
1479 __u32 claw_write_pages;
1480 void *p_buff=NULL;
1481 struct ccwbk*p_free_chain;
1482 struct ccwbk*p_buf;
1483 struct ccwbk*p_last_CCWB;
1484 struct ccwbk*p_first_CCWB;
1485 struct endccw *p_endccw=NULL;
1486 addr_t real_address;
1487 struct claw_privbk *privptr=dev->priv;
1488 struct clawh *pClawH=NULL;
1489 addr_t real_TIC_address;
1490 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001491 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493 /* initialize statistics field */
1494 privptr->active_link_ID=0;
1495 /* initialize ccwbk pointers */
1496 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1497 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1498 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1499 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1500 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1501 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1502 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1503 privptr->buffs_alloc = 0;
1504 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1505 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1506 /* initialize free write ccwbk counter */
1507 privptr->write_free_count=0; /* number of free bufs on write chain */
1508 p_last_CCWB = NULL;
1509 p_first_CCWB= NULL;
1510 /*
1511 * We need 1 CCW block for each read buffer, 1 for each
1512 * write buffer, plus 1 for ClawSignalBlock
1513 */
1514 ccw_blocks_required =
1515 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 /*
1517 * compute number of CCW blocks that will fit in a page
1518 */
1519 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1520 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001521 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 /*
1524 * read and write sizes are set by 2 constants in claw.h
1525 * 4k and 32k. Unpacked values other than 4k are not going to
1526 * provide good performance. With packing buffers support 32k
1527 * buffers are used.
1528 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001529 if (privptr->p_env->read_size < PAGE_SIZE) {
1530 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1531 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1532 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 }
1534 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001535 privptr->p_buff_pages_perread =
1536 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1537 claw_read_pages = privptr->p_env->read_buffers *
1538 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 }
1540 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001541 claw_writes_perpage =
1542 PAGE_SIZE / privptr->p_env->write_size;
1543 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1544 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
1546 }
1547 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001548 privptr->p_buff_pages_perwrite =
1549 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1550 claw_write_pages = privptr->p_env->write_buffers *
1551 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 /*
1554 * allocate ccw_pages_required
1555 */
1556 if (privptr->p_buff_ccw==NULL) {
1557 privptr->p_buff_ccw=
1558 (void *)__get_free_pages(__GFP_DMA,
1559 (int)pages_to_order_of_mag(ccw_pages_required ));
1560 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 return -ENOMEM;
1562 }
1563 privptr->p_buff_ccw_num=ccw_pages_required;
1564 }
1565 memset(privptr->p_buff_ccw, 0x00,
1566 privptr->p_buff_ccw_num * PAGE_SIZE);
1567
1568 /*
1569 * obtain ending ccw block address
1570 *
1571 */
1572 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1573 real_address = (__u32)__pa(privptr->p_end_ccw);
1574 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 p_endccw=privptr->p_end_ccw;
1576 p_endccw->real=real_address;
1577 p_endccw->write1=0x00;
1578 p_endccw->read1=0x00;
1579
1580 /* write1_nop1 */
1581 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1582 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1583 p_endccw->write1_nop1.count = 1;
1584 p_endccw->write1_nop1.cda = 0;
1585
1586 /* write1_nop2 */
1587 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1588 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1589 p_endccw->write1_nop2.count = 1;
1590 p_endccw->write1_nop2.cda = 0;
1591
1592 /* write2_nop1 */
1593 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1594 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1595 p_endccw->write2_nop1.count = 1;
1596 p_endccw->write2_nop1.cda = 0;
1597
1598 /* write2_nop2 */
1599 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1600 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1601 p_endccw->write2_nop2.count = 1;
1602 p_endccw->write2_nop2.cda = 0;
1603
1604 /* read1_nop1 */
1605 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1606 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1607 p_endccw->read1_nop1.count = 1;
1608 p_endccw->read1_nop1.cda = 0;
1609
1610 /* read1_nop2 */
1611 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1612 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1613 p_endccw->read1_nop2.count = 1;
1614 p_endccw->read1_nop2.cda = 0;
1615
1616 /* read2_nop1 */
1617 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1618 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1619 p_endccw->read2_nop1.count = 1;
1620 p_endccw->read2_nop1.cda = 0;
1621
1622 /* read2_nop2 */
1623 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1624 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1625 p_endccw->read2_nop2.count = 1;
1626 p_endccw->read2_nop2.cda = 0;
1627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 /*
1629 * Build a chain of CCWs
1630 *
1631 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 p_buff=privptr->p_buff_ccw;
1633
1634 p_free_chain=NULL;
1635 for (i=0 ; i < ccw_pages_required; i++ ) {
1636 real_address = (__u32)__pa(p_buff);
1637 p_buf=p_buff;
1638 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1639 p_buf->next = p_free_chain;
1640 p_free_chain = p_buf;
1641 p_buf->real=(__u32)__pa(p_buf);
1642 ++p_buf;
1643 }
1644 p_buff+=PAGE_SIZE;
1645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 /*
1647 * Initialize ClawSignalBlock
1648 *
1649 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 if (privptr->p_claw_signal_blk==NULL) {
1651 privptr->p_claw_signal_blk=p_free_chain;
1652 p_free_chain=p_free_chain->next;
1653 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1654 pClawH->length=0xffff;
1655 pClawH->opcode=0xff;
1656 pClawH->flag=CLAW_BUSY;
1657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 /*
1660 * allocate write_pages_required and add to free chain
1661 */
1662 if (privptr->p_buff_write==NULL) {
1663 if (privptr->p_env->write_size < PAGE_SIZE) {
1664 privptr->p_buff_write=
1665 (void *)__get_free_pages(__GFP_DMA,
1666 (int)pages_to_order_of_mag(claw_write_pages ));
1667 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 return -ENOMEM;
1670 }
1671 /*
1672 * Build CLAW write free chain
1673 *
1674 */
1675
1676 memset(privptr->p_buff_write, 0x00,
1677 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 privptr->p_write_free_chain=NULL;
1679
1680 p_buff=privptr->p_buff_write;
1681
1682 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1683 p_buf = p_free_chain; /* get a CCW */
1684 p_free_chain = p_buf->next;
1685 p_buf->next =privptr->p_write_free_chain;
1686 privptr->p_write_free_chain = p_buf;
1687 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1688 p_buf-> write.cda = (__u32)__pa(p_buff);
1689 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1690 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1691 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1692 p_buf-> w_read_FF.count = 1;
1693 p_buf-> w_read_FF.cda =
1694 (__u32)__pa(&p_buf-> header.flag);
1695 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1696 p_buf-> w_TIC_1.flags = 0;
1697 p_buf-> w_TIC_1.count = 0;
1698
1699 if (((unsigned long)p_buff+privptr->p_env->write_size) >=
1700 ((unsigned long)(p_buff+2*
1701 (privptr->p_env->write_size) -1) & PAGE_MASK)) {
1702 p_buff= p_buff+privptr->p_env->write_size;
1703 }
1704 }
1705 }
1706 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1707 {
1708 privptr->p_write_free_chain=NULL;
1709 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1710 p_buff=(void *)__get_free_pages(__GFP_DMA,
1711 (int)pages_to_order_of_mag(
1712 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 free_pages((unsigned long)privptr->p_buff_ccw,
1715 (int)pages_to_order_of_mag(
1716 privptr->p_buff_ccw_num));
1717 privptr->p_buff_ccw=NULL;
1718 p_buf=privptr->p_buff_write;
1719 while (p_buf!=NULL) {
1720 free_pages((unsigned long)
1721 p_buf->p_buffer,
1722 (int)pages_to_order_of_mag(
1723 privptr->p_buff_pages_perwrite));
1724 p_buf=p_buf->next;
1725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 return -ENOMEM;
1727 } /* Error on get_pages */
1728 memset(p_buff, 0x00, privptr->p_env->write_size );
1729 p_buf = p_free_chain;
1730 p_free_chain = p_buf->next;
1731 p_buf->next = privptr->p_write_free_chain;
1732 privptr->p_write_free_chain = p_buf;
1733 privptr->p_buff_write = p_buf;
1734 p_buf->p_buffer=(struct clawbuf *)p_buff;
1735 p_buf-> write.cda = (__u32)__pa(p_buff);
1736 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1737 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1738 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1739 p_buf-> w_read_FF.count = 1;
1740 p_buf-> w_read_FF.cda =
1741 (__u32)__pa(&p_buf-> header.flag);
1742 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1743 p_buf-> w_TIC_1.flags = 0;
1744 p_buf-> w_TIC_1.count = 0;
1745 } /* for all write_buffers */
1746
1747 } /* else buffers are PAGE_SIZE or bigger */
1748
1749 }
1750 privptr->p_buff_write_num=claw_write_pages;
1751 privptr->write_free_count=privptr->p_env->write_buffers;
1752
1753
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 /*
1755 * allocate read_pages_required and chain to free chain
1756 */
1757 if (privptr->p_buff_read==NULL) {
1758 if (privptr->p_env->read_size < PAGE_SIZE) {
1759 privptr->p_buff_read=
1760 (void *)__get_free_pages(__GFP_DMA,
1761 (int)pages_to_order_of_mag(claw_read_pages) );
1762 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 free_pages((unsigned long)privptr->p_buff_ccw,
1764 (int)pages_to_order_of_mag(
1765 privptr->p_buff_ccw_num));
1766 /* free the write pages size is < page size */
1767 free_pages((unsigned long)privptr->p_buff_write,
1768 (int)pages_to_order_of_mag(
1769 privptr->p_buff_write_num));
1770 privptr->p_buff_ccw=NULL;
1771 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 return -ENOMEM;
1773 }
1774 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1775 privptr->p_buff_read_num=claw_read_pages;
1776 /*
1777 * Build CLAW read free chain
1778 *
1779 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 p_buff=privptr->p_buff_read;
1781 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1782 p_buf = p_free_chain;
1783 p_free_chain = p_buf->next;
1784
1785 if (p_last_CCWB==NULL) {
1786 p_buf->next=NULL;
1787 real_TIC_address=0;
1788 p_last_CCWB=p_buf;
1789 }
1790 else {
1791 p_buf->next=p_first_CCWB;
1792 real_TIC_address=
1793 (__u32)__pa(&p_first_CCWB -> read );
1794 }
1795
1796 p_first_CCWB=p_buf;
1797
1798 p_buf->p_buffer=(struct clawbuf *)p_buff;
1799 /* initialize read command */
1800 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1801 p_buf-> read.cda = (__u32)__pa(p_buff);
1802 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1803 p_buf-> read.count = privptr->p_env->read_size;
1804
1805 /* initialize read_h command */
1806 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1807 p_buf-> read_h.cda =
1808 (__u32)__pa(&(p_buf->header));
1809 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1810 p_buf-> read_h.count = sizeof(struct clawh);
1811
1812 /* initialize Signal command */
1813 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1814 p_buf-> signal.cda =
1815 (__u32)__pa(&(pClawH->flag));
1816 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1817 p_buf-> signal.count = 1;
1818
1819 /* initialize r_TIC_1 command */
1820 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1821 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1822 p_buf-> r_TIC_1.flags = 0;
1823 p_buf-> r_TIC_1.count = 0;
1824
1825 /* initialize r_read_FF command */
1826 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1827 p_buf-> r_read_FF.cda =
1828 (__u32)__pa(&(pClawH->flag));
1829 p_buf-> r_read_FF.flags =
1830 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1831 p_buf-> r_read_FF.count = 1;
1832
1833 /* initialize r_TIC_2 */
1834 memcpy(&p_buf->r_TIC_2,
1835 &p_buf->r_TIC_1, sizeof(struct ccw1));
1836
1837 /* initialize Header */
1838 p_buf->header.length=0xffff;
1839 p_buf->header.opcode=0xff;
1840 p_buf->header.flag=CLAW_PENDING;
1841
1842 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1843 ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
1844 & PAGE_MASK) ) {
1845 p_buff= p_buff+privptr->p_env->read_size;
1846 }
1847 else {
1848 p_buff=
1849 (void *)((unsigned long)
1850 (p_buff+2*(privptr->p_env->read_size) -1)
1851 & PAGE_MASK) ;
1852 }
1853 } /* for read_buffers */
1854 } /* read_size < PAGE_SIZE */
1855 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1857 p_buff = (void *)__get_free_pages(__GFP_DMA,
1858 (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
1859 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 free_pages((unsigned long)privptr->p_buff_ccw,
1861 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
1862 /* free the write pages */
1863 p_buf=privptr->p_buff_write;
1864 while (p_buf!=NULL) {
1865 free_pages((unsigned long)p_buf->p_buffer,
1866 (int)pages_to_order_of_mag(
1867 privptr->p_buff_pages_perwrite ));
1868 p_buf=p_buf->next;
1869 }
1870 /* free any read pages already alloc */
1871 p_buf=privptr->p_buff_read;
1872 while (p_buf!=NULL) {
1873 free_pages((unsigned long)p_buf->p_buffer,
1874 (int)pages_to_order_of_mag(
1875 privptr->p_buff_pages_perread ));
1876 p_buf=p_buf->next;
1877 }
1878 privptr->p_buff_ccw=NULL;
1879 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 return -ENOMEM;
1881 }
1882 memset(p_buff, 0x00, privptr->p_env->read_size);
1883 p_buf = p_free_chain;
1884 privptr->p_buff_read = p_buf;
1885 p_free_chain = p_buf->next;
1886
1887 if (p_last_CCWB==NULL) {
1888 p_buf->next=NULL;
1889 real_TIC_address=0;
1890 p_last_CCWB=p_buf;
1891 }
1892 else {
1893 p_buf->next=p_first_CCWB;
1894 real_TIC_address=
1895 (addr_t)__pa(
1896 &p_first_CCWB -> read );
1897 }
1898
1899 p_first_CCWB=p_buf;
1900 /* save buff address */
1901 p_buf->p_buffer=(struct clawbuf *)p_buff;
1902 /* initialize read command */
1903 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1904 p_buf-> read.cda = (__u32)__pa(p_buff);
1905 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1906 p_buf-> read.count = privptr->p_env->read_size;
1907
1908 /* initialize read_h command */
1909 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1910 p_buf-> read_h.cda =
1911 (__u32)__pa(&(p_buf->header));
1912 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1913 p_buf-> read_h.count = sizeof(struct clawh);
1914
1915 /* initialize Signal command */
1916 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1917 p_buf-> signal.cda =
1918 (__u32)__pa(&(pClawH->flag));
1919 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1920 p_buf-> signal.count = 1;
1921
1922 /* initialize r_TIC_1 command */
1923 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1924 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1925 p_buf-> r_TIC_1.flags = 0;
1926 p_buf-> r_TIC_1.count = 0;
1927
1928 /* initialize r_read_FF command */
1929 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1930 p_buf-> r_read_FF.cda =
1931 (__u32)__pa(&(pClawH->flag));
1932 p_buf-> r_read_FF.flags =
1933 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1934 p_buf-> r_read_FF.count = 1;
1935
1936 /* initialize r_TIC_2 */
1937 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1938 sizeof(struct ccw1));
1939
1940 /* initialize Header */
1941 p_buf->header.length=0xffff;
1942 p_buf->header.opcode=0xff;
1943 p_buf->header.flag=CLAW_PENDING;
1944
1945 } /* For read_buffers */
1946 } /* read_size >= PAGE_SIZE */
1947 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1949 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02001950
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 return 0;
1952} /* end of init_ccw_bk */
1953
1954/*-------------------------------------------------------------------*
1955* *
1956* probe_error *
1957* *
1958*--------------------------------------------------------------------*/
1959
1960static void
1961probe_error( struct ccwgroup_device *cgdev)
1962{
1963 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02001964
1965 CLAW_DBF_TEXT(4, trace, "proberr");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 privptr=(struct claw_privbk *)cgdev->dev.driver_data;
1967 if (privptr!=NULL) {
Jesper Juhl17fd6822005-11-07 01:01:30 -08001968 kfree(privptr->p_env);
1969 privptr->p_env=NULL;
1970 kfree(privptr->p_mtc_envelope);
1971 privptr->p_mtc_envelope=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 kfree(privptr);
1973 privptr=NULL;
1974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 return;
1976} /* probe_error */
1977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978/*-------------------------------------------------------------------*
1979* claw_process_control *
1980* *
1981* *
1982*--------------------------------------------------------------------*/
1983
1984static int
1985claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
1986{
1987
1988 struct clawbuf *p_buf;
1989 struct clawctl ctlbk;
1990 struct clawctl *p_ctlbk;
1991 char temp_host_name[8];
1992 char temp_ws_name[8];
1993 struct claw_privbk *privptr;
1994 struct claw_env *p_env;
1995 struct sysval *p_sysval;
1996 struct conncmd *p_connect=NULL;
1997 int rc;
1998 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02001999 struct device *tdev;
2000 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 udelay(1000); /* Wait a ms for the control packets to
2002 *catch up to each other */
2003 privptr=dev->priv;
2004 p_env=privptr->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02002005 tdev = &privptr->channel[READ].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 memcpy( &temp_host_name, p_env->host_name, 8);
2007 memcpy( &temp_ws_name, p_env->adapter_name , 8);
2008 printk(KERN_INFO "%s: CLAW device %.8s: "
2009 "Received Control Packet\n",
2010 dev->name, temp_ws_name);
2011 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 return 0;
2013 }
2014 p_buf=p_ccw->p_buffer;
2015 p_ctlbk=&ctlbk;
2016 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2017 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2018 } else {
2019 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2020 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 switch (p_ctlbk->command)
2022 {
Andy Richterb805da72008-07-18 15:24:56 +02002023 case SYSTEM_VALIDATE_REQUEST:
2024 if (p_ctlbk->version != CLAW_VERSION_ID) {
2025 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2026 CLAW_RC_WRONG_VERSION);
2027 printk("%s: %d is wrong version id. "
2028 "Expected %d\n",
2029 dev->name, p_ctlbk->version,
2030 CLAW_VERSION_ID);
2031 }
2032 p_sysval = (struct sysval *)&(p_ctlbk->data);
2033 printk("%s: Recv Sys Validate Request: "
2034 "Vers=%d,link_id=%d,Corr=%d,WS name=%."
2035 "8s,Host name=%.8s\n",
2036 dev->name, p_ctlbk->version,
2037 p_ctlbk->linkid,
2038 p_ctlbk->correlator,
2039 p_sysval->WS_name,
2040 p_sysval->host_name);
2041 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2042 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2043 CLAW_RC_NAME_MISMATCH);
2044 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2045 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2046 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
2047 printk(KERN_INFO "%s: Host name mismatch\n",
2048 dev->name);
2049 printk(KERN_INFO "%s: Received :%s: "
2050 "expected :%s: \n",
2051 dev->name,
2052 p_sysval->host_name,
2053 temp_host_name);
2054 }
2055 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2056 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2057 CLAW_RC_NAME_MISMATCH);
2058 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2059 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2060 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
2061 printk(KERN_INFO "%s: WS name mismatch\n",
2062 dev->name);
2063 printk(KERN_INFO "%s: Received :%s: "
2064 "expected :%s: \n",
2065 dev->name,
2066 p_sysval->WS_name,
2067 temp_ws_name);
2068 }
2069 if ((p_sysval->write_frame_size < p_env->write_size) &&
2070 (p_env->packing == 0)) {
2071 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2072 CLAW_RC_HOST_RCV_TOO_SMALL);
2073 printk(KERN_INFO "%s: host write size is too "
2074 "small\n", dev->name);
2075 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2076 }
2077 if ((p_sysval->read_frame_size < p_env->read_size) &&
2078 (p_env->packing == 0)) {
2079 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2080 CLAW_RC_HOST_RCV_TOO_SMALL);
2081 printk(KERN_INFO "%s: host read size is too "
2082 "small\n", dev->name);
2083 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2084 }
2085 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
2086 printk(KERN_INFO "%s: CLAW device %.8s: System validate "
2087 "completed.\n", dev->name, temp_ws_name);
2088 printk("%s: sys Validate Rsize:%d Wsize:%d\n", dev->name,
2089 p_sysval->read_frame_size, p_sysval->write_frame_size);
2090 privptr->system_validate_comp = 1;
2091 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2092 p_env->packing = PACKING_ASK;
2093 claw_strt_conn_req(dev);
2094 break;
2095 case SYSTEM_VALIDATE_RESPONSE:
2096 p_sysval = (struct sysval *)&(p_ctlbk->data);
2097 printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
2098 "WS name=%.8s,Host name=%.8s\n",
2099 dev->name,
2100 p_ctlbk->version,
2101 p_ctlbk->correlator,
2102 p_ctlbk->rc,
2103 p_sysval->WS_name,
2104 p_sysval->host_name);
2105 switch (p_ctlbk->rc) {
2106 case 0:
2107 printk(KERN_INFO "%s: CLAW device "
2108 "%.8s: System validate "
2109 "completed.\n",
2110 dev->name, temp_ws_name);
2111 if (privptr->system_validate_comp == 0)
2112 claw_strt_conn_req(dev);
2113 privptr->system_validate_comp = 1;
2114 break;
2115 case CLAW_RC_NAME_MISMATCH:
2116 printk(KERN_INFO "%s: Sys Validate "
2117 "Resp : Host, WS name is "
2118 "mismatch\n",
2119 dev->name);
2120 break;
2121 case CLAW_RC_WRONG_VERSION:
2122 printk(KERN_INFO "%s: Sys Validate "
2123 "Resp : Wrong version\n",
2124 dev->name);
2125 break;
2126 case CLAW_RC_HOST_RCV_TOO_SMALL:
2127 printk(KERN_INFO "%s: Sys Validate "
2128 "Resp : bad frame size\n",
2129 dev->name);
2130 break;
2131 default:
2132 printk(KERN_INFO "%s: Sys Validate "
2133 "error code=%d \n",
2134 dev->name, p_ctlbk->rc);
2135 break;
2136 }
2137 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Andy Richterb805da72008-07-18 15:24:56 +02002139 case CONNECTION_REQUEST:
2140 p_connect = (struct conncmd *)&(p_ctlbk->data);
2141 printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2142 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2143 dev->name,
2144 p_ctlbk->version,
2145 p_ctlbk->linkid,
2146 p_ctlbk->correlator,
2147 p_connect->host_name,
2148 p_connect->WS_name);
2149 if (privptr->active_link_ID != 0) {
2150 claw_snd_disc(dev, p_ctlbk);
2151 printk(KERN_INFO "%s: Conn Req error : "
2152 "already logical link is active \n",
2153 dev->name);
2154 }
2155 if (p_ctlbk->linkid != 1) {
2156 claw_snd_disc(dev, p_ctlbk);
2157 printk(KERN_INFO "%s: Conn Req error : "
2158 "req logical link id is not 1\n",
2159 dev->name);
2160 }
2161 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2162 if (rc != 0) {
2163 claw_snd_disc(dev, p_ctlbk);
2164 printk(KERN_INFO "%s: Conn Resp error: "
2165 "req appl name does not match\n",
2166 dev->name);
2167 }
2168 claw_send_control(dev,
2169 CONNECTION_CONFIRM, p_ctlbk->linkid,
2170 p_ctlbk->correlator,
2171 0, p_connect->host_name,
2172 p_connect->WS_name);
2173 if (p_env->packing == PACKING_ASK) {
2174 p_env->packing = PACK_SEND;
2175 claw_snd_conn_req(dev, 0);
2176 }
2177 printk(KERN_INFO "%s: CLAW device %.8s: Connection "
2178 "completed link_id=%d.\n",
2179 dev->name, temp_ws_name,
2180 p_ctlbk->linkid);
2181 privptr->active_link_ID = p_ctlbk->linkid;
2182 p_ch = &privptr->channel[WRITE];
2183 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2184 break;
2185 case CONNECTION_RESPONSE:
2186 p_connect = (struct conncmd *)&(p_ctlbk->data);
2187 printk(KERN_INFO "%s: Revc Conn Resp: Vers=%d,link_id=%d,"
2188 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2189 dev->name,
2190 p_ctlbk->version,
2191 p_ctlbk->linkid,
2192 p_ctlbk->correlator,
2193 p_ctlbk->rc,
2194 p_connect->host_name,
2195 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
Andy Richterb805da72008-07-18 15:24:56 +02002197 if (p_ctlbk->rc != 0) {
2198 printk(KERN_INFO "%s: Conn Resp error: rc=%d \n",
2199 dev->name, p_ctlbk->rc);
2200 return 1;
2201 }
2202 rc = find_link(dev,
2203 p_connect->host_name, p_connect->WS_name);
2204 if (rc != 0) {
2205 claw_snd_disc(dev, p_ctlbk);
2206 printk(KERN_INFO "%s: Conn Resp error: "
2207 "req appl name does not match\n",
2208 dev->name);
2209 }
2210 /* should be until CONNECTION_CONFIRM */
2211 privptr->active_link_ID = -(p_ctlbk->linkid);
2212 break;
2213 case CONNECTION_CONFIRM:
2214 p_connect = (struct conncmd *)&(p_ctlbk->data);
2215 printk(KERN_INFO "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2216 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2217 dev->name,
2218 p_ctlbk->version,
2219 p_ctlbk->linkid,
2220 p_ctlbk->correlator,
2221 p_connect->host_name,
2222 p_connect->WS_name);
2223 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2224 privptr->active_link_ID = p_ctlbk->linkid;
2225 if (p_env->packing > PACKING_ASK) {
2226 printk(KERN_INFO "%s: Confirmed Now packing\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 p_env->packing = DO_PACKED;
2229 }
Andy Richterb805da72008-07-18 15:24:56 +02002230 p_ch = &privptr->channel[WRITE];
2231 wake_up(&p_ch->wait);
2232 } else {
2233 printk(KERN_INFO "%s: Conn confirm: "
2234 "unexpected linkid=%d \n",
2235 dev->name, p_ctlbk->linkid);
2236 claw_snd_disc(dev, p_ctlbk);
2237 }
2238 break;
2239 case DISCONNECT:
2240 printk(KERN_INFO "%s: Disconnect: "
2241 "Vers=%d,link_id=%d,Corr=%d\n",
2242 dev->name, p_ctlbk->version,
2243 p_ctlbk->linkid, p_ctlbk->correlator);
2244 if ((p_ctlbk->linkid == 2) &&
2245 (p_env->packing == PACK_SEND)) {
2246 privptr->active_link_ID = 1;
2247 p_env->packing = DO_PACKED;
2248 } else
2249 privptr->active_link_ID = 0;
2250 break;
2251 case CLAW_ERROR:
2252 printk(KERN_INFO "%s: CLAW ERROR detected\n",
2253 dev->name);
2254 break;
2255 default:
2256 printk(KERN_INFO "%s: Unexpected command code=%d \n",
2257 dev->name, p_ctlbk->command);
2258 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 }
2260
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 return 0;
2262} /* end of claw_process_control */
2263
2264
2265/*-------------------------------------------------------------------*
2266* claw_send_control *
2267* *
2268*--------------------------------------------------------------------*/
2269
2270static int
2271claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2272 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2273{
2274 struct claw_privbk *privptr;
2275 struct clawctl *p_ctl;
2276 struct sysval *p_sysval;
2277 struct conncmd *p_connect;
2278 struct sk_buff *skb;
2279
Andy Richterb805da72008-07-18 15:24:56 +02002280 CLAW_DBF_TEXT(2, setup, "sndcntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 privptr=dev->priv;
2282 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2283
2284 p_ctl->command=type;
2285 p_ctl->version=CLAW_VERSION_ID;
2286 p_ctl->linkid=link;
2287 p_ctl->correlator=correlator;
2288 p_ctl->rc=rc;
2289
2290 p_sysval=(struct sysval *)&p_ctl->data;
2291 p_connect=(struct conncmd *)&p_ctl->data;
2292
2293 switch (p_ctl->command) {
2294 case SYSTEM_VALIDATE_REQUEST:
2295 case SYSTEM_VALIDATE_RESPONSE:
2296 memcpy(&p_sysval->host_name, local_name, 8);
2297 memcpy(&p_sysval->WS_name, remote_name, 8);
2298 if (privptr->p_env->packing > 0) {
2299 p_sysval->read_frame_size=DEF_PACK_BUFSIZE;
2300 p_sysval->write_frame_size=DEF_PACK_BUFSIZE;
2301 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002302 /* how big is the biggest group of packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 p_sysval->read_frame_size=privptr->p_env->read_size;
2304 p_sysval->write_frame_size=privptr->p_env->write_size;
2305 }
2306 memset(&p_sysval->reserved, 0x00, 4);
2307 break;
2308 case CONNECTION_REQUEST:
2309 case CONNECTION_RESPONSE:
2310 case CONNECTION_CONFIRM:
2311 case DISCONNECT:
2312 memcpy(&p_sysval->host_name, local_name, 8);
2313 memcpy(&p_sysval->WS_name, remote_name, 8);
2314 if (privptr->p_env->packing > 0) {
2315 /* How big is the biggest packet */
2316 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2317 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2318 } else {
2319 memset(&p_connect->reserved1, 0x00, 4);
2320 memset(&p_connect->reserved2, 0x00, 4);
2321 }
2322 break;
2323 default:
2324 break;
2325 }
2326
2327 /* write Control Record to the device */
2328
2329
2330 skb = dev_alloc_skb(sizeof(struct clawctl));
2331 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 return -ENOMEM;
2333 }
2334 memcpy(skb_put(skb, sizeof(struct clawctl)),
2335 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 if (privptr->p_env->packing >= PACK_SEND)
2337 claw_hw_tx(skb, dev, 1);
2338 else
2339 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 return 0;
2341} /* end of claw_send_control */
2342
2343/*-------------------------------------------------------------------*
2344* claw_snd_conn_req *
2345* *
2346*--------------------------------------------------------------------*/
2347static int
2348claw_snd_conn_req(struct net_device *dev, __u8 link)
2349{
2350 int rc;
2351 struct claw_privbk *privptr=dev->priv;
2352 struct clawctl *p_ctl;
2353
Andy Richterb805da72008-07-18 15:24:56 +02002354 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 rc = 1;
2356 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2357 p_ctl->linkid = link;
2358 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 return rc;
2360 }
2361 if (privptr->p_env->packing == PACKING_ASK )
2362 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2363 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2364 if (privptr->p_env->packing == PACK_SEND) {
2365 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2366 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2367 }
2368 if (privptr->p_env->packing == 0)
2369 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2370 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 return rc;
2372
2373} /* end of claw_snd_conn_req */
2374
2375
2376/*-------------------------------------------------------------------*
2377* claw_snd_disc *
2378* *
2379*--------------------------------------------------------------------*/
2380
2381static int
2382claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2383{
2384 int rc;
2385 struct conncmd * p_connect;
2386
Andy Richterb805da72008-07-18 15:24:56 +02002387 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 p_connect=(struct conncmd *)&p_ctl->data;
2389
2390 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2391 p_ctl->correlator, 0,
2392 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 return rc;
2394} /* end of claw_snd_disc */
2395
2396
2397/*-------------------------------------------------------------------*
2398* claw_snd_sys_validate_rsp *
2399* *
2400*--------------------------------------------------------------------*/
2401
2402static int
2403claw_snd_sys_validate_rsp(struct net_device *dev,
2404 struct clawctl *p_ctl, __u32 return_code)
2405{
2406 struct claw_env * p_env;
2407 struct claw_privbk *privptr;
2408 int rc;
2409
Andy Richterb805da72008-07-18 15:24:56 +02002410 CLAW_DBF_TEXT(2, setup, "chkresp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 privptr = dev->priv;
2412 p_env=privptr->p_env;
2413 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2414 p_ctl->linkid,
2415 p_ctl->correlator,
2416 return_code,
2417 p_env->host_name,
2418 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 return rc;
2420} /* end of claw_snd_sys_validate_rsp */
2421
2422/*-------------------------------------------------------------------*
2423* claw_strt_conn_req *
2424* *
2425*--------------------------------------------------------------------*/
2426
2427static int
2428claw_strt_conn_req(struct net_device *dev )
2429{
2430 int rc;
2431
Andy Richterb805da72008-07-18 15:24:56 +02002432 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 return rc;
2435} /* end of claw_strt_conn_req */
2436
2437
2438
2439/*-------------------------------------------------------------------*
2440 * claw_stats *
2441 *-------------------------------------------------------------------*/
2442
2443static struct
2444net_device_stats *claw_stats(struct net_device *dev)
2445{
2446 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002447
2448 CLAW_DBF_TEXT(4, trace, "stats");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 privptr = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 return &privptr->stats;
2451} /* end of claw_stats */
2452
2453
2454/*-------------------------------------------------------------------*
2455* unpack_read *
2456* *
2457*--------------------------------------------------------------------*/
2458static void
2459unpack_read(struct net_device *dev )
2460{
2461 struct sk_buff *skb;
2462 struct claw_privbk *privptr;
2463 struct claw_env *p_env;
2464 struct ccwbk *p_this_ccw;
2465 struct ccwbk *p_first_ccw;
2466 struct ccwbk *p_last_ccw;
2467 struct clawph *p_packh;
2468 void *p_packd;
2469 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002470 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
2472 __u32 len_of_data;
2473 __u32 pack_off;
2474 __u8 link_num;
2475 __u8 mtc_this_frm=0;
2476 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 int i=0;
2478 int p=0;
2479
Andy Richterb805da72008-07-18 15:24:56 +02002480 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 p_first_ccw=NULL;
2482 p_last_ccw=NULL;
2483 p_packh=NULL;
2484 p_packd=NULL;
2485 privptr=dev->priv;
Andy Richterb805da72008-07-18 15:24:56 +02002486
2487 p_dev = &privptr->channel[READ].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 p_env = privptr->p_env;
2489 p_this_ccw=privptr->p_read_active_first;
2490 i=0;
2491 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 pack_off = 0;
2493 p = 0;
2494 p_this_ccw->header.flag=CLAW_PENDING;
2495 privptr->p_read_active_first=p_this_ccw->next;
2496 p_this_ccw->next=NULL;
2497 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2498 if ((p_env->packing == PACK_SEND) &&
2499 (p_packh->len == 32) &&
2500 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2501 p_packh++; /* peek past pack header */
2502 p_ctlrec = (struct clawctl *)p_packh;
2503 p_packh--; /* un peek */
2504 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2505 (p_ctlrec->command == CONNECTION_CONFIRM))
2506 p_env->packing = DO_PACKED;
2507 }
2508 if (p_env->packing == DO_PACKED)
2509 link_num=p_packh->link_num;
2510 else
2511 link_num=p_this_ccw->header.opcode / 8;
2512 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 mtc_this_frm=1;
2514 if (p_this_ccw->header.length!=
2515 privptr->p_env->read_size ) {
2516 printk(KERN_INFO " %s: Invalid frame detected "
2517 "length is %02x\n" ,
2518 dev->name, p_this_ccw->header.length);
2519 }
2520 }
2521
2522 if (privptr->mtc_skipping) {
2523 /*
2524 * We're in the mode of skipping past a
2525 * multi-frame message
2526 * that we can't process for some reason or other.
2527 * The first frame without the More-To-Come flag is
2528 * the last frame of the skipped message.
2529 */
2530 /* in case of More-To-Come not set in this frame */
2531 if (mtc_this_frm==0) {
2532 privptr->mtc_skipping=0; /* Ok, the end */
2533 privptr->mtc_logical_link=-1;
2534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 goto NextFrame;
2536 }
2537
2538 if (link_num==0) {
2539 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002540 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 goto NextFrame;
2542 }
2543unpack_next:
2544 if (p_env->packing == DO_PACKED) {
2545 if (pack_off > p_env->read_size)
2546 goto NextFrame;
2547 p_packd = p_this_ccw->p_buffer+pack_off;
2548 p_packh = (struct clawph *) p_packd;
2549 if ((p_packh->len == 0) || /* all done with this frame? */
2550 (p_packh->flag != 0))
2551 goto NextFrame;
2552 bytes_to_mov = p_packh->len;
2553 pack_off += bytes_to_mov+sizeof(struct clawph);
2554 p++;
2555 } else {
2556 bytes_to_mov=p_this_ccw->header.length;
2557 }
2558 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
2560 /*
2561 * if More-To-Come is set in this frame then we don't know
2562 * length of entire message, and hence have to allocate
2563 * large buffer */
2564
2565 /* We are starting a new envelope */
2566 privptr->mtc_offset=0;
2567 privptr->mtc_logical_link=link_num;
2568 }
2569
2570 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2571 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 privptr->stats.rx_frame_errors++;
2573 goto NextFrame;
2574 }
2575 if (p_env->packing == DO_PACKED) {
2576 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2577 p_packd+sizeof(struct clawph), bytes_to_mov);
2578
2579 } else {
2580 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2581 p_this_ccw->p_buffer, bytes_to_mov);
2582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 if (mtc_this_frm==0) {
2584 len_of_data=privptr->mtc_offset+bytes_to_mov;
2585 skb=dev_alloc_skb(len_of_data);
2586 if (skb) {
2587 memcpy(skb_put(skb,len_of_data),
2588 privptr->p_mtc_envelope,
2589 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002591 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 skb->protocol=htons(ETH_P_IP);
2593 skb->ip_summed=CHECKSUM_UNNECESSARY;
2594 privptr->stats.rx_packets++;
2595 privptr->stats.rx_bytes+=len_of_data;
2596 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 }
2598 else {
2599 privptr->stats.rx_dropped++;
2600 printk(KERN_WARNING "%s: %s() low on memory\n",
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +02002601 dev->name,__func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 }
2603 privptr->mtc_offset=0;
2604 privptr->mtc_logical_link=-1;
2605 }
2606 else {
2607 privptr->mtc_offset+=bytes_to_mov;
2608 }
2609 if (p_env->packing == DO_PACKED)
2610 goto unpack_next;
2611NextFrame:
2612 /*
2613 * Remove ThisCCWblock from active read queue, and add it
2614 * to queue of free blocks to be reused.
2615 */
2616 i++;
2617 p_this_ccw->header.length=0xffff;
2618 p_this_ccw->header.opcode=0xff;
2619 /*
2620 * add this one to the free queue for later reuse
2621 */
2622 if (p_first_ccw==NULL) {
2623 p_first_ccw = p_this_ccw;
2624 }
2625 else {
2626 p_last_ccw->next = p_this_ccw;
2627 }
2628 p_last_ccw = p_this_ccw;
2629 /*
2630 * chain to next block on active read queue
2631 */
2632 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002633 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 } /* end of while */
2635
2636 /* check validity */
2637
Andy Richterb805da72008-07-18 15:24:56 +02002638 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 return;
2642} /* end of unpack_read */
2643
2644/*-------------------------------------------------------------------*
2645* claw_strt_read *
2646* *
2647*--------------------------------------------------------------------*/
2648static void
2649claw_strt_read (struct net_device *dev, int lock )
2650{
2651 int rc = 0;
2652 __u32 parm;
2653 unsigned long saveflags = 0;
2654 struct claw_privbk *privptr=dev->priv;
2655 struct ccwbk*p_ccwbk;
2656 struct chbk *p_ch;
2657 struct clawh *p_clawh;
2658 p_ch=&privptr->channel[READ];
2659
Andy Richterb805da72008-07-18 15:24:56 +02002660 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2662 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2663
2664 if ((privptr->p_write_active_first!=NULL &&
2665 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2666 (privptr->p_read_active_first!=NULL &&
2667 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2668 p_clawh->flag=CLAW_BUSY; /* 0xff */
2669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 if (lock==LOCK_YES) {
2671 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2672 }
2673 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002674 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 p_ccwbk=privptr->p_read_active_first;
2676 parm = (unsigned long) p_ch;
2677 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2678 0xff, 0);
2679 if (rc != 0) {
2680 ccw_check_return_code(p_ch->cdev, rc);
2681 }
2682 }
2683 else {
Andy Richterb805da72008-07-18 15:24:56 +02002684 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 }
2686
2687 if (lock==LOCK_YES) {
2688 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2689 }
Andy Richterb805da72008-07-18 15:24:56 +02002690 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 return;
2692} /* end of claw_strt_read */
2693
2694/*-------------------------------------------------------------------*
2695* claw_strt_out_IO *
2696* *
2697*--------------------------------------------------------------------*/
2698
2699static void
2700claw_strt_out_IO( struct net_device *dev )
2701{
2702 int rc = 0;
2703 unsigned long parm;
2704 struct claw_privbk *privptr;
2705 struct chbk *p_ch;
2706 struct ccwbk *p_first_ccw;
2707
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 if (!dev) {
2709 return;
2710 }
2711 privptr=(struct claw_privbk *)dev->priv;
2712 p_ch=&privptr->channel[WRITE];
2713
Andy Richterb805da72008-07-18 15:24:56 +02002714 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 p_first_ccw=privptr->p_write_active_first;
2716
2717 if (p_ch->claw_state == CLAW_STOP)
2718 return;
2719 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 return;
2721 }
2722 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2723 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002724 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 rc = ccw_device_start (p_ch->cdev,&p_first_ccw->write, parm,
2726 0xff, 0);
2727 if (rc != 0) {
2728 ccw_check_return_code(p_ch->cdev, rc);
2729 }
2730 }
2731 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 return;
2733} /* end of claw_strt_out_IO */
2734
2735/*-------------------------------------------------------------------*
2736* Free write buffers *
2737* *
2738*--------------------------------------------------------------------*/
2739
2740static void
2741claw_free_wrt_buf( struct net_device *dev )
2742{
2743
2744 struct claw_privbk *privptr=(struct claw_privbk *)dev->priv;
2745 struct ccwbk*p_first_ccw;
2746 struct ccwbk*p_last_ccw;
2747 struct ccwbk*p_this_ccw;
2748 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002749
2750 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 /* scan the write queue to free any completed write packets */
2752 p_first_ccw=NULL;
2753 p_last_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 p_this_ccw=privptr->p_write_active_first;
2755 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2756 {
2757 p_next_ccw = p_this_ccw->next;
2758 if (((p_next_ccw!=NULL) &&
2759 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2760 ((p_this_ccw == privptr->p_write_active_last) &&
2761 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2762 /* The next CCW is OK or this is */
2763 /* the last CCW...free it @A1A */
2764 privptr->p_write_active_first=p_this_ccw->next;
2765 p_this_ccw->header.flag=CLAW_PENDING;
2766 p_this_ccw->next=privptr->p_write_free_chain;
2767 privptr->p_write_free_chain=p_this_ccw;
2768 ++privptr->write_free_count;
2769 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2770 p_this_ccw=privptr->p_write_active_first;
2771 privptr->stats.tx_packets++;
2772 }
2773 else {
2774 break;
2775 }
2776 }
2777 if (privptr->write_free_count!=0) {
2778 claw_clearbit_busy(TB_NOBUFFER,dev);
2779 }
2780 /* whole chain removed? */
2781 if (privptr->p_write_active_first==NULL) {
2782 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 }
Andy Richterb805da72008-07-18 15:24:56 +02002784 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 return;
2786}
2787
2788/*-------------------------------------------------------------------*
2789* claw free netdevice *
2790* *
2791*--------------------------------------------------------------------*/
2792static void
2793claw_free_netdevice(struct net_device * dev, int free_dev)
2794{
2795 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
Andy Richterb805da72008-07-18 15:24:56 +02002797 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 if (!dev)
2799 return;
Andy Richterb805da72008-07-18 15:24:56 +02002800 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 privptr = dev->priv;
2802 if (dev->flags & IFF_RUNNING)
2803 claw_release(dev);
2804 if (privptr) {
2805 privptr->channel[READ].ndev = NULL; /* say it's free */
2806 }
2807 dev->priv=NULL;
2808#ifdef MODULE
2809 if (free_dev) {
2810 free_netdev(dev);
2811 }
2812#endif
Andy Richterb805da72008-07-18 15:24:56 +02002813 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814}
2815
2816/**
2817 * Claw init netdevice
2818 * Initialize everything of the net device except the name and the
2819 * channel structs.
2820 */
2821static void
2822claw_init_netdevice(struct net_device * dev)
2823{
Andy Richterb805da72008-07-18 15:24:56 +02002824 CLAW_DBF_TEXT(2, setup, "init_dev");
2825 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
2827 dev->hard_start_xmit = claw_tx;
2828 dev->open = claw_open;
2829 dev->stop = claw_release;
2830 dev->get_stats = claw_stats;
2831 dev->change_mtu = claw_change_mtu;
2832 dev->hard_header_len = 0;
2833 dev->addr_len = 0;
2834 dev->type = ARPHRD_SLIP;
2835 dev->tx_queue_len = 1300;
2836 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Andy Richterb805da72008-07-18 15:24:56 +02002837 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 return;
2839}
2840
2841/**
2842 * Init a new channel in the privptr->channel[i].
2843 *
2844 * @param cdev The ccw_device to be added.
2845 *
2846 * @return 0 on success, !0 on error.
2847 */
2848static int
2849add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2850{
2851 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002852 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853
Andy Richterb805da72008-07-18 15:24:56 +02002854 CLAW_DBF_TEXT_(2, setup, "%s", cdev->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2856 p_ch = &privptr->channel[i];
2857 p_ch->cdev = cdev;
2858 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", cdev->dev.bus_id);
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002859 ccw_device_get_id(cdev, &dev_id);
2860 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002861 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 return -ENOMEM;
2863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 return 0;
2865}
2866
2867
2868/**
2869 *
2870 * Setup an interface.
2871 *
2872 * @param cgdev Device to be setup.
2873 *
2874 * @returns 0 on success, !0 on failure.
2875 */
2876static int
2877claw_new_device(struct ccwgroup_device *cgdev)
2878{
2879 struct claw_privbk *privptr;
2880 struct claw_env *p_env;
2881 struct net_device *dev;
2882 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002883 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 printk(KERN_INFO "claw: add for %s\n",cgdev->cdev[READ]->dev.bus_id);
Andy Richterb805da72008-07-18 15:24:56 +02002886 CLAW_DBF_TEXT(2, setup, "new_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 privptr = cgdev->dev.driver_data;
2888 cgdev->cdev[READ]->dev.driver_data = privptr;
2889 cgdev->cdev[WRITE]->dev.driver_data = privptr;
2890 if (!privptr)
2891 return -ENODEV;
2892 p_env = privptr->p_env;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002893 ccw_device_get_id(cgdev->cdev[READ], &dev_id);
2894 p_env->devno[READ] = dev_id.devno;
2895 ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
2896 p_env->devno[WRITE] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 ret = add_channel(cgdev->cdev[0],0,privptr);
2898 if (ret == 0)
2899 ret = add_channel(cgdev->cdev[1],1,privptr);
2900 if (ret != 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002901 printk(KERN_WARNING
2902 "add channel failed with ret = %d\n", ret);
2903 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 }
2905 ret = ccw_device_set_online(cgdev->cdev[READ]);
2906 if (ret != 0) {
2907 printk(KERN_WARNING
Andy Richterb805da72008-07-18 15:24:56 +02002908 "claw: ccw_device_set_online %s READ failed "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 "with ret = %d\n",cgdev->cdev[READ]->dev.bus_id,ret);
2910 goto out;
2911 }
2912 ret = ccw_device_set_online(cgdev->cdev[WRITE]);
2913 if (ret != 0) {
2914 printk(KERN_WARNING
Andy Richterb805da72008-07-18 15:24:56 +02002915 "claw: ccw_device_set_online %s WRITE failed "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 "with ret = %d\n",cgdev->cdev[WRITE]->dev.bus_id, ret);
2917 goto out;
2918 }
2919 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2920 if (!dev) {
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +02002921 printk(KERN_WARNING "%s:alloc_netdev failed\n",__func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 goto out;
2923 }
2924 dev->priv = privptr;
2925 cgdev->dev.driver_data = privptr;
2926 cgdev->cdev[READ]->dev.driver_data = privptr;
2927 cgdev->cdev[WRITE]->dev.driver_data = privptr;
2928 /* sysfs magic */
2929 SET_NETDEV_DEV(dev, &cgdev->dev);
2930 if (register_netdev(dev) != 0) {
2931 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02002932 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 goto out;
2934 }
2935 dev->flags &=~IFF_RUNNING;
2936 if (privptr->buffs_alloc == 0) {
2937 ret=init_ccw_bk(dev);
2938 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 unregister_netdev(dev);
2940 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02002941 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 goto out;
2943 }
2944 }
2945 privptr->channel[READ].ndev = dev;
2946 privptr->channel[WRITE].ndev = dev;
2947 privptr->p_env->ndev = dev;
2948
2949 printk(KERN_INFO "%s:readsize=%d writesize=%d "
2950 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2951 dev->name, p_env->read_size,
2952 p_env->write_size, p_env->read_buffers,
2953 p_env->write_buffers, p_env->devno[READ],
2954 p_env->devno[WRITE]);
2955 printk(KERN_INFO "%s:host_name:%.8s, adapter_name "
2956 ":%.8s api_type: %.8s\n",
2957 dev->name, p_env->host_name,
2958 p_env->adapter_name , p_env->api_type);
2959 return 0;
2960out:
2961 ccw_device_set_offline(cgdev->cdev[1]);
2962 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 return -ENODEV;
2964}
2965
2966static void
2967claw_purge_skb_queue(struct sk_buff_head *q)
2968{
2969 struct sk_buff *skb;
2970
Andy Richterb805da72008-07-18 15:24:56 +02002971 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 while ((skb = skb_dequeue(q))) {
2973 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02002974 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 }
2976}
2977
2978/**
2979 * Shutdown an interface.
2980 *
2981 * @param cgdev Device to be shut down.
2982 *
2983 * @returns 0 on success, !0 on failure.
2984 */
2985static int
2986claw_shutdown_device(struct ccwgroup_device *cgdev)
2987{
2988 struct claw_privbk *priv;
2989 struct net_device *ndev;
2990 int ret;
2991
Andy Richterb805da72008-07-18 15:24:56 +02002992 CLAW_DBF_TEXT_(2, setup, "%s", cgdev->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 priv = cgdev->dev.driver_data;
2994 if (!priv)
2995 return -ENODEV;
2996 ndev = priv->channel[READ].ndev;
2997 if (ndev) {
2998 /* Close the device */
2999 printk(KERN_INFO
3000 "%s: shuting down \n",ndev->name);
3001 if (ndev->flags & IFF_RUNNING)
3002 ret = claw_release(ndev);
3003 ndev->flags &=~IFF_RUNNING;
3004 unregister_netdev(ndev);
3005 ndev->priv = NULL; /* cgdev data, not ndev's to free */
3006 claw_free_netdevice(ndev, 1);
3007 priv->channel[READ].ndev = NULL;
3008 priv->channel[WRITE].ndev = NULL;
3009 priv->p_env->ndev = NULL;
3010 }
3011 ccw_device_set_offline(cgdev->cdev[1]);
3012 ccw_device_set_offline(cgdev->cdev[0]);
3013 return 0;
3014}
3015
3016static void
3017claw_remove_device(struct ccwgroup_device *cgdev)
3018{
3019 struct claw_privbk *priv;
3020
Andy Richterb805da72008-07-18 15:24:56 +02003021 BUG_ON(!cgdev);
3022 CLAW_DBF_TEXT_(2, setup, "%s", cgdev->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 priv = cgdev->dev.driver_data;
Andy Richterb805da72008-07-18 15:24:56 +02003024 BUG_ON(!priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 printk(KERN_INFO "claw: %s() called %s will be removed.\n",
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +02003026 __func__,cgdev->cdev[0]->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 if (cgdev->state == CCWGROUP_ONLINE)
3028 claw_shutdown_device(cgdev);
3029 claw_remove_files(&cgdev->dev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003030 kfree(priv->p_mtc_envelope);
3031 priv->p_mtc_envelope=NULL;
3032 kfree(priv->p_env);
3033 priv->p_env=NULL;
3034 kfree(priv->channel[0].irb);
3035 priv->channel[0].irb=NULL;
3036 kfree(priv->channel[1].irb);
3037 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 kfree(priv);
3039 cgdev->dev.driver_data=NULL;
3040 cgdev->cdev[READ]->dev.driver_data = NULL;
3041 cgdev->cdev[WRITE]->dev.driver_data = NULL;
3042 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003043
3044 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045}
3046
3047
3048/*
3049 * sysfs attributes
3050 */
3051static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003052claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053{
3054 struct claw_privbk *priv;
3055 struct claw_env * p_env;
3056
3057 priv = dev->driver_data;
3058 if (!priv)
3059 return -ENODEV;
3060 p_env = priv->p_env;
3061 return sprintf(buf, "%s\n",p_env->host_name);
3062}
3063
3064static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003065claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066{
3067 struct claw_privbk *priv;
3068 struct claw_env * p_env;
3069
3070 priv = dev->driver_data;
3071 if (!priv)
3072 return -ENODEV;
3073 p_env = priv->p_env;
3074 if (count > MAX_NAME_LEN+1)
3075 return -EINVAL;
3076 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3077 strncpy(p_env->host_name,buf, count);
3078 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3079 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003080 CLAW_DBF_TEXT(2, setup, "HstnSet");
3081 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
3083 return count;
3084}
3085
3086static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3087
3088static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003089claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090{
3091 struct claw_privbk *priv;
3092 struct claw_env * p_env;
3093
3094 priv = dev->driver_data;
3095 if (!priv)
3096 return -ENODEV;
3097 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003098 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
3101static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003102claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103{
3104 struct claw_privbk *priv;
3105 struct claw_env * p_env;
3106
3107 priv = dev->driver_data;
3108 if (!priv)
3109 return -ENODEV;
3110 p_env = priv->p_env;
3111 if (count > MAX_NAME_LEN+1)
3112 return -EINVAL;
3113 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3114 strncpy(p_env->adapter_name,buf, count);
3115 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3116 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003117 CLAW_DBF_TEXT(2, setup, "AdnSet");
3118 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
3120 return count;
3121}
3122
3123static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3124
3125static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003126claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127{
3128 struct claw_privbk *priv;
3129 struct claw_env * p_env;
3130
3131 priv = dev->driver_data;
3132 if (!priv)
3133 return -ENODEV;
3134 p_env = priv->p_env;
3135 return sprintf(buf, "%s\n",
3136 p_env->api_type);
3137}
3138
3139static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003140claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141{
3142 struct claw_privbk *priv;
3143 struct claw_env * p_env;
3144
3145 priv = dev->driver_data;
3146 if (!priv)
3147 return -ENODEV;
3148 p_env = priv->p_env;
3149 if (count > MAX_NAME_LEN+1)
3150 return -EINVAL;
3151 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3152 strncpy(p_env->api_type,buf, count);
3153 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3154 p_env->api_type[MAX_NAME_LEN] = 0x00;
3155 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3156 p_env->read_size=DEF_PACK_BUFSIZE;
3157 p_env->write_size=DEF_PACK_BUFSIZE;
3158 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003159 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
3161 else {
3162 p_env->packing=0;
3163 p_env->read_size=CLAW_FRAME_SIZE;
3164 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003165 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 }
Andy Richterb805da72008-07-18 15:24:56 +02003167 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 return count;
3169}
3170
3171static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3172
3173static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003174claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175{
3176 struct claw_privbk *priv;
3177 struct claw_env * p_env;
3178
3179 priv = dev->driver_data;
3180 if (!priv)
3181 return -ENODEV;
3182 p_env = priv->p_env;
3183 return sprintf(buf, "%d\n", p_env->write_buffers);
3184}
3185
3186static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003187claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188{
3189 struct claw_privbk *priv;
3190 struct claw_env * p_env;
3191 int nnn,max;
3192
3193 priv = dev->driver_data;
3194 if (!priv)
3195 return -ENODEV;
3196 p_env = priv->p_env;
3197 sscanf(buf, "%i", &nnn);
3198 if (p_env->packing) {
3199 max = 64;
3200 }
3201 else {
3202 max = 512;
3203 }
3204 if ((nnn > max ) || (nnn < 2))
3205 return -EINVAL;
3206 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003207 CLAW_DBF_TEXT(2, setup, "Wbufset");
3208 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 return count;
3210}
3211
3212static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3213
3214static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003215claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216{
3217 struct claw_privbk *priv;
3218 struct claw_env * p_env;
3219
3220 priv = dev->driver_data;
3221 if (!priv)
3222 return -ENODEV;
3223 p_env = priv->p_env;
3224 return sprintf(buf, "%d\n", p_env->read_buffers);
3225}
3226
3227static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003228claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229{
3230 struct claw_privbk *priv;
3231 struct claw_env *p_env;
3232 int nnn,max;
3233
3234 priv = dev->driver_data;
3235 if (!priv)
3236 return -ENODEV;
3237 p_env = priv->p_env;
3238 sscanf(buf, "%i", &nnn);
3239 if (p_env->packing) {
3240 max = 64;
3241 }
3242 else {
3243 max = 512;
3244 }
3245 if ((nnn > max ) || (nnn < 2))
3246 return -EINVAL;
3247 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003248 CLAW_DBF_TEXT(2, setup, "Rbufset");
3249 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 return count;
3251}
3252
3253static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3254
3255static struct attribute *claw_attr[] = {
3256 &dev_attr_read_buffer.attr,
3257 &dev_attr_write_buffer.attr,
3258 &dev_attr_adapter_name.attr,
3259 &dev_attr_api_type.attr,
3260 &dev_attr_host_name.attr,
3261 NULL,
3262};
3263
3264static struct attribute_group claw_attr_group = {
3265 .attrs = claw_attr,
3266};
3267
3268static int
3269claw_add_files(struct device *dev)
3270{
Andy Richterb805da72008-07-18 15:24:56 +02003271 CLAW_DBF_TEXT(2, setup, "add_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3273}
3274
3275static void
3276claw_remove_files(struct device *dev)
3277{
Andy Richterb805da72008-07-18 15:24:56 +02003278 CLAW_DBF_TEXT(2, setup, "rem_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3280}
3281
3282/*--------------------------------------------------------------------*
3283* claw_init and cleanup *
3284*---------------------------------------------------------------------*/
3285
3286static void __exit
3287claw_cleanup(void)
3288{
3289 unregister_cu3088_discipline(&claw_group_driver);
3290 claw_unregister_debug_facility();
3291 printk(KERN_INFO "claw: Driver unloaded\n");
3292
3293}
3294
3295/**
3296 * Initialize module.
3297 * This is called just after the module is loaded.
3298 *
3299 * @return 0 on success, !0 on error.
3300 */
3301static int __init
3302claw_init(void)
3303{
3304 int ret = 0;
Heiko Carstense018ba12006-02-01 03:06:31 -08003305 printk(KERN_INFO "claw: starting driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 ret = claw_register_debug_facility();
3308 if (ret) {
3309 printk(KERN_WARNING "claw: %s() debug_register failed %d\n",
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +02003310 __func__,ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 return ret;
3312 }
Andy Richterb805da72008-07-18 15:24:56 +02003313 CLAW_DBF_TEXT(2, setup, "init_mod");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 ret = register_cu3088_discipline(&claw_group_driver);
3315 if (ret) {
Andy Richterb805da72008-07-18 15:24:56 +02003316 CLAW_DBF_TEXT(2, setup, "init_bad");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 claw_unregister_debug_facility();
3318 printk(KERN_WARNING "claw; %s() cu3088 register failed %d\n",
Harvey Harrison2a2cf6b2008-04-17 07:46:21 +02003319 __func__,ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 return ret;
3322}
3323
3324module_init(claw_init);
3325module_exit(claw_cleanup);
3326
Andy Richterb805da72008-07-18 15:24:56 +02003327MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3328MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3329 "Copyright 2000,2008 IBM Corporation\n");
3330MODULE_LICENSE("GPL");