blob: 2e2d2dfe78db4849d7b76608236e3422eae38344 [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
Frank Blaschka88efc2c2009-06-16 10:30:33 +02006 * Copyright IBM Corp. 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Author(s) Original code written by:
Frank Blaschka88efc2c2009-06-16 10:30:33 +02008 * Kazuo Iimura <iimura@jp.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Rewritten by
Frank Blaschka88efc2c2009-06-16 10:30:33 +020010 * Andy Richter <richtera@us.ibm.com>
11 * Marc Price <mwprice@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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 */
Andy Richter4811fcb2009-01-20 06:14:33 +000063
64#define KMSG_COMPONENT "claw"
65
Heiko Carstens355eb402011-01-05 12:47:36 +010066#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#include <asm/ccwdev.h>
68#include <asm/ccwgroup.h>
69#include <asm/debug.h>
70#include <asm/idals.h>
71#include <asm/io.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070072#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include <linux/ctype.h>
74#include <linux/delay.h>
75#include <linux/errno.h>
76#include <linux/if_arp.h>
77#include <linux/init.h>
78#include <linux/interrupt.h>
79#include <linux/ip.h>
80#include <linux/kernel.h>
81#include <linux/module.h>
82#include <linux/netdevice.h>
83#include <linux/etherdevice.h>
84#include <linux/proc_fs.h>
85#include <linux/sched.h>
86#include <linux/signal.h>
87#include <linux/skbuff.h>
88#include <linux/slab.h>
89#include <linux/string.h>
90#include <linux/tcp.h>
91#include <linux/timer.h>
92#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#include "claw.h"
95
Andy Richterb805da72008-07-18 15:24:56 +020096/*
97 CLAW uses the s390dbf file system see claw_trace and claw_setup
Linus Torvalds1da177e2005-04-16 15:20:36 -070098*/
99
Andy Richter4811fcb2009-01-20 06:14:33 +0000100static char version[] __initdata = "CLAW driver";
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100101static char debug_buffer[255];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/**
103 * Debug Facility Stuff
104 */
105static debug_info_t *claw_dbf_setup;
106static debug_info_t *claw_dbf_trace;
107
108/**
109 * CLAW Debug Facility functions
110 */
111static void
112claw_unregister_debug_facility(void)
113{
114 if (claw_dbf_setup)
115 debug_unregister(claw_dbf_setup);
116 if (claw_dbf_trace)
117 debug_unregister(claw_dbf_trace);
118}
119
120static int
121claw_register_debug_facility(void)
122{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700123 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
124 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 claw_unregister_debug_facility();
127 return -ENOMEM;
128 }
129 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
130 debug_set_level(claw_dbf_setup, 2);
131 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
132 debug_set_level(claw_dbf_trace, 2);
133 return 0;
134}
135
136static inline void
137claw_set_busy(struct net_device *dev)
138{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200139 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 eieio();
141}
142
143static inline void
144claw_clear_busy(struct net_device *dev)
145{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200146 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 netif_wake_queue(dev);
148 eieio();
149}
150
151static inline int
152claw_check_busy(struct net_device *dev)
153{
154 eieio();
Peter Tiedemann6951df32008-08-21 17:10:23 +0200155 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
158static inline void
159claw_setbit_busy(int nr,struct net_device *dev)
160{
161 netif_stop_queue(dev);
Peter Tiedemann6951df32008-08-21 17:10:23 +0200162 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static inline void
166claw_clearbit_busy(int nr,struct net_device *dev)
167{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200168 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 netif_wake_queue(dev);
170}
171
172static inline int
173claw_test_and_setbit_busy(int nr,struct net_device *dev)
174{
175 netif_stop_queue(dev);
176 return test_and_set_bit(nr,
Peter Tiedemann6951df32008-08-21 17:10:23 +0200177 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
180
181/* Functions for the DEV methods */
182
183static int claw_probe(struct ccwgroup_device *cgdev);
184static void claw_remove_device(struct ccwgroup_device *cgdev);
185static void claw_purge_skb_queue(struct sk_buff_head *q);
186static int claw_new_device(struct ccwgroup_device *cgdev);
187static int claw_shutdown_device(struct ccwgroup_device *cgdev);
188static int claw_tx(struct sk_buff *skb, struct net_device *dev);
189static int claw_change_mtu( struct net_device *dev, int new_mtu);
190static int claw_open(struct net_device *dev);
191static void claw_irq_handler(struct ccw_device *cdev,
192 unsigned long intparm, struct irb *irb);
193static void claw_irq_tasklet ( unsigned long data );
194static int claw_release(struct net_device *dev);
195static void claw_write_retry ( struct chbk * p_ch );
196static void claw_write_next ( struct chbk * p_ch );
197static void claw_timer ( struct chbk * p_ch );
198
199/* Functions */
200static int add_claw_reads(struct net_device *dev,
201 struct ccwbk* p_first, struct ccwbk* p_last);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100202static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
203static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static int find_link(struct net_device *dev, char *host_name, char *ws_name );
205static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
206static int init_ccw_bk(struct net_device *dev);
207static void probe_error( struct ccwgroup_device *cgdev);
208static struct net_device_stats *claw_stats(struct net_device *dev);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100209static int pages_to_order_of_mag(int num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/* sysfs Functions */
Andy Richter4811fcb2009-01-20 06:14:33 +0000212static ssize_t claw_hname_show(struct device *dev,
213 struct device_attribute *attr, char *buf);
214static ssize_t claw_hname_write(struct device *dev,
215 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000217static ssize_t claw_adname_show(struct device *dev,
218 struct device_attribute *attr, char *buf);
219static ssize_t claw_adname_write(struct device *dev,
220 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000222static ssize_t claw_apname_show(struct device *dev,
223 struct device_attribute *attr, char *buf);
224static ssize_t claw_apname_write(struct device *dev,
225 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000227static ssize_t claw_wbuff_show(struct device *dev,
228 struct device_attribute *attr, char *buf);
229static ssize_t claw_wbuff_write(struct device *dev,
230 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000232static ssize_t claw_rbuff_show(struct device *dev,
233 struct device_attribute *attr, char *buf);
234static ssize_t claw_rbuff_write(struct device *dev,
235 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 const char *buf, size_t count);
237static int claw_add_files(struct device *dev);
238static void claw_remove_files(struct device *dev);
239
240/* Functions for System Validate */
241static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
242static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
243 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
244static int claw_snd_conn_req(struct net_device *dev, __u8 link);
245static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
246static int claw_snd_sys_validate_rsp(struct net_device *dev,
247 struct clawctl * p_ctl, __u32 return_code);
248static int claw_strt_conn_req(struct net_device *dev );
Andy Richterb805da72008-07-18 15:24:56 +0200249static void claw_strt_read(struct net_device *dev, int lock);
250static void claw_strt_out_IO(struct net_device *dev);
251static void claw_free_wrt_buf(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253/* Functions for unpack reads */
Andy Richterb805da72008-07-18 15:24:56 +0200254static void unpack_read(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200256static int claw_pm_prepare(struct ccwgroup_device *gdev)
257{
258 return -EPERM;
259}
260
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000261/* the root device for claw group devices */
262static struct device *claw_root_dev;
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264/* ccwgroup table */
265
266static struct ccwgroup_driver claw_group_driver = {
267 .owner = THIS_MODULE,
268 .name = "claw",
269 .max_slaves = 2,
270 .driver_id = 0xC3D3C1E6,
271 .probe = claw_probe,
272 .remove = claw_remove_device,
273 .set_online = claw_new_device,
274 .set_offline = claw_shutdown_device,
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200275 .prepare = claw_pm_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000278static struct ccw_device_id claw_ids[] = {
279 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
280 {},
281};
282MODULE_DEVICE_TABLE(ccw, claw_ids);
283
284static struct ccw_driver claw_ccw_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +0100285 .driver = {
286 .owner = THIS_MODULE,
287 .name = "claw",
288 },
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000289 .ids = claw_ids,
290 .probe = ccwgroup_probe_ccwdev,
291 .remove = ccwgroup_remove_ccwdev,
292};
293
294static ssize_t
295claw_driver_group_store(struct device_driver *ddrv, const char *buf,
296 size_t count)
297{
298 int err;
299 err = ccwgroup_create_from_string(claw_root_dev,
300 claw_group_driver.driver_id,
Ursula Braune48d24a2010-07-22 23:15:07 +0000301 &claw_ccw_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000302 return err ? err : count;
303}
304
305static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
306
307static struct attribute *claw_group_attrs[] = {
308 &driver_attr_group.attr,
309 NULL,
310};
311
312static struct attribute_group claw_group_attr_group = {
313 .attrs = claw_group_attrs,
314};
315
Heiko Carstens302689a2009-11-17 06:47:02 -0800316static const struct attribute_group *claw_group_attr_groups[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000317 &claw_group_attr_group,
318 NULL,
319};
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322* Key functions
323*/
324
325/*----------------------------------------------------------------*
326 * claw_probe *
327 * this function is called for each CLAW device. *
328 *----------------------------------------------------------------*/
329static int
330claw_probe(struct ccwgroup_device *cgdev)
331{
332 int rc;
333 struct claw_privbk *privptr=NULL;
334
Andy Richterb805da72008-07-18 15:24:56 +0200335 CLAW_DBF_TEXT(2, setup, "probe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (!get_device(&cgdev->dev))
337 return -ENODEV;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800338 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700339 dev_set_drvdata(&cgdev->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (privptr == NULL) {
341 probe_error(cgdev);
342 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200343 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return -ENOMEM;
345 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700346 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
347 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
349 probe_error(cgdev);
350 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200351 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return -ENOMEM;
353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
355 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
356 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
357 privptr->p_env->packing = 0;
358 privptr->p_env->write_buffers = 5;
359 privptr->p_env->read_buffers = 5;
360 privptr->p_env->read_size = CLAW_FRAME_SIZE;
361 privptr->p_env->write_size = CLAW_FRAME_SIZE;
362 rc = claw_add_files(&cgdev->dev);
363 if (rc) {
364 probe_error(cgdev);
365 put_device(&cgdev->dev);
Andy Richter4811fcb2009-01-20 06:14:33 +0000366 dev_err(&cgdev->dev, "Creating the /proc files for a new"
367 " CLAW device failed\n");
Andy Richterb805da72008-07-18 15:24:56 +0200368 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return rc;
370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 privptr->p_env->p_priv = privptr;
372 cgdev->cdev[0]->handler = claw_irq_handler;
373 cgdev->cdev[1]->handler = claw_irq_handler;
Andy Richterb805da72008-07-18 15:24:56 +0200374 CLAW_DBF_TEXT(2, setup, "prbext 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 return 0;
377} /* end of claw_probe */
378
379/*-------------------------------------------------------------------*
380 * claw_tx *
381 *-------------------------------------------------------------------*/
382
383static int
384claw_tx(struct sk_buff *skb, struct net_device *dev)
385{
386 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200387 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 unsigned long saveflags;
389 struct chbk *p_ch;
390
Andy Richterb805da72008-07-18 15:24:56 +0200391 CLAW_DBF_TEXT(4, trace, "claw_tx");
Heiko Carstens319cb082010-08-12 01:58:27 +0000392 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
394 rc=claw_hw_tx( skb, dev, 1 );
395 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200396 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000397 if (rc)
398 rc = NETDEV_TX_BUSY;
Patrick McHardyec634fe2009-07-05 19:23:38 -0700399 else
400 rc = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return rc;
402} /* end of claw_tx */
403
404/*------------------------------------------------------------------*
405 * pack the collect queue into an skb and return it *
406 * If not packing just return the top skb from the queue *
407 *------------------------------------------------------------------*/
408
409static struct sk_buff *
410claw_pack_skb(struct claw_privbk *privptr)
411{
412 struct sk_buff *new_skb,*held_skb;
Heiko Carstens319cb082010-08-12 01:58:27 +0000413 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 struct claw_env *p_env = privptr->p_env;
415 int pkt_cnt,pk_ind,so_far;
416
417 new_skb = NULL; /* assume no dice */
418 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200419 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700420 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /* some data */
422 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200424 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 else
426 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200427 if (p_env->packing != DO_PACKED)
428 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* get a new SKB we will pack at least one */
430 new_skb = dev_alloc_skb(p_env->write_size);
431 if (new_skb == NULL) {
432 atomic_inc(&held_skb->users);
433 skb_queue_head(&p_ch->collect_queue,held_skb);
434 return NULL;
435 }
436 /* we have packed packet and a place to put it */
437 pk_ind = 1;
438 so_far = 0;
439 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
440 while ((pk_ind) && (held_skb != NULL)) {
441 if (held_skb->len+so_far <= p_env->write_size-8) {
442 memcpy(skb_put(new_skb,held_skb->len),
443 held_skb->data,held_skb->len);
444 privptr->stats.tx_packets++;
445 so_far += held_skb->len;
446 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200447 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 held_skb = skb_dequeue(&p_ch->collect_queue);
449 if (held_skb)
450 atomic_dec(&held_skb->users);
451 } else {
452 pk_ind = 0;
453 atomic_inc(&held_skb->users);
454 skb_queue_head(&p_ch->collect_queue,held_skb);
455 }
456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
Andy Richterb805da72008-07-18 15:24:56 +0200458 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return new_skb;
460}
461
462/*-------------------------------------------------------------------*
463 * claw_change_mtu *
464 * *
465 *-------------------------------------------------------------------*/
466
467static int
468claw_change_mtu(struct net_device *dev, int new_mtu)
469{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200470 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200472 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 buff_size = privptr->p_env->write_size;
474 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 return -EINVAL;
476 }
477 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return 0;
479} /* end of claw_change_mtu */
480
481
482/*-------------------------------------------------------------------*
483 * claw_open *
484 * *
485 *-------------------------------------------------------------------*/
486static int
487claw_open(struct net_device *dev)
488{
489
490 int rc;
491 int i;
492 unsigned long saveflags=0;
493 unsigned long parm;
494 struct claw_privbk *privptr;
495 DECLARE_WAITQUEUE(wait, current);
496 struct timer_list timer;
497 struct ccwbk *p_buf;
498
Andy Richterb805da72008-07-18 15:24:56 +0200499 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200500 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 /* allocate and initialize CCW blocks */
502 if (privptr->buffs_alloc == 0) {
503 rc=init_ccw_bk(dev);
504 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200505 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 return -ENOMEM;
507 }
508 }
509 privptr->system_validate_comp=0;
510 privptr->release_pend=0;
511 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
512 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
513 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
514 privptr->p_env->packing=PACKING_ASK;
515 } else {
516 privptr->p_env->packing=0;
517 privptr->p_env->read_size=CLAW_FRAME_SIZE;
518 privptr->p_env->write_size=CLAW_FRAME_SIZE;
519 }
520 claw_set_busy(dev);
Heiko Carstens319cb082010-08-12 01:58:27 +0000521 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
522 (unsigned long) &privptr->channel[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200524 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 init_waitqueue_head(&privptr->channel[i].wait);
526 /* skb_queue_head_init(&p_ch->io_queue); */
Heiko Carstens319cb082010-08-12 01:58:27 +0000527 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 skb_queue_head_init(
Heiko Carstens319cb082010-08-12 01:58:27 +0000529 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 privptr->channel[i].flag_a = 0;
531 privptr->channel[i].IO_active = 0;
532 privptr->channel[i].flag &= ~CLAW_TIMER;
533 init_timer(&timer);
534 timer.function = (void *)claw_timer;
535 timer.data = (unsigned long)(&privptr->channel[i]);
536 timer.expires = jiffies + 15*HZ;
537 add_timer(&timer);
538 spin_lock_irqsave(get_ccwdev_lock(
539 privptr->channel[i].cdev), saveflags);
540 parm = (unsigned long) &privptr->channel[i];
541 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
542 rc = 0;
543 add_wait_queue(&privptr->channel[i].wait, &wait);
544 rc = ccw_device_halt(
545 (struct ccw_device *)privptr->channel[i].cdev,parm);
546 set_current_state(TASK_INTERRUPTIBLE);
547 spin_unlock_irqrestore(
548 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
549 schedule();
550 set_current_state(TASK_RUNNING);
551 remove_wait_queue(&privptr->channel[i].wait, &wait);
552 if(rc != 0)
553 ccw_check_return_code(privptr->channel[i].cdev, rc);
554 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
555 del_timer(&timer);
556 }
Heiko Carstens319cb082010-08-12 01:58:27 +0000557 if ((((privptr->channel[READ_CHANNEL].last_dstat |
558 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
Heiko Carstens319cb082010-08-12 01:58:27 +0000560 (((privptr->channel[READ_CHANNEL].flag |
561 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
562 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000563 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200564 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 for ( i = 0; i < 2; i++) {
567 spin_lock_irqsave(
568 get_ccwdev_lock(privptr->channel[i].cdev),
569 saveflags);
570 parm = (unsigned long) &privptr->channel[i];
571 privptr->channel[i].claw_state = CLAW_STOP;
572 rc = ccw_device_halt(
573 (struct ccw_device *)&privptr->channel[i].cdev,
574 parm);
575 spin_unlock_irqrestore(
576 get_ccwdev_lock(privptr->channel[i].cdev),
577 saveflags);
578 if (rc != 0) {
579 ccw_check_return_code(
580 privptr->channel[i].cdev, rc);
581 }
582 }
583 free_pages((unsigned long)privptr->p_buff_ccw,
584 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
585 if (privptr->p_env->read_size < PAGE_SIZE) {
586 free_pages((unsigned long)privptr->p_buff_read,
587 (int)pages_to_order_of_mag(
588 privptr->p_buff_read_num));
589 }
590 else {
591 p_buf=privptr->p_read_active_first;
592 while (p_buf!=NULL) {
593 free_pages((unsigned long)p_buf->p_buffer,
594 (int)pages_to_order_of_mag(
595 privptr->p_buff_pages_perread ));
596 p_buf=p_buf->next;
597 }
598 }
599 if (privptr->p_env->write_size < PAGE_SIZE ) {
600 free_pages((unsigned long)privptr->p_buff_write,
601 (int)pages_to_order_of_mag(
602 privptr->p_buff_write_num));
603 }
604 else {
605 p_buf=privptr->p_write_active_first;
606 while (p_buf!=NULL) {
607 free_pages((unsigned long)p_buf->p_buffer,
608 (int)pages_to_order_of_mag(
609 privptr->p_buff_pages_perwrite ));
610 p_buf=p_buf->next;
611 }
612 }
613 privptr->buffs_alloc = 0;
Heiko Carstens319cb082010-08-12 01:58:27 +0000614 privptr->channel[READ_CHANNEL].flag = 0x00;
615 privptr->channel[WRITE_CHANNEL].flag = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 privptr->p_buff_ccw=NULL;
617 privptr->p_buff_read=NULL;
618 privptr->p_buff_write=NULL;
619 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200620 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 return -EIO;
622 }
623
624 /* Send SystemValidate command */
625
626 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200627 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return 0;
629} /* end of claw_open */
630
631/*-------------------------------------------------------------------*
632* *
633* claw_irq_handler *
634* *
635*--------------------------------------------------------------------*/
636static void
637claw_irq_handler(struct ccw_device *cdev,
638 unsigned long intparm, struct irb *irb)
639{
640 struct chbk *p_ch = NULL;
641 struct claw_privbk *privptr = NULL;
642 struct net_device *dev = NULL;
643 struct claw_env *p_env;
644 struct chbk *p_ch_r=NULL;
645
Heiko Carstens355eb402011-01-05 12:47:36 +0100646 kstat_cpu(smp_processor_id()).irqs[IOINT_CLW]++;
Andy Richterb805da72008-07-18 15:24:56 +0200647 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 /* Bypass all 'unsolicited interrupts' */
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700649 privptr = dev_get_drvdata(&cdev->dev);
650 if (!privptr) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000651 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
652 " IRQ, c-%02x d-%02x\n",
653 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200654 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 return;
656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 /* Try to extract channel from driver data. */
Heiko Carstens319cb082010-08-12 01:58:27 +0000659 if (privptr->channel[READ_CHANNEL].cdev == cdev)
660 p_ch = &privptr->channel[READ_CHANNEL];
661 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
662 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000664 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200665 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 return;
667 }
Andy Richterb805da72008-07-18 15:24:56 +0200668 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 dev = (struct net_device *) (p_ch->ndev);
671 p_env=privptr->p_env;
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 /* Copy interruption response block. */
674 memcpy(p_ch->irb, irb, sizeof(struct irb));
675
Andy Richterb805da72008-07-18 15:24:56 +0200676 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200677 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000678 dev_info(&cdev->dev,
679 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
681 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200682 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
683 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200684 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 /* return; */
686 }
687
688 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200689 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200693 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200696 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
697 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
698 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
699 (p_ch->irb->scsw.cmd.stctl ==
700 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
701 return;
702 wake_up(&p_ch->wait); /* wake up claw_release */
703 CLAW_DBF_TEXT(4, trace, "stop");
704 return;
705 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
706 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
707 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
708 (p_ch->irb->scsw.cmd.stctl ==
709 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
710 CLAW_DBF_TEXT(4, trace, "haltio");
711 return;
712 }
713 if (p_ch->flag == CLAW_READ) {
714 p_ch->claw_state = CLAW_START_READ;
715 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
716 } else if (p_ch->flag == CLAW_WRITE) {
717 p_ch->claw_state = CLAW_START_WRITE;
Andy Richter4811fcb2009-01-20 06:14:33 +0000718 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200719 claw_strt_read(dev, LOCK_NO);
720 claw_send_control(dev,
721 SYSTEM_VALIDATE_REQUEST,
722 0, 0, 0,
723 p_env->host_name,
724 p_env->adapter_name);
725 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000726 dev_warn(&cdev->dev, "The CLAW device received"
727 " an unexpected IRQ, "
728 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200729 irb->scsw.cmd.cstat,
730 irb->scsw.cmd.dstat);
731 return;
732 }
733 CLAW_DBF_TEXT(4, trace, "haltio");
734 return;
735 case CLAW_START_READ:
736 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
737 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
738 clear_bit(0, (void *)&p_ch->IO_active);
739 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
740 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
741 (p_ch->irb->ecw[0]) == 0) {
742 privptr->stats.rx_errors++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000743 dev_info(&cdev->dev,
744 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200745 "side recovers \n",
746 dev->name);
747 }
748 CLAW_DBF_TEXT(4, trace, "notrdy");
749 return;
750 }
751 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
752 (p_ch->irb->scsw.cmd.dstat == 0)) {
753 if (test_and_set_bit(CLAW_BH_ACTIVE,
754 (void *)&p_ch->flag_a) == 0)
755 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 else
Andy Richterb805da72008-07-18 15:24:56 +0200757 CLAW_DBF_TEXT(4, trace, "PCINoBH");
758 CLAW_DBF_TEXT(4, trace, "PCI_read");
759 return;
760 }
761 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
762 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
763 (p_ch->irb->scsw.cmd.stctl ==
764 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
765 CLAW_DBF_TEXT(4, trace, "SPend_rd");
766 return;
767 }
768 clear_bit(0, (void *)&p_ch->IO_active);
769 claw_clearbit_busy(TB_RETRY, dev);
770 if (test_and_set_bit(CLAW_BH_ACTIVE,
771 (void *)&p_ch->flag_a) == 0)
772 tasklet_schedule(&p_ch->tasklet);
773 else
774 CLAW_DBF_TEXT(4, trace, "RdBHAct");
775 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
776 return;
777 case CLAW_START_WRITE:
778 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000779 dev_info(&cdev->dev,
780 "%s: Unit Check Occured in "
Andy Richterb805da72008-07-18 15:24:56 +0200781 "write channel\n", dev->name);
782 clear_bit(0, (void *)&p_ch->IO_active);
783 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000784 dev_info(&cdev->dev,
785 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200786 "occurred:\n", dev->name);
787 init_timer(&p_ch->timer);
788 p_ch->timer.function =
789 (void *)claw_write_retry;
790 p_ch->timer.data = (unsigned long)p_ch;
791 p_ch->timer.expires = jiffies + 10*HZ;
792 add_timer(&p_ch->timer);
Andy Richter4811fcb2009-01-20 06:14:33 +0000793 dev_info(&cdev->dev,
794 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200795 "restarting\n", dev->name);
796 }
797 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
798 return;
799 }
800 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
801 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000802 dev_info(&cdev->dev,
803 "%s: Unit Exception "
804 "occurred in write channel\n",
805 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200806 }
807 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
808 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
809 (p_ch->irb->scsw.cmd.stctl ==
810 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
811 CLAW_DBF_TEXT(4, trace, "writeUE");
812 return;
813 }
814 clear_bit(0, (void *)&p_ch->IO_active);
815 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
816 claw_write_next(p_ch);
817 claw_clearbit_busy(TB_TX, dev);
818 claw_clear_busy(dev);
819 }
Heiko Carstens319cb082010-08-12 01:58:27 +0000820 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +0200821 if (test_and_set_bit(CLAW_BH_ACTIVE,
822 (void *)&p_ch_r->flag_a) == 0)
823 tasklet_schedule(&p_ch_r->tasklet);
824 CLAW_DBF_TEXT(4, trace, "StWtExit");
825 return;
826 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000827 dev_warn(&cdev->dev,
828 "The CLAW device for %s received an unexpected IRQ\n",
829 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200830 CLAW_DBF_TEXT(2, trace, "badIRQ");
831 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
833
834} /* end of claw_irq_handler */
835
836
837/*-------------------------------------------------------------------*
838* claw_irq_tasklet *
839* *
840*--------------------------------------------------------------------*/
841static void
842claw_irq_tasklet ( unsigned long data )
843{
844 struct chbk * p_ch;
845 struct net_device *dev;
846 struct claw_privbk * privptr;
847
848 p_ch = (struct chbk *) data;
849 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200850 CLAW_DBF_TEXT(4, trace, "IRQtask");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200851 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 unpack_read(dev);
853 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200854 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 return;
856} /* end of claw_irq_bh */
857
858/*-------------------------------------------------------------------*
859* claw_release *
860* *
861*--------------------------------------------------------------------*/
862static int
863claw_release(struct net_device *dev)
864{
865 int rc;
866 int i;
867 unsigned long saveflags;
868 unsigned long parm;
869 struct claw_privbk *privptr;
870 DECLARE_WAITQUEUE(wait, current);
871 struct ccwbk* p_this_ccw;
872 struct ccwbk* p_buf;
873
874 if (!dev)
875 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200876 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 if (!privptr)
878 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200879 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 privptr->release_pend=1;
881 claw_setbit_busy(TB_STOP,dev);
882 for ( i = 1; i >=0 ; i--) {
883 spin_lock_irqsave(
884 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
Heiko Carstens319cb082010-08-12 01:58:27 +0000885 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 privptr->channel[i].claw_state = CLAW_STOP;
887 privptr->channel[i].IO_active = 0;
888 parm = (unsigned long) &privptr->channel[i];
Heiko Carstens319cb082010-08-12 01:58:27 +0000889 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 claw_purge_skb_queue(
Heiko Carstens319cb082010-08-12 01:58:27 +0000891 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
893 if (privptr->system_validate_comp==0x00) /* never opened? */
894 init_waitqueue_head(&privptr->channel[i].wait);
895 add_wait_queue(&privptr->channel[i].wait, &wait);
896 set_current_state(TASK_INTERRUPTIBLE);
897 spin_unlock_irqrestore(
898 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
899 schedule();
900 set_current_state(TASK_RUNNING);
901 remove_wait_queue(&privptr->channel[i].wait, &wait);
902 if (rc != 0) {
903 ccw_check_return_code(privptr->channel[i].cdev, rc);
904 }
905 }
906 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200907 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 privptr->pk_skb = NULL;
909 }
910 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200911 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 return 0;
913 }
Andy Richterb805da72008-07-18 15:24:56 +0200914 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 if (privptr->p_buff_ccw != NULL) {
916 free_pages((unsigned long)privptr->p_buff_ccw,
917 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
918 }
Andy Richterb805da72008-07-18 15:24:56 +0200919 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if (privptr->p_env->read_size < PAGE_SIZE) {
921 if (privptr->p_buff_read != NULL) {
922 free_pages((unsigned long)privptr->p_buff_read,
923 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
924 }
925 }
926 else {
927 p_buf=privptr->p_read_active_first;
928 while (p_buf!=NULL) {
929 free_pages((unsigned long)p_buf->p_buffer,
930 (int)pages_to_order_of_mag(
931 privptr->p_buff_pages_perread ));
932 p_buf=p_buf->next;
933 }
934 }
Andy Richterb805da72008-07-18 15:24:56 +0200935 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 if (privptr->p_env->write_size < PAGE_SIZE ) {
937 free_pages((unsigned long)privptr->p_buff_write,
938 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
939 }
940 else {
941 p_buf=privptr->p_write_active_first;
942 while (p_buf!=NULL) {
943 free_pages((unsigned long)p_buf->p_buffer,
944 (int)pages_to_order_of_mag(
945 privptr->p_buff_pages_perwrite ));
946 p_buf=p_buf->next;
947 }
948 }
Andy Richterb805da72008-07-18 15:24:56 +0200949 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 privptr->buffs_alloc = 0;
951 privptr->p_buff_ccw=NULL;
952 privptr->p_buff_read=NULL;
953 privptr->p_buff_write=NULL;
954 privptr->system_validate_comp=0;
955 privptr->release_pend=0;
956 /* Remove any writes that were pending and reset all reads */
957 p_this_ccw=privptr->p_read_active_first;
958 while (p_this_ccw!=NULL) {
959 p_this_ccw->header.length=0xffff;
960 p_this_ccw->header.opcode=0xff;
961 p_this_ccw->header.flag=0x00;
962 p_this_ccw=p_this_ccw->next;
963 }
964
965 while (privptr->p_write_active_first!=NULL) {
966 p_this_ccw=privptr->p_write_active_first;
967 p_this_ccw->header.flag=CLAW_PENDING;
968 privptr->p_write_active_first=p_this_ccw->next;
969 p_this_ccw->next=privptr->p_write_free_chain;
970 privptr->p_write_free_chain=p_this_ccw;
971 ++privptr->write_free_count;
972 }
973 privptr->p_write_active_last=NULL;
974 privptr->mtc_logical_link = -1;
975 privptr->mtc_skipping = 1;
976 privptr->mtc_offset=0;
977
Heiko Carstens319cb082010-08-12 01:58:27 +0000978 if (((privptr->channel[READ_CHANNEL].last_dstat |
979 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Heiko Carstens319cb082010-08-12 01:58:27 +0000981 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000982 "Deactivating %s completed with incorrect"
983 " subchannel status "
984 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 dev->name,
Heiko Carstens319cb082010-08-12 01:58:27 +0000986 privptr->channel[READ_CHANNEL].last_dstat,
987 privptr->channel[WRITE_CHANNEL].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200988 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 }
Andy Richterb805da72008-07-18 15:24:56 +0200990 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 return 0;
992} /* end of claw_release */
993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994/*-------------------------------------------------------------------*
995* claw_write_retry *
996* *
997*--------------------------------------------------------------------*/
998
999static void
1000claw_write_retry ( struct chbk *p_ch )
1001{
1002
1003 struct net_device *dev=p_ch->ndev;
1004
Andy Richterb805da72008-07-18 15:24:56 +02001005 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 return;
1008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +02001010 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 return;
1012} /* end of claw_write_retry */
1013
1014
1015/*-------------------------------------------------------------------*
1016* claw_write_next *
1017* *
1018*--------------------------------------------------------------------*/
1019
1020static void
1021claw_write_next ( struct chbk * p_ch )
1022{
1023
1024 struct net_device *dev;
1025 struct claw_privbk *privptr=NULL;
1026 struct sk_buff *pk_skb;
1027 int rc;
1028
Andy Richterb805da72008-07-18 15:24:56 +02001029 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 if (p_ch->claw_state == CLAW_STOP)
1031 return;
1032 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001033 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 claw_free_wrt_buf( dev );
1035 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -07001036 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 pk_skb = claw_pack_skb(privptr);
1038 while (pk_skb != NULL) {
1039 rc = claw_hw_tx( pk_skb, dev,1);
1040 if (privptr->write_free_count > 0) {
1041 pk_skb = claw_pack_skb(privptr);
1042 } else
1043 pk_skb = NULL;
1044 }
1045 }
1046 if (privptr->p_write_active_first!=NULL) {
1047 claw_strt_out_IO(dev);
1048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 return;
1050} /* end of claw_write_next */
1051
1052/*-------------------------------------------------------------------*
1053* *
1054* claw_timer *
1055*--------------------------------------------------------------------*/
1056
1057static void
1058claw_timer ( struct chbk * p_ch )
1059{
Andy Richterb805da72008-07-18 15:24:56 +02001060 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 p_ch->flag |= CLAW_TIMER;
1062 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 return;
1064} /* end of claw_timer */
1065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066/*
1067*
1068* functions
1069*/
1070
1071
1072/*-------------------------------------------------------------------*
1073* *
1074* pages_to_order_of_mag *
1075* *
1076* takes a number of pages from 1 to 512 and returns the *
1077* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1078* of magnitude get_free_pages() has an upper order of 9 *
1079*--------------------------------------------------------------------*/
1080
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001081static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082pages_to_order_of_mag(int num_of_pages)
1083{
1084 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001085 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001086
1087 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1089 /* 512 pages = 2Meg on 4k page systems */
1090 if (num_of_pages >= 512) {return 9; }
1091 /* we have two or more pages order is at least 1 */
1092 for (nump=2 ;nump <= 512;nump*=2) {
1093 if (num_of_pages <= nump)
1094 break;
1095 order_of_mag +=1;
1096 }
1097 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001098 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 return order_of_mag;
1100}
1101
1102/*-------------------------------------------------------------------*
1103* *
1104* add_claw_reads *
1105* *
1106*--------------------------------------------------------------------*/
1107static int
1108add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1109 struct ccwbk* p_last)
1110{
1111 struct claw_privbk *privptr;
1112 struct ccw1 temp_ccw;
1113 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001114 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001115 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 p_end = privptr->p_end_ccw;
1117
1118 /* first CCW and last CCW contains a new set of read channel programs
1119 * to apend the running channel programs
1120 */
1121 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001122 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 return 0;
1124 }
1125
1126 /* set up ending CCW sequence for this segment */
1127 if (p_end->read1) {
1128 p_end->read1=0x00; /* second ending CCW is now active */
1129 /* reset ending CCWs and setup TIC CCWs */
1130 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1131 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1132 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1133 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1134 p_end->read2_nop2.cda=0;
1135 p_end->read2_nop2.count=1;
1136 }
1137 else {
1138 p_end->read1=0x01; /* first ending CCW is now active */
1139 /* reset ending CCWs and setup TIC CCWs */
1140 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1141 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1142 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1143 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1144 p_end->read1_nop2.cda=0;
1145 p_end->read1_nop2.count=1;
1146 }
1147
1148 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001149 privptr->p_read_active_first = p_first; /* set new first */
1150 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 }
1152 else {
1153
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 /* set up TIC ccw */
1155 temp_ccw.cda= (__u32)__pa(&p_first->read);
1156 temp_ccw.count=0;
1157 temp_ccw.flags=0;
1158 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1159
1160
1161 if (p_end->read1) {
1162
1163 /* first set of CCW's is chained to the new read */
1164 /* chain, so the second set is chained to the active chain. */
1165 /* Therefore modify the second set to point to the new */
1166 /* read chain set up TIC CCWs */
1167 /* make sure we update the CCW so channel doesn't fetch it */
1168 /* when it's only half done */
1169 memcpy( &p_end->read2_nop2, &temp_ccw ,
1170 sizeof(struct ccw1));
1171 privptr->p_read_active_last->r_TIC_1.cda=
1172 (__u32)__pa(&p_first->read);
1173 privptr->p_read_active_last->r_TIC_2.cda=
1174 (__u32)__pa(&p_first->read);
1175 }
1176 else {
1177 /* make sure we update the CCW so channel doesn't */
1178 /* fetch it when it is only half done */
1179 memcpy( &p_end->read1_nop2, &temp_ccw ,
1180 sizeof(struct ccw1));
1181 privptr->p_read_active_last->r_TIC_1.cda=
1182 (__u32)__pa(&p_first->read);
1183 privptr->p_read_active_last->r_TIC_2.cda=
1184 (__u32)__pa(&p_first->read);
1185 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001186 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 privptr->p_read_active_last->next = p_first;
1188 privptr->p_read_active_last=p_last;
1189 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001190 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 return 0;
1192} /* end of add_claw_reads */
1193
1194/*-------------------------------------------------------------------*
1195 * ccw_check_return_code *
1196 * *
1197 *-------------------------------------------------------------------*/
1198
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001199static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200ccw_check_return_code(struct ccw_device *cdev, int return_code)
1201{
Andy Richterb805da72008-07-18 15:24:56 +02001202 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 if (return_code != 0) {
1204 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001205 case -EBUSY: /* BUSY is a transient state no action needed */
1206 break;
1207 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001208 dev_err(&cdev->dev, "The remote channel adapter is not"
1209 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001210 break;
1211 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001212 dev_err(&cdev->dev,
1213 "The status of the remote channel adapter"
1214 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001215 break;
1216 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001217 dev_err(&cdev->dev, "The common device layer"
1218 " returned error code %d\n",
1219 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001220 }
1221 }
1222 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223} /* end of ccw_check_return_code */
1224
1225/*-------------------------------------------------------------------*
1226* ccw_check_unit_check *
1227*--------------------------------------------------------------------*/
1228
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001229static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1231{
Andy Richterb805da72008-07-18 15:24:56 +02001232 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001233 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Andy Richterb805da72008-07-18 15:24:56 +02001235 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001236 dev_warn(dev, "The communication peer of %s disconnected\n",
1237 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001239 if (sense & 0x40) {
1240 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001241 dev_warn(dev, "The remote channel adapter for"
1242 " %s has been reset\n",
1243 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001244 }
1245 } else if (sense & 0x20) {
1246 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001247 dev_warn(dev, "A data streaming timeout occurred"
1248 " for %s\n",
1249 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001250 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001251 dev_warn(dev, "The remote channel adapter for %s"
1252 " is faulty\n",
1253 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001254 } else {
1255 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001256 " for %s\n",
1257 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001258 }
1259 } else if (sense & 0x10) {
1260 dev_warn(dev, "A read data parity error occurred"
1261 " for %s\n",
1262 ndev->name);
1263 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265} /* end of ccw_check_unit_check */
1266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267/*-------------------------------------------------------------------*
1268* find_link *
1269*--------------------------------------------------------------------*/
1270static int
1271find_link(struct net_device *dev, char *host_name, char *ws_name )
1272{
1273 struct claw_privbk *privptr;
1274 struct claw_env *p_env;
1275 int rc=0;
1276
Andy Richterb805da72008-07-18 15:24:56 +02001277 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001278 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 p_env=privptr->p_env;
1280 switch (p_env->packing)
1281 {
1282 case PACKING_ASK:
1283 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1284 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1285 rc = EINVAL;
1286 break;
1287 case DO_PACKED:
1288 case PACK_SEND:
1289 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1290 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1291 rc = EINVAL;
1292 break;
1293 default:
1294 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1295 (memcmp(p_env->api_type , ws_name, 8)!=0))
1296 rc = EINVAL;
1297 break;
1298 }
1299
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001300 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301} /* end of find_link */
1302
1303/*-------------------------------------------------------------------*
1304 * claw_hw_tx *
1305 * *
1306 * *
1307 *-------------------------------------------------------------------*/
1308
1309static int
1310claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1311{
1312 int rc=0;
1313 struct claw_privbk *privptr;
1314 struct ccwbk *p_this_ccw;
1315 struct ccwbk *p_first_ccw;
1316 struct ccwbk *p_last_ccw;
1317 __u32 numBuffers;
1318 signed long len_of_data;
1319 unsigned long bytesInThisBuffer;
1320 unsigned char *pDataAddress;
1321 struct endccw *pEnd;
1322 struct ccw1 tempCCW;
1323 struct chbk *p_ch;
1324 struct claw_env *p_env;
1325 int lock;
1326 struct clawph *pk_head;
1327 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001328
1329 CLAW_DBF_TEXT(4, trace, "hw_tx");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001330 privptr = (struct claw_privbk *)(dev->ml_priv);
Heiko Carstens319cb082010-08-12 01:58:27 +00001331 p_ch = (struct chbk *)&privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1334 /* scan the write queue to free any completed write packets */
1335 p_first_ccw=NULL;
1336 p_last_ccw=NULL;
1337 if ((p_env->packing >= PACK_SEND) &&
1338 (skb->cb[1] != 'P')) {
1339 skb_push(skb,sizeof(struct clawph));
1340 pk_head=(struct clawph *)skb->data;
1341 pk_head->len=skb->len-sizeof(struct clawph);
1342 if (pk_head->len%4) {
1343 pk_head->len+= 4-(pk_head->len%4);
1344 skb_pad(skb,4-(pk_head->len%4));
1345 skb_put(skb,4-(pk_head->len%4));
1346 }
1347 if (p_env->packing == DO_PACKED)
1348 pk_head->link_num = linkid;
1349 else
1350 pk_head->link_num = 0;
1351 pk_head->flag = 0x00;
1352 skb_pad(skb,4);
1353 skb->cb[1] = 'P';
1354 }
1355 if (linkid == 0) {
1356 if (claw_check_busy(dev)) {
1357 if (privptr->write_free_count!=0) {
1358 claw_clear_busy(dev);
1359 }
1360 else {
1361 claw_strt_out_IO(dev );
1362 claw_free_wrt_buf( dev );
1363 if (privptr->write_free_count==0) {
Heiko Carstens319cb082010-08-12 01:58:27 +00001364 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 atomic_inc(&skb->users);
1366 skb_queue_tail(&ch->collect_queue, skb);
1367 goto Done;
1368 }
1369 else {
1370 claw_clear_busy(dev);
1371 }
1372 }
1373 }
1374 /* tx lock */
1375 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Heiko Carstens319cb082010-08-12 01:58:27 +00001376 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 atomic_inc(&skb->users);
1378 skb_queue_tail(&ch->collect_queue, skb);
1379 claw_strt_out_IO(dev );
1380 rc=-EBUSY;
1381 goto Done2;
1382 }
1383 }
1384 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001385 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387 /* If that number of buffers isn't available, give up for now */
1388 if (privptr->write_free_count < numBuffers ||
1389 privptr->p_write_free_chain == NULL ) {
1390
1391 claw_setbit_busy(TB_NOBUFFER,dev);
Heiko Carstens319cb082010-08-12 01:58:27 +00001392 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 atomic_inc(&skb->users);
1394 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001395 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 goto Done2;
1397 }
1398 pDataAddress=skb->data;
1399 len_of_data=skb->len;
1400
1401 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1403 if (p_this_ccw == NULL) { /* lost the race */
Heiko Carstens319cb082010-08-12 01:58:27 +00001404 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 atomic_inc(&skb->users);
1406 skb_queue_tail(&ch->collect_queue, skb);
1407 goto Done2;
1408 }
1409 privptr->p_write_free_chain=p_this_ccw->next;
1410 p_this_ccw->next=NULL;
1411 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001412 if (len_of_data >= privptr->p_env->write_size)
1413 bytesInThisBuffer = privptr->p_env->write_size;
1414 else
1415 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1417 len_of_data-=bytesInThisBuffer;
1418 pDataAddress+=(unsigned long)bytesInThisBuffer;
1419 /* setup write CCW */
1420 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1421 if (len_of_data>0) {
1422 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1423 }
1424 p_this_ccw->write.count=bytesInThisBuffer;
1425 /* now add to end of this chain */
1426 if (p_first_ccw==NULL) {
1427 p_first_ccw=p_this_ccw;
1428 }
1429 if (p_last_ccw!=NULL) {
1430 p_last_ccw->next=p_this_ccw;
1431 /* set up TIC ccws */
1432 p_last_ccw->w_TIC_1.cda=
1433 (__u32)__pa(&p_this_ccw->write);
1434 }
1435 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 }
1437
1438 /* FirstCCW and LastCCW now contain a new set of write channel
1439 * programs to append to the running channel program
1440 */
1441
1442 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001443 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 pEnd=privptr->p_end_ccw;
1445 if (pEnd->write1) {
1446 pEnd->write1=0x00; /* second end ccw is now active */
1447 /* set up Tic CCWs */
1448 p_last_ccw->w_TIC_1.cda=
1449 (__u32)__pa(&pEnd->write2_nop1);
1450 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1451 pEnd->write2_nop2.flags =
1452 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1453 pEnd->write2_nop2.cda=0;
1454 pEnd->write2_nop2.count=1;
1455 }
1456 else { /* end of if (pEnd->write1)*/
1457 pEnd->write1=0x01; /* first end ccw is now active */
1458 /* set up Tic CCWs */
1459 p_last_ccw->w_TIC_1.cda=
1460 (__u32)__pa(&pEnd->write1_nop1);
1461 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1462 pEnd->write1_nop2.flags =
1463 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1464 pEnd->write1_nop2.cda=0;
1465 pEnd->write1_nop2.count=1;
1466 } /* end if if (pEnd->write1) */
1467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 if (privptr->p_write_active_first==NULL ) {
1469 privptr->p_write_active_first=p_first_ccw;
1470 privptr->p_write_active_last=p_last_ccw;
1471 }
1472 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 /* set up Tic CCWs */
1474
1475 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1476 tempCCW.count=0;
1477 tempCCW.flags=0;
1478 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1479
1480 if (pEnd->write1) {
1481
1482 /*
1483 * first set of ending CCW's is chained to the new write
1484 * chain, so the second set is chained to the active chain
1485 * Therefore modify the second set to point the new write chain.
1486 * make sure we update the CCW atomically
1487 * so channel does not fetch it when it's only half done
1488 */
1489 memcpy( &pEnd->write2_nop2, &tempCCW ,
1490 sizeof(struct ccw1));
1491 privptr->p_write_active_last->w_TIC_1.cda=
1492 (__u32)__pa(&p_first_ccw->write);
1493 }
1494 else {
1495
1496 /*make sure we update the CCW atomically
1497 *so channel does not fetch it when it's only half done
1498 */
1499 memcpy(&pEnd->write1_nop2, &tempCCW ,
1500 sizeof(struct ccw1));
1501 privptr->p_write_active_last->w_TIC_1.cda=
1502 (__u32)__pa(&p_first_ccw->write);
1503
1504 } /* end if if (pEnd->write1) */
1505
1506 privptr->p_write_active_last->next=p_first_ccw;
1507 privptr->p_write_active_last=p_last_ccw;
1508 }
1509
1510 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001511 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 if (linkid==0) {
1513 lock=LOCK_NO;
1514 }
1515 else {
1516 lock=LOCK_YES;
1517 }
1518 claw_strt_out_IO(dev );
1519 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 if (privptr->write_free_count==0) {
1521 claw_setbit_busy(TB_NOBUFFER,dev);
1522 }
1523Done2:
1524 claw_clearbit_busy(TB_TX,dev);
1525Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return(rc);
1527} /* end of claw_hw_tx */
1528
1529/*-------------------------------------------------------------------*
1530* *
1531* init_ccw_bk *
1532* *
1533*--------------------------------------------------------------------*/
1534
1535static int
1536init_ccw_bk(struct net_device *dev)
1537{
1538
1539 __u32 ccw_blocks_required;
1540 __u32 ccw_blocks_perpage;
1541 __u32 ccw_pages_required;
1542 __u32 claw_reads_perpage=1;
1543 __u32 claw_read_pages;
1544 __u32 claw_writes_perpage=1;
1545 __u32 claw_write_pages;
1546 void *p_buff=NULL;
1547 struct ccwbk*p_free_chain;
1548 struct ccwbk*p_buf;
1549 struct ccwbk*p_last_CCWB;
1550 struct ccwbk*p_first_CCWB;
1551 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001552 addr_t real_address;
1553 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 struct clawh *pClawH=NULL;
1555 addr_t real_TIC_address;
1556 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001557 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
1559 /* initialize statistics field */
1560 privptr->active_link_ID=0;
1561 /* initialize ccwbk pointers */
1562 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1563 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1564 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1565 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1566 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1567 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1568 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1569 privptr->buffs_alloc = 0;
1570 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1571 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1572 /* initialize free write ccwbk counter */
1573 privptr->write_free_count=0; /* number of free bufs on write chain */
1574 p_last_CCWB = NULL;
1575 p_first_CCWB= NULL;
1576 /*
1577 * We need 1 CCW block for each read buffer, 1 for each
1578 * write buffer, plus 1 for ClawSignalBlock
1579 */
1580 ccw_blocks_required =
1581 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 /*
1583 * compute number of CCW blocks that will fit in a page
1584 */
1585 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1586 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001587 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 /*
1590 * read and write sizes are set by 2 constants in claw.h
1591 * 4k and 32k. Unpacked values other than 4k are not going to
1592 * provide good performance. With packing buffers support 32k
1593 * buffers are used.
1594 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001595 if (privptr->p_env->read_size < PAGE_SIZE) {
1596 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1597 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1598 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 }
1600 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001601 privptr->p_buff_pages_perread =
1602 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1603 claw_read_pages = privptr->p_env->read_buffers *
1604 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 }
1606 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001607 claw_writes_perpage =
1608 PAGE_SIZE / privptr->p_env->write_size;
1609 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1610 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 }
1613 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001614 privptr->p_buff_pages_perwrite =
1615 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1616 claw_write_pages = privptr->p_env->write_buffers *
1617 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 /*
1620 * allocate ccw_pages_required
1621 */
1622 if (privptr->p_buff_ccw==NULL) {
1623 privptr->p_buff_ccw=
1624 (void *)__get_free_pages(__GFP_DMA,
1625 (int)pages_to_order_of_mag(ccw_pages_required ));
1626 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 return -ENOMEM;
1628 }
1629 privptr->p_buff_ccw_num=ccw_pages_required;
1630 }
1631 memset(privptr->p_buff_ccw, 0x00,
1632 privptr->p_buff_ccw_num * PAGE_SIZE);
1633
1634 /*
1635 * obtain ending ccw block address
1636 *
1637 */
1638 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1639 real_address = (__u32)__pa(privptr->p_end_ccw);
1640 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 p_endccw=privptr->p_end_ccw;
1642 p_endccw->real=real_address;
1643 p_endccw->write1=0x00;
1644 p_endccw->read1=0x00;
1645
1646 /* write1_nop1 */
1647 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1648 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1649 p_endccw->write1_nop1.count = 1;
1650 p_endccw->write1_nop1.cda = 0;
1651
1652 /* write1_nop2 */
1653 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1654 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1655 p_endccw->write1_nop2.count = 1;
1656 p_endccw->write1_nop2.cda = 0;
1657
1658 /* write2_nop1 */
1659 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1660 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1661 p_endccw->write2_nop1.count = 1;
1662 p_endccw->write2_nop1.cda = 0;
1663
1664 /* write2_nop2 */
1665 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1666 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1667 p_endccw->write2_nop2.count = 1;
1668 p_endccw->write2_nop2.cda = 0;
1669
1670 /* read1_nop1 */
1671 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1672 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1673 p_endccw->read1_nop1.count = 1;
1674 p_endccw->read1_nop1.cda = 0;
1675
1676 /* read1_nop2 */
1677 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1678 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1679 p_endccw->read1_nop2.count = 1;
1680 p_endccw->read1_nop2.cda = 0;
1681
1682 /* read2_nop1 */
1683 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1684 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1685 p_endccw->read2_nop1.count = 1;
1686 p_endccw->read2_nop1.cda = 0;
1687
1688 /* read2_nop2 */
1689 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1690 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1691 p_endccw->read2_nop2.count = 1;
1692 p_endccw->read2_nop2.cda = 0;
1693
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 /*
1695 * Build a chain of CCWs
1696 *
1697 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 p_buff=privptr->p_buff_ccw;
1699
1700 p_free_chain=NULL;
1701 for (i=0 ; i < ccw_pages_required; i++ ) {
1702 real_address = (__u32)__pa(p_buff);
1703 p_buf=p_buff;
1704 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1705 p_buf->next = p_free_chain;
1706 p_free_chain = p_buf;
1707 p_buf->real=(__u32)__pa(p_buf);
1708 ++p_buf;
1709 }
1710 p_buff+=PAGE_SIZE;
1711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 /*
1713 * Initialize ClawSignalBlock
1714 *
1715 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 if (privptr->p_claw_signal_blk==NULL) {
1717 privptr->p_claw_signal_blk=p_free_chain;
1718 p_free_chain=p_free_chain->next;
1719 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1720 pClawH->length=0xffff;
1721 pClawH->opcode=0xff;
1722 pClawH->flag=CLAW_BUSY;
1723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 /*
1726 * allocate write_pages_required and add to free chain
1727 */
1728 if (privptr->p_buff_write==NULL) {
1729 if (privptr->p_env->write_size < PAGE_SIZE) {
1730 privptr->p_buff_write=
1731 (void *)__get_free_pages(__GFP_DMA,
1732 (int)pages_to_order_of_mag(claw_write_pages ));
1733 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 return -ENOMEM;
1736 }
1737 /*
1738 * Build CLAW write free chain
1739 *
1740 */
1741
1742 memset(privptr->p_buff_write, 0x00,
1743 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 privptr->p_write_free_chain=NULL;
1745
1746 p_buff=privptr->p_buff_write;
1747
1748 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1749 p_buf = p_free_chain; /* get a CCW */
1750 p_free_chain = p_buf->next;
1751 p_buf->next =privptr->p_write_free_chain;
1752 privptr->p_write_free_chain = p_buf;
1753 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1754 p_buf-> write.cda = (__u32)__pa(p_buff);
1755 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1756 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1757 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1758 p_buf-> w_read_FF.count = 1;
1759 p_buf-> w_read_FF.cda =
1760 (__u32)__pa(&p_buf-> header.flag);
1761 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1762 p_buf-> w_TIC_1.flags = 0;
1763 p_buf-> w_TIC_1.count = 0;
1764
Andy Richter4811fcb2009-01-20 06:14:33 +00001765 if (((unsigned long)p_buff +
1766 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001768 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1769 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 }
1771 }
1772 }
1773 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1774 {
1775 privptr->p_write_free_chain=NULL;
1776 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1777 p_buff=(void *)__get_free_pages(__GFP_DMA,
1778 (int)pages_to_order_of_mag(
1779 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 free_pages((unsigned long)privptr->p_buff_ccw,
1782 (int)pages_to_order_of_mag(
1783 privptr->p_buff_ccw_num));
1784 privptr->p_buff_ccw=NULL;
1785 p_buf=privptr->p_buff_write;
1786 while (p_buf!=NULL) {
1787 free_pages((unsigned long)
1788 p_buf->p_buffer,
1789 (int)pages_to_order_of_mag(
1790 privptr->p_buff_pages_perwrite));
1791 p_buf=p_buf->next;
1792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 return -ENOMEM;
1794 } /* Error on get_pages */
1795 memset(p_buff, 0x00, privptr->p_env->write_size );
1796 p_buf = p_free_chain;
1797 p_free_chain = p_buf->next;
1798 p_buf->next = privptr->p_write_free_chain;
1799 privptr->p_write_free_chain = p_buf;
1800 privptr->p_buff_write = p_buf;
1801 p_buf->p_buffer=(struct clawbuf *)p_buff;
1802 p_buf-> write.cda = (__u32)__pa(p_buff);
1803 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1804 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1805 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1806 p_buf-> w_read_FF.count = 1;
1807 p_buf-> w_read_FF.cda =
1808 (__u32)__pa(&p_buf-> header.flag);
1809 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1810 p_buf-> w_TIC_1.flags = 0;
1811 p_buf-> w_TIC_1.count = 0;
1812 } /* for all write_buffers */
1813
1814 } /* else buffers are PAGE_SIZE or bigger */
1815
1816 }
1817 privptr->p_buff_write_num=claw_write_pages;
1818 privptr->write_free_count=privptr->p_env->write_buffers;
1819
1820
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 /*
1822 * allocate read_pages_required and chain to free chain
1823 */
1824 if (privptr->p_buff_read==NULL) {
1825 if (privptr->p_env->read_size < PAGE_SIZE) {
1826 privptr->p_buff_read=
1827 (void *)__get_free_pages(__GFP_DMA,
1828 (int)pages_to_order_of_mag(claw_read_pages) );
1829 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 free_pages((unsigned long)privptr->p_buff_ccw,
1831 (int)pages_to_order_of_mag(
1832 privptr->p_buff_ccw_num));
1833 /* free the write pages size is < page size */
1834 free_pages((unsigned long)privptr->p_buff_write,
1835 (int)pages_to_order_of_mag(
1836 privptr->p_buff_write_num));
1837 privptr->p_buff_ccw=NULL;
1838 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 return -ENOMEM;
1840 }
1841 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1842 privptr->p_buff_read_num=claw_read_pages;
1843 /*
1844 * Build CLAW read free chain
1845 *
1846 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 p_buff=privptr->p_buff_read;
1848 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1849 p_buf = p_free_chain;
1850 p_free_chain = p_buf->next;
1851
1852 if (p_last_CCWB==NULL) {
1853 p_buf->next=NULL;
1854 real_TIC_address=0;
1855 p_last_CCWB=p_buf;
1856 }
1857 else {
1858 p_buf->next=p_first_CCWB;
1859 real_TIC_address=
1860 (__u32)__pa(&p_first_CCWB -> read );
1861 }
1862
1863 p_first_CCWB=p_buf;
1864
1865 p_buf->p_buffer=(struct clawbuf *)p_buff;
1866 /* initialize read command */
1867 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1868 p_buf-> read.cda = (__u32)__pa(p_buff);
1869 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1870 p_buf-> read.count = privptr->p_env->read_size;
1871
1872 /* initialize read_h command */
1873 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1874 p_buf-> read_h.cda =
1875 (__u32)__pa(&(p_buf->header));
1876 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1877 p_buf-> read_h.count = sizeof(struct clawh);
1878
1879 /* initialize Signal command */
1880 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1881 p_buf-> signal.cda =
1882 (__u32)__pa(&(pClawH->flag));
1883 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1884 p_buf-> signal.count = 1;
1885
1886 /* initialize r_TIC_1 command */
1887 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1888 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1889 p_buf-> r_TIC_1.flags = 0;
1890 p_buf-> r_TIC_1.count = 0;
1891
1892 /* initialize r_read_FF command */
1893 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1894 p_buf-> r_read_FF.cda =
1895 (__u32)__pa(&(pClawH->flag));
1896 p_buf-> r_read_FF.flags =
1897 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1898 p_buf-> r_read_FF.count = 1;
1899
1900 /* initialize r_TIC_2 */
1901 memcpy(&p_buf->r_TIC_2,
1902 &p_buf->r_TIC_1, sizeof(struct ccw1));
1903
1904 /* initialize Header */
1905 p_buf->header.length=0xffff;
1906 p_buf->header.opcode=0xff;
1907 p_buf->header.flag=CLAW_PENDING;
1908
Andy Richter4811fcb2009-01-20 06:14:33 +00001909 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1910 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1911 -1)
1912 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 p_buff= p_buff+privptr->p_env->read_size;
1914 }
1915 else {
1916 p_buff=
1917 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001918 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 & PAGE_MASK) ;
1920 }
1921 } /* for read_buffers */
1922 } /* read_size < PAGE_SIZE */
1923 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1925 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001926 (int)pages_to_order_of_mag(
1927 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001930 (int)pages_to_order_of_mag(privptr->
1931 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 /* free the write pages */
1933 p_buf=privptr->p_buff_write;
1934 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001935 free_pages(
1936 (unsigned long)p_buf->p_buffer,
1937 (int)pages_to_order_of_mag(
1938 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 p_buf=p_buf->next;
1940 }
1941 /* free any read pages already alloc */
1942 p_buf=privptr->p_buff_read;
1943 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001944 free_pages(
1945 (unsigned long)p_buf->p_buffer,
1946 (int)pages_to_order_of_mag(
1947 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 p_buf=p_buf->next;
1949 }
1950 privptr->p_buff_ccw=NULL;
1951 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 return -ENOMEM;
1953 }
1954 memset(p_buff, 0x00, privptr->p_env->read_size);
1955 p_buf = p_free_chain;
1956 privptr->p_buff_read = p_buf;
1957 p_free_chain = p_buf->next;
1958
1959 if (p_last_CCWB==NULL) {
1960 p_buf->next=NULL;
1961 real_TIC_address=0;
1962 p_last_CCWB=p_buf;
1963 }
1964 else {
1965 p_buf->next=p_first_CCWB;
1966 real_TIC_address=
1967 (addr_t)__pa(
1968 &p_first_CCWB -> read );
1969 }
1970
1971 p_first_CCWB=p_buf;
1972 /* save buff address */
1973 p_buf->p_buffer=(struct clawbuf *)p_buff;
1974 /* initialize read command */
1975 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1976 p_buf-> read.cda = (__u32)__pa(p_buff);
1977 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1978 p_buf-> read.count = privptr->p_env->read_size;
1979
1980 /* initialize read_h command */
1981 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1982 p_buf-> read_h.cda =
1983 (__u32)__pa(&(p_buf->header));
1984 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1985 p_buf-> read_h.count = sizeof(struct clawh);
1986
1987 /* initialize Signal command */
1988 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1989 p_buf-> signal.cda =
1990 (__u32)__pa(&(pClawH->flag));
1991 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1992 p_buf-> signal.count = 1;
1993
1994 /* initialize r_TIC_1 command */
1995 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1996 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1997 p_buf-> r_TIC_1.flags = 0;
1998 p_buf-> r_TIC_1.count = 0;
1999
2000 /* initialize r_read_FF command */
2001 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2002 p_buf-> r_read_FF.cda =
2003 (__u32)__pa(&(pClawH->flag));
2004 p_buf-> r_read_FF.flags =
2005 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2006 p_buf-> r_read_FF.count = 1;
2007
2008 /* initialize r_TIC_2 */
2009 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
2010 sizeof(struct ccw1));
2011
2012 /* initialize Header */
2013 p_buf->header.length=0xffff;
2014 p_buf->header.opcode=0xff;
2015 p_buf->header.flag=CLAW_PENDING;
2016
2017 } /* For read_buffers */
2018 } /* read_size >= PAGE_SIZE */
2019 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
2021 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02002022
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 return 0;
2024} /* end of init_ccw_bk */
2025
2026/*-------------------------------------------------------------------*
2027* *
2028* probe_error *
2029* *
2030*--------------------------------------------------------------------*/
2031
2032static void
2033probe_error( struct ccwgroup_device *cgdev)
2034{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002035 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002036
2037 CLAW_DBF_TEXT(4, trace, "proberr");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002038 privptr = dev_get_drvdata(&cgdev->dev);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002039 if (privptr != NULL) {
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002040 dev_set_drvdata(&cgdev->dev, NULL);
Jesper Juhl17fd6822005-11-07 01:01:30 -08002041 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002042 kfree(privptr->p_mtc_envelope);
2043 kfree(privptr);
2044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045} /* probe_error */
2046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047/*-------------------------------------------------------------------*
2048* claw_process_control *
2049* *
2050* *
2051*--------------------------------------------------------------------*/
2052
2053static int
2054claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2055{
2056
2057 struct clawbuf *p_buf;
2058 struct clawctl ctlbk;
2059 struct clawctl *p_ctlbk;
2060 char temp_host_name[8];
2061 char temp_ws_name[8];
2062 struct claw_privbk *privptr;
2063 struct claw_env *p_env;
2064 struct sysval *p_sysval;
2065 struct conncmd *p_connect=NULL;
2066 int rc;
2067 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002068 struct device *tdev;
2069 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 udelay(1000); /* Wait a ms for the control packets to
2071 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02002072 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 p_env=privptr->p_env;
Heiko Carstens319cb082010-08-12 01:58:27 +00002074 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 memcpy( &temp_host_name, p_env->host_name, 8);
2076 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00002077 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 "Received Control Packet\n",
2079 dev->name, temp_ws_name);
2080 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 return 0;
2082 }
2083 p_buf=p_ccw->p_buffer;
2084 p_ctlbk=&ctlbk;
2085 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2086 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2087 } else {
2088 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 switch (p_ctlbk->command)
2091 {
Andy Richterb805da72008-07-18 15:24:56 +02002092 case SYSTEM_VALIDATE_REQUEST:
2093 if (p_ctlbk->version != CLAW_VERSION_ID) {
2094 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2095 CLAW_RC_WRONG_VERSION);
Andy Richter4811fcb2009-01-20 06:14:33 +00002096 dev_warn(tdev, "The communication peer of %s"
2097 " uses an incorrect API version %d\n",
2098 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002099 }
2100 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002101 dev_info(tdev, "%s: Recv Sys Validate Request: "
2102 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2103 "Host name=%.8s\n",
2104 dev->name, p_ctlbk->version,
2105 p_ctlbk->linkid,
2106 p_ctlbk->correlator,
2107 p_sysval->WS_name,
2108 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002109 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2110 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2111 CLAW_RC_NAME_MISMATCH);
2112 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2113 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2114 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002115 dev_warn(tdev,
2116 "Host name %s for %s does not match the"
2117 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002118 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002119 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002120 temp_host_name);
2121 }
2122 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2123 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2124 CLAW_RC_NAME_MISMATCH);
2125 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2126 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2127 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002128 dev_warn(tdev, "Adapter name %s for %s does not match"
2129 " the remote host name %s\n",
2130 p_sysval->WS_name,
2131 dev->name,
2132 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002133 }
2134 if ((p_sysval->write_frame_size < p_env->write_size) &&
2135 (p_env->packing == 0)) {
2136 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2137 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002138 dev_warn(tdev,
2139 "The local write buffer is smaller than the"
2140 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002141 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2142 }
2143 if ((p_sysval->read_frame_size < p_env->read_size) &&
2144 (p_env->packing == 0)) {
2145 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2146 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002147 dev_warn(tdev,
2148 "The local read buffer is smaller than the"
2149 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002150 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2151 }
2152 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002153 dev_info(tdev,
2154 "CLAW device %.8s: System validate"
2155 " completed.\n", temp_ws_name);
2156 dev_info(tdev,
2157 "%s: sys Validate Rsize:%d Wsize:%d\n",
2158 dev->name, p_sysval->read_frame_size,
2159 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002160 privptr->system_validate_comp = 1;
2161 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2162 p_env->packing = PACKING_ASK;
2163 claw_strt_conn_req(dev);
2164 break;
2165 case SYSTEM_VALIDATE_RESPONSE:
2166 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002167 dev_info(tdev,
2168 "Settings for %s validated (version=%d, "
2169 "remote device=%d, rc=%d, adapter name=%.8s, "
2170 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002171 dev->name,
2172 p_ctlbk->version,
2173 p_ctlbk->correlator,
2174 p_ctlbk->rc,
2175 p_sysval->WS_name,
2176 p_sysval->host_name);
2177 switch (p_ctlbk->rc) {
2178 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002179 dev_info(tdev, "%s: CLAW device "
2180 "%.8s: System validate completed.\n",
2181 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002182 if (privptr->system_validate_comp == 0)
2183 claw_strt_conn_req(dev);
2184 privptr->system_validate_comp = 1;
2185 break;
2186 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002187 dev_warn(tdev, "Validating %s failed because of"
2188 " a host or adapter name mismatch\n",
2189 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002190 break;
2191 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002192 dev_warn(tdev, "Validating %s failed because of a"
2193 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002194 dev->name);
2195 break;
2196 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002197 dev_warn(tdev, "Validating %s failed because of a"
2198 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002199 dev->name);
2200 break;
2201 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002202 dev_warn(tdev, "The communication peer of %s rejected"
2203 " the connection\n",
2204 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002205 break;
2206 }
2207 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
Andy Richterb805da72008-07-18 15:24:56 +02002209 case CONNECTION_REQUEST:
2210 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002211 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002212 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2213 dev->name,
2214 p_ctlbk->version,
2215 p_ctlbk->linkid,
2216 p_ctlbk->correlator,
2217 p_connect->host_name,
2218 p_connect->WS_name);
2219 if (privptr->active_link_ID != 0) {
2220 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002221 dev_info(tdev, "%s rejected a connection request"
2222 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002223 dev->name);
2224 }
2225 if (p_ctlbk->linkid != 1) {
2226 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002227 dev_info(tdev, "%s rejected a request to open multiple"
2228 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002229 dev->name);
2230 }
2231 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2232 if (rc != 0) {
2233 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002234 dev_info(tdev, "%s rejected a connection request"
2235 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002236 dev->name);
2237 }
2238 claw_send_control(dev,
2239 CONNECTION_CONFIRM, p_ctlbk->linkid,
2240 p_ctlbk->correlator,
2241 0, p_connect->host_name,
2242 p_connect->WS_name);
2243 if (p_env->packing == PACKING_ASK) {
2244 p_env->packing = PACK_SEND;
2245 claw_snd_conn_req(dev, 0);
2246 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002247 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002248 "completed link_id=%d.\n",
2249 dev->name, temp_ws_name,
2250 p_ctlbk->linkid);
2251 privptr->active_link_ID = p_ctlbk->linkid;
Heiko Carstens319cb082010-08-12 01:58:27 +00002252 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002253 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2254 break;
2255 case CONNECTION_RESPONSE:
2256 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002257 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002258 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2259 dev->name,
2260 p_ctlbk->version,
2261 p_ctlbk->linkid,
2262 p_ctlbk->correlator,
2263 p_ctlbk->rc,
2264 p_connect->host_name,
2265 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Andy Richterb805da72008-07-18 15:24:56 +02002267 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002268 dev_warn(tdev, "The communication peer of %s rejected"
2269 " a connection request\n",
2270 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002271 return 1;
2272 }
2273 rc = find_link(dev,
2274 p_connect->host_name, p_connect->WS_name);
2275 if (rc != 0) {
2276 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002277 dev_warn(tdev, "The communication peer of %s"
2278 " rejected a connection "
2279 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002280 dev->name);
2281 }
2282 /* should be until CONNECTION_CONFIRM */
2283 privptr->active_link_ID = -(p_ctlbk->linkid);
2284 break;
2285 case CONNECTION_CONFIRM:
2286 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002287 dev_info(tdev,
2288 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002289 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2290 dev->name,
2291 p_ctlbk->version,
2292 p_ctlbk->linkid,
2293 p_ctlbk->correlator,
2294 p_connect->host_name,
2295 p_connect->WS_name);
2296 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2297 privptr->active_link_ID = p_ctlbk->linkid;
2298 if (p_env->packing > PACKING_ASK) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002299 dev_info(tdev,
2300 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 p_env->packing = DO_PACKED;
2302 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002303 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002304 wake_up(&p_ch->wait);
2305 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002306 dev_warn(tdev, "Activating %s failed because of"
2307 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002308 dev->name, p_ctlbk->linkid);
2309 claw_snd_disc(dev, p_ctlbk);
2310 }
2311 break;
2312 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002313 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002314 "Vers=%d,link_id=%d,Corr=%d\n",
2315 dev->name, p_ctlbk->version,
2316 p_ctlbk->linkid, p_ctlbk->correlator);
2317 if ((p_ctlbk->linkid == 2) &&
2318 (p_env->packing == PACK_SEND)) {
2319 privptr->active_link_ID = 1;
2320 p_env->packing = DO_PACKED;
2321 } else
2322 privptr->active_link_ID = 0;
2323 break;
2324 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002325 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002326 dev->name);
2327 break;
2328 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002329 dev_warn(tdev, "The communication peer of %s sent"
2330 " an unknown command code\n",
2331 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002332 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 }
2334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 return 0;
2336} /* end of claw_process_control */
2337
2338
2339/*-------------------------------------------------------------------*
2340* claw_send_control *
2341* *
2342*--------------------------------------------------------------------*/
2343
2344static int
2345claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2346 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2347{
2348 struct claw_privbk *privptr;
2349 struct clawctl *p_ctl;
2350 struct sysval *p_sysval;
2351 struct conncmd *p_connect;
2352 struct sk_buff *skb;
2353
Andy Richterb805da72008-07-18 15:24:56 +02002354 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002355 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2357
2358 p_ctl->command=type;
2359 p_ctl->version=CLAW_VERSION_ID;
2360 p_ctl->linkid=link;
2361 p_ctl->correlator=correlator;
2362 p_ctl->rc=rc;
2363
2364 p_sysval=(struct sysval *)&p_ctl->data;
2365 p_connect=(struct conncmd *)&p_ctl->data;
2366
2367 switch (p_ctl->command) {
2368 case SYSTEM_VALIDATE_REQUEST:
2369 case SYSTEM_VALIDATE_RESPONSE:
2370 memcpy(&p_sysval->host_name, local_name, 8);
2371 memcpy(&p_sysval->WS_name, remote_name, 8);
2372 if (privptr->p_env->packing > 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002373 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2374 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002376 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002377 p_sysval->read_frame_size =
2378 privptr->p_env->read_size;
2379 p_sysval->write_frame_size =
2380 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 }
2382 memset(&p_sysval->reserved, 0x00, 4);
2383 break;
2384 case CONNECTION_REQUEST:
2385 case CONNECTION_RESPONSE:
2386 case CONNECTION_CONFIRM:
2387 case DISCONNECT:
2388 memcpy(&p_sysval->host_name, local_name, 8);
2389 memcpy(&p_sysval->WS_name, remote_name, 8);
2390 if (privptr->p_env->packing > 0) {
2391 /* How big is the biggest packet */
2392 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2393 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2394 } else {
2395 memset(&p_connect->reserved1, 0x00, 4);
2396 memset(&p_connect->reserved2, 0x00, 4);
2397 }
2398 break;
2399 default:
2400 break;
2401 }
2402
2403 /* write Control Record to the device */
2404
2405
2406 skb = dev_alloc_skb(sizeof(struct clawctl));
2407 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 return -ENOMEM;
2409 }
2410 memcpy(skb_put(skb, sizeof(struct clawctl)),
2411 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 if (privptr->p_env->packing >= PACK_SEND)
2413 claw_hw_tx(skb, dev, 1);
2414 else
2415 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 return 0;
2417} /* end of claw_send_control */
2418
2419/*-------------------------------------------------------------------*
2420* claw_snd_conn_req *
2421* *
2422*--------------------------------------------------------------------*/
2423static int
2424claw_snd_conn_req(struct net_device *dev, __u8 link)
2425{
2426 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002427 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 struct clawctl *p_ctl;
2429
Andy Richterb805da72008-07-18 15:24:56 +02002430 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 rc = 1;
2432 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2433 p_ctl->linkid = link;
2434 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 return rc;
2436 }
2437 if (privptr->p_env->packing == PACKING_ASK )
2438 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2439 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2440 if (privptr->p_env->packing == PACK_SEND) {
2441 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2442 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2443 }
2444 if (privptr->p_env->packing == 0)
2445 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2446 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 return rc;
2448
2449} /* end of claw_snd_conn_req */
2450
2451
2452/*-------------------------------------------------------------------*
2453* claw_snd_disc *
2454* *
2455*--------------------------------------------------------------------*/
2456
2457static int
2458claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2459{
2460 int rc;
2461 struct conncmd * p_connect;
2462
Andy Richterb805da72008-07-18 15:24:56 +02002463 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 p_connect=(struct conncmd *)&p_ctl->data;
2465
2466 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2467 p_ctl->correlator, 0,
2468 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 return rc;
2470} /* end of claw_snd_disc */
2471
2472
2473/*-------------------------------------------------------------------*
2474* claw_snd_sys_validate_rsp *
2475* *
2476*--------------------------------------------------------------------*/
2477
2478static int
2479claw_snd_sys_validate_rsp(struct net_device *dev,
2480 struct clawctl *p_ctl, __u32 return_code)
2481{
2482 struct claw_env * p_env;
2483 struct claw_privbk *privptr;
2484 int rc;
2485
Andy Richterb805da72008-07-18 15:24:56 +02002486 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002487 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 p_env=privptr->p_env;
2489 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2490 p_ctl->linkid,
2491 p_ctl->correlator,
2492 return_code,
2493 p_env->host_name,
2494 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 return rc;
2496} /* end of claw_snd_sys_validate_rsp */
2497
2498/*-------------------------------------------------------------------*
2499* claw_strt_conn_req *
2500* *
2501*--------------------------------------------------------------------*/
2502
2503static int
2504claw_strt_conn_req(struct net_device *dev )
2505{
2506 int rc;
2507
Andy Richterb805da72008-07-18 15:24:56 +02002508 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 return rc;
2511} /* end of claw_strt_conn_req */
2512
2513
2514
2515/*-------------------------------------------------------------------*
2516 * claw_stats *
2517 *-------------------------------------------------------------------*/
2518
2519static struct
2520net_device_stats *claw_stats(struct net_device *dev)
2521{
2522 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002523
2524 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002525 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 return &privptr->stats;
2527} /* end of claw_stats */
2528
2529
2530/*-------------------------------------------------------------------*
2531* unpack_read *
2532* *
2533*--------------------------------------------------------------------*/
2534static void
2535unpack_read(struct net_device *dev )
2536{
2537 struct sk_buff *skb;
2538 struct claw_privbk *privptr;
2539 struct claw_env *p_env;
2540 struct ccwbk *p_this_ccw;
2541 struct ccwbk *p_first_ccw;
2542 struct ccwbk *p_last_ccw;
2543 struct clawph *p_packh;
2544 void *p_packd;
2545 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002546 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548 __u32 len_of_data;
2549 __u32 pack_off;
2550 __u8 link_num;
2551 __u8 mtc_this_frm=0;
2552 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 int i=0;
2554 int p=0;
2555
Andy Richterb805da72008-07-18 15:24:56 +02002556 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 p_first_ccw=NULL;
2558 p_last_ccw=NULL;
2559 p_packh=NULL;
2560 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002561 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002562
Heiko Carstens319cb082010-08-12 01:58:27 +00002563 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 p_env = privptr->p_env;
2565 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 pack_off = 0;
2568 p = 0;
2569 p_this_ccw->header.flag=CLAW_PENDING;
2570 privptr->p_read_active_first=p_this_ccw->next;
2571 p_this_ccw->next=NULL;
2572 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2573 if ((p_env->packing == PACK_SEND) &&
2574 (p_packh->len == 32) &&
2575 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2576 p_packh++; /* peek past pack header */
2577 p_ctlrec = (struct clawctl *)p_packh;
2578 p_packh--; /* un peek */
2579 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2580 (p_ctlrec->command == CONNECTION_CONFIRM))
2581 p_env->packing = DO_PACKED;
2582 }
2583 if (p_env->packing == DO_PACKED)
2584 link_num=p_packh->link_num;
2585 else
2586 link_num=p_this_ccw->header.opcode / 8;
2587 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 mtc_this_frm=1;
2589 if (p_this_ccw->header.length!=
2590 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002591 dev_warn(p_dev,
2592 "The communication peer of %s"
2593 " sent a faulty"
2594 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 dev->name, p_this_ccw->header.length);
2596 }
2597 }
2598
2599 if (privptr->mtc_skipping) {
2600 /*
2601 * We're in the mode of skipping past a
2602 * multi-frame message
2603 * that we can't process for some reason or other.
2604 * The first frame without the More-To-Come flag is
2605 * the last frame of the skipped message.
2606 */
2607 /* in case of More-To-Come not set in this frame */
2608 if (mtc_this_frm==0) {
2609 privptr->mtc_skipping=0; /* Ok, the end */
2610 privptr->mtc_logical_link=-1;
2611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 goto NextFrame;
2613 }
2614
2615 if (link_num==0) {
2616 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002617 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 goto NextFrame;
2619 }
2620unpack_next:
2621 if (p_env->packing == DO_PACKED) {
2622 if (pack_off > p_env->read_size)
2623 goto NextFrame;
2624 p_packd = p_this_ccw->p_buffer+pack_off;
2625 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002626 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 (p_packh->flag != 0))
2628 goto NextFrame;
2629 bytes_to_mov = p_packh->len;
2630 pack_off += bytes_to_mov+sizeof(struct clawph);
2631 p++;
2632 } else {
2633 bytes_to_mov=p_this_ccw->header.length;
2634 }
2635 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
2637 /*
2638 * if More-To-Come is set in this frame then we don't know
2639 * length of entire message, and hence have to allocate
2640 * large buffer */
2641
2642 /* We are starting a new envelope */
2643 privptr->mtc_offset=0;
2644 privptr->mtc_logical_link=link_num;
2645 }
2646
2647 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2648 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 privptr->stats.rx_frame_errors++;
2650 goto NextFrame;
2651 }
2652 if (p_env->packing == DO_PACKED) {
2653 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2654 p_packd+sizeof(struct clawph), bytes_to_mov);
2655
2656 } else {
2657 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2658 p_this_ccw->p_buffer, bytes_to_mov);
2659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 if (mtc_this_frm==0) {
2661 len_of_data=privptr->mtc_offset+bytes_to_mov;
2662 skb=dev_alloc_skb(len_of_data);
2663 if (skb) {
2664 memcpy(skb_put(skb,len_of_data),
2665 privptr->p_mtc_envelope,
2666 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002668 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 skb->protocol=htons(ETH_P_IP);
2670 skb->ip_summed=CHECKSUM_UNNECESSARY;
2671 privptr->stats.rx_packets++;
2672 privptr->stats.rx_bytes+=len_of_data;
2673 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 }
2675 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002676 dev_info(p_dev, "Allocating a buffer for"
2677 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 }
2680 privptr->mtc_offset=0;
2681 privptr->mtc_logical_link=-1;
2682 }
2683 else {
2684 privptr->mtc_offset+=bytes_to_mov;
2685 }
2686 if (p_env->packing == DO_PACKED)
2687 goto unpack_next;
2688NextFrame:
2689 /*
2690 * Remove ThisCCWblock from active read queue, and add it
2691 * to queue of free blocks to be reused.
2692 */
2693 i++;
2694 p_this_ccw->header.length=0xffff;
2695 p_this_ccw->header.opcode=0xff;
2696 /*
2697 * add this one to the free queue for later reuse
2698 */
2699 if (p_first_ccw==NULL) {
2700 p_first_ccw = p_this_ccw;
2701 }
2702 else {
2703 p_last_ccw->next = p_this_ccw;
2704 }
2705 p_last_ccw = p_this_ccw;
2706 /*
2707 * chain to next block on active read queue
2708 */
2709 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002710 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 } /* end of while */
2712
2713 /* check validity */
2714
Andy Richterb805da72008-07-18 15:24:56 +02002715 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 return;
2719} /* end of unpack_read */
2720
2721/*-------------------------------------------------------------------*
2722* claw_strt_read *
2723* *
2724*--------------------------------------------------------------------*/
2725static void
2726claw_strt_read (struct net_device *dev, int lock )
2727{
2728 int rc = 0;
2729 __u32 parm;
2730 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002731 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 struct ccwbk*p_ccwbk;
2733 struct chbk *p_ch;
2734 struct clawh *p_clawh;
Heiko Carstens319cb082010-08-12 01:58:27 +00002735 p_ch = &privptr->channel[READ_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
Andy Richterb805da72008-07-18 15:24:56 +02002737 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2739 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2740
2741 if ((privptr->p_write_active_first!=NULL &&
2742 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2743 (privptr->p_read_active_first!=NULL &&
2744 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2745 p_clawh->flag=CLAW_BUSY; /* 0xff */
2746 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 if (lock==LOCK_YES) {
2748 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2749 }
2750 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002751 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 p_ccwbk=privptr->p_read_active_first;
2753 parm = (unsigned long) p_ch;
2754 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2755 0xff, 0);
2756 if (rc != 0) {
2757 ccw_check_return_code(p_ch->cdev, rc);
2758 }
2759 }
2760 else {
Andy Richterb805da72008-07-18 15:24:56 +02002761 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 }
2763
2764 if (lock==LOCK_YES) {
2765 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2766 }
Andy Richterb805da72008-07-18 15:24:56 +02002767 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 return;
2769} /* end of claw_strt_read */
2770
2771/*-------------------------------------------------------------------*
2772* claw_strt_out_IO *
2773* *
2774*--------------------------------------------------------------------*/
2775
2776static void
2777claw_strt_out_IO( struct net_device *dev )
2778{
2779 int rc = 0;
2780 unsigned long parm;
2781 struct claw_privbk *privptr;
2782 struct chbk *p_ch;
2783 struct ccwbk *p_first_ccw;
2784
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 if (!dev) {
2786 return;
2787 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002788 privptr = (struct claw_privbk *)dev->ml_priv;
Heiko Carstens319cb082010-08-12 01:58:27 +00002789 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
Andy Richterb805da72008-07-18 15:24:56 +02002791 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 p_first_ccw=privptr->p_write_active_first;
2793
2794 if (p_ch->claw_state == CLAW_STOP)
2795 return;
2796 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 return;
2798 }
2799 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2800 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002801 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002802 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2803 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 if (rc != 0) {
2805 ccw_check_return_code(p_ch->cdev, rc);
2806 }
2807 }
2808 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 return;
2810} /* end of claw_strt_out_IO */
2811
2812/*-------------------------------------------------------------------*
2813* Free write buffers *
2814* *
2815*--------------------------------------------------------------------*/
2816
2817static void
2818claw_free_wrt_buf( struct net_device *dev )
2819{
2820
Peter Tiedemann6951df32008-08-21 17:10:23 +02002821 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 struct ccwbk*p_first_ccw;
2823 struct ccwbk*p_last_ccw;
2824 struct ccwbk*p_this_ccw;
2825 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002826
2827 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 /* scan the write queue to free any completed write packets */
2829 p_first_ccw=NULL;
2830 p_last_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 p_this_ccw=privptr->p_write_active_first;
2832 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2833 {
2834 p_next_ccw = p_this_ccw->next;
2835 if (((p_next_ccw!=NULL) &&
2836 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2837 ((p_this_ccw == privptr->p_write_active_last) &&
2838 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2839 /* The next CCW is OK or this is */
2840 /* the last CCW...free it @A1A */
2841 privptr->p_write_active_first=p_this_ccw->next;
2842 p_this_ccw->header.flag=CLAW_PENDING;
2843 p_this_ccw->next=privptr->p_write_free_chain;
2844 privptr->p_write_free_chain=p_this_ccw;
2845 ++privptr->write_free_count;
2846 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2847 p_this_ccw=privptr->p_write_active_first;
2848 privptr->stats.tx_packets++;
2849 }
2850 else {
2851 break;
2852 }
2853 }
2854 if (privptr->write_free_count!=0) {
2855 claw_clearbit_busy(TB_NOBUFFER,dev);
2856 }
2857 /* whole chain removed? */
2858 if (privptr->p_write_active_first==NULL) {
2859 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 }
Andy Richterb805da72008-07-18 15:24:56 +02002861 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 return;
2863}
2864
2865/*-------------------------------------------------------------------*
2866* claw free netdevice *
2867* *
2868*--------------------------------------------------------------------*/
2869static void
2870claw_free_netdevice(struct net_device * dev, int free_dev)
2871{
2872 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
Andy Richterb805da72008-07-18 15:24:56 +02002874 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 if (!dev)
2876 return;
Andy Richterb805da72008-07-18 15:24:56 +02002877 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002878 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 if (dev->flags & IFF_RUNNING)
2880 claw_release(dev);
2881 if (privptr) {
Heiko Carstens319cb082010-08-12 01:58:27 +00002882 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002884 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885#ifdef MODULE
2886 if (free_dev) {
2887 free_netdev(dev);
2888 }
2889#endif
Andy Richterb805da72008-07-18 15:24:56 +02002890 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891}
2892
2893/**
2894 * Claw init netdevice
2895 * Initialize everything of the net device except the name and the
2896 * channel structs.
2897 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002898static const struct net_device_ops claw_netdev_ops = {
2899 .ndo_open = claw_open,
2900 .ndo_stop = claw_release,
2901 .ndo_get_stats = claw_stats,
2902 .ndo_start_xmit = claw_tx,
2903 .ndo_change_mtu = claw_change_mtu,
2904};
2905
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906static void
2907claw_init_netdevice(struct net_device * dev)
2908{
Andy Richterb805da72008-07-18 15:24:56 +02002909 CLAW_DBF_TEXT(2, setup, "init_dev");
2910 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 dev->hard_header_len = 0;
2913 dev->addr_len = 0;
2914 dev->type = ARPHRD_SLIP;
2915 dev->tx_queue_len = 1300;
2916 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002917 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002918 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 return;
2920}
2921
2922/**
2923 * Init a new channel in the privptr->channel[i].
2924 *
2925 * @param cdev The ccw_device to be added.
2926 *
2927 * @return 0 on success, !0 on error.
2928 */
2929static int
2930add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2931{
2932 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002933 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934
Kay Sievers2a0217d2008-10-10 21:33:09 +02002935 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2937 p_ch = &privptr->channel[i];
2938 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002939 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002940 ccw_device_get_id(cdev, &dev_id);
2941 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002942 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 return -ENOMEM;
2944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 return 0;
2946}
2947
2948
2949/**
2950 *
2951 * Setup an interface.
2952 *
2953 * @param cgdev Device to be setup.
2954 *
2955 * @returns 0 on success, !0 on failure.
2956 */
2957static int
2958claw_new_device(struct ccwgroup_device *cgdev)
2959{
2960 struct claw_privbk *privptr;
2961 struct claw_env *p_env;
2962 struct net_device *dev;
2963 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002964 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965
Andy Richter4811fcb2009-01-20 06:14:33 +00002966 dev_info(&cgdev->dev, "add for %s\n",
Heiko Carstens319cb082010-08-12 01:58:27 +00002967 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002968 CLAW_DBF_TEXT(2, setup, "new_dev");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002969 privptr = dev_get_drvdata(&cgdev->dev);
Heiko Carstens319cb082010-08-12 01:58:27 +00002970 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2971 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 if (!privptr)
2973 return -ENODEV;
2974 p_env = privptr->p_env;
Heiko Carstens319cb082010-08-12 01:58:27 +00002975 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2976 p_env->devno[READ_CHANNEL] = dev_id.devno;
2977 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2978 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 ret = add_channel(cgdev->cdev[0],0,privptr);
2980 if (ret == 0)
2981 ret = add_channel(cgdev->cdev[1],1,privptr);
2982 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002983 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2984 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002985 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002987 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002989 dev_warn(&cgdev->dev,
2990 "Setting the read subchannel online"
2991 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 goto out;
2993 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002994 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002996 dev_warn(&cgdev->dev,
2997 "Setting the write subchannel online "
2998 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 goto out;
3000 }
3001 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
3002 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003003 dev_warn(&cgdev->dev,
3004 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 goto out;
3006 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02003007 dev->ml_priv = privptr;
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003008 dev_set_drvdata(&cgdev->dev, privptr);
Heiko Carstens319cb082010-08-12 01:58:27 +00003009 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
3010 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 /* sysfs magic */
3012 SET_NETDEV_DEV(dev, &cgdev->dev);
3013 if (register_netdev(dev) != 0) {
3014 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02003015 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 goto out;
3017 }
3018 dev->flags &=~IFF_RUNNING;
3019 if (privptr->buffs_alloc == 0) {
3020 ret=init_ccw_bk(dev);
3021 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 unregister_netdev(dev);
3023 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02003024 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 goto out;
3026 }
3027 }
Heiko Carstens319cb082010-08-12 01:58:27 +00003028 privptr->channel[READ_CHANNEL].ndev = dev;
3029 privptr->channel[WRITE_CHANNEL].ndev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 privptr->p_env->ndev = dev;
3031
Andy Richter4811fcb2009-01-20 06:14:33 +00003032 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3034 dev->name, p_env->read_size,
3035 p_env->write_size, p_env->read_buffers,
Heiko Carstens319cb082010-08-12 01:58:27 +00003036 p_env->write_buffers, p_env->devno[READ_CHANNEL],
3037 p_env->devno[WRITE_CHANNEL]);
Andy Richter4811fcb2009-01-20 06:14:33 +00003038 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 ":%.8s api_type: %.8s\n",
3040 dev->name, p_env->host_name,
3041 p_env->adapter_name , p_env->api_type);
3042 return 0;
3043out:
3044 ccw_device_set_offline(cgdev->cdev[1]);
3045 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 return -ENODEV;
3047}
3048
3049static void
3050claw_purge_skb_queue(struct sk_buff_head *q)
3051{
3052 struct sk_buff *skb;
3053
Andy Richterb805da72008-07-18 15:24:56 +02003054 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 while ((skb = skb_dequeue(q))) {
3056 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02003057 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 }
3059}
3060
3061/**
3062 * Shutdown an interface.
3063 *
3064 * @param cgdev Device to be shut down.
3065 *
3066 * @returns 0 on success, !0 on failure.
3067 */
3068static int
3069claw_shutdown_device(struct ccwgroup_device *cgdev)
3070{
3071 struct claw_privbk *priv;
3072 struct net_device *ndev;
3073 int ret;
3074
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003075 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003076 priv = dev_get_drvdata(&cgdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 if (!priv)
3078 return -ENODEV;
Heiko Carstens319cb082010-08-12 01:58:27 +00003079 ndev = priv->channel[READ_CHANNEL].ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 if (ndev) {
3081 /* Close the device */
Heiko Carstens319cb082010-08-12 01:58:27 +00003082 dev_info(&cgdev->dev, "%s: shutting down\n",
Andy Richter4811fcb2009-01-20 06:14:33 +00003083 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 if (ndev->flags & IFF_RUNNING)
3085 ret = claw_release(ndev);
3086 ndev->flags &=~IFF_RUNNING;
3087 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003088 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 claw_free_netdevice(ndev, 1);
Heiko Carstens319cb082010-08-12 01:58:27 +00003090 priv->channel[READ_CHANNEL].ndev = NULL;
3091 priv->channel[WRITE_CHANNEL].ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 priv->p_env->ndev = NULL;
3093 }
3094 ccw_device_set_offline(cgdev->cdev[1]);
3095 ccw_device_set_offline(cgdev->cdev[0]);
3096 return 0;
3097}
3098
3099static void
3100claw_remove_device(struct ccwgroup_device *cgdev)
3101{
3102 struct claw_privbk *priv;
3103
Andy Richterb805da72008-07-18 15:24:56 +02003104 BUG_ON(!cgdev);
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003105 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003106 priv = dev_get_drvdata(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003107 BUG_ON(!priv);
Andy Richter4811fcb2009-01-20 06:14:33 +00003108 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 if (cgdev->state == CCWGROUP_ONLINE)
3110 claw_shutdown_device(cgdev);
3111 claw_remove_files(&cgdev->dev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003112 kfree(priv->p_mtc_envelope);
3113 priv->p_mtc_envelope=NULL;
3114 kfree(priv->p_env);
3115 priv->p_env=NULL;
3116 kfree(priv->channel[0].irb);
3117 priv->channel[0].irb=NULL;
3118 kfree(priv->channel[1].irb);
3119 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 kfree(priv);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003121 dev_set_drvdata(&cgdev->dev, NULL);
Heiko Carstens319cb082010-08-12 01:58:27 +00003122 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3123 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003125
3126 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127}
3128
3129
3130/*
3131 * sysfs attributes
3132 */
3133static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003134claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135{
3136 struct claw_privbk *priv;
3137 struct claw_env * p_env;
3138
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003139 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 if (!priv)
3141 return -ENODEV;
3142 p_env = priv->p_env;
3143 return sprintf(buf, "%s\n",p_env->host_name);
3144}
3145
3146static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003147claw_hname_write(struct device *dev, struct device_attribute *attr,
3148 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149{
3150 struct claw_privbk *priv;
3151 struct claw_env * p_env;
3152
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003153 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 if (!priv)
3155 return -ENODEV;
3156 p_env = priv->p_env;
3157 if (count > MAX_NAME_LEN+1)
3158 return -EINVAL;
3159 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3160 strncpy(p_env->host_name,buf, count);
3161 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3162 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003163 CLAW_DBF_TEXT(2, setup, "HstnSet");
3164 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
3166 return count;
3167}
3168
3169static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3170
3171static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003172claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173{
3174 struct claw_privbk *priv;
3175 struct claw_env * p_env;
3176
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003177 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 if (!priv)
3179 return -ENODEV;
3180 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003181 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182}
3183
3184static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003185claw_adname_write(struct device *dev, struct device_attribute *attr,
3186 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187{
3188 struct claw_privbk *priv;
3189 struct claw_env * p_env;
3190
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003191 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 if (!priv)
3193 return -ENODEV;
3194 p_env = priv->p_env;
3195 if (count > MAX_NAME_LEN+1)
3196 return -EINVAL;
3197 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3198 strncpy(p_env->adapter_name,buf, count);
3199 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3200 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003201 CLAW_DBF_TEXT(2, setup, "AdnSet");
3202 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203
3204 return count;
3205}
3206
3207static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3208
3209static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003210claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211{
3212 struct claw_privbk *priv;
3213 struct claw_env * p_env;
3214
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003215 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 if (!priv)
3217 return -ENODEV;
3218 p_env = priv->p_env;
3219 return sprintf(buf, "%s\n",
3220 p_env->api_type);
3221}
3222
3223static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003224claw_apname_write(struct device *dev, struct device_attribute *attr,
3225 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226{
3227 struct claw_privbk *priv;
3228 struct claw_env * p_env;
3229
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003230 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 if (!priv)
3232 return -ENODEV;
3233 p_env = priv->p_env;
3234 if (count > MAX_NAME_LEN+1)
3235 return -EINVAL;
3236 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3237 strncpy(p_env->api_type,buf, count);
3238 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3239 p_env->api_type[MAX_NAME_LEN] = 0x00;
3240 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3241 p_env->read_size=DEF_PACK_BUFSIZE;
3242 p_env->write_size=DEF_PACK_BUFSIZE;
3243 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003244 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 }
3246 else {
3247 p_env->packing=0;
3248 p_env->read_size=CLAW_FRAME_SIZE;
3249 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003250 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 }
Andy Richterb805da72008-07-18 15:24:56 +02003252 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 return count;
3254}
3255
3256static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3257
3258static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003259claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260{
3261 struct claw_privbk *priv;
3262 struct claw_env * p_env;
3263
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003264 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 if (!priv)
3266 return -ENODEV;
3267 p_env = priv->p_env;
3268 return sprintf(buf, "%d\n", p_env->write_buffers);
3269}
3270
3271static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003272claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3273 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274{
3275 struct claw_privbk *priv;
3276 struct claw_env * p_env;
3277 int nnn,max;
3278
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003279 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 if (!priv)
3281 return -ENODEV;
3282 p_env = priv->p_env;
3283 sscanf(buf, "%i", &nnn);
3284 if (p_env->packing) {
3285 max = 64;
3286 }
3287 else {
3288 max = 512;
3289 }
3290 if ((nnn > max ) || (nnn < 2))
3291 return -EINVAL;
3292 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003293 CLAW_DBF_TEXT(2, setup, "Wbufset");
3294 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 return count;
3296}
3297
3298static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3299
3300static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003301claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302{
3303 struct claw_privbk *priv;
3304 struct claw_env * p_env;
3305
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003306 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 if (!priv)
3308 return -ENODEV;
3309 p_env = priv->p_env;
3310 return sprintf(buf, "%d\n", p_env->read_buffers);
3311}
3312
3313static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003314claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3315 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316{
3317 struct claw_privbk *priv;
3318 struct claw_env *p_env;
3319 int nnn,max;
3320
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003321 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 if (!priv)
3323 return -ENODEV;
3324 p_env = priv->p_env;
3325 sscanf(buf, "%i", &nnn);
3326 if (p_env->packing) {
3327 max = 64;
3328 }
3329 else {
3330 max = 512;
3331 }
3332 if ((nnn > max ) || (nnn < 2))
3333 return -EINVAL;
3334 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003335 CLAW_DBF_TEXT(2, setup, "Rbufset");
3336 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 return count;
3338}
3339
3340static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3341
3342static struct attribute *claw_attr[] = {
3343 &dev_attr_read_buffer.attr,
3344 &dev_attr_write_buffer.attr,
3345 &dev_attr_adapter_name.attr,
3346 &dev_attr_api_type.attr,
3347 &dev_attr_host_name.attr,
3348 NULL,
3349};
3350
3351static struct attribute_group claw_attr_group = {
3352 .attrs = claw_attr,
3353};
3354
3355static int
3356claw_add_files(struct device *dev)
3357{
Andy Richterb805da72008-07-18 15:24:56 +02003358 CLAW_DBF_TEXT(2, setup, "add_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3360}
3361
3362static void
3363claw_remove_files(struct device *dev)
3364{
Andy Richterb805da72008-07-18 15:24:56 +02003365 CLAW_DBF_TEXT(2, setup, "rem_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3367}
3368
3369/*--------------------------------------------------------------------*
3370* claw_init and cleanup *
3371*---------------------------------------------------------------------*/
3372
3373static void __exit
3374claw_cleanup(void)
3375{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003376 driver_remove_file(&claw_group_driver.driver,
3377 &driver_attr_group);
3378 ccwgroup_driver_unregister(&claw_group_driver);
3379 ccw_driver_unregister(&claw_ccw_driver);
3380 root_device_unregister(claw_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003382 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383
3384}
3385
3386/**
3387 * Initialize module.
3388 * This is called just after the module is loaded.
3389 *
3390 * @return 0 on success, !0 on error.
3391 */
3392static int __init
3393claw_init(void)
3394{
3395 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
Andy Richter4811fcb2009-01-20 06:14:33 +00003397 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 ret = claw_register_debug_facility();
3399 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003400 pr_err("Registering with the S/390 debug feature"
3401 " failed with error code %d\n", ret);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003402 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 }
Andy Richterb805da72008-07-18 15:24:56 +02003404 CLAW_DBF_TEXT(2, setup, "init_mod");
Ursula Braund950d172010-01-04 03:14:45 +00003405 claw_root_dev = root_device_register("claw");
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003406 ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0;
3407 if (ret)
3408 goto register_err;
3409 ret = ccw_driver_register(&claw_ccw_driver);
3410 if (ret)
3411 goto ccw_err;
3412 claw_group_driver.driver.groups = claw_group_attr_groups;
3413 ret = ccwgroup_driver_register(&claw_group_driver);
3414 if (ret)
3415 goto ccwgroup_err;
3416 return 0;
3417
3418ccwgroup_err:
3419 ccw_driver_unregister(&claw_ccw_driver);
3420ccw_err:
3421 root_device_unregister(claw_root_dev);
3422register_err:
3423 CLAW_DBF_TEXT(2, setup, "init_bad");
3424 claw_unregister_debug_facility();
3425out_err:
3426 pr_err("Initializing the claw device driver failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 return ret;
3428}
3429
3430module_init(claw_init);
3431module_exit(claw_cleanup);
3432
Andy Richterb805da72008-07-18 15:24:56 +02003433MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3434MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3435 "Copyright 2000,2008 IBM Corporation\n");
3436MODULE_LICENSE("GPL");