| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *  drivers/s390/net/claw.c | 
|  | 3 | *    ESCON CLAW network driver | 
|  | 4 | * | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 5 | *  Linux for zSeries version | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | *    Copyright (C) 2002,2005 IBM Corporation | 
|  | 7 | *  Author(s) Original code written by: | 
|  | 8 | *              Kazuo Iimura (iimura@jp.ibm.com) | 
|  | 9 | *   	      Rewritten by | 
|  | 10 | *              Andy Richter (richtera@us.ibm.com) | 
|  | 11 | *              Marc Price (mwprice@us.ibm.com) | 
|  | 12 | * | 
|  | 13 | *    sysfs parms: | 
|  | 14 | *   group x.x.rrrr,x.x.wwww | 
|  | 15 | *   read_buffer nnnnnnn | 
|  | 16 | *   write_buffer nnnnnn | 
|  | 17 | *   host_name  aaaaaaaa | 
|  | 18 | *   adapter_name aaaaaaaa | 
|  | 19 | *   api_type    aaaaaaaa | 
|  | 20 | * | 
|  | 21 | *  eg. | 
|  | 22 | *   group  0.0.0200 0.0.0201 | 
|  | 23 | *   read_buffer 25 | 
|  | 24 | *   write_buffer 20 | 
|  | 25 | *   host_name LINUX390 | 
|  | 26 | *   adapter_name RS6K | 
|  | 27 | *   api_type     TCPIP | 
|  | 28 | * | 
|  | 29 | *  where | 
|  | 30 | * | 
|  | 31 | *   The device id is decided by the order entries | 
|  | 32 | *   are added to the group the first is claw0 the second claw1 | 
|  | 33 | *   up to CLAW_MAX_DEV | 
|  | 34 | * | 
|  | 35 | *   rrrr     -	the first of 2 consecutive device addresses used for the | 
|  | 36 | *		CLAW protocol. | 
|  | 37 | *		The specified address is always used as the input (Read) | 
|  | 38 | *		channel and the next address is used as the output channel. | 
|  | 39 | * | 
|  | 40 | *   wwww     -	the second of 2 consecutive device addresses used for | 
|  | 41 | *		the CLAW protocol. | 
|  | 42 | *              The specified address is always used as the output | 
|  | 43 | *		channel and the previous address is used as the input channel. | 
|  | 44 | * | 
|  | 45 | *   read_buffer	-       specifies number of input buffers to allocate. | 
|  | 46 | *   write_buffer       -       specifies number of output buffers to allocate. | 
|  | 47 | *   host_name          -       host name | 
|  | 48 | *   adaptor_name       -       adaptor name | 
|  | 49 | *   api_type           -       API type TCPIP or API will be sent and expected | 
|  | 50 | *				as ws_name | 
|  | 51 | * | 
|  | 52 | *   Note the following requirements: | 
|  | 53 | *   1)  host_name must match the configured adapter_name on the remote side | 
|  | 54 | *   2)  adaptor_name must match the configured host name on the remote side | 
|  | 55 | * | 
|  | 56 | *  Change History | 
|  | 57 | *    1.00  Initial release shipped | 
|  | 58 | *    1.10  Changes for Buffer allocation | 
|  | 59 | *    1.15  Changed for 2.6 Kernel  No longer compiles on 2.4 or lower | 
|  | 60 | *    1.25  Added Packing support | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 61 | *    1.5 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | */ | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 63 |  | 
|  | 64 | #define KMSG_COMPONENT "claw" | 
|  | 65 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #include <asm/ccwdev.h> | 
|  | 67 | #include <asm/ccwgroup.h> | 
|  | 68 | #include <asm/debug.h> | 
|  | 69 | #include <asm/idals.h> | 
|  | 70 | #include <asm/io.h> | 
| Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 71 | #include <linux/bitops.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include <linux/ctype.h> | 
|  | 73 | #include <linux/delay.h> | 
|  | 74 | #include <linux/errno.h> | 
|  | 75 | #include <linux/if_arp.h> | 
|  | 76 | #include <linux/init.h> | 
|  | 77 | #include <linux/interrupt.h> | 
|  | 78 | #include <linux/ip.h> | 
|  | 79 | #include <linux/kernel.h> | 
|  | 80 | #include <linux/module.h> | 
|  | 81 | #include <linux/netdevice.h> | 
|  | 82 | #include <linux/etherdevice.h> | 
|  | 83 | #include <linux/proc_fs.h> | 
|  | 84 | #include <linux/sched.h> | 
|  | 85 | #include <linux/signal.h> | 
|  | 86 | #include <linux/skbuff.h> | 
|  | 87 | #include <linux/slab.h> | 
|  | 88 | #include <linux/string.h> | 
|  | 89 | #include <linux/tcp.h> | 
|  | 90 | #include <linux/timer.h> | 
|  | 91 | #include <linux/types.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | #include "cu3088.h" | 
|  | 94 | #include "claw.h" | 
|  | 95 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 96 | /* | 
|  | 97 | CLAW uses the s390dbf file system  see claw_trace and claw_setup | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | */ | 
|  | 99 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 100 | static char version[] __initdata = "CLAW driver"; | 
| Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 101 | static char debug_buffer[255]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | /** | 
|  | 103 | * Debug Facility Stuff | 
|  | 104 | */ | 
|  | 105 | static debug_info_t *claw_dbf_setup; | 
|  | 106 | static debug_info_t *claw_dbf_trace; | 
|  | 107 |  | 
|  | 108 | /** | 
|  | 109 | *  CLAW Debug Facility functions | 
|  | 110 | */ | 
|  | 111 | static void | 
|  | 112 | claw_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 |  | 
|  | 120 | static int | 
|  | 121 | claw_register_debug_facility(void) | 
|  | 122 | { | 
| Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 123 | claw_dbf_setup = debug_register("claw_setup", 2, 1, 8); | 
|  | 124 | claw_dbf_trace = debug_register("claw_trace", 2, 2, 8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | 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 |  | 
|  | 136 | static inline void | 
|  | 137 | claw_set_busy(struct net_device *dev) | 
|  | 138 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 139 | ((struct claw_privbk *)dev->ml_priv)->tbusy = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | eieio(); | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | static inline void | 
|  | 144 | claw_clear_busy(struct net_device *dev) | 
|  | 145 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 146 | clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | netif_wake_queue(dev); | 
|  | 148 | eieio(); | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | static inline int | 
|  | 152 | claw_check_busy(struct net_device *dev) | 
|  | 153 | { | 
|  | 154 | eieio(); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 155 | return ((struct claw_privbk *) dev->ml_priv)->tbusy; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
|  | 158 | static inline void | 
|  | 159 | claw_setbit_busy(int nr,struct net_device *dev) | 
|  | 160 | { | 
|  | 161 | netif_stop_queue(dev); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 162 | set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } | 
|  | 164 |  | 
|  | 165 | static inline void | 
|  | 166 | claw_clearbit_busy(int nr,struct net_device *dev) | 
|  | 167 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 168 | clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | netif_wake_queue(dev); | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | static inline int | 
|  | 173 | claw_test_and_setbit_busy(int nr,struct net_device *dev) | 
|  | 174 | { | 
|  | 175 | netif_stop_queue(dev); | 
|  | 176 | return test_and_set_bit(nr, | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 177 | (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } | 
|  | 179 |  | 
|  | 180 |  | 
|  | 181 | /* Functions for the DEV methods */ | 
|  | 182 |  | 
|  | 183 | static int claw_probe(struct ccwgroup_device *cgdev); | 
|  | 184 | static void claw_remove_device(struct ccwgroup_device *cgdev); | 
|  | 185 | static void claw_purge_skb_queue(struct sk_buff_head *q); | 
|  | 186 | static int claw_new_device(struct ccwgroup_device *cgdev); | 
|  | 187 | static int claw_shutdown_device(struct ccwgroup_device *cgdev); | 
|  | 188 | static int claw_tx(struct sk_buff *skb, struct net_device *dev); | 
|  | 189 | static int claw_change_mtu( struct net_device *dev, int new_mtu); | 
|  | 190 | static int claw_open(struct net_device *dev); | 
|  | 191 | static void claw_irq_handler(struct ccw_device *cdev, | 
|  | 192 | unsigned long intparm, struct irb *irb); | 
|  | 193 | static void claw_irq_tasklet ( unsigned long data ); | 
|  | 194 | static int claw_release(struct net_device *dev); | 
|  | 195 | static void claw_write_retry ( struct chbk * p_ch ); | 
|  | 196 | static void claw_write_next ( struct chbk * p_ch ); | 
|  | 197 | static void claw_timer ( struct chbk * p_ch ); | 
|  | 198 |  | 
|  | 199 | /* Functions */ | 
|  | 200 | static int add_claw_reads(struct net_device *dev, | 
|  | 201 | struct ccwbk* p_first, struct ccwbk* p_last); | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 202 | static void ccw_check_return_code (struct ccw_device *cdev, int return_code); | 
|  | 203 | static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | static int find_link(struct net_device *dev, char *host_name, char *ws_name ); | 
|  | 205 | static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid); | 
|  | 206 | static int init_ccw_bk(struct net_device *dev); | 
|  | 207 | static void probe_error( struct ccwgroup_device *cgdev); | 
|  | 208 | static struct net_device_stats *claw_stats(struct net_device *dev); | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 209 | static int pages_to_order_of_mag(int num_of_pages); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* sysfs Functions */ | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 212 | static ssize_t claw_hname_show(struct device *dev, | 
|  | 213 | struct device_attribute *attr, char *buf); | 
|  | 214 | static ssize_t claw_hname_write(struct device *dev, | 
|  | 215 | struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | const char *buf, size_t count); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 217 | static ssize_t claw_adname_show(struct device *dev, | 
|  | 218 | struct device_attribute *attr, char *buf); | 
|  | 219 | static ssize_t claw_adname_write(struct device *dev, | 
|  | 220 | struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | const char *buf, size_t count); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 222 | static ssize_t claw_apname_show(struct device *dev, | 
|  | 223 | struct device_attribute *attr, char *buf); | 
|  | 224 | static ssize_t claw_apname_write(struct device *dev, | 
|  | 225 | struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | const char *buf, size_t count); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 227 | static ssize_t claw_wbuff_show(struct device *dev, | 
|  | 228 | struct device_attribute *attr, char *buf); | 
|  | 229 | static ssize_t claw_wbuff_write(struct device *dev, | 
|  | 230 | struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | const char *buf, size_t count); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 232 | static ssize_t claw_rbuff_show(struct device *dev, | 
|  | 233 | struct device_attribute *attr, char *buf); | 
|  | 234 | static ssize_t claw_rbuff_write(struct device *dev, | 
|  | 235 | struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | const char *buf, size_t count); | 
|  | 237 | static int claw_add_files(struct device *dev); | 
|  | 238 | static void claw_remove_files(struct device *dev); | 
|  | 239 |  | 
|  | 240 | /*   Functions for System Validate  */ | 
|  | 241 | static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw); | 
|  | 242 | static int claw_send_control(struct net_device *dev, __u8 type, __u8 link, | 
|  | 243 | __u8 correlator, __u8 rc , char *local_name, char *remote_name); | 
|  | 244 | static int claw_snd_conn_req(struct net_device *dev, __u8 link); | 
|  | 245 | static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl); | 
|  | 246 | static int claw_snd_sys_validate_rsp(struct net_device *dev, | 
|  | 247 | struct clawctl * p_ctl, __u32 return_code); | 
|  | 248 | static int claw_strt_conn_req(struct net_device *dev ); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 249 | static void claw_strt_read(struct net_device *dev, int lock); | 
|  | 250 | static void claw_strt_out_IO(struct net_device *dev); | 
|  | 251 | static void claw_free_wrt_buf(struct net_device *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 |  | 
|  | 253 | /* Functions for unpack reads   */ | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 254 | static void unpack_read(struct net_device *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 |  | 
|  | 256 | /* ccwgroup table  */ | 
|  | 257 |  | 
|  | 258 | static struct ccwgroup_driver claw_group_driver = { | 
|  | 259 | .owner       = THIS_MODULE, | 
|  | 260 | .name        = "claw", | 
|  | 261 | .max_slaves  = 2, | 
|  | 262 | .driver_id   = 0xC3D3C1E6, | 
|  | 263 | .probe       = claw_probe, | 
|  | 264 | .remove      = claw_remove_device, | 
|  | 265 | .set_online  = claw_new_device, | 
|  | 266 | .set_offline = claw_shutdown_device, | 
|  | 267 | }; | 
|  | 268 |  | 
|  | 269 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | *       Key functions | 
|  | 271 | */ | 
|  | 272 |  | 
|  | 273 | /*----------------------------------------------------------------* | 
|  | 274 | *   claw_probe                                                   * | 
|  | 275 | *      this function is called for each CLAW device.             * | 
|  | 276 | *----------------------------------------------------------------*/ | 
|  | 277 | static int | 
|  | 278 | claw_probe(struct ccwgroup_device *cgdev) | 
|  | 279 | { | 
|  | 280 | int  		rc; | 
|  | 281 | struct claw_privbk *privptr=NULL; | 
|  | 282 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 283 | CLAW_DBF_TEXT(2, setup, "probe"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | if (!get_device(&cgdev->dev)) | 
|  | 285 | return -ENODEV; | 
| Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 286 | privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL); | 
| Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 287 | cgdev->dev.driver_data = privptr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (privptr == NULL) { | 
|  | 289 | probe_error(cgdev); | 
|  | 290 | put_device(&cgdev->dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 291 | CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | return -ENOMEM; | 
|  | 293 | } | 
| Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 294 | privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL); | 
|  | 295 | privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) { | 
|  | 297 | probe_error(cgdev); | 
|  | 298 | put_device(&cgdev->dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 299 | CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | return -ENOMEM; | 
|  | 301 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8); | 
|  | 303 | memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8); | 
|  | 304 | memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8); | 
|  | 305 | privptr->p_env->packing = 0; | 
|  | 306 | privptr->p_env->write_buffers = 5; | 
|  | 307 | privptr->p_env->read_buffers = 5; | 
|  | 308 | privptr->p_env->read_size = CLAW_FRAME_SIZE; | 
|  | 309 | privptr->p_env->write_size = CLAW_FRAME_SIZE; | 
|  | 310 | rc = claw_add_files(&cgdev->dev); | 
|  | 311 | if (rc) { | 
|  | 312 | probe_error(cgdev); | 
|  | 313 | put_device(&cgdev->dev); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 314 | dev_err(&cgdev->dev, "Creating the /proc files for a new" | 
|  | 315 | " CLAW device failed\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 316 | CLAW_DBF_TEXT_(2, setup, "probex%d", rc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return rc; | 
|  | 318 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | privptr->p_env->p_priv = privptr; | 
|  | 320 | cgdev->cdev[0]->handler = claw_irq_handler; | 
|  | 321 | cgdev->cdev[1]->handler = claw_irq_handler; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 322 | CLAW_DBF_TEXT(2, setup, "prbext 0"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 |  | 
|  | 324 | return 0; | 
|  | 325 | }  /*  end of claw_probe       */ | 
|  | 326 |  | 
|  | 327 | /*-------------------------------------------------------------------* | 
|  | 328 | *   claw_tx                                                         * | 
|  | 329 | *-------------------------------------------------------------------*/ | 
|  | 330 |  | 
|  | 331 | static int | 
|  | 332 | claw_tx(struct sk_buff *skb, struct net_device *dev) | 
|  | 333 | { | 
|  | 334 | int             rc; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 335 | struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | unsigned long saveflags; | 
|  | 337 | struct chbk *p_ch; | 
|  | 338 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 339 | CLAW_DBF_TEXT(4, trace, "claw_tx"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | p_ch=&privptr->channel[WRITE]; | 
|  | 341 | if (skb == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | privptr->stats.tx_dropped++; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 343 | privptr->stats.tx_errors++; | 
|  | 344 | CLAW_DBF_TEXT_(2, trace, "clawtx%d", -EIO); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return -EIO; | 
|  | 346 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags); | 
|  | 348 | rc=claw_hw_tx( skb, dev, 1 ); | 
|  | 349 | spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 350 | CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | return rc; | 
|  | 352 | }   /*  end of claw_tx */ | 
|  | 353 |  | 
|  | 354 | /*------------------------------------------------------------------* | 
|  | 355 | *  pack the collect queue into an skb and return it                * | 
|  | 356 | *   If not packing just return the top skb from the queue          * | 
|  | 357 | *------------------------------------------------------------------*/ | 
|  | 358 |  | 
|  | 359 | static struct sk_buff * | 
|  | 360 | claw_pack_skb(struct claw_privbk *privptr) | 
|  | 361 | { | 
|  | 362 | struct sk_buff *new_skb,*held_skb; | 
|  | 363 | struct chbk *p_ch = &privptr->channel[WRITE]; | 
|  | 364 | struct claw_env  *p_env = privptr->p_env; | 
|  | 365 | int	pkt_cnt,pk_ind,so_far; | 
|  | 366 |  | 
|  | 367 | new_skb = NULL;		/* assume no dice */ | 
|  | 368 | pkt_cnt = 0; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 369 | CLAW_DBF_TEXT(4, trace, "PackSKBe"); | 
| David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 370 | if (!skb_queue_empty(&p_ch->collect_queue)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | /* some data */ | 
|  | 372 | held_skb = skb_dequeue(&p_ch->collect_queue); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | if (held_skb) | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 374 | dev_kfree_skb_any(held_skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | else | 
|  | 376 | return NULL; | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 377 | if (p_env->packing != DO_PACKED) | 
|  | 378 | return held_skb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | /* get a new SKB we will pack at least one */ | 
|  | 380 | new_skb = dev_alloc_skb(p_env->write_size); | 
|  | 381 | if (new_skb == NULL) { | 
|  | 382 | atomic_inc(&held_skb->users); | 
|  | 383 | skb_queue_head(&p_ch->collect_queue,held_skb); | 
|  | 384 | return NULL; | 
|  | 385 | } | 
|  | 386 | /* we have packed packet and a place to put it  */ | 
|  | 387 | pk_ind = 1; | 
|  | 388 | so_far = 0; | 
|  | 389 | new_skb->cb[1] = 'P'; /* every skb on queue has pack header */ | 
|  | 390 | while ((pk_ind) && (held_skb != NULL)) { | 
|  | 391 | if (held_skb->len+so_far <= p_env->write_size-8) { | 
|  | 392 | memcpy(skb_put(new_skb,held_skb->len), | 
|  | 393 | held_skb->data,held_skb->len); | 
|  | 394 | privptr->stats.tx_packets++; | 
|  | 395 | so_far += held_skb->len; | 
|  | 396 | pkt_cnt++; | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 397 | dev_kfree_skb_any(held_skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | held_skb = skb_dequeue(&p_ch->collect_queue); | 
|  | 399 | if (held_skb) | 
|  | 400 | atomic_dec(&held_skb->users); | 
|  | 401 | } else { | 
|  | 402 | pk_ind = 0; | 
|  | 403 | atomic_inc(&held_skb->users); | 
|  | 404 | skb_queue_head(&p_ch->collect_queue,held_skb); | 
|  | 405 | } | 
|  | 406 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 408 | CLAW_DBF_TEXT(4, trace, "PackSKBx"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | return new_skb; | 
|  | 410 | } | 
|  | 411 |  | 
|  | 412 | /*-------------------------------------------------------------------* | 
|  | 413 | *   claw_change_mtu                                                 * | 
|  | 414 | *                                                                   * | 
|  | 415 | *-------------------------------------------------------------------*/ | 
|  | 416 |  | 
|  | 417 | static int | 
|  | 418 | claw_change_mtu(struct net_device *dev, int new_mtu) | 
|  | 419 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 420 | struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | int buff_size; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 422 | CLAW_DBF_TEXT(4, trace, "setmtu"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | buff_size = privptr->p_env->write_size; | 
|  | 424 | if ((new_mtu < 60) || (new_mtu > buff_size)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return -EINVAL; | 
|  | 426 | } | 
|  | 427 | dev->mtu = new_mtu; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return 0; | 
|  | 429 | }  /*   end of claw_change_mtu */ | 
|  | 430 |  | 
|  | 431 |  | 
|  | 432 | /*-------------------------------------------------------------------* | 
|  | 433 | *   claw_open                                                       * | 
|  | 434 | *                                                                   * | 
|  | 435 | *-------------------------------------------------------------------*/ | 
|  | 436 | static int | 
|  | 437 | claw_open(struct net_device *dev) | 
|  | 438 | { | 
|  | 439 |  | 
|  | 440 | int     rc; | 
|  | 441 | int     i; | 
|  | 442 | unsigned long       saveflags=0; | 
|  | 443 | unsigned long       parm; | 
|  | 444 | struct claw_privbk  *privptr; | 
|  | 445 | DECLARE_WAITQUEUE(wait, current); | 
|  | 446 | struct timer_list  timer; | 
|  | 447 | struct ccwbk *p_buf; | 
|  | 448 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 449 | CLAW_DBF_TEXT(4, trace, "open"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 450 | privptr = (struct claw_privbk *)dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | /*   allocate and initialize CCW blocks */ | 
|  | 452 | if (privptr->buffs_alloc == 0) { | 
|  | 453 | rc=init_ccw_bk(dev); | 
|  | 454 | if (rc) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 455 | CLAW_DBF_TEXT(2, trace, "openmem"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return -ENOMEM; | 
|  | 457 | } | 
|  | 458 | } | 
|  | 459 | privptr->system_validate_comp=0; | 
|  | 460 | privptr->release_pend=0; | 
|  | 461 | if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) { | 
|  | 462 | privptr->p_env->read_size=DEF_PACK_BUFSIZE; | 
|  | 463 | privptr->p_env->write_size=DEF_PACK_BUFSIZE; | 
|  | 464 | privptr->p_env->packing=PACKING_ASK; | 
|  | 465 | } else { | 
|  | 466 | privptr->p_env->packing=0; | 
|  | 467 | privptr->p_env->read_size=CLAW_FRAME_SIZE; | 
|  | 468 | privptr->p_env->write_size=CLAW_FRAME_SIZE; | 
|  | 469 | } | 
|  | 470 | claw_set_busy(dev); | 
|  | 471 | tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet, | 
|  | 472 | (unsigned long) &privptr->channel[READ]); | 
|  | 473 | for ( i = 0; i < 2;  i++) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 474 | CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | init_waitqueue_head(&privptr->channel[i].wait); | 
|  | 476 | /* skb_queue_head_init(&p_ch->io_queue); */ | 
|  | 477 | if (i == WRITE) | 
|  | 478 | skb_queue_head_init( | 
|  | 479 | &privptr->channel[WRITE].collect_queue); | 
|  | 480 | privptr->channel[i].flag_a = 0; | 
|  | 481 | privptr->channel[i].IO_active = 0; | 
|  | 482 | privptr->channel[i].flag  &= ~CLAW_TIMER; | 
|  | 483 | init_timer(&timer); | 
|  | 484 | timer.function = (void *)claw_timer; | 
|  | 485 | timer.data = (unsigned long)(&privptr->channel[i]); | 
|  | 486 | timer.expires = jiffies + 15*HZ; | 
|  | 487 | add_timer(&timer); | 
|  | 488 | spin_lock_irqsave(get_ccwdev_lock( | 
|  | 489 | privptr->channel[i].cdev), saveflags); | 
|  | 490 | parm = (unsigned long) &privptr->channel[i]; | 
|  | 491 | privptr->channel[i].claw_state = CLAW_START_HALT_IO; | 
|  | 492 | rc = 0; | 
|  | 493 | add_wait_queue(&privptr->channel[i].wait, &wait); | 
|  | 494 | rc = ccw_device_halt( | 
|  | 495 | (struct ccw_device *)privptr->channel[i].cdev,parm); | 
|  | 496 | set_current_state(TASK_INTERRUPTIBLE); | 
|  | 497 | spin_unlock_irqrestore( | 
|  | 498 | get_ccwdev_lock(privptr->channel[i].cdev), saveflags); | 
|  | 499 | schedule(); | 
|  | 500 | set_current_state(TASK_RUNNING); | 
|  | 501 | remove_wait_queue(&privptr->channel[i].wait, &wait); | 
|  | 502 | if(rc != 0) | 
|  | 503 | ccw_check_return_code(privptr->channel[i].cdev, rc); | 
|  | 504 | if((privptr->channel[i].flag & CLAW_TIMER) == 0x00) | 
|  | 505 | del_timer(&timer); | 
|  | 506 | } | 
|  | 507 | if ((((privptr->channel[READ].last_dstat | | 
|  | 508 | privptr->channel[WRITE].last_dstat) & | 
|  | 509 | ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) || | 
|  | 510 | (((privptr->channel[READ].flag | | 
|  | 511 | privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 512 | dev_info(&privptr->channel[READ].cdev->dev, | 
|  | 513 | "%s: remote side is not ready\n", dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 514 | CLAW_DBF_TEXT(2, trace, "notrdy"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 |  | 
|  | 516 | for ( i = 0; i < 2;  i++) { | 
|  | 517 | spin_lock_irqsave( | 
|  | 518 | get_ccwdev_lock(privptr->channel[i].cdev), | 
|  | 519 | saveflags); | 
|  | 520 | parm = (unsigned long) &privptr->channel[i]; | 
|  | 521 | privptr->channel[i].claw_state = CLAW_STOP; | 
|  | 522 | rc = ccw_device_halt( | 
|  | 523 | (struct ccw_device *)&privptr->channel[i].cdev, | 
|  | 524 | parm); | 
|  | 525 | spin_unlock_irqrestore( | 
|  | 526 | get_ccwdev_lock(privptr->channel[i].cdev), | 
|  | 527 | saveflags); | 
|  | 528 | if (rc != 0) { | 
|  | 529 | ccw_check_return_code( | 
|  | 530 | privptr->channel[i].cdev, rc); | 
|  | 531 | } | 
|  | 532 | } | 
|  | 533 | free_pages((unsigned long)privptr->p_buff_ccw, | 
|  | 534 | (int)pages_to_order_of_mag(privptr->p_buff_ccw_num)); | 
|  | 535 | if (privptr->p_env->read_size < PAGE_SIZE) { | 
|  | 536 | free_pages((unsigned long)privptr->p_buff_read, | 
|  | 537 | (int)pages_to_order_of_mag( | 
|  | 538 | privptr->p_buff_read_num)); | 
|  | 539 | } | 
|  | 540 | else { | 
|  | 541 | p_buf=privptr->p_read_active_first; | 
|  | 542 | while (p_buf!=NULL) { | 
|  | 543 | free_pages((unsigned long)p_buf->p_buffer, | 
|  | 544 | (int)pages_to_order_of_mag( | 
|  | 545 | privptr->p_buff_pages_perread )); | 
|  | 546 | p_buf=p_buf->next; | 
|  | 547 | } | 
|  | 548 | } | 
|  | 549 | if (privptr->p_env->write_size < PAGE_SIZE ) { | 
|  | 550 | free_pages((unsigned long)privptr->p_buff_write, | 
|  | 551 | (int)pages_to_order_of_mag( | 
|  | 552 | privptr->p_buff_write_num)); | 
|  | 553 | } | 
|  | 554 | else { | 
|  | 555 | p_buf=privptr->p_write_active_first; | 
|  | 556 | while (p_buf!=NULL) { | 
|  | 557 | free_pages((unsigned long)p_buf->p_buffer, | 
|  | 558 | (int)pages_to_order_of_mag( | 
|  | 559 | privptr->p_buff_pages_perwrite )); | 
|  | 560 | p_buf=p_buf->next; | 
|  | 561 | } | 
|  | 562 | } | 
|  | 563 | privptr->buffs_alloc = 0; | 
|  | 564 | privptr->channel[READ].flag= 0x00; | 
|  | 565 | privptr->channel[WRITE].flag = 0x00; | 
|  | 566 | privptr->p_buff_ccw=NULL; | 
|  | 567 | privptr->p_buff_read=NULL; | 
|  | 568 | privptr->p_buff_write=NULL; | 
|  | 569 | claw_clear_busy(dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 570 | CLAW_DBF_TEXT(2, trace, "open EIO"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | return -EIO; | 
|  | 572 | } | 
|  | 573 |  | 
|  | 574 | /*   Send SystemValidate command */ | 
|  | 575 |  | 
|  | 576 | claw_clear_busy(dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 577 | CLAW_DBF_TEXT(4, trace, "openok"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | return 0; | 
|  | 579 | }    /*     end of claw_open    */ | 
|  | 580 |  | 
|  | 581 | /*-------------------------------------------------------------------* | 
|  | 582 | *                                                                    * | 
|  | 583 | *       claw_irq_handler                                             * | 
|  | 584 | *                                                                    * | 
|  | 585 | *--------------------------------------------------------------------*/ | 
|  | 586 | static void | 
|  | 587 | claw_irq_handler(struct ccw_device *cdev, | 
|  | 588 | unsigned long intparm, struct irb *irb) | 
|  | 589 | { | 
|  | 590 | struct chbk *p_ch = NULL; | 
|  | 591 | struct claw_privbk *privptr = NULL; | 
|  | 592 | struct net_device *dev = NULL; | 
|  | 593 | struct claw_env  *p_env; | 
|  | 594 | struct chbk *p_ch_r=NULL; | 
|  | 595 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 596 | CLAW_DBF_TEXT(4, trace, "clawirq"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | /* Bypass all 'unsolicited interrupts' */ | 
|  | 598 | if (!cdev->dev.driver_data) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 599 | dev_warn(&cdev->dev, "An uninitialized CLAW device received an" | 
|  | 600 | " IRQ, c-%02x d-%02x\n", | 
|  | 601 | irb->scsw.cmd.cstat, irb->scsw.cmd.dstat); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 602 | CLAW_DBF_TEXT(2, trace, "badirq"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | return; | 
|  | 604 | } | 
|  | 605 | privptr = (struct claw_privbk *)cdev->dev.driver_data; | 
|  | 606 |  | 
|  | 607 | /* Try to extract channel from driver data. */ | 
|  | 608 | if (privptr->channel[READ].cdev == cdev) | 
|  | 609 | p_ch = &privptr->channel[READ]; | 
|  | 610 | else if (privptr->channel[WRITE].cdev == cdev) | 
|  | 611 | p_ch = &privptr->channel[WRITE]; | 
|  | 612 | else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 613 | dev_warn(&cdev->dev, "The device is not a CLAW device\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 614 | CLAW_DBF_TEXT(2, trace, "badchan"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | return; | 
|  | 616 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 617 | CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 |  | 
|  | 619 | dev = (struct net_device *) (p_ch->ndev); | 
|  | 620 | p_env=privptr->p_env; | 
|  | 621 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | /* Copy interruption response block. */ | 
|  | 623 | memcpy(p_ch->irb, irb, sizeof(struct irb)); | 
|  | 624 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 625 | /* Check for good subchannel return code, otherwise info message */ | 
| Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 626 | if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 627 | dev_info(&cdev->dev, | 
|  | 628 | "%s: subchannel check for device: %04x -" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | " Sch Stat %02x  Dev Stat %02x CPA - %04x\n", | 
|  | 630 | dev->name, p_ch->devno, | 
| Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 631 | irb->scsw.cmd.cstat, irb->scsw.cmd.dstat, | 
|  | 632 | irb->scsw.cmd.cpa); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 633 | CLAW_DBF_TEXT(2, trace, "chanchk"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | /* return; */ | 
|  | 635 | } | 
|  | 636 |  | 
|  | 637 | /* Check the reason-code of a unit check */ | 
| Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 638 | if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | ccw_check_unit_check(p_ch, irb->ecw[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 |  | 
|  | 641 | /* State machine to bring the connection up, down and to restart */ | 
| Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 642 | p_ch->last_dstat = irb->scsw.cmd.dstat; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 |  | 
|  | 644 | switch (p_ch->claw_state) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 645 | case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */ | 
|  | 646 | if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || | 
|  | 647 | (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || | 
|  | 648 | (p_ch->irb->scsw.cmd.stctl == | 
|  | 649 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) | 
|  | 650 | return; | 
|  | 651 | wake_up(&p_ch->wait);   /* wake up claw_release */ | 
|  | 652 | CLAW_DBF_TEXT(4, trace, "stop"); | 
|  | 653 | return; | 
|  | 654 | case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open  */ | 
|  | 655 | if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || | 
|  | 656 | (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || | 
|  | 657 | (p_ch->irb->scsw.cmd.stctl == | 
|  | 658 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { | 
|  | 659 | CLAW_DBF_TEXT(4, trace, "haltio"); | 
|  | 660 | return; | 
|  | 661 | } | 
|  | 662 | if (p_ch->flag == CLAW_READ) { | 
|  | 663 | p_ch->claw_state = CLAW_START_READ; | 
|  | 664 | wake_up(&p_ch->wait); /* wake claw_open (READ)*/ | 
|  | 665 | } else if (p_ch->flag == CLAW_WRITE) { | 
|  | 666 | p_ch->claw_state = CLAW_START_WRITE; | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 667 | /*      send SYSTEM_VALIDATE                    */ | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 668 | claw_strt_read(dev, LOCK_NO); | 
|  | 669 | claw_send_control(dev, | 
|  | 670 | SYSTEM_VALIDATE_REQUEST, | 
|  | 671 | 0, 0, 0, | 
|  | 672 | p_env->host_name, | 
|  | 673 | p_env->adapter_name); | 
|  | 674 | } else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 675 | dev_warn(&cdev->dev, "The CLAW device received" | 
|  | 676 | " an unexpected IRQ, " | 
|  | 677 | "c-%02x d-%02x\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 678 | irb->scsw.cmd.cstat, | 
|  | 679 | irb->scsw.cmd.dstat); | 
|  | 680 | return; | 
|  | 681 | } | 
|  | 682 | CLAW_DBF_TEXT(4, trace, "haltio"); | 
|  | 683 | return; | 
|  | 684 | case CLAW_START_READ: | 
|  | 685 | CLAW_DBF_TEXT(4, trace, "ReadIRQ"); | 
|  | 686 | if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { | 
|  | 687 | clear_bit(0, (void *)&p_ch->IO_active); | 
|  | 688 | if ((p_ch->irb->ecw[0] & 0x41) == 0x41 || | 
|  | 689 | (p_ch->irb->ecw[0] & 0x40) == 0x40 || | 
|  | 690 | (p_ch->irb->ecw[0])        == 0) { | 
|  | 691 | privptr->stats.rx_errors++; | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 692 | dev_info(&cdev->dev, | 
|  | 693 | "%s: Restart is required after remote " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 694 | "side recovers \n", | 
|  | 695 | dev->name); | 
|  | 696 | } | 
|  | 697 | CLAW_DBF_TEXT(4, trace, "notrdy"); | 
|  | 698 | return; | 
|  | 699 | } | 
|  | 700 | if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) && | 
|  | 701 | (p_ch->irb->scsw.cmd.dstat == 0)) { | 
|  | 702 | if (test_and_set_bit(CLAW_BH_ACTIVE, | 
|  | 703 | (void *)&p_ch->flag_a) == 0) | 
|  | 704 | tasklet_schedule(&p_ch->tasklet); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | else | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 706 | CLAW_DBF_TEXT(4, trace, "PCINoBH"); | 
|  | 707 | CLAW_DBF_TEXT(4, trace, "PCI_read"); | 
|  | 708 | return; | 
|  | 709 | } | 
|  | 710 | if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || | 
|  | 711 | (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || | 
|  | 712 | (p_ch->irb->scsw.cmd.stctl == | 
|  | 713 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { | 
|  | 714 | CLAW_DBF_TEXT(4, trace, "SPend_rd"); | 
|  | 715 | return; | 
|  | 716 | } | 
|  | 717 | clear_bit(0, (void *)&p_ch->IO_active); | 
|  | 718 | claw_clearbit_busy(TB_RETRY, dev); | 
|  | 719 | if (test_and_set_bit(CLAW_BH_ACTIVE, | 
|  | 720 | (void *)&p_ch->flag_a) == 0) | 
|  | 721 | tasklet_schedule(&p_ch->tasklet); | 
|  | 722 | else | 
|  | 723 | CLAW_DBF_TEXT(4, trace, "RdBHAct"); | 
|  | 724 | CLAW_DBF_TEXT(4, trace, "RdIRQXit"); | 
|  | 725 | return; | 
|  | 726 | case CLAW_START_WRITE: | 
|  | 727 | if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 728 | dev_info(&cdev->dev, | 
|  | 729 | "%s: Unit Check Occured in " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 730 | "write channel\n", dev->name); | 
|  | 731 | clear_bit(0, (void *)&p_ch->IO_active); | 
|  | 732 | if (p_ch->irb->ecw[0] & 0x80) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 733 | dev_info(&cdev->dev, | 
|  | 734 | "%s: Resetting Event " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 735 | "occurred:\n", dev->name); | 
|  | 736 | init_timer(&p_ch->timer); | 
|  | 737 | p_ch->timer.function = | 
|  | 738 | (void *)claw_write_retry; | 
|  | 739 | p_ch->timer.data = (unsigned long)p_ch; | 
|  | 740 | p_ch->timer.expires = jiffies + 10*HZ; | 
|  | 741 | add_timer(&p_ch->timer); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 742 | dev_info(&cdev->dev, | 
|  | 743 | "%s: write connection " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 744 | "restarting\n", dev->name); | 
|  | 745 | } | 
|  | 746 | CLAW_DBF_TEXT(4, trace, "rstrtwrt"); | 
|  | 747 | return; | 
|  | 748 | } | 
|  | 749 | if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) { | 
|  | 750 | clear_bit(0, (void *)&p_ch->IO_active); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 751 | dev_info(&cdev->dev, | 
|  | 752 | "%s: Unit Exception " | 
|  | 753 | "occurred in write channel\n", | 
|  | 754 | dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 755 | } | 
|  | 756 | if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || | 
|  | 757 | (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || | 
|  | 758 | (p_ch->irb->scsw.cmd.stctl == | 
|  | 759 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { | 
|  | 760 | CLAW_DBF_TEXT(4, trace, "writeUE"); | 
|  | 761 | return; | 
|  | 762 | } | 
|  | 763 | clear_bit(0, (void *)&p_ch->IO_active); | 
|  | 764 | if (claw_test_and_setbit_busy(TB_TX, dev) == 0) { | 
|  | 765 | claw_write_next(p_ch); | 
|  | 766 | claw_clearbit_busy(TB_TX, dev); | 
|  | 767 | claw_clear_busy(dev); | 
|  | 768 | } | 
|  | 769 | p_ch_r = (struct chbk *)&privptr->channel[READ]; | 
|  | 770 | if (test_and_set_bit(CLAW_BH_ACTIVE, | 
|  | 771 | (void *)&p_ch_r->flag_a) == 0) | 
|  | 772 | tasklet_schedule(&p_ch_r->tasklet); | 
|  | 773 | CLAW_DBF_TEXT(4, trace, "StWtExit"); | 
|  | 774 | return; | 
|  | 775 | default: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 776 | dev_warn(&cdev->dev, | 
|  | 777 | "The CLAW device for %s received an unexpected IRQ\n", | 
|  | 778 | dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 779 | CLAW_DBF_TEXT(2, trace, "badIRQ"); | 
|  | 780 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } | 
|  | 782 |  | 
|  | 783 | }       /*   end of claw_irq_handler    */ | 
|  | 784 |  | 
|  | 785 |  | 
|  | 786 | /*-------------------------------------------------------------------* | 
|  | 787 | *       claw_irq_tasklet                                             * | 
|  | 788 | *                                                                    * | 
|  | 789 | *--------------------------------------------------------------------*/ | 
|  | 790 | static void | 
|  | 791 | claw_irq_tasklet ( unsigned long data ) | 
|  | 792 | { | 
|  | 793 | struct chbk * p_ch; | 
|  | 794 | struct net_device  *dev; | 
|  | 795 | struct claw_privbk *       privptr; | 
|  | 796 |  | 
|  | 797 | p_ch = (struct chbk *) data; | 
|  | 798 | dev = (struct net_device *)p_ch->ndev; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 799 | CLAW_DBF_TEXT(4, trace, "IRQtask"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 800 | privptr = (struct claw_privbk *)dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | unpack_read(dev); | 
|  | 802 | clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 803 | CLAW_DBF_TEXT(4, trace, "TskletXt"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | return; | 
|  | 805 | }       /*    end of claw_irq_bh    */ | 
|  | 806 |  | 
|  | 807 | /*-------------------------------------------------------------------* | 
|  | 808 | *       claw_release                                                 * | 
|  | 809 | *                                                                    * | 
|  | 810 | *--------------------------------------------------------------------*/ | 
|  | 811 | static int | 
|  | 812 | claw_release(struct net_device *dev) | 
|  | 813 | { | 
|  | 814 | int                rc; | 
|  | 815 | int                i; | 
|  | 816 | unsigned long      saveflags; | 
|  | 817 | unsigned long      parm; | 
|  | 818 | struct claw_privbk *privptr; | 
|  | 819 | DECLARE_WAITQUEUE(wait, current); | 
|  | 820 | struct ccwbk*             p_this_ccw; | 
|  | 821 | struct ccwbk*             p_buf; | 
|  | 822 |  | 
|  | 823 | if (!dev) | 
|  | 824 | return 0; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 825 | privptr = (struct claw_privbk *)dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | if (!privptr) | 
|  | 827 | return 0; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 828 | CLAW_DBF_TEXT(4, trace, "release"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | privptr->release_pend=1; | 
|  | 830 | claw_setbit_busy(TB_STOP,dev); | 
|  | 831 | for ( i = 1; i >=0 ;  i--) { | 
|  | 832 | spin_lock_irqsave( | 
|  | 833 | get_ccwdev_lock(privptr->channel[i].cdev), saveflags); | 
|  | 834 | /*   del_timer(&privptr->channel[READ].timer);  */ | 
|  | 835 | privptr->channel[i].claw_state = CLAW_STOP; | 
|  | 836 | privptr->channel[i].IO_active = 0; | 
|  | 837 | parm = (unsigned long) &privptr->channel[i]; | 
|  | 838 | if (i == WRITE) | 
|  | 839 | claw_purge_skb_queue( | 
|  | 840 | &privptr->channel[WRITE].collect_queue); | 
|  | 841 | rc = ccw_device_halt (privptr->channel[i].cdev, parm); | 
|  | 842 | if (privptr->system_validate_comp==0x00)  /* never opened? */ | 
|  | 843 | init_waitqueue_head(&privptr->channel[i].wait); | 
|  | 844 | add_wait_queue(&privptr->channel[i].wait, &wait); | 
|  | 845 | set_current_state(TASK_INTERRUPTIBLE); | 
|  | 846 | spin_unlock_irqrestore( | 
|  | 847 | get_ccwdev_lock(privptr->channel[i].cdev), saveflags); | 
|  | 848 | schedule(); | 
|  | 849 | set_current_state(TASK_RUNNING); | 
|  | 850 | remove_wait_queue(&privptr->channel[i].wait, &wait); | 
|  | 851 | if (rc != 0) { | 
|  | 852 | ccw_check_return_code(privptr->channel[i].cdev, rc); | 
|  | 853 | } | 
|  | 854 | } | 
|  | 855 | if (privptr->pk_skb != NULL) { | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 856 | dev_kfree_skb_any(privptr->pk_skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | privptr->pk_skb = NULL; | 
|  | 858 | } | 
|  | 859 | if(privptr->buffs_alloc != 1) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 860 | CLAW_DBF_TEXT(4, trace, "none2fre"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | return 0; | 
|  | 862 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 863 | CLAW_DBF_TEXT(4, trace, "freebufs"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | if (privptr->p_buff_ccw != NULL) { | 
|  | 865 | free_pages((unsigned long)privptr->p_buff_ccw, | 
|  | 866 | (int)pages_to_order_of_mag(privptr->p_buff_ccw_num)); | 
|  | 867 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 868 | CLAW_DBF_TEXT(4, trace, "freeread"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | if (privptr->p_env->read_size < PAGE_SIZE) { | 
|  | 870 | if (privptr->p_buff_read != NULL) { | 
|  | 871 | free_pages((unsigned long)privptr->p_buff_read, | 
|  | 872 | (int)pages_to_order_of_mag(privptr->p_buff_read_num)); | 
|  | 873 | } | 
|  | 874 | } | 
|  | 875 | else { | 
|  | 876 | p_buf=privptr->p_read_active_first; | 
|  | 877 | while (p_buf!=NULL) { | 
|  | 878 | free_pages((unsigned long)p_buf->p_buffer, | 
|  | 879 | (int)pages_to_order_of_mag( | 
|  | 880 | privptr->p_buff_pages_perread )); | 
|  | 881 | p_buf=p_buf->next; | 
|  | 882 | } | 
|  | 883 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 884 | CLAW_DBF_TEXT(4, trace, "freewrit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | if (privptr->p_env->write_size < PAGE_SIZE ) { | 
|  | 886 | free_pages((unsigned long)privptr->p_buff_write, | 
|  | 887 | (int)pages_to_order_of_mag(privptr->p_buff_write_num)); | 
|  | 888 | } | 
|  | 889 | else { | 
|  | 890 | p_buf=privptr->p_write_active_first; | 
|  | 891 | while (p_buf!=NULL) { | 
|  | 892 | free_pages((unsigned long)p_buf->p_buffer, | 
|  | 893 | (int)pages_to_order_of_mag( | 
|  | 894 | privptr->p_buff_pages_perwrite )); | 
|  | 895 | p_buf=p_buf->next; | 
|  | 896 | } | 
|  | 897 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 898 | CLAW_DBF_TEXT(4, trace, "clearptr"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | privptr->buffs_alloc = 0; | 
|  | 900 | privptr->p_buff_ccw=NULL; | 
|  | 901 | privptr->p_buff_read=NULL; | 
|  | 902 | privptr->p_buff_write=NULL; | 
|  | 903 | privptr->system_validate_comp=0; | 
|  | 904 | privptr->release_pend=0; | 
|  | 905 | /*      Remove any writes that were pending and reset all reads   */ | 
|  | 906 | p_this_ccw=privptr->p_read_active_first; | 
|  | 907 | while (p_this_ccw!=NULL) { | 
|  | 908 | p_this_ccw->header.length=0xffff; | 
|  | 909 | p_this_ccw->header.opcode=0xff; | 
|  | 910 | p_this_ccw->header.flag=0x00; | 
|  | 911 | p_this_ccw=p_this_ccw->next; | 
|  | 912 | } | 
|  | 913 |  | 
|  | 914 | while (privptr->p_write_active_first!=NULL) { | 
|  | 915 | p_this_ccw=privptr->p_write_active_first; | 
|  | 916 | p_this_ccw->header.flag=CLAW_PENDING; | 
|  | 917 | privptr->p_write_active_first=p_this_ccw->next; | 
|  | 918 | p_this_ccw->next=privptr->p_write_free_chain; | 
|  | 919 | privptr->p_write_free_chain=p_this_ccw; | 
|  | 920 | ++privptr->write_free_count; | 
|  | 921 | } | 
|  | 922 | privptr->p_write_active_last=NULL; | 
|  | 923 | privptr->mtc_logical_link = -1; | 
|  | 924 | privptr->mtc_skipping = 1; | 
|  | 925 | privptr->mtc_offset=0; | 
|  | 926 |  | 
|  | 927 | if (((privptr->channel[READ].last_dstat | | 
|  | 928 | privptr->channel[WRITE].last_dstat) & | 
|  | 929 | ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 930 | dev_warn(&privptr->channel[READ].cdev->dev, | 
|  | 931 | "Deactivating %s completed with incorrect" | 
|  | 932 | " subchannel status " | 
|  | 933 | "(read %02x, write %02x)\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | dev->name, | 
|  | 935 | privptr->channel[READ].last_dstat, | 
|  | 936 | privptr->channel[WRITE].last_dstat); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 937 | CLAW_DBF_TEXT(2, trace, "badclose"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 939 | CLAW_DBF_TEXT(4, trace, "rlsexit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | return 0; | 
|  | 941 | }      /* end of claw_release     */ | 
|  | 942 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | /*-------------------------------------------------------------------* | 
|  | 944 | *       claw_write_retry                                             * | 
|  | 945 | *                                                                    * | 
|  | 946 | *--------------------------------------------------------------------*/ | 
|  | 947 |  | 
|  | 948 | static void | 
|  | 949 | claw_write_retry ( struct chbk *p_ch ) | 
|  | 950 | { | 
|  | 951 |  | 
|  | 952 | struct net_device  *dev=p_ch->ndev; | 
|  | 953 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 954 | CLAW_DBF_TEXT(4, trace, "w_retry"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | if (p_ch->claw_state == CLAW_STOP) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | return; | 
|  | 957 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | claw_strt_out_IO( dev ); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 959 | CLAW_DBF_TEXT(4, trace, "rtry_xit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | return; | 
|  | 961 | }      /* end of claw_write_retry      */ | 
|  | 962 |  | 
|  | 963 |  | 
|  | 964 | /*-------------------------------------------------------------------* | 
|  | 965 | *       claw_write_next                                              * | 
|  | 966 | *                                                                    * | 
|  | 967 | *--------------------------------------------------------------------*/ | 
|  | 968 |  | 
|  | 969 | static void | 
|  | 970 | claw_write_next ( struct chbk * p_ch ) | 
|  | 971 | { | 
|  | 972 |  | 
|  | 973 | struct net_device  *dev; | 
|  | 974 | struct claw_privbk *privptr=NULL; | 
|  | 975 | struct sk_buff *pk_skb; | 
|  | 976 | int	rc; | 
|  | 977 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 978 | CLAW_DBF_TEXT(4, trace, "claw_wrt"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | if (p_ch->claw_state == CLAW_STOP) | 
|  | 980 | return; | 
|  | 981 | dev = (struct net_device *) p_ch->ndev; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 982 | privptr = (struct claw_privbk *) dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | claw_free_wrt_buf( dev ); | 
|  | 984 | if ((privptr->write_free_count > 0) && | 
| David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 985 | !skb_queue_empty(&p_ch->collect_queue)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | pk_skb = claw_pack_skb(privptr); | 
|  | 987 | while (pk_skb != NULL) { | 
|  | 988 | rc = claw_hw_tx( pk_skb, dev,1); | 
|  | 989 | if (privptr->write_free_count > 0) { | 
|  | 990 | pk_skb = claw_pack_skb(privptr); | 
|  | 991 | } else | 
|  | 992 | pk_skb = NULL; | 
|  | 993 | } | 
|  | 994 | } | 
|  | 995 | if (privptr->p_write_active_first!=NULL) { | 
|  | 996 | claw_strt_out_IO(dev); | 
|  | 997 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | return; | 
|  | 999 | }      /* end of claw_write_next      */ | 
|  | 1000 |  | 
|  | 1001 | /*-------------------------------------------------------------------* | 
|  | 1002 | *                                                                    * | 
|  | 1003 | *       claw_timer                                                   * | 
|  | 1004 | *--------------------------------------------------------------------*/ | 
|  | 1005 |  | 
|  | 1006 | static void | 
|  | 1007 | claw_timer ( struct chbk * p_ch ) | 
|  | 1008 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1009 | CLAW_DBF_TEXT(4, trace, "timer"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | p_ch->flag |= CLAW_TIMER; | 
|  | 1011 | wake_up(&p_ch->wait); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | return; | 
|  | 1013 | }      /* end of claw_timer  */ | 
|  | 1014 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | /* | 
|  | 1016 | * | 
|  | 1017 | *       functions | 
|  | 1018 | */ | 
|  | 1019 |  | 
|  | 1020 |  | 
|  | 1021 | /*-------------------------------------------------------------------* | 
|  | 1022 | *                                                                    * | 
|  | 1023 | *     pages_to_order_of_mag                                          * | 
|  | 1024 | *                                                                    * | 
|  | 1025 | *    takes a number of pages from 1 to 512 and returns the           * | 
|  | 1026 | *    log(num_pages)/log(2) get_free_pages() needs a base 2 order     * | 
|  | 1027 | *    of magnitude get_free_pages() has an upper order of 9           * | 
|  | 1028 | *--------------------------------------------------------------------*/ | 
|  | 1029 |  | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1030 | static int | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | pages_to_order_of_mag(int num_of_pages) | 
|  | 1032 | { | 
|  | 1033 | int	order_of_mag=1;		/* assume 2 pages */ | 
|  | 1034 | int	nump=2; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1035 |  | 
|  | 1036 | CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | if (num_of_pages == 1)   {return 0; }  /* magnitude of 0 = 1 page */ | 
|  | 1038 | /* 512 pages = 2Meg on 4k page systems */ | 
|  | 1039 | if (num_of_pages >= 512) {return 9; } | 
|  | 1040 | /* we have two or more pages order is at least 1 */ | 
|  | 1041 | for (nump=2 ;nump <= 512;nump*=2) { | 
|  | 1042 | if (num_of_pages <= nump) | 
|  | 1043 | break; | 
|  | 1044 | order_of_mag +=1; | 
|  | 1045 | } | 
|  | 1046 | if (order_of_mag > 9) { order_of_mag = 9; }  /* I know it's paranoid */ | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1047 | CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | return order_of_mag; | 
|  | 1049 | } | 
|  | 1050 |  | 
|  | 1051 | /*-------------------------------------------------------------------* | 
|  | 1052 | *                                                                    * | 
|  | 1053 | *     add_claw_reads                                                 * | 
|  | 1054 | *                                                                    * | 
|  | 1055 | *--------------------------------------------------------------------*/ | 
|  | 1056 | static int | 
|  | 1057 | add_claw_reads(struct net_device *dev, struct ccwbk* p_first, | 
|  | 1058 | struct ccwbk* p_last) | 
|  | 1059 | { | 
|  | 1060 | struct claw_privbk *privptr; | 
|  | 1061 | struct ccw1  temp_ccw; | 
|  | 1062 | struct endccw * p_end; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1063 | CLAW_DBF_TEXT(4, trace, "addreads"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1064 | privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | p_end = privptr->p_end_ccw; | 
|  | 1066 |  | 
|  | 1067 | /* first CCW and last CCW contains a new set of read channel programs | 
|  | 1068 | *       to apend the running channel programs | 
|  | 1069 | */ | 
|  | 1070 | if ( p_first==NULL) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1071 | CLAW_DBF_TEXT(4, trace, "addexit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | return 0; | 
|  | 1073 | } | 
|  | 1074 |  | 
|  | 1075 | /* set up ending CCW sequence for this segment */ | 
|  | 1076 | if (p_end->read1) { | 
|  | 1077 | p_end->read1=0x00;    /*  second ending CCW is now active */ | 
|  | 1078 | /*      reset ending CCWs and setup TIC CCWs              */ | 
|  | 1079 | p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1080 | p_end->read2_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
|  | 1081 | p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1); | 
|  | 1082 | p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1); | 
|  | 1083 | p_end->read2_nop2.cda=0; | 
|  | 1084 | p_end->read2_nop2.count=1; | 
|  | 1085 | } | 
|  | 1086 | else { | 
|  | 1087 | p_end->read1=0x01;  /* first ending CCW is now active */ | 
|  | 1088 | /*      reset ending CCWs and setup TIC CCWs          */ | 
|  | 1089 | p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1090 | p_end->read1_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
|  | 1091 | p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1); | 
|  | 1092 | p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1); | 
|  | 1093 | p_end->read1_nop2.cda=0; | 
|  | 1094 | p_end->read1_nop2.count=1; | 
|  | 1095 | } | 
|  | 1096 |  | 
|  | 1097 | if ( privptr-> p_read_active_first ==NULL ) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1098 | privptr->p_read_active_first = p_first;  /*  set new first */ | 
|  | 1099 | privptr->p_read_active_last  = p_last;   /*  set new last  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | } | 
|  | 1101 | else { | 
|  | 1102 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | /* set up TIC ccw  */ | 
|  | 1104 | temp_ccw.cda= (__u32)__pa(&p_first->read); | 
|  | 1105 | temp_ccw.count=0; | 
|  | 1106 | temp_ccw.flags=0; | 
|  | 1107 | temp_ccw.cmd_code = CCW_CLAW_CMD_TIC; | 
|  | 1108 |  | 
|  | 1109 |  | 
|  | 1110 | if (p_end->read1) { | 
|  | 1111 |  | 
|  | 1112 | /* first set of CCW's is chained to the new read              */ | 
|  | 1113 | /* chain, so the second set is chained to the active chain.   */ | 
|  | 1114 | /* Therefore modify the second set to point to the new        */ | 
|  | 1115 | /* read chain set up TIC CCWs                                 */ | 
|  | 1116 | /* make sure we update the CCW so channel doesn't fetch it    */ | 
|  | 1117 | /* when it's only half done                                   */ | 
|  | 1118 | memcpy( &p_end->read2_nop2, &temp_ccw , | 
|  | 1119 | sizeof(struct ccw1)); | 
|  | 1120 | privptr->p_read_active_last->r_TIC_1.cda= | 
|  | 1121 | (__u32)__pa(&p_first->read); | 
|  | 1122 | privptr->p_read_active_last->r_TIC_2.cda= | 
|  | 1123 | (__u32)__pa(&p_first->read); | 
|  | 1124 | } | 
|  | 1125 | else { | 
|  | 1126 | /* make sure we update the CCW so channel doesn't   */ | 
|  | 1127 | /* fetch it when it is only half done               */ | 
|  | 1128 | memcpy( &p_end->read1_nop2, &temp_ccw , | 
|  | 1129 | sizeof(struct ccw1)); | 
|  | 1130 | privptr->p_read_active_last->r_TIC_1.cda= | 
|  | 1131 | (__u32)__pa(&p_first->read); | 
|  | 1132 | privptr->p_read_active_last->r_TIC_2.cda= | 
|  | 1133 | (__u32)__pa(&p_first->read); | 
|  | 1134 | } | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1135 | /*      chain in new set of blocks                         */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | privptr->p_read_active_last->next = p_first; | 
|  | 1137 | privptr->p_read_active_last=p_last; | 
|  | 1138 | } /* end of if ( privptr-> p_read_active_first ==NULL)  */ | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1139 | CLAW_DBF_TEXT(4, trace, "addexit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | return 0; | 
|  | 1141 | }    /*     end of add_claw_reads   */ | 
|  | 1142 |  | 
|  | 1143 | /*-------------------------------------------------------------------* | 
|  | 1144 | *   ccw_check_return_code                                           * | 
|  | 1145 | *                                                                   * | 
|  | 1146 | *-------------------------------------------------------------------*/ | 
|  | 1147 |  | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1148 | static void | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | ccw_check_return_code(struct ccw_device *cdev, int return_code) | 
|  | 1150 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1151 | CLAW_DBF_TEXT(4, trace, "ccwret"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | if (return_code != 0) { | 
|  | 1153 | switch (return_code) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1154 | case -EBUSY: /* BUSY is a transient state no action needed */ | 
|  | 1155 | break; | 
|  | 1156 | case -ENODEV: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1157 | dev_err(&cdev->dev, "The remote channel adapter is not" | 
|  | 1158 | " available\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1159 | break; | 
|  | 1160 | case -EINVAL: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1161 | dev_err(&cdev->dev, | 
|  | 1162 | "The status of the remote channel adapter" | 
|  | 1163 | " is not valid\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1164 | break; | 
|  | 1165 | default: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1166 | dev_err(&cdev->dev, "The common device layer" | 
|  | 1167 | " returned error code %d\n", | 
|  | 1168 | return_code); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1169 | } | 
|  | 1170 | } | 
|  | 1171 | CLAW_DBF_TEXT(4, trace, "ccwret"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | }    /*    end of ccw_check_return_code   */ | 
|  | 1173 |  | 
|  | 1174 | /*-------------------------------------------------------------------* | 
|  | 1175 | *       ccw_check_unit_check                                         * | 
|  | 1176 | *--------------------------------------------------------------------*/ | 
|  | 1177 |  | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1178 | static void | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | ccw_check_unit_check(struct chbk * p_ch, unsigned char sense ) | 
|  | 1180 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1181 | struct net_device *ndev = p_ch->ndev; | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1182 | struct device *dev = &p_ch->cdev->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1184 | CLAW_DBF_TEXT(4, trace, "unitchek"); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1185 | dev_warn(dev, "The communication peer of %s disconnected\n", | 
|  | 1186 | ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 |  | 
|  | 1188 | if (sense & 0x40) { | 
|  | 1189 | if (sense & 0x01) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1190 | dev_warn(dev, "The remote channel adapter for" | 
|  | 1191 | " %s has been reset\n", | 
|  | 1192 | ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | } | 
|  | 1194 | } | 
|  | 1195 | else if (sense & 0x20) { | 
|  | 1196 | if (sense & 0x04) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1197 | dev_warn(dev, "A data streaming timeout occurred" | 
|  | 1198 | " for %s\n", | 
|  | 1199 | ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | } | 
|  | 1201 | else  { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1202 | dev_warn(dev, "A data transfer parity error occurred" | 
|  | 1203 | " for %s\n", | 
|  | 1204 | ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | } | 
|  | 1206 | } | 
|  | 1207 | else if (sense & 0x10) { | 
|  | 1208 | if (sense & 0x20) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1209 | dev_warn(dev, "The remote channel adapter for %s" | 
|  | 1210 | " is faulty\n", | 
|  | 1211 | ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | } | 
|  | 1213 | else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1214 | dev_warn(dev, "A read data parity error occurred" | 
|  | 1215 | " for %s\n", | 
|  | 1216 | ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | } | 
|  | 1218 | } | 
|  | 1219 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | }   /*    end of ccw_check_unit_check    */ | 
|  | 1221 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | /*-------------------------------------------------------------------* | 
|  | 1223 | *               find_link                                            * | 
|  | 1224 | *--------------------------------------------------------------------*/ | 
|  | 1225 | static int | 
|  | 1226 | find_link(struct net_device *dev, char *host_name, char *ws_name ) | 
|  | 1227 | { | 
|  | 1228 | struct claw_privbk *privptr; | 
|  | 1229 | struct claw_env *p_env; | 
|  | 1230 | int    rc=0; | 
|  | 1231 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1232 | CLAW_DBF_TEXT(2, setup, "findlink"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1233 | privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | p_env=privptr->p_env; | 
|  | 1235 | switch (p_env->packing) | 
|  | 1236 | { | 
|  | 1237 | case  PACKING_ASK: | 
|  | 1238 | if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) || | 
|  | 1239 | (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 )) | 
|  | 1240 | rc = EINVAL; | 
|  | 1241 | break; | 
|  | 1242 | case  DO_PACKED: | 
|  | 1243 | case  PACK_SEND: | 
|  | 1244 | if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) || | 
|  | 1245 | (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 )) | 
|  | 1246 | rc = EINVAL; | 
|  | 1247 | break; | 
|  | 1248 | default: | 
|  | 1249 | if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) || | 
|  | 1250 | (memcmp(p_env->api_type , ws_name, 8)!=0)) | 
|  | 1251 | rc = EINVAL; | 
|  | 1252 | break; | 
|  | 1253 | } | 
|  | 1254 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | return 0; | 
|  | 1256 | }    /*    end of find_link    */ | 
|  | 1257 |  | 
|  | 1258 | /*-------------------------------------------------------------------* | 
|  | 1259 | *   claw_hw_tx                                                      * | 
|  | 1260 | *                                                                   * | 
|  | 1261 | *                                                                   * | 
|  | 1262 | *-------------------------------------------------------------------*/ | 
|  | 1263 |  | 
|  | 1264 | static int | 
|  | 1265 | claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid) | 
|  | 1266 | { | 
|  | 1267 | int                             rc=0; | 
|  | 1268 | struct claw_privbk 		*privptr; | 
|  | 1269 | struct ccwbk           *p_this_ccw; | 
|  | 1270 | struct ccwbk           *p_first_ccw; | 
|  | 1271 | struct ccwbk           *p_last_ccw; | 
|  | 1272 | __u32                           numBuffers; | 
|  | 1273 | signed long                     len_of_data; | 
|  | 1274 | unsigned long                   bytesInThisBuffer; | 
|  | 1275 | unsigned char                   *pDataAddress; | 
|  | 1276 | struct endccw                   *pEnd; | 
|  | 1277 | struct ccw1                     tempCCW; | 
|  | 1278 | struct chbk                     *p_ch; | 
|  | 1279 | struct claw_env			*p_env; | 
|  | 1280 | int                             lock; | 
|  | 1281 | struct clawph			*pk_head; | 
|  | 1282 | struct chbk			*ch; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1283 |  | 
|  | 1284 | CLAW_DBF_TEXT(4, trace, "hw_tx"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1285 | privptr = (struct claw_privbk *)(dev->ml_priv); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | p_ch=(struct chbk *)&privptr->channel[WRITE]; | 
|  | 1287 | p_env =privptr->p_env; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | claw_free_wrt_buf(dev);	/* Clean up free chain if posible */ | 
|  | 1289 | /*  scan the write queue to free any completed write packets   */ | 
|  | 1290 | p_first_ccw=NULL; | 
|  | 1291 | p_last_ccw=NULL; | 
|  | 1292 | if ((p_env->packing >= PACK_SEND) && | 
|  | 1293 | (skb->cb[1] != 'P')) { | 
|  | 1294 | skb_push(skb,sizeof(struct clawph)); | 
|  | 1295 | pk_head=(struct clawph *)skb->data; | 
|  | 1296 | pk_head->len=skb->len-sizeof(struct clawph); | 
|  | 1297 | if (pk_head->len%4)  { | 
|  | 1298 | pk_head->len+= 4-(pk_head->len%4); | 
|  | 1299 | skb_pad(skb,4-(pk_head->len%4)); | 
|  | 1300 | skb_put(skb,4-(pk_head->len%4)); | 
|  | 1301 | } | 
|  | 1302 | if (p_env->packing == DO_PACKED) | 
|  | 1303 | pk_head->link_num = linkid; | 
|  | 1304 | else | 
|  | 1305 | pk_head->link_num = 0; | 
|  | 1306 | pk_head->flag = 0x00; | 
|  | 1307 | skb_pad(skb,4); | 
|  | 1308 | skb->cb[1] = 'P'; | 
|  | 1309 | } | 
|  | 1310 | if (linkid == 0) { | 
|  | 1311 | if (claw_check_busy(dev)) { | 
|  | 1312 | if (privptr->write_free_count!=0) { | 
|  | 1313 | claw_clear_busy(dev); | 
|  | 1314 | } | 
|  | 1315 | else { | 
|  | 1316 | claw_strt_out_IO(dev ); | 
|  | 1317 | claw_free_wrt_buf( dev ); | 
|  | 1318 | if (privptr->write_free_count==0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | ch = &privptr->channel[WRITE]; | 
|  | 1320 | atomic_inc(&skb->users); | 
|  | 1321 | skb_queue_tail(&ch->collect_queue, skb); | 
|  | 1322 | goto Done; | 
|  | 1323 | } | 
|  | 1324 | else { | 
|  | 1325 | claw_clear_busy(dev); | 
|  | 1326 | } | 
|  | 1327 | } | 
|  | 1328 | } | 
|  | 1329 | /*  tx lock  */ | 
|  | 1330 | if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | ch = &privptr->channel[WRITE]; | 
|  | 1332 | atomic_inc(&skb->users); | 
|  | 1333 | skb_queue_tail(&ch->collect_queue, skb); | 
|  | 1334 | claw_strt_out_IO(dev ); | 
|  | 1335 | rc=-EBUSY; | 
|  | 1336 | goto Done2; | 
|  | 1337 | } | 
|  | 1338 | } | 
|  | 1339 | /*      See how many write buffers are required to hold this data */ | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1340 | numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 |  | 
|  | 1342 | /*      If that number of buffers isn't available, give up for now */ | 
|  | 1343 | if (privptr->write_free_count < numBuffers || | 
|  | 1344 | privptr->p_write_free_chain == NULL ) { | 
|  | 1345 |  | 
|  | 1346 | claw_setbit_busy(TB_NOBUFFER,dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | ch = &privptr->channel[WRITE]; | 
|  | 1348 | atomic_inc(&skb->users); | 
|  | 1349 | skb_queue_tail(&ch->collect_queue, skb); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1350 | CLAW_DBF_TEXT(2, trace, "clawbusy"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | goto Done2; | 
|  | 1352 | } | 
|  | 1353 | pDataAddress=skb->data; | 
|  | 1354 | len_of_data=skb->len; | 
|  | 1355 |  | 
|  | 1356 | while (len_of_data > 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | p_this_ccw=privptr->p_write_free_chain;  /* get a block */ | 
|  | 1358 | if (p_this_ccw == NULL) { /* lost the race */ | 
|  | 1359 | ch = &privptr->channel[WRITE]; | 
|  | 1360 | atomic_inc(&skb->users); | 
|  | 1361 | skb_queue_tail(&ch->collect_queue, skb); | 
|  | 1362 | goto Done2; | 
|  | 1363 | } | 
|  | 1364 | privptr->p_write_free_chain=p_this_ccw->next; | 
|  | 1365 | p_this_ccw->next=NULL; | 
|  | 1366 | --privptr->write_free_count; /* -1 */ | 
|  | 1367 | bytesInThisBuffer=len_of_data; | 
|  | 1368 | memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer); | 
|  | 1369 | len_of_data-=bytesInThisBuffer; | 
|  | 1370 | pDataAddress+=(unsigned long)bytesInThisBuffer; | 
|  | 1371 | /*      setup write CCW         */ | 
|  | 1372 | p_this_ccw->write.cmd_code = (linkid * 8) +1; | 
|  | 1373 | if (len_of_data>0) { | 
|  | 1374 | p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG; | 
|  | 1375 | } | 
|  | 1376 | p_this_ccw->write.count=bytesInThisBuffer; | 
|  | 1377 | /*      now add to end of this chain    */ | 
|  | 1378 | if (p_first_ccw==NULL)    { | 
|  | 1379 | p_first_ccw=p_this_ccw; | 
|  | 1380 | } | 
|  | 1381 | if (p_last_ccw!=NULL) { | 
|  | 1382 | p_last_ccw->next=p_this_ccw; | 
|  | 1383 | /*      set up TIC ccws         */ | 
|  | 1384 | p_last_ccw->w_TIC_1.cda= | 
|  | 1385 | (__u32)__pa(&p_this_ccw->write); | 
|  | 1386 | } | 
|  | 1387 | p_last_ccw=p_this_ccw;      /* save new last block */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | } | 
|  | 1389 |  | 
|  | 1390 | /*      FirstCCW and LastCCW now contain a new set of write channel | 
|  | 1391 | *       programs to append to the running channel program | 
|  | 1392 | */ | 
|  | 1393 |  | 
|  | 1394 | if (p_first_ccw!=NULL) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1395 | /*      setup ending ccw sequence for this segment           */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | pEnd=privptr->p_end_ccw; | 
|  | 1397 | if (pEnd->write1) { | 
|  | 1398 | pEnd->write1=0x00;   /* second end ccw is now active */ | 
|  | 1399 | /*      set up Tic CCWs         */ | 
|  | 1400 | p_last_ccw->w_TIC_1.cda= | 
|  | 1401 | (__u32)__pa(&pEnd->write2_nop1); | 
|  | 1402 | pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1403 | pEnd->write2_nop2.flags    = | 
|  | 1404 | CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
|  | 1405 | pEnd->write2_nop2.cda=0; | 
|  | 1406 | pEnd->write2_nop2.count=1; | 
|  | 1407 | } | 
|  | 1408 | else {  /*  end of if (pEnd->write1)*/ | 
|  | 1409 | pEnd->write1=0x01;   /* first end ccw is now active */ | 
|  | 1410 | /*      set up Tic CCWs         */ | 
|  | 1411 | p_last_ccw->w_TIC_1.cda= | 
|  | 1412 | (__u32)__pa(&pEnd->write1_nop1); | 
|  | 1413 | pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1414 | pEnd->write1_nop2.flags    = | 
|  | 1415 | CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
|  | 1416 | pEnd->write1_nop2.cda=0; | 
|  | 1417 | pEnd->write1_nop2.count=1; | 
|  | 1418 | }  /* end if if (pEnd->write1) */ | 
|  | 1419 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | if (privptr->p_write_active_first==NULL ) { | 
|  | 1421 | privptr->p_write_active_first=p_first_ccw; | 
|  | 1422 | privptr->p_write_active_last=p_last_ccw; | 
|  | 1423 | } | 
|  | 1424 | else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | /*      set up Tic CCWs         */ | 
|  | 1426 |  | 
|  | 1427 | tempCCW.cda=(__u32)__pa(&p_first_ccw->write); | 
|  | 1428 | tempCCW.count=0; | 
|  | 1429 | tempCCW.flags=0; | 
|  | 1430 | tempCCW.cmd_code=CCW_CLAW_CMD_TIC; | 
|  | 1431 |  | 
|  | 1432 | if (pEnd->write1) { | 
|  | 1433 |  | 
|  | 1434 | /* | 
|  | 1435 | * first set of ending CCW's is chained to the new write | 
|  | 1436 | * chain, so the second set is chained to the active chain | 
|  | 1437 | * Therefore modify the second set to point the new write chain. | 
|  | 1438 | * make sure we update the CCW atomically | 
|  | 1439 | * so channel does not fetch it when it's only half done | 
|  | 1440 | */ | 
|  | 1441 | memcpy( &pEnd->write2_nop2, &tempCCW , | 
|  | 1442 | sizeof(struct ccw1)); | 
|  | 1443 | privptr->p_write_active_last->w_TIC_1.cda= | 
|  | 1444 | (__u32)__pa(&p_first_ccw->write); | 
|  | 1445 | } | 
|  | 1446 | else { | 
|  | 1447 |  | 
|  | 1448 | /*make sure we update the CCW atomically | 
|  | 1449 | *so channel does not fetch it when it's only half done | 
|  | 1450 | */ | 
|  | 1451 | memcpy(&pEnd->write1_nop2, &tempCCW , | 
|  | 1452 | sizeof(struct ccw1)); | 
|  | 1453 | privptr->p_write_active_last->w_TIC_1.cda= | 
|  | 1454 | (__u32)__pa(&p_first_ccw->write); | 
|  | 1455 |  | 
|  | 1456 | } /* end if if (pEnd->write1) */ | 
|  | 1457 |  | 
|  | 1458 | privptr->p_write_active_last->next=p_first_ccw; | 
|  | 1459 | privptr->p_write_active_last=p_last_ccw; | 
|  | 1460 | } | 
|  | 1461 |  | 
|  | 1462 | } /* endif (p_first_ccw!=NULL)  */ | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 1463 | dev_kfree_skb_any(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | if (linkid==0) { | 
|  | 1465 | lock=LOCK_NO; | 
|  | 1466 | } | 
|  | 1467 | else  { | 
|  | 1468 | lock=LOCK_YES; | 
|  | 1469 | } | 
|  | 1470 | claw_strt_out_IO(dev ); | 
|  | 1471 | /*      if write free count is zero , set NOBUFFER       */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | if (privptr->write_free_count==0) { | 
|  | 1473 | claw_setbit_busy(TB_NOBUFFER,dev); | 
|  | 1474 | } | 
|  | 1475 | Done2: | 
|  | 1476 | claw_clearbit_busy(TB_TX,dev); | 
|  | 1477 | Done: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | return(rc); | 
|  | 1479 | }    /*    end of claw_hw_tx    */ | 
|  | 1480 |  | 
|  | 1481 | /*-------------------------------------------------------------------* | 
|  | 1482 | *                                                                    * | 
|  | 1483 | *     init_ccw_bk                                                    * | 
|  | 1484 | *                                                                    * | 
|  | 1485 | *--------------------------------------------------------------------*/ | 
|  | 1486 |  | 
|  | 1487 | static int | 
|  | 1488 | init_ccw_bk(struct net_device *dev) | 
|  | 1489 | { | 
|  | 1490 |  | 
|  | 1491 | __u32   ccw_blocks_required; | 
|  | 1492 | __u32   ccw_blocks_perpage; | 
|  | 1493 | __u32   ccw_pages_required; | 
|  | 1494 | __u32   claw_reads_perpage=1; | 
|  | 1495 | __u32   claw_read_pages; | 
|  | 1496 | __u32   claw_writes_perpage=1; | 
|  | 1497 | __u32   claw_write_pages; | 
|  | 1498 | void    *p_buff=NULL; | 
|  | 1499 | struct ccwbk*p_free_chain; | 
|  | 1500 | struct ccwbk*p_buf; | 
|  | 1501 | struct ccwbk*p_last_CCWB; | 
|  | 1502 | struct ccwbk*p_first_CCWB; | 
|  | 1503 | struct endccw *p_endccw=NULL; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1504 | addr_t  real_address; | 
|  | 1505 | struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | struct clawh *pClawH=NULL; | 
|  | 1507 | addr_t   real_TIC_address; | 
|  | 1508 | int i,j; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1509 | CLAW_DBF_TEXT(4, trace, "init_ccw"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 |  | 
|  | 1511 | /*  initialize  statistics field */ | 
|  | 1512 | privptr->active_link_ID=0; | 
|  | 1513 | /*  initialize  ccwbk pointers  */ | 
|  | 1514 | privptr->p_write_free_chain=NULL;   /* pointer to free ccw chain*/ | 
|  | 1515 | privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/ | 
|  | 1516 | privptr->p_write_active_last=NULL;  /* pointer to the last write ccw*/ | 
|  | 1517 | privptr->p_read_active_first=NULL;  /* pointer to the first read ccw*/ | 
|  | 1518 | privptr->p_read_active_last=NULL;   /* pointer to the last read ccw */ | 
|  | 1519 | privptr->p_end_ccw=NULL;            /* pointer to ending ccw        */ | 
|  | 1520 | privptr->p_claw_signal_blk=NULL;    /* pointer to signal block      */ | 
|  | 1521 | privptr->buffs_alloc = 0; | 
|  | 1522 | memset(&privptr->end_ccw, 0x00, sizeof(struct endccw)); | 
|  | 1523 | memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl)); | 
|  | 1524 | /*  initialize  free write ccwbk counter  */ | 
|  | 1525 | privptr->write_free_count=0;  /* number of free bufs on write chain */ | 
|  | 1526 | p_last_CCWB = NULL; | 
|  | 1527 | p_first_CCWB= NULL; | 
|  | 1528 | /* | 
|  | 1529 | *  We need 1 CCW block for each read buffer, 1 for each | 
|  | 1530 | *  write buffer, plus 1 for ClawSignalBlock | 
|  | 1531 | */ | 
|  | 1532 | ccw_blocks_required = | 
|  | 1533 | privptr->p_env->read_buffers+privptr->p_env->write_buffers+1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | /* | 
|  | 1535 | * compute number of CCW blocks that will fit in a page | 
|  | 1536 | */ | 
|  | 1537 | ccw_blocks_perpage= PAGE_SIZE /  CCWBK_SIZE; | 
|  | 1538 | ccw_pages_required= | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1539 | DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | /* | 
|  | 1542 | *  read and write sizes are set by 2 constants in claw.h | 
|  | 1543 | *  4k and 32k.  Unpacked values other than 4k are not going to | 
|  | 1544 | * provide good performance. With packing buffers support 32k | 
|  | 1545 | * buffers are used. | 
|  | 1546 | */ | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1547 | if (privptr->p_env->read_size < PAGE_SIZE) { | 
|  | 1548 | claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size; | 
|  | 1549 | claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers, | 
|  | 1550 | claw_reads_perpage); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | } | 
|  | 1552 | else {       /* > or equal  */ | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1553 | privptr->p_buff_pages_perread = | 
|  | 1554 | DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE); | 
|  | 1555 | claw_read_pages = privptr->p_env->read_buffers * | 
|  | 1556 | privptr->p_buff_pages_perread; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | } | 
|  | 1558 | if (privptr->p_env->write_size < PAGE_SIZE) { | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1559 | claw_writes_perpage = | 
|  | 1560 | PAGE_SIZE / privptr->p_env->write_size; | 
|  | 1561 | claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers, | 
|  | 1562 | claw_writes_perpage); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 |  | 
|  | 1564 | } | 
|  | 1565 | else {      /* >  or equal  */ | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1566 | privptr->p_buff_pages_perwrite = | 
|  | 1567 | DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE); | 
|  | 1568 | claw_write_pages = privptr->p_env->write_buffers * | 
|  | 1569 | privptr->p_buff_pages_perwrite; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | /* | 
|  | 1572 | *               allocate ccw_pages_required | 
|  | 1573 | */ | 
|  | 1574 | if (privptr->p_buff_ccw==NULL) { | 
|  | 1575 | privptr->p_buff_ccw= | 
|  | 1576 | (void *)__get_free_pages(__GFP_DMA, | 
|  | 1577 | (int)pages_to_order_of_mag(ccw_pages_required )); | 
|  | 1578 | if (privptr->p_buff_ccw==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | return -ENOMEM; | 
|  | 1580 | } | 
|  | 1581 | privptr->p_buff_ccw_num=ccw_pages_required; | 
|  | 1582 | } | 
|  | 1583 | memset(privptr->p_buff_ccw, 0x00, | 
|  | 1584 | privptr->p_buff_ccw_num * PAGE_SIZE); | 
|  | 1585 |  | 
|  | 1586 | /* | 
|  | 1587 | *               obtain ending ccw block address | 
|  | 1588 | * | 
|  | 1589 | */ | 
|  | 1590 | privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw; | 
|  | 1591 | real_address  = (__u32)__pa(privptr->p_end_ccw); | 
|  | 1592 | /*                              Initialize ending CCW block       */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | p_endccw=privptr->p_end_ccw; | 
|  | 1594 | p_endccw->real=real_address; | 
|  | 1595 | p_endccw->write1=0x00; | 
|  | 1596 | p_endccw->read1=0x00; | 
|  | 1597 |  | 
|  | 1598 | /*      write1_nop1                                     */ | 
|  | 1599 | p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP; | 
|  | 1600 | p_endccw->write1_nop1.flags       = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1601 | p_endccw->write1_nop1.count       = 1; | 
|  | 1602 | p_endccw->write1_nop1.cda         = 0; | 
|  | 1603 |  | 
|  | 1604 | /*      write1_nop2                                     */ | 
|  | 1605 | p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1606 | p_endccw->write1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
|  | 1607 | p_endccw->write1_nop2.count      = 1; | 
|  | 1608 | p_endccw->write1_nop2.cda        = 0; | 
|  | 1609 |  | 
|  | 1610 | /*      write2_nop1                                     */ | 
|  | 1611 | p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP; | 
|  | 1612 | p_endccw->write2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1613 | p_endccw->write2_nop1.count        = 1; | 
|  | 1614 | p_endccw->write2_nop1.cda          = 0; | 
|  | 1615 |  | 
|  | 1616 | /*      write2_nop2                                     */ | 
|  | 1617 | p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1618 | p_endccw->write2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
|  | 1619 | p_endccw->write2_nop2.count        = 1; | 
|  | 1620 | p_endccw->write2_nop2.cda          = 0; | 
|  | 1621 |  | 
|  | 1622 | /*      read1_nop1                                      */ | 
|  | 1623 | p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP; | 
|  | 1624 | p_endccw->read1_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1625 | p_endccw->read1_nop1.count        = 1; | 
|  | 1626 | p_endccw->read1_nop1.cda          = 0; | 
|  | 1627 |  | 
|  | 1628 | /*      read1_nop2                                      */ | 
|  | 1629 | p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1630 | p_endccw->read1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
|  | 1631 | p_endccw->read1_nop2.count        = 1; | 
|  | 1632 | p_endccw->read1_nop2.cda          = 0; | 
|  | 1633 |  | 
|  | 1634 | /*      read2_nop1                                      */ | 
|  | 1635 | p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP; | 
|  | 1636 | p_endccw->read2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1637 | p_endccw->read2_nop1.count        = 1; | 
|  | 1638 | p_endccw->read2_nop1.cda          = 0; | 
|  | 1639 |  | 
|  | 1640 | /*      read2_nop2                                      */ | 
|  | 1641 | p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1642 | p_endccw->read2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
|  | 1643 | p_endccw->read2_nop2.count        = 1; | 
|  | 1644 | p_endccw->read2_nop2.cda          = 0; | 
|  | 1645 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | /* | 
|  | 1647 | *                               Build a chain of CCWs | 
|  | 1648 | * | 
|  | 1649 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | p_buff=privptr->p_buff_ccw; | 
|  | 1651 |  | 
|  | 1652 | p_free_chain=NULL; | 
|  | 1653 | for (i=0 ; i < ccw_pages_required; i++ ) { | 
|  | 1654 | real_address  = (__u32)__pa(p_buff); | 
|  | 1655 | p_buf=p_buff; | 
|  | 1656 | for (j=0 ; j < ccw_blocks_perpage ; j++) { | 
|  | 1657 | p_buf->next  = p_free_chain; | 
|  | 1658 | p_free_chain = p_buf; | 
|  | 1659 | p_buf->real=(__u32)__pa(p_buf); | 
|  | 1660 | ++p_buf; | 
|  | 1661 | } | 
|  | 1662 | p_buff+=PAGE_SIZE; | 
|  | 1663 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | /* | 
|  | 1665 | *                               Initialize ClawSignalBlock | 
|  | 1666 | * | 
|  | 1667 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | if (privptr->p_claw_signal_blk==NULL) { | 
|  | 1669 | privptr->p_claw_signal_blk=p_free_chain; | 
|  | 1670 | p_free_chain=p_free_chain->next; | 
|  | 1671 | pClawH=(struct clawh *)privptr->p_claw_signal_blk; | 
|  | 1672 | pClawH->length=0xffff; | 
|  | 1673 | pClawH->opcode=0xff; | 
|  | 1674 | pClawH->flag=CLAW_BUSY; | 
|  | 1675 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 |  | 
|  | 1677 | /* | 
|  | 1678 | *               allocate write_pages_required and add to free chain | 
|  | 1679 | */ | 
|  | 1680 | if (privptr->p_buff_write==NULL) { | 
|  | 1681 | if (privptr->p_env->write_size < PAGE_SIZE) { | 
|  | 1682 | privptr->p_buff_write= | 
|  | 1683 | (void *)__get_free_pages(__GFP_DMA, | 
|  | 1684 | (int)pages_to_order_of_mag(claw_write_pages )); | 
|  | 1685 | if (privptr->p_buff_write==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | privptr->p_buff_ccw=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | return -ENOMEM; | 
|  | 1688 | } | 
|  | 1689 | /* | 
|  | 1690 | *                               Build CLAW write free chain | 
|  | 1691 | * | 
|  | 1692 | */ | 
|  | 1693 |  | 
|  | 1694 | memset(privptr->p_buff_write, 0x00, | 
|  | 1695 | ccw_pages_required * PAGE_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | privptr->p_write_free_chain=NULL; | 
|  | 1697 |  | 
|  | 1698 | p_buff=privptr->p_buff_write; | 
|  | 1699 |  | 
|  | 1700 | for (i=0 ; i< privptr->p_env->write_buffers ; i++) { | 
|  | 1701 | p_buf        = p_free_chain;      /*  get a CCW */ | 
|  | 1702 | p_free_chain = p_buf->next; | 
|  | 1703 | p_buf->next  =privptr->p_write_free_chain; | 
|  | 1704 | privptr->p_write_free_chain = p_buf; | 
|  | 1705 | p_buf-> p_buffer	= (struct clawbuf *)p_buff; | 
|  | 1706 | p_buf-> write.cda       = (__u32)__pa(p_buff); | 
|  | 1707 | p_buf-> write.flags     = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1708 | p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1709 | p_buf-> w_read_FF.flags   = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1710 | p_buf-> w_read_FF.count   = 1; | 
|  | 1711 | p_buf-> w_read_FF.cda     = | 
|  | 1712 | (__u32)__pa(&p_buf-> header.flag); | 
|  | 1713 | p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; | 
|  | 1714 | p_buf-> w_TIC_1.flags      = 0; | 
|  | 1715 | p_buf-> w_TIC_1.count      = 0; | 
|  | 1716 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1717 | if (((unsigned long)p_buff + | 
|  | 1718 | privptr->p_env->write_size) >= | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | ((unsigned long)(p_buff+2* | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1720 | (privptr->p_env->write_size) - 1) & PAGE_MASK)) { | 
|  | 1721 | p_buff = p_buff+privptr->p_env->write_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | } | 
|  | 1723 | } | 
|  | 1724 | } | 
|  | 1725 | else      /*  Buffers are => PAGE_SIZE. 1 buff per get_free_pages */ | 
|  | 1726 | { | 
|  | 1727 | privptr->p_write_free_chain=NULL; | 
|  | 1728 | for (i = 0; i< privptr->p_env->write_buffers ; i++) { | 
|  | 1729 | p_buff=(void *)__get_free_pages(__GFP_DMA, | 
|  | 1730 | (int)pages_to_order_of_mag( | 
|  | 1731 | privptr->p_buff_pages_perwrite) ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | if (p_buff==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | free_pages((unsigned long)privptr->p_buff_ccw, | 
|  | 1734 | (int)pages_to_order_of_mag( | 
|  | 1735 | privptr->p_buff_ccw_num)); | 
|  | 1736 | privptr->p_buff_ccw=NULL; | 
|  | 1737 | p_buf=privptr->p_buff_write; | 
|  | 1738 | while (p_buf!=NULL) { | 
|  | 1739 | free_pages((unsigned long) | 
|  | 1740 | p_buf->p_buffer, | 
|  | 1741 | (int)pages_to_order_of_mag( | 
|  | 1742 | privptr->p_buff_pages_perwrite)); | 
|  | 1743 | p_buf=p_buf->next; | 
|  | 1744 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | return -ENOMEM; | 
|  | 1746 | }  /* Error on get_pages   */ | 
|  | 1747 | memset(p_buff, 0x00, privptr->p_env->write_size ); | 
|  | 1748 | p_buf         = p_free_chain; | 
|  | 1749 | p_free_chain  = p_buf->next; | 
|  | 1750 | p_buf->next   = privptr->p_write_free_chain; | 
|  | 1751 | privptr->p_write_free_chain = p_buf; | 
|  | 1752 | privptr->p_buff_write = p_buf; | 
|  | 1753 | p_buf->p_buffer=(struct clawbuf *)p_buff; | 
|  | 1754 | p_buf-> write.cda     = (__u32)__pa(p_buff); | 
|  | 1755 | p_buf-> write.flags   = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1756 | p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1757 | p_buf-> w_read_FF.flags    = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1758 | p_buf-> w_read_FF.count    = 1; | 
|  | 1759 | p_buf-> w_read_FF.cda      = | 
|  | 1760 | (__u32)__pa(&p_buf-> header.flag); | 
|  | 1761 | p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; | 
|  | 1762 | p_buf-> w_TIC_1.flags   = 0; | 
|  | 1763 | p_buf-> w_TIC_1.count   = 0; | 
|  | 1764 | }  /* for all write_buffers   */ | 
|  | 1765 |  | 
|  | 1766 | }    /* else buffers are PAGE_SIZE or bigger */ | 
|  | 1767 |  | 
|  | 1768 | } | 
|  | 1769 | privptr->p_buff_write_num=claw_write_pages; | 
|  | 1770 | privptr->write_free_count=privptr->p_env->write_buffers; | 
|  | 1771 |  | 
|  | 1772 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | /* | 
|  | 1774 | *               allocate read_pages_required and chain to free chain | 
|  | 1775 | */ | 
|  | 1776 | if (privptr->p_buff_read==NULL) { | 
|  | 1777 | if (privptr->p_env->read_size < PAGE_SIZE)  { | 
|  | 1778 | privptr->p_buff_read= | 
|  | 1779 | (void *)__get_free_pages(__GFP_DMA, | 
|  | 1780 | (int)pages_to_order_of_mag(claw_read_pages) ); | 
|  | 1781 | if (privptr->p_buff_read==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | free_pages((unsigned long)privptr->p_buff_ccw, | 
|  | 1783 | (int)pages_to_order_of_mag( | 
|  | 1784 | privptr->p_buff_ccw_num)); | 
|  | 1785 | /* free the write pages size is < page size  */ | 
|  | 1786 | free_pages((unsigned long)privptr->p_buff_write, | 
|  | 1787 | (int)pages_to_order_of_mag( | 
|  | 1788 | privptr->p_buff_write_num)); | 
|  | 1789 | privptr->p_buff_ccw=NULL; | 
|  | 1790 | privptr->p_buff_write=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | return -ENOMEM; | 
|  | 1792 | } | 
|  | 1793 | memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE); | 
|  | 1794 | privptr->p_buff_read_num=claw_read_pages; | 
|  | 1795 | /* | 
|  | 1796 | *                               Build CLAW read free chain | 
|  | 1797 | * | 
|  | 1798 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | p_buff=privptr->p_buff_read; | 
|  | 1800 | for (i=0 ; i< privptr->p_env->read_buffers ; i++) { | 
|  | 1801 | p_buf        = p_free_chain; | 
|  | 1802 | p_free_chain = p_buf->next; | 
|  | 1803 |  | 
|  | 1804 | if (p_last_CCWB==NULL) { | 
|  | 1805 | p_buf->next=NULL; | 
|  | 1806 | real_TIC_address=0; | 
|  | 1807 | p_last_CCWB=p_buf; | 
|  | 1808 | } | 
|  | 1809 | else { | 
|  | 1810 | p_buf->next=p_first_CCWB; | 
|  | 1811 | real_TIC_address= | 
|  | 1812 | (__u32)__pa(&p_first_CCWB -> read ); | 
|  | 1813 | } | 
|  | 1814 |  | 
|  | 1815 | p_first_CCWB=p_buf; | 
|  | 1816 |  | 
|  | 1817 | p_buf->p_buffer=(struct clawbuf *)p_buff; | 
|  | 1818 | /*  initialize read command */ | 
|  | 1819 | p_buf-> read.cmd_code = CCW_CLAW_CMD_READ; | 
|  | 1820 | p_buf-> read.cda = (__u32)__pa(p_buff); | 
|  | 1821 | p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1822 | p_buf-> read.count       = privptr->p_env->read_size; | 
|  | 1823 |  | 
|  | 1824 | /*  initialize read_h command */ | 
|  | 1825 | p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER; | 
|  | 1826 | p_buf-> read_h.cda = | 
|  | 1827 | (__u32)__pa(&(p_buf->header)); | 
|  | 1828 | p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1829 | p_buf-> read_h.count      = sizeof(struct clawh); | 
|  | 1830 |  | 
|  | 1831 | /*  initialize Signal command */ | 
|  | 1832 | p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD; | 
|  | 1833 | p_buf-> signal.cda = | 
|  | 1834 | (__u32)__pa(&(pClawH->flag)); | 
|  | 1835 | p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1836 | p_buf-> signal.count     = 1; | 
|  | 1837 |  | 
|  | 1838 | /*  initialize r_TIC_1 command */ | 
|  | 1839 | p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; | 
|  | 1840 | p_buf-> r_TIC_1.cda = (__u32)real_TIC_address; | 
|  | 1841 | p_buf-> r_TIC_1.flags = 0; | 
|  | 1842 | p_buf-> r_TIC_1.count      = 0; | 
|  | 1843 |  | 
|  | 1844 | /*  initialize r_read_FF command */ | 
|  | 1845 | p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1846 | p_buf-> r_read_FF.cda = | 
|  | 1847 | (__u32)__pa(&(pClawH->flag)); | 
|  | 1848 | p_buf-> r_read_FF.flags = | 
|  | 1849 | CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI; | 
|  | 1850 | p_buf-> r_read_FF.count    = 1; | 
|  | 1851 |  | 
|  | 1852 | /*    initialize r_TIC_2          */ | 
|  | 1853 | memcpy(&p_buf->r_TIC_2, | 
|  | 1854 | &p_buf->r_TIC_1, sizeof(struct ccw1)); | 
|  | 1855 |  | 
|  | 1856 | /*     initialize Header     */ | 
|  | 1857 | p_buf->header.length=0xffff; | 
|  | 1858 | p_buf->header.opcode=0xff; | 
|  | 1859 | p_buf->header.flag=CLAW_PENDING; | 
|  | 1860 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1861 | if (((unsigned long)p_buff+privptr->p_env->read_size) >= | 
|  | 1862 | ((unsigned long)(p_buff+2*(privptr->p_env->read_size) | 
|  | 1863 | -1) | 
|  | 1864 | & PAGE_MASK)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | p_buff= p_buff+privptr->p_env->read_size; | 
|  | 1866 | } | 
|  | 1867 | else { | 
|  | 1868 | p_buff= | 
|  | 1869 | (void *)((unsigned long) | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1870 | (p_buff+2*(privptr->p_env->read_size)-1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | & PAGE_MASK) ; | 
|  | 1872 | } | 
|  | 1873 | }   /* for read_buffers   */ | 
|  | 1874 | }         /* read_size < PAGE_SIZE  */ | 
|  | 1875 | else {  /* read Size >= PAGE_SIZE  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | for (i=0 ; i< privptr->p_env->read_buffers ; i++) { | 
|  | 1877 | p_buff = (void *)__get_free_pages(__GFP_DMA, | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1878 | (int)pages_to_order_of_mag( | 
|  | 1879 | privptr->p_buff_pages_perread)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | if (p_buff==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | free_pages((unsigned long)privptr->p_buff_ccw, | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1882 | (int)pages_to_order_of_mag(privptr-> | 
|  | 1883 | p_buff_ccw_num)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | /* free the write pages  */ | 
|  | 1885 | p_buf=privptr->p_buff_write; | 
|  | 1886 | while (p_buf!=NULL) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1887 | free_pages( | 
|  | 1888 | (unsigned long)p_buf->p_buffer, | 
|  | 1889 | (int)pages_to_order_of_mag( | 
|  | 1890 | privptr->p_buff_pages_perwrite)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | p_buf=p_buf->next; | 
|  | 1892 | } | 
|  | 1893 | /* free any read pages already alloc  */ | 
|  | 1894 | p_buf=privptr->p_buff_read; | 
|  | 1895 | while (p_buf!=NULL) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1896 | free_pages( | 
|  | 1897 | (unsigned long)p_buf->p_buffer, | 
|  | 1898 | (int)pages_to_order_of_mag( | 
|  | 1899 | privptr->p_buff_pages_perread)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | p_buf=p_buf->next; | 
|  | 1901 | } | 
|  | 1902 | privptr->p_buff_ccw=NULL; | 
|  | 1903 | privptr->p_buff_write=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | return -ENOMEM; | 
|  | 1905 | } | 
|  | 1906 | memset(p_buff, 0x00, privptr->p_env->read_size); | 
|  | 1907 | p_buf        = p_free_chain; | 
|  | 1908 | privptr->p_buff_read = p_buf; | 
|  | 1909 | p_free_chain = p_buf->next; | 
|  | 1910 |  | 
|  | 1911 | if (p_last_CCWB==NULL) { | 
|  | 1912 | p_buf->next=NULL; | 
|  | 1913 | real_TIC_address=0; | 
|  | 1914 | p_last_CCWB=p_buf; | 
|  | 1915 | } | 
|  | 1916 | else { | 
|  | 1917 | p_buf->next=p_first_CCWB; | 
|  | 1918 | real_TIC_address= | 
|  | 1919 | (addr_t)__pa( | 
|  | 1920 | &p_first_CCWB -> read ); | 
|  | 1921 | } | 
|  | 1922 |  | 
|  | 1923 | p_first_CCWB=p_buf; | 
|  | 1924 | /* save buff address */ | 
|  | 1925 | p_buf->p_buffer=(struct clawbuf *)p_buff; | 
|  | 1926 | /*  initialize read command */ | 
|  | 1927 | p_buf-> read.cmd_code = CCW_CLAW_CMD_READ; | 
|  | 1928 | p_buf-> read.cda = (__u32)__pa(p_buff); | 
|  | 1929 | p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1930 | p_buf-> read.count       = privptr->p_env->read_size; | 
|  | 1931 |  | 
|  | 1932 | /*  initialize read_h command */ | 
|  | 1933 | p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER; | 
|  | 1934 | p_buf-> read_h.cda = | 
|  | 1935 | (__u32)__pa(&(p_buf->header)); | 
|  | 1936 | p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1937 | p_buf-> read_h.count      = sizeof(struct clawh); | 
|  | 1938 |  | 
|  | 1939 | /*  initialize Signal command */ | 
|  | 1940 | p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD; | 
|  | 1941 | p_buf-> signal.cda = | 
|  | 1942 | (__u32)__pa(&(pClawH->flag)); | 
|  | 1943 | p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
|  | 1944 | p_buf-> signal.count     = 1; | 
|  | 1945 |  | 
|  | 1946 | /*  initialize r_TIC_1 command */ | 
|  | 1947 | p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; | 
|  | 1948 | p_buf-> r_TIC_1.cda = (__u32)real_TIC_address; | 
|  | 1949 | p_buf-> r_TIC_1.flags = 0; | 
|  | 1950 | p_buf-> r_TIC_1.count      = 0; | 
|  | 1951 |  | 
|  | 1952 | /*  initialize r_read_FF command */ | 
|  | 1953 | p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF; | 
|  | 1954 | p_buf-> r_read_FF.cda = | 
|  | 1955 | (__u32)__pa(&(pClawH->flag)); | 
|  | 1956 | p_buf-> r_read_FF.flags = | 
|  | 1957 | CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI; | 
|  | 1958 | p_buf-> r_read_FF.count    = 1; | 
|  | 1959 |  | 
|  | 1960 | /*    initialize r_TIC_2          */ | 
|  | 1961 | memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1, | 
|  | 1962 | sizeof(struct ccw1)); | 
|  | 1963 |  | 
|  | 1964 | /*     initialize Header     */ | 
|  | 1965 | p_buf->header.length=0xffff; | 
|  | 1966 | p_buf->header.opcode=0xff; | 
|  | 1967 | p_buf->header.flag=CLAW_PENDING; | 
|  | 1968 |  | 
|  | 1969 | }    /* For read_buffers   */ | 
|  | 1970 | }     /*  read_size >= PAGE_SIZE   */ | 
|  | 1971 | }       /*  pBuffread = NULL */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | add_claw_reads( dev  ,p_first_CCWB , p_last_CCWB); | 
|  | 1973 | privptr->buffs_alloc = 1; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1974 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | return 0; | 
|  | 1976 | }    /*    end of init_ccw_bk */ | 
|  | 1977 |  | 
|  | 1978 | /*-------------------------------------------------------------------* | 
|  | 1979 | *                                                                    * | 
|  | 1980 | *       probe_error                                                  * | 
|  | 1981 | *                                                                    * | 
|  | 1982 | *--------------------------------------------------------------------*/ | 
|  | 1983 |  | 
|  | 1984 | static void | 
|  | 1985 | probe_error( struct ccwgroup_device *cgdev) | 
|  | 1986 | { | 
| Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 1987 | struct claw_privbk *privptr; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1988 |  | 
|  | 1989 | CLAW_DBF_TEXT(4, trace, "proberr"); | 
| Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 1990 | privptr = (struct claw_privbk *) cgdev->dev.driver_data; | 
|  | 1991 | if (privptr != NULL) { | 
|  | 1992 | cgdev->dev.driver_data = NULL; | 
| Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 1993 | kfree(privptr->p_env); | 
| Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 1994 | kfree(privptr->p_mtc_envelope); | 
|  | 1995 | kfree(privptr); | 
|  | 1996 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | }    /*    probe_error    */ | 
|  | 1998 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | /*-------------------------------------------------------------------* | 
|  | 2000 | *    claw_process_control                                            * | 
|  | 2001 | *                                                                    * | 
|  | 2002 | *                                                                    * | 
|  | 2003 | *--------------------------------------------------------------------*/ | 
|  | 2004 |  | 
|  | 2005 | static int | 
|  | 2006 | claw_process_control( struct net_device *dev, struct ccwbk * p_ccw) | 
|  | 2007 | { | 
|  | 2008 |  | 
|  | 2009 | struct clawbuf *p_buf; | 
|  | 2010 | struct clawctl  ctlbk; | 
|  | 2011 | struct clawctl *p_ctlbk; | 
|  | 2012 | char    temp_host_name[8]; | 
|  | 2013 | char    temp_ws_name[8]; | 
|  | 2014 | struct claw_privbk *privptr; | 
|  | 2015 | struct claw_env *p_env; | 
|  | 2016 | struct sysval *p_sysval; | 
|  | 2017 | struct conncmd *p_connect=NULL; | 
|  | 2018 | int rc; | 
|  | 2019 | struct chbk *p_ch = NULL; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2020 | struct device *tdev; | 
|  | 2021 | CLAW_DBF_TEXT(2, setup, "clw_cntl"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | udelay(1000);  /* Wait a ms for the control packets to | 
|  | 2023 | *catch up to each other */ | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2024 | privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | p_env=privptr->p_env; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2026 | tdev = &privptr->channel[READ].cdev->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | memcpy( &temp_host_name, p_env->host_name, 8); | 
|  | 2028 | memcpy( &temp_ws_name, p_env->adapter_name , 8); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2029 | dev_info(tdev, "%s: CLAW device %.8s: " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | "Received Control Packet\n", | 
|  | 2031 | dev->name, temp_ws_name); | 
|  | 2032 | if (privptr->release_pend==1) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | return 0; | 
|  | 2034 | } | 
|  | 2035 | p_buf=p_ccw->p_buffer; | 
|  | 2036 | p_ctlbk=&ctlbk; | 
|  | 2037 | if (p_env->packing == DO_PACKED) { /* packing in progress?*/ | 
|  | 2038 | memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl)); | 
|  | 2039 | } else { | 
|  | 2040 | memcpy(p_ctlbk, p_buf, sizeof(struct clawctl)); | 
|  | 2041 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | switch (p_ctlbk->command) | 
|  | 2043 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2044 | case SYSTEM_VALIDATE_REQUEST: | 
|  | 2045 | if (p_ctlbk->version != CLAW_VERSION_ID) { | 
|  | 2046 | claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
|  | 2047 | CLAW_RC_WRONG_VERSION); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2048 | dev_warn(tdev, "The communication peer of %s" | 
|  | 2049 | " uses an incorrect API version %d\n", | 
|  | 2050 | dev->name, p_ctlbk->version); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2051 | } | 
|  | 2052 | p_sysval = (struct sysval *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2053 | dev_info(tdev, "%s: Recv Sys Validate Request: " | 
|  | 2054 | "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s," | 
|  | 2055 | "Host name=%.8s\n", | 
|  | 2056 | dev->name, p_ctlbk->version, | 
|  | 2057 | p_ctlbk->linkid, | 
|  | 2058 | p_ctlbk->correlator, | 
|  | 2059 | p_sysval->WS_name, | 
|  | 2060 | p_sysval->host_name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2061 | if (memcmp(temp_host_name, p_sysval->host_name, 8)) { | 
|  | 2062 | claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
|  | 2063 | CLAW_RC_NAME_MISMATCH); | 
|  | 2064 | CLAW_DBF_TEXT(2, setup, "HSTBAD"); | 
|  | 2065 | CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name); | 
|  | 2066 | CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2067 | dev_warn(tdev, | 
|  | 2068 | "Host name %s for %s does not match the" | 
|  | 2069 | " remote adapter name %s\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2070 | p_sysval->host_name, | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2071 | dev->name, | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2072 | temp_host_name); | 
|  | 2073 | } | 
|  | 2074 | if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) { | 
|  | 2075 | claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
|  | 2076 | CLAW_RC_NAME_MISMATCH); | 
|  | 2077 | CLAW_DBF_TEXT(2, setup, "WSNBAD"); | 
|  | 2078 | CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name); | 
|  | 2079 | CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2080 | dev_warn(tdev, "Adapter name %s for %s does not match" | 
|  | 2081 | " the remote host name %s\n", | 
|  | 2082 | p_sysval->WS_name, | 
|  | 2083 | dev->name, | 
|  | 2084 | temp_ws_name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2085 | } | 
|  | 2086 | if ((p_sysval->write_frame_size < p_env->write_size) && | 
|  | 2087 | (p_env->packing == 0)) { | 
|  | 2088 | claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
|  | 2089 | CLAW_RC_HOST_RCV_TOO_SMALL); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2090 | dev_warn(tdev, | 
|  | 2091 | "The local write buffer is smaller than the" | 
|  | 2092 | " remote read buffer\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2093 | CLAW_DBF_TEXT(2, setup, "wrtszbad"); | 
|  | 2094 | } | 
|  | 2095 | if ((p_sysval->read_frame_size < p_env->read_size) && | 
|  | 2096 | (p_env->packing == 0)) { | 
|  | 2097 | claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
|  | 2098 | CLAW_RC_HOST_RCV_TOO_SMALL); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2099 | dev_warn(tdev, | 
|  | 2100 | "The local read buffer is smaller than the" | 
|  | 2101 | " remote write buffer\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2102 | CLAW_DBF_TEXT(2, setup, "rdsizbad"); | 
|  | 2103 | } | 
|  | 2104 | claw_snd_sys_validate_rsp(dev, p_ctlbk, 0); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2105 | dev_info(tdev, | 
|  | 2106 | "CLAW device %.8s: System validate" | 
|  | 2107 | " completed.\n", temp_ws_name); | 
|  | 2108 | dev_info(tdev, | 
|  | 2109 | "%s: sys Validate Rsize:%d Wsize:%d\n", | 
|  | 2110 | dev->name, p_sysval->read_frame_size, | 
|  | 2111 | p_sysval->write_frame_size); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2112 | privptr->system_validate_comp = 1; | 
|  | 2113 | if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0) | 
|  | 2114 | p_env->packing = PACKING_ASK; | 
|  | 2115 | claw_strt_conn_req(dev); | 
|  | 2116 | break; | 
|  | 2117 | case SYSTEM_VALIDATE_RESPONSE: | 
|  | 2118 | p_sysval = (struct sysval *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2119 | dev_info(tdev, | 
|  | 2120 | "Settings for %s validated (version=%d, " | 
|  | 2121 | "remote device=%d, rc=%d, adapter name=%.8s, " | 
|  | 2122 | "host name=%.8s)\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2123 | dev->name, | 
|  | 2124 | p_ctlbk->version, | 
|  | 2125 | p_ctlbk->correlator, | 
|  | 2126 | p_ctlbk->rc, | 
|  | 2127 | p_sysval->WS_name, | 
|  | 2128 | p_sysval->host_name); | 
|  | 2129 | switch (p_ctlbk->rc) { | 
|  | 2130 | case 0: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2131 | dev_info(tdev, "%s: CLAW device " | 
|  | 2132 | "%.8s: System validate completed.\n", | 
|  | 2133 | dev->name, temp_ws_name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2134 | if (privptr->system_validate_comp == 0) | 
|  | 2135 | claw_strt_conn_req(dev); | 
|  | 2136 | privptr->system_validate_comp = 1; | 
|  | 2137 | break; | 
|  | 2138 | case CLAW_RC_NAME_MISMATCH: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2139 | dev_warn(tdev, "Validating %s failed because of" | 
|  | 2140 | " a host or adapter name mismatch\n", | 
|  | 2141 | dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2142 | break; | 
|  | 2143 | case CLAW_RC_WRONG_VERSION: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2144 | dev_warn(tdev, "Validating %s failed because of a" | 
|  | 2145 | " version conflict\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2146 | dev->name); | 
|  | 2147 | break; | 
|  | 2148 | case CLAW_RC_HOST_RCV_TOO_SMALL: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2149 | dev_warn(tdev, "Validating %s failed because of a" | 
|  | 2150 | " frame size conflict\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2151 | dev->name); | 
|  | 2152 | break; | 
|  | 2153 | default: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2154 | dev_warn(tdev, "The communication peer of %s rejected" | 
|  | 2155 | " the connection\n", | 
|  | 2156 | dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2157 | break; | 
|  | 2158 | } | 
|  | 2159 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2161 | case CONNECTION_REQUEST: | 
|  | 2162 | p_connect = (struct conncmd *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2163 | dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d," | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2164 | "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n", | 
|  | 2165 | dev->name, | 
|  | 2166 | p_ctlbk->version, | 
|  | 2167 | p_ctlbk->linkid, | 
|  | 2168 | p_ctlbk->correlator, | 
|  | 2169 | p_connect->host_name, | 
|  | 2170 | p_connect->WS_name); | 
|  | 2171 | if (privptr->active_link_ID != 0) { | 
|  | 2172 | claw_snd_disc(dev, p_ctlbk); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2173 | dev_info(tdev, "%s rejected a connection request" | 
|  | 2174 | " because it is already active\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2175 | dev->name); | 
|  | 2176 | } | 
|  | 2177 | if (p_ctlbk->linkid != 1) { | 
|  | 2178 | claw_snd_disc(dev, p_ctlbk); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2179 | dev_info(tdev, "%s rejected a request to open multiple" | 
|  | 2180 | " connections\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2181 | dev->name); | 
|  | 2182 | } | 
|  | 2183 | rc = find_link(dev, p_connect->host_name, p_connect->WS_name); | 
|  | 2184 | if (rc != 0) { | 
|  | 2185 | claw_snd_disc(dev, p_ctlbk); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2186 | dev_info(tdev, "%s rejected a connection request" | 
|  | 2187 | " because of a type mismatch\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2188 | dev->name); | 
|  | 2189 | } | 
|  | 2190 | claw_send_control(dev, | 
|  | 2191 | CONNECTION_CONFIRM, p_ctlbk->linkid, | 
|  | 2192 | p_ctlbk->correlator, | 
|  | 2193 | 0, p_connect->host_name, | 
|  | 2194 | p_connect->WS_name); | 
|  | 2195 | if (p_env->packing == PACKING_ASK) { | 
|  | 2196 | p_env->packing = PACK_SEND; | 
|  | 2197 | claw_snd_conn_req(dev, 0); | 
|  | 2198 | } | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2199 | dev_info(tdev, "%s: CLAW device %.8s: Connection " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2200 | "completed link_id=%d.\n", | 
|  | 2201 | dev->name, temp_ws_name, | 
|  | 2202 | p_ctlbk->linkid); | 
|  | 2203 | privptr->active_link_ID = p_ctlbk->linkid; | 
|  | 2204 | p_ch = &privptr->channel[WRITE]; | 
|  | 2205 | wake_up(&p_ch->wait);  /* wake up claw_open ( WRITE) */ | 
|  | 2206 | break; | 
|  | 2207 | case CONNECTION_RESPONSE: | 
|  | 2208 | p_connect = (struct conncmd *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2209 | dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d," | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2210 | "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n", | 
|  | 2211 | dev->name, | 
|  | 2212 | p_ctlbk->version, | 
|  | 2213 | p_ctlbk->linkid, | 
|  | 2214 | p_ctlbk->correlator, | 
|  | 2215 | p_ctlbk->rc, | 
|  | 2216 | p_connect->host_name, | 
|  | 2217 | p_connect->WS_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2219 | if (p_ctlbk->rc != 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2220 | dev_warn(tdev, "The communication peer of %s rejected" | 
|  | 2221 | " a connection request\n", | 
|  | 2222 | dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2223 | return 1; | 
|  | 2224 | } | 
|  | 2225 | rc = find_link(dev, | 
|  | 2226 | p_connect->host_name, p_connect->WS_name); | 
|  | 2227 | if (rc != 0) { | 
|  | 2228 | claw_snd_disc(dev, p_ctlbk); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2229 | dev_warn(tdev, "The communication peer of %s" | 
|  | 2230 | " rejected a connection " | 
|  | 2231 | "request because of a type mismatch\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2232 | dev->name); | 
|  | 2233 | } | 
|  | 2234 | /* should be until CONNECTION_CONFIRM */ | 
|  | 2235 | privptr->active_link_ID = -(p_ctlbk->linkid); | 
|  | 2236 | break; | 
|  | 2237 | case CONNECTION_CONFIRM: | 
|  | 2238 | p_connect = (struct conncmd *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2239 | dev_info(tdev, | 
|  | 2240 | "%s: Recv Conn Confirm:Vers=%d,link_id=%d," | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2241 | "Corr=%d,Host appl=%.8s,WS appl=%.8s\n", | 
|  | 2242 | dev->name, | 
|  | 2243 | p_ctlbk->version, | 
|  | 2244 | p_ctlbk->linkid, | 
|  | 2245 | p_ctlbk->correlator, | 
|  | 2246 | p_connect->host_name, | 
|  | 2247 | p_connect->WS_name); | 
|  | 2248 | if (p_ctlbk->linkid == -(privptr->active_link_ID)) { | 
|  | 2249 | privptr->active_link_ID = p_ctlbk->linkid; | 
|  | 2250 | if (p_env->packing > PACKING_ASK) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2251 | dev_info(tdev, | 
|  | 2252 | "%s: Confirmed Now packing\n", dev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | p_env->packing = DO_PACKED; | 
|  | 2254 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2255 | p_ch = &privptr->channel[WRITE]; | 
|  | 2256 | wake_up(&p_ch->wait); | 
|  | 2257 | } else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2258 | dev_warn(tdev, "Activating %s failed because of" | 
|  | 2259 | " an incorrect link ID=%d\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2260 | dev->name, p_ctlbk->linkid); | 
|  | 2261 | claw_snd_disc(dev, p_ctlbk); | 
|  | 2262 | } | 
|  | 2263 | break; | 
|  | 2264 | case DISCONNECT: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2265 | dev_info(tdev, "%s: Disconnect: " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2266 | "Vers=%d,link_id=%d,Corr=%d\n", | 
|  | 2267 | dev->name, p_ctlbk->version, | 
|  | 2268 | p_ctlbk->linkid, p_ctlbk->correlator); | 
|  | 2269 | if ((p_ctlbk->linkid == 2) && | 
|  | 2270 | (p_env->packing == PACK_SEND)) { | 
|  | 2271 | privptr->active_link_ID = 1; | 
|  | 2272 | p_env->packing = DO_PACKED; | 
|  | 2273 | } else | 
|  | 2274 | privptr->active_link_ID = 0; | 
|  | 2275 | break; | 
|  | 2276 | case CLAW_ERROR: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2277 | dev_warn(tdev, "The communication peer of %s failed\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2278 | dev->name); | 
|  | 2279 | break; | 
|  | 2280 | default: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2281 | dev_warn(tdev, "The communication peer of %s sent" | 
|  | 2282 | " an unknown command code\n", | 
|  | 2283 | dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2284 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | } | 
|  | 2286 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | return 0; | 
|  | 2288 | }   /*    end of claw_process_control    */ | 
|  | 2289 |  | 
|  | 2290 |  | 
|  | 2291 | /*-------------------------------------------------------------------* | 
|  | 2292 | *               claw_send_control                                    * | 
|  | 2293 | *                                                                    * | 
|  | 2294 | *--------------------------------------------------------------------*/ | 
|  | 2295 |  | 
|  | 2296 | static int | 
|  | 2297 | claw_send_control(struct net_device *dev, __u8 type, __u8 link, | 
|  | 2298 | __u8 correlator, __u8 rc, char *local_name, char *remote_name) | 
|  | 2299 | { | 
|  | 2300 | struct claw_privbk 		*privptr; | 
|  | 2301 | struct clawctl                  *p_ctl; | 
|  | 2302 | struct sysval                   *p_sysval; | 
|  | 2303 | struct conncmd                  *p_connect; | 
|  | 2304 | struct sk_buff 			*skb; | 
|  | 2305 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2306 | CLAW_DBF_TEXT(2, setup, "sndcntl"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2307 | privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | p_ctl=(struct clawctl *)&privptr->ctl_bk; | 
|  | 2309 |  | 
|  | 2310 | p_ctl->command=type; | 
|  | 2311 | p_ctl->version=CLAW_VERSION_ID; | 
|  | 2312 | p_ctl->linkid=link; | 
|  | 2313 | p_ctl->correlator=correlator; | 
|  | 2314 | p_ctl->rc=rc; | 
|  | 2315 |  | 
|  | 2316 | p_sysval=(struct sysval *)&p_ctl->data; | 
|  | 2317 | p_connect=(struct conncmd *)&p_ctl->data; | 
|  | 2318 |  | 
|  | 2319 | switch (p_ctl->command) { | 
|  | 2320 | case SYSTEM_VALIDATE_REQUEST: | 
|  | 2321 | case SYSTEM_VALIDATE_RESPONSE: | 
|  | 2322 | memcpy(&p_sysval->host_name, local_name, 8); | 
|  | 2323 | memcpy(&p_sysval->WS_name, remote_name, 8); | 
|  | 2324 | if (privptr->p_env->packing > 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2325 | p_sysval->read_frame_size = DEF_PACK_BUFSIZE; | 
|  | 2326 | p_sysval->write_frame_size = DEF_PACK_BUFSIZE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | } else { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2328 | /* how big is the biggest group of packets */ | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2329 | p_sysval->read_frame_size = | 
|  | 2330 | privptr->p_env->read_size; | 
|  | 2331 | p_sysval->write_frame_size = | 
|  | 2332 | privptr->p_env->write_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | } | 
|  | 2334 | memset(&p_sysval->reserved, 0x00, 4); | 
|  | 2335 | break; | 
|  | 2336 | case CONNECTION_REQUEST: | 
|  | 2337 | case CONNECTION_RESPONSE: | 
|  | 2338 | case CONNECTION_CONFIRM: | 
|  | 2339 | case DISCONNECT: | 
|  | 2340 | memcpy(&p_sysval->host_name, local_name, 8); | 
|  | 2341 | memcpy(&p_sysval->WS_name, remote_name, 8); | 
|  | 2342 | if (privptr->p_env->packing > 0) { | 
|  | 2343 | /* How big is the biggest packet */ | 
|  | 2344 | p_connect->reserved1[0]=CLAW_FRAME_SIZE; | 
|  | 2345 | p_connect->reserved1[1]=CLAW_FRAME_SIZE; | 
|  | 2346 | } else { | 
|  | 2347 | memset(&p_connect->reserved1, 0x00, 4); | 
|  | 2348 | memset(&p_connect->reserved2, 0x00, 4); | 
|  | 2349 | } | 
|  | 2350 | break; | 
|  | 2351 | default: | 
|  | 2352 | break; | 
|  | 2353 | } | 
|  | 2354 |  | 
|  | 2355 | /*      write Control Record to the device                   */ | 
|  | 2356 |  | 
|  | 2357 |  | 
|  | 2358 | skb = dev_alloc_skb(sizeof(struct clawctl)); | 
|  | 2359 | if (!skb) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | return -ENOMEM; | 
|  | 2361 | } | 
|  | 2362 | memcpy(skb_put(skb, sizeof(struct clawctl)), | 
|  | 2363 | p_ctl, sizeof(struct clawctl)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | if (privptr->p_env->packing >= PACK_SEND) | 
|  | 2365 | claw_hw_tx(skb, dev, 1); | 
|  | 2366 | else | 
|  | 2367 | claw_hw_tx(skb, dev, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | return 0; | 
|  | 2369 | }  /*   end of claw_send_control  */ | 
|  | 2370 |  | 
|  | 2371 | /*-------------------------------------------------------------------* | 
|  | 2372 | *               claw_snd_conn_req                                    * | 
|  | 2373 | *                                                                    * | 
|  | 2374 | *--------------------------------------------------------------------*/ | 
|  | 2375 | static int | 
|  | 2376 | claw_snd_conn_req(struct net_device *dev, __u8 link) | 
|  | 2377 | { | 
|  | 2378 | int                rc; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2379 | struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | struct clawctl 	   *p_ctl; | 
|  | 2381 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2382 | CLAW_DBF_TEXT(2, setup, "snd_conn"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | rc = 1; | 
|  | 2384 | p_ctl=(struct clawctl *)&privptr->ctl_bk; | 
|  | 2385 | p_ctl->linkid = link; | 
|  | 2386 | if ( privptr->system_validate_comp==0x00 ) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | return rc; | 
|  | 2388 | } | 
|  | 2389 | if (privptr->p_env->packing == PACKING_ASK ) | 
|  | 2390 | rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, | 
|  | 2391 | WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED); | 
|  | 2392 | if (privptr->p_env->packing == PACK_SEND)  { | 
|  | 2393 | rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, | 
|  | 2394 | WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME); | 
|  | 2395 | } | 
|  | 2396 | if (privptr->p_env->packing == 0) | 
|  | 2397 | rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, | 
|  | 2398 | HOST_APPL_NAME, privptr->p_env->api_type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | return rc; | 
|  | 2400 |  | 
|  | 2401 | }  /*  end of claw_snd_conn_req */ | 
|  | 2402 |  | 
|  | 2403 |  | 
|  | 2404 | /*-------------------------------------------------------------------* | 
|  | 2405 | *               claw_snd_disc                                        * | 
|  | 2406 | *                                                                    * | 
|  | 2407 | *--------------------------------------------------------------------*/ | 
|  | 2408 |  | 
|  | 2409 | static int | 
|  | 2410 | claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl) | 
|  | 2411 | { | 
|  | 2412 | int rc; | 
|  | 2413 | struct conncmd *  p_connect; | 
|  | 2414 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2415 | CLAW_DBF_TEXT(2, setup, "snd_dsc"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | p_connect=(struct conncmd *)&p_ctl->data; | 
|  | 2417 |  | 
|  | 2418 | rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid, | 
|  | 2419 | p_ctl->correlator, 0, | 
|  | 2420 | p_connect->host_name, p_connect->WS_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | return rc; | 
|  | 2422 | }     /*   end of claw_snd_disc    */ | 
|  | 2423 |  | 
|  | 2424 |  | 
|  | 2425 | /*-------------------------------------------------------------------* | 
|  | 2426 | *               claw_snd_sys_validate_rsp                            * | 
|  | 2427 | *                                                                    * | 
|  | 2428 | *--------------------------------------------------------------------*/ | 
|  | 2429 |  | 
|  | 2430 | static int | 
|  | 2431 | claw_snd_sys_validate_rsp(struct net_device *dev, | 
|  | 2432 | struct clawctl *p_ctl, __u32 return_code) | 
|  | 2433 | { | 
|  | 2434 | struct claw_env *  p_env; | 
|  | 2435 | struct claw_privbk *privptr; | 
|  | 2436 | int    rc; | 
|  | 2437 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2438 | CLAW_DBF_TEXT(2, setup, "chkresp"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2439 | privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | p_env=privptr->p_env; | 
|  | 2441 | rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE, | 
|  | 2442 | p_ctl->linkid, | 
|  | 2443 | p_ctl->correlator, | 
|  | 2444 | return_code, | 
|  | 2445 | p_env->host_name, | 
|  | 2446 | p_env->adapter_name  ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | return rc; | 
|  | 2448 | }     /*    end of claw_snd_sys_validate_rsp    */ | 
|  | 2449 |  | 
|  | 2450 | /*-------------------------------------------------------------------* | 
|  | 2451 | *               claw_strt_conn_req                                   * | 
|  | 2452 | *                                                                    * | 
|  | 2453 | *--------------------------------------------------------------------*/ | 
|  | 2454 |  | 
|  | 2455 | static int | 
|  | 2456 | claw_strt_conn_req(struct net_device *dev ) | 
|  | 2457 | { | 
|  | 2458 | int rc; | 
|  | 2459 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2460 | CLAW_DBF_TEXT(2, setup, "conn_req"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | rc=claw_snd_conn_req(dev, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | return rc; | 
|  | 2463 | }    /*   end of claw_strt_conn_req   */ | 
|  | 2464 |  | 
|  | 2465 |  | 
|  | 2466 |  | 
|  | 2467 | /*-------------------------------------------------------------------* | 
|  | 2468 | *   claw_stats                                                      * | 
|  | 2469 | *-------------------------------------------------------------------*/ | 
|  | 2470 |  | 
|  | 2471 | static struct | 
|  | 2472 | net_device_stats *claw_stats(struct net_device *dev) | 
|  | 2473 | { | 
|  | 2474 | struct claw_privbk *privptr; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2475 |  | 
|  | 2476 | CLAW_DBF_TEXT(4, trace, "stats"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2477 | privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | return &privptr->stats; | 
|  | 2479 | }     /*   end of claw_stats   */ | 
|  | 2480 |  | 
|  | 2481 |  | 
|  | 2482 | /*-------------------------------------------------------------------* | 
|  | 2483 | *       unpack_read                                                  * | 
|  | 2484 | *                                                                    * | 
|  | 2485 | *--------------------------------------------------------------------*/ | 
|  | 2486 | static void | 
|  | 2487 | unpack_read(struct net_device *dev ) | 
|  | 2488 | { | 
|  | 2489 | struct sk_buff *skb; | 
|  | 2490 | struct claw_privbk *privptr; | 
|  | 2491 | struct claw_env    *p_env; | 
|  | 2492 | struct ccwbk 	*p_this_ccw; | 
|  | 2493 | struct ccwbk 	*p_first_ccw; | 
|  | 2494 | struct ccwbk 	*p_last_ccw; | 
|  | 2495 | struct clawph 	*p_packh; | 
|  | 2496 | void		*p_packd; | 
|  | 2497 | struct clawctl 	*p_ctlrec=NULL; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2498 | struct device	*p_dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 |  | 
|  | 2500 | __u32	len_of_data; | 
|  | 2501 | __u32	pack_off; | 
|  | 2502 | __u8	link_num; | 
|  | 2503 | __u8 	mtc_this_frm=0; | 
|  | 2504 | __u32	bytes_to_mov; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | int	i=0; | 
|  | 2506 | int     p=0; | 
|  | 2507 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2508 | CLAW_DBF_TEXT(4, trace, "unpkread"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | p_first_ccw=NULL; | 
|  | 2510 | p_last_ccw=NULL; | 
|  | 2511 | p_packh=NULL; | 
|  | 2512 | p_packd=NULL; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2513 | privptr = dev->ml_priv; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2514 |  | 
|  | 2515 | p_dev = &privptr->channel[READ].cdev->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | p_env = privptr->p_env; | 
|  | 2517 | p_this_ccw=privptr->p_read_active_first; | 
|  | 2518 | i=0; | 
|  | 2519 | while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | pack_off = 0; | 
|  | 2521 | p = 0; | 
|  | 2522 | p_this_ccw->header.flag=CLAW_PENDING; | 
|  | 2523 | privptr->p_read_active_first=p_this_ccw->next; | 
|  | 2524 | p_this_ccw->next=NULL; | 
|  | 2525 | p_packh = (struct clawph *)p_this_ccw->p_buffer; | 
|  | 2526 | if ((p_env->packing == PACK_SEND) && | 
|  | 2527 | (p_packh->len == 32)           && | 
|  | 2528 | (p_packh->link_num == 0)) {   /* is it a packed ctl rec? */ | 
|  | 2529 | p_packh++;  /* peek past pack header */ | 
|  | 2530 | p_ctlrec = (struct clawctl *)p_packh; | 
|  | 2531 | p_packh--;  /* un peek */ | 
|  | 2532 | if ((p_ctlrec->command == CONNECTION_RESPONSE) || | 
|  | 2533 | (p_ctlrec->command == CONNECTION_CONFIRM)) | 
|  | 2534 | p_env->packing = DO_PACKED; | 
|  | 2535 | } | 
|  | 2536 | if (p_env->packing == DO_PACKED) | 
|  | 2537 | link_num=p_packh->link_num; | 
|  | 2538 | else | 
|  | 2539 | link_num=p_this_ccw->header.opcode / 8; | 
|  | 2540 | if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | mtc_this_frm=1; | 
|  | 2542 | if (p_this_ccw->header.length!= | 
|  | 2543 | privptr->p_env->read_size ) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2544 | dev_warn(p_dev, | 
|  | 2545 | "The communication peer of %s" | 
|  | 2546 | " sent a faulty" | 
|  | 2547 | " frame of length %02x\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | dev->name, p_this_ccw->header.length); | 
|  | 2549 | } | 
|  | 2550 | } | 
|  | 2551 |  | 
|  | 2552 | if (privptr->mtc_skipping) { | 
|  | 2553 | /* | 
|  | 2554 | *   We're in the mode of skipping past a | 
|  | 2555 | *   multi-frame message | 
|  | 2556 | *   that we can't process for some reason or other. | 
|  | 2557 | *   The first frame without the More-To-Come flag is | 
|  | 2558 | *   the last frame of the skipped message. | 
|  | 2559 | */ | 
|  | 2560 | /*  in case of More-To-Come not set in this frame */ | 
|  | 2561 | if (mtc_this_frm==0) { | 
|  | 2562 | privptr->mtc_skipping=0; /* Ok, the end */ | 
|  | 2563 | privptr->mtc_logical_link=-1; | 
|  | 2564 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | goto NextFrame; | 
|  | 2566 | } | 
|  | 2567 |  | 
|  | 2568 | if (link_num==0) { | 
|  | 2569 | claw_process_control(dev, p_this_ccw); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2570 | CLAW_DBF_TEXT(4, trace, "UnpkCntl"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | goto NextFrame; | 
|  | 2572 | } | 
|  | 2573 | unpack_next: | 
|  | 2574 | if (p_env->packing == DO_PACKED) { | 
|  | 2575 | if (pack_off > p_env->read_size) | 
|  | 2576 | goto NextFrame; | 
|  | 2577 | p_packd = p_this_ccw->p_buffer+pack_off; | 
|  | 2578 | p_packh = (struct clawph *) p_packd; | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2579 | if ((p_packh->len == 0) || /* done with this frame? */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | (p_packh->flag != 0)) | 
|  | 2581 | goto NextFrame; | 
|  | 2582 | bytes_to_mov = p_packh->len; | 
|  | 2583 | pack_off += bytes_to_mov+sizeof(struct clawph); | 
|  | 2584 | p++; | 
|  | 2585 | } else { | 
|  | 2586 | bytes_to_mov=p_this_ccw->header.length; | 
|  | 2587 | } | 
|  | 2588 | if (privptr->mtc_logical_link<0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 |  | 
|  | 2590 | /* | 
|  | 2591 | *  if More-To-Come is set in this frame then we don't know | 
|  | 2592 | *  length of entire message, and hence have to allocate | 
|  | 2593 | *  large buffer   */ | 
|  | 2594 |  | 
|  | 2595 | /*      We are starting a new envelope  */ | 
|  | 2596 | privptr->mtc_offset=0; | 
|  | 2597 | privptr->mtc_logical_link=link_num; | 
|  | 2598 | } | 
|  | 2599 |  | 
|  | 2600 | if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) { | 
|  | 2601 | /*      error     */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | privptr->stats.rx_frame_errors++; | 
|  | 2603 | goto NextFrame; | 
|  | 2604 | } | 
|  | 2605 | if (p_env->packing == DO_PACKED) { | 
|  | 2606 | memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset, | 
|  | 2607 | p_packd+sizeof(struct clawph), bytes_to_mov); | 
|  | 2608 |  | 
|  | 2609 | } else	{ | 
|  | 2610 | memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset, | 
|  | 2611 | p_this_ccw->p_buffer, bytes_to_mov); | 
|  | 2612 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | if (mtc_this_frm==0) { | 
|  | 2614 | len_of_data=privptr->mtc_offset+bytes_to_mov; | 
|  | 2615 | skb=dev_alloc_skb(len_of_data); | 
|  | 2616 | if (skb) { | 
|  | 2617 | memcpy(skb_put(skb,len_of_data), | 
|  | 2618 | privptr->p_mtc_envelope, | 
|  | 2619 | len_of_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | skb->dev=dev; | 
| Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 2621 | skb_reset_mac_header(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | skb->protocol=htons(ETH_P_IP); | 
|  | 2623 | skb->ip_summed=CHECKSUM_UNNECESSARY; | 
|  | 2624 | privptr->stats.rx_packets++; | 
|  | 2625 | privptr->stats.rx_bytes+=len_of_data; | 
|  | 2626 | netif_rx(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | } | 
|  | 2628 | else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2629 | dev_info(p_dev, "Allocating a buffer for" | 
|  | 2630 | " incoming data failed\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | privptr->stats.rx_dropped++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | } | 
|  | 2633 | privptr->mtc_offset=0; | 
|  | 2634 | privptr->mtc_logical_link=-1; | 
|  | 2635 | } | 
|  | 2636 | else { | 
|  | 2637 | privptr->mtc_offset+=bytes_to_mov; | 
|  | 2638 | } | 
|  | 2639 | if (p_env->packing == DO_PACKED) | 
|  | 2640 | goto unpack_next; | 
|  | 2641 | NextFrame: | 
|  | 2642 | /* | 
|  | 2643 | *   Remove ThisCCWblock from active read queue, and add it | 
|  | 2644 | *   to queue of free blocks to be reused. | 
|  | 2645 | */ | 
|  | 2646 | i++; | 
|  | 2647 | p_this_ccw->header.length=0xffff; | 
|  | 2648 | p_this_ccw->header.opcode=0xff; | 
|  | 2649 | /* | 
|  | 2650 | *       add this one to the free queue for later reuse | 
|  | 2651 | */ | 
|  | 2652 | if (p_first_ccw==NULL) { | 
|  | 2653 | p_first_ccw = p_this_ccw; | 
|  | 2654 | } | 
|  | 2655 | else { | 
|  | 2656 | p_last_ccw->next = p_this_ccw; | 
|  | 2657 | } | 
|  | 2658 | p_last_ccw = p_this_ccw; | 
|  | 2659 | /* | 
|  | 2660 | *       chain to next block on active read queue | 
|  | 2661 | */ | 
|  | 2662 | p_this_ccw = privptr->p_read_active_first; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2663 | CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | } /* end of while */ | 
|  | 2665 |  | 
|  | 2666 | /*      check validity                  */ | 
|  | 2667 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2668 | CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | add_claw_reads(dev, p_first_ccw, p_last_ccw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | claw_strt_read(dev, LOCK_YES); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | return; | 
|  | 2672 | }     /*  end of unpack_read   */ | 
|  | 2673 |  | 
|  | 2674 | /*-------------------------------------------------------------------* | 
|  | 2675 | *       claw_strt_read                                               * | 
|  | 2676 | *                                                                    * | 
|  | 2677 | *--------------------------------------------------------------------*/ | 
|  | 2678 | static void | 
|  | 2679 | claw_strt_read (struct net_device *dev, int lock ) | 
|  | 2680 | { | 
|  | 2681 | int        rc = 0; | 
|  | 2682 | __u32      parm; | 
|  | 2683 | unsigned long  saveflags = 0; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2684 | struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | struct ccwbk*p_ccwbk; | 
|  | 2686 | struct chbk *p_ch; | 
|  | 2687 | struct clawh *p_clawh; | 
|  | 2688 | p_ch=&privptr->channel[READ]; | 
|  | 2689 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2690 | CLAW_DBF_TEXT(4, trace, "StRdNter"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | p_clawh=(struct clawh *)privptr->p_claw_signal_blk; | 
|  | 2692 | p_clawh->flag=CLAW_IDLE;    /* 0x00 */ | 
|  | 2693 |  | 
|  | 2694 | if ((privptr->p_write_active_first!=NULL && | 
|  | 2695 | privptr->p_write_active_first->header.flag!=CLAW_PENDING) || | 
|  | 2696 | (privptr->p_read_active_first!=NULL && | 
|  | 2697 | privptr->p_read_active_first->header.flag!=CLAW_PENDING )) { | 
|  | 2698 | p_clawh->flag=CLAW_BUSY;    /* 0xff */ | 
|  | 2699 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | if (lock==LOCK_YES) { | 
|  | 2701 | spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags); | 
|  | 2702 | } | 
|  | 2703 | if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2704 | CLAW_DBF_TEXT(4, trace, "HotRead"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | p_ccwbk=privptr->p_read_active_first; | 
|  | 2706 | parm = (unsigned long) p_ch; | 
|  | 2707 | rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm, | 
|  | 2708 | 0xff, 0); | 
|  | 2709 | if (rc != 0) { | 
|  | 2710 | ccw_check_return_code(p_ch->cdev, rc); | 
|  | 2711 | } | 
|  | 2712 | } | 
|  | 2713 | else { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2714 | CLAW_DBF_TEXT(2, trace, "ReadAct"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | } | 
|  | 2716 |  | 
|  | 2717 | if (lock==LOCK_YES) { | 
|  | 2718 | spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags); | 
|  | 2719 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2720 | CLAW_DBF_TEXT(4, trace, "StRdExit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | return; | 
|  | 2722 | }       /*    end of claw_strt_read    */ | 
|  | 2723 |  | 
|  | 2724 | /*-------------------------------------------------------------------* | 
|  | 2725 | *       claw_strt_out_IO                                             * | 
|  | 2726 | *                                                                    * | 
|  | 2727 | *--------------------------------------------------------------------*/ | 
|  | 2728 |  | 
|  | 2729 | static void | 
|  | 2730 | claw_strt_out_IO( struct net_device *dev ) | 
|  | 2731 | { | 
|  | 2732 | int             	rc = 0; | 
|  | 2733 | unsigned long   	parm; | 
|  | 2734 | struct claw_privbk 	*privptr; | 
|  | 2735 | struct chbk     	*p_ch; | 
|  | 2736 | struct ccwbk   	*p_first_ccw; | 
|  | 2737 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | if (!dev) { | 
|  | 2739 | return; | 
|  | 2740 | } | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2741 | privptr = (struct claw_privbk *)dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | p_ch=&privptr->channel[WRITE]; | 
|  | 2743 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2744 | CLAW_DBF_TEXT(4, trace, "strt_io"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | p_first_ccw=privptr->p_write_active_first; | 
|  | 2746 |  | 
|  | 2747 | if (p_ch->claw_state == CLAW_STOP) | 
|  | 2748 | return; | 
|  | 2749 | if (p_first_ccw == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | return; | 
|  | 2751 | } | 
|  | 2752 | if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) { | 
|  | 2753 | parm = (unsigned long) p_ch; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2754 | CLAW_DBF_TEXT(2, trace, "StWrtIO"); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2755 | rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm, | 
|  | 2756 | 0xff, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | if (rc != 0) { | 
|  | 2758 | ccw_check_return_code(p_ch->cdev, rc); | 
|  | 2759 | } | 
|  | 2760 | } | 
|  | 2761 | dev->trans_start = jiffies; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | return; | 
|  | 2763 | }       /*    end of claw_strt_out_IO    */ | 
|  | 2764 |  | 
|  | 2765 | /*-------------------------------------------------------------------* | 
|  | 2766 | *       Free write buffers                                           * | 
|  | 2767 | *                                                                    * | 
|  | 2768 | *--------------------------------------------------------------------*/ | 
|  | 2769 |  | 
|  | 2770 | static void | 
|  | 2771 | claw_free_wrt_buf( struct net_device *dev ) | 
|  | 2772 | { | 
|  | 2773 |  | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2774 | struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | struct ccwbk*p_first_ccw; | 
|  | 2776 | struct ccwbk*p_last_ccw; | 
|  | 2777 | struct ccwbk*p_this_ccw; | 
|  | 2778 | struct ccwbk*p_next_ccw; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2779 |  | 
|  | 2780 | CLAW_DBF_TEXT(4, trace, "freewrtb"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | /*  scan the write queue to free any completed write packets   */ | 
|  | 2782 | p_first_ccw=NULL; | 
|  | 2783 | p_last_ccw=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | p_this_ccw=privptr->p_write_active_first; | 
|  | 2785 | while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING)) | 
|  | 2786 | { | 
|  | 2787 | p_next_ccw = p_this_ccw->next; | 
|  | 2788 | if (((p_next_ccw!=NULL) && | 
|  | 2789 | (p_next_ccw->header.flag!=CLAW_PENDING)) || | 
|  | 2790 | ((p_this_ccw == privptr->p_write_active_last) && | 
|  | 2791 | (p_this_ccw->header.flag!=CLAW_PENDING))) { | 
|  | 2792 | /* The next CCW is OK or this is  */ | 
|  | 2793 | /* the last CCW...free it   @A1A  */ | 
|  | 2794 | privptr->p_write_active_first=p_this_ccw->next; | 
|  | 2795 | p_this_ccw->header.flag=CLAW_PENDING; | 
|  | 2796 | p_this_ccw->next=privptr->p_write_free_chain; | 
|  | 2797 | privptr->p_write_free_chain=p_this_ccw; | 
|  | 2798 | ++privptr->write_free_count; | 
|  | 2799 | privptr->stats.tx_bytes+= p_this_ccw->write.count; | 
|  | 2800 | p_this_ccw=privptr->p_write_active_first; | 
|  | 2801 | privptr->stats.tx_packets++; | 
|  | 2802 | } | 
|  | 2803 | else { | 
|  | 2804 | break; | 
|  | 2805 | } | 
|  | 2806 | } | 
|  | 2807 | if (privptr->write_free_count!=0) { | 
|  | 2808 | claw_clearbit_busy(TB_NOBUFFER,dev); | 
|  | 2809 | } | 
|  | 2810 | /*   whole chain removed?   */ | 
|  | 2811 | if (privptr->p_write_active_first==NULL) { | 
|  | 2812 | privptr->p_write_active_last=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2814 | CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | return; | 
|  | 2816 | } | 
|  | 2817 |  | 
|  | 2818 | /*-------------------------------------------------------------------* | 
|  | 2819 | *       claw free netdevice                                          * | 
|  | 2820 | *                                                                    * | 
|  | 2821 | *--------------------------------------------------------------------*/ | 
|  | 2822 | static void | 
|  | 2823 | claw_free_netdevice(struct net_device * dev, int free_dev) | 
|  | 2824 | { | 
|  | 2825 | struct claw_privbk *privptr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2827 | CLAW_DBF_TEXT(2, setup, "free_dev"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | if (!dev) | 
|  | 2829 | return; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2830 | CLAW_DBF_TEXT_(2, setup, "%s", dev->name); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2831 | privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | if (dev->flags & IFF_RUNNING) | 
|  | 2833 | claw_release(dev); | 
|  | 2834 | if (privptr) { | 
|  | 2835 | privptr->channel[READ].ndev = NULL;  /* say it's free */ | 
|  | 2836 | } | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2837 | dev->ml_priv = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | #ifdef MODULE | 
|  | 2839 | if (free_dev) { | 
|  | 2840 | free_netdev(dev); | 
|  | 2841 | } | 
|  | 2842 | #endif | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2843 | CLAW_DBF_TEXT(2, setup, "free_ok"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | } | 
|  | 2845 |  | 
|  | 2846 | /** | 
|  | 2847 | * Claw init netdevice | 
|  | 2848 | * Initialize everything of the net device except the name and the | 
|  | 2849 | * channel structs. | 
|  | 2850 | */ | 
| Frank Blaschka | 2171dc1 | 2009-01-09 03:43:59 +0000 | [diff] [blame] | 2851 | static const struct net_device_ops claw_netdev_ops = { | 
|  | 2852 | .ndo_open		= claw_open, | 
|  | 2853 | .ndo_stop		= claw_release, | 
|  | 2854 | .ndo_get_stats		= claw_stats, | 
|  | 2855 | .ndo_start_xmit		= claw_tx, | 
|  | 2856 | .ndo_change_mtu		= claw_change_mtu, | 
|  | 2857 | }; | 
|  | 2858 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | static void | 
|  | 2860 | claw_init_netdevice(struct net_device * dev) | 
|  | 2861 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2862 | CLAW_DBF_TEXT(2, setup, "init_dev"); | 
|  | 2863 | CLAW_DBF_TEXT_(2, setup, "%s", dev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | dev->mtu = CLAW_DEFAULT_MTU_SIZE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | dev->hard_header_len = 0; | 
|  | 2866 | dev->addr_len = 0; | 
|  | 2867 | dev->type = ARPHRD_SLIP; | 
|  | 2868 | dev->tx_queue_len = 1300; | 
|  | 2869 | dev->flags = IFF_POINTOPOINT | IFF_NOARP; | 
| Frank Blaschka | 2171dc1 | 2009-01-09 03:43:59 +0000 | [diff] [blame] | 2870 | dev->netdev_ops = &claw_netdev_ops; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2871 | CLAW_DBF_TEXT(2, setup, "initok"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | return; | 
|  | 2873 | } | 
|  | 2874 |  | 
|  | 2875 | /** | 
|  | 2876 | * Init a new channel in the privptr->channel[i]. | 
|  | 2877 | * | 
|  | 2878 | * @param cdev  The ccw_device to be added. | 
|  | 2879 | * | 
|  | 2880 | * @return 0 on success, !0 on error. | 
|  | 2881 | */ | 
|  | 2882 | static int | 
|  | 2883 | add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr) | 
|  | 2884 | { | 
|  | 2885 | struct chbk *p_ch; | 
| Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2886 | struct ccw_dev_id dev_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 |  | 
| Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2888 | CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | privptr->channel[i].flag  = i+1;   /* Read is 1 Write is 2 */ | 
|  | 2890 | p_ch = &privptr->channel[i]; | 
|  | 2891 | p_ch->cdev = cdev; | 
| Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2892 | snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev)); | 
| Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2893 | ccw_device_get_id(cdev, &dev_id); | 
|  | 2894 | p_ch->devno = dev_id.devno; | 
| Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 2895 | if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | return -ENOMEM; | 
|  | 2897 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | return 0; | 
|  | 2899 | } | 
|  | 2900 |  | 
|  | 2901 |  | 
|  | 2902 | /** | 
|  | 2903 | * | 
|  | 2904 | * Setup an interface. | 
|  | 2905 | * | 
|  | 2906 | * @param cgdev  Device to be setup. | 
|  | 2907 | * | 
|  | 2908 | * @returns 0 on success, !0 on failure. | 
|  | 2909 | */ | 
|  | 2910 | static int | 
|  | 2911 | claw_new_device(struct ccwgroup_device *cgdev) | 
|  | 2912 | { | 
|  | 2913 | struct claw_privbk *privptr; | 
|  | 2914 | struct claw_env *p_env; | 
|  | 2915 | struct net_device *dev; | 
|  | 2916 | int ret; | 
| Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2917 | struct ccw_dev_id dev_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2919 | dev_info(&cgdev->dev, "add for %s\n", | 
|  | 2920 | dev_name(&cgdev->cdev[READ]->dev)); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2921 | CLAW_DBF_TEXT(2, setup, "new_dev"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | privptr = cgdev->dev.driver_data; | 
|  | 2923 | cgdev->cdev[READ]->dev.driver_data = privptr; | 
|  | 2924 | cgdev->cdev[WRITE]->dev.driver_data = privptr; | 
|  | 2925 | if (!privptr) | 
|  | 2926 | return -ENODEV; | 
|  | 2927 | p_env = privptr->p_env; | 
| Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2928 | ccw_device_get_id(cgdev->cdev[READ], &dev_id); | 
|  | 2929 | p_env->devno[READ] = dev_id.devno; | 
|  | 2930 | ccw_device_get_id(cgdev->cdev[WRITE], &dev_id); | 
|  | 2931 | p_env->devno[WRITE] = dev_id.devno; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | ret = add_channel(cgdev->cdev[0],0,privptr); | 
|  | 2933 | if (ret == 0) | 
|  | 2934 | ret = add_channel(cgdev->cdev[1],1,privptr); | 
|  | 2935 | if (ret != 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2936 | dev_warn(&cgdev->dev, "Creating a CLAW group device" | 
|  | 2937 | " failed with error code %d\n", ret); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2938 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | } | 
|  | 2940 | ret = ccw_device_set_online(cgdev->cdev[READ]); | 
|  | 2941 | if (ret != 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2942 | dev_warn(&cgdev->dev, | 
|  | 2943 | "Setting the read subchannel online" | 
|  | 2944 | " failed with error code %d\n", ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | goto out; | 
|  | 2946 | } | 
|  | 2947 | ret = ccw_device_set_online(cgdev->cdev[WRITE]); | 
|  | 2948 | if (ret != 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2949 | dev_warn(&cgdev->dev, | 
|  | 2950 | "Setting the write subchannel online " | 
|  | 2951 | "failed with error code %d\n", ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | goto out; | 
|  | 2953 | } | 
|  | 2954 | dev = alloc_netdev(0,"claw%d",claw_init_netdevice); | 
|  | 2955 | if (!dev) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2956 | dev_warn(&cgdev->dev, | 
|  | 2957 | "Activating the CLAW device failed\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | goto out; | 
|  | 2959 | } | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2960 | dev->ml_priv = privptr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | cgdev->dev.driver_data = privptr; | 
|  | 2962 | cgdev->cdev[READ]->dev.driver_data = privptr; | 
|  | 2963 | cgdev->cdev[WRITE]->dev.driver_data = privptr; | 
|  | 2964 | /* sysfs magic */ | 
|  | 2965 | SET_NETDEV_DEV(dev, &cgdev->dev); | 
|  | 2966 | if (register_netdev(dev) != 0) { | 
|  | 2967 | claw_free_netdevice(dev, 1); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2968 | CLAW_DBF_TEXT(2, trace, "regfail"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | goto out; | 
|  | 2970 | } | 
|  | 2971 | dev->flags &=~IFF_RUNNING; | 
|  | 2972 | if (privptr->buffs_alloc == 0) { | 
|  | 2973 | ret=init_ccw_bk(dev); | 
|  | 2974 | if (ret !=0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | unregister_netdev(dev); | 
|  | 2976 | claw_free_netdevice(dev,1); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2977 | CLAW_DBF_TEXT(2, trace, "ccwmem"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | goto out; | 
|  | 2979 | } | 
|  | 2980 | } | 
|  | 2981 | privptr->channel[READ].ndev = dev; | 
|  | 2982 | privptr->channel[WRITE].ndev = dev; | 
|  | 2983 | privptr->p_env->ndev = dev; | 
|  | 2984 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2985 | dev_info(&cgdev->dev, "%s:readsize=%d  writesize=%d " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n", | 
|  | 2987 | dev->name, p_env->read_size, | 
|  | 2988 | p_env->write_size, p_env->read_buffers, | 
|  | 2989 | p_env->write_buffers, p_env->devno[READ], | 
|  | 2990 | p_env->devno[WRITE]); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2991 | dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | ":%.8s api_type: %.8s\n", | 
|  | 2993 | dev->name, p_env->host_name, | 
|  | 2994 | p_env->adapter_name , p_env->api_type); | 
|  | 2995 | return 0; | 
|  | 2996 | out: | 
|  | 2997 | ccw_device_set_offline(cgdev->cdev[1]); | 
|  | 2998 | ccw_device_set_offline(cgdev->cdev[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | return -ENODEV; | 
|  | 3000 | } | 
|  | 3001 |  | 
|  | 3002 | static void | 
|  | 3003 | claw_purge_skb_queue(struct sk_buff_head *q) | 
|  | 3004 | { | 
|  | 3005 | struct sk_buff *skb; | 
|  | 3006 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3007 | CLAW_DBF_TEXT(4, trace, "purgque"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | while ((skb = skb_dequeue(q))) { | 
|  | 3009 | atomic_dec(&skb->users); | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 3010 | dev_kfree_skb_any(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | } | 
|  | 3012 | } | 
|  | 3013 |  | 
|  | 3014 | /** | 
|  | 3015 | * Shutdown an interface. | 
|  | 3016 | * | 
|  | 3017 | * @param cgdev  Device to be shut down. | 
|  | 3018 | * | 
|  | 3019 | * @returns 0 on success, !0 on failure. | 
|  | 3020 | */ | 
|  | 3021 | static int | 
|  | 3022 | claw_shutdown_device(struct ccwgroup_device *cgdev) | 
|  | 3023 | { | 
|  | 3024 | struct claw_privbk *priv; | 
|  | 3025 | struct net_device *ndev; | 
|  | 3026 | int	ret; | 
|  | 3027 |  | 
| Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 3028 | CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | priv = cgdev->dev.driver_data; | 
|  | 3030 | if (!priv) | 
|  | 3031 | return -ENODEV; | 
|  | 3032 | ndev = priv->channel[READ].ndev; | 
|  | 3033 | if (ndev) { | 
|  | 3034 | /* Close the device */ | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3035 | dev_info(&cgdev->dev, "%s: shutting down \n", | 
|  | 3036 | ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | if (ndev->flags & IFF_RUNNING) | 
|  | 3038 | ret = claw_release(ndev); | 
|  | 3039 | ndev->flags &=~IFF_RUNNING; | 
|  | 3040 | unregister_netdev(ndev); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 3041 | ndev->ml_priv = NULL;  /* cgdev data, not ndev's to free */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | claw_free_netdevice(ndev, 1); | 
|  | 3043 | priv->channel[READ].ndev = NULL; | 
|  | 3044 | priv->channel[WRITE].ndev = NULL; | 
|  | 3045 | priv->p_env->ndev = NULL; | 
|  | 3046 | } | 
|  | 3047 | ccw_device_set_offline(cgdev->cdev[1]); | 
|  | 3048 | ccw_device_set_offline(cgdev->cdev[0]); | 
|  | 3049 | return 0; | 
|  | 3050 | } | 
|  | 3051 |  | 
|  | 3052 | static void | 
|  | 3053 | claw_remove_device(struct ccwgroup_device *cgdev) | 
|  | 3054 | { | 
|  | 3055 | struct claw_privbk *priv; | 
|  | 3056 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3057 | BUG_ON(!cgdev); | 
| Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 3058 | CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | priv = cgdev->dev.driver_data; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3060 | BUG_ON(!priv); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3061 | dev_info(&cgdev->dev, " will be removed.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | if (cgdev->state == CCWGROUP_ONLINE) | 
|  | 3063 | claw_shutdown_device(cgdev); | 
|  | 3064 | claw_remove_files(&cgdev->dev); | 
| Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 3065 | kfree(priv->p_mtc_envelope); | 
|  | 3066 | priv->p_mtc_envelope=NULL; | 
|  | 3067 | kfree(priv->p_env); | 
|  | 3068 | priv->p_env=NULL; | 
|  | 3069 | kfree(priv->channel[0].irb); | 
|  | 3070 | priv->channel[0].irb=NULL; | 
|  | 3071 | kfree(priv->channel[1].irb); | 
|  | 3072 | priv->channel[1].irb=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | kfree(priv); | 
|  | 3074 | cgdev->dev.driver_data=NULL; | 
|  | 3075 | cgdev->cdev[READ]->dev.driver_data = NULL; | 
|  | 3076 | cgdev->cdev[WRITE]->dev.driver_data = NULL; | 
|  | 3077 | put_device(&cgdev->dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3078 |  | 
|  | 3079 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | } | 
|  | 3081 |  | 
|  | 3082 |  | 
|  | 3083 | /* | 
|  | 3084 | * sysfs attributes | 
|  | 3085 | */ | 
|  | 3086 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3087 | claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | { | 
|  | 3089 | struct claw_privbk *priv; | 
|  | 3090 | struct claw_env *  p_env; | 
|  | 3091 |  | 
|  | 3092 | priv = dev->driver_data; | 
|  | 3093 | if (!priv) | 
|  | 3094 | return -ENODEV; | 
|  | 3095 | p_env = priv->p_env; | 
|  | 3096 | return sprintf(buf, "%s\n",p_env->host_name); | 
|  | 3097 | } | 
|  | 3098 |  | 
|  | 3099 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3100 | claw_hname_write(struct device *dev, struct device_attribute *attr, | 
|  | 3101 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | { | 
|  | 3103 | struct claw_privbk *priv; | 
|  | 3104 | struct claw_env *  p_env; | 
|  | 3105 |  | 
|  | 3106 | priv = dev->driver_data; | 
|  | 3107 | if (!priv) | 
|  | 3108 | return -ENODEV; | 
|  | 3109 | p_env = priv->p_env; | 
|  | 3110 | if (count > MAX_NAME_LEN+1) | 
|  | 3111 | return -EINVAL; | 
|  | 3112 | memset(p_env->host_name, 0x20, MAX_NAME_LEN); | 
|  | 3113 | strncpy(p_env->host_name,buf, count); | 
|  | 3114 | p_env->host_name[count-1] = 0x20;  /* clear extra 0x0a */ | 
|  | 3115 | p_env->host_name[MAX_NAME_LEN] = 0x00; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3116 | CLAW_DBF_TEXT(2, setup, "HstnSet"); | 
|  | 3117 | CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 |  | 
|  | 3119 | return count; | 
|  | 3120 | } | 
|  | 3121 |  | 
|  | 3122 | static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write); | 
|  | 3123 |  | 
|  | 3124 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3125 | claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | { | 
|  | 3127 | struct claw_privbk *priv; | 
|  | 3128 | struct claw_env *  p_env; | 
|  | 3129 |  | 
|  | 3130 | priv = dev->driver_data; | 
|  | 3131 | if (!priv) | 
|  | 3132 | return -ENODEV; | 
|  | 3133 | p_env = priv->p_env; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3134 | return sprintf(buf, "%s\n", p_env->adapter_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | } | 
|  | 3136 |  | 
|  | 3137 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3138 | claw_adname_write(struct device *dev, struct device_attribute *attr, | 
|  | 3139 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | { | 
|  | 3141 | struct claw_privbk *priv; | 
|  | 3142 | struct claw_env *  p_env; | 
|  | 3143 |  | 
|  | 3144 | priv = dev->driver_data; | 
|  | 3145 | if (!priv) | 
|  | 3146 | return -ENODEV; | 
|  | 3147 | p_env = priv->p_env; | 
|  | 3148 | if (count > MAX_NAME_LEN+1) | 
|  | 3149 | return -EINVAL; | 
|  | 3150 | memset(p_env->adapter_name, 0x20, MAX_NAME_LEN); | 
|  | 3151 | strncpy(p_env->adapter_name,buf, count); | 
|  | 3152 | p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */ | 
|  | 3153 | p_env->adapter_name[MAX_NAME_LEN] = 0x00; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3154 | CLAW_DBF_TEXT(2, setup, "AdnSet"); | 
|  | 3155 | CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 |  | 
|  | 3157 | return count; | 
|  | 3158 | } | 
|  | 3159 |  | 
|  | 3160 | static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write); | 
|  | 3161 |  | 
|  | 3162 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3163 | claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | { | 
|  | 3165 | struct claw_privbk *priv; | 
|  | 3166 | struct claw_env *  p_env; | 
|  | 3167 |  | 
|  | 3168 | priv = dev->driver_data; | 
|  | 3169 | if (!priv) | 
|  | 3170 | return -ENODEV; | 
|  | 3171 | p_env = priv->p_env; | 
|  | 3172 | return sprintf(buf, "%s\n", | 
|  | 3173 | p_env->api_type); | 
|  | 3174 | } | 
|  | 3175 |  | 
|  | 3176 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3177 | claw_apname_write(struct device *dev, struct device_attribute *attr, | 
|  | 3178 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | { | 
|  | 3180 | struct claw_privbk *priv; | 
|  | 3181 | struct claw_env *  p_env; | 
|  | 3182 |  | 
|  | 3183 | priv = dev->driver_data; | 
|  | 3184 | if (!priv) | 
|  | 3185 | return -ENODEV; | 
|  | 3186 | p_env = priv->p_env; | 
|  | 3187 | if (count > MAX_NAME_LEN+1) | 
|  | 3188 | return -EINVAL; | 
|  | 3189 | memset(p_env->api_type, 0x20, MAX_NAME_LEN); | 
|  | 3190 | strncpy(p_env->api_type,buf, count); | 
|  | 3191 | p_env->api_type[count-1] = 0x20;  /* we get a loose 0x0a */ | 
|  | 3192 | p_env->api_type[MAX_NAME_LEN] = 0x00; | 
|  | 3193 | if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) { | 
|  | 3194 | p_env->read_size=DEF_PACK_BUFSIZE; | 
|  | 3195 | p_env->write_size=DEF_PACK_BUFSIZE; | 
|  | 3196 | p_env->packing=PACKING_ASK; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3197 | CLAW_DBF_TEXT(2, setup, "PACKING"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | } | 
|  | 3199 | else { | 
|  | 3200 | p_env->packing=0; | 
|  | 3201 | p_env->read_size=CLAW_FRAME_SIZE; | 
|  | 3202 | p_env->write_size=CLAW_FRAME_SIZE; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3203 | CLAW_DBF_TEXT(2, setup, "ApiSet"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3205 | CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | return count; | 
|  | 3207 | } | 
|  | 3208 |  | 
|  | 3209 | static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write); | 
|  | 3210 |  | 
|  | 3211 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3212 | claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | { | 
|  | 3214 | struct claw_privbk *priv; | 
|  | 3215 | struct claw_env * p_env; | 
|  | 3216 |  | 
|  | 3217 | priv = dev->driver_data; | 
|  | 3218 | if (!priv) | 
|  | 3219 | return -ENODEV; | 
|  | 3220 | p_env = priv->p_env; | 
|  | 3221 | return sprintf(buf, "%d\n", p_env->write_buffers); | 
|  | 3222 | } | 
|  | 3223 |  | 
|  | 3224 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3225 | claw_wbuff_write(struct device *dev, struct device_attribute *attr, | 
|  | 3226 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | { | 
|  | 3228 | struct claw_privbk *priv; | 
|  | 3229 | struct claw_env *  p_env; | 
|  | 3230 | int nnn,max; | 
|  | 3231 |  | 
|  | 3232 | priv = dev->driver_data; | 
|  | 3233 | if (!priv) | 
|  | 3234 | return -ENODEV; | 
|  | 3235 | p_env = priv->p_env; | 
|  | 3236 | sscanf(buf, "%i", &nnn); | 
|  | 3237 | if (p_env->packing) { | 
|  | 3238 | max = 64; | 
|  | 3239 | } | 
|  | 3240 | else { | 
|  | 3241 | max = 512; | 
|  | 3242 | } | 
|  | 3243 | if ((nnn > max ) || (nnn < 2)) | 
|  | 3244 | return -EINVAL; | 
|  | 3245 | p_env->write_buffers = nnn; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3246 | CLAW_DBF_TEXT(2, setup, "Wbufset"); | 
|  | 3247 | CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | return count; | 
|  | 3249 | } | 
|  | 3250 |  | 
|  | 3251 | static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write); | 
|  | 3252 |  | 
|  | 3253 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3254 | claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | { | 
|  | 3256 | struct claw_privbk *priv; | 
|  | 3257 | struct claw_env *  p_env; | 
|  | 3258 |  | 
|  | 3259 | priv = dev->driver_data; | 
|  | 3260 | if (!priv) | 
|  | 3261 | return -ENODEV; | 
|  | 3262 | p_env = priv->p_env; | 
|  | 3263 | return sprintf(buf, "%d\n", p_env->read_buffers); | 
|  | 3264 | } | 
|  | 3265 |  | 
|  | 3266 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3267 | claw_rbuff_write(struct device *dev, struct device_attribute *attr, | 
|  | 3268 | const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | { | 
|  | 3270 | struct claw_privbk *priv; | 
|  | 3271 | struct claw_env *p_env; | 
|  | 3272 | int nnn,max; | 
|  | 3273 |  | 
|  | 3274 | priv = dev->driver_data; | 
|  | 3275 | if (!priv) | 
|  | 3276 | return -ENODEV; | 
|  | 3277 | p_env = priv->p_env; | 
|  | 3278 | sscanf(buf, "%i", &nnn); | 
|  | 3279 | if (p_env->packing) { | 
|  | 3280 | max = 64; | 
|  | 3281 | } | 
|  | 3282 | else { | 
|  | 3283 | max = 512; | 
|  | 3284 | } | 
|  | 3285 | if ((nnn > max ) || (nnn < 2)) | 
|  | 3286 | return -EINVAL; | 
|  | 3287 | p_env->read_buffers = nnn; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3288 | CLAW_DBF_TEXT(2, setup, "Rbufset"); | 
|  | 3289 | CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | return count; | 
|  | 3291 | } | 
|  | 3292 |  | 
|  | 3293 | static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write); | 
|  | 3294 |  | 
|  | 3295 | static struct attribute *claw_attr[] = { | 
|  | 3296 | &dev_attr_read_buffer.attr, | 
|  | 3297 | &dev_attr_write_buffer.attr, | 
|  | 3298 | &dev_attr_adapter_name.attr, | 
|  | 3299 | &dev_attr_api_type.attr, | 
|  | 3300 | &dev_attr_host_name.attr, | 
|  | 3301 | NULL, | 
|  | 3302 | }; | 
|  | 3303 |  | 
|  | 3304 | static struct attribute_group claw_attr_group = { | 
|  | 3305 | .attrs = claw_attr, | 
|  | 3306 | }; | 
|  | 3307 |  | 
|  | 3308 | static int | 
|  | 3309 | claw_add_files(struct device *dev) | 
|  | 3310 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3311 | CLAW_DBF_TEXT(2, setup, "add_file"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | return sysfs_create_group(&dev->kobj, &claw_attr_group); | 
|  | 3313 | } | 
|  | 3314 |  | 
|  | 3315 | static void | 
|  | 3316 | claw_remove_files(struct device *dev) | 
|  | 3317 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3318 | CLAW_DBF_TEXT(2, setup, "rem_file"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | sysfs_remove_group(&dev->kobj, &claw_attr_group); | 
|  | 3320 | } | 
|  | 3321 |  | 
|  | 3322 | /*--------------------------------------------------------------------* | 
|  | 3323 | *    claw_init  and cleanup                                           * | 
|  | 3324 | *---------------------------------------------------------------------*/ | 
|  | 3325 |  | 
|  | 3326 | static void __exit | 
|  | 3327 | claw_cleanup(void) | 
|  | 3328 | { | 
|  | 3329 | unregister_cu3088_discipline(&claw_group_driver); | 
|  | 3330 | claw_unregister_debug_facility(); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3331 | pr_info("Driver unloaded\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 |  | 
|  | 3333 | } | 
|  | 3334 |  | 
|  | 3335 | /** | 
|  | 3336 | * Initialize module. | 
|  | 3337 | * This is called just after the module is loaded. | 
|  | 3338 | * | 
|  | 3339 | * @return 0 on success, !0 on error. | 
|  | 3340 | */ | 
|  | 3341 | static int __init | 
|  | 3342 | claw_init(void) | 
|  | 3343 | { | 
|  | 3344 | int ret = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3346 | pr_info("Loading %s\n", version); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | ret = claw_register_debug_facility(); | 
|  | 3348 | if (ret) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3349 | pr_err("Registering with the S/390 debug feature" | 
|  | 3350 | " failed with error code %d\n", ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | return ret; | 
|  | 3352 | } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3353 | CLAW_DBF_TEXT(2, setup, "init_mod"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | ret = register_cu3088_discipline(&claw_group_driver); | 
|  | 3355 | if (ret) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3356 | CLAW_DBF_TEXT(2, setup, "init_bad"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | claw_unregister_debug_facility(); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3358 | pr_err("Registering with the cu3088 device driver failed " | 
|  | 3359 | "with error code %d\n", ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | return ret; | 
|  | 3362 | } | 
|  | 3363 |  | 
|  | 3364 | module_init(claw_init); | 
|  | 3365 | module_exit(claw_cleanup); | 
|  | 3366 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3367 | MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>"); | 
|  | 3368 | MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \ | 
|  | 3369 | "Copyright 2000,2008 IBM Corporation\n"); | 
|  | 3370 | MODULE_LICENSE("GPL"); |