Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Heiko Carstens | e018ba1 | 2006-02-01 03:06:31 -0800 | [diff] [blame] | 2 | * linux/drivers/s390/net/qeth_main.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Linux on zSeries OSA Express and HiperSockets support |
| 5 | * |
| 6 | * Copyright 2000,2003 IBM Corporation |
| 7 | * |
| 8 | * Author(s): Original Code written by |
| 9 | * Utz Bacher (utz.bacher@de.ibm.com) |
| 10 | * Rewritten by |
Frank Pavlic | 1387780f | 2005-11-10 13:51:42 +0100 | [diff] [blame] | 11 | * Frank Pavlic (fpavlic@de.ibm.com) and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Thomas Spatzier <tspat@de.ibm.com> |
| 13 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2, or (at your option) |
| 17 | * any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 27 | */ |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/moduleparam.h> |
| 32 | #include <linux/string.h> |
| 33 | #include <linux/errno.h> |
| 34 | #include <linux/mm.h> |
| 35 | #include <linux/ip.h> |
| 36 | #include <linux/inetdevice.h> |
| 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/sched.h> |
| 39 | #include <linux/workqueue.h> |
| 40 | #include <linux/kernel.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/interrupt.h> |
| 43 | #include <linux/tcp.h> |
| 44 | #include <linux/icmp.h> |
| 45 | #include <linux/skbuff.h> |
| 46 | #include <linux/in.h> |
| 47 | #include <linux/igmp.h> |
| 48 | #include <linux/init.h> |
| 49 | #include <linux/reboot.h> |
| 50 | #include <linux/mii.h> |
| 51 | #include <linux/rcupdate.h> |
| 52 | #include <linux/ethtool.h> |
| 53 | |
| 54 | #include <net/arp.h> |
| 55 | #include <net/ip.h> |
| 56 | #include <net/route.h> |
| 57 | |
| 58 | #include <asm/ebcdic.h> |
| 59 | #include <asm/io.h> |
| 60 | #include <asm/qeth.h> |
| 61 | #include <asm/timex.h> |
| 62 | #include <asm/semaphore.h> |
| 63 | #include <asm/uaccess.h> |
Carsten Otte | cfb1b55 | 2006-01-06 00:19:14 -0800 | [diff] [blame] | 64 | #include <asm/s390_rdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | #include "qeth.h" |
| 67 | #include "qeth_mpc.h" |
| 68 | #include "qeth_fs.h" |
| 69 | #include "qeth_eddp.h" |
| 70 | #include "qeth_tso.h" |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static const char *version = "qeth S/390 OSA-Express driver"; |
| 73 | |
| 74 | /** |
| 75 | * Debug Facility Stuff |
| 76 | */ |
| 77 | static debug_info_t *qeth_dbf_setup = NULL; |
| 78 | static debug_info_t *qeth_dbf_data = NULL; |
| 79 | static debug_info_t *qeth_dbf_misc = NULL; |
| 80 | static debug_info_t *qeth_dbf_control = NULL; |
| 81 | debug_info_t *qeth_dbf_trace = NULL; |
| 82 | static debug_info_t *qeth_dbf_sense = NULL; |
| 83 | static debug_info_t *qeth_dbf_qerr = NULL; |
| 84 | |
| 85 | DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf); |
| 86 | |
Heiko Carstens | 91ebe2a | 2006-07-03 00:25:26 -0700 | [diff] [blame] | 87 | static struct lock_class_key qdio_out_skb_queue_key; |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /** |
| 90 | * some more definitions and declarations |
| 91 | */ |
| 92 | static unsigned int known_devices[][10] = QETH_MODELLIST_ARRAY; |
| 93 | |
| 94 | /* list of our cards */ |
| 95 | struct qeth_card_list_struct qeth_card_list; |
| 96 | /*process list want to be notified*/ |
| 97 | spinlock_t qeth_notify_lock; |
| 98 | struct list_head qeth_notify_list; |
| 99 | |
| 100 | static void qeth_send_control_data_cb(struct qeth_channel *, |
| 101 | struct qeth_cmd_buffer *); |
| 102 | |
| 103 | /** |
| 104 | * here we go with function implementation |
| 105 | */ |
| 106 | static void |
| 107 | qeth_init_qdio_info(struct qeth_card *card); |
| 108 | |
| 109 | static int |
| 110 | qeth_init_qdio_queues(struct qeth_card *card); |
| 111 | |
| 112 | static int |
| 113 | qeth_alloc_qdio_buffers(struct qeth_card *card); |
| 114 | |
| 115 | static void |
| 116 | qeth_free_qdio_buffers(struct qeth_card *); |
| 117 | |
| 118 | static void |
| 119 | qeth_clear_qdio_buffers(struct qeth_card *); |
| 120 | |
| 121 | static void |
| 122 | qeth_clear_ip_list(struct qeth_card *, int, int); |
| 123 | |
| 124 | static void |
| 125 | qeth_clear_ipacmd_list(struct qeth_card *); |
| 126 | |
| 127 | static int |
| 128 | qeth_qdio_clear_card(struct qeth_card *, int); |
| 129 | |
| 130 | static void |
| 131 | qeth_clear_working_pool_list(struct qeth_card *); |
| 132 | |
| 133 | static void |
| 134 | qeth_clear_cmd_buffers(struct qeth_channel *); |
| 135 | |
| 136 | static int |
| 137 | qeth_stop(struct net_device *); |
| 138 | |
| 139 | static void |
| 140 | qeth_clear_ipato_list(struct qeth_card *); |
| 141 | |
| 142 | static int |
| 143 | qeth_is_addr_covered_by_ipato(struct qeth_card *, struct qeth_ipaddr *); |
| 144 | |
| 145 | static void |
| 146 | qeth_irq_tasklet(unsigned long); |
| 147 | |
| 148 | static int |
| 149 | qeth_set_online(struct ccwgroup_device *); |
| 150 | |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 151 | static int |
| 152 | __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode); |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | static struct qeth_ipaddr * |
| 155 | qeth_get_addr_buffer(enum qeth_prot_versions); |
| 156 | |
| 157 | static void |
| 158 | qeth_set_multicast_list(struct net_device *); |
| 159 | |
| 160 | static void |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 161 | qeth_setadp_promisc_mode(struct qeth_card *); |
| 162 | |
| 163 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | qeth_notify_processes(void) |
| 165 | { |
| 166 | /*notify all registered processes */ |
| 167 | struct qeth_notify_list_struct *n_entry; |
| 168 | |
| 169 | QETH_DBF_TEXT(trace,3,"procnoti"); |
| 170 | spin_lock(&qeth_notify_lock); |
| 171 | list_for_each_entry(n_entry, &qeth_notify_list, list) { |
| 172 | send_sig(n_entry->signum, n_entry->task, 1); |
| 173 | } |
| 174 | spin_unlock(&qeth_notify_lock); |
| 175 | |
| 176 | } |
| 177 | int |
| 178 | qeth_notifier_unregister(struct task_struct *p) |
| 179 | { |
| 180 | struct qeth_notify_list_struct *n_entry, *tmp; |
| 181 | |
| 182 | QETH_DBF_TEXT(trace, 2, "notunreg"); |
| 183 | spin_lock(&qeth_notify_lock); |
| 184 | list_for_each_entry_safe(n_entry, tmp, &qeth_notify_list, list) { |
| 185 | if (n_entry->task == p) { |
| 186 | list_del(&n_entry->list); |
| 187 | kfree(n_entry); |
| 188 | goto out; |
| 189 | } |
| 190 | } |
| 191 | out: |
| 192 | spin_unlock(&qeth_notify_lock); |
| 193 | return 0; |
| 194 | } |
| 195 | int |
| 196 | qeth_notifier_register(struct task_struct *p, int signum) |
| 197 | { |
| 198 | struct qeth_notify_list_struct *n_entry; |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | /*check first if entry already exists*/ |
| 201 | spin_lock(&qeth_notify_lock); |
| 202 | list_for_each_entry(n_entry, &qeth_notify_list, list) { |
| 203 | if (n_entry->task == p) { |
| 204 | n_entry->signum = signum; |
| 205 | spin_unlock(&qeth_notify_lock); |
| 206 | return 0; |
| 207 | } |
| 208 | } |
| 209 | spin_unlock(&qeth_notify_lock); |
| 210 | |
| 211 | n_entry = (struct qeth_notify_list_struct *) |
| 212 | kmalloc(sizeof(struct qeth_notify_list_struct),GFP_KERNEL); |
| 213 | if (!n_entry) |
| 214 | return -ENOMEM; |
| 215 | n_entry->task = p; |
| 216 | n_entry->signum = signum; |
| 217 | spin_lock(&qeth_notify_lock); |
| 218 | list_add(&n_entry->list,&qeth_notify_list); |
| 219 | spin_unlock(&qeth_notify_lock); |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | /** |
| 225 | * free channel command buffers |
| 226 | */ |
| 227 | static void |
| 228 | qeth_clean_channel(struct qeth_channel *channel) |
| 229 | { |
| 230 | int cnt; |
| 231 | |
| 232 | QETH_DBF_TEXT(setup, 2, "freech"); |
| 233 | for (cnt = 0; cnt < QETH_CMD_BUFFER_NO; cnt++) |
| 234 | kfree(channel->iob[cnt].data); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * free card |
| 239 | */ |
| 240 | static void |
| 241 | qeth_free_card(struct qeth_card *card) |
| 242 | { |
| 243 | |
| 244 | QETH_DBF_TEXT(setup, 2, "freecrd"); |
| 245 | QETH_DBF_HEX(setup, 2, &card, sizeof(void *)); |
| 246 | qeth_clean_channel(&card->read); |
| 247 | qeth_clean_channel(&card->write); |
| 248 | if (card->dev) |
| 249 | free_netdev(card->dev); |
| 250 | qeth_clear_ip_list(card, 0, 0); |
| 251 | qeth_clear_ipato_list(card); |
| 252 | kfree(card->ip_tbd_list); |
| 253 | qeth_free_qdio_buffers(card); |
| 254 | kfree(card); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * alloc memory for command buffer per channel |
| 259 | */ |
| 260 | static int |
| 261 | qeth_setup_channel(struct qeth_channel *channel) |
| 262 | { |
| 263 | int cnt; |
| 264 | |
| 265 | QETH_DBF_TEXT(setup, 2, "setupch"); |
| 266 | for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) { |
| 267 | channel->iob[cnt].data = (char *) |
| 268 | kmalloc(QETH_BUFSIZE, GFP_DMA|GFP_KERNEL); |
| 269 | if (channel->iob[cnt].data == NULL) |
| 270 | break; |
| 271 | channel->iob[cnt].state = BUF_STATE_FREE; |
| 272 | channel->iob[cnt].channel = channel; |
| 273 | channel->iob[cnt].callback = qeth_send_control_data_cb; |
| 274 | channel->iob[cnt].rc = 0; |
| 275 | } |
| 276 | if (cnt < QETH_CMD_BUFFER_NO) { |
| 277 | while (cnt-- > 0) |
| 278 | kfree(channel->iob[cnt].data); |
| 279 | return -ENOMEM; |
| 280 | } |
| 281 | channel->buf_no = 0; |
| 282 | channel->io_buf_no = 0; |
| 283 | atomic_set(&channel->irq_pending, 0); |
| 284 | spin_lock_init(&channel->iob_lock); |
| 285 | |
| 286 | init_waitqueue_head(&channel->wait_q); |
| 287 | channel->irq_tasklet.data = (unsigned long) channel; |
| 288 | channel->irq_tasklet.func = qeth_irq_tasklet; |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * alloc memory for card structure |
| 294 | */ |
| 295 | static struct qeth_card * |
| 296 | qeth_alloc_card(void) |
| 297 | { |
| 298 | struct qeth_card *card; |
| 299 | |
| 300 | QETH_DBF_TEXT(setup, 2, "alloccrd"); |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 301 | card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (!card) |
| 303 | return NULL; |
| 304 | QETH_DBF_HEX(setup, 2, &card, sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | if (qeth_setup_channel(&card->read)) { |
| 306 | kfree(card); |
| 307 | return NULL; |
| 308 | } |
| 309 | if (qeth_setup_channel(&card->write)) { |
| 310 | qeth_clean_channel(&card->read); |
| 311 | kfree(card); |
| 312 | return NULL; |
| 313 | } |
| 314 | return card; |
| 315 | } |
| 316 | |
| 317 | static long |
| 318 | __qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb) |
| 319 | { |
| 320 | if (!IS_ERR(irb)) |
| 321 | return 0; |
| 322 | |
| 323 | switch (PTR_ERR(irb)) { |
| 324 | case -EIO: |
| 325 | PRINT_WARN("i/o-error on device %s\n", cdev->dev.bus_id); |
| 326 | QETH_DBF_TEXT(trace, 2, "ckirberr"); |
| 327 | QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO); |
| 328 | break; |
| 329 | case -ETIMEDOUT: |
| 330 | PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id); |
| 331 | QETH_DBF_TEXT(trace, 2, "ckirberr"); |
| 332 | QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT); |
| 333 | break; |
| 334 | default: |
| 335 | PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb), |
| 336 | cdev->dev.bus_id); |
| 337 | QETH_DBF_TEXT(trace, 2, "ckirberr"); |
| 338 | QETH_DBF_TEXT(trace, 2, " rc???"); |
| 339 | } |
| 340 | return PTR_ERR(irb); |
| 341 | } |
| 342 | |
| 343 | static int |
| 344 | qeth_get_problem(struct ccw_device *cdev, struct irb *irb) |
| 345 | { |
| 346 | int dstat,cstat; |
| 347 | char *sense; |
| 348 | |
| 349 | sense = (char *) irb->ecw; |
| 350 | cstat = irb->scsw.cstat; |
| 351 | dstat = irb->scsw.dstat; |
| 352 | |
| 353 | if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK | |
| 354 | SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK | |
| 355 | SCHN_STAT_PROT_CHECK | SCHN_STAT_PROG_CHECK)) { |
| 356 | QETH_DBF_TEXT(trace,2, "CGENCHK"); |
| 357 | PRINT_WARN("check on device %s, dstat=x%x, cstat=x%x ", |
| 358 | cdev->dev.bus_id, dstat, cstat); |
| 359 | HEXDUMP16(WARN, "irb: ", irb); |
| 360 | HEXDUMP16(WARN, "irb: ", ((char *) irb) + 32); |
| 361 | return 1; |
| 362 | } |
| 363 | |
| 364 | if (dstat & DEV_STAT_UNIT_CHECK) { |
| 365 | if (sense[SENSE_RESETTING_EVENT_BYTE] & |
| 366 | SENSE_RESETTING_EVENT_FLAG) { |
| 367 | QETH_DBF_TEXT(trace,2,"REVIND"); |
| 368 | return 1; |
| 369 | } |
| 370 | if (sense[SENSE_COMMAND_REJECT_BYTE] & |
| 371 | SENSE_COMMAND_REJECT_FLAG) { |
| 372 | QETH_DBF_TEXT(trace,2,"CMDREJi"); |
| 373 | return 0; |
| 374 | } |
| 375 | if ((sense[2] == 0xaf) && (sense[3] == 0xfe)) { |
| 376 | QETH_DBF_TEXT(trace,2,"AFFE"); |
| 377 | return 1; |
| 378 | } |
| 379 | if ((!sense[0]) && (!sense[1]) && (!sense[2]) && (!sense[3])) { |
| 380 | QETH_DBF_TEXT(trace,2,"ZEROSEN"); |
| 381 | return 0; |
| 382 | } |
| 383 | QETH_DBF_TEXT(trace,2,"DGENCHK"); |
| 384 | return 1; |
| 385 | } |
| 386 | return 0; |
| 387 | } |
| 388 | static int qeth_issue_next_read(struct qeth_card *); |
| 389 | |
| 390 | /** |
| 391 | * interrupt handler |
| 392 | */ |
| 393 | static void |
| 394 | qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb) |
| 395 | { |
| 396 | int rc; |
| 397 | int cstat,dstat; |
| 398 | struct qeth_cmd_buffer *buffer; |
| 399 | struct qeth_channel *channel; |
| 400 | struct qeth_card *card; |
| 401 | |
| 402 | QETH_DBF_TEXT(trace,5,"irq"); |
| 403 | |
| 404 | if (__qeth_check_irb_error(cdev, irb)) |
| 405 | return; |
| 406 | cstat = irb->scsw.cstat; |
| 407 | dstat = irb->scsw.dstat; |
| 408 | |
| 409 | card = CARD_FROM_CDEV(cdev); |
| 410 | if (!card) |
| 411 | return; |
| 412 | |
| 413 | if (card->read.ccwdev == cdev){ |
| 414 | channel = &card->read; |
| 415 | QETH_DBF_TEXT(trace,5,"read"); |
| 416 | } else if (card->write.ccwdev == cdev) { |
| 417 | channel = &card->write; |
| 418 | QETH_DBF_TEXT(trace,5,"write"); |
| 419 | } else { |
| 420 | channel = &card->data; |
| 421 | QETH_DBF_TEXT(trace,5,"data"); |
| 422 | } |
| 423 | atomic_set(&channel->irq_pending, 0); |
| 424 | |
| 425 | if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC)) |
| 426 | channel->state = CH_STATE_STOPPED; |
| 427 | |
| 428 | if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC)) |
| 429 | channel->state = CH_STATE_HALTED; |
| 430 | |
| 431 | /*let's wake up immediately on data channel*/ |
| 432 | if ((channel == &card->data) && (intparm != 0)) |
| 433 | goto out; |
| 434 | |
| 435 | if (intparm == QETH_CLEAR_CHANNEL_PARM) { |
| 436 | QETH_DBF_TEXT(trace, 6, "clrchpar"); |
| 437 | /* we don't have to handle this further */ |
| 438 | intparm = 0; |
| 439 | } |
| 440 | if (intparm == QETH_HALT_CHANNEL_PARM) { |
| 441 | QETH_DBF_TEXT(trace, 6, "hltchpar"); |
| 442 | /* we don't have to handle this further */ |
| 443 | intparm = 0; |
| 444 | } |
| 445 | if ((dstat & DEV_STAT_UNIT_EXCEP) || |
| 446 | (dstat & DEV_STAT_UNIT_CHECK) || |
| 447 | (cstat)) { |
| 448 | if (irb->esw.esw0.erw.cons) { |
| 449 | /* TODO: we should make this s390dbf */ |
| 450 | PRINT_WARN("sense data available on channel %s.\n", |
| 451 | CHANNEL_ID(channel)); |
| 452 | PRINT_WARN(" cstat 0x%X\n dstat 0x%X\n", cstat, dstat); |
| 453 | HEXDUMP16(WARN,"irb: ",irb); |
| 454 | HEXDUMP16(WARN,"sense data: ",irb->ecw); |
| 455 | } |
| 456 | rc = qeth_get_problem(cdev,irb); |
| 457 | if (rc) { |
| 458 | qeth_schedule_recovery(card); |
| 459 | goto out; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | if (intparm) { |
| 464 | buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm); |
| 465 | buffer->state = BUF_STATE_PROCESSED; |
| 466 | } |
| 467 | if (channel == &card->data) |
| 468 | return; |
| 469 | |
| 470 | if (channel == &card->read && |
| 471 | channel->state == CH_STATE_UP) |
| 472 | qeth_issue_next_read(card); |
| 473 | |
| 474 | tasklet_schedule(&channel->irq_tasklet); |
| 475 | return; |
| 476 | out: |
| 477 | wake_up(&card->wait_q); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * tasklet function scheduled from irq handler |
| 482 | */ |
| 483 | static void |
| 484 | qeth_irq_tasklet(unsigned long data) |
| 485 | { |
| 486 | struct qeth_card *card; |
| 487 | struct qeth_channel *channel; |
| 488 | struct qeth_cmd_buffer *iob; |
| 489 | __u8 index; |
| 490 | |
| 491 | QETH_DBF_TEXT(trace,5,"irqtlet"); |
| 492 | channel = (struct qeth_channel *) data; |
| 493 | iob = channel->iob; |
| 494 | index = channel->buf_no; |
| 495 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 496 | while (iob[index].state == BUF_STATE_PROCESSED) { |
| 497 | if (iob[index].callback !=NULL) { |
| 498 | iob[index].callback(channel,iob + index); |
| 499 | } |
| 500 | index = (index + 1) % QETH_CMD_BUFFER_NO; |
| 501 | } |
| 502 | channel->buf_no = index; |
| 503 | wake_up(&card->wait_q); |
| 504 | } |
| 505 | |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 506 | static int qeth_stop_card(struct qeth_card *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | static int |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 509 | __qeth_set_offline(struct ccwgroup_device *cgdev, int recovery_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
| 511 | struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data; |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 512 | int rc = 0, rc2 = 0, rc3 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | enum qeth_card_states recover_flag; |
| 514 | |
| 515 | QETH_DBF_TEXT(setup, 3, "setoffl"); |
| 516 | QETH_DBF_HEX(setup, 3, &card, sizeof(void *)); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 517 | |
Frank Pavlic | 66cc5d5 | 2006-02-07 17:04:38 +0100 | [diff] [blame] | 518 | if (card->dev && netif_carrier_ok(card->dev)) |
| 519 | netif_carrier_off(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | recover_flag = card->state; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 521 | if (qeth_stop_card(card, recovery_mode) == -ERESTARTSYS){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | PRINT_WARN("Stopping card %s interrupted by user!\n", |
| 523 | CARD_BUS_ID(card)); |
| 524 | return -ERESTARTSYS; |
| 525 | } |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 526 | rc = ccw_device_set_offline(CARD_DDEV(card)); |
| 527 | rc2 = ccw_device_set_offline(CARD_WDEV(card)); |
| 528 | rc3 = ccw_device_set_offline(CARD_RDEV(card)); |
| 529 | if (!rc) |
| 530 | rc = (rc2) ? rc2 : rc3; |
| 531 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | if (recover_flag == CARD_STATE_UP) |
| 534 | card->state = CARD_STATE_RECOVER; |
| 535 | qeth_notify_processes(); |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | static int |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 540 | qeth_set_offline(struct ccwgroup_device *cgdev) |
| 541 | { |
| 542 | return __qeth_set_offline(cgdev, 0); |
| 543 | } |
| 544 | |
| 545 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | qeth_wait_for_threads(struct qeth_card *card, unsigned long threads); |
| 547 | |
| 548 | |
| 549 | static void |
| 550 | qeth_remove_device(struct ccwgroup_device *cgdev) |
| 551 | { |
| 552 | struct qeth_card *card = (struct qeth_card *) cgdev->dev.driver_data; |
| 553 | unsigned long flags; |
| 554 | |
| 555 | QETH_DBF_TEXT(setup, 3, "rmdev"); |
| 556 | QETH_DBF_HEX(setup, 3, &card, sizeof(void *)); |
| 557 | |
| 558 | if (!card) |
| 559 | return; |
| 560 | |
| 561 | if (qeth_wait_for_threads(card, 0xffffffff)) |
| 562 | return; |
| 563 | |
| 564 | if (cgdev->state == CCWGROUP_ONLINE){ |
| 565 | card->use_hard_stop = 1; |
| 566 | qeth_set_offline(cgdev); |
| 567 | } |
| 568 | /* remove form our internal list */ |
| 569 | write_lock_irqsave(&qeth_card_list.rwlock, flags); |
| 570 | list_del(&card->list); |
| 571 | write_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 572 | if (card->dev) |
| 573 | unregister_netdev(card->dev); |
| 574 | qeth_remove_device_attributes(&cgdev->dev); |
| 575 | qeth_free_card(card); |
| 576 | cgdev->dev.driver_data = NULL; |
| 577 | put_device(&cgdev->dev); |
| 578 | } |
| 579 | |
| 580 | static int |
| 581 | qeth_register_addr_entry(struct qeth_card *, struct qeth_ipaddr *); |
| 582 | static int |
| 583 | qeth_deregister_addr_entry(struct qeth_card *, struct qeth_ipaddr *); |
| 584 | |
| 585 | /** |
| 586 | * Add/remove address to/from card's ip list, i.e. try to add or remove |
| 587 | * reference to/from an IP address that is already registered on the card. |
| 588 | * Returns: |
| 589 | * 0 address was on card and its reference count has been adjusted, |
| 590 | * but is still > 0, so nothing has to be done |
| 591 | * also returns 0 if card was not on card and the todo was to delete |
| 592 | * the address -> there is also nothing to be done |
| 593 | * 1 address was not on card and the todo is to add it to the card's ip |
| 594 | * list |
| 595 | * -1 address was on card and its reference count has been decremented |
| 596 | * to <= 0 by the todo -> address must be removed from card |
| 597 | */ |
| 598 | static int |
| 599 | __qeth_ref_ip_on_card(struct qeth_card *card, struct qeth_ipaddr *todo, |
| 600 | struct qeth_ipaddr **__addr) |
| 601 | { |
| 602 | struct qeth_ipaddr *addr; |
| 603 | int found = 0; |
| 604 | |
| 605 | list_for_each_entry(addr, &card->ip_list, entry) { |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 606 | if (card->options.layer2) { |
| 607 | if ((addr->type == todo->type) && |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 608 | (memcmp(&addr->mac, &todo->mac, |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 609 | OSA_ADDR_LEN) == 0)) { |
| 610 | found = 1; |
| 611 | break; |
| 612 | } |
| 613 | continue; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 614 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | if ((addr->proto == QETH_PROT_IPV4) && |
| 616 | (todo->proto == QETH_PROT_IPV4) && |
| 617 | (addr->type == todo->type) && |
| 618 | (addr->u.a4.addr == todo->u.a4.addr) && |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 619 | (addr->u.a4.mask == todo->u.a4.mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | found = 1; |
| 621 | break; |
| 622 | } |
| 623 | if ((addr->proto == QETH_PROT_IPV6) && |
| 624 | (todo->proto == QETH_PROT_IPV6) && |
| 625 | (addr->type == todo->type) && |
| 626 | (addr->u.a6.pfxlen == todo->u.a6.pfxlen) && |
| 627 | (memcmp(&addr->u.a6.addr, &todo->u.a6.addr, |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 628 | sizeof(struct in6_addr)) == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | found = 1; |
| 630 | break; |
| 631 | } |
| 632 | } |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 633 | if (found) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | addr->users += todo->users; |
| 635 | if (addr->users <= 0){ |
| 636 | *__addr = addr; |
| 637 | return -1; |
| 638 | } else { |
| 639 | /* for VIPA and RXIP limit refcount to 1 */ |
| 640 | if (addr->type != QETH_IP_TYPE_NORMAL) |
| 641 | addr->users = 1; |
| 642 | return 0; |
| 643 | } |
| 644 | } |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 645 | if (todo->users > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | /* for VIPA and RXIP limit refcount to 1 */ |
| 647 | if (todo->type != QETH_IP_TYPE_NORMAL) |
| 648 | todo->users = 1; |
| 649 | return 1; |
| 650 | } else |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static inline int |
| 655 | __qeth_address_exists_in_list(struct list_head *list, struct qeth_ipaddr *addr, |
| 656 | int same_type) |
| 657 | { |
| 658 | struct qeth_ipaddr *tmp; |
| 659 | |
| 660 | list_for_each_entry(tmp, list, entry) { |
| 661 | if ((tmp->proto == QETH_PROT_IPV4) && |
| 662 | (addr->proto == QETH_PROT_IPV4) && |
| 663 | ((same_type && (tmp->type == addr->type)) || |
| 664 | (!same_type && (tmp->type != addr->type)) ) && |
| 665 | (tmp->u.a4.addr == addr->u.a4.addr) ){ |
| 666 | return 1; |
| 667 | } |
| 668 | if ((tmp->proto == QETH_PROT_IPV6) && |
| 669 | (addr->proto == QETH_PROT_IPV6) && |
| 670 | ((same_type && (tmp->type == addr->type)) || |
| 671 | (!same_type && (tmp->type != addr->type)) ) && |
| 672 | (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr, |
| 673 | sizeof(struct in6_addr)) == 0) ) { |
| 674 | return 1; |
| 675 | } |
| 676 | } |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | /* |
| 681 | * Add IP to be added to todo list. If there is already an "add todo" |
| 682 | * in this list we just incremenent the reference count. |
| 683 | * Returns 0 if we just incremented reference count. |
| 684 | */ |
| 685 | static int |
| 686 | __qeth_insert_ip_todo(struct qeth_card *card, struct qeth_ipaddr *addr, int add) |
| 687 | { |
| 688 | struct qeth_ipaddr *tmp, *t; |
| 689 | int found = 0; |
| 690 | |
| 691 | list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) { |
| 692 | if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) && |
| 693 | (tmp->type == QETH_IP_TYPE_DEL_ALL_MC)) |
| 694 | return 0; |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 695 | if (card->options.layer2) { |
| 696 | if ((tmp->type == addr->type) && |
| 697 | (tmp->is_multicast == addr->is_multicast) && |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 698 | (memcmp(&tmp->mac, &addr->mac, |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 699 | OSA_ADDR_LEN) == 0)) { |
| 700 | found = 1; |
| 701 | break; |
| 702 | } |
| 703 | continue; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 704 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if ((tmp->proto == QETH_PROT_IPV4) && |
| 706 | (addr->proto == QETH_PROT_IPV4) && |
| 707 | (tmp->type == addr->type) && |
| 708 | (tmp->is_multicast == addr->is_multicast) && |
| 709 | (tmp->u.a4.addr == addr->u.a4.addr) && |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 710 | (tmp->u.a4.mask == addr->u.a4.mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | found = 1; |
| 712 | break; |
| 713 | } |
| 714 | if ((tmp->proto == QETH_PROT_IPV6) && |
| 715 | (addr->proto == QETH_PROT_IPV6) && |
| 716 | (tmp->type == addr->type) && |
| 717 | (tmp->is_multicast == addr->is_multicast) && |
| 718 | (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) && |
| 719 | (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr, |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 720 | sizeof(struct in6_addr)) == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | found = 1; |
| 722 | break; |
| 723 | } |
| 724 | } |
| 725 | if (found){ |
| 726 | if (addr->users != 0) |
| 727 | tmp->users += addr->users; |
| 728 | else |
| 729 | tmp->users += add? 1:-1; |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 730 | if (tmp->users == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | list_del(&tmp->entry); |
| 732 | kfree(tmp); |
| 733 | } |
| 734 | return 0; |
| 735 | } else { |
| 736 | if (addr->type == QETH_IP_TYPE_DEL_ALL_MC) |
| 737 | list_add(&addr->entry, card->ip_tbd_list); |
| 738 | else { |
| 739 | if (addr->users == 0) |
| 740 | addr->users += add? 1:-1; |
| 741 | if (add && (addr->type == QETH_IP_TYPE_NORMAL) && |
| 742 | qeth_is_addr_covered_by_ipato(card, addr)){ |
| 743 | QETH_DBF_TEXT(trace, 2, "tkovaddr"); |
| 744 | addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG; |
| 745 | } |
| 746 | list_add_tail(&addr->entry, card->ip_tbd_list); |
| 747 | } |
| 748 | return 1; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | /** |
| 753 | * Remove IP address from list |
| 754 | */ |
| 755 | static int |
| 756 | qeth_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 757 | { |
| 758 | unsigned long flags; |
| 759 | int rc = 0; |
| 760 | |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 761 | QETH_DBF_TEXT(trace, 4, "delip"); |
| 762 | |
| 763 | if (card->options.layer2) |
| 764 | QETH_DBF_HEX(trace, 4, &addr->mac, 6); |
| 765 | else if (addr->proto == QETH_PROT_IPV4) |
| 766 | QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | else { |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 768 | QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8); |
| 769 | QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | spin_lock_irqsave(&card->ip_lock, flags); |
| 772 | rc = __qeth_insert_ip_todo(card, addr, 0); |
| 773 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 774 | return rc; |
| 775 | } |
| 776 | |
| 777 | static int |
| 778 | qeth_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 779 | { |
| 780 | unsigned long flags; |
| 781 | int rc = 0; |
| 782 | |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 783 | QETH_DBF_TEXT(trace, 4, "addip"); |
| 784 | if (card->options.layer2) |
| 785 | QETH_DBF_HEX(trace, 4, &addr->mac, 6); |
| 786 | else if (addr->proto == QETH_PROT_IPV4) |
| 787 | QETH_DBF_HEX(trace, 4, &addr->u.a4.addr, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | else { |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 789 | QETH_DBF_HEX(trace, 4, &addr->u.a6.addr, 8); |
| 790 | QETH_DBF_HEX(trace, 4, ((char *)&addr->u.a6.addr) + 8, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | spin_lock_irqsave(&card->ip_lock, flags); |
| 793 | rc = __qeth_insert_ip_todo(card, addr, 1); |
| 794 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 795 | return rc; |
| 796 | } |
| 797 | |
| 798 | static inline void |
| 799 | __qeth_delete_all_mc(struct qeth_card *card, unsigned long *flags) |
| 800 | { |
| 801 | struct qeth_ipaddr *addr, *tmp; |
| 802 | int rc; |
Frank Pavlic | d805d7c | 2005-11-10 13:50:58 +0100 | [diff] [blame] | 803 | again: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) { |
| 805 | if (addr->is_multicast) { |
| 806 | spin_unlock_irqrestore(&card->ip_lock, *flags); |
| 807 | rc = qeth_deregister_addr_entry(card, addr); |
| 808 | spin_lock_irqsave(&card->ip_lock, *flags); |
| 809 | if (!rc) { |
| 810 | list_del(&addr->entry); |
| 811 | kfree(addr); |
Frank Pavlic | d805d7c | 2005-11-10 13:50:58 +0100 | [diff] [blame] | 812 | goto again; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | static void |
| 819 | qeth_set_ip_addr_list(struct qeth_card *card) |
| 820 | { |
| 821 | struct list_head *tbd_list; |
| 822 | struct qeth_ipaddr *todo, *addr; |
| 823 | unsigned long flags; |
| 824 | int rc; |
| 825 | |
| 826 | QETH_DBF_TEXT(trace, 2, "sdiplist"); |
| 827 | QETH_DBF_HEX(trace, 2, &card, sizeof(void *)); |
| 828 | |
| 829 | spin_lock_irqsave(&card->ip_lock, flags); |
| 830 | tbd_list = card->ip_tbd_list; |
| 831 | card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC); |
| 832 | if (!card->ip_tbd_list) { |
| 833 | QETH_DBF_TEXT(trace, 0, "silnomem"); |
| 834 | card->ip_tbd_list = tbd_list; |
| 835 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 836 | return; |
| 837 | } else |
| 838 | INIT_LIST_HEAD(card->ip_tbd_list); |
| 839 | |
| 840 | while (!list_empty(tbd_list)){ |
| 841 | todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry); |
| 842 | list_del(&todo->entry); |
| 843 | if (todo->type == QETH_IP_TYPE_DEL_ALL_MC){ |
| 844 | __qeth_delete_all_mc(card, &flags); |
| 845 | kfree(todo); |
| 846 | continue; |
| 847 | } |
| 848 | rc = __qeth_ref_ip_on_card(card, todo, &addr); |
| 849 | if (rc == 0) { |
| 850 | /* nothing to be done; only adjusted refcount */ |
| 851 | kfree(todo); |
| 852 | } else if (rc == 1) { |
| 853 | /* new entry to be added to on-card list */ |
| 854 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 855 | rc = qeth_register_addr_entry(card, todo); |
| 856 | spin_lock_irqsave(&card->ip_lock, flags); |
| 857 | if (!rc) |
| 858 | list_add_tail(&todo->entry, &card->ip_list); |
| 859 | else |
| 860 | kfree(todo); |
| 861 | } else if (rc == -1) { |
| 862 | /* on-card entry to be removed */ |
| 863 | list_del_init(&addr->entry); |
| 864 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 865 | rc = qeth_deregister_addr_entry(card, addr); |
| 866 | spin_lock_irqsave(&card->ip_lock, flags); |
| 867 | if (!rc) |
| 868 | kfree(addr); |
| 869 | else |
| 870 | list_add_tail(&addr->entry, &card->ip_list); |
| 871 | kfree(todo); |
| 872 | } |
| 873 | } |
| 874 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 875 | kfree(tbd_list); |
| 876 | } |
| 877 | |
| 878 | static void qeth_delete_mc_addresses(struct qeth_card *); |
| 879 | static void qeth_add_multicast_ipv4(struct qeth_card *); |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 880 | static void qeth_layer2_add_multicast(struct qeth_card *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | #ifdef CONFIG_QETH_IPV6 |
| 882 | static void qeth_add_multicast_ipv6(struct qeth_card *); |
| 883 | #endif |
| 884 | |
| 885 | static inline int |
| 886 | qeth_set_thread_start_bit(struct qeth_card *card, unsigned long thread) |
| 887 | { |
| 888 | unsigned long flags; |
| 889 | |
| 890 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 891 | if ( !(card->thread_allowed_mask & thread) || |
| 892 | (card->thread_start_mask & thread) ) { |
| 893 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 894 | return -EPERM; |
| 895 | } |
| 896 | card->thread_start_mask |= thread; |
| 897 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | static void |
| 902 | qeth_clear_thread_start_bit(struct qeth_card *card, unsigned long thread) |
| 903 | { |
| 904 | unsigned long flags; |
| 905 | |
| 906 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 907 | card->thread_start_mask &= ~thread; |
| 908 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 909 | wake_up(&card->wait_q); |
| 910 | } |
| 911 | |
| 912 | static void |
| 913 | qeth_clear_thread_running_bit(struct qeth_card *card, unsigned long thread) |
| 914 | { |
| 915 | unsigned long flags; |
| 916 | |
| 917 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 918 | card->thread_running_mask &= ~thread; |
| 919 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 920 | wake_up(&card->wait_q); |
| 921 | } |
| 922 | |
| 923 | static inline int |
| 924 | __qeth_do_run_thread(struct qeth_card *card, unsigned long thread) |
| 925 | { |
| 926 | unsigned long flags; |
| 927 | int rc = 0; |
| 928 | |
| 929 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 930 | if (card->thread_start_mask & thread){ |
| 931 | if ((card->thread_allowed_mask & thread) && |
| 932 | !(card->thread_running_mask & thread)){ |
| 933 | rc = 1; |
| 934 | card->thread_start_mask &= ~thread; |
| 935 | card->thread_running_mask |= thread; |
| 936 | } else |
| 937 | rc = -EPERM; |
| 938 | } |
| 939 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 940 | return rc; |
| 941 | } |
| 942 | |
| 943 | static int |
| 944 | qeth_do_run_thread(struct qeth_card *card, unsigned long thread) |
| 945 | { |
| 946 | int rc = 0; |
| 947 | |
| 948 | wait_event(card->wait_q, |
| 949 | (rc = __qeth_do_run_thread(card, thread)) >= 0); |
| 950 | return rc; |
| 951 | } |
| 952 | |
| 953 | static int |
| 954 | qeth_register_ip_addresses(void *ptr) |
| 955 | { |
| 956 | struct qeth_card *card; |
| 957 | |
| 958 | card = (struct qeth_card *) ptr; |
| 959 | daemonize("qeth_reg_ip"); |
| 960 | QETH_DBF_TEXT(trace,4,"regipth1"); |
| 961 | if (!qeth_do_run_thread(card, QETH_SET_IP_THREAD)) |
| 962 | return 0; |
| 963 | QETH_DBF_TEXT(trace,4,"regipth2"); |
| 964 | qeth_set_ip_addr_list(card); |
| 965 | qeth_clear_thread_running_bit(card, QETH_SET_IP_THREAD); |
| 966 | return 0; |
| 967 | } |
| 968 | |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 969 | /* |
| 970 | * Drive the SET_PROMISC_MODE thread |
| 971 | */ |
| 972 | static int |
| 973 | qeth_set_promisc_mode(void *ptr) |
| 974 | { |
| 975 | struct qeth_card *card = (struct qeth_card *) ptr; |
| 976 | |
| 977 | daemonize("qeth_setprm"); |
| 978 | QETH_DBF_TEXT(trace,4,"setprm1"); |
| 979 | if (!qeth_do_run_thread(card, QETH_SET_PROMISC_MODE_THREAD)) |
| 980 | return 0; |
| 981 | QETH_DBF_TEXT(trace,4,"setprm2"); |
| 982 | qeth_setadp_promisc_mode(card); |
| 983 | qeth_clear_thread_running_bit(card, QETH_SET_PROMISC_MODE_THREAD); |
| 984 | return 0; |
| 985 | } |
| 986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | static int |
| 988 | qeth_recover(void *ptr) |
| 989 | { |
| 990 | struct qeth_card *card; |
| 991 | int rc = 0; |
| 992 | |
| 993 | card = (struct qeth_card *) ptr; |
| 994 | daemonize("qeth_recover"); |
| 995 | QETH_DBF_TEXT(trace,2,"recover1"); |
| 996 | QETH_DBF_HEX(trace, 2, &card, sizeof(void *)); |
| 997 | if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) |
| 998 | return 0; |
| 999 | QETH_DBF_TEXT(trace,2,"recover2"); |
| 1000 | PRINT_WARN("Recovery of device %s started ...\n", |
| 1001 | CARD_BUS_ID(card)); |
| 1002 | card->use_hard_stop = 1; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 1003 | __qeth_set_offline(card->gdev,1); |
| 1004 | rc = __qeth_set_online(card->gdev,1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | if (!rc) |
| 1006 | PRINT_INFO("Device %s successfully recovered!\n", |
| 1007 | CARD_BUS_ID(card)); |
| 1008 | else |
| 1009 | PRINT_INFO("Device %s could not be recovered!\n", |
| 1010 | CARD_BUS_ID(card)); |
| 1011 | /* don't run another scheduled recovery */ |
| 1012 | qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); |
| 1013 | qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
| 1017 | void |
| 1018 | qeth_schedule_recovery(struct qeth_card *card) |
| 1019 | { |
| 1020 | QETH_DBF_TEXT(trace,2,"startrec"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0) |
| 1022 | schedule_work(&card->kernel_thread_starter); |
| 1023 | } |
| 1024 | |
| 1025 | static int |
| 1026 | qeth_do_start_thread(struct qeth_card *card, unsigned long thread) |
| 1027 | { |
| 1028 | unsigned long flags; |
| 1029 | int rc = 0; |
| 1030 | |
| 1031 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 1032 | QETH_DBF_TEXT_(trace, 4, " %02x%02x%02x", |
| 1033 | (u8) card->thread_start_mask, |
| 1034 | (u8) card->thread_allowed_mask, |
| 1035 | (u8) card->thread_running_mask); |
| 1036 | rc = (card->thread_start_mask & thread); |
| 1037 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 1038 | return rc; |
| 1039 | } |
| 1040 | |
| 1041 | static void |
| 1042 | qeth_start_kernel_thread(struct qeth_card *card) |
| 1043 | { |
| 1044 | QETH_DBF_TEXT(trace , 2, "strthrd"); |
| 1045 | |
| 1046 | if (card->read.state != CH_STATE_UP && |
| 1047 | card->write.state != CH_STATE_UP) |
| 1048 | return; |
| 1049 | |
| 1050 | if (qeth_do_start_thread(card, QETH_SET_IP_THREAD)) |
| 1051 | kernel_thread(qeth_register_ip_addresses, (void *)card,SIGCHLD); |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 1052 | if (qeth_do_start_thread(card, QETH_SET_PROMISC_MODE_THREAD)) |
| 1053 | kernel_thread(qeth_set_promisc_mode, (void *)card, SIGCHLD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | if (qeth_do_start_thread(card, QETH_RECOVER_THREAD)) |
| 1055 | kernel_thread(qeth_recover, (void *) card, SIGCHLD); |
| 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | static void |
| 1060 | qeth_set_intial_options(struct qeth_card *card) |
| 1061 | { |
| 1062 | card->options.route4.type = NO_ROUTER; |
| 1063 | #ifdef CONFIG_QETH_IPV6 |
| 1064 | card->options.route6.type = NO_ROUTER; |
| 1065 | #endif /* QETH_IPV6 */ |
| 1066 | card->options.checksum_type = QETH_CHECKSUM_DEFAULT; |
| 1067 | card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS; |
| 1068 | card->options.macaddr_mode = QETH_TR_MACADDR_NONCANONICAL; |
| 1069 | card->options.fake_broadcast = 0; |
| 1070 | card->options.add_hhlen = DEFAULT_ADD_HHLEN; |
| 1071 | card->options.fake_ll = 0; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1072 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 1073 | card->options.layer2 = 1; |
| 1074 | else |
| 1075 | card->options.layer2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * initialize channels ,card and all state machines |
| 1080 | */ |
| 1081 | static int |
| 1082 | qeth_setup_card(struct qeth_card *card) |
| 1083 | { |
| 1084 | |
| 1085 | QETH_DBF_TEXT(setup, 2, "setupcrd"); |
| 1086 | QETH_DBF_HEX(setup, 2, &card, sizeof(void *)); |
| 1087 | |
| 1088 | card->read.state = CH_STATE_DOWN; |
| 1089 | card->write.state = CH_STATE_DOWN; |
| 1090 | card->data.state = CH_STATE_DOWN; |
| 1091 | card->state = CARD_STATE_DOWN; |
| 1092 | card->lan_online = 0; |
| 1093 | card->use_hard_stop = 0; |
| 1094 | card->dev = NULL; |
| 1095 | #ifdef CONFIG_QETH_VLAN |
| 1096 | spin_lock_init(&card->vlanlock); |
| 1097 | card->vlangrp = NULL; |
| 1098 | #endif |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 1099 | spin_lock_init(&card->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | spin_lock_init(&card->ip_lock); |
| 1101 | spin_lock_init(&card->thread_mask_lock); |
| 1102 | card->thread_start_mask = 0; |
| 1103 | card->thread_allowed_mask = 0; |
| 1104 | card->thread_running_mask = 0; |
| 1105 | INIT_WORK(&card->kernel_thread_starter, |
| 1106 | (void *)qeth_start_kernel_thread,card); |
| 1107 | INIT_LIST_HEAD(&card->ip_list); |
| 1108 | card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_KERNEL); |
| 1109 | if (!card->ip_tbd_list) { |
| 1110 | QETH_DBF_TEXT(setup, 0, "iptbdnom"); |
| 1111 | return -ENOMEM; |
| 1112 | } |
| 1113 | INIT_LIST_HEAD(card->ip_tbd_list); |
| 1114 | INIT_LIST_HEAD(&card->cmd_waiter_list); |
| 1115 | init_waitqueue_head(&card->wait_q); |
| 1116 | /* intial options */ |
| 1117 | qeth_set_intial_options(card); |
| 1118 | /* IP address takeover */ |
| 1119 | INIT_LIST_HEAD(&card->ipato.entries); |
| 1120 | card->ipato.enabled = 0; |
| 1121 | card->ipato.invert4 = 0; |
| 1122 | card->ipato.invert6 = 0; |
| 1123 | /* init QDIO stuff */ |
| 1124 | qeth_init_qdio_info(card); |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | static int |
| 1129 | is_1920_device (struct qeth_card *card) |
| 1130 | { |
| 1131 | int single_queue = 0; |
| 1132 | struct ccw_device *ccwdev; |
| 1133 | struct channelPath_dsc { |
| 1134 | u8 flags; |
| 1135 | u8 lsn; |
| 1136 | u8 desc; |
| 1137 | u8 chpid; |
| 1138 | u8 swla; |
| 1139 | u8 zeroes; |
| 1140 | u8 chla; |
| 1141 | u8 chpp; |
| 1142 | } *chp_dsc; |
| 1143 | |
| 1144 | QETH_DBF_TEXT(setup, 2, "chk_1920"); |
| 1145 | |
| 1146 | ccwdev = card->data.ccwdev; |
| 1147 | chp_dsc = (struct channelPath_dsc *)ccw_device_get_chp_desc(ccwdev, 0); |
| 1148 | if (chp_dsc != NULL) { |
| 1149 | /* CHPP field bit 6 == 1 -> single queue */ |
| 1150 | single_queue = ((chp_dsc->chpp & 0x02) == 0x02); |
| 1151 | kfree(chp_dsc); |
| 1152 | } |
| 1153 | QETH_DBF_TEXT_(setup, 2, "rc:%x", single_queue); |
| 1154 | return single_queue; |
| 1155 | } |
| 1156 | |
| 1157 | static int |
| 1158 | qeth_determine_card_type(struct qeth_card *card) |
| 1159 | { |
| 1160 | int i = 0; |
| 1161 | |
| 1162 | QETH_DBF_TEXT(setup, 2, "detcdtyp"); |
| 1163 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1164 | card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT; |
| 1165 | card->qdio.default_out_queue = QETH_DEFAULT_QUEUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | while (known_devices[i][4]) { |
| 1167 | if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) && |
| 1168 | (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) { |
| 1169 | card->info.type = known_devices[i][4]; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1170 | card->qdio.no_out_queues = known_devices[i][8]; |
| 1171 | card->info.is_multicast_different = known_devices[i][9]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | if (is_1920_device(card)) { |
| 1173 | PRINT_INFO("Priority Queueing not able " |
| 1174 | "due to hardware limitations!\n"); |
| 1175 | card->qdio.no_out_queues = 1; |
| 1176 | card->qdio.default_out_queue = 0; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1177 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | return 0; |
| 1179 | } |
| 1180 | i++; |
| 1181 | } |
| 1182 | card->info.type = QETH_CARD_TYPE_UNKNOWN; |
| 1183 | PRINT_ERR("unknown card type on device %s\n", CARD_BUS_ID(card)); |
| 1184 | return -ENOENT; |
| 1185 | } |
| 1186 | |
| 1187 | static int |
| 1188 | qeth_probe_device(struct ccwgroup_device *gdev) |
| 1189 | { |
| 1190 | struct qeth_card *card; |
| 1191 | struct device *dev; |
| 1192 | unsigned long flags; |
| 1193 | int rc; |
| 1194 | |
| 1195 | QETH_DBF_TEXT(setup, 2, "probedev"); |
| 1196 | |
| 1197 | dev = &gdev->dev; |
| 1198 | if (!get_device(dev)) |
| 1199 | return -ENODEV; |
| 1200 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1201 | QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | card = qeth_alloc_card(); |
| 1204 | if (!card) { |
| 1205 | put_device(dev); |
| 1206 | QETH_DBF_TEXT_(setup, 2, "1err%d", -ENOMEM); |
| 1207 | return -ENOMEM; |
| 1208 | } |
| 1209 | card->read.ccwdev = gdev->cdev[0]; |
| 1210 | card->write.ccwdev = gdev->cdev[1]; |
| 1211 | card->data.ccwdev = gdev->cdev[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | gdev->dev.driver_data = card; |
| 1213 | card->gdev = gdev; |
| 1214 | gdev->cdev[0]->handler = qeth_irq; |
| 1215 | gdev->cdev[1]->handler = qeth_irq; |
| 1216 | gdev->cdev[2]->handler = qeth_irq; |
| 1217 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1218 | if ((rc = qeth_determine_card_type(card))){ |
| 1219 | PRINT_WARN("%s: not a valid card type\n", __func__); |
| 1220 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
| 1221 | put_device(dev); |
| 1222 | qeth_free_card(card); |
| 1223 | return rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1224 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1225 | if ((rc = qeth_setup_card(card))){ |
| 1226 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | put_device(dev); |
| 1228 | qeth_free_card(card); |
| 1229 | return rc; |
| 1230 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1231 | rc = qeth_create_device_attributes(dev); |
| 1232 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | put_device(dev); |
| 1234 | qeth_free_card(card); |
| 1235 | return rc; |
| 1236 | } |
| 1237 | /* insert into our internal list */ |
| 1238 | write_lock_irqsave(&qeth_card_list.rwlock, flags); |
| 1239 | list_add_tail(&card->list, &qeth_card_list.list); |
| 1240 | write_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 1241 | return rc; |
| 1242 | } |
| 1243 | |
| 1244 | |
| 1245 | static int |
| 1246 | qeth_get_unitaddr(struct qeth_card *card) |
| 1247 | { |
| 1248 | int length; |
| 1249 | char *prcd; |
| 1250 | int rc; |
| 1251 | |
| 1252 | QETH_DBF_TEXT(setup, 2, "getunit"); |
| 1253 | rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length); |
| 1254 | if (rc) { |
| 1255 | PRINT_ERR("read_conf_data for device %s returned %i\n", |
| 1256 | CARD_DDEV_ID(card), rc); |
| 1257 | return rc; |
| 1258 | } |
| 1259 | card->info.chpid = prcd[30]; |
| 1260 | card->info.unit_addr2 = prcd[31]; |
| 1261 | card->info.cula = prcd[63]; |
| 1262 | card->info.guestlan = ((prcd[0x10] == _ascebc['V']) && |
| 1263 | (prcd[0x11] == _ascebc['M'])); |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
| 1267 | static void |
| 1268 | qeth_init_tokens(struct qeth_card *card) |
| 1269 | { |
| 1270 | card->token.issuer_rm_w = 0x00010103UL; |
| 1271 | card->token.cm_filter_w = 0x00010108UL; |
| 1272 | card->token.cm_connection_w = 0x0001010aUL; |
| 1273 | card->token.ulp_filter_w = 0x0001010bUL; |
| 1274 | card->token.ulp_connection_w = 0x0001010dUL; |
| 1275 | } |
| 1276 | |
| 1277 | static inline __u16 |
| 1278 | raw_devno_from_bus_id(char *id) |
| 1279 | { |
| 1280 | id += (strlen(id) - 4); |
| 1281 | return (__u16) simple_strtoul(id, &id, 16); |
| 1282 | } |
| 1283 | /** |
| 1284 | * setup channel |
| 1285 | */ |
| 1286 | static void |
| 1287 | qeth_setup_ccw(struct qeth_channel *channel,unsigned char *iob, __u32 len) |
| 1288 | { |
| 1289 | struct qeth_card *card; |
| 1290 | |
| 1291 | QETH_DBF_TEXT(trace, 4, "setupccw"); |
| 1292 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 1293 | if (channel == &card->read) |
| 1294 | memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1)); |
| 1295 | else |
| 1296 | memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1)); |
| 1297 | channel->ccw.count = len; |
| 1298 | channel->ccw.cda = (__u32) __pa(iob); |
| 1299 | } |
| 1300 | |
| 1301 | /** |
| 1302 | * get free buffer for ccws (IDX activation, lancmds,ipassists...) |
| 1303 | */ |
| 1304 | static struct qeth_cmd_buffer * |
| 1305 | __qeth_get_buffer(struct qeth_channel *channel) |
| 1306 | { |
| 1307 | __u8 index; |
| 1308 | |
| 1309 | QETH_DBF_TEXT(trace, 6, "getbuff"); |
| 1310 | index = channel->io_buf_no; |
| 1311 | do { |
| 1312 | if (channel->iob[index].state == BUF_STATE_FREE) { |
| 1313 | channel->iob[index].state = BUF_STATE_LOCKED; |
| 1314 | channel->io_buf_no = (channel->io_buf_no + 1) % |
| 1315 | QETH_CMD_BUFFER_NO; |
| 1316 | memset(channel->iob[index].data, 0, QETH_BUFSIZE); |
| 1317 | return channel->iob + index; |
| 1318 | } |
| 1319 | index = (index + 1) % QETH_CMD_BUFFER_NO; |
| 1320 | } while(index != channel->io_buf_no); |
| 1321 | |
| 1322 | return NULL; |
| 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * release command buffer |
| 1327 | */ |
| 1328 | static void |
| 1329 | qeth_release_buffer(struct qeth_channel *channel, struct qeth_cmd_buffer *iob) |
| 1330 | { |
| 1331 | unsigned long flags; |
| 1332 | |
| 1333 | QETH_DBF_TEXT(trace, 6, "relbuff"); |
| 1334 | spin_lock_irqsave(&channel->iob_lock, flags); |
| 1335 | memset(iob->data, 0, QETH_BUFSIZE); |
| 1336 | iob->state = BUF_STATE_FREE; |
| 1337 | iob->callback = qeth_send_control_data_cb; |
| 1338 | iob->rc = 0; |
| 1339 | spin_unlock_irqrestore(&channel->iob_lock, flags); |
| 1340 | } |
| 1341 | |
| 1342 | static struct qeth_cmd_buffer * |
| 1343 | qeth_get_buffer(struct qeth_channel *channel) |
| 1344 | { |
| 1345 | struct qeth_cmd_buffer *buffer = NULL; |
| 1346 | unsigned long flags; |
| 1347 | |
| 1348 | spin_lock_irqsave(&channel->iob_lock, flags); |
| 1349 | buffer = __qeth_get_buffer(channel); |
| 1350 | spin_unlock_irqrestore(&channel->iob_lock, flags); |
| 1351 | return buffer; |
| 1352 | } |
| 1353 | |
| 1354 | static struct qeth_cmd_buffer * |
| 1355 | qeth_wait_for_buffer(struct qeth_channel *channel) |
| 1356 | { |
| 1357 | struct qeth_cmd_buffer *buffer; |
| 1358 | wait_event(channel->wait_q, |
| 1359 | ((buffer = qeth_get_buffer(channel)) != NULL)); |
| 1360 | return buffer; |
| 1361 | } |
| 1362 | |
| 1363 | static void |
| 1364 | qeth_clear_cmd_buffers(struct qeth_channel *channel) |
| 1365 | { |
Frank Pavlic | 1380fee | 2006-03-22 16:03:41 +0100 | [diff] [blame] | 1366 | int cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
| 1368 | for (cnt=0; cnt < QETH_CMD_BUFFER_NO; cnt++) |
| 1369 | qeth_release_buffer(channel,&channel->iob[cnt]); |
| 1370 | channel->buf_no = 0; |
| 1371 | channel->io_buf_no = 0; |
| 1372 | } |
| 1373 | |
| 1374 | /** |
| 1375 | * start IDX for read and write channel |
| 1376 | */ |
| 1377 | static int |
| 1378 | qeth_idx_activate_get_answer(struct qeth_channel *channel, |
| 1379 | void (*idx_reply_cb)(struct qeth_channel *, |
| 1380 | struct qeth_cmd_buffer *)) |
| 1381 | { |
| 1382 | struct qeth_cmd_buffer *iob; |
| 1383 | unsigned long flags; |
| 1384 | int rc; |
| 1385 | struct qeth_card *card; |
| 1386 | |
| 1387 | QETH_DBF_TEXT(setup, 2, "idxanswr"); |
| 1388 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 1389 | iob = qeth_get_buffer(channel); |
| 1390 | iob->callback = idx_reply_cb; |
| 1391 | memcpy(&channel->ccw, READ_CCW, sizeof(struct ccw1)); |
| 1392 | channel->ccw.count = QETH_BUFSIZE; |
| 1393 | channel->ccw.cda = (__u32) __pa(iob->data); |
| 1394 | |
| 1395 | wait_event(card->wait_q, |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1396 | atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | QETH_DBF_TEXT(setup, 6, "noirqpnd"); |
| 1398 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 1399 | rc = ccw_device_start(channel->ccwdev, |
| 1400 | &channel->ccw,(addr_t) iob, 0, 0); |
| 1401 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 1402 | |
| 1403 | if (rc) { |
| 1404 | PRINT_ERR("qeth: Error2 in activating channel rc=%d\n",rc); |
| 1405 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 1406 | atomic_set(&channel->irq_pending, 0); |
| 1407 | wake_up(&card->wait_q); |
| 1408 | return rc; |
| 1409 | } |
| 1410 | rc = wait_event_interruptible_timeout(card->wait_q, |
| 1411 | channel->state == CH_STATE_UP, QETH_TIMEOUT); |
| 1412 | if (rc == -ERESTARTSYS) |
| 1413 | return rc; |
| 1414 | if (channel->state != CH_STATE_UP){ |
| 1415 | rc = -ETIME; |
| 1416 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
| 1417 | qeth_clear_cmd_buffers(channel); |
| 1418 | } else |
| 1419 | rc = 0; |
| 1420 | return rc; |
| 1421 | } |
| 1422 | |
| 1423 | static int |
| 1424 | qeth_idx_activate_channel(struct qeth_channel *channel, |
| 1425 | void (*idx_reply_cb)(struct qeth_channel *, |
| 1426 | struct qeth_cmd_buffer *)) |
| 1427 | { |
| 1428 | struct qeth_card *card; |
| 1429 | struct qeth_cmd_buffer *iob; |
| 1430 | unsigned long flags; |
| 1431 | __u16 temp; |
| 1432 | int rc; |
| 1433 | |
| 1434 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 1435 | |
| 1436 | QETH_DBF_TEXT(setup, 2, "idxactch"); |
| 1437 | |
| 1438 | iob = qeth_get_buffer(channel); |
| 1439 | iob->callback = idx_reply_cb; |
| 1440 | memcpy(&channel->ccw, WRITE_CCW, sizeof(struct ccw1)); |
| 1441 | channel->ccw.count = IDX_ACTIVATE_SIZE; |
| 1442 | channel->ccw.cda = (__u32) __pa(iob->data); |
| 1443 | if (channel == &card->write) { |
| 1444 | memcpy(iob->data, IDX_ACTIVATE_WRITE, IDX_ACTIVATE_SIZE); |
| 1445 | memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data), |
| 1446 | &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH); |
| 1447 | card->seqno.trans_hdr++; |
| 1448 | } else { |
| 1449 | memcpy(iob->data, IDX_ACTIVATE_READ, IDX_ACTIVATE_SIZE); |
| 1450 | memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data), |
| 1451 | &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH); |
| 1452 | } |
| 1453 | memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data), |
| 1454 | &card->token.issuer_rm_w,QETH_MPC_TOKEN_LENGTH); |
| 1455 | memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob->data), |
| 1456 | &card->info.func_level,sizeof(__u16)); |
| 1457 | temp = raw_devno_from_bus_id(CARD_DDEV_ID(card)); |
| 1458 | memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob->data), &temp, 2); |
| 1459 | temp = (card->info.cula << 8) + card->info.unit_addr2; |
| 1460 | memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob->data), &temp, 2); |
| 1461 | |
| 1462 | wait_event(card->wait_q, |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1463 | atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | QETH_DBF_TEXT(setup, 6, "noirqpnd"); |
| 1465 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 1466 | rc = ccw_device_start(channel->ccwdev, |
| 1467 | &channel->ccw,(addr_t) iob, 0, 0); |
| 1468 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 1469 | |
| 1470 | if (rc) { |
| 1471 | PRINT_ERR("qeth: Error1 in activating channel. rc=%d\n",rc); |
| 1472 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 1473 | atomic_set(&channel->irq_pending, 0); |
| 1474 | wake_up(&card->wait_q); |
| 1475 | return rc; |
| 1476 | } |
| 1477 | rc = wait_event_interruptible_timeout(card->wait_q, |
| 1478 | channel->state == CH_STATE_ACTIVATING, QETH_TIMEOUT); |
| 1479 | if (rc == -ERESTARTSYS) |
| 1480 | return rc; |
| 1481 | if (channel->state != CH_STATE_ACTIVATING) { |
| 1482 | PRINT_WARN("qeth: IDX activate timed out!\n"); |
| 1483 | QETH_DBF_TEXT_(setup, 2, "2err%d", -ETIME); |
| 1484 | qeth_clear_cmd_buffers(channel); |
| 1485 | return -ETIME; |
| 1486 | } |
| 1487 | return qeth_idx_activate_get_answer(channel,idx_reply_cb); |
| 1488 | } |
| 1489 | |
| 1490 | static int |
| 1491 | qeth_peer_func_level(int level) |
| 1492 | { |
| 1493 | if ((level & 0xff) == 8) |
| 1494 | return (level & 0xff) + 0x400; |
| 1495 | if (((level >> 8) & 3) == 1) |
| 1496 | return (level & 0xff) + 0x200; |
| 1497 | return level; |
| 1498 | } |
| 1499 | |
| 1500 | static void |
| 1501 | qeth_idx_write_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob) |
| 1502 | { |
| 1503 | struct qeth_card *card; |
| 1504 | __u16 temp; |
| 1505 | |
| 1506 | QETH_DBF_TEXT(setup ,2, "idxwrcb"); |
| 1507 | |
| 1508 | if (channel->state == CH_STATE_DOWN) { |
| 1509 | channel->state = CH_STATE_ACTIVATING; |
| 1510 | goto out; |
| 1511 | } |
| 1512 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 1513 | |
| 1514 | if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) { |
| 1515 | PRINT_ERR("IDX_ACTIVATE on write channel device %s: negative " |
| 1516 | "reply\n", CARD_WDEV_ID(card)); |
| 1517 | goto out; |
| 1518 | } |
| 1519 | memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2); |
| 1520 | if ((temp & ~0x0100) != qeth_peer_func_level(card->info.func_level)) { |
| 1521 | PRINT_WARN("IDX_ACTIVATE on write channel device %s: " |
| 1522 | "function level mismatch " |
| 1523 | "(sent: 0x%x, received: 0x%x)\n", |
| 1524 | CARD_WDEV_ID(card), card->info.func_level, temp); |
| 1525 | goto out; |
| 1526 | } |
| 1527 | channel->state = CH_STATE_UP; |
| 1528 | out: |
| 1529 | qeth_release_buffer(channel, iob); |
| 1530 | } |
| 1531 | |
| 1532 | static int |
| 1533 | qeth_check_idx_response(unsigned char *buffer) |
| 1534 | { |
| 1535 | if (!buffer) |
| 1536 | return 0; |
| 1537 | |
| 1538 | QETH_DBF_HEX(control, 2, buffer, QETH_DBF_CONTROL_LEN); |
| 1539 | if ((buffer[2] & 0xc0) == 0xc0) { |
| 1540 | PRINT_WARN("received an IDX TERMINATE " |
| 1541 | "with cause code 0x%02x%s\n", |
| 1542 | buffer[4], |
| 1543 | ((buffer[4] == 0x22) ? |
| 1544 | " -- try another portname" : "")); |
| 1545 | QETH_DBF_TEXT(trace, 2, "ckidxres"); |
| 1546 | QETH_DBF_TEXT(trace, 2, " idxterm"); |
| 1547 | QETH_DBF_TEXT_(trace, 2, " rc%d", -EIO); |
| 1548 | return -EIO; |
| 1549 | } |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
| 1553 | static void |
| 1554 | qeth_idx_read_cb(struct qeth_channel *channel, struct qeth_cmd_buffer *iob) |
| 1555 | { |
| 1556 | struct qeth_card *card; |
| 1557 | __u16 temp; |
| 1558 | |
| 1559 | QETH_DBF_TEXT(setup , 2, "idxrdcb"); |
| 1560 | if (channel->state == CH_STATE_DOWN) { |
| 1561 | channel->state = CH_STATE_ACTIVATING; |
| 1562 | goto out; |
| 1563 | } |
| 1564 | |
| 1565 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 1566 | if (qeth_check_idx_response(iob->data)) { |
| 1567 | goto out; |
| 1568 | } |
| 1569 | if (!(QETH_IS_IDX_ACT_POS_REPLY(iob->data))) { |
| 1570 | PRINT_ERR("IDX_ACTIVATE on read channel device %s: negative " |
| 1571 | "reply\n", CARD_RDEV_ID(card)); |
| 1572 | goto out; |
| 1573 | } |
| 1574 | |
| 1575 | /** |
| 1576 | * temporary fix for microcode bug |
| 1577 | * to revert it,replace OR by AND |
| 1578 | */ |
| 1579 | if ( (!QETH_IDX_NO_PORTNAME_REQUIRED(iob->data)) || |
| 1580 | (card->info.type == QETH_CARD_TYPE_OSAE) ) |
| 1581 | card->info.portname_required = 1; |
| 1582 | |
| 1583 | memcpy(&temp, QETH_IDX_ACT_FUNC_LEVEL(iob->data), 2); |
| 1584 | if (temp != qeth_peer_func_level(card->info.func_level)) { |
| 1585 | PRINT_WARN("IDX_ACTIVATE on read channel device %s: function " |
| 1586 | "level mismatch (sent: 0x%x, received: 0x%x)\n", |
| 1587 | CARD_RDEV_ID(card), card->info.func_level, temp); |
| 1588 | goto out; |
| 1589 | } |
| 1590 | memcpy(&card->token.issuer_rm_r, |
| 1591 | QETH_IDX_ACT_ISSUER_RM_TOKEN(iob->data), |
| 1592 | QETH_MPC_TOKEN_LENGTH); |
| 1593 | memcpy(&card->info.mcl_level[0], |
| 1594 | QETH_IDX_REPLY_LEVEL(iob->data), QETH_MCL_LENGTH); |
| 1595 | channel->state = CH_STATE_UP; |
| 1596 | out: |
| 1597 | qeth_release_buffer(channel,iob); |
| 1598 | } |
| 1599 | |
| 1600 | static int |
| 1601 | qeth_issue_next_read(struct qeth_card *card) |
| 1602 | { |
| 1603 | int rc; |
| 1604 | struct qeth_cmd_buffer *iob; |
| 1605 | |
| 1606 | QETH_DBF_TEXT(trace,5,"issnxrd"); |
| 1607 | if (card->read.state != CH_STATE_UP) |
| 1608 | return -EIO; |
| 1609 | iob = qeth_get_buffer(&card->read); |
| 1610 | if (!iob) { |
| 1611 | PRINT_WARN("issue_next_read failed: no iob available!\n"); |
| 1612 | return -ENOMEM; |
| 1613 | } |
| 1614 | qeth_setup_ccw(&card->read, iob->data, QETH_BUFSIZE); |
| 1615 | wait_event(card->wait_q, |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1616 | atomic_cmpxchg(&card->read.irq_pending, 0, 1) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | QETH_DBF_TEXT(trace, 6, "noirqpnd"); |
| 1618 | rc = ccw_device_start(card->read.ccwdev, &card->read.ccw, |
| 1619 | (addr_t) iob, 0, 0); |
| 1620 | if (rc) { |
| 1621 | PRINT_ERR("Error in starting next read ccw! rc=%i\n", rc); |
| 1622 | atomic_set(&card->read.irq_pending, 0); |
| 1623 | qeth_schedule_recovery(card); |
| 1624 | wake_up(&card->wait_q); |
| 1625 | } |
| 1626 | return rc; |
| 1627 | } |
| 1628 | |
| 1629 | static struct qeth_reply * |
| 1630 | qeth_alloc_reply(struct qeth_card *card) |
| 1631 | { |
| 1632 | struct qeth_reply *reply; |
| 1633 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 1634 | reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | if (reply){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | atomic_set(&reply->refcnt, 1); |
| 1637 | reply->card = card; |
| 1638 | }; |
| 1639 | return reply; |
| 1640 | } |
| 1641 | |
| 1642 | static void |
| 1643 | qeth_get_reply(struct qeth_reply *reply) |
| 1644 | { |
| 1645 | WARN_ON(atomic_read(&reply->refcnt) <= 0); |
| 1646 | atomic_inc(&reply->refcnt); |
| 1647 | } |
| 1648 | |
| 1649 | static void |
| 1650 | qeth_put_reply(struct qeth_reply *reply) |
| 1651 | { |
| 1652 | WARN_ON(atomic_read(&reply->refcnt) <= 0); |
| 1653 | if (atomic_dec_and_test(&reply->refcnt)) |
| 1654 | kfree(reply); |
| 1655 | } |
| 1656 | |
| 1657 | static void |
| 1658 | qeth_cmd_timeout(unsigned long data) |
| 1659 | { |
| 1660 | struct qeth_reply *reply, *list_reply, *r; |
| 1661 | unsigned long flags; |
| 1662 | |
| 1663 | reply = (struct qeth_reply *) data; |
| 1664 | spin_lock_irqsave(&reply->card->lock, flags); |
| 1665 | list_for_each_entry_safe(list_reply, r, |
| 1666 | &reply->card->cmd_waiter_list, list) { |
| 1667 | if (reply == list_reply){ |
| 1668 | qeth_get_reply(reply); |
| 1669 | list_del_init(&reply->list); |
| 1670 | spin_unlock_irqrestore(&reply->card->lock, flags); |
| 1671 | reply->rc = -ETIME; |
| 1672 | reply->received = 1; |
| 1673 | wake_up(&reply->wait_q); |
| 1674 | qeth_put_reply(reply); |
| 1675 | return; |
| 1676 | } |
| 1677 | } |
| 1678 | spin_unlock_irqrestore(&reply->card->lock, flags); |
| 1679 | } |
| 1680 | |
Frank Pavlic | 66cc5d5 | 2006-02-07 17:04:38 +0100 | [diff] [blame] | 1681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | static struct qeth_ipa_cmd * |
| 1683 | qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob) |
| 1684 | { |
| 1685 | struct qeth_ipa_cmd *cmd = NULL; |
| 1686 | |
| 1687 | QETH_DBF_TEXT(trace,5,"chkipad"); |
| 1688 | if (IS_IPA(iob->data)){ |
| 1689 | cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data); |
| 1690 | if (IS_IPA_REPLY(cmd)) |
| 1691 | return cmd; |
| 1692 | else { |
| 1693 | switch (cmd->hdr.command) { |
| 1694 | case IPA_CMD_STOPLAN: |
| 1695 | PRINT_WARN("Link failure on %s (CHPID 0x%X) - " |
| 1696 | "there is a network problem or " |
| 1697 | "someone pulled the cable or " |
| 1698 | "disabled the port.\n", |
| 1699 | QETH_CARD_IFNAME(card), |
| 1700 | card->info.chpid); |
| 1701 | card->lan_online = 0; |
Frank Pavlic | 66cc5d5 | 2006-02-07 17:04:38 +0100 | [diff] [blame] | 1702 | if (card->dev && netif_carrier_ok(card->dev)) |
| 1703 | netif_carrier_off(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | return NULL; |
| 1705 | case IPA_CMD_STARTLAN: |
| 1706 | PRINT_INFO("Link reestablished on %s " |
| 1707 | "(CHPID 0x%X). Scheduling " |
| 1708 | "IP address reset.\n", |
| 1709 | QETH_CARD_IFNAME(card), |
| 1710 | card->info.chpid); |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 1711 | qeth_schedule_recovery(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | return NULL; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1713 | case IPA_CMD_MODCCID: |
| 1714 | return cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | case IPA_CMD_REGISTER_LOCAL_ADDR: |
| 1716 | QETH_DBF_TEXT(trace,3, "irla"); |
| 1717 | break; |
| 1718 | case IPA_CMD_UNREGISTER_LOCAL_ADDR: |
| 1719 | QETH_DBF_TEXT(trace,3, "urla"); |
| 1720 | break; |
| 1721 | default: |
| 1722 | PRINT_WARN("Received data is IPA " |
| 1723 | "but not a reply!\n"); |
| 1724 | break; |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | return cmd; |
| 1729 | } |
| 1730 | |
| 1731 | /** |
| 1732 | * wake all waiting ipa commands |
| 1733 | */ |
| 1734 | static void |
| 1735 | qeth_clear_ipacmd_list(struct qeth_card *card) |
| 1736 | { |
| 1737 | struct qeth_reply *reply, *r; |
| 1738 | unsigned long flags; |
| 1739 | |
| 1740 | QETH_DBF_TEXT(trace, 4, "clipalst"); |
| 1741 | |
| 1742 | spin_lock_irqsave(&card->lock, flags); |
| 1743 | list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) { |
| 1744 | qeth_get_reply(reply); |
| 1745 | reply->rc = -EIO; |
| 1746 | reply->received = 1; |
| 1747 | list_del_init(&reply->list); |
| 1748 | wake_up(&reply->wait_q); |
| 1749 | qeth_put_reply(reply); |
| 1750 | } |
| 1751 | spin_unlock_irqrestore(&card->lock, flags); |
| 1752 | } |
| 1753 | |
| 1754 | static void |
| 1755 | qeth_send_control_data_cb(struct qeth_channel *channel, |
| 1756 | struct qeth_cmd_buffer *iob) |
| 1757 | { |
| 1758 | struct qeth_card *card; |
| 1759 | struct qeth_reply *reply, *r; |
| 1760 | struct qeth_ipa_cmd *cmd; |
| 1761 | unsigned long flags; |
| 1762 | int keep_reply; |
| 1763 | |
| 1764 | QETH_DBF_TEXT(trace,4,"sndctlcb"); |
| 1765 | |
| 1766 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 1767 | if (qeth_check_idx_response(iob->data)) { |
| 1768 | qeth_clear_ipacmd_list(card); |
| 1769 | qeth_schedule_recovery(card); |
| 1770 | goto out; |
| 1771 | } |
| 1772 | |
| 1773 | cmd = qeth_check_ipa_data(card, iob); |
| 1774 | if ((cmd == NULL) && (card->state != CARD_STATE_DOWN)) |
| 1775 | goto out; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1776 | /*in case of OSN : check if cmd is set */ |
| 1777 | if (card->info.type == QETH_CARD_TYPE_OSN && |
| 1778 | cmd && |
| 1779 | cmd->hdr.command != IPA_CMD_STARTLAN && |
| 1780 | card->osn_info.assist_cb != NULL) { |
| 1781 | card->osn_info.assist_cb(card->dev, cmd); |
| 1782 | goto out; |
| 1783 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | |
| 1785 | spin_lock_irqsave(&card->lock, flags); |
| 1786 | list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) { |
| 1787 | if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) || |
| 1788 | ((cmd) && (reply->seqno == cmd->hdr.seqno))) { |
| 1789 | qeth_get_reply(reply); |
| 1790 | list_del_init(&reply->list); |
| 1791 | spin_unlock_irqrestore(&card->lock, flags); |
| 1792 | keep_reply = 0; |
| 1793 | if (reply->callback != NULL) { |
| 1794 | if (cmd) { |
| 1795 | reply->offset = (__u16)((char*)cmd - |
| 1796 | (char *)iob->data); |
| 1797 | keep_reply = reply->callback(card, |
| 1798 | reply, |
| 1799 | (unsigned long)cmd); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1800 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | keep_reply = reply->callback(card, |
| 1802 | reply, |
| 1803 | (unsigned long)iob); |
| 1804 | } |
| 1805 | if (cmd) |
| 1806 | reply->rc = (u16) cmd->hdr.return_code; |
| 1807 | else if (iob->rc) |
| 1808 | reply->rc = iob->rc; |
| 1809 | if (keep_reply) { |
| 1810 | spin_lock_irqsave(&card->lock, flags); |
| 1811 | list_add_tail(&reply->list, |
| 1812 | &card->cmd_waiter_list); |
| 1813 | spin_unlock_irqrestore(&card->lock, flags); |
| 1814 | } else { |
| 1815 | reply->received = 1; |
| 1816 | wake_up(&reply->wait_q); |
| 1817 | } |
| 1818 | qeth_put_reply(reply); |
| 1819 | goto out; |
| 1820 | } |
| 1821 | } |
| 1822 | spin_unlock_irqrestore(&card->lock, flags); |
| 1823 | out: |
| 1824 | memcpy(&card->seqno.pdu_hdr_ack, |
| 1825 | QETH_PDU_HEADER_SEQ_NO(iob->data), |
| 1826 | QETH_SEQ_NO_LENGTH); |
| 1827 | qeth_release_buffer(channel,iob); |
| 1828 | } |
| 1829 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1830 | static inline void |
| 1831 | qeth_prepare_control_data(struct qeth_card *card, int len, |
| 1832 | struct qeth_cmd_buffer *iob) |
| 1833 | { |
| 1834 | qeth_setup_ccw(&card->write,iob->data,len); |
| 1835 | iob->callback = qeth_release_buffer; |
| 1836 | |
| 1837 | memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data), |
| 1838 | &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH); |
| 1839 | card->seqno.trans_hdr++; |
| 1840 | memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data), |
| 1841 | &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH); |
| 1842 | card->seqno.pdu_hdr++; |
| 1843 | memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data), |
| 1844 | &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH); |
| 1845 | QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN); |
| 1846 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | static int |
| 1849 | qeth_send_control_data(struct qeth_card *card, int len, |
| 1850 | struct qeth_cmd_buffer *iob, |
| 1851 | int (*reply_cb) |
| 1852 | (struct qeth_card *, struct qeth_reply*, unsigned long), |
| 1853 | void *reply_param) |
| 1854 | |
| 1855 | { |
| 1856 | int rc; |
| 1857 | unsigned long flags; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1858 | struct qeth_reply *reply = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | struct timer_list timer; |
| 1860 | |
| 1861 | QETH_DBF_TEXT(trace, 2, "sendctl"); |
| 1862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | reply = qeth_alloc_reply(card); |
| 1864 | if (!reply) { |
| 1865 | PRINT_WARN("Could no alloc qeth_reply!\n"); |
| 1866 | return -ENOMEM; |
| 1867 | } |
| 1868 | reply->callback = reply_cb; |
| 1869 | reply->param = reply_param; |
| 1870 | if (card->state == CARD_STATE_DOWN) |
| 1871 | reply->seqno = QETH_IDX_COMMAND_SEQNO; |
| 1872 | else |
| 1873 | reply->seqno = card->seqno.ipa++; |
| 1874 | init_timer(&timer); |
| 1875 | timer.function = qeth_cmd_timeout; |
| 1876 | timer.data = (unsigned long) reply; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | init_waitqueue_head(&reply->wait_q); |
| 1878 | spin_lock_irqsave(&card->lock, flags); |
| 1879 | list_add_tail(&reply->list, &card->cmd_waiter_list); |
| 1880 | spin_unlock_irqrestore(&card->lock, flags); |
| 1881 | QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN); |
| 1882 | wait_event(card->wait_q, |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1883 | atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1884 | qeth_prepare_control_data(card, len, iob); |
| 1885 | if (IS_IPA(iob->data)) |
| 1886 | timer.expires = jiffies + QETH_IPA_TIMEOUT; |
| 1887 | else |
| 1888 | timer.expires = jiffies + QETH_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | QETH_DBF_TEXT(trace, 6, "noirqpnd"); |
| 1890 | spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1891 | rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, |
| 1892 | (addr_t) iob, 0, 0); |
| 1893 | spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1894 | if (rc){ |
| 1895 | PRINT_WARN("qeth_send_control_data: " |
| 1896 | "ccw_device_start rc = %i\n", rc); |
| 1897 | QETH_DBF_TEXT_(trace, 2, " err%d", rc); |
| 1898 | spin_lock_irqsave(&card->lock, flags); |
| 1899 | list_del_init(&reply->list); |
| 1900 | qeth_put_reply(reply); |
| 1901 | spin_unlock_irqrestore(&card->lock, flags); |
| 1902 | qeth_release_buffer(iob->channel, iob); |
| 1903 | atomic_set(&card->write.irq_pending, 0); |
| 1904 | wake_up(&card->wait_q); |
| 1905 | return rc; |
| 1906 | } |
| 1907 | add_timer(&timer); |
| 1908 | wait_event(reply->wait_q, reply->received); |
| 1909 | del_timer_sync(&timer); |
| 1910 | rc = reply->rc; |
| 1911 | qeth_put_reply(reply); |
| 1912 | return rc; |
| 1913 | } |
| 1914 | |
| 1915 | static int |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1916 | qeth_osn_send_control_data(struct qeth_card *card, int len, |
| 1917 | struct qeth_cmd_buffer *iob) |
| 1918 | { |
| 1919 | unsigned long flags; |
| 1920 | int rc = 0; |
| 1921 | |
| 1922 | QETH_DBF_TEXT(trace, 5, "osndctrd"); |
| 1923 | |
| 1924 | wait_event(card->wait_q, |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1925 | atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1926 | qeth_prepare_control_data(card, len, iob); |
| 1927 | QETH_DBF_TEXT(trace, 6, "osnoirqp"); |
| 1928 | spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1929 | rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, |
| 1930 | (addr_t) iob, 0, 0); |
| 1931 | spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1932 | if (rc){ |
| 1933 | PRINT_WARN("qeth_osn_send_control_data: " |
| 1934 | "ccw_device_start rc = %i\n", rc); |
| 1935 | QETH_DBF_TEXT_(trace, 2, " err%d", rc); |
| 1936 | qeth_release_buffer(iob->channel, iob); |
| 1937 | atomic_set(&card->write.irq_pending, 0); |
| 1938 | wake_up(&card->wait_q); |
| 1939 | } |
| 1940 | return rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1941 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1942 | |
| 1943 | static inline void |
| 1944 | qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 1945 | char prot_type) |
| 1946 | { |
| 1947 | memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE); |
| 1948 | memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1); |
| 1949 | memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data), |
| 1950 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 1951 | } |
| 1952 | |
| 1953 | static int |
| 1954 | qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 1955 | int data_len) |
| 1956 | { |
| 1957 | u16 s1, s2; |
| 1958 | |
Frank Pavlic | 4965e97 | 2005-12-13 08:22:30 +0100 | [diff] [blame] | 1959 | QETH_DBF_TEXT(trace,4,"osndipa"); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1960 | |
| 1961 | qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2); |
| 1962 | s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len); |
| 1963 | s2 = (u16)data_len; |
| 1964 | memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); |
| 1965 | memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); |
| 1966 | memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); |
| 1967 | memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); |
| 1968 | return qeth_osn_send_control_data(card, s1, iob); |
| 1969 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1970 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1971 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 1973 | int (*reply_cb) |
| 1974 | (struct qeth_card *,struct qeth_reply*, unsigned long), |
| 1975 | void *reply_param) |
| 1976 | { |
| 1977 | int rc; |
| 1978 | char prot_type; |
| 1979 | |
| 1980 | QETH_DBF_TEXT(trace,4,"sendipa"); |
| 1981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | if (card->options.layer2) |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1983 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 1984 | prot_type = QETH_PROT_OSN2; |
| 1985 | else |
| 1986 | prot_type = QETH_PROT_LAYER2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | else |
| 1988 | prot_type = QETH_PROT_TCPIP; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1989 | qeth_prepare_ipa_cmd(card,iob,prot_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob, |
| 1991 | reply_cb, reply_param); |
| 1992 | return rc; |
| 1993 | } |
| 1994 | |
| 1995 | |
| 1996 | static int |
| 1997 | qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 1998 | unsigned long data) |
| 1999 | { |
| 2000 | struct qeth_cmd_buffer *iob; |
| 2001 | |
| 2002 | QETH_DBF_TEXT(setup, 2, "cmenblcb"); |
| 2003 | |
| 2004 | iob = (struct qeth_cmd_buffer *) data; |
| 2005 | memcpy(&card->token.cm_filter_r, |
| 2006 | QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data), |
| 2007 | QETH_MPC_TOKEN_LENGTH); |
| 2008 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2009 | return 0; |
| 2010 | } |
| 2011 | |
| 2012 | static int |
| 2013 | qeth_cm_enable(struct qeth_card *card) |
| 2014 | { |
| 2015 | int rc; |
| 2016 | struct qeth_cmd_buffer *iob; |
| 2017 | |
| 2018 | QETH_DBF_TEXT(setup,2,"cmenable"); |
| 2019 | |
| 2020 | iob = qeth_wait_for_buffer(&card->write); |
| 2021 | memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE); |
| 2022 | memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data), |
| 2023 | &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH); |
| 2024 | memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data), |
| 2025 | &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH); |
| 2026 | |
| 2027 | rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob, |
| 2028 | qeth_cm_enable_cb, NULL); |
| 2029 | return rc; |
| 2030 | } |
| 2031 | |
| 2032 | static int |
| 2033 | qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 2034 | unsigned long data) |
| 2035 | { |
| 2036 | |
| 2037 | struct qeth_cmd_buffer *iob; |
| 2038 | |
| 2039 | QETH_DBF_TEXT(setup, 2, "cmsetpcb"); |
| 2040 | |
| 2041 | iob = (struct qeth_cmd_buffer *) data; |
| 2042 | memcpy(&card->token.cm_connection_r, |
| 2043 | QETH_CM_SETUP_RESP_DEST_ADDR(iob->data), |
| 2044 | QETH_MPC_TOKEN_LENGTH); |
| 2045 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2046 | return 0; |
| 2047 | } |
| 2048 | |
| 2049 | static int |
| 2050 | qeth_cm_setup(struct qeth_card *card) |
| 2051 | { |
| 2052 | int rc; |
| 2053 | struct qeth_cmd_buffer *iob; |
| 2054 | |
| 2055 | QETH_DBF_TEXT(setup,2,"cmsetup"); |
| 2056 | |
| 2057 | iob = qeth_wait_for_buffer(&card->write); |
| 2058 | memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE); |
| 2059 | memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data), |
| 2060 | &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH); |
| 2061 | memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data), |
| 2062 | &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH); |
| 2063 | memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data), |
| 2064 | &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH); |
| 2065 | rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob, |
| 2066 | qeth_cm_setup_cb, NULL); |
| 2067 | return rc; |
| 2068 | |
| 2069 | } |
| 2070 | |
| 2071 | static int |
| 2072 | qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 2073 | unsigned long data) |
| 2074 | { |
| 2075 | |
| 2076 | __u16 mtu, framesize; |
| 2077 | __u16 len; |
| 2078 | __u8 link_type; |
| 2079 | struct qeth_cmd_buffer *iob; |
| 2080 | |
| 2081 | QETH_DBF_TEXT(setup, 2, "ulpenacb"); |
| 2082 | |
| 2083 | iob = (struct qeth_cmd_buffer *) data; |
| 2084 | memcpy(&card->token.ulp_filter_r, |
| 2085 | QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data), |
| 2086 | QETH_MPC_TOKEN_LENGTH); |
| 2087 | if (qeth_get_mtu_out_of_mpc(card->info.type)) { |
| 2088 | memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2); |
| 2089 | mtu = qeth_get_mtu_outof_framesize(framesize); |
| 2090 | if (!mtu) { |
| 2091 | iob->rc = -EINVAL; |
| 2092 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2093 | return 0; |
| 2094 | } |
| 2095 | card->info.max_mtu = mtu; |
| 2096 | card->info.initial_mtu = mtu; |
| 2097 | card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE; |
| 2098 | } else { |
| 2099 | card->info.initial_mtu = qeth_get_initial_mtu_for_card(card); |
| 2100 | card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type); |
| 2101 | card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT; |
| 2102 | } |
| 2103 | |
| 2104 | memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2); |
| 2105 | if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) { |
| 2106 | memcpy(&link_type, |
| 2107 | QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1); |
| 2108 | card->info.link_type = link_type; |
| 2109 | } else |
| 2110 | card->info.link_type = 0; |
| 2111 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2112 | return 0; |
| 2113 | } |
| 2114 | |
| 2115 | static int |
| 2116 | qeth_ulp_enable(struct qeth_card *card) |
| 2117 | { |
| 2118 | int rc; |
| 2119 | char prot_type; |
| 2120 | struct qeth_cmd_buffer *iob; |
| 2121 | |
| 2122 | /*FIXME: trace view callbacks*/ |
| 2123 | QETH_DBF_TEXT(setup,2,"ulpenabl"); |
| 2124 | |
| 2125 | iob = qeth_wait_for_buffer(&card->write); |
| 2126 | memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE); |
| 2127 | |
| 2128 | *(QETH_ULP_ENABLE_LINKNUM(iob->data)) = |
| 2129 | (__u8) card->info.portno; |
| 2130 | if (card->options.layer2) |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2131 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 2132 | prot_type = QETH_PROT_OSN2; |
| 2133 | else |
| 2134 | prot_type = QETH_PROT_LAYER2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | else |
| 2136 | prot_type = QETH_PROT_TCPIP; |
| 2137 | |
| 2138 | memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1); |
| 2139 | memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data), |
| 2140 | &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 2141 | memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data), |
| 2142 | &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH); |
| 2143 | memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data), |
| 2144 | card->info.portname, 9); |
| 2145 | rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob, |
| 2146 | qeth_ulp_enable_cb, NULL); |
| 2147 | return rc; |
| 2148 | |
| 2149 | } |
| 2150 | |
| 2151 | static inline __u16 |
| 2152 | __raw_devno_from_bus_id(char *id) |
| 2153 | { |
| 2154 | id += (strlen(id) - 4); |
| 2155 | return (__u16) simple_strtoul(id, &id, 16); |
| 2156 | } |
| 2157 | |
| 2158 | static int |
| 2159 | qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 2160 | unsigned long data) |
| 2161 | { |
| 2162 | struct qeth_cmd_buffer *iob; |
| 2163 | |
| 2164 | QETH_DBF_TEXT(setup, 2, "ulpstpcb"); |
| 2165 | |
| 2166 | iob = (struct qeth_cmd_buffer *) data; |
| 2167 | memcpy(&card->token.ulp_connection_r, |
| 2168 | QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data), |
| 2169 | QETH_MPC_TOKEN_LENGTH); |
| 2170 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2171 | return 0; |
| 2172 | } |
| 2173 | |
| 2174 | static int |
| 2175 | qeth_ulp_setup(struct qeth_card *card) |
| 2176 | { |
| 2177 | int rc; |
| 2178 | __u16 temp; |
| 2179 | struct qeth_cmd_buffer *iob; |
| 2180 | |
| 2181 | QETH_DBF_TEXT(setup,2,"ulpsetup"); |
| 2182 | |
| 2183 | iob = qeth_wait_for_buffer(&card->write); |
| 2184 | memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE); |
| 2185 | |
| 2186 | memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data), |
| 2187 | &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 2188 | memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data), |
| 2189 | &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH); |
| 2190 | memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data), |
| 2191 | &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH); |
| 2192 | |
| 2193 | temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card)); |
| 2194 | memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2); |
| 2195 | temp = (card->info.cula << 8) + card->info.unit_addr2; |
| 2196 | memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2); |
| 2197 | rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob, |
| 2198 | qeth_ulp_setup_cb, NULL); |
| 2199 | return rc; |
| 2200 | } |
| 2201 | |
| 2202 | static inline int |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2203 | qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error, |
| 2204 | unsigned int siga_error, const char *dbftext) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | if (qdio_error || siga_error) { |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2207 | QETH_DBF_TEXT(trace, 2, dbftext); |
| 2208 | QETH_DBF_TEXT(qerr, 2, dbftext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | QETH_DBF_TEXT_(qerr, 2, " F15=%02X", |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2210 | buf->element[15].flags & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | QETH_DBF_TEXT_(qerr, 2, " F14=%02X", |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2212 | buf->element[14].flags & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error); |
| 2214 | QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error); |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2215 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | } |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2217 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | static inline struct sk_buff * |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2221 | qeth_get_skb(unsigned int length, struct qeth_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | { |
| 2223 | struct sk_buff* skb; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2224 | int add_len; |
| 2225 | |
| 2226 | add_len = 0; |
| 2227 | if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN) |
| 2228 | add_len = sizeof(struct qeth_hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | #ifdef CONFIG_QETH_VLAN |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2230 | else |
| 2231 | add_len = VLAN_HLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | #endif |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2233 | skb = dev_alloc_skb(length + add_len); |
| 2234 | if (skb && add_len) |
| 2235 | skb_reserve(skb, add_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | return skb; |
| 2237 | } |
| 2238 | |
| 2239 | static inline struct sk_buff * |
| 2240 | qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer, |
| 2241 | struct qdio_buffer_element **__element, int *__offset, |
| 2242 | struct qeth_hdr **hdr) |
| 2243 | { |
| 2244 | struct qdio_buffer_element *element = *__element; |
| 2245 | int offset = *__offset; |
| 2246 | struct sk_buff *skb = NULL; |
| 2247 | int skb_len; |
| 2248 | void *data_ptr; |
| 2249 | int data_len; |
| 2250 | |
| 2251 | QETH_DBF_TEXT(trace,6,"nextskb"); |
| 2252 | /* qeth_hdr must not cross element boundaries */ |
| 2253 | if (element->length < offset + sizeof(struct qeth_hdr)){ |
| 2254 | if (qeth_is_last_sbale(element)) |
| 2255 | return NULL; |
| 2256 | element++; |
| 2257 | offset = 0; |
| 2258 | if (element->length < sizeof(struct qeth_hdr)) |
| 2259 | return NULL; |
| 2260 | } |
| 2261 | *hdr = element->addr + offset; |
| 2262 | |
| 2263 | offset += sizeof(struct qeth_hdr); |
| 2264 | if (card->options.layer2) |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2265 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 2266 | skb_len = (*hdr)->hdr.osn.pdu_length; |
| 2267 | else |
| 2268 | skb_len = (*hdr)->hdr.l2.pkt_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | else |
| 2270 | skb_len = (*hdr)->hdr.l3.length; |
| 2271 | |
| 2272 | if (!skb_len) |
| 2273 | return NULL; |
| 2274 | if (card->options.fake_ll){ |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2275 | if(card->dev->type == ARPHRD_IEEE802_TR){ |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2276 | if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR, *hdr))) |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2277 | goto no_mem; |
| 2278 | skb_reserve(skb,QETH_FAKE_LL_LEN_TR); |
| 2279 | } else { |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2280 | if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH, *hdr))) |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2281 | goto no_mem; |
| 2282 | skb_reserve(skb,QETH_FAKE_LL_LEN_ETH); |
| 2283 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2284 | } else if (!(skb = qeth_get_skb(skb_len, *hdr))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | goto no_mem; |
| 2286 | data_ptr = element->addr + offset; |
| 2287 | while (skb_len) { |
| 2288 | data_len = min(skb_len, (int)(element->length - offset)); |
| 2289 | if (data_len) |
| 2290 | memcpy(skb_put(skb, data_len), data_ptr, data_len); |
| 2291 | skb_len -= data_len; |
| 2292 | if (skb_len){ |
| 2293 | if (qeth_is_last_sbale(element)){ |
| 2294 | QETH_DBF_TEXT(trace,4,"unexeob"); |
| 2295 | QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card)); |
| 2296 | QETH_DBF_TEXT(qerr,2,"unexeob"); |
| 2297 | QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card)); |
| 2298 | QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer)); |
| 2299 | dev_kfree_skb_any(skb); |
| 2300 | card->stats.rx_errors++; |
| 2301 | return NULL; |
| 2302 | } |
| 2303 | element++; |
| 2304 | offset = 0; |
| 2305 | data_ptr = element->addr; |
| 2306 | } else { |
| 2307 | offset += data_len; |
| 2308 | } |
| 2309 | } |
| 2310 | *__element = element; |
| 2311 | *__offset = offset; |
| 2312 | return skb; |
| 2313 | no_mem: |
| 2314 | if (net_ratelimit()){ |
| 2315 | PRINT_WARN("No memory for packet received on %s.\n", |
| 2316 | QETH_CARD_IFNAME(card)); |
| 2317 | QETH_DBF_TEXT(trace,2,"noskbmem"); |
| 2318 | QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card)); |
| 2319 | } |
| 2320 | card->stats.rx_dropped++; |
| 2321 | return NULL; |
| 2322 | } |
| 2323 | |
Alexey Dobriyan | ab61148 | 2005-07-12 12:08:43 -0700 | [diff] [blame] | 2324 | static inline __be16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | qeth_type_trans(struct sk_buff *skb, struct net_device *dev) |
| 2326 | { |
| 2327 | struct qeth_card *card; |
| 2328 | struct ethhdr *eth; |
| 2329 | |
| 2330 | QETH_DBF_TEXT(trace,6,"typtrans"); |
| 2331 | |
| 2332 | card = (struct qeth_card *)dev->priv; |
| 2333 | #ifdef CONFIG_TR |
| 2334 | if ((card->info.link_type == QETH_LINK_TYPE_HSTR) || |
| 2335 | (card->info.link_type == QETH_LINK_TYPE_LANE_TR)) |
| 2336 | return tr_type_trans(skb,dev); |
| 2337 | #endif /* CONFIG_TR */ |
| 2338 | skb->mac.raw = skb->data; |
| 2339 | skb_pull(skb, ETH_HLEN ); |
| 2340 | eth = eth_hdr(skb); |
| 2341 | |
| 2342 | if (*eth->h_dest & 1) { |
| 2343 | if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0) |
| 2344 | skb->pkt_type = PACKET_BROADCAST; |
| 2345 | else |
| 2346 | skb->pkt_type = PACKET_MULTICAST; |
| 2347 | } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN)) |
| 2348 | skb->pkt_type = PACKET_OTHERHOST; |
| 2349 | |
| 2350 | if (ntohs(eth->h_proto) >= 1536) |
| 2351 | return eth->h_proto; |
| 2352 | if (*(unsigned short *) (skb->data) == 0xFFFF) |
| 2353 | return htons(ETH_P_802_3); |
| 2354 | return htons(ETH_P_802_2); |
| 2355 | } |
| 2356 | |
| 2357 | static inline void |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2358 | qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb, |
| 2359 | struct qeth_hdr *hdr) |
| 2360 | { |
| 2361 | struct trh_hdr *fake_hdr; |
| 2362 | struct trllc *fake_llc; |
| 2363 | struct iphdr *ip_hdr; |
| 2364 | |
| 2365 | QETH_DBF_TEXT(trace,5,"skbfktr"); |
| 2366 | skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_TR; |
| 2367 | /* this is a fake ethernet header */ |
| 2368 | fake_hdr = (struct trh_hdr *) skb->mac.raw; |
| 2369 | |
| 2370 | /* the destination MAC address */ |
| 2371 | switch (skb->pkt_type){ |
| 2372 | case PACKET_MULTICAST: |
| 2373 | switch (skb->protocol){ |
| 2374 | #ifdef CONFIG_QETH_IPV6 |
| 2375 | case __constant_htons(ETH_P_IPV6): |
| 2376 | ndisc_mc_map((struct in6_addr *) |
| 2377 | skb->data + QETH_FAKE_LL_V6_ADDR_POS, |
| 2378 | fake_hdr->daddr, card->dev, 0); |
| 2379 | break; |
| 2380 | #endif /* CONFIG_QETH_IPV6 */ |
| 2381 | case __constant_htons(ETH_P_IP): |
| 2382 | ip_hdr = (struct iphdr *)skb->data; |
| 2383 | ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr); |
| 2384 | break; |
| 2385 | default: |
| 2386 | memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN); |
| 2387 | } |
| 2388 | break; |
| 2389 | case PACKET_BROADCAST: |
| 2390 | memset(fake_hdr->daddr, 0xff, TR_ALEN); |
| 2391 | break; |
| 2392 | default: |
| 2393 | memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN); |
| 2394 | } |
| 2395 | /* the source MAC address */ |
| 2396 | if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR) |
| 2397 | memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN); |
| 2398 | else |
| 2399 | memset(fake_hdr->saddr, 0, TR_ALEN); |
| 2400 | fake_hdr->rcf=0; |
| 2401 | fake_llc = (struct trllc*)&(fake_hdr->rcf); |
| 2402 | fake_llc->dsap = EXTENDED_SAP; |
| 2403 | fake_llc->ssap = EXTENDED_SAP; |
| 2404 | fake_llc->llc = UI_CMD; |
| 2405 | fake_llc->protid[0] = 0; |
| 2406 | fake_llc->protid[1] = 0; |
| 2407 | fake_llc->protid[2] = 0; |
| 2408 | fake_llc->ethertype = ETH_P_IP; |
| 2409 | } |
| 2410 | |
| 2411 | static inline void |
| 2412 | qeth_rebuild_skb_fake_ll_eth(struct qeth_card *card, struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | struct qeth_hdr *hdr) |
| 2414 | { |
| 2415 | struct ethhdr *fake_hdr; |
| 2416 | struct iphdr *ip_hdr; |
| 2417 | |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2418 | QETH_DBF_TEXT(trace,5,"skbfketh"); |
| 2419 | skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_ETH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | /* this is a fake ethernet header */ |
| 2421 | fake_hdr = (struct ethhdr *) skb->mac.raw; |
| 2422 | |
| 2423 | /* the destination MAC address */ |
| 2424 | switch (skb->pkt_type){ |
| 2425 | case PACKET_MULTICAST: |
| 2426 | switch (skb->protocol){ |
| 2427 | #ifdef CONFIG_QETH_IPV6 |
| 2428 | case __constant_htons(ETH_P_IPV6): |
| 2429 | ndisc_mc_map((struct in6_addr *) |
| 2430 | skb->data + QETH_FAKE_LL_V6_ADDR_POS, |
| 2431 | fake_hdr->h_dest, card->dev, 0); |
| 2432 | break; |
| 2433 | #endif /* CONFIG_QETH_IPV6 */ |
| 2434 | case __constant_htons(ETH_P_IP): |
| 2435 | ip_hdr = (struct iphdr *)skb->data; |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2436 | ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | break; |
| 2438 | default: |
| 2439 | memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN); |
| 2440 | } |
| 2441 | break; |
| 2442 | case PACKET_BROADCAST: |
| 2443 | memset(fake_hdr->h_dest, 0xff, ETH_ALEN); |
| 2444 | break; |
| 2445 | default: |
| 2446 | memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN); |
| 2447 | } |
| 2448 | /* the source MAC address */ |
| 2449 | if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR) |
| 2450 | memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN); |
| 2451 | else |
| 2452 | memset(fake_hdr->h_source, 0, ETH_ALEN); |
| 2453 | /* the protocol */ |
| 2454 | fake_hdr->h_proto = skb->protocol; |
| 2455 | } |
| 2456 | |
| 2457 | static inline void |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2458 | qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb, |
| 2459 | struct qeth_hdr *hdr) |
| 2460 | { |
| 2461 | if (card->dev->type == ARPHRD_IEEE802_TR) |
| 2462 | qeth_rebuild_skb_fake_ll_tr(card, skb, hdr); |
| 2463 | else |
| 2464 | qeth_rebuild_skb_fake_ll_eth(card, skb, hdr); |
| 2465 | } |
| 2466 | |
| 2467 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | qeth_rebuild_skb_vlan(struct qeth_card *card, struct sk_buff *skb, |
| 2469 | struct qeth_hdr *hdr) |
| 2470 | { |
| 2471 | #ifdef CONFIG_QETH_VLAN |
| 2472 | u16 *vlan_tag; |
| 2473 | |
| 2474 | if (hdr->hdr.l3.ext_flags & |
| 2475 | (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) { |
| 2476 | vlan_tag = (u16 *) skb_push(skb, VLAN_HLEN); |
| 2477 | *vlan_tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)? |
| 2478 | hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]); |
| 2479 | *(vlan_tag + 1) = skb->protocol; |
| 2480 | skb->protocol = __constant_htons(ETH_P_8021Q); |
| 2481 | } |
| 2482 | #endif /* CONFIG_QETH_VLAN */ |
| 2483 | } |
| 2484 | |
| 2485 | static inline __u16 |
| 2486 | qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, |
| 2487 | struct qeth_hdr *hdr) |
| 2488 | { |
| 2489 | unsigned short vlan_id = 0; |
| 2490 | #ifdef CONFIG_QETH_VLAN |
| 2491 | struct vlan_hdr *vhdr; |
| 2492 | #endif |
| 2493 | |
| 2494 | skb->pkt_type = PACKET_HOST; |
| 2495 | skb->protocol = qeth_type_trans(skb, skb->dev); |
| 2496 | if (card->options.checksum_type == NO_CHECKSUMMING) |
| 2497 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2498 | else |
| 2499 | skb->ip_summed = CHECKSUM_NONE; |
| 2500 | #ifdef CONFIG_QETH_VLAN |
| 2501 | if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) { |
| 2502 | vhdr = (struct vlan_hdr *) skb->data; |
| 2503 | skb->protocol = |
| 2504 | __constant_htons(vhdr->h_vlan_encapsulated_proto); |
| 2505 | vlan_id = hdr->hdr.l2.vlan_id; |
| 2506 | skb_pull(skb, VLAN_HLEN); |
| 2507 | } |
| 2508 | #endif |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 2509 | *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | return vlan_id; |
| 2511 | } |
| 2512 | |
| 2513 | static inline void |
| 2514 | qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, |
| 2515 | struct qeth_hdr *hdr) |
| 2516 | { |
| 2517 | #ifdef CONFIG_QETH_IPV6 |
| 2518 | if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) { |
| 2519 | skb->pkt_type = PACKET_HOST; |
| 2520 | skb->protocol = qeth_type_trans(skb, card->dev); |
| 2521 | return; |
| 2522 | } |
| 2523 | #endif /* CONFIG_QETH_IPV6 */ |
| 2524 | skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 : |
| 2525 | ETH_P_IP); |
| 2526 | switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){ |
| 2527 | case QETH_CAST_UNICAST: |
| 2528 | skb->pkt_type = PACKET_HOST; |
| 2529 | break; |
| 2530 | case QETH_CAST_MULTICAST: |
| 2531 | skb->pkt_type = PACKET_MULTICAST; |
| 2532 | card->stats.multicast++; |
| 2533 | break; |
| 2534 | case QETH_CAST_BROADCAST: |
| 2535 | skb->pkt_type = PACKET_BROADCAST; |
| 2536 | card->stats.multicast++; |
| 2537 | break; |
| 2538 | case QETH_CAST_ANYCAST: |
| 2539 | case QETH_CAST_NOCAST: |
| 2540 | default: |
| 2541 | skb->pkt_type = PACKET_HOST; |
| 2542 | } |
| 2543 | qeth_rebuild_skb_vlan(card, skb, hdr); |
| 2544 | if (card->options.fake_ll) |
| 2545 | qeth_rebuild_skb_fake_ll(card, skb, hdr); |
| 2546 | else |
| 2547 | skb->mac.raw = skb->data; |
| 2548 | skb->ip_summed = card->options.checksum_type; |
| 2549 | if (card->options.checksum_type == HW_CHECKSUMMING){ |
| 2550 | if ( (hdr->hdr.l3.ext_flags & |
| 2551 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 2552 | QETH_HDR_EXT_CSUM_TRANSP_REQ)) == |
| 2553 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 2554 | QETH_HDR_EXT_CSUM_TRANSP_REQ) ) |
| 2555 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2556 | else |
| 2557 | skb->ip_summed = SW_CHECKSUMMING; |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | static inline void |
| 2562 | qeth_process_inbound_buffer(struct qeth_card *card, |
| 2563 | struct qeth_qdio_buffer *buf, int index) |
| 2564 | { |
| 2565 | struct qdio_buffer_element *element; |
| 2566 | struct sk_buff *skb; |
| 2567 | struct qeth_hdr *hdr; |
| 2568 | int offset; |
| 2569 | int rxrc; |
| 2570 | __u16 vlan_tag = 0; |
| 2571 | |
| 2572 | /* get first element of current buffer */ |
| 2573 | element = (struct qdio_buffer_element *)&buf->buffer->element[0]; |
| 2574 | offset = 0; |
| 2575 | #ifdef CONFIG_QETH_PERF_STATS |
| 2576 | card->perf_stats.bufs_rec++; |
| 2577 | #endif |
| 2578 | while((skb = qeth_get_next_skb(card, buf->buffer, &element, |
| 2579 | &offset, &hdr))) { |
| 2580 | skb->dev = card->dev; |
| 2581 | if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2) |
| 2582 | vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2583 | else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | qeth_rebuild_skb(card, skb, hdr); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2585 | else { /*in case of OSN*/ |
| 2586 | skb_push(skb, sizeof(struct qeth_hdr)); |
| 2587 | memcpy(skb->data, hdr, sizeof(struct qeth_hdr)); |
| 2588 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | /* is device UP ? */ |
| 2590 | if (!(card->dev->flags & IFF_UP)){ |
| 2591 | dev_kfree_skb_any(skb); |
| 2592 | continue; |
| 2593 | } |
| 2594 | #ifdef CONFIG_QETH_VLAN |
| 2595 | if (vlan_tag) |
| 2596 | vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag); |
| 2597 | else |
| 2598 | #endif |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2599 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 2600 | rxrc = card->osn_info.data_cb(skb); |
| 2601 | else |
| 2602 | rxrc = netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | card->dev->last_rx = jiffies; |
| 2604 | card->stats.rx_packets++; |
| 2605 | card->stats.rx_bytes += skb->len; |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | static inline struct qeth_buffer_pool_entry * |
| 2610 | qeth_get_buffer_pool_entry(struct qeth_card *card) |
| 2611 | { |
| 2612 | struct qeth_buffer_pool_entry *entry; |
| 2613 | |
| 2614 | QETH_DBF_TEXT(trace, 6, "gtbfplen"); |
| 2615 | if (!list_empty(&card->qdio.in_buf_pool.entry_list)) { |
| 2616 | entry = list_entry(card->qdio.in_buf_pool.entry_list.next, |
| 2617 | struct qeth_buffer_pool_entry, list); |
| 2618 | list_del_init(&entry->list); |
| 2619 | return entry; |
| 2620 | } |
| 2621 | return NULL; |
| 2622 | } |
| 2623 | |
| 2624 | static inline void |
| 2625 | qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf) |
| 2626 | { |
| 2627 | struct qeth_buffer_pool_entry *pool_entry; |
| 2628 | int i; |
| 2629 | |
| 2630 | pool_entry = qeth_get_buffer_pool_entry(card); |
| 2631 | /* |
| 2632 | * since the buffer is accessed only from the input_tasklet |
| 2633 | * there shouldn't be a need to synchronize; also, since we use |
| 2634 | * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off |
| 2635 | * buffers |
| 2636 | */ |
| 2637 | BUG_ON(!pool_entry); |
| 2638 | |
| 2639 | buf->pool_entry = pool_entry; |
| 2640 | for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){ |
| 2641 | buf->buffer->element[i].length = PAGE_SIZE; |
| 2642 | buf->buffer->element[i].addr = pool_entry->elements[i]; |
| 2643 | if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1) |
| 2644 | buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY; |
| 2645 | else |
| 2646 | buf->buffer->element[i].flags = 0; |
| 2647 | } |
| 2648 | buf->state = QETH_QDIO_BUF_EMPTY; |
| 2649 | } |
| 2650 | |
| 2651 | static inline void |
| 2652 | qeth_clear_output_buffer(struct qeth_qdio_out_q *queue, |
| 2653 | struct qeth_qdio_out_buffer *buf) |
| 2654 | { |
| 2655 | int i; |
| 2656 | struct sk_buff *skb; |
| 2657 | |
| 2658 | /* is PCI flag set on buffer? */ |
| 2659 | if (buf->buffer->element[0].flags & 0x40) |
| 2660 | atomic_dec(&queue->set_pci_flags_count); |
| 2661 | |
| 2662 | while ((skb = skb_dequeue(&buf->skb_list))){ |
| 2663 | atomic_dec(&skb->users); |
| 2664 | dev_kfree_skb_any(skb); |
| 2665 | } |
| 2666 | qeth_eddp_buf_release_contexts(buf); |
| 2667 | for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){ |
| 2668 | buf->buffer->element[i].length = 0; |
| 2669 | buf->buffer->element[i].addr = NULL; |
| 2670 | buf->buffer->element[i].flags = 0; |
| 2671 | } |
| 2672 | buf->next_element_to_fill = 0; |
| 2673 | atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY); |
| 2674 | } |
| 2675 | |
| 2676 | static inline void |
| 2677 | qeth_queue_input_buffer(struct qeth_card *card, int index) |
| 2678 | { |
| 2679 | struct qeth_qdio_q *queue = card->qdio.in_q; |
| 2680 | int count; |
| 2681 | int i; |
| 2682 | int rc; |
| 2683 | |
| 2684 | QETH_DBF_TEXT(trace,6,"queinbuf"); |
| 2685 | count = (index < queue->next_buf_to_init)? |
| 2686 | card->qdio.in_buf_pool.buf_count - |
| 2687 | (queue->next_buf_to_init - index) : |
| 2688 | card->qdio.in_buf_pool.buf_count - |
| 2689 | (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index); |
| 2690 | /* only requeue at a certain threshold to avoid SIGAs */ |
| 2691 | if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){ |
| 2692 | for (i = queue->next_buf_to_init; |
| 2693 | i < queue->next_buf_to_init + count; ++i) |
| 2694 | qeth_init_input_buffer(card, |
| 2695 | &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]); |
| 2696 | /* |
| 2697 | * according to old code it should be avoided to requeue all |
| 2698 | * 128 buffers in order to benefit from PCI avoidance. |
| 2699 | * this function keeps at least one buffer (the buffer at |
| 2700 | * 'index') un-requeued -> this buffer is the first buffer that |
| 2701 | * will be requeued the next time |
| 2702 | */ |
| 2703 | #ifdef CONFIG_QETH_PERF_STATS |
| 2704 | card->perf_stats.inbound_do_qdio_cnt++; |
| 2705 | card->perf_stats.inbound_do_qdio_start_time = qeth_get_micros(); |
| 2706 | #endif |
| 2707 | rc = do_QDIO(CARD_DDEV(card), |
| 2708 | QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT, |
| 2709 | 0, queue->next_buf_to_init, count, NULL); |
| 2710 | #ifdef CONFIG_QETH_PERF_STATS |
| 2711 | card->perf_stats.inbound_do_qdio_time += qeth_get_micros() - |
| 2712 | card->perf_stats.inbound_do_qdio_start_time; |
| 2713 | #endif |
| 2714 | if (rc){ |
| 2715 | PRINT_WARN("qeth_queue_input_buffer's do_QDIO " |
| 2716 | "return %i (device %s).\n", |
| 2717 | rc, CARD_DDEV_ID(card)); |
| 2718 | QETH_DBF_TEXT(trace,2,"qinberr"); |
| 2719 | QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card)); |
| 2720 | } |
| 2721 | queue->next_buf_to_init = (queue->next_buf_to_init + count) % |
| 2722 | QDIO_MAX_BUFFERS_PER_Q; |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | static inline void |
| 2727 | qeth_put_buffer_pool_entry(struct qeth_card *card, |
| 2728 | struct qeth_buffer_pool_entry *entry) |
| 2729 | { |
| 2730 | QETH_DBF_TEXT(trace, 6, "ptbfplen"); |
| 2731 | list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list); |
| 2732 | } |
| 2733 | |
| 2734 | static void |
| 2735 | qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status, |
| 2736 | unsigned int qdio_err, unsigned int siga_err, |
| 2737 | unsigned int queue, int first_element, int count, |
| 2738 | unsigned long card_ptr) |
| 2739 | { |
| 2740 | struct net_device *net_dev; |
| 2741 | struct qeth_card *card; |
| 2742 | struct qeth_qdio_buffer *buffer; |
| 2743 | int index; |
| 2744 | int i; |
| 2745 | |
| 2746 | QETH_DBF_TEXT(trace, 6, "qdinput"); |
| 2747 | card = (struct qeth_card *) card_ptr; |
| 2748 | net_dev = card->dev; |
| 2749 | #ifdef CONFIG_QETH_PERF_STATS |
| 2750 | card->perf_stats.inbound_cnt++; |
| 2751 | card->perf_stats.inbound_start_time = qeth_get_micros(); |
| 2752 | #endif |
| 2753 | if (status & QDIO_STATUS_LOOK_FOR_ERROR) { |
| 2754 | if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){ |
| 2755 | QETH_DBF_TEXT(trace, 1,"qdinchk"); |
| 2756 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2757 | QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count); |
| 2758 | QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status); |
| 2759 | qeth_schedule_recovery(card); |
| 2760 | return; |
| 2761 | } |
| 2762 | } |
| 2763 | for (i = first_element; i < (first_element + count); ++i) { |
| 2764 | index = i % QDIO_MAX_BUFFERS_PER_Q; |
| 2765 | buffer = &card->qdio.in_q->bufs[index]; |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2766 | if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) && |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2767 | qeth_check_qdio_errors(buffer->buffer, |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2768 | qdio_err, siga_err,"qinerr"))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | qeth_process_inbound_buffer(card, buffer, index); |
| 2770 | /* clear buffer and give back to hardware */ |
| 2771 | qeth_put_buffer_pool_entry(card, buffer->pool_entry); |
| 2772 | qeth_queue_input_buffer(card, index); |
| 2773 | } |
| 2774 | #ifdef CONFIG_QETH_PERF_STATS |
| 2775 | card->perf_stats.inbound_time += qeth_get_micros() - |
| 2776 | card->perf_stats.inbound_start_time; |
| 2777 | #endif |
| 2778 | } |
| 2779 | |
| 2780 | static inline int |
| 2781 | qeth_handle_send_error(struct qeth_card *card, |
| 2782 | struct qeth_qdio_out_buffer *buffer, |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2783 | unsigned int qdio_err, unsigned int siga_err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | { |
| 2785 | int sbalf15 = buffer->buffer->element[15].flags & 0xff; |
| 2786 | int cc = siga_err & 3; |
| 2787 | |
| 2788 | QETH_DBF_TEXT(trace, 6, "hdsnderr"); |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2789 | qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | switch (cc) { |
| 2791 | case 0: |
| 2792 | if (qdio_err){ |
| 2793 | QETH_DBF_TEXT(trace, 1,"lnkfail"); |
| 2794 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2795 | QETH_DBF_TEXT_(trace,1,"%04x %02x", |
| 2796 | (u16)qdio_err, (u8)sbalf15); |
| 2797 | return QETH_SEND_ERROR_LINK_FAILURE; |
| 2798 | } |
| 2799 | return QETH_SEND_ERROR_NONE; |
| 2800 | case 2: |
| 2801 | if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) { |
| 2802 | QETH_DBF_TEXT(trace, 1, "SIGAcc2B"); |
| 2803 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2804 | return QETH_SEND_ERROR_KICK_IT; |
| 2805 | } |
| 2806 | if ((sbalf15 >= 15) && (sbalf15 <= 31)) |
| 2807 | return QETH_SEND_ERROR_RETRY; |
| 2808 | return QETH_SEND_ERROR_LINK_FAILURE; |
| 2809 | /* look at qdio_error and sbalf 15 */ |
| 2810 | case 1: |
| 2811 | QETH_DBF_TEXT(trace, 1, "SIGAcc1"); |
| 2812 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2813 | return QETH_SEND_ERROR_LINK_FAILURE; |
| 2814 | case 3: |
Frank Pavlic | 1380fee | 2006-03-22 16:03:41 +0100 | [diff] [blame] | 2815 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | QETH_DBF_TEXT(trace, 1, "SIGAcc3"); |
| 2817 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2818 | return QETH_SEND_ERROR_KICK_IT; |
| 2819 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | void |
| 2823 | qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int, |
| 2824 | int index, int count) |
| 2825 | { |
| 2826 | struct qeth_qdio_out_buffer *buf; |
| 2827 | int rc; |
| 2828 | int i; |
| 2829 | |
| 2830 | QETH_DBF_TEXT(trace, 6, "flushbuf"); |
| 2831 | |
| 2832 | for (i = index; i < index + count; ++i) { |
| 2833 | buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; |
| 2834 | buf->buffer->element[buf->next_element_to_fill - 1].flags |= |
| 2835 | SBAL_FLAGS_LAST_ENTRY; |
| 2836 | |
| 2837 | if (queue->card->info.type == QETH_CARD_TYPE_IQD) |
| 2838 | continue; |
| 2839 | |
| 2840 | if (!queue->do_pack){ |
| 2841 | if ((atomic_read(&queue->used_buffers) >= |
| 2842 | (QETH_HIGH_WATERMARK_PACK - |
| 2843 | QETH_WATERMARK_PACK_FUZZ)) && |
| 2844 | !atomic_read(&queue->set_pci_flags_count)){ |
| 2845 | /* it's likely that we'll go to packing |
| 2846 | * mode soon */ |
| 2847 | atomic_inc(&queue->set_pci_flags_count); |
| 2848 | buf->buffer->element[0].flags |= 0x40; |
| 2849 | } |
| 2850 | } else { |
| 2851 | if (!atomic_read(&queue->set_pci_flags_count)){ |
| 2852 | /* |
| 2853 | * there's no outstanding PCI any more, so we |
| 2854 | * have to request a PCI to be sure the the PCI |
| 2855 | * will wake at some time in the future then we |
| 2856 | * can flush packed buffers that might still be |
| 2857 | * hanging around, which can happen if no |
| 2858 | * further send was requested by the stack |
| 2859 | */ |
| 2860 | atomic_inc(&queue->set_pci_flags_count); |
| 2861 | buf->buffer->element[0].flags |= 0x40; |
| 2862 | } |
| 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | queue->card->dev->trans_start = jiffies; |
| 2867 | #ifdef CONFIG_QETH_PERF_STATS |
| 2868 | queue->card->perf_stats.outbound_do_qdio_cnt++; |
| 2869 | queue->card->perf_stats.outbound_do_qdio_start_time = qeth_get_micros(); |
| 2870 | #endif |
| 2871 | if (under_int) |
| 2872 | rc = do_QDIO(CARD_DDEV(queue->card), |
| 2873 | QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT, |
| 2874 | queue->queue_no, index, count, NULL); |
| 2875 | else |
| 2876 | rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT, |
| 2877 | queue->queue_no, index, count, NULL); |
| 2878 | #ifdef CONFIG_QETH_PERF_STATS |
| 2879 | queue->card->perf_stats.outbound_do_qdio_time += qeth_get_micros() - |
| 2880 | queue->card->perf_stats.outbound_do_qdio_start_time; |
| 2881 | #endif |
| 2882 | if (rc){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | QETH_DBF_TEXT(trace, 2, "flushbuf"); |
| 2884 | QETH_DBF_TEXT_(trace, 2, " err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 2885 | QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | queue->card->stats.tx_errors += count; |
| 2887 | /* this must not happen under normal circumstances. if it |
| 2888 | * happens something is really wrong -> recover */ |
| 2889 | qeth_schedule_recovery(queue->card); |
| 2890 | return; |
| 2891 | } |
| 2892 | atomic_add(count, &queue->used_buffers); |
| 2893 | #ifdef CONFIG_QETH_PERF_STATS |
| 2894 | queue->card->perf_stats.bufs_sent += count; |
| 2895 | #endif |
| 2896 | } |
| 2897 | |
| 2898 | /* |
| 2899 | * Switched to packing state if the number of used buffers on a queue |
| 2900 | * reaches a certain limit. |
| 2901 | */ |
| 2902 | static inline void |
| 2903 | qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue) |
| 2904 | { |
| 2905 | if (!queue->do_pack) { |
| 2906 | if (atomic_read(&queue->used_buffers) |
| 2907 | >= QETH_HIGH_WATERMARK_PACK){ |
| 2908 | /* switch non-PACKING -> PACKING */ |
| 2909 | QETH_DBF_TEXT(trace, 6, "np->pack"); |
| 2910 | #ifdef CONFIG_QETH_PERF_STATS |
| 2911 | queue->card->perf_stats.sc_dp_p++; |
| 2912 | #endif |
| 2913 | queue->do_pack = 1; |
| 2914 | } |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | /* |
| 2919 | * Switches from packing to non-packing mode. If there is a packing |
| 2920 | * buffer on the queue this buffer will be prepared to be flushed. |
| 2921 | * In that case 1 is returned to inform the caller. If no buffer |
| 2922 | * has to be flushed, zero is returned. |
| 2923 | */ |
| 2924 | static inline int |
| 2925 | qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue) |
| 2926 | { |
| 2927 | struct qeth_qdio_out_buffer *buffer; |
| 2928 | int flush_count = 0; |
| 2929 | |
| 2930 | if (queue->do_pack) { |
| 2931 | if (atomic_read(&queue->used_buffers) |
| 2932 | <= QETH_LOW_WATERMARK_PACK) { |
| 2933 | /* switch PACKING -> non-PACKING */ |
| 2934 | QETH_DBF_TEXT(trace, 6, "pack->np"); |
| 2935 | #ifdef CONFIG_QETH_PERF_STATS |
| 2936 | queue->card->perf_stats.sc_p_dp++; |
| 2937 | #endif |
| 2938 | queue->do_pack = 0; |
| 2939 | /* flush packing buffers */ |
| 2940 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 2941 | if ((atomic_read(&buffer->state) == |
| 2942 | QETH_QDIO_BUF_EMPTY) && |
| 2943 | (buffer->next_element_to_fill > 0)) { |
| 2944 | atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED); |
| 2945 | flush_count++; |
| 2946 | queue->next_buf_to_fill = |
| 2947 | (queue->next_buf_to_fill + 1) % |
| 2948 | QDIO_MAX_BUFFERS_PER_Q; |
| 2949 | } |
| 2950 | } |
| 2951 | } |
| 2952 | return flush_count; |
| 2953 | } |
| 2954 | |
| 2955 | /* |
| 2956 | * Called to flush a packing buffer if no more pci flags are on the queue. |
| 2957 | * Checks if there is a packing buffer and prepares it to be flushed. |
| 2958 | * In that case returns 1, otherwise zero. |
| 2959 | */ |
| 2960 | static inline int |
| 2961 | qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue) |
| 2962 | { |
| 2963 | struct qeth_qdio_out_buffer *buffer; |
| 2964 | |
| 2965 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 2966 | if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) && |
| 2967 | (buffer->next_element_to_fill > 0)){ |
| 2968 | /* it's a packing buffer */ |
| 2969 | atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED); |
| 2970 | queue->next_buf_to_fill = |
| 2971 | (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q; |
| 2972 | return 1; |
| 2973 | } |
| 2974 | return 0; |
| 2975 | } |
| 2976 | |
| 2977 | static inline void |
| 2978 | qeth_check_outbound_queue(struct qeth_qdio_out_q *queue) |
| 2979 | { |
| 2980 | int index; |
| 2981 | int flush_cnt = 0; |
| 2982 | int q_was_packing = 0; |
| 2983 | |
| 2984 | /* |
| 2985 | * check if weed have to switch to non-packing mode or if |
| 2986 | * we have to get a pci flag out on the queue |
| 2987 | */ |
| 2988 | if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) || |
| 2989 | !atomic_read(&queue->set_pci_flags_count)){ |
| 2990 | if (atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) == |
| 2991 | QETH_OUT_Q_UNLOCKED) { |
| 2992 | /* |
| 2993 | * If we get in here, there was no action in |
| 2994 | * do_send_packet. So, we check if there is a |
| 2995 | * packing buffer to be flushed here. |
| 2996 | */ |
| 2997 | netif_stop_queue(queue->card->dev); |
| 2998 | index = queue->next_buf_to_fill; |
| 2999 | q_was_packing = queue->do_pack; |
| 3000 | flush_cnt += qeth_switch_to_nonpacking_if_needed(queue); |
| 3001 | if (!flush_cnt && |
| 3002 | !atomic_read(&queue->set_pci_flags_count)) |
| 3003 | flush_cnt += |
| 3004 | qeth_flush_buffers_on_no_pci(queue); |
| 3005 | #ifdef CONFIG_QETH_PERF_STATS |
| 3006 | if (q_was_packing) |
| 3007 | queue->card->perf_stats.bufs_sent_pack += |
| 3008 | flush_cnt; |
| 3009 | #endif |
| 3010 | if (flush_cnt) |
| 3011 | qeth_flush_buffers(queue, 1, index, flush_cnt); |
| 3012 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 3013 | } |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | static void |
| 3018 | qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status, |
| 3019 | unsigned int qdio_error, unsigned int siga_error, |
| 3020 | unsigned int __queue, int first_element, int count, |
| 3021 | unsigned long card_ptr) |
| 3022 | { |
| 3023 | struct qeth_card *card = (struct qeth_card *) card_ptr; |
| 3024 | struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue]; |
| 3025 | struct qeth_qdio_out_buffer *buffer; |
| 3026 | int i; |
| 3027 | |
| 3028 | QETH_DBF_TEXT(trace, 6, "qdouhdl"); |
| 3029 | if (status & QDIO_STATUS_LOOK_FOR_ERROR) { |
| 3030 | if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){ |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3031 | QETH_DBF_TEXT(trace, 2, "achkcond"); |
| 3032 | QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | QETH_DBF_TEXT_(trace, 2, "%08x", status); |
| 3034 | netif_stop_queue(card->dev); |
| 3035 | qeth_schedule_recovery(card); |
| 3036 | return; |
| 3037 | } |
| 3038 | } |
| 3039 | #ifdef CONFIG_QETH_PERF_STATS |
| 3040 | card->perf_stats.outbound_handler_cnt++; |
| 3041 | card->perf_stats.outbound_handler_start_time = qeth_get_micros(); |
| 3042 | #endif |
| 3043 | for(i = first_element; i < (first_element + count); ++i){ |
| 3044 | buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; |
| 3045 | /*we only handle the KICK_IT error by doing a recovery */ |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 3046 | if (qeth_handle_send_error(card, buffer, |
| 3047 | qdio_error, siga_error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | == QETH_SEND_ERROR_KICK_IT){ |
| 3049 | netif_stop_queue(card->dev); |
| 3050 | qeth_schedule_recovery(card); |
| 3051 | return; |
| 3052 | } |
| 3053 | qeth_clear_output_buffer(queue, buffer); |
| 3054 | } |
| 3055 | atomic_sub(count, &queue->used_buffers); |
| 3056 | /* check if we need to do something on this outbound queue */ |
| 3057 | if (card->info.type != QETH_CARD_TYPE_IQD) |
| 3058 | qeth_check_outbound_queue(queue); |
| 3059 | |
| 3060 | netif_wake_queue(queue->card->dev); |
| 3061 | #ifdef CONFIG_QETH_PERF_STATS |
| 3062 | card->perf_stats.outbound_handler_time += qeth_get_micros() - |
| 3063 | card->perf_stats.outbound_handler_start_time; |
| 3064 | #endif |
| 3065 | } |
| 3066 | |
| 3067 | static void |
| 3068 | qeth_create_qib_param_field(struct qeth_card *card, char *param_field) |
| 3069 | { |
| 3070 | |
| 3071 | param_field[0] = _ascebc['P']; |
| 3072 | param_field[1] = _ascebc['C']; |
| 3073 | param_field[2] = _ascebc['I']; |
| 3074 | param_field[3] = _ascebc['T']; |
| 3075 | *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card); |
| 3076 | *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card); |
| 3077 | *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card); |
| 3078 | } |
| 3079 | |
| 3080 | static void |
| 3081 | qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field) |
| 3082 | { |
| 3083 | param_field[16] = _ascebc['B']; |
| 3084 | param_field[17] = _ascebc['L']; |
| 3085 | param_field[18] = _ascebc['K']; |
| 3086 | param_field[19] = _ascebc['T']; |
| 3087 | *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total; |
| 3088 | *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet; |
| 3089 | *((unsigned int *) (¶m_field[28])) = card->info.blkt.inter_packet_jumbo; |
| 3090 | } |
| 3091 | |
| 3092 | static void |
| 3093 | qeth_initialize_working_pool_list(struct qeth_card *card) |
| 3094 | { |
| 3095 | struct qeth_buffer_pool_entry *entry; |
| 3096 | |
| 3097 | QETH_DBF_TEXT(trace,5,"inwrklst"); |
| 3098 | |
| 3099 | list_for_each_entry(entry, |
| 3100 | &card->qdio.init_pool.entry_list, init_list) { |
| 3101 | qeth_put_buffer_pool_entry(card,entry); |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | static void |
| 3106 | qeth_clear_working_pool_list(struct qeth_card *card) |
| 3107 | { |
| 3108 | struct qeth_buffer_pool_entry *pool_entry, *tmp; |
| 3109 | |
| 3110 | QETH_DBF_TEXT(trace,5,"clwrklst"); |
| 3111 | list_for_each_entry_safe(pool_entry, tmp, |
| 3112 | &card->qdio.in_buf_pool.entry_list, list){ |
| 3113 | list_del(&pool_entry->list); |
| 3114 | } |
| 3115 | } |
| 3116 | |
| 3117 | static void |
| 3118 | qeth_free_buffer_pool(struct qeth_card *card) |
| 3119 | { |
| 3120 | struct qeth_buffer_pool_entry *pool_entry, *tmp; |
| 3121 | int i=0; |
| 3122 | QETH_DBF_TEXT(trace,5,"freepool"); |
| 3123 | list_for_each_entry_safe(pool_entry, tmp, |
| 3124 | &card->qdio.init_pool.entry_list, init_list){ |
| 3125 | for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) |
| 3126 | free_page((unsigned long)pool_entry->elements[i]); |
| 3127 | list_del(&pool_entry->init_list); |
| 3128 | kfree(pool_entry); |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | static int |
| 3133 | qeth_alloc_buffer_pool(struct qeth_card *card) |
| 3134 | { |
| 3135 | struct qeth_buffer_pool_entry *pool_entry; |
| 3136 | void *ptr; |
| 3137 | int i, j; |
| 3138 | |
| 3139 | QETH_DBF_TEXT(trace,5,"alocpool"); |
| 3140 | for (i = 0; i < card->qdio.init_pool.buf_count; ++i){ |
| 3141 | pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL); |
| 3142 | if (!pool_entry){ |
| 3143 | qeth_free_buffer_pool(card); |
| 3144 | return -ENOMEM; |
| 3145 | } |
| 3146 | for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){ |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 3147 | ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | if (!ptr) { |
| 3149 | while (j > 0) |
| 3150 | free_page((unsigned long) |
| 3151 | pool_entry->elements[--j]); |
| 3152 | kfree(pool_entry); |
| 3153 | qeth_free_buffer_pool(card); |
| 3154 | return -ENOMEM; |
| 3155 | } |
| 3156 | pool_entry->elements[j] = ptr; |
| 3157 | } |
| 3158 | list_add(&pool_entry->init_list, |
| 3159 | &card->qdio.init_pool.entry_list); |
| 3160 | } |
| 3161 | return 0; |
| 3162 | } |
| 3163 | |
| 3164 | int |
| 3165 | qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt) |
| 3166 | { |
| 3167 | QETH_DBF_TEXT(trace, 2, "realcbp"); |
| 3168 | |
| 3169 | if ((card->state != CARD_STATE_DOWN) && |
| 3170 | (card->state != CARD_STATE_RECOVER)) |
| 3171 | return -EPERM; |
| 3172 | |
| 3173 | /* TODO: steel/add buffers from/to a running card's buffer pool (?) */ |
| 3174 | qeth_clear_working_pool_list(card); |
| 3175 | qeth_free_buffer_pool(card); |
| 3176 | card->qdio.in_buf_pool.buf_count = bufcnt; |
| 3177 | card->qdio.init_pool.buf_count = bufcnt; |
| 3178 | return qeth_alloc_buffer_pool(card); |
| 3179 | } |
| 3180 | |
| 3181 | static int |
| 3182 | qeth_alloc_qdio_buffers(struct qeth_card *card) |
| 3183 | { |
| 3184 | int i, j; |
| 3185 | |
| 3186 | QETH_DBF_TEXT(setup, 2, "allcqdbf"); |
| 3187 | |
| 3188 | if (card->qdio.state == QETH_QDIO_ALLOCATED) |
| 3189 | return 0; |
| 3190 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 3191 | card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q), |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 3192 | GFP_KERNEL|GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | if (!card->qdio.in_q) |
| 3194 | return - ENOMEM; |
| 3195 | QETH_DBF_TEXT(setup, 2, "inq"); |
| 3196 | QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *)); |
| 3197 | memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q)); |
| 3198 | /* give inbound qeth_qdio_buffers their qdio_buffers */ |
| 3199 | for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) |
| 3200 | card->qdio.in_q->bufs[i].buffer = |
| 3201 | &card->qdio.in_q->qdio_bufs[i]; |
| 3202 | /* inbound buffer pool */ |
| 3203 | if (qeth_alloc_buffer_pool(card)){ |
| 3204 | kfree(card->qdio.in_q); |
| 3205 | return -ENOMEM; |
| 3206 | } |
| 3207 | /* outbound */ |
| 3208 | card->qdio.out_qs = |
| 3209 | kmalloc(card->qdio.no_out_queues * |
| 3210 | sizeof(struct qeth_qdio_out_q *), GFP_KERNEL); |
| 3211 | if (!card->qdio.out_qs){ |
| 3212 | qeth_free_buffer_pool(card); |
| 3213 | return -ENOMEM; |
| 3214 | } |
| 3215 | for (i = 0; i < card->qdio.no_out_queues; ++i){ |
| 3216 | card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q), |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 3217 | GFP_KERNEL|GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | if (!card->qdio.out_qs[i]){ |
| 3219 | while (i > 0) |
| 3220 | kfree(card->qdio.out_qs[--i]); |
| 3221 | kfree(card->qdio.out_qs); |
| 3222 | return -ENOMEM; |
| 3223 | } |
| 3224 | QETH_DBF_TEXT_(setup, 2, "outq %i", i); |
| 3225 | QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *)); |
| 3226 | memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q)); |
| 3227 | card->qdio.out_qs[i]->queue_no = i; |
| 3228 | /* give outbound qeth_qdio_buffers their qdio_buffers */ |
| 3229 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){ |
| 3230 | card->qdio.out_qs[i]->bufs[j].buffer = |
| 3231 | &card->qdio.out_qs[i]->qdio_bufs[j]; |
| 3232 | skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j]. |
| 3233 | skb_list); |
Heiko Carstens | 91ebe2a | 2006-07-03 00:25:26 -0700 | [diff] [blame] | 3234 | lockdep_set_class( |
| 3235 | &card->qdio.out_qs[i]->bufs[j].skb_list.lock, |
| 3236 | &qdio_out_skb_queue_key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list); |
| 3238 | } |
| 3239 | } |
| 3240 | card->qdio.state = QETH_QDIO_ALLOCATED; |
| 3241 | return 0; |
| 3242 | } |
| 3243 | |
| 3244 | static void |
| 3245 | qeth_free_qdio_buffers(struct qeth_card *card) |
| 3246 | { |
| 3247 | int i, j; |
| 3248 | |
| 3249 | QETH_DBF_TEXT(trace, 2, "freeqdbf"); |
| 3250 | if (card->qdio.state == QETH_QDIO_UNINITIALIZED) |
| 3251 | return; |
| 3252 | kfree(card->qdio.in_q); |
| 3253 | /* inbound buffer pool */ |
| 3254 | qeth_free_buffer_pool(card); |
| 3255 | /* free outbound qdio_qs */ |
| 3256 | for (i = 0; i < card->qdio.no_out_queues; ++i){ |
| 3257 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) |
| 3258 | qeth_clear_output_buffer(card->qdio.out_qs[i], |
| 3259 | &card->qdio.out_qs[i]->bufs[j]); |
| 3260 | kfree(card->qdio.out_qs[i]); |
| 3261 | } |
| 3262 | kfree(card->qdio.out_qs); |
| 3263 | card->qdio.state = QETH_QDIO_UNINITIALIZED; |
| 3264 | } |
| 3265 | |
| 3266 | static void |
| 3267 | qeth_clear_qdio_buffers(struct qeth_card *card) |
| 3268 | { |
| 3269 | int i, j; |
| 3270 | |
| 3271 | QETH_DBF_TEXT(trace, 2, "clearqdbf"); |
| 3272 | /* clear outbound buffers to free skbs */ |
| 3273 | for (i = 0; i < card->qdio.no_out_queues; ++i) |
| 3274 | if (card->qdio.out_qs[i]){ |
| 3275 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) |
| 3276 | qeth_clear_output_buffer(card->qdio.out_qs[i], |
| 3277 | &card->qdio.out_qs[i]->bufs[j]); |
| 3278 | } |
| 3279 | } |
| 3280 | |
| 3281 | static void |
| 3282 | qeth_init_qdio_info(struct qeth_card *card) |
| 3283 | { |
| 3284 | QETH_DBF_TEXT(setup, 4, "intqdinf"); |
| 3285 | card->qdio.state = QETH_QDIO_UNINITIALIZED; |
| 3286 | /* inbound */ |
| 3287 | card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT; |
| 3288 | card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT; |
| 3289 | card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count; |
| 3290 | INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list); |
| 3291 | INIT_LIST_HEAD(&card->qdio.init_pool.entry_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | static int |
| 3295 | qeth_init_qdio_queues(struct qeth_card *card) |
| 3296 | { |
| 3297 | int i, j; |
| 3298 | int rc; |
| 3299 | |
| 3300 | QETH_DBF_TEXT(setup, 2, "initqdqs"); |
| 3301 | |
| 3302 | /* inbound queue */ |
| 3303 | memset(card->qdio.in_q->qdio_bufs, 0, |
| 3304 | QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer)); |
| 3305 | qeth_initialize_working_pool_list(card); |
| 3306 | /*give only as many buffers to hardware as we have buffer pool entries*/ |
| 3307 | for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i) |
| 3308 | qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]); |
| 3309 | card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1; |
| 3310 | rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0, |
| 3311 | card->qdio.in_buf_pool.buf_count - 1, NULL); |
| 3312 | if (rc) { |
| 3313 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 3314 | return rc; |
| 3315 | } |
| 3316 | rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0); |
| 3317 | if (rc) { |
| 3318 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 3319 | return rc; |
| 3320 | } |
| 3321 | /* outbound queue */ |
| 3322 | for (i = 0; i < card->qdio.no_out_queues; ++i){ |
| 3323 | memset(card->qdio.out_qs[i]->qdio_bufs, 0, |
| 3324 | QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer)); |
| 3325 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){ |
| 3326 | qeth_clear_output_buffer(card->qdio.out_qs[i], |
| 3327 | &card->qdio.out_qs[i]->bufs[j]); |
| 3328 | } |
| 3329 | card->qdio.out_qs[i]->card = card; |
| 3330 | card->qdio.out_qs[i]->next_buf_to_fill = 0; |
| 3331 | card->qdio.out_qs[i]->do_pack = 0; |
| 3332 | atomic_set(&card->qdio.out_qs[i]->used_buffers,0); |
| 3333 | atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0); |
| 3334 | atomic_set(&card->qdio.out_qs[i]->state, |
| 3335 | QETH_OUT_Q_UNLOCKED); |
| 3336 | } |
| 3337 | return 0; |
| 3338 | } |
| 3339 | |
| 3340 | static int |
| 3341 | qeth_qdio_establish(struct qeth_card *card) |
| 3342 | { |
| 3343 | struct qdio_initialize init_data; |
| 3344 | char *qib_param_field; |
| 3345 | struct qdio_buffer **in_sbal_ptrs; |
| 3346 | struct qdio_buffer **out_sbal_ptrs; |
| 3347 | int i, j, k; |
| 3348 | int rc; |
| 3349 | |
| 3350 | QETH_DBF_TEXT(setup, 2, "qdioest"); |
| 3351 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 3352 | qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | GFP_KERNEL); |
| 3354 | if (!qib_param_field) |
| 3355 | return -ENOMEM; |
| 3356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | qeth_create_qib_param_field(card, qib_param_field); |
| 3358 | qeth_create_qib_param_field_blkt(card, qib_param_field); |
| 3359 | |
| 3360 | in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *), |
| 3361 | GFP_KERNEL); |
| 3362 | if (!in_sbal_ptrs) { |
| 3363 | kfree(qib_param_field); |
| 3364 | return -ENOMEM; |
| 3365 | } |
| 3366 | for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) |
| 3367 | in_sbal_ptrs[i] = (struct qdio_buffer *) |
| 3368 | virt_to_phys(card->qdio.in_q->bufs[i].buffer); |
| 3369 | |
| 3370 | out_sbal_ptrs = |
| 3371 | kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q * |
| 3372 | sizeof(void *), GFP_KERNEL); |
| 3373 | if (!out_sbal_ptrs) { |
| 3374 | kfree(in_sbal_ptrs); |
| 3375 | kfree(qib_param_field); |
| 3376 | return -ENOMEM; |
| 3377 | } |
| 3378 | for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i) |
| 3379 | for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){ |
| 3380 | out_sbal_ptrs[k] = (struct qdio_buffer *) |
| 3381 | virt_to_phys(card->qdio.out_qs[i]-> |
| 3382 | bufs[j].buffer); |
| 3383 | } |
| 3384 | |
| 3385 | memset(&init_data, 0, sizeof(struct qdio_initialize)); |
| 3386 | init_data.cdev = CARD_DDEV(card); |
| 3387 | init_data.q_format = qeth_get_qdio_q_format(card); |
| 3388 | init_data.qib_param_field_format = 0; |
| 3389 | init_data.qib_param_field = qib_param_field; |
| 3390 | init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD; |
| 3391 | init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD; |
| 3392 | init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD; |
| 3393 | init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD; |
| 3394 | init_data.no_input_qs = 1; |
| 3395 | init_data.no_output_qs = card->qdio.no_out_queues; |
| 3396 | init_data.input_handler = (qdio_handler_t *) |
| 3397 | qeth_qdio_input_handler; |
| 3398 | init_data.output_handler = (qdio_handler_t *) |
| 3399 | qeth_qdio_output_handler; |
| 3400 | init_data.int_parm = (unsigned long) card; |
| 3401 | init_data.flags = QDIO_INBOUND_0COPY_SBALS | |
| 3402 | QDIO_OUTBOUND_0COPY_SBALS | |
| 3403 | QDIO_USE_OUTBOUND_PCIS; |
| 3404 | init_data.input_sbal_addr_array = (void **) in_sbal_ptrs; |
| 3405 | init_data.output_sbal_addr_array = (void **) out_sbal_ptrs; |
| 3406 | |
| 3407 | if (!(rc = qdio_initialize(&init_data))) |
| 3408 | card->qdio.state = QETH_QDIO_ESTABLISHED; |
| 3409 | |
| 3410 | kfree(out_sbal_ptrs); |
| 3411 | kfree(in_sbal_ptrs); |
| 3412 | kfree(qib_param_field); |
| 3413 | return rc; |
| 3414 | } |
| 3415 | |
| 3416 | static int |
| 3417 | qeth_qdio_activate(struct qeth_card *card) |
| 3418 | { |
| 3419 | QETH_DBF_TEXT(setup,3,"qdioact"); |
| 3420 | return qdio_activate(CARD_DDEV(card), 0); |
| 3421 | } |
| 3422 | |
| 3423 | static int |
| 3424 | qeth_clear_channel(struct qeth_channel *channel) |
| 3425 | { |
| 3426 | unsigned long flags; |
| 3427 | struct qeth_card *card; |
| 3428 | int rc; |
| 3429 | |
| 3430 | QETH_DBF_TEXT(trace,3,"clearch"); |
| 3431 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 3432 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 3433 | rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM); |
| 3434 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 3435 | |
| 3436 | if (rc) |
| 3437 | return rc; |
| 3438 | rc = wait_event_interruptible_timeout(card->wait_q, |
| 3439 | channel->state==CH_STATE_STOPPED, QETH_TIMEOUT); |
| 3440 | if (rc == -ERESTARTSYS) |
| 3441 | return rc; |
| 3442 | if (channel->state != CH_STATE_STOPPED) |
| 3443 | return -ETIME; |
| 3444 | channel->state = CH_STATE_DOWN; |
| 3445 | return 0; |
| 3446 | } |
| 3447 | |
| 3448 | static int |
| 3449 | qeth_halt_channel(struct qeth_channel *channel) |
| 3450 | { |
| 3451 | unsigned long flags; |
| 3452 | struct qeth_card *card; |
| 3453 | int rc; |
| 3454 | |
| 3455 | QETH_DBF_TEXT(trace,3,"haltch"); |
| 3456 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 3457 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 3458 | rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM); |
| 3459 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 3460 | |
| 3461 | if (rc) |
| 3462 | return rc; |
| 3463 | rc = wait_event_interruptible_timeout(card->wait_q, |
| 3464 | channel->state==CH_STATE_HALTED, QETH_TIMEOUT); |
| 3465 | if (rc == -ERESTARTSYS) |
| 3466 | return rc; |
| 3467 | if (channel->state != CH_STATE_HALTED) |
| 3468 | return -ETIME; |
| 3469 | return 0; |
| 3470 | } |
| 3471 | |
| 3472 | static int |
| 3473 | qeth_halt_channels(struct qeth_card *card) |
| 3474 | { |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3475 | int rc1 = 0, rc2=0, rc3 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | |
| 3477 | QETH_DBF_TEXT(trace,3,"haltchs"); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3478 | rc1 = qeth_halt_channel(&card->read); |
| 3479 | rc2 = qeth_halt_channel(&card->write); |
| 3480 | rc3 = qeth_halt_channel(&card->data); |
| 3481 | if (rc1) |
| 3482 | return rc1; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 3483 | if (rc2) |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3484 | return rc2; |
| 3485 | return rc3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | } |
| 3487 | static int |
| 3488 | qeth_clear_channels(struct qeth_card *card) |
| 3489 | { |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3490 | int rc1 = 0, rc2=0, rc3 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | |
| 3492 | QETH_DBF_TEXT(trace,3,"clearchs"); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3493 | rc1 = qeth_clear_channel(&card->read); |
| 3494 | rc2 = qeth_clear_channel(&card->write); |
| 3495 | rc3 = qeth_clear_channel(&card->data); |
| 3496 | if (rc1) |
| 3497 | return rc1; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 3498 | if (rc2) |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3499 | return rc2; |
| 3500 | return rc3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | static int |
| 3504 | qeth_clear_halt_card(struct qeth_card *card, int halt) |
| 3505 | { |
| 3506 | int rc = 0; |
| 3507 | |
| 3508 | QETH_DBF_TEXT(trace,3,"clhacrd"); |
| 3509 | QETH_DBF_HEX(trace, 3, &card, sizeof(void *)); |
| 3510 | |
| 3511 | if (halt) |
| 3512 | rc = qeth_halt_channels(card); |
| 3513 | if (rc) |
| 3514 | return rc; |
| 3515 | return qeth_clear_channels(card); |
| 3516 | } |
| 3517 | |
| 3518 | static int |
| 3519 | qeth_qdio_clear_card(struct qeth_card *card, int use_halt) |
| 3520 | { |
| 3521 | int rc = 0; |
| 3522 | |
| 3523 | QETH_DBF_TEXT(trace,3,"qdioclr"); |
| 3524 | if (card->qdio.state == QETH_QDIO_ESTABLISHED){ |
| 3525 | if ((rc = qdio_cleanup(CARD_DDEV(card), |
| 3526 | (card->info.type == QETH_CARD_TYPE_IQD) ? |
| 3527 | QDIO_FLAG_CLEANUP_USING_HALT : |
| 3528 | QDIO_FLAG_CLEANUP_USING_CLEAR))) |
| 3529 | QETH_DBF_TEXT_(trace, 3, "1err%d", rc); |
| 3530 | card->qdio.state = QETH_QDIO_ALLOCATED; |
| 3531 | } |
| 3532 | if ((rc = qeth_clear_halt_card(card, use_halt))) |
| 3533 | QETH_DBF_TEXT_(trace, 3, "2err%d", rc); |
| 3534 | card->state = CARD_STATE_DOWN; |
| 3535 | return rc; |
| 3536 | } |
| 3537 | |
| 3538 | static int |
| 3539 | qeth_dm_act(struct qeth_card *card) |
| 3540 | { |
| 3541 | int rc; |
| 3542 | struct qeth_cmd_buffer *iob; |
| 3543 | |
| 3544 | QETH_DBF_TEXT(setup,2,"dmact"); |
| 3545 | |
| 3546 | iob = qeth_wait_for_buffer(&card->write); |
| 3547 | memcpy(iob->data, DM_ACT, DM_ACT_SIZE); |
| 3548 | |
| 3549 | memcpy(QETH_DM_ACT_DEST_ADDR(iob->data), |
| 3550 | &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 3551 | memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data), |
| 3552 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 3553 | rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL); |
| 3554 | return rc; |
| 3555 | } |
| 3556 | |
| 3557 | static int |
| 3558 | qeth_mpc_initialize(struct qeth_card *card) |
| 3559 | { |
| 3560 | int rc; |
| 3561 | |
| 3562 | QETH_DBF_TEXT(setup,2,"mpcinit"); |
| 3563 | |
| 3564 | if ((rc = qeth_issue_next_read(card))){ |
| 3565 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 3566 | return rc; |
| 3567 | } |
| 3568 | if ((rc = qeth_cm_enable(card))){ |
| 3569 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3570 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | } |
| 3572 | if ((rc = qeth_cm_setup(card))){ |
| 3573 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3574 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | } |
| 3576 | if ((rc = qeth_ulp_enable(card))){ |
| 3577 | QETH_DBF_TEXT_(setup, 2, "4err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3578 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | } |
| 3580 | if ((rc = qeth_ulp_setup(card))){ |
| 3581 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3582 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | } |
| 3584 | if ((rc = qeth_alloc_qdio_buffers(card))){ |
| 3585 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3586 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | } |
| 3588 | if ((rc = qeth_qdio_establish(card))){ |
| 3589 | QETH_DBF_TEXT_(setup, 2, "6err%d", rc); |
| 3590 | qeth_free_qdio_buffers(card); |
| 3591 | goto out_qdio; |
| 3592 | } |
| 3593 | if ((rc = qeth_qdio_activate(card))){ |
| 3594 | QETH_DBF_TEXT_(setup, 2, "7err%d", rc); |
| 3595 | goto out_qdio; |
| 3596 | } |
| 3597 | if ((rc = qeth_dm_act(card))){ |
| 3598 | QETH_DBF_TEXT_(setup, 2, "8err%d", rc); |
| 3599 | goto out_qdio; |
| 3600 | } |
| 3601 | |
| 3602 | return 0; |
| 3603 | out_qdio: |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3604 | qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | return rc; |
| 3606 | } |
| 3607 | |
| 3608 | static struct net_device * |
| 3609 | qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype) |
| 3610 | { |
| 3611 | struct net_device *dev = NULL; |
| 3612 | |
| 3613 | switch (type) { |
| 3614 | case QETH_CARD_TYPE_OSAE: |
| 3615 | switch (linktype) { |
| 3616 | case QETH_LINK_TYPE_LANE_TR: |
| 3617 | case QETH_LINK_TYPE_HSTR: |
| 3618 | #ifdef CONFIG_TR |
| 3619 | dev = alloc_trdev(0); |
| 3620 | #endif /* CONFIG_TR */ |
| 3621 | break; |
| 3622 | default: |
| 3623 | dev = alloc_etherdev(0); |
| 3624 | } |
| 3625 | break; |
| 3626 | case QETH_CARD_TYPE_IQD: |
| 3627 | dev = alloc_netdev(0, "hsi%d", ether_setup); |
| 3628 | break; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3629 | case QETH_CARD_TYPE_OSN: |
| 3630 | dev = alloc_netdev(0, "osn%d", ether_setup); |
| 3631 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | default: |
| 3633 | dev = alloc_etherdev(0); |
| 3634 | } |
| 3635 | return dev; |
| 3636 | } |
| 3637 | |
| 3638 | /*hard_header fake function; used in case fake_ll is set */ |
| 3639 | static int |
| 3640 | qeth_fake_header(struct sk_buff *skb, struct net_device *dev, |
| 3641 | unsigned short type, void *daddr, void *saddr, |
| 3642 | unsigned len) |
| 3643 | { |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 3644 | if(dev->type == ARPHRD_IEEE802_TR){ |
| 3645 | struct trh_hdr *hdr; |
| 3646 | hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR); |
| 3647 | memcpy(hdr->saddr, dev->dev_addr, TR_ALEN); |
| 3648 | memcpy(hdr->daddr, "FAKELL", TR_ALEN); |
| 3649 | return QETH_FAKE_LL_LEN_TR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 3651 | } else { |
| 3652 | struct ethhdr *hdr; |
| 3653 | hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH); |
| 3654 | memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN); |
| 3655 | memcpy(hdr->h_dest, "FAKELL", ETH_ALEN); |
| 3656 | if (type != ETH_P_802_3) |
| 3657 | hdr->h_proto = htons(type); |
| 3658 | else |
| 3659 | hdr->h_proto = htons(len); |
| 3660 | return QETH_FAKE_LL_LEN_ETH; |
| 3661 | |
| 3662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | static inline int |
| 3666 | qeth_send_packet(struct qeth_card *, struct sk_buff *); |
| 3667 | |
| 3668 | static int |
| 3669 | qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 3670 | { |
| 3671 | int rc; |
| 3672 | struct qeth_card *card; |
| 3673 | |
| 3674 | QETH_DBF_TEXT(trace, 6, "hrdstxmi"); |
| 3675 | card = (struct qeth_card *)dev->priv; |
| 3676 | if (skb==NULL) { |
| 3677 | card->stats.tx_dropped++; |
| 3678 | card->stats.tx_errors++; |
| 3679 | /* return OK; otherwise ksoftirqd goes to 100% */ |
| 3680 | return NETDEV_TX_OK; |
| 3681 | } |
| 3682 | if ((card->state != CARD_STATE_UP) || !card->lan_online) { |
| 3683 | card->stats.tx_dropped++; |
| 3684 | card->stats.tx_errors++; |
| 3685 | card->stats.tx_carrier_errors++; |
| 3686 | dev_kfree_skb_any(skb); |
| 3687 | /* return OK; otherwise ksoftirqd goes to 100% */ |
| 3688 | return NETDEV_TX_OK; |
| 3689 | } |
| 3690 | #ifdef CONFIG_QETH_PERF_STATS |
| 3691 | card->perf_stats.outbound_cnt++; |
| 3692 | card->perf_stats.outbound_start_time = qeth_get_micros(); |
| 3693 | #endif |
| 3694 | netif_stop_queue(dev); |
| 3695 | if ((rc = qeth_send_packet(card, skb))) { |
| 3696 | if (rc == -EBUSY) { |
| 3697 | return NETDEV_TX_BUSY; |
| 3698 | } else { |
| 3699 | card->stats.tx_errors++; |
| 3700 | card->stats.tx_dropped++; |
| 3701 | dev_kfree_skb_any(skb); |
| 3702 | /*set to OK; otherwise ksoftirqd goes to 100% */ |
| 3703 | rc = NETDEV_TX_OK; |
| 3704 | } |
| 3705 | } |
| 3706 | netif_wake_queue(dev); |
| 3707 | #ifdef CONFIG_QETH_PERF_STATS |
| 3708 | card->perf_stats.outbound_time += qeth_get_micros() - |
| 3709 | card->perf_stats.outbound_start_time; |
| 3710 | #endif |
| 3711 | return rc; |
| 3712 | } |
| 3713 | |
| 3714 | static int |
| 3715 | qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card) |
| 3716 | { |
| 3717 | int rc = 0; |
| 3718 | #ifdef CONFIG_QETH_VLAN |
| 3719 | struct vlan_group *vg; |
| 3720 | int i; |
| 3721 | |
| 3722 | if (!(vg = card->vlangrp)) |
| 3723 | return rc; |
| 3724 | |
| 3725 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){ |
| 3726 | if (vg->vlan_devices[i] == dev){ |
| 3727 | rc = QETH_VLAN_CARD; |
| 3728 | break; |
| 3729 | } |
| 3730 | } |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 3731 | if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card)) |
| 3732 | return 0; |
| 3733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | #endif |
| 3735 | return rc; |
| 3736 | } |
| 3737 | |
| 3738 | static int |
| 3739 | qeth_verify_dev(struct net_device *dev) |
| 3740 | { |
| 3741 | struct qeth_card *card; |
| 3742 | unsigned long flags; |
| 3743 | int rc = 0; |
| 3744 | |
| 3745 | read_lock_irqsave(&qeth_card_list.rwlock, flags); |
| 3746 | list_for_each_entry(card, &qeth_card_list.list, list){ |
| 3747 | if (card->dev == dev){ |
| 3748 | rc = QETH_REAL_CARD; |
| 3749 | break; |
| 3750 | } |
| 3751 | rc = qeth_verify_vlan_dev(dev, card); |
| 3752 | if (rc) |
| 3753 | break; |
| 3754 | } |
| 3755 | read_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 3756 | |
| 3757 | return rc; |
| 3758 | } |
| 3759 | |
| 3760 | static struct qeth_card * |
| 3761 | qeth_get_card_from_dev(struct net_device *dev) |
| 3762 | { |
| 3763 | struct qeth_card *card = NULL; |
| 3764 | int rc; |
| 3765 | |
| 3766 | rc = qeth_verify_dev(dev); |
| 3767 | if (rc == QETH_REAL_CARD) |
| 3768 | card = (struct qeth_card *)dev->priv; |
| 3769 | else if (rc == QETH_VLAN_CARD) |
| 3770 | card = (struct qeth_card *) |
| 3771 | VLAN_DEV_INFO(dev)->real_dev->priv; |
| 3772 | |
| 3773 | QETH_DBF_TEXT_(trace, 4, "%d", rc); |
| 3774 | return card ; |
| 3775 | } |
| 3776 | |
| 3777 | static void |
| 3778 | qeth_tx_timeout(struct net_device *dev) |
| 3779 | { |
| 3780 | struct qeth_card *card; |
| 3781 | |
| 3782 | card = (struct qeth_card *) dev->priv; |
| 3783 | card->stats.tx_errors++; |
| 3784 | qeth_schedule_recovery(card); |
| 3785 | } |
| 3786 | |
| 3787 | static int |
| 3788 | qeth_open(struct net_device *dev) |
| 3789 | { |
| 3790 | struct qeth_card *card; |
| 3791 | |
| 3792 | QETH_DBF_TEXT(trace, 4, "qethopen"); |
| 3793 | |
| 3794 | card = (struct qeth_card *) dev->priv; |
| 3795 | |
| 3796 | if (card->state != CARD_STATE_SOFTSETUP) |
| 3797 | return -ENODEV; |
| 3798 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3799 | if ( (card->info.type != QETH_CARD_TYPE_OSN) && |
| 3800 | (card->options.layer2) && |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 3801 | (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | QETH_DBF_TEXT(trace,4,"nomacadr"); |
| 3803 | return -EPERM; |
| 3804 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | card->data.state = CH_STATE_UP; |
| 3806 | card->state = CARD_STATE_UP; |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 3807 | card->dev->flags |= IFF_UP; |
| 3808 | netif_start_queue(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 3809 | |
Frank Pavlic | 4965e97 | 2005-12-13 08:22:30 +0100 | [diff] [blame] | 3810 | if (!card->lan_online && netif_carrier_ok(dev)) |
| 3811 | netif_carrier_off(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | return 0; |
| 3813 | } |
| 3814 | |
| 3815 | static int |
| 3816 | qeth_stop(struct net_device *dev) |
| 3817 | { |
| 3818 | struct qeth_card *card; |
| 3819 | |
| 3820 | QETH_DBF_TEXT(trace, 4, "qethstop"); |
| 3821 | |
| 3822 | card = (struct qeth_card *) dev->priv; |
| 3823 | |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 3824 | netif_tx_disable(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | card->dev->flags &= ~IFF_UP; |
| 3826 | if (card->state == CARD_STATE_UP) |
| 3827 | card->state = CARD_STATE_SOFTSETUP; |
| 3828 | return 0; |
| 3829 | } |
| 3830 | |
| 3831 | static inline int |
| 3832 | qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb) |
| 3833 | { |
| 3834 | int cast_type = RTN_UNSPEC; |
| 3835 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3836 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 3837 | return cast_type; |
| 3838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | if (skb->dst && skb->dst->neighbour){ |
| 3840 | cast_type = skb->dst->neighbour->type; |
| 3841 | if ((cast_type == RTN_BROADCAST) || |
| 3842 | (cast_type == RTN_MULTICAST) || |
| 3843 | (cast_type == RTN_ANYCAST)) |
| 3844 | return cast_type; |
| 3845 | else |
| 3846 | return RTN_UNSPEC; |
| 3847 | } |
| 3848 | /* try something else */ |
| 3849 | if (skb->protocol == ETH_P_IPV6) |
| 3850 | return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0; |
| 3851 | else if (skb->protocol == ETH_P_IP) |
| 3852 | return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0; |
| 3853 | /* ... */ |
| 3854 | if (!memcmp(skb->data, skb->dev->broadcast, 6)) |
| 3855 | return RTN_BROADCAST; |
| 3856 | else { |
| 3857 | u16 hdr_mac; |
| 3858 | |
| 3859 | hdr_mac = *((u16 *)skb->data); |
| 3860 | /* tr multicast? */ |
| 3861 | switch (card->info.link_type) { |
| 3862 | case QETH_LINK_TYPE_HSTR: |
| 3863 | case QETH_LINK_TYPE_LANE_TR: |
| 3864 | if ((hdr_mac == QETH_TR_MAC_NC) || |
| 3865 | (hdr_mac == QETH_TR_MAC_C)) |
| 3866 | return RTN_MULTICAST; |
Frank Pavlic | 1380fee | 2006-03-22 16:03:41 +0100 | [diff] [blame] | 3867 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | /* eth or so multicast? */ |
| 3869 | default: |
| 3870 | if ((hdr_mac == QETH_ETH_MAC_V4) || |
| 3871 | (hdr_mac == QETH_ETH_MAC_V6)) |
| 3872 | return RTN_MULTICAST; |
| 3873 | } |
| 3874 | } |
| 3875 | return cast_type; |
| 3876 | } |
| 3877 | |
| 3878 | static inline int |
| 3879 | qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb, |
| 3880 | int ipv, int cast_type) |
| 3881 | { |
| 3882 | if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE)) |
| 3883 | return card->qdio.default_out_queue; |
| 3884 | switch (card->qdio.no_out_queues) { |
| 3885 | case 4: |
| 3886 | if (cast_type && card->info.is_multicast_different) |
| 3887 | return card->info.is_multicast_different & |
| 3888 | (card->qdio.no_out_queues - 1); |
| 3889 | if (card->qdio.do_prio_queueing && (ipv == 4)) { |
| 3890 | if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){ |
| 3891 | if (skb->nh.iph->tos & IP_TOS_NOTIMPORTANT) |
| 3892 | return 3; |
| 3893 | if (skb->nh.iph->tos & IP_TOS_HIGHRELIABILITY) |
| 3894 | return 2; |
| 3895 | if (skb->nh.iph->tos & IP_TOS_HIGHTHROUGHPUT) |
| 3896 | return 1; |
| 3897 | if (skb->nh.iph->tos & IP_TOS_LOWDELAY) |
| 3898 | return 0; |
| 3899 | } |
| 3900 | if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC) |
| 3901 | return 3 - (skb->nh.iph->tos >> 6); |
| 3902 | } else if (card->qdio.do_prio_queueing && (ipv == 6)) { |
| 3903 | /* TODO: IPv6!!! */ |
| 3904 | } |
| 3905 | return card->qdio.default_out_queue; |
| 3906 | case 1: /* fallthrough for single-out-queue 1920-device */ |
| 3907 | default: |
| 3908 | return card->qdio.default_out_queue; |
| 3909 | } |
| 3910 | } |
| 3911 | |
| 3912 | static inline int |
| 3913 | qeth_get_ip_version(struct sk_buff *skb) |
| 3914 | { |
| 3915 | switch (skb->protocol) { |
| 3916 | case ETH_P_IPV6: |
| 3917 | return 6; |
| 3918 | case ETH_P_IP: |
| 3919 | return 4; |
| 3920 | default: |
| 3921 | return 0; |
| 3922 | } |
| 3923 | } |
| 3924 | |
| 3925 | static inline int |
| 3926 | qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb, |
| 3927 | struct qeth_hdr **hdr, int ipv) |
| 3928 | { |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3929 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | #ifdef CONFIG_QETH_VLAN |
| 3931 | u16 *tag; |
| 3932 | #endif |
| 3933 | |
| 3934 | QETH_DBF_TEXT(trace, 6, "prepskb"); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3935 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 3936 | *hdr = (struct qeth_hdr *)(*skb)->data; |
| 3937 | return rc; |
| 3938 | } |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 3939 | rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr)); |
| 3940 | if (rc) |
| 3941 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | #ifdef CONFIG_QETH_VLAN |
| 3943 | if (card->vlangrp && vlan_tx_tag_present(*skb) && |
| 3944 | ((ipv == 6) || card->options.layer2) ) { |
| 3945 | /* |
| 3946 | * Move the mac addresses (6 bytes src, 6 bytes dest) |
| 3947 | * to the beginning of the new header. We are using three |
| 3948 | * memcpys instead of one memmove to save cycles. |
| 3949 | */ |
| 3950 | skb_push(*skb, VLAN_HLEN); |
| 3951 | memcpy((*skb)->data, (*skb)->data + 4, 4); |
| 3952 | memcpy((*skb)->data + 4, (*skb)->data + 8, 4); |
| 3953 | memcpy((*skb)->data + 8, (*skb)->data + 12, 4); |
| 3954 | tag = (u16 *)((*skb)->data + 12); |
| 3955 | /* |
| 3956 | * first two bytes = ETH_P_8021Q (0x8100) |
| 3957 | * second two bytes = VLANID |
| 3958 | */ |
| 3959 | *tag = __constant_htons(ETH_P_8021Q); |
| 3960 | *(tag + 1) = htons(vlan_tx_tag_get(*skb)); |
| 3961 | } |
| 3962 | #endif |
| 3963 | *hdr = (struct qeth_hdr *) |
| 3964 | qeth_push_skb(card, skb, sizeof(struct qeth_hdr)); |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 3965 | if (*hdr == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | return -EINVAL; |
| 3967 | return 0; |
| 3968 | } |
| 3969 | |
| 3970 | static inline u8 |
| 3971 | qeth_get_qeth_hdr_flags4(int cast_type) |
| 3972 | { |
| 3973 | if (cast_type == RTN_MULTICAST) |
| 3974 | return QETH_CAST_MULTICAST; |
| 3975 | if (cast_type == RTN_BROADCAST) |
| 3976 | return QETH_CAST_BROADCAST; |
| 3977 | return QETH_CAST_UNICAST; |
| 3978 | } |
| 3979 | |
| 3980 | static inline u8 |
| 3981 | qeth_get_qeth_hdr_flags6(int cast_type) |
| 3982 | { |
| 3983 | u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6; |
| 3984 | if (cast_type == RTN_MULTICAST) |
| 3985 | return ct | QETH_CAST_MULTICAST; |
| 3986 | if (cast_type == RTN_ANYCAST) |
| 3987 | return ct | QETH_CAST_ANYCAST; |
| 3988 | if (cast_type == RTN_BROADCAST) |
| 3989 | return ct | QETH_CAST_BROADCAST; |
| 3990 | return ct | QETH_CAST_UNICAST; |
| 3991 | } |
| 3992 | |
| 3993 | static inline void |
| 3994 | qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr, |
| 3995 | struct sk_buff *skb) |
| 3996 | { |
| 3997 | __u16 hdr_mac; |
| 3998 | |
| 3999 | if (!memcmp(skb->data+QETH_HEADER_SIZE, |
| 4000 | skb->dev->broadcast,6)) { /* broadcast? */ |
| 4001 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4002 | QETH_LAYER2_FLAG_BROADCAST << 8; |
| 4003 | return; |
| 4004 | } |
| 4005 | hdr_mac=*((__u16*)skb->data); |
| 4006 | /* tr multicast? */ |
| 4007 | switch (card->info.link_type) { |
| 4008 | case QETH_LINK_TYPE_HSTR: |
| 4009 | case QETH_LINK_TYPE_LANE_TR: |
| 4010 | if ((hdr_mac == QETH_TR_MAC_NC) || |
| 4011 | (hdr_mac == QETH_TR_MAC_C) ) |
| 4012 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4013 | QETH_LAYER2_FLAG_MULTICAST << 8; |
| 4014 | else |
| 4015 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4016 | QETH_LAYER2_FLAG_UNICAST << 8; |
| 4017 | break; |
| 4018 | /* eth or so multicast? */ |
| 4019 | default: |
| 4020 | if ( (hdr_mac==QETH_ETH_MAC_V4) || |
| 4021 | (hdr_mac==QETH_ETH_MAC_V6) ) |
| 4022 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4023 | QETH_LAYER2_FLAG_MULTICAST << 8; |
| 4024 | else |
| 4025 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4026 | QETH_LAYER2_FLAG_UNICAST << 8; |
| 4027 | } |
| 4028 | } |
| 4029 | |
| 4030 | static inline void |
| 4031 | qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, |
| 4032 | struct sk_buff *skb, int cast_type) |
| 4033 | { |
| 4034 | memset(hdr, 0, sizeof(struct qeth_hdr)); |
| 4035 | hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; |
| 4036 | |
| 4037 | /* set byte 0 to "0x02" and byte 3 to casting flags */ |
| 4038 | if (cast_type==RTN_MULTICAST) |
| 4039 | *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8; |
| 4040 | else if (cast_type==RTN_BROADCAST) |
| 4041 | *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8; |
| 4042 | else |
| 4043 | qeth_layer2_get_packet_type(card, hdr, skb); |
| 4044 | |
| 4045 | hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE; |
| 4046 | #ifdef CONFIG_QETH_VLAN |
| 4047 | /* VSWITCH relies on the VLAN |
| 4048 | * information to be present in |
| 4049 | * the QDIO header */ |
| 4050 | if ((card->vlangrp != NULL) && |
| 4051 | vlan_tx_tag_present(skb)) { |
| 4052 | *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8; |
| 4053 | hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb); |
| 4054 | } |
| 4055 | #endif |
| 4056 | } |
| 4057 | |
| 4058 | void |
| 4059 | qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, |
| 4060 | struct sk_buff *skb, int ipv, int cast_type) |
| 4061 | { |
| 4062 | QETH_DBF_TEXT(trace, 6, "fillhdr"); |
| 4063 | |
| 4064 | memset(hdr, 0, sizeof(struct qeth_hdr)); |
| 4065 | if (card->options.layer2) { |
| 4066 | qeth_layer2_fill_header(card, hdr, skb, cast_type); |
| 4067 | return; |
| 4068 | } |
| 4069 | hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3; |
| 4070 | hdr->hdr.l3.ext_flags = 0; |
| 4071 | #ifdef CONFIG_QETH_VLAN |
| 4072 | /* |
| 4073 | * before we're going to overwrite this location with next hop ip. |
| 4074 | * v6 uses passthrough, v4 sets the tag in the QDIO header. |
| 4075 | */ |
| 4076 | if (card->vlangrp && vlan_tx_tag_present(skb)) { |
| 4077 | hdr->hdr.l3.ext_flags = (ipv == 4) ? |
| 4078 | QETH_HDR_EXT_VLAN_FRAME : |
| 4079 | QETH_HDR_EXT_INCLUDE_VLAN_TAG; |
| 4080 | hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb); |
| 4081 | } |
| 4082 | #endif /* CONFIG_QETH_VLAN */ |
| 4083 | hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr); |
| 4084 | if (ipv == 4) { /* IPv4 */ |
| 4085 | hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type); |
| 4086 | memset(hdr->hdr.l3.dest_addr, 0, 12); |
| 4087 | if ((skb->dst) && (skb->dst->neighbour)) { |
| 4088 | *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = |
| 4089 | *((u32 *) skb->dst->neighbour->primary_key); |
| 4090 | } else { |
| 4091 | /* fill in destination address used in ip header */ |
| 4092 | *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = skb->nh.iph->daddr; |
| 4093 | } |
| 4094 | } else if (ipv == 6) { /* IPv6 or passthru */ |
| 4095 | hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type); |
| 4096 | if ((skb->dst) && (skb->dst->neighbour)) { |
| 4097 | memcpy(hdr->hdr.l3.dest_addr, |
| 4098 | skb->dst->neighbour->primary_key, 16); |
| 4099 | } else { |
| 4100 | /* fill in destination address used in ip header */ |
| 4101 | memcpy(hdr->hdr.l3.dest_addr, &skb->nh.ipv6h->daddr, 16); |
| 4102 | } |
| 4103 | } else { /* passthrough */ |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4104 | if((skb->dev->type == ARPHRD_IEEE802_TR) && |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 4105 | !memcmp(skb->data + sizeof(struct qeth_hdr) + |
Frank Pavlic | 9a45581 | 2005-05-12 20:38:28 +0200 | [diff] [blame] | 4106 | sizeof(__u16), skb->dev->broadcast, 6)) { |
| 4107 | hdr->hdr.l3.flags = QETH_CAST_BROADCAST | |
| 4108 | QETH_HDR_PASSTHRU; |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4109 | } else if (!memcmp(skb->data + sizeof(struct qeth_hdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | skb->dev->broadcast, 6)) { /* broadcast? */ |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4111 | hdr->hdr.l3.flags = QETH_CAST_BROADCAST | |
| 4112 | QETH_HDR_PASSTHRU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | } else { |
| 4114 | hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ? |
| 4115 | QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU : |
| 4116 | QETH_CAST_UNICAST | QETH_HDR_PASSTHRU; |
| 4117 | } |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer, |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4123 | int is_tso, int *next_element_to_fill) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | { |
| 4125 | int length = skb->len; |
| 4126 | int length_here; |
| 4127 | int element; |
| 4128 | char *data; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4129 | int first_lap ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | |
| 4131 | element = *next_element_to_fill; |
| 4132 | data = skb->data; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4133 | first_lap = (is_tso == 0 ? 1 : 0); |
| 4134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | while (length > 0) { |
| 4136 | /* length_here is the remaining amount of data in this page */ |
| 4137 | length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE); |
| 4138 | if (length < length_here) |
| 4139 | length_here = length; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | buffer->element[element].addr = data; |
| 4142 | buffer->element[element].length = length_here; |
| 4143 | length -= length_here; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4144 | if (!length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | if (first_lap) |
| 4146 | buffer->element[element].flags = 0; |
| 4147 | else |
| 4148 | buffer->element[element].flags = |
| 4149 | SBAL_FLAGS_LAST_FRAG; |
| 4150 | } else { |
| 4151 | if (first_lap) |
| 4152 | buffer->element[element].flags = |
| 4153 | SBAL_FLAGS_FIRST_FRAG; |
| 4154 | else |
| 4155 | buffer->element[element].flags = |
| 4156 | SBAL_FLAGS_MIDDLE_FRAG; |
| 4157 | } |
| 4158 | data += length_here; |
| 4159 | element++; |
| 4160 | first_lap = 0; |
| 4161 | } |
| 4162 | *next_element_to_fill = element; |
| 4163 | } |
| 4164 | |
| 4165 | static inline int |
| 4166 | qeth_fill_buffer(struct qeth_qdio_out_q *queue, |
| 4167 | struct qeth_qdio_out_buffer *buf, |
| 4168 | struct sk_buff *skb) |
| 4169 | { |
| 4170 | struct qdio_buffer *buffer; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4171 | struct qeth_hdr_tso *hdr; |
| 4172 | int flush_cnt = 0, hdr_len, large_send = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | |
| 4174 | QETH_DBF_TEXT(trace, 6, "qdfillbf"); |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | buffer = buf->buffer; |
| 4177 | atomic_inc(&skb->users); |
| 4178 | skb_queue_tail(&buf->skb_list, skb); |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4179 | |
| 4180 | hdr = (struct qeth_hdr_tso *) skb->data; |
| 4181 | /*check first on TSO ....*/ |
| 4182 | if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) { |
| 4183 | int element = buf->next_element_to_fill; |
| 4184 | |
| 4185 | hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len; |
| 4186 | /*fill first buffer entry only with header information */ |
| 4187 | buffer->element[element].addr = skb->data; |
| 4188 | buffer->element[element].length = hdr_len; |
| 4189 | buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG; |
| 4190 | buf->next_element_to_fill++; |
| 4191 | skb->data += hdr_len; |
| 4192 | skb->len -= hdr_len; |
| 4193 | large_send = 1; |
| 4194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | if (skb_shinfo(skb)->nr_frags == 0) |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4196 | __qeth_fill_buffer(skb, buffer, large_send, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | (int *)&buf->next_element_to_fill); |
| 4198 | else |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4199 | __qeth_fill_buffer_frag(skb, buffer, large_send, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | (int *)&buf->next_element_to_fill); |
| 4201 | |
| 4202 | if (!queue->do_pack) { |
| 4203 | QETH_DBF_TEXT(trace, 6, "fillbfnp"); |
| 4204 | /* set state to PRIMED -> will be flushed */ |
| 4205 | atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED); |
| 4206 | flush_cnt = 1; |
| 4207 | } else { |
| 4208 | QETH_DBF_TEXT(trace, 6, "fillbfpa"); |
| 4209 | #ifdef CONFIG_QETH_PERF_STATS |
| 4210 | queue->card->perf_stats.skbs_sent_pack++; |
| 4211 | #endif |
| 4212 | if (buf->next_element_to_fill >= |
| 4213 | QETH_MAX_BUFFER_ELEMENTS(queue->card)) { |
| 4214 | /* |
| 4215 | * packed buffer if full -> set state PRIMED |
| 4216 | * -> will be flushed |
| 4217 | */ |
| 4218 | atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED); |
| 4219 | flush_cnt = 1; |
| 4220 | } |
| 4221 | } |
| 4222 | return flush_cnt; |
| 4223 | } |
| 4224 | |
| 4225 | static inline int |
| 4226 | qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue, |
| 4227 | struct sk_buff *skb, struct qeth_hdr *hdr, |
| 4228 | int elements_needed, |
| 4229 | struct qeth_eddp_context *ctx) |
| 4230 | { |
| 4231 | struct qeth_qdio_out_buffer *buffer; |
| 4232 | int buffers_needed = 0; |
| 4233 | int flush_cnt = 0; |
| 4234 | int index; |
| 4235 | |
| 4236 | QETH_DBF_TEXT(trace, 6, "dosndpfa"); |
| 4237 | |
| 4238 | /* spin until we get the queue ... */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 4239 | while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED, |
| 4240 | QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | /* ... now we've got the queue */ |
| 4242 | index = queue->next_buf_to_fill; |
| 4243 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 4244 | /* |
| 4245 | * check if buffer is empty to make sure that we do not 'overtake' |
| 4246 | * ourselves and try to fill a buffer that is already primed |
| 4247 | */ |
| 4248 | if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) { |
| 4249 | card->stats.tx_dropped++; |
| 4250 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4251 | return -EBUSY; |
| 4252 | } |
| 4253 | if (ctx == NULL) |
| 4254 | queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) % |
| 4255 | QDIO_MAX_BUFFERS_PER_Q; |
| 4256 | else { |
| 4257 | buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx); |
| 4258 | if (buffers_needed < 0) { |
| 4259 | card->stats.tx_dropped++; |
| 4260 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4261 | return -EBUSY; |
| 4262 | } |
| 4263 | queue->next_buf_to_fill = |
| 4264 | (queue->next_buf_to_fill + buffers_needed) % |
| 4265 | QDIO_MAX_BUFFERS_PER_Q; |
| 4266 | } |
| 4267 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4268 | if (ctx == NULL) { |
| 4269 | qeth_fill_buffer(queue, buffer, skb); |
| 4270 | qeth_flush_buffers(queue, 0, index, 1); |
| 4271 | } else { |
| 4272 | flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index); |
| 4273 | WARN_ON(buffers_needed != flush_cnt); |
| 4274 | qeth_flush_buffers(queue, 0, index, flush_cnt); |
| 4275 | } |
| 4276 | return 0; |
| 4277 | } |
| 4278 | |
| 4279 | static inline int |
| 4280 | qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue, |
| 4281 | struct sk_buff *skb, struct qeth_hdr *hdr, |
| 4282 | int elements_needed, struct qeth_eddp_context *ctx) |
| 4283 | { |
| 4284 | struct qeth_qdio_out_buffer *buffer; |
| 4285 | int start_index; |
| 4286 | int flush_count = 0; |
| 4287 | int do_pack = 0; |
| 4288 | int tmp; |
| 4289 | int rc = 0; |
| 4290 | |
| 4291 | QETH_DBF_TEXT(trace, 6, "dosndpkt"); |
| 4292 | |
| 4293 | /* spin until we get the queue ... */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 4294 | while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED, |
| 4295 | QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | start_index = queue->next_buf_to_fill; |
| 4297 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 4298 | /* |
| 4299 | * check if buffer is empty to make sure that we do not 'overtake' |
| 4300 | * ourselves and try to fill a buffer that is already primed |
| 4301 | */ |
| 4302 | if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY){ |
| 4303 | card->stats.tx_dropped++; |
| 4304 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4305 | return -EBUSY; |
| 4306 | } |
| 4307 | /* check if we need to switch packing state of this queue */ |
| 4308 | qeth_switch_to_packing_if_needed(queue); |
| 4309 | if (queue->do_pack){ |
| 4310 | do_pack = 1; |
| 4311 | if (ctx == NULL) { |
| 4312 | /* does packet fit in current buffer? */ |
| 4313 | if((QETH_MAX_BUFFER_ELEMENTS(card) - |
| 4314 | buffer->next_element_to_fill) < elements_needed){ |
| 4315 | /* ... no -> set state PRIMED */ |
| 4316 | atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED); |
| 4317 | flush_count++; |
| 4318 | queue->next_buf_to_fill = |
| 4319 | (queue->next_buf_to_fill + 1) % |
| 4320 | QDIO_MAX_BUFFERS_PER_Q; |
| 4321 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 4322 | /* we did a step forward, so check buffer state |
| 4323 | * again */ |
| 4324 | if (atomic_read(&buffer->state) != |
| 4325 | QETH_QDIO_BUF_EMPTY){ |
| 4326 | card->stats.tx_dropped++; |
| 4327 | qeth_flush_buffers(queue, 0, start_index, flush_count); |
| 4328 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4329 | return -EBUSY; |
| 4330 | } |
| 4331 | } |
| 4332 | } else { |
| 4333 | /* check if we have enough elements (including following |
| 4334 | * free buffers) to handle eddp context */ |
| 4335 | if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){ |
| 4336 | printk("eddp tx_dropped 1\n"); |
| 4337 | card->stats.tx_dropped++; |
| 4338 | rc = -EBUSY; |
| 4339 | goto out; |
| 4340 | } |
| 4341 | } |
| 4342 | } |
| 4343 | if (ctx == NULL) |
| 4344 | tmp = qeth_fill_buffer(queue, buffer, skb); |
| 4345 | else { |
| 4346 | tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill); |
| 4347 | if (tmp < 0) { |
| 4348 | printk("eddp tx_dropped 2\n"); |
| 4349 | card->stats.tx_dropped++; |
| 4350 | rc = - EBUSY; |
| 4351 | goto out; |
| 4352 | } |
| 4353 | } |
| 4354 | queue->next_buf_to_fill = (queue->next_buf_to_fill + tmp) % |
| 4355 | QDIO_MAX_BUFFERS_PER_Q; |
| 4356 | flush_count += tmp; |
| 4357 | out: |
| 4358 | if (flush_count) |
| 4359 | qeth_flush_buffers(queue, 0, start_index, flush_count); |
Frank Pavlic | d805d7c | 2005-11-10 13:50:58 +0100 | [diff] [blame] | 4360 | else if (!atomic_read(&queue->set_pci_flags_count)) |
| 4361 | atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | /* |
| 4363 | * queue->state will go from LOCKED -> UNLOCKED or from |
| 4364 | * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us |
| 4365 | * (switch packing state or flush buffer to get another pci flag out). |
| 4366 | * In that case we will enter this loop |
| 4367 | */ |
| 4368 | while (atomic_dec_return(&queue->state)){ |
| 4369 | flush_count = 0; |
| 4370 | start_index = queue->next_buf_to_fill; |
| 4371 | /* check if we can go back to non-packing state */ |
| 4372 | flush_count += qeth_switch_to_nonpacking_if_needed(queue); |
| 4373 | /* |
| 4374 | * check if we need to flush a packing buffer to get a pci |
| 4375 | * flag out on the queue |
| 4376 | */ |
| 4377 | if (!flush_count && !atomic_read(&queue->set_pci_flags_count)) |
| 4378 | flush_count += qeth_flush_buffers_on_no_pci(queue); |
| 4379 | if (flush_count) |
| 4380 | qeth_flush_buffers(queue, 0, start_index, flush_count); |
| 4381 | } |
| 4382 | /* at this point the queue is UNLOCKED again */ |
| 4383 | #ifdef CONFIG_QETH_PERF_STATS |
| 4384 | if (do_pack) |
| 4385 | queue->card->perf_stats.bufs_sent_pack += flush_count; |
| 4386 | #endif /* CONFIG_QETH_PERF_STATS */ |
| 4387 | |
| 4388 | return rc; |
| 4389 | } |
| 4390 | |
| 4391 | static inline int |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 4392 | qeth_get_elements_no(struct qeth_card *card, void *hdr, |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4393 | struct sk_buff *skb, int elems) |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4394 | { |
| 4395 | int elements_needed = 0; |
| 4396 | |
| 4397 | if (skb_shinfo(skb)->nr_frags > 0) { |
| 4398 | elements_needed = (skb_shinfo(skb)->nr_frags + 1); |
| 4399 | } |
| 4400 | if (elements_needed == 0 ) |
| 4401 | elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE) |
| 4402 | + skb->len) >> PAGE_SHIFT); |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4403 | if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){ |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4404 | PRINT_ERR("qeth_do_send_packet: invalid size of " |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4405 | "IP packet (Number=%d / Length=%d). Discarded.\n", |
| 4406 | (elements_needed+elems), skb->len); |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4407 | return 0; |
| 4408 | } |
| 4409 | return elements_needed; |
| 4410 | } |
| 4411 | |
| 4412 | static inline int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | qeth_send_packet(struct qeth_card *card, struct sk_buff *skb) |
| 4414 | { |
| 4415 | int ipv = 0; |
| 4416 | int cast_type; |
| 4417 | struct qeth_qdio_out_q *queue; |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 4418 | struct qeth_hdr *hdr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | int elements_needed = 0; |
| 4420 | enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO; |
| 4421 | struct qeth_eddp_context *ctx = NULL; |
Frank Pavlic | 95f6b5a | 2006-03-22 16:03:39 +0100 | [diff] [blame] | 4422 | int tx_bytes = skb->len; |
Serge E. Hallyn | 9c4b9a9 | 2006-07-10 04:45:17 -0700 | [diff] [blame] | 4423 | #ifdef CONFIG_QETH_PERF_STATS |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 4424 | unsigned short nr_frags = skb_shinfo(skb)->nr_frags; |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 4425 | unsigned short tso_size = skb_shinfo(skb)->gso_size; |
Serge E. Hallyn | 9c4b9a9 | 2006-07-10 04:45:17 -0700 | [diff] [blame] | 4426 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | int rc; |
| 4428 | |
| 4429 | QETH_DBF_TEXT(trace, 6, "sendpkt"); |
| 4430 | |
| 4431 | if (!card->options.layer2) { |
| 4432 | ipv = qeth_get_ip_version(skb); |
| 4433 | if ((card->dev->hard_header == qeth_fake_header) && ipv) { |
| 4434 | if ((skb = qeth_pskb_unshare(skb,GFP_ATOMIC)) == NULL) { |
| 4435 | card->stats.tx_dropped++; |
| 4436 | dev_kfree_skb_irq(skb); |
| 4437 | return 0; |
| 4438 | } |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4439 | if(card->dev->type == ARPHRD_IEEE802_TR){ |
| 4440 | skb_pull(skb, QETH_FAKE_LL_LEN_TR); |
| 4441 | } else { |
| 4442 | skb_pull(skb, QETH_FAKE_LL_LEN_ETH); |
| 4443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | } |
| 4445 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 4446 | if ((card->info.type == QETH_CARD_TYPE_OSN) && |
| 4447 | (skb->protocol == htons(ETH_P_IPV6))) { |
| 4448 | dev_kfree_skb_any(skb); |
| 4449 | return 0; |
| 4450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | cast_type = qeth_get_cast_type(card, skb); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 4452 | if ((cast_type == RTN_BROADCAST) && |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 4453 | (card->info.broadcast_capable == 0)){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | card->stats.tx_dropped++; |
| 4455 | card->stats.tx_errors++; |
| 4456 | dev_kfree_skb_any(skb); |
| 4457 | return NETDEV_TX_OK; |
| 4458 | } |
| 4459 | queue = card->qdio.out_qs |
| 4460 | [qeth_get_priority_queue(card, skb, ipv, cast_type)]; |
| 4461 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 4462 | if (skb_is_gso(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | large_send = card->options.large_send; |
| 4464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | /*are we able to do TSO ? If so ,prepare and send it from here */ |
| 4466 | if ((large_send == QETH_LARGE_SEND_TSO) && |
| 4467 | (cast_type == RTN_UNSPEC)) { |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4468 | rc = qeth_tso_prepare_packet(card, skb, ipv, cast_type); |
| 4469 | if (rc) { |
| 4470 | card->stats.tx_dropped++; |
| 4471 | card->stats.tx_errors++; |
| 4472 | dev_kfree_skb_any(skb); |
| 4473 | return NETDEV_TX_OK; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 4474 | } |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4475 | elements_needed++; |
| 4476 | } else { |
| 4477 | if ((rc = qeth_prepare_skb(card, &skb, &hdr, ipv))) { |
| 4478 | QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc); |
| 4479 | return rc; |
| 4480 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 4481 | if (card->info.type != QETH_CARD_TYPE_OSN) |
| 4482 | qeth_fill_header(card, hdr, skb, ipv, cast_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | } |
| 4484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | if (large_send == QETH_LARGE_SEND_EDDP) { |
| 4486 | ctx = qeth_eddp_create_context(card, skb, hdr); |
| 4487 | if (ctx == NULL) { |
| 4488 | PRINT_WARN("could not create eddp context\n"); |
| 4489 | return -EINVAL; |
| 4490 | } |
| 4491 | } else { |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4492 | int elems = qeth_get_elements_no(card,(void*) hdr, skb, |
| 4493 | elements_needed); |
| 4494 | if (!elems) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | return -EINVAL; |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4496 | elements_needed += elems; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | if (card->info.type != QETH_CARD_TYPE_IQD) |
| 4500 | rc = qeth_do_send_packet(card, queue, skb, hdr, |
| 4501 | elements_needed, ctx); |
| 4502 | else |
| 4503 | rc = qeth_do_send_packet_fast(card, queue, skb, hdr, |
| 4504 | elements_needed, ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | if (!rc){ |
| 4506 | card->stats.tx_packets++; |
Frank Pavlic | 95f6b5a | 2006-03-22 16:03:39 +0100 | [diff] [blame] | 4507 | card->stats.tx_bytes += tx_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | #ifdef CONFIG_QETH_PERF_STATS |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 4509 | if (tso_size && |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4510 | !(large_send == QETH_LARGE_SEND_NO)) { |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 4511 | card->perf_stats.large_send_bytes += tx_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | card->perf_stats.large_send_cnt++; |
| 4513 | } |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 4514 | if (nr_frags > 0){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | card->perf_stats.sg_skbs_sent++; |
| 4516 | /* nr_frags + skb->data */ |
| 4517 | card->perf_stats.sg_frags_sent += |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 4518 | nr_frags + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | } |
| 4520 | #endif /* CONFIG_QETH_PERF_STATS */ |
| 4521 | } |
| 4522 | if (ctx != NULL) { |
| 4523 | /* drop creator's reference */ |
| 4524 | qeth_eddp_put_context(ctx); |
| 4525 | /* free skb; it's not referenced by a buffer */ |
| 4526 | if (rc == 0) |
| 4527 | dev_kfree_skb_any(skb); |
| 4528 | |
| 4529 | } |
| 4530 | return rc; |
| 4531 | } |
| 4532 | |
| 4533 | static int |
| 4534 | qeth_mdio_read(struct net_device *dev, int phy_id, int regnum) |
| 4535 | { |
| 4536 | struct qeth_card *card = (struct qeth_card *) dev->priv; |
| 4537 | int rc = 0; |
| 4538 | |
| 4539 | switch(regnum){ |
| 4540 | case MII_BMCR: /* Basic mode control register */ |
| 4541 | rc = BMCR_FULLDPLX; |
| 4542 | if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&& |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 4543 | (card->info.link_type != QETH_LINK_TYPE_OSN) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH)) |
| 4545 | rc |= BMCR_SPEED100; |
| 4546 | break; |
| 4547 | case MII_BMSR: /* Basic mode status register */ |
| 4548 | rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS | |
| 4549 | BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL | |
| 4550 | BMSR_100BASE4; |
| 4551 | break; |
| 4552 | case MII_PHYSID1: /* PHYS ID 1 */ |
| 4553 | rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) | |
| 4554 | dev->dev_addr[2]; |
| 4555 | rc = (rc >> 5) & 0xFFFF; |
| 4556 | break; |
| 4557 | case MII_PHYSID2: /* PHYS ID 2 */ |
| 4558 | rc = (dev->dev_addr[2] << 10) & 0xFFFF; |
| 4559 | break; |
| 4560 | case MII_ADVERTISE: /* Advertisement control reg */ |
| 4561 | rc = ADVERTISE_ALL; |
| 4562 | break; |
| 4563 | case MII_LPA: /* Link partner ability reg */ |
| 4564 | rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL | |
| 4565 | LPA_100BASE4 | LPA_LPACK; |
| 4566 | break; |
| 4567 | case MII_EXPANSION: /* Expansion register */ |
| 4568 | break; |
| 4569 | case MII_DCOUNTER: /* disconnect counter */ |
| 4570 | break; |
| 4571 | case MII_FCSCOUNTER: /* false carrier counter */ |
| 4572 | break; |
| 4573 | case MII_NWAYTEST: /* N-way auto-neg test register */ |
| 4574 | break; |
| 4575 | case MII_RERRCOUNTER: /* rx error counter */ |
| 4576 | rc = card->stats.rx_errors; |
| 4577 | break; |
| 4578 | case MII_SREVISION: /* silicon revision */ |
| 4579 | break; |
| 4580 | case MII_RESV1: /* reserved 1 */ |
| 4581 | break; |
| 4582 | case MII_LBRERROR: /* loopback, rx, bypass error */ |
| 4583 | break; |
| 4584 | case MII_PHYADDR: /* physical address */ |
| 4585 | break; |
| 4586 | case MII_RESV2: /* reserved 2 */ |
| 4587 | break; |
| 4588 | case MII_TPISTATUS: /* TPI status for 10mbps */ |
| 4589 | break; |
| 4590 | case MII_NCONFIG: /* network interface config */ |
| 4591 | break; |
| 4592 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | break; |
| 4594 | } |
| 4595 | return rc; |
| 4596 | } |
| 4597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | |
| 4599 | static inline const char * |
| 4600 | qeth_arp_get_error_cause(int *rc) |
| 4601 | { |
| 4602 | switch (*rc) { |
| 4603 | case QETH_IPA_ARP_RC_FAILED: |
| 4604 | *rc = -EIO; |
| 4605 | return "operation failed"; |
| 4606 | case QETH_IPA_ARP_RC_NOTSUPP: |
| 4607 | *rc = -EOPNOTSUPP; |
| 4608 | return "operation not supported"; |
| 4609 | case QETH_IPA_ARP_RC_OUT_OF_RANGE: |
| 4610 | *rc = -EINVAL; |
| 4611 | return "argument out of range"; |
| 4612 | case QETH_IPA_ARP_RC_Q_NOTSUPP: |
| 4613 | *rc = -EOPNOTSUPP; |
| 4614 | return "query operation not supported"; |
| 4615 | case QETH_IPA_ARP_RC_Q_NO_DATA: |
| 4616 | *rc = -ENOENT; |
| 4617 | return "no query data available"; |
| 4618 | default: |
| 4619 | return "unknown error"; |
| 4620 | } |
| 4621 | } |
| 4622 | |
| 4623 | static int |
| 4624 | qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs, |
| 4625 | __u16, long); |
| 4626 | |
| 4627 | static int |
| 4628 | qeth_arp_set_no_entries(struct qeth_card *card, int no_entries) |
| 4629 | { |
| 4630 | int tmp; |
| 4631 | int rc; |
| 4632 | |
| 4633 | QETH_DBF_TEXT(trace,3,"arpstnoe"); |
| 4634 | |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 4635 | /* |
| 4636 | * currently GuestLAN only supports the ARP assist function |
| 4637 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES; |
| 4638 | * thus we say EOPNOTSUPP for this ARP function |
| 4639 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | if (card->info.guestlan) |
| 4641 | return -EOPNOTSUPP; |
| 4642 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 4643 | PRINT_WARN("ARP processing not supported " |
| 4644 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 4645 | return -EOPNOTSUPP; |
| 4646 | } |
| 4647 | rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
| 4648 | IPA_CMD_ASS_ARP_SET_NO_ENTRIES, |
| 4649 | no_entries); |
| 4650 | if (rc) { |
| 4651 | tmp = rc; |
| 4652 | PRINT_WARN("Could not set number of ARP entries on %s: " |
| 4653 | "%s (0x%x/%d)\n", |
| 4654 | QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc), |
| 4655 | tmp, tmp); |
| 4656 | } |
| 4657 | return rc; |
| 4658 | } |
| 4659 | |
| 4660 | static inline void |
| 4661 | qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo, |
| 4662 | struct qeth_arp_query_data *qdata, |
| 4663 | int entry_size, int uentry_size) |
| 4664 | { |
| 4665 | char *entry_ptr; |
| 4666 | char *uentry_ptr; |
| 4667 | int i; |
| 4668 | |
| 4669 | entry_ptr = (char *)&qdata->data; |
| 4670 | uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset); |
| 4671 | for (i = 0; i < qdata->no_entries; ++i){ |
| 4672 | /* strip off 32 bytes "media specific information" */ |
| 4673 | memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32); |
| 4674 | entry_ptr += entry_size; |
| 4675 | uentry_ptr += uentry_size; |
| 4676 | } |
| 4677 | } |
| 4678 | |
| 4679 | static int |
| 4680 | qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 4681 | unsigned long data) |
| 4682 | { |
| 4683 | struct qeth_ipa_cmd *cmd; |
| 4684 | struct qeth_arp_query_data *qdata; |
| 4685 | struct qeth_arp_query_info *qinfo; |
| 4686 | int entry_size; |
| 4687 | int uentry_size; |
| 4688 | int i; |
| 4689 | |
| 4690 | QETH_DBF_TEXT(trace,4,"arpquecb"); |
| 4691 | |
| 4692 | qinfo = (struct qeth_arp_query_info *) reply->param; |
| 4693 | cmd = (struct qeth_ipa_cmd *) data; |
| 4694 | if (cmd->hdr.return_code) { |
| 4695 | QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code); |
| 4696 | return 0; |
| 4697 | } |
| 4698 | if (cmd->data.setassparms.hdr.return_code) { |
| 4699 | cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; |
| 4700 | QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code); |
| 4701 | return 0; |
| 4702 | } |
| 4703 | qdata = &cmd->data.setassparms.data.query_arp; |
| 4704 | switch(qdata->reply_bits){ |
| 4705 | case 5: |
| 4706 | uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5); |
| 4707 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 4708 | uentry_size = sizeof(struct qeth_arp_qi_entry5_short); |
| 4709 | break; |
| 4710 | case 7: |
| 4711 | /* fall through to default */ |
| 4712 | default: |
| 4713 | /* tr is the same as eth -> entry7 */ |
| 4714 | uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7); |
| 4715 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 4716 | uentry_size = sizeof(struct qeth_arp_qi_entry7_short); |
| 4717 | break; |
| 4718 | } |
| 4719 | /* check if there is enough room in userspace */ |
| 4720 | if ((qinfo->udata_len - qinfo->udata_offset) < |
| 4721 | qdata->no_entries * uentry_size){ |
| 4722 | QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM); |
| 4723 | cmd->hdr.return_code = -ENOMEM; |
| 4724 | PRINT_WARN("query ARP user space buffer is too small for " |
| 4725 | "the returned number of ARP entries. " |
| 4726 | "Aborting query!\n"); |
| 4727 | goto out_error; |
| 4728 | } |
| 4729 | QETH_DBF_TEXT_(trace, 4, "anore%i", |
| 4730 | cmd->data.setassparms.hdr.number_of_replies); |
| 4731 | QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no); |
| 4732 | QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries); |
| 4733 | |
| 4734 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) { |
| 4735 | /* strip off "media specific information" */ |
| 4736 | qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size, |
| 4737 | uentry_size); |
| 4738 | } else |
| 4739 | /*copy entries to user buffer*/ |
| 4740 | memcpy(qinfo->udata + qinfo->udata_offset, |
| 4741 | (char *)&qdata->data, qdata->no_entries*uentry_size); |
| 4742 | |
| 4743 | qinfo->no_entries += qdata->no_entries; |
| 4744 | qinfo->udata_offset += (qdata->no_entries*uentry_size); |
| 4745 | /* check if all replies received ... */ |
| 4746 | if (cmd->data.setassparms.hdr.seq_no < |
| 4747 | cmd->data.setassparms.hdr.number_of_replies) |
| 4748 | return 1; |
| 4749 | memcpy(qinfo->udata, &qinfo->no_entries, 4); |
| 4750 | /* keep STRIP_ENTRIES flag so the user program can distinguish |
| 4751 | * stripped entries from normal ones */ |
| 4752 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 4753 | qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES; |
| 4754 | memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2); |
| 4755 | return 0; |
| 4756 | out_error: |
| 4757 | i = 0; |
| 4758 | memcpy(qinfo->udata, &i, 4); |
| 4759 | return 0; |
| 4760 | } |
| 4761 | |
| 4762 | static int |
| 4763 | qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 4764 | int len, int (*reply_cb)(struct qeth_card *, |
| 4765 | struct qeth_reply *, |
| 4766 | unsigned long), |
| 4767 | void *reply_param) |
| 4768 | { |
| 4769 | QETH_DBF_TEXT(trace,4,"sendarp"); |
| 4770 | |
| 4771 | memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE); |
| 4772 | memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data), |
| 4773 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 4774 | return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob, |
| 4775 | reply_cb, reply_param); |
| 4776 | } |
| 4777 | |
| 4778 | static int |
| 4779 | qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 4780 | int len, int (*reply_cb)(struct qeth_card *, |
| 4781 | struct qeth_reply *, |
| 4782 | unsigned long), |
| 4783 | void *reply_param) |
| 4784 | { |
| 4785 | u16 s1, s2; |
| 4786 | |
| 4787 | QETH_DBF_TEXT(trace,4,"sendsnmp"); |
| 4788 | |
| 4789 | memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE); |
| 4790 | memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data), |
| 4791 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 4792 | /* adjust PDU length fields in IPA_PDU_HEADER */ |
| 4793 | s1 = (u32) IPA_PDU_HEADER_SIZE + len; |
| 4794 | s2 = (u32) len; |
| 4795 | memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); |
| 4796 | memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); |
| 4797 | memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); |
| 4798 | memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); |
| 4799 | return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob, |
| 4800 | reply_cb, reply_param); |
| 4801 | } |
| 4802 | |
| 4803 | static struct qeth_cmd_buffer * |
| 4804 | qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs, |
| 4805 | __u16, __u16, enum qeth_prot_versions); |
| 4806 | static int |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 4807 | qeth_arp_query(struct qeth_card *card, char __user *udata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | { |
| 4809 | struct qeth_cmd_buffer *iob; |
| 4810 | struct qeth_arp_query_info qinfo = {0, }; |
| 4811 | int tmp; |
| 4812 | int rc; |
| 4813 | |
| 4814 | QETH_DBF_TEXT(trace,3,"arpquery"); |
| 4815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/ |
| 4817 | IPA_ARP_PROCESSING)) { |
| 4818 | PRINT_WARN("ARP processing not supported " |
| 4819 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 4820 | return -EOPNOTSUPP; |
| 4821 | } |
| 4822 | /* get size of userspace buffer and mask_bits -> 6 bytes */ |
| 4823 | if (copy_from_user(&qinfo, udata, 6)) |
| 4824 | return -EFAULT; |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 4825 | if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET; |
| 4828 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 4829 | IPA_CMD_ASS_ARP_QUERY_INFO, |
| 4830 | sizeof(int),QETH_PROT_IPV4); |
| 4831 | |
| 4832 | rc = qeth_send_ipa_arp_cmd(card, iob, |
| 4833 | QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN, |
| 4834 | qeth_arp_query_cb, (void *)&qinfo); |
| 4835 | if (rc) { |
| 4836 | tmp = rc; |
| 4837 | PRINT_WARN("Error while querying ARP cache on %s: %s " |
| 4838 | "(0x%x/%d)\n", |
| 4839 | QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc), |
| 4840 | tmp, tmp); |
| 4841 | copy_to_user(udata, qinfo.udata, 4); |
| 4842 | } else { |
| 4843 | copy_to_user(udata, qinfo.udata, qinfo.udata_len); |
| 4844 | } |
| 4845 | kfree(qinfo.udata); |
| 4846 | return rc; |
| 4847 | } |
| 4848 | |
| 4849 | /** |
| 4850 | * SNMP command callback |
| 4851 | */ |
| 4852 | static int |
| 4853 | qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 4854 | unsigned long sdata) |
| 4855 | { |
| 4856 | struct qeth_ipa_cmd *cmd; |
| 4857 | struct qeth_arp_query_info *qinfo; |
| 4858 | struct qeth_snmp_cmd *snmp; |
| 4859 | unsigned char *data; |
| 4860 | __u16 data_len; |
| 4861 | |
| 4862 | QETH_DBF_TEXT(trace,3,"snpcmdcb"); |
| 4863 | |
| 4864 | cmd = (struct qeth_ipa_cmd *) sdata; |
| 4865 | data = (unsigned char *)((char *)cmd - reply->offset); |
| 4866 | qinfo = (struct qeth_arp_query_info *) reply->param; |
| 4867 | snmp = &cmd->data.setadapterparms.data.snmp; |
| 4868 | |
| 4869 | if (cmd->hdr.return_code) { |
| 4870 | QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code); |
| 4871 | return 0; |
| 4872 | } |
| 4873 | if (cmd->data.setadapterparms.hdr.return_code) { |
| 4874 | cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code; |
| 4875 | QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code); |
| 4876 | return 0; |
| 4877 | } |
| 4878 | data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data)); |
| 4879 | if (cmd->data.setadapterparms.hdr.seq_no == 1) |
| 4880 | data_len -= (__u16)((char *)&snmp->data - (char *)cmd); |
| 4881 | else |
| 4882 | data_len -= (__u16)((char*)&snmp->request - (char *)cmd); |
| 4883 | |
| 4884 | /* check if there is enough room in userspace */ |
| 4885 | if ((qinfo->udata_len - qinfo->udata_offset) < data_len) { |
| 4886 | QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM); |
| 4887 | cmd->hdr.return_code = -ENOMEM; |
| 4888 | return 0; |
| 4889 | } |
| 4890 | QETH_DBF_TEXT_(trace, 4, "snore%i", |
| 4891 | cmd->data.setadapterparms.hdr.used_total); |
| 4892 | QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no); |
| 4893 | /*copy entries to user buffer*/ |
| 4894 | if (cmd->data.setadapterparms.hdr.seq_no == 1) { |
| 4895 | memcpy(qinfo->udata + qinfo->udata_offset, |
| 4896 | (char *)snmp, |
| 4897 | data_len + offsetof(struct qeth_snmp_cmd,data)); |
| 4898 | qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data); |
| 4899 | } else { |
| 4900 | memcpy(qinfo->udata + qinfo->udata_offset, |
| 4901 | (char *)&snmp->request, data_len); |
| 4902 | } |
| 4903 | qinfo->udata_offset += data_len; |
| 4904 | /* check if all replies received ... */ |
| 4905 | QETH_DBF_TEXT_(trace, 4, "srtot%i", |
| 4906 | cmd->data.setadapterparms.hdr.used_total); |
| 4907 | QETH_DBF_TEXT_(trace, 4, "srseq%i", |
| 4908 | cmd->data.setadapterparms.hdr.seq_no); |
| 4909 | if (cmd->data.setadapterparms.hdr.seq_no < |
| 4910 | cmd->data.setadapterparms.hdr.used_total) |
| 4911 | return 1; |
| 4912 | return 0; |
| 4913 | } |
| 4914 | |
| 4915 | static struct qeth_cmd_buffer * |
| 4916 | qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds, |
| 4917 | enum qeth_prot_versions ); |
| 4918 | |
| 4919 | static struct qeth_cmd_buffer * |
| 4920 | qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen) |
| 4921 | { |
| 4922 | struct qeth_cmd_buffer *iob; |
| 4923 | struct qeth_ipa_cmd *cmd; |
| 4924 | |
| 4925 | iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS, |
| 4926 | QETH_PROT_IPV4); |
| 4927 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 4928 | cmd->data.setadapterparms.hdr.cmdlength = cmdlen; |
| 4929 | cmd->data.setadapterparms.hdr.command_code = command; |
| 4930 | cmd->data.setadapterparms.hdr.used_total = 1; |
| 4931 | cmd->data.setadapterparms.hdr.seq_no = 1; |
| 4932 | |
| 4933 | return iob; |
| 4934 | } |
| 4935 | |
| 4936 | /** |
| 4937 | * function to send SNMP commands to OSA-E card |
| 4938 | */ |
| 4939 | static int |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 4940 | qeth_snmp_command(struct qeth_card *card, char __user *udata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | { |
| 4942 | struct qeth_cmd_buffer *iob; |
| 4943 | struct qeth_ipa_cmd *cmd; |
| 4944 | struct qeth_snmp_ureq *ureq; |
| 4945 | int req_len; |
| 4946 | struct qeth_arp_query_info qinfo = {0, }; |
| 4947 | int rc = 0; |
| 4948 | |
| 4949 | QETH_DBF_TEXT(trace,3,"snmpcmd"); |
| 4950 | |
| 4951 | if (card->info.guestlan) |
| 4952 | return -EOPNOTSUPP; |
| 4953 | |
| 4954 | if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) && |
| 4955 | (!card->options.layer2) ) { |
| 4956 | PRINT_WARN("SNMP Query MIBS not supported " |
| 4957 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 4958 | return -EOPNOTSUPP; |
| 4959 | } |
| 4960 | /* skip 4 bytes (data_len struct member) to get req_len */ |
| 4961 | if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int))) |
| 4962 | return -EFAULT; |
| 4963 | ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL); |
| 4964 | if (!ureq) { |
| 4965 | QETH_DBF_TEXT(trace, 2, "snmpnome"); |
| 4966 | return -ENOMEM; |
| 4967 | } |
| 4968 | if (copy_from_user(ureq, udata, |
| 4969 | req_len+sizeof(struct qeth_snmp_ureq_hdr))){ |
| 4970 | kfree(ureq); |
| 4971 | return -EFAULT; |
| 4972 | } |
| 4973 | qinfo.udata_len = ureq->hdr.data_len; |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 4974 | if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | kfree(ureq); |
| 4976 | return -ENOMEM; |
| 4977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr); |
| 4979 | |
| 4980 | iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL, |
| 4981 | QETH_SNMP_SETADP_CMDLENGTH + req_len); |
| 4982 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 4983 | memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len); |
| 4984 | rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len, |
| 4985 | qeth_snmp_command_cb, (void *)&qinfo); |
| 4986 | if (rc) |
| 4987 | PRINT_WARN("SNMP command failed on %s: (0x%x)\n", |
| 4988 | QETH_CARD_IFNAME(card), rc); |
| 4989 | else |
| 4990 | copy_to_user(udata, qinfo.udata, qinfo.udata_len); |
| 4991 | |
| 4992 | kfree(ureq); |
| 4993 | kfree(qinfo.udata); |
| 4994 | return rc; |
| 4995 | } |
| 4996 | |
| 4997 | static int |
| 4998 | qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *, |
| 4999 | unsigned long); |
| 5000 | |
| 5001 | static int |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5002 | qeth_default_setadapterparms_cb(struct qeth_card *card, |
| 5003 | struct qeth_reply *reply, |
| 5004 | unsigned long data); |
| 5005 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *, |
| 5007 | __u16, long, |
| 5008 | int (*reply_cb) |
| 5009 | (struct qeth_card *, struct qeth_reply *, unsigned long), |
| 5010 | void *reply_param); |
| 5011 | |
| 5012 | static int |
| 5013 | qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry) |
| 5014 | { |
| 5015 | struct qeth_cmd_buffer *iob; |
| 5016 | char buf[16]; |
| 5017 | int tmp; |
| 5018 | int rc; |
| 5019 | |
| 5020 | QETH_DBF_TEXT(trace,3,"arpadent"); |
| 5021 | |
| 5022 | /* |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 5023 | * currently GuestLAN only supports the ARP assist function |
| 5024 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY; |
| 5025 | * thus we say EOPNOTSUPP for this ARP function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | */ |
| 5027 | if (card->info.guestlan) |
| 5028 | return -EOPNOTSUPP; |
| 5029 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 5030 | PRINT_WARN("ARP processing not supported " |
| 5031 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 5032 | return -EOPNOTSUPP; |
| 5033 | } |
| 5034 | |
| 5035 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 5036 | IPA_CMD_ASS_ARP_ADD_ENTRY, |
| 5037 | sizeof(struct qeth_arp_cache_entry), |
| 5038 | QETH_PROT_IPV4); |
| 5039 | rc = qeth_send_setassparms(card, iob, |
| 5040 | sizeof(struct qeth_arp_cache_entry), |
| 5041 | (unsigned long) entry, |
| 5042 | qeth_default_setassparms_cb, NULL); |
| 5043 | if (rc) { |
| 5044 | tmp = rc; |
| 5045 | qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf); |
| 5046 | PRINT_WARN("Could not add ARP entry for address %s on %s: " |
| 5047 | "%s (0x%x/%d)\n", |
| 5048 | buf, QETH_CARD_IFNAME(card), |
| 5049 | qeth_arp_get_error_cause(&rc), tmp, tmp); |
| 5050 | } |
| 5051 | return rc; |
| 5052 | } |
| 5053 | |
| 5054 | static int |
| 5055 | qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry) |
| 5056 | { |
| 5057 | struct qeth_cmd_buffer *iob; |
| 5058 | char buf[16] = {0, }; |
| 5059 | int tmp; |
| 5060 | int rc; |
| 5061 | |
| 5062 | QETH_DBF_TEXT(trace,3,"arprment"); |
| 5063 | |
| 5064 | /* |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 5065 | * currently GuestLAN only supports the ARP assist function |
| 5066 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY; |
| 5067 | * thus we say EOPNOTSUPP for this ARP function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | */ |
| 5069 | if (card->info.guestlan) |
| 5070 | return -EOPNOTSUPP; |
| 5071 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 5072 | PRINT_WARN("ARP processing not supported " |
| 5073 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 5074 | return -EOPNOTSUPP; |
| 5075 | } |
| 5076 | memcpy(buf, entry, 12); |
| 5077 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 5078 | IPA_CMD_ASS_ARP_REMOVE_ENTRY, |
| 5079 | 12, |
| 5080 | QETH_PROT_IPV4); |
| 5081 | rc = qeth_send_setassparms(card, iob, |
| 5082 | 12, (unsigned long)buf, |
| 5083 | qeth_default_setassparms_cb, NULL); |
| 5084 | if (rc) { |
| 5085 | tmp = rc; |
| 5086 | memset(buf, 0, 16); |
| 5087 | qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf); |
| 5088 | PRINT_WARN("Could not delete ARP entry for address %s on %s: " |
| 5089 | "%s (0x%x/%d)\n", |
| 5090 | buf, QETH_CARD_IFNAME(card), |
| 5091 | qeth_arp_get_error_cause(&rc), tmp, tmp); |
| 5092 | } |
| 5093 | return rc; |
| 5094 | } |
| 5095 | |
| 5096 | static int |
| 5097 | qeth_arp_flush_cache(struct qeth_card *card) |
| 5098 | { |
| 5099 | int rc; |
| 5100 | int tmp; |
| 5101 | |
| 5102 | QETH_DBF_TEXT(trace,3,"arpflush"); |
| 5103 | |
| 5104 | /* |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 5105 | * currently GuestLAN only supports the ARP assist function |
| 5106 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE; |
| 5107 | * thus we say EOPNOTSUPP for this ARP function |
| 5108 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5109 | if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD)) |
| 5110 | return -EOPNOTSUPP; |
| 5111 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 5112 | PRINT_WARN("ARP processing not supported " |
| 5113 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 5114 | return -EOPNOTSUPP; |
| 5115 | } |
| 5116 | rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
| 5117 | IPA_CMD_ASS_ARP_FLUSH_CACHE, 0); |
| 5118 | if (rc){ |
| 5119 | tmp = rc; |
| 5120 | PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n", |
| 5121 | QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc), |
| 5122 | tmp, tmp); |
| 5123 | } |
| 5124 | return rc; |
| 5125 | } |
| 5126 | |
| 5127 | static int |
| 5128 | qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 5129 | { |
| 5130 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 5131 | struct qeth_arp_cache_entry arp_entry; |
| 5132 | struct mii_ioctl_data *mii_data; |
| 5133 | int rc = 0; |
| 5134 | |
| 5135 | if (!card) |
| 5136 | return -ENODEV; |
| 5137 | |
| 5138 | if ((card->state != CARD_STATE_UP) && |
| 5139 | (card->state != CARD_STATE_SOFTSETUP)) |
| 5140 | return -ENODEV; |
| 5141 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 5142 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 5143 | return -EPERM; |
| 5144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | switch (cmd){ |
| 5146 | case SIOC_QETH_ARP_SET_NO_ENTRIES: |
| 5147 | if ( !capable(CAP_NET_ADMIN) || |
| 5148 | (card->options.layer2) ) { |
| 5149 | rc = -EPERM; |
| 5150 | break; |
| 5151 | } |
| 5152 | rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue); |
| 5153 | break; |
| 5154 | case SIOC_QETH_ARP_QUERY_INFO: |
| 5155 | if ( !capable(CAP_NET_ADMIN) || |
| 5156 | (card->options.layer2) ) { |
| 5157 | rc = -EPERM; |
| 5158 | break; |
| 5159 | } |
| 5160 | rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data); |
| 5161 | break; |
| 5162 | case SIOC_QETH_ARP_ADD_ENTRY: |
| 5163 | if ( !capable(CAP_NET_ADMIN) || |
| 5164 | (card->options.layer2) ) { |
| 5165 | rc = -EPERM; |
| 5166 | break; |
| 5167 | } |
| 5168 | if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data, |
| 5169 | sizeof(struct qeth_arp_cache_entry))) |
| 5170 | rc = -EFAULT; |
| 5171 | else |
| 5172 | rc = qeth_arp_add_entry(card, &arp_entry); |
| 5173 | break; |
| 5174 | case SIOC_QETH_ARP_REMOVE_ENTRY: |
| 5175 | if ( !capable(CAP_NET_ADMIN) || |
| 5176 | (card->options.layer2) ) { |
| 5177 | rc = -EPERM; |
| 5178 | break; |
| 5179 | } |
| 5180 | if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data, |
| 5181 | sizeof(struct qeth_arp_cache_entry))) |
| 5182 | rc = -EFAULT; |
| 5183 | else |
| 5184 | rc = qeth_arp_remove_entry(card, &arp_entry); |
| 5185 | break; |
| 5186 | case SIOC_QETH_ARP_FLUSH_CACHE: |
| 5187 | if ( !capable(CAP_NET_ADMIN) || |
| 5188 | (card->options.layer2) ) { |
| 5189 | rc = -EPERM; |
| 5190 | break; |
| 5191 | } |
| 5192 | rc = qeth_arp_flush_cache(card); |
| 5193 | break; |
| 5194 | case SIOC_QETH_ADP_SET_SNMP_CONTROL: |
| 5195 | rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data); |
| 5196 | break; |
| 5197 | case SIOC_QETH_GET_CARD_TYPE: |
| 5198 | if ((card->info.type == QETH_CARD_TYPE_OSAE) && |
| 5199 | !card->info.guestlan) |
| 5200 | return 1; |
| 5201 | return 0; |
| 5202 | break; |
| 5203 | case SIOCGMIIPHY: |
| 5204 | mii_data = if_mii(rq); |
| 5205 | mii_data->phy_id = 0; |
| 5206 | break; |
| 5207 | case SIOCGMIIREG: |
| 5208 | mii_data = if_mii(rq); |
| 5209 | if (mii_data->phy_id != 0) |
| 5210 | rc = -EINVAL; |
| 5211 | else |
| 5212 | mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id, |
| 5213 | mii_data->reg_num); |
| 5214 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | default: |
| 5216 | rc = -EOPNOTSUPP; |
| 5217 | } |
| 5218 | if (rc) |
| 5219 | QETH_DBF_TEXT_(trace, 2, "ioce%d", rc); |
| 5220 | return rc; |
| 5221 | } |
| 5222 | |
| 5223 | static struct net_device_stats * |
| 5224 | qeth_get_stats(struct net_device *dev) |
| 5225 | { |
| 5226 | struct qeth_card *card; |
| 5227 | |
| 5228 | card = (struct qeth_card *) (dev->priv); |
| 5229 | |
| 5230 | QETH_DBF_TEXT(trace,5,"getstat"); |
| 5231 | |
| 5232 | return &card->stats; |
| 5233 | } |
| 5234 | |
| 5235 | static int |
| 5236 | qeth_change_mtu(struct net_device *dev, int new_mtu) |
| 5237 | { |
| 5238 | struct qeth_card *card; |
| 5239 | char dbf_text[15]; |
| 5240 | |
| 5241 | card = (struct qeth_card *) (dev->priv); |
| 5242 | |
| 5243 | QETH_DBF_TEXT(trace,4,"chgmtu"); |
| 5244 | sprintf(dbf_text, "%8x", new_mtu); |
| 5245 | QETH_DBF_TEXT(trace,4,dbf_text); |
| 5246 | |
| 5247 | if (new_mtu < 64) |
| 5248 | return -EINVAL; |
| 5249 | if (new_mtu > 65535) |
| 5250 | return -EINVAL; |
| 5251 | if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) && |
| 5252 | (!qeth_mtu_is_valid(card, new_mtu))) |
| 5253 | return -EINVAL; |
| 5254 | dev->mtu = new_mtu; |
| 5255 | return 0; |
| 5256 | } |
| 5257 | |
| 5258 | #ifdef CONFIG_QETH_VLAN |
| 5259 | static void |
| 5260 | qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 5261 | { |
| 5262 | struct qeth_card *card; |
| 5263 | unsigned long flags; |
| 5264 | |
| 5265 | QETH_DBF_TEXT(trace,4,"vlanreg"); |
| 5266 | |
| 5267 | card = (struct qeth_card *) dev->priv; |
| 5268 | spin_lock_irqsave(&card->vlanlock, flags); |
| 5269 | card->vlangrp = grp; |
| 5270 | spin_unlock_irqrestore(&card->vlanlock, flags); |
| 5271 | } |
| 5272 | |
| 5273 | static inline void |
| 5274 | qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf, |
| 5275 | unsigned short vid) |
| 5276 | { |
| 5277 | int i; |
| 5278 | struct sk_buff *skb; |
| 5279 | struct sk_buff_head tmp_list; |
| 5280 | |
| 5281 | skb_queue_head_init(&tmp_list); |
Heiko Carstens | 91ebe2a | 2006-07-03 00:25:26 -0700 | [diff] [blame] | 5282 | lockdep_set_class(&tmp_list.lock, &qdio_out_skb_queue_key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5283 | for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){ |
| 5284 | while ((skb = skb_dequeue(&buf->skb_list))){ |
| 5285 | if (vlan_tx_tag_present(skb) && |
| 5286 | (vlan_tx_tag_get(skb) == vid)) { |
| 5287 | atomic_dec(&skb->users); |
| 5288 | dev_kfree_skb(skb); |
| 5289 | } else |
| 5290 | skb_queue_tail(&tmp_list, skb); |
| 5291 | } |
| 5292 | } |
| 5293 | while ((skb = skb_dequeue(&tmp_list))) |
| 5294 | skb_queue_tail(&buf->skb_list, skb); |
| 5295 | } |
| 5296 | |
| 5297 | static void |
| 5298 | qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid) |
| 5299 | { |
| 5300 | int i, j; |
| 5301 | |
| 5302 | QETH_DBF_TEXT(trace, 4, "frvlskbs"); |
| 5303 | for (i = 0; i < card->qdio.no_out_queues; ++i){ |
| 5304 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) |
| 5305 | qeth_free_vlan_buffer(card, &card->qdio. |
| 5306 | out_qs[i]->bufs[j], vid); |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | static void |
| 5311 | qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid) |
| 5312 | { |
| 5313 | struct in_device *in_dev; |
| 5314 | struct in_ifaddr *ifa; |
| 5315 | struct qeth_ipaddr *addr; |
| 5316 | |
| 5317 | QETH_DBF_TEXT(trace, 4, "frvaddr4"); |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | rcu_read_lock(); |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 5320 | in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | if (!in_dev) |
| 5322 | goto out; |
| 5323 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
| 5324 | addr = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 5325 | if (addr){ |
| 5326 | addr->u.a4.addr = ifa->ifa_address; |
| 5327 | addr->u.a4.mask = ifa->ifa_mask; |
| 5328 | addr->type = QETH_IP_TYPE_NORMAL; |
| 5329 | if (!qeth_delete_ip(card, addr)) |
| 5330 | kfree(addr); |
| 5331 | } |
| 5332 | } |
| 5333 | out: |
| 5334 | rcu_read_unlock(); |
| 5335 | } |
| 5336 | |
| 5337 | static void |
| 5338 | qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid) |
| 5339 | { |
| 5340 | #ifdef CONFIG_QETH_IPV6 |
| 5341 | struct inet6_dev *in6_dev; |
| 5342 | struct inet6_ifaddr *ifa; |
| 5343 | struct qeth_ipaddr *addr; |
| 5344 | |
| 5345 | QETH_DBF_TEXT(trace, 4, "frvaddr6"); |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5347 | in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]); |
| 5348 | if (!in6_dev) |
| 5349 | return; |
| 5350 | for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){ |
| 5351 | addr = qeth_get_addr_buffer(QETH_PROT_IPV6); |
| 5352 | if (addr){ |
| 5353 | memcpy(&addr->u.a6.addr, &ifa->addr, |
| 5354 | sizeof(struct in6_addr)); |
| 5355 | addr->u.a6.pfxlen = ifa->prefix_len; |
| 5356 | addr->type = QETH_IP_TYPE_NORMAL; |
| 5357 | if (!qeth_delete_ip(card, addr)) |
| 5358 | kfree(addr); |
| 5359 | } |
| 5360 | } |
| 5361 | in6_dev_put(in6_dev); |
| 5362 | #endif /* CONFIG_QETH_IPV6 */ |
| 5363 | } |
| 5364 | |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5365 | static void |
| 5366 | qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid) |
| 5367 | { |
| 5368 | if (card->options.layer2 || !card->vlangrp) |
| 5369 | return; |
| 5370 | qeth_free_vlan_addresses4(card, vid); |
| 5371 | qeth_free_vlan_addresses6(card, vid); |
| 5372 | } |
| 5373 | |
Frank Pavlic | 508cc2b | 2005-11-10 13:49:15 +0100 | [diff] [blame] | 5374 | static int |
| 5375 | qeth_layer2_send_setdelvlan_cb(struct qeth_card *card, |
| 5376 | struct qeth_reply *reply, |
| 5377 | unsigned long data) |
| 5378 | { |
| 5379 | struct qeth_ipa_cmd *cmd; |
| 5380 | |
| 5381 | QETH_DBF_TEXT(trace, 2, "L2sdvcb"); |
| 5382 | cmd = (struct qeth_ipa_cmd *) data; |
| 5383 | if (cmd->hdr.return_code) { |
| 5384 | PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. " |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5385 | "Continuing\n",cmd->data.setdelvlan.vlan_id, |
Frank Pavlic | 508cc2b | 2005-11-10 13:49:15 +0100 | [diff] [blame] | 5386 | QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
| 5387 | QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command); |
| 5388 | QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card)); |
| 5389 | QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code); |
| 5390 | } |
| 5391 | return 0; |
| 5392 | } |
| 5393 | |
| 5394 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5395 | qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i, |
| 5396 | enum qeth_ipa_cmds ipacmd) |
| 5397 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5398 | struct qeth_ipa_cmd *cmd; |
| 5399 | struct qeth_cmd_buffer *iob; |
| 5400 | |
| 5401 | QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd); |
| 5402 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
| 5403 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 5404 | cmd->data.setdelvlan.vlan_id = i; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5405 | return qeth_send_ipa_cmd(card, iob, |
Frank Pavlic | 508cc2b | 2005-11-10 13:49:15 +0100 | [diff] [blame] | 5406 | qeth_layer2_send_setdelvlan_cb, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | } |
| 5408 | |
| 5409 | static void |
| 5410 | qeth_layer2_process_vlans(struct qeth_card *card, int clear) |
| 5411 | { |
| 5412 | unsigned short i; |
| 5413 | |
| 5414 | QETH_DBF_TEXT(trace, 3, "L2prcvln"); |
| 5415 | |
| 5416 | if (!card->vlangrp) |
| 5417 | return; |
| 5418 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 5419 | if (card->vlangrp->vlan_devices[i] == NULL) |
| 5420 | continue; |
| 5421 | if (clear) |
| 5422 | qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN); |
| 5423 | else |
| 5424 | qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN); |
| 5425 | } |
| 5426 | } |
| 5427 | |
| 5428 | /*add_vid is layer 2 used only ....*/ |
| 5429 | static void |
| 5430 | qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) |
| 5431 | { |
| 5432 | struct qeth_card *card; |
| 5433 | |
| 5434 | QETH_DBF_TEXT_(trace, 4, "aid:%d", vid); |
| 5435 | |
| 5436 | card = (struct qeth_card *) dev->priv; |
| 5437 | if (!card->options.layer2) |
| 5438 | return; |
| 5439 | qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); |
| 5440 | } |
| 5441 | |
| 5442 | /*... kill_vid used for both modes*/ |
| 5443 | static void |
| 5444 | qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
| 5445 | { |
| 5446 | struct qeth_card *card; |
| 5447 | unsigned long flags; |
| 5448 | |
| 5449 | QETH_DBF_TEXT_(trace, 4, "kid:%d", vid); |
| 5450 | |
| 5451 | card = (struct qeth_card *) dev->priv; |
| 5452 | /* free all skbs for the vlan device */ |
| 5453 | qeth_free_vlan_skbs(card, vid); |
| 5454 | spin_lock_irqsave(&card->vlanlock, flags); |
| 5455 | /* unregister IP addresses of vlan device */ |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5456 | qeth_free_vlan_addresses(card, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5457 | if (card->vlangrp) |
| 5458 | card->vlangrp->vlan_devices[vid] = NULL; |
| 5459 | spin_unlock_irqrestore(&card->vlanlock, flags); |
| 5460 | if (card->options.layer2) |
| 5461 | qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); |
| 5462 | qeth_set_multicast_list(card->dev); |
| 5463 | } |
| 5464 | #endif |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5465 | /** |
| 5466 | * Examine hardware response to SET_PROMISC_MODE |
| 5467 | */ |
| 5468 | static int |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5469 | qeth_setadp_promisc_mode_cb(struct qeth_card *card, |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5470 | struct qeth_reply *reply, |
| 5471 | unsigned long data) |
| 5472 | { |
| 5473 | struct qeth_ipa_cmd *cmd; |
| 5474 | struct qeth_ipacmd_setadpparms *setparms; |
| 5475 | |
| 5476 | QETH_DBF_TEXT(trace,4,"prmadpcb"); |
| 5477 | |
| 5478 | cmd = (struct qeth_ipa_cmd *) data; |
| 5479 | setparms = &(cmd->data.setadapterparms); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5480 | |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5481 | qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5482 | if (cmd->hdr.return_code) { |
| 5483 | QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code); |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5484 | setparms->data.mode = SET_PROMISC_MODE_OFF; |
| 5485 | } |
| 5486 | card->info.promisc_mode = setparms->data.mode; |
| 5487 | return 0; |
| 5488 | } |
| 5489 | /* |
| 5490 | * Set promiscuous mode (on or off) (SET_PROMISC_MODE command) |
| 5491 | */ |
| 5492 | static void |
| 5493 | qeth_setadp_promisc_mode(struct qeth_card *card) |
| 5494 | { |
| 5495 | enum qeth_ipa_promisc_modes mode; |
| 5496 | struct net_device *dev = card->dev; |
| 5497 | struct qeth_cmd_buffer *iob; |
| 5498 | struct qeth_ipa_cmd *cmd; |
| 5499 | |
| 5500 | QETH_DBF_TEXT(trace, 4, "setprom"); |
| 5501 | |
| 5502 | if (((dev->flags & IFF_PROMISC) && |
| 5503 | (card->info.promisc_mode == SET_PROMISC_MODE_ON)) || |
| 5504 | (!(dev->flags & IFF_PROMISC) && |
| 5505 | (card->info.promisc_mode == SET_PROMISC_MODE_OFF))) |
| 5506 | return; |
| 5507 | mode = SET_PROMISC_MODE_OFF; |
| 5508 | if (dev->flags & IFF_PROMISC) |
| 5509 | mode = SET_PROMISC_MODE_ON; |
| 5510 | QETH_DBF_TEXT_(trace, 4, "mode:%x", mode); |
| 5511 | |
| 5512 | iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE, |
| 5513 | sizeof(struct qeth_ipacmd_setadpparms)); |
| 5514 | cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE); |
| 5515 | cmd->data.setadapterparms.data.mode = mode; |
| 5516 | qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL); |
| 5517 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | |
| 5519 | /** |
| 5520 | * set multicast address on card |
| 5521 | */ |
| 5522 | static void |
| 5523 | qeth_set_multicast_list(struct net_device *dev) |
| 5524 | { |
| 5525 | struct qeth_card *card = (struct qeth_card *) dev->priv; |
| 5526 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 5527 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 5528 | return ; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5529 | |
Frank Pavlic | 66cc5d5 | 2006-02-07 17:04:38 +0100 | [diff] [blame] | 5530 | QETH_DBF_TEXT(trace, 3, "setmulti"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | qeth_delete_mc_addresses(card); |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5532 | if (card->options.layer2) { |
| 5533 | qeth_layer2_add_multicast(card); |
| 5534 | goto out; |
| 5535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 | qeth_add_multicast_ipv4(card); |
| 5537 | #ifdef CONFIG_QETH_IPV6 |
| 5538 | qeth_add_multicast_ipv6(card); |
| 5539 | #endif |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5540 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 5542 | schedule_work(&card->kernel_thread_starter); |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5543 | if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
| 5544 | return; |
| 5545 | if (qeth_set_thread_start_bit(card, QETH_SET_PROMISC_MODE_THREAD)==0) |
| 5546 | schedule_work(&card->kernel_thread_starter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | static int |
| 5550 | qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np) |
| 5551 | { |
| 5552 | return 0; |
| 5553 | } |
| 5554 | |
| 5555 | static void |
| 5556 | qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev) |
| 5557 | { |
| 5558 | if (dev->type == ARPHRD_IEEE802_TR) |
| 5559 | ip_tr_mc_map(ipm, mac); |
| 5560 | else |
| 5561 | ip_eth_mc_map(ipm, mac); |
| 5562 | } |
| 5563 | |
| 5564 | static struct qeth_ipaddr * |
| 5565 | qeth_get_addr_buffer(enum qeth_prot_versions prot) |
| 5566 | { |
| 5567 | struct qeth_ipaddr *addr; |
| 5568 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 5569 | addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5570 | if (addr == NULL) { |
| 5571 | PRINT_WARN("Not enough memory to add address\n"); |
| 5572 | return NULL; |
| 5573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5574 | addr->type = QETH_IP_TYPE_NORMAL; |
| 5575 | addr->proto = prot; |
| 5576 | return addr; |
| 5577 | } |
| 5578 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 5579 | int |
| 5580 | qeth_osn_assist(struct net_device *dev, |
| 5581 | void *data, |
| 5582 | int data_len) |
| 5583 | { |
| 5584 | struct qeth_cmd_buffer *iob; |
| 5585 | struct qeth_card *card; |
| 5586 | int rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5587 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 5588 | QETH_DBF_TEXT(trace, 2, "osnsdmc"); |
| 5589 | if (!dev) |
| 5590 | return -ENODEV; |
| 5591 | card = (struct qeth_card *)dev->priv; |
| 5592 | if (!card) |
| 5593 | return -ENODEV; |
| 5594 | if ((card->state != CARD_STATE_UP) && |
| 5595 | (card->state != CARD_STATE_SOFTSETUP)) |
| 5596 | return -ENODEV; |
| 5597 | iob = qeth_wait_for_buffer(&card->write); |
| 5598 | memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len); |
| 5599 | rc = qeth_osn_send_ipa_cmd(card, iob, data_len); |
| 5600 | return rc; |
| 5601 | } |
| 5602 | |
| 5603 | static struct net_device * |
| 5604 | qeth_netdev_by_devno(unsigned char *read_dev_no) |
| 5605 | { |
| 5606 | struct qeth_card *card; |
| 5607 | struct net_device *ndev; |
| 5608 | unsigned char *readno; |
| 5609 | __u16 temp_dev_no, card_dev_no; |
| 5610 | char *endp; |
| 5611 | unsigned long flags; |
| 5612 | |
| 5613 | ndev = NULL; |
| 5614 | memcpy(&temp_dev_no, read_dev_no, 2); |
| 5615 | read_lock_irqsave(&qeth_card_list.rwlock, flags); |
| 5616 | list_for_each_entry(card, &qeth_card_list.list, list) { |
| 5617 | readno = CARD_RDEV_ID(card); |
| 5618 | readno += (strlen(readno) - 4); |
| 5619 | card_dev_no = simple_strtoul(readno, &endp, 16); |
| 5620 | if (card_dev_no == temp_dev_no) { |
| 5621 | ndev = card->dev; |
| 5622 | break; |
| 5623 | } |
| 5624 | } |
| 5625 | read_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 5626 | return ndev; |
| 5627 | } |
| 5628 | |
| 5629 | int |
| 5630 | qeth_osn_register(unsigned char *read_dev_no, |
| 5631 | struct net_device **dev, |
| 5632 | int (*assist_cb)(struct net_device *, void *), |
| 5633 | int (*data_cb)(struct sk_buff *)) |
| 5634 | { |
| 5635 | struct qeth_card * card; |
| 5636 | |
| 5637 | QETH_DBF_TEXT(trace, 2, "osnreg"); |
| 5638 | *dev = qeth_netdev_by_devno(read_dev_no); |
| 5639 | if (*dev == NULL) |
| 5640 | return -ENODEV; |
| 5641 | card = (struct qeth_card *)(*dev)->priv; |
| 5642 | if (!card) |
| 5643 | return -ENODEV; |
| 5644 | if ((assist_cb == NULL) || (data_cb == NULL)) |
| 5645 | return -EINVAL; |
| 5646 | card->osn_info.assist_cb = assist_cb; |
| 5647 | card->osn_info.data_cb = data_cb; |
| 5648 | return 0; |
| 5649 | } |
| 5650 | |
| 5651 | void |
| 5652 | qeth_osn_deregister(struct net_device * dev) |
| 5653 | { |
| 5654 | struct qeth_card *card; |
| 5655 | |
| 5656 | QETH_DBF_TEXT(trace, 2, "osndereg"); |
| 5657 | if (!dev) |
| 5658 | return; |
| 5659 | card = (struct qeth_card *)dev->priv; |
| 5660 | if (!card) |
| 5661 | return; |
| 5662 | card->osn_info.assist_cb = NULL; |
| 5663 | card->osn_info.data_cb = NULL; |
| 5664 | return; |
| 5665 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | static void |
| 5668 | qeth_delete_mc_addresses(struct qeth_card *card) |
| 5669 | { |
| 5670 | struct qeth_ipaddr *iptodo; |
| 5671 | unsigned long flags; |
| 5672 | |
| 5673 | QETH_DBF_TEXT(trace,4,"delmc"); |
| 5674 | iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 5675 | if (!iptodo) { |
| 5676 | QETH_DBF_TEXT(trace, 2, "dmcnomem"); |
| 5677 | return; |
| 5678 | } |
| 5679 | iptodo->type = QETH_IP_TYPE_DEL_ALL_MC; |
| 5680 | spin_lock_irqsave(&card->ip_lock, flags); |
| 5681 | if (!__qeth_insert_ip_todo(card, iptodo, 0)) |
| 5682 | kfree(iptodo); |
| 5683 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 5684 | } |
| 5685 | |
| 5686 | static inline void |
| 5687 | qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev) |
| 5688 | { |
| 5689 | struct qeth_ipaddr *ipm; |
| 5690 | struct ip_mc_list *im4; |
| 5691 | char buf[MAX_ADDR_LEN]; |
| 5692 | |
| 5693 | QETH_DBF_TEXT(trace,4,"addmc"); |
| 5694 | for (im4 = in4_dev->mc_list; im4; im4 = im4->next) { |
| 5695 | qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev); |
| 5696 | ipm = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 5697 | if (!ipm) |
| 5698 | continue; |
| 5699 | ipm->u.a4.addr = im4->multiaddr; |
| 5700 | memcpy(ipm->mac,buf,OSA_ADDR_LEN); |
| 5701 | ipm->is_multicast = 1; |
| 5702 | if (!qeth_add_ip(card,ipm)) |
| 5703 | kfree(ipm); |
| 5704 | } |
| 5705 | } |
| 5706 | |
| 5707 | static inline void |
| 5708 | qeth_add_vlan_mc(struct qeth_card *card) |
| 5709 | { |
| 5710 | #ifdef CONFIG_QETH_VLAN |
| 5711 | struct in_device *in_dev; |
| 5712 | struct vlan_group *vg; |
| 5713 | int i; |
| 5714 | |
| 5715 | QETH_DBF_TEXT(trace,4,"addmcvl"); |
| 5716 | if ( ((card->options.layer2 == 0) && |
| 5717 | (!qeth_is_supported(card,IPA_FULL_VLAN))) || |
| 5718 | (card->vlangrp == NULL) ) |
| 5719 | return ; |
| 5720 | |
| 5721 | vg = card->vlangrp; |
| 5722 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 5723 | if (vg->vlan_devices[i] == NULL || |
| 5724 | !(vg->vlan_devices[i]->flags & IFF_UP)) |
| 5725 | continue; |
| 5726 | in_dev = in_dev_get(vg->vlan_devices[i]); |
| 5727 | if (!in_dev) |
| 5728 | continue; |
| 5729 | read_lock(&in_dev->mc_list_lock); |
| 5730 | qeth_add_mc(card,in_dev); |
| 5731 | read_unlock(&in_dev->mc_list_lock); |
| 5732 | in_dev_put(in_dev); |
| 5733 | } |
| 5734 | #endif |
| 5735 | } |
| 5736 | |
| 5737 | static void |
| 5738 | qeth_add_multicast_ipv4(struct qeth_card *card) |
| 5739 | { |
| 5740 | struct in_device *in4_dev; |
| 5741 | |
| 5742 | QETH_DBF_TEXT(trace,4,"chkmcv4"); |
| 5743 | in4_dev = in_dev_get(card->dev); |
| 5744 | if (in4_dev == NULL) |
| 5745 | return; |
| 5746 | read_lock(&in4_dev->mc_list_lock); |
| 5747 | qeth_add_mc(card, in4_dev); |
| 5748 | qeth_add_vlan_mc(card); |
| 5749 | read_unlock(&in4_dev->mc_list_lock); |
| 5750 | in_dev_put(in4_dev); |
| 5751 | } |
| 5752 | |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5753 | static void |
| 5754 | qeth_layer2_add_multicast(struct qeth_card *card) |
| 5755 | { |
| 5756 | struct qeth_ipaddr *ipm; |
| 5757 | struct dev_mc_list *dm; |
| 5758 | |
| 5759 | QETH_DBF_TEXT(trace,4,"L2addmc"); |
| 5760 | for (dm = card->dev->mc_list; dm; dm = dm->next) { |
| 5761 | ipm = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 5762 | if (!ipm) |
| 5763 | continue; |
| 5764 | memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN); |
| 5765 | ipm->is_multicast = 1; |
| 5766 | if (!qeth_add_ip(card, ipm)) |
| 5767 | kfree(ipm); |
| 5768 | } |
| 5769 | } |
| 5770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | #ifdef CONFIG_QETH_IPV6 |
| 5772 | static inline void |
| 5773 | qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev) |
| 5774 | { |
| 5775 | struct qeth_ipaddr *ipm; |
| 5776 | struct ifmcaddr6 *im6; |
| 5777 | char buf[MAX_ADDR_LEN]; |
| 5778 | |
| 5779 | QETH_DBF_TEXT(trace,4,"addmc6"); |
| 5780 | for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) { |
| 5781 | ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0); |
| 5782 | ipm = qeth_get_addr_buffer(QETH_PROT_IPV6); |
| 5783 | if (!ipm) |
| 5784 | continue; |
| 5785 | ipm->is_multicast = 1; |
| 5786 | memcpy(ipm->mac,buf,OSA_ADDR_LEN); |
| 5787 | memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr, |
| 5788 | sizeof(struct in6_addr)); |
| 5789 | if (!qeth_add_ip(card,ipm)) |
| 5790 | kfree(ipm); |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | static inline void |
| 5795 | qeth_add_vlan_mc6(struct qeth_card *card) |
| 5796 | { |
| 5797 | #ifdef CONFIG_QETH_VLAN |
| 5798 | struct inet6_dev *in_dev; |
| 5799 | struct vlan_group *vg; |
| 5800 | int i; |
| 5801 | |
| 5802 | QETH_DBF_TEXT(trace,4,"admc6vl"); |
| 5803 | if ( ((card->options.layer2 == 0) && |
| 5804 | (!qeth_is_supported(card,IPA_FULL_VLAN))) || |
| 5805 | (card->vlangrp == NULL)) |
| 5806 | return ; |
| 5807 | |
| 5808 | vg = card->vlangrp; |
| 5809 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 5810 | if (vg->vlan_devices[i] == NULL || |
| 5811 | !(vg->vlan_devices[i]->flags & IFF_UP)) |
| 5812 | continue; |
| 5813 | in_dev = in6_dev_get(vg->vlan_devices[i]); |
| 5814 | if (!in_dev) |
| 5815 | continue; |
| 5816 | read_lock(&in_dev->lock); |
| 5817 | qeth_add_mc6(card,in_dev); |
| 5818 | read_unlock(&in_dev->lock); |
| 5819 | in6_dev_put(in_dev); |
| 5820 | } |
| 5821 | #endif /* CONFIG_QETH_VLAN */ |
| 5822 | } |
| 5823 | |
| 5824 | static void |
| 5825 | qeth_add_multicast_ipv6(struct qeth_card *card) |
| 5826 | { |
| 5827 | struct inet6_dev *in6_dev; |
| 5828 | |
| 5829 | QETH_DBF_TEXT(trace,4,"chkmcv6"); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5830 | if (!qeth_is_supported(card, IPA_IPV6)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5831 | return ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5832 | in6_dev = in6_dev_get(card->dev); |
| 5833 | if (in6_dev == NULL) |
| 5834 | return; |
| 5835 | read_lock(&in6_dev->lock); |
| 5836 | qeth_add_mc6(card, in6_dev); |
| 5837 | qeth_add_vlan_mc6(card); |
| 5838 | read_unlock(&in6_dev->lock); |
| 5839 | in6_dev_put(in6_dev); |
| 5840 | } |
| 5841 | #endif /* CONFIG_QETH_IPV6 */ |
| 5842 | |
| 5843 | static int |
| 5844 | qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac, |
| 5845 | enum qeth_ipa_cmds ipacmd, |
| 5846 | int (*reply_cb) (struct qeth_card *, |
| 5847 | struct qeth_reply*, |
| 5848 | unsigned long)) |
| 5849 | { |
| 5850 | struct qeth_ipa_cmd *cmd; |
| 5851 | struct qeth_cmd_buffer *iob; |
| 5852 | |
| 5853 | QETH_DBF_TEXT(trace, 2, "L2sdmac"); |
| 5854 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
| 5855 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 5856 | cmd->data.setdelmac.mac_length = OSA_ADDR_LEN; |
| 5857 | memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN); |
| 5858 | return qeth_send_ipa_cmd(card, iob, reply_cb, NULL); |
| 5859 | } |
| 5860 | |
| 5861 | static int |
| 5862 | qeth_layer2_send_setgroupmac_cb(struct qeth_card *card, |
| 5863 | struct qeth_reply *reply, |
| 5864 | unsigned long data) |
| 5865 | { |
| 5866 | struct qeth_ipa_cmd *cmd; |
| 5867 | __u8 *mac; |
| 5868 | |
| 5869 | QETH_DBF_TEXT(trace, 2, "L2Sgmacb"); |
| 5870 | cmd = (struct qeth_ipa_cmd *) data; |
| 5871 | mac = &cmd->data.setdelmac.mac[0]; |
| 5872 | /* MAC already registered, needed in couple/uncouple case */ |
| 5873 | if (cmd->hdr.return_code == 0x2005) { |
| 5874 | PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \ |
| 5875 | "already existing on %s \n", |
| 5876 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], |
| 5877 | QETH_CARD_IFNAME(card)); |
| 5878 | cmd->hdr.return_code = 0; |
| 5879 | } |
| 5880 | if (cmd->hdr.return_code) |
| 5881 | PRINT_ERR("Could not set group MAC " \ |
| 5882 | "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n", |
| 5883 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], |
| 5884 | QETH_CARD_IFNAME(card),cmd->hdr.return_code); |
| 5885 | return 0; |
| 5886 | } |
| 5887 | |
| 5888 | static int |
| 5889 | qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac) |
| 5890 | { |
| 5891 | QETH_DBF_TEXT(trace, 2, "L2Sgmac"); |
| 5892 | return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC, |
| 5893 | qeth_layer2_send_setgroupmac_cb); |
| 5894 | } |
| 5895 | |
| 5896 | static int |
| 5897 | qeth_layer2_send_delgroupmac_cb(struct qeth_card *card, |
| 5898 | struct qeth_reply *reply, |
| 5899 | unsigned long data) |
| 5900 | { |
| 5901 | struct qeth_ipa_cmd *cmd; |
| 5902 | __u8 *mac; |
| 5903 | |
| 5904 | QETH_DBF_TEXT(trace, 2, "L2Dgmacb"); |
| 5905 | cmd = (struct qeth_ipa_cmd *) data; |
| 5906 | mac = &cmd->data.setdelmac.mac[0]; |
| 5907 | if (cmd->hdr.return_code) |
| 5908 | PRINT_ERR("Could not delete group MAC " \ |
| 5909 | "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n", |
| 5910 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], |
| 5911 | QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
| 5912 | return 0; |
| 5913 | } |
| 5914 | |
| 5915 | static int |
| 5916 | qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac) |
| 5917 | { |
| 5918 | QETH_DBF_TEXT(trace, 2, "L2Dgmac"); |
| 5919 | return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC, |
| 5920 | qeth_layer2_send_delgroupmac_cb); |
| 5921 | } |
| 5922 | |
| 5923 | static int |
| 5924 | qeth_layer2_send_setmac_cb(struct qeth_card *card, |
| 5925 | struct qeth_reply *reply, |
| 5926 | unsigned long data) |
| 5927 | { |
| 5928 | struct qeth_ipa_cmd *cmd; |
| 5929 | |
| 5930 | QETH_DBF_TEXT(trace, 2, "L2Smaccb"); |
| 5931 | cmd = (struct qeth_ipa_cmd *) data; |
| 5932 | if (cmd->hdr.return_code) { |
| 5933 | QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code); |
| 5934 | PRINT_WARN("Error in registering MAC address on " \ |
| 5935 | "device %s: x%x\n", CARD_BUS_ID(card), |
| 5936 | cmd->hdr.return_code); |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 5937 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5938 | cmd->hdr.return_code = -EIO; |
| 5939 | } else { |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 5940 | card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac, |
| 5942 | OSA_ADDR_LEN); |
| 5943 | PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x " |
| 5944 | "successfully registered on device %s\n", |
| 5945 | card->dev->dev_addr[0], card->dev->dev_addr[1], |
| 5946 | card->dev->dev_addr[2], card->dev->dev_addr[3], |
| 5947 | card->dev->dev_addr[4], card->dev->dev_addr[5], |
| 5948 | card->dev->name); |
| 5949 | } |
| 5950 | return 0; |
| 5951 | } |
| 5952 | |
| 5953 | static int |
| 5954 | qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac) |
| 5955 | { |
| 5956 | QETH_DBF_TEXT(trace, 2, "L2Setmac"); |
| 5957 | return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC, |
| 5958 | qeth_layer2_send_setmac_cb); |
| 5959 | } |
| 5960 | |
| 5961 | static int |
| 5962 | qeth_layer2_send_delmac_cb(struct qeth_card *card, |
| 5963 | struct qeth_reply *reply, |
| 5964 | unsigned long data) |
| 5965 | { |
| 5966 | struct qeth_ipa_cmd *cmd; |
| 5967 | |
| 5968 | QETH_DBF_TEXT(trace, 2, "L2Dmaccb"); |
| 5969 | cmd = (struct qeth_ipa_cmd *) data; |
| 5970 | if (cmd->hdr.return_code) { |
| 5971 | PRINT_WARN("Error in deregistering MAC address on " \ |
| 5972 | "device %s: x%x\n", CARD_BUS_ID(card), |
| 5973 | cmd->hdr.return_code); |
| 5974 | QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code); |
| 5975 | cmd->hdr.return_code = -EIO; |
| 5976 | return 0; |
| 5977 | } |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 5978 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5979 | |
| 5980 | return 0; |
| 5981 | } |
| 5982 | static int |
| 5983 | qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac) |
| 5984 | { |
| 5985 | QETH_DBF_TEXT(trace, 2, "L2Delmac"); |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 5986 | if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | return 0; |
| 5988 | return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC, |
| 5989 | qeth_layer2_send_delmac_cb); |
| 5990 | } |
| 5991 | |
| 5992 | static int |
| 5993 | qeth_layer2_set_mac_address(struct net_device *dev, void *p) |
| 5994 | { |
| 5995 | struct sockaddr *addr = p; |
| 5996 | struct qeth_card *card; |
| 5997 | int rc = 0; |
| 5998 | |
| 5999 | QETH_DBF_TEXT(trace, 3, "setmac"); |
| 6000 | |
| 6001 | if (qeth_verify_dev(dev) != QETH_REAL_CARD) { |
| 6002 | QETH_DBF_TEXT(trace, 3, "setmcINV"); |
| 6003 | return -EOPNOTSUPP; |
| 6004 | } |
| 6005 | card = (struct qeth_card *) dev->priv; |
| 6006 | |
| 6007 | if (!card->options.layer2) { |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 6008 | PRINT_WARN("Setting MAC address on %s is not supported " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6009 | "in Layer 3 mode.\n", dev->name); |
| 6010 | QETH_DBF_TEXT(trace, 3, "setmcLY3"); |
| 6011 | return -EOPNOTSUPP; |
| 6012 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6013 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 6014 | PRINT_WARN("Setting MAC address on %s is not supported.\n", |
| 6015 | dev->name); |
| 6016 | QETH_DBF_TEXT(trace, 3, "setmcOSN"); |
| 6017 | return -EOPNOTSUPP; |
| 6018 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card)); |
| 6020 | QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN); |
| 6021 | rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]); |
| 6022 | if (!rc) |
| 6023 | rc = qeth_layer2_send_setmac(card, addr->sa_data); |
| 6024 | return rc; |
| 6025 | } |
| 6026 | |
| 6027 | static void |
| 6028 | qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd, |
| 6029 | __u8 command, enum qeth_prot_versions prot) |
| 6030 | { |
| 6031 | memset(cmd, 0, sizeof (struct qeth_ipa_cmd)); |
| 6032 | cmd->hdr.command = command; |
| 6033 | cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST; |
| 6034 | cmd->hdr.seqno = card->seqno.ipa; |
| 6035 | cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type); |
| 6036 | cmd->hdr.rel_adapter_no = (__u8) card->info.portno; |
| 6037 | if (card->options.layer2) |
| 6038 | cmd->hdr.prim_version_no = 2; |
| 6039 | else |
| 6040 | cmd->hdr.prim_version_no = 1; |
| 6041 | cmd->hdr.param_count = 1; |
| 6042 | cmd->hdr.prot_version = prot; |
| 6043 | cmd->hdr.ipa_supported = 0; |
| 6044 | cmd->hdr.ipa_enabled = 0; |
| 6045 | } |
| 6046 | |
| 6047 | static struct qeth_cmd_buffer * |
| 6048 | qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd, |
| 6049 | enum qeth_prot_versions prot) |
| 6050 | { |
| 6051 | struct qeth_cmd_buffer *iob; |
| 6052 | struct qeth_ipa_cmd *cmd; |
| 6053 | |
| 6054 | iob = qeth_wait_for_buffer(&card->write); |
| 6055 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6056 | qeth_fill_ipacmd_header(card, cmd, ipacmd, prot); |
| 6057 | |
| 6058 | return iob; |
| 6059 | } |
| 6060 | |
| 6061 | static int |
| 6062 | qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd) |
| 6063 | { |
| 6064 | int rc; |
| 6065 | struct qeth_cmd_buffer *iob; |
| 6066 | struct qeth_ipa_cmd *cmd; |
| 6067 | |
| 6068 | QETH_DBF_TEXT(trace,4,"setdelmc"); |
| 6069 | |
| 6070 | iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto); |
| 6071 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6072 | memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN); |
| 6073 | if (addr->proto == QETH_PROT_IPV6) |
| 6074 | memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr, |
| 6075 | sizeof(struct in6_addr)); |
| 6076 | else |
| 6077 | memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4); |
| 6078 | |
| 6079 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 6080 | |
| 6081 | return rc; |
| 6082 | } |
| 6083 | static inline void |
| 6084 | qeth_fill_netmask(u8 *netmask, unsigned int len) |
| 6085 | { |
| 6086 | int i,j; |
| 6087 | for (i=0;i<16;i++) { |
| 6088 | j=(len)-(i*8); |
| 6089 | if (j >= 8) |
| 6090 | netmask[i] = 0xff; |
| 6091 | else if (j > 0) |
| 6092 | netmask[i] = (u8)(0xFF00>>j); |
| 6093 | else |
| 6094 | netmask[i] = 0; |
| 6095 | } |
| 6096 | } |
| 6097 | |
| 6098 | static int |
| 6099 | qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr, |
| 6100 | int ipacmd, unsigned int flags) |
| 6101 | { |
| 6102 | int rc; |
| 6103 | struct qeth_cmd_buffer *iob; |
| 6104 | struct qeth_ipa_cmd *cmd; |
| 6105 | __u8 netmask[16]; |
| 6106 | |
| 6107 | QETH_DBF_TEXT(trace,4,"setdelip"); |
| 6108 | QETH_DBF_TEXT_(trace,4,"flags%02X", flags); |
| 6109 | |
| 6110 | iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto); |
| 6111 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6112 | if (addr->proto == QETH_PROT_IPV6) { |
| 6113 | memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr, |
| 6114 | sizeof(struct in6_addr)); |
| 6115 | qeth_fill_netmask(netmask,addr->u.a6.pfxlen); |
| 6116 | memcpy(cmd->data.setdelip6.mask, netmask, |
| 6117 | sizeof(struct in6_addr)); |
| 6118 | cmd->data.setdelip6.flags = flags; |
| 6119 | } else { |
| 6120 | memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4); |
| 6121 | memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4); |
| 6122 | cmd->data.setdelip4.flags = flags; |
| 6123 | } |
| 6124 | |
| 6125 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 6126 | |
| 6127 | return rc; |
| 6128 | } |
| 6129 | |
| 6130 | static int |
| 6131 | qeth_layer2_register_addr_entry(struct qeth_card *card, |
| 6132 | struct qeth_ipaddr *addr) |
| 6133 | { |
| 6134 | if (!addr->is_multicast) |
| 6135 | return 0; |
| 6136 | QETH_DBF_TEXT(trace, 2, "setgmac"); |
| 6137 | QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN); |
| 6138 | return qeth_layer2_send_setgroupmac(card, &addr->mac[0]); |
| 6139 | } |
| 6140 | |
| 6141 | static int |
| 6142 | qeth_layer2_deregister_addr_entry(struct qeth_card *card, |
| 6143 | struct qeth_ipaddr *addr) |
| 6144 | { |
| 6145 | if (!addr->is_multicast) |
| 6146 | return 0; |
| 6147 | QETH_DBF_TEXT(trace, 2, "delgmac"); |
| 6148 | QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN); |
| 6149 | return qeth_layer2_send_delgroupmac(card, &addr->mac[0]); |
| 6150 | } |
| 6151 | |
| 6152 | static int |
| 6153 | qeth_layer3_register_addr_entry(struct qeth_card *card, |
| 6154 | struct qeth_ipaddr *addr) |
| 6155 | { |
| 6156 | char buf[50]; |
| 6157 | int rc; |
| 6158 | int cnt = 3; |
| 6159 | |
| 6160 | if (addr->proto == QETH_PROT_IPV4) { |
| 6161 | QETH_DBF_TEXT(trace, 2,"setaddr4"); |
| 6162 | QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int)); |
| 6163 | } else if (addr->proto == QETH_PROT_IPV6) { |
| 6164 | QETH_DBF_TEXT(trace, 2, "setaddr6"); |
| 6165 | QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8); |
| 6166 | QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8); |
| 6167 | } else { |
| 6168 | QETH_DBF_TEXT(trace, 2, "setaddr?"); |
| 6169 | QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr)); |
| 6170 | } |
| 6171 | do { |
| 6172 | if (addr->is_multicast) |
| 6173 | rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM); |
| 6174 | else |
| 6175 | rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP, |
| 6176 | addr->set_flags); |
| 6177 | if (rc) |
| 6178 | QETH_DBF_TEXT(trace, 2, "failed"); |
| 6179 | } while ((--cnt > 0) && rc); |
| 6180 | if (rc){ |
| 6181 | QETH_DBF_TEXT(trace, 2, "FAILED"); |
| 6182 | qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf); |
| 6183 | PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n", |
| 6184 | buf, rc, rc); |
| 6185 | } |
| 6186 | return rc; |
| 6187 | } |
| 6188 | |
| 6189 | static int |
| 6190 | qeth_layer3_deregister_addr_entry(struct qeth_card *card, |
| 6191 | struct qeth_ipaddr *addr) |
| 6192 | { |
| 6193 | //char buf[50]; |
| 6194 | int rc; |
| 6195 | |
| 6196 | if (addr->proto == QETH_PROT_IPV4) { |
| 6197 | QETH_DBF_TEXT(trace, 2,"deladdr4"); |
| 6198 | QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int)); |
| 6199 | } else if (addr->proto == QETH_PROT_IPV6) { |
| 6200 | QETH_DBF_TEXT(trace, 2, "deladdr6"); |
| 6201 | QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8); |
| 6202 | QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8); |
| 6203 | } else { |
| 6204 | QETH_DBF_TEXT(trace, 2, "deladdr?"); |
| 6205 | QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr)); |
| 6206 | } |
| 6207 | if (addr->is_multicast) |
| 6208 | rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM); |
| 6209 | else |
| 6210 | rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP, |
| 6211 | addr->del_flags); |
| 6212 | if (rc) { |
| 6213 | QETH_DBF_TEXT(trace, 2, "failed"); |
| 6214 | /* TODO: re-activate this warning as soon as we have a |
| 6215 | * clean mirco code |
| 6216 | qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf); |
| 6217 | PRINT_WARN("Could not deregister IP address %s (rc=%x)\n", |
| 6218 | buf, rc); |
| 6219 | */ |
| 6220 | } |
| 6221 | return rc; |
| 6222 | } |
| 6223 | |
| 6224 | static int |
| 6225 | qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 6226 | { |
| 6227 | if (card->options.layer2) |
| 6228 | return qeth_layer2_register_addr_entry(card, addr); |
| 6229 | |
| 6230 | return qeth_layer3_register_addr_entry(card, addr); |
| 6231 | } |
| 6232 | |
| 6233 | static int |
| 6234 | qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 6235 | { |
| 6236 | if (card->options.layer2) |
| 6237 | return qeth_layer2_deregister_addr_entry(card, addr); |
| 6238 | |
| 6239 | return qeth_layer3_deregister_addr_entry(card, addr); |
| 6240 | } |
| 6241 | |
| 6242 | static u32 |
| 6243 | qeth_ethtool_get_tx_csum(struct net_device *dev) |
| 6244 | { |
| 6245 | /* We may need to say that we support tx csum offload if |
| 6246 | * we do EDDP or TSO. There are discussions going on to |
| 6247 | * enforce rules in the stack and in ethtool that make |
| 6248 | * SG and TSO depend on HW_CSUM. At the moment there are |
| 6249 | * no such rules.... |
| 6250 | * If we say yes here, we have to checksum outbound packets |
| 6251 | * any time. */ |
| 6252 | return 0; |
| 6253 | } |
| 6254 | |
| 6255 | static int |
| 6256 | qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data) |
| 6257 | { |
| 6258 | return -EINVAL; |
| 6259 | } |
| 6260 | |
| 6261 | static u32 |
| 6262 | qeth_ethtool_get_rx_csum(struct net_device *dev) |
| 6263 | { |
| 6264 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6265 | |
| 6266 | return (card->options.checksum_type == HW_CHECKSUMMING); |
| 6267 | } |
| 6268 | |
| 6269 | static int |
| 6270 | qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data) |
| 6271 | { |
| 6272 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6273 | |
| 6274 | if ((card->state != CARD_STATE_DOWN) && |
| 6275 | (card->state != CARD_STATE_RECOVER)) |
| 6276 | return -EPERM; |
| 6277 | if (data) |
| 6278 | card->options.checksum_type = HW_CHECKSUMMING; |
| 6279 | else |
| 6280 | card->options.checksum_type = SW_CHECKSUMMING; |
| 6281 | return 0; |
| 6282 | } |
| 6283 | |
| 6284 | static u32 |
| 6285 | qeth_ethtool_get_sg(struct net_device *dev) |
| 6286 | { |
| 6287 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6288 | |
| 6289 | return ((card->options.large_send != QETH_LARGE_SEND_NO) && |
| 6290 | (dev->features & NETIF_F_SG)); |
| 6291 | } |
| 6292 | |
| 6293 | static int |
| 6294 | qeth_ethtool_set_sg(struct net_device *dev, u32 data) |
| 6295 | { |
| 6296 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6297 | |
| 6298 | if (data) { |
| 6299 | if (card->options.large_send != QETH_LARGE_SEND_NO) |
| 6300 | dev->features |= NETIF_F_SG; |
| 6301 | else { |
| 6302 | dev->features &= ~NETIF_F_SG; |
| 6303 | return -EINVAL; |
| 6304 | } |
| 6305 | } else |
| 6306 | dev->features &= ~NETIF_F_SG; |
| 6307 | return 0; |
| 6308 | } |
| 6309 | |
| 6310 | static u32 |
| 6311 | qeth_ethtool_get_tso(struct net_device *dev) |
| 6312 | { |
| 6313 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6314 | |
| 6315 | return ((card->options.large_send != QETH_LARGE_SEND_NO) && |
| 6316 | (dev->features & NETIF_F_TSO)); |
| 6317 | } |
| 6318 | |
| 6319 | static int |
| 6320 | qeth_ethtool_set_tso(struct net_device *dev, u32 data) |
| 6321 | { |
| 6322 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6323 | |
| 6324 | if (data) { |
| 6325 | if (card->options.large_send != QETH_LARGE_SEND_NO) |
| 6326 | dev->features |= NETIF_F_TSO; |
| 6327 | else { |
| 6328 | dev->features &= ~NETIF_F_TSO; |
| 6329 | return -EINVAL; |
| 6330 | } |
| 6331 | } else |
| 6332 | dev->features &= ~NETIF_F_TSO; |
| 6333 | return 0; |
| 6334 | } |
| 6335 | |
| 6336 | static struct ethtool_ops qeth_ethtool_ops = { |
| 6337 | .get_tx_csum = qeth_ethtool_get_tx_csum, |
| 6338 | .set_tx_csum = qeth_ethtool_set_tx_csum, |
| 6339 | .get_rx_csum = qeth_ethtool_get_rx_csum, |
| 6340 | .set_rx_csum = qeth_ethtool_set_rx_csum, |
| 6341 | .get_sg = qeth_ethtool_get_sg, |
| 6342 | .set_sg = qeth_ethtool_set_sg, |
| 6343 | .get_tso = qeth_ethtool_get_tso, |
| 6344 | .set_tso = qeth_ethtool_set_tso, |
| 6345 | }; |
| 6346 | |
| 6347 | static int |
| 6348 | qeth_netdev_init(struct net_device *dev) |
| 6349 | { |
| 6350 | struct qeth_card *card; |
| 6351 | |
| 6352 | card = (struct qeth_card *) dev->priv; |
| 6353 | |
| 6354 | QETH_DBF_TEXT(trace,3,"initdev"); |
| 6355 | |
| 6356 | dev->tx_timeout = &qeth_tx_timeout; |
| 6357 | dev->watchdog_timeo = QETH_TX_TIMEOUT; |
| 6358 | dev->open = qeth_open; |
| 6359 | dev->stop = qeth_stop; |
| 6360 | dev->hard_start_xmit = qeth_hard_start_xmit; |
| 6361 | dev->do_ioctl = qeth_do_ioctl; |
| 6362 | dev->get_stats = qeth_get_stats; |
| 6363 | dev->change_mtu = qeth_change_mtu; |
| 6364 | dev->neigh_setup = qeth_neigh_setup; |
| 6365 | dev->set_multicast_list = qeth_set_multicast_list; |
| 6366 | #ifdef CONFIG_QETH_VLAN |
| 6367 | dev->vlan_rx_register = qeth_vlan_rx_register; |
| 6368 | dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid; |
| 6369 | dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid; |
| 6370 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6371 | if (qeth_get_netdev_flags(card) & IFF_NOARP) { |
| 6372 | dev->rebuild_header = NULL; |
| 6373 | dev->hard_header = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6374 | dev->header_cache_update = NULL; |
| 6375 | dev->hard_header_cache = NULL; |
| 6376 | } |
| 6377 | #ifdef CONFIG_QETH_IPV6 |
| 6378 | /*IPv6 address autoconfiguration stuff*/ |
| 6379 | if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD)) |
| 6380 | card->dev->dev_id = card->info.unique_id & 0xffff; |
| 6381 | #endif |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 6382 | if (card->options.fake_ll && |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 6383 | (qeth_get_netdev_flags(card) & IFF_NOARP)) |
| 6384 | dev->hard_header = qeth_fake_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6385 | dev->hard_header_parse = NULL; |
| 6386 | dev->set_mac_address = qeth_layer2_set_mac_address; |
| 6387 | dev->flags |= qeth_get_netdev_flags(card); |
| 6388 | if ((card->options.fake_broadcast) || |
| 6389 | (card->info.broadcast_capable)) |
| 6390 | dev->flags |= IFF_BROADCAST; |
| 6391 | dev->hard_header_len = |
| 6392 | qeth_get_hlen(card->info.link_type) + card->options.add_hhlen; |
| 6393 | dev->addr_len = OSA_ADDR_LEN; |
| 6394 | dev->mtu = card->info.initial_mtu; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6395 | if (card->info.type != QETH_CARD_TYPE_OSN) |
| 6396 | SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | SET_MODULE_OWNER(dev); |
| 6398 | return 0; |
| 6399 | } |
| 6400 | |
| 6401 | static void |
| 6402 | qeth_init_func_level(struct qeth_card *card) |
| 6403 | { |
| 6404 | if (card->ipato.enabled) { |
| 6405 | if (card->info.type == QETH_CARD_TYPE_IQD) |
| 6406 | card->info.func_level = |
| 6407 | QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT; |
| 6408 | else |
| 6409 | card->info.func_level = |
| 6410 | QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT; |
| 6411 | } else { |
| 6412 | if (card->info.type == QETH_CARD_TYPE_IQD) |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6413 | /*FIXME:why do we have same values for dis and ena for osae??? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6414 | card->info.func_level = |
| 6415 | QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT; |
| 6416 | else |
| 6417 | card->info.func_level = |
| 6418 | QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT; |
| 6419 | } |
| 6420 | } |
| 6421 | |
| 6422 | /** |
| 6423 | * hardsetup card, initialize MPC and QDIO stuff |
| 6424 | */ |
| 6425 | static int |
| 6426 | qeth_hardsetup_card(struct qeth_card *card) |
| 6427 | { |
| 6428 | int retries = 3; |
| 6429 | int rc; |
| 6430 | |
| 6431 | QETH_DBF_TEXT(setup, 2, "hrdsetup"); |
| 6432 | |
| 6433 | retry: |
| 6434 | if (retries < 3){ |
| 6435 | PRINT_WARN("Retrying to do IDX activates.\n"); |
| 6436 | ccw_device_set_offline(CARD_DDEV(card)); |
| 6437 | ccw_device_set_offline(CARD_WDEV(card)); |
| 6438 | ccw_device_set_offline(CARD_RDEV(card)); |
| 6439 | ccw_device_set_online(CARD_RDEV(card)); |
| 6440 | ccw_device_set_online(CARD_WDEV(card)); |
| 6441 | ccw_device_set_online(CARD_DDEV(card)); |
| 6442 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6443 | rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6444 | if (rc == -ERESTARTSYS) { |
| 6445 | QETH_DBF_TEXT(setup, 2, "break1"); |
| 6446 | return rc; |
| 6447 | } else if (rc) { |
| 6448 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 6449 | if (--retries < 0) |
| 6450 | goto out; |
| 6451 | else |
| 6452 | goto retry; |
| 6453 | } |
| 6454 | if ((rc = qeth_get_unitaddr(card))){ |
| 6455 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 6456 | return rc; |
| 6457 | } |
| 6458 | qeth_init_tokens(card); |
| 6459 | qeth_init_func_level(card); |
| 6460 | rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb); |
| 6461 | if (rc == -ERESTARTSYS) { |
| 6462 | QETH_DBF_TEXT(setup, 2, "break2"); |
| 6463 | return rc; |
| 6464 | } else if (rc) { |
| 6465 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
| 6466 | if (--retries < 0) |
| 6467 | goto out; |
| 6468 | else |
| 6469 | goto retry; |
| 6470 | } |
| 6471 | rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb); |
| 6472 | if (rc == -ERESTARTSYS) { |
| 6473 | QETH_DBF_TEXT(setup, 2, "break3"); |
| 6474 | return rc; |
| 6475 | } else if (rc) { |
| 6476 | QETH_DBF_TEXT_(setup, 2, "4err%d", rc); |
| 6477 | if (--retries < 0) |
| 6478 | goto out; |
| 6479 | else |
| 6480 | goto retry; |
| 6481 | } |
| 6482 | if ((rc = qeth_mpc_initialize(card))){ |
| 6483 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
| 6484 | goto out; |
| 6485 | } |
| 6486 | /*network device will be recovered*/ |
| 6487 | if (card->dev) { |
| 6488 | card->dev->hard_header = card->orig_hard_header; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 6489 | if (card->options.fake_ll && |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 6490 | (qeth_get_netdev_flags(card) & IFF_NOARP)) |
| 6491 | card->dev->hard_header = qeth_fake_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6492 | return 0; |
| 6493 | } |
| 6494 | /* at first set_online allocate netdev */ |
| 6495 | card->dev = qeth_get_netdevice(card->info.type, |
| 6496 | card->info.link_type); |
| 6497 | if (!card->dev){ |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6498 | qeth_qdio_clear_card(card, card->info.type != |
| 6499 | QETH_CARD_TYPE_IQD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6500 | rc = -ENODEV; |
| 6501 | QETH_DBF_TEXT_(setup, 2, "6err%d", rc); |
| 6502 | goto out; |
| 6503 | } |
| 6504 | card->dev->priv = card; |
| 6505 | card->orig_hard_header = card->dev->hard_header; |
| 6506 | card->dev->type = qeth_get_arphdr_type(card->info.type, |
| 6507 | card->info.link_type); |
| 6508 | card->dev->init = qeth_netdev_init; |
| 6509 | return 0; |
| 6510 | out: |
| 6511 | PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc); |
| 6512 | return rc; |
| 6513 | } |
| 6514 | |
| 6515 | static int |
| 6516 | qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 6517 | unsigned long data) |
| 6518 | { |
| 6519 | struct qeth_ipa_cmd *cmd; |
| 6520 | |
| 6521 | QETH_DBF_TEXT(trace,4,"defadpcb"); |
| 6522 | |
| 6523 | cmd = (struct qeth_ipa_cmd *) data; |
| 6524 | if (cmd->hdr.return_code == 0){ |
| 6525 | cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; |
| 6526 | if (cmd->hdr.prot_version == QETH_PROT_IPV4) |
| 6527 | card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled; |
| 6528 | #ifdef CONFIG_QETH_IPV6 |
| 6529 | if (cmd->hdr.prot_version == QETH_PROT_IPV6) |
| 6530 | card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled; |
| 6531 | #endif |
| 6532 | } |
| 6533 | if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM && |
| 6534 | cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) { |
| 6535 | card->info.csum_mask = cmd->data.setassparms.data.flags_32bit; |
| 6536 | QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask); |
| 6537 | } |
| 6538 | return 0; |
| 6539 | } |
| 6540 | |
| 6541 | static int |
| 6542 | qeth_default_setadapterparms_cb(struct qeth_card *card, |
| 6543 | struct qeth_reply *reply, |
| 6544 | unsigned long data) |
| 6545 | { |
| 6546 | struct qeth_ipa_cmd *cmd; |
| 6547 | |
| 6548 | QETH_DBF_TEXT(trace,4,"defadpcb"); |
| 6549 | |
| 6550 | cmd = (struct qeth_ipa_cmd *) data; |
| 6551 | if (cmd->hdr.return_code == 0) |
| 6552 | cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code; |
| 6553 | return 0; |
| 6554 | } |
| 6555 | |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 6556 | |
| 6557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6558 | static int |
| 6559 | qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 6560 | unsigned long data) |
| 6561 | { |
| 6562 | struct qeth_ipa_cmd *cmd; |
| 6563 | |
| 6564 | QETH_DBF_TEXT(trace,3,"quyadpcb"); |
| 6565 | |
| 6566 | cmd = (struct qeth_ipa_cmd *) data; |
| 6567 | if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f) |
| 6568 | card->info.link_type = |
| 6569 | cmd->data.setadapterparms.data.query_cmds_supp.lan_type; |
| 6570 | card->options.adp.supported_funcs = |
| 6571 | cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds; |
| 6572 | return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd); |
| 6573 | } |
| 6574 | |
| 6575 | static int |
| 6576 | qeth_query_setadapterparms(struct qeth_card *card) |
| 6577 | { |
| 6578 | int rc; |
| 6579 | struct qeth_cmd_buffer *iob; |
| 6580 | |
| 6581 | QETH_DBF_TEXT(trace,3,"queryadp"); |
| 6582 | iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED, |
| 6583 | sizeof(struct qeth_ipacmd_setadpparms)); |
| 6584 | rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL); |
| 6585 | return rc; |
| 6586 | } |
| 6587 | |
| 6588 | static int |
| 6589 | qeth_setadpparms_change_macaddr_cb(struct qeth_card *card, |
| 6590 | struct qeth_reply *reply, |
| 6591 | unsigned long data) |
| 6592 | { |
| 6593 | struct qeth_ipa_cmd *cmd; |
| 6594 | |
| 6595 | QETH_DBF_TEXT(trace,4,"chgmaccb"); |
| 6596 | |
| 6597 | cmd = (struct qeth_ipa_cmd *) data; |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 6598 | if (!card->options.layer2 || card->info.guestlan || |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 6599 | !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) { |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 6600 | memcpy(card->dev->dev_addr, |
| 6601 | &cmd->data.setadapterparms.data.change_addr.addr, |
| 6602 | OSA_ADDR_LEN); |
| 6603 | card->info.mac_bits |= QETH_LAYER2_MAC_READ; |
| 6604 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6605 | qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd); |
| 6606 | return 0; |
| 6607 | } |
| 6608 | |
| 6609 | static int |
| 6610 | qeth_setadpparms_change_macaddr(struct qeth_card *card) |
| 6611 | { |
| 6612 | int rc; |
| 6613 | struct qeth_cmd_buffer *iob; |
| 6614 | struct qeth_ipa_cmd *cmd; |
| 6615 | |
| 6616 | QETH_DBF_TEXT(trace,4,"chgmac"); |
| 6617 | |
| 6618 | iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS, |
| 6619 | sizeof(struct qeth_ipacmd_setadpparms)); |
| 6620 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6621 | cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC; |
| 6622 | cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN; |
| 6623 | memcpy(&cmd->data.setadapterparms.data.change_addr.addr, |
| 6624 | card->dev->dev_addr, OSA_ADDR_LEN); |
| 6625 | rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb, |
| 6626 | NULL); |
| 6627 | return rc; |
| 6628 | } |
| 6629 | |
| 6630 | static int |
| 6631 | qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode) |
| 6632 | { |
| 6633 | int rc; |
| 6634 | struct qeth_cmd_buffer *iob; |
| 6635 | struct qeth_ipa_cmd *cmd; |
| 6636 | |
| 6637 | QETH_DBF_TEXT(trace,4,"adpmode"); |
| 6638 | |
| 6639 | iob = qeth_get_adapter_cmd(card, command, |
| 6640 | sizeof(struct qeth_ipacmd_setadpparms)); |
| 6641 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6642 | cmd->data.setadapterparms.data.mode = mode; |
| 6643 | rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb, |
| 6644 | NULL); |
| 6645 | return rc; |
| 6646 | } |
| 6647 | |
| 6648 | static inline int |
| 6649 | qeth_setadapter_hstr(struct qeth_card *card) |
| 6650 | { |
| 6651 | int rc; |
| 6652 | |
| 6653 | QETH_DBF_TEXT(trace,4,"adphstr"); |
| 6654 | |
| 6655 | if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) { |
| 6656 | rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE, |
| 6657 | card->options.broadcast_mode); |
| 6658 | if (rc) |
| 6659 | PRINT_WARN("couldn't set broadcast mode on " |
| 6660 | "device %s: x%x\n", |
| 6661 | CARD_BUS_ID(card), rc); |
| 6662 | rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS, |
| 6663 | card->options.macaddr_mode); |
| 6664 | if (rc) |
| 6665 | PRINT_WARN("couldn't set macaddr mode on " |
| 6666 | "device %s: x%x\n", CARD_BUS_ID(card), rc); |
| 6667 | return rc; |
| 6668 | } |
| 6669 | if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL) |
| 6670 | PRINT_WARN("set adapter parameters not available " |
| 6671 | "to set broadcast mode, using ALLRINGS " |
| 6672 | "on device %s:\n", CARD_BUS_ID(card)); |
| 6673 | if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL) |
| 6674 | PRINT_WARN("set adapter parameters not available " |
| 6675 | "to set macaddr mode, using NONCANONICAL " |
| 6676 | "on device %s:\n", CARD_BUS_ID(card)); |
| 6677 | return 0; |
| 6678 | } |
| 6679 | |
| 6680 | static int |
| 6681 | qeth_setadapter_parms(struct qeth_card *card) |
| 6682 | { |
| 6683 | int rc; |
| 6684 | |
| 6685 | QETH_DBF_TEXT(setup, 2, "setadprm"); |
| 6686 | |
| 6687 | if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){ |
| 6688 | PRINT_WARN("set adapter parameters not supported " |
| 6689 | "on device %s.\n", |
| 6690 | CARD_BUS_ID(card)); |
| 6691 | QETH_DBF_TEXT(setup, 2, " notsupp"); |
| 6692 | return 0; |
| 6693 | } |
| 6694 | rc = qeth_query_setadapterparms(card); |
| 6695 | if (rc) { |
| 6696 | PRINT_WARN("couldn't set adapter parameters on device %s: " |
| 6697 | "x%x\n", CARD_BUS_ID(card), rc); |
| 6698 | return rc; |
| 6699 | } |
| 6700 | if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) { |
| 6701 | rc = qeth_setadpparms_change_macaddr(card); |
| 6702 | if (rc) |
| 6703 | PRINT_WARN("couldn't get MAC address on " |
| 6704 | "device %s: x%x\n", |
| 6705 | CARD_BUS_ID(card), rc); |
| 6706 | } |
| 6707 | |
| 6708 | if ((card->info.link_type == QETH_LINK_TYPE_HSTR) || |
| 6709 | (card->info.link_type == QETH_LINK_TYPE_LANE_TR)) |
| 6710 | rc = qeth_setadapter_hstr(card); |
| 6711 | |
| 6712 | return rc; |
| 6713 | } |
| 6714 | |
| 6715 | static int |
| 6716 | qeth_layer2_initialize(struct qeth_card *card) |
| 6717 | { |
| 6718 | int rc = 0; |
| 6719 | |
| 6720 | |
| 6721 | QETH_DBF_TEXT(setup, 2, "doL2init"); |
| 6722 | QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card)); |
| 6723 | |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 6724 | rc = qeth_query_setadapterparms(card); |
| 6725 | if (rc) { |
| 6726 | PRINT_WARN("could not query adapter parameters on device %s: " |
| 6727 | "x%x\n", CARD_BUS_ID(card), rc); |
| 6728 | } |
| 6729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6730 | rc = qeth_setadpparms_change_macaddr(card); |
| 6731 | if (rc) { |
| 6732 | PRINT_WARN("couldn't get MAC address on " |
| 6733 | "device %s: x%x\n", |
| 6734 | CARD_BUS_ID(card), rc); |
| 6735 | QETH_DBF_TEXT_(setup, 2,"1err%d",rc); |
| 6736 | return rc; |
| 6737 | } |
| 6738 | QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN); |
| 6739 | |
| 6740 | rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]); |
| 6741 | if (rc) |
| 6742 | QETH_DBF_TEXT_(setup, 2,"2err%d",rc); |
| 6743 | return 0; |
| 6744 | } |
| 6745 | |
| 6746 | |
| 6747 | static int |
| 6748 | qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd, |
| 6749 | enum qeth_prot_versions prot) |
| 6750 | { |
| 6751 | int rc; |
| 6752 | struct qeth_cmd_buffer *iob; |
| 6753 | |
| 6754 | iob = qeth_get_ipacmd_buffer(card,ipacmd,prot); |
| 6755 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 6756 | |
| 6757 | return rc; |
| 6758 | } |
| 6759 | |
| 6760 | static int |
| 6761 | qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot) |
| 6762 | { |
| 6763 | int rc; |
| 6764 | |
| 6765 | QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot); |
| 6766 | |
| 6767 | rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot); |
| 6768 | return rc; |
| 6769 | } |
| 6770 | |
| 6771 | static int |
| 6772 | qeth_send_stoplan(struct qeth_card *card) |
| 6773 | { |
| 6774 | int rc = 0; |
| 6775 | |
| 6776 | /* |
| 6777 | * TODO: according to the IPA format document page 14, |
| 6778 | * TCP/IP (we!) never issue a STOPLAN |
| 6779 | * is this right ?!? |
| 6780 | */ |
| 6781 | QETH_DBF_TEXT(trace, 2, "stoplan"); |
| 6782 | |
| 6783 | rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4); |
| 6784 | return rc; |
| 6785 | } |
| 6786 | |
| 6787 | static int |
| 6788 | qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 6789 | unsigned long data) |
| 6790 | { |
| 6791 | struct qeth_ipa_cmd *cmd; |
| 6792 | |
| 6793 | QETH_DBF_TEXT(setup, 2, "qipasscb"); |
| 6794 | |
| 6795 | cmd = (struct qeth_ipa_cmd *) data; |
| 6796 | if (cmd->hdr.prot_version == QETH_PROT_IPV4) { |
| 6797 | card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported; |
| 6798 | card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled; |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 6799 | /* Disable IPV6 support hard coded for Hipersockets */ |
| 6800 | if(card->info.type == QETH_CARD_TYPE_IQD) |
| 6801 | card->options.ipa4.supported_funcs &= ~IPA_IPV6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6802 | } else { |
| 6803 | #ifdef CONFIG_QETH_IPV6 |
| 6804 | card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported; |
| 6805 | card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled; |
| 6806 | #endif |
| 6807 | } |
| 6808 | QETH_DBF_TEXT(setup, 2, "suppenbl"); |
| 6809 | QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported); |
| 6810 | QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled); |
| 6811 | return 0; |
| 6812 | } |
| 6813 | |
| 6814 | static int |
| 6815 | qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot) |
| 6816 | { |
| 6817 | int rc; |
| 6818 | struct qeth_cmd_buffer *iob; |
| 6819 | |
| 6820 | QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot); |
| 6821 | if (card->options.layer2) { |
| 6822 | QETH_DBF_TEXT(setup, 2, "noprmly2"); |
| 6823 | return -EPERM; |
| 6824 | } |
| 6825 | |
| 6826 | iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot); |
| 6827 | rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL); |
| 6828 | return rc; |
| 6829 | } |
| 6830 | |
| 6831 | static struct qeth_cmd_buffer * |
| 6832 | qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func, |
| 6833 | __u16 cmd_code, __u16 len, |
| 6834 | enum qeth_prot_versions prot) |
| 6835 | { |
| 6836 | struct qeth_cmd_buffer *iob; |
| 6837 | struct qeth_ipa_cmd *cmd; |
| 6838 | |
| 6839 | QETH_DBF_TEXT(trace,4,"getasscm"); |
| 6840 | iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot); |
| 6841 | |
| 6842 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6843 | cmd->data.setassparms.hdr.assist_no = ipa_func; |
| 6844 | cmd->data.setassparms.hdr.length = 8 + len; |
| 6845 | cmd->data.setassparms.hdr.command_code = cmd_code; |
| 6846 | cmd->data.setassparms.hdr.return_code = 0; |
| 6847 | cmd->data.setassparms.hdr.seq_no = 0; |
| 6848 | |
| 6849 | return iob; |
| 6850 | } |
| 6851 | |
| 6852 | static int |
| 6853 | qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 6854 | __u16 len, long data, |
| 6855 | int (*reply_cb) |
| 6856 | (struct qeth_card *,struct qeth_reply *,unsigned long), |
| 6857 | void *reply_param) |
| 6858 | { |
| 6859 | int rc; |
| 6860 | struct qeth_ipa_cmd *cmd; |
| 6861 | |
| 6862 | QETH_DBF_TEXT(trace,4,"sendassp"); |
| 6863 | |
| 6864 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6865 | if (len <= sizeof(__u32)) |
| 6866 | cmd->data.setassparms.data.flags_32bit = (__u32) data; |
Frank Pavlic | 1380fee | 2006-03-22 16:03:41 +0100 | [diff] [blame] | 6867 | else /* (len > sizeof(__u32)) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6868 | memcpy(&cmd->data.setassparms.data, (void *) data, len); |
| 6869 | |
| 6870 | rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param); |
| 6871 | return rc; |
| 6872 | } |
| 6873 | |
| 6874 | #ifdef CONFIG_QETH_IPV6 |
| 6875 | static int |
| 6876 | qeth_send_simple_setassparms_ipv6(struct qeth_card *card, |
| 6877 | enum qeth_ipa_funcs ipa_func, __u16 cmd_code) |
| 6878 | |
| 6879 | { |
| 6880 | int rc; |
| 6881 | struct qeth_cmd_buffer *iob; |
| 6882 | |
| 6883 | QETH_DBF_TEXT(trace,4,"simassp6"); |
| 6884 | iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code, |
| 6885 | 0, QETH_PROT_IPV6); |
| 6886 | rc = qeth_send_setassparms(card, iob, 0, 0, |
| 6887 | qeth_default_setassparms_cb, NULL); |
| 6888 | return rc; |
| 6889 | } |
| 6890 | #endif |
| 6891 | |
| 6892 | static int |
| 6893 | qeth_send_simple_setassparms(struct qeth_card *card, |
| 6894 | enum qeth_ipa_funcs ipa_func, |
| 6895 | __u16 cmd_code, long data) |
| 6896 | { |
| 6897 | int rc; |
| 6898 | int length = 0; |
| 6899 | struct qeth_cmd_buffer *iob; |
| 6900 | |
| 6901 | QETH_DBF_TEXT(trace,4,"simassp4"); |
| 6902 | if (data) |
| 6903 | length = sizeof(__u32); |
| 6904 | iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code, |
| 6905 | length, QETH_PROT_IPV4); |
| 6906 | rc = qeth_send_setassparms(card, iob, length, data, |
| 6907 | qeth_default_setassparms_cb, NULL); |
| 6908 | return rc; |
| 6909 | } |
| 6910 | |
| 6911 | static inline int |
| 6912 | qeth_start_ipa_arp_processing(struct qeth_card *card) |
| 6913 | { |
| 6914 | int rc; |
| 6915 | |
| 6916 | QETH_DBF_TEXT(trace,3,"ipaarp"); |
| 6917 | |
| 6918 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 6919 | PRINT_WARN("ARP processing not supported " |
| 6920 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 6921 | return 0; |
| 6922 | } |
| 6923 | rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING, |
| 6924 | IPA_CMD_ASS_START, 0); |
| 6925 | if (rc) { |
| 6926 | PRINT_WARN("Could not start ARP processing " |
| 6927 | "assist on %s: 0x%x\n", |
| 6928 | QETH_CARD_IFNAME(card), rc); |
| 6929 | } |
| 6930 | return rc; |
| 6931 | } |
| 6932 | |
| 6933 | static int |
| 6934 | qeth_start_ipa_ip_fragmentation(struct qeth_card *card) |
| 6935 | { |
| 6936 | int rc; |
| 6937 | |
| 6938 | QETH_DBF_TEXT(trace,3,"ipaipfrg"); |
| 6939 | |
| 6940 | if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) { |
| 6941 | PRINT_INFO("Hardware IP fragmentation not supported on %s\n", |
| 6942 | QETH_CARD_IFNAME(card)); |
| 6943 | return -EOPNOTSUPP; |
| 6944 | } |
| 6945 | |
| 6946 | rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION, |
| 6947 | IPA_CMD_ASS_START, 0); |
| 6948 | if (rc) { |
| 6949 | PRINT_WARN("Could not start Hardware IP fragmentation " |
| 6950 | "assist on %s: 0x%x\n", |
| 6951 | QETH_CARD_IFNAME(card), rc); |
| 6952 | } else |
| 6953 | PRINT_INFO("Hardware IP fragmentation enabled \n"); |
| 6954 | return rc; |
| 6955 | } |
| 6956 | |
| 6957 | static int |
| 6958 | qeth_start_ipa_source_mac(struct qeth_card *card) |
| 6959 | { |
| 6960 | int rc; |
| 6961 | |
| 6962 | QETH_DBF_TEXT(trace,3,"stsrcmac"); |
| 6963 | |
| 6964 | if (!card->options.fake_ll) |
| 6965 | return -EOPNOTSUPP; |
| 6966 | |
| 6967 | if (!qeth_is_supported(card, IPA_SOURCE_MAC)) { |
| 6968 | PRINT_INFO("Inbound source address not " |
| 6969 | "supported on %s\n", QETH_CARD_IFNAME(card)); |
| 6970 | return -EOPNOTSUPP; |
| 6971 | } |
| 6972 | |
| 6973 | rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC, |
| 6974 | IPA_CMD_ASS_START, 0); |
| 6975 | if (rc) |
| 6976 | PRINT_WARN("Could not start inbound source " |
| 6977 | "assist on %s: 0x%x\n", |
| 6978 | QETH_CARD_IFNAME(card), rc); |
| 6979 | return rc; |
| 6980 | } |
| 6981 | |
| 6982 | static int |
| 6983 | qeth_start_ipa_vlan(struct qeth_card *card) |
| 6984 | { |
| 6985 | int rc = 0; |
| 6986 | |
| 6987 | QETH_DBF_TEXT(trace,3,"strtvlan"); |
| 6988 | |
| 6989 | #ifdef CONFIG_QETH_VLAN |
| 6990 | if (!qeth_is_supported(card, IPA_FULL_VLAN)) { |
| 6991 | PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card)); |
| 6992 | return -EOPNOTSUPP; |
| 6993 | } |
| 6994 | |
| 6995 | rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO, |
| 6996 | IPA_CMD_ASS_START,0); |
| 6997 | if (rc) { |
| 6998 | PRINT_WARN("Could not start vlan " |
| 6999 | "assist on %s: 0x%x\n", |
| 7000 | QETH_CARD_IFNAME(card), rc); |
| 7001 | } else { |
| 7002 | PRINT_INFO("VLAN enabled \n"); |
| 7003 | card->dev->features |= |
| 7004 | NETIF_F_HW_VLAN_FILTER | |
| 7005 | NETIF_F_HW_VLAN_TX | |
| 7006 | NETIF_F_HW_VLAN_RX; |
| 7007 | } |
| 7008 | #endif /* QETH_VLAN */ |
| 7009 | return rc; |
| 7010 | } |
| 7011 | |
| 7012 | static int |
| 7013 | qeth_start_ipa_multicast(struct qeth_card *card) |
| 7014 | { |
| 7015 | int rc; |
| 7016 | |
| 7017 | QETH_DBF_TEXT(trace,3,"stmcast"); |
| 7018 | |
| 7019 | if (!qeth_is_supported(card, IPA_MULTICASTING)) { |
| 7020 | PRINT_WARN("Multicast not supported on %s\n", |
| 7021 | QETH_CARD_IFNAME(card)); |
| 7022 | return -EOPNOTSUPP; |
| 7023 | } |
| 7024 | |
| 7025 | rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING, |
| 7026 | IPA_CMD_ASS_START,0); |
| 7027 | if (rc) { |
| 7028 | PRINT_WARN("Could not start multicast " |
| 7029 | "assist on %s: rc=%i\n", |
| 7030 | QETH_CARD_IFNAME(card), rc); |
| 7031 | } else { |
| 7032 | PRINT_INFO("Multicast enabled\n"); |
| 7033 | card->dev->flags |= IFF_MULTICAST; |
| 7034 | } |
| 7035 | return rc; |
| 7036 | } |
| 7037 | |
| 7038 | #ifdef CONFIG_QETH_IPV6 |
| 7039 | static int |
| 7040 | qeth_softsetup_ipv6(struct qeth_card *card) |
| 7041 | { |
| 7042 | int rc; |
| 7043 | |
| 7044 | QETH_DBF_TEXT(trace,3,"softipv6"); |
| 7045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7046 | rc = qeth_send_startlan(card, QETH_PROT_IPV6); |
| 7047 | if (rc) { |
| 7048 | PRINT_ERR("IPv6 startlan failed on %s\n", |
| 7049 | QETH_CARD_IFNAME(card)); |
| 7050 | return rc; |
| 7051 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7052 | rc = qeth_query_ipassists(card,QETH_PROT_IPV6); |
| 7053 | if (rc) { |
| 7054 | PRINT_ERR("IPv6 query ipassist failed on %s\n", |
| 7055 | QETH_CARD_IFNAME(card)); |
| 7056 | return rc; |
| 7057 | } |
| 7058 | rc = qeth_send_simple_setassparms(card, IPA_IPV6, |
| 7059 | IPA_CMD_ASS_START, 3); |
| 7060 | if (rc) { |
| 7061 | PRINT_WARN("IPv6 start assist (version 4) failed " |
| 7062 | "on %s: 0x%x\n", |
| 7063 | QETH_CARD_IFNAME(card), rc); |
| 7064 | return rc; |
| 7065 | } |
| 7066 | rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6, |
| 7067 | IPA_CMD_ASS_START); |
| 7068 | if (rc) { |
| 7069 | PRINT_WARN("IPV6 start assist (version 6) failed " |
| 7070 | "on %s: 0x%x\n", |
| 7071 | QETH_CARD_IFNAME(card), rc); |
| 7072 | return rc; |
| 7073 | } |
| 7074 | rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU, |
| 7075 | IPA_CMD_ASS_START); |
| 7076 | if (rc) { |
| 7077 | PRINT_WARN("Could not enable passthrough " |
| 7078 | "on %s: 0x%x\n", |
| 7079 | QETH_CARD_IFNAME(card), rc); |
| 7080 | return rc; |
| 7081 | } |
| 7082 | PRINT_INFO("IPV6 enabled \n"); |
| 7083 | return 0; |
| 7084 | } |
| 7085 | |
| 7086 | #endif |
| 7087 | |
| 7088 | static int |
| 7089 | qeth_start_ipa_ipv6(struct qeth_card *card) |
| 7090 | { |
| 7091 | int rc = 0; |
| 7092 | #ifdef CONFIG_QETH_IPV6 |
| 7093 | QETH_DBF_TEXT(trace,3,"strtipv6"); |
| 7094 | |
| 7095 | if (!qeth_is_supported(card, IPA_IPV6)) { |
| 7096 | PRINT_WARN("IPv6 not supported on %s\n", |
| 7097 | QETH_CARD_IFNAME(card)); |
| 7098 | return 0; |
| 7099 | } |
| 7100 | rc = qeth_softsetup_ipv6(card); |
| 7101 | #endif |
| 7102 | return rc ; |
| 7103 | } |
| 7104 | |
| 7105 | static int |
| 7106 | qeth_start_ipa_broadcast(struct qeth_card *card) |
| 7107 | { |
| 7108 | int rc; |
| 7109 | |
| 7110 | QETH_DBF_TEXT(trace,3,"stbrdcst"); |
| 7111 | card->info.broadcast_capable = 0; |
| 7112 | if (!qeth_is_supported(card, IPA_FILTERING)) { |
| 7113 | PRINT_WARN("Broadcast not supported on %s\n", |
| 7114 | QETH_CARD_IFNAME(card)); |
| 7115 | rc = -EOPNOTSUPP; |
| 7116 | goto out; |
| 7117 | } |
| 7118 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
| 7119 | IPA_CMD_ASS_START, 0); |
| 7120 | if (rc) { |
| 7121 | PRINT_WARN("Could not enable broadcasting filtering " |
| 7122 | "on %s: 0x%x\n", |
| 7123 | QETH_CARD_IFNAME(card), rc); |
| 7124 | goto out; |
| 7125 | } |
| 7126 | |
| 7127 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
| 7128 | IPA_CMD_ASS_CONFIGURE, 1); |
| 7129 | if (rc) { |
| 7130 | PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n", |
| 7131 | QETH_CARD_IFNAME(card), rc); |
| 7132 | goto out; |
| 7133 | } |
| 7134 | card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO; |
| 7135 | PRINT_INFO("Broadcast enabled \n"); |
| 7136 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
| 7137 | IPA_CMD_ASS_ENABLE, 1); |
| 7138 | if (rc) { |
| 7139 | PRINT_WARN("Could not set up broadcast echo filtering on " |
| 7140 | "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc); |
| 7141 | goto out; |
| 7142 | } |
| 7143 | card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO; |
| 7144 | out: |
| 7145 | if (card->info.broadcast_capable) |
| 7146 | card->dev->flags |= IFF_BROADCAST; |
| 7147 | else |
| 7148 | card->dev->flags &= ~IFF_BROADCAST; |
| 7149 | return rc; |
| 7150 | } |
| 7151 | |
| 7152 | static int |
| 7153 | qeth_send_checksum_command(struct qeth_card *card) |
| 7154 | { |
| 7155 | int rc; |
| 7156 | |
| 7157 | rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM, |
| 7158 | IPA_CMD_ASS_START, 0); |
| 7159 | if (rc) { |
| 7160 | PRINT_WARN("Starting Inbound HW Checksumming failed on %s: " |
| 7161 | "0x%x,\ncontinuing using Inbound SW Checksumming\n", |
| 7162 | QETH_CARD_IFNAME(card), rc); |
| 7163 | return rc; |
| 7164 | } |
| 7165 | rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM, |
| 7166 | IPA_CMD_ASS_ENABLE, |
| 7167 | card->info.csum_mask); |
| 7168 | if (rc) { |
| 7169 | PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: " |
| 7170 | "0x%x,\ncontinuing using Inbound SW Checksumming\n", |
| 7171 | QETH_CARD_IFNAME(card), rc); |
| 7172 | return rc; |
| 7173 | } |
| 7174 | return 0; |
| 7175 | } |
| 7176 | |
| 7177 | static int |
| 7178 | qeth_start_ipa_checksum(struct qeth_card *card) |
| 7179 | { |
| 7180 | int rc = 0; |
| 7181 | |
| 7182 | QETH_DBF_TEXT(trace,3,"strtcsum"); |
| 7183 | |
| 7184 | if (card->options.checksum_type == NO_CHECKSUMMING) { |
| 7185 | PRINT_WARN("Using no checksumming on %s.\n", |
| 7186 | QETH_CARD_IFNAME(card)); |
| 7187 | return 0; |
| 7188 | } |
| 7189 | if (card->options.checksum_type == SW_CHECKSUMMING) { |
| 7190 | PRINT_WARN("Using SW checksumming on %s.\n", |
| 7191 | QETH_CARD_IFNAME(card)); |
| 7192 | return 0; |
| 7193 | } |
| 7194 | if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) { |
| 7195 | PRINT_WARN("Inbound HW Checksumming not " |
| 7196 | "supported on %s,\ncontinuing " |
| 7197 | "using Inbound SW Checksumming\n", |
| 7198 | QETH_CARD_IFNAME(card)); |
| 7199 | card->options.checksum_type = SW_CHECKSUMMING; |
| 7200 | return 0; |
| 7201 | } |
| 7202 | rc = qeth_send_checksum_command(card); |
| 7203 | if (!rc) { |
| 7204 | PRINT_INFO("HW Checksumming (inbound) enabled \n"); |
| 7205 | } |
| 7206 | return rc; |
| 7207 | } |
| 7208 | |
| 7209 | static int |
| 7210 | qeth_start_ipa_tso(struct qeth_card *card) |
| 7211 | { |
| 7212 | int rc; |
| 7213 | |
| 7214 | QETH_DBF_TEXT(trace,3,"sttso"); |
| 7215 | |
| 7216 | if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) { |
| 7217 | PRINT_WARN("Outbound TSO not supported on %s\n", |
| 7218 | QETH_CARD_IFNAME(card)); |
| 7219 | rc = -EOPNOTSUPP; |
| 7220 | } else { |
| 7221 | rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO, |
| 7222 | IPA_CMD_ASS_START,0); |
| 7223 | if (rc) |
| 7224 | PRINT_WARN("Could not start outbound TSO " |
| 7225 | "assist on %s: rc=%i\n", |
| 7226 | QETH_CARD_IFNAME(card), rc); |
| 7227 | else |
| 7228 | PRINT_INFO("Outbound TSO enabled\n"); |
| 7229 | } |
| 7230 | if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){ |
| 7231 | card->options.large_send = QETH_LARGE_SEND_NO; |
| 7232 | card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG); |
| 7233 | } |
| 7234 | return rc; |
| 7235 | } |
| 7236 | |
| 7237 | static int |
| 7238 | qeth_start_ipassists(struct qeth_card *card) |
| 7239 | { |
| 7240 | QETH_DBF_TEXT(trace,3,"strtipas"); |
| 7241 | qeth_start_ipa_arp_processing(card); /* go on*/ |
| 7242 | qeth_start_ipa_ip_fragmentation(card); /* go on*/ |
| 7243 | qeth_start_ipa_source_mac(card); /* go on*/ |
| 7244 | qeth_start_ipa_vlan(card); /* go on*/ |
| 7245 | qeth_start_ipa_multicast(card); /* go on*/ |
| 7246 | qeth_start_ipa_ipv6(card); /* go on*/ |
| 7247 | qeth_start_ipa_broadcast(card); /* go on*/ |
| 7248 | qeth_start_ipa_checksum(card); /* go on*/ |
| 7249 | qeth_start_ipa_tso(card); /* go on*/ |
| 7250 | return 0; |
| 7251 | } |
| 7252 | |
| 7253 | static int |
| 7254 | qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type, |
| 7255 | enum qeth_prot_versions prot) |
| 7256 | { |
| 7257 | int rc; |
| 7258 | struct qeth_ipa_cmd *cmd; |
| 7259 | struct qeth_cmd_buffer *iob; |
| 7260 | |
| 7261 | QETH_DBF_TEXT(trace,4,"setroutg"); |
| 7262 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot); |
| 7263 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 7264 | cmd->data.setrtg.type = (type); |
| 7265 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 7266 | |
| 7267 | return rc; |
| 7268 | |
| 7269 | } |
| 7270 | |
| 7271 | static void |
| 7272 | qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type, |
| 7273 | enum qeth_prot_versions prot) |
| 7274 | { |
| 7275 | if (card->info.type == QETH_CARD_TYPE_IQD) { |
| 7276 | switch (*type) { |
| 7277 | case NO_ROUTER: |
| 7278 | case PRIMARY_CONNECTOR: |
| 7279 | case SECONDARY_CONNECTOR: |
| 7280 | case MULTICAST_ROUTER: |
| 7281 | return; |
| 7282 | default: |
| 7283 | goto out_inval; |
| 7284 | } |
| 7285 | } else { |
| 7286 | switch (*type) { |
| 7287 | case NO_ROUTER: |
| 7288 | case PRIMARY_ROUTER: |
| 7289 | case SECONDARY_ROUTER: |
| 7290 | return; |
| 7291 | case MULTICAST_ROUTER: |
| 7292 | if (qeth_is_ipafunc_supported(card, prot, |
| 7293 | IPA_OSA_MC_ROUTER)) |
| 7294 | return; |
| 7295 | default: |
| 7296 | goto out_inval; |
| 7297 | } |
| 7298 | } |
| 7299 | out_inval: |
| 7300 | PRINT_WARN("Routing type '%s' not supported for interface %s.\n" |
| 7301 | "Router status set to 'no router'.\n", |
| 7302 | ((*type == PRIMARY_ROUTER)? "primary router" : |
| 7303 | (*type == SECONDARY_ROUTER)? "secondary router" : |
| 7304 | (*type == PRIMARY_CONNECTOR)? "primary connector" : |
| 7305 | (*type == SECONDARY_CONNECTOR)? "secondary connector" : |
| 7306 | (*type == MULTICAST_ROUTER)? "multicast router" : |
| 7307 | "unknown"), |
| 7308 | card->dev->name); |
| 7309 | *type = NO_ROUTER; |
| 7310 | } |
| 7311 | |
| 7312 | int |
| 7313 | qeth_setrouting_v4(struct qeth_card *card) |
| 7314 | { |
| 7315 | int rc; |
| 7316 | |
| 7317 | QETH_DBF_TEXT(trace,3,"setrtg4"); |
| 7318 | |
| 7319 | qeth_correct_routing_type(card, &card->options.route4.type, |
| 7320 | QETH_PROT_IPV4); |
| 7321 | |
| 7322 | rc = qeth_send_setrouting(card, card->options.route4.type, |
| 7323 | QETH_PROT_IPV4); |
| 7324 | if (rc) { |
| 7325 | card->options.route4.type = NO_ROUTER; |
| 7326 | PRINT_WARN("Error (0x%04x) while setting routing type on %s. " |
| 7327 | "Type set to 'no router'.\n", |
| 7328 | rc, QETH_CARD_IFNAME(card)); |
| 7329 | } |
| 7330 | return rc; |
| 7331 | } |
| 7332 | |
| 7333 | int |
| 7334 | qeth_setrouting_v6(struct qeth_card *card) |
| 7335 | { |
| 7336 | int rc = 0; |
| 7337 | |
| 7338 | QETH_DBF_TEXT(trace,3,"setrtg6"); |
| 7339 | #ifdef CONFIG_QETH_IPV6 |
| 7340 | |
| 7341 | qeth_correct_routing_type(card, &card->options.route6.type, |
| 7342 | QETH_PROT_IPV6); |
| 7343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7344 | rc = qeth_send_setrouting(card, card->options.route6.type, |
| 7345 | QETH_PROT_IPV6); |
| 7346 | if (rc) { |
| 7347 | card->options.route6.type = NO_ROUTER; |
| 7348 | PRINT_WARN("Error (0x%04x) while setting routing type on %s. " |
| 7349 | "Type set to 'no router'.\n", |
| 7350 | rc, QETH_CARD_IFNAME(card)); |
| 7351 | } |
| 7352 | #endif |
| 7353 | return rc; |
| 7354 | } |
| 7355 | |
| 7356 | int |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 7357 | qeth_set_large_send(struct qeth_card *card, enum qeth_large_send_types type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7358 | { |
| 7359 | int rc = 0; |
| 7360 | |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 7361 | if (card->dev == NULL) { |
| 7362 | card->options.large_send = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7363 | return 0; |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 7364 | } |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 7365 | if (card->state == CARD_STATE_UP) |
| 7366 | netif_tx_disable(card->dev); |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 7367 | card->options.large_send = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7368 | switch (card->options.large_send) { |
| 7369 | case QETH_LARGE_SEND_EDDP: |
| 7370 | card->dev->features |= NETIF_F_TSO | NETIF_F_SG; |
| 7371 | break; |
| 7372 | case QETH_LARGE_SEND_TSO: |
| 7373 | if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){ |
| 7374 | card->dev->features |= NETIF_F_TSO | NETIF_F_SG; |
| 7375 | } else { |
| 7376 | PRINT_WARN("TSO not supported on %s. " |
| 7377 | "large_send set to 'no'.\n", |
| 7378 | card->dev->name); |
| 7379 | card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG); |
| 7380 | card->options.large_send = QETH_LARGE_SEND_NO; |
| 7381 | rc = -EOPNOTSUPP; |
| 7382 | } |
| 7383 | break; |
| 7384 | default: /* includes QETH_LARGE_SEND_NO */ |
| 7385 | card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG); |
| 7386 | break; |
| 7387 | } |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 7388 | if (card->state == CARD_STATE_UP) |
| 7389 | netif_wake_queue(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7390 | return rc; |
| 7391 | } |
| 7392 | |
| 7393 | /* |
| 7394 | * softsetup card: init IPA stuff |
| 7395 | */ |
| 7396 | static int |
| 7397 | qeth_softsetup_card(struct qeth_card *card) |
| 7398 | { |
| 7399 | int rc; |
| 7400 | |
| 7401 | QETH_DBF_TEXT(setup, 2, "softsetp"); |
| 7402 | |
| 7403 | if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){ |
| 7404 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 7405 | if (rc == 0xe080){ |
| 7406 | PRINT_WARN("LAN on card %s if offline! " |
| 7407 | "Continuing softsetup.\n", |
| 7408 | CARD_BUS_ID(card)); |
| 7409 | card->lan_online = 0; |
| 7410 | } else |
| 7411 | return rc; |
| 7412 | } else |
| 7413 | card->lan_online = 1; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7414 | if (card->info.type==QETH_CARD_TYPE_OSN) |
| 7415 | goto out; |
Frank Pavlic | 66cc5d5 | 2006-02-07 17:04:38 +0100 | [diff] [blame] | 7416 | qeth_set_large_send(card, card->options.large_send); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7417 | if (card->options.layer2) { |
| 7418 | card->dev->features |= |
| 7419 | NETIF_F_HW_VLAN_FILTER | |
| 7420 | NETIF_F_HW_VLAN_TX | |
| 7421 | NETIF_F_HW_VLAN_RX; |
| 7422 | card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST; |
| 7423 | card->info.broadcast_capable=1; |
| 7424 | if ((rc = qeth_layer2_initialize(card))) { |
| 7425 | QETH_DBF_TEXT_(setup, 2, "L2err%d", rc); |
| 7426 | return rc; |
| 7427 | } |
| 7428 | #ifdef CONFIG_QETH_VLAN |
| 7429 | qeth_layer2_process_vlans(card, 0); |
| 7430 | #endif |
| 7431 | goto out; |
| 7432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7433 | if ((rc = qeth_setadapter_parms(card))) |
| 7434 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 7435 | if ((rc = qeth_start_ipassists(card))) |
| 7436 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
| 7437 | if ((rc = qeth_setrouting_v4(card))) |
| 7438 | QETH_DBF_TEXT_(setup, 2, "4err%d", rc); |
| 7439 | if ((rc = qeth_setrouting_v6(card))) |
| 7440 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
| 7441 | out: |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 7442 | netif_tx_disable(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7443 | return 0; |
| 7444 | } |
| 7445 | |
| 7446 | #ifdef CONFIG_QETH_IPV6 |
| 7447 | static int |
| 7448 | qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 7449 | unsigned long data) |
| 7450 | { |
| 7451 | struct qeth_ipa_cmd *cmd; |
| 7452 | |
| 7453 | cmd = (struct qeth_ipa_cmd *) data; |
| 7454 | if (cmd->hdr.return_code == 0) |
| 7455 | card->info.unique_id = *((__u16 *) |
| 7456 | &cmd->data.create_destroy_addr.unique_id[6]); |
| 7457 | else { |
| 7458 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 7459 | UNIQUE_ID_NOT_BY_CARD; |
| 7460 | PRINT_WARN("couldn't get a unique id from the card on device " |
| 7461 | "%s (result=x%x), using default id. ipv6 " |
| 7462 | "autoconfig on other lpars may lead to duplicate " |
| 7463 | "ip addresses. please use manually " |
| 7464 | "configured ones.\n", |
| 7465 | CARD_BUS_ID(card), cmd->hdr.return_code); |
| 7466 | } |
| 7467 | return 0; |
| 7468 | } |
| 7469 | #endif |
| 7470 | |
| 7471 | static int |
| 7472 | qeth_put_unique_id(struct qeth_card *card) |
| 7473 | { |
| 7474 | |
| 7475 | int rc = 0; |
| 7476 | #ifdef CONFIG_QETH_IPV6 |
| 7477 | struct qeth_cmd_buffer *iob; |
| 7478 | struct qeth_ipa_cmd *cmd; |
| 7479 | |
| 7480 | QETH_DBF_TEXT(trace,2,"puniqeid"); |
| 7481 | |
| 7482 | if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) == |
| 7483 | UNIQUE_ID_NOT_BY_CARD) |
| 7484 | return -1; |
| 7485 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR, |
| 7486 | QETH_PROT_IPV6); |
| 7487 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 7488 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 7489 | card->info.unique_id; |
| 7490 | memcpy(&cmd->data.create_destroy_addr.unique_id[0], |
| 7491 | card->dev->dev_addr, OSA_ADDR_LEN); |
| 7492 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 7493 | #else |
| 7494 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 7495 | UNIQUE_ID_NOT_BY_CARD; |
| 7496 | #endif |
| 7497 | return rc; |
| 7498 | } |
| 7499 | |
| 7500 | /** |
| 7501 | * Clear IP List |
| 7502 | */ |
| 7503 | static void |
| 7504 | qeth_clear_ip_list(struct qeth_card *card, int clean, int recover) |
| 7505 | { |
| 7506 | struct qeth_ipaddr *addr, *tmp; |
| 7507 | unsigned long flags; |
| 7508 | |
| 7509 | QETH_DBF_TEXT(trace,4,"clearip"); |
| 7510 | spin_lock_irqsave(&card->ip_lock, flags); |
| 7511 | /* clear todo list */ |
| 7512 | list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){ |
| 7513 | list_del(&addr->entry); |
| 7514 | kfree(addr); |
| 7515 | } |
| 7516 | |
| 7517 | while (!list_empty(&card->ip_list)) { |
| 7518 | addr = list_entry(card->ip_list.next, |
| 7519 | struct qeth_ipaddr, entry); |
| 7520 | list_del_init(&addr->entry); |
| 7521 | if (clean) { |
| 7522 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 7523 | qeth_deregister_addr_entry(card, addr); |
| 7524 | spin_lock_irqsave(&card->ip_lock, flags); |
| 7525 | } |
| 7526 | if (!recover || addr->is_multicast) { |
| 7527 | kfree(addr); |
| 7528 | continue; |
| 7529 | } |
| 7530 | list_add_tail(&addr->entry, card->ip_tbd_list); |
| 7531 | } |
| 7532 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 7533 | } |
| 7534 | |
| 7535 | static void |
| 7536 | qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads, |
| 7537 | int clear_start_mask) |
| 7538 | { |
| 7539 | unsigned long flags; |
| 7540 | |
| 7541 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 7542 | card->thread_allowed_mask = threads; |
| 7543 | if (clear_start_mask) |
| 7544 | card->thread_start_mask &= threads; |
| 7545 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 7546 | wake_up(&card->wait_q); |
| 7547 | } |
| 7548 | |
| 7549 | static inline int |
| 7550 | qeth_threads_running(struct qeth_card *card, unsigned long threads) |
| 7551 | { |
| 7552 | unsigned long flags; |
| 7553 | int rc = 0; |
| 7554 | |
| 7555 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 7556 | rc = (card->thread_running_mask & threads); |
| 7557 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 7558 | return rc; |
| 7559 | } |
| 7560 | |
| 7561 | static int |
| 7562 | qeth_wait_for_threads(struct qeth_card *card, unsigned long threads) |
| 7563 | { |
| 7564 | return wait_event_interruptible(card->wait_q, |
| 7565 | qeth_threads_running(card, threads) == 0); |
| 7566 | } |
| 7567 | |
| 7568 | static int |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7569 | qeth_stop_card(struct qeth_card *card, int recovery_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7570 | { |
| 7571 | int rc = 0; |
| 7572 | |
| 7573 | QETH_DBF_TEXT(setup ,2,"stopcard"); |
| 7574 | QETH_DBF_HEX(setup, 2, &card, sizeof(void *)); |
| 7575 | |
| 7576 | qeth_set_allowed_threads(card, 0, 1); |
| 7577 | if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)) |
| 7578 | return -ERESTARTSYS; |
| 7579 | if (card->read.state == CH_STATE_UP && |
| 7580 | card->write.state == CH_STATE_UP && |
| 7581 | (card->state == CARD_STATE_UP)) { |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 7582 | if (recovery_mode && |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7583 | card->info.type != QETH_CARD_TYPE_OSN) { |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7584 | qeth_stop(card->dev); |
| 7585 | } else { |
| 7586 | rtnl_lock(); |
| 7587 | dev_close(card->dev); |
| 7588 | rtnl_unlock(); |
| 7589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7590 | if (!card->use_hard_stop) { |
| 7591 | __u8 *mac = &card->dev->dev_addr[0]; |
| 7592 | rc = qeth_layer2_send_delmac(card, mac); |
| 7593 | QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc); |
| 7594 | if ((rc = qeth_send_stoplan(card))) |
| 7595 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 7596 | } |
| 7597 | card->state = CARD_STATE_SOFTSETUP; |
| 7598 | } |
| 7599 | if (card->state == CARD_STATE_SOFTSETUP) { |
| 7600 | #ifdef CONFIG_QETH_VLAN |
| 7601 | if (card->options.layer2) |
| 7602 | qeth_layer2_process_vlans(card, 1); |
| 7603 | #endif |
| 7604 | qeth_clear_ip_list(card, !card->use_hard_stop, 1); |
| 7605 | qeth_clear_ipacmd_list(card); |
| 7606 | card->state = CARD_STATE_HARDSETUP; |
| 7607 | } |
| 7608 | if (card->state == CARD_STATE_HARDSETUP) { |
| 7609 | if ((!card->use_hard_stop) && |
| 7610 | (!card->options.layer2)) |
| 7611 | if ((rc = qeth_put_unique_id(card))) |
| 7612 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 7613 | qeth_qdio_clear_card(card, 0); |
| 7614 | qeth_clear_qdio_buffers(card); |
| 7615 | qeth_clear_working_pool_list(card); |
| 7616 | card->state = CARD_STATE_DOWN; |
| 7617 | } |
| 7618 | if (card->state == CARD_STATE_DOWN) { |
| 7619 | qeth_clear_cmd_buffers(&card->read); |
| 7620 | qeth_clear_cmd_buffers(&card->write); |
| 7621 | } |
| 7622 | card->use_hard_stop = 0; |
| 7623 | return rc; |
| 7624 | } |
| 7625 | |
| 7626 | |
| 7627 | static int |
| 7628 | qeth_get_unique_id(struct qeth_card *card) |
| 7629 | { |
| 7630 | int rc = 0; |
| 7631 | #ifdef CONFIG_QETH_IPV6 |
| 7632 | struct qeth_cmd_buffer *iob; |
| 7633 | struct qeth_ipa_cmd *cmd; |
| 7634 | |
| 7635 | QETH_DBF_TEXT(setup, 2, "guniqeid"); |
| 7636 | |
| 7637 | if (!qeth_is_supported(card,IPA_IPV6)) { |
| 7638 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 7639 | UNIQUE_ID_NOT_BY_CARD; |
| 7640 | return 0; |
| 7641 | } |
| 7642 | |
| 7643 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR, |
| 7644 | QETH_PROT_IPV6); |
| 7645 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 7646 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 7647 | card->info.unique_id; |
| 7648 | |
| 7649 | rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL); |
| 7650 | #else |
| 7651 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 7652 | UNIQUE_ID_NOT_BY_CARD; |
| 7653 | #endif |
| 7654 | return rc; |
| 7655 | } |
| 7656 | static void |
| 7657 | qeth_print_status_with_portname(struct qeth_card *card) |
| 7658 | { |
| 7659 | char dbf_text[15]; |
| 7660 | int i; |
| 7661 | |
| 7662 | sprintf(dbf_text, "%s", card->info.portname + 1); |
| 7663 | for (i = 0; i < 8; i++) |
| 7664 | dbf_text[i] = |
| 7665 | (char) _ebcasc[(__u8) dbf_text[i]]; |
| 7666 | dbf_text[8] = 0; |
| 7667 | printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n" |
| 7668 | "with link type %s (portname: %s)\n", |
| 7669 | CARD_RDEV_ID(card), |
| 7670 | CARD_WDEV_ID(card), |
| 7671 | CARD_DDEV_ID(card), |
| 7672 | qeth_get_cardname(card), |
| 7673 | (card->info.mcl_level[0]) ? " (level: " : "", |
| 7674 | (card->info.mcl_level[0]) ? card->info.mcl_level : "", |
| 7675 | (card->info.mcl_level[0]) ? ")" : "", |
| 7676 | qeth_get_cardname_short(card), |
| 7677 | dbf_text); |
| 7678 | |
| 7679 | } |
| 7680 | |
| 7681 | static void |
| 7682 | qeth_print_status_no_portname(struct qeth_card *card) |
| 7683 | { |
| 7684 | if (card->info.portname[0]) |
| 7685 | printk("qeth: Device %s/%s/%s is a%s " |
| 7686 | "card%s%s%s\nwith link type %s " |
| 7687 | "(no portname needed by interface).\n", |
| 7688 | CARD_RDEV_ID(card), |
| 7689 | CARD_WDEV_ID(card), |
| 7690 | CARD_DDEV_ID(card), |
| 7691 | qeth_get_cardname(card), |
| 7692 | (card->info.mcl_level[0]) ? " (level: " : "", |
| 7693 | (card->info.mcl_level[0]) ? card->info.mcl_level : "", |
| 7694 | (card->info.mcl_level[0]) ? ")" : "", |
| 7695 | qeth_get_cardname_short(card)); |
| 7696 | else |
| 7697 | printk("qeth: Device %s/%s/%s is a%s " |
| 7698 | "card%s%s%s\nwith link type %s.\n", |
| 7699 | CARD_RDEV_ID(card), |
| 7700 | CARD_WDEV_ID(card), |
| 7701 | CARD_DDEV_ID(card), |
| 7702 | qeth_get_cardname(card), |
| 7703 | (card->info.mcl_level[0]) ? " (level: " : "", |
| 7704 | (card->info.mcl_level[0]) ? card->info.mcl_level : "", |
| 7705 | (card->info.mcl_level[0]) ? ")" : "", |
| 7706 | qeth_get_cardname_short(card)); |
| 7707 | } |
| 7708 | |
| 7709 | static void |
| 7710 | qeth_print_status_message(struct qeth_card *card) |
| 7711 | { |
| 7712 | switch (card->info.type) { |
| 7713 | case QETH_CARD_TYPE_OSAE: |
| 7714 | /* VM will use a non-zero first character |
| 7715 | * to indicate a HiperSockets like reporting |
| 7716 | * of the level OSA sets the first character to zero |
| 7717 | * */ |
| 7718 | if (!card->info.mcl_level[0]) { |
| 7719 | sprintf(card->info.mcl_level,"%02x%02x", |
| 7720 | card->info.mcl_level[2], |
| 7721 | card->info.mcl_level[3]); |
| 7722 | |
| 7723 | card->info.mcl_level[QETH_MCL_LENGTH] = 0; |
| 7724 | break; |
| 7725 | } |
| 7726 | /* fallthrough */ |
| 7727 | case QETH_CARD_TYPE_IQD: |
| 7728 | card->info.mcl_level[0] = (char) _ebcasc[(__u8) |
| 7729 | card->info.mcl_level[0]]; |
| 7730 | card->info.mcl_level[1] = (char) _ebcasc[(__u8) |
| 7731 | card->info.mcl_level[1]]; |
| 7732 | card->info.mcl_level[2] = (char) _ebcasc[(__u8) |
| 7733 | card->info.mcl_level[2]]; |
| 7734 | card->info.mcl_level[3] = (char) _ebcasc[(__u8) |
| 7735 | card->info.mcl_level[3]]; |
| 7736 | card->info.mcl_level[QETH_MCL_LENGTH] = 0; |
| 7737 | break; |
| 7738 | default: |
| 7739 | memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1); |
| 7740 | } |
| 7741 | if (card->info.portname_required) |
| 7742 | qeth_print_status_with_portname(card); |
| 7743 | else |
| 7744 | qeth_print_status_no_portname(card); |
| 7745 | } |
| 7746 | |
| 7747 | static int |
| 7748 | qeth_register_netdev(struct qeth_card *card) |
| 7749 | { |
| 7750 | QETH_DBF_TEXT(setup, 3, "regnetd"); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 7751 | if (card->dev->reg_state != NETREG_UNINITIALIZED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7752 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7753 | /* sysfs magic */ |
| 7754 | SET_NETDEV_DEV(card->dev, &card->gdev->dev); |
| 7755 | return register_netdev(card->dev); |
| 7756 | } |
| 7757 | |
| 7758 | static void |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7759 | qeth_start_again(struct qeth_card *card, int recovery_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7760 | { |
| 7761 | QETH_DBF_TEXT(setup ,2, "startag"); |
| 7762 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 7763 | if (recovery_mode && |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7764 | card->info.type != QETH_CARD_TYPE_OSN) { |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7765 | qeth_open(card->dev); |
| 7766 | } else { |
| 7767 | rtnl_lock(); |
| 7768 | dev_open(card->dev); |
| 7769 | rtnl_unlock(); |
| 7770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7771 | /* this also sets saved unicast addresses */ |
| 7772 | qeth_set_multicast_list(card->dev); |
| 7773 | } |
| 7774 | |
| 7775 | |
| 7776 | /* Layer 2 specific stuff */ |
| 7777 | #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \ |
| 7778 | if (card->options.option == value) { \ |
| 7779 | PRINT_ERR("%s not supported with layer 2 " \ |
| 7780 | "functionality, ignoring option on read" \ |
| 7781 | "channel device %s .\n",msg,CARD_RDEV_ID(card)); \ |
| 7782 | card->options.option = reset_value; \ |
| 7783 | } |
| 7784 | #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \ |
| 7785 | if (card->options.option != value) { \ |
| 7786 | PRINT_ERR("%s not supported with layer 2 " \ |
| 7787 | "functionality, ignoring option on read" \ |
| 7788 | "channel device %s .\n",msg,CARD_RDEV_ID(card)); \ |
| 7789 | card->options.option = reset_value; \ |
| 7790 | } |
| 7791 | |
| 7792 | |
| 7793 | static void qeth_make_parameters_consistent(struct qeth_card *card) |
| 7794 | { |
| 7795 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7796 | if (card->options.layer2 == 0) |
| 7797 | return; |
| 7798 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 7799 | return; |
| 7800 | if (card->info.type == QETH_CARD_TYPE_IQD) { |
| 7801 | PRINT_ERR("Device %s does not support layer 2 functionality." \ |
| 7802 | " Ignoring layer2 option.\n",CARD_BUS_ID(card)); |
| 7803 | card->options.layer2 = 0; |
| 7804 | return; |
| 7805 | } |
| 7806 | IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER, |
| 7807 | "Routing options are"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7808 | #ifdef CONFIG_QETH_IPV6 |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7809 | IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER, |
| 7810 | "Routing options are"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7811 | #endif |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7812 | IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING, |
| 7813 | QETH_CHECKSUM_DEFAULT, |
| 7814 | "Checksumming options are"); |
| 7815 | IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS, |
| 7816 | QETH_TR_BROADCAST_ALLRINGS, |
| 7817 | "Broadcast mode options are"); |
| 7818 | IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL, |
| 7819 | QETH_TR_MACADDR_NONCANONICAL, |
| 7820 | "Canonical MAC addr options are"); |
| 7821 | IGNORE_PARAM_NEQ(fake_broadcast, 0, 0, |
| 7822 | "Broadcast faking options are"); |
| 7823 | IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN, |
| 7824 | DEFAULT_ADD_HHLEN,"Option add_hhlen is"); |
| 7825 | IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7826 | } |
| 7827 | |
| 7828 | |
| 7829 | static int |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7830 | __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7831 | { |
| 7832 | struct qeth_card *card = gdev->dev.driver_data; |
| 7833 | int rc = 0; |
| 7834 | enum qeth_card_states recover_flag; |
| 7835 | |
| 7836 | BUG_ON(!card); |
| 7837 | QETH_DBF_TEXT(setup ,2, "setonlin"); |
| 7838 | QETH_DBF_HEX(setup, 2, &card, sizeof(void *)); |
| 7839 | |
| 7840 | qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1); |
| 7841 | if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){ |
| 7842 | PRINT_WARN("set_online of card %s interrupted by user!\n", |
| 7843 | CARD_BUS_ID(card)); |
| 7844 | return -ERESTARTSYS; |
| 7845 | } |
| 7846 | |
| 7847 | recover_flag = card->state; |
| 7848 | if ((rc = ccw_device_set_online(CARD_RDEV(card))) || |
| 7849 | (rc = ccw_device_set_online(CARD_WDEV(card))) || |
| 7850 | (rc = ccw_device_set_online(CARD_DDEV(card)))){ |
| 7851 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 7852 | return -EIO; |
| 7853 | } |
| 7854 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7855 | qeth_make_parameters_consistent(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7856 | |
| 7857 | if ((rc = qeth_hardsetup_card(card))){ |
| 7858 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 7859 | goto out_remove; |
| 7860 | } |
| 7861 | card->state = CARD_STATE_HARDSETUP; |
| 7862 | |
| 7863 | if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4))) |
| 7864 | rc = qeth_get_unique_id(card); |
| 7865 | |
| 7866 | if (rc && card->options.layer2 == 0) { |
| 7867 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
| 7868 | goto out_remove; |
| 7869 | } |
| 7870 | qeth_print_status_message(card); |
| 7871 | if ((rc = qeth_register_netdev(card))){ |
| 7872 | QETH_DBF_TEXT_(setup, 2, "4err%d", rc); |
| 7873 | goto out_remove; |
| 7874 | } |
| 7875 | if ((rc = qeth_softsetup_card(card))){ |
| 7876 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
| 7877 | goto out_remove; |
| 7878 | } |
| 7879 | card->state = CARD_STATE_SOFTSETUP; |
| 7880 | |
| 7881 | if ((rc = qeth_init_qdio_queues(card))){ |
| 7882 | QETH_DBF_TEXT_(setup, 2, "6err%d", rc); |
| 7883 | goto out_remove; |
| 7884 | } |
Frank Pavlic | 4965e97 | 2005-12-13 08:22:30 +0100 | [diff] [blame] | 7885 | netif_carrier_on(card->dev); |
| 7886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7887 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 7888 | if (recover_flag == CARD_STATE_RECOVER) |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7889 | qeth_start_again(card, recovery_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7890 | qeth_notify_processes(); |
| 7891 | return 0; |
| 7892 | out_remove: |
| 7893 | card->use_hard_stop = 1; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7894 | qeth_stop_card(card, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7895 | ccw_device_set_offline(CARD_DDEV(card)); |
| 7896 | ccw_device_set_offline(CARD_WDEV(card)); |
| 7897 | ccw_device_set_offline(CARD_RDEV(card)); |
| 7898 | if (recover_flag == CARD_STATE_RECOVER) |
| 7899 | card->state = CARD_STATE_RECOVER; |
| 7900 | else |
| 7901 | card->state = CARD_STATE_DOWN; |
| 7902 | return -ENODEV; |
| 7903 | } |
| 7904 | |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7905 | static int |
| 7906 | qeth_set_online(struct ccwgroup_device *gdev) |
| 7907 | { |
| 7908 | return __qeth_set_online(gdev, 0); |
| 7909 | } |
| 7910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7911 | static struct ccw_device_id qeth_ids[] = { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 7912 | {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE}, |
| 7913 | {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD}, |
| 7914 | {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7915 | {}, |
| 7916 | }; |
| 7917 | MODULE_DEVICE_TABLE(ccw, qeth_ids); |
| 7918 | |
| 7919 | struct device *qeth_root_dev = NULL; |
| 7920 | |
| 7921 | struct ccwgroup_driver qeth_ccwgroup_driver = { |
| 7922 | .owner = THIS_MODULE, |
| 7923 | .name = "qeth", |
| 7924 | .driver_id = 0xD8C5E3C8, |
| 7925 | .probe = qeth_probe_device, |
| 7926 | .remove = qeth_remove_device, |
| 7927 | .set_online = qeth_set_online, |
| 7928 | .set_offline = qeth_set_offline, |
| 7929 | }; |
| 7930 | |
| 7931 | struct ccw_driver qeth_ccw_driver = { |
| 7932 | .name = "qeth", |
| 7933 | .ids = qeth_ids, |
| 7934 | .probe = ccwgroup_probe_ccwdev, |
| 7935 | .remove = ccwgroup_remove_ccwdev, |
| 7936 | }; |
| 7937 | |
| 7938 | |
| 7939 | static void |
| 7940 | qeth_unregister_dbf_views(void) |
| 7941 | { |
| 7942 | if (qeth_dbf_setup) |
| 7943 | debug_unregister(qeth_dbf_setup); |
| 7944 | if (qeth_dbf_qerr) |
| 7945 | debug_unregister(qeth_dbf_qerr); |
| 7946 | if (qeth_dbf_sense) |
| 7947 | debug_unregister(qeth_dbf_sense); |
| 7948 | if (qeth_dbf_misc) |
| 7949 | debug_unregister(qeth_dbf_misc); |
| 7950 | if (qeth_dbf_data) |
| 7951 | debug_unregister(qeth_dbf_data); |
| 7952 | if (qeth_dbf_control) |
| 7953 | debug_unregister(qeth_dbf_control); |
| 7954 | if (qeth_dbf_trace) |
| 7955 | debug_unregister(qeth_dbf_trace); |
| 7956 | } |
| 7957 | static int |
| 7958 | qeth_register_dbf_views(void) |
| 7959 | { |
| 7960 | qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7961 | QETH_DBF_SETUP_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7962 | QETH_DBF_SETUP_NR_AREAS, |
| 7963 | QETH_DBF_SETUP_LEN); |
| 7964 | qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7965 | QETH_DBF_MISC_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7966 | QETH_DBF_MISC_NR_AREAS, |
| 7967 | QETH_DBF_MISC_LEN); |
| 7968 | qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7969 | QETH_DBF_DATA_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7970 | QETH_DBF_DATA_NR_AREAS, |
| 7971 | QETH_DBF_DATA_LEN); |
| 7972 | qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7973 | QETH_DBF_CONTROL_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7974 | QETH_DBF_CONTROL_NR_AREAS, |
| 7975 | QETH_DBF_CONTROL_LEN); |
| 7976 | qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7977 | QETH_DBF_SENSE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7978 | QETH_DBF_SENSE_NR_AREAS, |
| 7979 | QETH_DBF_SENSE_LEN); |
| 7980 | qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7981 | QETH_DBF_QERR_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7982 | QETH_DBF_QERR_NR_AREAS, |
| 7983 | QETH_DBF_QERR_LEN); |
| 7984 | qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7985 | QETH_DBF_TRACE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7986 | QETH_DBF_TRACE_NR_AREAS, |
| 7987 | QETH_DBF_TRACE_LEN); |
| 7988 | |
| 7989 | if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) || |
| 7990 | (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) || |
| 7991 | (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) || |
| 7992 | (qeth_dbf_trace == NULL)) { |
| 7993 | qeth_unregister_dbf_views(); |
| 7994 | return -ENOMEM; |
| 7995 | } |
| 7996 | debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view); |
| 7997 | debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL); |
| 7998 | |
| 7999 | debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view); |
| 8000 | debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL); |
| 8001 | |
| 8002 | debug_register_view(qeth_dbf_data, &debug_hex_ascii_view); |
| 8003 | debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL); |
| 8004 | |
| 8005 | debug_register_view(qeth_dbf_control, &debug_hex_ascii_view); |
| 8006 | debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL); |
| 8007 | |
| 8008 | debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view); |
| 8009 | debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL); |
| 8010 | |
| 8011 | debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view); |
| 8012 | debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL); |
| 8013 | |
| 8014 | debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view); |
| 8015 | debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL); |
| 8016 | |
| 8017 | return 0; |
| 8018 | } |
| 8019 | |
| 8020 | #ifdef CONFIG_QETH_IPV6 |
| 8021 | extern struct neigh_table arp_tbl; |
| 8022 | static struct neigh_ops *arp_direct_ops; |
| 8023 | static int (*qeth_old_arp_constructor) (struct neighbour *); |
| 8024 | |
| 8025 | static struct neigh_ops arp_direct_ops_template = { |
| 8026 | .family = AF_INET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8027 | .solicit = NULL, |
| 8028 | .error_report = NULL, |
| 8029 | .output = dev_queue_xmit, |
| 8030 | .connected_output = dev_queue_xmit, |
| 8031 | .hh_output = dev_queue_xmit, |
| 8032 | .queue_xmit = dev_queue_xmit |
| 8033 | }; |
| 8034 | |
| 8035 | static int |
| 8036 | qeth_arp_constructor(struct neighbour *neigh) |
| 8037 | { |
| 8038 | struct net_device *dev = neigh->dev; |
| 8039 | struct in_device *in_dev; |
| 8040 | struct neigh_parms *parms; |
| 8041 | struct qeth_card *card; |
| 8042 | |
| 8043 | card = qeth_get_card_from_dev(dev); |
| 8044 | if (card == NULL) |
| 8045 | goto out; |
| 8046 | if((card->options.layer2) || |
| 8047 | (card->dev->hard_header == qeth_fake_header)) |
| 8048 | goto out; |
| 8049 | |
| 8050 | rcu_read_lock(); |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 8051 | in_dev = __in_dev_get_rcu(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8052 | if (in_dev == NULL) { |
| 8053 | rcu_read_unlock(); |
| 8054 | return -EINVAL; |
| 8055 | } |
| 8056 | |
| 8057 | parms = in_dev->arp_parms; |
| 8058 | __neigh_parms_put(neigh->parms); |
| 8059 | neigh->parms = neigh_parms_clone(parms); |
| 8060 | rcu_read_unlock(); |
| 8061 | |
| 8062 | neigh->type = inet_addr_type(*(u32 *) neigh->primary_key); |
| 8063 | neigh->nud_state = NUD_NOARP; |
| 8064 | neigh->ops = arp_direct_ops; |
| 8065 | neigh->output = neigh->ops->queue_xmit; |
| 8066 | return 0; |
| 8067 | out: |
| 8068 | return qeth_old_arp_constructor(neigh); |
| 8069 | } |
| 8070 | #endif /*CONFIG_QETH_IPV6*/ |
| 8071 | |
| 8072 | /* |
| 8073 | * IP address takeover related functions |
| 8074 | */ |
| 8075 | static void |
| 8076 | qeth_clear_ipato_list(struct qeth_card *card) |
| 8077 | { |
| 8078 | struct qeth_ipato_entry *ipatoe, *tmp; |
| 8079 | unsigned long flags; |
| 8080 | |
| 8081 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8082 | list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) { |
| 8083 | list_del(&ipatoe->entry); |
| 8084 | kfree(ipatoe); |
| 8085 | } |
| 8086 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8087 | } |
| 8088 | |
| 8089 | int |
| 8090 | qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new) |
| 8091 | { |
| 8092 | struct qeth_ipato_entry *ipatoe; |
| 8093 | unsigned long flags; |
| 8094 | int rc = 0; |
| 8095 | |
| 8096 | QETH_DBF_TEXT(trace, 2, "addipato"); |
| 8097 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8098 | list_for_each_entry(ipatoe, &card->ipato.entries, entry){ |
| 8099 | if (ipatoe->proto != new->proto) |
| 8100 | continue; |
| 8101 | if (!memcmp(ipatoe->addr, new->addr, |
| 8102 | (ipatoe->proto == QETH_PROT_IPV4)? 4:16) && |
| 8103 | (ipatoe->mask_bits == new->mask_bits)){ |
| 8104 | PRINT_WARN("ipato entry already exists!\n"); |
| 8105 | rc = -EEXIST; |
| 8106 | break; |
| 8107 | } |
| 8108 | } |
| 8109 | if (!rc) { |
| 8110 | list_add_tail(&new->entry, &card->ipato.entries); |
| 8111 | } |
| 8112 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8113 | return rc; |
| 8114 | } |
| 8115 | |
| 8116 | void |
| 8117 | qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8118 | u8 *addr, int mask_bits) |
| 8119 | { |
| 8120 | struct qeth_ipato_entry *ipatoe, *tmp; |
| 8121 | unsigned long flags; |
| 8122 | |
| 8123 | QETH_DBF_TEXT(trace, 2, "delipato"); |
| 8124 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8125 | list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){ |
| 8126 | if (ipatoe->proto != proto) |
| 8127 | continue; |
| 8128 | if (!memcmp(ipatoe->addr, addr, |
| 8129 | (proto == QETH_PROT_IPV4)? 4:16) && |
| 8130 | (ipatoe->mask_bits == mask_bits)){ |
| 8131 | list_del(&ipatoe->entry); |
| 8132 | kfree(ipatoe); |
| 8133 | } |
| 8134 | } |
| 8135 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8136 | } |
| 8137 | |
| 8138 | static inline void |
| 8139 | qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len) |
| 8140 | { |
| 8141 | int i, j; |
| 8142 | u8 octet; |
| 8143 | |
| 8144 | for (i = 0; i < len; ++i){ |
| 8145 | octet = addr[i]; |
| 8146 | for (j = 7; j >= 0; --j){ |
| 8147 | bits[i*8 + j] = octet & 1; |
| 8148 | octet >>= 1; |
| 8149 | } |
| 8150 | } |
| 8151 | } |
| 8152 | |
| 8153 | static int |
| 8154 | qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 8155 | { |
| 8156 | struct qeth_ipato_entry *ipatoe; |
| 8157 | u8 addr_bits[128] = {0, }; |
| 8158 | u8 ipatoe_bits[128] = {0, }; |
| 8159 | int rc = 0; |
| 8160 | |
| 8161 | if (!card->ipato.enabled) |
| 8162 | return 0; |
| 8163 | |
| 8164 | qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits, |
| 8165 | (addr->proto == QETH_PROT_IPV4)? 4:16); |
| 8166 | list_for_each_entry(ipatoe, &card->ipato.entries, entry){ |
| 8167 | if (addr->proto != ipatoe->proto) |
| 8168 | continue; |
| 8169 | qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits, |
| 8170 | (ipatoe->proto==QETH_PROT_IPV4) ? |
| 8171 | 4:16); |
| 8172 | if (addr->proto == QETH_PROT_IPV4) |
| 8173 | rc = !memcmp(addr_bits, ipatoe_bits, |
| 8174 | min(32, ipatoe->mask_bits)); |
| 8175 | else |
| 8176 | rc = !memcmp(addr_bits, ipatoe_bits, |
| 8177 | min(128, ipatoe->mask_bits)); |
| 8178 | if (rc) |
| 8179 | break; |
| 8180 | } |
| 8181 | /* invert? */ |
| 8182 | if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4) |
| 8183 | rc = !rc; |
| 8184 | else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6) |
| 8185 | rc = !rc; |
| 8186 | |
| 8187 | return rc; |
| 8188 | } |
| 8189 | |
| 8190 | /* |
| 8191 | * VIPA related functions |
| 8192 | */ |
| 8193 | int |
| 8194 | qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8195 | const u8 *addr) |
| 8196 | { |
| 8197 | struct qeth_ipaddr *ipaddr; |
| 8198 | unsigned long flags; |
| 8199 | int rc = 0; |
| 8200 | |
| 8201 | ipaddr = qeth_get_addr_buffer(proto); |
| 8202 | if (ipaddr){ |
| 8203 | if (proto == QETH_PROT_IPV4){ |
| 8204 | QETH_DBF_TEXT(trace, 2, "addvipa4"); |
| 8205 | memcpy(&ipaddr->u.a4.addr, addr, 4); |
| 8206 | ipaddr->u.a4.mask = 0; |
| 8207 | #ifdef CONFIG_QETH_IPV6 |
| 8208 | } else if (proto == QETH_PROT_IPV6){ |
| 8209 | QETH_DBF_TEXT(trace, 2, "addvipa6"); |
| 8210 | memcpy(&ipaddr->u.a6.addr, addr, 16); |
| 8211 | ipaddr->u.a6.pfxlen = 0; |
| 8212 | #endif |
| 8213 | } |
| 8214 | ipaddr->type = QETH_IP_TYPE_VIPA; |
| 8215 | ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG; |
| 8216 | ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG; |
| 8217 | } else |
| 8218 | return -ENOMEM; |
| 8219 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8220 | if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) || |
| 8221 | __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0)) |
| 8222 | rc = -EEXIST; |
| 8223 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8224 | if (rc){ |
| 8225 | PRINT_WARN("Cannot add VIPA. Address already exists!\n"); |
| 8226 | return rc; |
| 8227 | } |
| 8228 | if (!qeth_add_ip(card, ipaddr)) |
| 8229 | kfree(ipaddr); |
| 8230 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8231 | schedule_work(&card->kernel_thread_starter); |
| 8232 | return rc; |
| 8233 | } |
| 8234 | |
| 8235 | void |
| 8236 | qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8237 | const u8 *addr) |
| 8238 | { |
| 8239 | struct qeth_ipaddr *ipaddr; |
| 8240 | |
| 8241 | ipaddr = qeth_get_addr_buffer(proto); |
| 8242 | if (ipaddr){ |
| 8243 | if (proto == QETH_PROT_IPV4){ |
| 8244 | QETH_DBF_TEXT(trace, 2, "delvipa4"); |
| 8245 | memcpy(&ipaddr->u.a4.addr, addr, 4); |
| 8246 | ipaddr->u.a4.mask = 0; |
| 8247 | #ifdef CONFIG_QETH_IPV6 |
| 8248 | } else if (proto == QETH_PROT_IPV6){ |
| 8249 | QETH_DBF_TEXT(trace, 2, "delvipa6"); |
| 8250 | memcpy(&ipaddr->u.a6.addr, addr, 16); |
| 8251 | ipaddr->u.a6.pfxlen = 0; |
| 8252 | #endif |
| 8253 | } |
| 8254 | ipaddr->type = QETH_IP_TYPE_VIPA; |
| 8255 | } else |
| 8256 | return; |
| 8257 | if (!qeth_delete_ip(card, ipaddr)) |
| 8258 | kfree(ipaddr); |
| 8259 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8260 | schedule_work(&card->kernel_thread_starter); |
| 8261 | } |
| 8262 | |
| 8263 | /* |
| 8264 | * proxy ARP related functions |
| 8265 | */ |
| 8266 | int |
| 8267 | qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8268 | const u8 *addr) |
| 8269 | { |
| 8270 | struct qeth_ipaddr *ipaddr; |
| 8271 | unsigned long flags; |
| 8272 | int rc = 0; |
| 8273 | |
| 8274 | ipaddr = qeth_get_addr_buffer(proto); |
| 8275 | if (ipaddr){ |
| 8276 | if (proto == QETH_PROT_IPV4){ |
| 8277 | QETH_DBF_TEXT(trace, 2, "addrxip4"); |
| 8278 | memcpy(&ipaddr->u.a4.addr, addr, 4); |
| 8279 | ipaddr->u.a4.mask = 0; |
| 8280 | #ifdef CONFIG_QETH_IPV6 |
| 8281 | } else if (proto == QETH_PROT_IPV6){ |
| 8282 | QETH_DBF_TEXT(trace, 2, "addrxip6"); |
| 8283 | memcpy(&ipaddr->u.a6.addr, addr, 16); |
| 8284 | ipaddr->u.a6.pfxlen = 0; |
| 8285 | #endif |
| 8286 | } |
| 8287 | ipaddr->type = QETH_IP_TYPE_RXIP; |
| 8288 | ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG; |
| 8289 | ipaddr->del_flags = 0; |
| 8290 | } else |
| 8291 | return -ENOMEM; |
| 8292 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8293 | if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) || |
| 8294 | __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0)) |
| 8295 | rc = -EEXIST; |
| 8296 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8297 | if (rc){ |
| 8298 | PRINT_WARN("Cannot add RXIP. Address already exists!\n"); |
| 8299 | return rc; |
| 8300 | } |
| 8301 | if (!qeth_add_ip(card, ipaddr)) |
| 8302 | kfree(ipaddr); |
| 8303 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8304 | schedule_work(&card->kernel_thread_starter); |
| 8305 | return 0; |
| 8306 | } |
| 8307 | |
| 8308 | void |
| 8309 | qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8310 | const u8 *addr) |
| 8311 | { |
| 8312 | struct qeth_ipaddr *ipaddr; |
| 8313 | |
| 8314 | ipaddr = qeth_get_addr_buffer(proto); |
| 8315 | if (ipaddr){ |
| 8316 | if (proto == QETH_PROT_IPV4){ |
| 8317 | QETH_DBF_TEXT(trace, 2, "addrxip4"); |
| 8318 | memcpy(&ipaddr->u.a4.addr, addr, 4); |
| 8319 | ipaddr->u.a4.mask = 0; |
| 8320 | #ifdef CONFIG_QETH_IPV6 |
| 8321 | } else if (proto == QETH_PROT_IPV6){ |
| 8322 | QETH_DBF_TEXT(trace, 2, "addrxip6"); |
| 8323 | memcpy(&ipaddr->u.a6.addr, addr, 16); |
| 8324 | ipaddr->u.a6.pfxlen = 0; |
| 8325 | #endif |
| 8326 | } |
| 8327 | ipaddr->type = QETH_IP_TYPE_RXIP; |
| 8328 | } else |
| 8329 | return; |
| 8330 | if (!qeth_delete_ip(card, ipaddr)) |
| 8331 | kfree(ipaddr); |
| 8332 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8333 | schedule_work(&card->kernel_thread_starter); |
| 8334 | } |
| 8335 | |
| 8336 | /** |
| 8337 | * IP event handler |
| 8338 | */ |
| 8339 | static int |
| 8340 | qeth_ip_event(struct notifier_block *this, |
| 8341 | unsigned long event,void *ptr) |
| 8342 | { |
| 8343 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 8344 | struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev; |
| 8345 | struct qeth_ipaddr *addr; |
| 8346 | struct qeth_card *card; |
| 8347 | |
| 8348 | QETH_DBF_TEXT(trace,3,"ipevent"); |
| 8349 | card = qeth_get_card_from_dev(dev); |
| 8350 | if (!card) |
| 8351 | return NOTIFY_DONE; |
| 8352 | if (card->options.layer2) |
| 8353 | return NOTIFY_DONE; |
| 8354 | |
| 8355 | addr = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 8356 | if (addr != NULL) { |
| 8357 | addr->u.a4.addr = ifa->ifa_address; |
| 8358 | addr->u.a4.mask = ifa->ifa_mask; |
| 8359 | addr->type = QETH_IP_TYPE_NORMAL; |
| 8360 | } else |
| 8361 | goto out; |
| 8362 | |
| 8363 | switch(event) { |
| 8364 | case NETDEV_UP: |
| 8365 | if (!qeth_add_ip(card, addr)) |
| 8366 | kfree(addr); |
| 8367 | break; |
| 8368 | case NETDEV_DOWN: |
| 8369 | if (!qeth_delete_ip(card, addr)) |
| 8370 | kfree(addr); |
| 8371 | break; |
| 8372 | default: |
| 8373 | break; |
| 8374 | } |
| 8375 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8376 | schedule_work(&card->kernel_thread_starter); |
| 8377 | out: |
| 8378 | return NOTIFY_DONE; |
| 8379 | } |
| 8380 | |
| 8381 | static struct notifier_block qeth_ip_notifier = { |
| 8382 | qeth_ip_event, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 8383 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8384 | }; |
| 8385 | |
| 8386 | #ifdef CONFIG_QETH_IPV6 |
| 8387 | /** |
| 8388 | * IPv6 event handler |
| 8389 | */ |
| 8390 | static int |
| 8391 | qeth_ip6_event(struct notifier_block *this, |
| 8392 | unsigned long event,void *ptr) |
| 8393 | { |
| 8394 | |
| 8395 | struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; |
| 8396 | struct net_device *dev = (struct net_device *)ifa->idev->dev; |
| 8397 | struct qeth_ipaddr *addr; |
| 8398 | struct qeth_card *card; |
| 8399 | |
| 8400 | QETH_DBF_TEXT(trace,3,"ip6event"); |
| 8401 | |
| 8402 | card = qeth_get_card_from_dev(dev); |
| 8403 | if (!card) |
| 8404 | return NOTIFY_DONE; |
| 8405 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 8406 | return NOTIFY_DONE; |
| 8407 | |
| 8408 | addr = qeth_get_addr_buffer(QETH_PROT_IPV6); |
| 8409 | if (addr != NULL) { |
| 8410 | memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr)); |
| 8411 | addr->u.a6.pfxlen = ifa->prefix_len; |
| 8412 | addr->type = QETH_IP_TYPE_NORMAL; |
| 8413 | } else |
| 8414 | goto out; |
| 8415 | |
| 8416 | switch(event) { |
| 8417 | case NETDEV_UP: |
| 8418 | if (!qeth_add_ip(card, addr)) |
| 8419 | kfree(addr); |
| 8420 | break; |
| 8421 | case NETDEV_DOWN: |
| 8422 | if (!qeth_delete_ip(card, addr)) |
| 8423 | kfree(addr); |
| 8424 | break; |
| 8425 | default: |
| 8426 | break; |
| 8427 | } |
| 8428 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8429 | schedule_work(&card->kernel_thread_starter); |
| 8430 | out: |
| 8431 | return NOTIFY_DONE; |
| 8432 | } |
| 8433 | |
| 8434 | static struct notifier_block qeth_ip6_notifier = { |
| 8435 | qeth_ip6_event, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 8436 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8437 | }; |
| 8438 | #endif |
| 8439 | |
| 8440 | static int |
Cornelia Huck | 66aea23 | 2005-08-08 09:22:36 -0700 | [diff] [blame] | 8441 | __qeth_reboot_event_card(struct device *dev, void *data) |
| 8442 | { |
| 8443 | struct qeth_card *card; |
| 8444 | |
| 8445 | card = (struct qeth_card *) dev->driver_data; |
| 8446 | qeth_clear_ip_list(card, 0, 0); |
| 8447 | qeth_qdio_clear_card(card, 0); |
| 8448 | return 0; |
| 8449 | } |
| 8450 | |
| 8451 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8452 | qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 8453 | { |
Heiko Carstens | d7cf0d5 | 2006-07-18 13:46:58 +0200 | [diff] [blame] | 8454 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8455 | |
Heiko Carstens | d7cf0d5 | 2006-07-18 13:46:58 +0200 | [diff] [blame] | 8456 | ret = driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL, |
| 8457 | __qeth_reboot_event_card); |
| 8458 | return ret ? NOTIFY_BAD : NOTIFY_DONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8459 | } |
| 8460 | |
| 8461 | |
| 8462 | static struct notifier_block qeth_reboot_notifier = { |
| 8463 | qeth_reboot_event, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 8464 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8465 | }; |
| 8466 | |
| 8467 | static int |
| 8468 | qeth_register_notifiers(void) |
| 8469 | { |
| 8470 | int r; |
| 8471 | |
| 8472 | QETH_DBF_TEXT(trace,5,"regnotif"); |
| 8473 | if ((r = register_reboot_notifier(&qeth_reboot_notifier))) |
| 8474 | return r; |
| 8475 | if ((r = register_inetaddr_notifier(&qeth_ip_notifier))) |
| 8476 | goto out_reboot; |
| 8477 | #ifdef CONFIG_QETH_IPV6 |
| 8478 | if ((r = register_inet6addr_notifier(&qeth_ip6_notifier))) |
| 8479 | goto out_ipv4; |
| 8480 | #endif |
| 8481 | return 0; |
| 8482 | |
| 8483 | #ifdef CONFIG_QETH_IPV6 |
| 8484 | out_ipv4: |
| 8485 | unregister_inetaddr_notifier(&qeth_ip_notifier); |
| 8486 | #endif |
| 8487 | out_reboot: |
| 8488 | unregister_reboot_notifier(&qeth_reboot_notifier); |
| 8489 | return r; |
| 8490 | } |
| 8491 | |
| 8492 | /** |
| 8493 | * unregister all event notifiers |
| 8494 | */ |
| 8495 | static void |
| 8496 | qeth_unregister_notifiers(void) |
| 8497 | { |
| 8498 | |
| 8499 | QETH_DBF_TEXT(trace,5,"unregnot"); |
| 8500 | BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier)); |
| 8501 | BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier)); |
| 8502 | #ifdef CONFIG_QETH_IPV6 |
| 8503 | BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier)); |
| 8504 | #endif /* QETH_IPV6 */ |
| 8505 | |
| 8506 | } |
| 8507 | |
| 8508 | #ifdef CONFIG_QETH_IPV6 |
| 8509 | static int |
| 8510 | qeth_ipv6_init(void) |
| 8511 | { |
| 8512 | qeth_old_arp_constructor = arp_tbl.constructor; |
Heiko Carstens | 3d8f3f3 | 2006-08-14 23:00:27 -0700 | [diff] [blame^] | 8513 | write_lock_bh(&arp_tbl.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8514 | arp_tbl.constructor = qeth_arp_constructor; |
Heiko Carstens | 3d8f3f3 | 2006-08-14 23:00:27 -0700 | [diff] [blame^] | 8515 | write_unlock_bh(&arp_tbl.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8516 | |
| 8517 | arp_direct_ops = (struct neigh_ops*) |
| 8518 | kmalloc(sizeof(struct neigh_ops), GFP_KERNEL); |
| 8519 | if (!arp_direct_ops) |
| 8520 | return -ENOMEM; |
| 8521 | |
| 8522 | memcpy(arp_direct_ops, &arp_direct_ops_template, |
| 8523 | sizeof(struct neigh_ops)); |
| 8524 | |
| 8525 | return 0; |
| 8526 | } |
| 8527 | |
| 8528 | static void |
| 8529 | qeth_ipv6_uninit(void) |
| 8530 | { |
Heiko Carstens | 3d8f3f3 | 2006-08-14 23:00:27 -0700 | [diff] [blame^] | 8531 | write_lock_bh(&arp_tbl.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8532 | arp_tbl.constructor = qeth_old_arp_constructor; |
Heiko Carstens | 3d8f3f3 | 2006-08-14 23:00:27 -0700 | [diff] [blame^] | 8533 | write_unlock_bh(&arp_tbl.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8534 | kfree(arp_direct_ops); |
| 8535 | } |
| 8536 | #endif /* CONFIG_QETH_IPV6 */ |
| 8537 | |
| 8538 | static void |
| 8539 | qeth_sysfs_unregister(void) |
| 8540 | { |
| 8541 | qeth_remove_driver_attributes(); |
| 8542 | ccw_driver_unregister(&qeth_ccw_driver); |
| 8543 | ccwgroup_driver_unregister(&qeth_ccwgroup_driver); |
| 8544 | s390_root_dev_unregister(qeth_root_dev); |
| 8545 | } |
| 8546 | /** |
| 8547 | * register qeth at sysfs |
| 8548 | */ |
| 8549 | static int |
| 8550 | qeth_sysfs_register(void) |
| 8551 | { |
| 8552 | int rc=0; |
| 8553 | |
| 8554 | rc = ccwgroup_driver_register(&qeth_ccwgroup_driver); |
| 8555 | if (rc) |
| 8556 | return rc; |
| 8557 | rc = ccw_driver_register(&qeth_ccw_driver); |
| 8558 | if (rc) |
| 8559 | return rc; |
| 8560 | rc = qeth_create_driver_attributes(); |
| 8561 | if (rc) |
| 8562 | return rc; |
| 8563 | qeth_root_dev = s390_root_dev_register("qeth"); |
| 8564 | if (IS_ERR(qeth_root_dev)) { |
| 8565 | rc = PTR_ERR(qeth_root_dev); |
| 8566 | return rc; |
| 8567 | } |
| 8568 | return 0; |
| 8569 | } |
| 8570 | |
| 8571 | /*** |
| 8572 | * init function |
| 8573 | */ |
| 8574 | static int __init |
| 8575 | qeth_init(void) |
| 8576 | { |
| 8577 | int rc=0; |
| 8578 | |
Heiko Carstens | e018ba1 | 2006-02-01 03:06:31 -0800 | [diff] [blame] | 8579 | PRINT_INFO("loading %s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8580 | |
| 8581 | INIT_LIST_HEAD(&qeth_card_list.list); |
| 8582 | INIT_LIST_HEAD(&qeth_notify_list); |
| 8583 | spin_lock_init(&qeth_notify_lock); |
| 8584 | rwlock_init(&qeth_card_list.rwlock); |
| 8585 | |
| 8586 | if (qeth_register_dbf_views()) |
| 8587 | goto out_err; |
| 8588 | if (qeth_sysfs_register()) |
| 8589 | goto out_sysfs; |
| 8590 | |
| 8591 | #ifdef CONFIG_QETH_IPV6 |
| 8592 | if (qeth_ipv6_init()) { |
| 8593 | PRINT_ERR("Out of memory during ipv6 init.\n"); |
| 8594 | goto out_sysfs; |
| 8595 | } |
| 8596 | #endif /* QETH_IPV6 */ |
| 8597 | if (qeth_register_notifiers()) |
| 8598 | goto out_ipv6; |
| 8599 | if (qeth_create_procfs_entries()) |
| 8600 | goto out_notifiers; |
| 8601 | |
| 8602 | return rc; |
| 8603 | |
| 8604 | out_notifiers: |
| 8605 | qeth_unregister_notifiers(); |
| 8606 | out_ipv6: |
| 8607 | #ifdef CONFIG_QETH_IPV6 |
| 8608 | qeth_ipv6_uninit(); |
| 8609 | #endif /* QETH_IPV6 */ |
| 8610 | out_sysfs: |
| 8611 | qeth_sysfs_unregister(); |
| 8612 | qeth_unregister_dbf_views(); |
| 8613 | out_err: |
| 8614 | PRINT_ERR("Initialization failed"); |
| 8615 | return rc; |
| 8616 | } |
| 8617 | |
| 8618 | static void |
| 8619 | __exit qeth_exit(void) |
| 8620 | { |
| 8621 | struct qeth_card *card, *tmp; |
| 8622 | unsigned long flags; |
| 8623 | |
| 8624 | QETH_DBF_TEXT(trace,1, "cleanup."); |
| 8625 | |
| 8626 | /* |
| 8627 | * Weed would not need to clean up our devices here, because the |
| 8628 | * common device layer calls qeth_remove_device for each device |
| 8629 | * as soon as we unregister our driver (done in qeth_sysfs_unregister). |
| 8630 | * But we do cleanup here so we can do a "soft" shutdown of our cards. |
| 8631 | * qeth_remove_device called by the common device layer would otherwise |
| 8632 | * do a "hard" shutdown (card->use_hard_stop is set to one in |
| 8633 | * qeth_remove_device). |
| 8634 | */ |
| 8635 | again: |
| 8636 | read_lock_irqsave(&qeth_card_list.rwlock, flags); |
| 8637 | list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){ |
| 8638 | read_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 8639 | qeth_set_offline(card->gdev); |
| 8640 | qeth_remove_device(card->gdev); |
| 8641 | goto again; |
| 8642 | } |
| 8643 | read_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 8644 | #ifdef CONFIG_QETH_IPV6 |
| 8645 | qeth_ipv6_uninit(); |
| 8646 | #endif |
| 8647 | qeth_unregister_notifiers(); |
| 8648 | qeth_remove_procfs_entries(); |
| 8649 | qeth_sysfs_unregister(); |
| 8650 | qeth_unregister_dbf_views(); |
| 8651 | printk("qeth: removed\n"); |
| 8652 | } |
| 8653 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 8654 | EXPORT_SYMBOL(qeth_osn_register); |
| 8655 | EXPORT_SYMBOL(qeth_osn_deregister); |
| 8656 | EXPORT_SYMBOL(qeth_osn_assist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8657 | module_init(qeth_init); |
| 8658 | module_exit(qeth_exit); |
Frank Pavlic | 1387780f | 2005-11-10 13:51:42 +0100 | [diff] [blame] | 8659 | MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8660 | MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \ |
| 8661 | "Copyright 2000,2003 IBM Corporation\n"); |
| 8662 | |
| 8663 | MODULE_LICENSE("GPL"); |