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