blob: da8aa75bb20ba8f41785cf6e4c9d5500b70df777 [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 = {
Sebastian Ott3c190c52011-03-23 10:16:04 +0100267 .driver = {
268 .owner = THIS_MODULE,
269 .name = "claw",
270 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 .max_slaves = 2,
272 .driver_id = 0xC3D3C1E6,
273 .probe = claw_probe,
274 .remove = claw_remove_device,
275 .set_online = claw_new_device,
276 .set_offline = claw_shutdown_device,
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200277 .prepare = claw_pm_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278};
279
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000280static struct ccw_device_id claw_ids[] = {
281 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
282 {},
283};
284MODULE_DEVICE_TABLE(ccw, claw_ids);
285
286static struct ccw_driver claw_ccw_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +0100287 .driver = {
288 .owner = THIS_MODULE,
289 .name = "claw",
290 },
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000291 .ids = claw_ids,
292 .probe = ccwgroup_probe_ccwdev,
293 .remove = ccwgroup_remove_ccwdev,
294};
295
296static ssize_t
297claw_driver_group_store(struct device_driver *ddrv, const char *buf,
298 size_t count)
299{
300 int err;
301 err = ccwgroup_create_from_string(claw_root_dev,
302 claw_group_driver.driver_id,
Ursula Braune48d24a2010-07-22 23:15:07 +0000303 &claw_ccw_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000304 return err ? err : count;
305}
306
307static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
308
309static struct attribute *claw_group_attrs[] = {
310 &driver_attr_group.attr,
311 NULL,
312};
313
314static struct attribute_group claw_group_attr_group = {
315 .attrs = claw_group_attrs,
316};
317
Heiko Carstens302689a2009-11-17 06:47:02 -0800318static const struct attribute_group *claw_group_attr_groups[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000319 &claw_group_attr_group,
320 NULL,
321};
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324* Key functions
325*/
326
327/*----------------------------------------------------------------*
328 * claw_probe *
329 * this function is called for each CLAW device. *
330 *----------------------------------------------------------------*/
331static int
332claw_probe(struct ccwgroup_device *cgdev)
333{
334 int rc;
335 struct claw_privbk *privptr=NULL;
336
Andy Richterb805da72008-07-18 15:24:56 +0200337 CLAW_DBF_TEXT(2, setup, "probe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (!get_device(&cgdev->dev))
339 return -ENODEV;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800340 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700341 dev_set_drvdata(&cgdev->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 if (privptr == NULL) {
343 probe_error(cgdev);
344 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200345 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return -ENOMEM;
347 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700348 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
349 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
351 probe_error(cgdev);
352 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200353 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return -ENOMEM;
355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
357 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
358 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
359 privptr->p_env->packing = 0;
360 privptr->p_env->write_buffers = 5;
361 privptr->p_env->read_buffers = 5;
362 privptr->p_env->read_size = CLAW_FRAME_SIZE;
363 privptr->p_env->write_size = CLAW_FRAME_SIZE;
364 rc = claw_add_files(&cgdev->dev);
365 if (rc) {
366 probe_error(cgdev);
367 put_device(&cgdev->dev);
Andy Richter4811fcb2009-01-20 06:14:33 +0000368 dev_err(&cgdev->dev, "Creating the /proc files for a new"
369 " CLAW device failed\n");
Andy Richterb805da72008-07-18 15:24:56 +0200370 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return rc;
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 privptr->p_env->p_priv = privptr;
374 cgdev->cdev[0]->handler = claw_irq_handler;
375 cgdev->cdev[1]->handler = claw_irq_handler;
Andy Richterb805da72008-07-18 15:24:56 +0200376 CLAW_DBF_TEXT(2, setup, "prbext 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 return 0;
379} /* end of claw_probe */
380
381/*-------------------------------------------------------------------*
382 * claw_tx *
383 *-------------------------------------------------------------------*/
384
385static int
386claw_tx(struct sk_buff *skb, struct net_device *dev)
387{
388 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200389 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 unsigned long saveflags;
391 struct chbk *p_ch;
392
Andy Richterb805da72008-07-18 15:24:56 +0200393 CLAW_DBF_TEXT(4, trace, "claw_tx");
Heiko Carstens319cb082010-08-12 01:58:27 +0000394 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
396 rc=claw_hw_tx( skb, dev, 1 );
397 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200398 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000399 if (rc)
400 rc = NETDEV_TX_BUSY;
Patrick McHardyec634fe2009-07-05 19:23:38 -0700401 else
402 rc = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 return rc;
404} /* end of claw_tx */
405
406/*------------------------------------------------------------------*
407 * pack the collect queue into an skb and return it *
408 * If not packing just return the top skb from the queue *
409 *------------------------------------------------------------------*/
410
411static struct sk_buff *
412claw_pack_skb(struct claw_privbk *privptr)
413{
414 struct sk_buff *new_skb,*held_skb;
Heiko Carstens319cb082010-08-12 01:58:27 +0000415 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 struct claw_env *p_env = privptr->p_env;
417 int pkt_cnt,pk_ind,so_far;
418
419 new_skb = NULL; /* assume no dice */
420 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200421 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700422 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 /* some data */
424 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200426 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 else
428 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200429 if (p_env->packing != DO_PACKED)
430 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 /* get a new SKB we will pack at least one */
432 new_skb = dev_alloc_skb(p_env->write_size);
433 if (new_skb == NULL) {
434 atomic_inc(&held_skb->users);
435 skb_queue_head(&p_ch->collect_queue,held_skb);
436 return NULL;
437 }
438 /* we have packed packet and a place to put it */
439 pk_ind = 1;
440 so_far = 0;
441 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
442 while ((pk_ind) && (held_skb != NULL)) {
443 if (held_skb->len+so_far <= p_env->write_size-8) {
444 memcpy(skb_put(new_skb,held_skb->len),
445 held_skb->data,held_skb->len);
446 privptr->stats.tx_packets++;
447 so_far += held_skb->len;
448 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200449 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 held_skb = skb_dequeue(&p_ch->collect_queue);
451 if (held_skb)
452 atomic_dec(&held_skb->users);
453 } else {
454 pk_ind = 0;
455 atomic_inc(&held_skb->users);
456 skb_queue_head(&p_ch->collect_queue,held_skb);
457 }
458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
Andy Richterb805da72008-07-18 15:24:56 +0200460 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return new_skb;
462}
463
464/*-------------------------------------------------------------------*
465 * claw_change_mtu *
466 * *
467 *-------------------------------------------------------------------*/
468
469static int
470claw_change_mtu(struct net_device *dev, int new_mtu)
471{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200472 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200474 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 buff_size = privptr->p_env->write_size;
476 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 return -EINVAL;
478 }
479 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 return 0;
481} /* end of claw_change_mtu */
482
483
484/*-------------------------------------------------------------------*
485 * claw_open *
486 * *
487 *-------------------------------------------------------------------*/
488static int
489claw_open(struct net_device *dev)
490{
491
492 int rc;
493 int i;
494 unsigned long saveflags=0;
495 unsigned long parm;
496 struct claw_privbk *privptr;
497 DECLARE_WAITQUEUE(wait, current);
498 struct timer_list timer;
499 struct ccwbk *p_buf;
500
Andy Richterb805da72008-07-18 15:24:56 +0200501 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200502 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 /* allocate and initialize CCW blocks */
504 if (privptr->buffs_alloc == 0) {
505 rc=init_ccw_bk(dev);
506 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200507 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return -ENOMEM;
509 }
510 }
511 privptr->system_validate_comp=0;
512 privptr->release_pend=0;
513 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
514 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
515 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
516 privptr->p_env->packing=PACKING_ASK;
517 } else {
518 privptr->p_env->packing=0;
519 privptr->p_env->read_size=CLAW_FRAME_SIZE;
520 privptr->p_env->write_size=CLAW_FRAME_SIZE;
521 }
522 claw_set_busy(dev);
Heiko Carstens319cb082010-08-12 01:58:27 +0000523 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
524 (unsigned long) &privptr->channel[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200526 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 init_waitqueue_head(&privptr->channel[i].wait);
528 /* skb_queue_head_init(&p_ch->io_queue); */
Heiko Carstens319cb082010-08-12 01:58:27 +0000529 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 skb_queue_head_init(
Heiko Carstens319cb082010-08-12 01:58:27 +0000531 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 privptr->channel[i].flag_a = 0;
533 privptr->channel[i].IO_active = 0;
534 privptr->channel[i].flag &= ~CLAW_TIMER;
535 init_timer(&timer);
536 timer.function = (void *)claw_timer;
537 timer.data = (unsigned long)(&privptr->channel[i]);
538 timer.expires = jiffies + 15*HZ;
539 add_timer(&timer);
540 spin_lock_irqsave(get_ccwdev_lock(
541 privptr->channel[i].cdev), saveflags);
542 parm = (unsigned long) &privptr->channel[i];
543 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
544 rc = 0;
545 add_wait_queue(&privptr->channel[i].wait, &wait);
546 rc = ccw_device_halt(
547 (struct ccw_device *)privptr->channel[i].cdev,parm);
548 set_current_state(TASK_INTERRUPTIBLE);
549 spin_unlock_irqrestore(
550 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
551 schedule();
552 set_current_state(TASK_RUNNING);
553 remove_wait_queue(&privptr->channel[i].wait, &wait);
554 if(rc != 0)
555 ccw_check_return_code(privptr->channel[i].cdev, rc);
556 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
557 del_timer(&timer);
558 }
Heiko Carstens319cb082010-08-12 01:58:27 +0000559 if ((((privptr->channel[READ_CHANNEL].last_dstat |
560 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
Heiko Carstens319cb082010-08-12 01:58:27 +0000562 (((privptr->channel[READ_CHANNEL].flag |
563 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
564 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000565 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200566 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 for ( i = 0; i < 2; i++) {
569 spin_lock_irqsave(
570 get_ccwdev_lock(privptr->channel[i].cdev),
571 saveflags);
572 parm = (unsigned long) &privptr->channel[i];
573 privptr->channel[i].claw_state = CLAW_STOP;
574 rc = ccw_device_halt(
575 (struct ccw_device *)&privptr->channel[i].cdev,
576 parm);
577 spin_unlock_irqrestore(
578 get_ccwdev_lock(privptr->channel[i].cdev),
579 saveflags);
580 if (rc != 0) {
581 ccw_check_return_code(
582 privptr->channel[i].cdev, rc);
583 }
584 }
585 free_pages((unsigned long)privptr->p_buff_ccw,
586 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
587 if (privptr->p_env->read_size < PAGE_SIZE) {
588 free_pages((unsigned long)privptr->p_buff_read,
589 (int)pages_to_order_of_mag(
590 privptr->p_buff_read_num));
591 }
592 else {
593 p_buf=privptr->p_read_active_first;
594 while (p_buf!=NULL) {
595 free_pages((unsigned long)p_buf->p_buffer,
596 (int)pages_to_order_of_mag(
597 privptr->p_buff_pages_perread ));
598 p_buf=p_buf->next;
599 }
600 }
601 if (privptr->p_env->write_size < PAGE_SIZE ) {
602 free_pages((unsigned long)privptr->p_buff_write,
603 (int)pages_to_order_of_mag(
604 privptr->p_buff_write_num));
605 }
606 else {
607 p_buf=privptr->p_write_active_first;
608 while (p_buf!=NULL) {
609 free_pages((unsigned long)p_buf->p_buffer,
610 (int)pages_to_order_of_mag(
611 privptr->p_buff_pages_perwrite ));
612 p_buf=p_buf->next;
613 }
614 }
615 privptr->buffs_alloc = 0;
Heiko Carstens319cb082010-08-12 01:58:27 +0000616 privptr->channel[READ_CHANNEL].flag = 0x00;
617 privptr->channel[WRITE_CHANNEL].flag = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 privptr->p_buff_ccw=NULL;
619 privptr->p_buff_read=NULL;
620 privptr->p_buff_write=NULL;
621 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200622 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 return -EIO;
624 }
625
626 /* Send SystemValidate command */
627
628 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200629 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return 0;
631} /* end of claw_open */
632
633/*-------------------------------------------------------------------*
634* *
635* claw_irq_handler *
636* *
637*--------------------------------------------------------------------*/
638static void
639claw_irq_handler(struct ccw_device *cdev,
640 unsigned long intparm, struct irb *irb)
641{
642 struct chbk *p_ch = NULL;
643 struct claw_privbk *privptr = NULL;
644 struct net_device *dev = NULL;
645 struct claw_env *p_env;
646 struct chbk *p_ch_r=NULL;
647
Heiko Carstens355eb402011-01-05 12:47:36 +0100648 kstat_cpu(smp_processor_id()).irqs[IOINT_CLW]++;
Andy Richterb805da72008-07-18 15:24:56 +0200649 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 /* Bypass all 'unsolicited interrupts' */
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700651 privptr = dev_get_drvdata(&cdev->dev);
652 if (!privptr) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000653 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
654 " IRQ, c-%02x d-%02x\n",
655 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200656 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 return;
658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 /* Try to extract channel from driver data. */
Heiko Carstens319cb082010-08-12 01:58:27 +0000661 if (privptr->channel[READ_CHANNEL].cdev == cdev)
662 p_ch = &privptr->channel[READ_CHANNEL];
663 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
664 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000666 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200667 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return;
669 }
Andy Richterb805da72008-07-18 15:24:56 +0200670 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672 dev = (struct net_device *) (p_ch->ndev);
673 p_env=privptr->p_env;
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 /* Copy interruption response block. */
676 memcpy(p_ch->irb, irb, sizeof(struct irb));
677
Andy Richterb805da72008-07-18 15:24:56 +0200678 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200679 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000680 dev_info(&cdev->dev,
681 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
683 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200684 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
685 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200686 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /* return; */
688 }
689
690 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200691 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200695 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
697 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200698 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
699 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
700 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
701 (p_ch->irb->scsw.cmd.stctl ==
702 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
703 return;
704 wake_up(&p_ch->wait); /* wake up claw_release */
705 CLAW_DBF_TEXT(4, trace, "stop");
706 return;
707 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
708 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
709 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
710 (p_ch->irb->scsw.cmd.stctl ==
711 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
712 CLAW_DBF_TEXT(4, trace, "haltio");
713 return;
714 }
715 if (p_ch->flag == CLAW_READ) {
716 p_ch->claw_state = CLAW_START_READ;
717 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
718 } else if (p_ch->flag == CLAW_WRITE) {
719 p_ch->claw_state = CLAW_START_WRITE;
Andy Richter4811fcb2009-01-20 06:14:33 +0000720 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200721 claw_strt_read(dev, LOCK_NO);
722 claw_send_control(dev,
723 SYSTEM_VALIDATE_REQUEST,
724 0, 0, 0,
725 p_env->host_name,
726 p_env->adapter_name);
727 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000728 dev_warn(&cdev->dev, "The CLAW device received"
729 " an unexpected IRQ, "
730 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200731 irb->scsw.cmd.cstat,
732 irb->scsw.cmd.dstat);
733 return;
734 }
735 CLAW_DBF_TEXT(4, trace, "haltio");
736 return;
737 case CLAW_START_READ:
738 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
739 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
740 clear_bit(0, (void *)&p_ch->IO_active);
741 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
742 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
743 (p_ch->irb->ecw[0]) == 0) {
744 privptr->stats.rx_errors++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000745 dev_info(&cdev->dev,
746 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200747 "side recovers \n",
748 dev->name);
749 }
750 CLAW_DBF_TEXT(4, trace, "notrdy");
751 return;
752 }
753 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
754 (p_ch->irb->scsw.cmd.dstat == 0)) {
755 if (test_and_set_bit(CLAW_BH_ACTIVE,
756 (void *)&p_ch->flag_a) == 0)
757 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 else
Andy Richterb805da72008-07-18 15:24:56 +0200759 CLAW_DBF_TEXT(4, trace, "PCINoBH");
760 CLAW_DBF_TEXT(4, trace, "PCI_read");
761 return;
762 }
763 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
764 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
765 (p_ch->irb->scsw.cmd.stctl ==
766 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
767 CLAW_DBF_TEXT(4, trace, "SPend_rd");
768 return;
769 }
770 clear_bit(0, (void *)&p_ch->IO_active);
771 claw_clearbit_busy(TB_RETRY, dev);
772 if (test_and_set_bit(CLAW_BH_ACTIVE,
773 (void *)&p_ch->flag_a) == 0)
774 tasklet_schedule(&p_ch->tasklet);
775 else
776 CLAW_DBF_TEXT(4, trace, "RdBHAct");
777 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
778 return;
779 case CLAW_START_WRITE:
780 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000781 dev_info(&cdev->dev,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300782 "%s: Unit Check Occurred in "
Andy Richterb805da72008-07-18 15:24:56 +0200783 "write channel\n", dev->name);
784 clear_bit(0, (void *)&p_ch->IO_active);
785 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000786 dev_info(&cdev->dev,
787 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200788 "occurred:\n", dev->name);
789 init_timer(&p_ch->timer);
790 p_ch->timer.function =
791 (void *)claw_write_retry;
792 p_ch->timer.data = (unsigned long)p_ch;
793 p_ch->timer.expires = jiffies + 10*HZ;
794 add_timer(&p_ch->timer);
Andy Richter4811fcb2009-01-20 06:14:33 +0000795 dev_info(&cdev->dev,
796 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200797 "restarting\n", dev->name);
798 }
799 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
800 return;
801 }
802 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
803 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000804 dev_info(&cdev->dev,
805 "%s: Unit Exception "
806 "occurred in write channel\n",
807 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200808 }
809 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
810 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
811 (p_ch->irb->scsw.cmd.stctl ==
812 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
813 CLAW_DBF_TEXT(4, trace, "writeUE");
814 return;
815 }
816 clear_bit(0, (void *)&p_ch->IO_active);
817 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
818 claw_write_next(p_ch);
819 claw_clearbit_busy(TB_TX, dev);
820 claw_clear_busy(dev);
821 }
Heiko Carstens319cb082010-08-12 01:58:27 +0000822 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +0200823 if (test_and_set_bit(CLAW_BH_ACTIVE,
824 (void *)&p_ch_r->flag_a) == 0)
825 tasklet_schedule(&p_ch_r->tasklet);
826 CLAW_DBF_TEXT(4, trace, "StWtExit");
827 return;
828 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000829 dev_warn(&cdev->dev,
830 "The CLAW device for %s received an unexpected IRQ\n",
831 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200832 CLAW_DBF_TEXT(2, trace, "badIRQ");
833 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835
836} /* end of claw_irq_handler */
837
838
839/*-------------------------------------------------------------------*
840* claw_irq_tasklet *
841* *
842*--------------------------------------------------------------------*/
843static void
844claw_irq_tasklet ( unsigned long data )
845{
846 struct chbk * p_ch;
847 struct net_device *dev;
848 struct claw_privbk * privptr;
849
850 p_ch = (struct chbk *) data;
851 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200852 CLAW_DBF_TEXT(4, trace, "IRQtask");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200853 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 unpack_read(dev);
855 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200856 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 return;
858} /* end of claw_irq_bh */
859
860/*-------------------------------------------------------------------*
861* claw_release *
862* *
863*--------------------------------------------------------------------*/
864static int
865claw_release(struct net_device *dev)
866{
867 int rc;
868 int i;
869 unsigned long saveflags;
870 unsigned long parm;
871 struct claw_privbk *privptr;
872 DECLARE_WAITQUEUE(wait, current);
873 struct ccwbk* p_this_ccw;
874 struct ccwbk* p_buf;
875
876 if (!dev)
877 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200878 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 if (!privptr)
880 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200881 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 privptr->release_pend=1;
883 claw_setbit_busy(TB_STOP,dev);
884 for ( i = 1; i >=0 ; i--) {
885 spin_lock_irqsave(
886 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
Heiko Carstens319cb082010-08-12 01:58:27 +0000887 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 privptr->channel[i].claw_state = CLAW_STOP;
889 privptr->channel[i].IO_active = 0;
890 parm = (unsigned long) &privptr->channel[i];
Heiko Carstens319cb082010-08-12 01:58:27 +0000891 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 claw_purge_skb_queue(
Heiko Carstens319cb082010-08-12 01:58:27 +0000893 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
895 if (privptr->system_validate_comp==0x00) /* never opened? */
896 init_waitqueue_head(&privptr->channel[i].wait);
897 add_wait_queue(&privptr->channel[i].wait, &wait);
898 set_current_state(TASK_INTERRUPTIBLE);
899 spin_unlock_irqrestore(
900 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
901 schedule();
902 set_current_state(TASK_RUNNING);
903 remove_wait_queue(&privptr->channel[i].wait, &wait);
904 if (rc != 0) {
905 ccw_check_return_code(privptr->channel[i].cdev, rc);
906 }
907 }
908 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200909 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 privptr->pk_skb = NULL;
911 }
912 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200913 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 return 0;
915 }
Andy Richterb805da72008-07-18 15:24:56 +0200916 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 if (privptr->p_buff_ccw != NULL) {
918 free_pages((unsigned long)privptr->p_buff_ccw,
919 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
920 }
Andy Richterb805da72008-07-18 15:24:56 +0200921 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 if (privptr->p_env->read_size < PAGE_SIZE) {
923 if (privptr->p_buff_read != NULL) {
924 free_pages((unsigned long)privptr->p_buff_read,
925 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
926 }
927 }
928 else {
929 p_buf=privptr->p_read_active_first;
930 while (p_buf!=NULL) {
931 free_pages((unsigned long)p_buf->p_buffer,
932 (int)pages_to_order_of_mag(
933 privptr->p_buff_pages_perread ));
934 p_buf=p_buf->next;
935 }
936 }
Andy Richterb805da72008-07-18 15:24:56 +0200937 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 if (privptr->p_env->write_size < PAGE_SIZE ) {
939 free_pages((unsigned long)privptr->p_buff_write,
940 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
941 }
942 else {
943 p_buf=privptr->p_write_active_first;
944 while (p_buf!=NULL) {
945 free_pages((unsigned long)p_buf->p_buffer,
946 (int)pages_to_order_of_mag(
947 privptr->p_buff_pages_perwrite ));
948 p_buf=p_buf->next;
949 }
950 }
Andy Richterb805da72008-07-18 15:24:56 +0200951 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 privptr->buffs_alloc = 0;
953 privptr->p_buff_ccw=NULL;
954 privptr->p_buff_read=NULL;
955 privptr->p_buff_write=NULL;
956 privptr->system_validate_comp=0;
957 privptr->release_pend=0;
958 /* Remove any writes that were pending and reset all reads */
959 p_this_ccw=privptr->p_read_active_first;
960 while (p_this_ccw!=NULL) {
961 p_this_ccw->header.length=0xffff;
962 p_this_ccw->header.opcode=0xff;
963 p_this_ccw->header.flag=0x00;
964 p_this_ccw=p_this_ccw->next;
965 }
966
967 while (privptr->p_write_active_first!=NULL) {
968 p_this_ccw=privptr->p_write_active_first;
969 p_this_ccw->header.flag=CLAW_PENDING;
970 privptr->p_write_active_first=p_this_ccw->next;
971 p_this_ccw->next=privptr->p_write_free_chain;
972 privptr->p_write_free_chain=p_this_ccw;
973 ++privptr->write_free_count;
974 }
975 privptr->p_write_active_last=NULL;
976 privptr->mtc_logical_link = -1;
977 privptr->mtc_skipping = 1;
978 privptr->mtc_offset=0;
979
Heiko Carstens319cb082010-08-12 01:58:27 +0000980 if (((privptr->channel[READ_CHANNEL].last_dstat |
981 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Heiko Carstens319cb082010-08-12 01:58:27 +0000983 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000984 "Deactivating %s completed with incorrect"
985 " subchannel status "
986 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 dev->name,
Heiko Carstens319cb082010-08-12 01:58:27 +0000988 privptr->channel[READ_CHANNEL].last_dstat,
989 privptr->channel[WRITE_CHANNEL].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200990 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
Andy Richterb805da72008-07-18 15:24:56 +0200992 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 return 0;
994} /* end of claw_release */
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996/*-------------------------------------------------------------------*
997* claw_write_retry *
998* *
999*--------------------------------------------------------------------*/
1000
1001static void
1002claw_write_retry ( struct chbk *p_ch )
1003{
1004
1005 struct net_device *dev=p_ch->ndev;
1006
Andy Richterb805da72008-07-18 15:24:56 +02001007 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 return;
1010 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +02001012 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 return;
1014} /* end of claw_write_retry */
1015
1016
1017/*-------------------------------------------------------------------*
1018* claw_write_next *
1019* *
1020*--------------------------------------------------------------------*/
1021
1022static void
1023claw_write_next ( struct chbk * p_ch )
1024{
1025
1026 struct net_device *dev;
1027 struct claw_privbk *privptr=NULL;
1028 struct sk_buff *pk_skb;
1029 int rc;
1030
Andy Richterb805da72008-07-18 15:24:56 +02001031 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (p_ch->claw_state == CLAW_STOP)
1033 return;
1034 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001035 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 claw_free_wrt_buf( dev );
1037 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -07001038 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 pk_skb = claw_pack_skb(privptr);
1040 while (pk_skb != NULL) {
1041 rc = claw_hw_tx( pk_skb, dev,1);
1042 if (privptr->write_free_count > 0) {
1043 pk_skb = claw_pack_skb(privptr);
1044 } else
1045 pk_skb = NULL;
1046 }
1047 }
1048 if (privptr->p_write_active_first!=NULL) {
1049 claw_strt_out_IO(dev);
1050 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 return;
1052} /* end of claw_write_next */
1053
1054/*-------------------------------------------------------------------*
1055* *
1056* claw_timer *
1057*--------------------------------------------------------------------*/
1058
1059static void
1060claw_timer ( struct chbk * p_ch )
1061{
Andy Richterb805da72008-07-18 15:24:56 +02001062 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 p_ch->flag |= CLAW_TIMER;
1064 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 return;
1066} /* end of claw_timer */
1067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068/*
1069*
1070* functions
1071*/
1072
1073
1074/*-------------------------------------------------------------------*
1075* *
1076* pages_to_order_of_mag *
1077* *
1078* takes a number of pages from 1 to 512 and returns the *
1079* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1080* of magnitude get_free_pages() has an upper order of 9 *
1081*--------------------------------------------------------------------*/
1082
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001083static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084pages_to_order_of_mag(int num_of_pages)
1085{
1086 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001087 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001088
1089 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1091 /* 512 pages = 2Meg on 4k page systems */
1092 if (num_of_pages >= 512) {return 9; }
1093 /* we have two or more pages order is at least 1 */
1094 for (nump=2 ;nump <= 512;nump*=2) {
1095 if (num_of_pages <= nump)
1096 break;
1097 order_of_mag +=1;
1098 }
1099 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001100 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 return order_of_mag;
1102}
1103
1104/*-------------------------------------------------------------------*
1105* *
1106* add_claw_reads *
1107* *
1108*--------------------------------------------------------------------*/
1109static int
1110add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1111 struct ccwbk* p_last)
1112{
1113 struct claw_privbk *privptr;
1114 struct ccw1 temp_ccw;
1115 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001116 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001117 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 p_end = privptr->p_end_ccw;
1119
1120 /* first CCW and last CCW contains a new set of read channel programs
1121 * to apend the running channel programs
1122 */
1123 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001124 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 return 0;
1126 }
1127
1128 /* set up ending CCW sequence for this segment */
1129 if (p_end->read1) {
1130 p_end->read1=0x00; /* second ending CCW is now active */
1131 /* reset ending CCWs and setup TIC CCWs */
1132 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1133 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1134 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1135 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1136 p_end->read2_nop2.cda=0;
1137 p_end->read2_nop2.count=1;
1138 }
1139 else {
1140 p_end->read1=0x01; /* first ending CCW is now active */
1141 /* reset ending CCWs and setup TIC CCWs */
1142 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1143 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1144 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1145 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1146 p_end->read1_nop2.cda=0;
1147 p_end->read1_nop2.count=1;
1148 }
1149
1150 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001151 privptr->p_read_active_first = p_first; /* set new first */
1152 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 }
1154 else {
1155
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 /* set up TIC ccw */
1157 temp_ccw.cda= (__u32)__pa(&p_first->read);
1158 temp_ccw.count=0;
1159 temp_ccw.flags=0;
1160 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1161
1162
1163 if (p_end->read1) {
1164
1165 /* first set of CCW's is chained to the new read */
1166 /* chain, so the second set is chained to the active chain. */
1167 /* Therefore modify the second set to point to the new */
1168 /* read chain set up TIC CCWs */
1169 /* make sure we update the CCW so channel doesn't fetch it */
1170 /* when it's only half done */
1171 memcpy( &p_end->read2_nop2, &temp_ccw ,
1172 sizeof(struct ccw1));
1173 privptr->p_read_active_last->r_TIC_1.cda=
1174 (__u32)__pa(&p_first->read);
1175 privptr->p_read_active_last->r_TIC_2.cda=
1176 (__u32)__pa(&p_first->read);
1177 }
1178 else {
1179 /* make sure we update the CCW so channel doesn't */
1180 /* fetch it when it is only half done */
1181 memcpy( &p_end->read1_nop2, &temp_ccw ,
1182 sizeof(struct ccw1));
1183 privptr->p_read_active_last->r_TIC_1.cda=
1184 (__u32)__pa(&p_first->read);
1185 privptr->p_read_active_last->r_TIC_2.cda=
1186 (__u32)__pa(&p_first->read);
1187 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001188 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 privptr->p_read_active_last->next = p_first;
1190 privptr->p_read_active_last=p_last;
1191 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001192 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 return 0;
1194} /* end of add_claw_reads */
1195
1196/*-------------------------------------------------------------------*
1197 * ccw_check_return_code *
1198 * *
1199 *-------------------------------------------------------------------*/
1200
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001201static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202ccw_check_return_code(struct ccw_device *cdev, int return_code)
1203{
Andy Richterb805da72008-07-18 15:24:56 +02001204 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 if (return_code != 0) {
1206 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001207 case -EBUSY: /* BUSY is a transient state no action needed */
1208 break;
1209 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001210 dev_err(&cdev->dev, "The remote channel adapter is not"
1211 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001212 break;
1213 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001214 dev_err(&cdev->dev,
1215 "The status of the remote channel adapter"
1216 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001217 break;
1218 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001219 dev_err(&cdev->dev, "The common device layer"
1220 " returned error code %d\n",
1221 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001222 }
1223 }
1224 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225} /* end of ccw_check_return_code */
1226
1227/*-------------------------------------------------------------------*
1228* ccw_check_unit_check *
1229*--------------------------------------------------------------------*/
1230
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001231static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1233{
Andy Richterb805da72008-07-18 15:24:56 +02001234 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001235 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Andy Richterb805da72008-07-18 15:24:56 +02001237 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001238 dev_warn(dev, "The communication peer of %s disconnected\n",
1239 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001241 if (sense & 0x40) {
1242 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001243 dev_warn(dev, "The remote channel adapter for"
1244 " %s has been reset\n",
1245 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001246 }
1247 } else if (sense & 0x20) {
1248 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001249 dev_warn(dev, "A data streaming timeout occurred"
1250 " for %s\n",
1251 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001252 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001253 dev_warn(dev, "The remote channel adapter for %s"
1254 " is faulty\n",
1255 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001256 } else {
1257 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001258 " for %s\n",
1259 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001260 }
1261 } else if (sense & 0x10) {
1262 dev_warn(dev, "A read data parity error occurred"
1263 " for %s\n",
1264 ndev->name);
1265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267} /* end of ccw_check_unit_check */
1268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269/*-------------------------------------------------------------------*
1270* find_link *
1271*--------------------------------------------------------------------*/
1272static int
1273find_link(struct net_device *dev, char *host_name, char *ws_name )
1274{
1275 struct claw_privbk *privptr;
1276 struct claw_env *p_env;
1277 int rc=0;
1278
Andy Richterb805da72008-07-18 15:24:56 +02001279 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001280 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 p_env=privptr->p_env;
1282 switch (p_env->packing)
1283 {
1284 case PACKING_ASK:
1285 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1286 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1287 rc = EINVAL;
1288 break;
1289 case DO_PACKED:
1290 case PACK_SEND:
1291 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1292 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1293 rc = EINVAL;
1294 break;
1295 default:
1296 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1297 (memcmp(p_env->api_type , ws_name, 8)!=0))
1298 rc = EINVAL;
1299 break;
1300 }
1301
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001302 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303} /* end of find_link */
1304
1305/*-------------------------------------------------------------------*
1306 * claw_hw_tx *
1307 * *
1308 * *
1309 *-------------------------------------------------------------------*/
1310
1311static int
1312claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1313{
1314 int rc=0;
1315 struct claw_privbk *privptr;
1316 struct ccwbk *p_this_ccw;
1317 struct ccwbk *p_first_ccw;
1318 struct ccwbk *p_last_ccw;
1319 __u32 numBuffers;
1320 signed long len_of_data;
1321 unsigned long bytesInThisBuffer;
1322 unsigned char *pDataAddress;
1323 struct endccw *pEnd;
1324 struct ccw1 tempCCW;
1325 struct chbk *p_ch;
1326 struct claw_env *p_env;
1327 int lock;
1328 struct clawph *pk_head;
1329 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001330
1331 CLAW_DBF_TEXT(4, trace, "hw_tx");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001332 privptr = (struct claw_privbk *)(dev->ml_priv);
Heiko Carstens319cb082010-08-12 01:58:27 +00001333 p_ch = (struct chbk *)&privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1336 /* scan the write queue to free any completed write packets */
1337 p_first_ccw=NULL;
1338 p_last_ccw=NULL;
1339 if ((p_env->packing >= PACK_SEND) &&
1340 (skb->cb[1] != 'P')) {
1341 skb_push(skb,sizeof(struct clawph));
1342 pk_head=(struct clawph *)skb->data;
1343 pk_head->len=skb->len-sizeof(struct clawph);
1344 if (pk_head->len%4) {
1345 pk_head->len+= 4-(pk_head->len%4);
1346 skb_pad(skb,4-(pk_head->len%4));
1347 skb_put(skb,4-(pk_head->len%4));
1348 }
1349 if (p_env->packing == DO_PACKED)
1350 pk_head->link_num = linkid;
1351 else
1352 pk_head->link_num = 0;
1353 pk_head->flag = 0x00;
1354 skb_pad(skb,4);
1355 skb->cb[1] = 'P';
1356 }
1357 if (linkid == 0) {
1358 if (claw_check_busy(dev)) {
1359 if (privptr->write_free_count!=0) {
1360 claw_clear_busy(dev);
1361 }
1362 else {
1363 claw_strt_out_IO(dev );
1364 claw_free_wrt_buf( dev );
1365 if (privptr->write_free_count==0) {
Heiko Carstens319cb082010-08-12 01:58:27 +00001366 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 atomic_inc(&skb->users);
1368 skb_queue_tail(&ch->collect_queue, skb);
1369 goto Done;
1370 }
1371 else {
1372 claw_clear_busy(dev);
1373 }
1374 }
1375 }
1376 /* tx lock */
1377 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Heiko Carstens319cb082010-08-12 01:58:27 +00001378 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 atomic_inc(&skb->users);
1380 skb_queue_tail(&ch->collect_queue, skb);
1381 claw_strt_out_IO(dev );
1382 rc=-EBUSY;
1383 goto Done2;
1384 }
1385 }
1386 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001387 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 /* If that number of buffers isn't available, give up for now */
1390 if (privptr->write_free_count < numBuffers ||
1391 privptr->p_write_free_chain == NULL ) {
1392
1393 claw_setbit_busy(TB_NOBUFFER,dev);
Heiko Carstens319cb082010-08-12 01:58:27 +00001394 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 atomic_inc(&skb->users);
1396 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001397 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 goto Done2;
1399 }
1400 pDataAddress=skb->data;
1401 len_of_data=skb->len;
1402
1403 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1405 if (p_this_ccw == NULL) { /* lost the race */
Heiko Carstens319cb082010-08-12 01:58:27 +00001406 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 atomic_inc(&skb->users);
1408 skb_queue_tail(&ch->collect_queue, skb);
1409 goto Done2;
1410 }
1411 privptr->p_write_free_chain=p_this_ccw->next;
1412 p_this_ccw->next=NULL;
1413 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001414 if (len_of_data >= privptr->p_env->write_size)
1415 bytesInThisBuffer = privptr->p_env->write_size;
1416 else
1417 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1419 len_of_data-=bytesInThisBuffer;
1420 pDataAddress+=(unsigned long)bytesInThisBuffer;
1421 /* setup write CCW */
1422 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1423 if (len_of_data>0) {
1424 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1425 }
1426 p_this_ccw->write.count=bytesInThisBuffer;
1427 /* now add to end of this chain */
1428 if (p_first_ccw==NULL) {
1429 p_first_ccw=p_this_ccw;
1430 }
1431 if (p_last_ccw!=NULL) {
1432 p_last_ccw->next=p_this_ccw;
1433 /* set up TIC ccws */
1434 p_last_ccw->w_TIC_1.cda=
1435 (__u32)__pa(&p_this_ccw->write);
1436 }
1437 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 }
1439
1440 /* FirstCCW and LastCCW now contain a new set of write channel
1441 * programs to append to the running channel program
1442 */
1443
1444 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001445 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 pEnd=privptr->p_end_ccw;
1447 if (pEnd->write1) {
1448 pEnd->write1=0x00; /* second end ccw is now active */
1449 /* set up Tic CCWs */
1450 p_last_ccw->w_TIC_1.cda=
1451 (__u32)__pa(&pEnd->write2_nop1);
1452 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1453 pEnd->write2_nop2.flags =
1454 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1455 pEnd->write2_nop2.cda=0;
1456 pEnd->write2_nop2.count=1;
1457 }
1458 else { /* end of if (pEnd->write1)*/
1459 pEnd->write1=0x01; /* first end ccw is now active */
1460 /* set up Tic CCWs */
1461 p_last_ccw->w_TIC_1.cda=
1462 (__u32)__pa(&pEnd->write1_nop1);
1463 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1464 pEnd->write1_nop2.flags =
1465 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1466 pEnd->write1_nop2.cda=0;
1467 pEnd->write1_nop2.count=1;
1468 } /* end if if (pEnd->write1) */
1469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 if (privptr->p_write_active_first==NULL ) {
1471 privptr->p_write_active_first=p_first_ccw;
1472 privptr->p_write_active_last=p_last_ccw;
1473 }
1474 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 /* set up Tic CCWs */
1476
1477 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1478 tempCCW.count=0;
1479 tempCCW.flags=0;
1480 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1481
1482 if (pEnd->write1) {
1483
1484 /*
1485 * first set of ending CCW's is chained to the new write
1486 * chain, so the second set is chained to the active chain
1487 * Therefore modify the second set to point the new write chain.
1488 * make sure we update the CCW atomically
1489 * so channel does not fetch it when it's only half done
1490 */
1491 memcpy( &pEnd->write2_nop2, &tempCCW ,
1492 sizeof(struct ccw1));
1493 privptr->p_write_active_last->w_TIC_1.cda=
1494 (__u32)__pa(&p_first_ccw->write);
1495 }
1496 else {
1497
1498 /*make sure we update the CCW atomically
1499 *so channel does not fetch it when it's only half done
1500 */
1501 memcpy(&pEnd->write1_nop2, &tempCCW ,
1502 sizeof(struct ccw1));
1503 privptr->p_write_active_last->w_TIC_1.cda=
1504 (__u32)__pa(&p_first_ccw->write);
1505
1506 } /* end if if (pEnd->write1) */
1507
1508 privptr->p_write_active_last->next=p_first_ccw;
1509 privptr->p_write_active_last=p_last_ccw;
1510 }
1511
1512 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001513 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 if (linkid==0) {
1515 lock=LOCK_NO;
1516 }
1517 else {
1518 lock=LOCK_YES;
1519 }
1520 claw_strt_out_IO(dev );
1521 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 if (privptr->write_free_count==0) {
1523 claw_setbit_busy(TB_NOBUFFER,dev);
1524 }
1525Done2:
1526 claw_clearbit_busy(TB_TX,dev);
1527Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 return(rc);
1529} /* end of claw_hw_tx */
1530
1531/*-------------------------------------------------------------------*
1532* *
1533* init_ccw_bk *
1534* *
1535*--------------------------------------------------------------------*/
1536
1537static int
1538init_ccw_bk(struct net_device *dev)
1539{
1540
1541 __u32 ccw_blocks_required;
1542 __u32 ccw_blocks_perpage;
1543 __u32 ccw_pages_required;
1544 __u32 claw_reads_perpage=1;
1545 __u32 claw_read_pages;
1546 __u32 claw_writes_perpage=1;
1547 __u32 claw_write_pages;
1548 void *p_buff=NULL;
1549 struct ccwbk*p_free_chain;
1550 struct ccwbk*p_buf;
1551 struct ccwbk*p_last_CCWB;
1552 struct ccwbk*p_first_CCWB;
1553 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001554 addr_t real_address;
1555 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 struct clawh *pClawH=NULL;
1557 addr_t real_TIC_address;
1558 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001559 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561 /* initialize statistics field */
1562 privptr->active_link_ID=0;
1563 /* initialize ccwbk pointers */
1564 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1565 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1566 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1567 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1568 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1569 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1570 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1571 privptr->buffs_alloc = 0;
1572 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1573 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1574 /* initialize free write ccwbk counter */
1575 privptr->write_free_count=0; /* number of free bufs on write chain */
1576 p_last_CCWB = NULL;
1577 p_first_CCWB= NULL;
1578 /*
1579 * We need 1 CCW block for each read buffer, 1 for each
1580 * write buffer, plus 1 for ClawSignalBlock
1581 */
1582 ccw_blocks_required =
1583 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 /*
1585 * compute number of CCW blocks that will fit in a page
1586 */
1587 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1588 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001589 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 /*
1592 * read and write sizes are set by 2 constants in claw.h
1593 * 4k and 32k. Unpacked values other than 4k are not going to
1594 * provide good performance. With packing buffers support 32k
1595 * buffers are used.
1596 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001597 if (privptr->p_env->read_size < PAGE_SIZE) {
1598 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1599 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1600 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 }
1602 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001603 privptr->p_buff_pages_perread =
1604 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1605 claw_read_pages = privptr->p_env->read_buffers *
1606 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 }
1608 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001609 claw_writes_perpage =
1610 PAGE_SIZE / privptr->p_env->write_size;
1611 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1612 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
1614 }
1615 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001616 privptr->p_buff_pages_perwrite =
1617 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1618 claw_write_pages = privptr->p_env->write_buffers *
1619 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 /*
1622 * allocate ccw_pages_required
1623 */
1624 if (privptr->p_buff_ccw==NULL) {
1625 privptr->p_buff_ccw=
1626 (void *)__get_free_pages(__GFP_DMA,
1627 (int)pages_to_order_of_mag(ccw_pages_required ));
1628 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 return -ENOMEM;
1630 }
1631 privptr->p_buff_ccw_num=ccw_pages_required;
1632 }
1633 memset(privptr->p_buff_ccw, 0x00,
1634 privptr->p_buff_ccw_num * PAGE_SIZE);
1635
1636 /*
1637 * obtain ending ccw block address
1638 *
1639 */
1640 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1641 real_address = (__u32)__pa(privptr->p_end_ccw);
1642 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 p_endccw=privptr->p_end_ccw;
1644 p_endccw->real=real_address;
1645 p_endccw->write1=0x00;
1646 p_endccw->read1=0x00;
1647
1648 /* write1_nop1 */
1649 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1650 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1651 p_endccw->write1_nop1.count = 1;
1652 p_endccw->write1_nop1.cda = 0;
1653
1654 /* write1_nop2 */
1655 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1656 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1657 p_endccw->write1_nop2.count = 1;
1658 p_endccw->write1_nop2.cda = 0;
1659
1660 /* write2_nop1 */
1661 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1662 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1663 p_endccw->write2_nop1.count = 1;
1664 p_endccw->write2_nop1.cda = 0;
1665
1666 /* write2_nop2 */
1667 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1668 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1669 p_endccw->write2_nop2.count = 1;
1670 p_endccw->write2_nop2.cda = 0;
1671
1672 /* read1_nop1 */
1673 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1674 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1675 p_endccw->read1_nop1.count = 1;
1676 p_endccw->read1_nop1.cda = 0;
1677
1678 /* read1_nop2 */
1679 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1680 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1681 p_endccw->read1_nop2.count = 1;
1682 p_endccw->read1_nop2.cda = 0;
1683
1684 /* read2_nop1 */
1685 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1686 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1687 p_endccw->read2_nop1.count = 1;
1688 p_endccw->read2_nop1.cda = 0;
1689
1690 /* read2_nop2 */
1691 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1692 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1693 p_endccw->read2_nop2.count = 1;
1694 p_endccw->read2_nop2.cda = 0;
1695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 /*
1697 * Build a chain of CCWs
1698 *
1699 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 p_buff=privptr->p_buff_ccw;
1701
1702 p_free_chain=NULL;
1703 for (i=0 ; i < ccw_pages_required; i++ ) {
1704 real_address = (__u32)__pa(p_buff);
1705 p_buf=p_buff;
1706 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1707 p_buf->next = p_free_chain;
1708 p_free_chain = p_buf;
1709 p_buf->real=(__u32)__pa(p_buf);
1710 ++p_buf;
1711 }
1712 p_buff+=PAGE_SIZE;
1713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 /*
1715 * Initialize ClawSignalBlock
1716 *
1717 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 if (privptr->p_claw_signal_blk==NULL) {
1719 privptr->p_claw_signal_blk=p_free_chain;
1720 p_free_chain=p_free_chain->next;
1721 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1722 pClawH->length=0xffff;
1723 pClawH->opcode=0xff;
1724 pClawH->flag=CLAW_BUSY;
1725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
1727 /*
1728 * allocate write_pages_required and add to free chain
1729 */
1730 if (privptr->p_buff_write==NULL) {
1731 if (privptr->p_env->write_size < PAGE_SIZE) {
1732 privptr->p_buff_write=
1733 (void *)__get_free_pages(__GFP_DMA,
1734 (int)pages_to_order_of_mag(claw_write_pages ));
1735 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 return -ENOMEM;
1738 }
1739 /*
1740 * Build CLAW write free chain
1741 *
1742 */
1743
1744 memset(privptr->p_buff_write, 0x00,
1745 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 privptr->p_write_free_chain=NULL;
1747
1748 p_buff=privptr->p_buff_write;
1749
1750 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1751 p_buf = p_free_chain; /* get a CCW */
1752 p_free_chain = p_buf->next;
1753 p_buf->next =privptr->p_write_free_chain;
1754 privptr->p_write_free_chain = p_buf;
1755 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1756 p_buf-> write.cda = (__u32)__pa(p_buff);
1757 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1758 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1759 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1760 p_buf-> w_read_FF.count = 1;
1761 p_buf-> w_read_FF.cda =
1762 (__u32)__pa(&p_buf-> header.flag);
1763 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1764 p_buf-> w_TIC_1.flags = 0;
1765 p_buf-> w_TIC_1.count = 0;
1766
Andy Richter4811fcb2009-01-20 06:14:33 +00001767 if (((unsigned long)p_buff +
1768 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001770 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1771 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 }
1773 }
1774 }
1775 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1776 {
1777 privptr->p_write_free_chain=NULL;
1778 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1779 p_buff=(void *)__get_free_pages(__GFP_DMA,
1780 (int)pages_to_order_of_mag(
1781 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 free_pages((unsigned long)privptr->p_buff_ccw,
1784 (int)pages_to_order_of_mag(
1785 privptr->p_buff_ccw_num));
1786 privptr->p_buff_ccw=NULL;
1787 p_buf=privptr->p_buff_write;
1788 while (p_buf!=NULL) {
1789 free_pages((unsigned long)
1790 p_buf->p_buffer,
1791 (int)pages_to_order_of_mag(
1792 privptr->p_buff_pages_perwrite));
1793 p_buf=p_buf->next;
1794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 return -ENOMEM;
1796 } /* Error on get_pages */
1797 memset(p_buff, 0x00, privptr->p_env->write_size );
1798 p_buf = p_free_chain;
1799 p_free_chain = p_buf->next;
1800 p_buf->next = privptr->p_write_free_chain;
1801 privptr->p_write_free_chain = p_buf;
1802 privptr->p_buff_write = p_buf;
1803 p_buf->p_buffer=(struct clawbuf *)p_buff;
1804 p_buf-> write.cda = (__u32)__pa(p_buff);
1805 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1806 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1807 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1808 p_buf-> w_read_FF.count = 1;
1809 p_buf-> w_read_FF.cda =
1810 (__u32)__pa(&p_buf-> header.flag);
1811 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1812 p_buf-> w_TIC_1.flags = 0;
1813 p_buf-> w_TIC_1.count = 0;
1814 } /* for all write_buffers */
1815
1816 } /* else buffers are PAGE_SIZE or bigger */
1817
1818 }
1819 privptr->p_buff_write_num=claw_write_pages;
1820 privptr->write_free_count=privptr->p_env->write_buffers;
1821
1822
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 /*
1824 * allocate read_pages_required and chain to free chain
1825 */
1826 if (privptr->p_buff_read==NULL) {
1827 if (privptr->p_env->read_size < PAGE_SIZE) {
1828 privptr->p_buff_read=
1829 (void *)__get_free_pages(__GFP_DMA,
1830 (int)pages_to_order_of_mag(claw_read_pages) );
1831 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 free_pages((unsigned long)privptr->p_buff_ccw,
1833 (int)pages_to_order_of_mag(
1834 privptr->p_buff_ccw_num));
1835 /* free the write pages size is < page size */
1836 free_pages((unsigned long)privptr->p_buff_write,
1837 (int)pages_to_order_of_mag(
1838 privptr->p_buff_write_num));
1839 privptr->p_buff_ccw=NULL;
1840 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 return -ENOMEM;
1842 }
1843 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1844 privptr->p_buff_read_num=claw_read_pages;
1845 /*
1846 * Build CLAW read free chain
1847 *
1848 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 p_buff=privptr->p_buff_read;
1850 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1851 p_buf = p_free_chain;
1852 p_free_chain = p_buf->next;
1853
1854 if (p_last_CCWB==NULL) {
1855 p_buf->next=NULL;
1856 real_TIC_address=0;
1857 p_last_CCWB=p_buf;
1858 }
1859 else {
1860 p_buf->next=p_first_CCWB;
1861 real_TIC_address=
1862 (__u32)__pa(&p_first_CCWB -> read );
1863 }
1864
1865 p_first_CCWB=p_buf;
1866
1867 p_buf->p_buffer=(struct clawbuf *)p_buff;
1868 /* initialize read command */
1869 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1870 p_buf-> read.cda = (__u32)__pa(p_buff);
1871 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1872 p_buf-> read.count = privptr->p_env->read_size;
1873
1874 /* initialize read_h command */
1875 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1876 p_buf-> read_h.cda =
1877 (__u32)__pa(&(p_buf->header));
1878 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1879 p_buf-> read_h.count = sizeof(struct clawh);
1880
1881 /* initialize Signal command */
1882 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1883 p_buf-> signal.cda =
1884 (__u32)__pa(&(pClawH->flag));
1885 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1886 p_buf-> signal.count = 1;
1887
1888 /* initialize r_TIC_1 command */
1889 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1890 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1891 p_buf-> r_TIC_1.flags = 0;
1892 p_buf-> r_TIC_1.count = 0;
1893
1894 /* initialize r_read_FF command */
1895 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1896 p_buf-> r_read_FF.cda =
1897 (__u32)__pa(&(pClawH->flag));
1898 p_buf-> r_read_FF.flags =
1899 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1900 p_buf-> r_read_FF.count = 1;
1901
1902 /* initialize r_TIC_2 */
1903 memcpy(&p_buf->r_TIC_2,
1904 &p_buf->r_TIC_1, sizeof(struct ccw1));
1905
1906 /* initialize Header */
1907 p_buf->header.length=0xffff;
1908 p_buf->header.opcode=0xff;
1909 p_buf->header.flag=CLAW_PENDING;
1910
Andy Richter4811fcb2009-01-20 06:14:33 +00001911 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1912 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1913 -1)
1914 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 p_buff= p_buff+privptr->p_env->read_size;
1916 }
1917 else {
1918 p_buff=
1919 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001920 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 & PAGE_MASK) ;
1922 }
1923 } /* for read_buffers */
1924 } /* read_size < PAGE_SIZE */
1925 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1927 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001928 (int)pages_to_order_of_mag(
1929 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001932 (int)pages_to_order_of_mag(privptr->
1933 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 /* free the write pages */
1935 p_buf=privptr->p_buff_write;
1936 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001937 free_pages(
1938 (unsigned long)p_buf->p_buffer,
1939 (int)pages_to_order_of_mag(
1940 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 p_buf=p_buf->next;
1942 }
1943 /* free any read pages already alloc */
1944 p_buf=privptr->p_buff_read;
1945 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001946 free_pages(
1947 (unsigned long)p_buf->p_buffer,
1948 (int)pages_to_order_of_mag(
1949 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 p_buf=p_buf->next;
1951 }
1952 privptr->p_buff_ccw=NULL;
1953 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 return -ENOMEM;
1955 }
1956 memset(p_buff, 0x00, privptr->p_env->read_size);
1957 p_buf = p_free_chain;
1958 privptr->p_buff_read = p_buf;
1959 p_free_chain = p_buf->next;
1960
1961 if (p_last_CCWB==NULL) {
1962 p_buf->next=NULL;
1963 real_TIC_address=0;
1964 p_last_CCWB=p_buf;
1965 }
1966 else {
1967 p_buf->next=p_first_CCWB;
1968 real_TIC_address=
1969 (addr_t)__pa(
1970 &p_first_CCWB -> read );
1971 }
1972
1973 p_first_CCWB=p_buf;
1974 /* save buff address */
1975 p_buf->p_buffer=(struct clawbuf *)p_buff;
1976 /* initialize read command */
1977 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1978 p_buf-> read.cda = (__u32)__pa(p_buff);
1979 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1980 p_buf-> read.count = privptr->p_env->read_size;
1981
1982 /* initialize read_h command */
1983 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1984 p_buf-> read_h.cda =
1985 (__u32)__pa(&(p_buf->header));
1986 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1987 p_buf-> read_h.count = sizeof(struct clawh);
1988
1989 /* initialize Signal command */
1990 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1991 p_buf-> signal.cda =
1992 (__u32)__pa(&(pClawH->flag));
1993 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1994 p_buf-> signal.count = 1;
1995
1996 /* initialize r_TIC_1 command */
1997 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1998 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1999 p_buf-> r_TIC_1.flags = 0;
2000 p_buf-> r_TIC_1.count = 0;
2001
2002 /* initialize r_read_FF command */
2003 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2004 p_buf-> r_read_FF.cda =
2005 (__u32)__pa(&(pClawH->flag));
2006 p_buf-> r_read_FF.flags =
2007 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2008 p_buf-> r_read_FF.count = 1;
2009
2010 /* initialize r_TIC_2 */
2011 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
2012 sizeof(struct ccw1));
2013
2014 /* initialize Header */
2015 p_buf->header.length=0xffff;
2016 p_buf->header.opcode=0xff;
2017 p_buf->header.flag=CLAW_PENDING;
2018
2019 } /* For read_buffers */
2020 } /* read_size >= PAGE_SIZE */
2021 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
2023 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02002024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 return 0;
2026} /* end of init_ccw_bk */
2027
2028/*-------------------------------------------------------------------*
2029* *
2030* probe_error *
2031* *
2032*--------------------------------------------------------------------*/
2033
2034static void
2035probe_error( struct ccwgroup_device *cgdev)
2036{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002037 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002038
2039 CLAW_DBF_TEXT(4, trace, "proberr");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002040 privptr = dev_get_drvdata(&cgdev->dev);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002041 if (privptr != NULL) {
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002042 dev_set_drvdata(&cgdev->dev, NULL);
Jesper Juhl17fd6822005-11-07 01:01:30 -08002043 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002044 kfree(privptr->p_mtc_envelope);
2045 kfree(privptr);
2046 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047} /* probe_error */
2048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049/*-------------------------------------------------------------------*
2050* claw_process_control *
2051* *
2052* *
2053*--------------------------------------------------------------------*/
2054
2055static int
2056claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2057{
2058
2059 struct clawbuf *p_buf;
2060 struct clawctl ctlbk;
2061 struct clawctl *p_ctlbk;
2062 char temp_host_name[8];
2063 char temp_ws_name[8];
2064 struct claw_privbk *privptr;
2065 struct claw_env *p_env;
2066 struct sysval *p_sysval;
2067 struct conncmd *p_connect=NULL;
2068 int rc;
2069 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002070 struct device *tdev;
2071 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 udelay(1000); /* Wait a ms for the control packets to
2073 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02002074 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 p_env=privptr->p_env;
Heiko Carstens319cb082010-08-12 01:58:27 +00002076 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 memcpy( &temp_host_name, p_env->host_name, 8);
2078 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00002079 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 "Received Control Packet\n",
2081 dev->name, temp_ws_name);
2082 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 return 0;
2084 }
2085 p_buf=p_ccw->p_buffer;
2086 p_ctlbk=&ctlbk;
2087 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2088 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2089 } else {
2090 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2091 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 switch (p_ctlbk->command)
2093 {
Andy Richterb805da72008-07-18 15:24:56 +02002094 case SYSTEM_VALIDATE_REQUEST:
2095 if (p_ctlbk->version != CLAW_VERSION_ID) {
2096 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2097 CLAW_RC_WRONG_VERSION);
Andy Richter4811fcb2009-01-20 06:14:33 +00002098 dev_warn(tdev, "The communication peer of %s"
2099 " uses an incorrect API version %d\n",
2100 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002101 }
2102 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002103 dev_info(tdev, "%s: Recv Sys Validate Request: "
2104 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2105 "Host name=%.8s\n",
2106 dev->name, p_ctlbk->version,
2107 p_ctlbk->linkid,
2108 p_ctlbk->correlator,
2109 p_sysval->WS_name,
2110 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002111 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2112 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2113 CLAW_RC_NAME_MISMATCH);
2114 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2115 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2116 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002117 dev_warn(tdev,
2118 "Host name %s for %s does not match the"
2119 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002120 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002121 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002122 temp_host_name);
2123 }
2124 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2125 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2126 CLAW_RC_NAME_MISMATCH);
2127 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2128 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2129 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002130 dev_warn(tdev, "Adapter name %s for %s does not match"
2131 " the remote host name %s\n",
2132 p_sysval->WS_name,
2133 dev->name,
2134 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002135 }
2136 if ((p_sysval->write_frame_size < p_env->write_size) &&
2137 (p_env->packing == 0)) {
2138 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2139 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002140 dev_warn(tdev,
2141 "The local write buffer is smaller than the"
2142 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002143 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2144 }
2145 if ((p_sysval->read_frame_size < p_env->read_size) &&
2146 (p_env->packing == 0)) {
2147 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2148 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002149 dev_warn(tdev,
2150 "The local read buffer is smaller than the"
2151 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002152 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2153 }
2154 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002155 dev_info(tdev,
2156 "CLAW device %.8s: System validate"
2157 " completed.\n", temp_ws_name);
2158 dev_info(tdev,
2159 "%s: sys Validate Rsize:%d Wsize:%d\n",
2160 dev->name, p_sysval->read_frame_size,
2161 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002162 privptr->system_validate_comp = 1;
2163 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2164 p_env->packing = PACKING_ASK;
2165 claw_strt_conn_req(dev);
2166 break;
2167 case SYSTEM_VALIDATE_RESPONSE:
2168 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002169 dev_info(tdev,
2170 "Settings for %s validated (version=%d, "
2171 "remote device=%d, rc=%d, adapter name=%.8s, "
2172 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002173 dev->name,
2174 p_ctlbk->version,
2175 p_ctlbk->correlator,
2176 p_ctlbk->rc,
2177 p_sysval->WS_name,
2178 p_sysval->host_name);
2179 switch (p_ctlbk->rc) {
2180 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002181 dev_info(tdev, "%s: CLAW device "
2182 "%.8s: System validate completed.\n",
2183 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002184 if (privptr->system_validate_comp == 0)
2185 claw_strt_conn_req(dev);
2186 privptr->system_validate_comp = 1;
2187 break;
2188 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002189 dev_warn(tdev, "Validating %s failed because of"
2190 " a host or adapter name mismatch\n",
2191 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002192 break;
2193 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002194 dev_warn(tdev, "Validating %s failed because of a"
2195 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002196 dev->name);
2197 break;
2198 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002199 dev_warn(tdev, "Validating %s failed because of a"
2200 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002201 dev->name);
2202 break;
2203 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002204 dev_warn(tdev, "The communication peer of %s rejected"
2205 " the connection\n",
2206 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002207 break;
2208 }
2209 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
Andy Richterb805da72008-07-18 15:24:56 +02002211 case CONNECTION_REQUEST:
2212 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002213 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002214 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2215 dev->name,
2216 p_ctlbk->version,
2217 p_ctlbk->linkid,
2218 p_ctlbk->correlator,
2219 p_connect->host_name,
2220 p_connect->WS_name);
2221 if (privptr->active_link_ID != 0) {
2222 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002223 dev_info(tdev, "%s rejected a connection request"
2224 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002225 dev->name);
2226 }
2227 if (p_ctlbk->linkid != 1) {
2228 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002229 dev_info(tdev, "%s rejected a request to open multiple"
2230 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002231 dev->name);
2232 }
2233 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2234 if (rc != 0) {
2235 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002236 dev_info(tdev, "%s rejected a connection request"
2237 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002238 dev->name);
2239 }
2240 claw_send_control(dev,
2241 CONNECTION_CONFIRM, p_ctlbk->linkid,
2242 p_ctlbk->correlator,
2243 0, p_connect->host_name,
2244 p_connect->WS_name);
2245 if (p_env->packing == PACKING_ASK) {
2246 p_env->packing = PACK_SEND;
2247 claw_snd_conn_req(dev, 0);
2248 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002249 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002250 "completed link_id=%d.\n",
2251 dev->name, temp_ws_name,
2252 p_ctlbk->linkid);
2253 privptr->active_link_ID = p_ctlbk->linkid;
Heiko Carstens319cb082010-08-12 01:58:27 +00002254 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002255 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2256 break;
2257 case CONNECTION_RESPONSE:
2258 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002259 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002260 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2261 dev->name,
2262 p_ctlbk->version,
2263 p_ctlbk->linkid,
2264 p_ctlbk->correlator,
2265 p_ctlbk->rc,
2266 p_connect->host_name,
2267 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Andy Richterb805da72008-07-18 15:24:56 +02002269 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002270 dev_warn(tdev, "The communication peer of %s rejected"
2271 " a connection request\n",
2272 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002273 return 1;
2274 }
2275 rc = find_link(dev,
2276 p_connect->host_name, p_connect->WS_name);
2277 if (rc != 0) {
2278 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002279 dev_warn(tdev, "The communication peer of %s"
2280 " rejected a connection "
2281 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002282 dev->name);
2283 }
2284 /* should be until CONNECTION_CONFIRM */
2285 privptr->active_link_ID = -(p_ctlbk->linkid);
2286 break;
2287 case CONNECTION_CONFIRM:
2288 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002289 dev_info(tdev,
2290 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002291 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2292 dev->name,
2293 p_ctlbk->version,
2294 p_ctlbk->linkid,
2295 p_ctlbk->correlator,
2296 p_connect->host_name,
2297 p_connect->WS_name);
2298 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2299 privptr->active_link_ID = p_ctlbk->linkid;
2300 if (p_env->packing > PACKING_ASK) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002301 dev_info(tdev,
2302 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 p_env->packing = DO_PACKED;
2304 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002305 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002306 wake_up(&p_ch->wait);
2307 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002308 dev_warn(tdev, "Activating %s failed because of"
2309 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002310 dev->name, p_ctlbk->linkid);
2311 claw_snd_disc(dev, p_ctlbk);
2312 }
2313 break;
2314 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002315 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002316 "Vers=%d,link_id=%d,Corr=%d\n",
2317 dev->name, p_ctlbk->version,
2318 p_ctlbk->linkid, p_ctlbk->correlator);
2319 if ((p_ctlbk->linkid == 2) &&
2320 (p_env->packing == PACK_SEND)) {
2321 privptr->active_link_ID = 1;
2322 p_env->packing = DO_PACKED;
2323 } else
2324 privptr->active_link_ID = 0;
2325 break;
2326 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002327 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002328 dev->name);
2329 break;
2330 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002331 dev_warn(tdev, "The communication peer of %s sent"
2332 " an unknown command code\n",
2333 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002334 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 }
2336
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 return 0;
2338} /* end of claw_process_control */
2339
2340
2341/*-------------------------------------------------------------------*
2342* claw_send_control *
2343* *
2344*--------------------------------------------------------------------*/
2345
2346static int
2347claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2348 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2349{
2350 struct claw_privbk *privptr;
2351 struct clawctl *p_ctl;
2352 struct sysval *p_sysval;
2353 struct conncmd *p_connect;
2354 struct sk_buff *skb;
2355
Andy Richterb805da72008-07-18 15:24:56 +02002356 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002357 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2359
2360 p_ctl->command=type;
2361 p_ctl->version=CLAW_VERSION_ID;
2362 p_ctl->linkid=link;
2363 p_ctl->correlator=correlator;
2364 p_ctl->rc=rc;
2365
2366 p_sysval=(struct sysval *)&p_ctl->data;
2367 p_connect=(struct conncmd *)&p_ctl->data;
2368
2369 switch (p_ctl->command) {
2370 case SYSTEM_VALIDATE_REQUEST:
2371 case SYSTEM_VALIDATE_RESPONSE:
2372 memcpy(&p_sysval->host_name, local_name, 8);
2373 memcpy(&p_sysval->WS_name, remote_name, 8);
2374 if (privptr->p_env->packing > 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002375 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2376 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002378 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002379 p_sysval->read_frame_size =
2380 privptr->p_env->read_size;
2381 p_sysval->write_frame_size =
2382 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 }
2384 memset(&p_sysval->reserved, 0x00, 4);
2385 break;
2386 case CONNECTION_REQUEST:
2387 case CONNECTION_RESPONSE:
2388 case CONNECTION_CONFIRM:
2389 case DISCONNECT:
2390 memcpy(&p_sysval->host_name, local_name, 8);
2391 memcpy(&p_sysval->WS_name, remote_name, 8);
2392 if (privptr->p_env->packing > 0) {
2393 /* How big is the biggest packet */
2394 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2395 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2396 } else {
2397 memset(&p_connect->reserved1, 0x00, 4);
2398 memset(&p_connect->reserved2, 0x00, 4);
2399 }
2400 break;
2401 default:
2402 break;
2403 }
2404
2405 /* write Control Record to the device */
2406
2407
2408 skb = dev_alloc_skb(sizeof(struct clawctl));
2409 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 return -ENOMEM;
2411 }
2412 memcpy(skb_put(skb, sizeof(struct clawctl)),
2413 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 if (privptr->p_env->packing >= PACK_SEND)
2415 claw_hw_tx(skb, dev, 1);
2416 else
2417 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 return 0;
2419} /* end of claw_send_control */
2420
2421/*-------------------------------------------------------------------*
2422* claw_snd_conn_req *
2423* *
2424*--------------------------------------------------------------------*/
2425static int
2426claw_snd_conn_req(struct net_device *dev, __u8 link)
2427{
2428 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002429 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 struct clawctl *p_ctl;
2431
Andy Richterb805da72008-07-18 15:24:56 +02002432 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 rc = 1;
2434 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2435 p_ctl->linkid = link;
2436 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 return rc;
2438 }
2439 if (privptr->p_env->packing == PACKING_ASK )
2440 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2441 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2442 if (privptr->p_env->packing == PACK_SEND) {
2443 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2444 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2445 }
2446 if (privptr->p_env->packing == 0)
2447 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2448 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 return rc;
2450
2451} /* end of claw_snd_conn_req */
2452
2453
2454/*-------------------------------------------------------------------*
2455* claw_snd_disc *
2456* *
2457*--------------------------------------------------------------------*/
2458
2459static int
2460claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2461{
2462 int rc;
2463 struct conncmd * p_connect;
2464
Andy Richterb805da72008-07-18 15:24:56 +02002465 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 p_connect=(struct conncmd *)&p_ctl->data;
2467
2468 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2469 p_ctl->correlator, 0,
2470 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 return rc;
2472} /* end of claw_snd_disc */
2473
2474
2475/*-------------------------------------------------------------------*
2476* claw_snd_sys_validate_rsp *
2477* *
2478*--------------------------------------------------------------------*/
2479
2480static int
2481claw_snd_sys_validate_rsp(struct net_device *dev,
2482 struct clawctl *p_ctl, __u32 return_code)
2483{
2484 struct claw_env * p_env;
2485 struct claw_privbk *privptr;
2486 int rc;
2487
Andy Richterb805da72008-07-18 15:24:56 +02002488 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002489 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 p_env=privptr->p_env;
2491 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2492 p_ctl->linkid,
2493 p_ctl->correlator,
2494 return_code,
2495 p_env->host_name,
2496 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 return rc;
2498} /* end of claw_snd_sys_validate_rsp */
2499
2500/*-------------------------------------------------------------------*
2501* claw_strt_conn_req *
2502* *
2503*--------------------------------------------------------------------*/
2504
2505static int
2506claw_strt_conn_req(struct net_device *dev )
2507{
2508 int rc;
2509
Andy Richterb805da72008-07-18 15:24:56 +02002510 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 return rc;
2513} /* end of claw_strt_conn_req */
2514
2515
2516
2517/*-------------------------------------------------------------------*
2518 * claw_stats *
2519 *-------------------------------------------------------------------*/
2520
2521static struct
2522net_device_stats *claw_stats(struct net_device *dev)
2523{
2524 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002525
2526 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002527 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 return &privptr->stats;
2529} /* end of claw_stats */
2530
2531
2532/*-------------------------------------------------------------------*
2533* unpack_read *
2534* *
2535*--------------------------------------------------------------------*/
2536static void
2537unpack_read(struct net_device *dev )
2538{
2539 struct sk_buff *skb;
2540 struct claw_privbk *privptr;
2541 struct claw_env *p_env;
2542 struct ccwbk *p_this_ccw;
2543 struct ccwbk *p_first_ccw;
2544 struct ccwbk *p_last_ccw;
2545 struct clawph *p_packh;
2546 void *p_packd;
2547 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002548 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
2550 __u32 len_of_data;
2551 __u32 pack_off;
2552 __u8 link_num;
2553 __u8 mtc_this_frm=0;
2554 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 int i=0;
2556 int p=0;
2557
Andy Richterb805da72008-07-18 15:24:56 +02002558 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 p_first_ccw=NULL;
2560 p_last_ccw=NULL;
2561 p_packh=NULL;
2562 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002563 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002564
Heiko Carstens319cb082010-08-12 01:58:27 +00002565 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 p_env = privptr->p_env;
2567 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 pack_off = 0;
2570 p = 0;
2571 p_this_ccw->header.flag=CLAW_PENDING;
2572 privptr->p_read_active_first=p_this_ccw->next;
2573 p_this_ccw->next=NULL;
2574 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2575 if ((p_env->packing == PACK_SEND) &&
2576 (p_packh->len == 32) &&
2577 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2578 p_packh++; /* peek past pack header */
2579 p_ctlrec = (struct clawctl *)p_packh;
2580 p_packh--; /* un peek */
2581 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2582 (p_ctlrec->command == CONNECTION_CONFIRM))
2583 p_env->packing = DO_PACKED;
2584 }
2585 if (p_env->packing == DO_PACKED)
2586 link_num=p_packh->link_num;
2587 else
2588 link_num=p_this_ccw->header.opcode / 8;
2589 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 mtc_this_frm=1;
2591 if (p_this_ccw->header.length!=
2592 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002593 dev_warn(p_dev,
2594 "The communication peer of %s"
2595 " sent a faulty"
2596 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 dev->name, p_this_ccw->header.length);
2598 }
2599 }
2600
2601 if (privptr->mtc_skipping) {
2602 /*
2603 * We're in the mode of skipping past a
2604 * multi-frame message
2605 * that we can't process for some reason or other.
2606 * The first frame without the More-To-Come flag is
2607 * the last frame of the skipped message.
2608 */
2609 /* in case of More-To-Come not set in this frame */
2610 if (mtc_this_frm==0) {
2611 privptr->mtc_skipping=0; /* Ok, the end */
2612 privptr->mtc_logical_link=-1;
2613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 goto NextFrame;
2615 }
2616
2617 if (link_num==0) {
2618 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002619 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 goto NextFrame;
2621 }
2622unpack_next:
2623 if (p_env->packing == DO_PACKED) {
2624 if (pack_off > p_env->read_size)
2625 goto NextFrame;
2626 p_packd = p_this_ccw->p_buffer+pack_off;
2627 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002628 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 (p_packh->flag != 0))
2630 goto NextFrame;
2631 bytes_to_mov = p_packh->len;
2632 pack_off += bytes_to_mov+sizeof(struct clawph);
2633 p++;
2634 } else {
2635 bytes_to_mov=p_this_ccw->header.length;
2636 }
2637 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
2639 /*
2640 * if More-To-Come is set in this frame then we don't know
2641 * length of entire message, and hence have to allocate
2642 * large buffer */
2643
2644 /* We are starting a new envelope */
2645 privptr->mtc_offset=0;
2646 privptr->mtc_logical_link=link_num;
2647 }
2648
2649 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2650 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 privptr->stats.rx_frame_errors++;
2652 goto NextFrame;
2653 }
2654 if (p_env->packing == DO_PACKED) {
2655 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2656 p_packd+sizeof(struct clawph), bytes_to_mov);
2657
2658 } else {
2659 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2660 p_this_ccw->p_buffer, bytes_to_mov);
2661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 if (mtc_this_frm==0) {
2663 len_of_data=privptr->mtc_offset+bytes_to_mov;
2664 skb=dev_alloc_skb(len_of_data);
2665 if (skb) {
2666 memcpy(skb_put(skb,len_of_data),
2667 privptr->p_mtc_envelope,
2668 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002670 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 skb->protocol=htons(ETH_P_IP);
2672 skb->ip_summed=CHECKSUM_UNNECESSARY;
2673 privptr->stats.rx_packets++;
2674 privptr->stats.rx_bytes+=len_of_data;
2675 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 }
2677 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002678 dev_info(p_dev, "Allocating a buffer for"
2679 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 }
2682 privptr->mtc_offset=0;
2683 privptr->mtc_logical_link=-1;
2684 }
2685 else {
2686 privptr->mtc_offset+=bytes_to_mov;
2687 }
2688 if (p_env->packing == DO_PACKED)
2689 goto unpack_next;
2690NextFrame:
2691 /*
2692 * Remove ThisCCWblock from active read queue, and add it
2693 * to queue of free blocks to be reused.
2694 */
2695 i++;
2696 p_this_ccw->header.length=0xffff;
2697 p_this_ccw->header.opcode=0xff;
2698 /*
2699 * add this one to the free queue for later reuse
2700 */
2701 if (p_first_ccw==NULL) {
2702 p_first_ccw = p_this_ccw;
2703 }
2704 else {
2705 p_last_ccw->next = p_this_ccw;
2706 }
2707 p_last_ccw = p_this_ccw;
2708 /*
2709 * chain to next block on active read queue
2710 */
2711 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002712 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 } /* end of while */
2714
2715 /* check validity */
2716
Andy Richterb805da72008-07-18 15:24:56 +02002717 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 return;
2721} /* end of unpack_read */
2722
2723/*-------------------------------------------------------------------*
2724* claw_strt_read *
2725* *
2726*--------------------------------------------------------------------*/
2727static void
2728claw_strt_read (struct net_device *dev, int lock )
2729{
2730 int rc = 0;
2731 __u32 parm;
2732 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002733 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 struct ccwbk*p_ccwbk;
2735 struct chbk *p_ch;
2736 struct clawh *p_clawh;
Heiko Carstens319cb082010-08-12 01:58:27 +00002737 p_ch = &privptr->channel[READ_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
Andy Richterb805da72008-07-18 15:24:56 +02002739 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2741 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2742
2743 if ((privptr->p_write_active_first!=NULL &&
2744 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2745 (privptr->p_read_active_first!=NULL &&
2746 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2747 p_clawh->flag=CLAW_BUSY; /* 0xff */
2748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 if (lock==LOCK_YES) {
2750 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2751 }
2752 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002753 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 p_ccwbk=privptr->p_read_active_first;
2755 parm = (unsigned long) p_ch;
2756 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2757 0xff, 0);
2758 if (rc != 0) {
2759 ccw_check_return_code(p_ch->cdev, rc);
2760 }
2761 }
2762 else {
Andy Richterb805da72008-07-18 15:24:56 +02002763 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 }
2765
2766 if (lock==LOCK_YES) {
2767 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2768 }
Andy Richterb805da72008-07-18 15:24:56 +02002769 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 return;
2771} /* end of claw_strt_read */
2772
2773/*-------------------------------------------------------------------*
2774* claw_strt_out_IO *
2775* *
2776*--------------------------------------------------------------------*/
2777
2778static void
2779claw_strt_out_IO( struct net_device *dev )
2780{
2781 int rc = 0;
2782 unsigned long parm;
2783 struct claw_privbk *privptr;
2784 struct chbk *p_ch;
2785 struct ccwbk *p_first_ccw;
2786
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 if (!dev) {
2788 return;
2789 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002790 privptr = (struct claw_privbk *)dev->ml_priv;
Heiko Carstens319cb082010-08-12 01:58:27 +00002791 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
Andy Richterb805da72008-07-18 15:24:56 +02002793 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 p_first_ccw=privptr->p_write_active_first;
2795
2796 if (p_ch->claw_state == CLAW_STOP)
2797 return;
2798 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 return;
2800 }
2801 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2802 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002803 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002804 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2805 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 if (rc != 0) {
2807 ccw_check_return_code(p_ch->cdev, rc);
2808 }
2809 }
2810 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 return;
2812} /* end of claw_strt_out_IO */
2813
2814/*-------------------------------------------------------------------*
2815* Free write buffers *
2816* *
2817*--------------------------------------------------------------------*/
2818
2819static void
2820claw_free_wrt_buf( struct net_device *dev )
2821{
2822
Peter Tiedemann6951df32008-08-21 17:10:23 +02002823 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 struct ccwbk*p_first_ccw;
2825 struct ccwbk*p_last_ccw;
2826 struct ccwbk*p_this_ccw;
2827 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002828
2829 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 /* scan the write queue to free any completed write packets */
2831 p_first_ccw=NULL;
2832 p_last_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 p_this_ccw=privptr->p_write_active_first;
2834 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2835 {
2836 p_next_ccw = p_this_ccw->next;
2837 if (((p_next_ccw!=NULL) &&
2838 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2839 ((p_this_ccw == privptr->p_write_active_last) &&
2840 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2841 /* The next CCW is OK or this is */
2842 /* the last CCW...free it @A1A */
2843 privptr->p_write_active_first=p_this_ccw->next;
2844 p_this_ccw->header.flag=CLAW_PENDING;
2845 p_this_ccw->next=privptr->p_write_free_chain;
2846 privptr->p_write_free_chain=p_this_ccw;
2847 ++privptr->write_free_count;
2848 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2849 p_this_ccw=privptr->p_write_active_first;
2850 privptr->stats.tx_packets++;
2851 }
2852 else {
2853 break;
2854 }
2855 }
2856 if (privptr->write_free_count!=0) {
2857 claw_clearbit_busy(TB_NOBUFFER,dev);
2858 }
2859 /* whole chain removed? */
2860 if (privptr->p_write_active_first==NULL) {
2861 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 }
Andy Richterb805da72008-07-18 15:24:56 +02002863 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 return;
2865}
2866
2867/*-------------------------------------------------------------------*
2868* claw free netdevice *
2869* *
2870*--------------------------------------------------------------------*/
2871static void
2872claw_free_netdevice(struct net_device * dev, int free_dev)
2873{
2874 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
Andy Richterb805da72008-07-18 15:24:56 +02002876 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 if (!dev)
2878 return;
Andy Richterb805da72008-07-18 15:24:56 +02002879 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002880 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 if (dev->flags & IFF_RUNNING)
2882 claw_release(dev);
2883 if (privptr) {
Heiko Carstens319cb082010-08-12 01:58:27 +00002884 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002886 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887#ifdef MODULE
2888 if (free_dev) {
2889 free_netdev(dev);
2890 }
2891#endif
Andy Richterb805da72008-07-18 15:24:56 +02002892 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893}
2894
2895/**
2896 * Claw init netdevice
2897 * Initialize everything of the net device except the name and the
2898 * channel structs.
2899 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002900static const struct net_device_ops claw_netdev_ops = {
2901 .ndo_open = claw_open,
2902 .ndo_stop = claw_release,
2903 .ndo_get_stats = claw_stats,
2904 .ndo_start_xmit = claw_tx,
2905 .ndo_change_mtu = claw_change_mtu,
2906};
2907
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908static void
2909claw_init_netdevice(struct net_device * dev)
2910{
Andy Richterb805da72008-07-18 15:24:56 +02002911 CLAW_DBF_TEXT(2, setup, "init_dev");
2912 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 dev->hard_header_len = 0;
2915 dev->addr_len = 0;
2916 dev->type = ARPHRD_SLIP;
2917 dev->tx_queue_len = 1300;
2918 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002919 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002920 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 return;
2922}
2923
2924/**
2925 * Init a new channel in the privptr->channel[i].
2926 *
2927 * @param cdev The ccw_device to be added.
2928 *
2929 * @return 0 on success, !0 on error.
2930 */
2931static int
2932add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2933{
2934 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002935 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
Kay Sievers2a0217d2008-10-10 21:33:09 +02002937 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2939 p_ch = &privptr->channel[i];
2940 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002941 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002942 ccw_device_get_id(cdev, &dev_id);
2943 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002944 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 return -ENOMEM;
2946 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 return 0;
2948}
2949
2950
2951/**
2952 *
2953 * Setup an interface.
2954 *
2955 * @param cgdev Device to be setup.
2956 *
2957 * @returns 0 on success, !0 on failure.
2958 */
2959static int
2960claw_new_device(struct ccwgroup_device *cgdev)
2961{
2962 struct claw_privbk *privptr;
2963 struct claw_env *p_env;
2964 struct net_device *dev;
2965 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002966 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Andy Richter4811fcb2009-01-20 06:14:33 +00002968 dev_info(&cgdev->dev, "add for %s\n",
Heiko Carstens319cb082010-08-12 01:58:27 +00002969 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002970 CLAW_DBF_TEXT(2, setup, "new_dev");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002971 privptr = dev_get_drvdata(&cgdev->dev);
Heiko Carstens319cb082010-08-12 01:58:27 +00002972 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2973 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 if (!privptr)
2975 return -ENODEV;
2976 p_env = privptr->p_env;
Heiko Carstens319cb082010-08-12 01:58:27 +00002977 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2978 p_env->devno[READ_CHANNEL] = dev_id.devno;
2979 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2980 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 ret = add_channel(cgdev->cdev[0],0,privptr);
2982 if (ret == 0)
2983 ret = add_channel(cgdev->cdev[1],1,privptr);
2984 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002985 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2986 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002987 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002989 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002991 dev_warn(&cgdev->dev,
2992 "Setting the read subchannel online"
2993 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 goto out;
2995 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002996 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002998 dev_warn(&cgdev->dev,
2999 "Setting the write subchannel online "
3000 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 goto out;
3002 }
3003 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
3004 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003005 dev_warn(&cgdev->dev,
3006 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 goto out;
3008 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02003009 dev->ml_priv = privptr;
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003010 dev_set_drvdata(&cgdev->dev, privptr);
Heiko Carstens319cb082010-08-12 01:58:27 +00003011 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
3012 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 /* sysfs magic */
3014 SET_NETDEV_DEV(dev, &cgdev->dev);
3015 if (register_netdev(dev) != 0) {
3016 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02003017 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 goto out;
3019 }
3020 dev->flags &=~IFF_RUNNING;
3021 if (privptr->buffs_alloc == 0) {
3022 ret=init_ccw_bk(dev);
3023 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 unregister_netdev(dev);
3025 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02003026 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 goto out;
3028 }
3029 }
Heiko Carstens319cb082010-08-12 01:58:27 +00003030 privptr->channel[READ_CHANNEL].ndev = dev;
3031 privptr->channel[WRITE_CHANNEL].ndev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 privptr->p_env->ndev = dev;
3033
Andy Richter4811fcb2009-01-20 06:14:33 +00003034 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3036 dev->name, p_env->read_size,
3037 p_env->write_size, p_env->read_buffers,
Heiko Carstens319cb082010-08-12 01:58:27 +00003038 p_env->write_buffers, p_env->devno[READ_CHANNEL],
3039 p_env->devno[WRITE_CHANNEL]);
Andy Richter4811fcb2009-01-20 06:14:33 +00003040 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 ":%.8s api_type: %.8s\n",
3042 dev->name, p_env->host_name,
3043 p_env->adapter_name , p_env->api_type);
3044 return 0;
3045out:
3046 ccw_device_set_offline(cgdev->cdev[1]);
3047 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 return -ENODEV;
3049}
3050
3051static void
3052claw_purge_skb_queue(struct sk_buff_head *q)
3053{
3054 struct sk_buff *skb;
3055
Andy Richterb805da72008-07-18 15:24:56 +02003056 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 while ((skb = skb_dequeue(q))) {
3058 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02003059 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 }
3061}
3062
3063/**
3064 * Shutdown an interface.
3065 *
3066 * @param cgdev Device to be shut down.
3067 *
3068 * @returns 0 on success, !0 on failure.
3069 */
3070static int
3071claw_shutdown_device(struct ccwgroup_device *cgdev)
3072{
3073 struct claw_privbk *priv;
3074 struct net_device *ndev;
3075 int ret;
3076
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003077 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003078 priv = dev_get_drvdata(&cgdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 if (!priv)
3080 return -ENODEV;
Heiko Carstens319cb082010-08-12 01:58:27 +00003081 ndev = priv->channel[READ_CHANNEL].ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 if (ndev) {
3083 /* Close the device */
Heiko Carstens319cb082010-08-12 01:58:27 +00003084 dev_info(&cgdev->dev, "%s: shutting down\n",
Andy Richter4811fcb2009-01-20 06:14:33 +00003085 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 if (ndev->flags & IFF_RUNNING)
3087 ret = claw_release(ndev);
3088 ndev->flags &=~IFF_RUNNING;
3089 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003090 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 claw_free_netdevice(ndev, 1);
Heiko Carstens319cb082010-08-12 01:58:27 +00003092 priv->channel[READ_CHANNEL].ndev = NULL;
3093 priv->channel[WRITE_CHANNEL].ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 priv->p_env->ndev = NULL;
3095 }
3096 ccw_device_set_offline(cgdev->cdev[1]);
3097 ccw_device_set_offline(cgdev->cdev[0]);
3098 return 0;
3099}
3100
3101static void
3102claw_remove_device(struct ccwgroup_device *cgdev)
3103{
3104 struct claw_privbk *priv;
3105
Andy Richterb805da72008-07-18 15:24:56 +02003106 BUG_ON(!cgdev);
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003107 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003108 priv = dev_get_drvdata(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003109 BUG_ON(!priv);
Andy Richter4811fcb2009-01-20 06:14:33 +00003110 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 if (cgdev->state == CCWGROUP_ONLINE)
3112 claw_shutdown_device(cgdev);
3113 claw_remove_files(&cgdev->dev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003114 kfree(priv->p_mtc_envelope);
3115 priv->p_mtc_envelope=NULL;
3116 kfree(priv->p_env);
3117 priv->p_env=NULL;
3118 kfree(priv->channel[0].irb);
3119 priv->channel[0].irb=NULL;
3120 kfree(priv->channel[1].irb);
3121 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 kfree(priv);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003123 dev_set_drvdata(&cgdev->dev, NULL);
Heiko Carstens319cb082010-08-12 01:58:27 +00003124 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3125 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003127
3128 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129}
3130
3131
3132/*
3133 * sysfs attributes
3134 */
3135static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003136claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137{
3138 struct claw_privbk *priv;
3139 struct claw_env * p_env;
3140
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003141 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 if (!priv)
3143 return -ENODEV;
3144 p_env = priv->p_env;
3145 return sprintf(buf, "%s\n",p_env->host_name);
3146}
3147
3148static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003149claw_hname_write(struct device *dev, struct device_attribute *attr,
3150 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151{
3152 struct claw_privbk *priv;
3153 struct claw_env * p_env;
3154
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003155 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 if (!priv)
3157 return -ENODEV;
3158 p_env = priv->p_env;
3159 if (count > MAX_NAME_LEN+1)
3160 return -EINVAL;
3161 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3162 strncpy(p_env->host_name,buf, count);
3163 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3164 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003165 CLAW_DBF_TEXT(2, setup, "HstnSet");
3166 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
3168 return count;
3169}
3170
3171static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3172
3173static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003174claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175{
3176 struct claw_privbk *priv;
3177 struct claw_env * p_env;
3178
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003179 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 if (!priv)
3181 return -ENODEV;
3182 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003183 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184}
3185
3186static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003187claw_adname_write(struct device *dev, struct device_attribute *attr,
3188 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189{
3190 struct claw_privbk *priv;
3191 struct claw_env * p_env;
3192
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003193 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 if (!priv)
3195 return -ENODEV;
3196 p_env = priv->p_env;
3197 if (count > MAX_NAME_LEN+1)
3198 return -EINVAL;
3199 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3200 strncpy(p_env->adapter_name,buf, count);
3201 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3202 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003203 CLAW_DBF_TEXT(2, setup, "AdnSet");
3204 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205
3206 return count;
3207}
3208
3209static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3210
3211static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003212claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213{
3214 struct claw_privbk *priv;
3215 struct claw_env * p_env;
3216
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003217 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 if (!priv)
3219 return -ENODEV;
3220 p_env = priv->p_env;
3221 return sprintf(buf, "%s\n",
3222 p_env->api_type);
3223}
3224
3225static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003226claw_apname_write(struct device *dev, struct device_attribute *attr,
3227 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228{
3229 struct claw_privbk *priv;
3230 struct claw_env * p_env;
3231
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003232 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 if (!priv)
3234 return -ENODEV;
3235 p_env = priv->p_env;
3236 if (count > MAX_NAME_LEN+1)
3237 return -EINVAL;
3238 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3239 strncpy(p_env->api_type,buf, count);
3240 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3241 p_env->api_type[MAX_NAME_LEN] = 0x00;
3242 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3243 p_env->read_size=DEF_PACK_BUFSIZE;
3244 p_env->write_size=DEF_PACK_BUFSIZE;
3245 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003246 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 }
3248 else {
3249 p_env->packing=0;
3250 p_env->read_size=CLAW_FRAME_SIZE;
3251 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003252 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 }
Andy Richterb805da72008-07-18 15:24:56 +02003254 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 return count;
3256}
3257
3258static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3259
3260static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003261claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262{
3263 struct claw_privbk *priv;
3264 struct claw_env * p_env;
3265
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003266 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 if (!priv)
3268 return -ENODEV;
3269 p_env = priv->p_env;
3270 return sprintf(buf, "%d\n", p_env->write_buffers);
3271}
3272
3273static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003274claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3275 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276{
3277 struct claw_privbk *priv;
3278 struct claw_env * p_env;
3279 int nnn,max;
3280
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003281 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 if (!priv)
3283 return -ENODEV;
3284 p_env = priv->p_env;
3285 sscanf(buf, "%i", &nnn);
3286 if (p_env->packing) {
3287 max = 64;
3288 }
3289 else {
3290 max = 512;
3291 }
3292 if ((nnn > max ) || (nnn < 2))
3293 return -EINVAL;
3294 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003295 CLAW_DBF_TEXT(2, setup, "Wbufset");
3296 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 return count;
3298}
3299
3300static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3301
3302static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003303claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304{
3305 struct claw_privbk *priv;
3306 struct claw_env * p_env;
3307
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003308 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 if (!priv)
3310 return -ENODEV;
3311 p_env = priv->p_env;
3312 return sprintf(buf, "%d\n", p_env->read_buffers);
3313}
3314
3315static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003316claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3317 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318{
3319 struct claw_privbk *priv;
3320 struct claw_env *p_env;
3321 int nnn,max;
3322
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003323 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 if (!priv)
3325 return -ENODEV;
3326 p_env = priv->p_env;
3327 sscanf(buf, "%i", &nnn);
3328 if (p_env->packing) {
3329 max = 64;
3330 }
3331 else {
3332 max = 512;
3333 }
3334 if ((nnn > max ) || (nnn < 2))
3335 return -EINVAL;
3336 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003337 CLAW_DBF_TEXT(2, setup, "Rbufset");
3338 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 return count;
3340}
3341
3342static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3343
3344static struct attribute *claw_attr[] = {
3345 &dev_attr_read_buffer.attr,
3346 &dev_attr_write_buffer.attr,
3347 &dev_attr_adapter_name.attr,
3348 &dev_attr_api_type.attr,
3349 &dev_attr_host_name.attr,
3350 NULL,
3351};
3352
3353static struct attribute_group claw_attr_group = {
3354 .attrs = claw_attr,
3355};
3356
3357static int
3358claw_add_files(struct device *dev)
3359{
Andy Richterb805da72008-07-18 15:24:56 +02003360 CLAW_DBF_TEXT(2, setup, "add_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3362}
3363
3364static void
3365claw_remove_files(struct device *dev)
3366{
Andy Richterb805da72008-07-18 15:24:56 +02003367 CLAW_DBF_TEXT(2, setup, "rem_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3369}
3370
3371/*--------------------------------------------------------------------*
3372* claw_init and cleanup *
3373*---------------------------------------------------------------------*/
3374
3375static void __exit
3376claw_cleanup(void)
3377{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003378 driver_remove_file(&claw_group_driver.driver,
3379 &driver_attr_group);
3380 ccwgroup_driver_unregister(&claw_group_driver);
3381 ccw_driver_unregister(&claw_ccw_driver);
3382 root_device_unregister(claw_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003384 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385
3386}
3387
3388/**
3389 * Initialize module.
3390 * This is called just after the module is loaded.
3391 *
3392 * @return 0 on success, !0 on error.
3393 */
3394static int __init
3395claw_init(void)
3396{
3397 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398
Andy Richter4811fcb2009-01-20 06:14:33 +00003399 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 ret = claw_register_debug_facility();
3401 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003402 pr_err("Registering with the S/390 debug feature"
3403 " failed with error code %d\n", ret);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003404 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 }
Andy Richterb805da72008-07-18 15:24:56 +02003406 CLAW_DBF_TEXT(2, setup, "init_mod");
Ursula Braund950d172010-01-04 03:14:45 +00003407 claw_root_dev = root_device_register("claw");
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003408 ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0;
3409 if (ret)
3410 goto register_err;
3411 ret = ccw_driver_register(&claw_ccw_driver);
3412 if (ret)
3413 goto ccw_err;
3414 claw_group_driver.driver.groups = claw_group_attr_groups;
3415 ret = ccwgroup_driver_register(&claw_group_driver);
3416 if (ret)
3417 goto ccwgroup_err;
3418 return 0;
3419
3420ccwgroup_err:
3421 ccw_driver_unregister(&claw_ccw_driver);
3422ccw_err:
3423 root_device_unregister(claw_root_dev);
3424register_err:
3425 CLAW_DBF_TEXT(2, setup, "init_bad");
3426 claw_unregister_debug_facility();
3427out_err:
3428 pr_err("Initializing the claw device driver failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 return ret;
3430}
3431
3432module_init(claw_init);
3433module_exit(claw_cleanup);
3434
Andy Richterb805da72008-07-18 15:24:56 +02003435MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3436MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3437 "Copyright 2000,2008 IBM Corporation\n");
3438MODULE_LICENSE("GPL");