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 | * Linux for S/390 Lan Channel Station Network Driver |
| 3 | * |
Klaus-Dieter Wacket | cbb2aec | 2009-06-16 10:30:30 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999, 2009 |
| 5 | * Author(s): Original Code written by |
| 6 | * DJ Barrow <djbarrow@de.ibm.com,barrow_dj@yahoo.com> |
| 7 | * Rewritten by |
| 8 | * Frank Pavlic <fpavlic@de.ibm.com> and |
| 9 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 26 | #define KMSG_COMPONENT "lcs" |
| 27 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
| 30 | #include <linux/if.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/trdevice.h> |
| 34 | #include <linux/fddidevice.h> |
| 35 | #include <linux/inetdevice.h> |
| 36 | #include <linux/in.h> |
| 37 | #include <linux/igmp.h> |
| 38 | #include <linux/delay.h> |
Klaus-Dieter Wacker | e5b5719 | 2009-03-24 03:27:43 +0000 | [diff] [blame] | 39 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <net/arp.h> |
| 41 | #include <net/ip.h> |
| 42 | |
| 43 | #include <asm/debug.h> |
| 44 | #include <asm/idals.h> |
| 45 | #include <asm/timex.h> |
| 46 | #include <linux/device.h> |
| 47 | #include <asm/ccwgroup.h> |
| 48 | |
| 49 | #include "lcs.h" |
| 50 | #include "cu3088.h" |
| 51 | |
| 52 | |
| 53 | #if !defined(CONFIG_NET_ETHERNET) && \ |
| 54 | !defined(CONFIG_TR) && !defined(CONFIG_FDDI) |
| 55 | #error Cannot compile lcs.c without some net devices switched on. |
| 56 | #endif |
| 57 | |
| 58 | /** |
| 59 | * initialization string for output |
| 60 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Heiko Carstens | e018ba1 | 2006-02-01 03:06:31 -0800 | [diff] [blame] | 62 | static char version[] __initdata = "LCS driver"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static char debug_buffer[255]; |
| 64 | |
| 65 | /** |
| 66 | * Some prototypes. |
| 67 | */ |
| 68 | static void lcs_tasklet(unsigned long); |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 69 | static void lcs_start_kernel_thread(struct work_struct *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static void lcs_get_frames_cb(struct lcs_channel *, struct lcs_buffer *); |
Heiko Carstens | 801599b | 2009-01-20 06:14:32 +0000 | [diff] [blame] | 71 | #ifdef CONFIG_IP_MULTICAST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static int lcs_send_delipm(struct lcs_card *, struct lcs_ipm_list *); |
Heiko Carstens | 801599b | 2009-01-20 06:14:32 +0000 | [diff] [blame] | 73 | #endif /* CONFIG_IP_MULTICAST */ |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 74 | static int lcs_recovery(void *ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Debug Facility Stuff |
| 78 | */ |
| 79 | static debug_info_t *lcs_dbf_setup; |
| 80 | static debug_info_t *lcs_dbf_trace; |
| 81 | |
| 82 | /** |
| 83 | * LCS Debug Facility functions |
| 84 | */ |
| 85 | static void |
| 86 | lcs_unregister_debug_facility(void) |
| 87 | { |
| 88 | if (lcs_dbf_setup) |
| 89 | debug_unregister(lcs_dbf_setup); |
| 90 | if (lcs_dbf_trace) |
| 91 | debug_unregister(lcs_dbf_trace); |
| 92 | } |
| 93 | |
| 94 | static int |
| 95 | lcs_register_debug_facility(void) |
| 96 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 97 | lcs_dbf_setup = debug_register("lcs_setup", 2, 1, 8); |
Peter Tiedemann | 164b0fb | 2008-02-08 13:09:04 +0100 | [diff] [blame] | 98 | lcs_dbf_trace = debug_register("lcs_trace", 4, 1, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (lcs_dbf_setup == NULL || lcs_dbf_trace == NULL) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 100 | pr_err("Not enough memory for debug facility.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | lcs_unregister_debug_facility(); |
| 102 | return -ENOMEM; |
| 103 | } |
| 104 | debug_register_view(lcs_dbf_setup, &debug_hex_ascii_view); |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 105 | debug_set_level(lcs_dbf_setup, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | debug_register_view(lcs_dbf_trace, &debug_hex_ascii_view); |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 107 | debug_set_level(lcs_dbf_trace, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Allocate io buffers. |
| 113 | */ |
| 114 | static int |
| 115 | lcs_alloc_channel(struct lcs_channel *channel) |
| 116 | { |
| 117 | int cnt; |
| 118 | |
| 119 | LCS_DBF_TEXT(2, setup, "ichalloc"); |
| 120 | for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { |
| 121 | /* alloc memory fo iobuffer */ |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 122 | channel->iob[cnt].data = |
| 123 | kzalloc(LCS_IOBUFFERSIZE, GFP_DMA | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if (channel->iob[cnt].data == NULL) |
| 125 | break; |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 126 | channel->iob[cnt].state = LCS_BUF_STATE_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | if (cnt < LCS_NUM_BUFFS) { |
| 129 | /* Not all io buffers could be allocated. */ |
| 130 | LCS_DBF_TEXT(2, setup, "echalloc"); |
| 131 | while (cnt-- > 0) |
| 132 | kfree(channel->iob[cnt].data); |
| 133 | return -ENOMEM; |
| 134 | } |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Free io buffers. |
| 140 | */ |
| 141 | static void |
| 142 | lcs_free_channel(struct lcs_channel *channel) |
| 143 | { |
| 144 | int cnt; |
| 145 | |
| 146 | LCS_DBF_TEXT(2, setup, "ichfree"); |
| 147 | for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 148 | kfree(channel->iob[cnt].data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | channel->iob[cnt].data = NULL; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Cleanup channel. |
| 155 | */ |
| 156 | static void |
| 157 | lcs_cleanup_channel(struct lcs_channel *channel) |
| 158 | { |
| 159 | LCS_DBF_TEXT(3, setup, "cleanch"); |
| 160 | /* Kill write channel tasklets. */ |
| 161 | tasklet_kill(&channel->irq_tasklet); |
| 162 | /* Free channel buffers. */ |
| 163 | lcs_free_channel(channel); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * LCS free memory for card and channels. |
| 168 | */ |
| 169 | static void |
| 170 | lcs_free_card(struct lcs_card *card) |
| 171 | { |
| 172 | LCS_DBF_TEXT(2, setup, "remcard"); |
| 173 | LCS_DBF_HEX(2, setup, &card, sizeof(void*)); |
| 174 | kfree(card); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * LCS alloc memory for card and channels |
| 179 | */ |
| 180 | static struct lcs_card * |
| 181 | lcs_alloc_card(void) |
| 182 | { |
| 183 | struct lcs_card *card; |
| 184 | int rc; |
| 185 | |
| 186 | LCS_DBF_TEXT(2, setup, "alloclcs"); |
| 187 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 188 | card = kzalloc(sizeof(struct lcs_card), GFP_KERNEL | GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | if (card == NULL) |
| 190 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | card->lan_type = LCS_FRAME_TYPE_AUTO; |
| 192 | card->pkt_seq = 0; |
| 193 | card->lancmd_timeout = LCS_LANCMD_TIMEOUT_DEFAULT; |
| 194 | /* Allocate io buffers for the read channel. */ |
| 195 | rc = lcs_alloc_channel(&card->read); |
| 196 | if (rc){ |
| 197 | LCS_DBF_TEXT(2, setup, "iccwerr"); |
| 198 | lcs_free_card(card); |
| 199 | return NULL; |
| 200 | } |
| 201 | /* Allocate io buffers for the write channel. */ |
| 202 | rc = lcs_alloc_channel(&card->write); |
| 203 | if (rc) { |
| 204 | LCS_DBF_TEXT(2, setup, "iccwerr"); |
| 205 | lcs_cleanup_channel(&card->read); |
| 206 | lcs_free_card(card); |
| 207 | return NULL; |
| 208 | } |
| 209 | |
| 210 | #ifdef CONFIG_IP_MULTICAST |
| 211 | INIT_LIST_HEAD(&card->ipm_list); |
| 212 | #endif |
| 213 | LCS_DBF_HEX(2, setup, &card, sizeof(void*)); |
| 214 | return card; |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * Setup read channel. |
| 219 | */ |
| 220 | static void |
| 221 | lcs_setup_read_ccws(struct lcs_card *card) |
| 222 | { |
| 223 | int cnt; |
| 224 | |
| 225 | LCS_DBF_TEXT(2, setup, "ireadccw"); |
| 226 | /* Setup read ccws. */ |
| 227 | memset(card->read.ccws, 0, sizeof (struct ccw1) * (LCS_NUM_BUFFS + 1)); |
| 228 | for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { |
| 229 | card->read.ccws[cnt].cmd_code = LCS_CCW_READ; |
| 230 | card->read.ccws[cnt].count = LCS_IOBUFFERSIZE; |
| 231 | card->read.ccws[cnt].flags = |
| 232 | CCW_FLAG_CC | CCW_FLAG_SLI | CCW_FLAG_PCI; |
| 233 | /* |
| 234 | * Note: we have allocated the buffer with GFP_DMA, so |
| 235 | * we do not need to do set_normalized_cda. |
| 236 | */ |
| 237 | card->read.ccws[cnt].cda = |
| 238 | (__u32) __pa(card->read.iob[cnt].data); |
| 239 | ((struct lcs_header *) |
| 240 | card->read.iob[cnt].data)->offset = LCS_ILLEGAL_OFFSET; |
| 241 | card->read.iob[cnt].callback = lcs_get_frames_cb; |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 242 | card->read.iob[cnt].state = LCS_BUF_STATE_READY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | card->read.iob[cnt].count = LCS_IOBUFFERSIZE; |
| 244 | } |
| 245 | card->read.ccws[0].flags &= ~CCW_FLAG_PCI; |
| 246 | card->read.ccws[LCS_NUM_BUFFS - 1].flags &= ~CCW_FLAG_PCI; |
| 247 | card->read.ccws[LCS_NUM_BUFFS - 1].flags |= CCW_FLAG_SUSPEND; |
| 248 | /* Last ccw is a tic (transfer in channel). */ |
| 249 | card->read.ccws[LCS_NUM_BUFFS].cmd_code = LCS_CCW_TRANSFER; |
| 250 | card->read.ccws[LCS_NUM_BUFFS].cda = |
| 251 | (__u32) __pa(card->read.ccws); |
| 252 | /* Setg initial state of the read channel. */ |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 253 | card->read.state = LCS_CH_STATE_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | card->read.io_idx = 0; |
| 256 | card->read.buf_idx = 0; |
| 257 | } |
| 258 | |
| 259 | static void |
| 260 | lcs_setup_read(struct lcs_card *card) |
| 261 | { |
| 262 | LCS_DBF_TEXT(3, setup, "initread"); |
| 263 | |
| 264 | lcs_setup_read_ccws(card); |
| 265 | /* Initialize read channel tasklet. */ |
| 266 | card->read.irq_tasklet.data = (unsigned long) &card->read; |
| 267 | card->read.irq_tasklet.func = lcs_tasklet; |
| 268 | /* Initialize waitqueue. */ |
| 269 | init_waitqueue_head(&card->read.wait_q); |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Setup write channel. |
| 274 | */ |
| 275 | static void |
| 276 | lcs_setup_write_ccws(struct lcs_card *card) |
| 277 | { |
| 278 | int cnt; |
| 279 | |
| 280 | LCS_DBF_TEXT(3, setup, "iwritccw"); |
| 281 | /* Setup write ccws. */ |
| 282 | memset(card->write.ccws, 0, sizeof(struct ccw1) * LCS_NUM_BUFFS + 1); |
| 283 | for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { |
| 284 | card->write.ccws[cnt].cmd_code = LCS_CCW_WRITE; |
| 285 | card->write.ccws[cnt].count = 0; |
| 286 | card->write.ccws[cnt].flags = |
| 287 | CCW_FLAG_SUSPEND | CCW_FLAG_CC | CCW_FLAG_SLI; |
| 288 | /* |
| 289 | * Note: we have allocated the buffer with GFP_DMA, so |
| 290 | * we do not need to do set_normalized_cda. |
| 291 | */ |
| 292 | card->write.ccws[cnt].cda = |
| 293 | (__u32) __pa(card->write.iob[cnt].data); |
| 294 | } |
| 295 | /* Last ccw is a tic (transfer in channel). */ |
| 296 | card->write.ccws[LCS_NUM_BUFFS].cmd_code = LCS_CCW_TRANSFER; |
| 297 | card->write.ccws[LCS_NUM_BUFFS].cda = |
| 298 | (__u32) __pa(card->write.ccws); |
| 299 | /* Set initial state of the write channel. */ |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 300 | card->read.state = LCS_CH_STATE_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | card->write.io_idx = 0; |
| 303 | card->write.buf_idx = 0; |
| 304 | } |
| 305 | |
| 306 | static void |
| 307 | lcs_setup_write(struct lcs_card *card) |
| 308 | { |
| 309 | LCS_DBF_TEXT(3, setup, "initwrit"); |
| 310 | |
| 311 | lcs_setup_write_ccws(card); |
| 312 | /* Initialize write channel tasklet. */ |
| 313 | card->write.irq_tasklet.data = (unsigned long) &card->write; |
| 314 | card->write.irq_tasklet.func = lcs_tasklet; |
| 315 | /* Initialize waitqueue. */ |
| 316 | init_waitqueue_head(&card->write.wait_q); |
| 317 | } |
| 318 | |
| 319 | static void |
| 320 | lcs_set_allowed_threads(struct lcs_card *card, unsigned long threads) |
| 321 | { |
| 322 | unsigned long flags; |
| 323 | |
| 324 | spin_lock_irqsave(&card->mask_lock, flags); |
| 325 | card->thread_allowed_mask = threads; |
| 326 | spin_unlock_irqrestore(&card->mask_lock, flags); |
| 327 | wake_up(&card->wait_q); |
| 328 | } |
| 329 | static inline int |
| 330 | lcs_threads_running(struct lcs_card *card, unsigned long threads) |
| 331 | { |
| 332 | unsigned long flags; |
| 333 | int rc = 0; |
| 334 | |
| 335 | spin_lock_irqsave(&card->mask_lock, flags); |
| 336 | rc = (card->thread_running_mask & threads); |
| 337 | spin_unlock_irqrestore(&card->mask_lock, flags); |
| 338 | return rc; |
| 339 | } |
| 340 | |
| 341 | static int |
| 342 | lcs_wait_for_threads(struct lcs_card *card, unsigned long threads) |
| 343 | { |
| 344 | return wait_event_interruptible(card->wait_q, |
| 345 | lcs_threads_running(card, threads) == 0); |
| 346 | } |
| 347 | |
| 348 | static inline int |
| 349 | lcs_set_thread_start_bit(struct lcs_card *card, unsigned long thread) |
| 350 | { |
| 351 | unsigned long flags; |
| 352 | |
| 353 | spin_lock_irqsave(&card->mask_lock, flags); |
| 354 | if ( !(card->thread_allowed_mask & thread) || |
| 355 | (card->thread_start_mask & thread) ) { |
| 356 | spin_unlock_irqrestore(&card->mask_lock, flags); |
| 357 | return -EPERM; |
| 358 | } |
| 359 | card->thread_start_mask |= thread; |
| 360 | spin_unlock_irqrestore(&card->mask_lock, flags); |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static void |
| 365 | lcs_clear_thread_running_bit(struct lcs_card *card, unsigned long thread) |
| 366 | { |
| 367 | unsigned long flags; |
| 368 | |
| 369 | spin_lock_irqsave(&card->mask_lock, flags); |
| 370 | card->thread_running_mask &= ~thread; |
| 371 | spin_unlock_irqrestore(&card->mask_lock, flags); |
| 372 | wake_up(&card->wait_q); |
| 373 | } |
| 374 | |
| 375 | static inline int |
| 376 | __lcs_do_run_thread(struct lcs_card *card, unsigned long thread) |
| 377 | { |
| 378 | unsigned long flags; |
| 379 | int rc = 0; |
| 380 | |
| 381 | spin_lock_irqsave(&card->mask_lock, flags); |
| 382 | if (card->thread_start_mask & thread){ |
| 383 | if ((card->thread_allowed_mask & thread) && |
| 384 | !(card->thread_running_mask & thread)){ |
| 385 | rc = 1; |
| 386 | card->thread_start_mask &= ~thread; |
| 387 | card->thread_running_mask |= thread; |
| 388 | } else |
| 389 | rc = -EPERM; |
| 390 | } |
| 391 | spin_unlock_irqrestore(&card->mask_lock, flags); |
| 392 | return rc; |
| 393 | } |
| 394 | |
| 395 | static int |
| 396 | lcs_do_run_thread(struct lcs_card *card, unsigned long thread) |
| 397 | { |
| 398 | int rc = 0; |
| 399 | wait_event(card->wait_q, |
| 400 | (rc = __lcs_do_run_thread(card, thread)) >= 0); |
| 401 | return rc; |
| 402 | } |
| 403 | |
| 404 | static int |
| 405 | lcs_do_start_thread(struct lcs_card *card, unsigned long thread) |
| 406 | { |
| 407 | unsigned long flags; |
| 408 | int rc = 0; |
| 409 | |
| 410 | spin_lock_irqsave(&card->mask_lock, flags); |
| 411 | LCS_DBF_TEXT_(4, trace, " %02x%02x%02x", |
| 412 | (u8) card->thread_start_mask, |
| 413 | (u8) card->thread_allowed_mask, |
| 414 | (u8) card->thread_running_mask); |
| 415 | rc = (card->thread_start_mask & thread); |
| 416 | spin_unlock_irqrestore(&card->mask_lock, flags); |
| 417 | return rc; |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Initialize channels,card and state machines. |
| 422 | */ |
| 423 | static void |
| 424 | lcs_setup_card(struct lcs_card *card) |
| 425 | { |
| 426 | LCS_DBF_TEXT(2, setup, "initcard"); |
| 427 | LCS_DBF_HEX(2, setup, &card, sizeof(void*)); |
| 428 | |
| 429 | lcs_setup_read(card); |
| 430 | lcs_setup_write(card); |
| 431 | /* Set cards initial state. */ |
| 432 | card->state = DEV_STATE_DOWN; |
| 433 | card->tx_buffer = NULL; |
| 434 | card->tx_emitted = 0; |
| 435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | init_waitqueue_head(&card->wait_q); |
| 437 | spin_lock_init(&card->lock); |
| 438 | spin_lock_init(&card->ipm_lock); |
| 439 | spin_lock_init(&card->mask_lock); |
| 440 | #ifdef CONFIG_IP_MULTICAST |
| 441 | INIT_LIST_HEAD(&card->ipm_list); |
| 442 | #endif |
| 443 | INIT_LIST_HEAD(&card->lancmd_waiters); |
| 444 | } |
| 445 | |
| 446 | static inline void |
| 447 | lcs_clear_multicast_list(struct lcs_card *card) |
| 448 | { |
| 449 | #ifdef CONFIG_IP_MULTICAST |
| 450 | struct lcs_ipm_list *ipm; |
| 451 | unsigned long flags; |
| 452 | |
| 453 | /* Free multicast list. */ |
| 454 | LCS_DBF_TEXT(3, setup, "clmclist"); |
| 455 | spin_lock_irqsave(&card->ipm_lock, flags); |
| 456 | while (!list_empty(&card->ipm_list)){ |
| 457 | ipm = list_entry(card->ipm_list.next, |
| 458 | struct lcs_ipm_list, list); |
| 459 | list_del(&ipm->list); |
| 460 | if (ipm->ipm_state != LCS_IPM_STATE_SET_REQUIRED){ |
| 461 | spin_unlock_irqrestore(&card->ipm_lock, flags); |
| 462 | lcs_send_delipm(card, ipm); |
| 463 | spin_lock_irqsave(&card->ipm_lock, flags); |
| 464 | } |
| 465 | kfree(ipm); |
| 466 | } |
| 467 | spin_unlock_irqrestore(&card->ipm_lock, flags); |
| 468 | #endif |
| 469 | } |
| 470 | /** |
| 471 | * Cleanup channels,card and state machines. |
| 472 | */ |
| 473 | static void |
| 474 | lcs_cleanup_card(struct lcs_card *card) |
| 475 | { |
| 476 | |
| 477 | LCS_DBF_TEXT(3, setup, "cleancrd"); |
| 478 | LCS_DBF_HEX(2,setup,&card,sizeof(void*)); |
| 479 | |
| 480 | if (card->dev != NULL) |
| 481 | free_netdev(card->dev); |
| 482 | /* Cleanup channels. */ |
| 483 | lcs_cleanup_channel(&card->write); |
| 484 | lcs_cleanup_channel(&card->read); |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Start channel. |
| 489 | */ |
| 490 | static int |
| 491 | lcs_start_channel(struct lcs_channel *channel) |
| 492 | { |
| 493 | unsigned long flags; |
| 494 | int rc; |
| 495 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 496 | LCS_DBF_TEXT_(4, trace,"ssch%s", dev_name(&channel->ccwdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 498 | rc = ccw_device_start(channel->ccwdev, |
| 499 | channel->ccws + channel->io_idx, 0, 0, |
| 500 | DOIO_DENY_PREFETCH | DOIO_ALLOW_SUSPEND); |
| 501 | if (rc == 0) |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 502 | channel->state = LCS_CH_STATE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 504 | if (rc) { |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 505 | LCS_DBF_TEXT_(4,trace,"essh%s", |
| 506 | dev_name(&channel->ccwdev->dev)); |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 507 | dev_err(&channel->ccwdev->dev, |
| 508 | "Starting an LCS device resulted in an error," |
| 509 | " rc=%d!\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } |
| 511 | return rc; |
| 512 | } |
| 513 | |
| 514 | static int |
| 515 | lcs_clear_channel(struct lcs_channel *channel) |
| 516 | { |
| 517 | unsigned long flags; |
| 518 | int rc; |
| 519 | |
| 520 | LCS_DBF_TEXT(4,trace,"clearch"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 521 | LCS_DBF_TEXT_(4, trace, "%s", dev_name(&channel->ccwdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 523 | rc = ccw_device_clear(channel->ccwdev, (addr_t) channel); |
| 524 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 525 | if (rc) { |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 526 | LCS_DBF_TEXT_(4, trace, "ecsc%s", |
| 527 | dev_name(&channel->ccwdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | return rc; |
| 529 | } |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 530 | wait_event(channel->wait_q, (channel->state == LCS_CH_STATE_CLEARED)); |
| 531 | channel->state = LCS_CH_STATE_STOPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | return rc; |
| 533 | } |
| 534 | |
| 535 | |
| 536 | /** |
| 537 | * Stop channel. |
| 538 | */ |
| 539 | static int |
| 540 | lcs_stop_channel(struct lcs_channel *channel) |
| 541 | { |
| 542 | unsigned long flags; |
| 543 | int rc; |
| 544 | |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 545 | if (channel->state == LCS_CH_STATE_STOPPED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | return 0; |
| 547 | LCS_DBF_TEXT(4,trace,"haltsch"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 548 | LCS_DBF_TEXT_(4, trace, "%s", dev_name(&channel->ccwdev->dev)); |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 549 | channel->state = LCS_CH_STATE_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 551 | rc = ccw_device_halt(channel->ccwdev, (addr_t) channel); |
| 552 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 553 | if (rc) { |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 554 | LCS_DBF_TEXT_(4, trace, "ehsc%s", |
| 555 | dev_name(&channel->ccwdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | return rc; |
| 557 | } |
| 558 | /* Asynchronous halt initialted. Wait for its completion. */ |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 559 | wait_event(channel->wait_q, (channel->state == LCS_CH_STATE_HALTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | lcs_clear_channel(channel); |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * start read and write channel |
| 566 | */ |
| 567 | static int |
| 568 | lcs_start_channels(struct lcs_card *card) |
| 569 | { |
| 570 | int rc; |
| 571 | |
| 572 | LCS_DBF_TEXT(2, trace, "chstart"); |
| 573 | /* start read channel */ |
| 574 | rc = lcs_start_channel(&card->read); |
| 575 | if (rc) |
| 576 | return rc; |
| 577 | /* start write channel */ |
| 578 | rc = lcs_start_channel(&card->write); |
| 579 | if (rc) |
| 580 | lcs_stop_channel(&card->read); |
| 581 | return rc; |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * stop read and write channel |
| 586 | */ |
| 587 | static int |
| 588 | lcs_stop_channels(struct lcs_card *card) |
| 589 | { |
| 590 | LCS_DBF_TEXT(2, trace, "chhalt"); |
| 591 | lcs_stop_channel(&card->read); |
| 592 | lcs_stop_channel(&card->write); |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * Get empty buffer. |
| 598 | */ |
| 599 | static struct lcs_buffer * |
| 600 | __lcs_get_buffer(struct lcs_channel *channel) |
| 601 | { |
| 602 | int index; |
| 603 | |
| 604 | LCS_DBF_TEXT(5, trace, "_getbuff"); |
| 605 | index = channel->io_idx; |
| 606 | do { |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 607 | if (channel->iob[index].state == LCS_BUF_STATE_EMPTY) { |
| 608 | channel->iob[index].state = LCS_BUF_STATE_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return channel->iob + index; |
| 610 | } |
| 611 | index = (index + 1) & (LCS_NUM_BUFFS - 1); |
| 612 | } while (index != channel->io_idx); |
| 613 | return NULL; |
| 614 | } |
| 615 | |
| 616 | static struct lcs_buffer * |
| 617 | lcs_get_buffer(struct lcs_channel *channel) |
| 618 | { |
| 619 | struct lcs_buffer *buffer; |
| 620 | unsigned long flags; |
| 621 | |
| 622 | LCS_DBF_TEXT(5, trace, "getbuff"); |
| 623 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 624 | buffer = __lcs_get_buffer(channel); |
| 625 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 626 | return buffer; |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Resume channel program if the channel is suspended. |
| 631 | */ |
| 632 | static int |
| 633 | __lcs_resume_channel(struct lcs_channel *channel) |
| 634 | { |
| 635 | int rc; |
| 636 | |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 637 | if (channel->state != LCS_CH_STATE_SUSPENDED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | return 0; |
| 639 | if (channel->ccws[channel->io_idx].flags & CCW_FLAG_SUSPEND) |
| 640 | return 0; |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 641 | LCS_DBF_TEXT_(5, trace, "rsch%s", dev_name(&channel->ccwdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | rc = ccw_device_resume(channel->ccwdev); |
| 643 | if (rc) { |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 644 | LCS_DBF_TEXT_(4, trace, "ersc%s", |
| 645 | dev_name(&channel->ccwdev->dev)); |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 646 | dev_err(&channel->ccwdev->dev, |
| 647 | "Sending data from the LCS device to the LAN failed" |
| 648 | " with rc=%d\n",rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } else |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 650 | channel->state = LCS_CH_STATE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | return rc; |
| 652 | |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Make a buffer ready for processing. |
| 657 | */ |
| 658 | static inline void |
| 659 | __lcs_ready_buffer_bits(struct lcs_channel *channel, int index) |
| 660 | { |
| 661 | int prev, next; |
| 662 | |
| 663 | LCS_DBF_TEXT(5, trace, "rdybits"); |
| 664 | prev = (index - 1) & (LCS_NUM_BUFFS - 1); |
| 665 | next = (index + 1) & (LCS_NUM_BUFFS - 1); |
| 666 | /* Check if we may clear the suspend bit of this buffer. */ |
| 667 | if (channel->ccws[next].flags & CCW_FLAG_SUSPEND) { |
| 668 | /* Check if we have to set the PCI bit. */ |
| 669 | if (!(channel->ccws[prev].flags & CCW_FLAG_SUSPEND)) |
| 670 | /* Suspend bit of the previous buffer is not set. */ |
| 671 | channel->ccws[index].flags |= CCW_FLAG_PCI; |
| 672 | /* Suspend bit of the next buffer is set. */ |
| 673 | channel->ccws[index].flags &= ~CCW_FLAG_SUSPEND; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | static int |
| 678 | lcs_ready_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer) |
| 679 | { |
| 680 | unsigned long flags; |
| 681 | int index, rc; |
| 682 | |
| 683 | LCS_DBF_TEXT(5, trace, "rdybuff"); |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 684 | BUG_ON(buffer->state != LCS_BUF_STATE_LOCKED && |
| 685 | buffer->state != LCS_BUF_STATE_PROCESSED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 687 | buffer->state = LCS_BUF_STATE_READY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | index = buffer - channel->iob; |
| 689 | /* Set length. */ |
| 690 | channel->ccws[index].count = buffer->count; |
| 691 | /* Check relevant PCI/suspend bits. */ |
| 692 | __lcs_ready_buffer_bits(channel, index); |
| 693 | rc = __lcs_resume_channel(channel); |
| 694 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 695 | return rc; |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Mark the buffer as processed. Take care of the suspend bit |
| 700 | * of the previous buffer. This function is called from |
| 701 | * interrupt context, so the lock must not be taken. |
| 702 | */ |
| 703 | static int |
| 704 | __lcs_processed_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer) |
| 705 | { |
| 706 | int index, prev, next; |
| 707 | |
| 708 | LCS_DBF_TEXT(5, trace, "prcsbuff"); |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 709 | BUG_ON(buffer->state != LCS_BUF_STATE_READY); |
| 710 | buffer->state = LCS_BUF_STATE_PROCESSED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | index = buffer - channel->iob; |
| 712 | prev = (index - 1) & (LCS_NUM_BUFFS - 1); |
| 713 | next = (index + 1) & (LCS_NUM_BUFFS - 1); |
| 714 | /* Set the suspend bit and clear the PCI bit of this buffer. */ |
| 715 | channel->ccws[index].flags |= CCW_FLAG_SUSPEND; |
| 716 | channel->ccws[index].flags &= ~CCW_FLAG_PCI; |
| 717 | /* Check the suspend bit of the previous buffer. */ |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 718 | if (channel->iob[prev].state == LCS_BUF_STATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | /* |
| 720 | * Previous buffer is in state ready. It might have |
| 721 | * happened in lcs_ready_buffer that the suspend bit |
| 722 | * has not been cleared to avoid an endless loop. |
| 723 | * Do it now. |
| 724 | */ |
| 725 | __lcs_ready_buffer_bits(channel, prev); |
| 726 | } |
| 727 | /* Clear PCI bit of next buffer. */ |
| 728 | channel->ccws[next].flags &= ~CCW_FLAG_PCI; |
| 729 | return __lcs_resume_channel(channel); |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * Put a processed buffer back to state empty. |
| 734 | */ |
| 735 | static void |
| 736 | lcs_release_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer) |
| 737 | { |
| 738 | unsigned long flags; |
| 739 | |
| 740 | LCS_DBF_TEXT(5, trace, "relbuff"); |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 741 | BUG_ON(buffer->state != LCS_BUF_STATE_LOCKED && |
| 742 | buffer->state != LCS_BUF_STATE_PROCESSED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 744 | buffer->state = LCS_BUF_STATE_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * Get buffer for a lan command. |
| 750 | */ |
| 751 | static struct lcs_buffer * |
| 752 | lcs_get_lancmd(struct lcs_card *card, int count) |
| 753 | { |
| 754 | struct lcs_buffer *buffer; |
| 755 | struct lcs_cmd *cmd; |
| 756 | |
| 757 | LCS_DBF_TEXT(4, trace, "getlncmd"); |
| 758 | /* Get buffer and wait if none is available. */ |
| 759 | wait_event(card->write.wait_q, |
| 760 | ((buffer = lcs_get_buffer(&card->write)) != NULL)); |
| 761 | count += sizeof(struct lcs_header); |
| 762 | *(__u16 *)(buffer->data + count) = 0; |
| 763 | buffer->count = count + sizeof(__u16); |
| 764 | buffer->callback = lcs_release_buffer; |
| 765 | cmd = (struct lcs_cmd *) buffer->data; |
| 766 | cmd->offset = count; |
| 767 | cmd->type = LCS_FRAME_TYPE_CONTROL; |
| 768 | cmd->slot = 0; |
| 769 | return buffer; |
| 770 | } |
| 771 | |
| 772 | |
| 773 | static void |
| 774 | lcs_get_reply(struct lcs_reply *reply) |
| 775 | { |
| 776 | WARN_ON(atomic_read(&reply->refcnt) <= 0); |
| 777 | atomic_inc(&reply->refcnt); |
| 778 | } |
| 779 | |
| 780 | static void |
| 781 | lcs_put_reply(struct lcs_reply *reply) |
| 782 | { |
| 783 | WARN_ON(atomic_read(&reply->refcnt) <= 0); |
| 784 | if (atomic_dec_and_test(&reply->refcnt)) { |
| 785 | kfree(reply); |
| 786 | } |
| 787 | |
| 788 | } |
| 789 | |
| 790 | static struct lcs_reply * |
| 791 | lcs_alloc_reply(struct lcs_cmd *cmd) |
| 792 | { |
| 793 | struct lcs_reply *reply; |
| 794 | |
| 795 | LCS_DBF_TEXT(4, trace, "getreply"); |
| 796 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 797 | reply = kzalloc(sizeof(struct lcs_reply), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | if (!reply) |
| 799 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | atomic_set(&reply->refcnt,1); |
| 801 | reply->sequence_no = cmd->sequence_no; |
| 802 | reply->received = 0; |
| 803 | reply->rc = 0; |
| 804 | init_waitqueue_head(&reply->wait_q); |
| 805 | |
| 806 | return reply; |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * Notifier function for lancmd replies. Called from read irq. |
| 811 | */ |
| 812 | static void |
| 813 | lcs_notify_lancmd_waiters(struct lcs_card *card, struct lcs_cmd *cmd) |
| 814 | { |
| 815 | struct list_head *l, *n; |
| 816 | struct lcs_reply *reply; |
| 817 | |
| 818 | LCS_DBF_TEXT(4, trace, "notiwait"); |
| 819 | spin_lock(&card->lock); |
| 820 | list_for_each_safe(l, n, &card->lancmd_waiters) { |
| 821 | reply = list_entry(l, struct lcs_reply, list); |
| 822 | if (reply->sequence_no == cmd->sequence_no) { |
| 823 | lcs_get_reply(reply); |
| 824 | list_del_init(&reply->list); |
| 825 | if (reply->callback != NULL) |
| 826 | reply->callback(card, cmd); |
| 827 | reply->received = 1; |
| 828 | reply->rc = cmd->return_code; |
| 829 | wake_up(&reply->wait_q); |
| 830 | lcs_put_reply(reply); |
| 831 | break; |
| 832 | } |
| 833 | } |
| 834 | spin_unlock(&card->lock); |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * Emit buffer of a lan comand. |
| 839 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 840 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | lcs_lancmd_timeout(unsigned long data) |
| 842 | { |
| 843 | struct lcs_reply *reply, *list_reply, *r; |
| 844 | unsigned long flags; |
| 845 | |
| 846 | LCS_DBF_TEXT(4, trace, "timeout"); |
| 847 | reply = (struct lcs_reply *) data; |
| 848 | spin_lock_irqsave(&reply->card->lock, flags); |
| 849 | list_for_each_entry_safe(list_reply, r, |
| 850 | &reply->card->lancmd_waiters,list) { |
| 851 | if (reply == list_reply) { |
| 852 | lcs_get_reply(reply); |
| 853 | list_del_init(&reply->list); |
| 854 | spin_unlock_irqrestore(&reply->card->lock, flags); |
| 855 | reply->received = 1; |
| 856 | reply->rc = -ETIME; |
| 857 | wake_up(&reply->wait_q); |
| 858 | lcs_put_reply(reply); |
| 859 | return; |
| 860 | } |
| 861 | } |
| 862 | spin_unlock_irqrestore(&reply->card->lock, flags); |
| 863 | } |
| 864 | |
| 865 | static int |
| 866 | lcs_send_lancmd(struct lcs_card *card, struct lcs_buffer *buffer, |
| 867 | void (*reply_callback)(struct lcs_card *, struct lcs_cmd *)) |
| 868 | { |
| 869 | struct lcs_reply *reply; |
| 870 | struct lcs_cmd *cmd; |
| 871 | struct timer_list timer; |
| 872 | unsigned long flags; |
| 873 | int rc; |
| 874 | |
| 875 | LCS_DBF_TEXT(4, trace, "sendcmd"); |
| 876 | cmd = (struct lcs_cmd *) buffer->data; |
| 877 | cmd->return_code = 0; |
| 878 | cmd->sequence_no = card->sequence_no++; |
| 879 | reply = lcs_alloc_reply(cmd); |
| 880 | if (!reply) |
| 881 | return -ENOMEM; |
| 882 | reply->callback = reply_callback; |
| 883 | reply->card = card; |
| 884 | spin_lock_irqsave(&card->lock, flags); |
| 885 | list_add_tail(&reply->list, &card->lancmd_waiters); |
| 886 | spin_unlock_irqrestore(&card->lock, flags); |
| 887 | |
| 888 | buffer->callback = lcs_release_buffer; |
| 889 | rc = lcs_ready_buffer(&card->write, buffer); |
| 890 | if (rc) |
| 891 | return rc; |
| 892 | init_timer(&timer); |
| 893 | timer.function = lcs_lancmd_timeout; |
| 894 | timer.data = (unsigned long) reply; |
| 895 | timer.expires = jiffies + HZ*card->lancmd_timeout; |
| 896 | add_timer(&timer); |
| 897 | wait_event(reply->wait_q, reply->received); |
| 898 | del_timer_sync(&timer); |
| 899 | LCS_DBF_TEXT_(4, trace, "rc:%d",reply->rc); |
| 900 | rc = reply->rc; |
| 901 | lcs_put_reply(reply); |
| 902 | return rc ? -EIO : 0; |
| 903 | } |
| 904 | |
| 905 | /** |
| 906 | * LCS startup command |
| 907 | */ |
| 908 | static int |
| 909 | lcs_send_startup(struct lcs_card *card, __u8 initiator) |
| 910 | { |
| 911 | struct lcs_buffer *buffer; |
| 912 | struct lcs_cmd *cmd; |
| 913 | |
| 914 | LCS_DBF_TEXT(2, trace, "startup"); |
| 915 | buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); |
| 916 | cmd = (struct lcs_cmd *) buffer->data; |
| 917 | cmd->cmd_code = LCS_CMD_STARTUP; |
| 918 | cmd->initiator = initiator; |
| 919 | cmd->cmd.lcs_startup.buff_size = LCS_IOBUFFERSIZE; |
| 920 | return lcs_send_lancmd(card, buffer, NULL); |
| 921 | } |
| 922 | |
| 923 | /** |
| 924 | * LCS shutdown command |
| 925 | */ |
| 926 | static int |
| 927 | lcs_send_shutdown(struct lcs_card *card) |
| 928 | { |
| 929 | struct lcs_buffer *buffer; |
| 930 | struct lcs_cmd *cmd; |
| 931 | |
| 932 | LCS_DBF_TEXT(2, trace, "shutdown"); |
| 933 | buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); |
| 934 | cmd = (struct lcs_cmd *) buffer->data; |
| 935 | cmd->cmd_code = LCS_CMD_SHUTDOWN; |
| 936 | cmd->initiator = LCS_INITIATOR_TCPIP; |
| 937 | return lcs_send_lancmd(card, buffer, NULL); |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * LCS lanstat command |
| 942 | */ |
| 943 | static void |
| 944 | __lcs_lanstat_cb(struct lcs_card *card, struct lcs_cmd *cmd) |
| 945 | { |
| 946 | LCS_DBF_TEXT(2, trace, "statcb"); |
| 947 | memcpy(card->mac, cmd->cmd.lcs_lanstat_cmd.mac_addr, LCS_MAC_LENGTH); |
| 948 | } |
| 949 | |
| 950 | static int |
| 951 | lcs_send_lanstat(struct lcs_card *card) |
| 952 | { |
| 953 | struct lcs_buffer *buffer; |
| 954 | struct lcs_cmd *cmd; |
| 955 | |
| 956 | LCS_DBF_TEXT(2,trace, "cmdstat"); |
| 957 | buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); |
| 958 | cmd = (struct lcs_cmd *) buffer->data; |
| 959 | /* Setup lanstat command. */ |
| 960 | cmd->cmd_code = LCS_CMD_LANSTAT; |
| 961 | cmd->initiator = LCS_INITIATOR_TCPIP; |
| 962 | cmd->cmd.lcs_std_cmd.lan_type = card->lan_type; |
| 963 | cmd->cmd.lcs_std_cmd.portno = card->portno; |
| 964 | return lcs_send_lancmd(card, buffer, __lcs_lanstat_cb); |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * send stoplan command |
| 969 | */ |
| 970 | static int |
| 971 | lcs_send_stoplan(struct lcs_card *card, __u8 initiator) |
| 972 | { |
| 973 | struct lcs_buffer *buffer; |
| 974 | struct lcs_cmd *cmd; |
| 975 | |
| 976 | LCS_DBF_TEXT(2, trace, "cmdstpln"); |
| 977 | buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); |
| 978 | cmd = (struct lcs_cmd *) buffer->data; |
| 979 | cmd->cmd_code = LCS_CMD_STOPLAN; |
| 980 | cmd->initiator = initiator; |
| 981 | cmd->cmd.lcs_std_cmd.lan_type = card->lan_type; |
| 982 | cmd->cmd.lcs_std_cmd.portno = card->portno; |
| 983 | return lcs_send_lancmd(card, buffer, NULL); |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * send startlan command |
| 988 | */ |
| 989 | static void |
| 990 | __lcs_send_startlan_cb(struct lcs_card *card, struct lcs_cmd *cmd) |
| 991 | { |
| 992 | LCS_DBF_TEXT(2, trace, "srtlancb"); |
| 993 | card->lan_type = cmd->cmd.lcs_std_cmd.lan_type; |
| 994 | card->portno = cmd->cmd.lcs_std_cmd.portno; |
| 995 | } |
| 996 | |
| 997 | static int |
| 998 | lcs_send_startlan(struct lcs_card *card, __u8 initiator) |
| 999 | { |
| 1000 | struct lcs_buffer *buffer; |
| 1001 | struct lcs_cmd *cmd; |
| 1002 | |
| 1003 | LCS_DBF_TEXT(2, trace, "cmdstaln"); |
| 1004 | buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); |
| 1005 | cmd = (struct lcs_cmd *) buffer->data; |
| 1006 | cmd->cmd_code = LCS_CMD_STARTLAN; |
| 1007 | cmd->initiator = initiator; |
| 1008 | cmd->cmd.lcs_std_cmd.lan_type = card->lan_type; |
| 1009 | cmd->cmd.lcs_std_cmd.portno = card->portno; |
| 1010 | return lcs_send_lancmd(card, buffer, __lcs_send_startlan_cb); |
| 1011 | } |
| 1012 | |
| 1013 | #ifdef CONFIG_IP_MULTICAST |
| 1014 | /** |
| 1015 | * send setipm command (Multicast) |
| 1016 | */ |
| 1017 | static int |
| 1018 | lcs_send_setipm(struct lcs_card *card,struct lcs_ipm_list *ipm_list) |
| 1019 | { |
| 1020 | struct lcs_buffer *buffer; |
| 1021 | struct lcs_cmd *cmd; |
| 1022 | |
| 1023 | LCS_DBF_TEXT(2, trace, "cmdsetim"); |
| 1024 | buffer = lcs_get_lancmd(card, LCS_MULTICAST_CMD_SIZE); |
| 1025 | cmd = (struct lcs_cmd *) buffer->data; |
| 1026 | cmd->cmd_code = LCS_CMD_SETIPM; |
| 1027 | cmd->initiator = LCS_INITIATOR_TCPIP; |
| 1028 | cmd->cmd.lcs_qipassist.lan_type = card->lan_type; |
| 1029 | cmd->cmd.lcs_qipassist.portno = card->portno; |
| 1030 | cmd->cmd.lcs_qipassist.version = 4; |
| 1031 | cmd->cmd.lcs_qipassist.num_ip_pairs = 1; |
| 1032 | memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair, |
| 1033 | &ipm_list->ipm, sizeof (struct lcs_ip_mac_pair)); |
| 1034 | LCS_DBF_TEXT_(2, trace, "%x",ipm_list->ipm.ip_addr); |
| 1035 | return lcs_send_lancmd(card, buffer, NULL); |
| 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * send delipm command (Multicast) |
| 1040 | */ |
| 1041 | static int |
| 1042 | lcs_send_delipm(struct lcs_card *card,struct lcs_ipm_list *ipm_list) |
| 1043 | { |
| 1044 | struct lcs_buffer *buffer; |
| 1045 | struct lcs_cmd *cmd; |
| 1046 | |
| 1047 | LCS_DBF_TEXT(2, trace, "cmddelim"); |
| 1048 | buffer = lcs_get_lancmd(card, LCS_MULTICAST_CMD_SIZE); |
| 1049 | cmd = (struct lcs_cmd *) buffer->data; |
| 1050 | cmd->cmd_code = LCS_CMD_DELIPM; |
| 1051 | cmd->initiator = LCS_INITIATOR_TCPIP; |
| 1052 | cmd->cmd.lcs_qipassist.lan_type = card->lan_type; |
| 1053 | cmd->cmd.lcs_qipassist.portno = card->portno; |
| 1054 | cmd->cmd.lcs_qipassist.version = 4; |
| 1055 | cmd->cmd.lcs_qipassist.num_ip_pairs = 1; |
| 1056 | memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair, |
| 1057 | &ipm_list->ipm, sizeof (struct lcs_ip_mac_pair)); |
| 1058 | LCS_DBF_TEXT_(2, trace, "%x",ipm_list->ipm.ip_addr); |
| 1059 | return lcs_send_lancmd(card, buffer, NULL); |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| 1063 | * check if multicast is supported by LCS |
| 1064 | */ |
| 1065 | static void |
| 1066 | __lcs_check_multicast_cb(struct lcs_card *card, struct lcs_cmd *cmd) |
| 1067 | { |
| 1068 | LCS_DBF_TEXT(2, trace, "chkmccb"); |
| 1069 | card->ip_assists_supported = |
| 1070 | cmd->cmd.lcs_qipassist.ip_assists_supported; |
| 1071 | card->ip_assists_enabled = |
| 1072 | cmd->cmd.lcs_qipassist.ip_assists_enabled; |
| 1073 | } |
| 1074 | |
| 1075 | static int |
| 1076 | lcs_check_multicast_support(struct lcs_card *card) |
| 1077 | { |
| 1078 | struct lcs_buffer *buffer; |
| 1079 | struct lcs_cmd *cmd; |
| 1080 | int rc; |
| 1081 | |
| 1082 | LCS_DBF_TEXT(2, trace, "cmdqipa"); |
| 1083 | /* Send query ipassist. */ |
| 1084 | buffer = lcs_get_lancmd(card, LCS_STD_CMD_SIZE); |
| 1085 | cmd = (struct lcs_cmd *) buffer->data; |
| 1086 | cmd->cmd_code = LCS_CMD_QIPASSIST; |
| 1087 | cmd->initiator = LCS_INITIATOR_TCPIP; |
| 1088 | cmd->cmd.lcs_qipassist.lan_type = card->lan_type; |
| 1089 | cmd->cmd.lcs_qipassist.portno = card->portno; |
| 1090 | cmd->cmd.lcs_qipassist.version = 4; |
| 1091 | cmd->cmd.lcs_qipassist.num_ip_pairs = 1; |
| 1092 | rc = lcs_send_lancmd(card, buffer, __lcs_check_multicast_cb); |
| 1093 | if (rc != 0) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1094 | pr_err("Query IPAssist failed. Assuming unsupported!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | return -EOPNOTSUPP; |
| 1096 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | if (card->ip_assists_supported & LCS_IPASS_MULTICAST_SUPPORT) |
| 1098 | return 0; |
| 1099 | return -EOPNOTSUPP; |
| 1100 | } |
| 1101 | |
| 1102 | /** |
| 1103 | * set or del multicast address on LCS card |
| 1104 | */ |
| 1105 | static void |
| 1106 | lcs_fix_multicast_list(struct lcs_card *card) |
| 1107 | { |
| 1108 | struct list_head failed_list; |
| 1109 | struct lcs_ipm_list *ipm, *tmp; |
| 1110 | unsigned long flags; |
| 1111 | int rc; |
| 1112 | |
| 1113 | LCS_DBF_TEXT(4,trace, "fixipm"); |
| 1114 | INIT_LIST_HEAD(&failed_list); |
| 1115 | spin_lock_irqsave(&card->ipm_lock, flags); |
| 1116 | list_modified: |
| 1117 | list_for_each_entry_safe(ipm, tmp, &card->ipm_list, list){ |
| 1118 | switch (ipm->ipm_state) { |
| 1119 | case LCS_IPM_STATE_SET_REQUIRED: |
| 1120 | /* del from ipm_list so noone else can tamper with |
| 1121 | * this entry */ |
| 1122 | list_del_init(&ipm->list); |
| 1123 | spin_unlock_irqrestore(&card->ipm_lock, flags); |
| 1124 | rc = lcs_send_setipm(card, ipm); |
| 1125 | spin_lock_irqsave(&card->ipm_lock, flags); |
| 1126 | if (rc) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1127 | pr_info("Adding multicast address failed." |
| 1128 | " Table possibly full!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | /* store ipm in failed list -> will be added |
| 1130 | * to ipm_list again, so a retry will be done |
| 1131 | * during the next call of this function */ |
| 1132 | list_add_tail(&ipm->list, &failed_list); |
| 1133 | } else { |
| 1134 | ipm->ipm_state = LCS_IPM_STATE_ON_CARD; |
| 1135 | /* re-insert into ipm_list */ |
| 1136 | list_add_tail(&ipm->list, &card->ipm_list); |
| 1137 | } |
| 1138 | goto list_modified; |
| 1139 | case LCS_IPM_STATE_DEL_REQUIRED: |
| 1140 | list_del(&ipm->list); |
| 1141 | spin_unlock_irqrestore(&card->ipm_lock, flags); |
| 1142 | lcs_send_delipm(card, ipm); |
| 1143 | spin_lock_irqsave(&card->ipm_lock, flags); |
| 1144 | kfree(ipm); |
| 1145 | goto list_modified; |
| 1146 | case LCS_IPM_STATE_ON_CARD: |
| 1147 | break; |
| 1148 | } |
| 1149 | } |
| 1150 | /* re-insert all entries from the failed_list into ipm_list */ |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 1151 | list_for_each_entry_safe(ipm, tmp, &failed_list, list) |
| 1152 | list_move_tail(&ipm->list, &card->ipm_list); |
| 1153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | spin_unlock_irqrestore(&card->ipm_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * get mac address for the relevant Multicast address |
| 1159 | */ |
| 1160 | static void |
Al Viro | 5a5a852 | 2006-11-14 21:43:44 -0800 | [diff] [blame] | 1161 | lcs_get_mac_for_ipm(__be32 ipm, char *mac, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | { |
| 1163 | LCS_DBF_TEXT(4,trace, "getmac"); |
| 1164 | if (dev->type == ARPHRD_IEEE802_TR) |
| 1165 | ip_tr_mc_map(ipm, mac); |
| 1166 | else |
| 1167 | ip_eth_mc_map(ipm, mac); |
| 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * function called by net device to handle multicast address relevant things |
| 1172 | */ |
| 1173 | static inline void |
| 1174 | lcs_remove_mc_addresses(struct lcs_card *card, struct in_device *in4_dev) |
| 1175 | { |
| 1176 | struct ip_mc_list *im4; |
| 1177 | struct list_head *l; |
| 1178 | struct lcs_ipm_list *ipm; |
| 1179 | unsigned long flags; |
| 1180 | char buf[MAX_ADDR_LEN]; |
| 1181 | |
| 1182 | LCS_DBF_TEXT(4, trace, "remmclst"); |
| 1183 | spin_lock_irqsave(&card->ipm_lock, flags); |
| 1184 | list_for_each(l, &card->ipm_list) { |
| 1185 | ipm = list_entry(l, struct lcs_ipm_list, list); |
| 1186 | for (im4 = in4_dev->mc_list; im4 != NULL; im4 = im4->next) { |
| 1187 | lcs_get_mac_for_ipm(im4->multiaddr, buf, card->dev); |
| 1188 | if ( (ipm->ipm.ip_addr == im4->multiaddr) && |
| 1189 | (memcmp(buf, &ipm->ipm.mac_addr, |
| 1190 | LCS_MAC_LENGTH) == 0) ) |
| 1191 | break; |
| 1192 | } |
| 1193 | if (im4 == NULL) |
| 1194 | ipm->ipm_state = LCS_IPM_STATE_DEL_REQUIRED; |
| 1195 | } |
| 1196 | spin_unlock_irqrestore(&card->ipm_lock, flags); |
| 1197 | } |
| 1198 | |
| 1199 | static inline struct lcs_ipm_list * |
| 1200 | lcs_check_addr_entry(struct lcs_card *card, struct ip_mc_list *im4, char *buf) |
| 1201 | { |
| 1202 | struct lcs_ipm_list *tmp, *ipm = NULL; |
| 1203 | struct list_head *l; |
| 1204 | unsigned long flags; |
| 1205 | |
| 1206 | LCS_DBF_TEXT(4, trace, "chkmcent"); |
| 1207 | spin_lock_irqsave(&card->ipm_lock, flags); |
| 1208 | list_for_each(l, &card->ipm_list) { |
| 1209 | tmp = list_entry(l, struct lcs_ipm_list, list); |
| 1210 | if ( (tmp->ipm.ip_addr == im4->multiaddr) && |
| 1211 | (memcmp(buf, &tmp->ipm.mac_addr, |
| 1212 | LCS_MAC_LENGTH) == 0) ) { |
| 1213 | ipm = tmp; |
| 1214 | break; |
| 1215 | } |
| 1216 | } |
| 1217 | spin_unlock_irqrestore(&card->ipm_lock, flags); |
| 1218 | return ipm; |
| 1219 | } |
| 1220 | |
| 1221 | static inline void |
| 1222 | lcs_set_mc_addresses(struct lcs_card *card, struct in_device *in4_dev) |
| 1223 | { |
| 1224 | |
| 1225 | struct ip_mc_list *im4; |
| 1226 | struct lcs_ipm_list *ipm; |
| 1227 | char buf[MAX_ADDR_LEN]; |
| 1228 | unsigned long flags; |
| 1229 | |
| 1230 | LCS_DBF_TEXT(4, trace, "setmclst"); |
| 1231 | for (im4 = in4_dev->mc_list; im4; im4 = im4->next) { |
| 1232 | lcs_get_mac_for_ipm(im4->multiaddr, buf, card->dev); |
| 1233 | ipm = lcs_check_addr_entry(card, im4, buf); |
| 1234 | if (ipm != NULL) |
| 1235 | continue; /* Address already in list. */ |
| 1236 | ipm = (struct lcs_ipm_list *) |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1237 | kzalloc(sizeof(struct lcs_ipm_list), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | if (ipm == NULL) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1239 | pr_info("Not enough memory to add" |
| 1240 | " new multicast entry!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | break; |
| 1242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | memcpy(&ipm->ipm.mac_addr, buf, LCS_MAC_LENGTH); |
| 1244 | ipm->ipm.ip_addr = im4->multiaddr; |
| 1245 | ipm->ipm_state = LCS_IPM_STATE_SET_REQUIRED; |
| 1246 | spin_lock_irqsave(&card->ipm_lock, flags); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1247 | LCS_DBF_HEX(2,trace,&ipm->ipm.ip_addr,4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | list_add(&ipm->list, &card->ipm_list); |
| 1249 | spin_unlock_irqrestore(&card->ipm_lock, flags); |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | static int |
| 1254 | lcs_register_mc_addresses(void *data) |
| 1255 | { |
| 1256 | struct lcs_card *card; |
| 1257 | struct in_device *in4_dev; |
| 1258 | |
| 1259 | card = (struct lcs_card *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
| 1261 | if (!lcs_do_run_thread(card, LCS_SET_MC_THREAD)) |
| 1262 | return 0; |
| 1263 | LCS_DBF_TEXT(4, trace, "regmulti"); |
| 1264 | |
| 1265 | in4_dev = in_dev_get(card->dev); |
| 1266 | if (in4_dev == NULL) |
| 1267 | goto out; |
| 1268 | read_lock(&in4_dev->mc_list_lock); |
| 1269 | lcs_remove_mc_addresses(card,in4_dev); |
| 1270 | lcs_set_mc_addresses(card, in4_dev); |
| 1271 | read_unlock(&in4_dev->mc_list_lock); |
| 1272 | in_dev_put(in4_dev); |
| 1273 | |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1274 | netif_carrier_off(card->dev); |
| 1275 | netif_tx_disable(card->dev); |
| 1276 | wait_event(card->write.wait_q, |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1277 | (card->write.state != LCS_CH_STATE_RUNNING)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | lcs_fix_multicast_list(card); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1279 | if (card->state == DEV_STATE_UP) { |
| 1280 | netif_carrier_on(card->dev); |
| 1281 | netif_wake_queue(card->dev); |
| 1282 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | out: |
| 1284 | lcs_clear_thread_running_bit(card, LCS_SET_MC_THREAD); |
| 1285 | return 0; |
| 1286 | } |
Heiko Carstens | 801599b | 2009-01-20 06:14:32 +0000 | [diff] [blame] | 1287 | #endif /* CONFIG_IP_MULTICAST */ |
| 1288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | /** |
| 1290 | * function called by net device to |
| 1291 | * handle multicast address relevant things |
| 1292 | */ |
| 1293 | static void |
| 1294 | lcs_set_multicast_list(struct net_device *dev) |
| 1295 | { |
Heiko Carstens | 801599b | 2009-01-20 06:14:32 +0000 | [diff] [blame] | 1296 | #ifdef CONFIG_IP_MULTICAST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | struct lcs_card *card; |
| 1298 | |
| 1299 | LCS_DBF_TEXT(4, trace, "setmulti"); |
Wang Chen | ad660e2 | 2008-12-06 23:57:49 -0800 | [diff] [blame] | 1300 | card = (struct lcs_card *) dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1302 | if (!lcs_set_thread_start_bit(card, LCS_SET_MC_THREAD)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | schedule_work(&card->kernel_thread_starter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | #endif /* CONFIG_IP_MULTICAST */ |
Heiko Carstens | 801599b | 2009-01-20 06:14:32 +0000 | [diff] [blame] | 1305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | |
| 1307 | static long |
| 1308 | lcs_check_irb_error(struct ccw_device *cdev, struct irb *irb) |
| 1309 | { |
| 1310 | if (!IS_ERR(irb)) |
| 1311 | return 0; |
| 1312 | |
| 1313 | switch (PTR_ERR(irb)) { |
| 1314 | case -EIO: |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1315 | dev_warn(&cdev->dev, |
| 1316 | "An I/O-error occurred on the LCS device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | LCS_DBF_TEXT(2, trace, "ckirberr"); |
| 1318 | LCS_DBF_TEXT_(2, trace, " rc%d", -EIO); |
| 1319 | break; |
| 1320 | case -ETIMEDOUT: |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1321 | dev_warn(&cdev->dev, |
| 1322 | "A command timed out on the LCS device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | LCS_DBF_TEXT(2, trace, "ckirberr"); |
| 1324 | LCS_DBF_TEXT_(2, trace, " rc%d", -ETIMEDOUT); |
| 1325 | break; |
| 1326 | default: |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1327 | dev_warn(&cdev->dev, |
| 1328 | "An error occurred on the LCS device, rc=%ld\n", |
| 1329 | PTR_ERR(irb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | LCS_DBF_TEXT(2, trace, "ckirberr"); |
| 1331 | LCS_DBF_TEXT(2, trace, " rc???"); |
| 1332 | } |
| 1333 | return PTR_ERR(irb); |
| 1334 | } |
| 1335 | |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1336 | static int |
| 1337 | lcs_get_problem(struct ccw_device *cdev, struct irb *irb) |
| 1338 | { |
| 1339 | int dstat, cstat; |
| 1340 | char *sense; |
| 1341 | |
| 1342 | sense = (char *) irb->ecw; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1343 | cstat = irb->scsw.cmd.cstat; |
| 1344 | dstat = irb->scsw.cmd.dstat; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1345 | |
| 1346 | if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK | |
| 1347 | SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK | |
| 1348 | SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) { |
| 1349 | LCS_DBF_TEXT(2, trace, "CGENCHK"); |
| 1350 | return 1; |
| 1351 | } |
| 1352 | if (dstat & DEV_STAT_UNIT_CHECK) { |
| 1353 | if (sense[LCS_SENSE_BYTE_1] & |
| 1354 | LCS_SENSE_RESETTING_EVENT) { |
| 1355 | LCS_DBF_TEXT(2, trace, "REVIND"); |
| 1356 | return 1; |
| 1357 | } |
| 1358 | if (sense[LCS_SENSE_BYTE_0] & |
| 1359 | LCS_SENSE_CMD_REJECT) { |
| 1360 | LCS_DBF_TEXT(2, trace, "CMDREJ"); |
| 1361 | return 0; |
| 1362 | } |
| 1363 | if ((!sense[LCS_SENSE_BYTE_0]) && |
| 1364 | (!sense[LCS_SENSE_BYTE_1]) && |
| 1365 | (!sense[LCS_SENSE_BYTE_2]) && |
| 1366 | (!sense[LCS_SENSE_BYTE_3])) { |
| 1367 | LCS_DBF_TEXT(2, trace, "ZEROSEN"); |
| 1368 | return 0; |
| 1369 | } |
| 1370 | LCS_DBF_TEXT(2, trace, "DGENCHK"); |
| 1371 | return 1; |
| 1372 | } |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 1376 | static void |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1377 | lcs_schedule_recovery(struct lcs_card *card) |
| 1378 | { |
| 1379 | LCS_DBF_TEXT(2, trace, "startrec"); |
| 1380 | if (!lcs_set_thread_start_bit(card, LCS_RECOVERY_THREAD)) |
| 1381 | schedule_work(&card->kernel_thread_starter); |
| 1382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
| 1384 | /** |
| 1385 | * IRQ Handler for LCS channels |
| 1386 | */ |
| 1387 | static void |
| 1388 | lcs_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb) |
| 1389 | { |
| 1390 | struct lcs_card *card; |
| 1391 | struct lcs_channel *channel; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1392 | int rc, index; |
| 1393 | int cstat, dstat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
| 1395 | if (lcs_check_irb_error(cdev, irb)) |
| 1396 | return; |
| 1397 | |
| 1398 | card = CARD_FROM_DEV(cdev); |
| 1399 | if (card->read.ccwdev == cdev) |
| 1400 | channel = &card->read; |
| 1401 | else |
| 1402 | channel = &card->write; |
| 1403 | |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1404 | cstat = irb->scsw.cmd.cstat; |
| 1405 | dstat = irb->scsw.cmd.dstat; |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1406 | LCS_DBF_TEXT_(5, trace, "Rint%s", dev_name(&cdev->dev)); |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1407 | LCS_DBF_TEXT_(5, trace, "%4x%4x", irb->scsw.cmd.cstat, |
| 1408 | irb->scsw.cmd.dstat); |
| 1409 | LCS_DBF_TEXT_(5, trace, "%4x%4x", irb->scsw.cmd.fctl, |
| 1410 | irb->scsw.cmd.actl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1412 | /* Check for channel and device errors presented */ |
| 1413 | rc = lcs_get_problem(cdev, irb); |
| 1414 | if (rc || (dstat & DEV_STAT_UNIT_EXCEP)) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1415 | dev_warn(&cdev->dev, |
| 1416 | "The LCS device stopped because of an error," |
| 1417 | " dstat=0x%X, cstat=0x%X \n", |
| 1418 | dstat, cstat); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1419 | if (rc) { |
Klaus D. Wacker | 59579da | 2007-10-05 16:45:47 +0200 | [diff] [blame] | 1420 | channel->state = LCS_CH_STATE_ERROR; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1421 | } |
| 1422 | } |
Klaus D. Wacker | 59579da | 2007-10-05 16:45:47 +0200 | [diff] [blame] | 1423 | if (channel->state == LCS_CH_STATE_ERROR) { |
| 1424 | lcs_schedule_recovery(card); |
| 1425 | wake_up(&card->wait_q); |
| 1426 | return; |
| 1427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | /* How far in the ccw chain have we processed? */ |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1429 | if ((channel->state != LCS_CH_STATE_INIT) && |
Klaus-D. Wacker | 9b3b9ab | 2008-08-21 17:10:25 +0200 | [diff] [blame] | 1430 | (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) && |
| 1431 | (irb->scsw.cmd.cpa != 0)) { |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1432 | index = (struct ccw1 *) __va((addr_t) irb->scsw.cmd.cpa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | - channel->ccws; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1434 | if ((irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED) || |
| 1435 | (irb->scsw.cmd.cstat & SCHN_STAT_PCI)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | /* Bloody io subsystem tells us lies about cpa... */ |
| 1437 | index = (index - 1) & (LCS_NUM_BUFFS - 1); |
| 1438 | while (channel->io_idx != index) { |
| 1439 | __lcs_processed_buffer(channel, |
| 1440 | channel->iob + channel->io_idx); |
| 1441 | channel->io_idx = |
| 1442 | (channel->io_idx + 1) & (LCS_NUM_BUFFS - 1); |
| 1443 | } |
| 1444 | } |
| 1445 | |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1446 | if ((irb->scsw.cmd.dstat & DEV_STAT_DEV_END) || |
| 1447 | (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) || |
| 1448 | (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | /* Mark channel as stopped. */ |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1450 | channel->state = LCS_CH_STATE_STOPPED; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1451 | else if (irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | /* CCW execution stopped on a suspend bit. */ |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1453 | channel->state = LCS_CH_STATE_SUSPENDED; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1454 | if (irb->scsw.cmd.fctl & SCSW_FCTL_HALT_FUNC) { |
| 1455 | if (irb->scsw.cmd.cc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | ccw_device_halt(channel->ccwdev, (addr_t) channel); |
| 1457 | return; |
| 1458 | } |
| 1459 | /* The channel has been stopped by halt_IO. */ |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1460 | channel->state = LCS_CH_STATE_HALTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | } |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1462 | if (irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC) |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1463 | channel->state = LCS_CH_STATE_CLEARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | /* Do the rest in the tasklet. */ |
| 1465 | tasklet_schedule(&channel->irq_tasklet); |
| 1466 | } |
| 1467 | |
| 1468 | /** |
| 1469 | * Tasklet for IRQ handler |
| 1470 | */ |
| 1471 | static void |
| 1472 | lcs_tasklet(unsigned long data) |
| 1473 | { |
| 1474 | unsigned long flags; |
| 1475 | struct lcs_channel *channel; |
| 1476 | struct lcs_buffer *iob; |
| 1477 | int buf_idx; |
| 1478 | int rc; |
| 1479 | |
| 1480 | channel = (struct lcs_channel *) data; |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1481 | LCS_DBF_TEXT_(5, trace, "tlet%s", dev_name(&channel->ccwdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
| 1483 | /* Check for processed buffers. */ |
| 1484 | iob = channel->iob; |
| 1485 | buf_idx = channel->buf_idx; |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1486 | while (iob[buf_idx].state == LCS_BUF_STATE_PROCESSED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | /* Do the callback thing. */ |
| 1488 | if (iob[buf_idx].callback != NULL) |
| 1489 | iob[buf_idx].callback(channel, iob + buf_idx); |
| 1490 | buf_idx = (buf_idx + 1) & (LCS_NUM_BUFFS - 1); |
| 1491 | } |
| 1492 | channel->buf_idx = buf_idx; |
| 1493 | |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1494 | if (channel->state == LCS_CH_STATE_STOPPED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | // FIXME: what if rc != 0 ?? |
| 1496 | rc = lcs_start_channel(channel); |
| 1497 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1498 | if (channel->state == LCS_CH_STATE_SUSPENDED && |
| 1499 | channel->iob[channel->io_idx].state == LCS_BUF_STATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | // FIXME: what if rc != 0 ?? |
| 1501 | rc = __lcs_resume_channel(channel); |
| 1502 | } |
| 1503 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 1504 | |
| 1505 | /* Something happened on the channel. Wake up waiters. */ |
| 1506 | wake_up(&channel->wait_q); |
| 1507 | } |
| 1508 | |
| 1509 | /** |
| 1510 | * Finish current tx buffer and make it ready for transmit. |
| 1511 | */ |
| 1512 | static void |
| 1513 | __lcs_emit_txbuffer(struct lcs_card *card) |
| 1514 | { |
| 1515 | LCS_DBF_TEXT(5, trace, "emittx"); |
| 1516 | *(__u16 *)(card->tx_buffer->data + card->tx_buffer->count) = 0; |
| 1517 | card->tx_buffer->count += 2; |
| 1518 | lcs_ready_buffer(&card->write, card->tx_buffer); |
| 1519 | card->tx_buffer = NULL; |
| 1520 | card->tx_emitted++; |
| 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * Callback for finished tx buffers. |
| 1525 | */ |
| 1526 | static void |
| 1527 | lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer) |
| 1528 | { |
| 1529 | struct lcs_card *card; |
| 1530 | |
| 1531 | LCS_DBF_TEXT(5, trace, "txbuffcb"); |
| 1532 | /* Put buffer back to pool. */ |
| 1533 | lcs_release_buffer(channel, buffer); |
Robert P. J. Day | b385a14 | 2007-02-10 01:46:25 -0800 | [diff] [blame] | 1534 | card = container_of(channel, struct lcs_card, write); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1535 | if (netif_queue_stopped(card->dev) && netif_carrier_ok(card->dev)) |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 1536 | netif_wake_queue(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | spin_lock(&card->lock); |
| 1538 | card->tx_emitted--; |
| 1539 | if (card->tx_emitted <= 0 && card->tx_buffer != NULL) |
| 1540 | /* |
| 1541 | * Last running tx buffer has finished. Submit partially |
| 1542 | * filled current buffer. |
| 1543 | */ |
| 1544 | __lcs_emit_txbuffer(card); |
| 1545 | spin_unlock(&card->lock); |
| 1546 | } |
| 1547 | |
| 1548 | /** |
| 1549 | * Packet transmit function called by network stack |
| 1550 | */ |
| 1551 | static int |
| 1552 | __lcs_start_xmit(struct lcs_card *card, struct sk_buff *skb, |
| 1553 | struct net_device *dev) |
| 1554 | { |
| 1555 | struct lcs_header *header; |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 1556 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | |
| 1558 | LCS_DBF_TEXT(5, trace, "hardxmit"); |
| 1559 | if (skb == NULL) { |
| 1560 | card->stats.tx_dropped++; |
| 1561 | card->stats.tx_errors++; |
Klaus-Dieter Wacker | 9e669d3 | 2009-03-24 03:27:44 +0000 | [diff] [blame] | 1562 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | } |
| 1564 | if (card->state != DEV_STATE_UP) { |
| 1565 | dev_kfree_skb(skb); |
| 1566 | card->stats.tx_dropped++; |
| 1567 | card->stats.tx_errors++; |
| 1568 | card->stats.tx_carrier_errors++; |
| 1569 | return 0; |
| 1570 | } |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1571 | if (skb->protocol == htons(ETH_P_IPV6)) { |
| 1572 | dev_kfree_skb(skb); |
| 1573 | return 0; |
| 1574 | } |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 1575 | netif_stop_queue(card->dev); |
| 1576 | spin_lock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | if (card->tx_buffer != NULL && |
| 1578 | card->tx_buffer->count + sizeof(struct lcs_header) + |
| 1579 | skb->len + sizeof(u16) > LCS_IOBUFFERSIZE) |
| 1580 | /* skb too big for current tx buffer. */ |
| 1581 | __lcs_emit_txbuffer(card); |
| 1582 | if (card->tx_buffer == NULL) { |
| 1583 | /* Get new tx buffer */ |
| 1584 | card->tx_buffer = lcs_get_buffer(&card->write); |
| 1585 | if (card->tx_buffer == NULL) { |
| 1586 | card->stats.tx_dropped++; |
Klaus-Dieter Wacker | 9e669d3 | 2009-03-24 03:27:44 +0000 | [diff] [blame] | 1587 | rc = NETDEV_TX_BUSY; |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 1588 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | } |
| 1590 | card->tx_buffer->callback = lcs_txbuffer_cb; |
| 1591 | card->tx_buffer->count = 0; |
| 1592 | } |
| 1593 | header = (struct lcs_header *) |
| 1594 | (card->tx_buffer->data + card->tx_buffer->count); |
| 1595 | card->tx_buffer->count += skb->len + sizeof(struct lcs_header); |
| 1596 | header->offset = card->tx_buffer->count; |
| 1597 | header->type = card->lan_type; |
| 1598 | header->slot = card->portno; |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1599 | skb_copy_from_linear_data(skb, header + 1, skb->len); |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 1600 | spin_unlock(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | card->stats.tx_bytes += skb->len; |
| 1602 | card->stats.tx_packets++; |
| 1603 | dev_kfree_skb(skb); |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 1604 | netif_wake_queue(card->dev); |
| 1605 | spin_lock(&card->lock); |
| 1606 | if (card->tx_emitted <= 0 && card->tx_buffer != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | /* If this is the first tx buffer emit it immediately. */ |
| 1608 | __lcs_emit_txbuffer(card); |
Frank Pavlic | 0d613a2 | 2006-02-07 17:04:36 +0100 | [diff] [blame] | 1609 | out: |
| 1610 | spin_unlock(&card->lock); |
| 1611 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | static int |
| 1615 | lcs_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1616 | { |
| 1617 | struct lcs_card *card; |
| 1618 | int rc; |
| 1619 | |
| 1620 | LCS_DBF_TEXT(5, trace, "pktxmit"); |
Wang Chen | ad660e2 | 2008-12-06 23:57:49 -0800 | [diff] [blame] | 1621 | card = (struct lcs_card *) dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | rc = __lcs_start_xmit(card, skb, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | return rc; |
| 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * send startlan and lanstat command to make LCS device ready |
| 1628 | */ |
| 1629 | static int |
| 1630 | lcs_startlan_auto(struct lcs_card *card) |
| 1631 | { |
| 1632 | int rc; |
| 1633 | |
| 1634 | LCS_DBF_TEXT(2, trace, "strtauto"); |
| 1635 | #ifdef CONFIG_NET_ETHERNET |
| 1636 | card->lan_type = LCS_FRAME_TYPE_ENET; |
| 1637 | rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP); |
| 1638 | if (rc == 0) |
| 1639 | return 0; |
| 1640 | |
| 1641 | #endif |
| 1642 | #ifdef CONFIG_TR |
| 1643 | card->lan_type = LCS_FRAME_TYPE_TR; |
| 1644 | rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP); |
| 1645 | if (rc == 0) |
| 1646 | return 0; |
| 1647 | #endif |
| 1648 | #ifdef CONFIG_FDDI |
| 1649 | card->lan_type = LCS_FRAME_TYPE_FDDI; |
| 1650 | rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP); |
| 1651 | if (rc == 0) |
| 1652 | return 0; |
| 1653 | #endif |
| 1654 | return -EIO; |
| 1655 | } |
| 1656 | |
| 1657 | static int |
| 1658 | lcs_startlan(struct lcs_card *card) |
| 1659 | { |
| 1660 | int rc, i; |
| 1661 | |
| 1662 | LCS_DBF_TEXT(2, trace, "startlan"); |
| 1663 | rc = 0; |
| 1664 | if (card->portno != LCS_INVALID_PORT_NO) { |
| 1665 | if (card->lan_type == LCS_FRAME_TYPE_AUTO) |
| 1666 | rc = lcs_startlan_auto(card); |
| 1667 | else |
| 1668 | rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP); |
| 1669 | } else { |
| 1670 | for (i = 0; i <= 16; i++) { |
| 1671 | card->portno = i; |
| 1672 | if (card->lan_type != LCS_FRAME_TYPE_AUTO) |
| 1673 | rc = lcs_send_startlan(card, |
| 1674 | LCS_INITIATOR_TCPIP); |
| 1675 | else |
| 1676 | /* autodetecting lan type */ |
| 1677 | rc = lcs_startlan_auto(card); |
| 1678 | if (rc == 0) |
| 1679 | break; |
| 1680 | } |
| 1681 | } |
| 1682 | if (rc == 0) |
| 1683 | return lcs_send_lanstat(card); |
| 1684 | return rc; |
| 1685 | } |
| 1686 | |
| 1687 | /** |
| 1688 | * LCS detect function |
| 1689 | * setup channels and make them I/O ready |
| 1690 | */ |
| 1691 | static int |
| 1692 | lcs_detect(struct lcs_card *card) |
| 1693 | { |
| 1694 | int rc = 0; |
| 1695 | |
| 1696 | LCS_DBF_TEXT(2, setup, "lcsdetct"); |
| 1697 | /* start/reset card */ |
| 1698 | if (card->dev) |
| 1699 | netif_stop_queue(card->dev); |
| 1700 | rc = lcs_stop_channels(card); |
| 1701 | if (rc == 0) { |
| 1702 | rc = lcs_start_channels(card); |
| 1703 | if (rc == 0) { |
| 1704 | rc = lcs_send_startup(card, LCS_INITIATOR_TCPIP); |
| 1705 | if (rc == 0) |
| 1706 | rc = lcs_startlan(card); |
| 1707 | } |
| 1708 | } |
| 1709 | if (rc == 0) { |
| 1710 | card->state = DEV_STATE_UP; |
| 1711 | } else { |
| 1712 | card->state = DEV_STATE_DOWN; |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1713 | card->write.state = LCS_CH_STATE_INIT; |
| 1714 | card->read.state = LCS_CH_STATE_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
| 1716 | return rc; |
| 1717 | } |
| 1718 | |
| 1719 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | * LCS Stop card |
| 1721 | */ |
| 1722 | static int |
| 1723 | lcs_stopcard(struct lcs_card *card) |
| 1724 | { |
| 1725 | int rc; |
| 1726 | |
| 1727 | LCS_DBF_TEXT(3, setup, "stopcard"); |
| 1728 | |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1729 | if (card->read.state != LCS_CH_STATE_STOPPED && |
| 1730 | card->write.state != LCS_CH_STATE_STOPPED && |
Klaus D. Wacker | 59579da | 2007-10-05 16:45:47 +0200 | [diff] [blame] | 1731 | card->read.state != LCS_CH_STATE_ERROR && |
| 1732 | card->write.state != LCS_CH_STATE_ERROR && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | card->state == DEV_STATE_UP) { |
| 1734 | lcs_clear_multicast_list(card); |
| 1735 | rc = lcs_send_stoplan(card,LCS_INITIATOR_TCPIP); |
| 1736 | rc = lcs_send_shutdown(card); |
| 1737 | } |
| 1738 | rc = lcs_stop_channels(card); |
| 1739 | card->state = DEV_STATE_DOWN; |
| 1740 | |
| 1741 | return rc; |
| 1742 | } |
| 1743 | |
| 1744 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | * Kernel Thread helper functions for LGW initiated commands |
| 1746 | */ |
| 1747 | static void |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 1748 | lcs_start_kernel_thread(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | { |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 1750 | struct lcs_card *card = container_of(work, struct lcs_card, kernel_thread_starter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | LCS_DBF_TEXT(5, trace, "krnthrd"); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1752 | if (lcs_do_start_thread(card, LCS_RECOVERY_THREAD)) |
Klaus-Dieter Wacker | e5b5719 | 2009-03-24 03:27:43 +0000 | [diff] [blame] | 1753 | kthread_run(lcs_recovery, card, "lcs_recover"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | #ifdef CONFIG_IP_MULTICAST |
| 1755 | if (lcs_do_start_thread(card, LCS_SET_MC_THREAD)) |
Klaus-Dieter Wacker | e5b5719 | 2009-03-24 03:27:43 +0000 | [diff] [blame] | 1756 | kthread_run(lcs_register_mc_addresses, card, "regipm"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | #endif |
| 1758 | } |
| 1759 | |
| 1760 | /** |
| 1761 | * Process control frames. |
| 1762 | */ |
| 1763 | static void |
| 1764 | lcs_get_control(struct lcs_card *card, struct lcs_cmd *cmd) |
| 1765 | { |
| 1766 | LCS_DBF_TEXT(5, trace, "getctrl"); |
| 1767 | if (cmd->initiator == LCS_INITIATOR_LGW) { |
| 1768 | switch(cmd->cmd_code) { |
| 1769 | case LCS_CMD_STARTUP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | case LCS_CMD_STARTLAN: |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1771 | lcs_schedule_recovery(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | break; |
| 1773 | case LCS_CMD_STOPLAN: |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1774 | pr_warning("Stoplan for %s initiated by LGW.\n", |
| 1775 | card->dev->name); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1776 | if (card->dev) |
| 1777 | netif_carrier_off(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | break; |
| 1779 | default: |
Klaus-D. Wacker | 6b64806 | 2008-07-14 09:59:42 +0200 | [diff] [blame] | 1780 | LCS_DBF_TEXT(5, trace, "noLGWcmd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | break; |
| 1782 | } |
| 1783 | } else |
| 1784 | lcs_notify_lancmd_waiters(card, cmd); |
| 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * Unpack network packet. |
| 1789 | */ |
| 1790 | static void |
| 1791 | lcs_get_skb(struct lcs_card *card, char *skb_data, unsigned int skb_len) |
| 1792 | { |
| 1793 | struct sk_buff *skb; |
| 1794 | |
| 1795 | LCS_DBF_TEXT(5, trace, "getskb"); |
| 1796 | if (card->dev == NULL || |
| 1797 | card->state != DEV_STATE_UP) |
| 1798 | /* The card isn't up. Ignore the packet. */ |
| 1799 | return; |
| 1800 | |
| 1801 | skb = dev_alloc_skb(skb_len); |
| 1802 | if (skb == NULL) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1803 | dev_err(&card->dev->dev, |
| 1804 | " Allocating a socket buffer to interface %s failed\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | card->dev->name); |
| 1806 | card->stats.rx_dropped++; |
| 1807 | return; |
| 1808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | memcpy(skb_put(skb, skb_len), skb_data, skb_len); |
| 1810 | skb->protocol = card->lan_type_trans(skb, card->dev); |
| 1811 | card->stats.rx_bytes += skb_len; |
| 1812 | card->stats.rx_packets++; |
Klaus D. Wacker | 93ad37d | 2008-04-24 10:15:18 +0200 | [diff] [blame] | 1813 | if (skb->protocol == htons(ETH_P_802_2)) |
| 1814 | *((__u32 *)skb->cb) = ++card->pkt_seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | netif_rx(skb); |
| 1816 | } |
| 1817 | |
| 1818 | /** |
| 1819 | * LCS main routine to get packets and lancmd replies from the buffers |
| 1820 | */ |
| 1821 | static void |
| 1822 | lcs_get_frames_cb(struct lcs_channel *channel, struct lcs_buffer *buffer) |
| 1823 | { |
| 1824 | struct lcs_card *card; |
| 1825 | struct lcs_header *lcs_hdr; |
| 1826 | __u16 offset; |
| 1827 | |
| 1828 | LCS_DBF_TEXT(5, trace, "lcsgtpkt"); |
| 1829 | lcs_hdr = (struct lcs_header *) buffer->data; |
| 1830 | if (lcs_hdr->offset == LCS_ILLEGAL_OFFSET) { |
| 1831 | LCS_DBF_TEXT(4, trace, "-eiogpkt"); |
| 1832 | return; |
| 1833 | } |
Robert P. J. Day | b385a14 | 2007-02-10 01:46:25 -0800 | [diff] [blame] | 1834 | card = container_of(channel, struct lcs_card, read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | offset = 0; |
| 1836 | while (lcs_hdr->offset != 0) { |
| 1837 | if (lcs_hdr->offset <= 0 || |
| 1838 | lcs_hdr->offset > LCS_IOBUFFERSIZE || |
| 1839 | lcs_hdr->offset < offset) { |
| 1840 | /* Offset invalid. */ |
| 1841 | card->stats.rx_length_errors++; |
| 1842 | card->stats.rx_errors++; |
| 1843 | return; |
| 1844 | } |
| 1845 | /* What kind of frame is it? */ |
| 1846 | if (lcs_hdr->type == LCS_FRAME_TYPE_CONTROL) |
| 1847 | /* Control frame. */ |
| 1848 | lcs_get_control(card, (struct lcs_cmd *) lcs_hdr); |
| 1849 | else if (lcs_hdr->type == LCS_FRAME_TYPE_ENET || |
| 1850 | lcs_hdr->type == LCS_FRAME_TYPE_TR || |
| 1851 | lcs_hdr->type == LCS_FRAME_TYPE_FDDI) |
| 1852 | /* Normal network packet. */ |
| 1853 | lcs_get_skb(card, (char *)(lcs_hdr + 1), |
| 1854 | lcs_hdr->offset - offset - |
| 1855 | sizeof(struct lcs_header)); |
| 1856 | else |
| 1857 | /* Unknown frame type. */ |
| 1858 | ; // FIXME: error message ? |
| 1859 | /* Proceed to next frame. */ |
| 1860 | offset = lcs_hdr->offset; |
| 1861 | lcs_hdr->offset = LCS_ILLEGAL_OFFSET; |
| 1862 | lcs_hdr = (struct lcs_header *) (buffer->data + offset); |
| 1863 | } |
| 1864 | /* The buffer is now empty. Make it ready again. */ |
| 1865 | lcs_ready_buffer(&card->read, buffer); |
| 1866 | } |
| 1867 | |
| 1868 | /** |
| 1869 | * get network statistics for ifconfig and other user programs |
| 1870 | */ |
| 1871 | static struct net_device_stats * |
| 1872 | lcs_getstats(struct net_device *dev) |
| 1873 | { |
| 1874 | struct lcs_card *card; |
| 1875 | |
| 1876 | LCS_DBF_TEXT(4, trace, "netstats"); |
Wang Chen | ad660e2 | 2008-12-06 23:57:49 -0800 | [diff] [blame] | 1877 | card = (struct lcs_card *) dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | return &card->stats; |
| 1879 | } |
| 1880 | |
| 1881 | /** |
| 1882 | * stop lcs device |
| 1883 | * This function will be called by user doing ifconfig xxx down |
| 1884 | */ |
| 1885 | static int |
| 1886 | lcs_stop_device(struct net_device *dev) |
| 1887 | { |
| 1888 | struct lcs_card *card; |
| 1889 | int rc; |
| 1890 | |
| 1891 | LCS_DBF_TEXT(2, trace, "stopdev"); |
Wang Chen | ad660e2 | 2008-12-06 23:57:49 -0800 | [diff] [blame] | 1892 | card = (struct lcs_card *) dev->ml_priv; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1893 | netif_carrier_off(dev); |
| 1894 | netif_tx_disable(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | dev->flags &= ~IFF_UP; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1896 | wait_event(card->write.wait_q, |
Ursula Braun | 9163bb2 | 2006-12-04 15:40:59 +0100 | [diff] [blame] | 1897 | (card->write.state != LCS_CH_STATE_RUNNING)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | rc = lcs_stopcard(card); |
| 1899 | if (rc) |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1900 | dev_err(&card->dev->dev, |
| 1901 | " Shutting down the LCS device failed\n "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | return rc; |
| 1903 | } |
| 1904 | |
| 1905 | /** |
| 1906 | * start lcs device and make it runnable |
| 1907 | * This function will be called by user doing ifconfig xxx up |
| 1908 | */ |
| 1909 | static int |
| 1910 | lcs_open_device(struct net_device *dev) |
| 1911 | { |
| 1912 | struct lcs_card *card; |
| 1913 | int rc; |
| 1914 | |
| 1915 | LCS_DBF_TEXT(2, trace, "opendev"); |
Wang Chen | ad660e2 | 2008-12-06 23:57:49 -0800 | [diff] [blame] | 1916 | card = (struct lcs_card *) dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | /* initialize statistics */ |
| 1918 | rc = lcs_detect(card); |
| 1919 | if (rc) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 1920 | pr_err("Error in opening device!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
| 1922 | } else { |
| 1923 | dev->flags |= IFF_UP; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 1924 | netif_carrier_on(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | netif_wake_queue(dev); |
| 1926 | card->state = DEV_STATE_UP; |
| 1927 | } |
| 1928 | return rc; |
| 1929 | } |
| 1930 | |
| 1931 | /** |
| 1932 | * show function for portno called by cat or similar things |
| 1933 | */ |
| 1934 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 1935 | lcs_portno_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | { |
| 1937 | struct lcs_card *card; |
| 1938 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1939 | card = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | |
| 1941 | if (!card) |
| 1942 | return 0; |
| 1943 | |
| 1944 | return sprintf(buf, "%d\n", card->portno); |
| 1945 | } |
| 1946 | |
| 1947 | /** |
| 1948 | * store the value which is piped to file portno |
| 1949 | */ |
| 1950 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 1951 | lcs_portno_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | { |
| 1953 | struct lcs_card *card; |
| 1954 | int value; |
| 1955 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1956 | card = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | |
| 1958 | if (!card) |
| 1959 | return 0; |
| 1960 | |
| 1961 | sscanf(buf, "%u", &value); |
| 1962 | /* TODO: sanity checks */ |
| 1963 | card->portno = value; |
| 1964 | |
| 1965 | return count; |
| 1966 | |
| 1967 | } |
| 1968 | |
| 1969 | static DEVICE_ATTR(portno, 0644, lcs_portno_show, lcs_portno_store); |
| 1970 | |
| 1971 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 1972 | lcs_type_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | { |
| 1974 | struct ccwgroup_device *cgdev; |
| 1975 | |
| 1976 | cgdev = to_ccwgroupdev(dev); |
| 1977 | if (!cgdev) |
| 1978 | return -ENODEV; |
| 1979 | |
| 1980 | return sprintf(buf, "%s\n", cu3088_type[cgdev->cdev[0]->id.driver_info]); |
| 1981 | } |
| 1982 | |
| 1983 | static DEVICE_ATTR(type, 0444, lcs_type_show, NULL); |
| 1984 | |
| 1985 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 1986 | lcs_timeout_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | { |
| 1988 | struct lcs_card *card; |
| 1989 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1990 | card = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | |
| 1992 | return card ? sprintf(buf, "%u\n", card->lancmd_timeout) : 0; |
| 1993 | } |
| 1994 | |
| 1995 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 1996 | lcs_timeout_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | { |
| 1998 | struct lcs_card *card; |
| 1999 | int value; |
| 2000 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2001 | card = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | |
| 2003 | if (!card) |
| 2004 | return 0; |
| 2005 | |
| 2006 | sscanf(buf, "%u", &value); |
| 2007 | /* TODO: sanity checks */ |
| 2008 | card->lancmd_timeout = value; |
| 2009 | |
| 2010 | return count; |
| 2011 | |
| 2012 | } |
| 2013 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 2014 | static DEVICE_ATTR(lancmd_timeout, 0644, lcs_timeout_show, lcs_timeout_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2016 | static ssize_t |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2017 | lcs_dev_recover_store(struct device *dev, struct device_attribute *attr, |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2018 | const char *buf, size_t count) |
| 2019 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2020 | struct lcs_card *card = dev_get_drvdata(dev); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2021 | char *tmp; |
| 2022 | int i; |
| 2023 | |
| 2024 | if (!card) |
| 2025 | return -EINVAL; |
| 2026 | if (card->state != DEV_STATE_UP) |
| 2027 | return -EPERM; |
| 2028 | i = simple_strtoul(buf, &tmp, 16); |
| 2029 | if (i == 1) |
| 2030 | lcs_schedule_recovery(card); |
| 2031 | return count; |
| 2032 | } |
| 2033 | |
| 2034 | static DEVICE_ATTR(recover, 0200, NULL, lcs_dev_recover_store); |
| 2035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | static struct attribute * lcs_attrs[] = { |
| 2037 | &dev_attr_portno.attr, |
| 2038 | &dev_attr_type.attr, |
| 2039 | &dev_attr_lancmd_timeout.attr, |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2040 | &dev_attr_recover.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | NULL, |
| 2042 | }; |
| 2043 | |
| 2044 | static struct attribute_group lcs_attr_group = { |
| 2045 | .attrs = lcs_attrs, |
| 2046 | }; |
| 2047 | |
| 2048 | /** |
| 2049 | * lcs_probe_device is called on establishing a new ccwgroup_device. |
| 2050 | */ |
| 2051 | static int |
| 2052 | lcs_probe_device(struct ccwgroup_device *ccwgdev) |
| 2053 | { |
| 2054 | struct lcs_card *card; |
| 2055 | int ret; |
| 2056 | |
| 2057 | if (!get_device(&ccwgdev->dev)) |
| 2058 | return -ENODEV; |
| 2059 | |
| 2060 | LCS_DBF_TEXT(2, setup, "add_dev"); |
| 2061 | card = lcs_alloc_card(); |
| 2062 | if (!card) { |
Klaus-D. Wacker | 6b64806 | 2008-07-14 09:59:42 +0200 | [diff] [blame] | 2063 | LCS_DBF_TEXT_(2, setup, " rc%d", -ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | put_device(&ccwgdev->dev); |
| 2065 | return -ENOMEM; |
| 2066 | } |
| 2067 | ret = sysfs_create_group(&ccwgdev->dev.kobj, &lcs_attr_group); |
| 2068 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | lcs_free_card(card); |
| 2070 | put_device(&ccwgdev->dev); |
| 2071 | return ret; |
| 2072 | } |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2073 | dev_set_drvdata(&ccwgdev->dev, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | ccwgdev->cdev[0]->handler = lcs_irq; |
| 2075 | ccwgdev->cdev[1]->handler = lcs_irq; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2076 | card->gdev = ccwgdev; |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 2077 | INIT_WORK(&card->kernel_thread_starter, lcs_start_kernel_thread); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2078 | card->thread_start_mask = 0; |
| 2079 | card->thread_allowed_mask = 0; |
| 2080 | card->thread_running_mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | return 0; |
| 2082 | } |
| 2083 | |
| 2084 | static int |
| 2085 | lcs_register_netdev(struct ccwgroup_device *ccwgdev) |
| 2086 | { |
| 2087 | struct lcs_card *card; |
| 2088 | |
| 2089 | LCS_DBF_TEXT(2, setup, "regnetdv"); |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2090 | card = dev_get_drvdata(&ccwgdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | if (card->dev->reg_state != NETREG_UNINITIALIZED) |
| 2092 | return 0; |
| 2093 | SET_NETDEV_DEV(card->dev, &ccwgdev->dev); |
| 2094 | return register_netdev(card->dev); |
| 2095 | } |
| 2096 | |
| 2097 | /** |
| 2098 | * lcs_new_device will be called by setting the group device online. |
| 2099 | */ |
Frank Blaschka | 0e0b46d | 2009-01-09 03:43:56 +0000 | [diff] [blame] | 2100 | static const struct net_device_ops lcs_netdev_ops = { |
| 2101 | .ndo_open = lcs_open_device, |
| 2102 | .ndo_stop = lcs_stop_device, |
| 2103 | .ndo_get_stats = lcs_getstats, |
| 2104 | .ndo_start_xmit = lcs_start_xmit, |
| 2105 | }; |
| 2106 | |
| 2107 | static const struct net_device_ops lcs_mc_netdev_ops = { |
| 2108 | .ndo_open = lcs_open_device, |
| 2109 | .ndo_stop = lcs_stop_device, |
| 2110 | .ndo_get_stats = lcs_getstats, |
| 2111 | .ndo_start_xmit = lcs_start_xmit, |
| 2112 | .ndo_set_multicast_list = lcs_set_multicast_list, |
| 2113 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | |
| 2115 | static int |
| 2116 | lcs_new_device(struct ccwgroup_device *ccwgdev) |
| 2117 | { |
| 2118 | struct lcs_card *card; |
| 2119 | struct net_device *dev=NULL; |
| 2120 | enum lcs_dev_states recover_state; |
| 2121 | int rc; |
| 2122 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2123 | card = dev_get_drvdata(&ccwgdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | if (!card) |
| 2125 | return -ENODEV; |
| 2126 | |
| 2127 | LCS_DBF_TEXT(2, setup, "newdev"); |
| 2128 | LCS_DBF_HEX(3, setup, &card, sizeof(void*)); |
| 2129 | card->read.ccwdev = ccwgdev->cdev[0]; |
| 2130 | card->write.ccwdev = ccwgdev->cdev[1]; |
| 2131 | |
| 2132 | recover_state = card->state; |
| 2133 | ccw_device_set_online(card->read.ccwdev); |
| 2134 | ccw_device_set_online(card->write.ccwdev); |
| 2135 | |
| 2136 | LCS_DBF_TEXT(3, setup, "lcsnewdv"); |
| 2137 | |
| 2138 | lcs_setup_card(card); |
| 2139 | rc = lcs_detect(card); |
| 2140 | if (rc) { |
| 2141 | LCS_DBF_TEXT(2, setup, "dtctfail"); |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2142 | dev_err(&card->dev->dev, |
| 2143 | "Detecting a network adapter for LCS devices" |
| 2144 | " failed with rc=%d (0x%x)\n", rc, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | lcs_stopcard(card); |
| 2146 | goto out; |
| 2147 | } |
| 2148 | if (card->dev) { |
| 2149 | LCS_DBF_TEXT(2, setup, "samedev"); |
| 2150 | LCS_DBF_HEX(3, setup, &card, sizeof(void*)); |
| 2151 | goto netdev_out; |
| 2152 | } |
| 2153 | switch (card->lan_type) { |
| 2154 | #ifdef CONFIG_NET_ETHERNET |
| 2155 | case LCS_FRAME_TYPE_ENET: |
| 2156 | card->lan_type_trans = eth_type_trans; |
| 2157 | dev = alloc_etherdev(0); |
| 2158 | break; |
| 2159 | #endif |
| 2160 | #ifdef CONFIG_TR |
| 2161 | case LCS_FRAME_TYPE_TR: |
| 2162 | card->lan_type_trans = tr_type_trans; |
| 2163 | dev = alloc_trdev(0); |
| 2164 | break; |
| 2165 | #endif |
| 2166 | #ifdef CONFIG_FDDI |
| 2167 | case LCS_FRAME_TYPE_FDDI: |
| 2168 | card->lan_type_trans = fddi_type_trans; |
| 2169 | dev = alloc_fddidev(0); |
| 2170 | break; |
| 2171 | #endif |
| 2172 | default: |
| 2173 | LCS_DBF_TEXT(3, setup, "errinit"); |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2174 | pr_err(" Initialization failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | goto out; |
| 2176 | } |
| 2177 | if (!dev) |
| 2178 | goto out; |
| 2179 | card->dev = dev; |
Wang Chen | ad660e2 | 2008-12-06 23:57:49 -0800 | [diff] [blame] | 2180 | card->dev->ml_priv = card; |
Frank Blaschka | 0e0b46d | 2009-01-09 03:43:56 +0000 | [diff] [blame] | 2181 | card->dev->netdev_ops = &lcs_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | memcpy(card->dev->dev_addr, card->mac, LCS_MAC_LENGTH); |
| 2183 | #ifdef CONFIG_IP_MULTICAST |
| 2184 | if (!lcs_check_multicast_support(card)) |
Frank Blaschka | 0e0b46d | 2009-01-09 03:43:56 +0000 | [diff] [blame] | 2185 | card->dev->netdev_ops = &lcs_mc_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | #endif |
Frank Pavlic | b5f9d55 | 2005-05-12 20:35:57 +0200 | [diff] [blame] | 2187 | netdev_out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | lcs_set_allowed_threads(card,0xffffffff); |
| 2189 | if (recover_state == DEV_STATE_RECOVER) { |
| 2190 | lcs_set_multicast_list(card->dev); |
| 2191 | card->dev->flags |= IFF_UP; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2192 | netif_carrier_on(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | netif_wake_queue(card->dev); |
| 2194 | card->state = DEV_STATE_UP; |
Frank Pavlic | b5f9d55 | 2005-05-12 20:35:57 +0200 | [diff] [blame] | 2195 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | lcs_stopcard(card); |
Frank Pavlic | b5f9d55 | 2005-05-12 20:35:57 +0200 | [diff] [blame] | 2197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
Frank Pavlic | b5f9d55 | 2005-05-12 20:35:57 +0200 | [diff] [blame] | 2199 | if (lcs_register_netdev(ccwgdev) != 0) |
| 2200 | goto out; |
| 2201 | |
| 2202 | /* Print out supported assists: IPv6 */ |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2203 | pr_info("LCS device %s %s IPv6 support\n", card->dev->name, |
| 2204 | (card->ip_assists_supported & LCS_IPASS_IPV6_SUPPORT) ? |
| 2205 | "with" : "without"); |
Frank Pavlic | b5f9d55 | 2005-05-12 20:35:57 +0200 | [diff] [blame] | 2206 | /* Print out supported assist: Multicast */ |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2207 | pr_info("LCS device %s %s Multicast support\n", card->dev->name, |
| 2208 | (card->ip_assists_supported & LCS_IPASS_MULTICAST_SUPPORT) ? |
| 2209 | "with" : "without"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | return 0; |
| 2211 | out: |
| 2212 | |
| 2213 | ccw_device_set_offline(card->read.ccwdev); |
| 2214 | ccw_device_set_offline(card->write.ccwdev); |
| 2215 | return -ENODEV; |
| 2216 | } |
| 2217 | |
| 2218 | /** |
| 2219 | * lcs_shutdown_device, called when setting the group device offline. |
| 2220 | */ |
| 2221 | static int |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2222 | __lcs_shutdown_device(struct ccwgroup_device *ccwgdev, int recovery_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | { |
| 2224 | struct lcs_card *card; |
| 2225 | enum lcs_dev_states recover_state; |
| 2226 | int ret; |
| 2227 | |
| 2228 | LCS_DBF_TEXT(3, setup, "shtdndev"); |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2229 | card = dev_get_drvdata(&ccwgdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | if (!card) |
| 2231 | return -ENODEV; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2232 | if (recovery_mode == 0) { |
| 2233 | lcs_set_allowed_threads(card, 0); |
| 2234 | if (lcs_wait_for_threads(card, LCS_SET_MC_THREAD)) |
| 2235 | return -ERESTARTSYS; |
| 2236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | LCS_DBF_HEX(3, setup, &card, sizeof(void*)); |
| 2238 | recover_state = card->state; |
| 2239 | |
| 2240 | ret = lcs_stop_device(card->dev); |
| 2241 | ret = ccw_device_set_offline(card->read.ccwdev); |
| 2242 | ret = ccw_device_set_offline(card->write.ccwdev); |
| 2243 | if (recover_state == DEV_STATE_UP) { |
| 2244 | card->state = DEV_STATE_RECOVER; |
| 2245 | } |
| 2246 | if (ret) |
| 2247 | return ret; |
| 2248 | return 0; |
| 2249 | } |
| 2250 | |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2251 | static int |
| 2252 | lcs_shutdown_device(struct ccwgroup_device *ccwgdev) |
| 2253 | { |
| 2254 | return __lcs_shutdown_device(ccwgdev, 0); |
| 2255 | } |
| 2256 | |
| 2257 | /** |
| 2258 | * drive lcs recovery after startup and startlan initiated by Lan Gateway |
| 2259 | */ |
| 2260 | static int |
| 2261 | lcs_recovery(void *ptr) |
| 2262 | { |
| 2263 | struct lcs_card *card; |
| 2264 | struct ccwgroup_device *gdev; |
| 2265 | int rc; |
| 2266 | |
| 2267 | card = (struct lcs_card *) ptr; |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2268 | |
| 2269 | LCS_DBF_TEXT(4, trace, "recover1"); |
| 2270 | if (!lcs_do_run_thread(card, LCS_RECOVERY_THREAD)) |
| 2271 | return 0; |
| 2272 | LCS_DBF_TEXT(4, trace, "recover2"); |
| 2273 | gdev = card->gdev; |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2274 | dev_warn(&gdev->dev, |
| 2275 | "A recovery process has been started for the LCS device\n"); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2276 | rc = __lcs_shutdown_device(gdev, 1); |
| 2277 | rc = lcs_new_device(gdev); |
| 2278 | if (!rc) |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2279 | pr_info("Device %s successfully recovered!\n", |
| 2280 | card->dev->name); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2281 | else |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2282 | pr_info("Device %s could not be recovered!\n", |
| 2283 | card->dev->name); |
Klaus Wacker | 27eb5ac | 2006-05-24 09:51:17 +0200 | [diff] [blame] | 2284 | lcs_clear_thread_running_bit(card, LCS_RECOVERY_THREAD); |
| 2285 | return 0; |
| 2286 | } |
| 2287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | /** |
| 2289 | * lcs_remove_device, free buffers and card |
| 2290 | */ |
| 2291 | static void |
| 2292 | lcs_remove_device(struct ccwgroup_device *ccwgdev) |
| 2293 | { |
| 2294 | struct lcs_card *card; |
| 2295 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2296 | card = dev_get_drvdata(&ccwgdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | if (!card) |
| 2298 | return; |
| 2299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | LCS_DBF_TEXT(3, setup, "remdev"); |
| 2301 | LCS_DBF_HEX(3, setup, &card, sizeof(void*)); |
| 2302 | if (ccwgdev->state == CCWGROUP_ONLINE) { |
| 2303 | lcs_shutdown_device(ccwgdev); |
| 2304 | } |
| 2305 | if (card->dev) |
| 2306 | unregister_netdev(card->dev); |
| 2307 | sysfs_remove_group(&ccwgdev->dev.kobj, &lcs_attr_group); |
| 2308 | lcs_cleanup_card(card); |
| 2309 | lcs_free_card(card); |
| 2310 | put_device(&ccwgdev->dev); |
| 2311 | } |
| 2312 | |
Klaus-Dieter Wacket | cbb2aec | 2009-06-16 10:30:30 +0200 | [diff] [blame] | 2313 | static int lcs_pm_suspend(struct lcs_card *card) |
| 2314 | { |
| 2315 | if (card->dev) |
| 2316 | netif_device_detach(card->dev); |
| 2317 | lcs_set_allowed_threads(card, 0); |
| 2318 | lcs_wait_for_threads(card, 0xffffffff); |
| 2319 | if (card->state != DEV_STATE_DOWN) |
| 2320 | __lcs_shutdown_device(card->gdev, 1); |
| 2321 | return 0; |
| 2322 | } |
| 2323 | |
| 2324 | static int lcs_pm_resume(struct lcs_card *card) |
| 2325 | { |
| 2326 | int rc = 0; |
| 2327 | |
| 2328 | if (card->state == DEV_STATE_RECOVER) |
| 2329 | rc = lcs_new_device(card->gdev); |
| 2330 | if (card->dev) |
| 2331 | netif_device_attach(card->dev); |
| 2332 | if (rc) { |
| 2333 | dev_warn(&card->gdev->dev, "The lcs device driver " |
| 2334 | "failed to recover the device\n"); |
| 2335 | } |
| 2336 | return rc; |
| 2337 | } |
| 2338 | |
| 2339 | static int lcs_prepare(struct ccwgroup_device *gdev) |
| 2340 | { |
| 2341 | return 0; |
| 2342 | } |
| 2343 | |
| 2344 | static void lcs_complete(struct ccwgroup_device *gdev) |
| 2345 | { |
| 2346 | return; |
| 2347 | } |
| 2348 | |
| 2349 | static int lcs_freeze(struct ccwgroup_device *gdev) |
| 2350 | { |
| 2351 | struct lcs_card *card = dev_get_drvdata(&gdev->dev); |
| 2352 | return lcs_pm_suspend(card); |
| 2353 | } |
| 2354 | |
| 2355 | static int lcs_thaw(struct ccwgroup_device *gdev) |
| 2356 | { |
| 2357 | struct lcs_card *card = dev_get_drvdata(&gdev->dev); |
| 2358 | return lcs_pm_resume(card); |
| 2359 | } |
| 2360 | |
| 2361 | static int lcs_restore(struct ccwgroup_device *gdev) |
| 2362 | { |
| 2363 | struct lcs_card *card = dev_get_drvdata(&gdev->dev); |
| 2364 | return lcs_pm_resume(card); |
| 2365 | } |
| 2366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | /** |
| 2368 | * LCS ccwgroup driver registration |
| 2369 | */ |
| 2370 | static struct ccwgroup_driver lcs_group_driver = { |
| 2371 | .owner = THIS_MODULE, |
| 2372 | .name = "lcs", |
| 2373 | .max_slaves = 2, |
| 2374 | .driver_id = 0xD3C3E2, |
| 2375 | .probe = lcs_probe_device, |
| 2376 | .remove = lcs_remove_device, |
| 2377 | .set_online = lcs_new_device, |
| 2378 | .set_offline = lcs_shutdown_device, |
Klaus-Dieter Wacket | cbb2aec | 2009-06-16 10:30:30 +0200 | [diff] [blame] | 2379 | .prepare = lcs_prepare, |
| 2380 | .complete = lcs_complete, |
| 2381 | .freeze = lcs_freeze, |
| 2382 | .thaw = lcs_thaw, |
| 2383 | .restore = lcs_restore, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | }; |
| 2385 | |
| 2386 | /** |
| 2387 | * LCS Module/Kernel initialization function |
| 2388 | */ |
| 2389 | static int |
| 2390 | __init lcs_init_module(void) |
| 2391 | { |
| 2392 | int rc; |
| 2393 | |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2394 | pr_info("Loading %s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | rc = lcs_register_debug_facility(); |
| 2396 | LCS_DBF_TEXT(0, setup, "lcsinit"); |
| 2397 | if (rc) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2398 | pr_err("Initialization failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | return rc; |
| 2400 | } |
| 2401 | |
| 2402 | rc = register_cu3088_discipline(&lcs_group_driver); |
| 2403 | if (rc) { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2404 | pr_err("Initialization failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | return rc; |
| 2406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | return 0; |
| 2408 | } |
| 2409 | |
| 2410 | |
| 2411 | /** |
| 2412 | * LCS module cleanup function |
| 2413 | */ |
| 2414 | static void |
| 2415 | __exit lcs_cleanup_module(void) |
| 2416 | { |
Klaus-D. Wacker | c99fc5d | 2008-12-25 13:39:33 +0100 | [diff] [blame] | 2417 | pr_info("Terminating lcs module.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | LCS_DBF_TEXT(0, trace, "cleanup"); |
| 2419 | unregister_cu3088_discipline(&lcs_group_driver); |
| 2420 | lcs_unregister_debug_facility(); |
| 2421 | } |
| 2422 | |
| 2423 | module_init(lcs_init_module); |
| 2424 | module_exit(lcs_cleanup_module); |
| 2425 | |
Frank Pavlic | 1387780f | 2005-11-10 13:51:42 +0100 | [diff] [blame] | 2426 | MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | MODULE_LICENSE("GPL"); |
| 2428 | |