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