Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * IUCV network driver |
| 3 | * |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2001, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 6 | * Author(s): |
| 7 | * Original netiucv driver: |
| 8 | * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com) |
| 9 | * Sysfs integration and all bugs therein: |
| 10 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
| 11 | * PM functions: |
| 12 | * Ursula Braun (ursula.braun@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
| 14 | * Documentation used: |
| 15 | * the source of the original IUCV driver by: |
| 16 | * Stefan Hegewald <hegewald@de.ibm.com> |
| 17 | * Hartmut Penner <hpenner@de.ibm.com> |
| 18 | * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
| 19 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 20 | * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000 |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by |
| 24 | * the Free Software Foundation; either version 2, or (at your option) |
| 25 | * any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 37 | |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 38 | #define KMSG_COMPONENT "netiucv" |
| 39 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #undef DEBUG |
| 42 | |
| 43 | #include <linux/module.h> |
| 44 | #include <linux/init.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/slab.h> |
| 47 | #include <linux/errno.h> |
| 48 | #include <linux/types.h> |
| 49 | #include <linux/interrupt.h> |
| 50 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/bitops.h> |
| 52 | |
| 53 | #include <linux/signal.h> |
| 54 | #include <linux/string.h> |
| 55 | #include <linux/device.h> |
| 56 | |
| 57 | #include <linux/ip.h> |
| 58 | #include <linux/if_arp.h> |
| 59 | #include <linux/tcp.h> |
| 60 | #include <linux/skbuff.h> |
| 61 | #include <linux/ctype.h> |
| 62 | #include <net/dst.h> |
| 63 | |
| 64 | #include <asm/io.h> |
| 65 | #include <asm/uaccess.h> |
| 66 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 67 | #include <net/iucv/iucv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include "fsm.h" |
| 69 | |
| 70 | MODULE_AUTHOR |
| 71 | ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)"); |
| 72 | MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver"); |
| 73 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 74 | /** |
| 75 | * Debug Facility stuff |
| 76 | */ |
| 77 | #define IUCV_DBF_SETUP_NAME "iucv_setup" |
| 78 | #define IUCV_DBF_SETUP_LEN 32 |
| 79 | #define IUCV_DBF_SETUP_PAGES 2 |
| 80 | #define IUCV_DBF_SETUP_NR_AREAS 1 |
| 81 | #define IUCV_DBF_SETUP_LEVEL 3 |
| 82 | |
| 83 | #define IUCV_DBF_DATA_NAME "iucv_data" |
| 84 | #define IUCV_DBF_DATA_LEN 128 |
| 85 | #define IUCV_DBF_DATA_PAGES 2 |
| 86 | #define IUCV_DBF_DATA_NR_AREAS 1 |
| 87 | #define IUCV_DBF_DATA_LEVEL 2 |
| 88 | |
| 89 | #define IUCV_DBF_TRACE_NAME "iucv_trace" |
| 90 | #define IUCV_DBF_TRACE_LEN 16 |
| 91 | #define IUCV_DBF_TRACE_PAGES 4 |
| 92 | #define IUCV_DBF_TRACE_NR_AREAS 1 |
| 93 | #define IUCV_DBF_TRACE_LEVEL 3 |
| 94 | |
| 95 | #define IUCV_DBF_TEXT(name,level,text) \ |
| 96 | do { \ |
| 97 | debug_text_event(iucv_dbf_##name,level,text); \ |
| 98 | } while (0) |
| 99 | |
| 100 | #define IUCV_DBF_HEX(name,level,addr,len) \ |
| 101 | do { \ |
| 102 | debug_event(iucv_dbf_##name,level,(void*)(addr),len); \ |
| 103 | } while (0) |
| 104 | |
| 105 | DECLARE_PER_CPU(char[256], iucv_dbf_txt_buf); |
| 106 | |
Peter Tiedemann | f33780d | 2008-02-08 13:09:05 +0100 | [diff] [blame] | 107 | /* Allow to sort out low debug levels early to avoid wasted sprints */ |
| 108 | static inline int iucv_dbf_passes(debug_info_t *dbf_grp, int level) |
| 109 | { |
| 110 | return (level <= dbf_grp->level); |
| 111 | } |
| 112 | |
| 113 | #define IUCV_DBF_TEXT_(name, level, text...) \ |
| 114 | do { \ |
| 115 | if (iucv_dbf_passes(iucv_dbf_##name, level)) { \ |
Tejun Heo | 390dfd9 | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 116 | char* __buf = get_cpu_var(iucv_dbf_txt_buf); \ |
| 117 | sprintf(__buf, text); \ |
| 118 | debug_text_event(iucv_dbf_##name, level, __buf); \ |
Peter Tiedemann | f33780d | 2008-02-08 13:09:05 +0100 | [diff] [blame] | 119 | put_cpu_var(iucv_dbf_txt_buf); \ |
| 120 | } \ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 121 | } while (0) |
| 122 | |
| 123 | #define IUCV_DBF_SPRINTF(name,level,text...) \ |
| 124 | do { \ |
| 125 | debug_sprintf_event(iucv_dbf_trace, level, ##text ); \ |
| 126 | debug_sprintf_event(iucv_dbf_trace, level, text ); \ |
| 127 | } while (0) |
| 128 | |
| 129 | /** |
| 130 | * some more debug stuff |
| 131 | */ |
| 132 | #define IUCV_HEXDUMP16(importance,header,ptr) \ |
| 133 | PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \ |
| 134 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", \ |
| 135 | *(((char*)ptr)),*(((char*)ptr)+1),*(((char*)ptr)+2), \ |
| 136 | *(((char*)ptr)+3),*(((char*)ptr)+4),*(((char*)ptr)+5), \ |
| 137 | *(((char*)ptr)+6),*(((char*)ptr)+7),*(((char*)ptr)+8), \ |
| 138 | *(((char*)ptr)+9),*(((char*)ptr)+10),*(((char*)ptr)+11), \ |
| 139 | *(((char*)ptr)+12),*(((char*)ptr)+13), \ |
| 140 | *(((char*)ptr)+14),*(((char*)ptr)+15)); \ |
| 141 | PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \ |
| 142 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", \ |
| 143 | *(((char*)ptr)+16),*(((char*)ptr)+17), \ |
| 144 | *(((char*)ptr)+18),*(((char*)ptr)+19), \ |
| 145 | *(((char*)ptr)+20),*(((char*)ptr)+21), \ |
| 146 | *(((char*)ptr)+22),*(((char*)ptr)+23), \ |
| 147 | *(((char*)ptr)+24),*(((char*)ptr)+25), \ |
| 148 | *(((char*)ptr)+26),*(((char*)ptr)+27), \ |
| 149 | *(((char*)ptr)+28),*(((char*)ptr)+29), \ |
| 150 | *(((char*)ptr)+30),*(((char*)ptr)+31)); |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | #define PRINTK_HEADER " iucv: " /* for debugging */ |
| 153 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 154 | /* dummy device to make sure netiucv_pm functions are called */ |
| 155 | static struct device *netiucv_dev; |
| 156 | |
| 157 | static int netiucv_pm_prepare(struct device *); |
| 158 | static void netiucv_pm_complete(struct device *); |
| 159 | static int netiucv_pm_freeze(struct device *); |
| 160 | static int netiucv_pm_restore_thaw(struct device *); |
| 161 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 162 | static const struct dev_pm_ops netiucv_pm_ops = { |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 163 | .prepare = netiucv_pm_prepare, |
| 164 | .complete = netiucv_pm_complete, |
| 165 | .freeze = netiucv_pm_freeze, |
| 166 | .thaw = netiucv_pm_restore_thaw, |
| 167 | .restore = netiucv_pm_restore_thaw, |
| 168 | }; |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | static struct device_driver netiucv_driver = { |
Cornelia Huck | 2219510 | 2008-02-08 13:09:02 +0100 | [diff] [blame] | 171 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | .name = "netiucv", |
| 173 | .bus = &iucv_bus, |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 174 | .pm = &netiucv_pm_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 177 | static int netiucv_callback_connreq(struct iucv_path *, |
| 178 | u8 ipvmid[8], u8 ipuser[16]); |
| 179 | static void netiucv_callback_connack(struct iucv_path *, u8 ipuser[16]); |
| 180 | static void netiucv_callback_connrej(struct iucv_path *, u8 ipuser[16]); |
| 181 | static void netiucv_callback_connsusp(struct iucv_path *, u8 ipuser[16]); |
| 182 | static void netiucv_callback_connres(struct iucv_path *, u8 ipuser[16]); |
| 183 | static void netiucv_callback_rx(struct iucv_path *, struct iucv_message *); |
| 184 | static void netiucv_callback_txdone(struct iucv_path *, struct iucv_message *); |
| 185 | |
| 186 | static struct iucv_handler netiucv_handler = { |
| 187 | .path_pending = netiucv_callback_connreq, |
| 188 | .path_complete = netiucv_callback_connack, |
| 189 | .path_severed = netiucv_callback_connrej, |
| 190 | .path_quiesced = netiucv_callback_connsusp, |
| 191 | .path_resumed = netiucv_callback_connres, |
| 192 | .message_pending = netiucv_callback_rx, |
| 193 | .message_complete = netiucv_callback_txdone |
| 194 | }; |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Per connection profiling data |
| 198 | */ |
| 199 | struct connection_profile { |
| 200 | unsigned long maxmulti; |
| 201 | unsigned long maxcqueue; |
| 202 | unsigned long doios_single; |
| 203 | unsigned long doios_multi; |
| 204 | unsigned long txlen; |
| 205 | unsigned long tx_time; |
| 206 | struct timespec send_stamp; |
| 207 | unsigned long tx_pending; |
| 208 | unsigned long tx_max_pending; |
| 209 | }; |
| 210 | |
| 211 | /** |
| 212 | * Representation of one iucv connection |
| 213 | */ |
| 214 | struct iucv_connection { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 215 | struct list_head list; |
| 216 | struct iucv_path *path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | struct sk_buff *rx_buff; |
| 218 | struct sk_buff *tx_buff; |
| 219 | struct sk_buff_head collect_queue; |
| 220 | struct sk_buff_head commit_queue; |
| 221 | spinlock_t collect_lock; |
| 222 | int collect_len; |
| 223 | int max_buffsize; |
| 224 | fsm_timer timer; |
| 225 | fsm_instance *fsm; |
| 226 | struct net_device *netdev; |
| 227 | struct connection_profile prof; |
| 228 | char userid[9]; |
| 229 | }; |
| 230 | |
| 231 | /** |
| 232 | * Linked list of all connection structs. |
| 233 | */ |
Denis Cheng | c11ca97 | 2008-01-26 14:11:13 +0100 | [diff] [blame] | 234 | static LIST_HEAD(iucv_connection_list); |
Thomas Gleixner | bfac0d0 | 2007-06-20 13:02:55 +0200 | [diff] [blame] | 235 | static DEFINE_RWLOCK(iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * Representation of event-data for the |
| 239 | * connection state machine. |
| 240 | */ |
| 241 | struct iucv_event { |
| 242 | struct iucv_connection *conn; |
| 243 | void *data; |
| 244 | }; |
| 245 | |
| 246 | /** |
| 247 | * Private part of the network device structure |
| 248 | */ |
| 249 | struct netiucv_priv { |
| 250 | struct net_device_stats stats; |
| 251 | unsigned long tbusy; |
| 252 | fsm_instance *fsm; |
| 253 | struct iucv_connection *conn; |
| 254 | struct device *dev; |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 255 | int pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | /** |
| 259 | * Link level header for a packet. |
| 260 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 261 | struct ll_header { |
| 262 | u16 next; |
| 263 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 265 | #define NETIUCV_HDRLEN (sizeof(struct ll_header)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | #define NETIUCV_BUFSIZE_MAX 32768 |
| 267 | #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX |
| 268 | #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN) |
| 269 | #define NETIUCV_MTU_DEFAULT 9216 |
| 270 | #define NETIUCV_QUEUELEN_DEFAULT 50 |
| 271 | #define NETIUCV_TIMEOUT_5SEC 5000 |
| 272 | |
| 273 | /** |
| 274 | * Compatibility macros for busy handling |
| 275 | * of network devices. |
| 276 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 277 | static inline void netiucv_clear_busy(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 279 | struct netiucv_priv *priv = netdev_priv(dev); |
| 280 | clear_bit(0, &priv->tbusy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | netif_wake_queue(dev); |
| 282 | } |
| 283 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 284 | static inline int netiucv_test_and_set_busy(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 286 | struct netiucv_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | netif_stop_queue(dev); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 288 | return test_and_set_bit(0, &priv->tbusy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 291 | static u8 iucvMagic[16] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
| 293 | 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 |
| 294 | }; |
| 295 | |
| 296 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | * Convert an iucv userId to its printable |
| 298 | * form (strip whitespace at end). |
| 299 | * |
| 300 | * @param An iucv userId |
| 301 | * |
| 302 | * @returns The printable string (static data!!) |
| 303 | */ |
Martin Schwidefsky | d461462 | 2007-06-20 13:03:57 +0200 | [diff] [blame] | 304 | static char *netiucv_printname(char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
| 306 | static char tmp[9]; |
| 307 | char *p = tmp; |
| 308 | memcpy(tmp, name, 8); |
| 309 | tmp[8] = '\0'; |
| 310 | while (*p && (!isspace(*p))) |
| 311 | p++; |
| 312 | *p = '\0'; |
| 313 | return tmp; |
| 314 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /** |
| 317 | * States of the interface statemachine. |
| 318 | */ |
| 319 | enum dev_states { |
| 320 | DEV_STATE_STOPPED, |
| 321 | DEV_STATE_STARTWAIT, |
| 322 | DEV_STATE_STOPWAIT, |
| 323 | DEV_STATE_RUNNING, |
| 324 | /** |
| 325 | * MUST be always the last element!! |
| 326 | */ |
| 327 | NR_DEV_STATES |
| 328 | }; |
| 329 | |
| 330 | static const char *dev_state_names[] = { |
| 331 | "Stopped", |
| 332 | "StartWait", |
| 333 | "StopWait", |
| 334 | "Running", |
| 335 | }; |
| 336 | |
| 337 | /** |
| 338 | * Events of the interface statemachine. |
| 339 | */ |
| 340 | enum dev_events { |
| 341 | DEV_EVENT_START, |
| 342 | DEV_EVENT_STOP, |
| 343 | DEV_EVENT_CONUP, |
| 344 | DEV_EVENT_CONDOWN, |
| 345 | /** |
| 346 | * MUST be always the last element!! |
| 347 | */ |
| 348 | NR_DEV_EVENTS |
| 349 | }; |
| 350 | |
| 351 | static const char *dev_event_names[] = { |
| 352 | "Start", |
| 353 | "Stop", |
| 354 | "Connection up", |
| 355 | "Connection down", |
| 356 | }; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /** |
| 359 | * Events of the connection statemachine |
| 360 | */ |
| 361 | enum conn_events { |
| 362 | /** |
| 363 | * Events, representing callbacks from |
| 364 | * lowlevel iucv layer) |
| 365 | */ |
| 366 | CONN_EVENT_CONN_REQ, |
| 367 | CONN_EVENT_CONN_ACK, |
| 368 | CONN_EVENT_CONN_REJ, |
| 369 | CONN_EVENT_CONN_SUS, |
| 370 | CONN_EVENT_CONN_RES, |
| 371 | CONN_EVENT_RX, |
| 372 | CONN_EVENT_TXDONE, |
| 373 | |
| 374 | /** |
| 375 | * Events, representing errors return codes from |
| 376 | * calls to lowlevel iucv layer |
| 377 | */ |
| 378 | |
| 379 | /** |
| 380 | * Event, representing timer expiry. |
| 381 | */ |
| 382 | CONN_EVENT_TIMER, |
| 383 | |
| 384 | /** |
| 385 | * Events, representing commands from upper levels. |
| 386 | */ |
| 387 | CONN_EVENT_START, |
| 388 | CONN_EVENT_STOP, |
| 389 | |
| 390 | /** |
| 391 | * MUST be always the last element!! |
| 392 | */ |
| 393 | NR_CONN_EVENTS, |
| 394 | }; |
| 395 | |
| 396 | static const char *conn_event_names[] = { |
| 397 | "Remote connection request", |
| 398 | "Remote connection acknowledge", |
| 399 | "Remote connection reject", |
| 400 | "Connection suspended", |
| 401 | "Connection resumed", |
| 402 | "Data received", |
| 403 | "Data sent", |
| 404 | |
| 405 | "Timer", |
| 406 | |
| 407 | "Start", |
| 408 | "Stop", |
| 409 | }; |
| 410 | |
| 411 | /** |
| 412 | * States of the connection statemachine. |
| 413 | */ |
| 414 | enum conn_states { |
| 415 | /** |
| 416 | * Connection not assigned to any device, |
| 417 | * initial state, invalid |
| 418 | */ |
| 419 | CONN_STATE_INVALID, |
| 420 | |
| 421 | /** |
| 422 | * Userid assigned but not operating |
| 423 | */ |
| 424 | CONN_STATE_STOPPED, |
| 425 | |
| 426 | /** |
| 427 | * Connection registered, |
| 428 | * no connection request sent yet, |
| 429 | * no connection request received |
| 430 | */ |
| 431 | CONN_STATE_STARTWAIT, |
| 432 | |
| 433 | /** |
| 434 | * Connection registered and connection request sent, |
| 435 | * no acknowledge and no connection request received yet. |
| 436 | */ |
| 437 | CONN_STATE_SETUPWAIT, |
| 438 | |
| 439 | /** |
| 440 | * Connection up and running idle |
| 441 | */ |
| 442 | CONN_STATE_IDLE, |
| 443 | |
| 444 | /** |
| 445 | * Data sent, awaiting CONN_EVENT_TXDONE |
| 446 | */ |
| 447 | CONN_STATE_TX, |
| 448 | |
| 449 | /** |
| 450 | * Error during registration. |
| 451 | */ |
| 452 | CONN_STATE_REGERR, |
| 453 | |
| 454 | /** |
| 455 | * Error during registration. |
| 456 | */ |
| 457 | CONN_STATE_CONNERR, |
| 458 | |
| 459 | /** |
| 460 | * MUST be always the last element!! |
| 461 | */ |
| 462 | NR_CONN_STATES, |
| 463 | }; |
| 464 | |
| 465 | static const char *conn_state_names[] = { |
| 466 | "Invalid", |
| 467 | "Stopped", |
| 468 | "StartWait", |
| 469 | "SetupWait", |
| 470 | "Idle", |
| 471 | "TX", |
| 472 | "Terminating", |
| 473 | "Registration error", |
| 474 | "Connect error", |
| 475 | }; |
| 476 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | /** |
| 479 | * Debug Facility Stuff |
| 480 | */ |
| 481 | static debug_info_t *iucv_dbf_setup = NULL; |
| 482 | static debug_info_t *iucv_dbf_data = NULL; |
| 483 | static debug_info_t *iucv_dbf_trace = NULL; |
| 484 | |
| 485 | DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf); |
| 486 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 487 | static void iucv_unregister_dbf_views(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
| 489 | if (iucv_dbf_setup) |
| 490 | debug_unregister(iucv_dbf_setup); |
| 491 | if (iucv_dbf_data) |
| 492 | debug_unregister(iucv_dbf_data); |
| 493 | if (iucv_dbf_trace) |
| 494 | debug_unregister(iucv_dbf_trace); |
| 495 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 496 | static int iucv_register_dbf_views(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
| 498 | iucv_dbf_setup = debug_register(IUCV_DBF_SETUP_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 499 | IUCV_DBF_SETUP_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | IUCV_DBF_SETUP_NR_AREAS, |
| 501 | IUCV_DBF_SETUP_LEN); |
| 502 | iucv_dbf_data = debug_register(IUCV_DBF_DATA_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 503 | IUCV_DBF_DATA_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | IUCV_DBF_DATA_NR_AREAS, |
| 505 | IUCV_DBF_DATA_LEN); |
| 506 | iucv_dbf_trace = debug_register(IUCV_DBF_TRACE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 507 | IUCV_DBF_TRACE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | IUCV_DBF_TRACE_NR_AREAS, |
| 509 | IUCV_DBF_TRACE_LEN); |
| 510 | |
| 511 | if ((iucv_dbf_setup == NULL) || (iucv_dbf_data == NULL) || |
| 512 | (iucv_dbf_trace == NULL)) { |
| 513 | iucv_unregister_dbf_views(); |
| 514 | return -ENOMEM; |
| 515 | } |
| 516 | debug_register_view(iucv_dbf_setup, &debug_hex_ascii_view); |
| 517 | debug_set_level(iucv_dbf_setup, IUCV_DBF_SETUP_LEVEL); |
| 518 | |
| 519 | debug_register_view(iucv_dbf_data, &debug_hex_ascii_view); |
| 520 | debug_set_level(iucv_dbf_data, IUCV_DBF_DATA_LEVEL); |
| 521 | |
| 522 | debug_register_view(iucv_dbf_trace, &debug_hex_ascii_view); |
| 523 | debug_set_level(iucv_dbf_trace, IUCV_DBF_TRACE_LEVEL); |
| 524 | |
| 525 | return 0; |
| 526 | } |
| 527 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 528 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | * Callback-wrappers, called from lowlevel iucv layer. |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 530 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 532 | static void netiucv_callback_rx(struct iucv_path *path, |
| 533 | struct iucv_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 535 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | struct iucv_event ev; |
| 537 | |
| 538 | ev.conn = conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 539 | ev.data = msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | fsm_event(conn->fsm, CONN_EVENT_RX, &ev); |
| 541 | } |
| 542 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 543 | static void netiucv_callback_txdone(struct iucv_path *path, |
| 544 | struct iucv_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 546 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | struct iucv_event ev; |
| 548 | |
| 549 | ev.conn = conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 550 | ev.data = msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev); |
| 552 | } |
| 553 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 554 | static void netiucv_callback_connack(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 556 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 558 | fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 561 | static int netiucv_callback_connreq(struct iucv_path *path, |
| 562 | u8 ipvmid[8], u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 564 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | struct iucv_event ev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 566 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Stefan Weil | 5df979d | 2011-02-02 06:04:35 +0000 | [diff] [blame] | 568 | if (memcmp(iucvMagic, ipuser, 16)) |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 569 | /* ipuser must match iucvMagic. */ |
| 570 | return -EINVAL; |
| 571 | rc = -EINVAL; |
| 572 | read_lock_bh(&iucv_connection_rwlock); |
| 573 | list_for_each_entry(conn, &iucv_connection_list, list) { |
| 574 | if (strncmp(ipvmid, conn->userid, 8)) |
| 575 | continue; |
| 576 | /* Found a matching connection for this path. */ |
| 577 | conn->path = path; |
| 578 | ev.conn = conn; |
| 579 | ev.data = path; |
| 580 | fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev); |
| 581 | rc = 0; |
| 582 | } |
| 583 | read_unlock_bh(&iucv_connection_rwlock); |
| 584 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 587 | static void netiucv_callback_connrej(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 589 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 591 | fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 594 | static void netiucv_callback_connsusp(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 596 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 598 | fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 601 | static void netiucv_callback_connres(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 603 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 605 | fsm_event(conn->fsm, CONN_EVENT_CONN_RES, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | /** |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 609 | * NOP action for statemachines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | */ |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 611 | static void netiucv_action_nop(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
| 613 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 614 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 615 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | * Actions of the connection statemachine |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 617 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 620 | * netiucv_unpack_skb |
| 621 | * @conn: The connection where this skb has been received. |
| 622 | * @pskb: The received skb. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 624 | * Unpack a just received skb and hand it over to upper layers. |
| 625 | * Helper function for conn_action_rx. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 627 | static void netiucv_unpack_skb(struct iucv_connection *conn, |
| 628 | struct sk_buff *pskb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | { |
| 630 | struct net_device *dev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 631 | struct netiucv_priv *privptr = netdev_priv(dev); |
| 632 | u16 offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
| 634 | skb_put(pskb, NETIUCV_HDRLEN); |
| 635 | pskb->dev = dev; |
| 636 | pskb->ip_summed = CHECKSUM_NONE; |
| 637 | pskb->protocol = ntohs(ETH_P_IP); |
| 638 | |
| 639 | while (1) { |
| 640 | struct sk_buff *skb; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 641 | struct ll_header *header = (struct ll_header *) pskb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | if (!header->next) |
| 644 | break; |
| 645 | |
| 646 | skb_pull(pskb, NETIUCV_HDRLEN); |
| 647 | header->next -= offset; |
| 648 | offset += header->next; |
| 649 | header->next -= NETIUCV_HDRLEN; |
| 650 | if (skb_tailroom(pskb) < header->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | IUCV_DBF_TEXT_(data, 2, "Illegal next field: %d > %d\n", |
| 652 | header->next, skb_tailroom(pskb)); |
| 653 | return; |
| 654 | } |
| 655 | skb_put(pskb, header->next); |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 656 | skb_reset_mac_header(pskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | skb = dev_alloc_skb(pskb->len); |
| 658 | if (!skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | IUCV_DBF_TEXT(data, 2, |
| 660 | "Out of memory in netiucv_unpack_skb\n"); |
| 661 | privptr->stats.rx_dropped++; |
| 662 | return; |
| 663 | } |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 664 | skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len), |
| 665 | pskb->len); |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 666 | skb_reset_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | skb->dev = pskb->dev; |
| 668 | skb->protocol = pskb->protocol; |
| 669 | pskb->ip_summed = CHECKSUM_UNNECESSARY; |
Julia Lawall | 9b3efc0 | 2007-12-10 17:17:37 -0800 | [diff] [blame] | 670 | privptr->stats.rx_packets++; |
| 671 | privptr->stats.rx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | /* |
| 673 | * Since receiving is always initiated from a tasklet (in iucv.c), |
| 674 | * we must use netif_rx_ni() instead of netif_rx() |
| 675 | */ |
| 676 | netif_rx_ni(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | skb_pull(pskb, header->next); |
| 678 | skb_put(pskb, NETIUCV_HDRLEN); |
| 679 | } |
| 680 | } |
| 681 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 682 | static void conn_action_rx(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 684 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 686 | struct iucv_message *msg = ev->data; |
| 687 | struct netiucv_priv *privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | int rc; |
| 689 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 690 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
| 692 | if (!conn->netdev) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 693 | iucv_message_reject(conn->path, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 695 | "Received data for unlinked connection\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | return; |
| 697 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 698 | if (msg->length > conn->max_buffsize) { |
| 699 | iucv_message_reject(conn->path, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | privptr->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | IUCV_DBF_TEXT_(data, 2, "msglen %d > max_buffsize %d\n", |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 702 | msg->length, conn->max_buffsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | return; |
| 704 | } |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 705 | conn->rx_buff->data = conn->rx_buff->head; |
| 706 | skb_reset_tail_pointer(conn->rx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | conn->rx_buff->len = 0; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 708 | rc = iucv_message_receive(conn->path, msg, 0, conn->rx_buff->data, |
| 709 | msg->length, NULL); |
| 710 | if (rc || msg->length < 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | privptr->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_receive\n", rc); |
| 713 | return; |
| 714 | } |
| 715 | netiucv_unpack_skb(conn, conn->rx_buff); |
| 716 | } |
| 717 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 718 | static void conn_action_txdone(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 720 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 722 | struct iucv_message *msg = ev->data; |
| 723 | struct iucv_message txmsg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | struct netiucv_priv *privptr = NULL; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 725 | u32 single_flag = msg->tag; |
| 726 | u32 txbytes = 0; |
| 727 | u32 txpackets = 0; |
| 728 | u32 stat_maxcq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | struct sk_buff *skb; |
| 730 | unsigned long saveflags; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 731 | struct ll_header header; |
| 732 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 734 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 736 | if (conn && conn->netdev) |
| 737 | privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | conn->prof.tx_pending--; |
| 739 | if (single_flag) { |
| 740 | if ((skb = skb_dequeue(&conn->commit_queue))) { |
| 741 | atomic_dec(&skb->users); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | if (privptr) { |
| 743 | privptr->stats.tx_packets++; |
| 744 | privptr->stats.tx_bytes += |
| 745 | (skb->len - NETIUCV_HDRLEN |
Ursula Braun | 998221c | 2009-11-12 21:46:30 +0000 | [diff] [blame] | 746 | - NETIUCV_HDRLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
Ursula Braun | 998221c | 2009-11-12 21:46:30 +0000 | [diff] [blame] | 748 | dev_kfree_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | } |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 751 | conn->tx_buff->data = conn->tx_buff->head; |
| 752 | skb_reset_tail_pointer(conn->tx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | conn->tx_buff->len = 0; |
| 754 | spin_lock_irqsave(&conn->collect_lock, saveflags); |
| 755 | while ((skb = skb_dequeue(&conn->collect_queue))) { |
| 756 | header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN; |
| 757 | memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, |
| 758 | NETIUCV_HDRLEN); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 759 | skb_copy_from_linear_data(skb, |
| 760 | skb_put(conn->tx_buff, skb->len), |
| 761 | skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | txbytes += skb->len; |
| 763 | txpackets++; |
| 764 | stat_maxcq++; |
| 765 | atomic_dec(&skb->users); |
| 766 | dev_kfree_skb_any(skb); |
| 767 | } |
| 768 | if (conn->collect_len > conn->prof.maxmulti) |
| 769 | conn->prof.maxmulti = conn->collect_len; |
| 770 | conn->collect_len = 0; |
| 771 | spin_unlock_irqrestore(&conn->collect_lock, saveflags); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 772 | if (conn->tx_buff->len == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | |
| 777 | header.next = 0; |
| 778 | memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
john stultz | 2c6b47d | 2007-07-24 17:47:43 -0700 | [diff] [blame] | 779 | conn->prof.send_stamp = current_kernel_time(); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 780 | txmsg.class = 0; |
| 781 | txmsg.tag = 0; |
| 782 | rc = iucv_message_send(conn->path, &txmsg, 0, 0, |
| 783 | conn->tx_buff->data, conn->tx_buff->len); |
| 784 | conn->prof.doios_multi++; |
| 785 | conn->prof.txlen += conn->tx_buff->len; |
| 786 | conn->prof.tx_pending++; |
| 787 | if (conn->prof.tx_pending > conn->prof.tx_max_pending) |
| 788 | conn->prof.tx_max_pending = conn->prof.tx_pending; |
| 789 | if (rc) { |
| 790 | conn->prof.tx_pending--; |
| 791 | fsm_newstate(fi, CONN_STATE_IDLE); |
| 792 | if (privptr) |
| 793 | privptr->stats.tx_errors += txpackets; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 794 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc); |
| 795 | } else { |
| 796 | if (privptr) { |
| 797 | privptr->stats.tx_packets += txpackets; |
| 798 | privptr->stats.tx_bytes += txbytes; |
| 799 | } |
| 800 | if (stat_maxcq > conn->prof.maxcqueue) |
| 801 | conn->prof.maxcqueue = stat_maxcq; |
| 802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 805 | static void conn_action_connaccept(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 807 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 809 | struct iucv_path *path = ev->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 811 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 814 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 816 | conn->path = path; |
| 817 | path->msglim = NETIUCV_QUEUELEN_DEFAULT; |
| 818 | path->flags = 0; |
| 819 | rc = iucv_path_accept(path, &netiucv_handler, NULL, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | IUCV_DBF_TEXT_(setup, 2, "rc %d from iucv_accept", rc); |
| 822 | return; |
| 823 | } |
| 824 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 825 | netdev->tx_queue_len = conn->path->msglim; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev); |
| 827 | } |
| 828 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 829 | static void conn_action_connreject(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 831 | struct iucv_event *ev = arg; |
| 832 | struct iucv_path *path = ev->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 834 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 835 | iucv_path_sever(path, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 838 | static void conn_action_connack(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 840 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 842 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 844 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | fsm_deltimer(&conn->timer); |
| 846 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 847 | netdev->tx_queue_len = conn->path->msglim; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev); |
| 849 | } |
| 850 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 851 | static void conn_action_conntimsev(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 853 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 855 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | fsm_deltimer(&conn->timer); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 857 | iucv_path_sever(conn->path, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 859 | } |
| 860 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 861 | static void conn_action_connsever(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 863 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 865 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 867 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
| 869 | fsm_deltimer(&conn->timer); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 870 | iucv_path_sever(conn->path, NULL); |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 871 | dev_info(privptr->dev, "The peer interface of the IUCV device" |
| 872 | " has closed the connection\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 874 | "conn_action_connsever: Remote dropped connection\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 876 | fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev); |
| 877 | } |
| 878 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 879 | static void conn_action_start(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 881 | struct iucv_connection *conn = arg; |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 882 | struct net_device *netdev = conn->netdev; |
| 883 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | int rc; |
| 885 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 886 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 888 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 889 | IUCV_DBF_TEXT_(setup, 2, "%s('%s'): connecting ...\n", |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 890 | netdev->name, conn->userid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 892 | /* |
| 893 | * We must set the state before calling iucv_connect because the |
| 894 | * callback handler could be called at any point after the connection |
| 895 | * request is sent |
| 896 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
| 898 | fsm_newstate(fi, CONN_STATE_SETUPWAIT); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 899 | conn->path = iucv_path_alloc(NETIUCV_QUEUELEN_DEFAULT, 0, GFP_KERNEL); |
| 900 | rc = iucv_path_connect(conn->path, &netiucv_handler, conn->userid, |
| 901 | NULL, iucvMagic, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | switch (rc) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 903 | case 0: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 904 | netdev->tx_queue_len = conn->path->msglim; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 905 | fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC, |
| 906 | CONN_EVENT_TIMER, conn); |
| 907 | return; |
| 908 | case 11: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 909 | dev_warn(privptr->dev, |
| 910 | "The IUCV device failed to connect to z/VM guest %s\n", |
| 911 | netiucv_printname(conn->userid)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 912 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 913 | break; |
| 914 | case 12: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 915 | dev_warn(privptr->dev, |
| 916 | "The IUCV device failed to connect to the peer on z/VM" |
| 917 | " guest %s\n", netiucv_printname(conn->userid)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 918 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 919 | break; |
| 920 | case 13: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 921 | dev_err(privptr->dev, |
| 922 | "Connecting the IUCV device would exceed the maximum" |
| 923 | " number of IUCV connections\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 924 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 925 | break; |
| 926 | case 14: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 927 | dev_err(privptr->dev, |
| 928 | "z/VM guest %s has too many IUCV connections" |
| 929 | " to connect with the IUCV device\n", |
| 930 | netiucv_printname(conn->userid)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 931 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 932 | break; |
| 933 | case 15: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 934 | dev_err(privptr->dev, |
| 935 | "The IUCV device cannot connect to a z/VM guest with no" |
| 936 | " IUCV authorization\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 937 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 938 | break; |
| 939 | default: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 940 | dev_err(privptr->dev, |
| 941 | "Connecting the IUCV device failed with error %d\n", |
| 942 | rc); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 943 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 944 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | } |
| 946 | IUCV_DBF_TEXT_(setup, 5, "iucv_connect rc is %d\n", rc); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 947 | kfree(conn->path); |
| 948 | conn->path = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 951 | static void netiucv_purge_skb_queue(struct sk_buff_head *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | { |
| 953 | struct sk_buff *skb; |
| 954 | |
| 955 | while ((skb = skb_dequeue(q))) { |
| 956 | atomic_dec(&skb->users); |
| 957 | dev_kfree_skb_any(skb); |
| 958 | } |
| 959 | } |
| 960 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 961 | static void conn_action_stop(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 963 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | struct iucv_connection *conn = ev->conn; |
| 965 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 966 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 968 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
| 970 | fsm_deltimer(&conn->timer); |
| 971 | fsm_newstate(fi, CONN_STATE_STOPPED); |
| 972 | netiucv_purge_skb_queue(&conn->collect_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 973 | if (conn->path) { |
| 974 | IUCV_DBF_TEXT(trace, 5, "calling iucv_path_sever\n"); |
| 975 | iucv_path_sever(conn->path, iucvMagic); |
| 976 | kfree(conn->path); |
| 977 | conn->path = NULL; |
| 978 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | netiucv_purge_skb_queue(&conn->commit_queue); |
| 980 | fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev); |
| 981 | } |
| 982 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 983 | static void conn_action_inval(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 985 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | struct net_device *netdev = conn->netdev; |
| 987 | |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 988 | IUCV_DBF_TEXT_(data, 2, "%s('%s'): conn_action_inval called\n", |
| 989 | netdev->name, conn->userid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | static const fsm_node conn_fsm[] = { |
| 993 | { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval }, |
| 994 | { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start }, |
| 995 | |
| 996 | { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop }, |
| 997 | { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop }, |
| 998 | { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop }, |
| 999 | { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop }, |
| 1000 | { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop }, |
| 1001 | { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop }, |
| 1002 | { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop }, |
| 1003 | |
| 1004 | { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1005 | { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept }, |
| 1006 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept }, |
| 1007 | { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1008 | { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1009 | |
| 1010 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack }, |
| 1011 | { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev }, |
| 1012 | |
| 1013 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1014 | { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1015 | { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1016 | |
| 1017 | { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx }, |
| 1018 | { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx }, |
| 1019 | |
| 1020 | { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone }, |
| 1021 | { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone }, |
| 1022 | }; |
| 1023 | |
| 1024 | static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node); |
| 1025 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1026 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1027 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | * Actions for interface - statemachine. |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1029 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
| 1031 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1032 | * dev_action_start |
| 1033 | * @fi: An instance of an interface statemachine. |
| 1034 | * @event: The event, just happened. |
| 1035 | * @arg: Generic pointer, casted from struct net_device * upon call. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1037 | * Startup connection by sending CONN_EVENT_START to it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1039 | static void dev_action_start(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1041 | struct net_device *dev = arg; |
| 1042 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1044 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | fsm_newstate(fi, DEV_STATE_STARTWAIT); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1047 | fsm_event(privptr->conn->fsm, CONN_EVENT_START, privptr->conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * Shutdown connection by sending CONN_EVENT_STOP to it. |
| 1052 | * |
| 1053 | * @param fi An instance of an interface statemachine. |
| 1054 | * @param event The event, just happened. |
| 1055 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1056 | */ |
| 1057 | static void |
| 1058 | dev_action_stop(fsm_instance *fi, int event, void *arg) |
| 1059 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1060 | struct net_device *dev = arg; |
| 1061 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | struct iucv_event ev; |
| 1063 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1064 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
| 1066 | ev.conn = privptr->conn; |
| 1067 | |
| 1068 | fsm_newstate(fi, DEV_STATE_STOPWAIT); |
| 1069 | fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev); |
| 1070 | } |
| 1071 | |
| 1072 | /** |
| 1073 | * Called from connection statemachine |
| 1074 | * when a connection is up and running. |
| 1075 | * |
| 1076 | * @param fi An instance of an interface statemachine. |
| 1077 | * @param event The event, just happened. |
| 1078 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1079 | */ |
| 1080 | static void |
| 1081 | dev_action_connup(fsm_instance *fi, int event, void *arg) |
| 1082 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1083 | struct net_device *dev = arg; |
| 1084 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1086 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | |
| 1088 | switch (fsm_getstate(fi)) { |
| 1089 | case DEV_STATE_STARTWAIT: |
| 1090 | fsm_newstate(fi, DEV_STATE_RUNNING); |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 1091 | dev_info(privptr->dev, |
| 1092 | "The IUCV device has been connected" |
| 1093 | " successfully to %s\n", privptr->conn->userid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | IUCV_DBF_TEXT(setup, 3, |
| 1095 | "connection is up and running\n"); |
| 1096 | break; |
| 1097 | case DEV_STATE_STOPWAIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | IUCV_DBF_TEXT(data, 2, |
| 1099 | "dev_action_connup: in DEV_STATE_STOPWAIT\n"); |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * Called from connection statemachine |
| 1106 | * when a connection has been shutdown. |
| 1107 | * |
| 1108 | * @param fi An instance of an interface statemachine. |
| 1109 | * @param event The event, just happened. |
| 1110 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1111 | */ |
| 1112 | static void |
| 1113 | dev_action_conndown(fsm_instance *fi, int event, void *arg) |
| 1114 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1115 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
| 1117 | switch (fsm_getstate(fi)) { |
| 1118 | case DEV_STATE_RUNNING: |
| 1119 | fsm_newstate(fi, DEV_STATE_STARTWAIT); |
| 1120 | break; |
| 1121 | case DEV_STATE_STOPWAIT: |
| 1122 | fsm_newstate(fi, DEV_STATE_STOPPED); |
| 1123 | IUCV_DBF_TEXT(setup, 3, "connection is down\n"); |
| 1124 | break; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | static const fsm_node dev_fsm[] = { |
| 1129 | { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start }, |
| 1130 | |
| 1131 | { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start }, |
| 1132 | { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown }, |
| 1133 | |
| 1134 | { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop }, |
| 1135 | { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup }, |
| 1136 | |
| 1137 | { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop }, |
| 1138 | { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown }, |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 1139 | { DEV_STATE_RUNNING, DEV_EVENT_CONUP, netiucv_action_nop }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | }; |
| 1141 | |
| 1142 | static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node); |
| 1143 | |
| 1144 | /** |
| 1145 | * Transmit a packet. |
| 1146 | * This is a helper function for netiucv_tx(). |
| 1147 | * |
| 1148 | * @param conn Connection to be used for sending. |
| 1149 | * @param skb Pointer to struct sk_buff of packet to send. |
| 1150 | * The linklevel header has already been set up |
| 1151 | * by netiucv_tx(). |
| 1152 | * |
| 1153 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1154 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1155 | static int netiucv_transmit_skb(struct iucv_connection *conn, |
| 1156 | struct sk_buff *skb) |
| 1157 | { |
| 1158 | struct iucv_message msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | unsigned long saveflags; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1160 | struct ll_header header; |
| 1161 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | |
| 1163 | if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) { |
| 1164 | int l = skb->len + NETIUCV_HDRLEN; |
| 1165 | |
| 1166 | spin_lock_irqsave(&conn->collect_lock, saveflags); |
| 1167 | if (conn->collect_len + l > |
| 1168 | (conn->max_buffsize - NETIUCV_HDRLEN)) { |
| 1169 | rc = -EBUSY; |
| 1170 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1171 | "EBUSY from netiucv_transmit_skb\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } else { |
| 1173 | atomic_inc(&skb->users); |
| 1174 | skb_queue_tail(&conn->collect_queue, skb); |
| 1175 | conn->collect_len += l; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1176 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | } |
| 1178 | spin_unlock_irqrestore(&conn->collect_lock, saveflags); |
| 1179 | } else { |
| 1180 | struct sk_buff *nskb = skb; |
| 1181 | /** |
| 1182 | * Copy the skb to a new allocated skb in lowmem only if the |
| 1183 | * data is located above 2G in memory or tailroom is < 2. |
| 1184 | */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 1185 | unsigned long hi = ((unsigned long)(skb_tail_pointer(skb) + |
| 1186 | NETIUCV_HDRLEN)) >> 31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | int copied = 0; |
| 1188 | if (hi || (skb_tailroom(skb) < 2)) { |
| 1189 | nskb = alloc_skb(skb->len + NETIUCV_HDRLEN + |
| 1190 | NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA); |
| 1191 | if (!nskb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | IUCV_DBF_TEXT(data, 2, "alloc_skb failed\n"); |
| 1193 | rc = -ENOMEM; |
| 1194 | return rc; |
| 1195 | } else { |
| 1196 | skb_reserve(nskb, NETIUCV_HDRLEN); |
| 1197 | memcpy(skb_put(nskb, skb->len), |
| 1198 | skb->data, skb->len); |
| 1199 | } |
| 1200 | copied = 1; |
| 1201 | } |
| 1202 | /** |
| 1203 | * skb now is below 2G and has enough room. Add headers. |
| 1204 | */ |
| 1205 | header.next = nskb->len + NETIUCV_HDRLEN; |
| 1206 | memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
| 1207 | header.next = 0; |
| 1208 | memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
| 1209 | |
| 1210 | fsm_newstate(conn->fsm, CONN_STATE_TX); |
john stultz | 2c6b47d | 2007-07-24 17:47:43 -0700 | [diff] [blame] | 1211 | conn->prof.send_stamp = current_kernel_time(); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1212 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1213 | msg.tag = 1; |
| 1214 | msg.class = 0; |
| 1215 | rc = iucv_message_send(conn->path, &msg, 0, 0, |
| 1216 | nskb->data, nskb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | conn->prof.doios_single++; |
| 1218 | conn->prof.txlen += skb->len; |
| 1219 | conn->prof.tx_pending++; |
| 1220 | if (conn->prof.tx_pending > conn->prof.tx_max_pending) |
| 1221 | conn->prof.tx_max_pending = conn->prof.tx_pending; |
| 1222 | if (rc) { |
| 1223 | struct netiucv_priv *privptr; |
| 1224 | fsm_newstate(conn->fsm, CONN_STATE_IDLE); |
| 1225 | conn->prof.tx_pending--; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1226 | privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | if (privptr) |
| 1228 | privptr->stats.tx_errors++; |
| 1229 | if (copied) |
| 1230 | dev_kfree_skb(nskb); |
| 1231 | else { |
| 1232 | /** |
| 1233 | * Remove our headers. They get added |
| 1234 | * again on retransmit. |
| 1235 | */ |
| 1236 | skb_pull(skb, NETIUCV_HDRLEN); |
| 1237 | skb_trim(skb, skb->len - NETIUCV_HDRLEN); |
| 1238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc); |
| 1240 | } else { |
| 1241 | if (copied) |
| 1242 | dev_kfree_skb(skb); |
| 1243 | atomic_inc(&nskb->users); |
| 1244 | skb_queue_tail(&conn->commit_queue, nskb); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | return rc; |
| 1249 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1250 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1251 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | * Interface API for upper network layers |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1253 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
| 1255 | /** |
| 1256 | * Open an interface. |
| 1257 | * Called from generic network layer when ifconfig up is run. |
| 1258 | * |
| 1259 | * @param dev Pointer to interface struct. |
| 1260 | * |
| 1261 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1262 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1263 | static int netiucv_open(struct net_device *dev) |
| 1264 | { |
| 1265 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1266 | |
| 1267 | fsm_event(priv->fsm, DEV_EVENT_START, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | return 0; |
| 1269 | } |
| 1270 | |
| 1271 | /** |
| 1272 | * Close an interface. |
| 1273 | * Called from generic network layer when ifconfig down is run. |
| 1274 | * |
| 1275 | * @param dev Pointer to interface struct. |
| 1276 | * |
| 1277 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1278 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1279 | static int netiucv_close(struct net_device *dev) |
| 1280 | { |
| 1281 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1282 | |
| 1283 | fsm_event(priv->fsm, DEV_EVENT_STOP, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | return 0; |
| 1285 | } |
| 1286 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1287 | static int netiucv_pm_prepare(struct device *dev) |
| 1288 | { |
| 1289 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
| 1293 | static void netiucv_pm_complete(struct device *dev) |
| 1294 | { |
| 1295 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1296 | return; |
| 1297 | } |
| 1298 | |
| 1299 | /** |
| 1300 | * netiucv_pm_freeze() - Freeze PM callback |
| 1301 | * @dev: netiucv device |
| 1302 | * |
| 1303 | * close open netiucv interfaces |
| 1304 | */ |
| 1305 | static int netiucv_pm_freeze(struct device *dev) |
| 1306 | { |
Martin Schwidefsky | 4f0076f | 2009-06-22 12:08:19 +0200 | [diff] [blame] | 1307 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1308 | struct net_device *ndev = NULL; |
| 1309 | int rc = 0; |
| 1310 | |
| 1311 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1312 | if (priv && priv->conn) |
| 1313 | ndev = priv->conn->netdev; |
| 1314 | if (!ndev) |
| 1315 | goto out; |
| 1316 | netif_device_detach(ndev); |
| 1317 | priv->pm_state = fsm_getstate(priv->fsm); |
| 1318 | rc = netiucv_close(ndev); |
| 1319 | out: |
| 1320 | return rc; |
| 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * netiucv_pm_restore_thaw() - Thaw and restore PM callback |
| 1325 | * @dev: netiucv device |
| 1326 | * |
| 1327 | * re-open netiucv interfaces closed during freeze |
| 1328 | */ |
| 1329 | static int netiucv_pm_restore_thaw(struct device *dev) |
| 1330 | { |
Martin Schwidefsky | 4f0076f | 2009-06-22 12:08:19 +0200 | [diff] [blame] | 1331 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1332 | struct net_device *ndev = NULL; |
| 1333 | int rc = 0; |
| 1334 | |
| 1335 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1336 | if (priv && priv->conn) |
| 1337 | ndev = priv->conn->netdev; |
| 1338 | if (!ndev) |
| 1339 | goto out; |
| 1340 | switch (priv->pm_state) { |
| 1341 | case DEV_STATE_RUNNING: |
| 1342 | case DEV_STATE_STARTWAIT: |
| 1343 | rc = netiucv_open(ndev); |
| 1344 | break; |
| 1345 | default: |
| 1346 | break; |
| 1347 | } |
| 1348 | netif_device_attach(ndev); |
| 1349 | out: |
| 1350 | return rc; |
| 1351 | } |
| 1352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | /** |
| 1354 | * Start transmission of a packet. |
| 1355 | * Called from generic network device layer. |
| 1356 | * |
| 1357 | * @param skb Pointer to buffer containing the packet. |
| 1358 | * @param dev Pointer to interface struct. |
| 1359 | * |
| 1360 | * @return 0 if packet consumed, !0 if packet rejected. |
| 1361 | * Note: If we return !0, then the packet is free'd by |
| 1362 | * the generic network layer. |
| 1363 | */ |
| 1364 | static int netiucv_tx(struct sk_buff *skb, struct net_device *dev) |
| 1365 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1366 | struct netiucv_priv *privptr = netdev_priv(dev); |
| 1367 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1369 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | /** |
| 1371 | * Some sanity checks ... |
| 1372 | */ |
| 1373 | if (skb == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | IUCV_DBF_TEXT(data, 2, "netiucv_tx: skb is NULL\n"); |
| 1375 | privptr->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1376 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } |
| 1378 | if (skb_headroom(skb) < NETIUCV_HDRLEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | IUCV_DBF_TEXT(data, 2, |
| 1380 | "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n"); |
| 1381 | dev_kfree_skb(skb); |
| 1382 | privptr->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1383 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | /** |
| 1387 | * If connection is not running, try to restart it |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1388 | * and throw away packet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | */ |
| 1390 | if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | dev_kfree_skb(skb); |
| 1392 | privptr->stats.tx_dropped++; |
| 1393 | privptr->stats.tx_errors++; |
| 1394 | privptr->stats.tx_carrier_errors++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1395 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | if (netiucv_test_and_set_busy(dev)) { |
| 1399 | IUCV_DBF_TEXT(data, 2, "EBUSY from netiucv_tx\n"); |
Ursula Braun | 4e584d6 | 2009-03-24 03:27:45 +0000 | [diff] [blame] | 1400 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | } |
| 1402 | dev->trans_start = jiffies; |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1403 | rc = netiucv_transmit_skb(privptr->conn, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | netiucv_clear_busy(dev); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1405 | return rc ? NETDEV_TX_BUSY : NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1409 | * netiucv_stats |
| 1410 | * @dev: Pointer to interface struct. |
| 1411 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | * Returns interface statistics of a device. |
| 1413 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1414 | * Returns pointer to stats struct of this interface. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1416 | static struct net_device_stats *netiucv_stats (struct net_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1418 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1419 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1420 | IUCV_DBF_TEXT(trace, 5, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1421 | return &priv->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1425 | * netiucv_change_mtu |
| 1426 | * @dev: Pointer to interface struct. |
| 1427 | * @new_mtu: The new MTU to use for this interface. |
| 1428 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | * Sets MTU of an interface. |
| 1430 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1431 | * Returns 0 on success, -EINVAL if MTU is out of valid range. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | * (valid range is 576 .. NETIUCV_MTU_MAX). |
| 1433 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1434 | static int netiucv_change_mtu(struct net_device * dev, int new_mtu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1436 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1437 | if (new_mtu < 576 || new_mtu > NETIUCV_MTU_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | IUCV_DBF_TEXT(setup, 2, "given MTU out of valid range\n"); |
| 1439 | return -EINVAL; |
| 1440 | } |
| 1441 | dev->mtu = new_mtu; |
| 1442 | return 0; |
| 1443 | } |
| 1444 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1445 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | * attributes in sysfs |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1447 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1449 | static ssize_t user_show(struct device *dev, struct device_attribute *attr, |
| 1450 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1452 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1454 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | return sprintf(buf, "%s\n", netiucv_printname(priv->conn->userid)); |
| 1456 | } |
| 1457 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1458 | static ssize_t user_write(struct device *dev, struct device_attribute *attr, |
| 1459 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1461 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | struct net_device *ndev = priv->conn->netdev; |
| 1463 | char *p; |
| 1464 | char *tmp; |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 1465 | char username[9]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | int i; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1467 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1469 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1470 | if (count > 9) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | IUCV_DBF_TEXT_(setup, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1472 | "%d is length of username\n", (int) count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | return -EINVAL; |
| 1474 | } |
| 1475 | |
| 1476 | tmp = strsep((char **) &buf, "\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1477 | for (i = 0, p = tmp; i < 8 && *p; i++, p++) { |
| 1478 | if (isalnum(*p) || (*p == '$')) { |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 1479 | username[i]= toupper(*p); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1480 | continue; |
| 1481 | } |
| 1482 | if (*p == '\n') { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | /* trailing lf, grr */ |
| 1484 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1486 | IUCV_DBF_TEXT_(setup, 2, |
| 1487 | "username: invalid character %c\n", *p); |
| 1488 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1490 | while (i < 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | username[i++] = ' '; |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 1492 | username[8] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1494 | if (memcmp(username, priv->conn->userid, 9) && |
| 1495 | (ndev->flags & (IFF_UP | IFF_RUNNING))) { |
| 1496 | /* username changed while the interface is active. */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1497 | IUCV_DBF_TEXT(setup, 2, "user_write: device active\n"); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 1498 | return -EPERM; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1499 | } |
| 1500 | read_lock_bh(&iucv_connection_rwlock); |
| 1501 | list_for_each_entry(cp, &iucv_connection_list, list) { |
| 1502 | if (!strncmp(username, cp->userid, 9) && cp->netdev != ndev) { |
| 1503 | read_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 1504 | IUCV_DBF_TEXT_(setup, 2, "user_write: Connection " |
| 1505 | "to %s already exists\n", username); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1506 | return -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | } |
| 1508 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1509 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | memcpy(priv->conn->userid, username, 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | static DEVICE_ATTR(user, 0644, user_show, user_write); |
| 1515 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1516 | static ssize_t buffer_show (struct device *dev, struct device_attribute *attr, |
| 1517 | char *buf) |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1518 | { |
| 1519 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1521 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | return sprintf(buf, "%d\n", priv->conn->max_buffsize); |
| 1523 | } |
| 1524 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1525 | static ssize_t buffer_write (struct device *dev, struct device_attribute *attr, |
| 1526 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1528 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | struct net_device *ndev = priv->conn->netdev; |
| 1530 | char *e; |
| 1531 | int bs1; |
| 1532 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1533 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | if (count >= 39) |
| 1535 | return -EINVAL; |
| 1536 | |
| 1537 | bs1 = simple_strtoul(buf, &e, 0); |
| 1538 | |
| 1539 | if (e && (!isspace(*e))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | IUCV_DBF_TEXT_(setup, 2, "buffer_write: invalid char %c\n", *e); |
| 1541 | return -EINVAL; |
| 1542 | } |
| 1543 | if (bs1 > NETIUCV_BUFSIZE_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | IUCV_DBF_TEXT_(setup, 2, |
| 1545 | "buffer_write: buffer size %d too large\n", |
| 1546 | bs1); |
| 1547 | return -EINVAL; |
| 1548 | } |
| 1549 | if ((ndev->flags & IFF_RUNNING) && |
| 1550 | (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | IUCV_DBF_TEXT_(setup, 2, |
| 1552 | "buffer_write: buffer size %d too small\n", |
| 1553 | bs1); |
| 1554 | return -EINVAL; |
| 1555 | } |
| 1556 | if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | IUCV_DBF_TEXT_(setup, 2, |
| 1558 | "buffer_write: buffer size %d too small\n", |
| 1559 | bs1); |
| 1560 | return -EINVAL; |
| 1561 | } |
| 1562 | |
| 1563 | priv->conn->max_buffsize = bs1; |
| 1564 | if (!(ndev->flags & IFF_RUNNING)) |
| 1565 | ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN; |
| 1566 | |
| 1567 | return count; |
| 1568 | |
| 1569 | } |
| 1570 | |
| 1571 | static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write); |
| 1572 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1573 | static ssize_t dev_fsm_show (struct device *dev, struct device_attribute *attr, |
| 1574 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1576 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1578 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm)); |
| 1580 | } |
| 1581 | |
| 1582 | static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL); |
| 1583 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1584 | static ssize_t conn_fsm_show (struct device *dev, |
| 1585 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1587 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1589 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm)); |
| 1591 | } |
| 1592 | |
| 1593 | static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL); |
| 1594 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1595 | static ssize_t maxmulti_show (struct device *dev, |
| 1596 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1598 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1600 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti); |
| 1602 | } |
| 1603 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1604 | static ssize_t maxmulti_write (struct device *dev, |
| 1605 | struct device_attribute *attr, |
| 1606 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1608 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1610 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | priv->conn->prof.maxmulti = 0; |
| 1612 | return count; |
| 1613 | } |
| 1614 | |
| 1615 | static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write); |
| 1616 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1617 | static ssize_t maxcq_show (struct device *dev, struct device_attribute *attr, |
| 1618 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1620 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1622 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue); |
| 1624 | } |
| 1625 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1626 | static ssize_t maxcq_write (struct device *dev, struct device_attribute *attr, |
| 1627 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1629 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1630 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1631 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | priv->conn->prof.maxcqueue = 0; |
| 1633 | return count; |
| 1634 | } |
| 1635 | |
| 1636 | static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write); |
| 1637 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1638 | static ssize_t sdoio_show (struct device *dev, struct device_attribute *attr, |
| 1639 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1641 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1643 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | return sprintf(buf, "%ld\n", priv->conn->prof.doios_single); |
| 1645 | } |
| 1646 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1647 | static ssize_t sdoio_write (struct device *dev, struct device_attribute *attr, |
| 1648 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1650 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1651 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1652 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | priv->conn->prof.doios_single = 0; |
| 1654 | return count; |
| 1655 | } |
| 1656 | |
| 1657 | static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write); |
| 1658 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1659 | static ssize_t mdoio_show (struct device *dev, struct device_attribute *attr, |
| 1660 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1662 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1664 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi); |
| 1666 | } |
| 1667 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1668 | static ssize_t mdoio_write (struct device *dev, struct device_attribute *attr, |
| 1669 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1671 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1672 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1673 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | priv->conn->prof.doios_multi = 0; |
| 1675 | return count; |
| 1676 | } |
| 1677 | |
| 1678 | static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write); |
| 1679 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1680 | static ssize_t txlen_show (struct device *dev, struct device_attribute *attr, |
| 1681 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1683 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1685 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | return sprintf(buf, "%ld\n", priv->conn->prof.txlen); |
| 1687 | } |
| 1688 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1689 | static ssize_t txlen_write (struct device *dev, struct device_attribute *attr, |
| 1690 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1692 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1693 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1694 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | priv->conn->prof.txlen = 0; |
| 1696 | return count; |
| 1697 | } |
| 1698 | |
| 1699 | static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write); |
| 1700 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1701 | static ssize_t txtime_show (struct device *dev, struct device_attribute *attr, |
| 1702 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1704 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1706 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_time); |
| 1708 | } |
| 1709 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1710 | static ssize_t txtime_write (struct device *dev, struct device_attribute *attr, |
| 1711 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1713 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1714 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1715 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | priv->conn->prof.tx_time = 0; |
| 1717 | return count; |
| 1718 | } |
| 1719 | |
| 1720 | static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write); |
| 1721 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1722 | static ssize_t txpend_show (struct device *dev, struct device_attribute *attr, |
| 1723 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1725 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1727 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending); |
| 1729 | } |
| 1730 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1731 | static ssize_t txpend_write (struct device *dev, struct device_attribute *attr, |
| 1732 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1734 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1736 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | priv->conn->prof.tx_pending = 0; |
| 1738 | return count; |
| 1739 | } |
| 1740 | |
| 1741 | static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write); |
| 1742 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1743 | static ssize_t txmpnd_show (struct device *dev, struct device_attribute *attr, |
| 1744 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1746 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1748 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending); |
| 1750 | } |
| 1751 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1752 | static ssize_t txmpnd_write (struct device *dev, struct device_attribute *attr, |
| 1753 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1755 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1757 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | priv->conn->prof.tx_max_pending = 0; |
| 1759 | return count; |
| 1760 | } |
| 1761 | |
| 1762 | static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write); |
| 1763 | |
| 1764 | static struct attribute *netiucv_attrs[] = { |
| 1765 | &dev_attr_buffer.attr, |
| 1766 | &dev_attr_user.attr, |
| 1767 | NULL, |
| 1768 | }; |
| 1769 | |
| 1770 | static struct attribute_group netiucv_attr_group = { |
| 1771 | .attrs = netiucv_attrs, |
| 1772 | }; |
| 1773 | |
| 1774 | static struct attribute *netiucv_stat_attrs[] = { |
| 1775 | &dev_attr_device_fsm_state.attr, |
| 1776 | &dev_attr_connection_fsm_state.attr, |
| 1777 | &dev_attr_max_tx_buffer_used.attr, |
| 1778 | &dev_attr_max_chained_skbs.attr, |
| 1779 | &dev_attr_tx_single_write_ops.attr, |
| 1780 | &dev_attr_tx_multi_write_ops.attr, |
| 1781 | &dev_attr_netto_bytes.attr, |
| 1782 | &dev_attr_max_tx_io_time.attr, |
| 1783 | &dev_attr_tx_pending.attr, |
| 1784 | &dev_attr_tx_max_pending.attr, |
| 1785 | NULL, |
| 1786 | }; |
| 1787 | |
| 1788 | static struct attribute_group netiucv_stat_attr_group = { |
| 1789 | .name = "stats", |
| 1790 | .attrs = netiucv_stat_attrs, |
| 1791 | }; |
| 1792 | |
Martin Schwidefsky | d461462 | 2007-06-20 13:03:57 +0200 | [diff] [blame] | 1793 | static int netiucv_add_files(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | { |
| 1795 | int ret; |
| 1796 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1797 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | ret = sysfs_create_group(&dev->kobj, &netiucv_attr_group); |
| 1799 | if (ret) |
| 1800 | return ret; |
| 1801 | ret = sysfs_create_group(&dev->kobj, &netiucv_stat_attr_group); |
| 1802 | if (ret) |
| 1803 | sysfs_remove_group(&dev->kobj, &netiucv_attr_group); |
| 1804 | return ret; |
| 1805 | } |
| 1806 | |
Martin Schwidefsky | d461462 | 2007-06-20 13:03:57 +0200 | [diff] [blame] | 1807 | static void netiucv_remove_files(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1809 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | sysfs_remove_group(&dev->kobj, &netiucv_stat_attr_group); |
| 1811 | sysfs_remove_group(&dev->kobj, &netiucv_attr_group); |
| 1812 | } |
| 1813 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1814 | static int netiucv_register_device(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1816 | struct netiucv_priv *priv = netdev_priv(ndev); |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 1817 | struct device *dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | int ret; |
| 1819 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1820 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | |
| 1822 | if (dev) { |
Cornelia Huck | 1bf5b28 | 2008-10-10 21:33:10 +0200 | [diff] [blame] | 1823 | dev_set_name(dev, "net%s", ndev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | dev->bus = &iucv_bus; |
| 1825 | dev->parent = iucv_root; |
| 1826 | /* |
| 1827 | * The release function could be called after the |
| 1828 | * module has been unloaded. It's _only_ task is to |
| 1829 | * free the struct. Therefore, we specify kfree() |
| 1830 | * directly here. (Probably a little bit obfuscating |
| 1831 | * but legitime ...). |
| 1832 | */ |
| 1833 | dev->release = (void (*)(struct device *))kfree; |
| 1834 | dev->driver = &netiucv_driver; |
| 1835 | } else |
| 1836 | return -ENOMEM; |
| 1837 | |
| 1838 | ret = device_register(dev); |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 1839 | if (ret) { |
| 1840 | put_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | return ret; |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 1842 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | ret = netiucv_add_files(dev); |
| 1844 | if (ret) |
| 1845 | goto out_unreg; |
| 1846 | priv->dev = dev; |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1847 | dev_set_drvdata(dev, priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | return 0; |
| 1849 | |
| 1850 | out_unreg: |
| 1851 | device_unregister(dev); |
| 1852 | return ret; |
| 1853 | } |
| 1854 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1855 | static void netiucv_unregister_device(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1857 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | netiucv_remove_files(dev); |
| 1859 | device_unregister(dev); |
| 1860 | } |
| 1861 | |
| 1862 | /** |
| 1863 | * Allocate and initialize a new connection structure. |
| 1864 | * Add it to the list of netiucv connections; |
| 1865 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1866 | static struct iucv_connection *netiucv_new_connection(struct net_device *dev, |
| 1867 | char *username) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1869 | struct iucv_connection *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1871 | conn = kzalloc(sizeof(*conn), GFP_KERNEL); |
| 1872 | if (!conn) |
| 1873 | goto out; |
| 1874 | skb_queue_head_init(&conn->collect_queue); |
| 1875 | skb_queue_head_init(&conn->commit_queue); |
| 1876 | spin_lock_init(&conn->collect_lock); |
| 1877 | conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT; |
| 1878 | conn->netdev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1880 | conn->rx_buff = alloc_skb(conn->max_buffsize, GFP_KERNEL | GFP_DMA); |
| 1881 | if (!conn->rx_buff) |
| 1882 | goto out_conn; |
| 1883 | conn->tx_buff = alloc_skb(conn->max_buffsize, GFP_KERNEL | GFP_DMA); |
| 1884 | if (!conn->tx_buff) |
| 1885 | goto out_rx; |
| 1886 | conn->fsm = init_fsm("netiucvconn", conn_state_names, |
| 1887 | conn_event_names, NR_CONN_STATES, |
| 1888 | NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN, |
| 1889 | GFP_KERNEL); |
| 1890 | if (!conn->fsm) |
| 1891 | goto out_tx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1893 | fsm_settimer(conn->fsm, &conn->timer); |
| 1894 | fsm_newstate(conn->fsm, CONN_STATE_INVALID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1896 | if (username) { |
| 1897 | memcpy(conn->userid, username, 9); |
| 1898 | fsm_newstate(conn->fsm, CONN_STATE_STOPPED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1900 | |
| 1901 | write_lock_bh(&iucv_connection_rwlock); |
| 1902 | list_add_tail(&conn->list, &iucv_connection_list); |
| 1903 | write_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | return conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1905 | |
| 1906 | out_tx: |
| 1907 | kfree_skb(conn->tx_buff); |
| 1908 | out_rx: |
| 1909 | kfree_skb(conn->rx_buff); |
| 1910 | out_conn: |
| 1911 | kfree(conn); |
| 1912 | out: |
| 1913 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /** |
| 1917 | * Release a connection structure and remove it from the |
| 1918 | * list of netiucv connections. |
| 1919 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1920 | static void netiucv_remove_connection(struct iucv_connection *conn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1922 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1923 | write_lock_bh(&iucv_connection_rwlock); |
| 1924 | list_del_init(&conn->list); |
| 1925 | write_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | 0be4ace | 2007-05-02 15:18:44 +0200 | [diff] [blame] | 1926 | fsm_deltimer(&conn->timer); |
| 1927 | netiucv_purge_skb_queue(&conn->collect_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1928 | if (conn->path) { |
| 1929 | iucv_path_sever(conn->path, iucvMagic); |
| 1930 | kfree(conn->path); |
| 1931 | conn->path = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | } |
Ursula Braun | 0be4ace | 2007-05-02 15:18:44 +0200 | [diff] [blame] | 1933 | netiucv_purge_skb_queue(&conn->commit_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1934 | kfree_fsm(conn->fsm); |
| 1935 | kfree_skb(conn->rx_buff); |
| 1936 | kfree_skb(conn->tx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | /** |
| 1940 | * Release everything of a net device. |
| 1941 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1942 | static void netiucv_free_netdevice(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1944 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1946 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | |
| 1948 | if (!dev) |
| 1949 | return; |
| 1950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | if (privptr) { |
| 1952 | if (privptr->conn) |
| 1953 | netiucv_remove_connection(privptr->conn); |
| 1954 | if (privptr->fsm) |
| 1955 | kfree_fsm(privptr->fsm); |
| 1956 | privptr->conn = NULL; privptr->fsm = NULL; |
| 1957 | /* privptr gets freed by free_netdev() */ |
| 1958 | } |
| 1959 | free_netdev(dev); |
| 1960 | } |
| 1961 | |
| 1962 | /** |
| 1963 | * Initialize a net device. (Called from kernel in alloc_netdev()) |
| 1964 | */ |
Frank Blaschka | 4edd73b | 2009-01-09 03:43:58 +0000 | [diff] [blame] | 1965 | static const struct net_device_ops netiucv_netdev_ops = { |
| 1966 | .ndo_open = netiucv_open, |
| 1967 | .ndo_stop = netiucv_close, |
| 1968 | .ndo_get_stats = netiucv_stats, |
| 1969 | .ndo_start_xmit = netiucv_tx, |
| 1970 | .ndo_change_mtu = netiucv_change_mtu, |
| 1971 | }; |
| 1972 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1973 | static void netiucv_setup_netdevice(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | dev->mtu = NETIUCV_MTU_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | dev->destructor = netiucv_free_netdevice; |
| 1977 | dev->hard_header_len = NETIUCV_HDRLEN; |
| 1978 | dev->addr_len = 0; |
| 1979 | dev->type = ARPHRD_SLIP; |
| 1980 | dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT; |
| 1981 | dev->flags = IFF_POINTOPOINT | IFF_NOARP; |
Frank Blaschka | 4edd73b | 2009-01-09 03:43:58 +0000 | [diff] [blame] | 1982 | dev->netdev_ops = &netiucv_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | /** |
| 1986 | * Allocate and initialize everything of a net device. |
| 1987 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1988 | static struct net_device *netiucv_init_netdevice(char *username) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | { |
| 1990 | struct netiucv_priv *privptr; |
| 1991 | struct net_device *dev; |
| 1992 | |
| 1993 | dev = alloc_netdev(sizeof(struct netiucv_priv), "iucv%d", |
| 1994 | netiucv_setup_netdevice); |
| 1995 | if (!dev) |
| 1996 | return NULL; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1997 | if (dev_alloc_name(dev, dev->name) < 0) |
| 1998 | goto out_netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2000 | privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | privptr->fsm = init_fsm("netiucvdev", dev_state_names, |
| 2002 | dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS, |
| 2003 | dev_fsm, DEV_FSM_LEN, GFP_KERNEL); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2004 | if (!privptr->fsm) |
| 2005 | goto out_netdev; |
| 2006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | privptr->conn = netiucv_new_connection(dev, username); |
| 2008 | if (!privptr->conn) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_new_connection\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2010 | goto out_fsm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | } |
| 2012 | fsm_newstate(privptr->fsm, DEV_STATE_STOPPED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | return dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2014 | |
| 2015 | out_fsm: |
| 2016 | kfree_fsm(privptr->fsm); |
| 2017 | out_netdev: |
| 2018 | free_netdev(dev); |
| 2019 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2022 | static ssize_t conn_write(struct device_driver *drv, |
| 2023 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2025 | const char *p; |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2026 | char username[9]; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2027 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | struct net_device *dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2029 | struct netiucv_priv *priv; |
| 2030 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2032 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | if (count>9) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | IUCV_DBF_TEXT(setup, 2, "conn_write: too long\n"); |
| 2035 | return -EINVAL; |
| 2036 | } |
| 2037 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2038 | for (i = 0, p = buf; i < 8 && *p; i++, p++) { |
| 2039 | if (isalnum(*p) || *p == '$') { |
| 2040 | username[i] = toupper(*p); |
| 2041 | continue; |
| 2042 | } |
| 2043 | if (*p == '\n') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | /* trailing lf, grr */ |
| 2045 | break; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2046 | IUCV_DBF_TEXT_(setup, 2, |
| 2047 | "conn_write: invalid character %c\n", *p); |
| 2048 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2050 | while (i < 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | username[i++] = ' '; |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2052 | username[8] = '\0'; |
| 2053 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2054 | read_lock_bh(&iucv_connection_rwlock); |
| 2055 | list_for_each_entry(cp, &iucv_connection_list, list) { |
| 2056 | if (!strncmp(username, cp->userid, 9)) { |
| 2057 | read_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 2058 | IUCV_DBF_TEXT_(setup, 2, "conn_write: Connection " |
| 2059 | "to %s already exists\n", username); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2060 | return -EEXIST; |
| 2061 | } |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2062 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2063 | read_unlock_bh(&iucv_connection_rwlock); |
| 2064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | dev = netiucv_init_netdevice(username); |
| 2066 | if (!dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_init_netdevice\n"); |
| 2068 | return -ENODEV; |
| 2069 | } |
| 2070 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2071 | rc = netiucv_register_device(dev); |
| 2072 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | IUCV_DBF_TEXT_(setup, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2074 | "ret %d from netiucv_register_device\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | goto out_free_ndev; |
| 2076 | } |
| 2077 | |
| 2078 | /* sysfs magic */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2079 | priv = netdev_priv(dev); |
| 2080 | SET_NETDEV_DEV(dev, priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2082 | rc = register_netdev(dev); |
| 2083 | if (rc) |
| 2084 | goto out_unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2086 | dev_info(priv->dev, "The IUCV interface to %s has been" |
| 2087 | " established successfully\n", netiucv_printname(username)); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | return count; |
| 2090 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2091 | out_unreg: |
| 2092 | netiucv_unregister_device(priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | out_free_ndev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | netiucv_free_netdevice(dev); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2095 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 2098 | static DRIVER_ATTR(connection, 0200, NULL, conn_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2100 | static ssize_t remove_write (struct device_driver *drv, |
| 2101 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2103 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | struct net_device *ndev; |
| 2105 | struct netiucv_priv *priv; |
| 2106 | struct device *dev; |
| 2107 | char name[IFNAMSIZ]; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2108 | const char *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | int i; |
| 2110 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2111 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | |
| 2113 | if (count >= IFNAMSIZ) |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 2114 | count = IFNAMSIZ - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2116 | for (i = 0, p = buf; i < count && *p; i++, p++) { |
| 2117 | if (*p == '\n' || *p == ' ') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | /* trailing lf, grr */ |
| 2119 | break; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2120 | name[i] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | } |
| 2122 | name[i] = '\0'; |
| 2123 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2124 | read_lock_bh(&iucv_connection_rwlock); |
| 2125 | list_for_each_entry(cp, &iucv_connection_list, list) { |
| 2126 | ndev = cp->netdev; |
| 2127 | priv = netdev_priv(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | dev = priv->dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2129 | if (strncmp(name, ndev->name, count)) |
| 2130 | continue; |
| 2131 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | if (ndev->flags & (IFF_UP | IFF_RUNNING)) { |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2133 | dev_warn(dev, "The IUCV device is connected" |
| 2134 | " to %s and cannot be removed\n", |
| 2135 | priv->conn->userid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | IUCV_DBF_TEXT(data, 2, "remove_write: still active\n"); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 2137 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | } |
| 2139 | unregister_netdev(ndev); |
| 2140 | netiucv_unregister_device(dev); |
| 2141 | return count; |
| 2142 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2143 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | IUCV_DBF_TEXT(data, 2, "remove_write: unknown device\n"); |
| 2145 | return -EINVAL; |
| 2146 | } |
| 2147 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 2148 | static DRIVER_ATTR(remove, 0200, NULL, remove_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2150 | static struct attribute * netiucv_drv_attrs[] = { |
| 2151 | &driver_attr_connection.attr, |
| 2152 | &driver_attr_remove.attr, |
| 2153 | NULL, |
| 2154 | }; |
| 2155 | |
| 2156 | static struct attribute_group netiucv_drv_attr_group = { |
| 2157 | .attrs = netiucv_drv_attrs, |
| 2158 | }; |
| 2159 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 2160 | static const struct attribute_group *netiucv_drv_attr_groups[] = { |
Cornelia Huck | 5b88feb | 2007-12-05 12:50:28 +0100 | [diff] [blame] | 2161 | &netiucv_drv_attr_group, |
| 2162 | NULL, |
| 2163 | }; |
| 2164 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2165 | static void netiucv_banner(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | { |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2167 | pr_info("driver initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2170 | static void __exit netiucv_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2172 | struct iucv_connection *cp; |
| 2173 | struct net_device *ndev; |
| 2174 | struct netiucv_priv *priv; |
| 2175 | struct device *dev; |
| 2176 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2177 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2178 | while (!list_empty(&iucv_connection_list)) { |
| 2179 | cp = list_entry(iucv_connection_list.next, |
| 2180 | struct iucv_connection, list); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2181 | ndev = cp->netdev; |
| 2182 | priv = netdev_priv(ndev); |
| 2183 | dev = priv->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | |
| 2185 | unregister_netdev(ndev); |
| 2186 | netiucv_unregister_device(dev); |
| 2187 | } |
| 2188 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2189 | device_unregister(netiucv_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | driver_unregister(&netiucv_driver); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2191 | iucv_unregister(&netiucv_handler, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | iucv_unregister_dbf_views(); |
| 2193 | |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2194 | pr_info("driver unloaded\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | return; |
| 2196 | } |
| 2197 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2198 | static int __init netiucv_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2200 | int rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2201 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2202 | rc = iucv_register_dbf_views(); |
| 2203 | if (rc) |
| 2204 | goto out; |
| 2205 | rc = iucv_register(&netiucv_handler, 1); |
| 2206 | if (rc) |
| 2207 | goto out_dbf; |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2208 | IUCV_DBF_TEXT(trace, 3, __func__); |
Cornelia Huck | 0a0a831 | 2008-04-24 10:15:28 +0200 | [diff] [blame] | 2209 | netiucv_driver.groups = netiucv_drv_attr_groups; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2210 | rc = driver_register(&netiucv_driver); |
| 2211 | if (rc) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2212 | IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_register\n", rc); |
| 2213 | goto out_iucv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | } |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2215 | /* establish dummy device */ |
| 2216 | netiucv_dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 2217 | if (!netiucv_dev) { |
| 2218 | rc = -ENOMEM; |
| 2219 | goto out_driver; |
| 2220 | } |
| 2221 | dev_set_name(netiucv_dev, "netiucv"); |
| 2222 | netiucv_dev->bus = &iucv_bus; |
| 2223 | netiucv_dev->parent = iucv_root; |
| 2224 | netiucv_dev->release = (void (*)(struct device *))kfree; |
| 2225 | netiucv_dev->driver = &netiucv_driver; |
| 2226 | rc = device_register(netiucv_dev); |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 2227 | if (rc) { |
| 2228 | put_device(netiucv_dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2229 | goto out_driver; |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 2230 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2231 | netiucv_banner(); |
| 2232 | return rc; |
| 2233 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2234 | out_driver: |
| 2235 | driver_unregister(&netiucv_driver); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2236 | out_iucv: |
| 2237 | iucv_unregister(&netiucv_handler, 1); |
| 2238 | out_dbf: |
| 2239 | iucv_unregister_dbf_views(); |
| 2240 | out: |
| 2241 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | module_init(netiucv_init); |
| 2245 | module_exit(netiucv_exit); |
| 2246 | MODULE_LICENSE("GPL"); |